From e637c3afe2854488d1c2e755e0272f431105c404 Mon Sep 17 00:00:00 2001 From: BrickPi <49528459+BrickPi@users.noreply.github.com> Date: Mon, 27 Feb 2023 06:09:41 -0600 Subject: Add Main Menu Version and Checksum Labels (#44) --- extension/src/Checksum.hpp | 38 +++++++++++++++++++++++++++++++++ extension/src/register_types.cpp | 9 ++++++++ game/src/MainMenu/MainMenu.gd | 6 ++++++ game/src/MainMenu/MainMenu.tscn | 46 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 extension/src/Checksum.hpp diff --git a/extension/src/Checksum.hpp b/extension/src/Checksum.hpp new file mode 100644 index 0000000..ebdbd43 --- /dev/null +++ b/extension/src/Checksum.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +namespace OpenVic2 { + class Checksum : public godot::Object { + GDCLASS(Checksum, godot::Object) + + //BEGIN BOILERPLATE + static Checksum* _checksum; + + protected: + static void _bind_methods() { + godot::ClassDB::bind_method(godot::D_METHOD("get_checksum_text"), &Checksum::get_checksum_text); + } + + public: + inline static Checksum* get_singleton() { return _checksum; } + + inline Checksum() { + ERR_FAIL_COND(_checksum != nullptr); + _checksum = this; + } + inline ~Checksum() { + ERR_FAIL_COND(_checksum != this); + _checksum = nullptr; + } + //END BOILERPLATE + + inline godot::String get_checksum_text() { + return godot::String("1234abcd"); + } + }; + + Checksum* Checksum::_checksum = nullptr; +} \ No newline at end of file diff --git a/extension/src/register_types.cpp b/extension/src/register_types.cpp index 84e4dc4..aac38b9 100644 --- a/extension/src/register_types.cpp +++ b/extension/src/register_types.cpp @@ -7,12 +7,14 @@ #include "TestSingleton.hpp" #include "Simulation.hpp" +#include "Checksum.hpp" using namespace godot; using namespace OpenVic2; static TestSingleton* _test_singleton; static Simulation* _simulation; +static Checksum* _checksum; void initialize_openvic2_types(ModuleInitializationLevel p_level) { @@ -28,6 +30,10 @@ void initialize_openvic2_types(ModuleInitializationLevel p_level) _simulation = memnew(Simulation); Engine::get_singleton()->register_singleton("Simulation", Simulation::get_singleton()); + ClassDB::register_class(); + _checksum = memnew(Checksum); + Engine::get_singleton()->register_singleton("Checksum", Checksum::get_singleton()); + } void uninitialize_openvic2_types(ModuleInitializationLevel p_level) { @@ -40,6 +46,9 @@ void uninitialize_openvic2_types(ModuleInitializationLevel p_level) { Engine::get_singleton()->unregister_singleton("Simulation"); memdelete(_simulation); + + Engine::get_singleton()->unregister_singleton("Checksum"); + memdelete(_checksum); } extern "C" diff --git a/game/src/MainMenu/MainMenu.gd b/game/src/MainMenu/MainMenu.gd index cd333a3..0a551e0 100644 --- a/game/src/MainMenu/MainMenu.gd +++ b/game/src/MainMenu/MainMenu.gd @@ -5,9 +5,15 @@ signal options_button_pressed @export var _new_game_button : BaseButton +@export +var _checksum_label : Label + func _ready(): print("From GDScript") TestSingleton.hello_singleton() + # UI-111 + _checksum_label.tooltip_text = "Checksum " + Checksum.get_checksum_text() + _checksum_label.text = "(" + Checksum.get_checksum_text().substr(0, 4) + ")" _new_game_button.grab_focus() diff --git a/game/src/MainMenu/MainMenu.tscn b/game/src/MainMenu/MainMenu.tscn index bb47f88..f306c63 100644 --- a/game/src/MainMenu/MainMenu.tscn +++ b/game/src/MainMenu/MainMenu.tscn @@ -3,7 +3,7 @@ [ext_resource type="Theme" uid="uid://1xrgnmmnrnce" path="res://default_theme.theme" id="1_6d448"] [ext_resource type="Script" path="res://src/MainMenu/MainMenu.gd" id="2_nm1fq"] -[node name="MainMenu" type="Control" node_paths=PackedStringArray("_new_game_button")] +[node name="MainMenu" type="Control" node_paths=PackedStringArray("_new_game_button", "_checksum_label")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -13,6 +13,7 @@ grow_vertical = 2 theme = ExtResource("1_6d448") script = ExtResource("2_nm1fq") _new_game_button = NodePath("Panel/VBox/Margin/ButtonList/NewGameButton") +_checksum_label = NodePath("Panel/VBox/Margin2/VersionChecksumBox/ChecksumLabel") [node name="Panel" type="PanelContainer" parent="."] layout_mode = 1 @@ -50,7 +51,11 @@ alignment = 1 [node name="NewGameButton" type="Button" parent="Panel/VBox/Margin/ButtonList" node_paths=PackedStringArray("shortcut_context")] layout_mode = 2 size_flags_horizontal = 3 +focus_neighbor_left = NodePath("../ExitButton") focus_neighbor_top = NodePath("../ExitButton") +focus_neighbor_right = NodePath("../ContinueButton") +focus_next = NodePath("../ContinueButton") +focus_previous = NodePath("../ExitButton") shortcut_context = NodePath("") theme_type_variation = &"Button_MainMenu" text = "New Game" @@ -59,6 +64,10 @@ clip_text = true [node name="ContinueButton" type="Button" parent="Panel/VBox/Margin/ButtonList"] layout_mode = 2 size_flags_horizontal = 3 +focus_neighbor_left = NodePath("../NewGameButton") +focus_neighbor_right = NodePath("../MultiplayerButton") +focus_next = NodePath("../MultiplayerButton") +focus_previous = NodePath("../NewGameButton") theme_type_variation = &"Button_MainMenu" disabled = true text = "Continue" @@ -67,6 +76,10 @@ clip_text = true [node name="MultiplayerButton" type="Button" parent="Panel/VBox/Margin/ButtonList"] layout_mode = 2 size_flags_horizontal = 3 +focus_neighbor_left = NodePath("../ContinueButton") +focus_neighbor_right = NodePath("../OptionsButton") +focus_next = NodePath("../OptionsButton") +focus_previous = NodePath("../ContinueButton") theme_type_variation = &"Button_MainMenu" text = "Multiplayer" clip_text = true @@ -74,6 +87,10 @@ clip_text = true [node name="OptionsButton" type="Button" parent="Panel/VBox/Margin/ButtonList"] layout_mode = 2 size_flags_horizontal = 3 +focus_neighbor_left = NodePath("../MultiplayerButton") +focus_neighbor_right = NodePath("../ExitButton") +focus_next = NodePath("../ExitButton") +focus_previous = NodePath("../MultiplayerButton") theme_type_variation = &"Button_MainMenu" text = "Options" clip_text = true @@ -81,7 +98,10 @@ clip_text = true [node name="ExitButton" type="Button" parent="Panel/VBox/Margin/ButtonList"] layout_mode = 2 size_flags_horizontal = 3 -focus_neighbor_bottom = NodePath("../NewGameButton") +focus_neighbor_left = NodePath("../OptionsButton") +focus_neighbor_right = NodePath("../NewGameButton") +focus_next = NodePath("../NewGameButton") +focus_previous = NodePath("../OptionsButton") theme_type_variation = &"Button_MainMenu" text = "Exit" clip_text = true @@ -91,6 +111,28 @@ layout_mode = 2 size_flags_vertical = 3 size_flags_stretch_ratio = 0.35 +[node name="Margin2" type="MarginContainer" parent="Panel/VBox"] +layout_mode = 2 +theme_override_constants/margin_left = 50 +theme_override_constants/margin_right = 50 +theme_override_constants/margin_bottom = 10 + +[node name="VersionChecksumBox" type="HBoxContainer" parent="Panel/VBox/Margin2"] +layout_mode = 2 + +[node name="VersionLabel" type="Label" parent="Panel/VBox/Margin2/VersionChecksumBox"] +layout_mode = 2 +tooltip_text = "OpenVic2 v0.01 \"Primum Mobile\"" +mouse_filter = 1 +text = "v0.01" + +[node name="ChecksumLabel" type="Label" parent="Panel/VBox/Margin2/VersionChecksumBox"] +layout_mode = 2 +tooltip_text = "Checksum 00000000" +mouse_filter = 1 +theme_override_colors/font_color = Color(0.247059, 0.392157, 1, 1) +text = "(0000)" + [connection signal="pressed" from="Panel/VBox/Margin/ButtonList/NewGameButton" to="." method="_on_new_game_button_pressed"] [connection signal="pressed" from="Panel/VBox/Margin/ButtonList/ContinueButton" to="." method="_on_continue_button_pressed"] [connection signal="pressed" from="Panel/VBox/Margin/ButtonList/MultiplayerButton" to="." method="_on_multi_player_button_pressed"] -- cgit v1.2.3-56-ga3b1