wire up the import from PNG to SHP button

store everything in user directory to not junk up the game
and for file permissions on Mac/Linux when installed
This commit is contained in:
Matthias Mailänder
2013-04-29 11:58:45 +02:00
parent 8f822f6cad
commit 6262aa846f
9 changed files with 101 additions and 51 deletions

View File

@@ -437,7 +437,7 @@
<Compile Include="Widgets\HueSliderWidget.cs" />
<Compile Include="Render\WithTurret.cs" />
<Compile Include="Widgets\Logic\AssetBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ExtractGameFilesLogic.cs" />
<Compile Include="Widgets\Logic\ConvertGameFilesLogic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -102,22 +102,25 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
var ExtractGameFiles = new string[][]
{
new string[] {"--extract", WidgetUtils.ActiveModId(), palette},
new string[] {"--extract", WidgetUtils.ActiveModId(), "{0}.shp".F(spriteImage.Image)},
new string[] {"--extract", WidgetUtils.ActiveModId(), palette, "--userdir"},
new string[] {"--extract", WidgetUtils.ActiveModId(), "{0}.shp".F(spriteImage.Image), "--userdir"},
};
var ExportToPng = new string[][]
{
new string[] {"--png", "{0}.shp".F(spriteImage.Image), palette},
new string[] {"--png", Platform.SupportDir+"{0}.shp".F(spriteImage.Image), Platform.SupportDir+palette},
};
var ImportFromPng = new string[][] { };
var args = new WidgetArgs()
{
{ "ExtractGameFiles", ExtractGameFiles },
{ "ExportToPng", ExportToPng }
{ "ExportToPng", ExportToPng },
{ "ImportFromPng", ImportFromPng}
};
Ui.OpenWindow("EXTRACT_ASSETS_PANEL", args);
Ui.OpenWindow("CONVERT_ASSETS_PANEL", args);
};
panel.Get<ButtonWidget>("EXTRACT_BUTTON").OnClick = () =>
@@ -125,24 +128,50 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var ExtractGameFilesList = new List<string[]>();
var ExportToPngList = new List<string[]>();
ExtractGameFilesList.Add(new string[] { "--extract", WidgetUtils.ActiveModId(), palette} );
ExtractGameFilesList.Add(new string[] { "--extract", WidgetUtils.ActiveModId(), palette, "--userdir"} );
foreach (var shp in AvailableShps)
{
ExtractGameFilesList.Add(new string[] { "--extract", WidgetUtils.ActiveModId(), shp } );
ExportToPngList.Add(new string[] { "--png", shp, palette } );
ExtractGameFilesList.Add(new string[] { "--extract", WidgetUtils.ActiveModId(), shp, "--userdir" } );
ExportToPngList.Add(new string[] { "--png", Platform.SupportDir+shp, Platform.SupportDir+palette } );
Console.WriteLine(Platform.SupportDir+shp);
}
var ExtractGameFiles = ExtractGameFilesList.ToArray();
var ExportToPng = ExportToPngList.ToArray();
var ImportFromPng = new string[][] { };
var args = new WidgetArgs()
{
{ "ExtractGameFiles", ExtractGameFiles },
{ "ExportToPng", ExportToPng }
{ "ExportToPng", ExportToPng },
{ "ImportFromPng", ImportFromPng}
};
Ui.OpenWindow("EXTRACT_ASSETS_PANEL", args);
Ui.OpenWindow("CONVERT_ASSETS_PANEL", args);
};
panel.Get<ButtonWidget>("IMPORT_BUTTON").OnClick = () =>
{
var imageSizeInput = panel.Get<TextFieldWidget>("IMAGE_SIZE_INPUT");
var imageFilename = panel.Get<TextFieldWidget>("IMAGE_FILENAME_INPUT");
var ExtractGameFiles = new string[][] { };
var ExportToPng = new string[][] { };
var ImportFromPng = new string[][]
{
new string[] {"--shp", Platform.SupportDir+imageFilename.Text, imageSizeInput.Text},
};
var args = new WidgetArgs()
{
{ "ExtractGameFiles", ExtractGameFiles },
{ "ExportToPng", ExportToPng },
{ "ImportFromPng", ImportFromPng}
};
Ui.OpenWindow("CONVERT_ASSETS_PANEL", args);
};
panel.Get<ButtonWidget>("CLOSE_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
@@ -210,7 +239,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
foreach (var shp in shps)
{
AddAsset(assetList, shp, template);
AvailableShps.Add(shp);
AvailableShps.Add(Path.GetFileName(shp));
}
}
}

View File

@@ -20,7 +20,7 @@ using OpenRA.Utility;
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ExtractGameFilesLogic
public class ConvertGameFilesLogic
{
Widget panel;
ProgressBarWidget progressBar;
@@ -28,12 +28,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ButtonWidget retryButton, backButton;
Widget extractingContainer;
string[][] ExtractGameFiles, ExportToPng;
string[][] ExtractGameFiles, ExportToPng, ImportFromPng;
[ObjectCreator.UseCtor]
public ExtractGameFilesLogic(Widget widget, string[][] ExtractGameFiles, string[][] ExportToPng)
public ConvertGameFilesLogic(Widget widget, string[][] ExtractGameFiles, string[][] ExportToPng, string[][] ImportFromPng)
{
panel = widget.Get("EXTRACT_ASSETS_PANEL");
panel = widget.Get("CONVERT_ASSETS_PANEL");
progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
statusLabel = panel.Get<LabelWidget>("STATUS_LABEL");
@@ -47,6 +47,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
this.ExtractGameFiles = ExtractGameFiles;
this.ExportToPng = ExportToPng;
this.ImportFromPng = ImportFromPng;
Extract();
}
@@ -78,21 +79,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic
for (int i = 0; i < ExportToPng.Length; i++)
{
progressBar.Percentage = i*100/ExportToPng.Count();
statusLabel.GetText = () => "Converting...";
statusLabel.GetText = () => "Exporting SHP to PNG...";
Utility.Command.ConvertShpToPng(ExportToPng[i]);
}
for (int i = 0; i < ImportFromPng.Length; i++)
{
progressBar.Percentage = i*100/ImportFromPng.Count();
statusLabel.GetText = () => "Converting PNG to SHP...";
Utility.Command.ConvertPngToShp(ImportFromPng[i]);
}
Game.RunAfterTick(() =>
{
progressBar.Percentage = 100;
statusLabel.GetText = () => "Extraction and conversion complete.";
statusLabel.GetText = () => "Done. Check {0}".F(Platform.SupportDir);
backButton.IsDisabled = () => false;
});
}
catch
catch (FileNotFoundException f)
{
onError("Extraction or conversion failed");
onError(f.FileName+" not found.");
}
catch (Exception e)
{
onError(e.Message);
}
}) { IsBackground = true };
t.Start();
}