-
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.
Add project settings, name and icon replacing (#48)
Co-authored-by: jonko0493 <[email protected]>
- Loading branch information
1 parent
b1ccb4e
commit 2708cef
Showing
9 changed files
with
282 additions
and
13 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
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,68 @@ | ||
using HaroohieClub.NitroPacker.Core; | ||
using HaroohieClub.NitroPacker.Nitro.Gx; | ||
using HaruhiChokuretsuLib.Archive.Graphics; | ||
using HaruhiChokuretsuLib.Util; | ||
using SkiaSharp; | ||
using System; | ||
using System.Linq; | ||
using static HaroohieClub.NitroPacker.Nitro.Card.Rom.RomBanner; | ||
|
||
namespace SerialLoops.Lib | ||
{ | ||
public class ProjectSettings | ||
{ | ||
public NdsProjectFile File { get; } | ||
private BannerV1 Banner => File.RomInfo.Banner.Banner; | ||
private readonly ILogger _log; | ||
|
||
public string Name { | ||
get => Banner.GameName[0]; | ||
set | ||
{ | ||
string name = value.Length > 128 ? value[..63] : value; | ||
for (int i = 0; i < Banner.GameName.Length; i++) | ||
{ | ||
Banner.GameName[i] = name; | ||
} | ||
} | ||
} | ||
|
||
public SKBitmap Icon | ||
{ | ||
get | ||
{ | ||
Rgba8Bitmap bitmap = Banner.GetIcon(); | ||
return new(bitmap.Width, bitmap.Height) | ||
{ | ||
Pixels = bitmap.Pixels.Select(p => new SKColor(p)).ToArray() | ||
}; | ||
} | ||
set | ||
{ | ||
GraphicsFile grp = new() | ||
{ | ||
Name = "ICON", | ||
PixelData = new(), | ||
PaletteData = new(), | ||
}; | ||
grp.Initialize(Array.Empty<byte>(), 0, _log); | ||
grp.FileFunction = GraphicsFile.Function.SHTX; | ||
grp.ImageForm = GraphicsFile.Form.TILE; | ||
grp.ImageTileForm = GraphicsFile.TileForm.GBA_4BPP; | ||
grp.Width = 32; | ||
grp.Height = 32; | ||
grp.Palette = new(new SKColor[16]); | ||
grp.SetImage(value, setPalette: true, transparentIndex: 0, newSize: true); | ||
|
||
Banner.Image = grp.PixelData.ToArray(); | ||
Banner.Pltt = grp.PaletteData.ToArray(); | ||
} | ||
} | ||
public ProjectSettings(NdsProjectFile file, ILogger log) | ||
{ | ||
File = file; | ||
_log = log; | ||
} | ||
|
||
} | ||
} |
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,159 @@ | ||
using Eto.Forms; | ||
using HaruhiChokuretsuLib.Util; | ||
using SerialLoops.Lib; | ||
using SerialLoops.Utility; | ||
using SkiaSharp; | ||
using System; | ||
|
||
namespace SerialLoops | ||
{ | ||
public class ProjectSettingsDialog : Dialog | ||
{ | ||
private readonly Project _project; | ||
private readonly ILogger _log; | ||
private ProjectSettings Settings => _project.Settings; | ||
|
||
private TextArea _nameBox; | ||
private SKBitmap _newIcon; | ||
|
||
public ProjectSettingsDialog(Project project, ILogger log) | ||
{ | ||
_project = project; | ||
_log = log; | ||
|
||
InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
Title = "Project Settings"; | ||
Padding = 10; | ||
MinimumSize = new(300, 250); | ||
|
||
Button applyButton = new() { Text = "Apply" }; | ||
applyButton.Click += ApplyButton_OnClick; | ||
|
||
Button cancelButton = new() { Text = "Cancel" }; | ||
cancelButton.Click += (sender, e) => { Close(); }; | ||
|
||
Content = new TableLayout( | ||
new TableRow( | ||
new GroupBox | ||
{ | ||
Text = "Game Banner", | ||
Padding = 10, | ||
Content = new StackLayout | ||
{ | ||
Padding = 10, | ||
Spacing = 10, | ||
Orientation = Orientation.Horizontal, | ||
HorizontalContentAlignment = HorizontalAlignment.Stretch, | ||
Items = { GetIconEditor(), GetNameEditor() } | ||
} | ||
} | ||
), | ||
new TableRow( | ||
new StackLayout | ||
{ | ||
Padding = 10, | ||
Spacing = 5, | ||
Orientation = Orientation.Horizontal, | ||
HorizontalContentAlignment = HorizontalAlignment.Center, | ||
Items = { applyButton, cancelButton } | ||
} | ||
) | ||
); | ||
} | ||
|
||
private Container GetIconEditor() | ||
{ | ||
Panel iconPanel = new() | ||
{ | ||
Content = GetPreview(Settings.Icon) | ||
}; | ||
Button replaceButton = new() { Text = "Replace..." }; | ||
replaceButton.Click += (sender, e) => | ||
{ | ||
OpenFileDialog dialog = new() | ||
{ | ||
Title = "Select Icon", | ||
Filters = { new FileFilter("Image Files", ".png", ".jpg", ".jpeg", ".bmp", ".gif") } | ||
}; | ||
|
||
if (dialog.ShowDialog(this) == DialogResult.Ok) | ||
{ | ||
SKBitmap newIcon = SKBitmap.Decode(dialog.FileName); | ||
_newIcon = new(32, 32); | ||
newIcon.ScalePixels(_newIcon, SKFilterQuality.High); | ||
iconPanel.Content = GetPreview(_newIcon); | ||
} | ||
}; | ||
|
||
return new StackLayout | ||
{ | ||
Padding = 10, | ||
Spacing = 10, | ||
HorizontalContentAlignment = HorizontalAlignment.Center, | ||
VerticalContentAlignment = VerticalAlignment.Center, | ||
Items = | ||
{ | ||
iconPanel, | ||
replaceButton | ||
} | ||
}; | ||
} | ||
|
||
private static SKGuiImage GetPreview(SKBitmap icon) | ||
{ | ||
SKBitmap preview = new(64, 64); | ||
icon.ScalePixels(preview, SKFilterQuality.None); | ||
return new SKGuiImage(preview); | ||
} | ||
|
||
private Container GetNameEditor() | ||
{ | ||
_nameBox = new() | ||
{ | ||
Text = Settings.Name, | ||
Size = new(190, 50), | ||
SpellCheck = false, | ||
AcceptsTab = false | ||
}; | ||
|
||
return new StackLayout | ||
{ | ||
Padding = 10, | ||
Spacing = 5, | ||
HorizontalContentAlignment = HorizontalAlignment.Center, | ||
VerticalContentAlignment = VerticalAlignment.Center, | ||
Items = {"Game Title", _nameBox } | ||
}; | ||
} | ||
|
||
private void ApplyButton_OnClick(object sender, EventArgs e) | ||
{ | ||
string text = _nameBox.Text; | ||
if (text.Length is < 1 or > 127) | ||
{ | ||
MessageBox.Show("Please enter a game name for the banner, between 1 and 128 characters.", MessageBoxType.Warning); | ||
return; | ||
} | ||
|
||
if (text.Split('\n').Length > 3) | ||
{ | ||
MessageBox.Show("Game banner can only contain up to three lines.", MessageBoxType.Error); | ||
return; | ||
} | ||
Settings.Name = text; | ||
|
||
if (_newIcon is not null) | ||
{ | ||
Settings.Icon = _newIcon; | ||
} | ||
|
||
_log.Log("Updated NDS Project File settings"); | ||
Close(); | ||
} | ||
|
||
} | ||
} |
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