updating components to follow new state management

This commit is contained in:
betalars 2023-06-25 23:45:52 +02:00
parent 2e8f22f1d2
commit 56f32a607b
4 changed files with 147 additions and 43 deletions

View File

@ -10,6 +10,15 @@ enum {
@onready var debug_board:Control = $"board of devs"
var has_focus = false:
set(focus):
if not focus == has_focus:
if focus:
for player in anim_players: player.play("reveal")
selection_state = CARDS # fixme
self.show()
has_focus = focus
var selection_state
var anim_players:Array
@ -37,14 +46,14 @@ func _ready():
for control in card_controls:
options.append(control.get_child(1))
anim_players.append(control.get_child(0))
selection_state = CARDS
selection_state = INI
fill_card_slots()
func fill_card_slots():
for i in range($cards.get_child_count()):
var card:Card = $cards.get_child(i).get_child(1)
card.replace_with(debug_board.get_child(2).get_child(i) as Card)
card.replace_with(debug_board.get_child(0).get_child(i) as Card)
func fill_post_slots():
var post_its: Array[PostIt] = []
@ -56,6 +65,7 @@ func fill_post_slots():
options[i].replace_with(post_its[i])
func _unhandled_input(event):
if has_focus:
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"):
curr_selection_id -= 1
elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right") or event.is_action_pressed("ui_focus_prev"):
@ -63,12 +73,7 @@ func _unhandled_input(event):
if event.is_action_pressed("ui_accept"):
pick(curr_selection_id)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func pick(id: int):
print("meep")
if id == -1:
curr_selection_id = 0
return

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=62 format=3 uid="uid://brk4hjdf2x81a"]
[gd_scene load_steps=65 format=3 uid="uid://brk4hjdf2x81a"]
[ext_resource type="Script" path="res://logic-scenes/card_picker/card_picker.gd" id="1_pjntm"]
[ext_resource type="PackedScene" uid="uid://dy5rd437h5hsw" path="res://logic-scenes/board/card.tscn" id="2_dqebt"]
@ -208,11 +208,40 @@ tracks/1/keys = {
"values": [-0.109599, 0.5044, 3.4924]
}
[sub_resource type="Animation" id="Animation_3304u"]
resource_name = "reveal"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.3),
"transitions": PackedFloat32Array(0.435275, 1),
"update": 0,
"values": [Vector2(0, 256), Vector2(-317, 25)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.3),
"transitions": PackedFloat32Array(0.435275, 1),
"update": 0,
"values": [0.174533, -0.109599]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_gdxmh"]
_data = {
"RESET": SubResource("Animation_dinvx"),
"deselect": SubResource("Animation_4dp1g"),
"pick": SubResource("Animation_76klu"),
"reveal": SubResource("Animation_3304u"),
"select": SubResource("Animation_ldr2c"),
"shuffle": SubResource("Animation_abihp"),
"unshuffle": SubResource("Animation_d68d2")
@ -397,11 +426,40 @@ tracks/1/keys = {
"values": [0.0, 0.0436332, 3.22362]
}
[sub_resource type="Animation" id="Animation_orrwn"]
resource_name = "reveal"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.1, 0.4),
"transitions": PackedFloat32Array(0.517633, 1),
"update": 0,
"values": [Vector2(0, 256), Vector2(0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.1, 0.4),
"transitions": PackedFloat32Array(0.517633, 1),
"update": 0,
"values": [0.349066, 0.0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_oxheu"]
_data = {
"RESET": SubResource("Animation_pcher"),
"deselect": SubResource("Animation_5q97d"),
"pick": SubResource("Animation_16dsw"),
"reveal": SubResource("Animation_orrwn"),
"select": SubResource("Animation_2c94q"),
"shuffle": SubResource("Animation_pdic8"),
"unshuffle": SubResource("Animation_sa974")
@ -610,11 +668,40 @@ tracks/1/keys = {
"values": [0.10472, 0.0436332, 3.22362]
}
[sub_resource type="Animation" id="Animation_ep22n"]
resource_name = "reveal"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.2, 0.5),
"transitions": PackedFloat32Array(0.482968, 1),
"update": 0,
"values": [Vector2(0, 256), Vector2(315, 22)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.2, 0.5),
"transitions": PackedFloat32Array(0.482968, 1),
"update": 0,
"values": [0.349066, 0.10472]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_8blxm"]
_data = {
"RESET": SubResource("Animation_pf55g"),
"deselect": SubResource("Animation_6ar8x"),
"pick": SubResource("Animation_wp0c8"),
"reveal": SubResource("Animation_ep22n"),
"select": SubResource("Animation_pcu23"),
"shuffle": SubResource("Animation_vu874"),
"unshuffle": SubResource("Animation_mj8e0")
@ -1376,6 +1463,7 @@ script = ExtResource("1_pjntm")
layout_mode = 2
[node name="label" type="Label" parent="Control"]
visible = false
layout_mode = 2
offset_left = -359.0
offset_top = -256.0

View File

@ -4,7 +4,7 @@ class_name Collectable_Ui
@export var collapsed = true:
set(collapse):
if is_inside_tree():
if is_inside_tree() and not Engine.is_editor_hint():
if State.reduce_motion:
collapsed = false
return
@ -25,21 +25,19 @@ class_name Collectable_Ui
if has_focus == focused: return
if focused:
has_focus = State.request_focus(self)
if has_focus:
has_focus = true
print(visible)
if not visible: show()
collapsed = false
if collected:
$Panel/Content/Buttons/VBoxContainer/put_back.grab_focus()
else:
$Panel/Content/Buttons/VBoxContainer/collect_or_listen.grab_focus()
elif has_focus:
has_focus = false # How did we get here?
State.focus_cleared(self)
has_focus = false
get_viewport().gui_release_focus()
hide()
#hide()
if not visible:
show()
@export var collected: bool = false:
@ -72,6 +70,8 @@ class_name Collectable_Ui
if is_inside_tree():
$Content/Name.text = new_notes
signal card_collected
# Called when the node enters the scene tree for the first time.
func _ready():
#$Panel/Content/ContentNotes.visible = State.show_content_notes
@ -80,13 +80,17 @@ func _ready():
if visible and not collapsed: _show_buttons()
func _hide_buttons():
if is_inside_tree():
if not State.reduce_motion: $AnimationPlayer.play_backwards("show_buttons")
func _show_buttons():
if State.reduce_motion:
if is_inside_tree():
if not State.reduce_motion:
$AnimationPlayer.play("show_buttons")
else:
$AnimationPlayer.play("RESET")
else:
$AnimationPlayer.play("RESET")
func hide():
if visible:
@ -106,4 +110,12 @@ func show():
tween.tween_property(self, "modulate", Color(1, 1, 1), 0.4)
func _yoink_focus():
State.request_focus(self, true)
return # fixme
if not has_focus:
State.request_focus_for(self, true)
func _on_pick_button_pressed():
hide()
print("card collected!")
emit_signal("card_collected")
State.drop_focus(self)

View File

@ -1,11 +1,11 @@
extends RigidBody3D
var has_focus: bool = false :
var has_focus: bool = false:
set(focused):
if has_focus != focused:
if focused:
has_focus = State.request_focus(self)
if is_inside_tree() and has_focus:
has_focus = true
if is_inside_tree():
camera.make_current()
get_viewport().gui_release_focus()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
@ -24,7 +24,6 @@ var has_focus: bool = false :
else:
jitter_strength = 0
has_focus = false
State.focus_cleared(self)
sleeping = has_focus
@ -64,7 +63,7 @@ var has_entered:bool = false
signal ui_exited
func _ready():
if has_focus: _handle_jitter(0)
_handle_jitter(0)
func _process(delta):
@ -77,7 +76,7 @@ func _process(delta):
emit_signal("ui_exited")
has_entered = false
if Input.is_action_just_pressed("ui_accept"):
State.assign_focus_to(focus_ray.get_collider())
State.pass_focus_to(focus_ray.get_collider())
func _physics_process(delta:float):
if has_focus:
@ -108,7 +107,7 @@ func _handle_movement(delta:float):
func _handle_rotation(delta:float):
var smoothness = min(3, 60.0/Engine.get_frames_per_second())
var input_speed = Vector2( Input.get_action_strength("look_right")-Input.get_action_strength("look_left"), Input.get_action_strength("look_down")-Input.get_action_strength("look_up")) * gamepad_response
var input_speed = Vector2( Input.get_action_strength("look_right")-Input.get_action_strength("look_left"), Input.get_action_strength("look_up")-Input.get_action_strength("look_down")) * gamepad_response
if current_mouse_rotation.length()>0:
input_speed = current_mouse_rotation
@ -150,14 +149,14 @@ func _unhandled_input(event:InputEvent):
_handle_mouse_input(event)
get_viewport().set_input_as_handled()
if event is InputEventMouseButton and has_entered:
has_focus = false
get_viewport().set_input_as_handled()
if event.is_action("ui_accept"):
State.assign_focus_to(focus_ray.get_collider())
State.free_focus()
get_viewport().set_input_as_handled()
#if event.is_action_pressed("ui_accept"):
# State.pass_focus_to(focus_ray.get_collider())
# get_viewport().set_input_as_handled()
func _on_empty_click():
State.pass_focus_to(self)
State.request_focus_for(self, true)
func _on_bed_enter(_body):
if not (crouched or on_crouch_cooldown):