From 410615bd1bf92c6073b9a75bfebdefea06a2d5df Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sun, 2 Feb 2025 15:47:25 -0500 Subject: [PATCH] Add MapView to LobbyMenu Replace MapView province hover behavior with signal Replace MapView province unhover behavior with signal Replace MapView province click behavior with signal Replace MapView province right click behavior with signal Add MapView province behavior signal implementations to GameSession Add LobbyMenu MapView TODOs Change GameSession scene type to Node --- game/src/Game/GameMenu.tscn | 1 + game/src/Game/GameSession/GameSession.gd | 24 +++++++++++++++++++- game/src/Game/GameSession/GameSession.tscn | 15 ++++++------- game/src/Game/GameSession/MapView.gd | 25 ++++++++------------- game/src/Game/Menu/LobbyMenu/LobbyMenu.gd | 14 ++++++++++++ game/src/Game/Menu/LobbyMenu/LobbyMenu.tscn | 16 +++++++++++-- 6 files changed, 68 insertions(+), 27 deletions(-) diff --git a/game/src/Game/GameMenu.tscn b/game/src/Game/GameMenu.tscn index 73287a54..238fa9b6 100644 --- a/game/src/Game/GameMenu.tscn +++ b/game/src/Game/GameMenu.tscn @@ -14,6 +14,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 script = ExtResource("1_cafwe") _main_menu = NodePath("MainMenu") _options_menu = NodePath("OptionsMenu") diff --git a/game/src/Game/GameSession/GameSession.gd b/game/src/Game/GameSession/GameSession.gd index 1f30cba6..f9c29824 100644 --- a/game/src/Game/GameSession/GameSession.gd +++ b/game/src/Game/GameSession/GameSession.gd @@ -1,5 +1,6 @@ -extends Control +extends Node +@export var _map_view : MapView @export var _model_manager : ModelManager @export var _game_session_menu : Control @@ -22,3 +23,24 @@ func _process(_delta : float) -> void: # * SS-42 func _on_game_session_menu_button_pressed() -> void: _game_session_menu.visible = !_game_session_menu.visible + +func _on_map_view_ready() -> void: + # Set the camera's starting position + _map_view._camera.position = _map_view._map_to_world_coords( + # Start at the player country's capital position (when loading a save game in the lobby or entering the actual game) + GameSingleton.get_viewed_country_capital_position() + ) + +func _on_map_view_province_hovered(index: int) -> void: + _map_view.set_hovered_province_index(index) + +func _on_map_view_province_unhovered() -> void: + _map_view.unset_hovered_province() + +func _on_map_view_province_clicked(index: int) -> void: + GameSingleton.set_selected_province(index) + +func _on_map_view_province_right_clicked(index: int) -> void: + # TODO - open diplomacy screen on province owner or viewed country if province has no owner + #Events.NationManagementScreens.open_nation_management_screen(NationManagement.Screen.DIPLOMACY) + GameSingleton.set_viewed_country_by_province_index(index) diff --git a/game/src/Game/GameSession/GameSession.tscn b/game/src/Game/GameSession/GameSession.tscn index 4f6c3a9c..8d882b99 100644 --- a/game/src/Game/GameSession/GameSession.tscn +++ b/game/src/Game/GameSession/GameSession.tscn @@ -39,16 +39,10 @@ transform_format = 1 use_custom_data = true mesh = SubResource("QuadMesh_fm6ks") -[node name="GameSession" type="Control" node_paths=PackedStringArray("_model_manager", "_game_session_menu")] +[node name="GameSession" type="Node" node_paths=PackedStringArray("_map_view", "_model_manager", "_game_session_menu")] editor_description = "SS-102, UI-546" -layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -mouse_filter = 2 script = ExtResource("1_eklvp") +_map_view = NodePath("MapView") _model_manager = NodePath("ModelManager") _game_session_menu = NodePath("UICanvasLayer/UI/GameSessionMenu") @@ -191,6 +185,11 @@ script = ExtResource("20_3306e") [connection signal="detailed_view_changed" from="MapView" to="BillboardManager" method="detailed_map"] [connection signal="map_view_camera_changed" from="MapView" to="UICanvasLayer/UI/Menubar" method="_on_map_view_camera_changed"] [connection signal="parchment_view_changed" from="MapView" to="BillboardManager" method="parchment_view"] +[connection signal="province_clicked" from="MapView" to="." method="_on_map_view_province_clicked"] +[connection signal="province_hovered" from="MapView" to="." method="_on_map_view_province_hovered"] +[connection signal="province_right_clicked" from="MapView" to="." method="_on_map_view_province_right_clicked"] +[connection signal="province_unhovered" from="MapView" to="." method="_on_map_view_province_unhovered"] +[connection signal="ready" from="MapView" to="." method="_on_map_view_ready"] [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"] diff --git a/game/src/Game/GameSession/MapView.gd b/game/src/Game/GameSession/MapView.gd index f0a301d7..7cc69b25 100644 --- a/game/src/Game/GameSession/MapView.gd +++ b/game/src/Game/GameSession/MapView.gd @@ -4,6 +4,10 @@ extends Node3D signal map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) signal parchment_view_changed(is_parchment_view : bool) signal detailed_view_changed(is_detailed_view : bool) +signal province_hovered(index : int) +signal province_unhovered() +signal province_clicked(index : int) +signal province_right_clicked(index : int) const _action_north : StringName = &"map_north" const _action_east : StringName = &"map_east" @@ -103,15 +107,6 @@ func _ready() -> void: GameSingleton.province_selected.connect(_on_province_selected) - # Set the camera's starting position - _camera.position = _map_to_world_coords( - # Start at the bookmark's start position (used when loading a bookmark in the lobby) - # GameSingleton.get_bookmark_start_position() - - # Start at the player country's capital position (when loading a save game in the lobby or entering the actual game) - GameSingleton.get_viewed_country_capital_position() - ) - # Start zoomed out with the parchment map active _camera.position.y = _zoom_parchment_threshold * 1.5 _zoom_target = _camera.position.y @@ -134,7 +129,7 @@ func _ready() -> void: func _notification(what: int) -> void: if what == NOTIFICATION_WM_MOUSE_EXIT: _mouse_over_viewport = false - unset_hovered_province() + province_unhovered.emit() func _world_to_map_coords(pos : Vector3) -> Vector2: return (Vector2(pos.x, pos.z) - _map_mesh_corner) / _map_mesh_dims @@ -195,7 +190,7 @@ func _update_province_hover() -> void: if not _province_hover_dirty: return _province_hover_dirty = false if _mouse_over_viewport: - set_hovered_province_at(_viewport_to_map_coords(_mouse_pos_viewport)) + province_hovered.emit(GameSingleton.get_province_index_from_uv_coords(_viewport_to_map_coords(_mouse_pos_viewport))) func _on_province_selected(index : int) -> void: if _map_shader_material: @@ -230,15 +225,13 @@ func _unhandled_input(event : InputEvent) -> void: if _mouse_over_viewport: # Check if the mouse is outside of bounds if _map_mesh.is_valid_uv_coord(_mouse_pos_map): - GameSingleton.set_selected_province(GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map)) + province_clicked.emit(GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map)) else: print("Clicked outside the map!") elif event.is_action_pressed(_action_right_click): if _mouse_over_viewport: if _map_mesh.is_valid_uv_coord(_mouse_pos_map): - # TODO - open diplomacy screen on province owner or viewed country if province has no owner - #Events.NationManagementScreens.open_nation_management_screen(NationManagement.Screen.DIPLOMACY) - GameSingleton.set_viewed_country_by_province_index(GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map)) + province_right_clicked.emit(GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map)) else: print("Right-clicked outside the map!") elif event.is_action_pressed(_action_drag): @@ -257,7 +250,7 @@ func _process(delta : float) -> void: if _is_viewport_inactive(): _mouse_over_viewport = false - unset_hovered_province() + province_unhovered.emit() _viewport_dims = Vector2(Resolution.get_current_resolution()) # Process movement diff --git a/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd b/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd index ef845ebb..097bb00f 100644 --- a/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd +++ b/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd @@ -19,6 +19,11 @@ signal start_date_selected(index : int) @export var session_tag_line_edit : LineEdit @export var session_tag_dialog : ConfirmationDialog @export var delete_dialog : ConfirmationDialog +@export var map_view : MapView + +func _ready() -> void: + # TODO: Needs to be able to set the map to the political mapmode + pass func filter_for_tag(tag : StringName) -> void: for child : Control in game_select_save_list.get_children(): @@ -171,3 +176,12 @@ func _on_visibility_changed() -> void: _build_save_list() else: _queue_clear_lists() + +func _on_map_view_ready() -> void: + # TODO: Start at the bookmark's start position (used when loading a bookmark in the lobby) + # GameSingleton.get_bookmark_start_position() + pass + +func _on_map_view_province_clicked(_index: int) -> void: + # TODO: need to be able to call something like GameSingleton.set_viewed_country_by_province_index(index) here + pass diff --git a/game/src/Game/Menu/LobbyMenu/LobbyMenu.tscn b/game/src/Game/Menu/LobbyMenu/LobbyMenu.tscn index 081beda3..0638b9d4 100644 --- a/game/src/Game/Menu/LobbyMenu/LobbyMenu.tscn +++ b/game/src/Game/Menu/LobbyMenu/LobbyMenu.tscn @@ -1,16 +1,18 @@ -[gd_scene load_steps=4 format=3 uid="uid://do60kx0d3nrh4"] +[gd_scene load_steps=5 format=3 uid="uid://do60kx0d3nrh4"] [ext_resource type="Script" path="res://src/Game/Menu/LobbyMenu/LobbyMenu.gd" id="1_cvwum"] [ext_resource type="PackedScene" uid="uid://k71f5gibwmtc" path="res://src/Game/Menu/LobbyMenu/LobbyPanelButton.tscn" id="2_exh17"] [ext_resource type="PackedScene" uid="uid://d2s7roinx2or7" path="res://src/Game/Menu/SaveLoadMenu/SavePanelButton.tscn" id="3_4otj7"] +[ext_resource type="PackedScene" uid="uid://dkehmdnuxih2r" path="res://src/Game/GameSession/MapView.tscn" id="4_y8n6u"] -[node name="LobbyMenu" type="HBoxContainer" node_paths=PackedStringArray("game_select_start_date", "game_select_save_tab", "game_select_save_list", "start_button", "session_tag_line_edit", "session_tag_dialog", "delete_dialog")] +[node name="LobbyMenu" type="HBoxContainer" node_paths=PackedStringArray("game_select_start_date", "game_select_save_tab", "game_select_save_list", "start_button", "session_tag_line_edit", "session_tag_dialog", "delete_dialog", "map_view")] editor_description = "UI-36" anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 script = ExtResource("1_cvwum") lobby_panel_button = ExtResource("2_exh17") save_scene = ExtResource("3_4otj7") @@ -21,6 +23,7 @@ start_button = NodePath("GameStartPanel/VBoxContainer/StartButton") session_tag_line_edit = NodePath("GameStartPanel/VBoxContainer/SessionTagEdit") session_tag_dialog = NodePath("SessionTagDialog") delete_dialog = NodePath("DeleteDialog") +map_view = NodePath("MapView") [node name="GameSelectPanel" type="PanelContainer" parent="."] layout_mode = 2 @@ -64,6 +67,7 @@ item_1/text = "1863" custom_minimum_size = Vector2(0, 150) layout_mode = 2 size_flags_vertical = 3 +mouse_filter = 2 [node name="BackButton" type="Button" parent="GameSelectPanel/VBoxContainer"] editor_description = "UI-37" @@ -73,6 +77,7 @@ text = "GAMELOBBY_BACK" [node name="Spacer2" type="Control" parent="GameSelectPanel/VBoxContainer"] custom_minimum_size = Vector2(0, 33) layout_mode = 2 +mouse_filter = 2 [node name="Spacer" type="Control" parent="."] layout_mode = 2 @@ -90,6 +95,7 @@ layout_mode = 2 [node name="Spacer" type="Control" parent="GameStartPanel/VBoxContainer"] custom_minimum_size = Vector2(0, 50) layout_mode = 2 +mouse_filter = 2 [node name="SelectedCountryNameLabel" type="Label" parent="GameStartPanel/VBoxContainer"] layout_mode = 2 @@ -100,6 +106,7 @@ horizontal_alignment = 1 custom_minimum_size = Vector2(0, 150) layout_mode = 2 size_flags_vertical = 3 +mouse_filter = 2 [node name="SessionTagEdit" type="LineEdit" parent="GameStartPanel/VBoxContainer"] layout_mode = 2 @@ -114,6 +121,7 @@ text = "GAMELOBBY_START" [node name="Spacer3" type="Control" parent="GameStartPanel/VBoxContainer"] custom_minimum_size = Vector2(0, 33) layout_mode = 2 +mouse_filter = 2 [node name="SessionTagDialog" type="ConfirmationDialog" parent="."] disable_3d = true @@ -129,6 +137,8 @@ ok_button_text = "DIALOG_OK" dialog_text = "GAMELOBBY_DELETE_DIALOG_TEXT" cancel_button_text = "DIALOG_CANCEL" +[node name="MapView" parent="." instance=ExtResource("4_y8n6u")] + [connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] [connection signal="tab_changed" from="GameSelectPanel/VBoxContainer/GameSelectScroll/GameSelectList/GameSelectSaveTab" to="." method="_on_game_select_save_tab_tab_changed"] [connection signal="button_down" from="GameSelectPanel/VBoxContainer/BackButton" to="." method="_on_back_button_button_down"] @@ -136,3 +146,5 @@ cancel_button_text = "DIALOG_CANCEL" [connection signal="pressed" from="GameStartPanel/VBoxContainer/StartButton" to="." method="_on_start_button_pressed"] [connection signal="confirmed" from="SessionTagDialog" to="." method="_on_session_tag_dialog_confirmed"] [connection signal="confirmed" from="DeleteDialog" to="." method="_on_delete_dialog_confirmed"] +[connection signal="province_clicked" from="MapView" to="." method="_on_map_view_province_clicked"] +[connection signal="ready" from="MapView" to="." method="_on_map_view_ready"]