Completely refractor the project so the code isn't so terrible #7

Merged
CactiChameleon9 merged 39 commits from card-rework into main 2022-08-24 09:51:59 +01:00
3 changed files with 77 additions and 1 deletions
Showing only changes of commit 41c2689e1f - Show all commits

View File

@ -13,6 +13,8 @@ const TYPE_COLORS = [
const input_dice_view = preload("res://UI/InputDiceView.tscn")
var input_dice_views = []
var hovering : bool = false setget set_hovering
var card : Card = Card.new() setget update_cardview
@ -116,3 +118,19 @@ func disconnect_signals():
func connect_signals():
card.connect("card_removed", self, "card_view_run")
func set_hovering(value : bool):
# set the hovering value
hovering = value
# wait until the old animation is finished
if ($AnimationPlayer.current_animation != "Hovering"
and $AnimationPlayer.current_animation != ""):
yield($AnimationPlayer, "animation_finished")
if hovering:
$AnimationPlayer.play("Hovering")
if not hovering:
$AnimationPlayer.play("RESET")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=12 format=2]
[ext_resource path="res://UI/CardView.gd" type="Script" id=1]
[ext_resource path="res://Assets/Metropolis-font/Metropolis-Bold.ttf" type="DynamicFontData" id=4]
@ -83,6 +83,23 @@ tracks/2/keys = {
} ]
}
[sub_resource type="Animation" id=11]
resource_name = "Hovering"
length = 0.15
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath("LocalPosition:rect_position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.15 ),
"transitions": PoolRealArray( 6.9644, 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( 0, -40 ) ]
}
[sub_resource type="Animation" id=8]
length = 0.001
tracks/0/type = "value"
@ -168,4 +185,5 @@ autowrap = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
"anims/Drop Off" = SubResource( 10 )
"anims/Fly Off" = SubResource( 7 )
anims/Hovering = SubResource( 11 )
anims/RESET = SubResource( 8 )

View File

@ -13,6 +13,7 @@ export (String) var view_property = "item"
var character : Character = Character.new() setget update_items_shown
var item_views = []
var hovering_view : int = -1
func update_items_shown(new_character = null):
@ -38,3 +39,42 @@ func remove_from_item_views(item_view):
var to_remove : int = item_views.find(item_view)
if to_remove != -1:
item_views.remove(to_remove)
func _physics_process(_delta):
if not active:
hovering_view = -1
return
# set the hovering view if just selected
if hovering_view == -1:
hovering_view = 0
item_views[hovering_view].hovering = false
# move the selection forward or backward the list depending on input
if (Input.is_action_just_pressed("ui_down") or
Input.is_action_just_pressed("ui_right")):
# disable hovering on the previous item
item_views[hovering_view].hovering = false
# cycle forward
hovering_view += 1
if hovering_view >= len(item_views):
hovering_view = 0
# enable hovering on the present item
item_views[hovering_view].hovering = true
if (Input.is_action_just_pressed("ui_up") or
Input.is_action_just_pressed("ui_left")):
item_views[hovering_view].hovering = false
hovering_view -= 1
if hovering_view < 0:
hovering_view = len(item_views) -1
item_views[hovering_view].hovering = true