mlpcardgame/Scenes/Shared/CardList/CardListItem.gd

43 lines
1.3 KiB
GDScript3
Raw Permalink Normal View History

extends Panel
export var barColors: Dictionary = {}
export var color: String = "none"
2019-06-11 23:13:24 +00:00
export var cardName: String = "Name"
export var cardSubname: String = "Subname"
export var showCost: bool = false
export var cardCost: int = 0
onready var nameLabel := $TextBlock/NameBlock/Name
onready var subnameLabel := $TextBlock/NameBlock/Subname
onready var colorIndicator := $ColorIndicator
onready var gradientIndicator := $ColorIndicator/TextureRect
onready var costIndicator := $TextBlock/CostIndicator
onready var costIndicatorLabel := $TextBlock/CostIndicator/CostLabel
func _ready():
2019-06-11 23:13:24 +00:00
nameLabel.text = cardName
subnameLabel.text = cardSubname
if showCost:
costIndicator.visible = true
costIndicatorLabel.text = str(cardCost)
if color.begins_with("multi|"):
make_gradient(color.trim_prefix("multi|").split("+"))
else:
if not barColors.has(color):
color = "none"
2019-06-11 23:13:24 +00:00
colorIndicator.color = barColors[color]
func make_gradient(colors: Array):
var gradient := Gradient.new()
var step = 1.0/(colors.size() - 1.0)
var i = 0
gradient.colors = PoolColorArray([])
gradient.offsets = PoolRealArray([])
for color in colors:
var offset: float = i*step
gradient.add_point(offset, barColors[color])
i += 1
var texture := GradientTexture.new()
texture.gradient = gradient
2019-06-11 23:13:24 +00:00
gradientIndicator.texture = texture
gradientIndicator.visible = true