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 Point ToPoint() { return new Point(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.Game.Graphics;
|
||||
using OpenRa.TechTree;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
@@ -19,14 +20,18 @@ namespace OpenRa.Game
|
||||
Game game;
|
||||
readonly GRegion region;
|
||||
|
||||
Animation clockAnimation = new Animation("clock");
|
||||
|
||||
public GRegion Region { get { return region; } }
|
||||
public float Width { get { return spriteWidth * 2; } }
|
||||
|
||||
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
||||
const int spriteWidth = 64, spriteHeight = 48;
|
||||
|
||||
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 )
|
||||
@@ -42,9 +47,14 @@ namespace OpenRa.Game
|
||||
LoadSprites("buildings.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)
|
||||
@@ -58,7 +68,10 @@ namespace OpenRa.Game
|
||||
foreach (string line in Util.ReadAllLines(FileSystem.Open(filename)))
|
||||
{
|
||||
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"));
|
||||
itemGroups.Add(key, group);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +108,8 @@ namespace OpenRa.Game
|
||||
else
|
||||
unitPos += spriteHeight;
|
||||
}
|
||||
|
||||
foreach (string g in groups) selectedItems[g] = null;
|
||||
}
|
||||
|
||||
void Paint()
|
||||
@@ -107,8 +122,14 @@ namespace OpenRa.Game
|
||||
|
||||
spriteRenderer.Flush();
|
||||
|
||||
clockRenderer.DrawSprite( clockAnimation.Images[0], region.Location, 0 );
|
||||
clockAnimation.Tick(1);
|
||||
foreach (var kvp in selectedItems)
|
||||
{
|
||||
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();
|
||||
}
|
||||
@@ -127,7 +148,16 @@ namespace OpenRa.Game
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
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;
|
||||
readonly Sprite sprite;
|
||||
|
||||
public bool isBuilding = false;
|
||||
|
||||
public SidebarItem(Sprite s, Item item, int y)
|
||||
{
|
||||
this.techTreeItem = item;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRa.TechTree
|
||||
|
||||
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))
|
||||
{
|
||||
Match m = pattern.Match(s);
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
IRON,Iron Curtain
|
||||
ATEK,Allied Tech Center
|
||||
PDOX,Chronosphere
|
||||
WEAP,War Factory
|
||||
SYRD,Shipyard
|
||||
SPEN,Sub Pen
|
||||
PBOX,Pillbox
|
||||
HBOX,Camo Pillbox
|
||||
TSLA,Tesla Coil
|
||||
GUN,Turret
|
||||
AGUN,AA Gun
|
||||
FTUR,Flame Turret
|
||||
FACT,Construction Yard
|
||||
PROC,Ore Refinery
|
||||
SILO,Silo
|
||||
HPAD,Helipad
|
||||
DOME,Radar Dome
|
||||
GAP,Gap Generator
|
||||
SAM,SAM Site
|
||||
MSLO,Missile Silo
|
||||
AFLD,Airstrip
|
||||
POWR,Power Plant
|
||||
APWR,Advanced Power Plant
|
||||
STEK,Soviet Tech Center
|
||||
BARR,Soviet Barracks
|
||||
TENT,Allied Barracks
|
||||
KENN,Kennel
|
||||
FIX,Service Depot
|
||||
SBAG,Sandbags
|
||||
BRIK,Concrete Wall
|
||||
FENC,Wire Fence
|
||||
FACF,Fake Construction Yard
|
||||
WEAF,Fake War Factory
|
||||
SYRF,Fake Shipyard
|
||||
SPEF,Fake Sub Pen
|
||||
DOMF,Fake Radar Dome
|
||||
IRON,Iron Curtain,building
|
||||
ATEK,Allied Tech Center,building
|
||||
PDOX,Chronosphere,building
|
||||
WEAP,War Factory,building
|
||||
SYRD,Shipyard,building
|
||||
SPEN,Sub Pen,building
|
||||
PBOX,Pillbox,building
|
||||
HBOX,Camo Pillbox,building
|
||||
TSLA,Tesla Coil,building
|
||||
GUN,Turret,building
|
||||
AGUN,AA Gun,building
|
||||
FTUR,Flame Turret,building
|
||||
FACT,Construction Yard,building
|
||||
PROC,Ore Refinery,building
|
||||
SILO,Silo,building
|
||||
HPAD,Helipad,building
|
||||
DOME,Radar Dome,building
|
||||
GAP,Gap Generator,building
|
||||
SAM,SAM Site,building
|
||||
MSLO,Missile Silo,building
|
||||
AFLD,Airstrip,building
|
||||
POWR,Power Plant,building
|
||||
APWR,Advanced Power Plant,building
|
||||
STEK,Soviet Tech Center,building
|
||||
BARR,Soviet Barracks,building
|
||||
TENT,Allied Barracks,building
|
||||
KENN,Kennel,building
|
||||
FIX,Service Depot,building
|
||||
SBAG,Sandbags,building
|
||||
BRIK,Concrete Wall,building
|
||||
FENC,Wire Fence,building
|
||||
FACF,Fake Construction Yard,building
|
||||
WEAF,Fake War Factory,building
|
||||
SYRF,Fake Shipyard,building
|
||||
SPEF,Fake Sub Pen,building
|
||||
DOMF,Fake Radar Dome,building
|
||||
|
||||
66
units.txt
66
units.txt
@@ -1,33 +1,33 @@
|
||||
V2RL,V2 Rocket
|
||||
1TNK,Light Tank
|
||||
3TNK,Heavy Tank
|
||||
2TNK,Medium Tank
|
||||
4TNK,Mammoth Tank
|
||||
MRJ,Radar Jammer
|
||||
MGG,Mobile Gap Generator
|
||||
ARTY,Artillery
|
||||
HARV,Ore Truck
|
||||
MCV,Mobile Construction Vehicle
|
||||
JEEP,Ranger
|
||||
APC,Armored Personnel Carrier
|
||||
MNLY,Minelayer
|
||||
SS,Submarine
|
||||
DD,Destroyer
|
||||
CA,Cruiser
|
||||
LST,Transport
|
||||
PT,Gunboat
|
||||
DOG,Attack Dog
|
||||
E1,Rifle Infantry
|
||||
E2,Grenadier
|
||||
E3,Rocket Soldier
|
||||
E4,Flamethrower
|
||||
E6,Engineer
|
||||
SPY,Spy
|
||||
THF,Thief
|
||||
E7,Tanya
|
||||
MEDI,Medic
|
||||
MIG,Mig Attack Plane
|
||||
YAK,Yak Attack Plane
|
||||
TRAN,Transport Helicopter
|
||||
HELI,Longbow
|
||||
HIND,Hind
|
||||
V2RL,V2 Rocket,vehicle
|
||||
1TNK,Light Tank,vehicle
|
||||
3TNK,Heavy Tank,vehicle
|
||||
2TNK,Medium Tank,vehicle
|
||||
4TNK,Mammoth Tank,vehicle
|
||||
MRJ,Radar Jammer,vehicle
|
||||
MGG,Mobile Gap Generator,vehicle
|
||||
ARTY,Artillery,vehicle
|
||||
HARV,Ore Truck,vehicle
|
||||
MCV,Mobile Construction Vehicle,vehicle
|
||||
JEEP,Ranger,vehicle
|
||||
APC,Armored Personnel Carrier,vehicle
|
||||
MNLY,Minelayer,vehicle
|
||||
SS,Submarine,boat
|
||||
DD,Destroyer,boat
|
||||
CA,Cruiser,boat
|
||||
LST,Transport,boat
|
||||
PT,Gunboat,boat
|
||||
DOG,Attack Dog,infantry
|
||||
E1,Rifle Infantry,infantry
|
||||
E2,Grenadier,infantry
|
||||
E3,Rocket Soldier,infantry
|
||||
E4,Flamethrower,infantry
|
||||
E6,Engineer,infantry
|
||||
SPY,Spy,infantry
|
||||
THF,Thief,infantry
|
||||
E7,Tanya,infantry
|
||||
MEDI,Medic,infantry
|
||||
MIG,Mig Attack Plane,plane
|
||||
YAK,Yak Attack Plane,plane
|
||||
TRAN,Transport Helicopter,plane
|
||||
HELI,Longbow,plane
|
||||
HIND,Hind,plane
|
||||
|
||||
Reference in New Issue
Block a user