From ec714dd793658cb0a21babba47b70e43b40c504e Mon Sep 17 00:00:00 2001 From: hop311 Date: Sun, 17 Nov 2024 23:47:31 +0000 Subject: Add skeleton ledger menu --- game/src/Game/GameSession/GameSession.tscn | 9 +++- game/src/Game/GameSession/Ledger.gd | 84 ++++++++++++++++++++++++++++++ game/src/Game/GameSession/Menubar.gd | 5 ++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 game/src/Game/GameSession/Ledger.gd (limited to 'game/src/Game/GameSession') diff --git a/game/src/Game/GameSession/GameSession.tscn b/game/src/Game/GameSession/GameSession.tscn index f60831f..041e9c0 100644 --- a/game/src/Game/GameSession/GameSession.tscn +++ b/game/src/Game/GameSession/GameSession.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=21 format=3 uid="uid://bgnupcshe1m7r"] +[gd_scene load_steps=22 format=3 uid="uid://bgnupcshe1m7r"] [ext_resource type="Script" path="res://src/Game/GameSession/GameSession.gd" id="1_eklvp"] [ext_resource type="PackedScene" uid="uid://cvl76duuym1wq" path="res://src/Game/MusicConductor/MusicPlayer.tscn" id="2_kt6aa"] @@ -18,6 +18,7 @@ [ext_resource type="Script" path="res://src/Game/GameSession/NationManagementScreen/TradeMenu.gd" id="10_mv1r6"] [ext_resource type="Script" path="res://src/Game/GameSession/NationManagementScreen/DiplomacyMenu.gd" id="11_fu7ys"] [ext_resource type="Script" path="res://src/Game/GameSession/NationManagementScreen/MilitaryMenu.gd" id="12_6h6nc"] +[ext_resource type="Script" path="res://src/Game/GameSession/Ledger.gd" id="15_vhb1p"] [ext_resource type="Script" path="res://src/Game/GameSession/Tooltip.gd" id="20_3306e"] [ext_resource type="Script" path="res://src/Game/GameSession/Menubar.gd" id="20_s1i71"] @@ -108,6 +109,11 @@ layout_mode = 1 anchors_preset = 15 script = ExtResource("20_s1i71") +[node name="Ledger" type="GUINode" parent="UICanvasLayer/UI"] +layout_mode = 1 +anchors_preset = 15 +script = ExtResource("15_vhb1p") + [node name="SearchPanel" type="GUINode" parent="UICanvasLayer/UI" node_paths=PackedStringArray("_map_view")] layout_mode = 1 anchors_preset = 15 @@ -160,6 +166,7 @@ script = ExtResource("20_3306e") [connection signal="detailed_view_changed" from="MapView" to="ModelManager" method="set_visible"] [connection signal="map_view_camera_changed" from="MapView" to="UICanvasLayer/UI/Menubar" method="_on_map_view_camera_changed"] [connection signal="game_session_menu_button_pressed" from="UICanvasLayer/UI/Menubar" to="." method="_on_game_session_menu_button_pressed"] +[connection signal="ledger_button_pressed" from="UICanvasLayer/UI/Menubar" to="UICanvasLayer/UI/Ledger" method="toggle_visibility"] [connection signal="minimap_clicked" from="UICanvasLayer/UI/Menubar" to="MapView" method="_on_minimap_clicked"] [connection signal="search_button_pressed" from="UICanvasLayer/UI/Menubar" to="UICanvasLayer/UI/SearchPanel" method="toggle_visibility"] [connection signal="zoom_in_button_pressed" from="UICanvasLayer/UI/Menubar" to="MapView" method="zoom_in"] diff --git a/game/src/Game/GameSession/Ledger.gd b/game/src/Game/GameSession/Ledger.gd new file mode 100644 index 0000000..50bde07 --- /dev/null +++ b/game/src/Game/GameSession/Ledger.gd @@ -0,0 +1,84 @@ +extends GUINode + +enum Page { + NATION_RANKING, + NATIONAL_COMPARISON, + POLITICAL_SYSTEMS, + POLITICAL_REFORMS, + SOCIAL_REFORMS, + COUNTRY_POPULATION, + PROVINCES, + PROVINCE_POPULATION, + PROVINCE_PRODUCTION, + FACTORY_PRODUCTION, + PRICE_HISTORY, + NUMBER_OF_PAGES +} +const _page_titles : PackedStringArray = [ + "LEDGER_HEADER_RANK", + "LEDGER_HEADER_COUNTRYCOMPARE", + "LEDGER_HEADER_COUNTRYPARTY", + "LEDGER_HEADER_COUNTRYPOLITICALREFORMS", + "LEDGER_HEADER_COUNTRYSOCIALREFORMS", + "LEDGER_HEADER_COUNTRY_POPS", + "LEDGER_HEADER_PROVINCES", + "LEDGER_HEADER_PROVINCE_POPS", + "LEDGER_HEADER_PROVINCEPRODUCTION", + "LEDGER_HEADER_FACTORYPRODUCTION", + "LEDGER_HEADER_GOODS_PRICEHISTORY" +] + +var _current_page : Page = Page.NATION_RANKING: + get: return _current_page + set(new_page): + _current_page = new_page + while _current_page < 0: + _current_page += Page.NUMBER_OF_PAGES + _current_page %= Page.NUMBER_OF_PAGES + _update_info() + +var _page_title_label : GUILabel +var _page_number_label : GUILabel +# TODO - add variables to store any nodes you'll need to refer in more than one function call + +func _ready(): + MenuSingleton.search_cache_changed.connect(_update_info) + + add_gui_element("v2ledger", "ledger") + + var close_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./ledger/close") + if close_button: + close_button.pressed.connect(hide) + + var previous_page_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./ledger/prev") + if previous_page_button: + previous_page_button.pressed.connect(func() -> void: _current_page -= 1) + + var next_page_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./ledger/next") + if next_page_button: + next_page_button.pressed.connect(func() -> void: _current_page += 1) + + _page_title_label = get_gui_label_from_nodepath(^"./ledger/ledger_header") + _page_number_label = get_gui_label_from_nodepath(^"./ledger/page_number") + + # TODO - get any nodes that need setting up or caching in the variables above + + hide() + +func toggle_visibility() -> void: + if is_visible(): + hide() + else: + show() + _update_info() + +func _update_info() -> void: + if is_visible(): + if _page_title_label: + _page_title_label.set_text(_page_titles[_current_page]) + + if _page_number_label: + # Pages are indexed from 0 in the code, but from 1 in the UI + _page_number_label.set_text(str(_current_page + 1)) + + # TODO - set contents of current ledger page diff --git a/game/src/Game/GameSession/Menubar.gd b/game/src/Game/GameSession/Menubar.gd index 61f8bbc..bff1418 100644 --- a/game/src/Game/GameSession/Menubar.gd +++ b/game/src/Game/GameSession/Menubar.gd @@ -1,6 +1,7 @@ extends GUINode signal game_session_menu_button_pressed +signal ledger_button_pressed signal search_button_pressed signal zoom_in_button_pressed signal zoom_out_button_pressed @@ -66,6 +67,7 @@ func _ready() -> void: var ledger_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./menubar/ledger_button") if ledger_button: ledger_button.tooltip_string = "M_LEDGER_BUTTON" + ledger_button.pressed.connect(_on_ledger_button_pressed) var search_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./menubar/button_goto") if search_button: @@ -101,6 +103,9 @@ func _ready() -> void: func _on_game_session_menu_button_pressed() -> void: game_session_menu_button_pressed.emit() +func _on_ledger_button_pressed() -> void: + ledger_button_pressed.emit() + func _on_search_button_pressed() -> void: search_button_pressed.emit() -- cgit v1.2.3-56-ga3b1