diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 2162cc91a0..99a1cb3686 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -37,22 +37,22 @@ namespace OpenRa.Game buildPaletteRenderer = new SpriteRenderer(renderer, true); specialBinSprite = new Sprite(specialBin, new Rectangle(0, 0, 32, 192), TextureChannel.Alpha); - moneyBinSprite = new Sprite(specialBin, new Rectangle(512-320, 0, 320, 64), TextureChannel.Alpha); + moneyBinSprite = new Sprite(specialBin, new Rectangle(512 - 320, 0, 320, 32), TextureChannel.Alpha); - blank = SheetBuilder.Add(new Size(64,48), 16); + blank = SheetBuilder.Add(new Size(64, 48), 16); sprites = groups .SelectMany(g => Rules.Categories[g]) .Where(u => Rules.UnitInfo[u].TechLevel != -1) .ToDictionary( - u => u, + u => u, u => SpriteSheetBuilder.LoadSprite(u + "icon", ".shp")); tabSprites = groups.Select( - (g, i) => Pair.New(g, - Util.MakeArray(3, - n => new Sprite(specialBin, - new Rectangle(512 - (n+1) * 27, 64 + i * 40, 27, 40), + (g, i) => Pair.New(g, + Util.MakeArray(3, + n => new Sprite(specialBin, + new Rectangle(512 - (n + 1) * 27, 64 + i * 40, 27, 40), TextureChannel.Alpha)))) .ToDictionary(a => a.First, a => a.Second); @@ -60,16 +60,17 @@ namespace OpenRa.Game cantBuild.PlayFetchIndex("idle", () => 0); clockAnimations = new Cache( - s => { - var anim = new Animation("clock"); - anim.PlayFetchIndex("idle", ClockAnimFrame(s)); - return anim; + s => + { + var anim = new Animation("clock"); + anim.PlayFetchIndex("idle", ClockAnimFrame(s)); + return anim; }); digitSprites = Util.MakeArray(10, a => a) .Select(n => new Sprite(specialBin, new Rectangle(32 + 13 * n, 0, 13, 17), TextureChannel.Alpha)).ToList(); - shimSprites = new [] + shimSprites = new[] { new Sprite( specialBin, new Rectangle( 0, 192, 192 +9, 10 ), TextureChannel.Alpha ), new Sprite( specialBin, new Rectangle( 0, 202, 192 +9, 10 ), TextureChannel.Alpha ), @@ -97,19 +98,19 @@ namespace OpenRa.Game PerfHistory.Render(renderer, Game.worldRenderer.lineRenderer); chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, 0); - chromeRenderer.DrawSprite(moneyBinSprite, new float2( Game.viewport.Width - 320, 0 ), 0); + chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), 0); var moneyDigits = Game.LocalPlayer.Cash.ToString(); var x = Game.viewport.Width - 155; - foreach( var d in moneyDigits.Reverse() ) + foreach (var d in moneyDigits.Reverse()) { - chromeRenderer.DrawSprite(digitSprites[d - '0'], new float2(x,6), 0); + chromeRenderer.DrawSprite(digitSprites[d - '0'], new float2(x, 6), 0); x -= 14; } x = Game.viewport.Width - 36 - 3 * 64; var y = 40; - + foreach (var q in tabSprites) { var groupName = q.Key; @@ -127,7 +128,7 @@ namespace OpenRa.Game } string currentTab = "Building"; - static string[] groups = new string[] { "Building", "Defense", "Vehicle", "Ship", "Infantry", "Plane" }; + static string[] groups = new string[] { "Building", "Defense", "Infantry", "Vehicle", "Plane", "Ship" }; Dictionary sprites; const int NumClockFrames = 54; @@ -153,8 +154,8 @@ namespace OpenRa.Game return; var allItems = Rules.TechTree.AllItems(Game.LocalPlayer, queueName) - .Where( a => Rules.UnitInfo[a].TechLevel != -1 ) - .OrderBy( a => Rules.UnitInfo[a].TechLevel ); + .Where(a => Rules.UnitInfo[a].TechLevel != -1) + .OrderBy(a => Rules.UnitInfo[a].TechLevel); var currentItem = Game.LocalPlayer.Producing(queueName); @@ -175,8 +176,15 @@ namespace OpenRa.Game if (currentItem.Done) { ready.Play("ready"); - buildPaletteRenderer.DrawSprite(ready.Image, Game.viewport.Location - + new float2(rect.Location) + buildPaletteRenderer.DrawSprite(ready.Image, Game.viewport.Location + + new float2(rect.Location) + + new float2((64 - ready.Image.size.X) / 2, 2), 0); + } + else if (currentItem.Paused) + { + ready.Play("hold"); + buildPaletteRenderer.DrawSprite(ready.Image, Game.viewport.Location + + new float2(rect.Location) + new float2((64 - ready.Image.size.X) / 2, 2), 0); } } @@ -187,7 +195,7 @@ namespace OpenRa.Game if (++x == 3) { x = 0; y++; } } - while( x != 0) + while (x != 0) { var rect = new Rectangle(Game.viewport.Width - (3 - x) * 64, 40 + 48 * y, 64, 48); buildPaletteRenderer.DrawSprite(blank, Game.viewport.Location + new float2(rect.Location), 0); @@ -254,7 +262,7 @@ namespace OpenRa.Game public bool HandleInput(MouseInput mi) { var action = buildItems.Where(a => a.First.Contains(mi.Location.ToPoint())) - .Select( a => a.Second ).FirstOrDefault(); + .Select(a => a.Second).FirstOrDefault(); if (action == null) return false; diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index dff4bfe9f7..4328be5b9e 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -10,8 +10,6 @@ namespace OpenRa.Game { readonly Renderer renderer; - public readonly Sidebar sidebar; - static Size GetResolution(Settings settings) { var desktopResolution = Screen.PrimaryScreen.Bounds.Size; @@ -72,10 +70,7 @@ namespace OpenRa.Game Game.world.Add(new Actor("heli", Game.map.Offset + new int2(11, 12), Game.players[1])); renderer.BuildPalette(Game.map); - sidebar = new Sidebar(renderer, Game.LocalPlayer); - ShowCursor(false); - Game.ResetTimer(); } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 4325aef1e4..5f729c2e55 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -128,8 +128,6 @@ - - diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs deleted file mode 100644 index c0d679d728..0000000000 --- a/OpenRa.Game/Sidebar.cs +++ /dev/null @@ -1,244 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Windows.Forms; -using OpenRa.FileFormats; -using OpenRa.Game.Graphics; -using System.Linq; - -namespace OpenRa.Game -{ - class Sidebar - { - Player player; - - SpriteRenderer spriteRenderer, clockRenderer; - Renderer renderer; - Sprite blank; - Animation ready; - Animation cantBuild; - public float Width { get { return spriteWidth * 2; } } - - Dictionary sprites = new Dictionary(); - const int spriteWidth = 64, spriteHeight = 48; - - static string[] groups = new string[] { "Building", "Defense", "Vehicle", "Ship", "Infantry", "Plane" }; - - Dictionary clockAnimations = new Dictionary(); //group->clockAnimation - - List items = new List(); - - public Sidebar( Renderer renderer, Player player ) - { - //this.player = player; - //this.renderer = renderer; - //region = GRegion.Create(Game.viewport, DockStyle.Right, /*128*/0, Paint, MouseHandler); - //region.UseScissor = false; - //region.AlwaysWantMovement = true; - //Game.viewport.AddRegion( region ); - //spriteRenderer = new SpriteRenderer(renderer, false); - //clockRenderer = new SpriteRenderer(renderer, true); - - //for( int i = 0 ; i < groups.Length ; i++ ) - // LoadSprites( groups[ i ] ); - - //foreach (string group in groups) - //{ - // clockAnimations.Add( group, new Animation( "clock" ) ); - // clockAnimations[ group ].PlayFetchIndex( "idle", ClockAnimFrame( group ) ); - //} - - //blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16); - //ready = new Animation("pips"); - //ready.PlayRepeating("ready"); - - //cantBuild = new Animation("clock"); - //cantBuild.PlayFetchIndex("idle", () => 0); - } - - const int NumClockFrames = 54; - Func ClockAnimFrame( string group ) - { - return () => - { - var producing = player.Producing( group ); - if( producing == null ) return 0; - return ( producing.TotalTime - producing.RemainingTime ) * NumClockFrames / producing.TotalTime; - }; - } - - public void Build( SidebarItem item ) - { - if( item == null ) return; - - if( item.IsStructure ) - Game.controller.orderGenerator = new PlaceBuilding( player, - item.Tag.ToLowerInvariant() ); - } - - void LoadSprites( string group ) - { - foreach( var u in Rules.Categories[ group ] ) - { - var unit = Rules.UnitInfo[ u ]; - - if( unit.TechLevel != -1 ) - sprites.Add( unit.Name, SpriteSheetBuilder.LoadSprite( unit.Name + "icon", ".shp" ) ); - } - } - - void DrawSprite(Sprite s, ref float2 p) - { - spriteRenderer.DrawSprite(s, p, 0); - p.Y += spriteHeight; - } - - void Fill(float height, float2 p) - { - while (p.Y < height) - DrawSprite(blank, ref p); - } - - int buildPos = 0; - int unitPos = 0; - - void PopulateItemList() - { - buildPos = 0; unitPos = 0; - - items.Clear(); - - foreach (var i in Rules.TechTree.BuildableItems(player, "Building")) - { - Sprite sprite; - if (!sprites.TryGetValue(i, out sprite)) continue; - items.Add(new SidebarItem(sprite, i, true, buildPos)); - buildPos += spriteHeight; - } - - foreach( var i in Rules.TechTree.BuildableItems( player, "Vehicle", "Infantry", "Ship", "Plane" ) ) - { - Sprite sprite; - if( !sprites.TryGetValue( i, out sprite ) ) continue; - items.Add( new SidebarItem( sprite, i, false, unitPos ) ); - unitPos += spriteHeight; - } - } - - void Paint() - { - //PopulateItemList(); - - ////foreach( var i in items ) /* draw the buttons */ - //// i.Paint(spriteRenderer, region.Location); - //spriteRenderer.Flush(); - - //foreach( var i in items ) /* draw the status overlays */ - //{ - // var group = Rules.UnitCategory[ i.Tag ]; - // var producing = player.Producing( group ); - // if( producing != null && producing.Item == i.Tag ) - // { - // clockAnimations[ group ].Tick(); - // clockRenderer.DrawSprite( clockAnimations[ group ].Image, region.Location.ToFloat2() + i.location, 0 ); - - // if (producing.Done) - // { - // ready.Play("ready"); - // clockRenderer.DrawSprite(ready.Image, region.Location.ToFloat2() + i.location + new float2((64 - ready.Image.size.X) / 2, 2), 0); - // } - // else if (producing.Paused) - // { - // ready.Play("hold"); - // clockRenderer.DrawSprite(ready.Image, region.Location.ToFloat2() + i.location + new float2((64 - ready.Image.size.X) / 2, 2), 0); - // } - // } - // else if (producing != null) - // clockRenderer.DrawSprite(cantBuild.Image, region.Location.ToFloat2() + i.location, 0); - //} - - //Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X, buildPos + region.Location.Y)); - //Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X + spriteWidth, unitPos + region.Location.Y)); - - //spriteRenderer.Flush(); - //clockRenderer.Flush(); - - //if (mouseOverItem != null) - //{ - // /* draw the sidebar help for this item */ - // /* todo: draw a solid background of the appropriate color */ - // var ui = Rules.UnitInfo[mouseOverItem.Tag]; - // var text = string.Format(ui.Cost > 0 ? "{0} ($ {1})" : "{0}", /* abilities! */ - // ui.Description, ui.Cost); - - // var size = renderer.MeasureText(text); - - // var pos = region.Position + mouseOverItem.location.ToInt2() -new int2(size.X+ 10, 0); - // renderer.DrawText( text, pos + new int2(0,-1), Color.Black ); - // renderer.DrawText(text, pos + new int2(0, 1), Color.Black); - // renderer.DrawText(text, pos + new int2(1, 0), Color.Black); - // renderer.DrawText(text, pos + new int2(-1, 0), Color.Black); - // renderer.DrawText(text, pos , Color.White); - //} - } - - public SidebarItem GetItem(float2 point) - { - foreach (SidebarItem i in items) - if (i.Clicked(point)) - return i; - - return null; - } - - SidebarItem mouseOverItem; - - void MouseHandler(MouseInput mi) - { - var point = mi.Location.ToFloat2(); - var item = GetItem( point ); - mouseOverItem = item; - if( item == null ) - return; - - string group = Rules.UnitCategory[item.Tag]; - var producing = player.Producing(group); - - if( mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down ) - { - if (producing == null) - { - Game.controller.AddOrder( Order.StartProduction( player, item.Tag ) ); - Game.PlaySound("abldgin1.aud", false); - } - else if (producing.Item == item.Tag) - { - if (producing.Done) - Build(item); - else - Game.controller.AddOrder( Order.PauseProduction( player, item.Tag, false ) ); - } - else - { - Game.PlaySound("progres1.aud", false); - } - } - else if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down) - { - if( producing == null ) return; - if (item.Tag != producing.Item) return; - - if (producing.Paused || producing.Done) - { - Game.PlaySound("cancld1.aud", false); - Game.controller.AddOrder( Order.CancelProduction( player, item.Tag ) ); - } - else - { - Game.PlaySound("onhold1.aud", false); - Game.controller.AddOrder( Order.PauseProduction( player, item.Tag, true ) ); - } - } - } - } -} diff --git a/OpenRa.Game/SidebarItem.cs b/OpenRa.Game/SidebarItem.cs deleted file mode 100644 index 784a80df03..0000000000 --- a/OpenRa.Game/SidebarItem.cs +++ /dev/null @@ -1,36 +0,0 @@ -using OpenRa.Game.Graphics; - -namespace OpenRa.Game -{ - class SidebarItem - { - public readonly float2 location; - public readonly string Tag; - public readonly bool IsStructure; - readonly Sprite sprite; - - public SidebarItem(Sprite s, string tag, bool isStructure, int y) - { - this.sprite = s; - this.Tag = tag; - this.IsStructure = isStructure; - location = new float2(isStructure ? 0 : 64, y); - } - - public bool Clicked(float2 p) - { - if (p.X < location.X || p.Y < location.Y) - return false; - - if (p.X > location.X + 64 || p.Y > location.Y + 48) - return false; - - return true; - } - - public void Paint(SpriteRenderer renderer, float2 offset) - { - renderer.DrawSprite(sprite, location + offset, 0); - } - } -} diff --git a/OpenRa.Game/UnitOrders.cs b/OpenRa.Game/UnitOrders.cs index 7b0ec8c734..6486e4aa57 100755 --- a/OpenRa.Game/UnitOrders.cs +++ b/OpenRa.Game/UnitOrders.cs @@ -100,7 +100,10 @@ namespace OpenRa.Game * ( 25 * 60 ) /* frames per min */ /* todo: build acceleration, if we do that */ / 1000; - time = .01f * time; /* temporary hax so we can build stuff fast for test */ + time = .08f * time; /* temporary hax so we can build stuff fast for test */ + + if (!Rules.TechTree.BuildableItems(order.Player, group).Contains(order.TargetString)) + return; /* you can't build that!! */ order.Player.BeginProduction(group, new ProductionItem(order.TargetString, (int)time, ui.Cost,