Merge pull request #3574 from ScottNZ/superweapons

Add atom bomb and gps public superweapon timers to RA
This commit is contained in:
Matthias Mailänder
2013-07-17 08:25:25 -07:00
10 changed files with 156 additions and 72 deletions

View File

@@ -141,21 +141,31 @@ namespace OpenRA.Widgets
DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y)); DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y));
} }
public static string FormatTime(int ticks) public static string FormatTime(int ticks)
{
return FormatTime(ticks, true);
}
public static string FormatTime(int ticks, bool leadingMinuteZero)
{ {
var seconds = (int)Math.Ceiling(ticks / 25f); var seconds = (int)Math.Ceiling(ticks / 25f);
return FormatTimeSeconds( seconds ); return FormatTimeSeconds(seconds, leadingMinuteZero);
} }
public static string FormatTimeSeconds(int seconds) public static string FormatTimeSeconds(int seconds)
{
return FormatTimeSeconds(seconds, true);
}
public static string FormatTimeSeconds(int seconds, bool leadingMinuteZero)
{ {
var minutes = seconds / 60; var minutes = seconds / 60;
if (minutes >= 60) if (minutes >= 60)
return "{0:D}:{1:D2}:{2:D2}".F(minutes / 60, minutes % 60, seconds % 60); return "{0:D}:{1:D2}:{2:D2}".F(minutes / 60, minutes % 60, seconds % 60);
else if (leadingMinuteZero)
return "{0:D2}:{1:D2}".F(minutes, seconds % 60); return "{0:D2}:{1:D2}".F(minutes, seconds % 60);
return "{0:D}:{1:D2}".F(minutes, seconds % 60);
} }
public static string WrapText(string text, int width, SpriteFont font) public static string WrapText(string text, int width, SpriteFont font)

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var baseHeight = widget.Bounds.Height; var baseHeight = widget.Bounds.Height;
var timeOffset = timeLabel.Bounds.X; var timeOffset = timeLabel.Bounds.X;
SupportPowerManager.SupportPowerInstance lastPower = null; SupportPowerInstance lastPower = null;
tooltipContainer.BeforeRender = () => tooltipContainer.BeforeRender = () =>
{ {
var sp = palette.TooltipPower; var sp = palette.TooltipPower;

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public readonly string TooltipContainer; public readonly string TooltipContainer;
public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP"; public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP";
public SupportPowerManager.SupportPowerInstance TooltipPower { get; private set; } public SupportPowerInstance TooltipPower { get; private set; }
Lazy<TooltipContainerWidget> tooltipContainer; Lazy<TooltipContainerWidget> tooltipContainer;
Rectangle eventBounds; Rectangle eventBounds;
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public class SupportPowerIcon public class SupportPowerIcon
{ {
public SupportPowerManager.SupportPowerInstance Power; public SupportPowerInstance Power;
public float2 Pos; public float2 Pos;
public Sprite Sprite; public Sprite Sprite;
} }

View File

@@ -410,6 +410,7 @@
<Compile Include="Widgets\OrderButtonWidget.cs" /> <Compile Include="Widgets\OrderButtonWidget.cs" />
<Compile Include="Widgets\RadarWidget.cs" /> <Compile Include="Widgets\RadarWidget.cs" />
<Compile Include="Widgets\StrategicProgressWidget.cs" /> <Compile Include="Widgets\StrategicProgressWidget.cs" />
<Compile Include="Widgets\SupportPowerTimerWidget.cs" />
<Compile Include="Widgets\SupportPowerBinWidget.cs" /> <Compile Include="Widgets\SupportPowerBinWidget.cs" />
<Compile Include="Widgets\WorldCommandWidget.cs" /> <Compile Include="Widgets\WorldCommandWidget.cs" />
<Compile Include="Widgets\WorldTooltipWidget.cs" /> <Compile Include="Widgets\WorldTooltipWidget.cs" />

View File

@@ -28,6 +28,8 @@ namespace OpenRA.Mods.RA
public readonly string SelectTargetSound = null; public readonly string SelectTargetSound = null;
public readonly string LaunchSound = null; public readonly string LaunchSound = null;
public readonly bool DisplayTimer = false;
public readonly string OrderName; public readonly string OrderName;
public abstract object Create(ActorInitializer init); public abstract object Create(ActorInitializer init);

View File

@@ -110,6 +110,7 @@ namespace OpenRA.Mods.RA
return a.TraitsImplementing<SupportPower>() return a.TraitsImplementing<SupportPower>()
.Select(t => Powers[MakeKey(t)]); .Select(t => Powers[MakeKey(t)]);
} }
}
public class SupportPowerInstance public class SupportPowerInstance
{ {
@@ -190,7 +191,6 @@ namespace OpenRA.Mods.RA
Disabled = true; Disabled = true;
} }
} }
}
public class SelectGenericPowerTarget : IOrderGenerator public class SelectGenericPowerTarget : IOrderGenerator
{ {

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.RA.Widgets
} }
} }
static string GetOverlayForItem(SupportPowerManager.SupportPowerInstance item) static string GetOverlayForItem(SupportPowerInstance item)
{ {
if (item.Disabled) return "ON HOLD"; if (item.Disabled) return "ON HOLD";
if (item.Ready) return "READY"; if (item.Ready) return "READY";

View File

@@ -0,0 +1,65 @@
#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.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets
{
public class SupportPowerTimerWidget : Widget
{
public readonly string Font = "Bold";
public readonly string Format = "{0}: {1}";
public readonly TimerOrder Order = TimerOrder.Descending;
readonly IEnumerable<SupportPowerInstance> powers;
Pair<string, Color>[] texts;
[ObjectCreator.UseCtor]
public SupportPowerTimerWidget(World world)
{
powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead() && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimer && !p.Disabled);
}
public override void Tick()
{
texts = powers.Select(p =>
{
var time = WidgetUtils.FormatTime(p.RemainingTime, false);
var text = Format.F(p.Info.Description, time);
var color = !p.Ready || Game.LocalTick % 50 < 25 ? p.Instances[0].self.Owner.Color.RGB : Color.White;
return Pair.New(text, color);
}).ToArray();
}
public override void Draw()
{
if (!IsVisible() || texts == null)
return;
var y = 0;
foreach (var t in texts)
{
var font = Game.Renderer.Fonts[Font];
font.DrawTextWithContrast(t.First, new float2(Bounds.Location) + new float2(0, y), t.Second, Color.Black, 1);
y += (font.Measure(t.First).Y + 5) * (int)Order;
}
}
public enum TimerOrder { Ascending = -1, Descending = 1 }
}
}

View File

@@ -52,6 +52,10 @@ Container@INGAME_ROOT:
Width:170 Width:170
Height:40 Height:40
TooltipContainer@TOOLTIP_CONTAINER: TooltipContainer@TOOLTIP_CONTAINER:
SupportPowerTimer@SUPPORT_POWER_TIMER:
X:15
Y:WINDOW_BOTTOM-30
Order:Ascending
Container@PLAYER_WIDGETS: Container@PLAYER_WIDGETS:
Children: Children:

View File

@@ -35,6 +35,7 @@ MSLO:
LaunchSound: alaunch1.aud LaunchSound: alaunch1.aud
MissileWeapon: atomic MissileWeapon: atomic
SpawnOffset: 0,427,0 SpawnOffset: 0,427,0
DisplayTimer: True
CanPowerDown: CanPowerDown:
RequiresPower: RequiresPower:
SupportPowerChargeBar: SupportPowerChargeBar:
@@ -849,9 +850,10 @@ ATEK:
OneShot: yes OneShot: yes
ChargeTime: 480 ChargeTime: 480
Description: GPS Satellite Description: GPS Satellite
LongDesc: Reveals the entire map LongDesc: Reveals the entire map.
RevealDelay: 15 RevealDelay: 15
LaunchSound: satlnch1.aud LaunchSound: satlnch1.aud
DisplayTimer: True
SupportPowerChargeBar: SupportPowerChargeBar:
WEAP: WEAP: