From 87ac0ca20d78c45507f03da78bce398e471e944f Mon Sep 17 00:00:00 2001 From: BrickPi Date: Wed, 13 Nov 2024 21:05:46 -0600 Subject: switch minimap background UI --- game/src/Game/GameSession/GameSession.tscn | 47 +++++++-- .../GameSession/MapControlPanel/MapControlPanel.gd | 62 ----------- .../MapControlPanel/MapControlPanel.tscn | 113 --------------------- .../Game/GameSession/MapControlPanel/Minimap.gd | 105 ------------------- .../GameSession/MapControlPanel/Minimap.gdshader | 18 ---- game/src/Game/GameSession/Menubar/Menubar.gd | 113 +++++++++++++++++++++ game/src/Game/GameSession/Menubar/Minimap.gd | 104 +++++++++++++++++++ game/src/Game/GameSession/Menubar/Minimap.gdshader | 18 ++++ 8 files changed, 272 insertions(+), 308 deletions(-) delete mode 100644 game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd delete mode 100644 game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn delete mode 100644 game/src/Game/GameSession/MapControlPanel/Minimap.gd delete mode 100644 game/src/Game/GameSession/MapControlPanel/Minimap.gdshader create mode 100644 game/src/Game/GameSession/Menubar/Menubar.gd create mode 100644 game/src/Game/GameSession/Menubar/Minimap.gd create mode 100644 game/src/Game/GameSession/Menubar/Minimap.gdshader (limited to 'game') diff --git a/game/src/Game/GameSession/GameSession.tscn b/game/src/Game/GameSession/GameSession.tscn index 5925f3d..ceb3ceb 100644 --- a/game/src/Game/GameSession/GameSession.tscn +++ b/game/src/Game/GameSession/GameSession.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=21 format=3 uid="uid://bgnupcshe1m7r"] +[gd_scene load_steps=26 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"] -[ext_resource type="PackedScene" uid="uid://g524p8lr574w" path="res://src/Game/GameSession/MapControlPanel/MapControlPanel.tscn" id="3_afh6d"] [ext_resource type="PackedScene" uid="uid://dvdynl6eir40o" path="res://src/Game/GameSession/GameSessionMenu.tscn" id="3_bvmqh"] [ext_resource type="Script" path="res://src/Game/GameSession/ModelManager.gd" id="3_qwk4j"] [ext_resource type="Script" path="res://src/Game/GameSession/Topbar.gd" id="4_2kbih"] @@ -19,7 +18,21 @@ [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/Menubar/Minimap.gd" id="15_ckojr"] +[ext_resource type="Shader" path="res://src/Game/GameSession/Menubar/Minimap.gdshader" id="15_gtm7r"] [ext_resource type="Script" path="res://src/Game/GameSession/Tooltip.gd" id="20_3306e"] +[ext_resource type="Script" path="res://src/Game/GameSession/Menubar/Menubar.gd" id="20_s1i71"] + +[sub_resource type="InputEventKey" id="InputEventKey_5qthf"] +keycode = 4194305 + +[sub_resource type="Shortcut" id="Shortcut_t1l8i"] +events = [SubResource("InputEventKey_5qthf")] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_6eoxs"] +shader = ExtResource("15_gtm7r") +shader_parameter/province_shape_subdivisions = null +shader_parameter/selected_index = null [node name="GameSession" type="Control" node_paths=PackedStringArray("_model_manager", "_game_session_menu")] editor_description = "SS-102, UI-546" @@ -103,15 +116,28 @@ layout_mode = 1 anchors_preset = 15 script = ExtResource("12_6h6nc") -[node name="MapControlPanel" parent="UICanvasLayer/UI" instance=ExtResource("3_afh6d")] +[node name="Menubar" type="GUINode" parent="UICanvasLayer/UI"] layout_mode = 1 -anchors_preset = -1 +anchors_preset = 15 +mouse_force_pass_scroll_events = false +script = ExtResource("20_s1i71") +_menu_shortcut = SubResource("Shortcut_t1l8i") + +[node name="MinimapRect" type="ColorRect" parent="UICanvasLayer/UI/Menubar"] +material = SubResource("ShaderMaterial_6eoxs") +layout_mode = 1 +anchors_preset = 3 anchor_left = 1.0 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 +offset_left = -1280.0 +offset_top = -720.0 +offset_right = -1280.0 +offset_bottom = -720.0 grow_horizontal = 0 grow_vertical = 0 +script = ExtResource("15_ckojr") [node name="SearchPanel" type="GUINode" parent="UICanvasLayer/UI" node_paths=PackedStringArray("_map_view")] layout_mode = 1 @@ -163,12 +189,13 @@ anchors_preset = 15 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/MapControlPanel" method="_on_map_view_camera_changed"] -[connection signal="game_session_menu_button_pressed" from="UICanvasLayer/UI/MapControlPanel" to="." method="_on_game_session_menu_button_pressed"] -[connection signal="minimap_clicked" from="UICanvasLayer/UI/MapControlPanel" to="MapView" method="_on_minimap_clicked"] -[connection signal="search_button_pressed" from="UICanvasLayer/UI/MapControlPanel" to="UICanvasLayer/UI/SearchPanel" method="toggle_visibility"] -[connection signal="zoom_in_button_pressed" from="UICanvasLayer/UI/MapControlPanel" to="MapView" method="zoom_in"] -[connection signal="zoom_out_button_pressed" from="UICanvasLayer/UI/MapControlPanel" to="MapView" method="zoom_out"] +[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="map_view_camera_changed" from="UICanvasLayer/UI/Menubar" to="UICanvasLayer/UI/Menubar/MinimapRect" method="_on_map_view_camera_changed"] +[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"] +[connection signal="zoom_out_button_pressed" from="UICanvasLayer/UI/Menubar" to="MapView" method="zoom_out"] +[connection signal="minimap_clicked" from="UICanvasLayer/UI/Menubar/MinimapRect" to="MapView" method="_on_minimap_clicked"] [connection signal="load_button_pressed" from="UICanvasLayer/UI/GameSessionMenu" to="UICanvasLayer/UI/SaveLoadMenu" method="show_for_load"] [connection signal="options_button_pressed" from="UICanvasLayer/UI/GameSessionMenu" to="UICanvasLayer/UI/OptionsMenu" method="show"] [connection signal="save_button_pressed" from="UICanvasLayer/UI/GameSessionMenu" to="UICanvasLayer/UI/SaveLoadMenu" method="show_for_save"] diff --git a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd b/game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd deleted file mode 100644 index 61de6ae..0000000 --- a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd +++ /dev/null @@ -1,62 +0,0 @@ -extends PanelContainer - -signal game_session_menu_button_pressed -signal search_button_pressed -signal map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -signal minimap_clicked(pos_clicked : Vector2) -signal zoom_in_button_pressed -signal zoom_out_button_pressed - -@export var _mapmodes_grid : GridContainer - -var _mapmode_button_group : ButtonGroup - -# REQUIREMENTS: -# * UI-550, UI-552, UI-554, UI-561, UI-562, UI-563 -func _add_mapmode_button(identifier : String) -> void: - var button := Button.new() - button.text = identifier - button.tooltip_text = identifier - button.toggle_mode = true - button.button_group = _mapmode_button_group - button.mouse_filter = MOUSE_FILTER_PASS - button.focus_mode = FOCUS_NONE - _mapmodes_grid.add_child(button) - if _mapmode_button_group.get_pressed_button() == null: - button.button_pressed = true - -func _ready() -> void: - _mapmode_button_group = ButtonGroup.new() - _mapmode_button_group.pressed.connect(_mapmode_pressed) - for index : int in GameSingleton.get_mapmode_count(): - _add_mapmode_button(GameSingleton.get_mapmode_identifier(index)) - -# REQUIREMENTS: -# * UIFUN-10 -func _on_game_session_menu_button_pressed() -> void: - game_session_menu_button_pressed.emit() - -func _on_search_button_pressed() -> void: - search_button_pressed.emit() - -# REQUIREMENTS: -# * SS-76 -# * UIFUN-129, UIFUN-131, UIFUN-133, UIFUN-140, UIFUN-141, UIFUN-142 -func _mapmode_pressed(button : BaseButton) -> void: - GameSingleton.set_mapmode(button.tooltip_text) - -func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -> void: - map_view_camera_changed.emit(near_left, far_left, far_right, near_right) - -func _on_minimap_clicked(pos_clicked : Vector2) -> void: - minimap_clicked.emit(pos_clicked) - -# REQUIREMENTS: -# * UIFUN-269 -func _on_zoom_in_button_pressed() -> void: - zoom_in_button_pressed.emit() - -# REQUIREMENTS: -# * UIFUN-270 -func _on_zoom_out_button_pressed() -> void: - zoom_out_button_pressed.emit() diff --git a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn b/game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn deleted file mode 100644 index d49cf61..0000000 --- a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn +++ /dev/null @@ -1,113 +0,0 @@ -[gd_scene load_steps=7 format=3 uid="uid://g524p8lr574w"] - -[ext_resource type="Script" path="res://src/Game/GameSession/MapControlPanel/MapControlPanel.gd" id="1_ign64"] -[ext_resource type="Shader" path="res://src/Game/GameSession/MapControlPanel/Minimap.gdshader" id="2_rinsg"] -[ext_resource type="Script" path="res://src/Game/GameSession/MapControlPanel/Minimap.gd" id="3_s4dml"] - -[sub_resource type="ShaderMaterial" id="ShaderMaterial_bhuqb"] -shader = ExtResource("2_rinsg") -shader_parameter/province_shape_subdivisions = null -shader_parameter/selected_index = null - -[sub_resource type="InputEventAction" id="InputEventAction_5nck3"] -action = &"ui_cancel" - -[sub_resource type="Shortcut" id="Shortcut_fc1tk"] -events = [SubResource("InputEventAction_5nck3")] - -[node name="MapControlPanel" type="PanelContainer" node_paths=PackedStringArray("_mapmodes_grid")] -editor_description = "SS-103, UI-548" -mouse_force_pass_scroll_events = false -script = ExtResource("1_ign64") -_mapmodes_grid = NodePath("MapPanelMargin/MapPanelList/MapDisplayList/MapmodesGrid") - -[node name="MapPanelMargin" type="MarginContainer" parent="."] -layout_mode = 2 -theme_override_constants/margin_left = 5 -theme_override_constants/margin_top = 5 -theme_override_constants/margin_right = 5 -theme_override_constants/margin_bottom = 5 - -[node name="MapPanelList" type="HBoxContainer" parent="MapPanelMargin"] -layout_mode = 2 -theme_override_constants/separation = 6 -alignment = 1 - -[node name="MapDisplayList" type="VBoxContainer" parent="MapPanelMargin/MapPanelList"] -layout_mode = 2 -alignment = 1 - -[node name="MapmodesGrid" type="GridContainer" parent="MapPanelMargin/MapPanelList/MapDisplayList"] -editor_description = "UI-750" -layout_mode = 2 -columns = 7 - -[node name="Minimap" type="PanelContainer" parent="MapPanelMargin/MapPanelList/MapDisplayList"] -editor_description = "UI-549" -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 -mouse_filter = 1 - -[node name="MinimapTexture" type="ColorRect" parent="MapPanelMargin/MapPanelList/MapDisplayList/Minimap"] -editor_description = "UI-751, FS-338" -material = SubResource("ShaderMaterial_bhuqb") -layout_mode = 2 -color = Color(0.921569, 0.835294, 0.701961, 1) - -[node name="ViewportQuad" type="Control" parent="MapPanelMargin/MapPanelList/MapDisplayList/Minimap" node_paths=PackedStringArray("_minimap_texture")] -layout_mode = 2 -mouse_filter = 1 -script = ExtResource("3_s4dml") -_minimap_texture = NodePath("../MinimapTexture") - -[node name="AuxiliaryPanel" type="VBoxContainer" parent="MapPanelMargin/MapPanelList"] -editor_description = "UI-761" -layout_mode = 2 - -[node name="GameSessionMenuButton" type="Button" parent="MapPanelMargin/MapPanelList/AuxiliaryPanel"] -editor_description = "UI-9" -layout_mode = 2 -focus_mode = 0 -mouse_filter = 1 -shortcut = SubResource("Shortcut_fc1tk") -text = "ESC" - -[node name="LedgerButton" type="Button" parent="MapPanelMargin/MapPanelList/AuxiliaryPanel"] -editor_description = "UI-860" -layout_mode = 2 -focus_mode = 0 -mouse_filter = 1 -text = "L" - -[node name="SearchButton" type="Button" parent="MapPanelMargin/MapPanelList/AuxiliaryPanel"] -editor_description = "UI-861" -layout_mode = 2 -focus_mode = 0 -mouse_filter = 1 -text = "F" - -[node name="ZoomButtonsContainer" type="HBoxContainer" parent="MapPanelMargin/MapPanelList/AuxiliaryPanel"] -layout_mode = 2 -alignment = 1 - -[node name="ZoomInButton" type="Button" parent="MapPanelMargin/MapPanelList/AuxiliaryPanel/ZoomButtonsContainer"] -editor_description = "UI-862" -layout_mode = 2 -focus_mode = 0 -mouse_filter = 1 -text = "+" - -[node name="ZoomOutButton" type="Button" parent="MapPanelMargin/MapPanelList/AuxiliaryPanel/ZoomButtonsContainer"] -editor_description = "UI-863" -layout_mode = 2 -focus_mode = 0 -mouse_filter = 1 -text = "-" - -[connection signal="map_view_camera_changed" from="." to="MapPanelMargin/MapPanelList/MapDisplayList/Minimap/ViewportQuad" method="_on_map_view_camera_changed"] -[connection signal="minimap_clicked" from="MapPanelMargin/MapPanelList/MapDisplayList/Minimap/ViewportQuad" to="." method="_on_minimap_clicked"] -[connection signal="pressed" from="MapPanelMargin/MapPanelList/AuxiliaryPanel/GameSessionMenuButton" to="." method="_on_game_session_menu_button_pressed"] -[connection signal="pressed" from="MapPanelMargin/MapPanelList/AuxiliaryPanel/SearchButton" to="." method="_on_search_button_pressed"] -[connection signal="pressed" from="MapPanelMargin/MapPanelList/AuxiliaryPanel/ZoomButtonsContainer/ZoomInButton" to="." method="_on_zoom_in_button_pressed"] -[connection signal="pressed" from="MapPanelMargin/MapPanelList/AuxiliaryPanel/ZoomButtonsContainer/ZoomOutButton" to="." method="_on_zoom_out_button_pressed"] diff --git a/game/src/Game/GameSession/MapControlPanel/Minimap.gd b/game/src/Game/GameSession/MapControlPanel/Minimap.gd deleted file mode 100644 index 7cf1794..0000000 --- a/game/src/Game/GameSession/MapControlPanel/Minimap.gd +++ /dev/null @@ -1,105 +0,0 @@ -extends Control - -signal minimap_clicked(pos_clicked : Vector2) - -const _action_click : StringName = &"map_click" - -@export var _minimap_texture : Control -var _minimap_shader : ShaderMaterial - -var _viewport_points : PackedVector2Array - -func _ready() -> void: - _minimap_texture.custom_minimum_size = Vector2(GameSingleton.get_map_aspect_ratio(), 1.0) * 150 - var minimap_material := _minimap_texture.get_material() - if GameLoader.ShaderManager.set_up_shader(minimap_material, false) != OK: - push_error("Failed to set up minimap shader") - else: - _minimap_shader = minimap_material - GameSingleton.province_selected.connect(_on_province_selected) - -func _on_province_selected(index : int) -> void: - if _minimap_shader != null: - _minimap_shader.set_shader_parameter(GameLoader.ShaderManager.param_selected_index, index) - -# REQUIREMENTS -# * SS-80 -# * UI-752 -func _draw() -> void: - if _viewport_points.size() > 1: - draw_multiline(_viewport_points, Color.WHITE, -1) - -# REQUIREMENTS -# * SS-81 -# * UIFUN-127 -func _gui_input(event : InputEvent) -> void: - if Input.is_action_pressed(_action_click): - var pos_clicked := get_local_mouse_position() / size - Vector2(0.5, 0.5) - if abs(pos_clicked.x) < 0.5 and abs(pos_clicked.y) < 0.5: - minimap_clicked.emit(pos_clicked) - -# Returns the point on the line going through p and q with the specific x coord -func _intersect_x(p : Vector2, q : Vector2, x : float) -> Vector2: - if p.x == q.x: - return Vector2(x, 0.5 * (p.y + q.y)) - var t := (x - q.x) / (p.x - q.x) - return q + t * (p - q) - -# Returns the point on the line going through p and q with the specific y coord -func _intersect_y(p : Vector2, q : Vector2, y : float) -> Vector2: - if p.y == q.y: - return Vector2(0.5 * (p.x + q.x), y) - var t := (y - q.y) / (p.y - q.y) - return q + t * (p - q) - -const _one_x := Vector2(1, 0) - -func _add_line_looped_over_x(left : Vector2, right : Vector2) -> void: - if left.x < 0: - if right.x < 0: - _viewport_points.push_back(left + _one_x) - _viewport_points.push_back(right + _one_x) - else: - var mid_point := _intersect_x(left, right, 0) - _viewport_points.push_back(mid_point) - _viewport_points.push_back(right) - mid_point.x = 1 - _viewport_points.push_back(left + _one_x) - _viewport_points.push_back(mid_point) - elif right.x > 1: - if left.x > 1: - _viewport_points.push_back(left - _one_x) - _viewport_points.push_back(right - _one_x) - else: - var mid_point := _intersect_x(left, right, 1) - _viewport_points.push_back(left) - _viewport_points.push_back(mid_point) - mid_point.x = 0 - _viewport_points.push_back(mid_point) - _viewport_points.push_back(right - _one_x) - else: - _viewport_points.push_back(left) - _viewport_points.push_back(right) - -# This can break if the viewport is rotated too far! -func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -> void: - # Bound far y coords - if far_left.y < 0: - far_left = _intersect_y(near_left, far_left, 0) - if far_right.y < 0: - far_right = _intersect_y(near_right, far_right, 0) - # Bound near y coords - if near_left.y > 1: - near_left = _intersect_y(near_left, far_left, 1) - if near_right.y > 1: - near_right = _intersect_y(near_right, far_right, 1) - - _viewport_points.clear() - _add_line_looped_over_x(near_left, near_right) - _add_line_looped_over_x(far_left, far_right) - _add_line_looped_over_x(far_left, near_left) - _add_line_looped_over_x(near_right, far_right) - - for i : int in _viewport_points.size(): - _viewport_points[i] *= size - queue_redraw() diff --git a/game/src/Game/GameSession/MapControlPanel/Minimap.gdshader b/game/src/Game/GameSession/MapControlPanel/Minimap.gdshader deleted file mode 100644 index 271b809..0000000 --- a/game/src/Game/GameSession/MapControlPanel/Minimap.gdshader +++ /dev/null @@ -1,18 +0,0 @@ -shader_type canvas_item; - -#include "res://src/Game/GameSession/ProvinceIndexSampler.gdshaderinc" - -// Index of the currently selected province -uniform uint selected_index; - -const vec3 land_colour = vec3(0.5); -const vec3 selected_colour = vec3(1.0, 1.0, 0.0); - -void fragment() { - uvec3 data = read_uvec3(UV); - uint index = uvec2_to_uint(data.rg); - float is_land = float(data.b != 0u); - float is_selected = float(index == selected_index); - COLOR.rgb = mix(COLOR.rgb, land_colour, is_land); - COLOR.rgb = mix(COLOR.rgb, selected_colour, is_selected); -} diff --git a/game/src/Game/GameSession/Menubar/Menubar.gd b/game/src/Game/GameSession/Menubar/Menubar.gd new file mode 100644 index 0000000..b6b18b0 --- /dev/null +++ b/game/src/Game/GameSession/Menubar/Menubar.gd @@ -0,0 +1,113 @@ +extends GUINode + +signal game_session_menu_button_pressed +signal search_button_pressed +signal map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) +signal zoom_in_button_pressed +signal zoom_out_button_pressed + +@export var _mapmodes_grid : GridContainer + +var _mapmode_button_group : ButtonGroup + +# REQUIREMENTS: +# * UI-550, UI-552, UI-554, UI-561, UI-562, UI-563 +func _add_mapmode_button(identifier : String) -> void: + pass + #var button := Button.new() + #button.text = identifier + #button.tooltip_text = identifier + #button.toggle_mode = true + #button.button_group = _mapmode_button_group + #button.mouse_filter = MOUSE_FILTER_PASS + #button.focus_mode = FOCUS_NONE + #_mapmodes_grid.add_child(button) + #if _mapmode_button_group.get_pressed_button() == null: + # button.button_pressed = true + +func _ready() -> void: + add_gui_element("menubar", "menubar") + + hide_nodes([ + ^"./menubar/messagelog_window", #todo + ^"./menubar/OPENbutton", # not quite sure what this is + ^"./menubar/menubar_plans_toggle", #todo + ^"./menubar/menubar_plans_open", #todo + ^"./menubar/menubar_mail_bg", #todo + ^"./menubar/menubar_msg_diplo", #todo + ^"./menubar/menubar_msg_settings", #todo + ^"./menubar/menubar_msg_combat", #todo + ^"./menubar/menubar_msg_diplo", #todo + ^"./menubar/menubar_msg_unit", #todo + ^"./menubar/menubar_msg_province", #todo + ^"./menubar/menubar_msg_event", #todo + ^"./menubar/menubar_msg_other", #todo + ^"./menubar/chat_window", #todo + ]) + + var menubar: Panel = get_panel_from_nodepath(^"./menubar") + if menubar: + menubar.mouse_filter = Control.MOUSE_FILTER_IGNORE + var minimap_bg: GUIIcon = get_gui_icon_from_nodepath(^"./menubar/minimap_bg") + if minimap_bg: + minimap_bg.mouse_filter = Control.MOUSE_FILTER_PASS + var menubar_bg: GUIIcon = get_gui_icon_from_nodepath(^"./menubar/menubar_bg") + if menubar_bg: + menubar_bg.mouse_filter = Control.MOUSE_FILTER_PASS + + var menu_button: GUIButton = get_gui_icon_button_from_nodepath(^"./menubar/menu_button") + if menu_button: + menu_button.pressed.connect(_on_game_session_menu_button_pressed) + + var search_button: GUIButton = get_gui_icon_button_from_nodepath(^"./menubar/button_goto") + if search_button: + search_button.pressed.connect(_on_search_button_pressed) + + var zoom_in_button: GUIButton = get_gui_icon_button_from_nodepath(^"./menubar/map_zoom_in") + if zoom_in_button: + zoom_in_button.pressed.connect(_on_zoom_in_button_pressed) + + var zoom_out_button: GUIButton = get_gui_icon_button_from_nodepath(^"./menubar/map_zoom_out") + if zoom_out_button: + zoom_out_button.pressed.connect(_on_zoom_out_button_pressed) + + add_gui_element("menubar", "minimap_pic") + var minimap_pic: GUIIcon = get_node(^"./minimap_pic") + var minimap_rect: Control = get_node(^"./MinimapRect") + minimap_rect.move_to_front() + if minimap_pic: + minimap_rect.custom_minimum_size = minimap_pic.size + minimap_rect.position = minimap_pic.position + minimap_pic.size + minimap_pic.queue_free() + + #_mapmode_button_group = ButtonGroup.new() + #_mapmode_button_group.pressed.connect(_mapmode_pressed) + #for index : int in GameSingleton.get_mapmode_count(): + # _add_mapmode_button(GameSingleton.get_mapmode_identifier(index)) + +# REQUIREMENTS: +# * UIFUN-10 +func _on_game_session_menu_button_pressed() -> void: + game_session_menu_button_pressed.emit() + +func _on_search_button_pressed() -> void: + search_button_pressed.emit() + +# REQUIREMENTS: +# * SS-76 +# * UIFUN-129, UIFUN-131, UIFUN-133, UIFUN-140, UIFUN-141, UIFUN-142 +func _mapmode_pressed(button : BaseButton) -> void: + GameSingleton.set_mapmode(button.tooltip_text) + +func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -> void: + map_view_camera_changed.emit(near_left, far_left, far_right, near_right) + +# REQUIREMENTS: +# * UIFUN-269 +func _on_zoom_in_button_pressed() -> void: + zoom_in_button_pressed.emit() + +# REQUIREMENTS: +# * UIFUN-270 +func _on_zoom_out_button_pressed() -> void: + zoom_out_button_pressed.emit() diff --git a/game/src/Game/GameSession/Menubar/Minimap.gd b/game/src/Game/GameSession/Menubar/Minimap.gd new file mode 100644 index 0000000..3b69147 --- /dev/null +++ b/game/src/Game/GameSession/Menubar/Minimap.gd @@ -0,0 +1,104 @@ +extends Control + +signal minimap_clicked(pos_clicked : Vector2) + +const _action_click : StringName = &"map_click" + +var _minimap_shader : ShaderMaterial + +var _viewport_points : PackedVector2Array + +func _ready() -> void: + custom_minimum_size = Vector2(GameSingleton.get_map_aspect_ratio(), 1.0) * 150 + var minimap_material := get_material() + if GameLoader.ShaderManager.set_up_shader(minimap_material, false) != OK: + push_error("Failed to set up minimap shader") + else: + _minimap_shader = minimap_material + GameSingleton.province_selected.connect(_on_province_selected) + +func _on_province_selected(index : int) -> void: + if _minimap_shader != null: + _minimap_shader.set_shader_parameter(GameLoader.ShaderManager.param_selected_index, index) + +# REQUIREMENTS +# * SS-80 +# * UI-752 +func _draw() -> void: + if _viewport_points.size() > 1: + draw_multiline(_viewport_points, Color.WHITE, -1) + +# REQUIREMENTS +# * SS-81 +# * UIFUN-127 +func _gui_input(_event : InputEvent) -> void: + if Input.is_action_pressed(_action_click): + var pos_clicked := get_local_mouse_position() / size - Vector2(0.5, 0.5) + if abs(pos_clicked.x) < 0.5 and abs(pos_clicked.y) < 0.5: + minimap_clicked.emit(pos_clicked) + +# Returns the point on the line going through p and q with the specific x coord +func _intersect_x(p : Vector2, q : Vector2, x : float) -> Vector2: + if p.x == q.x: + return Vector2(x, 0.5 * (p.y + q.y)) + var t := (x - q.x) / (p.x - q.x) + return q + t * (p - q) + +# Returns the point on the line going through p and q with the specific y coord +func _intersect_y(p : Vector2, q : Vector2, y : float) -> Vector2: + if p.y == q.y: + return Vector2(0.5 * (p.x + q.x), y) + var t := (y - q.y) / (p.y - q.y) + return q + t * (p - q) + +const _one_x := Vector2(1, 0) + +func _add_line_looped_over_x(left : Vector2, right : Vector2) -> void: + if left.x < 0: + if right.x < 0: + _viewport_points.push_back(left + _one_x) + _viewport_points.push_back(right + _one_x) + else: + var mid_point := _intersect_x(left, right, 0) + _viewport_points.push_back(mid_point) + _viewport_points.push_back(right) + mid_point.x = 1 + _viewport_points.push_back(left + _one_x) + _viewport_points.push_back(mid_point) + elif right.x > 1: + if left.x > 1: + _viewport_points.push_back(left - _one_x) + _viewport_points.push_back(right - _one_x) + else: + var mid_point := _intersect_x(left, right, 1) + _viewport_points.push_back(left) + _viewport_points.push_back(mid_point) + mid_point.x = 0 + _viewport_points.push_back(mid_point) + _viewport_points.push_back(right - _one_x) + else: + _viewport_points.push_back(left) + _viewport_points.push_back(right) + +# This can break if the viewport is rotated too far! +func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -> void: + # Bound far y coords + if far_left.y < 0: + far_left = _intersect_y(near_left, far_left, 0) + if far_right.y < 0: + far_right = _intersect_y(near_right, far_right, 0) + # Bound near y coords + if near_left.y > 1: + near_left = _intersect_y(near_left, far_left, 1) + if near_right.y > 1: + near_right = _intersect_y(near_right, far_right, 1) + + _viewport_points.clear() + _add_line_looped_over_x(near_left, near_right) + _add_line_looped_over_x(far_left, far_right) + _add_line_looped_over_x(far_left, near_left) + _add_line_looped_over_x(near_right, far_right) + + for i : int in _viewport_points.size(): + _viewport_points[i] *= size + queue_redraw() diff --git a/game/src/Game/GameSession/Menubar/Minimap.gdshader b/game/src/Game/GameSession/Menubar/Minimap.gdshader new file mode 100644 index 0000000..271b809 --- /dev/null +++ b/game/src/Game/GameSession/Menubar/Minimap.gdshader @@ -0,0 +1,18 @@ +shader_type canvas_item; + +#include "res://src/Game/GameSession/ProvinceIndexSampler.gdshaderinc" + +// Index of the currently selected province +uniform uint selected_index; + +const vec3 land_colour = vec3(0.5); +const vec3 selected_colour = vec3(1.0, 1.0, 0.0); + +void fragment() { + uvec3 data = read_uvec3(UV); + uint index = uvec2_to_uint(data.rg); + float is_land = float(data.b != 0u); + float is_selected = float(index == selected_index); + COLOR.rgb = mix(COLOR.rgb, land_colour, is_land); + COLOR.rgb = mix(COLOR.rgb, selected_colour, is_selected); +} -- cgit v1.2.3-56-ga3b1