Skip to content

Commit 07aeca2

Browse files
authored
Merge pull request #80 from Project-Funk-Engine/WinLoseFeedback
Win lose feedback
2 parents f4c4e15 + 6bd4acc commit 07aeca2

File tree

7 files changed

+165
-11
lines changed

7 files changed

+165
-11
lines changed

Globals/StageProducer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public partial class StageProducer : Node
1010
public static RandomNumberGenerator GlobalRng = new RandomNumberGenerator();
1111
private ulong _seed;
1212
private ulong _lastRngState;
13-
private bool _isInitialized = false;
13+
public static bool IsInitialized;
1414

1515
private Stages _curStage = Stages.Title; //TODO: State Machine kinda deal?
1616
private Node _curScene;
@@ -34,7 +34,7 @@ public void StartGame()
3434
PlayerStats = new PlayerStats();
3535

3636
CurRoom = Map.GetRooms()[0];
37-
_isInitialized = true;
37+
IsInitialized = true;
3838
}
3939

4040
public static void ChangeCurRoom(MapGrid.Room room)
@@ -53,7 +53,7 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
5353
switch (nextStage)
5454
{
5555
case Stages.Title:
56-
_isInitialized = false;
56+
IsInitialized = false;
5757
GetTree().ChangeSceneToFile("res://scenes/SceneTransitions/TitleScreen.tscn");
5858
break;
5959
case Stages.Battle:
@@ -73,7 +73,7 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
7373
break;
7474
case Stages.Map:
7575
GetTree().ChangeSceneToFile("res://scenes/Maps/cartographer.tscn");
76-
if (!_isInitialized)
76+
if (!IsInitialized)
7777
{
7878
StartGame();
7979
}

scenes/BattleDirector/scripts/BattleDirector.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ private void CheckBattleStatus(PuppetTemplate puppet)
200200
{
201201
if (puppet == Player)
202202
{
203-
GD.Print("Player is Dead");
204-
Audio.StreamPaused = true;
205-
GetNode<StageProducer>("/root/StageProducer").TransitionStage(Stages.Title);
203+
LostBattle();
206204
return;
207205
}
208206

@@ -215,12 +213,22 @@ private void CheckBattleStatus(PuppetTemplate puppet)
215213
}
216214
}
217215

216+
private void LostBattle()
217+
{
218+
GD.Print("Player is Dead");
219+
Audio.StreamPaused = true;
220+
AddChild(GD.Load<PackedScene>("res://scenes/UI/EndScreen.tscn").Instantiate());
221+
GetTree().Paused = true;
222+
}
223+
218224
private void ShowRewardSelection(int amount)
219225
{
220226
string type = "Note";
221227
if (StageProducer.Config.RoomType == Stages.Boss)
222228
type = "Relic";
223-
RewardSelect.CreateSelection(this, Player.Stats, amount, type).Selected += EndBattle;
229+
var rewardSelect = RewardSelect.CreateSelection(this, Player.Stats, amount, type);
230+
rewardSelect.GetNode<Label>("%TopLabel").Text = "You win!";
231+
rewardSelect.Selected += EndBattle;
224232
}
225233

226234
#endregion

scenes/Maps/scripts/Cartographer.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public override void _Ready()
1717
{
1818
DrawMap();
1919
GetViewport().GuiFocusChanged += UpdateFocus;
20+
if (StageProducer.CurRoom.Type == Stages.Boss && StageProducer.CurRoom.Children.Length == 0)
21+
{
22+
WinStage();
23+
}
2024
}
2125

2226
public override void _Process(double delta)
@@ -123,4 +127,14 @@ private void EnterStage(int roomIdx, Button button)
123127
tween.Finished += () =>
124128
GetNode<StageProducer>("/root/StageProducer").TransitionFromRoom(roomIdx);
125129
}
130+
131+
private void WinStage()
132+
{
133+
GD.Print("Player is Dead");
134+
EndScreen es = GD.Load<PackedScene>("res://scenes/UI/EndScreen.tscn")
135+
.Instantiate<EndScreen>();
136+
AddChild(es);
137+
es.TopLabel.Text = "You Win!";
138+
GetTree().Paused = true;
139+
}
126140
}

scenes/UI/EndScreen.tscn

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://hjho5n2f8rkf"]
2+
3+
[ext_resource type="Script" path="res://scenes/UI/scripts/EndScreen.cs" id="1_37m3y"]
4+
5+
[node name="CanvasLayer" type="CanvasLayer" node_paths=PackedStringArray("buttons", "TopLabel")]
6+
process_mode = 2
7+
script = ExtResource("1_37m3y")
8+
buttons = [NodePath("MarginContainer2/VBoxContainer/MarginContainer/Restart"), NodePath("MarginContainer2/VBoxContainer/MarginContainer2/Title"), NodePath("MarginContainer2/VBoxContainer/MarginContainer3/Quit")]
9+
TopLabel = NodePath("MarginContainer2/VBoxContainer/TopLabel")
10+
11+
[node name="ColorRect" type="ColorRect" parent="."]
12+
offset_right = 640.0
13+
offset_bottom = 360.0
14+
color = Color(0.24, 0.24, 0.24, 0.854902)
15+
16+
[node name="MarginContainer2" type="MarginContainer" parent="."]
17+
anchors_preset = 15
18+
anchor_right = 1.0
19+
anchor_bottom = 1.0
20+
grow_horizontal = 2
21+
grow_vertical = 2
22+
theme_override_constants/margin_left = 200
23+
theme_override_constants/margin_top = 20
24+
theme_override_constants/margin_right = 200
25+
theme_override_constants/margin_bottom = 20
26+
27+
[node name="ColorRect" type="ColorRect" parent="MarginContainer2"]
28+
layout_mode = 2
29+
color = Color(0.172833, 0.172833, 0.172833, 0.945)
30+
31+
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer2"]
32+
layout_mode = 2
33+
34+
[node name="TopLabel" type="Label" parent="MarginContainer2/VBoxContainer"]
35+
unique_name_in_owner = true
36+
layout_mode = 2
37+
theme_override_font_sizes/font_size = 20
38+
text = "Game Over!"
39+
horizontal_alignment = 1
40+
41+
[node name="HSeparator" type="HSeparator" parent="MarginContainer2/VBoxContainer"]
42+
layout_mode = 2
43+
44+
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer2/VBoxContainer"]
45+
layout_mode = 2
46+
size_flags_vertical = 3
47+
theme_override_constants/margin_left = 20
48+
theme_override_constants/margin_top = 20
49+
theme_override_constants/margin_right = 20
50+
theme_override_constants/margin_bottom = 20
51+
52+
[node name="Restart" type="Button" parent="MarginContainer2/VBoxContainer/MarginContainer"]
53+
layout_mode = 2
54+
focus_neighbor_top = NodePath("../../MarginContainer3/Quit")
55+
focus_neighbor_bottom = NodePath("../../MarginContainer2/Title")
56+
text = "Restart"
57+
58+
[node name="MarginContainer2" type="MarginContainer" parent="MarginContainer2/VBoxContainer"]
59+
layout_mode = 2
60+
size_flags_vertical = 3
61+
theme_override_constants/margin_left = 20
62+
theme_override_constants/margin_top = 20
63+
theme_override_constants/margin_right = 20
64+
theme_override_constants/margin_bottom = 20
65+
66+
[node name="Title" type="Button" parent="MarginContainer2/VBoxContainer/MarginContainer2"]
67+
layout_mode = 2
68+
focus_neighbor_top = NodePath("../../MarginContainer/Restart")
69+
focus_neighbor_bottom = NodePath("../../MarginContainer3/Quit")
70+
text = "Quit To Title"
71+
72+
[node name="MarginContainer3" type="MarginContainer" parent="MarginContainer2/VBoxContainer"]
73+
layout_mode = 2
74+
size_flags_vertical = 3
75+
theme_override_constants/margin_left = 20
76+
theme_override_constants/margin_top = 20
77+
theme_override_constants/margin_right = 20
78+
theme_override_constants/margin_bottom = 20
79+
80+
[node name="Quit" type="Button" parent="MarginContainer2/VBoxContainer/MarginContainer3"]
81+
layout_mode = 2
82+
focus_neighbor_top = NodePath("../../MarginContainer2/Title")
83+
focus_neighbor_bottom = NodePath("../../MarginContainer/Restart")
84+
text = "Quit Game"

scenes/UI/RewardSelectionUI.tscn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ grow_vertical = 2
2424
size_flags_horizontal = 3
2525
size_flags_vertical = 3
2626
theme_override_constants/margin_left = 50
27-
theme_override_constants/margin_top = 50
27+
theme_override_constants/margin_top = 20
2828
theme_override_constants/margin_right = 50
2929
theme_override_constants/margin_bottom = 50
3030

@@ -34,6 +34,13 @@ layout_mode = 2
3434
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer"]
3535
layout_mode = 2
3636

37+
[node name="TopLabel" type="Label" parent="MarginContainer/PanelContainer/VBoxContainer"]
38+
unique_name_in_owner = true
39+
layout_mode = 2
40+
theme_override_font_sizes/font_size = 20
41+
text = "Rewards!"
42+
horizontal_alignment = 1
43+
3744
[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
3845
layout_mode = 2
3946
size_flags_vertical = 3

scenes/UI/scripts/EndScreen.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using FunkEngine;
3+
using Godot;
4+
5+
public partial class EndScreen : CanvasLayer
6+
{
7+
[Export]
8+
private Button[] buttons;
9+
10+
[Export] public Label TopLabel;
11+
12+
public override void _Ready()
13+
{
14+
buttons[0].Pressed += Restart;
15+
buttons[1].Pressed += QuitToMainMenu;
16+
buttons[2].Pressed += Quit;
17+
buttons[0].GrabFocus();
18+
}
19+
20+
private void Restart()
21+
{
22+
GetTree().Paused = false;
23+
StageProducer.IsInitialized = false;
24+
GetNode<StageProducer>("/root/StageProducer").TransitionStage(Stages.Map);
25+
}
26+
27+
private void Quit()
28+
{
29+
GetNode<StageProducer>("/root/StageProducer").TransitionStage(Stages.Quit);
30+
}
31+
32+
private void QuitToMainMenu()
33+
{
34+
GetTree().Paused = false;
35+
GetNode<StageProducer>("/root/StageProducer").TransitionStage(Stages.Title);
36+
}
37+
}

scenes/UI/scripts/RewardSelect.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public override void _Process(double delta)
4949

5050
private void GenerateRelicChoices(int amount = 1)
5151
{
52+
if (amount < 1)
53+
GD.PushError("Error: In RewardSelect: amount < 1");
5254
//should probably change this so that the amount of relics offered can be changed when BD calls it
5355
//i.e less options when killing trash mobs/basic/weak enemies
5456
_rChoices = Scribe.GetRandomRelics(_player.CurRelics, amount);
@@ -59,12 +61,14 @@ private void GenerateRelicChoices(int amount = 1)
5961
button.Display(relic.Texture, relic.Tooltip, relic.Name);
6062
button.Pressed += () => OnRelicSelected(relic);
6163
ButtonContainer.AddChild(button);
62-
button.GrabFocus();
6364
}
65+
ButtonContainer.GetChild<Button>(0).GrabFocus();
6466
}
6567

6668
private void GenerateNoteChoices(int amount = 1)
6769
{
70+
if (amount < 1)
71+
GD.PushError("Error: In RewardSelect: amount < 1");
6872
//should probably change this so that the amount of relics offered can be changed when BD calls it
6973
//i.e less options when killing trash mobs/basic/weak enemies
7074
_nChoices = Scribe.GetRandomRewardNotes(amount);
@@ -75,8 +79,8 @@ private void GenerateNoteChoices(int amount = 1)
7579
button.Display(note.Texture, note.Tooltip, note.Name);
7680
button.Pressed += () => OnNoteSelected(note);
7781
ButtonContainer.AddChild(button);
78-
button.GrabFocus();
7982
}
83+
ButtonContainer.GetChild<Button>(0).GrabFocus();
8084
}
8185

8286
public static RewardSelect CreateSelection(

0 commit comments

Comments
 (0)