refactoring Widget

This commit is contained in:
Bob
2010-05-25 11:44:57 +12:00
parent ac10ca3fad
commit 8285c7d158
16 changed files with 30 additions and 76 deletions

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Graphics
bool gameWasStarted = false; bool gameWasStarted = false;
public void DrawRegions( World world ) public void DrawRegions( World world )
{ {
// Timer.Time( "DrawRegions start" ); Timer.Time( "DrawRegions start" );
world.WorldRenderer.palette.Update( world.WorldRenderer.palette.Update(
world.WorldActor.traits.WithInterface<IPaletteModifier>()); world.WorldActor.traits.WithInterface<IPaletteModifier>());
@@ -78,7 +78,7 @@ namespace OpenRA.Graphics
renderer.BeginFrame(r1, r2, scrollPosition.ToInt2()); renderer.BeginFrame(r1, r2, scrollPosition.ToInt2());
world.WorldRenderer.Draw(); world.WorldRenderer.Draw();
// Timer.Time( "worldRenderer: {0}" ); Timer.Time( "worldRenderer: {0}" );
if( Game.orderManager.GameStarted && world.LocalPlayer != null) if( Game.orderManager.GameStarted && world.LocalPlayer != null)
{ {
if (!gameWasStarted) if (!gameWasStarted)
@@ -88,6 +88,7 @@ namespace OpenRA.Graphics
} }
Game.chrome.Draw( world ); Game.chrome.Draw( world );
Timer.Time( "chromedraw: {0}" );
} }
else else
{ {
@@ -128,6 +129,7 @@ namespace OpenRA.Graphics
lastConnectionState = state; lastConnectionState = state;
Timer.Time( "connectionState: {0}" );
} }
Game.chrome.DrawWidgets(world); Game.chrome.DrawWidgets(world);
if (Chrome.rootWidget.GetWidget("SERVER_LOBBY").Visible) if (Chrome.rootWidget.GetWidget("SERVER_LOBBY").Visible)
@@ -135,19 +137,19 @@ namespace OpenRA.Graphics
else if (Chrome.rootWidget.GetWidget("MAP_CHOOSER").Visible) else if (Chrome.rootWidget.GetWidget("MAP_CHOOSER").Visible)
Game.chrome.DrawMapChooser(); Game.chrome.DrawMapChooser();
// Timer.Time( "widgets: {0}" ); Timer.Time( "widgets: {0}" );
var cursorName = Game.chrome.HitTest(mousePos) ? "default" : Game.controller.ChooseCursor( world ); var cursorName = Game.chrome.HitTest(mousePos) ? "default" : Game.controller.ChooseCursor( world );
var c = new Cursor(cursorName); var c = new Cursor(cursorName);
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor"); cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor");
// Timer.Time( "cursors: {0}" ); Timer.Time( "cursors: {0}" );
renderer.RgbaSpriteRenderer.Flush(); renderer.RgbaSpriteRenderer.Flush();
renderer.SpriteRenderer.Flush(); renderer.SpriteRenderer.Flush();
renderer.WorldSpriteRenderer.Flush(); renderer.WorldSpriteRenderer.Flush();
renderer.EndFrame(); renderer.EndFrame();
// Timer.Time( "endFrame: {0}" ); Timer.Time( "endFrame: {0}" );
} }
public void Tick() public void Tick()

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Traits
{ {
public class ShroudInfo : ITraitInfo public class ShroudInfo : ITraitInfo
{ {
public object Create(Actor self) { return new Shroud(self, this); } public object Create(Actor self) { return new Shroud(self); }
} }
public class Shroud public class Shroud
@@ -41,7 +41,7 @@ namespace OpenRA.Traits
public Rectangle? exploredBounds; public Rectangle? exploredBounds;
public event Action Dirty = () => { }; public event Action Dirty = () => { };
public Shroud(Actor self, ShroudInfo info) public Shroud(Actor self)
{ {
map = self.World.Map; map = self.World.Map;
visibleCells = new int[map.MapSize.X, map.MapSize.Y]; visibleCells = new int[map.MapSize.X, map.MapSize.Y];

View File

@@ -25,17 +25,11 @@ namespace OpenRA.Widgets
{ {
public readonly string Background = "dialog"; public readonly string Background = "dialog";
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (!IsVisible())
{
base.Draw(world);
return;
}
var pos = DrawPosition(); var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
WidgetUtils.DrawPanel(Background, rect); WidgetUtils.DrawPanel(Background, rect);
base.Draw(world);
} }
public BackgroundWidget() : base() { } public BackgroundWidget() : base() { }

View File

@@ -171,7 +171,7 @@ namespace OpenRA.Widgets
return false; return false;
} }
public override void Draw (World world) public override void DrawInner(World world)
{ {
int paletteHeight = DrawPalette(world, currentTab); int paletteHeight = DrawPalette(world, currentTab);
DrawBuildTabs(world, paletteHeight); DrawBuildTabs(world, paletteHeight);
@@ -181,11 +181,6 @@ namespace OpenRA.Widgets
{ {
string paletteCollection = "palette-" + world.LocalPlayer.Country.Race; string paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
if (!Visible)
{
base.Draw(world);
return 0;
}
buttons.Clear(); buttons.Clear();

View File

@@ -79,13 +79,8 @@ namespace OpenRA.Widgets
return false; return false;
} }
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (!IsVisible())
{
base.Draw(world);
return;
}
var pos = DrawPosition(); var pos = DrawPosition();
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
@@ -97,8 +92,6 @@ namespace OpenRA.Widgets
new int2( pos.X + Bounds.Width / 2, pos.Y + Bounds.Height / 2) new int2( pos.X + Bounds.Width / 2, pos.Y + Bounds.Height / 2)
- new int2(Game.chrome.renderer.BoldFont.Measure(text).X / 2, - new int2(Game.chrome.renderer.BoldFont.Measure(text).X / 2,
Game.chrome.renderer.BoldFont.Measure(text).Y / 2) + stateOffset, Color.White); Game.chrome.renderer.BoldFont.Measure(text).Y / 2) + stateOffset, Color.White);
base.Draw(world);
} }
public override Widget Clone() public override Widget Clone()

View File

@@ -28,13 +28,8 @@ namespace OpenRA.Widgets
public string Text = ""; public string Text = "";
public Func<bool> Checked = () => {return false;}; public Func<bool> Checked = () => {return false;};
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (!IsVisible())
{
base.Draw(world);
return;
}
var pos = DrawPosition(); var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location, WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location,
@@ -56,8 +51,6 @@ namespace OpenRA.Widgets
Color.White); Color.White);
Game.chrome.lineRenderer.Flush(); Game.chrome.lineRenderer.Flush();
} }
base.Draw(world);
} }
public CheckboxWidget() : base() { } public CheckboxWidget() : base() { }

View File

@@ -44,18 +44,11 @@ namespace OpenRA.Widgets
return new ColorBlockWidget(this); return new ColorBlockWidget(this);
} }
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (!IsVisible())
{
base.Draw(world);
return;
}
var pos = DrawPosition(); var pos = DrawPosition();
var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height); var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
Game.chrome.lineRenderer.FillRect(paletteRect, GetColor()); Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
base.Draw(world);
} }
} }
} }

View File

@@ -52,14 +52,8 @@ namespace OpenRA.Widgets
GetText = (other as LabelWidget).GetText; GetText = (other as LabelWidget).GetText;
} }
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (!IsVisible())
{
base.Draw(world);
return;
}
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont; var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
var text = GetText(); var text = GetText();
int2 textSize = font.Measure(text); int2 textSize = font.Measure(text);
@@ -69,7 +63,6 @@ namespace OpenRA.Widgets
position += new int2((Bounds.Width - textSize.X)/2, 0); position += new int2((Bounds.Width - textSize.X)/2, 0);
font.DrawText(text, position, Color.White); font.DrawText(text, position, Color.White);
base.Draw(world);
} }
public override Widget Clone() public override Widget Clone()

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new MapPreviewWidget(this); } public override Widget Clone() { return new MapPreviewWidget(this); }
public override void Draw( World world ) public override void DrawInner( World world )
{ {
var map = Game.chrome.currentMap; var map = Game.chrome.currentMap;
if( map == null ) return; if( map == null ) return;
@@ -55,7 +55,6 @@ namespace OpenRA.Widgets
new float2( mapRect.Size ) ); new float2( mapRect.Size ) );
DrawSpawnPoints( map, new Rectangle(pos.X, pos.Y, Parent.Bounds.Width, Parent.Bounds.Height ), world ); DrawSpawnPoints( map, new Rectangle(pos.X, pos.Y, Parent.Bounds.Width, Parent.Bounds.Height ), world );
base.Draw( world );
} }
void DrawSpawnPoints(MapStub map, Rectangle container, World world) void DrawSpawnPoints(MapStub map, Rectangle container, World world)

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new MoneyBinWidget(this); } public override Widget Clone() { return new MoneyBinWidget(this); }
public override void Draw(World world) public override void DrawInner(World world)
{ {
var playerResources = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>(); var playerResources = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();

View File

@@ -32,13 +32,8 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new PerfGraphWidget(this); } public override Widget Clone() { return new PerfGraphWidget(this); }
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (!IsVisible())
{
base.Draw(world);
return;
}
var pos = DrawPosition(); var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom); float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom);
@@ -62,8 +57,6 @@ namespace OpenRA.Widgets
} }
Game.chrome.lineRenderer.Flush(); Game.chrome.lineRenderer.Flush();
base.Draw(world);
} }
} }
} }

View File

@@ -36,10 +36,8 @@ namespace OpenRA.Widgets
// todo: all this shit needs to move, probably to Player. // todo: all this shit needs to move, probably to Player.
public override void Draw(World world) public override void DrawInner(World world)
{ {
base.Draw(world);
if (world.LocalPlayer == null) return; if (world.LocalPlayer == null) return;
if (world.players.Count > 2) /* more than just us + neutral */ if (world.players.Count > 2) /* more than just us + neutral */

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning RadarBin?"); } public override Widget Clone() { throw new NotImplementedException("Why are you Cloning RadarBin?"); }
public override void Draw(World world) public override void DrawInner(World world)
{ {
DrawRadar(world); DrawRadar(world);
DrawPower(world); DrawPower(world);

View File

@@ -80,13 +80,8 @@ namespace OpenRA.Widgets
return false; return false;
} }
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (!Visible)
{
base.Draw(world);
return;
}
buttons.Clear(); buttons.Clear();
var powers = world.LocalPlayer.PlayerActor.traits.WithInterface<SupportPower>(); var powers = world.LocalPlayer.PlayerActor.traits.WithInterface<SupportPower>();
@@ -170,7 +165,6 @@ namespace OpenRA.Widgets
} }
} }
Game.chrome.renderer.WorldSpriteRenderer.Flush(); Game.chrome.renderer.WorldSpriteRenderer.Flush();
base.Draw(world);
} }
Action<MouseInput> HandleSupportPower(SupportPower sp) Action<MouseInput> HandleSupportPower(SupportPower sp)

View File

@@ -167,12 +167,17 @@ namespace OpenRA.Widgets
throw new InvalidOperationException("Impossible"); throw new InvalidOperationException("Impossible");
} }
public virtual void Draw(World world) public abstract void DrawInner( World world );
public void Draw(World world)
{ {
if (IsVisible()) if (IsVisible())
{
DrawInner( world );
foreach (var child in Children) foreach (var child in Children)
child.Draw(world); child.Draw(world);
} }
}
public virtual void Tick(World world) public virtual void Tick(World world)
{ {
@@ -229,6 +234,8 @@ namespace OpenRA.Widgets
public ContainerWidget(Widget other) : base(other) { } public ContainerWidget(Widget other) : base(other) { }
public override void DrawInner( World world ) { }
public override Widget Clone() { return new ContainerWidget(this); } public override Widget Clone() { return new ContainerWidget(this); }
} }
public interface IWidgetDelegate { } public interface IWidgetDelegate { }

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new WorldTooltipWidget(this); } public override Widget Clone() { return new WorldTooltipWidget(this); }
public override void Draw(World world) public override void DrawInner(World world)
{ {
if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null) if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null)
return; return;