sidebar is dead. long live chrome

This commit is contained in:
Chris Forbes
2009-11-17 20:32:52 +13:00
parent a2de047c9f
commit 2c05e2d6e0
6 changed files with 35 additions and 311 deletions

View File

@@ -37,7 +37,7 @@ namespace OpenRa.Game
buildPaletteRenderer = new SpriteRenderer(renderer, true); buildPaletteRenderer = new SpriteRenderer(renderer, true);
specialBinSprite = new Sprite(specialBin, new Rectangle(0, 0, 32, 192), TextureChannel.Alpha); 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);
@@ -60,7 +60,8 @@ namespace OpenRa.Game
cantBuild.PlayFetchIndex("idle", () => 0); cantBuild.PlayFetchIndex("idle", () => 0);
clockAnimations = new Cache<string, Animation>( clockAnimations = new Cache<string, Animation>(
s => { s =>
{
var anim = new Animation("clock"); var anim = new Animation("clock");
anim.PlayFetchIndex("idle", ClockAnimFrame(s)); anim.PlayFetchIndex("idle", ClockAnimFrame(s));
return anim; return anim;
@@ -127,7 +128,7 @@ namespace OpenRa.Game
} }
string currentTab = "Building"; 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<string, Sprite> sprites; Dictionary<string, Sprite> sprites;
const int NumClockFrames = 54; const int NumClockFrames = 54;
@@ -179,6 +180,13 @@ namespace OpenRa.Game
+ new float2(rect.Location) + new float2(rect.Location)
+ new float2((64 - ready.Image.size.X) / 2, 2), 0); + 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);
}
} }
var closureItem = item; var closureItem = item;

View File

@@ -10,8 +10,6 @@ namespace OpenRa.Game
{ {
readonly Renderer renderer; readonly Renderer renderer;
public readonly Sidebar sidebar;
static Size GetResolution(Settings settings) static Size GetResolution(Settings settings)
{ {
var desktopResolution = Screen.PrimaryScreen.Bounds.Size; 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])); Game.world.Add(new Actor("heli", Game.map.Offset + new int2(11, 12), Game.players[1]));
renderer.BuildPalette(Game.map); renderer.BuildPalette(Game.map);
sidebar = new Sidebar(renderer, Game.LocalPlayer);
ShowCursor(false); ShowCursor(false);
Game.ResetTimer(); Game.ResetTimer();
} }

View File

@@ -128,8 +128,6 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Graphics\Renderer.cs" /> <Compile Include="Graphics\Renderer.cs" />
<Compile Include="Support\Settings.cs" /> <Compile Include="Support\Settings.cs" />
<Compile Include="Sidebar.cs" />
<Compile Include="SidebarItem.cs" />
<Compile Include="Graphics\Sprite.cs" /> <Compile Include="Graphics\Sprite.cs" />
<Compile Include="Graphics\SpriteRenderer.cs" /> <Compile Include="Graphics\SpriteRenderer.cs" />
<Compile Include="Graphics\SpriteSheetBuilder.cs" /> <Compile Include="Graphics\SpriteSheetBuilder.cs" />

View File

@@ -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<string, Sprite> sprites = new Dictionary<string,Sprite>();
const int spriteWidth = 64, spriteHeight = 48;
static string[] groups = new string[] { "Building", "Defense", "Vehicle", "Ship", "Infantry", "Plane" };
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
List<SidebarItem> items = new List<SidebarItem>();
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<int> 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 ) );
}
}
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -100,7 +100,10 @@ namespace OpenRa.Game
* ( 25 * 60 ) /* frames per min */ /* todo: build acceleration, if we do that */ * ( 25 * 60 ) /* frames per min */ /* todo: build acceleration, if we do that */
/ 1000; / 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, order.Player.BeginProduction(group,
new ProductionItem(order.TargetString, (int)time, ui.Cost, new ProductionItem(order.TargetString, (int)time, ui.Cost,