Interaction wheel
do interaction
This commit is contained in:
@@ -40,20 +40,6 @@ func is_corrupted() -> bool:
|
||||
func has_layer(layer: int) -> bool:
|
||||
return layer_info.has(layer)
|
||||
|
||||
func interact(timer: Timer) -> void:
|
||||
var is_interactable := has_resource() or not has_building()
|
||||
if is_interactable and not interaction_display:
|
||||
timer.timeout.connect(_on_interaction_finished.bind(timer))
|
||||
timer.start(3)
|
||||
|
||||
interaction_display = ProgressBar.new()
|
||||
interaction_display.position = Grid.grid_to_world_center(_pos) - Vector2(30, 10)
|
||||
interaction_display.size = Vector2(60, 20)
|
||||
interaction_display.show_percentage = false
|
||||
var tween = timer.get_tree().create_tween()
|
||||
tween.tween_property(interaction_display, "value", 100, 3)
|
||||
timer.get_parent().add_sibling(interaction_display)
|
||||
|
||||
func get_interaction_options() -> Array[Interaction]:
|
||||
var interactions: Array[Interaction] = []
|
||||
if has_resource():
|
||||
@@ -61,9 +47,3 @@ func get_interaction_options() -> Array[Interaction]:
|
||||
if not has_building():
|
||||
interactions.append(BUILD)
|
||||
return interactions
|
||||
|
||||
func _on_interaction_finished(timer: Timer) -> void:
|
||||
timer.timeout.disconnect(_on_interaction_finished)
|
||||
if has_resource():
|
||||
interaction_display.queue_free()
|
||||
get_resource().gained_resource.emit(get_resource())
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
extends Resource
|
||||
class_name Interaction
|
||||
|
||||
@export var name: String
|
||||
@export var image: AtlasTexture
|
||||
@@ -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)
|
||||
|
||||
@@ -7,7 +7,7 @@ var last_direction = 0
|
||||
var interaction_location: Vector2i
|
||||
var _interaction_options: InteractionWheel
|
||||
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
@onready var sprite: AnimatedSprite2D = $Sprite
|
||||
@onready var interaction_timer: Timer = $InteractionTimer
|
||||
const INTERACTION_WHEEL = preload("res://scene/interaction_wheel.tscn")
|
||||
|
||||
@@ -19,15 +19,14 @@ func _physics_process(delta: float) -> void:
|
||||
if input_direction:
|
||||
if _interaction_options:
|
||||
_interaction_options.queue_free()
|
||||
_interaction_options = null
|
||||
animation_player.current_animation = "walk"
|
||||
animation_player.play()
|
||||
last_direction = input_direction.angle() + 3 * PI / 2
|
||||
_on_interation_options_closed()
|
||||
sprite.play("walk")
|
||||
last_direction = input_direction.angle() + PI / 2
|
||||
rotation = last_direction
|
||||
interaction_location = Grid.world_to_grid(position) + Vector2i(input_direction.round())
|
||||
Grid.set_selected_tile(interaction_location)
|
||||
else:
|
||||
animation_player.stop()
|
||||
sprite.stop()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("select") and not _interaction_options:
|
||||
@@ -35,10 +34,11 @@ func _input(event: InputEvent) -> void:
|
||||
if interactions.size() > 0:
|
||||
_interaction_options = INTERACTION_WHEEL.instantiate()
|
||||
_interaction_options.initialize(interaction_location, interactions)
|
||||
_interaction_options.closed.connect(_on_interation_options_closed)
|
||||
add_sibling(_interaction_options)
|
||||
|
||||
func _finished_interaction(results: Dictionary) -> void:
|
||||
print("interaction finished: %s" % results)
|
||||
func _on_interation_options_closed() -> void:
|
||||
_interaction_options = null
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
|
||||
Reference in New Issue
Block a user