Remove the hardcoded mess of RadarBinWidget.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Mods.RA.Widgets;
|
||||
@@ -100,9 +102,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
|
||||
playerWidgets.Get<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
|
||||
|
||||
var winLossWatcher = playerWidgets.Get<LogicTickerWidget>("WIN_LOSS_WATCHER");
|
||||
winLossWatcher.OnTick = () =>
|
||||
bool radarEnabled = false;
|
||||
sidebarRoot.Get<RadarWidget>("RADAR_MINIMAP").IsEnabled = () => radarEnabled;
|
||||
|
||||
var sidebarTicker = playerWidgets.Get<LogicTickerWidget>("SIDEBAR_TICKER");
|
||||
sidebarTicker.OnTick = () =>
|
||||
{
|
||||
// Update radar bin
|
||||
radarEnabled = world.ActorsWithTrait<ProvidesRadar>()
|
||||
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
|
||||
|
||||
// Switch to observer mode after win/loss
|
||||
if (world.LocalPlayer.WinState != WinState.Undefined)
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
|
||||
@@ -409,7 +409,6 @@
|
||||
<Compile Include="Widgets\ObserverSupportPowerIconsWidget.cs" />
|
||||
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
||||
<Compile Include="Widgets\PowerBinWidget.cs" />
|
||||
<Compile Include="Widgets\RadarBinWidget.cs" />
|
||||
<Compile Include="Widgets\RadarWidget.cs" />
|
||||
<Compile Include="Widgets\StrategicProgressWidget.cs" />
|
||||
<Compile Include="Widgets\SupportPowerBinWidget.cs" />
|
||||
@@ -456,6 +455,7 @@
|
||||
<Compile Include="Widgets\Logic\CreditsLogic.cs" />
|
||||
<Compile Include="Render\WithResources.cs" />
|
||||
<Compile Include="Render\WithHarvestAnimation.cs" />
|
||||
<Compile Include="Widgets\SlidingContainerWidget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
observerWidgets.Get<ButtonWidget>("INGAME_STATS_BUTTON").OnClick = () => gameRoot.Get("OBSERVER_STATS").Visible ^= true;
|
||||
}
|
||||
|
||||
enum RadarBinState { Closed, BinAnimating, RadarAnimating, Open };
|
||||
void InitPlayerWidgets()
|
||||
{
|
||||
var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs());
|
||||
@@ -104,9 +105,28 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
moneyBin.Get<OrderButtonWidget>("POWER_DOWN").GetKey = _ => Game.Settings.Keys.PowerDownKey;
|
||||
moneyBin.Get<OrderButtonWidget>("REPAIR").GetKey = _ => Game.Settings.Keys.RepairKey;
|
||||
|
||||
var winLossWatcher = playerWidgets.Get<LogicTickerWidget>("WIN_LOSS_WATCHER");
|
||||
winLossWatcher.OnTick = () =>
|
||||
bool radarActive = false;
|
||||
RadarBinState binState = RadarBinState.Closed;
|
||||
var radarBin = playerWidgets.Get<SlidingContainerWidget>("INGAME_RADAR_BIN");
|
||||
radarBin.IsOpen = () => radarActive || binState > RadarBinState.BinAnimating;
|
||||
radarBin.AfterOpen = () => binState = RadarBinState.RadarAnimating;
|
||||
radarBin.AfterClose = () => binState = RadarBinState.Closed;
|
||||
|
||||
var radarMap = radarBin.Get<RadarWidget>("RADAR_MINIMAP");
|
||||
radarMap.IsEnabled = () => radarActive && binState >= RadarBinState.RadarAnimating;
|
||||
radarMap.AfterOpen = () => binState = RadarBinState.Open;
|
||||
radarMap.AfterClose = () => binState = RadarBinState.BinAnimating;
|
||||
|
||||
radarBin.Get<ImageWidget>("RADAR_BIN_BG").GetImageCollection = () => "chrome-"+world.LocalPlayer.Country.Race;
|
||||
|
||||
var sidebarTicker = playerWidgets.Get<LogicTickerWidget>("SIDEBAR_TICKER");
|
||||
sidebarTicker.OnTick = () =>
|
||||
{
|
||||
// Update radar bin
|
||||
radarActive = world.ActorsWithTrait<ProvidesRadar>()
|
||||
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
|
||||
|
||||
// Switch to observer mode after win/loss
|
||||
if (world.LocalPlayer.WinState != WinState.Undefined)
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
if( world.LocalPlayer == null ) return;
|
||||
if( world.LocalPlayer.WinState != WinState.Undefined ) return;
|
||||
|
||||
var radarBin = Ui.Root.Get<RadarBinWidget>(RadarBin);
|
||||
var radarBin = Ui.Root.Get<SlidingContainerWidget>(RadarBin);
|
||||
|
||||
powerCollection = "power-" + world.LocalPlayer.Country.Race;
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
return;
|
||||
|
||||
// Draw bar horizontally
|
||||
var barStart = powerOrigin + radarBin.RadarOrigin;
|
||||
var barStart = powerOrigin + radarBin.ChildOrigin;
|
||||
var barEnd = barStart + new float2(powerSize.Width, 0);
|
||||
|
||||
float powerScaleBy = 100;
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class RadarBinWidget : Widget
|
||||
{
|
||||
public string WorldInteractionController = null;
|
||||
|
||||
static float2 radarOpenOrigin = new float2(Game.viewport.Width - 215, 29);
|
||||
static float2 radarClosedOrigin = new float2(Game.viewport.Width - 215, -166);
|
||||
float2 radarOrigin = radarClosedOrigin;
|
||||
float radarMinimapHeight;
|
||||
const int radarSlideAnimationLength = 15;
|
||||
const int radarActivateAnimationLength = 5;
|
||||
int radarAnimationFrame = 0;
|
||||
bool radarAnimating = false;
|
||||
bool hasRadar = false;
|
||||
string radarCollection;
|
||||
|
||||
float previewScale = 0;
|
||||
RectangleF mapRect = Rectangle.Empty;
|
||||
int2 previewOrigin;
|
||||
|
||||
Sprite terrainSprite;
|
||||
Sprite customTerrainSprite;
|
||||
Sprite actorSprite;
|
||||
Sprite shroudSprite;
|
||||
|
||||
/* hack to expose this to other broken widgets which rely on it */
|
||||
public float2 RadarOrigin { get { return radarOrigin; } }
|
||||
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public RadarBinWidget(World world)
|
||||
{
|
||||
this.world = world;
|
||||
var size = Math.Max(world.Map.Bounds.Width, world.Map.Bounds.Height);
|
||||
previewScale = Math.Min(192f / world.Map.Bounds.Width, 192f / world.Map.Bounds.Height);
|
||||
previewOrigin = new int2(9 + (int)(radarOpenOrigin.X + previewScale * (size - world.Map.Bounds.Width)/2), (int)(radarOpenOrigin.Y + previewScale * (size - world.Map.Bounds.Height)/2));
|
||||
mapRect = new RectangleF(previewOrigin.X, previewOrigin.Y, (int)(world.Map.Bounds.Width * previewScale), (int)(world.Map.Bounds.Height * previewScale));
|
||||
|
||||
// Only needs to be done once
|
||||
var terrainBitmap = Minimap.TerrainBitmap(world.Map);
|
||||
var r = new Rectangle( 0, 0, world.Map.Bounds.Width, world.Map.Bounds.Height );
|
||||
var s = new Size( terrainBitmap.Width, terrainBitmap.Height );
|
||||
terrainSprite = new Sprite(new Sheet(s), r, TextureChannel.Alpha);
|
||||
terrainSprite.sheet.Texture.SetData(terrainBitmap);
|
||||
|
||||
// Data is set in Tick()
|
||||
customTerrainSprite = new Sprite(new Sheet(s), r, TextureChannel.Alpha);
|
||||
actorSprite = new Sprite(new Sheet(s), r, TextureChannel.Alpha);
|
||||
shroudSprite = new Sprite(new Sheet(s), r, TextureChannel.Alpha);
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos)
|
||||
{
|
||||
if (world == null || !hasRadar)
|
||||
return null;
|
||||
|
||||
var loc = MinimapPixelToCell(pos);
|
||||
|
||||
var mi = new MouseInput
|
||||
{
|
||||
Location = loc.ToInt2(),
|
||||
Button = MouseButton.Right,
|
||||
Modifiers = Game.GetModifierKeys()
|
||||
};
|
||||
|
||||
var cursor = world.OrderGenerator.GetCursor( world, loc, mi );
|
||||
if (cursor == null)
|
||||
return "default";
|
||||
|
||||
return CursorProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor;
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
||||
|
||||
if (!mapRect.Contains(mi.Location))
|
||||
return false;
|
||||
|
||||
var loc = MinimapPixelToCell(mi.Location);
|
||||
if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left)
|
||||
Game.viewport.Center(loc.ToFloat2());
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right)
|
||||
{
|
||||
// fake a mousedown/mouseup here
|
||||
var fakemi = new MouseInput
|
||||
{
|
||||
Event = MouseInputEvent.Down,
|
||||
Button = MouseButton.Right,
|
||||
Modifiers = mi.Modifiers,
|
||||
Location = (((loc.ToPPos().ToFloat2()) - Game.viewport.Location) * Game.viewport.Zoom).ToInt2()
|
||||
};
|
||||
|
||||
if (WorldInteractionController != null)
|
||||
{
|
||||
var controller = Ui.Root.Get<WorldInteractionControllerWidget>(WorldInteractionController);
|
||||
controller.HandleMouseInput(fakemi);
|
||||
fakemi.Event = MouseInputEvent.Up;
|
||||
controller.HandleMouseInput(fakemi);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override Rectangle EventBounds
|
||||
{
|
||||
get { return new Rectangle((int)mapRect.X, (int)mapRect.Y, (int)mapRect.Width, (int)mapRect.Height);}
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if( world == null || world.LocalPlayer == null ) return;
|
||||
if( world.LocalPlayer.WinState != WinState.Undefined ) return;
|
||||
|
||||
radarCollection = "radar-" + world.LocalPlayer.Country.Race;
|
||||
var rsr = Game.Renderer.RgbaSpriteRenderer;
|
||||
rsr.DrawSprite(ChromeProvider.GetImage(radarCollection, "left"), radarOrigin);
|
||||
rsr.DrawSprite(ChromeProvider.GetImage(radarCollection, "right"), radarOrigin + new float2(201, 0));
|
||||
rsr.DrawSprite(ChromeProvider.GetImage(radarCollection, "bottom"), radarOrigin + new float2(0, 192));
|
||||
rsr.DrawSprite(ChromeProvider.GetImage(radarCollection, "bg"), radarOrigin + new float2(9, 0));
|
||||
|
||||
// Don't draw the radar if the tray is moving
|
||||
if (radarAnimationFrame >= radarSlideAnimationLength)
|
||||
{
|
||||
var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight)/2);
|
||||
var s = new float2(mapRect.Size.Width, mapRect.Size.Height*radarMinimapHeight);
|
||||
rsr.DrawSprite(terrainSprite, o, s);
|
||||
rsr.DrawSprite(customTerrainSprite, o, s);
|
||||
rsr.DrawSprite(actorSprite, o, s);
|
||||
rsr.DrawSprite(shroudSprite, o, s);
|
||||
|
||||
// Draw viewport rect
|
||||
if (radarAnimationFrame == radarSlideAnimationLength + radarActivateAnimationLength)
|
||||
{
|
||||
var wr = Game.viewport.WorldRect;
|
||||
var wro = new CPos(wr.X, wr.Y);
|
||||
var tl = CellToMinimapPixel(wro);
|
||||
var br = CellToMinimapPixel(wro + new CVec(wr.Width, wr.Height));
|
||||
|
||||
Game.Renderer.EnableScissor((int)mapRect.Left, (int)mapRect.Top, (int)mapRect.Width, (int)mapRect.Height);
|
||||
Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White);
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int updateTicks = 0;
|
||||
public override void Tick()
|
||||
{
|
||||
var hasRadarNew = world
|
||||
.ActorsWithTrait<ProvidesRadar>()
|
||||
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
|
||||
|
||||
if (hasRadarNew != hasRadar)
|
||||
{
|
||||
radarAnimating = true;
|
||||
Sound.PlayNotification(null, "Sounds", (hasRadarNew ? "RadarUp" : "RadarDown"), null);
|
||||
}
|
||||
|
||||
hasRadar = hasRadarNew;
|
||||
|
||||
// Build the radar image
|
||||
if (hasRadar)
|
||||
{
|
||||
--updateTicks;
|
||||
if (updateTicks <= 0)
|
||||
{
|
||||
updateTicks = 12;
|
||||
customTerrainSprite.sheet.Texture.SetData(Minimap.CustomTerrainBitmap(world));
|
||||
}
|
||||
|
||||
if (updateTicks == 8)
|
||||
actorSprite.sheet.Texture.SetData(Minimap.ActorsBitmap(world));
|
||||
|
||||
if (updateTicks == 4)
|
||||
shroudSprite.sheet.Texture.SetData(Minimap.ShroudBitmap(world));
|
||||
}
|
||||
|
||||
if (!radarAnimating)
|
||||
return;
|
||||
|
||||
// Increment frame
|
||||
if (hasRadar)
|
||||
radarAnimationFrame++;
|
||||
else
|
||||
radarAnimationFrame--;
|
||||
|
||||
// Calculate radar bin position
|
||||
if (radarAnimationFrame <= radarSlideAnimationLength)
|
||||
radarOrigin = float2.Lerp(radarClosedOrigin, radarOpenOrigin, radarAnimationFrame * 1.0f / radarSlideAnimationLength);
|
||||
|
||||
// Minimap height
|
||||
if (radarAnimationFrame >= radarSlideAnimationLength)
|
||||
radarMinimapHeight = float2.Lerp(0, 1, (radarAnimationFrame - radarSlideAnimationLength) * 1.0f / radarActivateAnimationLength);
|
||||
|
||||
// Animation is complete
|
||||
if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength + radarActivateAnimationLength : 0))
|
||||
radarAnimating = false;
|
||||
}
|
||||
|
||||
int2 CellToMinimapPixel(CPos p)
|
||||
{
|
||||
return new int2((int)(mapRect.X +previewScale*(p.X - world.Map.Bounds.Left)), (int)(mapRect.Y + previewScale*(p.Y - world.Map.Bounds.Top)));
|
||||
}
|
||||
|
||||
CPos MinimapPixelToCell(int2 p)
|
||||
{
|
||||
return new CPos(world.Map.Bounds.Left + (int)((p.X - mapRect.X) / previewScale), world.Map.Bounds.Top + (int)((p.Y - mapRect.Y) / previewScale));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,18 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
public int AnimationLength = 5;
|
||||
public string RadarOnlineSound = null;
|
||||
public string RadarOfflineSound = null;
|
||||
public Func<bool> IsEnabled = () => false;
|
||||
public Action AfterOpen = () => {};
|
||||
public Action AfterClose = () => {};
|
||||
|
||||
float radarMinimapHeight;
|
||||
int AnimationFrame = 0;
|
||||
int frame = 0;
|
||||
bool hasRadar = false;
|
||||
bool animating = false;
|
||||
int updateTicks = 0;
|
||||
|
||||
float previewScale = 0;
|
||||
int2 previewOrigin = int2.Zero;
|
||||
Rectangle mapRect = Rectangle.Empty;
|
||||
int2 previewOrigin;
|
||||
|
||||
Sprite terrainSprite;
|
||||
Sprite customTerrainSprite;
|
||||
@@ -53,7 +55,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
var rb = RenderBounds;
|
||||
|
||||
previewScale = Math.Min(rb.Width * 1f / width, rb.Height * 1f / height);
|
||||
previewOrigin = RenderOrigin + new int2((int)(previewScale*(size - width)/2), (int)(previewScale*(size - height)/2));
|
||||
previewOrigin = new int2((int)(previewScale*(size - width)/2), (int)(previewScale*(size - height)/2));
|
||||
mapRect = new Rectangle(previewOrigin.X, previewOrigin.Y, (int)(previewScale*width), (int)(previewScale*height));
|
||||
|
||||
// Only needs to be done once
|
||||
@@ -92,7 +94,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (!hasRadar || animating)
|
||||
if (!hasRadar)
|
||||
return true;
|
||||
|
||||
if (!mapRect.Contains(mi.Location))
|
||||
@@ -134,6 +136,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight)/2);
|
||||
var s = new float2(mapRect.Size.Width, mapRect.Size.Height*radarMinimapHeight);
|
||||
|
||||
var rsr = Game.Renderer.RgbaSpriteRenderer;
|
||||
rsr.DrawSprite(terrainSprite, o, s);
|
||||
rsr.DrawSprite(customTerrainSprite, o, s);
|
||||
@@ -141,7 +144,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
rsr.DrawSprite(shroudSprite, o, s);
|
||||
|
||||
// Draw viewport rect
|
||||
if (hasRadar && !animating)
|
||||
if (hasRadar)
|
||||
{
|
||||
var wr = Game.viewport.WorldRect;
|
||||
var wro = new CPos(wr.X, wr.Y);
|
||||
@@ -154,50 +157,51 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
}
|
||||
}
|
||||
|
||||
bool cachedEnabled;
|
||||
public override void Tick()
|
||||
{
|
||||
var hasRadarNew = world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined ||
|
||||
world.ActorsWithTrait<ProvidesRadar>().Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
|
||||
|
||||
if (hasRadarNew != hasRadar)
|
||||
// Update the radar animation even when its closed
|
||||
// This avoids obviously stale data from being shown when first opened.
|
||||
// TODO: This delayed updating is a giant hack
|
||||
--updateTicks;
|
||||
if (updateTicks <= 0)
|
||||
{
|
||||
animating = true;
|
||||
Sound.Play(hasRadarNew ? RadarOnlineSound : RadarOfflineSound);
|
||||
}
|
||||
hasRadar = hasRadarNew;
|
||||
|
||||
// Build the radar image
|
||||
if (hasRadar)
|
||||
{
|
||||
--updateTicks;
|
||||
if (updateTicks <= 0)
|
||||
{
|
||||
updateTicks = 12;
|
||||
customTerrainSprite.sheet.Texture.SetData(Minimap.CustomTerrainBitmap(world));
|
||||
}
|
||||
|
||||
if (updateTicks == 8)
|
||||
actorSprite.sheet.Texture.SetData(Minimap.ActorsBitmap(world));
|
||||
|
||||
if (updateTicks == 4)
|
||||
shroudSprite.sheet.Texture.SetData(Minimap.ShroudBitmap(world));
|
||||
updateTicks = 12;
|
||||
customTerrainSprite.sheet.Texture.SetData(Minimap.CustomTerrainBitmap(world));
|
||||
}
|
||||
|
||||
if (!animating)
|
||||
if (updateTicks == 8)
|
||||
actorSprite.sheet.Texture.SetData(Minimap.ActorsBitmap(world));
|
||||
|
||||
if (updateTicks == 4)
|
||||
shroudSprite.sheet.Texture.SetData(Minimap.ShroudBitmap(world));
|
||||
|
||||
// Enable/Disable the radar
|
||||
var enabled = IsEnabled();
|
||||
if (enabled != cachedEnabled)
|
||||
Sound.Play(enabled ? RadarOnlineSound : RadarOfflineSound);
|
||||
cachedEnabled = enabled;
|
||||
|
||||
var targetFrame = enabled ? AnimationLength : 0;
|
||||
hasRadar = enabled && frame == AnimationLength;
|
||||
if (frame == targetFrame)
|
||||
return;
|
||||
|
||||
// Increment frame
|
||||
if (hasRadar)
|
||||
AnimationFrame++;
|
||||
else
|
||||
AnimationFrame--;
|
||||
frame += enabled ? 1 : -1;
|
||||
radarMinimapHeight = float2.Lerp(0, 1, (float)frame / AnimationLength);
|
||||
|
||||
// Minimap height
|
||||
radarMinimapHeight = float2.Lerp(0, 1, AnimationFrame*1.0f / AnimationLength);
|
||||
// Update map rectangle for event handling
|
||||
var ro = RenderOrigin;
|
||||
mapRect = new Rectangle(previewOrigin.X + ro.X, previewOrigin.Y + ro.Y, mapRect.Width, mapRect.Height);
|
||||
|
||||
// Animation is complete
|
||||
if (AnimationFrame == (hasRadar ? AnimationLength : 0))
|
||||
animating = false;
|
||||
if (frame == targetFrame)
|
||||
{
|
||||
if (enabled)
|
||||
AfterOpen();
|
||||
else
|
||||
AfterClose();
|
||||
}
|
||||
}
|
||||
|
||||
int2 CellToMinimapPixel(CPos p)
|
||||
|
||||
66
OpenRA.Mods.RA/Widgets/SlidingContainerWidget.cs
Executable file
66
OpenRA.Mods.RA/Widgets/SlidingContainerWidget.cs
Executable file
@@ -0,0 +1,66 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class SlidingContainerWidget : Widget
|
||||
{
|
||||
public int2 OpenOffset = int2.Zero;
|
||||
public int2 ClosedOffset = int2.Zero;
|
||||
public int AnimationLength = 0;
|
||||
public Func<bool> IsOpen = () => false;
|
||||
public Action AfterOpen = () => {};
|
||||
public Action AfterClose = () => {};
|
||||
|
||||
int2 offset;
|
||||
int frame;
|
||||
|
||||
public SlidingContainerWidget() : base() { }
|
||||
public override void Initialize(WidgetArgs args)
|
||||
{
|
||||
base.Initialize(args);
|
||||
|
||||
// Start in the closed position
|
||||
offset = ClosedOffset;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
var open = IsOpen();
|
||||
|
||||
var targetFrame = open ? AnimationLength : 0;
|
||||
if (frame == targetFrame)
|
||||
return;
|
||||
|
||||
// Update child origin
|
||||
frame += open ? 1 : -1;
|
||||
offset = int2.Lerp(ClosedOffset, OpenOffset, frame, AnimationLength);
|
||||
|
||||
// Animation is complete
|
||||
if (frame == targetFrame)
|
||||
{
|
||||
if (open)
|
||||
AfterOpen();
|
||||
else
|
||||
AfterClose();
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||
public override int2 ChildOrigin { get { return RenderOrigin + offset; } }
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ Container@OBSERVER_WIDGETS:
|
||||
Visible:true
|
||||
Container@PLAYER_WIDGETS:
|
||||
Children:
|
||||
LogicTicker@WIN_LOSS_WATCHER:
|
||||
LogicTicker@SIDEBAR_TICKER:
|
||||
WorldCommand:
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
@@ -146,7 +146,7 @@ Container@PLAYER_WIDGETS:
|
||||
Height:168
|
||||
Background:panel-gray
|
||||
Children:
|
||||
Radar:
|
||||
Radar@RADAR_MINIMAP:
|
||||
X:1
|
||||
Y:1
|
||||
Width:PARENT_RIGHT-2
|
||||
|
||||
@@ -2,15 +2,10 @@ chrome-atreides: chrome-atreides.png
|
||||
specialbin-top: 0,0,30,51
|
||||
specialbin-middle: 0,51,30,51
|
||||
specialbin-bottom: 0,153,30,39
|
||||
moneybin: 192,0,320,32
|
||||
moneybin: 192,0,320,31
|
||||
radar: 297,31,210,222
|
||||
tooltip-bg: 0,288,272,136
|
||||
|
||||
radar-atreides: chrome-atreides.png
|
||||
left: 297,31,9,192
|
||||
right: 498,31,9,192
|
||||
bottom: 297,223,210,30
|
||||
bg: 306,31,192,192
|
||||
|
||||
power-atreides: chrome-atreides.png
|
||||
power-indicator: 187,4,4,7
|
||||
|
||||
@@ -44,16 +39,10 @@ chrome-harkonnen: chrome-harkonnen.png
|
||||
specialbin-top: 0,0,30,51
|
||||
specialbin-middle: 0,51,30,51
|
||||
specialbin-bottom: 0,153,30,39
|
||||
moneybin: 192,0,320,32
|
||||
moneybin: 192,0,320,31
|
||||
radar: 297,31,210,222
|
||||
tooltip-bg: 0,288,272,136
|
||||
|
||||
radar-harkonnen: chrome-harkonnen.png
|
||||
left: 297,31,9,192
|
||||
right: 498,31,9,192
|
||||
bottom: 297,223,210,30
|
||||
bg: 306,31,192,192
|
||||
power-indicator: 187,4,4,7
|
||||
|
||||
power-harkonnen: chrome-harkonnen.png
|
||||
power-indicator: 187,4,4,7
|
||||
|
||||
@@ -87,15 +76,10 @@ chrome-ordos: chrome-ordos.png
|
||||
specialbin-top: 0,0,30,51
|
||||
specialbin-middle: 0,51,30,51
|
||||
specialbin-bottom: 0,153,30,39
|
||||
moneybin: 192,0,320,32
|
||||
moneybin: 192,0,320,31
|
||||
radar: 297,31,210,222
|
||||
tooltip-bg: 0,288,272,136
|
||||
|
||||
radar-ordos: chrome-ordos.png
|
||||
left: 297,31,9,192
|
||||
right: 498,31,9,192
|
||||
bottom: 297,223,210,30
|
||||
bg: 306,31,192,192
|
||||
|
||||
power-ordos: chrome-ordos.png
|
||||
power-indicator: 187,4,4,7
|
||||
|
||||
|
||||
@@ -2,15 +2,10 @@ chrome-allies: chrome-allies.png
|
||||
specialbin-top: 0,0,30,51
|
||||
specialbin-middle: 0,51,30,51
|
||||
specialbin-bottom: 0,153,30,39
|
||||
moneybin: 192,0,320,32
|
||||
moneybin: 192,0,320,31
|
||||
radar: 297,31,210,222
|
||||
tooltip-bg: 0,288,272,136
|
||||
|
||||
radar-allies: chrome-allies.png
|
||||
left: 297,31,9,192
|
||||
right: 498,31,9,192
|
||||
bottom: 297,223,210,30
|
||||
bg: 306,31,192,192
|
||||
|
||||
power-allies: chrome-allies.png
|
||||
power-indicator: 187,4,4,7
|
||||
|
||||
@@ -44,16 +39,10 @@ chrome-soviet: chrome-soviet.png
|
||||
specialbin-top: 0,0,30,51
|
||||
specialbin-middle: 0,51,30,51
|
||||
specialbin-bottom: 0,153,30,39
|
||||
moneybin: 192,0,320,32
|
||||
moneybin: 192,0,320,31
|
||||
radar: 297,31,210,222
|
||||
tooltip-bg: 0,288,272,136
|
||||
|
||||
radar-soviet: chrome-soviet.png
|
||||
left: 297,31,9,192
|
||||
right: 498,31,9,192
|
||||
bottom: 297,223,210,30
|
||||
bg: 306,31,192,192
|
||||
power-indicator: 187,4,4,7
|
||||
|
||||
power-soviet: chrome-soviet.png
|
||||
power-indicator: 187,4,4,7
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ Container@INGAME_ROOT:
|
||||
|
||||
Container@PLAYER_WIDGETS:
|
||||
Children:
|
||||
LogicTicker@WIN_LOSS_WATCHER:
|
||||
LogicTicker@SIDEBAR_TICKER:
|
||||
Button@INGAME_DIPLOMACY_BUTTON:
|
||||
X:162
|
||||
Y:0
|
||||
@@ -81,8 +81,20 @@ Container@PLAYER_WIDGETS:
|
||||
Visible:false
|
||||
Font:Bold
|
||||
Key: f3
|
||||
RadarBin@INGAME_RADAR_BIN:
|
||||
WorldInteractionController:INTERACTION_CONTROLLER
|
||||
SlidingContainer@INGAME_RADAR_BIN:
|
||||
X:WINDOW_RIGHT-215
|
||||
Y:0
|
||||
OpenOffset:0,29
|
||||
ClosedOffset:0,-166
|
||||
AnimationLength:15
|
||||
Children:
|
||||
Image@RADAR_BIN_BG:
|
||||
ImageName:radar
|
||||
Radar@RADAR_MINIMAP:
|
||||
WorldInteractionController:INTERACTION_CONTROLLER
|
||||
X:9
|
||||
Width:192
|
||||
Height:192
|
||||
PowerBin@INGAME_POWER_BIN:
|
||||
MoneyBin@INGAME_MONEY_BIN:
|
||||
X:WINDOW_RIGHT - WIDTH
|
||||
|
||||
Reference in New Issue
Block a user