]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/Settings/settings_editor.gd
Squashed commit of the following:
[wolf-seeking-sheep.git] / addons / dialogic / Editor / Settings / settings_editor.gd
1 @tool
2 extends DialogicEditor
3
4 ## Editor that contains all settings
5
6 var button_group := ButtonGroup.new()
7 var registered_sections: Array[DialogicSettingsPage] = []
8
9
10 func _get_title() -> String:
11         return "Settings"
12
13
14 func _get_icon() -> Texture:
15         return get_theme_icon("PluginScript", "EditorIcons")
16
17
18 func _register() -> void:
19         editors_manager.register_simple_editor(self)
20         self.alternative_text = "Customize dialogic and it's behaviour"
21
22
23 func _ready() -> void:
24         if get_parent() is SubViewport:
25                 return
26
27         register_settings_section("res://addons/dialogic/Editor/Settings/settings_general.tscn")
28         register_settings_section("res://addons/dialogic/Editor/Settings/settings_translation.tscn")
29         register_settings_section("res://addons/dialogic/Editor/Settings/settings_modules.tscn")
30
31         for indexer in DialogicUtil.get_indexers():
32                 for settings_page in indexer._get_settings_pages():
33                         register_settings_section(settings_page)
34
35         add_registered_sections()
36         %SettingsTabs.get_child(0).button_pressed = true
37         %SettingsContent.get_child(0).show()
38
39
40 func register_settings_section(path:String) -> void:
41         var section: Control = load(path).instantiate()
42         registered_sections.append(section)
43
44
45 func add_registered_sections() -> void:
46         for i in %SettingsTabs.get_children():
47                 i.queue_free()
48         for i in %FeatureTabs.get_children():
49                 i.queue_free()
50
51         for i in %SettingsContent.get_children():
52                 i.queue_free()
53
54
55         registered_sections.sort_custom(section_sort)
56         for section in registered_sections:
57
58                 section.name = section._get_title()
59
60                 var vbox := VBoxContainer.new()
61                 vbox.set_meta('section', section)
62                 vbox.size_flags_vertical = Control.SIZE_EXPAND_FILL
63                 vbox.name = section.name
64                 var hbox := HBoxContainer.new()
65
66                 var title := Label.new()
67                 title.text = section.name
68                 title.theme_type_variation = 'DialogicSectionBig'
69                 hbox.add_child(title)
70                 vbox.add_child(hbox)
71
72
73                 if !section.short_info.is_empty():
74                         var tooltip_hint: Control = load("res://addons/dialogic/Editor/Common/hint_tooltip_icon.tscn").instantiate()
75                         tooltip_hint.hint_text = section.short_info
76                         hbox.add_child(tooltip_hint)
77
78
79                 var scroll := ScrollContainer.new()
80                 scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
81                 scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
82                 var inner_vbox := VBoxContainer.new()
83                 inner_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
84                 inner_vbox.size_flags_vertical = Control.SIZE_EXPAND_FILL
85                 scroll.add_child(inner_vbox)
86                 var panel := PanelContainer.new()
87                 panel.theme_type_variation = "DialogicPanelA"
88                 panel.size_flags_horizontal = Control.SIZE_EXPAND_FILL
89                 if section.size_flags_vertical == Control.SIZE_EXPAND_FILL:
90                         panel.size_flags_vertical = Control.SIZE_EXPAND_FILL
91                 inner_vbox.add_child(panel)
92
93
94                 var info_section: Control = section._get_info_section()
95                 if info_section != null:
96                         inner_vbox.add_child(Control.new())
97                         inner_vbox.get_child(-1).custom_minimum_size.y = 50
98
99                         inner_vbox.add_child(title.duplicate())
100                         inner_vbox.get_child(-1).text = "Information"
101                         var info_panel := panel.duplicate()
102                         info_panel.theme_type_variation = "DialogicPanelDarkA"
103
104                         inner_vbox.add_child(info_panel)
105                         info_section.get_parent().remove_child(info_section)
106                         info_panel.add_child(info_section)
107
108                 panel.add_child(section)
109                 vbox.add_child(scroll)
110
111
112                 var button := Button.new()
113                 button.text = " "+section.name
114                 button.tooltip_text = section.name
115                 button.toggle_mode = true
116                 button.button_group = button_group
117                 button.expand_icon = true
118                 button.alignment = HORIZONTAL_ALIGNMENT_LEFT
119                 button.flat = true
120                 button.add_theme_color_override('font_pressed_color', get_theme_color("property_color_z", "Editor"))
121                 button.add_theme_color_override('font_hover_color', get_theme_color('warning_color', 'Editor'))
122                 button.add_theme_color_override('font_focus_color', get_theme_color('warning_color', 'Editor'))
123                 button.add_theme_stylebox_override('focus', StyleBoxEmpty.new())
124                 button.pressed.connect(open_tab.bind(vbox))
125                 if section._is_feature_tab():
126                         %FeatureTabs.add_child(button)
127                 else:
128                         %SettingsTabs.add_child(button)
129
130                 vbox.hide()
131 #               if section.has_method('_get_icon'):
132 #                       icon.texture = section._get_icon()
133                 %SettingsContent.add_child(vbox)
134
135
136 func open_tab(tab_to_show:Control) -> void:
137         for tab in %SettingsContent.get_children():
138                 tab.hide()
139
140         tab_to_show.show()
141
142
143 func section_sort(item1:DialogicSettingsPage, item2:DialogicSettingsPage) -> bool:
144         if !item1._is_feature_tab() and item2._is_feature_tab():
145                 return true
146         if item1._get_priority() > item2._get_priority():
147                 return true
148         return false
149
150
151
152 func _open(extra_information:Variant = null) -> void:
153         refresh()
154         if typeof(extra_information) == TYPE_STRING:
155                 if %SettingsContent.has_node(extra_information):
156                         open_tab(%SettingsContent.get_node(extra_information))
157
158
159 func _close() -> void:
160         for child in %SettingsContent.get_children():
161                 if child.get_meta('section').has_method('_about_to_close'):
162                         child.get_meta('section')._about_to_close()
163
164
165 func refresh() -> void:
166         for child in %SettingsContent.get_children():
167                 if child.get_meta('section').has_method('_refresh'):
168                         child.get_meta('section')._refresh()
169