Add Option 3 touch camera: gesture hold and button toggle modes
- Settings: new touch_camera_mode ("gesture"|"buttons"), persisted to camera section
- GameScreen: CamGestureTimer (3 s), CamCtrlPanel with Orbit/Pan/Zoom toggle buttons
- game_screen: gesture timer fires orbit/pan/zoom after 3-second stationary hold;
button mode shows on-screen toggles; single-finger drag now gated behind active mode
- InGameSettings: Camera Controls section with Touch Camera OptionButton
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -14,6 +14,7 @@ const SECTION := "audio"
|
||||
const SECTION_GAMEPLAY := "gameplay"
|
||||
const SECTION_VISUAL := "visual"
|
||||
const SECTION_HIGHLIGHTS := "highlights"
|
||||
const SECTION_CAMERA := "camera"
|
||||
|
||||
## Audio bus names as configured in the Godot project.
|
||||
const BUS_MUSIC := "Music"
|
||||
@@ -73,6 +74,15 @@ var skybox_mode : String = "live" :
|
||||
_save()
|
||||
settings_changed.emit()
|
||||
|
||||
## How touch camera control is activated.
|
||||
## "gesture" — hold finger(s) still for 3 s to activate (1 = orbit, 2 = zoom, 3 = pan).
|
||||
## "buttons" — tap the on-screen Orbit / Pan / Zoom toggle buttons.
|
||||
var touch_camera_mode : String = "gesture" :
|
||||
set(v):
|
||||
touch_camera_mode = v
|
||||
_save()
|
||||
settings_changed.emit()
|
||||
|
||||
## Per-type highlight texture URL overrides entered by the player.
|
||||
## Keys: "movement", "attack", "ability", "terramorpha", "selector"
|
||||
## Value: URL string, or "" to use the server default.
|
||||
@@ -147,6 +157,7 @@ func _load() -> void:
|
||||
sfx_muted = bool(cfg.get_value(SECTION, "sfx_muted", false))
|
||||
camera_follow_unit = bool(cfg.get_value(SECTION_GAMEPLAY, "camera_follow_unit", true))
|
||||
click_to_focus_camera = bool(cfg.get_value(SECTION_GAMEPLAY, "click_to_focus_camera", false))
|
||||
touch_camera_mode = str(cfg.get_value(SECTION_CAMERA, "touch_camera_mode", "gesture"))
|
||||
skybox_mode = str(cfg.get_value(SECTION_VISUAL, "skybox_mode", "live"))
|
||||
var raw_overrides = cfg.get_value(SECTION_HIGHLIGHTS, "highlight_overrides", {})
|
||||
if raw_overrides is Dictionary:
|
||||
@@ -161,6 +172,7 @@ func _save() -> void:
|
||||
cfg.set_value(SECTION, "sfx_muted", sfx_muted)
|
||||
cfg.set_value(SECTION_GAMEPLAY, "camera_follow_unit", camera_follow_unit)
|
||||
cfg.set_value(SECTION_GAMEPLAY, "click_to_focus_camera", click_to_focus_camera)
|
||||
cfg.set_value(SECTION_CAMERA, "touch_camera_mode", touch_camera_mode)
|
||||
cfg.set_value(SECTION_VISUAL, "skybox_mode", skybox_mode)
|
||||
cfg.set_value(SECTION_HIGHLIGHTS, "highlight_overrides", highlight_overrides)
|
||||
cfg.save(SAVE_PATH)
|
||||
|
||||
@@ -320,3 +320,43 @@ unique_name_in_owner = true
|
||||
unique_name_in_owner = true
|
||||
wait_time = 0.5
|
||||
one_shot = true
|
||||
|
||||
[node name="CamGestureTimer" type="Timer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
|
||||
[node name="CamCtrlPanel" type="PanelContainer" parent="HUD"]
|
||||
unique_name_in_owner = true
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_left = 8.0
|
||||
offset_top = 56.0
|
||||
offset_right = 96.0
|
||||
offset_bottom = 164.0
|
||||
visible = false
|
||||
|
||||
[node name="CamCtrlVBox" type="VBoxContainer" parent="HUD/CamCtrlPanel"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 4
|
||||
|
||||
[node name="CamOrbitBtn" type="Button" parent="HUD/CamCtrlPanel/CamCtrlVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "Orbit"
|
||||
|
||||
[node name="CamPanBtn" type="Button" parent="HUD/CamCtrlPanel/CamCtrlVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "Pan"
|
||||
|
||||
[node name="CamZoomBtn" type="Button" parent="HUD/CamCtrlPanel/CamCtrlVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "Zoom"
|
||||
|
||||
@@ -9,9 +9,9 @@ anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -220.0
|
||||
offset_top = -278.0
|
||||
offset_top = -305.0
|
||||
offset_right = 220.0
|
||||
offset_bottom = 278.0
|
||||
offset_bottom = 305.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_script")
|
||||
@@ -113,6 +113,34 @@ unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Focus camera when clicking a tile"
|
||||
|
||||
[node name="HSeparatorCam" type="HSeparator" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="CameraLabel" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Camera Controls"
|
||||
theme_override_font_sizes/font_size = 13
|
||||
|
||||
[node name="TouchCamRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TouchCamLabel" type="Label" parent="MarginContainer/VBoxContainer/TouchCamRow"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(100, 0)
|
||||
text = "Touch Camera"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TouchCamModeOption" type="OptionButton" parent="MarginContainer/VBoxContainer/TouchCamRow"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
item_count = 2
|
||||
popup/item_0/text = "Gesture (long hold)"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "Buttons (tap toggle)"
|
||||
popup/item_1/id = 1
|
||||
selected = 0
|
||||
|
||||
[node name="SkyboxRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
|
||||
@@ -29,7 +29,12 @@ enum Mode {
|
||||
@onready var _tiles_root : Node3D = $BoardRoot/TilesRoot
|
||||
@onready var _units_root : Node3D = $BoardRoot/UnitsRoot
|
||||
@onready var _hi_root : Node3D = $BoardRoot/HighlightsRoot
|
||||
@onready var _hold_timer : Timer = $HoldTimer
|
||||
@onready var _hold_timer : Timer = $HoldTimer
|
||||
@onready var _cam_gesture_timer : Timer = $CamGestureTimer
|
||||
@onready var _cam_ctrl_panel : Control = %CamCtrlPanel
|
||||
@onready var _cam_orbit_btn : Button = %CamOrbitBtn
|
||||
@onready var _cam_pan_btn : Button = %CamPanBtn
|
||||
@onready var _cam_zoom_btn : Button = %CamZoomBtn
|
||||
|
||||
# HUD
|
||||
@onready var _phase_lbl : Label = %PhaseLabel
|
||||
@@ -128,6 +133,14 @@ var _was_multi_touch : bool = false
|
||||
var _touch_drag_active : bool = false # set when cumulative finger movement > threshold; suppresses tap-click
|
||||
var _touch_drag_total : float = 0.0 # cumulative drag distance since last touch-down
|
||||
|
||||
# Touch camera mode — which camera action is currently active on touch
|
||||
var _touch_cam_orbit : bool = false # single-finger drag → orbit
|
||||
var _touch_cam_pan : bool = false # single-finger drag → pan
|
||||
var _touch_cam_zoom : bool = false # single-finger drag up/down → zoom
|
||||
# Gesture-hold detection
|
||||
var _gesture_move_accum : float = 0.0 # cumulative movement since fingers last settled
|
||||
var _gesture_finger_count : int = 0 # finger count when _cam_gesture_timer was last started
|
||||
|
||||
# ── Selection state ───────────────────────────────────────────────────────────
|
||||
|
||||
var _mode : Mode = Mode.NONE
|
||||
@@ -266,6 +279,12 @@ func _ready() -> void:
|
||||
_go_menu_btn.pressed.connect(func() -> void:
|
||||
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn"))
|
||||
_hold_timer.timeout.connect(_on_hold_timer_fired)
|
||||
_cam_gesture_timer.timeout.connect(_on_cam_gesture_timer_fired)
|
||||
_cam_orbit_btn.toggled.connect(_on_cam_orbit_btn_toggled)
|
||||
_cam_pan_btn.toggled.connect(_on_cam_pan_btn_toggled)
|
||||
_cam_zoom_btn.toggled.connect(_on_cam_zoom_btn_toggled)
|
||||
_sync_cam_ctrl_panel()
|
||||
Settings.settings_changed.connect(_sync_cam_ctrl_panel)
|
||||
_create_tile_drawer()
|
||||
Game.triggered_target_request.connect(_on_triggered_target_request)
|
||||
|
||||
@@ -782,6 +801,67 @@ func _zoom(delta: float) -> void:
|
||||
_cam_distance = clampf(_cam_distance - delta, 4.0, 22.0)
|
||||
_apply_camera()
|
||||
|
||||
|
||||
func _sync_cam_ctrl_panel() -> void:
|
||||
_cam_ctrl_panel.visible = (Settings.touch_camera_mode == "buttons")
|
||||
if Settings.touch_camera_mode != "buttons":
|
||||
_deactivate_touch_cam_modes()
|
||||
|
||||
|
||||
func _deactivate_touch_cam_modes() -> void:
|
||||
_touch_cam_orbit = false
|
||||
_touch_cam_pan = false
|
||||
_touch_cam_zoom = false
|
||||
if is_instance_valid(_cam_orbit_btn): _cam_orbit_btn.set_pressed_no_signal(false)
|
||||
if is_instance_valid(_cam_pan_btn): _cam_pan_btn.set_pressed_no_signal(false)
|
||||
if is_instance_valid(_cam_zoom_btn): _cam_zoom_btn.set_pressed_no_signal(false)
|
||||
|
||||
|
||||
func _on_cam_orbit_btn_toggled(pressed: bool) -> void:
|
||||
_touch_cam_orbit = pressed
|
||||
if pressed:
|
||||
_touch_cam_pan = false
|
||||
_touch_cam_zoom = false
|
||||
_cam_pan_btn.set_pressed_no_signal(false)
|
||||
_cam_zoom_btn.set_pressed_no_signal(false)
|
||||
|
||||
|
||||
func _on_cam_pan_btn_toggled(pressed: bool) -> void:
|
||||
_touch_cam_pan = pressed
|
||||
if pressed:
|
||||
_touch_cam_orbit = false
|
||||
_touch_cam_zoom = false
|
||||
_cam_orbit_btn.set_pressed_no_signal(false)
|
||||
_cam_zoom_btn.set_pressed_no_signal(false)
|
||||
|
||||
|
||||
func _on_cam_zoom_btn_toggled(pressed: bool) -> void:
|
||||
_touch_cam_zoom = pressed
|
||||
if pressed:
|
||||
_touch_cam_orbit = false
|
||||
_touch_cam_pan = false
|
||||
_cam_orbit_btn.set_pressed_no_signal(false)
|
||||
_cam_pan_btn.set_pressed_no_signal(false)
|
||||
|
||||
|
||||
func _on_cam_gesture_timer_fired() -> void:
|
||||
if Settings.touch_camera_mode != "gesture":
|
||||
return
|
||||
match _gesture_finger_count:
|
||||
1:
|
||||
_touch_cam_orbit = true
|
||||
_touch_cam_pan = false
|
||||
_touch_cam_zoom = false
|
||||
2:
|
||||
_touch_cam_zoom = true
|
||||
_touch_cam_orbit = false
|
||||
_touch_cam_pan = false
|
||||
3:
|
||||
_touch_cam_pan = true
|
||||
_touch_cam_orbit = false
|
||||
_touch_cam_zoom = false
|
||||
|
||||
|
||||
# ── Input ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
@@ -871,6 +951,11 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
_was_multi_touch = true
|
||||
_held_coord = Vector2i(-1, -1)
|
||||
_hold_timer.stop()
|
||||
# Gesture mode: (re)start timer whenever finger count changes.
|
||||
if Settings.touch_camera_mode == "gesture":
|
||||
_gesture_finger_count = _touch_points.size()
|
||||
_gesture_move_accum = 0.0
|
||||
_cam_gesture_timer.start()
|
||||
else:
|
||||
var released_pos := st.position
|
||||
var had_single_touch := (_touch_points.size() == 1 and _touch_points.has(st.index))
|
||||
@@ -885,18 +970,57 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
_press_was_on_board = false
|
||||
_held_coord = Vector2i(-1, -1)
|
||||
_hold_timer.stop()
|
||||
_cam_gesture_timer.stop()
|
||||
# Gesture mode: deactivate camera mode when all fingers lift.
|
||||
if Settings.touch_camera_mode == "gesture":
|
||||
_deactivate_touch_cam_modes()
|
||||
_gesture_move_accum = 0.0
|
||||
_gesture_finger_count = 0
|
||||
|
||||
elif event is InputEventScreenDrag:
|
||||
var sd := event as InputEventScreenDrag
|
||||
_touch_points[sd.index] = sd.position
|
||||
|
||||
# Cancel gesture timer if fingers move significantly before the hold activates.
|
||||
_gesture_move_accum += sd.relative.length()
|
||||
if _gesture_move_accum > 50.0:
|
||||
_cam_gesture_timer.stop()
|
||||
|
||||
if _touch_points.size() == 1 and not _was_multi_touch:
|
||||
_touch_drag_total += sd.relative.length()
|
||||
if _touch_drag_total > 36.0:
|
||||
_touch_drag_active = true
|
||||
_hold_timer.stop()
|
||||
if _touch_drag_active:
|
||||
_cam_yaw -= sd.relative.x * 0.4
|
||||
_cam_pitch = clampf(_cam_pitch + sd.relative.y * 0.3, 15.0, 75.0)
|
||||
if _touch_cam_orbit:
|
||||
_cam_yaw -= sd.relative.x * 0.4
|
||||
_cam_pitch = clampf(_cam_pitch + sd.relative.y * 0.3, 15.0, 75.0)
|
||||
_apply_camera()
|
||||
elif _touch_cam_pan:
|
||||
var ps_p := _cam_distance * 0.002
|
||||
var right_p := _camera_rig.global_basis.x * -sd.relative.x * ps_p
|
||||
var fwd_p := Vector3(_camera_rig.global_basis.z.x, 0,
|
||||
_camera_rig.global_basis.z.z).normalized()
|
||||
_cam_pivot += right_p + fwd_p * sd.relative.y * ps_p
|
||||
var pan_lim_p := clampf(max(Game.board_width(), Game.board_height()) * TILE_SPACING * 0.5, 6.0, 20.0)
|
||||
_cam_pivot.x = clampf(_cam_pivot.x, -pan_lim_p, pan_lim_p)
|
||||
_cam_pivot.z = clampf(_cam_pivot.z, -pan_lim_p, pan_lim_p)
|
||||
_apply_camera()
|
||||
elif _touch_cam_zoom:
|
||||
_zoom(sd.relative.y * -0.05)
|
||||
elif _touch_points.size() == 3 and _touch_cam_pan:
|
||||
# 3-finger pan (gesture mode): only process the leading finger to avoid triple-apply.
|
||||
var keys3 := _touch_points.keys()
|
||||
keys3.sort()
|
||||
if sd.index == keys3[0]:
|
||||
var ps3 := _cam_distance * 0.002
|
||||
var right3 := _camera_rig.global_basis.x * -sd.relative.x * ps3
|
||||
var fwd3 := Vector3(_camera_rig.global_basis.z.x, 0,
|
||||
_camera_rig.global_basis.z.z).normalized()
|
||||
_cam_pivot += right3 + fwd3 * sd.relative.y * ps3
|
||||
var pan_lim3 := clampf(max(Game.board_width(), Game.board_height()) * TILE_SPACING * 0.5, 6.0, 20.0)
|
||||
_cam_pivot.x = clampf(_cam_pivot.x, -pan_lim3, pan_lim3)
|
||||
_cam_pivot.z = clampf(_cam_pivot.z, -pan_lim3, pan_lim3)
|
||||
_apply_camera()
|
||||
elif _touch_points.size() >= 2:
|
||||
var keys := _touch_points.keys()
|
||||
|
||||
@@ -8,7 +8,8 @@ extends PanelContainer
|
||||
@onready var _sfx_mute : CheckButton = %SfxMute
|
||||
@onready var _cam_follow : CheckButton = %CameraFollowUnit
|
||||
@onready var _tile_focus_cam : CheckButton = %TileFocusCamera
|
||||
@onready var _skybox_opt : OptionButton = %SkyboxModeOption
|
||||
@onready var _skybox_opt : OptionButton = %SkyboxModeOption
|
||||
@onready var _touch_cam_mode_opt : OptionButton = %TouchCamModeOption
|
||||
@onready var _sync_btn : Button = %SyncBtn
|
||||
@onready var _concede_btn : Button = %ConcedeBtn
|
||||
@onready var _confirm_row : HBoxContainer = %ConcedeConfirmRow
|
||||
@@ -29,6 +30,8 @@ func _ready() -> void:
|
||||
_cam_follow.toggled.connect(func(v: bool) -> void: Settings.camera_follow_unit = v)
|
||||
_tile_focus_cam.toggled.connect(func(v: bool) -> void: Settings.click_to_focus_camera = v)
|
||||
_skybox_opt.item_selected.connect(_on_skybox_mode_changed)
|
||||
_touch_cam_mode_opt.item_selected.connect(func(idx: int) -> void:
|
||||
Settings.touch_camera_mode = (["gesture", "buttons"] as Array)[idx])
|
||||
|
||||
_sync_btn.pressed.connect(_on_sync_pressed)
|
||||
_concede_btn.pressed.connect(_on_concede_pressed)
|
||||
@@ -59,6 +62,7 @@ func _sync_from_settings() -> void:
|
||||
_cam_follow.set_pressed_no_signal(Settings.camera_follow_unit)
|
||||
_tile_focus_cam.set_pressed_no_signal(Settings.click_to_focus_camera)
|
||||
_skybox_opt.selected = ["live", "cdn", "off"].find(Settings.skybox_mode)
|
||||
_touch_cam_mode_opt.selected = ["gesture", "buttons"].find(Settings.touch_camera_mode)
|
||||
_music_slider.modulate.a = 0.4 if Settings.music_muted else 1.0
|
||||
_sfx_slider.modulate.a = 0.4 if Settings.sfx_muted else 1.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user