aboutsummaryrefslogtreecommitdiff
path: root/game/src/GameSession
diff options
context:
space:
mode:
author Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-05 01:04:40 +0200
committer Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-05 01:04:40 +0200
commitd3c7e9b27ba60550b23efb9e37cc66b91de0c795 (patch)
tree0f753afd37019984e18ca3cac74a650c7d3c040f /game/src/GameSession
parentc7def7396da00b39eced666ad360397733712bfd (diff)
Adding province overview panel and selection of province.
Diffstat (limited to 'game/src/GameSession')
-rw-r--r--game/src/GameSession/GameSession.gd2
-rw-r--r--game/src/GameSession/GameSession.tscn17
-rw-r--r--game/src/GameSession/MapView.gd67
-rw-r--r--game/src/GameSession/MapView.tscn1
-rw-r--r--game/src/GameSession/ProvinceOverviewPanel.gd13
-rw-r--r--game/src/GameSession/ProvinceOverviewPanel.tscn39
-rw-r--r--game/src/GameSession/TerrainMap.gdshader4
7 files changed, 127 insertions, 16 deletions
diff --git a/game/src/GameSession/GameSession.gd b/game/src/GameSession/GameSession.gd
index 0d69bf2..38eaba1 100644
--- a/game/src/GameSession/GameSession.gd
+++ b/game/src/GameSession/GameSession.gd
@@ -1,4 +1,4 @@
-extends Control
+extends Node
@export var _game_session_menu : Control
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn
index fb9bb3d..25a9509 100644
--- a/game/src/GameSession/GameSession.tscn
+++ b/game/src/GameSession/GameSession.tscn
@@ -1,9 +1,10 @@
-[gd_scene load_steps=5 format=3 uid="uid://bgnupcshe1m7r"]
+[gd_scene load_steps=6 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="PackedScene" uid="uid://byq323jbel48u" path="res://src/GameSession/ProvinceOverviewPanel.tscn" id="5_5gj48"]
[node name="GameSession" type="Control" node_paths=PackedStringArray("_game_session_menu")]
editor_description = "SS-102"
@@ -21,13 +22,8 @@ _game_session_menu = NodePath("GameSessionMenu")
[node name="GameSessionMenu" parent="." instance=ExtResource("3_bvmqh")]
visible = false
layout_mode = 1
-anchors_preset = 8
-anchor_left = 0.5
-anchor_top = 0.5
-anchor_right = 0.5
-anchor_bottom = 0.5
-grow_horizontal = 2
-grow_vertical = 2
+offset_right = 232.0
+offset_bottom = 74.0
[node name="MapControlPanel" parent="." instance=ExtResource("3_afh6d")]
layout_mode = 1
@@ -36,8 +32,13 @@ anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
+offset_left = -133.0
+offset_top = -56.0
grow_horizontal = 0
grow_vertical = 0
+[node name="ProvinceOverviewPanel" parent="." instance=ExtResource("5_5gj48")]
+layout_mode = 1
+
[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 982271d..958fabd 100644
--- a/game/src/GameSession/MapView.gd
+++ b/game/src/GameSession/MapView.gd
@@ -1,19 +1,29 @@
extends Node3D
+var ProvScene = preload("res://src/GameSession/ProvinceOverviewPanel.tscn")
+var ProvinceShape = MapSingleton.get_province_shape_image()
+
+@onready var viewport_size = get_viewport().size
+
const _action_north : StringName = &"map_north"
const _action_east : StringName = &"map_east"
const _action_south : StringName = &"map_south"
const _action_west : StringName = &"map_west"
const _action_zoomin : StringName = &"map_zoomin"
const _action_zoomout : StringName = &"map_zoomout"
-
+const _action_drag : StringName = &"map_drag"
+const _action_click : StringName = &"map_click"
const _shader_param_provinces : StringName = &"province_tex"
const _shader_param_mouse_pos : StringName = &"mouse_pos"
+
+
@export var _camera : Camera3D
@export var _move_speed : float = 1.0
-
+@export var _edge_move_threshold: float = 50.0
+@export var _edge_move_speed: float = 0.02
+@export var _dragSensitivity: float = 0.005
@export var _zoom_target_min : float = 0.2
@export var _zoom_target_max : float = 5.0
@export var _zoom_target_step : float = 0.1
@@ -28,9 +38,7 @@ var _map_shader_material : ShaderMaterial
var _map_aspect_ratio : float = 1.0
var _map_mesh_corner : Vector2
var _map_mesh_dims : Vector2
-
var _mouse_pos : Vector2 = Vector2(0.5, 0.5)
-
func _ready():
if _camera == null:
push_error("MapView's _camera variable hasn't been set!")
@@ -71,7 +79,41 @@ func _ready():
var texture := ImageTexture.create_from_image(province_shape_image)
_map_shader_material.set_shader_parameter(_shader_param_provinces, texture)
+
func _input(event : InputEvent):
+ if Input.is_action_pressed(_action_click, true) or event is InputEventMouseMotion:
+ # Check if the mouse is outside of bounds
+ var _mouse_inside_flag = false
+ if _mouse_pos.x > 1.0 or _mouse_pos.x < 0.0 and _mouse_pos.y > 1.0 or _mouse_pos.y < 0.0:
+ _mouse_inside_flag = false
+ else:
+ _mouse_inside_flag = true
+
+ # Convert the relative event position from 3D to 2D
+ # Could do one-liner but here split for readability
+ var mouse_pos2D = _mouse_pos
+ mouse_pos2D.x = mouse_pos2D.x * 2.0 - 0.5
+ mouse_pos2D.x = mouse_pos2D.x * ProvinceShape.get_size().x
+ mouse_pos2D.y = mouse_pos2D.y * ProvinceShape.get_size().y
+
+ if Input.is_action_pressed(_action_click, true) and _mouse_inside_flag == true and not event is InputEventMouseMotion:
+ var pxColour = ProvinceShape.get_pixel(int(mouse_pos2D.x), int(mouse_pos2D.y))
+ get_node('MapMeshInstance').material_override.set_shader_parameter("selection_hover", 1.2)
+ if get_parent().has_node("ProvinceOverviewPanel"):
+ get_parent().get_node("ProvinceOverviewPanel").ProvinceID = MapSingleton.get_province_id(pxColour.to_html(false))
+ get_parent().get_node("ProvinceOverviewPanel").set_id()
+ else:
+ var Province = ProvScene.instantiate()
+ Province.ProvinceID = MapSingleton.get_province_id(pxColour.to_html(false))
+ get_parent().add_child(Province)
+ else:
+ get_node('MapMeshInstance').material_override.set_shader_parameter("selection_hover", 0.8)
+#
+
+ if event is InputEventMouseMotion and Input.is_action_pressed(_action_drag, true):
+ _camera.position.x -= event.relative.x * _dragSensitivity
+ _camera.position.z -= event.relative.y * _dragSensitivity
+
if event.is_action_pressed(_action_zoomin, true):
_zoom_target -= _zoom_target_step
elif event.is_action_pressed(_action_zoomout, true):
@@ -80,6 +122,7 @@ func _input(event : InputEvent):
func _physics_process(delta : float):
# Process movement
_move_process(delta)
+ _edge_scrolling()
# Keep within map bounds
_clamp_over_map()
# Process zooming
@@ -88,7 +131,21 @@ func _physics_process(delta : float):
_update_orientation()
# Calculate where the mouse lies on the map
_update_mouse_map_position()
-
+
+
+func _edge_scrolling() -> void:
+ var local_mouse_pos = get_viewport().get_mouse_position()
+
+ if local_mouse_pos.y < _edge_move_threshold:
+ _camera.position.z -= _edge_move_speed
+ elif local_mouse_pos.y > get_viewport().size.y - _edge_move_threshold:
+ _camera.position.z += _edge_move_speed
+
+ if local_mouse_pos.x < _edge_move_threshold:
+ _camera.position.x -= _edge_move_speed
+ elif local_mouse_pos.x > get_viewport().size.x - _edge_move_threshold:
+ _camera.position.x += _edge_move_speed
+
func _move_process(delta : float) -> void:
var move := Vector3(
float(Input.is_action_pressed(_action_east)) - float(Input.is_action_pressed(_action_west)),
diff --git a/game/src/GameSession/MapView.tscn b/game/src/GameSession/MapView.tscn
index 97a72a8..927d162 100644
--- a/game/src/GameSession/MapView.tscn
+++ b/game/src/GameSession/MapView.tscn
@@ -7,6 +7,7 @@
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tayeg"]
render_priority = 0
shader = ExtResource("1_upocn")
+shader_parameter/selection_hover = 0.8
shader_parameter/mouse_pos = Vector2(0.5, 0.5)
shader_parameter/terrain_tex = ExtResource("3_l8pnf")
diff --git a/game/src/GameSession/ProvinceOverviewPanel.gd b/game/src/GameSession/ProvinceOverviewPanel.gd
new file mode 100644
index 0000000..f68ac73
--- /dev/null
+++ b/game/src/GameSession/ProvinceOverviewPanel.gd
@@ -0,0 +1,13 @@
+extends Panel
+@export var ProvinceID: String = "ID not loaded"
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ set_id()
+
+func set_id():
+ $VBoxContainer/ProvinceName.text = str(ProvinceID)+"_NAME"
+
+
+func _on_button_pressed():
+ queue_free()
diff --git a/game/src/GameSession/ProvinceOverviewPanel.tscn b/game/src/GameSession/ProvinceOverviewPanel.tscn
new file mode 100644
index 0000000..c31ff6e
--- /dev/null
+++ b/game/src/GameSession/ProvinceOverviewPanel.tscn
@@ -0,0 +1,39 @@
+[gd_scene load_steps=2 format=3 uid="uid://byq323jbel48u"]
+
+[ext_resource type="Script" path="res://src/GameSession/ProvinceOverviewPanel.gd" id="1_3n8k5"]
+
+[node name="ProvinceOverviewPanel" type="Panel"]
+anchors_preset = 2
+anchor_top = 1.0
+anchor_bottom = 1.0
+offset_top = -300.0
+offset_right = 200.0
+grow_vertical = 0
+script = ExtResource("1_3n8k5")
+
+[node name="Button" type="Button" parent="."]
+custom_minimum_size = Vector2(30, 30)
+layout_mode = 1
+anchors_preset = 1
+anchor_left = 1.0
+anchor_right = 1.0
+offset_left = -30.0
+offset_bottom = 30.0
+grow_horizontal = 0
+
+[node name="VBoxContainer" type="VBoxContainer" parent="."]
+layout_mode = 1
+anchors_preset = -1
+anchor_right = 1.0
+anchor_bottom = 1.0
+offset_left = 10.0
+offset_top = 5.0
+offset_right = -10.0
+offset_bottom = -5.0
+
+[node name="ProvinceName" type="Label" parent="VBoxContainer"]
+layout_mode = 2
+text = "1_NAME"
+vertical_alignment = 1
+
+[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader
index 0c5f3e1..1e5e6b9 100644
--- a/game/src/GameSession/TerrainMap.gdshader
+++ b/game/src/GameSession/TerrainMap.gdshader
@@ -6,7 +6,7 @@ render_mode unshaded;
uniform sampler2D terrain_tex: source_color, repeat_enable;
// Province shape texture
uniform sampler2D province_tex: source_color, repeat_enable;
-
+uniform float selection_hover = 0.8;
// Mouse position in UV coords over the map mesh
uniform vec2 mouse_pos;
@@ -22,6 +22,6 @@ void fragment() {
vec3 prov_colour = texture(province_tex, fixed_uv).rgb;
vec3 mouse_colour = texture(province_tex, fix_uv(mouse_pos)).rgb;
// Boost prov_colour's contribution if the mouse is over that colour and it isn't (0,0,0)
- float mix_val = prov_colour == mouse_colour && mouse_colour != vec3(0.0) ? 0.8 : 0.4;
+ float mix_val = prov_colour == mouse_colour && mouse_colour != vec3(0.0) ? selection_hover : 0.4;
ALBEDO = mix(texture(terrain_tex, fixed_uv).rgb, prov_colour, mix_val);
}