From 8a6f7dd39448e1db2426d20b63da6b304e013d38 Mon Sep 17 00:00:00 2001 From: armored-dragon Date: Fri, 13 Sep 2024 00:25:26 -0500 Subject: [PATCH] Don't allow late votes. Clear poll create screen. --- applications/voting/vote.js | 8 +++++++- applications/voting/vote.qml | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/applications/voting/vote.js b/applications/voting/vote.js index 3b95a52..c1df777 100644 --- a/applications/voting/vote.js +++ b/applications/voting/vote.js @@ -12,7 +12,6 @@ /* global Script Tablet Messages MyAvatar Uuid*/ // TODO: Documentation -// FIXME: Reset create_poll view when switching screens // FIXME: Handle ties: kill both of tied results // FIXME: Handle ties: Last two standing are tied. @@ -29,6 +28,7 @@ let responses = {}; // All ballots received and to be used by the election function. let electionIterations = 0; // How many times the election function has been called to narrow down a candidate. let activePolls = []; // All active polls. + let winnerSelected = false; // Whether or not the election function has selected a winner for the active poll const url = Script.resolvePath("./vote.qml"); const myUuid = generateUUID(MyAvatar.sessionUUID); @@ -187,6 +187,9 @@ // Check if poll is valid if (poll == undefined || poll.id == '') return; + // Check if a winner was already chosen + if (winnerSelected) return; + // Send vote to users in poll Messages.sendMessage(poll.id, JSON.stringify({type: "vote", ballot: event.ballot, uuid: myUuid})); } @@ -433,6 +436,8 @@ _emitEvent({type: "poll_prompt", prompt: message.prompt}); poll.question = message.prompt.question; + + winnerSelected = false; } if (message.type == "vote_count") { @@ -456,6 +461,7 @@ // Winner was broadcasted if (message.type == "poll_winner") { + winnerSelected = true; _emitEvent({type: "poll_winner", winner: message.winner, rounds: message.rounds, votesCounted: message.votesCounted}); } diff --git a/applications/voting/vote.qml b/applications/voting/vote.qml index bee2e85..5ed9ba4 100644 --- a/applications/voting/vote.qml +++ b/applications/voting/vote.qml @@ -95,7 +95,7 @@ Rectangle { TextField { width: 300 height: 30 - text: "New Poll" + text: MyAvatar.displayName + "'s Poll" cursorVisible: false font.pointSize: 16 Layout.fillWidth: true @@ -124,6 +124,7 @@ Rectangle { } + // Options RowLayout { width: parent.width @@ -135,6 +136,7 @@ Rectangle { } CheckBox { + id: poll_to_create_host_can_vote width: 30 height: 25 checked: false @@ -182,6 +184,7 @@ Rectangle { anchors.fill: parent onClicked: { toScript({type: "create_poll", poll: {title: poll_to_create_title.text, description: poll_to_create_description.text}}); + _clearHostCreate(); } } } @@ -906,6 +909,11 @@ Rectangle { poll_option_model_host.clear(); } + function _clearHostCreate() { + poll_to_create_title.text = MyAvatar.displayName + "'s Poll"; + poll_to_create_description.text = "Vote on things!"; + } + // Messages from script function fromScript(message) { switch (message.type){ @@ -963,6 +971,7 @@ Rectangle { // Set variables is_host = false + poll_to_create_host_can_vote.checked = false; break;