2 extends DialogicSettingsPage
4 ## Settings tab that holds genreal dialogic settings.
7 func _get_title() -> String:
11 func _get_priority() -> int:
14 func _ready() -> void:
15 var s := DCSS.inline({
17 'background': Color(0.545098, 0.545098, 0.545098, 0.211765)
19 %ExtensionsFolderPicker.resource_icon = get_theme_icon("Folder", "EditorIcons")
22 %ExtensionsFolderPicker.value_changed.connect(_on_ExtensionsFolder_value_changed)
23 %PhysicsTimerButton.toggled.connect(_on_physics_timer_button_toggled)
26 %ResetColorsButton.icon = get_theme_icon("Reload", "EditorIcons")
27 %ResetColorsButton.button_up.connect(_on_reset_colors_button)
30 %ExtensionCreator.hide()
33 func _refresh() -> void:
34 %PhysicsTimerButton.button_pressed = DialogicUtil.is_physics_timer()
35 %LayoutNodeEndBehaviour.select(ProjectSettings.get_setting('dialogic/layout/end_behaviour', 0))
36 %ExtensionsFolderPicker.set_value(ProjectSettings.get_setting('dialogic/extensions_folder', 'res://addons/dialogic_additions'))
38 update_color_palette()
41 %SectionList.create_item()
42 var cached_events := DialogicResourceUtil.get_event_cache()
44 var section_order: Array = DialogicUtil.get_editor_setting('event_section_order', ['Main', 'Logic', 'Flow', 'Audio', 'Visuals','Other', 'Helper'])
45 for ev in cached_events:
46 if !ev.event_category in sections:
47 sections.append(ev.event_category)
48 var item: TreeItem = %SectionList.create_item(null)
49 item.set_text(0, ev.event_category)
50 item.add_button(0, get_theme_icon("ArrowUp", "EditorIcons"))
51 item.add_button(0, get_theme_icon("ArrowDown", "EditorIcons"))
52 if ev.event_category in section_order:
54 item.move_before(item.get_parent().get_child(min(section_order.find(ev.event_category),item.get_parent().get_child_count()-1)))
56 %SectionList.get_root().get_child(0).set_button_disabled(0, 0, true)
57 %SectionList.get_root().get_child(-1).set_button_disabled(0, 1, true)
60 func _on_section_list_button_clicked(item:TreeItem, column, id, mouse_button_index):
62 item.move_before(item.get_parent().get_child(item.get_index()-1))
64 item.move_after(item.get_parent().get_child(item.get_index()+1))
66 for child in %SectionList.get_root().get_children():
67 child.set_button_disabled(0, 0, false)
68 child.set_button_disabled(0, 1, false)
70 %SectionList.get_root().get_child(0).set_button_disabled(0, 0, true)
71 %SectionList.get_root().get_child(-1).set_button_disabled(0, 1, true)
74 for child in %SectionList.get_root().get_children():
75 sections.append(child.get_text(0))
77 DialogicUtil.set_editor_setting('event_section_order', sections)
78 force_event_button_list_reload()
81 func force_event_button_list_reload() -> void:
82 find_parent('EditorsManager').editors['Timeline'].node.get_node('%VisualEditor').load_event_buttons()
85 func update_color_palette() -> void:
87 for child in %Colors.get_children():
89 for color in DialogicUtil.get_color_palette():
90 var button := ColorPickerButton.new()
91 button.custom_minimum_size = Vector2(50 ,50) * DialogicUtil.get_editor_scale()
92 %Colors.add_child(button)
93 button.color = DialogicUtil.get_color(color)
94 button.color_changed.connect(_on_color_change)
97 func _on_color_change(color:Color) -> void:
99 for i in %Colors.get_children():
100 new_palette['Color'+str(i.get_index()+1)] = i.color
101 DialogicUtil.set_editor_setting('color_palette', new_palette)
105 func _on_reset_colors_button() -> void:
106 DialogicUtil.set_editor_setting('color_palette', null)
107 update_color_palette()
110 func _on_physics_timer_button_toggled(is_toggled: bool) -> void:
111 ProjectSettings.set_setting('dialogic/timer/process_in_physics', is_toggled)
112 ProjectSettings.save()
115 func _on_ExtensionsFolder_value_changed(property:String, value:String) -> void:
116 if value == null or value.is_empty():
117 value = 'res://addons/dialogic_additions'
118 ProjectSettings.set_setting('dialogic/extensions_folder', value)
119 ProjectSettings.save()
122 func _on_layout_node_end_behaviour_item_selected(index:int) -> void:
123 ProjectSettings.set_setting('dialogic/layout/end_behaviour', index)
124 ProjectSettings.save()
127 ################################################################################
129 ################################################################################
131 func _on_create_extension_button_pressed() -> void:
132 %CreateExtensionButton.hide()
133 %ExtensionCreator.show()
136 %NameEdit.grab_focus()
139 func _on_submit_extension_button_pressed() -> void:
140 if %NameEdit.text.is_empty():
143 var extensions_folder: String = ProjectSettings.get_setting('dialogic/extensions_folder', 'res://addons/dialogic_additions')
145 extensions_folder = extensions_folder.path_join(%NameEdit.text.to_pascal_case())
146 DirAccess.make_dir_recursive_absolute(extensions_folder)
147 var mode: int = %ExtensionMode.selected
150 var indexer_content := "@tool\nextends DialogicIndexer\n\n"
151 if mode != 2: # don't add event in Subsystem Only mode
152 indexer_content += """func _get_events() -> Array:
153 return [this_folder.path_join('event_"""+%NameEdit.text.to_snake_case()+""".gd')]\n\n"""
154 file = FileAccess.open(extensions_folder.path_join('event_'+%NameEdit.text.to_snake_case()+'.gd'), FileAccess.WRITE)
157 #region EXTENDED EVENT SCRIPT
159 extends DialogicEvent
160 class_name Dialogic"""+%NameEdit.text.to_pascal_case()+"""Event
162 # Define properties of the event here
164 func _execute() -> void:
165 # This will execute when the event is reached
166 finish() # called to continue with the next event
170 ################################################################################
171 # Set fixed settings of this event
172 func _init() -> void:
173 event_name = \""""+%NameEdit.text.capitalize()+"""\"
174 event_category = "Other"
179 #region SAVING/LOADING
180 ################################################################################
181 func get_shortcode() -> String:
182 return \""""+%NameEdit.text.to_snake_case()+"""\"
184 func get_shortcode_parameters() -> Dictionary:
186 #param_name : property_info
187 #"my_parameter" : {"property": "property", "default": "Default"},
190 # You can alternatively overwrite these 3 functions: to_text(), from_text(), is_valid_event()
194 #region EDITOR REPRESENTATION
195 ################################################################################
197 func build_event_editor() -> void:
204 if mode != 0: # don't add subsystem in event only mode
205 indexer_content += """func _get_subsystems() -> Array:
206 return [{'name':'"""+%NameEdit.text.to_pascal_case()+"""', 'script':this_folder.path_join('subsystem_"""+%NameEdit.text.to_snake_case()+""".gd')}]"""
207 file = FileAccess.open(extensions_folder.path_join('subsystem_'+%NameEdit.text.to_snake_case()+'.gd'), FileAccess.WRITE)
210 # region EXTENDED SUBSYSTEM SCRIPT
211 """extends DialogicSubsystem
213 ## Describe the subsystems purpose here.
217 ####################################################################################################
219 func clear_game_state(clear_flag:=Dialogic.ClearFlags.FULL_CLEAR) -> void:
222 func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void:
229 ####################################################################################################
231 # Add some useful methods here.
235 file = FileAccess.open(extensions_folder.path_join('index.gd'), FileAccess.WRITE)
236 file.store_string(indexer_content)
238 %ExtensionCreator.hide()
239 %CreateExtensionButton.show()
241 find_parent('EditorView').plugin_reference.get_editor_interface().get_resource_filesystem().scan_sources()
242 force_event_button_list_reload()
246 func _on_reload_pressed() -> void:
247 DialogicUtil._update_autoload_subsystem_access()