16func create(parent:Control, options:Dictionary = {}) -> GridContainer:
17 root = GridContainer.new()
18 root.name = str(options.get(
"name",
"InventoryCategoryPanels"))
19 root.columns = int(options.get(
"columns", 1))
20 columns = root.columns
21 root.add_theme_constant_override(
"h_separation", int(options.get(
"h_separation", 8)))
22 root.add_theme_constant_override(
"v_separation", int(options.get(
"v_separation", 8)))
23 root.size_flags_horizontal = Control.SIZE_EXPAND_FILL
24 parent.add_child(root)
30func render(categories:Array, options:Dictionary = {}) -> void:
34 root.columns = int(options.get(
"columns", columns))
35 for category
in categories:
36 if category
is Dictionary:
37 root.add_child(_category_panel(category, options))
40func _category_panel(category:Dictionary, options:Dictionary) -> PanelContainer:
41 var panel = PanelContainer.new()
42 panel.name =
"%sPanel" % str(category.get(
"id",
"Category")).capitalize()
43 panel.size_flags_horizontal = Control.SIZE_EXPAND_FILL
44 var style = StyleBoxFlat.new()
45 style.bg_color = Color(str(options.get(
"background",
"#17232d")))
46 style.border_color = Color(str(options.get(
"border",
"#34495c")))
47 style.border_width_left = 1
48 style.border_width_right = 1
49 style.border_width_top = 1
50 style.border_width_bottom = 1
51 style.corner_radius_top_left = 6
52 style.corner_radius_top_right = 6
53 style.corner_radius_bottom_left = 6
54 style.corner_radius_bottom_right = 6
55 style.content_margin_left = 10
56 style.content_margin_right = 10
57 style.content_margin_top = 8
58 style.content_margin_bottom = 8
59 panel.add_theme_stylebox_override(
"panel", style)
60 var body = VBoxContainer.new()
62 body.add_theme_constant_override(
"separation", 5)
64 var title = Label.new()
66 title.text = str(category.get(
"title",
"Inventory"))
67 title.add_theme_font_size_override(
"font_size", int(options.get(
"title_size", 17)))
68 title.add_theme_color_override(
"font_color", Color(str(options.get(
"title_color",
"#f1f5f9"))))
69 title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
71 var underline = ColorRect.new()
72 underline.name =
"Underline"
73 underline.custom_minimum_size = Vector2(0, 2)
74 underline.color = Color(str(options.get(
"accent",
"#f0c85a")))
75 body.add_child(underline)
76 var description = str(category.get(
"description",
""))
78 var description_label = Label.new()
79 description_label.name =
"Description"
80 description_label.text = description
81 description_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
82 description_label.add_theme_color_override(
"font_color", Color(str(options.get(
"muted_color",
"#aeb8c4"))))
83 body.add_child(description_label)
84 var rows = category.get(
"rows", [])
85 if not rows
is Array
or rows.is_empty():
86 var empty = Label.new()
88 empty.text = str(category.get(
"empty_text",
"None"))
89 empty.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
90 empty.add_theme_color_override(
"font_color", Color(str(options.get(
"muted_color",
"#aeb8c4"))))
95 body.add_child(_row_control(row, options))
99func _row_control(row:Dictionary, options:Dictionary) -> Control:
100 var line = HBoxContainer.new()
101 line.name =
"%sRow" % str(row.get(
"id",
"Item")).capitalize()
102 line.add_theme_constant_override(
"separation", 8)
103 var label = Label.new()
105 label.text = str(row.get(
"label", row.get(
"id",
"")))
106 label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
107 label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
108 label.add_theme_color_override(
"font_color", Color(str(options.get(
"text_color",
"#e5edf5"))))
109 line.add_child(label)
110 var count = Label.new()
112 count.text =
"x%d" % int(row.get(
"count", 0))
113 count.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
114 count.custom_minimum_size = Vector2(48, 0)
115 count.add_theme_color_override(
"font_color", Color(str(options.get(
"accent",
"#f0c85a"))))
116 line.add_child(count)
120func _clear_children(node:Node) -> void:
121 for child
in node.get_children():