Repository navigation
Expand file tree
/
Copy pathVoteOptionButton.cs
More file actions
69 lines (56 loc) · 2.24 KB
/
Copy pathVoteOptionButton.cs
File metadata and controls
69 lines (56 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using MenuLib.MonoBehaviors;
using System;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;
namespace MapVote
{
internal sealed class VoteOptionButton
{
public string Level { get; set; }
public REPOButton Button { get; set; }
public bool IsRandomButton { get; set; }
public VoteOptionButton(string _level, int _votes, REPOButton _button, bool _isRandomButton = false)
{
Level = _level;
Button = _button;
IsRandomButton = _isRandomButton;
}
public int GetVotes(Dictionary<int, string> votes)
{
var votesNum = 0;
foreach (var entry in votes)
{
if (entry.Value == Level)
{
votesNum++;
}
}
return votesNum;
}
public void UpdateLabel(bool _highlight = false, bool _disabled = false)
{
var votes = MapVote.CurrentVotes.Values;
var ownVote = MapVote.OwnVoteLevel == Level;
var playerCount = Math.Max(Math.Min(GameDirector.instance.PlayerList.Count, 12), 4);
var votesCount = GetVotes(votes);
Color mainColor = _disabled ? Color.gray : (_highlight == true ? Color.green : ownVote ? Color.yellow : Color.white);
StringBuilder sb = new();
if (_disabled) sb.Append("<s>");
sb.Append($"<align=left><mspace=0.25em>[{Utilities.ColorString((ownVote || _highlight ? "X" : " "), mainColor)}]</mspace> ");
if(!_disabled) sb.Append($"<color={LevelColorDictionary.GetColor(Level)}>");
sb.Append($"{(IsRandomButton ? MapVote.VOTE_RANDOM_LABEL : Utilities.RemoveLevelPrefix(Level))}");
if (!_disabled)
{
sb.Append("</color>");
}
if (_disabled) sb.Append("</s>");
sb.Append("<line-height=0>\n");
sb.Append(
$"<align=right>{Utilities.ColorString(new string('I', votesCount), Color.green)}{Utilities.ColorString(new string('I', playerCount - votesCount), Color.white)}<line-height=1em>");
Button.labelTMP.text =
$"{sb.ToString()}";
}
}
}