Region is dead. long live IHandleInput. also tab-switching in chrome
This commit is contained in:
@@ -105,16 +105,20 @@ namespace OpenRa.Game
|
||||
|
||||
foreach (var q in tabSprites)
|
||||
{
|
||||
var groupName = q.Key;
|
||||
if (!Rules.TechTree.BuildableItems(Game.LocalPlayer, q.Key).Any()) continue;
|
||||
var index = q.Key == "Building" ? 2 : 0;
|
||||
var index = q.Key == currentTab ? 2 : 0;
|
||||
chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), 0);
|
||||
|
||||
buildItems.Add(Pair.New(new Rectangle(x, y, 27, 40), (Action<bool>)(isLmb => currentTab = groupName)));
|
||||
y += 40;
|
||||
}
|
||||
|
||||
chromeRenderer.Flush();
|
||||
DrawBuildPalette("Building");
|
||||
DrawBuildPalette(currentTab);
|
||||
}
|
||||
|
||||
string currentTab = "Building";
|
||||
static string[] groups = new string[] { "Building", "Defense", "Vehicle", "Ship", "Infantry", "Plane" };
|
||||
Dictionary<string, Sprite> sprites;
|
||||
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenRa.Game.Graphics
|
||||
{
|
||||
class Region
|
||||
{
|
||||
int2 location;
|
||||
Viewport viewport;
|
||||
|
||||
public int2 Location
|
||||
{
|
||||
get { return location + new int2( (int)viewport.Location.X, (int)viewport.Location.Y ); } // WTF HACK HACK HACK
|
||||
}
|
||||
|
||||
public int2 Position { get { return location; } }
|
||||
public readonly float2 Size;
|
||||
|
||||
Action drawFunction;
|
||||
Action<MouseInput> mouseHandler;
|
||||
Rectangle rect;
|
||||
public bool UseScissor = true;
|
||||
public bool AlwaysWantMovement = false;
|
||||
|
||||
static int2 MakeSize(Viewport v, DockStyle d, int size)
|
||||
{
|
||||
switch (d)
|
||||
{
|
||||
case DockStyle.Top:
|
||||
case DockStyle.Bottom:
|
||||
return new int2(v.Width, size);
|
||||
|
||||
case DockStyle.Left:
|
||||
case DockStyle.Right:
|
||||
return new int2(size, v.Height);
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mouseHandler != null) mouseHandler(new MouseInput
|
||||
{
|
||||
Button = mi.Button,
|
||||
Event = mi.Event,
|
||||
Location = mi.Location - location
|
||||
});
|
||||
return mouseHandler != null;
|
||||
}
|
||||
|
||||
public static Region Create(Viewport v, DockStyle d, int size, Action f, Action<MouseInput> m)
|
||||
{
|
||||
int2 s = MakeSize(v, d, size);
|
||||
|
||||
switch (d)
|
||||
{
|
||||
case DockStyle.Top:
|
||||
case DockStyle.Left:
|
||||
return new Region(int2.Zero, s, v, f, m);
|
||||
|
||||
case DockStyle.Right:
|
||||
case DockStyle.Bottom:
|
||||
return new Region(new int2( v.Width - s.X, v.Height - s.Y ), s, v, f, m);
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
Region(int2 location, int2 size, Viewport viewport, Action drawFunction, Action<MouseInput> mouseHandler)
|
||||
{
|
||||
this.location = location;
|
||||
this.Size = size;
|
||||
this.drawFunction = drawFunction;
|
||||
this.viewport = viewport;
|
||||
this.mouseHandler = mouseHandler;
|
||||
rect = new Rectangle(location.X, location.Y, size.X, size.Y);
|
||||
}
|
||||
|
||||
public bool Contains(int2 point) { return rect.Contains(point.ToPoint()); }
|
||||
|
||||
public void Draw(Renderer renderer)
|
||||
{
|
||||
if (UseScissor)
|
||||
renderer.Device.EnableScissor((int)location.X, (int)location.Y, (int)Size.X, (int)Size.Y);
|
||||
drawFunction();
|
||||
if (UseScissor)
|
||||
renderer.Device.DisableScissor();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user