Display an error label instead of crashing in the Asset Browser
This commit is contained in:
@@ -47,6 +47,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
bool isVideoLoaded = false;
|
bool isVideoLoaded = false;
|
||||||
int currentFrame;
|
int currentFrame;
|
||||||
|
|
||||||
|
LabelWidget errorLabelWidget;
|
||||||
|
SpriteFont errorFont;
|
||||||
|
bool IsErrorLabelVisible { get { return errorLabelWidget != null && errorLabelWidget.Visible; } }
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
|
public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||||
{
|
{
|
||||||
@@ -84,12 +88,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
spriteWidget.GetSprite = () => currentSprites != null ? currentSprites[currentFrame] : null;
|
spriteWidget.GetSprite = () => currentSprites != null ? currentSprites[currentFrame] : null;
|
||||||
currentPalette = spriteWidget.Palette;
|
currentPalette = spriteWidget.Palette;
|
||||||
spriteWidget.GetPalette = () => currentPalette;
|
spriteWidget.GetPalette = () => currentPalette;
|
||||||
spriteWidget.IsVisible = () => !isVideoLoaded;
|
spriteWidget.IsVisible = () => !isVideoLoaded && !IsErrorLabelVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerWidget = panel.GetOrNull<VqaPlayerWidget>("PLAYER");
|
var playerWidget = panel.GetOrNull<VqaPlayerWidget>("PLAYER");
|
||||||
if (playerWidget != null)
|
if (playerWidget != null)
|
||||||
playerWidget.IsVisible = () => isVideoLoaded;
|
playerWidget.IsVisible = () => isVideoLoaded && !IsErrorLabelVisible;
|
||||||
|
|
||||||
|
errorLabelWidget = panel.GetOrNull<LabelWidget>("ERROR");
|
||||||
|
if (errorLabelWidget != null)
|
||||||
|
errorFont = Game.Renderer.Fonts[errorLabelWidget.Font];
|
||||||
|
|
||||||
var paletteDropDown = panel.GetOrNull<DropDownButtonWidget>("PALETTE_SELECTOR");
|
var paletteDropDown = panel.GetOrNull<DropDownButtonWidget>("PALETTE_SELECTOR");
|
||||||
if (paletteDropDown != null)
|
if (paletteDropDown != null)
|
||||||
@@ -314,25 +322,44 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (!modData.DefaultFileSystem.Exists(filename))
|
if (!modData.DefaultFileSystem.Exists(filename))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Path.GetExtension(filename.ToLowerInvariant()) == ".vqa")
|
errorLabelWidget.Visible = false;
|
||||||
{
|
|
||||||
player = panel.Get<VqaPlayerWidget>("PLAYER");
|
try
|
||||||
currentFilename = filename;
|
|
||||||
player.Load(filename);
|
|
||||||
player.DrawOverlay = false;
|
|
||||||
isVideoLoaded = true;
|
|
||||||
frameSlider.MaximumValue = (float)player.Video.Frames - 1;
|
|
||||||
frameSlider.Ticks = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
if (Path.GetExtension(filename.ToLowerInvariant()) == ".vqa")
|
||||||
|
{
|
||||||
|
player = panel.Get<VqaPlayerWidget>("PLAYER");
|
||||||
|
currentFilename = filename;
|
||||||
|
player.Load(filename);
|
||||||
|
player.DrawOverlay = false;
|
||||||
|
isVideoLoaded = true;
|
||||||
|
frameSlider.MaximumValue = (float)player.Video.Frames - 1;
|
||||||
|
frameSlider.Ticks = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
currentFilename = filename;
|
currentFilename = filename;
|
||||||
currentSprites = world.Map.Rules.Sequences.SpriteCache[filename];
|
currentSprites = world.Map.Rules.Sequences.SpriteCache[filename];
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
frameSlider.MaximumValue = (float)currentSprites.Length - 1;
|
frameSlider.MaximumValue = (float)currentSprites.Length - 1;
|
||||||
frameSlider.Ticks = currentSprites.Length;
|
frameSlider.Ticks = currentSprites.Length;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (errorLabelWidget != null)
|
||||||
|
{
|
||||||
|
errorLabelWidget.Text = WidgetUtils.TruncateText(errorLabelWidget.Text.Replace("{filename}", filename),
|
||||||
|
errorLabelWidget.Bounds.Width, errorFont);
|
||||||
|
|
||||||
|
currentSprites = new Sprite[0];
|
||||||
|
errorLabelWidget.Visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.AddChannel("assetbrowser", "assetbrowser.log");
|
||||||
|
Log.Write("assetbrowser", "Error reading {0}:{3} {1}{3}{2}", filename, ex.Message, ex.StackTrace, Environment.NewLine);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,13 @@ Container@ASSETBROWSER_PANEL:
|
|||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
AspectRatio: 1
|
AspectRatio: 1
|
||||||
|
Label@ERROR:
|
||||||
|
X: 5
|
||||||
|
Width: 490 - 10
|
||||||
|
Height: 325
|
||||||
|
Align: Center
|
||||||
|
Visible: false
|
||||||
|
Text: Error displaying {filename} check assetbrowser.log
|
||||||
Container@FRAME_SELECTOR:
|
Container@FRAME_SELECTOR:
|
||||||
X: 190
|
X: 190
|
||||||
Y: 395
|
Y: 395
|
||||||
|
|||||||
@@ -100,6 +100,13 @@ Background@ASSETBROWSER_PANEL:
|
|||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
AspectRatio: 1
|
AspectRatio: 1
|
||||||
|
Label@ERROR:
|
||||||
|
X: 5
|
||||||
|
Width: 490 - 10
|
||||||
|
Height: 330
|
||||||
|
Align: Center
|
||||||
|
Visible: false
|
||||||
|
Text: Error displaying {filename} check assetbrowser.log
|
||||||
Container@FRAME_SELECTOR:
|
Container@FRAME_SELECTOR:
|
||||||
X: 190
|
X: 190
|
||||||
Y: 425
|
Y: 425
|
||||||
|
|||||||
Reference in New Issue
Block a user