Skip to content

Commit 692cf28

Browse files
committed
Simple Inventory menu implemented
1 parent cb1446e commit 692cf28

10 files changed

Lines changed: 245 additions & 36 deletions

File tree

Classes/Notes/Note.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ public partial class Note : Resource
1313
private int _baseVal;
1414
private Action<BattleDirector, Note, Timing> NoteEffect; //TODO: Where/How to deal with timing.
1515

16+
public string Tooltip;
1617
public Texture2D Texture;
1718

18-
//public string Tooltip;
19-
2019
public Note(
2120
string name,
22-
PuppetTemplate owner = null,
21+
string tooltip,
2322
Texture2D texture = null,
23+
PuppetTemplate owner = null,
2424
int baseVal = 1,
2525
Action<BattleDirector, Note, Timing> noteEffect = null
2626
)
2727
{
2828
Name = name;
2929
Owner = owner;
30-
Texture = texture;
3130
NoteEffect =
3231
noteEffect
3332
?? (
@@ -37,6 +36,8 @@ public Note(
3736
}
3837
);
3938
_baseVal = baseVal;
39+
Texture = texture;
40+
Tooltip = tooltip;
4041
}
4142

4243
public void OnHit(BattleDirector BD, Timing timing)

Classes/Relics/RelicTemplate.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ public partial class RelicTemplate : Resource
77
public RelicEffect[] Effects;
88
public string Name;
99

10-
//public Texture2D Texture
11-
//public string Tooltip
12-
public RelicTemplate(string Name = "", RelicEffect[] EffectTags = null)
10+
public Texture2D Texture;
11+
public string Tooltip;
12+
13+
public RelicTemplate(
14+
string name = "",
15+
string tooltip = "",
16+
Texture2D texture = null,
17+
RelicEffect[] EffectTags = null
18+
)
1319
{
1420
Effects = EffectTags;
15-
this.Name = Name;
21+
Name = name;
22+
Tooltip = tooltip;
23+
Texture = texture;
1624
}
1725

1826
public RelicTemplate Clone()

Globals/Scribe.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public partial class Scribe : Node
1212
{
1313
new Note(
1414
"EnemyBase",
15-
null,
15+
"Basic enemy note, deals damage to player.",
16+
GD.Load<Texture2D>("res://scenes/BattleDirector/assets/Character1.png"),
1617
null,
1718
1,
1819
(director, note, timing) =>
@@ -22,8 +23,9 @@ public partial class Scribe : Node
2223
),
2324
new Note(
2425
"PlayerBase",
25-
null,
26+
"Basic player note, deals damage to enemy",
2627
GD.Load<Texture2D>("res://Classes/Notes/assets/single_note.png"),
28+
null,
2729
1,
2830
(director, note, timing) =>
2931
{
@@ -32,8 +34,9 @@ public partial class Scribe : Node
3234
),
3335
new Note(
3436
"PlayerDouble",
37+
"Basic player note, deals damage to enemy",
38+
GD.Load<Texture2D>("res://Classes/Notes/assets/single_note.png"),
3539
null,
36-
GD.Load<Texture2D>("res://Classes/Notes/assets/double_note.png"),
3740
1,
3841
(director, note, timing) =>
3942
{
@@ -48,11 +51,13 @@ public partial class Scribe : Node
4851
{
4952
new RelicTemplate(
5053
"Breakfast", //Reference ha ha, Item to give when relic pool is empty.
54+
"Breakfast, currently does nothing :).", //TODO: Description can include the relics values?
55+
GD.Load<Texture2D>("res://scenes/BattleDirector/assets/Character1.png"),
5156
new RelicEffect[]
5257
{
5358
new RelicEffect(
5459
BattleEffectTrigger.NotePlaced,
55-
1,
60+
0,
5661
(director, val) =>
5762
{
5863
director.Player.Heal(val);
@@ -62,25 +67,13 @@ public partial class Scribe : Node
6267
),
6368
new RelicTemplate(
6469
"Good Vibes",
70+
"Good vibes, heals the player whenever they place a note.", //TODO: Description can include the relics values?
71+
GD.Load<Texture2D>("res://scenes/BattleDirector/assets/Character1.png"),
6572
new RelicEffect[]
6673
{
6774
new RelicEffect(
6875
BattleEffectTrigger.NotePlaced,
69-
5,
70-
(director, val) =>
71-
{
72-
director.Player.Heal(val);
73-
}
74-
),
75-
}
76-
),
77-
new RelicTemplate(
78-
"Dummy Item",
79-
new RelicEffect[]
80-
{
81-
new RelicEffect(
82-
BattleEffectTrigger.NotePlaced,
83-
100,
76+
1,
8477
(director, val) =>
8578
{
8679
director.Player.Heal(val);

project.godot

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Pause={
6363
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
6464
]
6565
}
66+
Inventory={
67+
"deadzone": 0.5,
68+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null)
69+
]
70+
}
6671

6772
[rendering]
6873

scenes/BattleDirector/scripts/BattleDirector.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ public override void _UnhandledInput(InputEvent @event)
134134
GetNode<CanvasLayer>("UILayer").AddChild(pauseMenu.Instantiate());
135135
GetTree().Paused = true;
136136
}
137+
if (@event.IsActionPressed("Inventory"))
138+
{
139+
var invenMenu = GD.Load<PackedScene>("res://scenes/UI/inventory.tscn")
140+
.Instantiate<Inventory>();
141+
GetNode<CanvasLayer>("UILayer").AddChild(invenMenu);
142+
invenMenu.Display(Player.Stats);
143+
GetTree().Paused = true;
144+
}
137145
}
138146

139147
private void OnNotePressed(ArrowType type)
@@ -224,7 +232,6 @@ private void EventizeRelics()
224232
{
225233
foreach (var relic in Player.Stats.CurRelics)
226234
{
227-
GetNode<Label>("TempRelicList").Text += "\n" + relic.Name;
228235
foreach (var effect in relic.Effects)
229236
{
230237
switch (effect.GetTrigger()) //TODO: Look into a way to get eventhandler from string

scenes/BattleDirector/test_battle_scene.tscn

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,3 @@ offset_left = 16.0
5151
offset_top = 164.0
5252
offset_right = 16.0
5353
offset_bottom = 164.0
54-
55-
[node name="TempRelicList" type="Label" parent="."]
56-
offset_left = 564.0
57-
offset_top = 165.0
58-
offset_right = 613.0
59-
offset_bottom = 188.0
60-
theme_override_font_sizes/font_size = 10
61-
text = "Relics:"

scenes/UI/display_button.tscn

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://cymo26khpw4m1"]
2+
3+
[ext_resource type="Script" path="res://scenes/UI/scripts/DisplayButton.cs" id="1_7lpm6"]
4+
5+
[node name="DisplayButton" type="Button"]
6+
anchors_preset = 15
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
grow_horizontal = 2
10+
grow_vertical = 2
11+
script = ExtResource("1_7lpm6")

scenes/UI/inventory.tscn

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://be6fb2sr5i515"]
2+
3+
[ext_resource type="Script" path="res://scenes/UI/scripts/Inventory.cs" id="1_8rcwd"]
4+
5+
[node name="Inventory" type="Control" node_paths=PackedStringArray("Relics", "Notes", "Description", "Tabs")]
6+
process_mode = 2
7+
layout_mode = 3
8+
anchors_preset = 15
9+
anchor_right = 1.0
10+
anchor_bottom = 1.0
11+
grow_horizontal = 2
12+
grow_vertical = 2
13+
script = ExtResource("1_8rcwd")
14+
Relics = NodePath("InvenVBox/Tabs/Relics/RelicBox/RelicGrid")
15+
Notes = NodePath("InvenVBox/Tabs/Notes/NotesBox/NotesGrid")
16+
Description = NodePath("InvenVBox/DescBox/Description")
17+
Tabs = NodePath("InvenVBox/Tabs")
18+
19+
[node name="BG" type="ColorRect" parent="."]
20+
layout_mode = 1
21+
anchors_preset = 15
22+
anchor_right = 1.0
23+
anchor_bottom = 1.0
24+
grow_horizontal = 2
25+
grow_vertical = 2
26+
color = Color(0, 0, 0.2, 0.533333)
27+
28+
[node name="InvenVBox" type="VBoxContainer" parent="."]
29+
layout_mode = 1
30+
anchors_preset = 15
31+
anchor_right = 1.0
32+
anchor_bottom = 1.0
33+
grow_horizontal = 2
34+
grow_vertical = 2
35+
36+
[node name="Tabs" type="TabContainer" parent="InvenVBox"]
37+
layout_mode = 2
38+
size_flags_vertical = 3
39+
current_tab = 0
40+
clip_tabs = false
41+
42+
[node name="Notes" type="MarginContainer" parent="InvenVBox/Tabs"]
43+
layout_mode = 2
44+
theme_override_constants/margin_left = 30
45+
theme_override_constants/margin_top = 30
46+
theme_override_constants/margin_right = 30
47+
theme_override_constants/margin_bottom = 30
48+
metadata/_tab_index = 0
49+
50+
[node name="NotesBox" type="ScrollContainer" parent="InvenVBox/Tabs/Notes"]
51+
layout_mode = 2
52+
follow_focus = true
53+
54+
[node name="NotesGrid" type="GridContainer" parent="InvenVBox/Tabs/Notes/NotesBox"]
55+
layout_mode = 2
56+
size_flags_vertical = 4
57+
columns = 5
58+
59+
[node name="Relics" type="MarginContainer" parent="InvenVBox/Tabs"]
60+
visible = false
61+
layout_mode = 2
62+
theme_override_constants/margin_left = 30
63+
theme_override_constants/margin_top = 30
64+
theme_override_constants/margin_right = 30
65+
theme_override_constants/margin_bottom = 30
66+
metadata/_tab_index = 1
67+
68+
[node name="RelicBox" type="ScrollContainer" parent="InvenVBox/Tabs/Relics"]
69+
layout_mode = 2
70+
follow_focus = true
71+
72+
[node name="RelicGrid" type="GridContainer" parent="InvenVBox/Tabs/Relics/RelicBox"]
73+
layout_mode = 2
74+
size_flags_vertical = 4
75+
columns = 5
76+
77+
[node name="DescBox" type="MarginContainer" parent="InvenVBox"]
78+
layout_mode = 2
79+
size_flags_vertical = 3
80+
size_flags_stretch_ratio = 0.4
81+
theme_override_constants/margin_left = 10
82+
theme_override_constants/margin_top = 10
83+
theme_override_constants/margin_right = 10
84+
theme_override_constants/margin_bottom = 10
85+
86+
[node name="ColorRect" type="ColorRect" parent="InvenVBox/DescBox"]
87+
layout_mode = 2
88+
color = Color(0, 0, 0, 0.552941)
89+
90+
[node name="Description" type="Label" parent="InvenVBox/DescBox"]
91+
layout_mode = 2
92+
size_flags_vertical = 1
93+
autowrap_mode = 2
94+
clip_text = true
95+
text_overrun_behavior = 1

scenes/UI/scripts/DisplayButton.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using Godot;
3+
4+
public partial class DisplayButton : Button
5+
{
6+
[Export]
7+
public Texture2D Texture;
8+
9+
[Export]
10+
public string Description;
11+
12+
[Export]
13+
public string DisplayName;
14+
15+
public void Display(Texture2D texture, string description, string name)
16+
{
17+
Texture = texture;
18+
Description = description;
19+
DisplayName = name;
20+
Icon = Texture;
21+
}
22+
}

scenes/UI/scripts/Inventory.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using Godot;
3+
4+
public partial class Inventory : Control
5+
{
6+
[Export]
7+
private GridContainer Relics;
8+
9+
[Export]
10+
private GridContainer Notes;
11+
12+
[Export]
13+
private Label Description;
14+
15+
[Export]
16+
private TabContainer Tabs;
17+
18+
public void Display(PlayerStats playerStats)
19+
{
20+
foreach (RelicTemplate relic in playerStats.CurRelics)
21+
{
22+
var newButton = GD.Load<PackedScene>("res://scenes/UI/display_button.tscn")
23+
.Instantiate<DisplayButton>();
24+
newButton.Display(relic.Texture, relic.Tooltip, relic.Name);
25+
newButton.Pressed += () =>
26+
{
27+
DoDescription(newButton);
28+
};
29+
Relics.AddChild(newButton);
30+
}
31+
foreach (Note note in playerStats.CurNotes)
32+
{
33+
var newButton = GD.Load<PackedScene>("res://scenes/UI/display_button.tscn")
34+
.Instantiate<DisplayButton>();
35+
newButton.Display(note.Texture, note.Tooltip, note.Name);
36+
newButton.Pressed += () =>
37+
{
38+
DoDescription(newButton);
39+
};
40+
Notes.AddChild(newButton);
41+
}
42+
43+
Tabs.TabChanged += ClearDescription;
44+
}
45+
46+
public override void _Ready()
47+
{
48+
Tabs.GetTabBar().GrabFocus();
49+
}
50+
51+
public override void _Input(InputEvent @event)
52+
{
53+
if (@event.IsActionPressed("Pause") || @event.IsActionPressed("Inventory"))
54+
{
55+
Resume();
56+
GetViewport().SetInputAsHandled();
57+
}
58+
}
59+
60+
private void Resume()
61+
{
62+
GetTree().Paused = false;
63+
QueueFree(); //Hacky and shortsighted (probably?)
64+
}
65+
66+
private void DoDescription(DisplayButton dispButton)
67+
{
68+
Description.Text = $"{dispButton.DisplayName}: {dispButton.Description}";
69+
}
70+
71+
private void ClearDescription(long newTab)
72+
{
73+
Description.Text = "";
74+
}
75+
}

0 commit comments

Comments
 (0)