added a talking rock
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
@tool
|
||||
extends EditorProperty
|
||||
|
||||
|
||||
const DialoguePropertyEditorControl = preload("./editor_property_control.tscn")
|
||||
|
||||
|
||||
var editor_plugin: EditorPlugin
|
||||
|
||||
var control = DialoguePropertyEditorControl.instantiate()
|
||||
var current_value: Resource
|
||||
var is_updating: bool = false
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
add_child(control)
|
||||
|
||||
control.resource = current_value
|
||||
|
||||
control.pressed.connect(_on_button_pressed)
|
||||
control.resource_changed.connect(_on_resource_changed)
|
||||
|
||||
|
||||
func _update_property() -> void:
|
||||
var next_value = get_edited_object()[get_edited_property()]
|
||||
|
||||
# The resource might have been deleted elsewhere so check that it's not in a weird state
|
||||
if is_instance_valid(next_value) and not next_value.resource_path.ends_with(".dialogue"):
|
||||
emit_changed(get_edited_property(), null)
|
||||
return
|
||||
|
||||
if next_value == current_value: return
|
||||
|
||||
is_updating = true
|
||||
current_value = next_value
|
||||
control.resource = current_value
|
||||
is_updating = false
|
||||
|
||||
|
||||
### Signals
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
editor_plugin.edit(current_value)
|
||||
|
||||
|
||||
func _on_resource_changed(next_resource: Resource) -> void:
|
||||
emit_changed(get_edited_property(), next_resource)
|
@@ -0,0 +1,147 @@
|
||||
@tool
|
||||
extends HBoxContainer
|
||||
|
||||
|
||||
signal pressed()
|
||||
signal resource_changed(next_resource: Resource)
|
||||
|
||||
|
||||
const ITEM_NEW = 100
|
||||
const ITEM_QUICK_LOAD = 200
|
||||
const ITEM_LOAD = 201
|
||||
const ITEM_EDIT = 300
|
||||
const ITEM_CLEAR = 301
|
||||
const ITEM_FILESYSTEM = 400
|
||||
|
||||
|
||||
@onready var button: Button = $ResourceButton
|
||||
@onready var menu_button: Button = $MenuButton
|
||||
@onready var menu: PopupMenu = $Menu
|
||||
@onready var quick_open_dialog: ConfirmationDialog = $QuickOpenDialog
|
||||
@onready var files_list = $QuickOpenDialog/FilesList
|
||||
@onready var new_dialog: FileDialog = $NewDialog
|
||||
@onready var open_dialog: FileDialog = $OpenDialog
|
||||
|
||||
var editor_plugin: EditorPlugin
|
||||
|
||||
var resource: Resource:
|
||||
set(next_resource):
|
||||
resource = next_resource
|
||||
if button:
|
||||
button.resource = resource
|
||||
get:
|
||||
return resource
|
||||
|
||||
var is_waiting_for_file: bool = false
|
||||
var quick_selected_file: String = ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
menu_button.icon = get_theme_icon("GuiDropdown", "EditorIcons")
|
||||
editor_plugin = Engine.get_meta("DialogueManagerPlugin")
|
||||
|
||||
|
||||
func build_menu() -> void:
|
||||
menu.clear()
|
||||
|
||||
menu.add_icon_item(editor_plugin._get_plugin_icon(), "New Dialogue", ITEM_NEW)
|
||||
menu.add_separator()
|
||||
menu.add_icon_item(get_theme_icon("Load", "EditorIcons"), "Quick Load", ITEM_QUICK_LOAD)
|
||||
menu.add_icon_item(get_theme_icon("Load", "EditorIcons"), "Load", ITEM_LOAD)
|
||||
if resource:
|
||||
menu.add_icon_item(get_theme_icon("Edit", "EditorIcons"), "Edit", ITEM_EDIT)
|
||||
menu.add_icon_item(get_theme_icon("Clear", "EditorIcons"), "Clear", ITEM_CLEAR)
|
||||
menu.add_separator()
|
||||
menu.add_item("Show in FileSystem", ITEM_FILESYSTEM)
|
||||
|
||||
menu.size = Vector2.ZERO
|
||||
|
||||
|
||||
### Signals
|
||||
|
||||
|
||||
func _on_new_dialog_file_selected(path: String) -> void:
|
||||
editor_plugin.main_view.new_file(path)
|
||||
is_waiting_for_file = false
|
||||
if Engine.get_meta("DialogueCache").has_file(path):
|
||||
resource_changed.emit(load(path))
|
||||
else:
|
||||
var next_resource: Resource = await editor_plugin.import_plugin.compiled_resource
|
||||
next_resource.resource_path = path
|
||||
resource_changed.emit(next_resource)
|
||||
|
||||
|
||||
func _on_open_dialog_file_selected(file: String) -> void:
|
||||
resource_changed.emit(load(file))
|
||||
|
||||
|
||||
func _on_file_dialog_canceled() -> void:
|
||||
is_waiting_for_file = false
|
||||
|
||||
|
||||
func _on_resource_button_pressed() -> void:
|
||||
if is_instance_valid(resource):
|
||||
editor_plugin.get_editor_interface().call_deferred("edit_resource", resource)
|
||||
else:
|
||||
build_menu()
|
||||
menu.position = get_viewport().position + Vector2i(
|
||||
button.global_position.x + button.size.x - menu.size.x,
|
||||
2 + menu_button.global_position.y + button.size.y
|
||||
)
|
||||
menu.popup()
|
||||
|
||||
|
||||
func _on_resource_button_resource_dropped(next_resource: Resource) -> void:
|
||||
resource_changed.emit(next_resource)
|
||||
|
||||
|
||||
func _on_menu_button_pressed() -> void:
|
||||
build_menu()
|
||||
menu.position = get_viewport().position + Vector2i(
|
||||
menu_button.global_position.x + menu_button.size.x - menu.size.x,
|
||||
2 + menu_button.global_position.y + menu_button.size.y
|
||||
)
|
||||
menu.popup()
|
||||
|
||||
|
||||
func _on_menu_id_pressed(id: int) -> void:
|
||||
match id:
|
||||
ITEM_NEW:
|
||||
is_waiting_for_file = true
|
||||
new_dialog.popup_centered()
|
||||
|
||||
ITEM_QUICK_LOAD:
|
||||
quick_selected_file = ""
|
||||
files_list.files = Engine.get_meta("DialogueCache").get_files()
|
||||
if resource:
|
||||
files_list.select_file(resource.resource_path)
|
||||
quick_open_dialog.popup_centered()
|
||||
files_list.focus_filter()
|
||||
|
||||
ITEM_LOAD:
|
||||
is_waiting_for_file = true
|
||||
open_dialog.popup_centered()
|
||||
|
||||
ITEM_EDIT:
|
||||
editor_plugin.get_editor_interface().call_deferred("edit_resource", resource)
|
||||
|
||||
ITEM_CLEAR:
|
||||
resource_changed.emit(null)
|
||||
|
||||
ITEM_FILESYSTEM:
|
||||
var file_system = editor_plugin.get_editor_interface().get_file_system_dock()
|
||||
file_system.navigate_to_path(resource.resource_path)
|
||||
|
||||
|
||||
func _on_files_list_file_double_clicked(file_path: String) -> void:
|
||||
resource_changed.emit(load(file_path))
|
||||
quick_open_dialog.hide()
|
||||
|
||||
|
||||
func _on_files_list_file_selected(file_path: String) -> void:
|
||||
quick_selected_file = file_path
|
||||
|
||||
|
||||
func _on_quick_open_dialog_confirmed() -> void:
|
||||
if quick_selected_file != "":
|
||||
resource_changed.emit(load(quick_selected_file))
|
@@ -0,0 +1,58 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://ycn6uaj7dsrh"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/dialogue_manager/components/editor_property/editor_property_control.gd" id="1_het12"]
|
||||
[ext_resource type="PackedScene" uid="uid://b16uuqjuof3n5" path="res://addons/dialogue_manager/components/editor_property/resource_button.tscn" id="2_hh3d4"]
|
||||
[ext_resource type="PackedScene" uid="uid://dnufpcdrreva3" path="res://addons/dialogue_manager/components/files_list.tscn" id="3_l8fp6"]
|
||||
|
||||
[node name="PropertyEditorButton" type="HBoxContainer"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 0
|
||||
script = ExtResource("1_het12")
|
||||
|
||||
[node name="ResourceButton" parent="." instance=ExtResource("2_hh3d4")]
|
||||
layout_mode = 2
|
||||
text = "<empty>"
|
||||
text_overrun_behavior = 3
|
||||
clip_text = true
|
||||
|
||||
[node name="MenuButton" type="Button" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Menu" type="PopupMenu" parent="."]
|
||||
|
||||
[node name="QuickOpenDialog" type="ConfirmationDialog" parent="."]
|
||||
title = "Find Dialogue Resource"
|
||||
size = Vector2i(400, 600)
|
||||
min_size = Vector2i(400, 600)
|
||||
ok_button_text = "Open"
|
||||
|
||||
[node name="FilesList" parent="QuickOpenDialog" instance=ExtResource("3_l8fp6")]
|
||||
|
||||
[node name="NewDialog" type="FileDialog" parent="."]
|
||||
size = Vector2i(900, 750)
|
||||
min_size = Vector2i(900, 750)
|
||||
dialog_hide_on_ok = true
|
||||
filters = PackedStringArray("*.dialogue ; Dialogue")
|
||||
|
||||
[node name="OpenDialog" type="FileDialog" parent="."]
|
||||
title = "Open a File"
|
||||
size = Vector2i(900, 750)
|
||||
min_size = Vector2i(900, 750)
|
||||
ok_button_text = "Open"
|
||||
dialog_hide_on_ok = true
|
||||
file_mode = 0
|
||||
filters = PackedStringArray("*.dialogue ; Dialogue")
|
||||
|
||||
[connection signal="pressed" from="ResourceButton" to="." method="_on_resource_button_pressed"]
|
||||
[connection signal="resource_dropped" from="ResourceButton" to="." method="_on_resource_button_resource_dropped"]
|
||||
[connection signal="pressed" from="MenuButton" to="." method="_on_menu_button_pressed"]
|
||||
[connection signal="id_pressed" from="Menu" to="." method="_on_menu_id_pressed"]
|
||||
[connection signal="confirmed" from="QuickOpenDialog" to="." method="_on_quick_open_dialog_confirmed"]
|
||||
[connection signal="file_double_clicked" from="QuickOpenDialog/FilesList" to="." method="_on_files_list_file_double_clicked"]
|
||||
[connection signal="file_selected" from="QuickOpenDialog/FilesList" to="." method="_on_files_list_file_selected"]
|
||||
[connection signal="canceled" from="NewDialog" to="." method="_on_file_dialog_canceled"]
|
||||
[connection signal="file_selected" from="NewDialog" to="." method="_on_new_dialog_file_selected"]
|
||||
[connection signal="canceled" from="OpenDialog" to="." method="_on_file_dialog_canceled"]
|
||||
[connection signal="file_selected" from="OpenDialog" to="." method="_on_open_dialog_file_selected"]
|
@@ -0,0 +1,48 @@
|
||||
@tool
|
||||
extends Button
|
||||
|
||||
|
||||
signal resource_dropped(next_resource: Resource)
|
||||
|
||||
|
||||
var resource: Resource:
|
||||
set(next_resource):
|
||||
resource = next_resource
|
||||
if resource:
|
||||
icon = Engine.get_meta("DialogueManagerPlugin")._get_plugin_icon()
|
||||
text = resource.resource_path.get_file().replace(".dialogue", "")
|
||||
else:
|
||||
icon = null
|
||||
text = "<empty>"
|
||||
get:
|
||||
return resource
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
match what:
|
||||
NOTIFICATION_DRAG_BEGIN:
|
||||
var data = get_viewport().gui_get_drag_data()
|
||||
if typeof(data) == TYPE_DICTIONARY and data.type == "files" and data.files.size() > 0 and data.files[0].ends_with(".dialogue"):
|
||||
add_theme_stylebox_override("normal", get_theme_stylebox("focus", "LineEdit"))
|
||||
add_theme_stylebox_override("hover", get_theme_stylebox("focus", "LineEdit"))
|
||||
|
||||
NOTIFICATION_DRAG_END:
|
||||
self.resource = resource
|
||||
remove_theme_stylebox_override("normal")
|
||||
remove_theme_stylebox_override("hover")
|
||||
|
||||
|
||||
func _can_drop_data(at_position: Vector2, data) -> bool:
|
||||
if typeof(data) != TYPE_DICTIONARY: return false
|
||||
if data.type != "files": return false
|
||||
|
||||
var files: PackedStringArray = Array(data.files).filter(func(f): return f.get_extension() == "dialogue")
|
||||
return files.size() > 0
|
||||
|
||||
|
||||
func _drop_data(at_position: Vector2, data) -> void:
|
||||
var files: PackedStringArray = Array(data.files).filter(func(f): return f.get_extension() == "dialogue")
|
||||
|
||||
if files.size() == 0: return
|
||||
|
||||
resource_dropped.emit(load(files[0]))
|
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b16uuqjuof3n5"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/dialogue_manager/components/editor_property/resource_button.gd" id="1_7u2i7"]
|
||||
|
||||
[node name="ResourceButton" type="Button"]
|
||||
offset_right = 8.0
|
||||
offset_bottom = 8.0
|
||||
size_flags_horizontal = 3
|
||||
script = ExtResource("1_7u2i7")
|
Reference in New Issue
Block a user