checkbox is failing somehow?
This commit is contained in:
@@ -155,65 +155,7 @@ namespace OpenRA
|
||||
|
||||
AddButton(r, _ => { });
|
||||
}
|
||||
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); }
|
||||
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||
|
||||
void CyclePalette(bool left)
|
||||
{
|
||||
var d = left ? +1 : Player.PlayerColors(Game.world).Count() - 1;
|
||||
|
||||
var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Player.PlayerColors(Game.world).Count();
|
||||
|
||||
while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex)
|
||||
newIndex = (newIndex + d) % Player.PlayerColors(Game.world).Count();
|
||||
|
||||
Game.IssueOrder(
|
||||
Order.Chat("/pal " + newIndex));
|
||||
}
|
||||
|
||||
void CycleRace(bool left)
|
||||
{
|
||||
var countries = new[] { "Random" }.Concat(Game.world.GetCountries().Select(c => c.Name));
|
||||
var nextCountry = countries
|
||||
.SkipWhile(c => c != Game.LocalClient.Country)
|
||||
.Skip(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (nextCountry == null)
|
||||
nextCountry = countries.First();
|
||||
|
||||
Game.IssueOrder(Order.Chat("/race " + nextCountry));
|
||||
}
|
||||
|
||||
void CycleReady(bool left)
|
||||
{
|
||||
Game.IssueOrder(Order.Chat("/ready"));
|
||||
}
|
||||
|
||||
void CycleSpawnPoint(bool left)
|
||||
{
|
||||
var d = left ? +1 : Game.world.Map.SpawnPoints.Count();
|
||||
|
||||
var newIndex = (Game.LocalClient.SpawnPoint + d) % (Game.world.Map.SpawnPoints.Count()+1);
|
||||
|
||||
while (!SpawnPointAvailable(newIndex) && newIndex != (int)Game.LocalClient.SpawnPoint)
|
||||
newIndex = (newIndex + d) % (Game.world.Map.SpawnPoints.Count()+1);
|
||||
|
||||
Game.IssueOrder(
|
||||
Order.Chat("/spawn " + newIndex));
|
||||
|
||||
}
|
||||
|
||||
void CycleTeam(bool left)
|
||||
{
|
||||
var d = left ? +1 : Game.world.Map.PlayerCount;
|
||||
|
||||
var newIndex = (Game.LocalClient.Team + d) % (Game.world.Map.PlayerCount+1);
|
||||
|
||||
Game.IssueOrder(
|
||||
Order.Chat("/team " + newIndex));
|
||||
|
||||
}
|
||||
|
||||
public void DrawWidgets(World world) { rootWidget.Draw(world); shpRenderer.Flush(); rgbaRenderer.Flush(); }
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Widgets
|
||||
var pos = DrawPosition();
|
||||
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location,
|
||||
new Size(Bounds.Height, Bounds.Height))); //HACK!
|
||||
new Size(Bounds.Height, Bounds.Height)));
|
||||
|
||||
Game.chrome.renderer.BoldFont.DrawText(Text,
|
||||
new float2(rect.Left + rect.Height * 2, rect.Top), Color.White);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
@@ -22,24 +24,22 @@ namespace OpenRA.Widgets.Delegates
|
||||
mapButton.OnMouseUp = mi => {
|
||||
r.OpenWindow("MAP_CHOOSER");
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
mapButton.IsVisible = () => {return (mapButton.Visible && Game.IsHost);};
|
||||
|
||||
Game.LobbyInfoChanged += () => { UpdatePlayerList(); };
|
||||
Game.LobbyInfoChanged += () => UpdatePlayerList();
|
||||
|
||||
UpdatePlayerList();
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
{
|
||||
Log.Write("UpdatePlayerList");
|
||||
|
||||
Players.Children.Clear();
|
||||
int i = 0;
|
||||
|
||||
int offset = 0;
|
||||
foreach(var client in Game.LobbyInfo.Clients)
|
||||
{
|
||||
//HACK : "the c# spec is, IMHO, broken here"
|
||||
var c = client;
|
||||
|
||||
Log.Write("Client {0}",c.Name);
|
||||
@@ -48,15 +48,106 @@ namespace OpenRA.Widgets.Delegates
|
||||
|
||||
template.Id = "PLAYER_{0}".F(c.Index);
|
||||
template.Parent = Players;
|
||||
template.GetWidget<ButtonWidget>("NAME").GetText = () => {return c.Name; };
|
||||
template.Bounds = new Rectangle(0, i, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => {return true;};
|
||||
|
||||
template.GetWidget<ButtonWidget>("NAME").GetText = () => c.Name;
|
||||
|
||||
//TODO: Real Color Button
|
||||
var color = template.GetWidget<ButtonWidget>("COLOR");
|
||||
color.OnMouseUp = mi => CyclePalette(mi);
|
||||
color.GetText = () => c.PaletteIndex.ToString();
|
||||
|
||||
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
||||
faction.OnMouseUp = mi => CycleRace(mi);
|
||||
faction.GetText = () => c.Country;
|
||||
|
||||
var spawn = template.GetWidget<ButtonWidget>("SPAWN");
|
||||
spawn.OnMouseUp = mi => CycleSpawnPoint(mi);
|
||||
spawn.GetText = () => { return (c.SpawnPoint == 0) ? "-" : c.SpawnPoint.ToString(); };
|
||||
|
||||
var team = template.GetWidget<ButtonWidget>("TEAM");
|
||||
team.OnMouseUp = mi => CycleTeam(mi);
|
||||
team.GetText = () => { return (c.Team == 0) ? "-" : c.Team.ToString(); };
|
||||
|
||||
//It fails here
|
||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||
status.Checked = () => { return (c.State == Session.ClientState.Ready) ? true : false; };
|
||||
status.OnMouseDown = mi => CycleReady(mi);
|
||||
|
||||
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
Players.AddChild(template);
|
||||
i += 30;
|
||||
|
||||
offset += template.Bounds.Height;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); }
|
||||
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||
|
||||
bool CyclePalette(MouseInput mi)
|
||||
{
|
||||
var d = (mi.Button == MouseButton.Left) ? +1 : Player.PlayerColors(Game.world).Count() - 1;
|
||||
|
||||
var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Player.PlayerColors(Game.world).Count();
|
||||
|
||||
while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex)
|
||||
newIndex = (newIndex + d) % Player.PlayerColors(Game.world).Count();
|
||||
|
||||
Game.IssueOrder(
|
||||
Order.Chat("/pal " + newIndex));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleRace(MouseInput mi)
|
||||
{
|
||||
var countries = new[] { "Random" }.Concat(Game.world.GetCountries().Select(c => c.Name));
|
||||
|
||||
if (mi.Button == MouseButton.Right)
|
||||
countries = countries.Reverse();
|
||||
|
||||
var nextCountry = countries
|
||||
.SkipWhile(c => c != Game.LocalClient.Country)
|
||||
.Skip(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (nextCountry == null)
|
||||
nextCountry = countries.First();
|
||||
|
||||
Game.IssueOrder(Order.Chat("/race " + nextCountry));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleReady(MouseInput mi)
|
||||
{
|
||||
Game.IssueOrder(Order.Chat("/ready"));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleSpawnPoint(MouseInput mi)
|
||||
{
|
||||
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.SpawnPoints.Count();
|
||||
|
||||
var newIndex = (Game.LocalClient.SpawnPoint + d) % (Game.world.Map.SpawnPoints.Count()+1);
|
||||
|
||||
while (!SpawnPointAvailable(newIndex) && newIndex != (int)Game.LocalClient.SpawnPoint)
|
||||
newIndex = (newIndex + d) % (Game.world.Map.SpawnPoints.Count()+1);
|
||||
|
||||
Game.IssueOrder(
|
||||
Order.Chat("/spawn " + newIndex));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleTeam(MouseInput mi)
|
||||
{
|
||||
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
|
||||
|
||||
var newIndex = (Game.LocalClient.Team + d) % (Game.world.Map.PlayerCount+1);
|
||||
|
||||
Game.IssueOrder(
|
||||
Order.Chat("/team " + newIndex));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,53 +292,59 @@ Container:
|
||||
Id:PLAYERS
|
||||
X:30
|
||||
Y:75
|
||||
Width:455
|
||||
Height:200
|
||||
Children:
|
||||
Container@TEMPLATE
|
||||
Id:TEMPLATE
|
||||
X:0
|
||||
Y:0
|
||||
Width:455
|
||||
Height:30
|
||||
Visible:false
|
||||
Children:
|
||||
Button@NAME
|
||||
Button@NAME:
|
||||
Id:NAME
|
||||
Text:Name
|
||||
Width:95
|
||||
Height:25
|
||||
X:0
|
||||
Y:0
|
||||
Button@COLOR
|
||||
Id:NAME
|
||||
Button@COLOR:
|
||||
Id:COLOR
|
||||
Text:Color
|
||||
Width:65
|
||||
Height:25
|
||||
X:100
|
||||
Y:0
|
||||
Button@FACTION
|
||||
Button@FACTION:
|
||||
Id:FACTION
|
||||
Text:Faction
|
||||
Width:90
|
||||
Height:25
|
||||
X:180
|
||||
Y:0
|
||||
Button@SPAWN
|
||||
Button@SPAWN:
|
||||
Id:SPAWN
|
||||
Text:Spawn
|
||||
Width:70
|
||||
Height:25
|
||||
X:275
|
||||
Y:0
|
||||
Button@TEAM
|
||||
Button@TEAM:
|
||||
Id:TEAM
|
||||
Text:Team
|
||||
Width:70
|
||||
Height:25
|
||||
X:355
|
||||
Y:0
|
||||
Button@STATUS
|
||||
Checkbox@STATUS:
|
||||
Id:STATUS
|
||||
Text:Foo
|
||||
X:430
|
||||
Y:0
|
||||
Width:300
|
||||
Height:20
|
||||
Text:Show Spatial Index Debug
|
||||
Button@CHANGEMAP_BUTTON:
|
||||
Id:CHANGEMAP_BUTTON
|
||||
Visible:true
|
||||
|
||||
Reference in New Issue
Block a user