Skip to content

Commit

Permalink
[MIRROR] Allow voting statistics to be hidden (#2172)
Browse files Browse the repository at this point in the history
* Allow voting statistics to be hidden

* Update VotePanel.tsx

* Update VotePanel.tsx

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: Jacquerel <[email protected]>
Co-authored-by: Bloop <[email protected]>
Co-authored-by: Iajret <[email protected]>
  • Loading branch information
5 people authored Mar 1, 2024
1 parent c08af86 commit a965599
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
1 change: 1 addition & 0 deletions code/controllers/subsystem/vote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ SUBSYSTEM_DEF(vote)
"question" = current_vote.override_question,
"timeRemaining" = current_vote.time_remaining,
"countMethod" = current_vote.count_method,
"displayStatistics" = current_vote.display_statistics,
"choices" = choices,
"vote" = vote_data,
)
Expand Down
33 changes: 18 additions & 15 deletions code/datums/votes/_vote_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
var/count_method = VOTE_COUNT_METHOD_SINGLE
/// The method for selecting a winner.
var/winner_method = VOTE_WINNER_METHOD_SIMPLE
/// Should we show details about the number of votes submitted for each option?
var/display_statistics = TRUE

/**
* Used to determine if this vote is a possible
Expand Down Expand Up @@ -193,21 +195,22 @@
if(total_votes <= 0)
return span_bold("Vote Result: Inconclusive - No Votes!")

returned_text += "\nResults:"
for(var/option in choices)
returned_text += "\n"
var/votes = choices[option]
var/percentage_text = ""
if(votes > 0)
var/actual_percentage = round((votes / total_votes) * 100, 0.1)
var/text = "[actual_percentage]"
var/spaces_needed = 5 - length(text)
for(var/_ in 1 to spaces_needed)
returned_text += " "
percentage_text += "[text]%"
else
percentage_text = " 0%"
returned_text += "[percentage_text] | [span_bold(option)]: [choices[option]]"
if (display_statistics)
returned_text += "\nResults:"
for(var/option in choices)
returned_text += "\n"
var/votes = choices[option]
var/percentage_text = ""
if(votes > 0)
var/actual_percentage = round((votes / total_votes) * 100, 0.1)
var/text = "[actual_percentage]"
var/spaces_needed = 5 - length(text)
for(var/_ in 1 to spaces_needed)
returned_text += " "
percentage_text += "[text]%"
else
percentage_text = " 0%"
returned_text += "[percentage_text] | [span_bold(option)]: [choices[option]]"

if(!real_winner) // vote has no winner or cannot be won, but still had votes
return returned_text
Expand Down
11 changes: 11 additions & 0 deletions code/datums/votes/custom_vote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
to_chat(vote_creator, span_boldwarning("Unknown winner method. Contact a coder."))
return FALSE

var/display_stats = tgui_alert(
vote_creator,
"Should voting statistics be public?",
"Show voting stats?",
list("Yes", "No"),
)

if(display_stats == null)
return FALSE
display_statistics = display_stats == "Yes"

override_question = tgui_input_text(vote_creator, "What is the vote for?", "Custom Vote")
if(!override_question)
return FALSE
Expand Down
1 change: 1 addition & 0 deletions code/datums/votes/map_vote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
message = "Vote for next round's map!"
count_method = VOTE_COUNT_METHOD_SINGLE
winner_method = VOTE_WINNER_METHOD_WEIGHTED_RANDOM
display_statistics = FALSE

/datum/vote/map_vote/New()
. = ..()
Expand Down
10 changes: 5 additions & 5 deletions tgui/packages/tgui/interfaces/VotePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ActiveVote = {
vote: Vote;
question: string | null;
timeRemaining: number;
displayStatistics: boolean;
choices: Option[];
countMethod: number;
};
Expand Down Expand Up @@ -209,11 +210,10 @@ const ChoicesPanel = (props) => {
name="vote-yea"
/>
)}
{
user.isLowerAdmin
? `${choice.votes} Votes`
: '' /* NOVA EDIT*/
}
{currentVote.displayStatistics ||
user.isLowerAdmin /* NOVA EDIT CHANGE - isLowerAdmin - ORIGINAL: {currentVote.displayStatistics */
? choice.votes + ' Votes'
: null}
</LabeledList.Item>
<LabeledList.Divider />
</Box>
Expand Down

0 comments on commit a965599

Please sign in to comment.