-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-loading brand new project now maintains the NineSlice image
fixes #409
- Loading branch information
Showing
3 changed files
with
90 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Gum/Plugins/InternalPlugins/NineSlicePlugin/MainNineSlicePlugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Gum.DataTypes; | ||
using Gum.Managers; | ||
using Gum.Plugins.BaseClasses; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ToolsUtilities; | ||
|
||
namespace Gum.Plugins.InternalPlugins.NineSlicePlugin; | ||
|
||
[Export(typeof(PluginBase))] | ||
internal class MainNineSlicePlugin : InternalPlugin | ||
{ | ||
public override void StartUp() | ||
{ | ||
AssignEvents(); | ||
} | ||
|
||
private void AssignEvents() | ||
{ | ||
this.ProjectLocationSet += HandleProjectLocationSet; | ||
} | ||
|
||
private void HandleProjectLocationSet(FilePath path) | ||
{ | ||
var gumProject = ObjectFinder.Self.GumProjectSave; | ||
|
||
var sourceFile = Path.Combine(GetExecutingDirectory(), "Content\\ExampleSpriteFrame.png"); | ||
var destinationFile = FileManager.GetDirectory(gumProject.FullFileName) + "ExampleSpriteFrame.png"; | ||
try | ||
{ | ||
System.IO.File.Copy(sourceFile, destinationFile); | ||
|
||
var nineSliceStandard = gumProject.StandardElements.Find(item => item.Name == "NineSlice"); | ||
nineSliceStandard.DefaultState.SetValue("SourceFile", "ExampleSpriteFrame.png", "string"); | ||
|
||
GumCommands.Self.FileCommands.TryAutoSaveElement(nineSliceStandard); | ||
} | ||
catch (Exception e) | ||
{ | ||
GumCommands.Self.GuiCommands.PrintOutput($"Error copying ExampleSpriteFrame.png: {e}"); | ||
} | ||
} | ||
|
||
static string GetExecutingDirectory() | ||
{ | ||
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
return path; | ||
} | ||
|
||
} |