aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-09 21:51:15 +0200
committer Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-09 21:51:15 +0200
commit9c74c5d67569c7ca6c08a2f0ef5a27272332f31d (patch)
tree97aa346ff22742d5b3be668d9f804ca7a3fb36c1
parenta44253be41840ca3236dbfa5f2a46a9dd7a8d300 (diff)
Minimap functionality
Adding minimap click, cutting minimap camera edges, adding check for mouse of the window to stop parallax, also adding lock for parallax when mouse on minimap.
-rw-r--r--game/art/ui/minimap.pngbin69018 -> 122017 bytes
-rw-r--r--game/src/GameSession/GameSession.tscn50
-rw-r--r--game/src/GameSession/MapControlPanel.gd21
-rw-r--r--game/src/GameSession/MapControlPanel.tscn49
-rw-r--r--game/src/GameSession/MapView.gd30
-rw-r--r--game/src/GameSession/Minimap.gd9
6 files changed, 101 insertions, 58 deletions
diff --git a/game/art/ui/minimap.png b/game/art/ui/minimap.png
index 9e5bdb6..9922b28 100644
--- a/game/art/ui/minimap.png
+++ b/game/art/ui/minimap.png
Binary files differ
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn
index dc3ab75..76a5fcc 100644
--- a/game/src/GameSession/GameSession.tscn
+++ b/game/src/GameSession/GameSession.tscn
@@ -1,13 +1,10 @@
-[gd_scene load_steps=9 format=3 uid="uid://bgnupcshe1m7r"]
+[gd_scene load_steps=6 format=3 uid="uid://bgnupcshe1m7r"]
[ext_resource type="Script" path="res://src/GameSession/GameSession.gd" id="1_eklvp"]
[ext_resource type="PackedScene" uid="uid://g524p8lr574w" path="res://src/GameSession/MapControlPanel.tscn" id="3_afh6d"]
[ext_resource type="PackedScene" uid="uid://dvdynl6eir40o" path="res://src/GameSession/GameSessionMenu.tscn" id="3_bvmqh"]
[ext_resource type="PackedScene" uid="uid://dkehmdnuxih2r" path="res://src/GameSession/MapView.tscn" id="4_xkg5j"]
-[ext_resource type="Texture2D" uid="uid://c0sm1jfu4kyv3" path="res://art/ui/minimap.png" id="5_l05wo"]
[ext_resource type="PackedScene" uid="uid://byq323jbel48u" path="res://src/GameSession/ProvinceOverviewPanel.tscn" id="5_osjnn"]
-[ext_resource type="Texture2D" uid="uid://vr1hq2stk8ny" path="res://art/ui/minimap_frame.png" id="6_ujbv2"]
-[ext_resource type="Script" path="res://src/GameSession/Minimap.gd" id="7_go8y3"]
[node name="GameSession" type="Node" node_paths=PackedStringArray("_game_session_menu")]
editor_description = "SS-102"
@@ -27,54 +24,16 @@ grow_horizontal = 2
grow_vertical = 2
[node name="MapControlPanel" parent="." instance=ExtResource("3_afh6d")]
-offset_left = 1147.0
-offset_top = 486.0
-offset_right = 1280.0
-offset_bottom = 542.0
-grow_horizontal = 0
-grow_vertical = 0
-
-[node name="Minimap" type="Control" parent="."]
-layout_mode = 3
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -350.0
-offset_top = -175.0
+offset_top = -210.0
grow_horizontal = 0
grow_vertical = 0
-[node name="TextureRect" type="TextureRect" parent="Minimap"]
-layout_mode = 0
-offset_right = 350.0
-offset_bottom = 175.0
-texture = ExtResource("5_l05wo")
-
-[node name="RectangularCamera" type="Control" parent="Minimap" node_paths=PackedStringArray("_background")]
-anchors_preset = 0
-offset_right = 40.0
-offset_bottom = 40.0
-mouse_filter = 2
-script = ExtResource("7_go8y3")
-_background = NodePath("../TextureRect")
-
-[node name="Frame" type="NinePatchRect" parent="Minimap"]
-layout_mode = 1
-anchors_preset = 8
-anchor_left = 0.5
-anchor_top = 0.5
-anchor_right = 0.5
-anchor_bottom = 0.5
-offset_left = -175.0
-offset_top = -87.5
-offset_right = 175.0
-offset_bottom = 87.5
-grow_horizontal = 2
-grow_vertical = 2
-texture = ExtResource("6_ujbv2")
-
[node name="ProvinceOverviewPanel" parent="." instance=ExtResource("5_osjnn")]
anchors_preset = -1
anchor_top = 0.583333
@@ -82,8 +41,11 @@ anchor_right = 0.15625
offset_top = 0.0
offset_right = 0.0
-[connection signal="map_view_camera_changed" from="MapView" to="Minimap/RectangularCamera" method="_on_camera_view_changed"]
+[connection signal="map_view_camera_changed" from="MapView" to="MapControlPanel" method="_on_map_view_map_view_camera_changed"]
[connection signal="province_selected" from="MapView" to="ProvinceOverviewPanel" method="_on_province_selected"]
[connection signal="close_button_pressed" from="GameSessionMenu" to="." method="_on_game_session_menu_close_button_pressed"]
+[connection signal="camera_change" from="MapControlPanel" to="MapView" method="_on_map_control_panel_camera_change"]
[connection signal="game_session_menu_button_pressed" from="MapControlPanel" to="." method="_on_game_session_menu_button_pressed"]
[connection signal="mapmode_changed" from="MapControlPanel" to="MapView" method="_update_colour_texture"]
+[connection signal="mouse_entered" from="MapControlPanel" to="MapView" method="_on_map_control_panel_mouse_entered"]
+[connection signal="mouse_exited" from="MapControlPanel" to="MapView" method="_on_map_control_panel_mouse_exited"]
diff --git a/game/src/GameSession/MapControlPanel.gd b/game/src/GameSession/MapControlPanel.gd
index cfd102c..b9aaaeb 100644
--- a/game/src/GameSession/MapControlPanel.gd
+++ b/game/src/GameSession/MapControlPanel.gd
@@ -2,8 +2,16 @@ extends PanelContainer
signal game_session_menu_button_pressed
signal mapmode_changed
+signal camera_change(_camera_pos_clicked: Vector2)
+
+const _action_click : StringName = &"map_click"
@export var _mapmodes_grid : GridContainer
+@export var _minimap : PanelContainer
+@onready var _map_camera : Control = _minimap.get_node("RectangularCamera")
+
+var _mouse_inside: bool = false
+
var _mapmode_button_group : ButtonGroup
func _add_mapmode_button(identifier : String) -> void:
@@ -30,3 +38,16 @@ func _on_game_session_menu_button_pressed() -> void:
func _mapmode_pressed(button : BaseButton) -> void:
MapSingleton.set_mapmode(button.tooltip_text)
mapmode_changed.emit()
+
+func _on_map_view_map_view_camera_changed(near_left, far_left, far_right, near_right):
+ _map_camera._on_camera_view_changed(near_left, far_left, far_right, near_right)
+
+func _process(delta):
+ if _mouse_inside and Input.is_action_pressed(_action_click):
+ camera_change.emit($VBoxContainer/Minimap.get_local_mouse_position())
+
+func _on_minimap_mouse_entered():
+ _mouse_inside = true
+
+func _on_minimap_mouse_exited():
+ _mouse_inside = false
diff --git a/game/src/GameSession/MapControlPanel.tscn b/game/src/GameSession/MapControlPanel.tscn
index e0ba0b2..daf0c96 100644
--- a/game/src/GameSession/MapControlPanel.tscn
+++ b/game/src/GameSession/MapControlPanel.tscn
@@ -1,6 +1,9 @@
-[gd_scene load_steps=4 format=3 uid="uid://g524p8lr574w"]
+[gd_scene load_steps=7 format=3 uid="uid://g524p8lr574w"]
[ext_resource type="Script" path="res://src/GameSession/MapControlPanel.gd" id="1_ign64"]
+[ext_resource type="Texture2D" uid="uid://c0sm1jfu4kyv3" path="res://art/ui/minimap.png" id="2_r613r"]
+[ext_resource type="Script" path="res://src/GameSession/Minimap.gd" id="3_s4dml"]
+[ext_resource type="Texture2D" uid="uid://vr1hq2stk8ny" path="res://art/ui/minimap_frame.png" id="4_f1exl"]
[sub_resource type="InputEventAction" id="InputEventAction_5nck3"]
action = &"ui_cancel"
@@ -8,33 +11,55 @@ action = &"ui_cancel"
[sub_resource type="Shortcut" id="Shortcut_fc1tk"]
events = [SubResource("InputEventAction_5nck3")]
-[node name="PanelContainer" type="PanelContainer" node_paths=PackedStringArray("_mapmodes_grid")]
+[node name="PanelContainer" type="PanelContainer" node_paths=PackedStringArray("_mapmodes_grid", "_minimap")]
editor_description = "SS-103"
+mouse_filter = 1
script = ExtResource("1_ign64")
-_mapmodes_grid = NodePath("HBoxContainer/VBoxContainer/MapmodesGrid")
+_mapmodes_grid = NodePath("VBoxContainer/HBoxContainer/VBoxContainer/MapmodesGrid")
+_minimap = NodePath("VBoxContainer/Minimap")
-[node name="HBoxContainer" type="HBoxContainer" parent="."]
+[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2
-[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
+[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
+alignment = 2
-[node name="MapmodesGrid" type="GridContainer" parent="HBoxContainer/VBoxContainer"]
+[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
-columns = 11
-[node name="MinimapPlaceholder" type="Label" parent="HBoxContainer/VBoxContainer"]
+[node name="MapmodesGrid" type="GridContainer" parent="VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
-text = "MINIMAP"
+columns = 11
-[node name="AuxiliaryPanel" type="VBoxContainer" parent="HBoxContainer"]
+[node name="AuxiliaryPanel" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
editor_description = "UI-761"
layout_mode = 2
-[node name="GameSessionMenuButton" type="Button" parent="HBoxContainer/AuxiliaryPanel"]
+[node name="GameSessionMenuButton" type="Button" parent="VBoxContainer/HBoxContainer/AuxiliaryPanel"]
editor_description = "UI-9"
layout_mode = 2
shortcut = SubResource("Shortcut_fc1tk")
text = "ESC"
-[connection signal="pressed" from="HBoxContainer/AuxiliaryPanel/GameSessionMenuButton" to="." method="_on_game_session_menu_button_pressed"]
+[node name="Minimap" type="PanelContainer" parent="VBoxContainer"]
+layout_mode = 2
+mouse_filter = 1
+
+[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Minimap"]
+layout_mode = 2
+texture = ExtResource("2_r613r")
+
+[node name="RectangularCamera" type="Control" parent="VBoxContainer/Minimap" node_paths=PackedStringArray("_background")]
+layout_mode = 2
+mouse_filter = 2
+script = ExtResource("3_s4dml")
+_background = NodePath("../TextureRect")
+
+[node name="Frame" type="NinePatchRect" parent="VBoxContainer/Minimap"]
+layout_mode = 2
+texture = ExtResource("4_f1exl")
+
+[connection signal="pressed" from="VBoxContainer/HBoxContainer/AuxiliaryPanel/GameSessionMenuButton" to="." method="_on_game_session_menu_button_pressed"]
+[connection signal="mouse_entered" from="VBoxContainer/Minimap" to="." method="_on_minimap_mouse_entered"]
+[connection signal="mouse_exited" from="VBoxContainer/Minimap" to="." method="_on_minimap_mouse_exited"]
diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd
index 2a60539..0d85706 100644
--- a/game/src/GameSession/MapView.gd
+++ b/game/src/GameSession/MapView.gd
@@ -25,6 +25,8 @@ const _shader_param_selected_pos : StringName = &"selected_pos"
var _drag_anchor : Vector2
var _drag_active : bool = false
+var _lock_movement : bool = false
+
@export var _zoom_target_min : float = 0.2
@export var _zoom_target_max : float = 5.0
@export var _zoom_target_step : float = 0.1
@@ -55,6 +57,17 @@ var _viewport_dims : Vector2 = Vector2(1, 1)
# to a failed HashMap lookup. I'm not sure if this is a bug in the
# editor, GDExtension, my own extension, or a combination of them.
# This was an absolute pain to track down. --- hop311
+
+func _notification(what):
+ # Working with MainLoop notifications system.
+ # https://godotengine.org/qa/101601/how-to-detect-when-my-application-is-not-visible
+ # https://docs.godotengine.org/en/stable/classes/class_mainloop.html#constants
+
+ if what == 1003: # Mouse out of window
+ _lock_movement = true
+ elif what == 1002: # Mouse inside window
+ _lock_movement = false
+
func _ready():
if _camera == null:
push_error("MapView's _camera variable hasn't been set!")
@@ -178,8 +191,11 @@ func _movement_process(delta : float) -> void:
func _edge_scrolling_vector() -> Vector2:
var mouse_vector := _mouse_pos_viewport / _viewport_dims - Vector2(0.5, 0.5)
- if abs(mouse_vector.x) < 0.5 - _edge_move_threshold and abs(mouse_vector.y) < 0.5 - _edge_move_threshold:
- mouse_vector *= 0
+ if _lock_movement:
+ mouse_vector = Vector2(0,0)
+ else:
+ if abs(mouse_vector.x) < 0.5 - _edge_move_threshold and abs(mouse_vector.y) < 0.5 - _edge_move_threshold:
+ mouse_vector *= 0
return mouse_vector * _edge_move_speed
func _cardinal_movement_vector() -> Vector2:
@@ -217,3 +233,13 @@ func _update_minimap_viewport() -> void:
func _update_mouse_map_position() -> void:
_mouse_pos_map = _viewport_to_map_coords(_mouse_pos_viewport)
_map_shader_material.set_shader_parameter(_shader_param_hover_pos, _mouse_pos_map)
+
+func _on_map_control_panel_mouse_entered():
+ _lock_movement = true
+
+func _on_map_control_panel_mouse_exited():
+ _lock_movement = false
+
+func _on_map_control_panel_camera_change(_camera_pos_clicked):
+ _camera.position.x = (_camera_pos_clicked.x-$"../MapControlPanel"._minimap.size.x/2)/$"../MapControlPanel"._minimap.size.x * _map_mesh_dims.x
+ _camera.position.z = (_camera_pos_clicked.y-$"../MapControlPanel"._minimap.size.y/2)/$"../MapControlPanel"._minimap.size.y * _map_mesh_dims.y
diff --git a/game/src/GameSession/Minimap.gd b/game/src/GameSession/Minimap.gd
index dcfc343..a8b0217 100644
--- a/game/src/GameSession/Minimap.gd
+++ b/game/src/GameSession/Minimap.gd
@@ -15,4 +15,13 @@ func _on_camera_view_changed(near_left : Vector2, far_left : Vector2, far_right
_viewport_points.push_back(far_right * _background.size)
_viewport_points.push_back(near_right * _background.size)
_viewport_points.push_back(_viewport_points[0])
+
+ # Cutting out of Frame part of camera polyline
+ for i in range(0,_viewport_points.size()):
+ for j in range(0,2):
+ if _viewport_points[i][j] > _background.size[j]:
+ _viewport_points[i][j] = _background.size[j]
+ elif _viewport_points[i][j] < 0:
+ _viewport_points[i][j] = 1
+
queue_redraw()