implement #223: controller support in burning cards section
This commit is contained in:
parent
0a87cc4205
commit
5bb5a6d112
|
|
@ -0,0 +1,25 @@
|
|||
class_name CandleCursor extends CPUParticles2D
|
||||
|
||||
var noise: = FastNoiseLite.new()
|
||||
var noise_position:= 0.0
|
||||
var noise_offset:= Vector2.ZERO
|
||||
|
||||
var gamepad_mode: bool = false
|
||||
var gamepad_target: Vector2 = Vector2.ZERO
|
||||
|
||||
var cursor_target: Vector2 = Vector2.ZERO
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
if gamepad_mode:
|
||||
cursor_target -= (cursor_target - gamepad_target) * 4 * delta
|
||||
else:
|
||||
cursor_target = get_viewport().get_mouse_position()
|
||||
|
||||
var diff: Vector2 = position - noise_offset - cursor_target
|
||||
noise_position += delta * 100
|
||||
noise_offset = Vector2(noise.get_noise_1d(noise_position), noise.get_noise_1d(-noise_position))*30.0
|
||||
position = cursor_target + noise_offset
|
||||
rotation = lerp(rotation, clamp(-PI/3, diff.x *.05, PI/3), delta*20.0)
|
||||
|
||||
lifetime = max(0.01, lerp(lifetime, .25 * (1.0/(1.0+diff.length()*.1) - noise_offset.length()*.02), 0.2))
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://rxt7txuyr3vj
|
||||
|
|
@ -14,6 +14,9 @@ var has_stage = false:
|
|||
process_mode = Node.PROCESS_MODE_DISABLED
|
||||
has_stage = focus
|
||||
|
||||
@onready var cursor: CandleCursor = %CandleCursor
|
||||
@onready var ancors: Array[Control] = [%Ancor1, %Ancor2, %Ancor3, %Ancor4]
|
||||
|
||||
func _ready():
|
||||
Scenes.sign_up_for_sequence(burn_cards, Scenes.id.TRANSITION, 1)
|
||||
%SkipButton.pressed.connect(card_burned.emit)
|
||||
|
|
@ -29,7 +32,7 @@ func burn_cards(_id, _repeat):
|
|||
|
||||
random_cards.shuffle()
|
||||
|
||||
for ancor:Control in [%Ancor1, %Ancor2, %Ancor3, %Ancor4]:
|
||||
for ancor:Control in ancors:
|
||||
if random_cards.size() > 0:
|
||||
ancor.get_child(0).queue_free()
|
||||
var new_child: Card = random_cards.pop_front()
|
||||
|
|
@ -54,3 +57,42 @@ func handle_hover(to_handle: Area2D):
|
|||
func handle_mouse_button(event: InputEventMouseButton, card: Card):
|
||||
if event.button_index == MOUSE_BUTTON_MASK_LEFT and event.is_pressed() and not event.is_echo():
|
||||
card.burn_state = Card.burned.BURNING
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if has_stage:
|
||||
if event.is_action_pressed("ui_up"):
|
||||
handle_direction_input(Vector2.UP)
|
||||
elif event.is_action_pressed("ui_down"):
|
||||
handle_direction_input(Vector2.DOWN)
|
||||
elif event.is_action_pressed("ui_left"):
|
||||
handle_direction_input(Vector2.LEFT)
|
||||
elif event.is_action_pressed("ui_right"):
|
||||
handle_direction_input(Vector2.RIGHT)
|
||||
|
||||
|
||||
|
||||
var focus_cards: bool = true
|
||||
var card_index: int = 0:
|
||||
set(index):
|
||||
ancors[card_index].get_child(0)._on_mouse_exited()
|
||||
card_index = index % 4
|
||||
handle_hover(ancors[card_index].get_child(0))
|
||||
func handle_direction_input(direction: Vector2):
|
||||
cursor.gamepad_mode = true
|
||||
match direction:
|
||||
Vector2.UP:
|
||||
focus_cards = true
|
||||
cursor.visible = true
|
||||
%SkipButton.release_focus()
|
||||
card_index = card_index
|
||||
Vector2.DOWN:
|
||||
focus_cards = false
|
||||
cursor.visible = false
|
||||
%SkipButton.grab_focus()
|
||||
ancors[card_index].get_child(0)._on_mouse_exited()
|
||||
Vector2.LEFT:
|
||||
card_index -= 1
|
||||
Vector2.RIGHT:
|
||||
card_index += 1
|
||||
cursor.gamepad_target = ancors[card_index].get_child(0).global_position + Vector2(-120, 150)
|
||||
if not focus_cards: cursor.gamepad_target += Vector2(0, 50)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ tracks/0/keys = {
|
|||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("../../CursorCandle:color")
|
||||
tracks/1/path = NodePath("../../CandleCursor:color")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
|
|
@ -74,7 +74,7 @@ tracks/0/keys = {
|
|||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("../../CursorCandle:color")
|
||||
tracks/1/path = NodePath("../../CandleCursor:color")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
|
|
@ -214,7 +214,8 @@ self_modulate = Color(1, 1, 1, 0)
|
|||
scale = Vector2(100, 100)
|
||||
texture = SubResource("GradientTexture2D_x6cxt")
|
||||
|
||||
[node name="CursorCandle" parent="." instance=ExtResource("3_l4ogr")]
|
||||
[node name="CandleCursor" parent="." instance=ExtResource("3_l4ogr")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
root_node = NodePath("../Control/HSplitContainer")
|
||||
|
|
|
|||
Loading…
Reference in New Issue