more infantry tweaks; sidebar mouseover shows desc & prices now
This commit is contained in:
@@ -20,6 +20,8 @@ namespace OpenRa.Game.Graphics
|
||||
Action drawFunction;
|
||||
Action<MouseInput> mouseHandler;
|
||||
Rectangle rect;
|
||||
public bool UseScissor = true;
|
||||
public bool AlwaysWantMovement = false;
|
||||
|
||||
static int2 MakeSize(Viewport v, DockStyle d, int size)
|
||||
{
|
||||
@@ -40,7 +42,6 @@ namespace OpenRa.Game.Graphics
|
||||
|
||||
public bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
/* todo: route to the mousehandler once that's sorted */
|
||||
if (mouseHandler != null) mouseHandler(new MouseInput
|
||||
{
|
||||
Button = mi.Button,
|
||||
@@ -83,9 +84,11 @@ namespace OpenRa.Game.Graphics
|
||||
|
||||
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();
|
||||
renderer.Device.DisableScissor();
|
||||
if (UseScissor)
|
||||
renderer.Device.DisableScissor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,5 +96,10 @@ namespace OpenRa.Game.Graphics
|
||||
fhDebug.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
|
||||
sh.End();
|
||||
}
|
||||
|
||||
public int2 MeasureText(string text)
|
||||
{
|
||||
return new int2(fhDebug.MeasureText(sh, text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ namespace OpenRa.Game.Graphics
|
||||
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));
|
||||
if (mi.Event != MouseInputEvent.Down)
|
||||
dragRegion = null;
|
||||
|
||||
@@ -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("e1", Game.map.Offset + new int2(9, 13), Game.players[1]));
|
||||
|
||||
sidebar = new Sidebar(renderer, Game.LocalPlayer);
|
||||
|
||||
renderer.BuildPalette(Game.map);
|
||||
sidebar = new Sidebar(renderer, Game.LocalPlayer);
|
||||
|
||||
ShowCursor(false);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace OpenRa.Game
|
||||
Player player;
|
||||
|
||||
SpriteRenderer spriteRenderer, clockRenderer;
|
||||
Renderer renderer;
|
||||
Sprite blank;
|
||||
Animation ready;
|
||||
Animation cantBuild;
|
||||
@@ -35,7 +36,10 @@ namespace OpenRa.Game
|
||||
public Sidebar( Renderer renderer, Player player )
|
||||
{
|
||||
this.player = player;
|
||||
this.renderer = renderer;
|
||||
region = GRegion.Create(Game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
||||
region.UseScissor = false;
|
||||
region.AlwaysWantMovement = true;
|
||||
Game.viewport.AddRegion( region );
|
||||
spriteRenderer = new SpriteRenderer(renderer, false);
|
||||
clockRenderer = new SpriteRenderer(renderer, true);
|
||||
@@ -158,6 +162,24 @@ namespace OpenRa.Game
|
||||
|
||||
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)
|
||||
@@ -174,10 +196,13 @@ namespace OpenRa.Game
|
||||
return group != "Building";
|
||||
}
|
||||
|
||||
SidebarItem mouseOverItem;
|
||||
|
||||
void MouseHandler(MouseInput mi)
|
||||
{
|
||||
var point = mi.Location.ToFloat2();
|
||||
var item = GetItem( point );
|
||||
mouseOverItem = item;
|
||||
if( item == null )
|
||||
return;
|
||||
|
||||
|
||||
@@ -53,10 +53,10 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
string currentSequence;
|
||||
|
||||
static int QuantizeFacingNicely(int facing, int n)
|
||||
static int QuantizeFacing(int facing, int n)
|
||||
{
|
||||
var step = 256 / n;
|
||||
var a = facing;
|
||||
var a = (facing + step/2) & 0xff;
|
||||
return a / step;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace OpenRa.Game.Traits
|
||||
if (currentSequence == seq) return;
|
||||
|
||||
if (isFacing)
|
||||
anim.PlayFetchIndex(seq, () => QuantizeFacingNicely(facing, anim.CurrentSequence.Length));
|
||||
anim.PlayFetchIndex(seq, () => QuantizeFacing(facing, anim.CurrentSequence.Length));
|
||||
else
|
||||
anim.PlayRepeatingPreservingPosition(seq);
|
||||
|
||||
@@ -76,8 +76,8 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
name = type;
|
||||
anim = new Animation(type);
|
||||
anim.PlayFetchIndex("stand",
|
||||
() => facing / (256 / anim.CurrentSequence.Length) );
|
||||
anim.PlayFetchIndex("stand",
|
||||
() => QuantizeFacing(facing, anim.CurrentSequence.Length));
|
||||
location = initialLocation;
|
||||
speed = ((UnitInfo.InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
|
||||
}
|
||||
@@ -87,12 +87,12 @@ namespace OpenRa.Game.Traits
|
||||
anim.Tick();
|
||||
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))
|
||||
PlaySequence("stand", true);
|
||||
else
|
||||
PlaySequence("run-" + QuantizeFacingNicely(facing, 8), false);
|
||||
PlaySequence("run-" + QuantizeFacing(facing, 8), false);
|
||||
|
||||
if (d.Length <= speed)
|
||||
location = desiredLocation;
|
||||
|
||||
Reference in New Issue
Block a user