more infantry tweaks; sidebar mouseover shows desc & prices now

This commit is contained in:
Chris Forbes
2009-11-01 15:06:21 +13:00
parent db810105da
commit 4ada055f06
6 changed files with 48 additions and 12 deletions

View File

@@ -20,6 +20,8 @@ namespace OpenRa.Game.Graphics
Action drawFunction; Action drawFunction;
Action<MouseInput> mouseHandler; Action<MouseInput> mouseHandler;
Rectangle rect; Rectangle rect;
public bool UseScissor = true;
public bool AlwaysWantMovement = false;
static int2 MakeSize(Viewport v, DockStyle d, int size) static int2 MakeSize(Viewport v, DockStyle d, int size)
{ {
@@ -40,7 +42,6 @@ namespace OpenRa.Game.Graphics
public bool HandleMouseInput(MouseInput mi) public bool HandleMouseInput(MouseInput mi)
{ {
/* todo: route to the mousehandler once that's sorted */
if (mouseHandler != null) mouseHandler(new MouseInput if (mouseHandler != null) mouseHandler(new MouseInput
{ {
Button = mi.Button, Button = mi.Button,
@@ -83,9 +84,11 @@ namespace OpenRa.Game.Graphics
public void Draw(Renderer renderer) public void Draw(Renderer renderer)
{ {
renderer.Device.EnableScissor((int)location.X, (int)location.Y, (int)Size.X, (int)Size.Y); if (UseScissor)
renderer.Device.EnableScissor((int)location.X, (int)location.Y, (int)Size.X, (int)Size.Y);
drawFunction(); drawFunction();
renderer.Device.DisableScissor(); if (UseScissor)
renderer.Device.DisableScissor();
} }
} }
} }

View File

@@ -96,5 +96,10 @@ namespace OpenRa.Game.Graphics
fhDebug.Draw(sh, text, pos.X, pos.Y, c.ToArgb()); fhDebug.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
sh.End(); sh.End();
} }
public int2 MeasureText(string text)
{
return new int2(fhDebug.MeasureText(sh, text));
}
} }
} }

View File

@@ -74,6 +74,10 @@ namespace OpenRa.Game.Graphics
return; return;
} }
if (mi.Event == MouseInputEvent.Move)
foreach (var reg in regions.Where(r => r.AlwaysWantMovement))
reg.HandleMouseInput(mi);
dragRegion = regions.FirstOrDefault(r => r.Contains(mi.Location) && r.HandleMouseInput(mi)); dragRegion = regions.FirstOrDefault(r => r.Contains(mi.Location) && r.HandleMouseInput(mi));
if (mi.Event != MouseInputEvent.Down) if (mi.Event != MouseInputEvent.Down)
dragRegion = null; dragRegion = null;

View File

@@ -66,9 +66,8 @@ namespace OpenRa.Game
Game.world.Add(new Actor("ca", Game.map.Offset + new int2(40, 7), Game.players[1])); Game.world.Add(new Actor("ca", Game.map.Offset + new int2(40, 7), Game.players[1]));
Game.world.Add(new Actor("e1", Game.map.Offset + new int2(9, 13), Game.players[1])); Game.world.Add(new Actor("e1", Game.map.Offset + new int2(9, 13), Game.players[1]));
sidebar = new Sidebar(renderer, Game.LocalPlayer);
renderer.BuildPalette(Game.map); renderer.BuildPalette(Game.map);
sidebar = new Sidebar(renderer, Game.LocalPlayer);
ShowCursor(false); ShowCursor(false);

View File

@@ -15,6 +15,7 @@ namespace OpenRa.Game
Player player; Player player;
SpriteRenderer spriteRenderer, clockRenderer; SpriteRenderer spriteRenderer, clockRenderer;
Renderer renderer;
Sprite blank; Sprite blank;
Animation ready; Animation ready;
Animation cantBuild; Animation cantBuild;
@@ -35,7 +36,10 @@ namespace OpenRa.Game
public Sidebar( Renderer renderer, Player player ) public Sidebar( Renderer renderer, Player player )
{ {
this.player = player; this.player = player;
this.renderer = renderer;
region = GRegion.Create(Game.viewport, DockStyle.Right, 128, Paint, MouseHandler); region = GRegion.Create(Game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
region.UseScissor = false;
region.AlwaysWantMovement = true;
Game.viewport.AddRegion( region ); Game.viewport.AddRegion( region );
spriteRenderer = new SpriteRenderer(renderer, false); spriteRenderer = new SpriteRenderer(renderer, false);
clockRenderer = new SpriteRenderer(renderer, true); clockRenderer = new SpriteRenderer(renderer, true);
@@ -158,6 +162,24 @@ namespace OpenRa.Game
spriteRenderer.Flush(); spriteRenderer.Flush();
clockRenderer.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) public SidebarItem GetItem(float2 point)
@@ -174,10 +196,13 @@ namespace OpenRa.Game
return group != "Building"; return group != "Building";
} }
SidebarItem mouseOverItem;
void MouseHandler(MouseInput mi) void MouseHandler(MouseInput mi)
{ {
var point = mi.Location.ToFloat2(); var point = mi.Location.ToFloat2();
var item = GetItem( point ); var item = GetItem( point );
mouseOverItem = item;
if( item == null ) if( item == null )
return; return;

View File

@@ -53,10 +53,10 @@ namespace OpenRa.Game.Traits
string currentSequence; string currentSequence;
static int QuantizeFacingNicely(int facing, int n) static int QuantizeFacing(int facing, int n)
{ {
var step = 256 / n; var step = 256 / n;
var a = facing; var a = (facing + step/2) & 0xff;
return a / step; return a / step;
} }
@@ -65,7 +65,7 @@ namespace OpenRa.Game.Traits
if (currentSequence == seq) return; if (currentSequence == seq) return;
if (isFacing) if (isFacing)
anim.PlayFetchIndex(seq, () => QuantizeFacingNicely(facing, anim.CurrentSequence.Length)); anim.PlayFetchIndex(seq, () => QuantizeFacing(facing, anim.CurrentSequence.Length));
else else
anim.PlayRepeatingPreservingPosition(seq); anim.PlayRepeatingPreservingPosition(seq);
@@ -77,7 +77,7 @@ namespace OpenRa.Game.Traits
name = type; name = type;
anim = new Animation(type); anim = new Animation(type);
anim.PlayFetchIndex("stand", anim.PlayFetchIndex("stand",
() => facing / (256 / anim.CurrentSequence.Length) ); () => QuantizeFacing(facing, anim.CurrentSequence.Length));
location = initialLocation; location = initialLocation;
speed = ((UnitInfo.InfantryInfo)Rules.UnitInfo[name]).Speed / 2; speed = ((UnitInfo.InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
} }
@@ -87,12 +87,12 @@ namespace OpenRa.Game.Traits
anim.Tick(); anim.Tick();
var d = (desiredLocation - location); var d = (desiredLocation - location);
facing = self.traits.Get<Mobile>().facing; facing = /*Util.GetFacing(d, facing); */ self.traits.Get<Mobile>().facing;
if (float2.WithinEpsilon(d, float2.Zero, .1f)) if (float2.WithinEpsilon(d, float2.Zero, .1f))
PlaySequence("stand", true); PlaySequence("stand", true);
else else
PlaySequence("run-" + QuantizeFacingNicely(facing, 8), false); PlaySequence("run-" + QuantizeFacing(facing, 8), false);
if (d.Length <= speed) if (d.Length <= speed)
location = desiredLocation; location = desiredLocation;