aboutsummaryrefslogtreecommitdiff
path: root/game/src
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-04-30 21:09:35 +0200
committer Hop311 <hop3114@gmail.com>2023-04-30 21:09:35 +0200
commitbce925ad8efa7bbf508e79cab2110416a71cb8ee (patch)
treef8ede3f3734c5c34abddd783984cc6a4b97c5810 /game/src
parent7e2700514652212e50a006ad525e7c7ca8e7840c (diff)
Highlight selected province on minimap
Diffstat (limited to 'game/src')
-rw-r--r--game/src/GameSession/GameSession.tscn1
-rw-r--r--game/src/GameSession/MapControlPanel.gd4
-rw-r--r--game/src/GameSession/MapControlPanel.tscn4
-rw-r--r--game/src/GameSession/Minimap.gd10
-rw-r--r--game/src/GameSession/Minimap.gdshader13
5 files changed, 29 insertions, 3 deletions
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn
index c146b3e..70f0583 100644
--- a/game/src/GameSession/GameSession.tscn
+++ b/game/src/GameSession/GameSession.tscn
@@ -66,6 +66,7 @@ offset_right = 0.0
grow_horizontal = 0
[connection signal="map_view_camera_changed" from="MapView" to="MapControlPanel" method="_on_map_view_camera_changed"]
+[connection signal="province_selected" from="MapView" to="MapControlPanel" method="_on_province_selected"]
[connection signal="province_selected" from="MapView" to="ProvinceOverviewPanel" method="_on_province_selected"]
[connection signal="options_button_pressed" from="GameSessionMenu" to="OptionsMenu" method="show"]
[connection signal="game_session_menu_button_pressed" from="MapControlPanel" to="." method="_on_game_session_menu_button_pressed"]
diff --git a/game/src/GameSession/MapControlPanel.gd b/game/src/GameSession/MapControlPanel.gd
index 508f692..e9249b3 100644
--- a/game/src/GameSession/MapControlPanel.gd
+++ b/game/src/GameSession/MapControlPanel.gd
@@ -3,6 +3,7 @@ extends PanelContainer
signal game_session_menu_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 province_selcted(index : int)
signal zoom_in_button_pressed
signal zoom_out_button_pressed
@@ -47,6 +48,9 @@ func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_ri
func _on_minimap_clicked(pos_clicked : Vector2) -> void:
minimap_clicked.emit(pos_clicked)
+func _on_province_selected(index : int) -> void:
+ province_selcted.emit(index)
+
# REQUIREMENTS:
# * UIFUN-269
func _on_zoom_in_button_pressed() -> void:
diff --git a/game/src/GameSession/MapControlPanel.tscn b/game/src/GameSession/MapControlPanel.tscn
index ae4c3dc..82b9c86 100644
--- a/game/src/GameSession/MapControlPanel.tscn
+++ b/game/src/GameSession/MapControlPanel.tscn
@@ -7,6 +7,7 @@
[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"
@@ -56,7 +57,7 @@ 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 = 2
+mouse_filter = 1
script = ExtResource("3_s4dml")
_minimap_texture = NodePath("../MinimapTexture")
@@ -100,6 +101,7 @@ 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="province_selcted" from="." to="MapPanelMargin/MapPanelList/MapDisplayList/Minimap/ViewportQuad" method="_on_province_selected"]
[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/ZoomButtonsContainer/ZoomInButton" to="." method="_on_zoom_in_button_pressed"]
diff --git a/game/src/GameSession/Minimap.gd b/game/src/GameSession/Minimap.gd
index 05c662b..f5d972a 100644
--- a/game/src/GameSession/Minimap.gd
+++ b/game/src/GameSession/Minimap.gd
@@ -5,13 +5,21 @@ 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():
_minimap_texture.custom_minimum_size = Vector2(GameSingleton.get_aspect_ratio(), 1.0) * 150
- if Events.ShaderManager.set_up_shader(_minimap_texture.get_material(), false) != OK:
+ var minimap_material := _minimap_texture.get_material()
+ if Events.ShaderManager.set_up_shader(minimap_material, false) != OK:
push_error("Failed to set up minimap shader")
+ else:
+ _minimap_shader = minimap_material
+
+func _on_province_selected(index : int) -> void:
+ if _minimap_shader != null:
+ _minimap_shader.set_shader_parameter(Events.ShaderManager.param_selected_index, index)
# REQUIREMENTS
# * SS-80
diff --git a/game/src/GameSession/Minimap.gdshader b/game/src/GameSession/Minimap.gdshader
index 9afd470..8b68108 100644
--- a/game/src/GameSession/Minimap.gdshader
+++ b/game/src/GameSession/Minimap.gdshader
@@ -2,6 +2,17 @@ shader_type canvas_item;
#include "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() {
- COLOR.rgb = mix(COLOR.rgb, vec3(0.5), float(read_uvec3(UV).b != 0u));
+ 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);
}