support power impl; incomplete
This commit is contained in:
@@ -47,6 +47,7 @@ namespace OpenRa.Game
|
|||||||
readonly List<Pair<Rectangle, Action<bool>>> buttons = new List<Pair<Rectangle, Action<bool>>>();
|
readonly List<Pair<Rectangle, Action<bool>>> buttons = new List<Pair<Rectangle, Action<bool>>>();
|
||||||
readonly List<Sprite> digitSprites;
|
readonly List<Sprite> digitSprites;
|
||||||
readonly Dictionary<string, Sprite[]> tabSprites;
|
readonly Dictionary<string, Sprite[]> tabSprites;
|
||||||
|
readonly Dictionary<string, Sprite> spsprites;
|
||||||
readonly Sprite[] shimSprites;
|
readonly Sprite[] shimSprites;
|
||||||
readonly Sprite blank;
|
readonly Sprite blank;
|
||||||
|
|
||||||
@@ -55,6 +56,12 @@ namespace OpenRa.Game
|
|||||||
bool hadRadar = false;
|
bool hadRadar = false;
|
||||||
bool optionsPressed = false;
|
bool optionsPressed = false;
|
||||||
const int MinRows = 4;
|
const int MinRows = 4;
|
||||||
|
|
||||||
|
string currentTab = "Building";
|
||||||
|
static string[] groups = new string[] { "Building", "Defense", "Infantry", "Vehicle", "Plane", "Ship" };
|
||||||
|
readonly Dictionary<string, Sprite> sprites;
|
||||||
|
|
||||||
|
const int NumClockFrames = 54;
|
||||||
|
|
||||||
public Chrome(Renderer r)
|
public Chrome(Renderer r)
|
||||||
{
|
{
|
||||||
@@ -116,6 +123,11 @@ namespace OpenRa.Game
|
|||||||
u => u,
|
u => u,
|
||||||
u => SpriteSheetBuilder.LoadAllSprites(Rules.UnitInfo[u].Icon ?? (u + "icon"))[0]);
|
u => SpriteSheetBuilder.LoadAllSprites(Rules.UnitInfo[u].Icon ?? (u + "icon"))[0]);
|
||||||
|
|
||||||
|
spsprites = Rules.SupportPowerInfo
|
||||||
|
.ToDictionary(
|
||||||
|
u => u.Key,
|
||||||
|
u => SpriteSheetBuilder.LoadAllSprites(u.Value.Image)[0]);
|
||||||
|
|
||||||
tabSprites = groups.Select(
|
tabSprites = groups.Select(
|
||||||
(g, i) => Pair.New(g,
|
(g, i) => Pair.New(g,
|
||||||
OpenRa.Game.Graphics.Util.MakeArray(3,
|
OpenRa.Game.Graphics.Util.MakeArray(3,
|
||||||
@@ -163,7 +175,6 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
DrawMinimap();
|
DrawMinimap();
|
||||||
|
|
||||||
chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, PaletteType.Chrome);
|
|
||||||
chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), PaletteType.Chrome);
|
chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), PaletteType.Chrome);
|
||||||
|
|
||||||
DrawMoney();
|
DrawMoney();
|
||||||
@@ -172,6 +183,7 @@ namespace OpenRa.Game
|
|||||||
DrawButtons();
|
DrawButtons();
|
||||||
|
|
||||||
int paletteHeight = DrawBuildPalette(currentTab);
|
int paletteHeight = DrawBuildPalette(currentTab);
|
||||||
|
DrawSupportPowers();
|
||||||
DrawBuildTabs(paletteHeight);
|
DrawBuildTabs(paletteHeight);
|
||||||
DrawChat();
|
DrawChat();
|
||||||
DrawOptionsMenu();
|
DrawOptionsMenu();
|
||||||
@@ -220,15 +232,11 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
// Don't let tabs overlap the bevel
|
// Don't let tabs overlap the bevel
|
||||||
if (y > paletteOrigin.Y + paletteHeight - tabHeight - 9 && y < paletteOrigin.Y + paletteHeight)
|
if (y > paletteOrigin.Y + paletteHeight - tabHeight - 9 && y < paletteOrigin.Y + paletteHeight)
|
||||||
{
|
|
||||||
y += tabHeight;
|
y += tabHeight;
|
||||||
}
|
|
||||||
|
|
||||||
// Stick tabs to the edge of the screen
|
// Stick tabs to the edge of the screen
|
||||||
if (y > paletteOrigin.Y + paletteHeight)
|
if (y > paletteOrigin.Y + paletteHeight)
|
||||||
{
|
|
||||||
x = Game.viewport.Width - tabWidth;
|
x = Game.viewport.Width - tabWidth;
|
||||||
}
|
|
||||||
|
|
||||||
chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), PaletteType.Chrome);
|
chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), PaletteType.Chrome);
|
||||||
|
|
||||||
@@ -321,10 +329,8 @@ namespace OpenRa.Game
|
|||||||
if (!hasChronosphere)
|
if (!hasChronosphere)
|
||||||
repairButton.ReplaceAnim("disabled");
|
repairButton.ReplaceAnim("disabled");
|
||||||
else
|
else
|
||||||
{
|
|
||||||
//repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal");
|
|
||||||
AddButton(chronoshiftRect, isLmb => HandleChronosphereButton());
|
AddButton(chronoshiftRect, isLmb => HandleChronosphereButton());
|
||||||
}
|
|
||||||
buildPaletteRenderer.DrawSprite(repairButton.Image, chronoshiftDrawPos, PaletteType.Chrome);
|
buildPaletteRenderer.DrawSprite(repairButton.Image, chronoshiftDrawPos, PaletteType.Chrome);
|
||||||
|
|
||||||
// Iron Curtain
|
// Iron Curtain
|
||||||
@@ -336,13 +342,10 @@ namespace OpenRa.Game
|
|||||||
if (!hasCurtain)
|
if (!hasCurtain)
|
||||||
repairButton.ReplaceAnim("disabled");
|
repairButton.ReplaceAnim("disabled");
|
||||||
else
|
else
|
||||||
{
|
|
||||||
//repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal");
|
|
||||||
AddButton(curtainRect, isLmb => HandleIronCurtainButton());
|
AddButton(curtainRect, isLmb => HandleIronCurtainButton());
|
||||||
}
|
|
||||||
buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome);
|
buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome);
|
||||||
|
|
||||||
|
|
||||||
// Repair
|
// Repair
|
||||||
Rectangle repairRect = new Rectangle(Game.viewport.Width - 120, 5, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
Rectangle repairRect = new Rectangle(Game.viewport.Width - 120, 5, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
||||||
var repairDrawPos = Game.viewport.Location + new float2(repairRect.Location);
|
var repairDrawPos = Game.viewport.Location + new float2(repairRect.Location);
|
||||||
@@ -386,7 +389,7 @@ namespace OpenRa.Game
|
|||||||
buildPaletteRenderer.Flush();
|
buildPaletteRenderer.Flush();
|
||||||
|
|
||||||
//Options
|
//Options
|
||||||
Rectangle optionsRect = new Rectangle(0 + 40,0, optionsButton.Image.bounds.Width,
|
Rectangle optionsRect = new Rectangle(0,0, optionsButton.Image.bounds.Width,
|
||||||
optionsButton.Image.bounds.Height);
|
optionsButton.Image.bounds.Height);
|
||||||
|
|
||||||
var optionsDrawPos = Game.viewport.Location + new float2(optionsRect.Location);
|
var optionsDrawPos = Game.viewport.Location + new float2(optionsRect.Location);
|
||||||
@@ -464,22 +467,6 @@ namespace OpenRa.Game
|
|||||||
renderer.DrawText(line.b, p, line.a);
|
renderer.DrawText(line.b, p, line.a);
|
||||||
renderer.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White);
|
renderer.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
string currentTab = "Building";
|
|
||||||
static string[] groups = new string[] { "Building", "Defense", "Infantry", "Vehicle", "Plane", "Ship" };
|
|
||||||
Dictionary<string, Sprite> sprites;
|
|
||||||
|
|
||||||
const int NumClockFrames = 54;
|
|
||||||
Func<int> ClockAnimFrame(string group)
|
|
||||||
{
|
|
||||||
return () =>
|
|
||||||
{
|
|
||||||
var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
|
||||||
var producing = queue.CurrentItem( group );
|
|
||||||
if (producing == null) return 0;
|
|
||||||
return (producing.TotalTime - producing.RemainingTime) * NumClockFrames / producing.TotalTime;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return an int telling us the y coordinate at the bottom of the palette
|
// Return an int telling us the y coordinate at the bottom of the palette
|
||||||
int DrawBuildPalette(string queueName)
|
int DrawBuildPalette(string queueName)
|
||||||
@@ -717,5 +704,40 @@ namespace OpenRa.Game
|
|||||||
renderer.DrawText(info.LongDesc.Replace( "\\n", "\n" ), p.ToInt2(), Color.White);
|
renderer.DrawText(info.LongDesc.Replace( "\\n", "\n" ), p.ToInt2(), Color.White);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawSupportPowers()
|
||||||
|
{
|
||||||
|
chromeRenderer.DrawSprite(specialBinSprite, new float2(0,14), PaletteType.Chrome);
|
||||||
|
chromeRenderer.Flush();
|
||||||
|
var y = 24;
|
||||||
|
foreach (var sp in Game.LocalPlayer.SupportPowers)
|
||||||
|
{
|
||||||
|
var image = spsprites[sp.Key];
|
||||||
|
if (sp.Value.IsAvailable)
|
||||||
|
{
|
||||||
|
var drawPos = Game.viewport.Location + new float2(5, y);
|
||||||
|
buildPaletteRenderer.DrawSprite(image, drawPos, PaletteType.Chrome);
|
||||||
|
|
||||||
|
clock.PlayFetchIndex("idle",
|
||||||
|
() => (sp.Value.TotalTime - sp.Value.RemainingTime)
|
||||||
|
* NumClockFrames / sp.Value.TotalTime);
|
||||||
|
clock.Tick();
|
||||||
|
|
||||||
|
buildPaletteRenderer.DrawSprite(clock.Image, drawPos, PaletteType.Chrome);
|
||||||
|
|
||||||
|
if (sp.Value.IsDone)
|
||||||
|
{
|
||||||
|
ready.Play("ready");
|
||||||
|
buildPaletteRenderer.DrawSprite(ready.Image,
|
||||||
|
drawPos + new float2((64 - ready.Image.size.X) / 2, 2),
|
||||||
|
PaletteType.Chrome);
|
||||||
|
}
|
||||||
|
|
||||||
|
y += 51;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildPaletteRenderer.Flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ using System.Text;
|
|||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Game.Graphics;
|
using OpenRa.Game.Graphics;
|
||||||
using IjwFramework.Types;
|
using IjwFramework.Types;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
namespace OpenRa.Game.GameRules
|
namespace OpenRa.Game.GameRules
|
||||||
{
|
{
|
||||||
class InfoLoader<T>
|
class InfoLoader<T> : IEnumerable<KeyValuePair<string, T>>
|
||||||
{
|
{
|
||||||
readonly Dictionary<string, T> infos = new Dictionary<string, T>();
|
readonly Dictionary<string, T> infos = new Dictionary<string, T>();
|
||||||
|
|
||||||
@@ -28,9 +29,7 @@ namespace OpenRa.Game.GameRules
|
|||||||
get { return infos[name.ToLowerInvariant()]; }
|
get { return infos[name.ToLowerInvariant()]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<KeyValuePair<string, T>> GetEnumerator()
|
public IEnumerator<KeyValuePair<string, T>> GetEnumerator() { return infos.GetEnumerator(); }
|
||||||
{
|
IEnumerator IEnumerable.GetEnumerator() { return infos.GetEnumerator(); }
|
||||||
return infos.GetEnumerator();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRa.Game.GameRules
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> BuildableItems( Player player, params string[] categories )
|
public IEnumerable<string> BuildableItems( Player player, params string[] categories )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -119,6 +119,7 @@
|
|||||||
<Compile Include="Shroud.cs" />
|
<Compile Include="Shroud.cs" />
|
||||||
<Compile Include="Smudge.cs" />
|
<Compile Include="Smudge.cs" />
|
||||||
<Compile Include="Sound.cs" />
|
<Compile Include="Sound.cs" />
|
||||||
|
<Compile Include="SupportPower.cs" />
|
||||||
<Compile Include="Support\Stopwatch.cs" />
|
<Compile Include="Support\Stopwatch.cs" />
|
||||||
<Compile Include="Support\PerfHistory.cs" />
|
<Compile Include="Support\PerfHistory.cs" />
|
||||||
<Compile Include="Traits\AcceptsOre.cs" />
|
<Compile Include="Traits\AcceptsOre.cs" />
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace OpenRa.Game
|
|||||||
public bool IsReady;
|
public bool IsReady;
|
||||||
|
|
||||||
public Shroud Shroud = new Shroud();
|
public Shroud Shroud = new Shroud();
|
||||||
|
public Dictionary<string, SupportPower> SupportPowers;
|
||||||
|
|
||||||
public Player( Actor playerActor, int index, PaletteType palette, string playerName, Race race, string internalName )
|
public Player( Actor playerActor, int index, PaletteType palette, string playerName, Race race, string internalName )
|
||||||
{
|
{
|
||||||
@@ -37,6 +38,10 @@ namespace OpenRa.Game
|
|||||||
this.InternalName = internalName;
|
this.InternalName = internalName;
|
||||||
this.PlayerName = playerName;
|
this.PlayerName = playerName;
|
||||||
this.Race = race;
|
this.Race = race;
|
||||||
|
|
||||||
|
SupportPowers = Rules.SupportPowerInfo.ToDictionary(
|
||||||
|
spi => spi.Key,
|
||||||
|
spi => new SupportPower(spi.Value, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePower()
|
void UpdatePower()
|
||||||
@@ -126,6 +131,9 @@ namespace OpenRa.Game
|
|||||||
UpdatePower();
|
UpdatePower();
|
||||||
UpdateOreCapacity();
|
UpdateOreCapacity();
|
||||||
|
|
||||||
|
foreach (var sp in SupportPowers.Values)
|
||||||
|
sp.Tick();
|
||||||
|
|
||||||
if (this == Game.LocalPlayer)
|
if (this == Game.LocalPlayer)
|
||||||
{
|
{
|
||||||
var totalMoney = Cash + Ore;
|
var totalMoney = Cash + Ore;
|
||||||
|
|||||||
48
OpenRa.Game/SupportPower.cs
Normal file
48
OpenRa.Game/SupportPower.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRa.Game.GameRules;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class SupportPower
|
||||||
|
{
|
||||||
|
public readonly SupportPowerInfo Info;
|
||||||
|
public readonly Player Owner;
|
||||||
|
|
||||||
|
public SupportPower(SupportPowerInfo info, Player owner)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
Owner = owner;
|
||||||
|
|
||||||
|
RemainingTime = TotalTime = (int)info.ChargeTime * 60 * 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsAvailable { get; private set; }
|
||||||
|
public bool IsDone { get { return RemainingTime == 0; } }
|
||||||
|
public int RemainingTime { get; private set; }
|
||||||
|
public int TotalTime { get; private set; }
|
||||||
|
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
if (Info.GivenAuto)
|
||||||
|
{
|
||||||
|
var buildings = Rules.TechTree.GatherBuildings(Owner);
|
||||||
|
var effectivePrereq = Info.Prerequisite
|
||||||
|
.Select( a => a.ToLowerInvariant() )
|
||||||
|
.Where( a => Rules.UnitInfo[a].Owner
|
||||||
|
.Any( r => r == Owner.Race ));
|
||||||
|
|
||||||
|
IsAvailable = Info.TechLevel > -1
|
||||||
|
&& effectivePrereq.Any()
|
||||||
|
&& effectivePrereq.All(a => buildings[a].Count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsAvailable && (!Info.Powered || Owner.GetPowerState() == PowerState.Normal))
|
||||||
|
{
|
||||||
|
if (RemainingTime > 0) --RemainingTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -857,6 +857,7 @@ Description=Chronoshift
|
|||||||
LongDesc=Temporarily teleports a vehicle across the map.
|
LongDesc=Temporarily teleports a vehicle across the map.
|
||||||
Prerequisite=PDOX
|
Prerequisite=PDOX
|
||||||
Image=warpicon
|
Image=warpicon
|
||||||
|
TechLevel=12
|
||||||
|
|
||||||
[SpyPlanePower] ; free with first AFLD
|
[SpyPlanePower] ; free with first AFLD
|
||||||
ChargeTime=3
|
ChargeTime=3
|
||||||
@@ -872,6 +873,7 @@ Description=Atom Bomb
|
|||||||
LongDesc=Launches a nuclear missile at your target
|
LongDesc=Launches a nuclear missile at your target
|
||||||
Prerequisite=MSLO
|
Prerequisite=MSLO
|
||||||
Image=atomicon
|
Image=atomicon
|
||||||
|
TechLevel=12
|
||||||
|
|
||||||
[GpsSatellitePower] ; free with ATEK
|
[GpsSatellitePower] ; free with ATEK
|
||||||
ChargeTime=8
|
ChargeTime=8
|
||||||
@@ -880,10 +882,12 @@ LongDesc=Reveals the entire map
|
|||||||
OneShot=yes
|
OneShot=yes
|
||||||
Prerequisite=ATEK
|
Prerequisite=ATEK
|
||||||
Image=gpssicon
|
Image=gpssicon
|
||||||
|
TechLevel=12
|
||||||
|
|
||||||
[InvulnerabilityPower] ; the point of IRON
|
[InvulnerabilityPower] ; the point of IRON
|
||||||
ChargeTime=11
|
ChargeTime=11
|
||||||
Description=Invulnerability
|
Description=Invulnerability
|
||||||
LongDesc=Makes a single unit invulnerable for a short time.
|
LongDesc=Makes a single unit invulnerable for a short time.
|
||||||
Image=infxicon
|
Image=infxicon
|
||||||
Prerequisite=IRON
|
Prerequisite=IRON
|
||||||
|
TechLevel=12
|
||||||
Reference in New Issue
Block a user