Skip to content

Commit

Permalink
Fixed touch camera control
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrw committed Oct 22, 2024
1 parent e394622 commit f04f74e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/scenes/GUI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ __meta__ = {
}

[node name="LeftStick" parent="." instance=ExtResource( 13 )]
visible = false
anchor_left = 0.12
anchor_top = 0.7
anchor_right = 0.12
Expand All @@ -262,5 +263,6 @@ margin_top = 0.0
margin_right = 0.0
margin_bottom = 0.0
rect_min_size = Vector2( 200, 200 )
visibility_mode = 0

[editable path="GridContainer/Settings"]
4 changes: 3 additions & 1 deletion src/ui/editor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ gdobj Editor of MarginContainer:
self.touch_timer = get_mono_time() + 0.5.seconds
else:
self.touch_timer = MonoTime.high
elif event of InputEventScreenDrag and self.scroll_state == Idle:
elif EditorVisible in state.local_flags and
CommandMode notin state.local_flags and event of InputEventScreenDrag and
self.scroll_state == Idle:
self.get_tree.set_input_as_handled()

method unhandled_input*(event: InputEvent) =
Expand Down
21 changes: 11 additions & 10 deletions src/ui/gui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import
import core, nodes/player_node, gdutils

gdobj GUI of Control:
var left_stick: Control
method ready() =
self.bind_signals self,
"mouse_entered", "mouse_exited", "focus_entered", "focus_exited"
self.left_stick = find("LeftStick", Control)
state.local_flags.changes:
self.left_stick.visible = TouchControls in state.local_flags

method on_mouse_entered() =
state.push_flag ViewportFocused
Expand All @@ -21,17 +25,7 @@ gdobj GUI of Control:
method on_focus_exited() =
state.pop_flag ViewportFocused

method gui_input(event: InputEvent) =
(state.nodes.player as PlayerNode).viewport_input(event)
self.accept_event()

method input(event: InputEvent) =
if host_os == "ios":
(state.nodes.player as PlayerNode).viewport_input(event)
else:
if event of InputEventKey:
(state.nodes.player as PlayerNode).viewport_input(event)

if event of InputEventScreenTouch:
let event = event as InputEventScreenTouch
let index = byte(event.index)
Expand All @@ -44,3 +38,10 @@ gdobj GUI of Control:
let index = byte(event.index)
if index in state.ignored_touches:
self.get_tree().set_input_as_handled()
return

if TouchControls in state.local_flags:
(state.nodes.player as PlayerNode).viewport_input(event)
else:
if event of InputEventKey:
(state.nodes.player as PlayerNode).viewport_input(event)

0 comments on commit f04f74e

Please sign in to comment.