Skip to content

Commit

Permalink
Merge pull request #371 from Spartan322/add/basic-lobby-map-view
Browse files Browse the repository at this point in the history
Add MapView to LobbyMenu
  • Loading branch information
Spartan322 authored Feb 3, 2025
2 parents 38c1d46 + 410615b commit 76ffaa3
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 27 deletions.
1 change: 1 addition & 0 deletions game/src/Game/GameMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 23 additions & 1 deletion game/src/Game/GameSession/GameSession.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends Control
extends Node

@export var _map_view : MapView
@export var _model_manager : ModelManager
@export var _game_session_menu : Control

Expand All @@ -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)
15 changes: 7 additions & 8 deletions game/src/Game/GameSession/GameSession.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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"]
Expand Down
25 changes: 9 additions & 16 deletions game/src/Game/GameSession/MapView.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions game/src/Game/Menu/LobbyMenu/LobbyMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
16 changes: 14 additions & 2 deletions game/src/Game/Menu/LobbyMenu/LobbyMenu.tscn
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -129,10 +137,14 @@ 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"]
[connection signal="text_submitted" from="GameStartPanel/VBoxContainer/SessionTagEdit" to="." method="_on_session_tag_edit_text_submitted"]
[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"]

0 comments on commit 76ffaa3

Please sign in to comment.