Overhaul asset browser.

This commit is contained in:
Paul Chote
2013-12-01 11:00:36 +13:00
parent 30f150fc91
commit 1e7f436448
10 changed files with 93 additions and 569 deletions

View File

@@ -33,9 +33,9 @@
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Optimize>False</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
@@ -47,17 +47,17 @@
</CustomCommands>
</CustomCommands>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Optimize>True</Optimize>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>bin\Release\</OutputPath>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="FuzzyLogicLibrary">
@@ -70,14 +70,13 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Mono.Nat">
<HintPath>..\thirdparty\Mono.Nat.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\thirdparty\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Activities\CaptureActor.cs" />
@@ -444,7 +443,6 @@
<Compile Include="Widgets\HueSliderWidget.cs" />
<Compile Include="Render\WithTurret.cs" />
<Compile Include="Widgets\Logic\AssetBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ConvertGameFilesLogic.cs" />
<Compile Include="VoxelNormalsPalette.cs" />
<Compile Include="Render\RenderVoxels.cs" />
<Compile Include="Render\WithVoxelTurret.cs" />
@@ -481,7 +479,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LuaInterface\LuaInterface.csproj">
<Project>{e915a0a4-2641-4f7e-8a88-8f123fa88bf1}</Project>
<Project>{E915A0A4-2641-4F7E-8A88-8F123FA88BF1}</Project>
<Name>LuaInterface</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
@@ -495,7 +493,7 @@
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\OpenRA.Irc\OpenRA.Irc.csproj">
<Project>{85b48234-8b31-4be6-af9c-665cc6866841}</Project>
<Project>{85B48234-8B31-4BE6-AF9C-665CC6866841}</Project>
<Name>OpenRA.Irc</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRA.Utility\OpenRA.Utility.csproj">

View File

@@ -35,6 +35,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
PaletteFromFile currentPalette;
static readonly string[] AllowedExtensions = { ".shp", ".r8", ".tem", ".des", ".sno", ".int" };
[ObjectCreator.UseCtor]
public AssetBrowserLogic(Widget widget, Action onExit, World world)
{
@@ -60,6 +62,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var paletteDropDown = panel.Get<DropDownButtonWidget>("PALETTE_SELECTOR");
paletteDropDown.OnMouseDown = _ => ShowPaletteDropdown(paletteDropDown, world);
paletteDropDown.GetText = () => currentPalette.Name;
var colorPreview = panel.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = Game.Settings.Player.Color;
@@ -80,7 +83,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
frameSlider.OnChange += x => { spriteWidget.Frame = (int)Math.Round(x); };
frameSlider.GetValue = () => spriteWidget.Frame;
panel.Get<LabelWidget>("FRAME_COUNT").GetText = () => "{0}/{1}".F(spriteWidget.Frame, spriteWidget.FrameCount);
panel.Get<LabelWidget>("FRAME_COUNT").GetText = () => "{0} / {1}".F(spriteWidget.Frame + 1, spriteWidget.FrameCount + 1);
playButton = panel.Get<ButtonWidget>("BUTTON_PLAY");
playButton.OnClick = () =>
@@ -118,96 +121,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template = panel.Get<ScrollItemWidget>("ASSET_TEMPLATE");
PopulateAssetList();
var modID = Game.modData.Manifest.Mod.Id;
// TODO: This should not invoke the OpenRA.Utility.exe, but use it's functions directly.
// TODO: Does not work with SHP(TS) yet?!
panel.Get<ButtonWidget>("EXPORT_BUTTON").OnClick = () =>
{
var ExtractGameFiles = new string[][]
{
new string[] { "--extract", modID, currentPalette.Filename, "--userdir" },
new string[] { "--extract", modID, "{0}.shp".F(spriteWidget.Image), "--userdir" },
};
var ExportToPng = new string[][]
{
new string[] { "--png", Platform.SupportDir + "{0}.shp".F(spriteWidget.Image), Platform.SupportDir + currentPalette.Filename },
};
var ImportFromPng = new string[][] { };
var args = new WidgetArgs()
{
{ "ExtractGameFiles", ExtractGameFiles },
{ "ExportToPng", ExportToPng },
{ "ImportFromPng", ImportFromPng }
};
Ui.OpenWindow("CONVERT_ASSETS_PANEL", args);
};
panel.Get<ButtonWidget>("EXTRACT_BUTTON").OnClick = () =>
{
var ExtractGameFilesList = new List<string[]>();
var ExportToPngList = new List<string[]>();
ExtractGameFilesList.Add(new string[] { "--extract", modID, currentPalette.Filename, "--userdir" });
foreach (var shp in availableShps)
{
ExtractGameFilesList.Add(new string[] { "--extract", modID, shp, "--userdir" });
ExportToPngList.Add(new string[] { "--png", Platform.SupportDir + shp, Platform.SupportDir + currentPalette.Filename });
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 },
{ "ImportFromPng", ImportFromPng }
};
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(); };
}
void AddAsset(ScrollPanelWidget list, string filepath, ScrollItemWidget template)
{
var r8 = filepath.EndsWith(".r8", true, CultureInfo.InvariantCulture);
var filename = Path.GetFileName(filepath);
var sprite = r8 ? filename : Path.GetFileNameWithoutExtension(filepath);
var filename = Path.GetFileName(filepath);
var item = ScrollItemWidget.Setup(template,
() => spriteWidget.Image == sprite,
() => {filenameInput.Text = filename; LoadAsset(filename); });
() => spriteWidget.Image == filename,
() => { filenameInput.Text = filename; LoadAsset(filename); });
item.Get<LabelWidget>("TITLE").GetText = () => filepath;
list.AddChild(item);
@@ -221,11 +143,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (!FileSystem.Exists(filename))
return false;
var r8 = filename.EndsWith(".r8", true, CultureInfo.InvariantCulture);
var sprite = r8 ? filename : Path.GetFileNameWithoutExtension(filename);
spriteWidget.Frame = 0;
spriteWidget.Image = sprite;
spriteWidget.Image = filename;
frameSlider.MaximumValue = (float)spriteWidget.FrameCount;
frameSlider.Ticks = spriteWidget.FrameCount + 1;
return true;
@@ -265,7 +184,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var files = assetSource.AllFileNames();
foreach (var file in files)
{
if (file.EndsWith(".shp", true, CultureInfo.InvariantCulture) || file.EndsWith(".r8", true, CultureInfo.InvariantCulture))
if (AllowedExtensions.Any(ext => file.EndsWith(ext, true, CultureInfo.InvariantCulture)))
{
AddAsset(assetList, file, template);
availableShps.Add(file);
@@ -278,8 +197,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Func<PaletteFromFile, ScrollItemWidget, ScrollItemWidget> setupItem = (palette, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => currentPalette.Name == palette.Name,
() => { currentPalette = palette; spriteWidget.Palette = currentPalette.Name; });
() => currentPalette.Name == palette.Name,
() => { currentPalette = palette; spriteWidget.Palette = currentPalette.Name; });
item.Get<LabelWidget>("LABEL").GetText = () => palette.Name;
return item;
};

View File

@@ -1,110 +0,0 @@
#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 OpenRA.Utility;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ConvertGameFilesLogic
{
Widget panel;
ProgressBarWidget progressBar;
LabelWidget statusLabel;
ButtonWidget retryButton, backButton;
Widget extractingContainer;
string[][] ExtractGameFiles, ExportToPng, ImportFromPng;
[ObjectCreator.UseCtor]
public ConvertGameFilesLogic(Widget widget, string[][] ExtractGameFiles, string[][] ExportToPng, string[][] ImportFromPng)
{
panel = widget.Get("CONVERT_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;
this.ExportToPng = ExportToPng;
this.ImportFromPng = ImportFromPng;
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...";
Command.ExtractFiles(ExtractGameFiles[i]);
}
for (int i = 0; i < ExportToPng.Length; i++)
{
progressBar.Percentage = i*100/ExportToPng.Count();
statusLabel.GetText = () => "Exporting SHP to PNG...";
Command.ConvertShpToPng(ExportToPng[i]);
}
for (int i = 0; i < ImportFromPng.Length; i++)
{
progressBar.Percentage = i*100/ImportFromPng.Count();
statusLabel.GetText = () => "Converting PNG to SHP...";
Command.ConvertPngToShp(ImportFromPng[i]);
}
Game.RunAfterTick(() =>
{
progressBar.Percentage = 100;
statusLabel.GetText = () => "Done. Check {0}".F(Platform.SupportDir);
backButton.IsDisabled = () => false;
});
}
catch (FileNotFoundException f)
{
onError(f.FileName+" not found.");
}
catch (Exception e)
{
onError(e.Message);
}
}) { IsBackground = true };
t.Start();
}
}
}