Quit-Rolling-Around-gmtk-ja.../UI/CardView.gd

84 lines
2.1 KiB
GDScript3
Raw Normal View History

2022-07-25 20:25:57 +01:00
tool
2022-07-25 11:13:09 +01:00
extends Control
const TYPE_COLORS = [
Color("#db4758"), # DAMAGE
Color("#3cc361"), # UTILITY
Color("#bcb64f"), # SPECIAL
Color("#bc5ec6"), # EFFECT
Color("#a4a4a4"), # MOVEMENT
]
const input_dice_view = preload("res://UI/InputDiceView.tscn")
var input_dice_views = []
var card : Card = Card.new() setget update_cardview
func _ready():
update_cardview()
connect_signals()
2022-07-25 11:13:09 +01:00
func update_cardview(new_card = null):
# allow the update card function to work with and without setget
if new_card != null:
card = new_card
connect_signals()
2022-07-25 11:13:09 +01:00
# change the color of the panel to match the appropriate type
2022-07-25 21:11:52 +01:00
var card_style = $"%Background".get('custom_styles/panel').duplicate(true)
2022-07-25 11:13:09 +01:00
card_style.set_bg_color(TYPE_COLORS[card.card_info.type])
2022-07-25 21:11:52 +01:00
$"%Background".set('custom_styles/panel', card_style)
2022-07-25 11:13:09 +01:00
# change the name and description
2022-07-25 21:11:52 +01:00
$"%Name".text = card.card_info.name
$"%Description".text = card.card_info.description
2022-07-25 11:13:09 +01:00
# add the correct number of input dice views
for i in card.card_info.number_of_dice:
add_input_dice_view()
2022-07-25 20:25:57 +01:00
# set the extra info
var extra_text = ""
if card.card_info.addition_dice == true:
2022-07-25 20:45:37 +01:00
# set the dice to have the remaining addition
extra_text = str(card.addition_dice_amount)
2022-07-25 20:25:57 +01:00
else:
2022-07-25 20:45:37 +01:00
# set the dice to have a list of accepted dice
2022-07-25 20:25:57 +01:00
for dice in card.card_info.accepted_dice:
extra_text += str(dice) + ", "
extra_text = extra_text.trim_suffix(", ")
for i in input_dice_views:
i.set_extra_info(extra_text)
2022-07-25 20:45:37 +01:00
# set bold dice if addition dice
2022-07-25 21:05:10 +01:00
if card.card_info.addition_dice == true:
for i in input_dice_views:
i.bold = true
2022-07-25 20:45:37 +01:00
2022-07-25 11:13:09 +01:00
# add an input_dice_view to the array (for easy management)
# and to the autogrid
func add_input_dice_view():
var dice_view = input_dice_view.instance()
input_dice_views.append(dice_view)
$"%AutoGrid".add_child(dice_view)
2022-07-26 08:02:04 +01:00
# this is run once the card emits card_removed
func card_view_run():
# play the using animation
$AnimationPlayer.play("Fly Off")
yield($AnimationPlayer, "animation_finished")
# remove the card completely once used
queue_free()
func connect_signals():
2022-07-26 08:02:04 +01:00
card.connect("card_removed", self, "card_view_run")