Skip to content

Commit 507c81c

Browse files
Add new editor settings, implement image preview field (#2449)
Adds an image preview field (used on the background event). Also adds a "Editor" settings page with some new settings (Image Preview Height, Event Block Bottom Margin, Show Event Names) and some old ones moved there (Color Palette, Section Order). --------- Co-authored-by: Jowan-Spooner <[email protected]>
1 parent d6c89c8 commit 507c81c

File tree

18 files changed

+441
-173
lines changed

18 files changed

+441
-173
lines changed

addons/dialogic/Editor/Events/EventBlock/event_block.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func _ready() -> void:
5555
func initialize_ui() -> void:
5656
var _scale := DialogicUtil.get_editor_scale()
5757

58+
add_theme_constant_override("margin_bottom", DialogicUtil.get_editor_setting("event_block_margin", 0) * _scale)
59+
5860
$PanelContainer.self_modulate = get_theme_color("accent_color", "Editor")
5961

6062
# Warning Icon
@@ -168,6 +170,7 @@ var FIELD_SCENES := {
168170
DialogicEvent.ValueType.VECTOR4: "res://addons/dialogic/Editor/Events/Fields/field_vector4.tscn",
169171
DialogicEvent.ValueType.COLOR: "res://addons/dialogic/Editor/Events/Fields/field_color.tscn",
170172
DialogicEvent.ValueType.AUDIO_PREVIEW: "res://addons/dialogic/Editor/Events/Fields/field_audio_preview.tscn",
173+
DialogicEvent.ValueType.IMAGE_PREVIEW: "res://addons/dialogic/Editor/Events/Fields/field_image_preview.tscn",
171174
}
172175

173176
func build_editor(build_header:bool = true, build_body:bool = false) -> void:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@tool
2+
extends DialogicVisualEditorField
3+
4+
5+
var body: Control
6+
var image_path: String
7+
8+
func _ready() -> void:
9+
body = find_parent('Body') as Control
10+
body.visibility_changed.connect(_on_body_visibility_toggled)
11+
12+
13+
func _enter_tree() -> void:
14+
%HiddenLabel.add_theme_color_override(
15+
'font_color',
16+
event_resource.event_color.lerp(get_theme_color("font_color", "Editor"), 0.8))
17+
18+
19+
#region OVERWRITES
20+
################################################################################
21+
22+
## To be overwritten
23+
func _set_value(value:Variant) -> void:
24+
if ResourceLoader.exists(value):
25+
image_path = value
26+
27+
if is_preview_enabled():
28+
self.texture = load(value)
29+
custom_minimum_size.y = get_preview_size()
30+
else:
31+
self.texture = null
32+
33+
minimum_size_changed.emit()
34+
35+
#endregion
36+
37+
38+
#region SIGNAL METHODS
39+
################################################################################
40+
41+
42+
func _on_body_visibility_toggled() -> void:
43+
custom_minimum_size.y = 0
44+
45+
if body.is_visible:
46+
%HiddenLabel.visible = not is_preview_enabled()
47+
48+
if is_preview_enabled() and ResourceLoader.exists(image_path):
49+
self.texture = load(image_path)
50+
custom_minimum_size.y = get_preview_size()
51+
else:
52+
self.texture = null
53+
54+
minimum_size_changed.emit()
55+
56+
#endregion
57+
58+
func is_preview_enabled() -> bool:
59+
return get_preview_size() != 0
60+
61+
62+
func get_preview_size() -> int:
63+
return DialogicUtil.get_editor_setting(
64+
"image_preview_height", 50) * DialogicUtil.get_editor_scale()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://bar0t74j5v4sa"]
2+
3+
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/field_image_preview.gd" id="1_e5vbc"]
4+
5+
[node name="Field_Image_Preview" type="TextureRect"]
6+
anchors_preset = 15
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
grow_horizontal = 2
10+
grow_vertical = 2
11+
size_flags_horizontal = 3
12+
size_flags_vertical = 0
13+
expand_mode = 2
14+
stretch_mode = 4
15+
script = ExtResource("1_e5vbc")
16+
17+
[node name="HiddenLabel" type="Label" parent="."]
18+
unique_name_in_owner = true
19+
visible = false
20+
layout_mode = 0
21+
tooltip_text = "Preview hidden because project setting 'dialogic/accessibility/image_preview_height' is 0."
22+
mouse_filter = 1
23+
text = "(Hidden)"
File renamed without changes.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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

Comments
 (0)