Implement a basic color changing card

This commit is contained in:
CactiChameleon9 2022-07-16 10:33:31 +01:00
parent 263d323d58
commit 97322b565f
4 changed files with 83 additions and 0 deletions

25
UI/Card.gd Normal file
View File

@ -0,0 +1,25 @@
tool
extends Control
enum TYPE {
DAMAGE = 0
UTILITY = 1
SPECIAL = 2
EFFECT = 3
}
const TYPE_COLORS = [
Color("#db4758"), # DAMAGE
Color("#3cc361"), # UTILITY
Color("#ddd55c"), # SPECIAL
Color("#bc5ec6"), # EFFECT
]
export (TYPE) var type
func _ready():
var card_style = $PanelContainer.get('custom_styles/panel').duplicate(true)
card_style.set_bg_color(TYPE_COLORS[type])
$PanelContainer.set('custom_styles/panel', card_style)

16
UI/Card.tscn Normal file
View File

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://UI/Card.gd" type="Script" id=1]
[ext_resource path="res://UI/CardStyle.tres" type="StyleBox" id=2]
[node name="Card" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource( 1 )
[node name="PanelContainer" type="PanelContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
custom_styles/panel = ExtResource( 2 )

7
UI/CardStyle.tres Normal file
View File

@ -0,0 +1,7 @@
[gd_resource type="StyleBoxFlat" format=2]
[resource]
corner_radius_top_left = 20
corner_radius_top_right = 20
corner_radius_bottom_right = 20
corner_radius_bottom_left = 20

35
UI/CardView.tscn Normal file
View File

@ -0,0 +1,35 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://UI/Card.tscn" type="PackedScene" id=1]
[node name="CardView" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="HBox" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
custom_constants/separation = 50
[node name="Card1" parent="HBox" instance=ExtResource( 1 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 308.0
margin_bottom = 600.0
type = 1
[node name="Card2" parent="HBox" instance=ExtResource( 1 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 358.0
margin_right = 666.0
margin_bottom = 600.0
type = 2
[node name="Card3" parent="HBox" instance=ExtResource( 1 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 716.0
margin_right = 1024.0
margin_bottom = 600.0
type = 3