mirror of
https://github.com/overte-org/community-apps.git
synced 2025-04-07 02:22:35 +02:00
Fix page on closing and reopening window.
This commit is contained in:
parent
8a6f7dd394
commit
9363457528
2 changed files with 45 additions and 27 deletions
|
@ -16,6 +16,12 @@
|
|||
// FIXME: Handle ties: Last two standing are tied.
|
||||
|
||||
// FIXME: Host closes window does not return them to client view when applicable
|
||||
// FIXME: Recasting vote from closed window does not populate the options.
|
||||
// FIXME: Sound is inconsistent
|
||||
|
||||
// STYLE ---------------
|
||||
// FIXME: Camel case
|
||||
// TODO: Placeholder text
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
|
@ -29,6 +35,7 @@
|
|||
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
|
||||
let selectedPage = ""; // Selected page the vote screen is on. Used when the host closes the window.
|
||||
|
||||
const url = Script.resolvePath("./vote.qml");
|
||||
const myUuid = generateUUID(MyAvatar.sessionUUID);
|
||||
|
@ -76,7 +83,8 @@
|
|||
|
||||
// If we are hosting a poll, switch the screen
|
||||
if (poll.id != '' && poll.host == myUuid) {
|
||||
return _emitEvent({type: "rehost", prompt: {question: poll.question, options: poll.options}});
|
||||
// return _emitEvent({type: "rehost", prompt: {question: poll.question, options: poll.options}});
|
||||
return _emitEvent({type: "switch_page", page: selectedPage, options: {isHost: poll.host == myUuid, hostCanVote: poll.host_can_vote}, poll: poll});
|
||||
}
|
||||
|
||||
// Request a list of active polls if we are not already in one
|
||||
|
@ -364,6 +372,9 @@
|
|||
electionIterations = 0;
|
||||
preformElection();
|
||||
break;
|
||||
case "page_name":
|
||||
selectedPage = event.page;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -45,7 +45,7 @@ Rectangle {
|
|||
anchors.fill: parent
|
||||
|
||||
onClicked: {
|
||||
current_page = "poll_create";
|
||||
_changePage("poll_create");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ Rectangle {
|
|||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
current_page = "poll_list";
|
||||
_changePage("poll_list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,10 +217,11 @@ Rectangle {
|
|||
verticalAlignment: Text.AlignVCenter
|
||||
y: 20
|
||||
}
|
||||
// TODO: Pleaseholder text
|
||||
TextEdit {
|
||||
id: poll_to_respond_title
|
||||
width: parent.width
|
||||
text: "<Question>"
|
||||
text: ""
|
||||
color: "white"
|
||||
font.pointSize: 20
|
||||
wrapMode: Text.NoWrap
|
||||
|
@ -236,6 +237,7 @@ Rectangle {
|
|||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
// TODO: Pleaseholder text
|
||||
ListView {
|
||||
property int index_selected: -1
|
||||
width: parent.width - 40
|
||||
|
@ -345,8 +347,8 @@ Rectangle {
|
|||
toScript({type: "prompt", prompt: {question: poll_to_respond_title.text, options: options}, host_can_vote: host_can_vote});
|
||||
|
||||
// If the host can vote, change the screen to the client view to allow the vote
|
||||
if (host_can_vote) current_page = "poll_client_view";
|
||||
else current_page = "poll_results"
|
||||
if (host_can_vote) _changePage("poll_client_view");
|
||||
else _changePage("poll_results");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -482,7 +484,7 @@ Rectangle {
|
|||
toScript({type: "cast_vote", ballot: onlyNames});
|
||||
|
||||
// Change screen to results screen
|
||||
current_page = "poll_results"
|
||||
_changePage("poll_results");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -615,7 +617,7 @@ Rectangle {
|
|||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
current_page = "poll_client_view"
|
||||
_changePage("poll_client_view");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -667,7 +669,7 @@ Rectangle {
|
|||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
current_page = "poll_host_view"
|
||||
_changePage("poll_host_view");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -691,7 +693,7 @@ Rectangle {
|
|||
onClicked: {
|
||||
_clearHost();
|
||||
_clearResults();
|
||||
current_page = "poll_host_view";
|
||||
_changePage("poll_host_view");
|
||||
votes_tallied = false;
|
||||
}
|
||||
}
|
||||
|
@ -914,6 +916,11 @@ Rectangle {
|
|||
poll_to_create_description.text = "Vote on things!";
|
||||
}
|
||||
|
||||
function _changePage(pageName){
|
||||
current_page = pageName;
|
||||
toScript({type: "page_name", page: pageName});
|
||||
}
|
||||
|
||||
// Messages from script
|
||||
function fromScript(message) {
|
||||
switch (message.type){
|
||||
|
@ -922,7 +929,7 @@ Rectangle {
|
|||
_clearHost()
|
||||
|
||||
// Show host page
|
||||
current_page = "poll_host_view";
|
||||
_changePage("poll_host_view");
|
||||
|
||||
// Set variables
|
||||
is_host = true
|
||||
|
@ -949,7 +956,7 @@ Rectangle {
|
|||
|
||||
if (is_host) return;
|
||||
|
||||
current_page = "poll_client_view";
|
||||
_changePage("poll_client_view");
|
||||
|
||||
// Clear the results page
|
||||
_clearResults()
|
||||
|
@ -959,7 +966,7 @@ Rectangle {
|
|||
|
||||
// Close the poll and remove it from the list of active polls
|
||||
case "close_poll":
|
||||
if (message.change_page == true) current_page = "poll_list"
|
||||
if (message.change_page == true) _changePage("poll_list");
|
||||
|
||||
// Find the poll with the matching ID and remove it from active polls
|
||||
for (var i = 0; i < active_polls.count; i++) {
|
||||
|
@ -974,20 +981,6 @@ Rectangle {
|
|||
poll_to_create_host_can_vote.checked = false;
|
||||
|
||||
break;
|
||||
|
||||
// Open the host view
|
||||
// Only called when the host closes their tablet and reopens it.
|
||||
case "rehost":
|
||||
current_page = "poll_host_view"
|
||||
|
||||
poll_to_respond_title.text = message.prompt.question
|
||||
|
||||
poll_option_model_host.clear();
|
||||
for (var option of message.prompt.options){
|
||||
console.log("adding option "+ option);
|
||||
poll_option_model_host.append({option: option})
|
||||
}
|
||||
break;
|
||||
case "poll_winner":
|
||||
poll_winner.text = message.winner
|
||||
tally_votes_itterations.text = message.rounds
|
||||
|
@ -997,6 +990,20 @@ Rectangle {
|
|||
case "received_vote":
|
||||
tally_votes_received.text = message.voteCount
|
||||
break;
|
||||
case "switch_page":
|
||||
current_page = message.page;
|
||||
is_host = message.options.isHost;
|
||||
host_can_vote = message.options.hostCanVote;
|
||||
// if (message.page == "poll_host_view") {
|
||||
// poll_to_respond_title.text = message.poll.question
|
||||
|
||||
// poll_option_model_host.clear();
|
||||
// for (var option of message.poll.options){
|
||||
// console.log("adding option "+ option);
|
||||
// poll_option_model_host.append({option: option})
|
||||
// }
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue