Interaction wheel
do interaction
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
extends Node2D
|
||||
class_name InteractionWheel
|
||||
|
||||
signal closed
|
||||
|
||||
var interactions: Array[Interaction]
|
||||
var grid_position: Vector2i
|
||||
|
||||
@onready var interaction_icons: Array[Node] = $Interactions.get_children()
|
||||
@onready var cursor: Sprite2D = $Cursor
|
||||
@onready var information_panel: Panel = $InformationPanel
|
||||
@onready var interaction_label: Label = $InformationPanel/InteractionLabel
|
||||
|
||||
func initialize(interaction_location: Vector2i, interactions: Array[Interaction]) -> void:
|
||||
grid_position = interaction_location
|
||||
position = Grid.grid_to_world_center(interaction_location)
|
||||
self.interactions = interactions
|
||||
|
||||
@@ -20,5 +26,21 @@ func _process(delta: float) -> void:
|
||||
if selection_direction:
|
||||
cursor.rotation = selection_direction.angle()
|
||||
cursor.show()
|
||||
if Input.is_action_just_pressed("select"):
|
||||
pass
|
||||
var selection = _get_selection_index(cursor.rotation)
|
||||
if selection < interactions.size():
|
||||
information_panel.show()
|
||||
interaction_label.text = interactions[selection].name
|
||||
else:
|
||||
information_panel.hide()
|
||||
if Input.is_action_just_pressed("select") and cursor.visible:
|
||||
var selection = _get_selection_index(cursor.rotation)
|
||||
print("Selection: %s Rotation: %s" % [selection, cursor.rotation])
|
||||
if selection < interactions.size():
|
||||
var next_interactions = interactions[selection].interact_at(grid_position, get_tree().root)
|
||||
if next_interactions.is_empty():
|
||||
closed.emit()
|
||||
queue_free()
|
||||
|
||||
func _get_selection_index(angle: float) -> int:
|
||||
var adjusted_angle = fposmod(angle + (PI / 2.0), 2.0 * PI)
|
||||
return floor(((int(floor(adjusted_angle / (PI / 8.0))) + 1) % 16) / 2.0)
|
||||
|
||||
Reference in New Issue
Block a user