Skip to content

Commit cf98ddb

Browse files
Tiles export.
1 parent badc999 commit cf98ddb

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

ArcanumTextureSlicer/ArcanumTextureSlicer.Console/Program.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void Main(string[] args)
5757
try
5858
{
5959
var tilePath =
60-
$"{outputFolder.TrimEnd('/', '\\')}\\tile_{LeadingZero(tile.Row)}_{LeadingZero(tile.Column)}.bmp";
60+
$"{outputFolder.TrimEnd('/', '\\')}\\tile_{tile.Row.ToString("D3")}_{tile.Column.ToString("D3")}.bmp";
6161
System.Console.WriteLine(tilePath);
6262
outputBitmap.Save(tilePath, ImageFormat.Bmp);
6363
}
@@ -75,14 +75,5 @@ public static void Main(string[] args)
7575
System.Console.WriteLine(e);
7676
}
7777
}
78-
79-
private static string LeadingZero(int i)
80-
{
81-
return i < 100
82-
? i < 10
83-
? $"00{i}"
84-
: $"0{i}"
85-
: $"{i}";
86-
}
8778
}
8879
}

ArcanumTextureSlicer/ArcanumTextureSlicer.Core/BitmapExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public static Point GetStartTileCenter(this Bitmap source)
6868

6969
public static Bitmap CreateTile(this Bitmap source, int x, int y)
7070
{
71-
var tile = CloneRegion(source, new Rectangle(x, y, Tile.Width, Tile.Height));
71+
var tile = CloneRegion(source,
72+
new Rectangle(x - Tile.HalfWidth, y - Tile.HalfHeight, Tile.Width, Tile.Height));
7273
tile.DrawAlpha();
7374
return tile;
7475
}
@@ -126,7 +127,7 @@ public static void DrawAlpha(this Bitmap tile)
126127
{
127128
for (var x = 0; x < Tile.Width; x++)
128129
{
129-
if (!Tile.HitTest(x, y))
130+
if (!Tile.HitTest(x - Tile.HalfWidth, y - Tile.HalfHeight))
130131
{
131132
canvasBytes[x + y*data.Stride] = 0;
132133
}

ArcanumTextureSlicer/ArcanumTextureSlicer.Gui/ArcanumTextureSlicer.Gui.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<Reference Include="System" />
3939
<Reference Include="System.Data" />
4040
<Reference Include="System.Drawing" />
41+
<Reference Include="System.Windows.Forms" />
4142
<Reference Include="System.Xml" />
4243
<Reference Include="Microsoft.CSharp" />
4344
<Reference Include="System.Core" />

ArcanumTextureSlicer/ArcanumTextureSlicer.Gui/Controls/GridViewer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ public class GridViewer : Image
3232
private IList<GridTile> _tiles;
3333
private int _width;
3434

35+
public IEnumerable<Tile> SelectedTiles => _tiles
36+
.Where(t => t.Selected)
37+
.OrderBy(t => t.SelectedIndex)
38+
.Select(t => new Tile
39+
{
40+
Row = t.Row,
41+
Column = t.Column,
42+
X = t.X + OffsetX,
43+
Y = t.Y + OffsetY
44+
});
45+
3546
public int OffsetX
3647
{
3748
get { return _offsetX; }

ArcanumTextureSlicer/ArcanumTextureSlicer.Gui/MainWindow.xaml.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
using System;
22
using System.Drawing;
33
using System.Drawing.Imaging;
4+
using System.IO;
5+
using System.Linq;
46
using System.Windows;
7+
using System.Windows.Forms;
58
using System.Windows.Input;
69
using System.Windows.Media;
10+
using ArcanumTextureSlicer.Core;
711
using ArcanumTextureSlicer.Gui.Commands;
8-
using Microsoft.Win32;
12+
using MessageBox = System.Windows.MessageBox;
13+
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
14+
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
915
using PixelFormat = System.Drawing.Imaging.PixelFormat;
1016
using Point = System.Windows.Point;
1117

@@ -17,6 +23,7 @@ namespace ArcanumTextureSlicer.Gui
1723
public partial class MainWindow : Window
1824
{
1925
private Bitmap _bitmap;
26+
private string _lastExportPath;
2027
private Point _mousePosition;
2128
private Point _scrollOffset;
2229
private double _zoom = 1.0;
@@ -45,18 +52,17 @@ private void Open_CanExecute(object sender, CanExecuteRoutedEventArgs e)
4552
e.CanExecute = true;
4653
}
4754

48-
4955
private void Open_Executed(object sender, ExecutedRoutedEventArgs e)
5056
{
51-
var openFileDialog = new OpenFileDialog
57+
var dialog = new OpenFileDialog
5258
{
5359
Multiselect = false,
5460
ShowReadOnly = true,
5561
Filter = "Bitmap Images (*.bmp)|*.bmp|All Files (*.*)|*.*"
5662
};
57-
if (openFileDialog.ShowDialog() == true)
63+
if (dialog.ShowDialog() == true)
5864
{
59-
OpenFile(openFileDialog.FileName);
65+
OpenFile(dialog.FileName);
6066
}
6167
}
6268

@@ -76,11 +82,37 @@ private void FileOpen_CanExecute(object sender, CanExecuteRoutedEventArgs e)
7682

7783
private void Export_Executed(object sender, ExecutedRoutedEventArgs e)
7884
{
79-
throw new NotImplementedException();
85+
var dialog = new FolderBrowserDialog
86+
{
87+
SelectedPath = _lastExportPath
88+
};
89+
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
90+
{
91+
_lastExportPath = dialog.SelectedPath;
92+
Directory.GetFiles(_lastExportPath, "tile_???.bmp").ToList().ForEach(File.Delete);
93+
var i = 1;
94+
foreach (var tile in GridViewer.SelectedTiles)
95+
{
96+
using (var output = _bitmap.CreateTile(tile.X, tile.Y))
97+
{
98+
try
99+
{
100+
var tilePath = $"{_lastExportPath.TrimEnd('/', '\\')}\\tile_{i.ToString("D3")}.bmp";
101+
output.Save(tilePath, ImageFormat.Bmp);
102+
}
103+
catch (Exception exception)
104+
{
105+
ShowError(exception);
106+
}
107+
i++;
108+
}
109+
}
110+
}
80111
}
81112

82113
private void OpenFile(string file)
83114
{
115+
_lastExportPath = new FileInfo(file).DirectoryName;
84116
var bitmap = CreateBitmap(file);
85117
if (bitmap != null)
86118
{

0 commit comments

Comments
 (0)