Skip to content

Commit

Permalink
Make the dock slot savable (#141)
Browse files Browse the repository at this point in the history
* Make the dock slot savable
  • Loading branch information
spimort authored Sep 28, 2024
1 parent c65cad6 commit 218231a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions addons/terrabrush/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class Plugin : EditorPlugin {
private const int ToolInfoOffset = 20;
private const string OverlayActionNameKey = "ActionName";

private Control _terrainDockContainer;
private TerrainControlDock _terrainControlDock;
private PackedScene _terrainControlDockPrefab;
private PackedScene _toolsPieMenuPrefab;
Expand Down Expand Up @@ -60,6 +61,11 @@ public override void _EnterTree() {
CreateCustomSetting(SettingContants.IconsColor, Color.FromHtml("#00151F"), Variant.Type.Color);
AddInspectorPlugin(new ButtonInspectorPlugin());

_terrainDockContainer = new Control() {
Name = "Terrain Editor"
};
AddControlToDock(DockSlot.RightBl, _terrainDockContainer);

_terrainControlDockPrefab = ResourceLoader.Load<PackedScene>("res://addons/terrabrush/Components/TerrainControlDock.tscn");
_toolsPieMenuPrefab = ResourceLoader.Load<PackedScene>("res://addons/terrabrush/Components/ToolsPieMenu.tscn");
_customContentPieMenuPrefab = ResourceLoader.Load<PackedScene>("res://addons/terrabrush/Components/CustomContentPieMenu.tscn");
Expand Down Expand Up @@ -316,6 +322,13 @@ private Vector3 GetMouseClickToZoneHeight(Vector3 from, Vector3 direction) {
}

public override void _ExitTree() {
if (_terrainDockContainer != null) {
RemoveControlFromDocks(_terrainDockContainer);
_terrainDockContainer.Free();

_terrainDockContainer = null;
}

RemoveCustomType("TerraBrush");
RemoveToolMenuItem("TerraBrush Key bindings");

Expand All @@ -324,9 +337,7 @@ public override void _ExitTree() {

private void RemoveDock() {
if (_terrainControlDock != null) {
RemoveControlFromDocks(_terrainControlDock);
_terrainControlDock.Free();

_terrainControlDock.QueueFree();
_terrainControlDock = null;
}

Expand Down Expand Up @@ -382,7 +393,7 @@ private void AddDock() {
_terrainControlDock.TerraBrush = _currentTerraBrushNode;
_terrainControlDock.BrushDecal = _brushDecal;
_terrainControlDock.EditorResourcePreview = EditorInterface.Singleton.GetResourcePreviewer();
AddControlToDock(DockSlot.RightBl, _terrainControlDock);
_terrainDockContainer.AddChild(_terrainControlDock);

_updateTerrainSettingsButton = new Button() {
Text = "Update terrain"
Expand Down
2 changes: 1 addition & 1 deletion addons/terrabrush/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="TerraBrush"
description=""
author="spimort"
version="0.8.5-alpha"
version="0.8.6-alpha"
script="Plugin.cs"

0 comments on commit 218231a

Please sign in to comment.