diff options
Diffstat (limited to 'game/src')
-rw-r--r-- | game/src/Autoload/Events.gd | 3 | ||||
-rw-r--r-- | game/src/GameSession/GameSession.tscn | 1 | ||||
-rw-r--r-- | game/src/GameSession/MapControlPanel.gd | 26 | ||||
-rw-r--r-- | game/src/GameSession/MapControlPanel.tscn | 7 | ||||
-rw-r--r-- | game/src/GameSession/MapView.gd | 67 | ||||
-rw-r--r-- | game/src/GameSession/TerrainMap.gdshader | 2 |
6 files changed, 76 insertions, 30 deletions
diff --git a/game/src/Autoload/Events.gd b/game/src/Autoload/Events.gd index 040cb06..c2f96d5 100644 --- a/game/src/Autoload/Events.gd +++ b/game/src/Autoload/Events.gd @@ -4,10 +4,13 @@ var Options = preload("Events/Options.gd").new() var Localisation = preload("Events/Localisation.gd").new() const _province_identifier_file : String = "res://common/map/provinces.json" +const _region_file : String = "res://common/map/regions.json" const _province_shape_file : String = "res://common/map/provinces.png" func _ready(): if MapSingleton.load_province_identifier_file(_province_identifier_file) != OK: push_error("Failed to load province identifiers") + if MapSingleton.load_region_file(_region_file) != OK: + push_error("Failed to load regions") if MapSingleton.load_province_shape_file(_province_shape_file) != OK: push_error("Failed to load province shapes") diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn index ca24256..dc3ab75 100644 --- a/game/src/GameSession/GameSession.tscn +++ b/game/src/GameSession/GameSession.tscn @@ -86,3 +86,4 @@ offset_right = 0.0 [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="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"] diff --git a/game/src/GameSession/MapControlPanel.gd b/game/src/GameSession/MapControlPanel.gd index ad56536..cfd102c 100644 --- a/game/src/GameSession/MapControlPanel.gd +++ b/game/src/GameSession/MapControlPanel.gd @@ -1,8 +1,32 @@ extends PanelContainer signal game_session_menu_button_pressed +signal mapmode_changed + +@export var _mapmodes_grid : GridContainer +var _mapmode_button_group : ButtonGroup + +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 + _mapmodes_grid.add_child(button) + if _mapmode_button_group.get_pressed_button() == null: + button.button_pressed = true + +func _ready(): + _mapmode_button_group = ButtonGroup.new() + _mapmode_button_group.pressed.connect(_mapmode_pressed) + for index in MapSingleton.get_mapmode_count(): + _add_mapmode_button(MapSingleton.get_mapmode_identifier(index)) # REQUIREMENTS: # * UIFUN-10 -func _on_game_session_menu_button_pressed(): +func _on_game_session_menu_button_pressed() -> void: game_session_menu_button_pressed.emit() + +func _mapmode_pressed(button : BaseButton) -> void: + MapSingleton.set_mapmode(button.tooltip_text) + mapmode_changed.emit() diff --git a/game/src/GameSession/MapControlPanel.tscn b/game/src/GameSession/MapControlPanel.tscn index 2a0c971..e0ba0b2 100644 --- a/game/src/GameSession/MapControlPanel.tscn +++ b/game/src/GameSession/MapControlPanel.tscn @@ -8,9 +8,10 @@ action = &"ui_cancel" [sub_resource type="Shortcut" id="Shortcut_fc1tk"] events = [SubResource("InputEventAction_5nck3")] -[node name="PanelContainer" type="PanelContainer"] +[node name="PanelContainer" type="PanelContainer" node_paths=PackedStringArray("_mapmodes_grid")] editor_description = "SS-103" script = ExtResource("1_ign64") +_mapmodes_grid = NodePath("HBoxContainer/VBoxContainer/MapmodesGrid") [node name="HBoxContainer" type="HBoxContainer" parent="."] layout_mode = 2 @@ -18,9 +19,9 @@ layout_mode = 2 [node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"] layout_mode = 2 -[node name="MapmodesPlaceholder" type="Label" parent="HBoxContainer/VBoxContainer"] +[node name="MapmodesGrid" type="GridContainer" parent="HBoxContainer/VBoxContainer"] layout_mode = 2 -text = "MAPMODES" +columns = 11 [node name="MinimapPlaceholder" type="Label" parent="HBoxContainer/VBoxContainer"] layout_mode = 2 diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd index 77fea96..2a60539 100644 --- a/game/src/GameSession/MapView.gd +++ b/game/src/GameSession/MapView.gd @@ -20,7 +20,7 @@ const _shader_param_selected_pos : StringName = &"selected_pos" @export var _camera : Camera3D @export var _cardinal_move_speed : float = 1.0 -@export var _edge_move_threshold: float = 0.15 +@export var _edge_move_threshold: float = 0.02 @export var _edge_move_speed: float = 2.5 var _drag_anchor : Vector2 var _drag_active : bool = false @@ -39,6 +39,8 @@ var _map_mesh : MapMesh var _map_shader_material : ShaderMaterial var _map_image_size : Vector2 var _map_province_index_image : Image +var _map_province_colour_image : Image +var _map_province_colour_texture : ImageTexture var _map_mesh_corner : Vector2 var _map_mesh_dims : Vector2 @@ -46,6 +48,13 @@ var _mouse_pos_viewport : Vector2 = Vector2(0.5, 0.5) var _mouse_pos_map : Vector2 = Vector2(0.5, 0.5) var _viewport_dims : Vector2 = Vector2(1, 1) +# ??? Strange Godot/GDExtension Bug ??? +# Upon first opening a clone of this repo with the Godot Editor, +# if MapSingleton.get_province_index_image is called before MapMesh +# is referenced in the script below, then the editor will crash due +# 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 _ready(): if _camera == null: push_error("MapView's _camera variable hasn't been set!") @@ -54,25 +63,9 @@ func _ready(): if _map_mesh_instance == null: push_error("MapView's _map_mesh variable hasn't been set!") return - if not _map_mesh_instance.mesh is MapMesh: - push_error("Invalid map mesh class: ", _map_mesh_instance.mesh.get_class(), "(expected MapMesh)") - return - _map_mesh = _map_mesh_instance.mesh - # Set map mesh size and get bounds - _map_image_size = Vector2(Vector2i(MapSingleton.get_width(), MapSingleton.get_height())) - _map_mesh.aspect_ratio = _map_image_size.x / _map_image_size.y - 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), - min(map_mesh_aabb.position.z, map_mesh_aabb.end.z) - ) - _map_mesh_dims = abs(Vector2( - map_mesh_aabb.position.x - map_mesh_aabb.end.x, - map_mesh_aabb.position.z - map_mesh_aabb.end.z - )) - - var map_material = _map_mesh_instance.get_active_material(0) + # Shader Material + var map_material := _map_mesh_instance.get_active_material(0) if map_material == null: push_error("Map mesh is missing material!") return @@ -80,6 +73,7 @@ func _ready(): push_error("Invalid map mesh material class: ", map_material.get_class()) return _map_shader_material = map_material + # Province index texture _map_province_index_image = MapSingleton.get_province_index_image() if _map_province_index_image == null: @@ -87,13 +81,36 @@ func _ready(): return var province_index_texture := ImageTexture.create_from_image(_map_province_index_image) _map_shader_material.set_shader_parameter(_shader_param_province_index, province_index_texture) + # Province colour texture - var province_colour_image = MapSingleton.get_province_colour_image() - if province_colour_image == null: + _map_province_colour_image = MapSingleton.get_province_colour_image() + if _map_province_colour_image == null: push_error("Failed to get province colour image!") return - var province_colour_texture := ImageTexture.create_from_image(province_colour_image) - _map_shader_material.set_shader_parameter(_shader_param_province_colour, province_colour_texture) + _map_province_colour_texture = ImageTexture.create_from_image(_map_province_colour_image) + _map_shader_material.set_shader_parameter(_shader_param_province_colour, _map_province_colour_texture) + + if not _map_mesh_instance.mesh is MapMesh: + push_error("Invalid map mesh class: ", _map_mesh_instance.mesh.get_class(), "(expected MapMesh)") + return + _map_mesh = _map_mesh_instance.mesh + + # Set map mesh size and get bounds + _map_image_size = Vector2(Vector2i(MapSingleton.get_width(), MapSingleton.get_height())) + _map_mesh.aspect_ratio = _map_image_size.x / _map_image_size.y + 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), + min(map_mesh_aabb.position.z, map_mesh_aabb.end.z) + ) + _map_mesh_dims = abs(Vector2( + map_mesh_aabb.position.x - map_mesh_aabb.end.x, + map_mesh_aabb.position.z - map_mesh_aabb.end.z + )) + +func _update_colour_texture() -> void: + MapSingleton.update_colour_image() + _map_province_colour_texture.update(_map_province_colour_image) func _world_to_map_coords(pos : Vector3) -> Vector2: return (Vector2(pos.x, pos.z) - _map_mesh_corner) / _map_mesh_dims @@ -160,8 +177,8 @@ func _movement_process(delta : float) -> void: _camera.position += Vector3(direction.x, 0, direction.y) func _edge_scrolling_vector() -> Vector2: - var mouse_vector := _mouse_pos_viewport / _viewport_dims - Vector2(0.5, 0.5); - if pow(mouse_vector.x, 4) + pow(mouse_vector.y, 4) < pow(0.5 - _edge_move_threshold, 4): + 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 return mouse_vector * _edge_move_speed diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader index a6774fd..f3d0c7d 100644 --- a/game/src/GameSession/TerrainMap.gdshader +++ b/game/src/GameSession/TerrainMap.gdshader @@ -37,7 +37,7 @@ void fragment() { uint selected_index = read_uint16(province_index_tex, selected_pos); // Boost prov_colour's contribution if it matches hover_colour or selected_colour - float mix_val = float(prov_index == hover_index) * 0.3 + float(prov_index == selected_index) * 0.5; + float mix_val = 0.3 + float(prov_index == hover_index) * 0.3 + float(prov_index == selected_index) * 0.3; // Don't mix if the province index is 0 mix_val *= float(prov_index != 0u); |