summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/NumberOption.cs
blob: ebe2f949531dc29211a5f204aa6dbb6561345d85 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using UnityEngine;

public class NumberOption : OptionBehaviour
{
	public TextRenderer TitleText;

	public TextRenderer ValueText;

	public float Value = 1f;

	private float oldValue = float.MaxValue;

	public float Increment;

	public FloatRange ValidRange = new FloatRange(0f, 2f);

	public string FormatString = "{0:0.0}x";

	public bool ZeroIsInfinity;

	public void OnEnable()
	{
		this.TitleText.Text = DestroyableSingleton<TranslationController>.Instance.GetString(this.Title, Array.Empty<object>());
		this.ValueText.Text = string.Format(this.FormatString, this.Value);
		GameOptionsData gameOptions = PlayerControl.GameOptions;
		StringNames title = this.Title;
		switch (title)
		{
		case StringNames.GameNumImpostors:
			this.Value = (float)gameOptions.NumImpostors;
			return;
		case StringNames.GameNumMeetings:
			this.Value = (float)gameOptions.NumEmergencyMeetings;
			return;
		case StringNames.GameDiscussTime:
			this.Value = (float)gameOptions.DiscussionTime;
			return;
		case StringNames.GameVotingTime:
			this.Value = (float)gameOptions.VotingTime;
			return;
		case StringNames.GamePlayerSpeed:
			this.Value = gameOptions.PlayerSpeedMod;
			return;
		case StringNames.GameCrewLight:
			this.Value = gameOptions.CrewLightMod;
			return;
		case StringNames.GameImpostorLight:
			this.Value = gameOptions.ImpostorLightMod;
			return;
		case StringNames.GameKillCooldown:
			this.Value = gameOptions.KillCooldown;
			return;
		case StringNames.GameKillDistance:
			break;
		case StringNames.GameCommonTasks:
			this.Value = (float)gameOptions.NumCommonTasks;
			return;
		case StringNames.GameLongTasks:
			this.Value = (float)gameOptions.NumLongTasks;
			return;
		case StringNames.GameShortTasks:
			this.Value = (float)gameOptions.NumShortTasks;
			return;
		default:
			if (title == StringNames.GameEmergencyCooldown)
			{
				this.Value = (float)gameOptions.EmergencyCooldown;
				return;
			}
			break;
		}
		Debug.Log("Ono, unrecognized setting: " + this.Title);
	}

	private void FixedUpdate()
	{
		if (this.oldValue != this.Value)
		{
			this.oldValue = this.Value;
			if (this.ZeroIsInfinity && Mathf.Abs(this.Value) < 0.0001f)
			{
				this.ValueText.Text = string.Format(this.FormatString, "∞");
				return;
			}
			this.ValueText.Text = string.Format(this.FormatString, this.Value);
		}
	}

	public void Increase()
	{
		this.Value = this.ValidRange.Clamp(this.Value + this.Increment);
		this.OnValueChanged(this);
	}

	public void Decrease()
	{
		this.Value = this.ValidRange.Clamp(this.Value - this.Increment);
		this.OnValueChanged(this);
	}

	public override float GetFloat()
	{
		return this.Value;
	}

	public override int GetInt()
	{
		return (int)this.Value;
	}
}