Lobby player listing working with widgets

This commit is contained in:
alzeih
2010-04-24 19:38:58 +12:00
parent bd4f66b433
commit 53865f974e
6 changed files with 291 additions and 110 deletions

View File

@@ -110,9 +110,7 @@ namespace OpenRA
Chrome.rootWidget.CloseWindow(); Chrome.rootWidget.CloseWindow();
}); });
var mapBackground = new Rectangle(r.Right - 284, r.Top + 26, 264, 264);
var mapContainer = new Rectangle(r.Right - 280, r.Top + 30, 256, 256); var mapContainer = new Rectangle(r.Right - 280, r.Top + 30, 256, 256);
var mapRect = currentMap.PreviewBounds(new Rectangle(mapContainer.X,mapContainer.Y,mapContainer.Width,mapContainer.Height));
var y = r.Top + 50; var y = r.Top + 50;
@@ -171,61 +169,6 @@ namespace OpenRA
var w = 800; var w = 800;
var h = 600; var h = 600;
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
var f = renderer.BoldFont;
rgbaRenderer.Flush();
var y = r.Top + 80;
foreach (var client in Game.LobbyInfo.Clients)
{
var isLocalPlayer = client.Index == Game.orderManager.Connection.LocalClientId;
var paletteRect = new Rectangle(r.Left + 130, y - 2, 65, 22);
/*
if (isLocalPlayer)
{
// todo: name editing
var nameRect = new Rectangle(r.Left + 30, y - 2, 95, 22);
DrawDialogBackground(nameRect, "dialog3");
DrawDialogBackground(paletteRect, "dialog3");
AddButton(paletteRect, CyclePalette);
var factionRect = new Rectangle(r.Left + 210, y - 2, 90, 22);
DrawDialogBackground(factionRect, "dialog3");
AddButton(factionRect, CycleRace);
var spawnPointRect = new Rectangle(r.Left + 305, y - 2, 70, 22);
DrawDialogBackground(spawnPointRect, "dialog3");
AddButton(spawnPointRect, CycleSpawnPoint);
var teamRect = new Rectangle(r.Left + 385, y - 2, 70, 22);
DrawDialogBackground(teamRect, "dialog3");
AddButton(teamRect, CycleTeam);
var readyRect = new Rectangle(r.Left + 465, y - 2, 50, 22);
DrawDialogBackground(readyRect, "dialog3");
AddButton(readyRect, CycleReady);
}
*/
shpRenderer.Flush();
/*
f = renderer.RegularFont;
f.DrawText(client.Name, new int2(r.Left + 40, y), Color.White);
lineRenderer.FillRect(RectangleF.FromLTRB(paletteRect.Left + Game.viewport.Location.X + 5,
paletteRect.Top + Game.viewport.Location.Y + 5,
paletteRect.Right + Game.viewport.Location.X - 5,
paletteRect.Bottom+Game.viewport.Location.Y - 5),
Player.PlayerColors(Game.world)[client.PaletteIndex % Player.PlayerColors(Game.world).Count()].c);
lineRenderer.Flush();
f.DrawText(client.Country, new int2(r.Left + 220, y), Color.White);
f.DrawText((client.SpawnPoint == 0) ? "-" : client.SpawnPoint.ToString(), new int2(r.Left + 315 + 20, y), Color.White);
f.DrawText((client.Team == 0)? "-" : client.Team.ToString(), new int2(r.Left + 395 + 20, y), Color.White);
f.DrawText(client.State.ToString(), new int2(r.Left + 475, y), Color.White);
y += 30;
*/
rgbaRenderer.Flush();
}
var typingBox = new Rectangle(r.Left + 20, r.Bottom - 47, r.Width - 40, 27); var typingBox = new Rectangle(r.Left + 20, r.Bottom - 47, r.Width - 40, 27);
var chatBox = new Rectangle(r.Left + 20, r.Bottom - 269, r.Width - 40, 220); var chatBox = new Rectangle(r.Left + 20, r.Bottom - 269, r.Width - 40, 220);
@@ -234,11 +177,6 @@ namespace OpenRA
DrawDialogBackground(chatBox, "dialog3"); DrawDialogBackground(chatBox, "dialog3");
DrawChat(typingBox, chatBox); DrawChat(typingBox, chatBox);
// block clicks `through` the dialog
AddButton(r, _ => { });
} }
void AddButton(RectangleF r, Action<bool> b) { buttons.Add(Pair.New(r, b)); } void AddButton(RectangleF r, Action<bool> b) { buttons.Add(Pair.New(r, b)); }

View File

@@ -36,13 +36,13 @@ namespace OpenRA.Widgets
GetText = () => { return Text; }; GetText = () => { return Text; };
} }
public ButtonWidget(ButtonWidget widget) public ButtonWidget(Widget widget)
:base(widget) :base(widget)
{ {
Text = widget.Text; Text = (widget as ButtonWidget).Text;
Depressed = widget.Depressed; Depressed = (widget as ButtonWidget).Depressed;
VisualHeight = widget.VisualHeight; VisualHeight = (widget as ButtonWidget).VisualHeight;
GetText = widget.GetText; GetText = (widget as ButtonWidget).GetText;
} }
public override bool HandleInput(MouseInput mi) public override bool HandleInput(MouseInput mi)

View File

@@ -9,15 +9,15 @@ namespace OpenRA.Widgets.Delegates
{ {
public class LobbyDelegate : IWidgetDelegate public class LobbyDelegate : IWidgetDelegate
{ {
Widget PlayerTemplate; Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
Widget Players;
public LobbyDelegate () public LobbyDelegate ()
{ {
var r = Chrome.rootWidget; var r = Chrome.rootWidget;
var lobby = r.GetWidget("SERVER_LOBBY"); var lobby = r.GetWidget("SERVER_LOBBY");
Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS"); Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS");
PlayerTemplate = Players.GetWidget("TEMPLATE"); LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON"); var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
@@ -26,11 +26,9 @@ namespace OpenRA.Widgets.Delegates
return true; return true;
}; };
mapButton.IsVisible = () => {return (mapButton.Visible && Game.IsHost);}; mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
Game.LobbyInfoChanged += () => UpdatePlayerList(); Game.LobbyInfoChanged += UpdatePlayerList;
UpdatePlayerList();
} }
void UpdatePlayerList() void UpdatePlayerList()
@@ -41,37 +39,53 @@ namespace OpenRA.Widgets.Delegates
foreach(var client in Game.LobbyInfo.Clients) foreach(var client in Game.LobbyInfo.Clients)
{ {
var c = client; var c = client;
var template = (client.Index == Game.LocalClient.Index)? LocalPlayerTemplate.Clone() : RemotePlayerTemplate.Clone();
Log.Write("Client {0}",c.Name);
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.Parent = Players;
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
template.GetWidget<ButtonWidget>("NAME").GetText = () => c.Name; if(client.Index == Game.LocalClient.Index)
{
//TODO: Real Color Button //TODO: Real Color Button
var color = template.GetWidget<ButtonWidget>("COLOR"); var color = template.GetWidget<ButtonWidget>("COLOR");
color.OnMouseUp = mi => CyclePalette(mi); color.OnMouseUp = CyclePalette;
color.GetText = () => c.PaletteIndex.ToString(); color.GetText = () => c.PaletteIndex.ToString();
var faction = template.GetWidget<ButtonWidget>("FACTION"); var faction = template.GetWidget<ButtonWidget>("FACTION");
faction.OnMouseUp = mi => CycleRace(mi); faction.OnMouseUp = CycleRace;
faction.GetText = () => c.Country; faction.GetText = () => c.Country;
var spawn = template.GetWidget<ButtonWidget>("SPAWN"); var spawn = template.GetWidget<ButtonWidget>("SPAWN");
spawn.OnMouseUp = mi => CycleSpawnPoint(mi); spawn.OnMouseUp = CycleSpawnPoint;
spawn.GetText = () => { return (c.SpawnPoint == 0) ? "-" : c.SpawnPoint.ToString(); }; spawn.GetText = () => (c.SpawnPoint == 0) ? "-" : c.SpawnPoint.ToString();
var team = template.GetWidget<ButtonWidget>("TEAM"); var team = template.GetWidget<ButtonWidget>("TEAM");
team.OnMouseUp = mi => CycleTeam(mi); team.OnMouseUp = CycleTeam;
team.GetText = () => { return (c.Team == 0) ? "-" : c.Team.ToString(); }; team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
//It fails here var status = template.GetWidget<CheckboxWidget>("STATUS");
var status = template.GetWidget<CheckboxWidget>("STATUS"); status.Checked = () => c.State == Session.ClientState.Ready;
status.Checked = () => { return (c.State == Session.ClientState.Ready) ? true : false; }; status.OnMouseDown = CycleReady;
status.OnMouseDown = mi => CycleReady(mi); }
else
{
//TODO: Real Color Label
var color = template.GetWidget<LabelWidget>("COLOR");
color.GetText = () => c.PaletteIndex.ToString();
var faction = template.GetWidget<LabelWidget>("FACTION");
faction.GetText = () => c.Country;
var spawn = template.GetWidget<LabelWidget>("SPAWN");
spawn.GetText = () => (c.SpawnPoint == 0) ? "-" : c.SpawnPoint.ToString();
var team = template.GetWidget<LabelWidget>("TEAM");
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
var status = template.GetWidget<CheckboxWidget>("STATUS");
status.Checked = () => c.State == Session.ClientState.Ready;
}
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height); template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true; template.IsVisible = () => true;

View File

@@ -36,6 +36,15 @@ namespace OpenRA.Widgets
GetText = () => { return Text; }; GetText = () => { return Text; };
} }
public LabelWidget(Widget other)
: base(other)
{
Text = (other as LabelWidget).Text;
Align = (other as LabelWidget).Align;
Bold = (other as LabelWidget).Bold;
GetText = (other as LabelWidget).GetText;
}
public override void Draw(World world) public override void Draw(World world)
{ {
if (!IsVisible()) if (!IsVisible())
@@ -56,5 +65,10 @@ namespace OpenRA.Widgets
font.DrawText(text, position, Color.White); font.DrawText(text, position, Color.White);
base.Draw(world); base.Draw(world);
} }
public override Widget Clone()
{
return new LabelWidget(this);
}
} }
} }

View File

@@ -262,6 +262,7 @@ Container:
Text:Abort Text:Abort
Background@SERVER_LOBBY: Background@SERVER_LOBBY:
Id:SERVER_LOBBY Id:SERVER_LOBBY
Delegate:LobbyDelegate
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:800 Width:800
@@ -287,6 +288,165 @@ Container:
Y:4 Y:4
Width:244 Width:244
Height:244 Height:244
Container@PLAYERS
Id:PLAYERS
X:30
Y:75
Width:500
Height:200
Children:
Container@TEMPLATE_LOCAL
Id:TEMPLATE_LOCAL
X:0
Y:0
Width:500
Height:30
Visible:false
Children:
Label@NAME:
Id:NAME
Text:Name
Width:95
Height:25
X:0
Y:0
Button@COLOR:
Id:COLOR
Text:Color
Width:65
Height:25
X:100
Y:0
Button@FACTION:
Id:FACTION
Text:Faction
Width:90
Height:25
X:180
Y:0
Button@SPAWN:
Id:SPAWN
Text:Spawn
Width:70
Height:25
X:275
Y:0
Button@TEAM:
Id:TEAM
Text:Team
Width:70
Height:25
X:355
Y:0
Checkbox@STATUS:
Id:STATUS
X:455
Y:0
Width:20
Height:20
Container@TEMPLATE_REMOTE
Id:TEMPLATE_REMOTE
X:0
Y:0
Width:500
Height:30
Visible:false
Children:
Label@NAME:
Id:NAME
Text:Name
Width:95
Height:25
X:0
Y:0
Label@COLOR:
Id:COLOR
Text:Color
Width:65
Height:25
X:100
Y:0
Align:Center
Label@FACTION:
Id:FACTION
Text:Faction
Width:90
Height:25
X:180
Y:0
Align:Center
Label@SPAWN:
Id:SPAWN
Text:Spawn
Width:70
Height:25
X:275
Y:0
Align:Center
Label@TEAM:
Id:TEAM
Text:Team
Width:70
Height:25
X:355
Y:0
Align:Center
Checkbox@STATUS:
Id:STATUS
X:455
Y:0
Width:20
Height:20
Button@CHANGEMAP_BUTTON:
Id:CHANGEMAP_BUTTON
Visible:true
X:PARENT_RIGHT-140
Y:300
Width:120
Height:25
Text:Change Map
Label@LABEL_LOBBY_NAME:
Id:LABEL_LOBBY_NAME
X:40
Y:50
Width:250
Height:25
Text:Name
Label@LABEL_LOBBY_COLOR:
Id:LABEL_LOBBY_COLOR
X:140
Y:50
Width:250
Height:25
Text:Color
Label@LABEL_LOBBY_FACTION
Id:LABEL_LOBBY_FACTION
X:220
Y:50
Width:250
Height:25
Text:Faction
Label@LABEL_LOBBY_SPAWN
Id:LABEL_LOBBY_SPAWN
X:315
Y:50
Width:250
Height:25
Text:Spawn
Label@LABEL_LOBBY_TEAM
Id:LABEL_LOBBY_TEAM
X:395
Y:50
Width:250
Height:25
Text:Team
Label@LABEL_LOBBY_STATUS
Id:LABEL_LOBBY_STATUS
X:475
Y:50
Width:250
Height:25
Text:Status
Background@MAP_CHOOSER: Background@MAP_CHOOSER:
Id:MAP_CHOOSER Id:MAP_CHOOSER
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
@@ -463,3 +623,6 @@ Container:
Width:25 Width:25
Height:25 Height:25
Text:[] Text:[]

View File

@@ -292,18 +292,18 @@ Container:
Id:PLAYERS Id:PLAYERS
X:30 X:30
Y:75 Y:75
Width:455 Width:500
Height:200 Height:200
Children: Children:
Container@TEMPLATE Container@TEMPLATE_LOCAL
Id:TEMPLATE Id:TEMPLATE_LOCAL
X:0 X:0
Y:0 Y:0
Width:455 Width:500
Height:30 Height:30
Visible:false Visible:false
Children: Children:
Button@NAME: Label@NAME:
Id:NAME Id:NAME
Text:Name Text:Name
Width:95 Width:95
@@ -340,11 +340,63 @@ Container:
Y:0 Y:0
Checkbox@STATUS: Checkbox@STATUS:
Id:STATUS Id:STATUS
X:430 X:455
Y:0 Y:0
Width:300 Width:20
Height:20
Container@TEMPLATE_REMOTE
Id:TEMPLATE_REMOTE
X:0
Y:0
Width:500
Height:30
Visible:false
Children:
Label@NAME:
Id:NAME
Text:Name
Width:95
Height:25
X:0
Y:0
Label@COLOR:
Id:COLOR
Text:Color
Width:65
Height:25
X:100
Y:0
Align:Center
Label@FACTION:
Id:FACTION
Text:Faction
Width:90
Height:25
X:180
Y:0
Align:Center
Label@SPAWN:
Id:SPAWN
Text:Spawn
Width:70
Height:25
X:275
Y:0
Align:Center
Label@TEAM:
Id:TEAM
Text:Team
Width:70
Height:25
X:355
Y:0
Align:Center
Checkbox@STATUS:
Id:STATUS
X:455
Y:0
Width:20
Height:20 Height:20
Text:Show Spatial Index Debug
Button@CHANGEMAP_BUTTON: Button@CHANGEMAP_BUTTON:
Id:CHANGEMAP_BUTTON Id:CHANGEMAP_BUTTON
Visible:true Visible:true