From a9655996f4392a1a442607a5f8cf8656a9baba2e Mon Sep 17 00:00:00 2001 From: Iajret Creature <122297233+Steals-The-PRs@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:00:57 +0300 Subject: [PATCH] [MIRROR] Allow voting statistics to be hidden (#2172) * Allow voting statistics to be hidden * Update VotePanel.tsx * Update VotePanel.tsx --------- Co-authored-by: NovaBot <154629622+NovaBot13@users.noreply.github.com> Co-authored-by: Jacquerel Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Iajret --- code/controllers/subsystem/vote.dm | 1 + code/datums/votes/_vote_datum.dm | 33 +++++++++++---------- code/datums/votes/custom_vote.dm | 11 +++++++ code/datums/votes/map_vote.dm | 1 + tgui/packages/tgui/interfaces/VotePanel.tsx | 10 +++---- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/code/controllers/subsystem/vote.dm b/code/controllers/subsystem/vote.dm index c4c3b85b4c9..410db36988d 100644 --- a/code/controllers/subsystem/vote.dm +++ b/code/controllers/subsystem/vote.dm @@ -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, ) diff --git a/code/datums/votes/_vote_datum.dm b/code/datums/votes/_vote_datum.dm index a882511b511..3f821a7129a 100644 --- a/code/datums/votes/_vote_datum.dm +++ b/code/datums/votes/_vote_datum.dm @@ -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 @@ -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 diff --git a/code/datums/votes/custom_vote.dm b/code/datums/votes/custom_vote.dm index 5960e7dff0e..d67eb0281c6 100644 --- a/code/datums/votes/custom_vote.dm +++ b/code/datums/votes/custom_vote.dm @@ -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 diff --git a/code/datums/votes/map_vote.dm b/code/datums/votes/map_vote.dm index f50c43d6c52..0092a455017 100644 --- a/code/datums/votes/map_vote.dm +++ b/code/datums/votes/map_vote.dm @@ -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() . = ..() diff --git a/tgui/packages/tgui/interfaces/VotePanel.tsx b/tgui/packages/tgui/interfaces/VotePanel.tsx index a92e45cc860..6e79ce58431 100644 --- a/tgui/packages/tgui/interfaces/VotePanel.tsx +++ b/tgui/packages/tgui/interfaces/VotePanel.tsx @@ -35,6 +35,7 @@ type ActiveVote = { vote: Vote; question: string | null; timeRemaining: number; + displayStatistics: boolean; choices: Option[]; countMethod: number; }; @@ -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}