Minor changes on Sidebar
This commit is contained in:
@@ -1,146 +1,146 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
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.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
using GRegion = OpenRa.Game.Graphics.Region;
|
using GRegion = OpenRa.Game.Graphics.Region;
|
||||||
|
|
||||||
|
|
||||||
class MainWindow : Form
|
class MainWindow : Form
|
||||||
{
|
{
|
||||||
readonly Renderer renderer;
|
readonly Renderer renderer;
|
||||||
|
|
||||||
public readonly Sidebar sidebar;
|
public readonly Sidebar sidebar;
|
||||||
|
|
||||||
static Size GetResolution(Settings settings)
|
static Size GetResolution(Settings settings)
|
||||||
{
|
{
|
||||||
Size desktopResolution = Screen.PrimaryScreen.Bounds.Size;
|
Size desktopResolution = Screen.PrimaryScreen.Bounds.Size;
|
||||||
|
|
||||||
return new Size(settings.GetValue("width", desktopResolution.Width),
|
return new Size(settings.GetValue("width", desktopResolution.Width),
|
||||||
settings.GetValue("height", desktopResolution.Height));
|
settings.GetValue("height", desktopResolution.Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32")]
|
[DllImport("user32")]
|
||||||
static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
|
static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
|
||||||
|
|
||||||
public MainWindow(Settings settings)
|
public MainWindow(Settings settings)
|
||||||
{
|
{
|
||||||
FileSystem.Mount(new Folder("../../../../"));
|
FileSystem.Mount(new Folder("../../../../"));
|
||||||
FileSystem.Mount(new Package("redalert.mix"));
|
FileSystem.Mount(new Package("redalert.mix"));
|
||||||
FileSystem.Mount(new Package("conquer.mix"));
|
FileSystem.Mount(new Package("conquer.mix"));
|
||||||
FileSystem.Mount(new Package("hires.mix"));
|
FileSystem.Mount(new Package("hires.mix"));
|
||||||
FileSystem.Mount(new Package("general.mix"));
|
FileSystem.Mount(new Package("general.mix"));
|
||||||
FileSystem.Mount(new Package("local.mix"));
|
FileSystem.Mount(new Package("local.mix"));
|
||||||
FileSystem.Mount(new Package("sounds.mix"));
|
FileSystem.Mount(new Package("sounds.mix"));
|
||||||
FileSystem.Mount(new Package("speech.mix"));
|
FileSystem.Mount(new Package("speech.mix"));
|
||||||
FileSystem.Mount(new Package("allies.mix"));
|
FileSystem.Mount(new Package("allies.mix"));
|
||||||
FileSystem.Mount(new Package("russian.mix"));
|
FileSystem.Mount(new Package("russian.mix"));
|
||||||
|
|
||||||
FormBorderStyle = FormBorderStyle.None;
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
BackColor = Color.Black;
|
BackColor = Color.Black;
|
||||||
StartPosition = FormStartPosition.Manual;
|
StartPosition = FormStartPosition.Manual;
|
||||||
Location = Point.Empty;
|
Location = Point.Empty;
|
||||||
Visible = true;
|
Visible = true;
|
||||||
|
|
||||||
bool windowed = !settings.GetValue("fullscreen", false);
|
bool windowed = !settings.GetValue("fullscreen", false);
|
||||||
renderer = new Renderer(this, GetResolution(settings), windowed);
|
renderer = new Renderer(this, GetResolution(settings), windowed);
|
||||||
SheetBuilder.Initialize(renderer);
|
SheetBuilder.Initialize(renderer);
|
||||||
|
|
||||||
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
|
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
|
||||||
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
|
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
|
||||||
Game.Replay = settings.GetValue("replay", "");
|
Game.Replay = settings.GetValue("replay", "");
|
||||||
|
|
||||||
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
|
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
|
||||||
settings.GetValue("player", 1));
|
settings.GetValue("player", 1));
|
||||||
|
|
||||||
SequenceProvider.ForcePrecache();
|
SequenceProvider.ForcePrecache();
|
||||||
|
|
||||||
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 5, 5 ), Game.players[ 1 ]) );
|
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 5, 5 ), Game.players[ 1 ]) );
|
||||||
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 7, 5 ), Game.players[ 2 ] ) );
|
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 7, 5 ), Game.players[ 2 ] ) );
|
||||||
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 9, 5 ), Game.players[ 0 ] ) );
|
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 9, 5 ), Game.players[ 0 ] ) );
|
||||||
Game.world.Add( new Actor( "jeep", Game.map.Offset + new int2( 9, 15 ), Game.players[ 1 ] ) );
|
Game.world.Add( new Actor( "jeep", Game.map.Offset + new int2( 9, 15 ), Game.players[ 1 ] ) );
|
||||||
Game.world.Add( new Actor( "3tnk", Game.map.Offset + new int2( 12, 7 ), Game.players[ 1 ] ) );
|
Game.world.Add( new Actor( "3tnk", Game.map.Offset + new int2( 12, 7 ), Game.players[ 1 ] ) );
|
||||||
|
|
||||||
sidebar = new Sidebar(renderer);
|
sidebar = new Sidebar(renderer, Game.LocalPlayer);
|
||||||
|
|
||||||
renderer.BuildPalette(Game.map);
|
renderer.BuildPalette(Game.map);
|
||||||
|
|
||||||
ShowCursor(false);
|
ShowCursor(false);
|
||||||
|
|
||||||
Game.world.ResetTimer();
|
Game.world.ResetTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Run()
|
internal void Run()
|
||||||
{
|
{
|
||||||
while (Created && Visible)
|
while (Created && Visible)
|
||||||
{
|
{
|
||||||
Game.Tick();
|
Game.Tick();
|
||||||
Game.viewport.cursor = Game.controller.ChooseCursor();
|
Game.viewport.cursor = Game.controller.ChooseCursor();
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int2 lastPos;
|
int2 lastPos;
|
||||||
|
|
||||||
protected override void OnMouseDown(MouseEventArgs e)
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseDown(e);
|
base.OnMouseDown(e);
|
||||||
lastPos = new int2(e.Location);
|
lastPos = new int2(e.Location);
|
||||||
|
|
||||||
Game.viewport.DispatchMouseInput(new MouseInput
|
Game.viewport.DispatchMouseInput(new MouseInput
|
||||||
{
|
{
|
||||||
Button = e.Button,
|
Button = e.Button,
|
||||||
Event = MouseInputEvent.Down,
|
Event = MouseInputEvent.Down,
|
||||||
Location = new int2(e.Location)
|
Location = new int2(e.Location)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseMove(MouseEventArgs e)
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseMove(e);
|
base.OnMouseMove(e);
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Middle)
|
if (e.Button == MouseButtons.Middle)
|
||||||
{
|
{
|
||||||
int2 p = new int2(e.Location);
|
int2 p = new int2(e.Location);
|
||||||
Game.viewport.Scroll(lastPos - p);
|
Game.viewport.Scroll(lastPos - p);
|
||||||
lastPos = p;
|
lastPos = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.viewport.DispatchMouseInput(new MouseInput
|
Game.viewport.DispatchMouseInput(new MouseInput
|
||||||
{
|
{
|
||||||
Button = e.Button,
|
Button = e.Button,
|
||||||
Event = MouseInputEvent.Move,
|
Event = MouseInputEvent.Move,
|
||||||
Location = new int2(e.Location)
|
Location = new int2(e.Location)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Game.controller.orderGenerator != null)
|
if (Game.controller.orderGenerator != null)
|
||||||
Game.controller.orderGenerator.PrepareOverlay(
|
Game.controller.orderGenerator.PrepareOverlay(
|
||||||
((1 / 24f) * (new float2(e.Location) + Game.viewport.Location)).ToInt2());
|
((1 / 24f) * (new float2(e.Location) + Game.viewport.Location)).ToInt2());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseUp(MouseEventArgs e)
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseUp(e);
|
base.OnMouseUp(e);
|
||||||
|
|
||||||
Game.viewport.DispatchMouseInput(new MouseInput
|
Game.viewport.DispatchMouseInput(new MouseInput
|
||||||
{
|
{
|
||||||
Button = e.Button,
|
Button = e.Button,
|
||||||
Event = MouseInputEvent.Up,
|
Event = MouseInputEvent.Up,
|
||||||
Location = new int2(e.Location)
|
Location = new int2(e.Location)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MouseInput
|
struct MouseInput
|
||||||
{
|
{
|
||||||
public MouseInputEvent Event;
|
public MouseInputEvent Event;
|
||||||
public int2 Location;
|
public int2 Location;
|
||||||
public MouseButtons Button;
|
public MouseButtons Button;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MouseInputEvent { Down, Move, Up };
|
enum MouseInputEvent { Down, Move, Up };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key: Production category. Categories are: building, infantry, vehicle, boat, plane (and one per super, if they're done in here)
|
// Key: Production category. Categories are: building, infantry, vehicle, ship, plane (and one per super, if they're done in here)
|
||||||
readonly Dictionary<string, ProductionItem> production = new Dictionary<string, ProductionItem>();
|
readonly Dictionary<string, ProductionItem> production = new Dictionary<string, ProductionItem>();
|
||||||
|
|
||||||
public void ProductionInit( string category )
|
public void ProductionInit( string category )
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
class Sidebar
|
class Sidebar
|
||||||
{
|
{
|
||||||
TechTree.TechTree techTree;
|
Player player;
|
||||||
|
|
||||||
SpriteRenderer spriteRenderer, clockRenderer;
|
SpriteRenderer spriteRenderer, clockRenderer;
|
||||||
Sprite blank;
|
Sprite blank;
|
||||||
@@ -25,17 +25,17 @@ namespace OpenRa.Game
|
|||||||
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;
|
||||||
|
|
||||||
static string[] groups = new string[] { "building", "vehicle", "boat", "infantry", "plane" };
|
static string[] groups = new string[] { "building", "vehicle", "ship", "infantry", "plane" };
|
||||||
|
|
||||||
Dictionary<string, string> itemGroups = new Dictionary<string,string>(); //item->group
|
Dictionary<string, string> itemGroups = new Dictionary<string,string>(); //item->group
|
||||||
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
||||||
|
|
||||||
List<SidebarItem> items = new List<SidebarItem>();
|
List<SidebarItem> items = new List<SidebarItem>();
|
||||||
|
|
||||||
public Sidebar( Renderer renderer )
|
public Sidebar( Renderer renderer, Player player )
|
||||||
{
|
{
|
||||||
this.techTree = Game.LocalPlayer.TechTree;
|
this.player = player;
|
||||||
this.techTree.BuildableItemsChanged += PopulateItemList;
|
this.player.TechTree.BuildableItemsChanged += PopulateItemList;
|
||||||
region = GRegion.Create(Game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
region = GRegion.Create(Game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
||||||
Game.viewport.AddRegion( region );
|
Game.viewport.AddRegion( region );
|
||||||
spriteRenderer = new SpriteRenderer(renderer, false);
|
spriteRenderer = new SpriteRenderer(renderer, false);
|
||||||
@@ -44,12 +44,12 @@ namespace OpenRa.Game
|
|||||||
LoadSprites( "BuildingTypes", "building" );
|
LoadSprites( "BuildingTypes", "building" );
|
||||||
LoadSprites( "VehicleTypes", "vehicle" );
|
LoadSprites( "VehicleTypes", "vehicle" );
|
||||||
LoadSprites( "InfantryTypes", "infantry" );
|
LoadSprites( "InfantryTypes", "infantry" );
|
||||||
LoadSprites( "ShipTypes", "boat" );
|
LoadSprites( "ShipTypes", "ship" );
|
||||||
LoadSprites( "PlaneTypes", "plane" );
|
LoadSprites( "PlaneTypes", "plane" );
|
||||||
|
|
||||||
foreach (string group in groups)
|
foreach (string group in groups)
|
||||||
{
|
{
|
||||||
Game.LocalPlayer.ProductionInit( group );
|
player.ProductionInit( group );
|
||||||
clockAnimations.Add( group, new Animation( "clock" ) );
|
clockAnimations.Add( group, new Animation( "clock" ) );
|
||||||
clockAnimations[ group ].PlayFetchIndex( "idle", ClockAnimFrame( group ) );
|
clockAnimations[ group ].PlayFetchIndex( "idle", ClockAnimFrame( group ) );
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
return () =>
|
return () =>
|
||||||
{
|
{
|
||||||
var producing = Game.LocalPlayer.Producing( group );
|
var producing = player.Producing( group );
|
||||||
if( producing == null ) return 0;
|
if( producing == null ) return 0;
|
||||||
return ( producing.TotalTime - producing.RemainingTime ) * NumClockFrames / producing.TotalTime;
|
return ( producing.TotalTime - producing.RemainingTime ) * NumClockFrames / producing.TotalTime;
|
||||||
};
|
};
|
||||||
@@ -73,10 +73,10 @@ namespace OpenRa.Game
|
|||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
|
|
||||||
if (item.techTreeItem.IsStructure)
|
if (item.techTreeItem.IsStructure)
|
||||||
Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer,
|
Game.controller.orderGenerator = new PlaceBuilding(player,
|
||||||
item.techTreeItem.tag.ToLowerInvariant());
|
item.techTreeItem.tag.ToLowerInvariant());
|
||||||
else
|
else
|
||||||
Game.controller.AddOrder(Order.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant()));
|
Game.controller.AddOrder(Order.BuildUnit(player, item.techTreeItem.tag.ToLowerInvariant()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSprites( string category, string group )
|
void LoadSprites( string category, string group )
|
||||||
@@ -112,7 +112,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
items.Clear();
|
items.Clear();
|
||||||
|
|
||||||
foreach (Item i in techTree.BuildableItems)
|
foreach (Item i in player.TechTree.BuildableItems)
|
||||||
{
|
{
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
if (!sprites.TryGetValue(i.tag, out sprite)) continue;
|
if (!sprites.TryGetValue(i.tag, out sprite)) continue;
|
||||||
@@ -125,7 +125,7 @@ namespace OpenRa.Game
|
|||||||
unitPos += spriteHeight;
|
unitPos += spriteHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach( string g in groups ) Game.LocalPlayer.CancelProduction( g );
|
foreach( string g in groups ) player.CancelProduction( g );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Paint()
|
void Paint()
|
||||||
@@ -133,7 +133,7 @@ namespace OpenRa.Game
|
|||||||
foreach( SidebarItem i in items )
|
foreach( SidebarItem i in items )
|
||||||
{
|
{
|
||||||
var group = itemGroups[ i.techTreeItem.tag ];
|
var group = itemGroups[ i.techTreeItem.tag ];
|
||||||
var producing = Game.LocalPlayer.Producing( group );
|
var producing = player.Producing( group );
|
||||||
if( producing != null && producing.Item == i.techTreeItem.tag )
|
if( producing != null && producing.Item == i.techTreeItem.tag )
|
||||||
{
|
{
|
||||||
clockAnimations[ group ].Tick();
|
clockAnimations[ group ].Tick();
|
||||||
@@ -167,9 +167,9 @@ namespace OpenRa.Game
|
|||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
string group = itemGroups[item.techTreeItem.tag];
|
string group = itemGroups[item.techTreeItem.tag];
|
||||||
if (Game.LocalPlayer.Producing(group) == null)
|
if (player.Producing(group) == null)
|
||||||
{
|
{
|
||||||
Game.LocalPlayer.BeginProduction( group, new ProductionItem( item.techTreeItem.tag, 25, 0 ) );
|
player.BeginProduction( group, new ProductionItem( item.techTreeItem.tag, 25, 0 ) );
|
||||||
Build(item);
|
Build(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ namespace OpenRa.Game
|
|||||||
if( item != null )
|
if( item != null )
|
||||||
{
|
{
|
||||||
string group = itemGroups[ item.techTreeItem.tag ];
|
string group = itemGroups[ item.techTreeItem.tag ];
|
||||||
Game.LocalPlayer.CancelProduction( group );
|
player.CancelProduction( group );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Game.GameRules;
|
using OpenRa.Game.GameRules;
|
||||||
|
using IjwFramework.Types;
|
||||||
|
|
||||||
namespace OpenRa.TechTree
|
namespace OpenRa.TechTree
|
||||||
{
|
{
|
||||||
@@ -33,7 +34,7 @@ namespace OpenRa.TechTree
|
|||||||
Race race = Race.None;
|
Race race = Race.None;
|
||||||
|
|
||||||
foreach (string s in owners)
|
foreach (string s in owners)
|
||||||
race |= (Race)Enum.Parse(typeof(Race), s, true);
|
race |= Enum<Race>.Parse(s);
|
||||||
|
|
||||||
return race;
|
return race;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,77 +1,77 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRa.Game;
|
using OpenRa.Game;
|
||||||
|
|
||||||
namespace OpenRa.TechTree
|
namespace OpenRa.TechTree
|
||||||
{
|
{
|
||||||
public class TechTree
|
public class TechTree
|
||||||
{
|
{
|
||||||
Dictionary<string, Item> objects = new Dictionary<string, Item>();
|
Dictionary<string, Item> objects = new Dictionary<string, Item>();
|
||||||
public ICollection<string> built = new List<string>();
|
public ICollection<string> built = new List<string>();
|
||||||
|
|
||||||
Race currentRace = Race.None;
|
Race currentRace = Race.None;
|
||||||
|
|
||||||
public Race CurrentRace
|
public Race CurrentRace
|
||||||
{
|
{
|
||||||
get { return currentRace; }
|
get { return currentRace; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
currentRace = value;
|
currentRace = value;
|
||||||
CheckAll();
|
CheckAll();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public TechTree()
|
|
||||||
{
|
|
||||||
LoadRules();
|
|
||||||
CheckAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadRules()
|
|
||||||
{
|
|
||||||
var allBuildings = Rules.AllRules.GetSection( "BuildingTypes" ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
|
||||||
|
|
||||||
foreach( var unit in Rules.UnitInfo )
|
|
||||||
objects.Add( unit.Key, new Item( unit.Key, unit.Value, allBuildings.Contains( unit.Key ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Build(string key, bool force)
|
|
||||||
{
|
|
||||||
if( string.IsNullOrEmpty( key ) ) return false;
|
|
||||||
key = key.ToLowerInvariant();
|
|
||||||
Item b = objects[ key ];
|
|
||||||
if (!force && !b.CanBuild) return false;
|
|
||||||
built.Add(key);
|
|
||||||
CheckAll();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Build(string key) { return Build(key, false); }
|
public TechTree()
|
||||||
|
{
|
||||||
public bool Unbuild(string key)
|
LoadRules();
|
||||||
{
|
CheckAll();
|
||||||
key = key.ToLowerInvariant();
|
|
||||||
Item b = objects[key];
|
|
||||||
if (!built.Contains(key)) return false;
|
|
||||||
built.Remove(key);
|
|
||||||
CheckAll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckAll()
|
|
||||||
{
|
|
||||||
foreach (Item unit in objects.Values)
|
|
||||||
unit.CheckPrerequisites(built, currentRace);
|
|
||||||
|
|
||||||
BuildableItemsChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Item> BuildableItems { get { return objects.Values.Where(b => b.CanBuild); } }
|
void LoadRules()
|
||||||
public event Action BuildableItemsChanged = () => { };
|
{
|
||||||
}
|
var allBuildings = Rules.AllRules.GetSection( "BuildingTypes" ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
||||||
}
|
|
||||||
|
foreach( var unit in Rules.UnitInfo )
|
||||||
|
objects.Add( unit.Key, new Item( unit.Key, unit.Value, allBuildings.Contains( unit.Key ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Build(string key, bool force)
|
||||||
|
{
|
||||||
|
if( string.IsNullOrEmpty( key ) ) return false;
|
||||||
|
key = key.ToLowerInvariant();
|
||||||
|
Item b = objects[ key ];
|
||||||
|
if (!force && !b.CanBuild) return false;
|
||||||
|
built.Add(key);
|
||||||
|
CheckAll();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Build(string key) { return Build(key, false); }
|
||||||
|
|
||||||
|
public bool Unbuild(string key)
|
||||||
|
{
|
||||||
|
key = key.ToLowerInvariant();
|
||||||
|
Item b = objects[key];
|
||||||
|
if (!built.Contains(key)) return false;
|
||||||
|
built.Remove(key);
|
||||||
|
CheckAll();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckAll()
|
||||||
|
{
|
||||||
|
foreach (Item unit in objects.Values)
|
||||||
|
unit.CheckPrerequisites(built, currentRace);
|
||||||
|
|
||||||
|
BuildableItemsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Item> BuildableItems { get { return objects.Values.Where(b => b.CanBuild); } }
|
||||||
|
public event Action BuildableItemsChanged = () => { };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user