Skip to content

Commit

Permalink
+finalize support for GameType (ark/atlas)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahstrike committed Feb 26, 2022
1 parent 01ba01f commit 170451f
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 32 deletions.
3 changes: 3 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<setting name="MyPaintings" serializeAs="String">
<value />
</setting>
<setting name="GameType" serializeAs="String">
<value>1</value>
</setting>
</DyeAtlas.Properties.Settings>
</userSettings>
</configuration>
50 changes: 33 additions & 17 deletions DyeAtlas.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 35 additions & 8 deletions DyeAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,27 @@ public Palette LoadPalette(GameType gt)
return pal;
}

public static Palette palette;// defer loading until form load.. make sure config files are nice
private Palette _palette = null;
public Palette palette
{
get
{
if(_palette == null)
{
_palette = LoadPalette((GameType)gamechoice.SelectedIndex);// should be ok to cast.. only 2 options lol
}

return _palette;
}

set
{
_palette = value;
}
}

private void DyeAtlas_Load(object sender, EventArgs e)
{
MessageBox.Show("need a dropdown for gametype");
palette = LoadPalette(GameType.Ark);

Bitmap bk = new Bitmap(preview.Width, preview.Height);
using (Graphics gfx = Graphics.FromImage(bk))
{
Expand All @@ -59,12 +73,14 @@ private void DyeAtlas_Load(object sender, EventArgs e)
savePNTButton.Enabled = false;

// load settings
gamechoice.SelectedIndex = Properties.Settings.Default.GameType;
mypaintings.Text = Properties.Settings.Default.MyPaintings;
}

private void DyeAtlas_FormClosed(object sender, FormClosedEventArgs e)
{
// save settings
Properties.Settings.Default.GameType = gamechoice.SelectedIndex;
Properties.Settings.Default.MyPaintings = mypaintings.Text;
}

Expand Down Expand Up @@ -95,7 +111,7 @@ public void SaveFile(string file)

if(Path.GetExtension(file).Equals(".pnt", StringComparison.InvariantCultureIgnoreCase))//IsFilePNT(file))
{
PNTImage pnt = PNTImage.GenerateFromBitmap(bmp, dithering.Checked);
PNTImage pnt = PNTImage.GenerateFromBitmap(palette, bmp, dithering.Checked);

pnt.Save(file);
}else
Expand Down Expand Up @@ -140,7 +156,7 @@ public void OpenFile(string file)
switch (Path.GetExtension(file).ToLowerInvariant())
{
case ".pnt":
pnt = PNTImage.LoadPNT(file);
pnt = PNTImage.LoadPNT(palette, file);

// autoselect resolution
if (pnt.width >= 256)
Expand Down Expand Up @@ -190,7 +206,7 @@ public void OpenFile(string file)
bmp = newBmp;
}

pnt = PNTImage.GenerateFromBitmap(bmp, dithering.Checked);
pnt = PNTImage.GenerateFromBitmap(palette, bmp, dithering.Checked);
}
break;
}
Expand Down Expand Up @@ -305,7 +321,7 @@ private void mypaintingsbrowse_Click(object sender, EventArgs e)
FolderBrowserDialog fld = new FolderBrowserDialog();

fld.SelectedPath = mypaintings.Text;
fld.Description = @"This is usually like: [ATLAS install]\ShooterGame\Saved\MyPaintings";
fld.Description = @"This is usually like: [GAME INSTALL]\ShooterGame\Saved\MyPaintings";

if (fld.ShowDialog() != DialogResult.OK)
return;
Expand All @@ -315,7 +331,18 @@ private void mypaintingsbrowse_Click(object sender, EventArgs e)

private void openfolder_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(mypaintings.Text) || !Directory.Exists(mypaintings.Text))
return;

System.Diagnostics.Process.Start("explorer", mypaintings.Text);
}

private void gamechoice_SelectedIndexChanged(object sender, EventArgs e)
{
// invalidate palette
palette = null;

OpenFile(currentfile.Text);
}
}
}
21 changes: 14 additions & 7 deletions PNTImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace DyeAtlas
{
public class PNTImage
{
public readonly Palette palette;

public uint version;
public int width;
public int height;
Expand All @@ -19,9 +21,14 @@ public class PNTImage

public byte[] bits;

public static PNTImage GenerateFromBitmap(Bitmap bmp, bool dither)
public PNTImage(Palette _palette)
{
palette = _palette;
}

public static PNTImage GenerateFromBitmap(Palette pal, Bitmap bmp, bool dither)
{
PNTImage pnt = new PNTImage();
PNTImage pnt = new PNTImage(pal);
pnt.version = 1;
pnt.width = bmp.Width;
pnt.height = bmp.Height;
Expand Down Expand Up @@ -77,12 +84,12 @@ private static void DitherHelper(Bitmap bmp, int x, int y, WorkColor error)
bmp.SetPixel(x, y, clr + error);
}

public static PNTImage LoadPNT(string file)
public static PNTImage LoadPNT(Palette pal, string file)
{
using (Stream fs = File.OpenRead(file))
using (BinaryReader br = new BinaryReader(fs))
{
PNTImage pnt = new PNTImage();
PNTImage pnt = new PNTImage(pal);
pnt.version = br.ReadUInt32();
pnt.width = br.ReadInt32();
pnt.height = br.ReadInt32();
Expand Down Expand Up @@ -115,15 +122,15 @@ public void Save(string file)
if (x < 0 || x >= width || y < 0 || y >= height)
return null;

return DyeAtlas.palette.Get(bits[x + y * width]);
return palette.Get(bits[x + y * width]);
}

public void SetPixel(int x, int y, Color clr)
{
if (x < 0 || x >= width || y < 0 || y >= height)
return;

bits[x + y * width] = (byte)DyeAtlas.palette.FindClosestIndex(clr);
bits[x + y * width] = (byte)palette.FindClosestIndex(clr);
}

public Bitmap GenerateBitmap()
Expand All @@ -133,7 +140,7 @@ public Bitmap GenerateBitmap()
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
{
bmp.SetPixel(x, y, DyeAtlas.palette.Get(bits[x + y * width]) ?? Color.FromArgb(0, 0, 0, 0));
bmp.SetPixel(x, y, palette.Get(bits[x + y * width]) ?? Color.FromArgb(0, 0, 0, 0));
}

return bmp;
Expand Down
12 changes: 12 additions & 0 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<Setting Name="MyPaintings" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="GameType" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 170451f

Please sign in to comment.