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()
18 body.add_theme_constant_override(
"separation", int(options.get(
"separation", 6)))
20 var title = Label.new()
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"))))
26 var rows = VBoxContainer.new()
28 rows.add_theme_constant_override(
"separation", int(options.get(
"row_separation", 4)))
30 parent.add_child(root)
36func render(objectives:Array, options:Dictionary = {}) -> void:
39 var title = root.get_node_or_null(
"Body/Title")
41 title.text = str(options.get(
"title",
"Objectives"))
42 var rows = root.get_node_or_null(
"Body/Rows")
46 if objectives.is_empty():
47 rows.add_child(_empty_label(options))
49 for objective
in objectives:
50 if objective
is Dictionary:
51 rows.add_child(_objective_row(objective, options))
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)
62 var mark = Label.new()
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()
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)
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"))))
82 var detail_text = str(objective.get(
"detail",
""))
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"))))
90 var reward_text = str(objective.get(
"reward_hint",
""))
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"))))
101func _empty_label(options:Dictionary) -> Label:
102 var label = Label.new()
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"))))
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")))
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
131func _clear_children(node:Node) -> void:
132 for child
in node.get_children():