add camera focusing
This commit is contained in:
parent
168a572fb7
commit
2b7d7f2c5e
BIN
assets/textures/gui/pictograms.png
(Stored with Git LFS)
BIN
assets/textures/gui/pictograms.png
(Stored with Git LFS)
Binary file not shown.
@ -78,11 +78,16 @@ reset_camera={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
toggle_confinement={
|
||||
focus_camera={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194333,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
toggle_confinement={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194336,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ region = Rect2(532.01, 2.29694, 48.3741, 55.326)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wimn7"]
|
||||
atlas = ExtResource("4_dmywd")
|
||||
region = Rect2(9.61571, 881, 845.387, 129)
|
||||
region = Rect2(9.61571, 881, 1006.99, 129)
|
||||
|
||||
[node name="PauseMenu" type="Panel"]
|
||||
process_mode = 3
|
||||
@ -122,7 +122,7 @@ anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 15.0
|
||||
offset_top = -169.0
|
||||
offset_right = 895.0
|
||||
offset_right = 1063.0
|
||||
offset_bottom = -21.0
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = ExtResource("1_06xpe")
|
||||
@ -134,10 +134,10 @@ anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -422.5
|
||||
offset_top = -64.5
|
||||
offset_right = 422.5
|
||||
offset_bottom = 64.5
|
||||
offset_left = -503.0
|
||||
offset_top = -64.0
|
||||
offset_right = 503.0
|
||||
offset_bottom = 65.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = SubResource("AtlasTexture_wimn7")
|
||||
|
||||
@ -13,6 +13,7 @@ atlas = ExtResource("3_tdly6")
|
||||
region = Rect2(0, 0, 108, 94)
|
||||
|
||||
[node name="UnitInfo" type="Panel"]
|
||||
process_priority = 100
|
||||
offset_right = 128.0
|
||||
offset_bottom = 128.0
|
||||
pivot_offset = Vector2(63, 130)
|
||||
|
||||
@ -4,6 +4,7 @@ class_name MainCamera
|
||||
enum State {
|
||||
FREE,
|
||||
HEADING_TO,
|
||||
FOCUSED,
|
||||
}
|
||||
|
||||
const ZOOM_STEP: float = 0.1
|
||||
@ -49,6 +50,8 @@ var _heading_from_position: Vector3 = Vector3.ZERO
|
||||
var _heading_from_zoom: float = 0
|
||||
var _heading_progress: float = 0
|
||||
|
||||
var _focus_target: Node3D
|
||||
|
||||
var _state: State = State.FREE
|
||||
|
||||
var _window_out_of_focus: bool = false
|
||||
@ -67,6 +70,7 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
_handle_heading_to(delta)
|
||||
_handle_movement(delta)
|
||||
_handle_focusing()
|
||||
|
||||
zoom_value = lerpf(zoom_value, _zoom_unsmoothed, delta * ZOOM_DAMP)
|
||||
|
||||
@ -86,6 +90,8 @@ func _process(delta: float) -> void:
|
||||
listener.global_position = _target_position + (Vector3.UP * distance)
|
||||
listener.global_rotation = global_rotation
|
||||
|
||||
UiManager.unit_info.closed.connect(_on_unit_info_closed)
|
||||
|
||||
DebugManager.marker("mc_target", _target_position, 0.05)
|
||||
DebugManager.marker("mc_listener", listener.global_position, 0.05, Color.GREEN)
|
||||
|
||||
@ -106,6 +112,13 @@ func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("reset_camera"):
|
||||
head_to(StaticNodesManager.player_anthill.global_position)
|
||||
|
||||
if (
|
||||
event.is_action_pressed("focus_camera")
|
||||
and UiManager.unit_info.unit != null
|
||||
):
|
||||
_state = State.FOCUSED
|
||||
_focus_target = UiManager.unit_info.unit
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_WM_WINDOW_FOCUS_IN:
|
||||
@ -230,3 +243,17 @@ func _handle_heading_to(delta: float) -> void:
|
||||
eased_progress,
|
||||
)
|
||||
zoom_value = _zoom_unsmoothed
|
||||
|
||||
|
||||
func _handle_focusing() -> void:
|
||||
if _state != State.FOCUSED:
|
||||
return
|
||||
|
||||
_target_position = _focus_target.global_position
|
||||
|
||||
|
||||
func _on_unit_info_closed() -> void:
|
||||
if _state != State.FOCUSED:
|
||||
return
|
||||
|
||||
_state = State.FREE
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
extends Control
|
||||
class_name CloseableUI
|
||||
|
||||
signal closed
|
||||
|
||||
const OPEN_TWEEN_DURATION: float = 0.5
|
||||
const CLOSE_TWEEN_DURATION: float = 0.25
|
||||
|
||||
@ -33,6 +35,7 @@ func _input(event: InputEvent) -> void:
|
||||
|
||||
|
||||
func close() -> void:
|
||||
closed.emit()
|
||||
await _close_animation(self)
|
||||
visible = false
|
||||
|
||||
|
||||
@ -50,7 +50,10 @@ func _on_quit_button_pressed() -> void:
|
||||
func _open_animation() -> void:
|
||||
await _animate(
|
||||
Vector2.ZERO,
|
||||
Vector2(_controls_info_pos.x, 1080),
|
||||
Vector2(
|
||||
_controls_info_pos.x,
|
||||
get_viewport().get_visible_rect().size.y
|
||||
),
|
||||
Vector2.ONE,
|
||||
_controls_info_pos,
|
||||
OPEN_TWEEN_DURATION,
|
||||
@ -63,7 +66,10 @@ func _close_animation() -> void:
|
||||
Vector2.ONE,
|
||||
_controls_info_pos,
|
||||
Vector2.ZERO,
|
||||
Vector2(_controls_info_pos.x, 1080),
|
||||
Vector2(
|
||||
_controls_info_pos.x,
|
||||
get_viewport().get_visible_rect().size.y
|
||||
),
|
||||
CLOSE_TWEEN_DURATION,
|
||||
Tween.EASE_IN,
|
||||
Tween.TRANS_BACK,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user