aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
author Benjamin Darnell <benjamindarnell00@gmail.com>2023-09-11 01:00:15 +0200
committer Benjamin Darnell <benjamindarnell00@gmail.com>2023-09-11 01:00:15 +0200
commit503cf424a3bd993df66f6a68b09603adfbb91650 (patch)
tree076bef7cb741584b0eedf2bdf5e9589da6e6f97f /game
parenta703b30704a61ae6624e4e5fe85b834ae0d6dae9 (diff)
Fix edge scrolling when window not in focus.
Diffstat (limited to '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