RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
guidance_panel.gd
Go to the documentation of this file.
1extends RefCounted
2
3
10
11
12
13func create(parent:Control, options:Dictionary = {}) -> PanelContainer:
14 var panel = PanelContainer.new()
15 panel.name = str(options.get("name", "GuidancePanel"))
16 panel.size_flags_horizontal = Control.SIZE_EXPAND_FILL
17 panel.add_theme_stylebox_override("panel", _style(options))
18 var body = VBoxContainer.new()
19 body.name = "Body"
20 body.add_theme_constant_override("separation", int(options.get("separation", 4)))
21 panel.add_child(body)
22 var title_parent:Control = body
23 if bool(options.get("closeable", false)):
24 var title_row = HBoxContainer.new()
25 title_row.name = "TitleRow"
26 title_row.size_flags_horizontal = Control.SIZE_EXPAND_FILL
27 body.add_child(title_row)
28 title_parent = title_row
29 var title = Label.new()
30 title.name = "Title"
31 title.text = str(options.get("title", "Guide"))
32 title.add_theme_font_size_override("font_size", int(options.get("title_size", 16)))
33 title.add_theme_color_override("font_color", Color(str(options.get("title_color", "#f4d06f"))))
34 title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
35 title_parent.add_child(title)
36 if bool(options.get("closeable", false)):
37 var close = Button.new()
38 close.name = "Close"
39 close.text = str(options.get("close_label", "Hide"))
40 close.custom_minimum_size = Vector2(62, 32)
41 var callback = options.get("close_callback", Callable())
42 close.pressed.connect(func():
43 panel.visible = false
44 if callback.is_valid():
45 callback.call()
46 )
47 title_parent.add_child(close)
48 var text = Label.new()
49 text.name = "Text"
50 text.text = str(options.get("text", ""))
51 text.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
52 text.add_theme_font_size_override("font_size", int(options.get("text_size", 14)))
53 text.add_theme_color_override("font_color", Color(str(options.get("text_color", "#dce7f2"))))
54 body.add_child(text)
55 parent.add_child(panel)
56 return panel
57
58
59
60func render(panel:PanelContainer, title_text:String, body_text:String, options:Dictionary = {}) -> void:
61 if panel == null:
62 return
63 panel.visible = body_text.strip_edges() != ""
64 if options.has("background") or options.has("border"):
65 panel.add_theme_stylebox_override("panel", _style(options))
66 var title = panel.get_node_or_null("Body/Title")
67 if title == null:
68 title = panel.get_node_or_null("Body/TitleRow/Title")
69 if title != null:
70 title.text = title_text
71 if options.has("title_size"):
72 title.add_theme_font_size_override("font_size", int(options.get("title_size", 16)))
73 var text = panel.get_node_or_null("Body/Text")
74 if text != null:
75 text.text = body_text
76 if options.has("text_size"):
77 text.add_theme_font_size_override("font_size", int(options.get("text_size", 14)))
78
79
80func _style(options:Dictionary) -> StyleBoxFlat:
81 var style = StyleBoxFlat.new()
82 style.bg_color = Color(str(options.get("background", "#15212b")))
83 style.border_color = Color(str(options.get("border", "#3c5062")))
84 style.set_border_width_all(int(options.get("border_width", 1)))
85 style.set_corner_radius_all(int(options.get("radius", 6)))
86 style.content_margin_left = int(options.get("margin_left", 10))
87 style.content_margin_right = int(options.get("margin_right", 10))
88 style.content_margin_top = int(options.get("margin_top", 8))
89 style.content_margin_bottom = int(options.get("margin_bottom", 8))
90 return style