diff --git a/qml/overlays/BulletinOverlay.qml b/qml/overlays/BulletinOverlay.qml index 75bfcff..57d0690 100644 --- a/qml/overlays/BulletinOverlay.qml +++ b/qml/overlays/BulletinOverlay.qml @@ -70,7 +70,7 @@ ColumnLayout { } if (msg.o != 2) return - if (msg.t != undefined) { + if (msg.t != undefined && msg.b != undefined) { jsonModel4.insert(0,{ "title":msg.t, "body": msg.b, diff --git a/qml/overlays/Game1Overlay.qml b/qml/overlays/Game1Overlay.qml index b534919..5f2e846 100644 --- a/qml/overlays/Game1Overlay.qml +++ b/qml/overlays/Game1Overlay.qml @@ -1,18 +1,260 @@ import QtGraphicalEffects 1.0 import QtQuick 2.7 import QtQuick.Controls 2.4 +import QtQuick.Controls 1.4 import QtQuick.Controls.Material 2.0 import QtQuick.Layouts 1.3 import "../widgets" import "../widgets/controls" as Awesome import "../fonts/Twemoji.js" as T +import "../utils.js" as Utils ColumnLayout { Layout.fillWidth: true + width:parent.width + anchors.horizontalCenter: parent.horizontalCenter + id: puzzleGame - ScalingLabel { - text: "gardening game or maybe some other cool cwtch-enabled game" - } + Connections { + target: gcd + + onClearMessages: function() { + + } + + onAppendMessage: function(handle, from, displayName, message, image, mid, fromMe, ts) { + var msg + try { + msg = JSON.parse(message) + } catch (e) { + return + } + if (msg.o != 3) return + + if (msg.p != undefined && msg.s != undefined) { + + var points = JSON.stringify(msg.s) + var path = JSON.stringify(msg.p) + + var remove = -1 + for(var i=0;i -1) { + solutions.remove(remove) + console.log("Better solution found for Puzzle " + "Puzzle " + JSON.stringify(msg.s)) + + } + solutions.insert(0,{ + "text": "Puzzle " + JSON.stringify(msg.s), + "points":points, + "path": path, + "from": from, + "displayName": displayName, + "timestamp": ts + }) + + } + } + } + + + ListModel { + id: solutions + } + + RowLayout { + + anchors.right: parent.right + anchors.rightMargin: 2 + + ComboBox { + width: 200 + textRole: "text" + model: solutions + onActivated: { + console.log("Loading puzzle " + index) + var solution = solutions.get(index) + console.log("Loading puzzle " + JSON.parse(solution.path)) + canvas.points = JSON.parse(solution.points) + canvas.path = JSON.parse(solution.path) + gameScore.text = Utils.scorePath(canvas.path) + canvas.requestPaint() + } + } + + Slider { + id: gameDifficulty + value: 5 + stepSize: 1.0 + minimumValue: 4.0 + maximumValue: 16.0 + anchors.rightMargin: 2 + } + + SimpleButton { // New Game + id: btnNewGame + icon: "regular/paper-plane" + text: "new game" + + anchors.rightMargin: 2 + + property int nextMessageID: 1 + + onClicked: { + /**if (newposttitle.text != "" && newpostbody.text != "") { + var msg = JSON.stringify({"o":2, "t":newposttitle.text, "b":newpostbody.text}) + gcd.sendMessage(msg, nextMessageID++) + } + newposttitle.text = "" + newpostbody.text = ""**/ + canvas.points = [] + canvas.path = [] + gameScore.text = 0 + for(var i=0;i