RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
combat_card_slot_panel.gd
Go to the documentation of this file.
1extends RefCounted
2
3
10
11
12
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))
20 if card.is_empty():
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"))))
24 return button
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]
31 if cooldown_ms > 0:
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" % [
37 slot_label,
38 title,
39 target_summary,
40 footer
41 ]
42 _apply_style(button, state, cooldown_ms > 0)
43 return button
44
45
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))]
56 if range > 0:
57 return "%s - %d squares" % [mode, range]
58 return "Spell"
59
60
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"))))
78 if cooling:
79 button.add_theme_color_override("font_disabled_color", Color(str(state.get("muted_color", "#a9b4bf"))))