aboutsummaryrefslogtreecommitdiff
path: root/game/src/GameSession
diff options
context:
space:
mode:
Diffstat (limited to 'game/src/GameSession')
-rw-r--r--game/src/GameSession/GameSession.tscn1
-rw-r--r--game/src/GameSession/MapView.gd14
-rw-r--r--game/src/GameSession/MapView.tscn6
-rw-r--r--game/src/GameSession/ProvinceOverviewPanel.gd4
-rw-r--r--game/src/GameSession/TerrainMap.gdshader19
5 files changed, 23 insertions, 21 deletions
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn
index 98b43dd..c146b3e 100644
--- a/game/src/GameSession/GameSession.tscn
+++ b/game/src/GameSession/GameSession.tscn
@@ -74,5 +74,6 @@ grow_horizontal = 0
[connection signal="mouse_exited" from="MapControlPanel" to="MapView" method="_on_mouse_entered_viewport"]
[connection signal="zoom_in_button_pressed" from="MapControlPanel" to="MapView" method="zoom_in"]
[connection signal="zoom_out_button_pressed" from="MapControlPanel" to="MapView" method="zoom_out"]
+[connection signal="province_deselected" from="ProvinceOverviewPanel" to="MapView" method="_deselect_province"]
[connection signal="back_button_pressed" from="OptionsMenu" to="MapView" method="enable_processing"]
[connection signal="back_button_pressed" from="OptionsMenu" to="OptionsMenu" method="hide"]
diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd
index 340083f..2e2c5e6 100644
--- a/game/src/GameSession/MapView.gd
+++ b/game/src/GameSession/MapView.gd
@@ -71,7 +71,8 @@ func _ready():
# Set map mesh size and get bounds
_map_mesh.aspect_ratio = GameSingleton.get_aspect_ratio()
- _map_shader_material.set_shader_parameter(Events.ShaderManager.param_terrain_tile_factor, float(GameSingleton.get_height()) / 64.0)
+ _map_shader_material.set_shader_parameter(Events.ShaderManager.param_terrain_tile_factor,
+ float(GameSingleton.get_height()) / 128.0)
var map_mesh_aabb := _map_mesh.get_core_aabb() * _map_mesh_instance.transform
_map_mesh_corner = Vector2(
min(map_mesh_aabb.position.x, map_mesh_aabb.end.x),
@@ -111,15 +112,20 @@ func zoom_in() -> void:
func zoom_out() -> void:
_zoom_target += _zoom_target_step
+func _select_province(index : int) -> void:
+ _map_shader_material.set_shader_parameter(Events.ShaderManager.param_selected_index, index)
+ province_selected.emit(index)
+
+func _deselect_province() -> void:
+ _select_province(0)
+
# REQUIREMENTS
# * SS-31
func _unhandled_input(event : InputEvent):
if _mouse_over_viewport and event.is_action_pressed(_action_click):
# Check if the mouse is outside of bounds
if _map_mesh.is_valid_uv_coord(_mouse_pos_map):
- var selected_index := GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map)
- _map_shader_material.set_shader_parameter(Events.ShaderManager.param_selected_index, selected_index)
- province_selected.emit(selected_index)
+ _select_province(GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map))
else:
print("Clicked outside the map!")
elif event.is_action_pressed(_action_drag):
diff --git a/game/src/GameSession/MapView.tscn b/game/src/GameSession/MapView.tscn
index efbad4e..fa6ffcd 100644
--- a/game/src/GameSession/MapView.tscn
+++ b/game/src/GameSession/MapView.tscn
@@ -1,17 +1,15 @@
-[gd_scene load_steps=6 format=3 uid="uid://dkehmdnuxih2r"]
+[gd_scene load_steps=5 format=3 uid="uid://dkehmdnuxih2r"]
[ext_resource type="Script" path="res://src/GameSession/MapView.gd" id="1_exccw"]
[ext_resource type="Shader" path="res://src/GameSession/TerrainMap.gdshader" id="1_upocn"]
-[ext_resource type="Texture2D" uid="uid://ckf222w5usrsu" path="res://art/terrain/farmlands.png" id="3_47mq1"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tayeg"]
render_priority = 0
shader = ExtResource("1_upocn")
-shader_parameter/province_index_subdivisions = null
+shader_parameter/province_shape_subdivisions = null
shader_parameter/hover_index = null
shader_parameter/selected_index = null
shader_parameter/terrain_tile_factor = null
-shader_parameter/farmlands_tex = ExtResource("3_47mq1")
[sub_resource type="MapMesh" id="MapMesh_3gtsd"]
diff --git a/game/src/GameSession/ProvinceOverviewPanel.gd b/game/src/GameSession/ProvinceOverviewPanel.gd
index 17da9d0..5a914f7 100644
--- a/game/src/GameSession/ProvinceOverviewPanel.gd
+++ b/game/src/GameSession/ProvinceOverviewPanel.gd
@@ -1,5 +1,7 @@
extends PanelContainer
+signal province_deselected
+
@export var _province_name_label : Label
@export var _region_name_label : Label
@export var _life_rating_bar : ProgressBar
@@ -92,4 +94,4 @@ func _on_province_selected(index : int) -> void:
_selected_index = index
func _on_close_button_pressed() -> void:
- _selected_index = 0
+ province_deselected.emit()
diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader
index 05928f3..cab757b 100644
--- a/game/src/GameSession/TerrainMap.gdshader
+++ b/game/src/GameSession/TerrainMap.gdshader
@@ -10,27 +10,22 @@ uniform sampler2D province_colour_tex: source_color, repeat_enable, filter_neare
uniform uint hover_index;
// Index of the currently selected province
uniform uint selected_index;
-// Cosmetic farmlands terrain texture
-uniform sampler2D farmlands_tex: source_color, repeat_enable, filter_linear;
+// Cosmetic terrain textures
+uniform sampler2DArray terrain_tex: source_color, repeat_enable, filter_linear;
// The number of times the terrain textures should tile vertically
uniform float terrain_tile_factor;
-const vec3 water_colour = vec3(0, 0, 1);
-
vec3 get_terrain_colour(vec2 uv, vec2 corner, vec2 half_pixel_size, vec2 terrain_uv) {
uvec3 province_data = read_uvec3(fma(corner, half_pixel_size, uv));
+ vec4 province_colour = texelFetch(province_colour_tex, ivec2(province_data.rg), 0);
+ vec3 terrain_colour = texture(terrain_tex, vec3(terrain_uv, float(province_data.b))).rgb;
uint index = uvec2_to_uint(province_data.rg);
- float is_land = float(province_data.b != 0u);
- vec3 province_colour = texelFetch(province_colour_tex, ivec2(province_data.rg), 0).rgb;
- vec3 farmlands_colour = texture(farmlands_tex, terrain_uv).rgb;
- vec3 terrain_colour = mix(water_colour, farmlands_colour, is_land);
- float mix_val = 0.4 + float(index == hover_index) * 0.2 + float(index == selected_index) * 0.2;
- vec3 mixed_colour = mix(terrain_colour, province_colour, mix_val);
- return mixed_colour;
+ float mix_val = province_colour.a + float(index == hover_index) * 0.2 + float(index == selected_index) * 0.2;
+ return mix(terrain_colour, province_colour.rgb, mix_val);
}
vec3 mix_terrain_colour(vec2 uv) {
- vec2 map_size = vec2(textureSize(province_shape_tex, 0).xy);
+ vec2 map_size = vec2(textureSize(province_shape_tex, 0).xy) * province_shape_subdivisions;
vec2 pixel_offset = fract(fma(uv, map_size, vec2(0.5)));
vec2 half_pixel_size = 0.49 / map_size;