RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
objective_panel.gd
Go to the documentation of this file.
1extends RefCounted
2
3
6
7var root:PanelContainer
8
9
10
11func create(parent:Control, options:Dictionary = {}) -> PanelContainer:
12 root = PanelContainer.new()
13 root.name = str(options.get("name", "ObjectivePanel"))
14 root.size_flags_horizontal = Control.SIZE_EXPAND_FILL
15 root.add_theme_stylebox_override("panel", _style(options))
16 var body = VBoxContainer.new()
17 body.name = "Body"
18 body.add_theme_constant_override("separation", int(options.get("separation", 6)))
19 root.add_child(body)
20 var title = Label.new()
21 title.name = "Title"
22 title.text = str(options.get("title", "Objectives"))
23 title.add_theme_font_size_override("font_size", int(options.get("title_size", 17)))
24 title.add_theme_color_override("font_color", Color(str(options.get("title_color", "#f1f5f9"))))
25 body.add_child(title)
26 var rows = VBoxContainer.new()
27 rows.name = "Rows"
28 rows.add_theme_constant_override("separation", int(options.get("row_separation", 4)))
29 body.add_child(rows)
30 parent.add_child(root)
31 return root
32
33
34
36func render(objectives:Array, options:Dictionary = {}) -> void:
37 if root == null:
38 return
39 var title = root.get_node_or_null("Body/Title")
40 if title != null:
41 title.text = str(options.get("title", "Objectives"))
42 var rows = root.get_node_or_null("Body/Rows")
43 if rows == null:
44 return
45 _clear_children(rows)
46 if objectives.is_empty():
47 rows.add_child(_empty_label(options))
48 return
49 for objective in objectives:
50 if objective is Dictionary:
51 rows.add_child(_objective_row(objective, options))
52
53
54func _objective_row(objective:Dictionary, options:Dictionary) -> Control:
55 var row = VBoxContainer.new()
56 row.name = "%sObjective" % str(objective.get("id", "item")).capitalize()
57 row.add_theme_constant_override("separation", 2)
58 var header = HBoxContainer.new()
59 header.name = "Header"
60 header.add_theme_constant_override("separation", 6)
61 row.add_child(header)
62 var mark = Label.new()
63 mark.name = "Mark"
64 mark.text = "[x]" if bool(objective.get("complete", false)) else ("[!]" if bool(objective.get("active", false)) else "[ ]")
65 mark.custom_minimum_size = Vector2(34, 0)
66 mark.add_theme_color_override("font_color", _state_color(objective, options))
67 header.add_child(mark)
68 var label = Label.new()
69 label.name = "Label"
70 label.text = str(objective.get("label", "Objective"))
71 label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
72 label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
73 label.add_theme_color_override("font_color", Color(str(options.get("text_color", "#e8f0f7"))))
74 header.add_child(label)
75 var tag = Label.new()
76 tag.name = "Tag"
77 tag.text = "Required" if bool(objective.get("required", true)) else "Optional"
78 tag.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
79 tag.custom_minimum_size = Vector2(76, 0)
80 tag.add_theme_color_override("font_color", Color(str(options.get("required_color", "#f0c85a") if bool(objective.get("required", true)) else options.get("optional_color", "#8bd3ff"))))
81 header.add_child(tag)
82 var detail_text = str(objective.get("detail", ""))
83 if detail_text != "":
84 var detail = Label.new()
85 detail.name = "Detail"
86 detail.text = detail_text
87 detail.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
88 detail.add_theme_color_override("font_color", Color(str(options.get("muted_color", "#a9b4bf"))))
89 row.add_child(detail)
90 var reward_text = str(objective.get("reward_hint", ""))
91 if reward_text != "":
92 var reward = Label.new()
93 reward.name = "Reward"
94 reward.text = "Reward: %s" % reward_text
95 reward.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
96 reward.add_theme_color_override("font_color", Color(str(options.get("reward_color", "#8bd3ff"))))
97 row.add_child(reward)
98 return row
99
100
101func _empty_label(options:Dictionary) -> Label:
102 var label = Label.new()
103 label.name = "Empty"
104 label.text = str(options.get("empty_text", "No objectives."))
105 label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
106 label.add_theme_color_override("font_color", Color(str(options.get("muted_color", "#a9b4bf"))))
107 return label
108
109
110func _state_color(objective:Dictionary, options:Dictionary) -> Color:
111 if bool(objective.get("complete", false)):
112 return Color(str(options.get("complete_color", "#5ddf7a")))
113 if bool(objective.get("active", false)):
114 return Color(str(options.get("active_color", "#f0c85a")))
115 return Color(str(options.get("muted_color", "#a9b4bf")))
116
117
118func _style(options:Dictionary) -> StyleBoxFlat:
119 var style = StyleBoxFlat.new()
120 style.bg_color = Color(str(options.get("background", "#15212b")))
121 style.border_color = Color(str(options.get("border", "#3c5062")))
122 style.set_border_width_all(1)
123 style.set_corner_radius_all(6)
124 style.content_margin_left = 10
125 style.content_margin_right = 10
126 style.content_margin_top = 8
127 style.content_margin_bottom = 8
128 return style
129
130
131func _clear_children(node:Node) -> void:
132 for child in node.get_children():
133 child.queue_free()