diff --git a/GD-AtlasTexture-Creator.csproj b/GD-AtlasTexture-Creator.csproj index 6565db3..e9a3da8 100644 --- a/GD-AtlasTexture-Creator.csproj +++ b/GD-AtlasTexture-Creator.csproj @@ -1,4 +1,4 @@ - + net6.0 true @@ -6,8 +6,10 @@ + + \ No newline at end of file diff --git a/addons/deyu_atlas_texture_creator_window/EditingAtlasTextureInfo.cs b/addons/deyu_atlas_texture_creator_window/EditingAtlasTextureInfo.cs index 3325a69..40eef51 100644 --- a/addons/deyu_atlas_texture_creator_window/EditingAtlasTextureInfo.cs +++ b/addons/deyu_atlas_texture_creator_window/EditingAtlasTextureInfo.cs @@ -1,14 +1,10 @@ #if TOOLS -#region - using System.Collections.Generic; using System.IO; using System.Linq; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; public class EditingAtlasTextureInfo @@ -35,6 +31,21 @@ private EditingAtlasTextureInfo(AtlasTexture backingAtlasTexture, Rect2 region, public bool Modified { get; private set; } + private static class GdPath + { + public static string Combine(string pathA, string pathB) + { + var newPath = Path.Combine(pathA, pathB); + return ToGdPath(newPath); + } + + public static string ToGdPath(string path) + { + var unixStyledPath = path.Replace("\\", "/"); + return unixStyledPath.Insert(unixStyledPath.IndexOf('/'), "/"); + } + } + public static EditingAtlasTextureInfo Create((AtlasTexture atlasTexture, string resourcePath) data) { var backingAtlasTexture = data.atlasTexture; @@ -127,7 +138,7 @@ public string ApplyChanges(Texture2D sourceTexture, string sourceTextureDirector { Atlas = sourceTexture }; - m_ResourcePath = GDPath.Combine(sourceTextureDirectory, $"{Name}.tres"); + m_ResourcePath = GdPath.Combine(sourceTextureDirectory, $"{Name}.tres"); } m_BackingAtlasTexture.Region = Region; @@ -150,21 +161,5 @@ public void DiscardChanges() FilterClip = m_BackingAtlasTexture.FilterClip; Modified = false; } - - private static class GDPath - { - - public static string Combine(string pathA, string pathB) - { - var newPath = Path.Combine(pathA, pathB); - return ToGDPath(newPath); - } - - public static string ToGDPath(string path) - { - var unixStyledPath = path.Replace("\\", "/"); - return unixStyledPath.Insert(unixStyledPath.IndexOf('/'), "/"); - } - } } #endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.CallRegisteration.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.CallRegisteration.cs new file mode 100644 index 0000000..4b96e31 --- /dev/null +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.CallRegisteration.cs @@ -0,0 +1,21 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Godot; +using Range = Godot.Range; + +namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; + +public partial class UnityAtlasTextureCreator +{ + private static void RegLineEdit([NotNull] LineEdit control, LineEdit.TextChangedEventHandler call) => control.TextChanged += call; + + private static void RegRangeValueChanged([NotNull] Range control, Range.ValueChangedEventHandler call) => control.ValueChanged += call; + + private static void RegButtonPressed([NotNull] BaseButton control, Action call) => control.Pressed += call; + + private static void RegButtonToggled([NotNull] BaseButton control, BaseButton.ToggledEventHandler call) => control.Toggled += call; + + private static void RegOptionButtonItemSelected([NotNull] OptionButton control, OptionButton.ItemSelectedEventHandler call) => control.ItemSelected += call; + + private static void RegResourceChanged([NotNull] Resource resource, Action call) => resource.Changed += call; +} diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.GDPathEmbedded.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.GDPathEmbedded.cs index 481b9f6..026cdb1 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.GDPathEmbedded.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.GDPathEmbedded.cs @@ -1,4 +1,6 @@ #if TOOLS + + using System; using System.IO; using System.Text.RegularExpressions; @@ -7,38 +9,32 @@ namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; public partial class UnityAtlasTextureCreator { - private static class GDPath + private static class GdPath { - private static readonly Regex PrefixNameRegex = new(@"(?.+):[\/\\]*.*", RegexOptions.Compiled); - private static readonly Regex SuffixNameRegex = new(@".+:[\/\\]*(?.*)", RegexOptions.Compiled); - + private static readonly Regex s_PrefixNameRegex = new(@"(?.+):[\/\\]*.*", RegexOptions.Compiled); + private static readonly Regex s_SuffixNameRegex = new(@".+:[\/\\]*(?.*)", RegexOptions.Compiled); + public static string GetDirectoryName(string path) { var directoryNameRaw = Path.GetDirectoryName(path); - return ToGDPath(directoryNameRaw); + return ToGdPath(directoryNameRaw); } - - public static string GetFileNameWithoutExtension(string path) => + + public static string GetFileNameWithoutExtension(string path) => Path.GetFileNameWithoutExtension(path); - - public static string ToGDPath(string path) + + public static string ToGdPath(string path) { var unixStyledPath = path.Replace("\\", "/"); - var prefixMatch = PrefixNameRegex.Match(unixStyledPath); - if (!prefixMatch.Success) - { - throw new FormatException(path); - } - - var suffixMatch = SuffixNameRegex.Match(unixStyledPath); - if (suffixMatch.Success) - { - return $"{prefixMatch.Groups["captured"]}://{suffixMatch.Groups["captured"]}"; - } - + var prefixMatch = s_PrefixNameRegex.Match(unixStyledPath); + if (!prefixMatch.Success) throw new FormatException(path); + + var suffixMatch = s_SuffixNameRegex.Match(unixStyledPath); + if (suffixMatch.Success) return $"{prefixMatch.Groups["captured"]}://{suffixMatch.Groups["captured"]}"; + return $"{prefixMatch.Groups["captured"]}://"; } } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.cs index 8b77253..3f63748 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Private.cs @@ -1,16 +1,12 @@ #if TOOLS -#region - using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Godot; using Godot.Collections; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the private fields and general api used by the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator @@ -19,12 +15,22 @@ public partial class UnityAtlasTextureCreator private readonly Vector2[] m_HandlePositionBuffer = new Vector2[8]; private readonly Array m_OneLengthArray = new(new Variant[1]); private string m_CurrentSourceTexturePath; + private Dragging m_DraggingHandle; + private Vector2 m_DraggingHandlePosition; + private Rect2 m_DraggingHandleStartRegion; + private Vector2 m_DraggingMousePositionOffset; private Vector2 m_DrawOffsets; private float m_DrawZoom; private EditorFileSystem m_EditorFileSystem; + + private EditorPlugin m_EditorPlugin; private EditorUndoRedoManager m_EditorUndoRedoManager; + + private EditingAtlasTextureInfo m_InspectingAtlasTextureInfo; private Texture2D m_InspectingTex; private string m_InspectingTexName; + private bool m_IsDragging; + private Rect2 m_ModifyingRegionBuffer; private CanvasTexture m_PreviewTex; private bool m_RequestCenter; private bool m_UpdatingScroll; @@ -32,17 +38,32 @@ public partial class UnityAtlasTextureCreator // ReSharper disable once IdentifierTypo private ViewPannerCSharpImpl m_ViewPanner; - private EditingAtlasTextureInfo m_InspectingAtlasTextureInfo; - private bool m_IsDragging; - private Dragging m_DraggingHandle; - private Rect2 m_ModifyingRegionBuffer; - private Rect2 m_DraggingHandleStartRegion; - private Vector2 m_DraggingHandlePosition; - private Vector2 m_DraggingMousePositionOffset; - + [NotNull] + private ViewPannerCSharpImpl ViewPanner + { + get + { + if (m_ViewPanner is null) + { + var settings = m_EditorPlugin.GetEditorInterface().GetEditorSettings(); + + m_ViewPanner = new(); + m_ViewPanner.SetCallbacks(Pan, ZoomOnPositionScroll); + m_ViewPanner.Setup( + settings.Get("editors/panning/sub_editors_panning_scheme").As(), + new(), // settings.GetShortcut("canvas_item_editor/pan_view"); // This api only exists in native side, Sad :( + settings.Get("editors/panning/simple_panning").As() + ); + } + + return m_ViewPanner; + } + } + /// - /// Update all UI controls based on the status of , and + /// Update all UI controls based on the status of , + /// and /// private void UpdateControls() { @@ -76,7 +97,7 @@ private void UpdateControls() } /// - /// Method called when the inspected texture is changed + /// Method called when the inspected texture is changed /// private void OnTexChanged() { @@ -86,7 +107,7 @@ private void OnTexChanged() } /// - /// Method to update the inspection of the current texture + /// Method to update the inspection of the current texture /// private void UpdateInspectingTexture() { diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section0.TopBarSection.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section0.TopBarSection.cs index 07fa8f4..aacbec3 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section0.TopBarSection.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section0.TopBarSection.cs @@ -1,24 +1,15 @@ #if TOOLS -#region - using System; using System.Collections.Generic; using System.Linq; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the exports and api used by the Top Bar Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator { - private enum SnapMode { NoneSnap, PixelSnap } - - private enum ScanMode { SourceFolderOnly, WholeProject } - private SnapMode m_CurrentSnapMode = SnapMode.NoneSnap; [Export, ExportSubgroup("Top Bar Section")] private OptionButton SnapModeButton { get; set; } @@ -37,8 +28,12 @@ private SnapMode CurrentSnapMode } } + private enum SnapMode { NoneSnap, PixelSnap } + + private enum ScanMode { SourceFolderOnly, WholeProject } + /// - /// Initialize the top bar section with editor settings + /// Initialize the top bar section with editor settings /// /// private void InitializeTopBarSection(EditorSettings settings) @@ -52,19 +47,15 @@ private void InitializeTopBarSection(EditorSettings settings) ) .As(); - SnapModeButton.ItemSelected += p_mode => CurrentSnapMode = (SnapMode)p_mode; - SnapModeButton.Selected = (int)CurrentSnapMode; + RegOptionButtonItemSelected(SnapModeButton, pMode => CurrentSnapMode = (SnapMode)pMode); + RegButtonPressed(ScanAtlasInFolderButton, () => ScanAtlasTexture(ScanMode.SourceFolderOnly, m_EditingAtlasTexture)); + RegButtonPressed(ScanAtlasInProjectButton, () => ScanAtlasTexture(ScanMode.WholeProject, m_EditingAtlasTexture)); - ScanAtlasInFolderButton.Pressed += - () => - ScanAtlasTexture(ScanMode.SourceFolderOnly, m_EditingAtlasTexture); - ScanAtlasInProjectButton.Pressed += - () => - ScanAtlasTexture(ScanMode.WholeProject, m_EditingAtlasTexture); + SnapModeButton.Selected = (int)CurrentSnapMode; } /// - /// Scan and populate atlas textures based on the selected scan mode + /// Scan and populate atlas textures based on the selected scan mode /// private void ScanAtlasTexture(ScanMode scanMode, List editingAtlasTextureInfoCache) { @@ -76,7 +67,7 @@ private void ScanAtlasTexture(ScanMode scanMode, List e { case ScanMode.SourceFolderOnly: var sourcePath = m_InspectingTex.ResourcePath; - var dirPath = GDPath.GetDirectoryName(sourcePath); + var dirPath = GdPath.GetDirectoryName(sourcePath); EditorFileSystemDirectory directory; directory = m_EditorFileSystem.GetFilesystemPath(dirPath); FindMatchingSourceTextureInDirectory(m_InspectingTex, collection, directory); @@ -95,7 +86,7 @@ private void ScanAtlasTexture(ScanMode scanMode, List e } /// - /// Recursive method to find matching source textures in a directory and its subdirectories + /// Recursive method to find matching source textures in a directory and its subdirectories /// private static void FindMatchingSourceTextureInDirectoryRecursive(Texture2D sourceTexture, ICollection<(AtlasTexture, string)> matchedAtlasTexture, EditorFileSystemDirectory directory) { @@ -110,7 +101,8 @@ private static void FindMatchingSourceTextureInDirectoryRecursive(Texture2D sour } /// - /// Scans and acquire the with the matching the provided from the providing + /// Scans and acquire the with the matching the provided + /// from the providing /// private static void FindMatchingSourceTextureInDirectory(Texture2D sourceTexture, ICollection<(AtlasTexture, string)> matchedAtlasTexture, EditorFileSystemDirectory directory) { @@ -125,4 +117,4 @@ private static void FindMatchingSourceTextureInDirectory(Texture2D sourceTexture } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Draw.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Draw.cs index 033ee68..eb465a6 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Draw.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Draw.cs @@ -1,21 +1,17 @@ #if TOOLS -#region using System; using System.Runtime.InteropServices; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the api used by the Draw submodule from the Primary View Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator { /// - /// Core method for drawing everything inside the main rect editor viewport + /// Core method for drawing everything inside the main rect editor viewport /// private void DrawRegion() { @@ -68,12 +64,10 @@ private void DrawRegion() } if (AtlasTextureSlicerButton.ButtonPressed) - { foreach (var slicePreviewRect in m_SlicePreview) { DrawRectFrame(slicePreviewRect, selectHandle, Colors.Red, Dragging.Area); } - } RenderingServer.CanvasItemAddSetTransform(rid, new()); @@ -127,7 +121,7 @@ private void DrawRegion() } /// - /// Helper method to draw a frame around a rectangle with optional handles + /// Helper method to draw a frame around a rectangle with optional handles /// private void DrawRectFrame(in Rect2 rect, Texture2D selectHandle, in Color color, Dragging drawHandleType) { @@ -170,4 +164,4 @@ void DrawHandleTextureDirect(Vector2 position) => } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Input.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Input.cs index c981879..d9305b8 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Input.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.Input.cs @@ -1,26 +1,22 @@ #if TOOLS -#region using System.Runtime.InteropServices; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the api used by the Input Handling submodule from the Primary View Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator { /// - /// Core method for handling input events related to the region editor + /// Core method for handling input events related to the region editor /// private void InputRegion(InputEvent p_input) { if (m_InspectingTex is null) return; - if (m_ViewPanner.ProcessGuiInput(p_input, new())) return; + if (ViewPanner.ProcessGuiInput(p_input, new())) return; switch (p_input) { @@ -34,14 +30,14 @@ private void InputRegion(InputEvent p_input) ZoomOnPosition(m_DrawZoom * magnify_gesture.Factor, magnify_gesture.Position); break; case InputEventPanGesture pan_gesture: - HScroll.Value = HScroll.Value + HScroll.Page * pan_gesture.Delta.X / 8; - VScroll.Value = VScroll.Value + VScroll.Page * pan_gesture.Delta.Y / 8; + HScroll.Value += HScroll.Page * pan_gesture.Delta.X / 8; + VScroll.Value += VScroll.Page * pan_gesture.Delta.Y / 8; break; } } /// - /// SubMethod for update information during mouse dragging + /// SubMethod for update information during mouse dragging /// private void OnMouseDragUpdate(in Vector2 localMousePosition, out Dragging draggingHandleIndex, out Vector2 draggingHandlePosition, out EditingAtlasTextureInfo inspectingAtlasTextureInfo) { @@ -83,7 +79,7 @@ private void OnMouseDragUpdate(in Vector2 localMousePosition, out Dragging dragg } /// - /// SubMethod for update information for mouse button events + /// SubMethod for update information for mouse button events /// private void ProcessMouseButton(InputEventMouseButton mouseButton) { @@ -131,7 +127,7 @@ out m_InspectingAtlasTextureInfo } /// - /// SubMethod for update information for mouse motion events + /// SubMethod for update information for mouse motion events /// private void ProcessMouseMotion(InputEventMouseMotion mouseMotion) { @@ -155,7 +151,7 @@ private void ProcessMouseMotion(InputEventMouseMotion mouseMotion) } /// - /// Core method for calculating the new region based on the dragging type and offset + /// Core method for calculating the new region based on the dragging type and offset /// private static Rect2 CalculateOffset(Rect2 region, Dragging dragging, Vector2 diff) => dragging switch @@ -172,7 +168,7 @@ private static Rect2 CalculateOffset(Rect2 region, Dragging dragging, Vector2 di }; /// - /// Pan the view + /// Pan the view /// private void Pan(Vector2 p_scroll_vec) { @@ -182,9 +178,9 @@ private void Pan(Vector2 p_scroll_vec) } /// - /// Creates the AtlasTexture Slice base on the given info + /// Creates the AtlasTexture Slice base on the given info /// - private void CreateSlice(in Rect2 region, in Rect2 margin ,bool filterClip) + private void CreateSlice(in Rect2 region, in Rect2 margin, bool filterClip) { m_InspectingAtlasTextureInfo = EditingAtlasTextureInfo.CreateEmpty( @@ -199,7 +195,8 @@ private void CreateSlice(in Rect2 region, in Rect2 margin ,bool filterClip) } /// - /// Called when releasing mouse drag, this function applies the info of current dragging rect (>) into the + /// Called when releasing mouse drag, this function applies the info of current dragging rect ( + /// >) into the /// private void FlushRegionModifyingBuffer() { @@ -218,4 +215,4 @@ private void FlushRegionModifyingBuffer() } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.cs index 71a2a68..af172ec 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section1.PrimaryViewSection.cs @@ -1,18 +1,22 @@ #if TOOLS -#region using System; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the exports and api used by the Primary View Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator { + [Export, ExportSubgroup("Primary View Section")] private Control EditDrawer { get; set; } + + [Export] private Button ZoomInButton { get; set; } + [Export] private Button ZoomResetButton { get; set; } + [Export] private Button ZoomOutButton { get; set; } + [Export] private VScrollBar VScroll { get; set; } + [Export] private HScrollBar HScroll { get; set; } + private enum Dragging { None = -1, @@ -26,31 +30,18 @@ private enum Dragging Handle_BottomLeft = 6, Handle_Left = 7 } - - [Export, ExportSubgroup("Primary View Section")] private Control EditDrawer { get; set; } - [Export] private Button ZoomInButton { get; set; } - [Export] private Button ZoomResetButton { get; set; } - [Export] private Button ZoomOutButton { get; set; } - [Export] private VScrollBar VScroll { get; set; } - [Export] private HScrollBar HScroll { get; set; } /// - /// Initialize the primary view section with editor settings + /// Initialize the primary view section with editor settings /// /// private void InitializePrimaryViewSection(EditorSettings settings) { m_PreviewTex = new(); - m_ViewPanner = new(); - m_ViewPanner.SetCallbacks( - Pan, - (p_zoom_factor, p_origin, _) => ZoomOnPosition(m_DrawZoom * p_zoom_factor, p_origin) - ); - EditDrawer.Draw += DrawRegion; EditDrawer.GuiInput += InputRegion; - EditDrawer.FocusExited += m_ViewPanner.ReleasePanKey; + EditDrawer.FocusExited += ReleasePanKey; m_DrawZoom = 1.0f; @@ -73,8 +64,15 @@ private void InitializePrimaryViewSection(EditorSettings settings) "ZoomMore" ); - VScroll.ValueChanged += OnScrollChanged; - HScroll.ValueChanged += OnScrollChanged; + RegRangeValueChanged(VScroll, OnScrollChanged); + RegRangeValueChanged(HScroll, OnScrollChanged); + + EditDrawer.AddThemeStyleboxOverride("panel", Theme.GetStylebox("panel", "Tree")); + + + m_UpdatingScroll = false; + + return; void OnScrollChanged(double _) { @@ -85,26 +83,19 @@ void OnScrollChanged(double _) EditDrawer.QueueRedraw(); } - EditDrawer.AddThemeStyleboxOverride("panel", Theme.GetStylebox("panel", "Tree")); - m_ViewPanner.Setup( - settings.Get("editors/panning/sub_editors_panning_scheme").As(), - new(), // settings.GetShortcut("canvas_item_editor/pan_view"); // This api only exists in native side, Sad :( - settings.Get("editors/panning/simple_panning").As() - ); - - m_UpdatingScroll = false; - void BindZoomButtons(Button button, string text, Action onPress, string editorIconName) { button.Flat = true; button.TooltipText = Tr(text); button.Icon = Theme.GetIcon(editorIconName, "EditorIcons"); - button.Pressed += onPress; + RegButtonPressed(button, onPress); } } + private void ReleasePanKey() => ViewPanner.ReleasePanKey(); + /// - /// Calculate eight handle positions for a given rectangle frame + /// Calculate eight handle positions for a given rectangle frame /// /// /// @@ -170,7 +161,12 @@ out Vector2 handle2 } /// - /// Zoom the view at a specific position + /// Zoom the view at a specific position (for view panner scroll) + /// + private void ZoomOnPositionScroll(float p_zoom, Vector2 p_position) => ZoomOnPosition(m_DrawZoom * p_zoom, p_position); + + /// + /// Zoom the view at a specific position /// private void ZoomOnPosition(float p_zoom, Vector2 p_position) { @@ -186,4 +182,4 @@ private void ZoomOnPosition(float p_zoom, Vector2 p_position) } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section2.AtlasTextureMiniInspector.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section2.AtlasTextureMiniInspector.cs index 38655a9..d58cef9 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section2.AtlasTextureMiniInspector.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section2.AtlasTextureMiniInspector.cs @@ -1,164 +1,190 @@ #if TOOLS -#region using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the exports and api used by the AtlasTexture Mini Inspector Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator { [Export, ExportSubgroup("AtlasTexture Mini Inspector Section")] private Control MiniInspectorWindow { get; set; } + [Export] private Label NewItemLabel { get; set; } [Export] private Button DeleteItemButton { get; set; } + [Export, ExportSubgroup("AtlasTexture Mini Inspector Section/Inputs")] private LineEdit AtlasTextureNameInput { get; set; } - [Export, ExportSubgroup("AtlasTexture Mini Inspector Section/Inputs/Region")] private SpinBox AtlasTextureRegionXInput { get; set; } + + [Export, ExportSubgroup("AtlasTexture Mini Inspector Section/Inputs/Region")] + private SpinBox AtlasTextureRegionXInput { get; set; } + [Export] private SpinBox AtlasTextureRegionYInput { get; set; } [Export] private SpinBox AtlasTextureRegionWInput { get; set; } [Export] private SpinBox AtlasTextureRegionHInput { get; set; } - [Export, ExportSubgroup("AtlasTexture Mini Inspector Section/Inputs/Margin")] private SpinBox AtlasTextureMarginXInput { get; set; } + + [Export, ExportSubgroup("AtlasTexture Mini Inspector Section/Inputs/Margin")] + private SpinBox AtlasTextureMarginXInput { get; set; } + [Export] private SpinBox AtlasTextureMarginYInput { get; set; } [Export] private SpinBox AtlasTextureMarginWInput { get; set; } [Export] private SpinBox AtlasTextureMarginHInput { get; set; } [Export] private CheckBox AtlasTextureFilterClipInput { get; set; } /// - /// Initialize callbacks for the MiniInspector + /// Initialize callbacks for the MiniInspector /// private void InitializeAtlasTextureMiniInspector() { - AtlasTextureNameInput.TextChanged += + RegLineEdit( + AtlasTextureNameInput, newText => { if (m_InspectingAtlasTextureInfo is null || !m_InspectingAtlasTextureInfo.IsTemp) return; if (m_InspectingAtlasTextureInfo.TrySetName(newText)) UpdateControls(); - }; + } + ); - AtlasTextureRegionXInput.ValueChanged += + RegRangeValueChanged( + AtlasTextureRegionXInput, newRegionX => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Region; value.Position = new((float)newRegionX, value.Position.Y); if (m_InspectingAtlasTextureInfo.TrySetRegion(value)) UpdateControls(); - }; - AtlasTextureRegionYInput.ValueChanged += + } + ); + RegRangeValueChanged( + AtlasTextureRegionYInput, newRegionY => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Region; value.Position = new(value.Position.X, (float)newRegionY); if (m_InspectingAtlasTextureInfo.TrySetRegion(value)) UpdateControls(); - }; - AtlasTextureRegionWInput.ValueChanged += + } + ); + RegRangeValueChanged( + AtlasTextureRegionWInput, newRegionW => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Region; value.Size = new((float)newRegionW, value.Size.Y); if (m_InspectingAtlasTextureInfo.TrySetRegion(value)) UpdateControls(); - }; - AtlasTextureRegionHInput.ValueChanged += + } + ); + RegRangeValueChanged( + AtlasTextureRegionHInput, newRegionH => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Region; value.Size = new(value.Size.X, (float)newRegionH); if (m_InspectingAtlasTextureInfo.TrySetRegion(value)) UpdateControls(); - }; + } + ); - AtlasTextureMarginXInput.ValueChanged += + RegRangeValueChanged( + AtlasTextureMarginXInput, newMarginX => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Margin; value.Position = new((float)newMarginX, value.Position.Y); if (m_InspectingAtlasTextureInfo.TrySetMargin(value)) UpdateControls(); - }; - AtlasTextureMarginYInput.ValueChanged += + } + ); + RegRangeValueChanged( + AtlasTextureMarginYInput, newMarginY => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Margin; value.Position = new(value.Position.X, (float)newMarginY); if (m_InspectingAtlasTextureInfo.TrySetMargin(value)) UpdateControls(); - }; - AtlasTextureMarginWInput.ValueChanged += + } + ); + RegRangeValueChanged( + AtlasTextureMarginWInput, newMarginW => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Margin; value.Size = new((float)newMarginW, value.Size.Y); if (m_InspectingAtlasTextureInfo.TrySetMargin(value)) UpdateControls(); - }; - AtlasTextureMarginHInput.ValueChanged += + } + ); + RegRangeValueChanged( + AtlasTextureMarginHInput, newMarginH => { if (m_InspectingAtlasTextureInfo is null) return; var value = m_InspectingAtlasTextureInfo.Margin; value.Size = new(value.Size.X, (float)newMarginH); if (m_InspectingAtlasTextureInfo.TrySetMargin(value)) UpdateControls(); - }; - AtlasTextureFilterClipInput.Toggled += + } + ); + RegButtonToggled( + AtlasTextureFilterClipInput, newFilterClip => { if (m_InspectingAtlasTextureInfo is null) return; if (m_InspectingAtlasTextureInfo.TrySetFilterClip(newFilterClip)) UpdateControls(); - }; - DeleteItemButton.Pressed += + } + ); + RegButtonPressed( + DeleteItemButton, () => { if (m_InspectingAtlasTextureInfo is null || !m_InspectingAtlasTextureInfo.IsTemp) return; m_EditingAtlasTexture.Remove(m_InspectingAtlasTextureInfo); m_InspectingAtlasTextureInfo = null; UpdateControls(); - }; + } + ); } /// - /// Set the spin box mode (rounded or not) for all value input related controls + /// Set the spin box mode (rounded or not) for all value input related controls /// /// private void SetSpinBoxMode(bool rounded) { - Set(AtlasTextureRegionXInput); - Set(AtlasTextureRegionYInput); - Set(AtlasTextureRegionWInput); - Set(AtlasTextureRegionHInput); - Set(AtlasTextureMarginXInput); - Set(AtlasTextureMarginYInput); - Set(AtlasTextureMarginWInput); - Set(AtlasTextureMarginHInput); - Set(NewAtlasTextureMarginXInput); - Set(NewAtlasTextureMarginYInput); - Set(NewAtlasTextureMarginWInput); - Set(NewAtlasTextureMarginHInput); - Set(CellSize_PixelSizeX); - Set(CellSize_PixelSizeY); - Set(CellSize_OffsetX); - Set(CellSize_OffsetY); - Set(CellSize_PaddingX); - Set(CellSize_PaddingY); - Set(CellCount_OffsetX); - Set(CellCount_OffsetY); - Set(CellCount_PaddingX); - Set(CellCount_PaddingY); + SetParams(AtlasTextureRegionXInput); + SetParams(AtlasTextureRegionYInput); + SetParams(AtlasTextureRegionWInput); + SetParams(AtlasTextureRegionHInput); + SetParams(AtlasTextureMarginXInput); + SetParams(AtlasTextureMarginYInput); + SetParams(AtlasTextureMarginWInput); + SetParams(AtlasTextureMarginHInput); + SetParams(NewAtlasTextureMarginXInput); + SetParams(NewAtlasTextureMarginYInput); + SetParams(NewAtlasTextureMarginWInput); + SetParams(NewAtlasTextureMarginHInput); + SetParams(CellSize_PixelSizeX); + SetParams(CellSize_PixelSizeY); + SetParams(CellSize_OffsetX); + SetParams(CellSize_OffsetY); + SetParams(CellSize_PaddingX); + SetParams(CellSize_PaddingY); + SetParams(CellCount_OffsetX); + SetParams(CellCount_OffsetY); + SetParams(CellCount_PaddingX); + SetParams(CellCount_PaddingY); return; - void Set(SpinBox spinBox) + void SetParams(SpinBox spinBox) { - if(spinBox is null) return; + if (spinBox is null) return; spinBox.Rounded = rounded; spinBox.Step = rounded ? 1 : 0.01f; } } /// - /// Update the metrics displayed in the mini-inspector based on the provided AtlasTextureInfo + /// Update the metrics displayed in the mini-inspector based on the provided AtlasTextureInfo /// /// private void UpdateInspectingMetrics(EditingAtlasTextureInfo atlasTextureInfo) @@ -190,7 +216,7 @@ private void UpdateInspectingMetrics(EditingAtlasTextureInfo atlasTextureInfo) } /// - /// Reset the displayed metrics in the mini-inspector + /// Reset the displayed metrics in the mini-inspector /// private void ResetInspectingMetrics() { @@ -198,7 +224,7 @@ private void ResetInspectingMetrics() NewItemLabel.Hide(); DeleteItemButton.Hide(); - + AtlasTextureRegionXInput.SetValueNoSignal(0f); AtlasTextureRegionYInput.SetValueNoSignal(0f); AtlasTextureRegionWInput.SetValueNoSignal(0f); @@ -213,4 +239,4 @@ private void ResetInspectingMetrics() } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section3.SaveDiscardSection.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section3.SaveDiscardSection.cs index ead23f6..0e47de4 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section3.SaveDiscardSection.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section3.SaveDiscardSection.cs @@ -1,27 +1,25 @@ #if TOOLS -#region using System.Collections.Generic; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the exports and api used by the Save & Discard Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator { [Export, ExportSubgroup("Save & Discard Section")] private Button DiscardButton { get; set; } + [Export] private Button SaveAndUpdateButton { get; set; } /// - /// Initialize the Save & Discard button callbacks + /// Initialize the Save & Discard button callbacks /// private void InitializeSaveDiscardSection() { - DiscardButton.Pressed += + RegButtonPressed( + DiscardButton, () => { var deletingAtlasTexture = new List(); @@ -42,8 +40,10 @@ private void InitializeSaveDiscardSection() UpdateControls(); if (m_InspectingAtlasTextureInfo is not null) UpdateInspectingMetrics(m_InspectingAtlasTextureInfo); else ResetInspectingMetrics(); - }; - SaveAndUpdateButton.Pressed += + } + ); + RegButtonPressed( + SaveAndUpdateButton, () => { foreach (var editingAtlasTextureInfo in m_EditingAtlasTexture) @@ -58,8 +58,9 @@ private void InitializeSaveDiscardSection() UpdateControls(); if (m_InspectingAtlasTextureInfo is not null) UpdateInspectingMetrics(m_InspectingAtlasTextureInfo); else ResetInspectingMetrics(); - }; + } + ); } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.IsPixelOpqaueImpls.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.IsPixelOpqaueImpls.cs index 8ff8fac..6d6d629 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.IsPixelOpqaueImpls.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.IsPixelOpqaueImpls.cs @@ -1,7 +1,6 @@ using Godot; namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the C# implementation of IsPixelOpaqueImpl for ImageTexture, PortableCompressedTexture2D, and CompressedTexture2D which the original methods are only available in Native Side public partial class UnityAtlasTextureCreator @@ -11,20 +10,18 @@ public partial class UnityAtlasTextureCreator private static Rid s_ImageTextureRid; /// - /// Extract the Image info from the given , Cached. + /// Extract the Image info from the given , Cached. /// private static Image GetImageFromTexture2D(Texture2D texture2D) { - if (!s_ImageTextureRid.IsValid) - { - s_ImageTextureRid = RenderingServer.Texture2DCreate(texture2D.GetImage()); - } + if (!s_ImageTextureRid.IsValid) s_ImageTextureRid = RenderingServer.Texture2DCreate(texture2D.GetImage()); return RenderingServer.Texture2DGet(s_ImageTextureRid); } /// - /// The C# implementation of IsPixelOpaqueImpl for ImageTexture, PortableCompressedTexture2D, and CompressedTexture2D which the original methods are only available in Native Side + /// The C# implementation of IsPixelOpaqueImpl for ImageTexture, PortableCompressedTexture2D, and CompressedTexture2D + /// which the original methods are only available in Native Side /// private static bool IsPixelOpaqueImpl(Texture2D texture2D, int x, int y) { @@ -60,10 +57,7 @@ private static bool IsPixelOpaqueImpl(Texture2D texture2D, int x, int y) if (s_ImageAlphaCache is null) return true; var (aw, ah) = s_ImageAlphaCache.GetSize(); - if (aw == 0 || ah == 0) - { - return true; - } + if (aw == 0 || ah == 0) return true; var imageSize = texture2D.GetSize(); diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.cs index 8cc71bd..9c2be4d 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Section4.SlicerSubviewSection.cs @@ -1,25 +1,28 @@ #if TOOLS -#region - using System; using System.Collections.Generic; using System.Linq; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the exports and api used by the Save & Discard Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator { + private readonly List m_SlicePreview = new(); + + + private SliceMethod m_CurrentSlicerMode = SliceMethod.Automatic; + [Export, ExportSubgroup("Slicer Subview Section")] private Control SlicerMenu { get; set; } + [Export] private OptionButton SlicerTypeSelection { get; set; } [Export] private OptionButton PreservationMethodSelection { get; set; } [Export] private Button ExecuteSliceButton { get; set; } + [Export, ExportSubgroup("Slicer Subview Section/Defaults")] private SpinBox NewAtlasTextureMarginXInput { get; set; } + [Export] private SpinBox NewAtlasTextureMarginYInput { get; set; } [Export] private SpinBox NewAtlasTextureMarginWInput { get; set; } [Export] private SpinBox NewAtlasTextureMarginHInput { get; set; } @@ -47,13 +50,6 @@ public partial class UnityAtlasTextureCreator [Export] private SpinBox CellCount_PaddingY { get; set; } [Export] private CheckBox CellCount_KeepEmptyRects { get; set; } - - private SliceMethod m_CurrentSlicerMode = SliceMethod.Automatic; - - private enum SliceMethod { Automatic = 0, GridByCellSize = 1, GridByCellCount = 2 } - - private enum PreservationMethod { IgnoreExisting = 0, AvoidExisting = 1 } - private SliceMethod CurrentSlicerMode { get => m_CurrentSlicerMode; @@ -99,7 +95,7 @@ private SliceMethod CurrentSlicerMode break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(value)); } PreviewCurrentSlice(); @@ -108,21 +104,25 @@ private SliceMethod CurrentSlicerMode private PreservationMethod CurrentPreservationMethod { get; set; } - private readonly List m_SlicePreview = new(); + private enum SliceMethod { Automatic = 0, GridByCellSize = 1, GridByCellCount = 2 } + + private enum PreservationMethod { IgnoreExisting = 0, AvoidExisting = 1 } /// - /// Initialize the slicer module with the given settings + /// Initialize the slicer module with the given settings /// private void InitializeSlicer(EditorSettings settings) { - AtlasTextureSlicerButton.Toggled += + RegButtonToggled( + AtlasTextureSlicerButton, isOn => { if (m_InspectingTex is null) return; if (isOn) ShowSlicerMenu(); else HideSlicerMenu(); - }; + } + ); CurrentSlicerMode = @@ -136,46 +136,49 @@ private void InitializeSlicer(EditorSettings settings) CurrentPreservationMethod = settings.GetProjectMetadata( - "atlas_texture_editor", - "preservation_mode", - Variant.From(PreservationMethod.AvoidExisting) - ) - .As(); + "atlas_texture_editor", + "preservation_mode", + Variant.From(PreservationMethod.AvoidExisting) + ) + .As(); + - SlicerTypeSelection.AddItem("Automatic", (int)SliceMethod.Automatic); SlicerTypeSelection.AddItem("Grid By Cell Size", (int)SliceMethod.GridByCellSize); SlicerTypeSelection.AddItem("Grid By Cell Count", (int)SliceMethod.GridByCellCount); - SlicerTypeSelection.ItemSelected += p_mode => CurrentSlicerMode = (SliceMethod)p_mode; + RegOptionButtonItemSelected(SlicerTypeSelection, p_mode => CurrentSlicerMode = (SliceMethod)p_mode); SlicerTypeSelection.Selected = (int)CurrentSlicerMode; PreservationMethodSelection.AddItem("Ignore Existing (Additive)", (int)PreservationMethod.IgnoreExisting); PreservationMethodSelection.AddItem("Avoid Existing (Smart)", (int)PreservationMethod.AvoidExisting); - PreservationMethodSelection.ItemSelected += mode => CurrentPreservationMethod = (PreservationMethod)mode; - PreservationMethodSelection.Selected = (int)CurrentPreservationMethod; + RegOptionButtonItemSelected(PreservationMethodSelection, mode => CurrentPreservationMethod = (PreservationMethod)mode); + PreservationMethodSelection.Selected = (int)CurrentPreservationMethod; ExecuteSliceButton.Pressed += PerformSlice; - CellSize_PixelSizeX.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellSize_PixelSizeY.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellSize_OffsetX.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellSize_OffsetY.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellSize_PaddingX.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellSize_PaddingY.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellSize_KeepEmptyRects.Toggled += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellCount_ColumnRowX.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellCount_ColumnRowY.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellCount_OffsetX.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellCount_OffsetY.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellCount_PaddingX.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellCount_PaddingY.ValueChanged += _ => CallDeferred(MethodName.PreviewCurrentSlice); - CellCount_KeepEmptyRects.Toggled += _ => CallDeferred(MethodName.PreviewCurrentSlice); + RegRangeValueChanged(CellSize_PixelSizeX, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellSize_PixelSizeY, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellSize_OffsetX, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellSize_OffsetY, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellSize_PaddingX, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellSize_PaddingY, PreviewCurrentSliceDeferred); + RegButtonToggled(CellSize_KeepEmptyRects, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellCount_ColumnRowX, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellCount_ColumnRowY, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellCount_OffsetX, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellCount_OffsetY, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellCount_PaddingX, PreviewCurrentSliceDeferred); + RegRangeValueChanged(CellCount_PaddingY, PreviewCurrentSliceDeferred); + RegButtonToggled(CellCount_KeepEmptyRects, PreviewCurrentSliceDeferred); SlicerMenu.Hide(); } + private void PreviewCurrentSliceDeferred(double newValue) => CallDeferred(MethodName.PreviewCurrentSlice); + private void PreviewCurrentSliceDeferred(bool newValue) => CallDeferred(MethodName.PreviewCurrentSlice); + /// - /// Show the slicer menu and trigger a preview of the current slice + /// Show the slicer menu and trigger a preview of the current slice /// private void ShowSlicerMenu() { @@ -186,7 +189,7 @@ private void ShowSlicerMenu() } /// - /// Hide the slicer menu and clear the slice preview + /// Hide the slicer menu and clear the slice preview /// private void HideSlicerMenu() { @@ -196,11 +199,13 @@ private void HideSlicerMenu() } /// - /// Perform the selected slicing mode (), and creates the corresponding into + /// Perform the selected slicing mode (), and creates the corresponding + /// into /// private void PerformSlice() { m_SlicePreview.Clear(); + switch (CurrentSlicerMode) { case SliceMethod.Automatic: @@ -231,17 +236,15 @@ private void PerformSlice() } if (CurrentPreservationMethod is PreservationMethod.AvoidExisting) - { for (var i = 0; i < m_SlicePreview.Count; i++) { var current = m_SlicePreview[i]; if (!m_EditingAtlasTexture.Any(editingAtlasTextureInfo => editingAtlasTextureInfo.Region.Intersects(current))) continue; - + m_SlicePreview.RemoveAt(i); i--; } - } var filterClip = FilterClip.ButtonPressed; @@ -251,7 +254,7 @@ private void PerformSlice() (float)NewAtlasTextureMarginWInput.Value, (float)NewAtlasTextureMarginHInput.Value ); - + foreach (var slice in m_SlicePreview) { CreateSlice(slice, margin, filterClip); @@ -262,7 +265,7 @@ private void PerformSlice() } /// - /// Creates a preview for current selecting slicing mode () + /// Creates a preview for current selecting slicing mode () /// /// private void PreviewCurrentSlice() @@ -300,7 +303,7 @@ private void PreviewCurrentSlice() } /// - /// Core method for Automatic Slice Calculation + /// Core method for Automatic Slice Calculation /// private static void CalculateAutomaticSlice(Texture2D texture, IList sliceData) { @@ -339,10 +342,7 @@ private static void CalculateAutomaticSlice(Texture2D texture, IList slic if (!f.IsValid || !e.IsValid) break; - if (f.Value == e.Value) - { - continue; - } + if (f.Value == e.Value) continue; if (!e.Value.Grow(1).Intersects(f.Value)) continue; e.Value = e.Value.Expand(f.Value.Position); @@ -354,12 +354,9 @@ private static void CalculateAutomaticSlice(Texture2D texture, IList slic var nextF = f.GetNext(); if (nextF.IsValid) sliceData.Remove(nextF.Value); } - else - { - queue_erase = true; - // Can't delete the first rect in the list. - } + else queue_erase = true; + // Can't delete the first rect in the list. merged = true; } } @@ -376,7 +373,7 @@ private static void CalculateAutomaticSlice(Texture2D texture, IList slic } /// - /// Core method for Slice Calculation based on Cell Size + /// Core method for Slice Calculation based on Cell Size /// private static void CalculateByCellSizeSlice(Texture2D texture, IList sliceData, Vector2 pixelSize, Vector2 offset, Vector2 margin, bool keepEmptyRect) { @@ -415,7 +412,7 @@ private static void CalculateByCellSizeSlice(Texture2D texture, IList sli } /// - /// Core method for Slice Calculation based on Cell Count + /// Core method for Slice Calculation based on Cell Count /// private static void CalculateByCellCountSlice(Texture2D texture, IList sliceData, Vector2I columnRow, Vector2 offset, Vector2 margin, bool keepEmptyRect) { diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Setction4.SlicerSubviewSection.ListItemReference.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Setction4.SlicerSubviewSection.ListItemReference.cs index a82fba6..3d51946 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Setction4.SlicerSubviewSection.ListItemReference.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.Setction4.SlicerSubviewSection.ListItemReference.cs @@ -1,8 +1,9 @@ #if TOOLS + + using System.Collections.Generic; namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains the exports and api used by the Save & Discard Section of the UnityAtlasTextureCreator public partial class UnityAtlasTextureCreator @@ -19,10 +20,7 @@ private readonly struct ListItemReference public ListItemReference GetNext() { var nextIndex = m_Index + 1; - if (nextIndex < m_BackingList.Count) - { - return new(m_BackingList, nextIndex); - } + if (nextIndex < m_BackingList.Count) return new(m_BackingList, nextIndex); return new(m_BackingList, -1); } @@ -30,10 +28,7 @@ public ListItemReference GetNext() public ListItemReference GetPrev() { var previousIndex = m_Index - 1; - if (previousIndex > 0) - { - return new(m_BackingList, previousIndex); - } + if (previousIndex > 0) return new(m_BackingList, previousIndex); return new(m_BackingList, -1); } @@ -55,4 +50,4 @@ public static IEnumerable> CreateForEach(IList list) public static ListItemReference CreateFor(IList list) => new(list, 0); } } -#endif \ No newline at end of file +#endif diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.cs index 7378f4d..ffc6b18 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreator.cs @@ -1,28 +1,25 @@ #if TOOLS -#region - using System.Diagnostics.CodeAnalysis; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; - // This script contains only the public apis of the UnityAtlasTextureCreator /// -/// Provides a unified window for ease of AtlasTexture creation and modification. +/// Provides a unified window for ease of AtlasTexture creation and modification. /// [Tool] public partial class UnityAtlasTextureCreator : Control { /// - /// Initializes the window + /// Initializes the window /// /// public void Initialize(EditorPlugin editorPlugin) { + m_EditorPlugin = editorPlugin; + var editorInterface = editorPlugin.GetEditorInterface(); m_EditorFileSystem = editorInterface.GetResourceFilesystem(); var settings = editorInterface.GetEditorSettings(); @@ -39,12 +36,12 @@ public void Initialize(EditorPlugin editorPlugin) } /// - /// Change the editing texture + /// Change the editing texture /// /// New texture for editing, pass null for abort - public void UpdateEditingTexture([AllowNull]Texture2D newTexture) + public void UpdateEditingTexture([AllowNull] Texture2D newTexture) { - if (m_InspectingTex is not null) + if (m_InspectingTex != null) { m_InspectingTex.Changed -= OnTexChanged; m_InspectingTex = null; @@ -59,16 +56,15 @@ public void UpdateEditingTexture([AllowNull]Texture2D newTexture) UpdateControls(); - if (m_InspectingTex is null) + if (m_InspectingTex == null) { HideSlicerMenu(); return; } - m_InspectingTexName = GDPath.GetFileNameWithoutExtension(m_InspectingTex.ResourcePath); - m_CurrentSourceTexturePath = GDPath.GetDirectoryName(m_InspectingTex.ResourcePath); - m_InspectingTex.Changed += OnTexChanged; - + m_InspectingTexName = GdPath.GetFileNameWithoutExtension(m_InspectingTex.ResourcePath); + m_CurrentSourceTexturePath = GdPath.GetDirectoryName(m_InspectingTex.ResourcePath); + RegResourceChanged(m_InspectingTex, OnTexChanged); UpdateInspectingTexture(); EditDrawer.QueueRedraw(); diff --git a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreatorBoot.cs b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreatorBoot.cs index 5b2b2d7..8aac640 100644 --- a/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreatorBoot.cs +++ b/addons/deyu_atlas_texture_creator_window/UnityAtlasTextureCreatorBoot.cs @@ -1,15 +1,12 @@ #if TOOLS -#region using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; /// -/// Bootstrap script for +/// Bootstrap script for /// [Tool] public partial class UnityAtlasTextureCreatorBoot : EditorPlugin @@ -17,7 +14,7 @@ public partial class UnityAtlasTextureCreatorBoot : EditorPlugin private UnityAtlasTextureCreator m_EditorWindow; /// - /// This window is capable for editing Texture2Ds, except AtlasTexture itself + /// This window is capable for editing Texture2Ds, except AtlasTexture itself /// public override bool _Handles(GodotObject godotObject) { @@ -28,7 +25,7 @@ public override bool _Handles(GodotObject godotObject) } /// - /// This triggers when user double click a supported assets in scene window. + /// This triggers when user double click a supported assets in scene window. /// public override void _Edit(GodotObject godotObject) { @@ -37,7 +34,7 @@ public override void _Edit(GodotObject godotObject) } /// - /// Creates the actual window and add it to editor dock. + /// Creates the actual window and add it to editor dock. /// public override void _EnterTree() { @@ -50,7 +47,7 @@ public override void _EnterTree() } /// - /// Delete the corresponding window from the editor dock + /// Delete the corresponding window from the editor dock /// public override void _ExitTree() { diff --git a/addons/deyu_atlas_texture_creator_window/ViewPannerCSharpImpl.cs b/addons/deyu_atlas_texture_creator_window/ViewPannerCSharpImpl.cs index d2448a4..1072044 100644 --- a/addons/deyu_atlas_texture_creator_window/ViewPannerCSharpImpl.cs +++ b/addons/deyu_atlas_texture_creator_window/ViewPannerCSharpImpl.cs @@ -1,14 +1,10 @@ -#region - using System; using Godot; -#endregion - namespace DEYU.GDUtilities.UnityAtlasTextureCreatorUtility; /// -/// The C# Implementation of the original ViewPanner exists in godot source code (view_panner.cpp) +/// The C# Implementation of the original ViewPanner exists in godot source code (view_panner.cpp) /// public class ViewPannerCSharpImpl { @@ -18,11 +14,11 @@ public enum PanAxis { Both, Horizontal, Vertical } private bool m_IsDragging; - private Action m_PanCallback; + private Action m_PanCallback; private bool m_PanKeyPressed; private float m_ScrollZoomFactor = 1.1f; - private Action m_ZoomCallback; + private Action m_ZoomCallback; public bool IsPanning => m_IsDragging || m_PanKeyPressed; public bool ForceDrag { get; set; } @@ -34,9 +30,9 @@ public enum PanAxis { Both, Horizontal, Vertical } public PanAxis CurrentPanAxis { get; set; } = PanAxis.Both; - public void SetCallbacks(Action panCallback, Action zoomCallback) + public void SetCallbacks(Action panCallback, Action zoomCallback) { - m_PanCallback = (arg, _) => panCallback(arg); + m_PanCallback = panCallback; m_ZoomCallback = zoomCallback; } @@ -72,7 +68,7 @@ public bool ProcessGuiInput(InputEvent inputEvent, Rect2 canvasRect) case InputEventMouseButton mb: Vector2 scroll_vec = new( - Convert.ToInt32(mb.ButtonIndex == MouseButton.WheelLeft) - Convert.ToInt32(mb.ButtonIndex == MouseButton.WheelLeft), + Convert.ToInt32(mb.ButtonIndex == MouseButton.WheelRight) - Convert.ToInt32(mb.ButtonIndex == MouseButton.WheelLeft), Convert.ToInt32(mb.ButtonIndex == MouseButton.WheelDown) - Convert.ToInt32(mb.ButtonIndex == MouseButton.WheelUp) ); @@ -86,7 +82,7 @@ public bool ProcessGuiInput(InputEvent inputEvent, Rect2 canvasRect) { // Compute the zoom factor. var zoom = scroll_vec.X + scroll_vec.Y > 0 ? 1.0f / m_ScrollZoomFactor : m_ScrollZoomFactor; - m_ZoomCallback(zoom, mb.Position, inputEvent); + m_ZoomCallback(zoom, mb.Position); return true; } @@ -106,7 +102,7 @@ public bool ProcessGuiInput(InputEvent inputEvent, Rect2 canvasRect) break; } - m_PanCallback(-panning * ScrollSpeed, inputEvent); + m_PanCallback(-panning * ScrollSpeed); return true; } @@ -128,7 +124,7 @@ public bool ProcessGuiInput(InputEvent inputEvent, Rect2 canvasRect) break; } - m_PanCallback(-panning * ScrollSpeed, inputEvent); + m_PanCallback(-panning * ScrollSpeed); return true; } @@ -136,7 +132,7 @@ public bool ProcessGuiInput(InputEvent inputEvent, Rect2 canvasRect) { // Compute the zoom factor. var zoom = scroll_vec.X + scroll_vec.Y > 0 ? 1.0f / m_ScrollZoomFactor : m_ScrollZoomFactor; - m_ZoomCallback(zoom, mb.Position, inputEvent); + m_ZoomCallback(zoom, mb.Position); return true; } } @@ -158,16 +154,16 @@ public bool ProcessGuiInput(InputEvent inputEvent, Rect2 canvasRect) break; case InputEventMouseMotion mm when m_IsDragging: - m_PanCallback(mm.Relative, inputEvent); + m_PanCallback(mm.Relative); if (canvasRect != new Rect2()) Input.WarpMouse(mm.Position); return true; case InputEventMagnifyGesture magnify_gesture: // Zoom gesture - m_ZoomCallback(magnify_gesture.Factor, magnify_gesture.Position, inputEvent); + m_ZoomCallback(magnify_gesture.Factor, magnify_gesture.Position); return true; case InputEventPanGesture pan_gesture: - m_PanCallback(-pan_gesture.Delta * ScrollSpeed, inputEvent); + m_PanCallback(-pan_gesture.Delta * ScrollSpeed); break; case InputEventScreenDrag screen_drag: // if (Input::get_singleton() . is_emulating_mouse_from_touch() || Input::get_singleton() . is_emulating_touch_from_mouse()) @@ -177,7 +173,7 @@ public bool ProcessGuiInput(InputEvent inputEvent, Rect2 canvasRect) // } // else // { - m_PanCallback(screen_drag.Relative, inputEvent); + m_PanCallback(screen_drag.Relative); // } break; case InputEventKey k when PanViewShortcut.HasValidEvent() && PanViewShortcut.MatchesEvent(k):