aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
Diffstat (limited to 'game')
-rw-r--r--game/art/terrain/terrain.png (renamed from game/common/map/terrain/terrain.png)bin27542091 -> 27542091 bytes
-rw-r--r--game/art/terrain/terrain.png.import (renamed from game/common/map/terrain/terrain.png.import)6
-rw-r--r--game/art/ui/minimap.pngbin0 -> 69018 bytes
-rw-r--r--game/art/ui/minimap.png.import34
-rw-r--r--game/art/ui/minimap_frame.pngbin0 -> 1043 bytes
-rw-r--r--game/art/ui/minimap_frame.png.import34
-rw-r--r--game/src/GameSession/GameSession.tscn46
-rw-r--r--game/src/GameSession/MapView.gd47
-rw-r--r--game/src/GameSession/MapView.tscn4
-rw-r--r--game/src/GameSession/Minimap.gd18
10 files changed, 168 insertions, 21 deletions
diff --git a/game/common/map/terrain/terrain.png b/game/art/terrain/terrain.png
index 6d36dee..6d36dee 100644
--- a/game/common/map/terrain/terrain.png
+++ b/game/art/terrain/terrain.png
Binary files differ
diff --git a/game/common/map/terrain/terrain.png.import b/game/art/terrain/terrain.png.import
index 56ba5dc..2642176 100644
--- a/game/common/map/terrain/terrain.png.import
+++ b/game/art/terrain/terrain.png.import
@@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cmw0pvjthnn8c"
-path="res://.godot/imported/terrain.png-c443b8a709ca7acc4b3bb3df1d3095a9.ctex"
+path="res://.godot/imported/terrain.png-06c63c2b87b3131a2067f668f87a9d67.ctex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://common/map/terrain/terrain.png"
-dest_files=["res://.godot/imported/terrain.png-c443b8a709ca7acc4b3bb3df1d3095a9.ctex"]
+source_file="res://art/terrain/terrain.png"
+dest_files=["res://.godot/imported/terrain.png-06c63c2b87b3131a2067f668f87a9d67.ctex"]
[params]
diff --git a/game/art/ui/minimap.png b/game/art/ui/minimap.png
new file mode 100644
index 0000000..9e5bdb6
--- /dev/null
+++ b/game/art/ui/minimap.png
Binary files differ
diff --git a/game/art/ui/minimap.png.import b/game/art/ui/minimap.png.import
new file mode 100644
index 0000000..31da5f0
--- /dev/null
+++ b/game/art/ui/minimap.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://c0sm1jfu4kyv3"
+path="res://.godot/imported/minimap.png-05ee44469856e77fd05107fe9e259e25.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://art/ui/minimap.png"
+dest_files=["res://.godot/imported/minimap.png-05ee44469856e77fd05107fe9e259e25.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/game/art/ui/minimap_frame.png b/game/art/ui/minimap_frame.png
new file mode 100644
index 0000000..21aa2ce
--- /dev/null
+++ b/game/art/ui/minimap_frame.png
Binary files differ
diff --git a/game/art/ui/minimap_frame.png.import b/game/art/ui/minimap_frame.png.import
new file mode 100644
index 0000000..6db81bc
--- /dev/null
+++ b/game/art/ui/minimap_frame.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://vr1hq2stk8ny"
+path="res://.godot/imported/minimap_frame.png-3668393435d2582fb1dc8a9598573e80.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://art/ui/minimap_frame.png"
+dest_files=["res://.godot/imported/minimap_frame.png-3668393435d2582fb1dc8a9598573e80.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn
index a645528..dc3ab75 100644
--- a/game/src/GameSession/GameSession.tscn
+++ b/game/src/GameSession/GameSession.tscn
@@ -1,10 +1,13 @@
-[gd_scene load_steps=6 format=3 uid="uid://bgnupcshe1m7r"]
+[gd_scene load_steps=9 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"
@@ -24,14 +27,54 @@ 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
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
@@ -39,6 +82,7 @@ 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="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"]
diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd
index b13f09d..2a60539 100644
--- a/game/src/GameSession/MapView.gd
+++ b/game/src/GameSession/MapView.gd
@@ -1,6 +1,7 @@
extends Node3D
signal province_selected(identifier : String)
+signal map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2)
const _action_north : StringName = &"map_north"
const _action_east : StringName = &"map_east"
@@ -45,6 +46,7 @@ var _map_mesh_dims : Vector2
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,
@@ -57,6 +59,7 @@ func _ready():
if _camera == null:
push_error("MapView's _camera variable hasn't been set!")
return
+ _zoom_target = _camera.position.y
if _map_mesh_instance == null:
push_error("MapView's _map_mesh variable hasn't been set!")
return
@@ -109,6 +112,22 @@ 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
+
+func _viewport_to_map_coords(pos_viewport : Vector2) -> Vector2:
+ var ray_origin := _camera.project_ray_origin(pos_viewport)
+ var ray_normal := _camera.project_ray_normal(pos_viewport)
+ # Plane with normal (0,1,0) facing upwards, at a distance 0 from the origin
+ var intersection = Plane(0, 1, 0, 0).intersects_ray(ray_origin, ray_normal)
+ if typeof(intersection) == TYPE_VECTOR3:
+ return _world_to_map_coords(intersection as Vector3)
+ else:
+ # Normals parallel to the xz-plane could cause null intersections,
+ # but the camera's orientation should prevent such normals
+ push_error("Invalid intersection: ", intersection)
+ return Vector2(0.5, 0.5)
+
func _unhandled_input(event : InputEvent):
if event.is_action_pressed(_action_click):
# Check if the mouse is outside of bounds
@@ -133,6 +152,7 @@ func _unhandled_input(event : InputEvent):
func _physics_process(delta : float):
_mouse_pos_viewport = get_viewport().get_mouse_position()
+ _viewport_dims = Vector2(Resolution.get_current_resolution())
# Process movement
_movement_process(delta)
# Keep within map bounds
@@ -141,6 +161,8 @@ func _physics_process(delta : float):
_zoom_process(delta)
# Orient based on height
_update_orientation()
+ # Update viewport on minimap
+ _update_minimap_viewport()
# Calculate where the mouse lies on the map
_update_mouse_map_position()
@@ -155,8 +177,7 @@ func _movement_process(delta : float) -> void:
_camera.position += Vector3(direction.x, 0, direction.y)
func _edge_scrolling_vector() -> Vector2:
- var viewport_dims := Vector2(Resolution.get_current_resolution())
- var mouse_vector := _mouse_pos_viewport / viewport_dims - Vector2(0.5, 0.5);
+ 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
@@ -186,17 +207,13 @@ func _update_orientation() -> void:
var dir := Vector3(0, -1, -exp(-_camera.position.y * 2.0 + 0.5))
_camera.look_at(_camera.position + dir)
+func _update_minimap_viewport() -> void:
+ var near_left := _viewport_to_map_coords(Vector2(0, _viewport_dims.y))
+ var far_left := _viewport_to_map_coords(Vector2(0, 0))
+ var far_right := _viewport_to_map_coords(Vector2(_viewport_dims.x, 0))
+ var near_right := _viewport_to_map_coords(_viewport_dims)
+ map_view_camera_changed.emit(near_left, far_left, far_right, near_right)
+
func _update_mouse_map_position() -> void:
- var ray_origin := _camera.project_ray_origin(_mouse_pos_viewport)
- var ray_normal := _camera.project_ray_normal(_mouse_pos_viewport)
- # Plane with normal (0,1,0) facing upwards, at a distance 0 from the origin
- var intersection = Plane(0, 1, 0, 0).intersects_ray(ray_origin, ray_normal)
- if typeof(intersection) == TYPE_VECTOR3:
- var intersection_vec := intersection as Vector3
- # This loops both horizontally (good) and vertically (bad)
- _mouse_pos_map = (Vector2(intersection_vec.x, intersection_vec.z) - _map_mesh_corner) / _map_mesh_dims
- _map_shader_material.set_shader_parameter(_shader_param_hover_pos, _mouse_pos_map)
- else:
- # Normals parallel to the xz-plane could cause null intersections,
- # but the camera's orientation should prevent such normals
- push_error("Invalid intersection: ", intersection)
+ _mouse_pos_map = _viewport_to_map_coords(_mouse_pos_viewport)
+ _map_shader_material.set_shader_parameter(_shader_param_hover_pos, _mouse_pos_map)
diff --git a/game/src/GameSession/MapView.tscn b/game/src/GameSession/MapView.tscn
index 4650acb..f4f3a9e 100644
--- a/game/src/GameSession/MapView.tscn
+++ b/game/src/GameSession/MapView.tscn
@@ -2,7 +2,7 @@
[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://cmw0pvjthnn8c" path="res://common/map/terrain/terrain.png" id="3_l8pnf"]
+[ext_resource type="Texture2D" uid="uid://cmw0pvjthnn8c" path="res://art/terrain/terrain.png" id="3_l8pnf"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tayeg"]
render_priority = 0
@@ -19,7 +19,7 @@ _camera = NodePath("MapCamera")
_map_mesh_instance = NodePath("MapMeshInstance")
[node name="MapCamera" type="Camera3D" parent="."]
-transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 1, 1)
+transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0.25, 1.5, -2.75)
[node name="MapMeshInstance" type="MeshInstance3D" parent="."]
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
diff --git a/game/src/GameSession/Minimap.gd b/game/src/GameSession/Minimap.gd
new file mode 100644
index 0000000..dcfc343
--- /dev/null
+++ b/game/src/GameSession/Minimap.gd
@@ -0,0 +1,18 @@
+extends Control
+
+@export var _background : TextureRect
+
+var _viewport_points : PackedVector2Array
+
+func _draw() -> void:
+ if _viewport_points.size() > 1:
+ draw_polyline(_viewport_points, Color.WHITE, -1)
+
+func _on_camera_view_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -> void:
+ _viewport_points.clear()
+ _viewport_points.push_back(near_left * _background.size)
+ _viewport_points.push_back(far_left * _background.size)
+ _viewport_points.push_back(far_right * _background.size)
+ _viewport_points.push_back(near_right * _background.size)
+ _viewport_points.push_back(_viewport_points[0])
+ queue_redraw()