Skip to content

Commit 1f1951b

Browse files
committed
Heal Button functionality
Shops now have heal button. Clicking it will restore 1/4 max hp at the cost of 30 money. This will disable the button for the reminder of time spent in shop. If player is at max hp or does not have enough money upon entering shop, button will be disabled automatically. Added display for the player's current health out of max health, with a placeholder heart sprite.
1 parent 11411cb commit 1f1951b

7 files changed

Lines changed: 126 additions & 7 deletions

File tree

Globals/Translations/Translations.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SHOP_REMOVAL,Remove A Note,移除音符
3434
SHOP_CONFIRM,Confirm Purchase,购买已确认
3535
SHOP_CANCEL,Cancel,取消操作
3636
REMOVAL_COST,Removal Fee,删除费用
37+
SHOP_HEAL, Heal, 愈合
3738
BATTLE_ROOM_BEGIN_BUTTON,Begin Battle [Enter],开始战斗 [Enter]
3839
BATTLE_ROOM_PERFECT,Perfect,Perfect
3940
BATTLE_ROOM_GOOD,Good,良好

Scenes/BattleDirector/Scripts/BattleDirector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public override void _UnhandledInput(InputEvent @event)
200200
{
201201
if (@event is InputEventKey eventKey && eventKey.Pressed && !eventKey.Echo)
202202
{
203-
return;
203+
//return;
204204
if (eventKey.Keycode == Key.Key0)
205205
{
206206
DebugKillEnemy();

Scenes/ShopScene/Scripts/ShopScene.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ public partial class ShopScene : Control
1111
[Export]
1212
private Label _moneyLabel;
1313

14+
[Export]
15+
private Label _currentHealthLabel;
16+
1417
[Export]
1518
private Button _exitButton;
1619

1720
[Export]
1821
private Button _removalButton;
1922

23+
[Export]
24+
private Button _healButton;
25+
2026
[Export]
2127
private GridContainer _noteGrid;
2228

@@ -66,6 +72,7 @@ public override void _Ready()
6672
_removalButton.Pressed += OpenRemovalPane;
6773
_removalAcceptButton.Pressed += RemoveNote;
6874
_cancelRemoveButton.Pressed += CloseRemovalPane;
75+
_healButton.Pressed += TryHeal;
6976
}
7077

7178
public override void _EnterTree()
@@ -76,8 +83,10 @@ public override void _EnterTree()
7683
private void Initialize()
7784
{
7885
UpdateMoneyLabel();
86+
UpdateCurrentHealthLabel();
7987
GenerateShopItems();
8088
PopulatePossessedNotes();
89+
HealButtonStatus();
8190
}
8291

8392
public override void _Input(InputEvent @event)
@@ -106,6 +115,12 @@ private void UpdateMoneyLabel()
106115
_moneyLabel.Text = StageProducer.PlayerStats.Money.ToString();
107116
}
108117

118+
private void UpdateCurrentHealthLabel()
119+
{
120+
_currentHealthLabel.Text =
121+
$"{StageProducer.PlayerStats.CurrentHealth}/{StageProducer.PlayerStats.MaxHealth}";
122+
}
123+
109124
private const int RelicOptions = 3;
110125
private const int NoteOptions = 5;
111126

@@ -322,4 +337,44 @@ private void RemoveNote()
322337
_selectedRemoveButton.QueueFree();
323338
CloseRemovalPane();
324339
}
340+
341+
private bool _hasHealed = false;
342+
private const int HealCost = 30;
343+
private int _healAmount = (StageProducer.PlayerStats.MaxHealth / 4);
344+
345+
private void HealButtonStatus()
346+
{
347+
if (
348+
StageProducer.PlayerStats.Money <= HealCost
349+
|| StageProducer.PlayerStats.CurrentHealth == StageProducer.PlayerStats.MaxHealth
350+
|| _hasHealed
351+
)
352+
{
353+
_healButton.Disabled = true;
354+
}
355+
}
356+
357+
private void TryHeal()
358+
{
359+
if (_hasHealed)
360+
{
361+
return;
362+
}
363+
HealPlayer();
364+
}
365+
366+
private void HealPlayer()
367+
{
368+
StageProducer.PlayerStats.CurrentHealth += _healAmount;
369+
if (StageProducer.PlayerStats.CurrentHealth > StageProducer.PlayerStats.MaxHealth)
370+
{
371+
StageProducer.PlayerStats.CurrentHealth = StageProducer.PlayerStats.MaxHealth;
372+
}
373+
374+
StageProducer.PlayerStats.Money -= 30;
375+
UpdateCurrentHealthLabel();
376+
UpdateMoneyLabel();
377+
_hasHealed = true;
378+
HealButtonStatus();
379+
}
325380
}

Scenes/ShopScene/ShopUI.tscn

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://bk0js6ji42xrt"]
1+
[gd_scene load_steps=9 format=3 uid="uid://bk0js6ji42xrt"]
22

33
[ext_resource type="Texture2D" uid="uid://djd6iw2g84bba" path="res://Scenes/UI/Assets/UI_CenterFrame.png" id="1_67his"]
44
[ext_resource type="Script" uid="uid://dg0xaieus84ns" path="res://Scenes/ShopScene/Scripts/ShopScene.cs" id="1_bmt43"]
@@ -7,8 +7,9 @@
77
[ext_resource type="Theme" uid="uid://d37e3tpsbxwak" path="res://Scenes/UI/Assets/GeneralTheme.tres" id="4_3vktw"]
88
[ext_resource type="Script" uid="uid://cahjluc6v7ked" path="res://Scenes/UI/TitleScreen/Scripts/SceneChange.cs" id="5_w0f8r"]
99
[ext_resource type="Texture2D" uid="uid://dyt1cvag13aik" path="res://SharedAssets/Money.png" id="6_tf865"]
10+
[ext_resource type="Texture2D" uid="uid://dtaf4wcsur721" path="res://SharedAssets/Heart.png" id="8_r34tc"]
1011

11-
[node name="ShopUI" type="Control" node_paths=PackedStringArray("_moneyLabel", "_exitButton", "_removalButton", "_noteGrid", "_relicGrid", "_confirmationPopup", "_confirmationButton", "_denyButton", "_descriptionLabel", "_removalPanel", "_possessionGrid", "_removalAcceptButton", "_cancelRemoveButton", "_removalCostLabel")]
12+
[node name="ShopUI" type="Control" node_paths=PackedStringArray("_moneyLabel", "_currentHealthLabel", "_exitButton", "_removalButton", "_healButton", "_noteGrid", "_relicGrid", "_confirmationPopup", "_confirmationButton", "_denyButton", "_descriptionLabel", "_removalPanel", "_possessionGrid", "_removalAcceptButton", "_cancelRemoveButton", "_removalCostLabel")]
1213
z_index = 2
1314
layout_mode = 3
1415
anchors_preset = 15
@@ -18,8 +19,10 @@ grow_horizontal = 2
1819
grow_vertical = 2
1920
script = ExtResource("1_bmt43")
2021
_moneyLabel = NodePath("MoneyContainer/MoneyFrame/MarginContainer/HBoxContainer/MoneyLabel")
22+
_currentHealthLabel = NodePath("HealthContainer/HealthFrame/MarginContainer/HBoxContainer/CurrentHealthLabel")
2123
_exitButton = NodePath("BottomPanel/DescBox/HBoxContainer/OptionsBG/OptionsMargin/OptionsBG/MarginContainer/VBoxContainer/Continue")
2224
_removalButton = NodePath("BottomPanel/DescBox/HBoxContainer/OptionsBG/OptionsMargin/OptionsBG/MarginContainer/VBoxContainer/Removal")
25+
_healButton = NodePath("BottomPanel/DescBox/HBoxContainer/OptionsBG/OptionsMargin/OptionsBG/MarginContainer/VBoxContainer/Heal")
2326
_noteGrid = NodePath("TopPanel/MarginContainer/VBoxContainer/NoteSelection/MarginContainer/NotesBox/CenterContainer/NotesGrid")
2427
_relicGrid = NodePath("TopPanel/MarginContainer/VBoxContainer/RelicSelection/MarginContainer/RelicsBox/CenterContainer/RelicsGrid")
2528
_confirmationPopup = NodePath("ConfirmPurchase")
@@ -265,6 +268,13 @@ size_flags_vertical = 4
265268
theme = ExtResource("4_3vktw")
266269
text = "SHOP_REMOVAL"
267270

271+
[node name="Heal" type="Button" parent="BottomPanel/DescBox/HBoxContainer/OptionsBG/OptionsMargin/OptionsBG/MarginContainer/VBoxContainer"]
272+
layout_mode = 2
273+
size_flags_horizontal = 4
274+
size_flags_vertical = 4
275+
theme = ExtResource("4_3vktw")
276+
text = "SHOP_HEAL"
277+
268278
[node name="Continue" type="Button" parent="BottomPanel/DescBox/HBoxContainer/OptionsBG/OptionsMargin/OptionsBG/MarginContainer/VBoxContainer"]
269279
layout_mode = 2
270280
size_flags_horizontal = 4
@@ -327,6 +337,59 @@ horizontal_alignment = 2
327337
vertical_alignment = 1
328338
clip_text = true
329339

340+
[node name="HealthContainer" type="MarginContainer" parent="."]
341+
layout_mode = 1
342+
anchors_preset = 1
343+
anchor_left = 1.0
344+
anchor_right = 1.0
345+
offset_left = -125.0
346+
offset_top = 24.0
347+
offset_bottom = 53.0
348+
grow_horizontal = 0
349+
theme_override_constants/margin_left = -1
350+
theme_override_constants/margin_top = 5
351+
theme_override_constants/margin_right = 5
352+
theme_override_constants/margin_bottom = 0
353+
354+
[node name="HealthFrame" type="NinePatchRect" parent="HealthContainer"]
355+
layout_mode = 2
356+
texture = ExtResource("2_bmt43")
357+
patch_margin_left = 7
358+
patch_margin_top = 7
359+
patch_margin_right = 7
360+
patch_margin_bottom = 7
361+
362+
[node name="MarginContainer" type="MarginContainer" parent="HealthContainer/HealthFrame"]
363+
layout_mode = 1
364+
anchors_preset = 15
365+
anchor_right = 1.0
366+
anchor_bottom = 1.0
367+
grow_horizontal = 2
368+
grow_vertical = 2
369+
theme_override_constants/margin_right = 8
370+
371+
[node name="HBoxContainer" type="HBoxContainer" parent="HealthContainer/HealthFrame/MarginContainer"]
372+
layout_mode = 2
373+
374+
[node name="MarginContainer" type="MarginContainer" parent="HealthContainer/HealthFrame/MarginContainer/HBoxContainer"]
375+
layout_mode = 2
376+
theme_override_constants/margin_left = 6
377+
378+
[node name="TextureRect" type="TextureRect" parent="HealthContainer/HealthFrame/MarginContainer/HBoxContainer/MarginContainer"]
379+
layout_mode = 2
380+
size_flags_vertical = 4
381+
texture = ExtResource("8_r34tc")
382+
383+
[node name="CurrentHealthLabel" type="Label" parent="HealthContainer/HealthFrame/MarginContainer/HBoxContainer"]
384+
custom_minimum_size = Vector2(91, 0)
385+
layout_mode = 2
386+
size_flags_horizontal = 10
387+
size_flags_vertical = 1
388+
text = "0"
389+
horizontal_alignment = 2
390+
vertical_alignment = 1
391+
clip_text = true
392+
330393
[node name="ConfirmPurchase" type="CenterContainer" parent="."]
331394
visible = false
332395
z_index = 3

SharedAssets/Heart.png

1.49 KB
Loading
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
importer="texture"
44
type="CompressedTexture2D"
5-
uid="uid://ox0iikoj3ooe"
6-
path="res://.godot/imported/riff_rabbit.png-2c147e4df2c202fb7e5a3e11aacf00f1.ctex"
5+
uid="uid://dtaf4wcsur721"
6+
path="res://.godot/imported/Heart.png-7dfefac643a1f449fa6e4073fe6379c7.ctex"
77
metadata={
88
"vram_texture": false
99
}
1010

1111
[deps]
1212

13-
source_file="res://SharedAssets/riff_rabbit.png"
14-
dest_files=["res://.godot/imported/riff_rabbit.png-2c147e4df2c202fb7e5a3e11aacf00f1.ctex"]
13+
source_file="res://SharedAssets/Heart.png"
14+
dest_files=["res://.godot/imported/Heart.png-7dfefac643a1f449fa6e4073fe6379c7.ctex"]
1515

1616
[params]
1717

SharedAssets/riff_rabbit.png

-1.57 KB
Binary file not shown.

0 commit comments

Comments
 (0)