From 56f32a607b50202164a6841ff59ef561a9e870da Mon Sep 17 00:00:00 2001 From: betalars Date: Sun, 25 Jun 2023 23:45:52 +0200 Subject: [PATCH] updating components to follow new state management --- src/logic-scenes/card_picker/card_picker.gd | 31 ++++--- src/logic-scenes/card_picker/card_picker.tscn | 90 ++++++++++++++++++- .../collectable/collectable_ui.gd | 46 ++++++---- .../player_controller/player_controller.gd | 23 +++-- 4 files changed, 147 insertions(+), 43 deletions(-) diff --git a/src/logic-scenes/card_picker/card_picker.gd b/src/logic-scenes/card_picker/card_picker.gd index 17c2c2c..7afdd1d 100644 --- a/src/logic-scenes/card_picker/card_picker.gd +++ b/src/logic-scenes/card_picker/card_picker.gd @@ -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,19 +65,15 @@ func fill_post_slots(): options[i].replace_with(post_its[i]) func _unhandled_input(event): - 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"): - curr_selection_id += 1 - 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 + 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"): + curr_selection_id += 1 + if event.is_action_pressed("ui_accept"): + pick(curr_selection_id) func pick(id: int): - print("meep") if id == -1: curr_selection_id = 0 return diff --git a/src/logic-scenes/card_picker/card_picker.tscn b/src/logic-scenes/card_picker/card_picker.tscn index 8948153..454e093 100644 --- a/src/logic-scenes/card_picker/card_picker.tscn +++ b/src/logic-scenes/card_picker/card_picker.tscn @@ -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 diff --git a/src/logic-scenes/collectable/collectable_ui.gd b/src/logic-scenes/collectable/collectable_ui.gd index 8a29608..d7847d0 100644 --- a/src/logic-scenes/collectable/collectable_ui.gd +++ b/src/logic-scenes/collectable/collectable_ui.gd @@ -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: - collapsed = false - if collected: - $Panel/Content/Buttons/VBoxContainer/put_back.grab_focus() - else: - $Panel/Content/Buttons/VBoxContainer/collect_or_listen.grab_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,11 +80,15 @@ func _ready(): if visible and not collapsed: _show_buttons() func _hide_buttons(): - if not State.reduce_motion: $AnimationPlayer.play_backwards("show_buttons") + if is_inside_tree(): + if not State.reduce_motion: $AnimationPlayer.play_backwards("show_buttons") func _show_buttons(): - if State.reduce_motion: - $AnimationPlayer.play("show_buttons") + if is_inside_tree(): + if not State.reduce_motion: + $AnimationPlayer.play("show_buttons") + else: + $AnimationPlayer.play("RESET") else: $AnimationPlayer.play("RESET") @@ -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) diff --git a/src/logic-scenes/player_controller/player_controller.gd b/src/logic-scenes/player_controller/player_controller.gd index b85d2a5..0ba9fee 100644 --- a/src/logic-scenes/player_controller/player_controller.gd +++ b/src/logic-scenes/player_controller/player_controller.gd @@ -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):