aboutsummaryrefslogtreecommitdiff
path: root/game/src
diff options
context:
space:
mode:
Diffstat (limited to 'game/src')
-rw-r--r--game/src/Autoload/Events.gd10
-rw-r--r--game/src/Autoload/Events/ShaderManager.gd20
-rw-r--r--game/src/GameSession/GameSession.tscn2
-rw-r--r--game/src/GameSession/MapControlPanel.gd4
-rw-r--r--game/src/GameSession/MapControlPanel.tscn4
-rw-r--r--game/src/GameSession/MapView.gd15
-rw-r--r--game/src/GameSession/MapView.tscn6
-rw-r--r--game/src/GameSession/Minimap.gd10
-rw-r--r--game/src/GameSession/Minimap.gdshader13
-rw-r--r--game/src/GameSession/ProvinceOverviewPanel.gd4
-rw-r--r--game/src/GameSession/TerrainMap.gdshader19
11 files changed, 74 insertions, 33 deletions
diff --git a/game/src/Autoload/Events.gd b/game/src/Autoload/Events.gd
index f94d338..47c3b88 100644
--- a/game/src/Autoload/Events.gd
+++ b/game/src/Autoload/Events.gd
@@ -8,7 +8,9 @@ var ShaderManager = preload("Events/ShaderManager.gd").new()
const _province_identifier_file : String = "res://common/map/provinces.json"
const _water_province_file : String = "res://common/map/water.json"
const _region_file : String = "res://common/map/regions.json"
-const _province_shape_file : String = "res://common/map/provinces.png"
+const _terrain_file : String = "res://common/map/terrain.json"
+const _province_image_file : String = "res://common/map/provinces.png"
+const _terrain_image_file : String = "res://common/map/terrain.png"
# REQUIREMENTS
# * FS-333, FS-334, FS-335, FS-341
@@ -19,5 +21,7 @@ func _ready():
push_error("Failed to load water provinces")
if GameSingleton.load_region_file(_region_file) != OK:
push_error("Failed to load regions")
- if GameSingleton.load_province_shape_file(_province_shape_file) != OK:
- push_error("Failed to load province shapes")
+ if GameSingleton.load_terrain_file(_terrain_file) != OK:
+ push_error("Failed to load terrain variants")
+ if GameSingleton.load_map_images(_province_image_file, _terrain_image_file) != OK:
+ push_error("Failed to load map images")
diff --git a/game/src/Autoload/Events/ShaderManager.gd b/game/src/Autoload/Events/ShaderManager.gd
index 96ed5b4..a503c52 100644
--- a/game/src/Autoload/Events/ShaderManager.gd
+++ b/game/src/Autoload/Events/ShaderManager.gd
@@ -1,13 +1,14 @@
extends RefCounted
-const param_province_shape : StringName = &"province_shape_tex"
+const param_province_shape_tex : StringName = &"province_shape_tex"
const param_province_shape_subdivisions : StringName = &"province_shape_subdivisions"
-const param_province_colour : StringName = &"province_colour_tex"
+const param_province_colour_tex : StringName = &"province_colour_tex"
const param_hover_index : StringName = &"hover_index"
const param_selected_index : StringName = &"selected_index"
+const param_terrain_tex : StringName = &"terrain_tex"
const param_terrain_tile_factor : StringName = &"terrain_tile_factor"
-func set_up_shader(material : Material, add_colour_texture : bool) -> Error:
+func set_up_shader(material : Material, add_cosmetic_textures : bool) -> Error:
# Shader Material
if material == null:
push_error("material is null!")
@@ -22,19 +23,26 @@ func set_up_shader(material : Material, add_colour_texture : bool) -> Error:
if province_shape_texture == null:
push_error("Failed to get province shape texture!")
return FAILED
- shader_material.set_shader_parameter(param_province_shape, province_shape_texture)
+ shader_material.set_shader_parameter(param_province_shape_tex, province_shape_texture)
var subdivisions := GameSingleton.get_province_shape_image_subdivisions()
if subdivisions.x < 1 or subdivisions.y < 1:
push_error("Invalid province shape image subdivision: ", subdivisions.x, "x", subdivisions.y)
return FAILED
shader_material.set_shader_parameter(param_province_shape_subdivisions, Vector2(subdivisions))
- if add_colour_texture:
+ if add_cosmetic_textures:
# Province colour texture
var map_province_colour_texture := GameSingleton.get_province_colour_texture()
if map_province_colour_texture == null:
push_error("Failed to get province colour image!")
return FAILED
- shader_material.set_shader_parameter(param_province_colour, map_province_colour_texture)
+ shader_material.set_shader_parameter(param_province_colour_tex, map_province_colour_texture)
+
+ # Terrain texture
+ var terrain_texture := GameSingleton.get_terrain_texture()
+ if terrain_texture == null:
+ push_error("Failed to get terrain texture!")
+ return FAILED
+ shader_material.set_shader_parameter(param_terrain_tex, terrain_texture)
return OK
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn
index 98b43dd..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"]
@@ -74,5 +75,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/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/MapView.gd b/game/src/GameSession/MapView.gd
index 340083f..e2c8519 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):
@@ -222,6 +228,7 @@ func _on_mouse_entered_viewport():
func _on_mouse_exited_viewport():
_mouse_over_viewport = false
+ _map_shader_material.set_shader_parameter(Events.ShaderManager.param_hover_index, 0)
func _on_minimap_clicked(pos_clicked : Vector2):
pos_clicked *= _map_mesh_dims
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/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);
}
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;