@@ -102,7 +102,6 @@
|
||||
<Compile Include="Widgets\Logic\CncPerfDebugLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncSettingsLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\ProductionPaletteWidget.cs" />
|
||||
@@ -110,7 +109,6 @@
|
||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||
<Compile Include="WithFire.cs" />
|
||||
<Compile Include="WithRoof.cs" />
|
||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTabsLogic.cs" />
|
||||
<Compile Include="Widgets\ProductionTypeButtonWidget.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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,22 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
|
||||
playerWidgets.Get<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
|
||||
|
||||
var winLossWatcher = playerWidgets.Get<LogicTickerWidget>("WIN_LOSS_WATCHER");
|
||||
winLossWatcher.OnTick = () =>
|
||||
var radarEnabled = false;
|
||||
var cachedRadarEnabled = 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);
|
||||
|
||||
if (radarEnabled != cachedRadarEnabled)
|
||||
Sound.PlayNotification(null, "Sounds", (radarEnabled ? "RadarUp" : "RadarDown"), null);
|
||||
cachedRadarEnabled = radarEnabled;
|
||||
|
||||
// Switch to observer mode after win/loss
|
||||
if (world.LocalPlayer.WinState != WinState.Undefined)
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
@@ -115,11 +130,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
siloBar.GetProvided = () => playerResources.OreCapacity;
|
||||
siloBar.GetUsed = () => playerResources.Ore;
|
||||
siloBar.TooltipFormat = "Silo Usage: {0}/{1}";
|
||||
siloBar.RightIndicator = true;
|
||||
siloBar.GetBarColor = () =>
|
||||
{
|
||||
if (playerResources.Ore == playerResources.OreCapacity) return Color.Red;
|
||||
if (playerResources.Ore >= 0.8 * playerResources.OreCapacity) return Color.Orange;
|
||||
if (playerResources.Ore == playerResources.OreCapacity)
|
||||
return Color.Red;
|
||||
if (playerResources.Ore >= 0.8 * playerResources.OreCapacity)
|
||||
return Color.Orange;
|
||||
return Color.LimeGreen;
|
||||
};
|
||||
|
||||
@@ -127,11 +143,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
powerBar.GetProvided = () => powerManager.PowerProvided;
|
||||
powerBar.GetUsed = () => powerManager.PowerDrained;
|
||||
powerBar.TooltipFormat = "Power Usage: {0}/{1}";
|
||||
powerBar.RightIndicator = false;
|
||||
powerBar.GetBarColor = () =>
|
||||
{
|
||||
if (powerManager.PowerState == PowerState.Critical) return Color.Red;
|
||||
if (powerManager.PowerState == PowerState.Low) return Color.Orange;
|
||||
if (powerManager.PowerState == PowerState.Critical)
|
||||
return Color.Red;
|
||||
if (powerManager.PowerState == PowerState.Low)
|
||||
return Color.Orange;
|
||||
return Color.LimeGreen;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,84 +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 OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public class ResourceBarWidget : Widget
|
||||
{
|
||||
public readonly string TooltipTemplate = "SIMPLE_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public float LowStorageThreshold = 0.8f;
|
||||
EWMA providedLerp = new EWMA(0.3f);
|
||||
EWMA usedLerp = new EWMA(0.3f);
|
||||
|
||||
public Func<float> GetProvided = () => 0;
|
||||
public Func<float> GetUsed = () => 0;
|
||||
public string TooltipFormat = "";
|
||||
public bool RightIndicator = false;
|
||||
public Func<Color> GetBarColor = () => Color.White;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ResourceBarWidget(World world)
|
||||
{
|
||||
tooltipContainer = Lazy.New(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
Func<string> getText = () => TooltipFormat.F(GetUsed(), GetProvided());
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "getText", getText }});
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
var scaleBy = 100.0f;
|
||||
var provided = GetProvided();
|
||||
var used = GetUsed();
|
||||
var max = Math.Max(provided, used);
|
||||
while (max >= scaleBy) scaleBy *= 2;
|
||||
|
||||
var providedFrac = providedLerp.Update(provided/scaleBy);
|
||||
var usedFrac = usedLerp.Update(used/scaleBy);
|
||||
|
||||
var color = GetBarColor();
|
||||
|
||||
var b = RenderBounds;
|
||||
var rect = new RectangleF(b.X, float2.Lerp( b.Bottom, b.Top, providedFrac ),
|
||||
b.Width, providedFrac*b.Height);
|
||||
Game.Renderer.LineRenderer.FillRect(rect, color);
|
||||
|
||||
var indicator = ChromeProvider.GetImage("sidebar-bits",
|
||||
RightIndicator ? "right-indicator" : "left-indicator");
|
||||
|
||||
var indicatorX = RightIndicator ? (b.Right - indicator.size.X) : b.Left;
|
||||
|
||||
var pos = new float2(indicatorX, float2.Lerp( b.Bottom, b.Top, usedFrac ) - indicator.size.Y / 2);
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,8 +408,6 @@
|
||||
<Compile Include="Widgets\ObserverProductionIconsWidget.cs" />
|
||||
<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 +454,9 @@
|
||||
<Compile Include="Widgets\Logic\CreditsLogic.cs" />
|
||||
<Compile Include="Render\WithResources.cs" />
|
||||
<Compile Include="Render\WithHarvestAnimation.cs" />
|
||||
<Compile Include="Widgets\SlidingContainerWidget.cs" />
|
||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -77,6 +78,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 +106,48 @@ 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 powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
||||
var powerBar = radarBin.Get<ResourceBarWidget>("POWERBAR");
|
||||
powerBar.IndicatorCollection = "power-"+world.LocalPlayer.Country.Race;
|
||||
powerBar.GetProvided = () => powerManager.PowerProvided;
|
||||
powerBar.GetUsed = () => powerManager.PowerDrained;
|
||||
powerBar.TooltipFormat = "Power Usage: {0}/{1}";
|
||||
powerBar.GetBarColor = () =>
|
||||
{
|
||||
if (powerManager.PowerState == PowerState.Critical)
|
||||
return Color.Red;
|
||||
if (powerManager.PowerState == PowerState.Low)
|
||||
return Color.Orange;
|
||||
return Color.LimeGreen;
|
||||
};
|
||||
|
||||
var cachedRadarActive = false;
|
||||
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);
|
||||
|
||||
if (radarActive != cachedRadarActive)
|
||||
Sound.PlayNotification(null, "Sounds", (radarActive ? "RadarUp" : "RadarDown"), null);
|
||||
cachedRadarActive = radarActive;
|
||||
|
||||
// Switch to observer mode after win/loss
|
||||
if (world.LocalPlayer.WinState != WinState.Undefined)
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* 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,
|
||||
@@ -11,7 +11,7 @@
|
||||
using System;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class SimpleTooltipLogic
|
||||
{
|
||||
@@ -1,119 +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 OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class PowerBinWidget : Widget
|
||||
{
|
||||
// Power bar
|
||||
float2 powerOrigin = new float2(42, 205); // Relative to radarOrigin
|
||||
Size powerSize = new Size(138, 5);
|
||||
|
||||
float? lastPowerProvidedPos;
|
||||
float? lastPowerDrainedPos;
|
||||
string powerCollection;
|
||||
|
||||
readonly string RadarBin = "INGAME_RADAR_BIN";
|
||||
readonly PowerManager power;
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public PowerBinWidget(World world)
|
||||
{
|
||||
this.world = world;
|
||||
|
||||
if (world.LocalPlayer != null)
|
||||
power = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
static Color GetPowerColor(PowerManager pm)
|
||||
{
|
||||
if (pm.PowerState == PowerState.Critical) return Color.Red;
|
||||
if (pm.PowerState == PowerState.Low) return Color.Orange;
|
||||
return Color.LimeGreen;
|
||||
}
|
||||
|
||||
const float PowerBarLerpFactor = .2f;
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if( world.LocalPlayer == null ) return;
|
||||
if( world.LocalPlayer.WinState != WinState.Undefined ) return;
|
||||
|
||||
var radarBin = Ui.Root.Get<RadarBinWidget>(RadarBin);
|
||||
|
||||
powerCollection = "power-" + world.LocalPlayer.Country.Race;
|
||||
|
||||
// Nothing to draw
|
||||
if (power.PowerProvided == 0 && power.PowerDrained == 0)
|
||||
return;
|
||||
|
||||
// Draw bar horizontally
|
||||
var barStart = powerOrigin + radarBin.RadarOrigin;
|
||||
var barEnd = barStart + new float2(powerSize.Width, 0);
|
||||
|
||||
float powerScaleBy = 100;
|
||||
var maxPower = Math.Max(power.PowerProvided, power.PowerDrained);
|
||||
|
||||
while (maxPower >= powerScaleBy) powerScaleBy *= 2;
|
||||
|
||||
// Current power supply
|
||||
var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (power.PowerProvided / powerScaleBy);
|
||||
lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, PowerBarLerpFactor);
|
||||
var powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y);
|
||||
|
||||
var color = GetPowerColor(power);
|
||||
|
||||
var colorDark = Exts.ColorLerp(0.25f, color, Color.Black);
|
||||
for (int i = 0; i < powerSize.Height; i++)
|
||||
{
|
||||
color = (i - 1 < powerSize.Height / 2) ? color : colorDark;
|
||||
var leftOffset = new float2(0, i);
|
||||
var rightOffset = new float2(0, i);
|
||||
// Indent corners
|
||||
if ((i == 0 || i == powerSize.Height - 1) && powerLevel.X - barStart.X > 1)
|
||||
{
|
||||
leftOffset.X += 1;
|
||||
rightOffset.X -= 1;
|
||||
}
|
||||
Game.Renderer.LineRenderer.DrawLine(barStart + leftOffset, powerLevel + rightOffset, color, color);
|
||||
}
|
||||
|
||||
// Power usage indicator
|
||||
var indicator = ChromeProvider.GetImage( powerCollection, "power-indicator");
|
||||
var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (power.PowerDrained / powerScaleBy);
|
||||
lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, PowerBarLerpFactor);
|
||||
var powerDrainLevel = new float2(lastPowerDrainedPos.Value - indicator.size.X / 2, barStart.Y - 1);
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, powerDrainLevel);
|
||||
|
||||
// Render the tooltip
|
||||
var rect = new Rectangle((int) barStart.X, (int) barStart.Y, powerSize.Width, powerSize.Height);
|
||||
|
||||
if (rect.InflateBy(0, 5, 0, 5).Contains(Viewport.LastMousePos))
|
||||
{
|
||||
var pos = new int2(rect.Left + 5, rect.Top + 5);
|
||||
|
||||
var border = WidgetUtils.GetBorderSizes("dialog4");
|
||||
WidgetUtils.DrawPanel("dialog4", rect.InflateBy(0, 0, 0, 50 + border[1]));
|
||||
|
||||
Game.Renderer.Fonts["Bold"].DrawText("Power", pos, Color.White);
|
||||
pos += new int2(0, 20);
|
||||
Game.Renderer.Fonts["Regular"].DrawText("Provided: {0}\nDrained: {1}".F(power.PowerProvided, power.PowerDrained), pos, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
RectangleF mapRect = Rectangle.Empty;
|
||||
int2 previewOrigin;
|
||||
int2 previewOrigin = int2.Zero;
|
||||
Rectangle mapRect = Rectangle.Empty;
|
||||
|
||||
Sprite terrainSprite;
|
||||
Sprite customTerrainSprite;
|
||||
@@ -47,15 +49,19 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
base.Initialize(args);
|
||||
|
||||
var size = Math.Max(world.Map.Bounds.Width, world.Map.Bounds.Height);
|
||||
previewScale = Math.Min(RenderBounds.Width * 1f / world.Map.Bounds.Width, RenderBounds.Height * 1f / world.Map.Bounds.Height);
|
||||
previewOrigin = new int2(RenderOrigin.X, RenderOrigin.Y + (int)(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));
|
||||
var width = world.Map.Bounds.Width;
|
||||
var height = world.Map.Bounds.Height;
|
||||
var size = Math.Max(width, height);
|
||||
var rb = RenderBounds;
|
||||
|
||||
previewScale = Math.Min(rb.Width * 1f / width, rb.Height * 1f / height);
|
||||
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
|
||||
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 );
|
||||
var r = new Rectangle(0, 0, width, height);
|
||||
var s = new Size(terrainBitmap.Width, terrainBitmap.Height);
|
||||
terrainSprite = new Sprite(new Sheet(s), r, TextureChannel.Alpha);
|
||||
terrainSprite.sheet.Texture.SetData(terrainBitmap);
|
||||
|
||||
@@ -88,10 +94,11 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (!hasRadar || animating) return false;
|
||||
if (!hasRadar)
|
||||
return true;
|
||||
|
||||
if (!mapRect.Contains(mi.Location))
|
||||
return false;
|
||||
return true;
|
||||
|
||||
var loc = MinimapPixelToCell(mi.Location);
|
||||
if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left)
|
||||
@@ -120,17 +127,16 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
public override Rectangle EventBounds
|
||||
{
|
||||
get { return new Rectangle((int)mapRect.X, (int)mapRect.Y, (int)mapRect.Width, (int)mapRect.Height);}
|
||||
}
|
||||
public override Rectangle EventBounds { get { return mapRect; } }
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (world == null) return;
|
||||
if (world == null)
|
||||
return;
|
||||
|
||||
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);
|
||||
@@ -138,63 +144,64 @@ 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);
|
||||
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.EnableScissor(mapRect.Left, mapRect.Top, mapRect.Width, mapRect.Height);
|
||||
Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White);
|
||||
Game.Renderer.DisableScissor();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
138
OpenRA.Mods.RA/Widgets/ResourceBarWidget.cs
Executable file
138
OpenRA.Mods.RA/Widgets/ResourceBarWidget.cs
Executable file
@@ -0,0 +1,138 @@
|
||||
#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.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public enum ResourceBarOrientation { Vertical, Horizontal }
|
||||
public enum ResourceBarStyle { Flat, Bevelled }
|
||||
public class ResourceBarWidget : Widget
|
||||
{
|
||||
public readonly string TooltipTemplate = "SIMPLE_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public string TooltipFormat = "";
|
||||
public ResourceBarOrientation Orientation = ResourceBarOrientation.Vertical;
|
||||
public ResourceBarStyle Style = ResourceBarStyle.Flat;
|
||||
public string IndicatorCollection = "sidebar-bits";
|
||||
public string IndicatorImage = "indicator";
|
||||
|
||||
public Func<float> GetProvided = () => 0;
|
||||
public Func<float> GetUsed = () => 0;
|
||||
public Func<Color> GetBarColor = () => Color.White;
|
||||
EWMA providedLerp = new EWMA(0.3f);
|
||||
EWMA usedLerp = new EWMA(0.3f);
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ResourceBarWidget(World world)
|
||||
{
|
||||
tooltipContainer = Lazy.New(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
Func<string> getText = () => TooltipFormat.F(GetUsed(), GetProvided());
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "getText", getText }});
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
var scaleBy = 100.0f;
|
||||
var provided = GetProvided();
|
||||
var used = GetUsed();
|
||||
var max = Math.Max(provided, used);
|
||||
while (max >= scaleBy)
|
||||
scaleBy *= 2;
|
||||
|
||||
var providedFrac = providedLerp.Update(provided/scaleBy);
|
||||
var usedFrac = usedLerp.Update(used/scaleBy);
|
||||
|
||||
var b = RenderBounds;
|
||||
var indicator = ChromeProvider.GetImage(IndicatorCollection, IndicatorImage);
|
||||
|
||||
var color = GetBarColor();
|
||||
if (Orientation == ResourceBarOrientation.Vertical)
|
||||
{
|
||||
if (Style == ResourceBarStyle.Bevelled)
|
||||
{
|
||||
var colorDark = Exts.ColorLerp(0.25f, color, Color.Black);
|
||||
for (var i = 0; i < b.Height; i++)
|
||||
{
|
||||
color = (i - 1 < b.Height / 2) ? color : colorDark;
|
||||
var bottom = new float2(b.Left + i, b.Bottom);
|
||||
var top = new float2(b.Left + i, b.Bottom + providedFrac*b.Height);
|
||||
|
||||
// Indent corners
|
||||
if ((i == 0 || i == b.Width - 1) && providedFrac*b.Height > 1)
|
||||
{
|
||||
bottom.Y += 1;
|
||||
top.Y -= 1;
|
||||
}
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(bottom, top, color, color);
|
||||
}
|
||||
}
|
||||
else
|
||||
Game.Renderer.LineRenderer.FillRect(new Rectangle(b.X, (int)float2.Lerp(b.Bottom, b.Top, providedFrac),
|
||||
b.Width, (int)(providedFrac*b.Height)), color);
|
||||
|
||||
var x = (b.Left + b.Right - indicator.size.X) / 2;
|
||||
var y = float2.Lerp(b.Bottom, b.Top, usedFrac) - indicator.size.Y / 2;
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, new float2(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Style == ResourceBarStyle.Bevelled)
|
||||
{
|
||||
var colorDark = Exts.ColorLerp(0.25f, color, Color.Black);
|
||||
for (var i = 0; i < b.Height; i++)
|
||||
{
|
||||
color = (i - 1 < b.Height / 2) ? color : colorDark;
|
||||
var left = new float2(b.Left, b.Top + i);
|
||||
var right = new float2(b.Left + providedFrac*b.Width, b.Top + i);
|
||||
|
||||
// Indent corners
|
||||
if ((i == 0 || i == b.Height - 1) && providedFrac*b.Width > 1)
|
||||
{
|
||||
left.X += 1;
|
||||
right.X -= 1;
|
||||
}
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(left, right, color, color);
|
||||
}
|
||||
}
|
||||
else
|
||||
Game.Renderer.LineRenderer.FillRect(new Rectangle(b.X, b.Y, (int)(providedFrac*b.Width), b.Height), color);
|
||||
|
||||
var x = float2.Lerp(b.Left, b.Right, usedFrac) - indicator.size.X / 2;
|
||||
var y = (b.Bottom + b.Top - indicator.size.Y) / 2;
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, new float2(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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; } }
|
||||
}
|
||||
}
|
||||
@@ -99,9 +99,9 @@
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="15.999999"
|
||||
inkscape:cx="385.97751"
|
||||
inkscape:cy="397.09537"
|
||||
inkscape:zoom="5.6568539"
|
||||
inkscape:cx="371.83537"
|
||||
inkscape:cy="425.37964"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="svg2"
|
||||
showgrid="false"
|
||||
@@ -205,13 +205,6 @@
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<rect
|
||||
style="fill:#768bd7;fill-opacity:1;stroke:none"
|
||||
id="rect3200"
|
||||
width="767.91803"
|
||||
height="742.46216"
|
||||
x="-195.16148"
|
||||
y="-169.65097" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
@@ -877,21 +870,15 @@
|
||||
sodipodi:nodetypes="ccccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path3948"
|
||||
d="m 320,580.3622 4,4 0,0 -4,4 z"
|
||||
d="m 400,588.3622 4,4 0,0 -4,4 z"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
id="rect3950"
|
||||
width="10"
|
||||
height="2"
|
||||
x="323"
|
||||
y="583.36224" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
d="m 336,580.3622 -4,4 0,0 4,4 z"
|
||||
id="path3952"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccc" />
|
||||
x="403"
|
||||
y="591.36224" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
id="rect3167"
|
||||
@@ -1355,6 +1342,19 @@
|
||||
id="path3993"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccc" />
|
||||
<rect
|
||||
y="599.36224"
|
||||
x="403"
|
||||
height="2"
|
||||
width="10"
|
||||
id="rect3206"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none" />
|
||||
<path
|
||||
sodipodi:nodetypes="ccccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path3208"
|
||||
d="m 416,596.3622 -4,4 0,0 4,4 z"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none" />
|
||||
</g>
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
|
||||
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
@@ -422,8 +422,8 @@ strategic: strategic.png
|
||||
player_owned: 96,0,32,32
|
||||
|
||||
sidebar-bits: chrome.png
|
||||
left-indicator: 320,40,11,8
|
||||
right-indicator: 325,40,11,8
|
||||
indicator-left: 400,48,16,8
|
||||
indicator-right: 400,56,16,8
|
||||
|
||||
production-icons: chrome.png
|
||||
building: 384,0,16,16
|
||||
|
||||
@@ -215,19 +215,19 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Checkbox@ALLOWCHEATS_CHECKBOX:
|
||||
X:150
|
||||
Y:80
|
||||
Width:80
|
||||
Width:230
|
||||
Height:20
|
||||
Text:Enable Cheats / Debug Menu
|
||||
Checkbox@CRATES_CHECKBOX:
|
||||
X:150
|
||||
Y:110
|
||||
Width:80
|
||||
Width:230
|
||||
Height:20
|
||||
Text:Enable Crates
|
||||
Checkbox@FRAGILEALLIANCES_CHECKBOX:
|
||||
X:150
|
||||
Y:140
|
||||
Width:80
|
||||
Width:230
|
||||
Height:20
|
||||
Text:Allow Team Changes
|
||||
Label@DIFFICULTY_DESC:
|
||||
|
||||
@@ -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
|
||||
@@ -165,6 +165,7 @@ Container@PLAYER_WIDGETS:
|
||||
Width:PARENT_RIGHT-2
|
||||
Height:PARENT_BOTTOM-2
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
IndicatorImage:indicator-left
|
||||
Background@SILOBAR_PANEL:
|
||||
X:180
|
||||
Y:5
|
||||
@@ -178,6 +179,7 @@ Container@PLAYER_WIDGETS:
|
||||
Width:PARENT_RIGHT-2
|
||||
Height:PARENT_BOTTOM-2
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
IndicatorImage:indicator-right
|
||||
Label@CASH:
|
||||
Y:170
|
||||
Width:PARENT_RIGHT
|
||||
|
||||
@@ -90,17 +90,17 @@ Container@SERVER_LOBBY:
|
||||
Align:Left
|
||||
Font:Bold
|
||||
Container@PLAYER_BIN_ROOT:
|
||||
Button@OPTIONS_BUTTON:
|
||||
X:15
|
||||
Y:254
|
||||
Width:112
|
||||
Height:25
|
||||
DropDownButton@SLOTS_DROPDOWNBUTTON:
|
||||
X:132
|
||||
X:15
|
||||
Y:254
|
||||
Width:150
|
||||
Height:25
|
||||
Text:Slot Admin
|
||||
Button@OPTIONS_BUTTON:
|
||||
X:170
|
||||
Y:254
|
||||
Width:112
|
||||
Height:25
|
||||
Button@CHANGEMAP_BUTTON:
|
||||
X:287
|
||||
Y:254
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
@@ -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
|
||||
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
Background@SIMPLE_TOOLTIP:
|
||||
Logic:SimpleTooltipLogic
|
||||
Background:dialog3
|
||||
Height:31
|
||||
Children:
|
||||
Label@LABEL:
|
||||
X:5
|
||||
Y:3
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic:SpawnSelectorTooltipLogic
|
||||
Background:dialog3
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -51,10 +51,11 @@ Container@INGAME_ROOT:
|
||||
Y:205
|
||||
Width:170
|
||||
Height:40
|
||||
TooltipContainer@TOOLTIP_CONTAINER:
|
||||
|
||||
Container@PLAYER_WIDGETS:
|
||||
Children:
|
||||
LogicTicker@WIN_LOSS_WATCHER:
|
||||
LogicTicker@SIDEBAR_TICKER:
|
||||
Button@INGAME_DIPLOMACY_BUTTON:
|
||||
X:162
|
||||
Y:0
|
||||
@@ -81,9 +82,29 @@ Container@PLAYER_WIDGETS:
|
||||
Visible:false
|
||||
Font:Bold
|
||||
Key: f3
|
||||
RadarBin@INGAME_RADAR_BIN:
|
||||
WorldInteractionController:INTERACTION_CONTROLLER
|
||||
PowerBin@INGAME_POWER_BIN:
|
||||
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
|
||||
ResourceBar@POWERBAR:
|
||||
X:42
|
||||
Y:205
|
||||
Width:138
|
||||
Height:5
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
IndicatorImage:power-indicator
|
||||
Orientation:Horizontal
|
||||
Style:Bevelled
|
||||
MoneyBin@INGAME_MONEY_BIN:
|
||||
X:WINDOW_RIGHT - WIDTH
|
||||
Y:0
|
||||
|
||||
@@ -68,19 +68,19 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Checkbox@ALLOWCHEATS_CHECKBOX:
|
||||
X:150
|
||||
Y:80
|
||||
Width:80
|
||||
Width:220
|
||||
Height:20
|
||||
Text:Enable Cheats / Debug Menu
|
||||
Checkbox@CRATES_CHECKBOX:
|
||||
X:150
|
||||
Y:110
|
||||
Width:80
|
||||
Width:220
|
||||
Height:20
|
||||
Text:Enable Crates
|
||||
Checkbox@FRAGILEALLIANCES_CHECKBOX:
|
||||
X:150
|
||||
Y:140
|
||||
Width:80
|
||||
Width:220
|
||||
Height:20
|
||||
Text:Allow Team Changes
|
||||
Label@DIFFICULTY_DESC:
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
Background@SIMPLE_TOOLTIP:
|
||||
Logic:SimpleTooltipLogic
|
||||
Background:dialog4
|
||||
Height:29
|
||||
Children:
|
||||
Label@LABEL:
|
||||
X:7
|
||||
Y:2
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic:SpawnSelectorTooltipLogic
|
||||
Background:dialog4
|
||||
|
||||
Reference in New Issue
Block a user