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<Sprite> digitSprites;
|
||||
readonly Dictionary<string, Sprite[]> tabSprites;
|
||||
readonly Dictionary<string, Sprite> spsprites;
|
||||
readonly Sprite[] shimSprites;
|
||||
readonly Sprite blank;
|
||||
|
||||
@@ -56,6 +57,12 @@ namespace OpenRa.Game
|
||||
bool optionsPressed = false;
|
||||
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)
|
||||
{
|
||||
// Positioning of chrome elements
|
||||
@@ -116,6 +123,11 @@ namespace OpenRa.Game
|
||||
u => u,
|
||||
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(
|
||||
(g, i) => Pair.New(g,
|
||||
OpenRa.Game.Graphics.Util.MakeArray(3,
|
||||
@@ -163,7 +175,6 @@ namespace OpenRa.Game
|
||||
|
||||
DrawMinimap();
|
||||
|
||||
chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, PaletteType.Chrome);
|
||||
chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), PaletteType.Chrome);
|
||||
|
||||
DrawMoney();
|
||||
@@ -172,6 +183,7 @@ namespace OpenRa.Game
|
||||
DrawButtons();
|
||||
|
||||
int paletteHeight = DrawBuildPalette(currentTab);
|
||||
DrawSupportPowers();
|
||||
DrawBuildTabs(paletteHeight);
|
||||
DrawChat();
|
||||
DrawOptionsMenu();
|
||||
@@ -220,15 +232,11 @@ namespace OpenRa.Game
|
||||
|
||||
// Don't let tabs overlap the bevel
|
||||
if (y > paletteOrigin.Y + paletteHeight - tabHeight - 9 && y < paletteOrigin.Y + paletteHeight)
|
||||
{
|
||||
y += tabHeight;
|
||||
}
|
||||
|
||||
// Stick tabs to the edge of the screen
|
||||
if (y > paletteOrigin.Y + paletteHeight)
|
||||
{
|
||||
x = Game.viewport.Width - tabWidth;
|
||||
}
|
||||
|
||||
chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), PaletteType.Chrome);
|
||||
|
||||
@@ -321,10 +329,8 @@ namespace OpenRa.Game
|
||||
if (!hasChronosphere)
|
||||
repairButton.ReplaceAnim("disabled");
|
||||
else
|
||||
{
|
||||
//repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal");
|
||||
AddButton(chronoshiftRect, isLmb => HandleChronosphereButton());
|
||||
}
|
||||
|
||||
buildPaletteRenderer.DrawSprite(repairButton.Image, chronoshiftDrawPos, PaletteType.Chrome);
|
||||
|
||||
// Iron Curtain
|
||||
@@ -336,12 +342,9 @@ namespace OpenRa.Game
|
||||
if (!hasCurtain)
|
||||
repairButton.ReplaceAnim("disabled");
|
||||
else
|
||||
{
|
||||
//repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal");
|
||||
AddButton(curtainRect, isLmb => HandleIronCurtainButton());
|
||||
}
|
||||
buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome);
|
||||
|
||||
buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome);
|
||||
|
||||
// Repair
|
||||
Rectangle repairRect = new Rectangle(Game.viewport.Width - 120, 5, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
||||
@@ -386,7 +389,7 @@ namespace OpenRa.Game
|
||||
buildPaletteRenderer.Flush();
|
||||
|
||||
//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);
|
||||
|
||||
var optionsDrawPos = Game.viewport.Location + new float2(optionsRect.Location);
|
||||
@@ -465,22 +468,6 @@ namespace OpenRa.Game
|
||||
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
|
||||
int DrawBuildPalette(string queueName)
|
||||
{
|
||||
@@ -717,5 +704,40 @@ namespace OpenRa.Game
|
||||
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.Game.Graphics;
|
||||
using IjwFramework.Types;
|
||||
using System.Collections;
|
||||
|
||||
namespace OpenRa.Game.GameRules
|
||||
{
|
||||
class InfoLoader<T>
|
||||
class InfoLoader<T> : IEnumerable<KeyValuePair<string, T>>
|
||||
{
|
||||
readonly Dictionary<string, T> infos = new Dictionary<string, T>();
|
||||
|
||||
@@ -28,9 +29,7 @@ namespace OpenRa.Game.GameRules
|
||||
get { return infos[name.ToLowerInvariant()]; }
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, T>> GetEnumerator()
|
||||
{
|
||||
return infos.GetEnumerator();
|
||||
}
|
||||
public IEnumerator<KeyValuePair<string, T>> GetEnumerator() { return infos.GetEnumerator(); }
|
||||
IEnumerator IEnumerable.GetEnumerator() { return infos.GetEnumerator(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
<Compile Include="Shroud.cs" />
|
||||
<Compile Include="Smudge.cs" />
|
||||
<Compile Include="Sound.cs" />
|
||||
<Compile Include="SupportPower.cs" />
|
||||
<Compile Include="Support\Stopwatch.cs" />
|
||||
<Compile Include="Support\PerfHistory.cs" />
|
||||
<Compile Include="Traits\AcceptsOre.cs" />
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace OpenRa.Game
|
||||
public bool IsReady;
|
||||
|
||||
public Shroud Shroud = new Shroud();
|
||||
public Dictionary<string, SupportPower> SupportPowers;
|
||||
|
||||
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.PlayerName = playerName;
|
||||
this.Race = race;
|
||||
|
||||
SupportPowers = Rules.SupportPowerInfo.ToDictionary(
|
||||
spi => spi.Key,
|
||||
spi => new SupportPower(spi.Value, this));
|
||||
}
|
||||
|
||||
void UpdatePower()
|
||||
@@ -126,6 +131,9 @@ namespace OpenRa.Game
|
||||
UpdatePower();
|
||||
UpdateOreCapacity();
|
||||
|
||||
foreach (var sp in SupportPowers.Values)
|
||||
sp.Tick();
|
||||
|
||||
if (this == Game.LocalPlayer)
|
||||
{
|
||||
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.
|
||||
Prerequisite=PDOX
|
||||
Image=warpicon
|
||||
TechLevel=12
|
||||
|
||||
[SpyPlanePower] ; free with first AFLD
|
||||
ChargeTime=3
|
||||
@@ -872,6 +873,7 @@ Description=Atom Bomb
|
||||
LongDesc=Launches a nuclear missile at your target
|
||||
Prerequisite=MSLO
|
||||
Image=atomicon
|
||||
TechLevel=12
|
||||
|
||||
[GpsSatellitePower] ; free with ATEK
|
||||
ChargeTime=8
|
||||
@@ -880,6 +882,7 @@ LongDesc=Reveals the entire map
|
||||
OneShot=yes
|
||||
Prerequisite=ATEK
|
||||
Image=gpssicon
|
||||
TechLevel=12
|
||||
|
||||
[InvulnerabilityPower] ; the point of IRON
|
||||
ChargeTime=11
|
||||
@@ -887,3 +890,4 @@ Description=Invulnerability
|
||||
LongDesc=Makes a single unit invulnerable for a short time.
|
||||
Image=infxicon
|
||||
Prerequisite=IRON
|
||||
TechLevel=12
|
||||
Reference in New Issue
Block a user