Added grouping of items in sidebar + correct clock placement
Items in the sidebar are now grouped by their type and one of each item in the group can be 'built' at a time. Clock animation is now drawn on the items that are being built. Build time still not implemented. Behaviour after item built not correct.
This commit is contained in:
@@ -37,5 +37,6 @@ namespace OpenRa
|
|||||||
public static readonly int2 Zero = new int2(0, 0);
|
public static readonly int2 Zero = new int2(0, 0);
|
||||||
public Point ToPoint() { return new Point(X, Y); }
|
public Point ToPoint() { return new Point(X, Y); }
|
||||||
public PointF ToPointF() { return new PointF(X, Y); }
|
public PointF ToPointF() { return new PointF(X, Y); }
|
||||||
|
public float2 ToFloat2() { return new float2(X, Y); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Windows.Forms;
|
|||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Game.Graphics;
|
using OpenRa.Game.Graphics;
|
||||||
using OpenRa.TechTree;
|
using OpenRa.TechTree;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -19,16 +20,20 @@ namespace OpenRa.Game
|
|||||||
Game game;
|
Game game;
|
||||||
readonly GRegion region;
|
readonly GRegion region;
|
||||||
|
|
||||||
Animation clockAnimation = new Animation("clock");
|
|
||||||
|
|
||||||
public GRegion Region { get { return region; } }
|
public GRegion Region { get { return region; } }
|
||||||
public float Width { get { return spriteWidth * 2; } }
|
public float Width { get { return spriteWidth * 2; } }
|
||||||
|
|
||||||
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
||||||
const int spriteWidth = 64, spriteHeight = 48;
|
const int spriteWidth = 64, spriteHeight = 48;
|
||||||
|
|
||||||
List<SidebarItem> items = new List<SidebarItem>();
|
static string[] groups = new string[] { "building", "vehicle", "boat", "infantry", "plane" };
|
||||||
|
|
||||||
|
Dictionary<string, string> itemGroups = new Dictionary<string,string>(); //item->group
|
||||||
|
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
||||||
|
Dictionary<string, SidebarItem> selectedItems = new Dictionary<string,SidebarItem>(); //group->selectedItem
|
||||||
|
|
||||||
|
List<SidebarItem> items = new List<SidebarItem>();
|
||||||
|
|
||||||
public Sidebar( Race race, Renderer renderer, Game game )
|
public Sidebar( Race race, Renderer renderer, Game game )
|
||||||
{
|
{
|
||||||
this.techTree = game.LocalPlayer.TechTree;
|
this.techTree = game.LocalPlayer.TechTree;
|
||||||
@@ -42,9 +47,14 @@ namespace OpenRa.Game
|
|||||||
LoadSprites("buildings.txt");
|
LoadSprites("buildings.txt");
|
||||||
LoadSprites("units.txt");
|
LoadSprites("units.txt");
|
||||||
|
|
||||||
blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16);
|
foreach (string s in groups)
|
||||||
|
{
|
||||||
|
clockAnimations.Add(s, new Animation("clock"));
|
||||||
|
clockAnimations[s].PlayRepeating("idle");
|
||||||
|
selectedItems.Add(s, null);
|
||||||
|
}
|
||||||
|
|
||||||
clockAnimation.PlayRepeating("idle");
|
blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Build(SidebarItem item)
|
public void Build(SidebarItem item)
|
||||||
@@ -58,7 +68,10 @@ namespace OpenRa.Game
|
|||||||
foreach (string line in Util.ReadAllLines(FileSystem.Open(filename)))
|
foreach (string line in Util.ReadAllLines(FileSystem.Open(filename)))
|
||||||
{
|
{
|
||||||
string key = line.Substring(0, line.IndexOf(','));
|
string key = line.Substring(0, line.IndexOf(','));
|
||||||
|
int secondComma = line.IndexOf(',', line.IndexOf(',') + 1);
|
||||||
|
string group = line.Substring(secondComma + 1, line.Length - secondComma - 1);
|
||||||
sprites.Add(key, SpriteSheetBuilder.LoadSprite(key + "icon.shp"));
|
sprites.Add(key, SpriteSheetBuilder.LoadSprite(key + "icon.shp"));
|
||||||
|
itemGroups.Add(key, group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +108,8 @@ namespace OpenRa.Game
|
|||||||
else
|
else
|
||||||
unitPos += spriteHeight;
|
unitPos += spriteHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (string g in groups) selectedItems[g] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Paint()
|
void Paint()
|
||||||
@@ -107,9 +122,15 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
|
|
||||||
clockRenderer.DrawSprite( clockAnimation.Images[0], region.Location, 0 );
|
foreach (var kvp in selectedItems)
|
||||||
clockAnimation.Tick(1);
|
{
|
||||||
|
if (kvp.Value != null)
|
||||||
|
{
|
||||||
|
clockRenderer.DrawSprite(clockAnimations[kvp.Key].Images[0], region.Location.ToFloat2() + kvp.Value.location, 0);
|
||||||
|
clockAnimations[kvp.Key].Tick(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clockRenderer.Flush();
|
clockRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +148,16 @@ namespace OpenRa.Game
|
|||||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
var point = new float2(mi.Location.X, mi.Location.Y);
|
var point = new float2(mi.Location.X, mi.Location.Y);
|
||||||
Build(GetItem(point));
|
var item = GetItem(point);
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
string group = itemGroups[item.techTreeItem.tag];
|
||||||
|
if (selectedItems[group] == null)
|
||||||
|
{
|
||||||
|
selectedItems[group] = item;
|
||||||
|
Build(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ namespace OpenRa.Game
|
|||||||
public readonly float2 location;
|
public readonly float2 location;
|
||||||
readonly Sprite sprite;
|
readonly Sprite sprite;
|
||||||
|
|
||||||
public bool isBuilding = false;
|
|
||||||
|
|
||||||
public SidebarItem(Sprite s, Item item, int y)
|
public SidebarItem(Sprite s, Item item, int y)
|
||||||
{
|
{
|
||||||
this.techTreeItem = item;
|
this.techTreeItem = item;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRa.TechTree
|
|||||||
|
|
||||||
IEnumerable<Tuple<string, string, bool>> Lines(string filename, bool param)
|
IEnumerable<Tuple<string, string, bool>> Lines(string filename, bool param)
|
||||||
{
|
{
|
||||||
Regex pattern = new Regex(@"^(\w+),([\w ]+)$");
|
Regex pattern = new Regex(@"^(\w+),([\w ]+),(\w+)$");
|
||||||
foreach (string s in File.ReadAllLines("../../../../" + filename))
|
foreach (string s in File.ReadAllLines("../../../../" + filename))
|
||||||
{
|
{
|
||||||
Match m = pattern.Match(s);
|
Match m = pattern.Match(s);
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
IRON,Iron Curtain
|
IRON,Iron Curtain,building
|
||||||
ATEK,Allied Tech Center
|
ATEK,Allied Tech Center,building
|
||||||
PDOX,Chronosphere
|
PDOX,Chronosphere,building
|
||||||
WEAP,War Factory
|
WEAP,War Factory,building
|
||||||
SYRD,Shipyard
|
SYRD,Shipyard,building
|
||||||
SPEN,Sub Pen
|
SPEN,Sub Pen,building
|
||||||
PBOX,Pillbox
|
PBOX,Pillbox,building
|
||||||
HBOX,Camo Pillbox
|
HBOX,Camo Pillbox,building
|
||||||
TSLA,Tesla Coil
|
TSLA,Tesla Coil,building
|
||||||
GUN,Turret
|
GUN,Turret,building
|
||||||
AGUN,AA Gun
|
AGUN,AA Gun,building
|
||||||
FTUR,Flame Turret
|
FTUR,Flame Turret,building
|
||||||
FACT,Construction Yard
|
FACT,Construction Yard,building
|
||||||
PROC,Ore Refinery
|
PROC,Ore Refinery,building
|
||||||
SILO,Silo
|
SILO,Silo,building
|
||||||
HPAD,Helipad
|
HPAD,Helipad,building
|
||||||
DOME,Radar Dome
|
DOME,Radar Dome,building
|
||||||
GAP,Gap Generator
|
GAP,Gap Generator,building
|
||||||
SAM,SAM Site
|
SAM,SAM Site,building
|
||||||
MSLO,Missile Silo
|
MSLO,Missile Silo,building
|
||||||
AFLD,Airstrip
|
AFLD,Airstrip,building
|
||||||
POWR,Power Plant
|
POWR,Power Plant,building
|
||||||
APWR,Advanced Power Plant
|
APWR,Advanced Power Plant,building
|
||||||
STEK,Soviet Tech Center
|
STEK,Soviet Tech Center,building
|
||||||
BARR,Soviet Barracks
|
BARR,Soviet Barracks,building
|
||||||
TENT,Allied Barracks
|
TENT,Allied Barracks,building
|
||||||
KENN,Kennel
|
KENN,Kennel,building
|
||||||
FIX,Service Depot
|
FIX,Service Depot,building
|
||||||
SBAG,Sandbags
|
SBAG,Sandbags,building
|
||||||
BRIK,Concrete Wall
|
BRIK,Concrete Wall,building
|
||||||
FENC,Wire Fence
|
FENC,Wire Fence,building
|
||||||
FACF,Fake Construction Yard
|
FACF,Fake Construction Yard,building
|
||||||
WEAF,Fake War Factory
|
WEAF,Fake War Factory,building
|
||||||
SYRF,Fake Shipyard
|
SYRF,Fake Shipyard,building
|
||||||
SPEF,Fake Sub Pen
|
SPEF,Fake Sub Pen,building
|
||||||
DOMF,Fake Radar Dome
|
DOMF,Fake Radar Dome,building
|
||||||
|
|||||||
66
units.txt
66
units.txt
@@ -1,33 +1,33 @@
|
|||||||
V2RL,V2 Rocket
|
V2RL,V2 Rocket,vehicle
|
||||||
1TNK,Light Tank
|
1TNK,Light Tank,vehicle
|
||||||
3TNK,Heavy Tank
|
3TNK,Heavy Tank,vehicle
|
||||||
2TNK,Medium Tank
|
2TNK,Medium Tank,vehicle
|
||||||
4TNK,Mammoth Tank
|
4TNK,Mammoth Tank,vehicle
|
||||||
MRJ,Radar Jammer
|
MRJ,Radar Jammer,vehicle
|
||||||
MGG,Mobile Gap Generator
|
MGG,Mobile Gap Generator,vehicle
|
||||||
ARTY,Artillery
|
ARTY,Artillery,vehicle
|
||||||
HARV,Ore Truck
|
HARV,Ore Truck,vehicle
|
||||||
MCV,Mobile Construction Vehicle
|
MCV,Mobile Construction Vehicle,vehicle
|
||||||
JEEP,Ranger
|
JEEP,Ranger,vehicle
|
||||||
APC,Armored Personnel Carrier
|
APC,Armored Personnel Carrier,vehicle
|
||||||
MNLY,Minelayer
|
MNLY,Minelayer,vehicle
|
||||||
SS,Submarine
|
SS,Submarine,boat
|
||||||
DD,Destroyer
|
DD,Destroyer,boat
|
||||||
CA,Cruiser
|
CA,Cruiser,boat
|
||||||
LST,Transport
|
LST,Transport,boat
|
||||||
PT,Gunboat
|
PT,Gunboat,boat
|
||||||
DOG,Attack Dog
|
DOG,Attack Dog,infantry
|
||||||
E1,Rifle Infantry
|
E1,Rifle Infantry,infantry
|
||||||
E2,Grenadier
|
E2,Grenadier,infantry
|
||||||
E3,Rocket Soldier
|
E3,Rocket Soldier,infantry
|
||||||
E4,Flamethrower
|
E4,Flamethrower,infantry
|
||||||
E6,Engineer
|
E6,Engineer,infantry
|
||||||
SPY,Spy
|
SPY,Spy,infantry
|
||||||
THF,Thief
|
THF,Thief,infantry
|
||||||
E7,Tanya
|
E7,Tanya,infantry
|
||||||
MEDI,Medic
|
MEDI,Medic,infantry
|
||||||
MIG,Mig Attack Plane
|
MIG,Mig Attack Plane,plane
|
||||||
YAK,Yak Attack Plane
|
YAK,Yak Attack Plane,plane
|
||||||
TRAN,Transport Helicopter
|
TRAN,Transport Helicopter,plane
|
||||||
HELI,Longbow
|
HELI,Longbow,plane
|
||||||
HIND,Hind
|
HIND,Hind,plane
|
||||||
|
|||||||
Reference in New Issue
Block a user