mlpcardgame/Scenes/Draft/CardListItem.gd

27 lines
749 B
GDScript3
Raw Normal View History

extends Panel
export var barColors: Dictionary = {}
export var color: String = "none"
func _ready():
if color.begins_with("multi|"):
make_gradient(color.trim_prefix("multi|").split("+"))
else:
if not barColors.has(color):
color = "none"
$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
$ColorIndicator/TextureRect.texture = texture
$ColorIndicator/TextureRect.visible = true