From 181189f515df62f965b5c90737df52b2bd805d17 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 21 Jan 2022 22:58:14 +0100 Subject: [PATCH] Now the world generator's editor plugin distributes the plugin itself to every class that will need it. --- game/addons/world_generator/plugin.gd | 1 + game/addons/world_generator/ui/DataList.gd | 9 ++++++++- game/addons/world_generator/ui/MainScreen.gd | 6 ++++++ game/addons/world_generator/ui/RectEditor.gd | 3 +++ game/addons/world_generator/ui/RectView.gd | 7 +++++++ game/addons/world_generator/ui/ResourcePropertyList.gd | 7 +++++++ game/addons/world_generator/ui/WorldTab.gd | 5 +++++ game/addons/world_generator/ui/tabs/Continent.gd | 5 +++++ game/addons/world_generator/ui/tabs/SubZone.gd | 3 +++ game/addons/world_generator/ui/tabs/Zone.gd | 5 +++++ 10 files changed, 50 insertions(+), 1 deletion(-) diff --git a/game/addons/world_generator/plugin.gd b/game/addons/world_generator/plugin.gd index b760fc81..f6a33fa1 100644 --- a/game/addons/world_generator/plugin.gd +++ b/game/addons/world_generator/plugin.gd @@ -26,6 +26,7 @@ func _enter_tree(): add_custom_type("SubZone", "Resource", SSubZone, null) editor_scene = editor_packed_scene.instance() + editor_scene.set_plugin(self) tool_button = add_control_to_bottom_panel(editor_scene, "World Editor") tool_button.hide() diff --git a/game/addons/world_generator/ui/DataList.gd b/game/addons/world_generator/ui/DataList.gd index 3ebede37..9eed0811 100644 --- a/game/addons/world_generator/ui/DataList.gd +++ b/game/addons/world_generator/ui/DataList.gd @@ -6,9 +6,16 @@ export(int, "Continent,Zone,Sub Zone") var class_types : int = 0 var edited_resource : WorldGenBaseResource = null var name_edited_resource : WorldGenBaseResource = null +var _plugin : EditorPlugin = null +var _undo_redo : UndoRedo = null + func _init(): connect("item_activated", self, "on_item_activated") - + +func set_plugin(plugin : EditorPlugin) -> void: + _plugin = plugin + _undo_redo = _plugin.get_undo_redo() + func _enter_tree(): var dir : Directory = Directory.new() diff --git a/game/addons/world_generator/ui/MainScreen.gd b/game/addons/world_generator/ui/MainScreen.gd index 46a3fca6..a6512c5e 100644 --- a/game/addons/world_generator/ui/MainScreen.gd +++ b/game/addons/world_generator/ui/MainScreen.gd @@ -3,6 +3,12 @@ extends PanelContainer var edited_world +func set_plugin(plugin : EditorPlugin) -> void: + $TabContainer/World.set_plugin(plugin) + $TabContainer/Continent.set_plugin(plugin) + $TabContainer/Zone.set_plugin(plugin) + $TabContainer/SubZone.set_plugin(plugin) + func refresh() -> void: $TabContainer/World.set_wgworld(edited_world) $TabContainer/Continent.set_wgworld(edited_world) diff --git a/game/addons/world_generator/ui/RectEditor.gd b/game/addons/world_generator/ui/RectEditor.gd index d74f025f..d86112e3 100644 --- a/game/addons/world_generator/ui/RectEditor.gd +++ b/game/addons/world_generator/ui/RectEditor.gd @@ -5,5 +5,8 @@ func _init(): # Control/EditorZoomWidget pass +func set_plugin(plugin : EditorPlugin) -> void: + $ScrollContainer/MarginContainer/RectView.set_plugin(plugin) + func set_edited_resource(res : WorldGenBaseResource): $ScrollContainer/MarginContainer/RectView.set_edited_resource(res) diff --git a/game/addons/world_generator/ui/RectView.gd b/game/addons/world_generator/ui/RectView.gd index 1e3ba957..2f775283 100644 --- a/game/addons/world_generator/ui/RectView.gd +++ b/game/addons/world_generator/ui/RectView.gd @@ -10,6 +10,9 @@ var _rect_scale : float = 1 var edited_resource : WorldGenBaseResource = null var edited_resource_current_size : Vector2 = Vector2() +var _plugin : EditorPlugin = null +var _undo_redo : UndoRedo = null + func _enter_tree(): var zoom_widget : Node = get_node_or_null(zoom_widget_path) @@ -22,6 +25,10 @@ func _enter_tree(): if !is_connected("visibility_changed", self, "on_visibility_changed"): connect("visibility_changed", self, "on_visibility_changed") +func set_plugin(plugin : EditorPlugin) -> void: + _plugin = plugin + _undo_redo = _plugin.get_undo_redo() + func on_visibility_changed() -> void: call_deferred("apply_zoom") diff --git a/game/addons/world_generator/ui/ResourcePropertyList.gd b/game/addons/world_generator/ui/ResourcePropertyList.gd index 8fb81b28..846d781c 100644 --- a/game/addons/world_generator/ui/ResourcePropertyList.gd +++ b/game/addons/world_generator/ui/ResourcePropertyList.gd @@ -6,6 +6,13 @@ var EditorResourceWidget : PackedScene = preload("res://addons/world_generator/w var _edited_resource : WorldGenBaseResource = null var properties : Array = Array() +var _plugin : EditorPlugin = null +var _undo_redo : UndoRedo = null + +func set_plugin(plugin : EditorPlugin) -> void: + _plugin = plugin + _undo_redo = _plugin.get_undo_redo() + func add_h_separator() -> int: var hsep : HSeparator = HSeparator.new() diff --git a/game/addons/world_generator/ui/WorldTab.gd b/game/addons/world_generator/ui/WorldTab.gd index 45845609..ece22128 100644 --- a/game/addons/world_generator/ui/WorldTab.gd +++ b/game/addons/world_generator/ui/WorldTab.gd @@ -3,6 +3,11 @@ extends HBoxContainer var edited_world +func set_plugin(plugin : EditorPlugin) -> void: + $HSplitContainer/ResourcePropertyList.set_plugin(plugin) + $HSplitContainer/RectEditor.set_plugin(plugin) + $VBoxContainer/DataList.set_plugin(plugin) + func refresh() -> void: $HSplitContainer/ResourcePropertyList.edit_resource(edited_world) $VBoxContainer/DataList.set_edited_resource(edited_world) diff --git a/game/addons/world_generator/ui/tabs/Continent.gd b/game/addons/world_generator/ui/tabs/Continent.gd index b87c78d1..c4ec5b04 100644 --- a/game/addons/world_generator/ui/tabs/Continent.gd +++ b/game/addons/world_generator/ui/tabs/Continent.gd @@ -8,6 +8,11 @@ func _ready(): var option_button : OptionButton = $HSplitContainer/VBoxContainer/OptionButton option_button.connect("item_selected", self, "on_item_selected") +func set_plugin(plugin : EditorPlugin) -> void: + $HSplitContainer/VBoxContainer/HBoxContainer2/ResourcePropertyList.set_plugin(plugin) + $HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList.set_plugin(plugin) + $HSplitContainer/RectEditor.set_plugin(plugin) + func refresh_continent() -> void: $HSplitContainer/VBoxContainer/HBoxContainer2/ResourcePropertyList.edit_resource(edited_continent) $HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList.set_edited_resource(edited_continent) diff --git a/game/addons/world_generator/ui/tabs/SubZone.gd b/game/addons/world_generator/ui/tabs/SubZone.gd index f2dd7800..5da25cbe 100644 --- a/game/addons/world_generator/ui/tabs/SubZone.gd +++ b/game/addons/world_generator/ui/tabs/SubZone.gd @@ -16,6 +16,9 @@ func _ready(): var szoption_button : OptionButton = $VBoxContainer/SubZoneOptionButton szoption_button.connect("item_selected", self, "on_sub_zone_item_selected") +func set_plugin(plugin : EditorPlugin) -> void: + $VBoxContainer/HBoxContainer2/ResourcePropertyList.set_plugin(plugin) + func continent_changed() -> void: var option_button : OptionButton = $VBoxContainer/ZoneOptionButton option_button.clear() diff --git a/game/addons/world_generator/ui/tabs/Zone.gd b/game/addons/world_generator/ui/tabs/Zone.gd index 93ff4ff7..7ea49b79 100644 --- a/game/addons/world_generator/ui/tabs/Zone.gd +++ b/game/addons/world_generator/ui/tabs/Zone.gd @@ -12,6 +12,11 @@ func _ready(): var zoption_button : OptionButton = $HSplitContainer/VBoxContainer/ZoneOptionButton zoption_button.connect("item_selected", self, "on_zone_item_selected") +func set_plugin(plugin : EditorPlugin) -> void: + $HSplitContainer/VBoxContainer/HBoxContainer2/ResourcePropertyList.set_plugin(plugin) + $HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList.set_plugin(plugin) + $HSplitContainer/RectEditor.set_plugin(plugin) + func refresh() -> void: var option_button : OptionButton = $HSplitContainer/VBoxContainer/ContinentOptionButton option_button.clear()