summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-04-12 14:50:42 +0200
committerMarvin Borner2020-04-12 14:50:42 +0200
commitbdbe3a0c074c3a1b81786ffb9f7cc1b41fc0b0dd (patch)
treed2147ce6f92dadd8cac22ab619438b5b4e7cddb6
parent0cc8b365bfdf030820cdbaad87709a38e591b0b2 (diff)
Added resign, draw and abort logic and chat
-rw-r--r--harbour-sailchess.pro1
-rw-r--r--qml/Functions.qml17
-rw-r--r--qml/harbour-sailchess.qml2
-rw-r--r--qml/pages/Board.qml36
-rw-r--r--qml/pages/Login.qml2
-rw-r--r--qml/pages/UserDialog.qml25
-rw-r--r--translations/harbour-sailchess-de.ts57
-rw-r--r--translations/harbour-sailchess.ts35
8 files changed, 149 insertions, 26 deletions
diff --git a/harbour-sailchess.pro b/harbour-sailchess.pro
index bf82072..02c52aa 100644
--- a/harbour-sailchess.pro
+++ b/harbour-sailchess.pro
@@ -23,6 +23,7 @@ DISTFILES += qml/harbour-sailchess.qml \
qml/Functions.qml \
qml/pages/ChallengeDialog.qml \
qml/pages/Login.qml \
+ qml/pages/UserDialog.qml \
rpm/harbour-sailchess.changes.in \
rpm/harbour-sailchess.changes.run.in \
rpm/harbour-sailchess.spec \
diff --git a/qml/Functions.qml b/qml/Functions.qml
index 67c5f30..d6a9ca1 100644
--- a/qml/Functions.qml
+++ b/qml/Functions.qml
@@ -179,6 +179,7 @@ Item {
stop_game();
return;
} else if (data["type"] === "chatLine") {
+ chat.text = data["username"] + ": " + data["text"];
return;
}
@@ -239,6 +240,22 @@ Item {
})
}
+ function resign() {
+ post("board/game/" + game_id + "/resign", "", function (response) {
+ if (response["ok"]) {
+ information.text = qsTr("Game over: ") + qsTr("Resigned");
+ stop_game();
+ }
+ })
+ }
+
+ function offer_draw() {
+ post("board/game/" + game_id + "/draw/yes", "", function (response) {
+ if (response["ok"])
+ information.text = qsTr("Offered draw");
+ })
+ }
+
function challenge(username) {
post("challenge/" + username, "rated=false&clock.limit=10800&clock.increment=60&days=14&color=white", function (response) {
if (!response["error"]) {
diff --git a/qml/harbour-sailchess.qml b/qml/harbour-sailchess.qml
index aed55f7..d336a99 100644
--- a/qml/harbour-sailchess.qml
+++ b/qml/harbour-sailchess.qml
@@ -1,6 +1,6 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
-import org.nemomobile.configuration 1.0
+import Nemo.Configuration 1.0
import "pages"
ApplicationWindow
diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml
index 240fa11..0f2af45 100644
--- a/qml/pages/Board.qml
+++ b/qml/pages/Board.qml
@@ -1,6 +1,6 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
-import org.nemomobile.configuration 1.0
+import Nemo.Configuration 1.0
import ".."
Page {
@@ -30,15 +30,31 @@ Page {
onClicked: functions.start_seek()
}
MenuItem {
- text: qsTr("Play against bot")
+ text: qsTr("Challenge user")
visible: functions.game_id === "" ? true : false
- onClicked: functions.challenge("awesomelvin")
+ onClicked: {
+ var dialog = pageStack.push("UserDialog.qml");
+ dialog.accepted.connect(function() {
+ functions.challenge(dialog.name);
+ });
+ }
}
MenuItem {
+ // I THINK it works like that
text: qsTr("Abort game")
- visible: functions.game_id === "" ? false : true
+ visible: functions.game_id !== "" && functions.moves.split(" ").length <= 2 ? true : false
onClicked: functions.abort()
}
+ MenuItem {
+ text: qsTr("Resign game")
+ visible: functions.game_id !== "" && functions.moves.split(" ").length > 2 ? true : false
+ onClicked: functions.resign()
+ }
+ MenuItem {
+ text: qsTr("Offer/accept draw")
+ visible: functions.game_id !== "" && functions.moves.split(" ").length > 2 ? true : false
+ onClicked: functions.offer_draw()
+ }
}
Column {
@@ -83,12 +99,22 @@ Page {
}
Label {
- // id: turn_label
+ id: turn_label
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: grid.bottom
topPadding: Theme.paddingMedium
text: functions.turn ? qsTr("Your turn") : qsTr("Opponents turn");
}
+
+ LinkedLabel {
+ id: chat
+ width: parent.width
+ color: "white"
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.top: turn_label.bottom
+ topPadding: Theme.paddingMedium
+ plainText: "";
+ }
}
}
diff --git a/qml/pages/Login.qml b/qml/pages/Login.qml
index e493f2f..8f621f4 100644
--- a/qml/pages/Login.qml
+++ b/qml/pages/Login.qml
@@ -1,7 +1,7 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
import QtWebKit 3.0
-import org.nemomobile.configuration 1.0
+import Nemo.Configuration 1.0
Page {
SilicaWebView {
diff --git a/qml/pages/UserDialog.qml b/qml/pages/UserDialog.qml
new file mode 100644
index 0000000..3471819
--- /dev/null
+++ b/qml/pages/UserDialog.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.2
+import Sailfish.Silica 1.0
+
+Dialog {
+ property var name
+
+ Column {
+ width: parent.width
+
+ DialogHeader { }
+
+ TextField {
+ id: username
+ width: parent.width
+ placeholderText: qsTr("e.g. LeelaChess")
+ label: qsTr("Username")
+ }
+ }
+
+ onDone: {
+ if (result == DialogResult.Accepted) {
+ name = username.text;
+ }
+ }
+}
diff --git a/translations/harbour-sailchess-de.ts b/translations/harbour-sailchess-de.ts
index 25b3944..e96d805 100644
--- a/translations/harbour-sailchess-de.ts
+++ b/translations/harbour-sailchess-de.ts
@@ -5,42 +5,50 @@
<name>Board</name>
<message>
<source>Chess</source>
- <translation type="unfinished"></translation>
+ <translation>Schach</translation>
</message>
<message>
<source>Random player</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <source>Play against bot</source>
- <translation type="unfinished"></translation>
+ <translation>Zufälliger Spieler</translation>
</message>
<message>
<source>Please start a game</source>
- <translation type="unfinished"></translation>
+ <translation>Bitte starte ein Spiel</translation>
</message>
<message>
<source>Abort game</source>
- <translation type="unfinished"></translation>
+ <translation>Abbrechen</translation>
</message>
<message>
<source>Refresh login</source>
- <translation type="unfinished"></translation>
+ <translation>Anmeldung regenerieren</translation>
</message>
<message>
<source>Your turn</source>
- <translation type="unfinished"></translation>
+ <translation>Du bist dran</translation>
</message>
<message>
<source>Opponents turn</source>
+ <translation>Der Gegner ist dran</translation>
+ </message>
+ <message>
+ <source>Challenge user</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Resign game</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>Offer/accept draw</source>
+ <translation>Remis anbieten/annehmen</translation>
+ </message>
</context>
<context>
<name>ChallengeDialog</name>
<message>
<source> challenges you</source>
- <translation type="unfinished"></translation>
+ <translation> fordert dich heraus</translation>
</message>
</context>
<context>
@@ -54,23 +62,42 @@
<name>Functions</name>
<message>
<source>Game started!</source>
- <translation type="unfinished"></translation>
+ <translation>Spiel gestartet!</translation>
</message>
<message>
<source>Please start a game</source>
- <translation type="unfinished"></translation>
+ <translation>Bitte starte ein Spiel</translation>
</message>
<message>
<source>Waiting for </source>
- <translation type="unfinished"></translation>
+ <translation>Warte auf </translation>
</message>
<message>
<source>Game over: </source>
- <translation type="unfinished"></translation>
+ <translation>Spiel vorbei: </translation>
</message>
<message>
<source>An error occurred: </source>
+ <translation>Ein Fehler ist aufgetreten: </translation>
+ </message>
+ <message>
+ <source>Resigned</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>Offered draw</source>
+ <translation>Remis angeboten</translation>
+ </message>
+</context>
+<context>
+ <name>UserDialog</name>
+ <message>
+ <source>e.g. LeelaChess</source>
+ <translation>z.B. LeelaChess</translation>
+ </message>
+ <message>
+ <source>Username</source>
+ <translation>Nutzername</translation>
+ </message>
</context>
</TS>
diff --git a/translations/harbour-sailchess.ts b/translations/harbour-sailchess.ts
index dbba811..a7295c9 100644
--- a/translations/harbour-sailchess.ts
+++ b/translations/harbour-sailchess.ts
@@ -12,10 +12,6 @@
<translation type="unfinished"></translation>
</message>
<message>
- <source>Play against bot</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
<source>Please start a game</source>
<translation type="unfinished"></translation>
</message>
@@ -35,6 +31,18 @@
<source>Opponents turn</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>Challenge user</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Resign game</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Offer/accept draw</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
<context>
<name>ChallengeDialog</name>
@@ -72,5 +80,24 @@
<source>An error occurred: </source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>Resigned</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Offered draw</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>UserDialog</name>
+ <message>
+ <source>e.g. LeelaChess</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Username</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
</TS>