Merge pull request #170 from Nitwel/imp2
Allow for using joystick to move objects towards/away
This commit is contained in:
commit
cfbd73bb21
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user