-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: William <[email protected]>
- Loading branch information
1 parent
8516ab2
commit b8279b2
Showing
18 changed files
with
325 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ public enum ItemType | |
Chess, | ||
Chibi, | ||
Group_Selection, | ||
Item, | ||
Map, | ||
Place, | ||
Puzzle, | ||
|
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,71 @@ | ||
using HaruhiChokuretsuLib.Archive.Graphics; | ||
using HaruhiChokuretsuLib.Util; | ||
using SerialLoops.Lib.Util; | ||
using SkiaSharp; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace SerialLoops.Lib.Items | ||
{ | ||
public class ItemItem : Item, IPreviewableGraphic | ||
{ | ||
public GraphicsFile ItemGraphic { get; set; } | ||
public int ItemIndex { get; set; } | ||
|
||
public ItemItem(string name) : base(name, ItemType.Item) | ||
{ | ||
} | ||
public ItemItem(string name, int itemIndex, short grpIndex, Project project) : base(name, ItemType.Item) | ||
{ | ||
ItemGraphic = project.Grp.Files[grpIndex - 1]; | ||
ItemIndex = itemIndex; | ||
} | ||
|
||
public SKBitmap GetImage() | ||
{ | ||
return ItemGraphic.GetImage(transparentIndex: 0); | ||
} | ||
|
||
public void SetImage(SKBitmap image, IProgressTracker tracker, ILogger log) | ||
{ | ||
tracker.Focus("Setting CG single image...", 1); | ||
List<SKColor> palette = Helpers.GetPaletteFromImage(image, 255, log); | ||
ItemGraphic.SetPalette(palette, 0); | ||
ItemGraphic.SetImage(image); | ||
tracker.Finished++; | ||
} | ||
|
||
public void Write(Project project, ILogger log) | ||
{ | ||
using MemoryStream grp1Stream = new(); | ||
ItemGraphic.GetImage().Encode(grp1Stream, SKEncodedImageFormat.Png, 1); | ||
IO.WriteBinaryFile(Path.Combine("assets", "graphics", $"{ItemGraphic.Index:X3}.png"), grp1Stream.ToArray(), project, log); | ||
IO.WriteStringFile(Path.Combine("assets", "graphics", $"{ItemGraphic.Index:X3}_pal.csv"), | ||
string.Join(',', ItemGraphic.Palette.Select(c => c.ToString())), project, log); | ||
} | ||
|
||
SKBitmap IPreviewableGraphic.GetPreview(Project project) | ||
{ | ||
return GetImage(); | ||
} | ||
|
||
public override void Refresh(Project project, ILogger log) | ||
{ | ||
} | ||
|
||
public enum ItemLocation | ||
{ | ||
Exit = 221, | ||
Left = 222, | ||
Center = 223, | ||
Right = 224, | ||
} | ||
|
||
public enum ItemTransition | ||
{ | ||
Slide = 225, | ||
Fade = 226, | ||
} | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/SerialLoops.Lib/Script/Parameters/ItemLocationScriptParameter.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,16 @@ | ||
using HaruhiChokuretsuLib.Archive.Event; | ||
using SerialLoops.Lib.Items; | ||
|
||
namespace SerialLoops.Lib.Script.Parameters | ||
{ | ||
public class ItemLocationScriptParameter(string name, short itemLocation) : ScriptParameter(name, ParameterType.ITEM_LOCATION) | ||
{ | ||
public ItemItem.ItemLocation Location { get; set; } = (ItemItem.ItemLocation)itemLocation; | ||
public override short[] GetValues(object obj = null) => [(short)Location]; | ||
|
||
public override ItemLocationScriptParameter Clone(Project project, EventFile eventFile) | ||
{ | ||
return new(Name, (short)Location); | ||
} | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/SerialLoops.Lib/Script/Parameters/ItemTransitionScriptParameter.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,16 @@ | ||
using HaruhiChokuretsuLib.Archive.Event; | ||
using SerialLoops.Lib.Items; | ||
|
||
namespace SerialLoops.Lib.Script.Parameters | ||
{ | ||
public class ItemTransitionScriptParameter(string name, short itemTransition) : ScriptParameter(name, ParameterType.ITEM_TRANSITION) | ||
{ | ||
public ItemItem.ItemTransition Transition { get; set; } = (ItemItem.ItemTransition)itemTransition; | ||
public override short[] GetValues(object obj = null) => [(short)Transition]; | ||
|
||
public override ItemTransitionScriptParameter Clone(Project project, EventFile eventFile) | ||
{ | ||
return new(Name, (short)Transition); | ||
} | ||
} | ||
} |
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
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
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
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,98 @@ | ||
using Eto.Forms; | ||
using HaruhiChokuretsuLib.Util; | ||
using SerialLoops.Dialogs; | ||
using SerialLoops.Lib; | ||
using SerialLoops.Lib.Items; | ||
using SerialLoops.Utility; | ||
using SkiaSharp; | ||
using System; | ||
using System.IO; | ||
|
||
namespace SerialLoops.Editors | ||
{ | ||
public class ItemEditor(ItemItem item, Project project, ILogger log) : Editor(item,log, project) | ||
{ | ||
private ItemItem _item; | ||
|
||
public override Container GetEditorPanel() | ||
{ | ||
_item = (ItemItem)Description; | ||
|
||
Button exportButton = new() { Text = "Export" }; | ||
exportButton.Click += ExportButton_Click; | ||
|
||
Button replaceButton = new() { Text = "Replace" }; | ||
replaceButton.Click += ReplaceButton_Click; | ||
|
||
return new Scrollable | ||
{ | ||
Content = new StackLayout | ||
{ | ||
Orientation = Orientation.Vertical, | ||
Spacing = 5, | ||
Items = | ||
{ | ||
new ImageView() { Image = new SKGuiImage(_item.GetImage()) }, | ||
new StackLayout | ||
{ | ||
Orientation = Orientation.Horizontal, | ||
Spacing = 3, | ||
Items = | ||
{ | ||
exportButton, | ||
replaceButton, | ||
} | ||
}, | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private void ExportButton_Click(object sender, EventArgs e) | ||
{ | ||
SaveFileDialog saveFileDialog = new(); | ||
saveFileDialog.Filters.Add(new() { Name = "PNG Image", Extensions = [".png"] }); | ||
if (saveFileDialog.ShowAndReportIfFileSelected(this)) | ||
{ | ||
try | ||
{ | ||
using FileStream fs = File.Create(saveFileDialog.FileName); | ||
_item.GetImage().Encode(fs, SKEncodedImageFormat.Png, 1); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_log.LogError($"Failed to export background {_item.DisplayName} to file {saveFileDialog.FileName}: {ex.Message}\n\n{ex.StackTrace}"); | ||
} | ||
} | ||
} | ||
|
||
private void ReplaceButton_Click(object sender, EventArgs e) | ||
{ | ||
OpenFileDialog openFileDialog = new(); | ||
SKBitmap original = _item.GetImage(); | ||
openFileDialog.Filters.Add(new() { Name = "Supported Images", Extensions = [".bmp", ".gif", ".heif", ".jpg", ".jpeg", ".png", ".webp",] }); | ||
if (openFileDialog.ShowAndReportIfFileSelected(this)) | ||
{ | ||
ImageCropResizeDialog itemResizeDialog = new(SKBitmap.Decode(openFileDialog.FileName), original.Width, original.Height, _log); | ||
itemResizeDialog.Closed += (sender, args) => | ||
{ | ||
if (itemResizeDialog.SaveChanges) | ||
{ | ||
try | ||
{ | ||
LoopyProgressTracker tracker = new(); | ||
_ = new ProgressDialog(() => _item.SetImage(itemResizeDialog.FinalImage, tracker, _log), | ||
() => Content = GetEditorPanel(), tracker, $"Replacing {_item.DisplayName}..."); | ||
UpdateTabTitle(false); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_log.LogError($"Failed to replace background {_item.DisplayName} with file {openFileDialog.FileName}: {ex.Message}\n\n{ex.StackTrace}"); | ||
} | ||
} | ||
}; | ||
itemResizeDialog.ShowModal(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.