added button to extract the selected SHP and convert it to PNG

This commit is contained in:
Matthias Mailänder
2013-04-28 19:42:01 +02:00
parent 6a6776754b
commit 7f40f59d85
8 changed files with 189 additions and 3 deletions

View File

@@ -227,6 +227,12 @@ namespace OpenRA.Widgets
return Mod.AllMods[mod].Title; return Mod.AllMods[mod].Title;
} }
public static string ActiveModId()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Id;
}
public static string ChooseInitialMap(string map) public static string ChooseInitialMap(string map)
{ {
var availableMaps = Game.modData.AvailableMaps; var availableMaps = Game.modData.AvailableMaps;

View File

@@ -437,6 +437,7 @@
<Compile Include="Widgets\HueSliderWidget.cs" /> <Compile Include="Widgets\HueSliderWidget.cs" />
<Compile Include="Render\WithTurret.cs" /> <Compile Include="Render\WithTurret.cs" />
<Compile Include="Widgets\Logic\AssetBrowserLogic.cs" /> <Compile Include="Widgets\Logic\AssetBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ExtractGameFilesLogic.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
@@ -449,6 +450,10 @@
<Name>OpenRA.Game</Name> <Name>OpenRA.Game</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\OpenRA.Utility\OpenRA.Utility.csproj">
<Project>{F33337BE-CB69-4B24-850F-07D23E408DDF}</Project>
<Name>OpenRA.Utility</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <BootstrapperPackage Include="Microsoft.Net.Client.3.5">

View File

@@ -95,6 +95,30 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template = panel.Get<ScrollItemWidget>("ASSET_TEMPLATE"); template = panel.Get<ScrollItemWidget>("ASSET_TEMPLATE");
PopulateAssetList(); PopulateAssetList();
panel.Get<ButtonWidget>("EXPORT_BUTTON").OnClick = () =>
{
var palette = (WidgetUtils.ActiveModId() == "d2k") ? "d2k.pal" : "egopal.pal";
var ExtractGameFiles = new string[][]
{
new string[] {"--extract", WidgetUtils.ActiveModId(), palette},
new string[] {"--extract", WidgetUtils.ActiveModId(), "{0}.shp".F(spriteImage.Image)},
};
var ExportToPng = new string[][]
{
new string[] {"--png", "{0}.shp".F(spriteImage.Image), palette},
};
var args = new WidgetArgs()
{
{ "ExtractGameFiles", ExtractGameFiles },
{ "ExportToPng", ExportToPng }
};
Ui.OpenWindow("EXTRACT_ASSETS_PANEL", args);
};
panel.Get<ButtonWidget>("CLOSE_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; panel.Get<ButtonWidget>("CLOSE_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
} }

View File

@@ -0,0 +1,103 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Diagnostics;
using OpenRA.FileFormats;
using OpenRA.FileFormats.Graphics;
using OpenRA.Widgets;
using OpenRA.Utility;
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ExtractGameFilesLogic
{
Widget panel;
ProgressBarWidget progressBar;
LabelWidget statusLabel;
ButtonWidget retryButton, backButton;
Widget extractingContainer;
string[][] ExtractGameFiles, ExportToPng;
[ObjectCreator.UseCtor]
public ExtractGameFilesLogic(Widget widget, string[][] ExtractGameFiles, string[][] ExportToPng)
{
panel = widget.Get("EXTRACT_ASSETS_PANEL");
progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
statusLabel = panel.Get<LabelWidget>("STATUS_LABEL");
backButton = panel.Get<ButtonWidget>("BACK_BUTTON");
backButton.OnClick = Ui.CloseWindow;
retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");
retryButton.OnClick = Extract;
extractingContainer = panel.Get("EXTRACTING");
this.ExtractGameFiles = ExtractGameFiles;
foreach (var s in ExtractGameFiles)
foreach (var ss in s)
Console.WriteLine(ss);
this.ExportToPng = ExportToPng;
Extract();
}
void Extract()
{
backButton.IsDisabled = () => true;
retryButton.IsDisabled = () => true;
extractingContainer.IsVisible = () => true;
var onError = (Action<string>)(s => Game.RunAfterTick(() =>
{
statusLabel.GetText = () => "Error: "+s;
backButton.IsDisabled = () => false;
retryButton.IsDisabled = () => false;
}));
var t = new Thread( _ =>
{
try
{
for (int i = 0; i < ExtractGameFiles.Length; i++)
{
progressBar.Percentage = i*100/ExtractGameFiles.Count();
statusLabel.GetText = () => "Extracting...";
Utility.Command.ExtractFiles(ExtractGameFiles[i]);
}
for (int i = 0; i < ExportToPng.Length; i++)
{
progressBar.Percentage = i*100/ExportToPng.Count();
statusLabel.GetText = () => "Converting...";
Utility.Command.ConvertShpToPng(ExportToPng[i]);
}
Game.RunAfterTick(() =>
{
progressBar.Percentage = 100;
statusLabel.GetText = () => "Extraction and conversion complete.";
backButton.IsDisabled = () => false;
});
}
catch
{
onError("Extraction or conversion failed");
}
}) { IsBackground = true };
t.Start();
}
}
}

View File

@@ -69,6 +69,7 @@ ChromeLayout:
mods/ra/chrome/musicplayer.yaml mods/ra/chrome/musicplayer.yaml
mods/d2k/chrome/tooltips.yaml mods/d2k/chrome/tooltips.yaml
mods/ra/chrome/assetbrowser.yaml mods/ra/chrome/assetbrowser.yaml
mods/ra/chrome/extractassets.yaml
Weapons: Weapons:
mods/d2k/weapons/defaults.yaml mods/d2k/weapons/defaults.yaml

View File

@@ -97,7 +97,7 @@ Background@ASSETBROWSER_BG:
Y:PARENT_BOTTOM - 235 Y:PARENT_BOTTOM - 235
Width:160 Width:160
Height:25 Height:25
Text:Extract to Folder Text:Extract all to PNG
Font:Bold Font:Bold
Disabled: yes Disabled: yes
Button@EXPORT_BUTTON: Button@EXPORT_BUTTON:
@@ -105,9 +105,8 @@ Background@ASSETBROWSER_BG:
Y:PARENT_BOTTOM - 200 Y:PARENT_BOTTOM - 200
Width:160 Width:160
Height:25 Height:25
Text:Export as PNG Text:Selected to PNG
Font:Bold Font:Bold
Disabled: yes
Button@CLOSE_BUTTON: Button@CLOSE_BUTTON:
X:PARENT_RIGHT - 200 X:PARENT_RIGHT - 200
Y:PARENT_BOTTOM - 115 Y:PARENT_BOTTOM - 115

View File

@@ -0,0 +1,47 @@
Background@EXTRACT_ASSETS_PANEL:
Logic:ExtractGameFilesLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:500
Height:160
Children:
Label@TITLE:
X:0
Y:20
Width:PARENT_RIGHT
Height:25
Text:Extracting and Converting Gamefiles
Align:Center
Font:Bold
Container@EXTRACTING:
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Visible: false
Children:
ProgressBar@PROGRESS_BAR:
X:50
Y:55
Width:PARENT_RIGHT - 100
Height:25
Label@STATUS_LABEL:
X:50
Y:80
Width:PARENT_RIGHT - 100
Height:25
Align:Left
Button@RETRY_BUTTON:
X:PARENT_RIGHT - 280
Y:PARENT_BOTTOM - 45
Width:120
Height:25
Text:Retry
Font:Bold
Key:return
Button@BACK_BUTTON:
X:PARENT_RIGHT - 140
Y:PARENT_BOTTOM - 45
Width:120
Height:25
Text:Back
Font:Bold
Key:escape

View File

@@ -78,6 +78,7 @@ ChromeLayout:
mods/ra/chrome/musicplayer.yaml mods/ra/chrome/musicplayer.yaml
mods/ra/chrome/tooltips.yaml mods/ra/chrome/tooltips.yaml
mods/ra/chrome/assetbrowser.yaml mods/ra/chrome/assetbrowser.yaml
mods/ra/chrome/extractassets.yaml
Weapons: Weapons:
mods/ra/weapons.yaml mods/ra/weapons.yaml