refactoring Widget
This commit is contained in:
@@ -68,7 +68,7 @@ namespace OpenRA.Graphics
|
||||
bool gameWasStarted = false;
|
||||
public void DrawRegions( World world )
|
||||
{
|
||||
// Timer.Time( "DrawRegions start" );
|
||||
Timer.Time( "DrawRegions start" );
|
||||
|
||||
world.WorldRenderer.palette.Update(
|
||||
world.WorldActor.traits.WithInterface<IPaletteModifier>());
|
||||
@@ -78,7 +78,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
renderer.BeginFrame(r1, r2, scrollPosition.ToInt2());
|
||||
world.WorldRenderer.Draw();
|
||||
// Timer.Time( "worldRenderer: {0}" );
|
||||
Timer.Time( "worldRenderer: {0}" );
|
||||
if( Game.orderManager.GameStarted && world.LocalPlayer != null)
|
||||
{
|
||||
if (!gameWasStarted)
|
||||
@@ -88,6 +88,7 @@ namespace OpenRA.Graphics
|
||||
}
|
||||
|
||||
Game.chrome.Draw( world );
|
||||
Timer.Time( "chromedraw: {0}" );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -128,6 +129,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
lastConnectionState = state;
|
||||
|
||||
Timer.Time( "connectionState: {0}" );
|
||||
}
|
||||
Game.chrome.DrawWidgets(world);
|
||||
if (Chrome.rootWidget.GetWidget("SERVER_LOBBY").Visible)
|
||||
@@ -135,19 +137,19 @@ namespace OpenRA.Graphics
|
||||
else if (Chrome.rootWidget.GetWidget("MAP_CHOOSER").Visible)
|
||||
Game.chrome.DrawMapChooser();
|
||||
|
||||
// Timer.Time( "widgets: {0}" );
|
||||
Timer.Time( "widgets: {0}" );
|
||||
|
||||
var cursorName = Game.chrome.HitTest(mousePos) ? "default" : Game.controller.ChooseCursor( world );
|
||||
var c = new Cursor(cursorName);
|
||||
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor");
|
||||
// Timer.Time( "cursors: {0}" );
|
||||
Timer.Time( "cursors: {0}" );
|
||||
|
||||
renderer.RgbaSpriteRenderer.Flush();
|
||||
renderer.SpriteRenderer.Flush();
|
||||
renderer.WorldSpriteRenderer.Flush();
|
||||
|
||||
renderer.EndFrame();
|
||||
// Timer.Time( "endFrame: {0}" );
|
||||
Timer.Time( "endFrame: {0}" );
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
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
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Traits
|
||||
public Rectangle? exploredBounds;
|
||||
public event Action Dirty = () => { };
|
||||
|
||||
public Shroud(Actor self, ShroudInfo info)
|
||||
public Shroud(Actor self)
|
||||
{
|
||||
map = self.World.Map;
|
||||
visibleCells = new int[map.MapSize.X, map.MapSize.Y];
|
||||
|
||||
@@ -25,17 +25,11 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
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 rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
WidgetUtils.DrawPanel(Background, rect);
|
||||
base.Draw(world);
|
||||
}
|
||||
|
||||
public BackgroundWidget() : base() { }
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace OpenRA.Widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Draw (World world)
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
int paletteHeight = DrawPalette(world, currentTab);
|
||||
DrawBuildTabs(world, paletteHeight);
|
||||
@@ -181,11 +181,6 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
string paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
|
||||
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw(world);
|
||||
return 0;
|
||||
}
|
||||
buttons.Clear();
|
||||
|
||||
|
||||
|
||||
@@ -79,13 +79,8 @@ namespace OpenRA.Widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Draw(World world)
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
if (!IsVisible())
|
||||
{
|
||||
base.Draw(world);
|
||||
return;
|
||||
}
|
||||
var pos = DrawPosition();
|
||||
|
||||
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(Game.chrome.renderer.BoldFont.Measure(text).X / 2,
|
||||
Game.chrome.renderer.BoldFont.Measure(text).Y / 2) + stateOffset, Color.White);
|
||||
|
||||
base.Draw(world);
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
|
||||
@@ -28,13 +28,8 @@ namespace OpenRA.Widgets
|
||||
public string Text = "";
|
||||
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 rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location,
|
||||
@@ -56,8 +51,6 @@ namespace OpenRA.Widgets
|
||||
Color.White);
|
||||
Game.chrome.lineRenderer.Flush();
|
||||
}
|
||||
|
||||
base.Draw(world);
|
||||
}
|
||||
|
||||
public CheckboxWidget() : base() { }
|
||||
|
||||
@@ -44,18 +44,11 @@ namespace OpenRA.Widgets
|
||||
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 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());
|
||||
base.Draw(world);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +52,8 @@ namespace OpenRA.Widgets
|
||||
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 text = GetText();
|
||||
int2 textSize = font.Measure(text);
|
||||
@@ -69,7 +63,6 @@ namespace OpenRA.Widgets
|
||||
position += new int2((Bounds.Width - textSize.X)/2, 0);
|
||||
|
||||
font.DrawText(text, position, Color.White);
|
||||
base.Draw(world);
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
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;
|
||||
if( map == null ) return;
|
||||
@@ -55,7 +55,6 @@ namespace OpenRA.Widgets
|
||||
new float2( mapRect.Size ) );
|
||||
|
||||
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)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
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>();
|
||||
|
||||
|
||||
@@ -32,13 +32,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
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 rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom);
|
||||
@@ -62,8 +57,6 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
Game.chrome.lineRenderer.Flush();
|
||||
|
||||
base.Draw(world);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,10 +36,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
// 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.players.Count > 2) /* more than just us + neutral */
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
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);
|
||||
DrawPower(world);
|
||||
|
||||
@@ -80,13 +80,8 @@ namespace OpenRA.Widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Draw(World world)
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw(world);
|
||||
return;
|
||||
}
|
||||
buttons.Clear();
|
||||
|
||||
var powers = world.LocalPlayer.PlayerActor.traits.WithInterface<SupportPower>();
|
||||
@@ -170,7 +165,6 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
}
|
||||
Game.chrome.renderer.WorldSpriteRenderer.Flush();
|
||||
base.Draw(world);
|
||||
}
|
||||
|
||||
Action<MouseInput> HandleSupportPower(SupportPower sp)
|
||||
|
||||
@@ -167,11 +167,16 @@ namespace OpenRA.Widgets
|
||||
throw new InvalidOperationException("Impossible");
|
||||
}
|
||||
|
||||
public virtual void Draw(World world)
|
||||
public abstract void DrawInner( World world );
|
||||
|
||||
public void Draw(World world)
|
||||
{
|
||||
if (IsVisible())
|
||||
{
|
||||
DrawInner( world );
|
||||
foreach (var child in Children)
|
||||
child.Draw(world);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Tick(World world)
|
||||
@@ -229,6 +234,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
public ContainerWidget(Widget other) : base(other) { }
|
||||
|
||||
public override void DrawInner( World world ) { }
|
||||
|
||||
public override Widget Clone() { return new ContainerWidget(this); }
|
||||
}
|
||||
public interface IWidgetDelegate { }
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user