it fails
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
@@ -27,6 +28,14 @@ namespace OpenRA.Widgets
|
||||
public string Text = "";
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = 1;
|
||||
public Func<string> GetText;
|
||||
|
||||
public ButtonWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => { return Text; };
|
||||
}
|
||||
|
||||
public override bool HandleInput(MouseInput mi)
|
||||
{
|
||||
if (Chrome.selectedWidget == this)
|
||||
@@ -79,5 +88,20 @@ namespace OpenRA.Widgets
|
||||
|
||||
base.Draw(world);
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
{
|
||||
Log.Write("Foo");
|
||||
var widget = (base.Clone() as ButtonWidget);
|
||||
Log.Write(widget.Id);
|
||||
|
||||
widget.Text = Text;
|
||||
widget.Depressed = Depressed;
|
||||
widget.VisualHeight = VisualHeight;
|
||||
widget.GetText = GetText;
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,55 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public class LobbyDelegate : IWidgetDelegate
|
||||
{
|
||||
Widget PlayerTemplate;
|
||||
Widget Players;
|
||||
|
||||
public LobbyDelegate ()
|
||||
{
|
||||
var r = Chrome.rootWidget;
|
||||
var lobby = r.GetWidget("SERVER_LOBBY");
|
||||
Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS");
|
||||
PlayerTemplate = Players.GetWidget("TEMPLATE");
|
||||
|
||||
|
||||
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
|
||||
mapButton.OnMouseUp = mi => {
|
||||
r.OpenWindow("MAP_CHOOSER");
|
||||
return true;
|
||||
};
|
||||
mapButton.IsVisible = () => {return (mapButton.Visible && Game.IsHost);};
|
||||
|
||||
Game.LobbyInfoChanged += () => { UpdatePlayerList(); };
|
||||
|
||||
UpdatePlayerList();
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
{
|
||||
Log.Write("UpdatePlayerList");
|
||||
|
||||
Players.Children.Clear();
|
||||
int i = 0;
|
||||
foreach(var client in Game.LobbyInfo.Clients)
|
||||
{
|
||||
Log.Write("Client {0}",client.Name);
|
||||
var template = PlayerTemplate.Clone();
|
||||
template.Id = "PLAYER_{0}".F(client.Name);
|
||||
template.GetWidget<ButtonWidget>("NAME").GetText = () => client.Name;
|
||||
template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + i, template.Bounds.Width, template.Bounds.Height);
|
||||
template.Visible = true;
|
||||
Players.AddChild(template);
|
||||
i += 30;
|
||||
}
|
||||
Log.Write("Players has {0} children",Players.Children.Count);
|
||||
foreach (var foo in Players.Children)
|
||||
Log.Write("{0} {1} {2}",foo.Id, foo.GetWidget<ButtonWidget>("NAME").GetText(), foo.Bounds.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,6 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
GetText = () => { return Text; };
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
public override void Draw(World world)
|
||||
{
|
||||
|
||||
@@ -54,7 +54,34 @@ namespace OpenRA.Widgets
|
||||
public Func<bool> IsVisible;
|
||||
|
||||
public Widget() { IsVisible = () => Visible; }
|
||||
|
||||
|
||||
public virtual Widget Clone()
|
||||
{
|
||||
Widget widget = new Widget();
|
||||
|
||||
widget.Id = Id;
|
||||
widget.X = X;
|
||||
widget.Y = Y;
|
||||
widget.Width = Width;
|
||||
widget.Height = Height;
|
||||
widget.Delegate = Delegate;
|
||||
widget.ClickThrough = ClickThrough;
|
||||
widget.Visible = Visible;
|
||||
|
||||
widget.Bounds = Bounds;
|
||||
widget.Parent = Parent;
|
||||
|
||||
widget.OnMouseDown = OnMouseDown;
|
||||
widget.OnMouseUp = OnMouseUp;
|
||||
widget.OnMouseMove = OnMouseMove;
|
||||
widget.IsVisible = IsVisible;
|
||||
|
||||
foreach(var child in Children)
|
||||
widget.AddChild(child.Clone());
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
// Parse the YAML equations to find the widget bounds
|
||||
|
||||
Reference in New Issue
Block a user