Skip to content

Commit 08805df

Browse files
committed
feat: update UI labels for nodes, time, and moves; improve error handling
1 parent f1ab533 commit 08805df

File tree

5 files changed

+136
-9
lines changed

5 files changed

+136
-9
lines changed

src/main_scene/main_scene.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ void MainScene::_notification(int p_what) {
5454
algo_button->select(0);
5555
}
5656

57+
node_label = get_node<Label>("UI/NodeLabel");
58+
if (node_label) node_label->set_text("Nodes: 0");
59+
5760
time_label = get_node<Label>("UI/TimeLabel");
5861
if (time_label) time_label->set_text("Time: 0.0s");
5962

63+
move_label = get_node<Label>("UI/MoveLabel");
64+
if (move_label) move_label->set_text("Moves: 0");
65+
6066
floor = get_node<MeshInstance3D>("StaticBody3D/Floor");
6167
if (floor) {
6268
for (int i = floor->get_child_count() - 1; i >= 0; i--) {
@@ -173,11 +179,13 @@ void MainScene::_on_solve_button_pressed() {
173179

174180
if (solution.is_solved) {
175181
is_solved = true;
176-
UtilityFunctions::print("Moves: ", solution.moves.size());
177-
UtilityFunctions::print("Time taken: ", solution.duration.count(), " ms");
178-
UtilityFunctions::print("Nodes visited: ", solution.node);
182+
UtilityFunctions::print("Moves: ", String::num_int64(solution.moves.size()));
183+
UtilityFunctions::print("Time taken: ", String::num(solution.duration.count()), " ms");
184+
UtilityFunctions::print("Nodes visited: ", String::num_int64(solution.node));
179185

186+
node_label->set_text("Nodes: " + String::num_int64(solution.node));
180187
time_label->set_text("Time: " + String::num(solution.duration.count()) + " ms");
188+
move_label->set_text("Moves: " + String::num_int64(solution.moves.size()));
181189
this->current_solution = solution;
182190
this->current_move_index = 0;
183191
this->is_animating_solution = true;
@@ -574,7 +582,8 @@ bool MainScene::load_input(String path, vector<Piece>& pieces, Board& board) {
574582
}
575583

576584
if (pieces.size() != board.other_pieces_count + 1) {
577-
UtilityFunctions::printerr("Error: Pieces count mismatch. Expected: ", board.other_pieces_count + 1, ", Found: ", pieces.size());
585+
UtilityFunctions::printerr("Error: Pieces count mismatch. Expected: ", String::num_int64(board.other_pieces_count + 1),
586+
", Found: ", String::num_int64(pieces.size()));
578587
return false;
579588
}
580589

src/main_scene/main_scene.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <godot_cpp/classes/node3d.hpp>
44
#include <godot_cpp/classes/camera3d.hpp>
55
#include <godot_cpp/classes/input_event_mouse_button.hpp>
6+
#include <godot_cpp/classes/panel_container.hpp>
67
#include <godot_cpp/classes/button.hpp>
78
#include <godot_cpp/classes/option_button.hpp>
89
#include <godot_cpp/classes/label.hpp>
@@ -44,7 +45,9 @@ class MainScene : public Node3D {
4445
bool is_solved = false;
4546
AlgoType algo_type = BFS;
4647

48+
Label* node_label = nullptr;
4749
Label* time_label = nullptr;
50+
Label* move_label = nullptr;
4851

4952
Button* solve_button = nullptr;
5053
Button* reset_button = nullptr;
@@ -65,13 +68,17 @@ class MainScene : public Node3D {
6568
Solution current_solution;
6669
int current_move_index = -1;
6770
bool is_animating_solution = false;
68-
const float ANIMATION_DURATION = 0.5f;
71+
const float ANIMATION_DURATION = 0.25f;
6972

7073
Camera3D* camera_node;
7174
float zoom_speed = 0.5f;
7275
float min_zoom_distance = 2.0f;
7376
float max_zoom_distance = 20.0f;
7477

78+
int notification_count = 0;
79+
VBoxContainer* notification_container = nullptr;
80+
PanelContainer* notification_panel_template = nullptr;
81+
7582
void _animate_next_move();
7683
void _on_move_animation_finished();
7784
Vector3 _get_3d_position_for_piece_coords(const Coordinates& piece_top_left_coords, int piece_size, bool is_vertical_piece);
@@ -90,6 +97,8 @@ class MainScene : public Node3D {
9097
void _clear_all_cars();
9198
void _spawn_piece_as_car(const Piece& piece_data);
9299

100+
void add_notification(const String& p_message);
101+
93102
protected:
94103
static void _bind_methods();
95104
void _notification(int p_what);
@@ -99,5 +108,5 @@ class MainScene : public Node3D {
99108
~MainScene();
100109

101110
void _process(double delta) override;
102-
void _input(const Ref<InputEvent>& event);
111+
void _input(const Ref<InputEvent>& event) override;
103112
};

tukang-parkir-simulator/export_presets.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ custom_features=""
99
export_filter="all_resources"
1010
include_filter=""
1111
exclude_filter=""
12-
export_path="../../executable/godot cpp template.html"
12+
export_path="../bin/web/godot cpp template.html"
1313
patches=PackedStringArray()
1414
encryption_include_filters=""
1515
encryption_exclude_filters=""
@@ -22,7 +22,7 @@ script_export_mode=2
2222

2323
custom_template/debug=""
2424
custom_template/release=""
25-
variant/extensions_support=false
25+
variant/extensions_support=true
2626
variant/thread_support=false
2727
vram_texture_compression/for_desktop=true
2828
vram_texture_compression/for_mobile=false

tukang-parkir-simulator/project.godot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ window/stretch/mode="viewport"
2727

2828
[rendering]
2929

30+
textures/canvas_textures/default_texture_filter=0
3031
renderer/rendering_method="gl_compatibility"
3132
renderer/rendering_method.mobile="gl_compatibility"

tukang-parkir-simulator/scenes/main.tscn

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=13 format=3 uid="uid://deic8j1v28f5m"]
1+
[gd_scene load_steps=15 format=3 uid="uid://deic8j1v28f5m"]
22

33
[ext_resource type="PackedScene" uid="uid://bj1kkdl8im8kb" path="res://scenes/car2.tscn" id="1_0wfyh"]
44
[ext_resource type="Shader" uid="uid://dif4yb3527o0r" path="res://scenes/floor.gdshader" id="1_sugp2"]
@@ -39,6 +39,44 @@ size = Vector2(6, 6)
3939
data = PackedVector3Array(50, 0, 50, -50, 0, 50, 50, 0, -50, -50, 0, 50, -50, 0, -50, 50, 0, -50)
4040

4141
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kuqtn"]
42+
bg_color = Color(0.91815, 0, 0.228352, 1)
43+
border_width_left = 5
44+
border_width_top = 5
45+
border_width_right = 5
46+
border_width_bottom = 5
47+
border_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
48+
corner_radius_top_left = 10
49+
corner_radius_top_right = 10
50+
corner_radius_bottom_right = 10
51+
corner_radius_bottom_left = 10
52+
53+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tbgi4"]
54+
content_margin_left = 15.0
55+
content_margin_right = 15.0
56+
bg_color = Color(0.91815, 0, 0.228352, 1)
57+
border_width_left = 5
58+
border_width_top = 5
59+
border_width_right = 5
60+
border_width_bottom = 5
61+
border_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
62+
corner_radius_top_left = 10
63+
corner_radius_top_right = 10
64+
corner_radius_bottom_right = 10
65+
corner_radius_bottom_left = 10
66+
67+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jyhfs"]
68+
content_margin_left = 15.0
69+
content_margin_right = 15.0
70+
bg_color = Color(0.91815, 0, 0.228352, 1)
71+
border_width_left = 5
72+
border_width_top = 5
73+
border_width_right = 5
74+
border_width_bottom = 5
75+
border_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
76+
corner_radius_top_left = 10
77+
corner_radius_top_right = 10
78+
corner_radius_bottom_right = 10
79+
corner_radius_bottom_left = 10
4280

4381
[node name="Main" type="MainScene"]
4482

@@ -87,6 +125,18 @@ offset_bottom = -26.0
87125
grow_horizontal = 2
88126
grow_vertical = 0
89127
focus_mode = 0
128+
theme_override_colors/font_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
129+
theme_override_font_sizes/font_size = 31
130+
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
131+
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
132+
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
133+
theme_override_styles/hover_pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
134+
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_kuqtn")
135+
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
136+
theme_override_styles/hover = SubResource("StyleBoxFlat_kuqtn")
137+
theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
138+
theme_override_styles/pressed = SubResource("StyleBoxFlat_kuqtn")
139+
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
90140
theme_override_styles/normal = SubResource("StyleBoxFlat_kuqtn")
91141
text = "Solve"
92142

@@ -103,6 +153,18 @@ offset_bottom = -27.0
103153
grow_horizontal = 2
104154
grow_vertical = 0
105155
focus_mode = 0
156+
theme_override_colors/font_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
157+
theme_override_font_sizes/font_size = 31
158+
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
159+
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
160+
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
161+
theme_override_styles/hover_pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
162+
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_kuqtn")
163+
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
164+
theme_override_styles/hover = SubResource("StyleBoxFlat_kuqtn")
165+
theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
166+
theme_override_styles/pressed = SubResource("StyleBoxFlat_kuqtn")
167+
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
106168
theme_override_styles/normal = SubResource("StyleBoxFlat_kuqtn")
107169
text = "Load"
108170

@@ -119,6 +181,18 @@ offset_bottom = -25.0
119181
grow_horizontal = 2
120182
grow_vertical = 0
121183
focus_mode = 0
184+
theme_override_colors/font_color = Color(0.825689, 0.839261, 7.70092e-07, 1)
185+
theme_override_font_sizes/font_size = 31
186+
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
187+
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
188+
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
189+
theme_override_styles/hover_pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
190+
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_kuqtn")
191+
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
192+
theme_override_styles/hover = SubResource("StyleBoxFlat_kuqtn")
193+
theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_kuqtn")
194+
theme_override_styles/pressed = SubResource("StyleBoxFlat_kuqtn")
195+
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
122196
theme_override_styles/normal = SubResource("StyleBoxFlat_kuqtn")
123197
text = "Reset"
124198

@@ -131,6 +205,26 @@ offset_top = 25.0
131205
offset_right = -30.0
132206
offset_bottom = 69.0
133207
grow_horizontal = 0
208+
theme_override_styles/focus = SubResource("StyleBoxFlat_kuqtn")
209+
theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_kuqtn")
210+
theme_override_styles/disabled = SubResource("StyleBoxFlat_kuqtn")
211+
theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_kuqtn")
212+
theme_override_styles/hover = SubResource("StyleBoxFlat_tbgi4")
213+
theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_kuqtn")
214+
theme_override_styles/normal = SubResource("StyleBoxFlat_jyhfs")
215+
216+
[node name="NodeLabel" type="Label" parent="UI"]
217+
anchors_preset = 7
218+
anchor_left = 0.5
219+
anchor_top = 1.0
220+
anchor_right = 0.5
221+
anchor_bottom = 1.0
222+
offset_left = -177.0
223+
offset_top = -23.0
224+
offset_right = -99.0
225+
grow_horizontal = 2
226+
grow_vertical = 0
227+
text = "Node: 0"
134228

135229
[node name="TimeLabel" type="Label" parent="UI"]
136230
anchors_preset = 7
@@ -144,3 +238,17 @@ offset_right = 20.0
144238
grow_horizontal = 2
145239
grow_vertical = 0
146240
text = "Time: 0.0s"
241+
242+
[node name="MoveLabel" type="Label" parent="UI"]
243+
anchors_preset = 7
244+
anchor_left = 0.5
245+
anchor_top = 1.0
246+
anchor_right = 0.5
247+
anchor_bottom = 1.0
248+
offset_left = 111.0
249+
offset_top = -25.0
250+
offset_right = 189.0
251+
offset_bottom = -2.0
252+
grow_horizontal = 2
253+
grow_vertical = 0
254+
text = "Move: 0"

0 commit comments

Comments
 (0)