You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.7 KiB
GDScript

8 months ago
@tool
2 years ago
extends Control
8 months ago
@onready var core_item_list: Array[CoreItemSub] = [
$CoreItemFree/Up, $CoreItemFree/Left, $CoreItemFree/Down, $CoreItemFree/Right,
$CoreItemLock/Up, $CoreItemLock/Left, $CoreItemLock/Down, $CoreItemLock/Right,
]
8 months ago
@onready var core_item_input_list: Array[InputItem] = [
$CoreItemInput/Up, $CoreItemInput/Left, $CoreItemInput/Down, $CoreItemInput/Right,
]
2 years ago
@onready var core_item_free: Control = $CoreItemFree
@onready var core_item_lock: Control = $CoreItemLock
2 years ago
8 months ago
@export var is_switch: bool:
set(value):
is_switch = value
is_switch_animation = true
@export var is_lock: bool:
set(value):
is_lock = value
core_item_free.visible = not is_lock
core_item_lock.visible = is_lock
@export var switch_animation_time_max: float = 0.1
var switch_animation_time: float = 0.0
var is_switch_animation: bool
@export var switch_center_pos1 = Vector2(560, 300)
@export var switch_center_pos2 = Vector2(480, 280)
var switch_item_pos1 = [
Vector2(0, -16), Vector2(-24, 0), Vector2(0, 16), Vector2(24, 0),
Vector2(0, -16), Vector2(-24, 0), Vector2(0, 16), Vector2(24, 0),
]
var switch_item_pos2 = [
Vector2(0, -32), Vector2(-32, 0), Vector2(0, 32), Vector2(32, 0),
Vector2(0, -32), Vector2(-32, 0), Vector2(0, 32), Vector2(32, 0),
]
var core_item_input_pos1 = Vector2(0, 0)
var core_item_input_pos2 = [
Vector2(0, -16), Vector2(-16, 0), Vector2(0, 16), Vector2(16, 0),
]
func _process(delta):
if not is_switch_animation:
return
switch_animation_time += delta if is_switch else -delta
switch_animation_time = max(0, min(switch_animation_time, switch_animation_time_max))
var rate = switch_animation_time / switch_animation_time_max
animation_lerp(rate)
if switch_animation_time == switch_animation_time_max or switch_animation_time == 0:
is_switch_animation = false
2 years ago
func on_core_active_list_changed(core_list: Array[CoreCfg]):
for i in range(len(core_list)):
8 months ago
var cfg: CoreCfg = core_list[i]
var item: CoreItemSub = core_item_list[i] as CoreItemSub
8 months ago
item.set_info(cfg)
2 years ago
func on_is_switch_changed(value: bool):
8 months ago
is_switch = value
2 years ago
8 months ago
func on_is_lock_changed(value: bool):
is_lock = value
8 months ago
func animation_lerp(rate: float):
position = lerp(switch_center_pos1, switch_center_pos2, rate)
for i in len(core_item_list):
var item: CoreItemSub = core_item_list[i] as CoreItemSub
item.position = lerp(switch_item_pos1[i], switch_item_pos2[i], rate)
item.detail_rate = rate
for i in len(core_item_input_list):
var item: InputItem = core_item_input_list[i] as InputItem
item.position = lerp(core_item_input_pos1, core_item_input_pos2[i], rate)
item.detail_rate = rate