|
| 1 | +@tool |
| 2 | +extends DialogicSettingsPage |
| 3 | + |
| 4 | +## Settings tab that holds dialogic editor settings. |
| 5 | + |
| 6 | +const _SETTING_IMAGE_PREVIEW_HEIGHT = "image_preview_height" |
| 7 | +const _SETTING_EVENT_BLOCK_MARGIN = "event_block_margin" |
| 8 | +const _SETTING_SHOW_EVENT_NAMES = "show_event_names" |
| 9 | + |
| 10 | +const _SETTING_EVENT_COLOR_PALETTE = "color_palette" |
| 11 | +const _SETTING_EVENT_SECTION_ODER = "event_section_order" |
| 12 | + |
| 13 | +var do_timeline_editor_refresh_on_close := false |
| 14 | + |
| 15 | +func _get_title() -> String: |
| 16 | + return "Editor" |
| 17 | + |
| 18 | + |
| 19 | +func _get_priority() -> int: |
| 20 | + return 98 |
| 21 | + |
| 22 | + |
| 23 | +func _refresh() -> void: |
| 24 | + do_timeline_editor_refresh_on_close = false |
| 25 | + %ImagePreviewHeight.value = DialogicUtil.get_editor_setting(_SETTING_IMAGE_PREVIEW_HEIGHT, 100) |
| 26 | + %EventBlockMargin.value = DialogicUtil.get_editor_setting(_SETTING_EVENT_BLOCK_MARGIN, 0) |
| 27 | + %ShowEventNames.set_pressed_no_signal(DialogicUtil.get_editor_setting(_SETTING_SHOW_EVENT_NAMES, false)) |
| 28 | + |
| 29 | + update_color_palette() |
| 30 | + reload_section_list() |
| 31 | + |
| 32 | + |
| 33 | +func _ready() -> void: |
| 34 | + %ResetColorsButton.icon = get_theme_icon("Reload", "EditorIcons") |
| 35 | + %ResetColorsButton.pressed.connect(_on_reset_colors_button) |
| 36 | + |
| 37 | + %ImagePreviewHeight.value_changed.connect(_on_ImagePreviewHeight_value_changed) |
| 38 | + %EventBlockMargin.value_changed.connect(_on_EventBlockMargin_value_changed) |
| 39 | + %ShowEventNames.toggled.connect(_on_ShowEventNames_toggled) |
| 40 | + |
| 41 | + |
| 42 | +func _about_to_close(): |
| 43 | + if do_timeline_editor_refresh_on_close: |
| 44 | + refresh_visual_timeline_editor() |
| 45 | + |
| 46 | + |
| 47 | +func refresh_visual_timeline_editor() -> void: |
| 48 | + var timeline_node: DialogicEditor = settings_editor.editors_manager.editors["Timeline"]["node"] |
| 49 | + timeline_node.get_node("%VisualEditor").load_event_buttons() |
| 50 | + |
| 51 | + # If the visual editor is open, close and reopen the timeline to have the colors reloaded. |
| 52 | + if timeline_node.get_node("%VisualEditor").visible: |
| 53 | + |
| 54 | + var current_timeline := timeline_node.current_resource |
| 55 | + settings_editor.editors_manager.clear_editor(timeline_node) |
| 56 | + |
| 57 | + settings_editor.editors_manager.edit_resource(current_timeline, true, true) |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +#region SECTION ORDER |
| 62 | +################################################################################ |
| 63 | + |
| 64 | +func reload_section_list(): |
| 65 | + %SectionList.clear() |
| 66 | + %SectionList.create_item() |
| 67 | + var cached_events := DialogicResourceUtil.get_event_cache() |
| 68 | + var sections := [] |
| 69 | + var section_order: Array = DialogicUtil.get_editor_setting(_SETTING_EVENT_SECTION_ODER, ['Main', 'Logic', 'Flow', 'Audio', 'Visuals','Other', 'Helper']) |
| 70 | + for ev in cached_events: |
| 71 | + if !ev.event_category in sections: |
| 72 | + sections.append(ev.event_category) |
| 73 | + var item: TreeItem = %SectionList.create_item(null) |
| 74 | + item.set_text(0, ev.event_category) |
| 75 | + item.add_button(0, get_theme_icon("ArrowUp", "EditorIcons")) |
| 76 | + item.add_button(0, get_theme_icon("ArrowDown", "EditorIcons")) |
| 77 | + if ev.event_category in section_order: |
| 78 | + |
| 79 | + item.move_before(item.get_parent().get_child(min(section_order.find(ev.event_category),item.get_parent().get_child_count()-1))) |
| 80 | + |
| 81 | + %SectionList.get_root().get_child(0).set_button_disabled(0, 0, true) |
| 82 | + %SectionList.get_root().get_child(-1).set_button_disabled(0, 1, true) |
| 83 | + |
| 84 | + |
| 85 | +func _on_section_list_button_clicked(item:TreeItem, column, id, mouse_button_index): |
| 86 | + if id == 0: |
| 87 | + item.move_before(item.get_parent().get_child(item.get_index()-1)) |
| 88 | + else: |
| 89 | + item.move_after(item.get_parent().get_child(item.get_index()+1)) |
| 90 | + |
| 91 | + for child in %SectionList.get_root().get_children(): |
| 92 | + child.set_button_disabled(0, 0, false) |
| 93 | + child.set_button_disabled(0, 1, false) |
| 94 | + |
| 95 | + %SectionList.get_root().get_child(0).set_button_disabled(0, 0, true) |
| 96 | + %SectionList.get_root().get_child(-1).set_button_disabled(0, 1, true) |
| 97 | + |
| 98 | + var sections := [] |
| 99 | + for child in %SectionList.get_root().get_children(): |
| 100 | + sections.append(child.get_text(0)) |
| 101 | + |
| 102 | + DialogicUtil.set_editor_setting(_SETTING_EVENT_SECTION_ODER, sections) |
| 103 | + do_timeline_editor_refresh_on_close = true |
| 104 | + |
| 105 | +#endregion |
| 106 | + |
| 107 | + |
| 108 | +#region COLOR PALETTE |
| 109 | +################################################################################ |
| 110 | + |
| 111 | +## Completely reloads the color palette buttons |
| 112 | +func update_color_palette() -> void: |
| 113 | + for child in %Colors.get_children(): |
| 114 | + child.queue_free() |
| 115 | + for color in DialogicUtil.get_color_palette(): |
| 116 | + var button := ColorPickerButton.new() |
| 117 | + button.custom_minimum_size = Vector2(50 ,50) * DialogicUtil.get_editor_scale() |
| 118 | + %Colors.add_child(button) |
| 119 | + button.color = DialogicUtil.get_color(color) |
| 120 | + button.popup_closed.connect(_on_palette_color_popup_closed) |
| 121 | + |
| 122 | + |
| 123 | +func _on_palette_color_popup_closed() -> void: |
| 124 | + var new_palette := {} |
| 125 | + for i in %Colors.get_children(): |
| 126 | + new_palette["Color"+str(i.get_index()+1)] = i.color |
| 127 | + DialogicUtil.set_editor_setting(_SETTING_EVENT_COLOR_PALETTE, new_palette) |
| 128 | + |
| 129 | + do_timeline_editor_refresh_on_close = true |
| 130 | + |
| 131 | + |
| 132 | +func _on_reset_colors_button() -> void: |
| 133 | + DialogicUtil.set_editor_setting(_SETTING_EVENT_COLOR_PALETTE, null) |
| 134 | + update_color_palette() |
| 135 | + |
| 136 | + do_timeline_editor_refresh_on_close = true |
| 137 | + |
| 138 | +#endregion |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | +func _on_ImagePreviewHeight_value_changed(value:float) -> void: |
| 144 | + DialogicUtil.set_editor_setting(_SETTING_IMAGE_PREVIEW_HEIGHT, value) |
| 145 | + |
| 146 | + |
| 147 | +func _on_EventBlockMargin_value_changed(value:float) -> void: |
| 148 | + DialogicUtil.set_editor_setting(_SETTING_EVENT_BLOCK_MARGIN, value) |
| 149 | + do_timeline_editor_refresh_on_close = true |
| 150 | + |
| 151 | + |
| 152 | +func _on_ShowEventNames_toggled(toggled:bool) -> void: |
| 153 | + DialogicUtil.set_editor_setting(_SETTING_SHOW_EVENT_NAMES, toggled) |
| 154 | + do_timeline_editor_refresh_on_close = true |
0 commit comments