Merge pull request #170 from Nitwel/imp2

Allow for using joystick to move objects towards/away
This commit is contained in:
Nitwel 2024-05-28 18:37:21 +02:00 committed by GitHub
commit cfbd73bb21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 20 deletions

View File

@ -39,6 +39,12 @@ func reset():
initiator2 = null
on_moved.emit()
func _on_action_value(event: EventAction):
if event.name != "primary"||event.initiator != initiator:
return
relative_transform = relative_transform.translated(Vector3(0, 0, -event.value.y * 0.05)).rotated_local(Vector3(0, 1, 0), event.value.x * 0.05)
func _on_grab_down(event: EventPointer):
if disabled:
return
@ -65,6 +71,8 @@ func _on_grab_down(event: EventPointer):
initiator = event.initiator
EventSystem.on_action_value.connect(_on_action_value)
_update_relative_transform()
initial_global_transform = get_parent().global_transform
@ -115,6 +123,7 @@ func _on_grab_up(event: EventPointer):
initiator = null
initiator2 = null
on_moved.emit()
EventSystem.on_action_value.disconnect(_on_action_value)
func _get_first_ray_point():
if initiator == null:

View File

@ -52,14 +52,6 @@ var grabbed = false
var moving_entity = null
func _ready():
button_pressed.connect(func(action_name):
EventSystem.emit_action(action_name, true, false)
)
button_released.connect(func(action_name):
EventSystem.emit_action(action_name, false, false)
)
_setup_hand()
palm.remove_child(entity_settings)

View File

@ -39,13 +39,6 @@ var pressed = false
var grabbed = false
func _ready():
button_pressed.connect(func(action_name):
EventSystem.emit_action(action_name, true, true)
)
button_released.connect(func(action_name):
EventSystem.emit_action(action_name, false, true)
)
_setup_hand()
func _setup_hand():

View File

@ -32,14 +32,26 @@ func _ready():
add_child(pointer)
get_parent().button_pressed.connect(func(button: String):
EventSystem.emit_action(button, true, initiator)
if _event_type_map.has(button):
pointer.pressed(_event_type_map[button])
)
get_parent().button_released.connect(func(button: String):
EventSystem.emit_action(button, false, initiator)
if _event_type_map.has(button):
pointer.released(_event_type_map[button])
)
get_parent().input_float_changed.connect(func(action_name, value):
EventSystem.emit_action(action_name, value, initiator)
)
get_parent().input_vector2_changed.connect(func(action_name, value):
EventSystem.emit_action(action_name, value, initiator)
)
R.effect(func(_arg):
var style=Store.settings.state.cursor_style

View File

@ -2,9 +2,11 @@ extends Event
## EventAction is emitted when the user presses a button or trigger on the controller.
class_name EventAction
const Initiator = preload ("res://lib/utils/pointer/initiator.gd")
## The name of the action that was triggered.
var name: String
## True if the right controller triggered the action, false if the left controller triggered the action.
var right_controller: bool
## Boolean, Float or Vector2
var value
var value
## The initiator that started the event.
var initiator: Initiator

View File

@ -1,5 +1,7 @@
extends Node
const Initiator = preload ("res://lib/utils/pointer/initiator.gd")
## Prefix for the function names to be called
const FN_PREFIX = "_on_"
## Prefix for the signal names to be emitted
@ -83,11 +85,11 @@ func notify(message: String, type:=EventNotify.Type.INFO):
emit("notify", event)
## Helper for emitting controller actions
func emit_action(name: String, value, right_controller: bool=true):
func emit_action(name: String, value, initiator: Initiator):
var event = EventAction.new()
event.name = name
event.value = value
event.right_controller = right_controller
event.initiator = initiator
match typeof(value):
TYPE_BOOL: