199 lines
6.2 KiB
GDScript
Executable File
199 lines
6.2 KiB
GDScript
Executable File
@tool
|
|
extends EditorPlugin
|
|
|
|
# Main plugin script for the cutscene editor
|
|
|
|
var dock_panel: Control
|
|
var graph_edit: GraphEdit
|
|
|
|
func _enter_tree() -> void:
|
|
# Initialize the plugin when it's enabled
|
|
_setup_plugin()
|
|
|
|
# Add custom types for cutscene resources
|
|
add_custom_type("CutsceneResource", "Resource", preload("res://addons/cutscene_editor/editor/resources/CutsceneResource.gd"),
|
|
preload("res://addons/cutscene_editor/icons/icon_entry.svg"))
|
|
|
|
func _exit_tree() -> void:
|
|
# Clean up when the plugin is disabled
|
|
_cleanup_plugin()
|
|
|
|
# Remove custom types
|
|
remove_custom_type("CutsceneResource")
|
|
|
|
func _setup_plugin() -> void:
|
|
# Create the main dock panel
|
|
dock_panel = _create_dock_panel()
|
|
|
|
# Add the dock panel to the editor
|
|
add_control_to_bottom_panel(dock_panel, "Cutscene Editor")
|
|
|
|
# Register the custom inspector plugin
|
|
#var inspector_plugin = preload("res://addons/cutscene_editor/editor/inspectors/CutsceneInspectorPlugin.gd").new()
|
|
#add_inspector_plugin(inspector_plugin)
|
|
|
|
func _cleanup_plugin() -> void:
|
|
# Remove the dock panel from the editor
|
|
if dock_panel:
|
|
remove_control_from_bottom_panel(dock_panel)
|
|
dock_panel.queue_free()
|
|
|
|
# Remove inspector plugin
|
|
# Note: Inspector plugins are automatically removed when the plugin is disabled
|
|
|
|
func _create_dock_panel() -> Control:
|
|
# Create the main dock panel UI
|
|
var panel = PanelContainer.new()
|
|
|
|
# Create a main container for the editor
|
|
var main_vbox = VBoxContainer.new()
|
|
main_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
main_vbox.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
panel.add_child(main_vbox)
|
|
|
|
# Create toolbar
|
|
var toolbar = _create_toolbar()
|
|
main_vbox.add_child(toolbar)
|
|
|
|
# Create graph edit area
|
|
graph_edit = _create_graph_edit()
|
|
main_vbox.add_child(graph_edit)
|
|
|
|
# Set up undo/redo system
|
|
_setup_undo_redo_system()
|
|
|
|
return panel
|
|
|
|
func _create_toolbar() -> Control:
|
|
# Create the main toolbar with common actions
|
|
var toolbar = HBoxContainer.new()
|
|
|
|
# New button
|
|
var new_button = Button.new()
|
|
new_button.text = "New"
|
|
new_button.icon = get_editor_interface().get_base_control().get_theme_icon("New", "EditorIcons")
|
|
new_button.connect("pressed", _on_new_pressed)
|
|
toolbar.add_child(new_button)
|
|
|
|
# Open button
|
|
var open_button = Button.new()
|
|
open_button.text = "Open"
|
|
open_button.icon = get_editor_interface().get_base_control().get_theme_icon("Load", "EditorIcons")
|
|
open_button.connect("pressed", _on_open_pressed)
|
|
toolbar.add_child(open_button)
|
|
|
|
# Save button
|
|
var save_button = Button.new()
|
|
save_button.text = "Save"
|
|
save_button.icon = get_editor_interface().get_base_control().get_theme_icon("Save", "EditorIcons")
|
|
save_button.connect("pressed", _on_save_pressed)
|
|
toolbar.add_child(save_button)
|
|
|
|
# Separator
|
|
var separator1 = VSeparator.new()
|
|
toolbar.add_child(separator1)
|
|
|
|
# Undo button
|
|
var undo_button = Button.new()
|
|
undo_button.text = "Undo"
|
|
undo_button.icon = get_editor_interface().get_base_control().get_theme_icon("Undo", "EditorIcons")
|
|
undo_button.connect("pressed", _on_undo_pressed)
|
|
toolbar.add_child(undo_button)
|
|
|
|
# Redo button
|
|
var redo_button = Button.new()
|
|
redo_button.text = "Redo"
|
|
redo_button.icon = get_editor_interface().get_base_control().get_theme_icon("Redo", "EditorIcons")
|
|
redo_button.connect("pressed", _on_redo_pressed)
|
|
toolbar.add_child(redo_button)
|
|
|
|
# Separator
|
|
var separator2 = VSeparator.new()
|
|
toolbar.add_child(separator2)
|
|
|
|
|
|
return toolbar
|
|
|
|
func _create_graph_edit() -> GraphEdit:
|
|
# Create the main graph edit component
|
|
var graph = preload("res://addons/cutscene_editor/editor/CutsceneGraphEdit.gd").new()
|
|
graph.name = "CutsceneGraphEdit"
|
|
graph.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
graph.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
|
|
# Set up graph properties
|
|
graph.set_right_disconnects(true)
|
|
graph.set_show_grid(true)
|
|
graph.set_snapping_enabled(true)
|
|
graph.set_snapping_distance(20)
|
|
graph.set_minimap_enabled(true)
|
|
graph.set_minimap_size(Vector2(200, 150))
|
|
|
|
# Connect signals
|
|
graph.connect("connection_request", graph._on_connection_request)
|
|
graph.connect("disconnection_request", graph._on_disconnection_request)
|
|
graph.connect("node_selected", graph._on_node_selected)
|
|
graph.connect("node_unselected", graph._on_node_unselected)
|
|
graph.connect("popup_request", graph._on_popup_request)
|
|
graph.connect("connection_to_empty", graph._on_connection_to_empty)
|
|
graph.connect("connection_from_empty", graph._on_connection_from_empty)
|
|
|
|
return graph
|
|
|
|
|
|
func _setup_undo_redo_system() -> void:
|
|
# Set up the undo/redo system
|
|
if graph_edit:
|
|
graph_edit._setup_undo_redo()
|
|
|
|
# Toolbar button handlers
|
|
func _on_new_pressed() -> void:
|
|
if graph_edit:
|
|
graph_edit.clear_graph()
|
|
|
|
func _on_open_pressed() -> void:
|
|
# Open file dialog to load a cutscene
|
|
var file_dialog = EditorFileDialog.new()
|
|
file_dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_FILE
|
|
file_dialog.access = EditorFileDialog.ACCESS_RESOURCES
|
|
file_dialog.filters = ["*.tres", "*.res"]
|
|
file_dialog.connect("file_selected", _on_file_selected)
|
|
|
|
# Add to editor interface
|
|
get_editor_interface().get_base_control().add_child(file_dialog)
|
|
file_dialog.popup_centered_ratio()
|
|
|
|
func _on_file_selected(path: String) -> void:
|
|
# Load the selected cutscene file
|
|
if graph_edit:
|
|
var cutscene_resource = load(path)
|
|
if cutscene_resource and cutscene_resource is CutsceneResource: #preload("res://addons/cutscene_editor/editor/resources/CutsceneResource.gd"):
|
|
graph_edit.load_from_cutscene(cutscene_resource)
|
|
|
|
func _on_save_pressed() -> void:
|
|
# Open file dialog to save a cutscene
|
|
var file_dialog = EditorFileDialog.new()
|
|
file_dialog.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE
|
|
file_dialog.access = EditorFileDialog.ACCESS_RESOURCES
|
|
file_dialog.filters = ["*.tres", "*.res"]
|
|
file_dialog.connect("file_selected", _on_save_file_selected)
|
|
|
|
# Add to editor interface
|
|
get_editor_interface().get_base_control().add_child(file_dialog)
|
|
file_dialog.popup_centered_ratio()
|
|
|
|
func _on_save_file_selected(path: String) -> void:
|
|
# Save the current cutscene to the selected file
|
|
if graph_edit:
|
|
var cutscene_resource = graph_edit.save_to_cutscene()
|
|
if cutscene_resource:
|
|
ResourceSaver.save(cutscene_resource, path)
|
|
|
|
func _on_undo_pressed() -> void:
|
|
if graph_edit:
|
|
graph_edit.undo()
|
|
|
|
func _on_redo_pressed() -> void:
|
|
if graph_edit:
|
|
graph_edit.redo()
|