Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a GameCube banner editor #75

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion IndustrialPark/IndustrialPark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,19 @@
<Compile Include="MainForm\BuildISO.Designer.cs">
<DependentUpon>BuildISO.cs</DependentUpon>
</Compile>
<Compile Include="MainForm\CreateGameCubeBanner.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm\CreateGameCubeBanner.Designer.cs">
<DependentUpon>CreateGameCubeBanner.cs</DependentUpon>
</Compile>
<Compile Include="MainForm\OpenLevel.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm\OpenLevel.Designer.cs">
<DependentUpon>OpenLevel.cs</DependentUpon>
</Compile>
<Compile Include="Other\GameCubeBanner.cs" />
<Compile Include="Other\MessageBox.cs" />
<Compile Include="Models\BSP_IO_Shared.cs" />
<Compile Include="Models\ChooseTarget.cs">
Expand Down Expand Up @@ -702,6 +709,9 @@
<EmbeddedResource Include="MainForm\BuildISO.resx">
<DependentUpon>BuildISO.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm\CreateGameCubeBanner.resx">
<DependentUpon>CreateGameCubeBanner.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm\MainForm.en-GB.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -930,6 +940,7 @@
<Content Include="Resources\ArrowDefault.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\PlaceholderBanner1.png" />
<Content Include="Resources\Scripts\readme.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -1001,7 +1012,7 @@ for /d %25%25G in ("$(TargetDir)build_test*") do rd /s /q %25%25G &amp;&amp; ec
:: Delete all orderlog files
del "$(TargetDir)*orderlog.txt"
:: Move all assemblies and related files to lib folder
:: ROBOCOPY "$(TargetDir) " "$(TargetDir)lib\ " /XF *.exe *.config *.json *.manifest *.xml *.pdb *.txt *.cmd *.application /XD app.publish Resources runtimes lib logs data /E /IS /MOVE
:: ROBOCOPY "$(TargetDir) " "$(TargetDir)lib\ " /XF *.exe *.config *.json *.manifest *.xml *.pdb *.txt *.cmd *.application /XD app.publish Resources runtimes lib logs data /E /IS /MOVE
if %25errorlevel%25 leq 4 exit 0 else exit %25errorlevel%25
) ELSE (
cd $(TargetDir)
Expand Down
2 changes: 2 additions & 0 deletions IndustrialPark/IndustrialPark.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/DesignerComponentManagerNuGet/DesignerToolboxNuGetState/@EntryValue">D:\Dev\HeavyIron\IndustrialPark\packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll|*D:\Dev\HeavyIron\IndustrialPark\packages\SharpDX.Desktop.4.2.0\lib\net45\SharpDX.Desktop.dll|</s:String></wpf:ResourceDictionary>
318 changes: 318 additions & 0 deletions IndustrialPark/MainForm/CreateGameCubeBanner.Designer.cs

Large diffs are not rendered by default.

209 changes: 209 additions & 0 deletions IndustrialPark/MainForm/CreateGameCubeBanner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using IndustrialPark.Other;
using Image = System.Web.UI.WebControls.Image;

namespace IndustrialPark
{
public partial class CreateGameCubeBanner : Form
{
public CreateGameCubeBanner()
{
InitializeComponent();
}

private void cancelButton_Click(object sender, EventArgs e)
{
Close();
}

private void saveButton_Click(object sender, EventArgs e)
{
Bitmap image = new Bitmap(GameCubeBanner.IMAGE_WIDTH, GameCubeBanner.IMAGE_HEIGHT);
bannerPictureBox.DrawToBitmap(image, bannerPictureBox.ClientRectangle);

GameCubeBanner banner = new GameCubeBanner
{
Image = image,
Creator = creatorTextBox.Text,
CreatorFull = creatorFullTextBox.Text,
Description = descriptionTextBox.Text,
Title = titleTextBox.Text,
TitleFull = titleFullTextBox.Text
};

// Get save location from dialog

SaveFileDialog dialog = new SaveFileDialog
{
Filter = "GameCube Banner (*.bnr)|*.bnr",
Title = "Save GameCube Banner",
FileName = GameCubeBanner.DEFAULT_FILENAME,
AddExtension = true,
DefaultExt = "bnr"
};

if (dialog.ShowDialog() == DialogResult.OK)
{
// Save banner to file
if (banner.SaveToFile(dialog.FileName))
{
MessageBox.Show("Banner saved successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Failed to save banner.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

private void selectImageButton_Click(object sender, EventArgs e)
{
// Open file dialog to select image
OpenFileDialog dialog = new OpenFileDialog
{
Filter = "Image Files|*.bmp;*.jpg;*.jpeg;*.png;*.gif;*.tif;*.tiff",
Title = "Select an image file"
};

if (dialog.ShowDialog() == DialogResult.OK)
{
imagePathTextBox.Text = dialog.FileName;
metadataTextChanged(null, null);

// Update PictureBox with image
try
{
bannerPictureBox.Image = new Bitmap(dialog.FileName);
}
catch (Exception ex)
{
MessageBox.Show("Failed to load image: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

private void UpdateFieldsFromBanner(string filepath)
{
// Import banner from file
GameCubeBanner banner = GameCubeBanner.ImportFromFile(filepath);

if (banner != null)
{
// Set metadata fields
titleTextBox.Text = banner.Title;
creatorTextBox.Text = banner.Creator;
titleFullTextBox.Text = banner.TitleFull;
creatorFullTextBox.Text = banner.CreatorFull;
descriptionTextBox.Text = banner.Description;

// Convert image to PictureBox
bannerPictureBox.Image = banner.Image;

// Update image path text box
imagePathTextBox.Text = filepath;
}
else
{
MessageBox.Show("Failed to import banner.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private bool IsSupportedImageFile(string extension)
{
// List of image file extensions
string[] imageExtensions = { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff", ".tif" };
return Array.Exists(imageExtensions, ext => ext == extension);
}

private void metadataTextChanged(object sender, EventArgs e)
{
// Enable save button if all metadata fields are filled
saveButton.Enabled = !string.IsNullOrWhiteSpace(titleTextBox.Text) &&
!string.IsNullOrWhiteSpace(creatorTextBox.Text) &&
!string.IsNullOrWhiteSpace(titleFullTextBox.Text) &&
!string.IsNullOrWhiteSpace(creatorFullTextBox.Text) &&
!string.IsNullOrWhiteSpace(descriptionTextBox.Text);

}

private void importBnrButton_Click(object sender, EventArgs e)
{
// Open file dialog to select BNR file

OpenFileDialog dialog = new OpenFileDialog
{
Filter = "GameCube Banner (*.bnr)|*.bnr",
Title = "Select a GameCube Banner file"
};

if (dialog.ShowDialog() == DialogResult.OK)
{
UpdateFieldsFromBanner(dialog.FileName);
}
}

private void CreateGameCubeBanner_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length > 0)
{
string extension = Path.GetExtension(files[0]).ToLower();
if (IsSupportedImageFile(extension) || extension == GameCubeBanner.DEFAULT_FILE_EXTENSION)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
else
{
e.Effect = DragDropEffects.None;
}
}

private void CreateGameCubeBanner_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

if (files.Length > 0)
{
string filePath = files[0];
string extension = Path.GetExtension(filePath).ToLower();

try
{
if (IsSupportedImageFile(extension))
{
var image = System.Drawing.Image.FromFile(filePath);
bannerPictureBox.Image = image;
imagePathTextBox.Text = filePath;
}
else if (extension == GameCubeBanner.DEFAULT_FILE_EXTENSION)
{
UpdateFieldsFromBanner(filePath);
}
else
{
MessageBox.Show("Unsupported file type. Must be a supported image or GameCube Banner file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
}
}
}
123 changes: 123 additions & 0 deletions IndustrialPark/MainForm/CreateGameCubeBanner.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="label1.Text" xml:space="preserve">
<value>GameCube banners, named "opening.bnr", contain metadata about the game, including its title and creator, and a 96px x 32px banner image which is displayed in menu mode. It is also displayed in Dolphin's game list.</value>
</data>
</root>
Loading