-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
320588d
commit ac7d1c2
Showing
5 changed files
with
97 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using BTD_Mod_Helper.Api.Helpers; | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
using UnityEngine.UI; | ||
namespace BTD_Mod_Helper.Api.Commands; | ||
|
||
internal class ExportImageCommand : ModCommand<ExportCommand> | ||
{ | ||
public override string Command => "image"; | ||
public override string Help => "Exports UI images raycasted from the current mouse position"; | ||
|
||
public override bool Execute(ref string resultText) | ||
{ | ||
try | ||
{ | ||
var exported = new List<string>(); | ||
var raycastResults = new Il2CppSystem.Collections.Generic.List<RaycastResult>(); | ||
EventSystem.current.RaycastAll(new PointerEventData(EventSystem.current) | ||
{ | ||
position = Input.mousePosition | ||
}, raycastResults); | ||
|
||
var imagesFolder = Path.Combine(FileIOHelper.sandboxRoot, "Images"); | ||
|
||
foreach (var result in raycastResults) | ||
{ | ||
if (result.gameObject.Is(out var gameObject) && | ||
gameObject.HasComponent(out Image image) && | ||
image.sprite != null) | ||
{ | ||
var path = Path.Combine(imagesFolder, image.sprite.name + ".png"); | ||
if (image.sprite.TrySaveToPNG(path)) | ||
{ | ||
ModHelper.Msg($"Exported {path}"); | ||
exported.Add(image.sprite.name); | ||
} | ||
} | ||
} | ||
|
||
resultText = $"Exported {exported.Join()} to {imagesFolder}"; | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
resultText = e.Message; | ||
ModHelper.Warning(e); | ||
} | ||
|
||
return true; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
- Added a ModBloonOverlay class for making custom Bloon Overlays | ||
- NOTE: Due to a MelonLoader bug, these won't properly display unless you're on ML 0.6.6 or higher | ||
- Accounted for a Unity bug that was affecting the internal durations of embedded AudioClips | ||
- Added a Sprite.TrySaveToPNG() extension like the one for Textures except accounting for position and size within a larger texture atlas | ||
- Added a Sprite.TrySaveToPNG() extension like the one for Textures except accounting for position and size within a larger texture atlas | ||
- Added `export image` console commands that exports all UI images underneath your mouse cursor to png files |
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