aboutsummaryrefslogtreecommitdiffhomepage
path: root/qml
diff options
context:
space:
mode:
authorMarvin Borner2020-04-05 19:24:57 +0200
committerMarvin Borner2020-04-05 19:24:57 +0200
commitbf800f3b9a78140d6ee5c031389af67f67d52d8f (patch)
tree0756b7ebd20e618b5d02a26a099b1eae61b2440b /qml
parentbfb99fed8efd71290f67735d27c7aa6bf4ee88f0 (diff)
v1.0 - Added awesome leaderboard!1.0
Was quite some work but I finally implemented a frontend for my backend leaderboard - works flawless! Furthermore this is now named v1.0 because I'm probably finished with the main work and won't add many more features.
Diffstat (limited to 'qml')
-rw-r--r--qml/pages/Game.qml27
-rw-r--r--qml/pages/LeaderBoard.qml106
-rw-r--r--qml/pages/Menu.qml7
3 files changed, 130 insertions, 10 deletions
diff --git a/qml/pages/Game.qml b/qml/pages/Game.qml
index fb0f01d..c99c8a3 100644
--- a/qml/pages/Game.qml
+++ b/qml/pages/Game.qml
@@ -1,5 +1,6 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
+import org.nemomobile.configuration 1.0
import ".."
Page {
@@ -14,12 +15,12 @@ Page {
anchors.fill: parent
contentHeight: root.height
- /*PullDownMenu {
+ PullDownMenu {
MenuItem {
text: qsTr("Leaderboard")
onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
}
- }*/
+ }
Column {
property int bits: page.bits
@@ -37,6 +38,18 @@ Page {
title: qsTr("Binary Fun")
}
+ function submit(start_time, end_time, difficulty, level) {
+ var key = "RmMwQ0ptT1FlSkpIeEdzNDB3a1B5OVk1ZE8wYkRjSzI=";
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", "https://marvinborner.de/lead/binaryfun1/add", true);
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
+ var query = "writeKey=" + Qt.atob(key) + "&win=true&board=default&start_time=" + start_time
+ + "&end_time=" + end_time + "&difficulty=" + difficulty
+ + "&level=" + level + "&cheats=" + (root.help ? "true" : "false")
+ + "&name="+ username.value + "&mods=0" + "&time=" + (end_time - start_time);
+ xhr.send(query);
+ }
+
function nearest(number) {
if (number % (bits + 1) === 0) {
return number
@@ -63,10 +76,12 @@ Page {
if (correct.filter(function(i) { return i === 1 }).length === bits) {
if (timer.running) { // aka still playing
+ var end_time = (new Date()).getTime();
info_label.text = "Yeeehaaw!";
- timer_label.text = ((new Date().getTime() - start_time) / 1000) + "s - " + qsTr("Not bad!");
+ timer_label.text = ((end_time - start_time) / 1000) + "s - " + qsTr("Not bad!");
timer.running = false;
new_game.visible = true;
+ submit(start_time, end_time, bits, root.matrix.join(","))
}
}
}
@@ -124,4 +139,10 @@ Page {
}
}
}
+
+ ConfigurationValue {
+ id: username
+ key: "/com/binaryfun/username"
+ defaultValue: "anon"
+ }
}
diff --git a/qml/pages/LeaderBoard.qml b/qml/pages/LeaderBoard.qml
index eae37b0..f80c969 100644
--- a/qml/pages/LeaderBoard.qml
+++ b/qml/pages/LeaderBoard.qml
@@ -1,22 +1,114 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
+import org.nemomobile.configuration 1.0
Page {
id: page
allowedOrientations: Orientation.Portrait
- SilicaFlickable {
+ Column {
anchors.fill: parent
- contentHeight: column.height
+ anchors.margins: Theme.paddingMedium
- Column {
- id: column
+ PageHeader {
+ title: qsTr("Leaderboard")
+ }
+
+ TextField {
+ placeholderText: "Enter username (default: anon)"
+ text: username.value
+ label: "Username"
width: page.width
- spacing: Theme.paddingLarge
+ EnterKey.enabled: text.length > 0 && text.length <= 16
+ EnterKey.iconSource: "image://theme/icon-m-enter-close"
+ EnterKey.onClicked: {
+ focus = false
+ username.value = text
+ }
+ }
+
+ ComboBox {
+ id: selector
+ label: "Difficulty"
- PageHeader {
- title: qsTr("Under Construction!")
+ function select(diff) {
+ var xhr = new XMLHttpRequest()
+ xhr.open("GET",
+ "https://marvinborner.de/lead/binaryfun1/list?sort=time&order=asc&count=1000&filter=difficulty,"+diff,
+ false)
+ xhr.send()
+ if (xhr.status !== 0) {
+ list.model = JSON.parse(xhr.responseText);
+ internet.visible = false;
+ } else {
+ internet.visible = true;
+ }
}
+
+ menu: ContextMenu {
+ MenuItem {
+ text: qsTr("Please select")
+ }
+ MenuItem {
+ property int diff: 2
+ text: qsTr("Very easy (2 Bit)")
+ onClicked: selector.select(diff)
+ }
+ MenuItem {
+ property int diff: 4
+ text: qsTr("Easy (4 Bit)")
+ onClicked: selector.select(diff)
+ }
+ MenuItem {
+ property int diff: 6
+ text: qsTr("Medium (6 Bit)")
+ onClicked: selector.select(diff)
+ }
+ MenuItem {
+ property int diff: 8
+ text: qsTr("Hard (8 Bit)")
+ onClicked: selector.select(diff)
+ }
+ MenuItem {
+ property int diff: 10
+ text: qsTr("God-like (10 Bit)")
+ onClicked: selector.select(diff)
+ }
+ }
+ }
+
+ Label {
+ id: internet
+ text: qsTr("No internet connection!")
+ visible: false
}
+
+ ListView {
+ id: list
+ clip: true
+ width: page.width
+ height: page.height - y
+ model: []
+ delegate: ListItem {
+ contentHeight: Theme.itemSizeMedium
+
+ Label {
+ id: name
+ text: index + 1 + ". " + modelData.name
+ }
+
+ Label {
+ anchors.top: name.bottom
+ text: ((modelData.end_time[1] - modelData.start_time[1]) / 1000) + "s - Help: " + modelData.cheats
+ font.pixelSize: Theme.fontSizeSmall
+ }
+ }
+ }
+ }
+
+ ConfigurationValue {
+ id: username
+ key: "/com/binaryfun/username"
+ defaultValue: "anon"
}
}
diff --git a/qml/pages/Menu.qml b/qml/pages/Menu.qml
index caf2e00..6c1dd08 100644
--- a/qml/pages/Menu.qml
+++ b/qml/pages/Menu.qml
@@ -9,6 +9,13 @@ Page {
anchors.fill: parent
contentHeight: column.height
+ PullDownMenu {
+ MenuItem {
+ text: qsTr("Leaderboard")
+ onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
+ }
+ }
+
Column {
property bool bar: false