-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHUD.cs
84 lines (69 loc) · 2.66 KB
/
HUD.cs
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
using System;
using System.Globalization;
using Godot;
namespace PictureTiles
{
public class HUD : CanvasLayer
{
private int _moveCounter;
private Label _counterNode;
private Label _shuffleLabel;
private HSlider _shuffleSlider;
private bool _timerStarted;
public override void _Ready()
{
// Connect signals
AutoLoadGlobals.Instance.Connect("TileClicked", this, nameof(UpdateMoveCounter));
GetNode<Button>("Start").Connect("pressed", this, nameof(OnPressedStart));
GetNode<Button>("Main").Connect("pressed", this, nameof(OnPressedMain));
GetNode<Godot.Timer>("HideSolved").Connect("timeout", this, nameof(OnHideSolvedTimeout));
_shuffleSlider = GetNode<HSlider>("SliderContainer/ShuffleSlider");
_shuffleSlider.MinValue = AutoLoadGlobals.InitialShuffles;
_shuffleSlider.Connect("value_changed", this, nameof(OnShuffleSliderValueChanged));
GetNode<CenterContainer>("SolvedContainer").Visible = false;
_counterNode = GetNode<Label>("VBoxContainer/HBoxContainer/Moves");
_moveCounter = 0;
_shuffleLabel = GetNode<Label>("ShuffleMoves/Shuffles");
_shuffleLabel.Text = AutoLoadGlobals.InitialShuffles.ToString();
}
public override void _PhysicsProcess(float delta)
{
// _timerStarted ensures StartTimer is only called once
if (GetNode<CenterContainer>("SolvedContainer").Visible && !_timerStarted)
{
_timerStarted = true;
StartTimer();
}
}
private void StartTimer()
{
GetNode<Godot.Timer>("HideSolved").Start();
}
private void UpdateMoveCounter()
{
_moveCounter++;
_counterNode.Text = _moveCounter.ToString();
}
private void OnPressedStart()
{
AutoLoadGlobals.Solved = false;
_moveCounter = 0;
_counterNode.Text = _moveCounter.ToString();
_timerStarted = false;
AutoLoadGlobals.Instance.EmitSignal("ShuffleTiles");
}
private void OnPressedMain()
{
GetTree().ChangeScene(AutoLoadGlobals.TitleScene);
}
private void OnShuffleSliderValueChanged(float value)
{
_shuffleLabel.Text = value.ToString(CultureInfo.InvariantCulture);
AutoLoadGlobals.InitialShuffles = (int) value;
}
private void OnHideSolvedTimeout()
{
GetNode<CenterContainer>("SolvedContainer").Visible = false;
}
}
}