refactored a bit - something is still failing

This commit is contained in:
alzeih
2010-04-24 17:33:43 +12:00
parent 3d1d6f5e00
commit 471a5c29c8
12 changed files with 32 additions and 18 deletions

View File

@@ -31,7 +31,8 @@ namespace OpenRA.Widgets
base.Draw(world); base.Draw(world);
return; return;
} }
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
WidgetUtils.DrawPanel(Background, rect); WidgetUtils.DrawPanel(Background, rect);
base.Draw(world); base.Draw(world);
} }

View File

@@ -86,13 +86,14 @@ namespace OpenRA.Widgets
base.Draw(world); base.Draw(world);
return; return;
} }
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);
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height ) ); WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
var text = GetText(); var text = GetText();
Game.chrome.renderer.BoldFont.DrawText(text, Game.chrome.renderer.BoldFont.DrawText(text,
new int2( ( Bounds.X + getParentOffset().X) + Bounds.Width / 2, ( Bounds.Y + getParentOffset().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);

View File

@@ -35,9 +35,10 @@ namespace OpenRA.Widgets
base.Draw(world); base.Draw(world);
return; return;
} }
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); var pos = DrawPosition();
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,
new Size(Bounds.Height, Bounds.Height))); new Size(Bounds.Height, Bounds.Height))); //HACK!
Game.chrome.renderer.BoldFont.DrawText(Text, Game.chrome.renderer.BoldFont.DrawText(Text,
new float2(rect.Left + rect.Height * 2, rect.Top), Color.White); new float2(rect.Left + rect.Height * 2, rect.Top), Color.White);

View File

@@ -36,6 +36,7 @@ namespace OpenRA.Widgets.Delegates
Players.Children.Clear(); Players.Children.Clear();
int i = 0; int i = 0;
foreach(var client in Game.LobbyInfo.Clients) foreach(var client in Game.LobbyInfo.Clients)
{ {
//HACK : "the c# spec is, IMHO, broken here" //HACK : "the c# spec is, IMHO, broken here"
@@ -43,9 +44,12 @@ namespace OpenRA.Widgets.Delegates
Log.Write("Client {0}",c.Name); Log.Write("Client {0}",c.Name);
var template = PlayerTemplate.Clone(); var template = PlayerTemplate.Clone();
var pos = template.DrawPosition();
template.Id = "PLAYER_{0}".F(c.Index); template.Id = "PLAYER_{0}".F(c.Index);
template.Parent = Players;
template.GetWidget<ButtonWidget>("NAME").GetText = () => {return c.Name; }; template.GetWidget<ButtonWidget>("NAME").GetText = () => {return c.Name; };
template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + i, template.Bounds.Width, template.Bounds.Height); template.Bounds = new Rectangle(pos.X, pos.Y + i, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => {return true;}; template.IsVisible = () => {return true;};
Players.AddChild(template); Players.AddChild(template);
i += 30; i += 30;

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Widgets.Delegates
var g = game; var g = game;
var b = new ButtonWidget var b = new ButtonWidget
{ {
Bounds = new Rectangle(bg.Bounds.X + margin, bg.Bounds.Y + height, bg.Bounds.Width - 2 * margin, 25), Bounds = new Rectangle(bg.DrawPosition().X + margin, bg.DrawPosition().Y + height, bg.Bounds.Width - 2 * margin, 25),
Id = "JOIN_GAME_{0}".F(i), Id = "JOIN_GAME_{0}".F(i),
Text = "{0} ({1})".F(game.Name, game.Address), Text = "{0} ({1})".F(game.Name, game.Address),
Delegate = "ServerBrowserDelegate", Delegate = "ServerBrowserDelegate",

View File

@@ -47,10 +47,10 @@ namespace OpenRA.Widgets
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);
int2 position = new int2(Parent.Bounds.X + Bounds.X,Parent.Bounds.Y + Bounds.Y); int2 position = DrawPosition();
if (Align == "Center") if (Align == "Center")
position = new int2(Bounds.X + Parent.Bounds.X +Bounds.Width/2, Bounds.Y + Parent.Bounds.Y + Bounds.Height/2) position = new int2(position.X +Bounds.Width/2, position.Y + Bounds.Height/2)
- new int2(textSize.X / 2, textSize.Y/2); - new int2(textSize.X / 2, textSize.Y/2);
font.DrawText(text, position, Color.White); font.DrawText(text, position, Color.White);

View File

@@ -25,7 +25,8 @@ namespace OpenRA.Widgets
mapPreviewDirty = true; mapPreviewDirty = true;
lastMap = map; lastMap = map;
} }
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
var mapRect = map.PreviewBounds( new Rectangle( rect.X, rect.Y, rect.Width, rect.Height ) ); var mapRect = map.PreviewBounds( new Rectangle( rect.X, rect.Y, rect.Width, rect.Height ) );
if( mapPreviewDirty ) if( mapPreviewDirty )
@@ -43,7 +44,7 @@ namespace OpenRA.Widgets
"chrome", "chrome",
new float2( mapRect.Size ) ); new float2( mapRect.Size ) );
DrawSpawnPoints( map, Parent.Bounds, world ); DrawSpawnPoints( map, new Rectangle(pos.X, pos.Y, Parent.Bounds.Width, Parent.Bounds.Height ), world );
base.Draw( world ); base.Draw( world );
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.

View File

@@ -33,7 +33,8 @@ namespace OpenRA.Widgets
base.Draw(world); base.Draw(world);
return; return;
} }
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); 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); float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom);
float2 basis = new float2(-rect.Width/100,-rect.Height/100); float2 basis = new float2(-rect.Width/100,-rect.Height/100);

View File

@@ -85,7 +85,8 @@ namespace OpenRA.Widgets
var powers = world.LocalPlayer.PlayerActor.traits.WithInterface<SupportPower>(); var powers = world.LocalPlayer.PlayerActor.traits.WithInterface<SupportPower>();
var numPowers = powers.Count(p => p.IsAvailable); var numPowers = powers.Count(p => p.IsAvailable);
if (numPowers == 0) return; if (numPowers == 0) return;
var rectBounds = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); var position = DrawPosition();
var rectBounds = new Rectangle(position.X, position.Y, Bounds.Width, Bounds.Height);
WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"),new float2(rectBounds.X,rectBounds.Y)); WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"),new float2(rectBounds.X,rectBounds.Y));
for (var i = 1; i < numPowers; i++) for (var i = 1; i < numPowers; i++)
WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world,"specialbin-middle"), new float2(rectBounds.X, rectBounds.Y + i * 51)); WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world,"specialbin-middle"), new float2(rectBounds.X, rectBounds.Y + i * 51));

View File

@@ -83,9 +83,9 @@ namespace OpenRA.Widgets
return new Widget(this); return new Widget(this);
} }
public int2 getParentOffset() public int2 DrawPosition()
{ {
return (Parent == null) ? int2.Zero : new int2(Parent.Bounds.Location.X, Parent.Bounds.Location.Y) ; return new int2(Bounds.X, Bounds.Y) + ((Parent == null) ? int2.Zero : Parent.DrawPosition());
} }
public virtual void Initialize() public virtual void Initialize()
@@ -127,7 +127,8 @@ namespace OpenRA.Widgets
public bool HitTest(int2 xy) public bool HitTest(int2 xy)
{ {
if (!IsVisible()) return false; if (!IsVisible()) return false;
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
if (rect.Contains(xy.ToPoint()) && !ClickThrough) return true; if (rect.Contains(xy.ToPoint()) && !ClickThrough) return true;
return Children.Any(c => c.HitTest(xy)); return Children.Any(c => c.HitTest(xy));
@@ -135,7 +136,8 @@ namespace OpenRA.Widgets
public Rectangle GetEventBounds() public Rectangle GetEventBounds()
{ {
var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); var pos = DrawPosition();
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
return Children return Children
.Where(c => c.Visible) .Where(c => c.Visible)
.Select(c => c.GetEventBounds()) .Select(c => c.GetEventBounds())

View File

@@ -295,6 +295,8 @@ Container:
Children: Children:
Container@TEMPLATE Container@TEMPLATE
Id:TEMPLATE Id:TEMPLATE
X:0
Y:0
Visible:false Visible:false
Children: Children:
Button@NAME Button@NAME