aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game
diff options
context:
space:
mode:
Diffstat (limited to 'game/src/Game')
-rw-r--r--game/src/Game/GameSession/MapView.gd19
1 files changed, 16 insertions, 3 deletions
diff --git a/game/src/Game/GameSession/MapView.gd b/game/src/Game/GameSession/MapView.gd
index 3cab19d..345ab9e 100644
--- a/game/src/Game/GameSession/MapView.gd
+++ b/game/src/Game/GameSession/MapView.gd
@@ -20,16 +20,17 @@ var _drag_anchor : Vector2
var _drag_active : bool = false
var _mouse_over_viewport : bool = true
+var _window_in_focus : bool = true
@export var _zoom_target_min : float = 0.05
@export var _zoom_target_max : float = 5.0
@export var _zoom_target_step : float = 0.1
-@export var _zoom_epsilon : float = _zoom_target_step * 0.1
+@export var _zoom_epsilon : float = _zoom_target_step * 0.005
@export var _zoom_speed : float = 5.0
@export var _zoom_target : float = 1.0:
get: return _zoom_target
set(v): _zoom_target = clamp(v, _zoom_target_min, _zoom_target_max)
-const _zoom_position_multiplier = 4.0 # This value needs to be fine-tuned.
+const _zoom_position_multiplier = 3.14159 # Horizontal movement coefficient during zoom
var _zoom_position : Vector2
@export var _map_mesh_instance : MeshInstance3D
@@ -92,6 +93,10 @@ func _notification(what : int):
_on_mouse_entered_viewport()
NOTIFICATION_WM_MOUSE_EXIT: # Mouse out of window
_on_mouse_exited_viewport()
+ NOTIFICATION_WM_WINDOW_FOCUS_IN: # Window comes into focus
+ _on_window_entered_focus()
+ NOTIFICATION_WM_WINDOW_FOCUS_OUT: # Window goes out of focus
+ _on_window_exited_focus()
func _world_to_map_coords(pos : Vector3) -> Vector2:
return (Vector2(pos.x, pos.z) - _map_mesh_corner) / _map_mesh_dims
@@ -176,6 +181,8 @@ func _movement_process(delta : float) -> void:
# REQUIREMENTS
# * UIFUN-125
func _edge_scrolling_vector() -> Vector2:
+ if not _window_in_focus:
+ return Vector2()
var mouse_vector := _mouse_pos_viewport * GuiScale.get_current_guiscale() / _viewport_dims - Vector2(0.5, 0.5)
# Only scroll if outside the move threshold.
if abs(mouse_vector.x) < 0.5 - _edge_move_threshold and abs(mouse_vector.y) < 0.5 - _edge_move_threshold:
@@ -205,7 +212,7 @@ func _zoom_process(delta : float) -> void:
# Set to target if height is within _zoom_epsilon of it or has overshot past it
if abs(zoom - zoom_delta) < _zoom_epsilon or sign(zoom) != sign(zoom - zoom_delta):
zoom_delta = zoom
- _camera.position += Vector3(_zoom_position.x * zoom_delta, zoom_delta, _zoom_position.y * zoom_delta)
+ _camera.position += Vector3(_zoom_position.x * zoom_delta * int(_mouse_over_viewport), zoom_delta, _zoom_position.y * zoom_delta * int(_mouse_over_viewport))
func _update_orientation() -> void:
var dir := Vector3(0, -1, -exp(-_camera.position.y - 1))
@@ -231,6 +238,12 @@ func _on_mouse_exited_viewport():
_mouse_over_viewport = false
_map_shader_material.set_shader_parameter(GameLoader.ShaderManager.param_hover_index, 0)
+func _on_window_entered_focus():
+ _window_in_focus = true
+
+func _on_window_exited_focus():
+ _window_in_focus = false
+
func _on_minimap_clicked(pos_clicked : Vector2):
pos_clicked *= _map_mesh_dims
_camera.position.x = pos_clicked.x