Skip to content

Commit 294936f

Browse files
cornerloanLifeHckr
authored andcommitted
Event room added
currently not accessible in the game, but can be tested through running the scene
1 parent 1a9670a commit 294936f

9 files changed

Lines changed: 290 additions & 0 deletions

File tree

Classes/Events/Assets/TEMP.png

26 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://cy15tmixv0b6"
6+
path="res://.godot/imported/TEMP.png-782c35a0eebabf4d103f16dcac6860f5.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://Classes/Events/Assets/TEMP.png"
14+
dest_files=["res://.godot/imported/TEMP.png-782c35a0eebabf4d103f16dcac6860f5.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1

Classes/Events/EventDatabase.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Godot;
4+
5+
/// <summary>
6+
/// Holds all game events and their associated logic.
7+
/// </summary>
8+
public partial class EventDatabase : Node
9+
{
10+
public static readonly EventTemplate[] EventDictionary = new[]
11+
{
12+
new EventTemplate(
13+
1,
14+
"A wild creature appears in the forest.",
15+
new string[] { "Fight", "Run", "Mysterious third option" },
16+
new EventAction[]
17+
{
18+
() =>
19+
{
20+
GD.Print("You chose to fight");
21+
},
22+
() =>
23+
{
24+
GD.Print("You chose to run");
25+
},
26+
() =>
27+
{
28+
GD.Print("You chose to Mysterious third option");
29+
},
30+
},
31+
GD.Load<Texture2D>("res://Classes/Events/Assets/TEMP.png")
32+
),
33+
};
34+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://c7pukvtaeda8h

Classes/Events/EventTemplate.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using FunkEngine;
3+
using Godot;
4+
5+
public delegate void EventAction();
6+
7+
public partial class EventTemplate : Resource
8+
{
9+
public int Id;
10+
public string EventDescription;
11+
public string[] ButtonDescriptions;
12+
public Texture2D Texture;
13+
14+
// Note: Actions are NOT exported since delegates cannot be serialized
15+
public EventAction[] OptionActions;
16+
17+
public EventTemplate() { }
18+
19+
public EventTemplate(
20+
int id,
21+
string eventDescription,
22+
string[] buttonDescriptions,
23+
EventAction[] optionActions,
24+
Texture2D texture
25+
)
26+
{
27+
Id = id;
28+
EventDescription = eventDescription;
29+
ButtonDescriptions = buttonDescriptions;
30+
OptionActions = optionActions;
31+
Texture = texture;
32+
}
33+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://4ro8fwi5f8uk

Scenes/EventScene/EventScene.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using FunkEngine;
3+
using Godot;
4+
5+
public partial class EventScene : Node
6+
{
7+
public static readonly string LoadPath = "res://Scenes/ChestScene/ChestScene.tscn";
8+
private PlayerPuppet _player;
9+
10+
[Export]
11+
public Marker2D PlayerMarker;
12+
13+
[Export]
14+
public Sprite2D EventSprite;
15+
16+
[Export]
17+
private Label _eventDescription;
18+
19+
[Export]
20+
private VBoxContainer _buttonContainer;
21+
22+
private Theme _buttonTheme; // Store the theme
23+
24+
public override void _Ready()
25+
{
26+
_player = GD.Load<PackedScene>(PlayerPuppet.LoadPath).Instantiate<PlayerPuppet>();
27+
PlayerMarker.AddChild(_player);
28+
29+
// Load the theme from the path
30+
_buttonTheme = GD.Load<Theme>("res://Scenes/UI/Assets/GeneralTheme.tres");
31+
32+
DisplayEvent(0);
33+
}
34+
35+
/// <summary>
36+
/// Displays the event with the given index.
37+
/// </summary>
38+
/// <param name="eventIndex">Index of the event in EventDatabase.</param>
39+
public void DisplayEvent(int eventIndex)
40+
{
41+
var eventTemplate = EventDatabase.EventDictionary[eventIndex];
42+
43+
_eventDescription.Text = eventTemplate.EventDescription;
44+
EventSprite.Texture = eventTemplate.Texture;
45+
46+
for (int i = 0; i < eventTemplate.ButtonDescriptions.Length; i++)
47+
{
48+
var button = new Button
49+
{
50+
Text = eventTemplate.ButtonDescriptions[i],
51+
Theme = _buttonTheme,
52+
};
53+
54+
button.SizeFlagsVertical = Control.SizeFlags.Expand | Control.SizeFlags.Fill;
55+
56+
int capturedIndex = i; // was given a warning to capture the index
57+
button.Pressed += () =>
58+
{
59+
GD.Print($"Selected option: {eventTemplate.ButtonDescriptions[capturedIndex]}");
60+
eventTemplate.OptionActions[capturedIndex]?.Invoke();
61+
StageProducer.LiveInstance.TransitionStage(Stages.Map);
62+
};
63+
64+
_buttonContainer.AddChild(button);
65+
}
66+
}
67+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://md1vhln8ji5h

Scenes/EventScene/EventScene.tscn

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
[gd_scene load_steps=7 format=3 uid="uid://u7oppwtmvmci"]
2+
3+
[ext_resource type="Script" uid="uid://md1vhln8ji5h" path="res://Scenes/EventScene/EventScene.cs" id="1_x82kl"]
4+
[ext_resource type="AudioStream" uid="uid://be5ial13ynf3o" path="res://Audio/Song1.ogg" id="2_vywvm"]
5+
[ext_resource type="Texture2D" uid="uid://qhwve7fik4do" path="res://SharedAssets/BackGround_Full.png" id="4_l56en"]
6+
[ext_resource type="Texture2D" uid="uid://8u3xvcma81d" path="res://Scenes/UI/Assets/UI_CrystalFrame.png" id="5_erk58"]
7+
[ext_resource type="Script" uid="uid://cp6t6haqyef7o" path="res://Scenes/AreaBasedBackground.cs" id="5_v3lan"]
8+
[ext_resource type="Texture2D" uid="uid://burj10os057fx" path="res://Scenes/UI/Assets/UI_CrystalFrameInset.png" id="6_4prsq"]
9+
10+
[node name="EventScene" type="Node2D" node_paths=PackedStringArray("PlayerMarker", "EventSprite", "_eventDescription", "_buttonContainer")]
11+
process_mode = 1
12+
script = ExtResource("1_x82kl")
13+
PlayerMarker = NodePath("PlayerMarker")
14+
EventSprite = NodePath("EventSprite")
15+
_eventDescription = NodePath("Control/MarginContainer/PanelContainer/HBoxContainer/DescBox/DescMargin/Description")
16+
_buttonContainer = NodePath("Control/MarginContainer/PanelContainer/HBoxContainer/ButtonContainer/VBoxContainer")
17+
18+
[node name="Audio" type="AudioStreamPlayer" parent="."]
19+
unique_name_in_owner = true
20+
stream = ExtResource("2_vywvm")
21+
autoplay = true
22+
23+
[node name="PlayerMarker" type="Marker2D" parent="."]
24+
position = Vector2(158, 125)
25+
26+
[node name="EventSprite" type="Sprite2D" parent="."]
27+
position = Vector2(385, 125)
28+
29+
[node name="BackGround" type="TextureRect" parent="."]
30+
z_index = -1
31+
offset_right = 640.0
32+
offset_bottom = 178.0
33+
texture = ExtResource("4_l56en")
34+
script = ExtResource("5_v3lan")
35+
36+
[node name="Control" type="Control" parent="."]
37+
layout_mode = 3
38+
anchors_preset = 0
39+
offset_right = 650.0
40+
offset_bottom = 40.0
41+
42+
[node name="MarginContainer" type="MarginContainer" parent="Control"]
43+
layout_mode = 1
44+
anchors_preset = 15
45+
anchor_right = 1.0
46+
anchor_bottom = 1.0
47+
offset_left = -50.0
48+
offset_top = 160.0
49+
offset_right = 40.0
50+
offset_bottom = 340.0
51+
grow_horizontal = 2
52+
grow_vertical = 2
53+
size_flags_horizontal = 3
54+
size_flags_vertical = 3
55+
theme_override_constants/margin_left = 50
56+
theme_override_constants/margin_top = 20
57+
theme_override_constants/margin_right = 50
58+
theme_override_constants/margin_bottom = 20
59+
60+
[node name="PanelContainer" type="PanelContainer" parent="Control/MarginContainer"]
61+
layout_mode = 2
62+
63+
[node name="SelectionBG" type="NinePatchRect" parent="Control/MarginContainer/PanelContainer"]
64+
self_modulate = Color(1, 1, 1, 0.75)
65+
custom_minimum_size = Vector2(540, 105)
66+
layout_mode = 2
67+
size_flags_horizontal = 3
68+
size_flags_vertical = 3
69+
texture = ExtResource("5_erk58")
70+
patch_margin_left = 30
71+
patch_margin_top = 10
72+
patch_margin_right = 20
73+
patch_margin_bottom = 27
74+
75+
[node name="HBoxContainer" type="HBoxContainer" parent="Control/MarginContainer/PanelContainer"]
76+
layout_mode = 2
77+
78+
[node name="DescBox" type="MarginContainer" parent="Control/MarginContainer/PanelContainer/HBoxContainer"]
79+
layout_mode = 2
80+
size_flags_horizontal = 3
81+
size_flags_vertical = 3
82+
theme_override_constants/margin_top = 7
83+
theme_override_constants/margin_right = -10
84+
theme_override_constants/margin_bottom = 7
85+
86+
[node name="DescBackground" type="NinePatchRect" parent="Control/MarginContainer/PanelContainer/HBoxContainer/DescBox"]
87+
layout_mode = 2
88+
texture = ExtResource("6_4prsq")
89+
patch_margin_left = 7
90+
patch_margin_top = 7
91+
patch_margin_right = 7
92+
patch_margin_bottom = 7
93+
94+
[node name="DescMargin" type="MarginContainer" parent="Control/MarginContainer/PanelContainer/HBoxContainer/DescBox"]
95+
layout_mode = 2
96+
theme_override_constants/margin_left = 0
97+
theme_override_constants/margin_top = 0
98+
theme_override_constants/margin_right = 0
99+
theme_override_constants/margin_bottom = 0
100+
101+
[node name="Description" type="Label" parent="Control/MarginContainer/PanelContainer/HBoxContainer/DescBox/DescMargin"]
102+
layout_mode = 2
103+
size_flags_vertical = 1
104+
text = ":HeathCliff:"
105+
horizontal_alignment = 1
106+
vertical_alignment = 1
107+
autowrap_mode = 2
108+
clip_text = true
109+
text_overrun_behavior = 1
110+
111+
[node name="ButtonContainer" type="MarginContainer" parent="Control/MarginContainer/PanelContainer/HBoxContainer"]
112+
layout_mode = 2
113+
theme_override_constants/margin_left = 10
114+
theme_override_constants/margin_top = 7
115+
theme_override_constants/margin_right = 10
116+
theme_override_constants/margin_bottom = 7
117+
118+
[node name="VBoxContainer" type="VBoxContainer" parent="Control/MarginContainer/PanelContainer/HBoxContainer/ButtonContainer"]
119+
layout_mode = 2

0 commit comments

Comments
 (0)