13func create_button(slot_index:int, card:Dictionary, state:Dictionary = {}, formatter = null) -> Button:
14 var button = Button.new()
15 button.name =
"CombatSlot%dButton" % (slot_index + 1)
16 button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
17 button.custom_minimum_size = Vector2(0, int(state.get(
"height", 82)))
18 button.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
19 var slot_label = str(state.get(
"slot_label", slot_index + 1))
21 button.text =
"%s\nEmpty" % slot_label
22 button.disabled = true
23 button.add_theme_color_override(
"font_color", Color(str(state.get(
"muted_color",
"#9ca3af"))))
25 var cooldown_ms = int(state.get(
"cooldown_ms", 0))
26 var title = str(card.get(
"name",
"Spell"))
27 var energy = int(card.get(
"energy", 0))
28 var damage = int(card.get(
"damage", 0))
29 var target_summary = _target_summary(card, formatter, state.get(
"targeting_config", {}))
30 var footer =
"Cost %d | Dmg %d" % [energy, damage]
32 footer =
"Cooling %.1fs" % (float(cooldown_ms) / 1000.0)
33 button.disabled = true
34 if bool(state.get(
"selected", false)):
35 footer =
"Aiming | press again to cancel"
36 button.text =
"%s: %s\n%s\n%s" % [
42 _apply_style(button, state, cooldown_ms > 0)
46func _target_summary(card:Dictionary, formatter, config:Dictionary) -> String:
47 if formatter != null
and formatter.has_method(
"get_targeting_summary"):
48 var summary = formatter.get_targeting_summary(card, config)
49 return "%s - %s" % [str(summary.get(
"mode",
"Spell")), str(summary.get(
"range_text",
""))]
50 var targeting = card.get(
"targeting", {})
51 if targeting
is Dictionary:
52 var mode = str(targeting.get(
"type",
"projectile")).capitalize()
53 var range = int(targeting.get(
"range", 0))
54 if str(targeting.get(
"type",
"")) ==
"aoe":
55 return "%s - radius %d" % [mode, int(targeting.get(
"aoe_radius", 1))]
57 return "%s - %d squares" % [mode, range]
61func _apply_style(button:Button, state:Dictionary, cooling:bool) -> void:
62 var normal = StyleBoxFlat.new()
63 normal.bg_color = Color(str(state.get(
"background",
"#182734")))
64 normal.border_color = Color(str(state.get(
"cooldown_border",
"#6b7280")
if cooling
else state.get(
"border",
"#3d566c")))
65 if bool(state.get(
"selected", false)):
66 normal.border_color = Color(str(state.get(
"selected_border",
"#f0c85a")))
67 normal.set_border_width_all(2
if bool(state.get(
"selected", false))
else 1)
68 normal.set_corner_radius_all(6)
69 normal.content_margin_left = 8
70 normal.content_margin_right = 8
71 normal.content_margin_top = 6
72 normal.content_margin_bottom = 6
73 button.add_theme_stylebox_override(
"normal", normal)
74 button.add_theme_stylebox_override(
"hover", normal)
75 button.add_theme_stylebox_override(
"pressed", normal)
76 button.add_theme_stylebox_override(
"disabled", normal)
77 button.add_theme_color_override(
"font_color", Color(str(state.get(
"text_color",
"#e8f0f7"))))
79 button.add_theme_color_override(
"font_disabled_color", Color(str(state.get(
"muted_color",
"#a9b4bf"))))