Add "Assign Teams" lobby drop down button
This commit is contained in:
@@ -24,13 +24,13 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (!server.lobbyInfo.Slots.ContainsKey(arg))
|
if (!server.lobbyInfo.Slots.ContainsKey(arg))
|
||||||
{
|
{
|
||||||
Log.Write("server", "Invalid slot: {0}", arg );
|
Log.Write("server", "Invalid slot: {0}", arg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requiresHost && !client.IsAdmin)
|
if (requiresHost && !client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "Only the host can do that" );
|
server.SendChatTo(conn, "Only the host can do that");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,6 +318,47 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
server.SyncLobbyInfo();
|
server.SyncLobbyInfo();
|
||||||
return true;
|
return true;
|
||||||
}},
|
}},
|
||||||
|
{ "assignteams",
|
||||||
|
s =>
|
||||||
|
{
|
||||||
|
if (!client.IsAdmin)
|
||||||
|
{
|
||||||
|
server.SendChatTo(conn, "Only the host can set that option");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int teams;
|
||||||
|
if (!int.TryParse(s, out teams))
|
||||||
|
{
|
||||||
|
server.SendChatTo(conn, "Number of teams could not be parsed: {0}".F(s));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
teams = teams.Clamp(2, 8);
|
||||||
|
|
||||||
|
var clients = server.lobbyInfo.Slots
|
||||||
|
.Select(slot => server.lobbyInfo.Clients.SingleOrDefault(c => c.Slot == slot.Key))
|
||||||
|
.Where(c => c != null && !server.lobbyInfo.Slots[c.Slot].LockTeam).ToArray();
|
||||||
|
|
||||||
|
var teamSizes = new int[clients.Length];
|
||||||
|
|
||||||
|
for (var i = 0; i < clients.Length; i++)
|
||||||
|
teamSizes[i % teams]++;
|
||||||
|
|
||||||
|
var clientIndex = 0;
|
||||||
|
for (var team = 1; team <= teams; team++)
|
||||||
|
{
|
||||||
|
for (var teamClientIndex = 0; teamClientIndex < teamSizes[team - 1]; clientIndex++, teamClientIndex++)
|
||||||
|
{
|
||||||
|
var cl = clients[clientIndex];
|
||||||
|
if (cl.Bot == null)
|
||||||
|
cl.State = Session.ClientState.NotReady;
|
||||||
|
cl.Team = team;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
server.SyncLobbyInfo();
|
||||||
|
return true;
|
||||||
|
}},
|
||||||
{ "crates",
|
{ "crates",
|
||||||
s =>
|
s =>
|
||||||
{
|
{
|
||||||
@@ -481,7 +522,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
var cmdName = cmd.Split(' ').First();
|
var cmdName = cmd.Split(' ').First();
|
||||||
var cmdValue = cmd.Split(' ').Skip(1).JoinWith(" ");
|
var cmdValue = cmd.Split(' ').Skip(1).JoinWith(" ");
|
||||||
|
|
||||||
Func<string,bool> a;
|
Func<string, bool> a;
|
||||||
if (!dict.TryGetValue(cmdName, out a))
|
if (!dict.TryGetValue(cmdName, out a))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
.ToDictionary(a => a.Race, a => a.Name);
|
.ToDictionary(a => a.Race, a => a.Name);
|
||||||
CountryNames.Add("random", "Any");
|
CountryNames.Add("random", "Any");
|
||||||
|
|
||||||
|
var gameStarting = false;
|
||||||
|
|
||||||
var mapButton = lobby.Get<ButtonWidget>("CHANGEMAP_BUTTON");
|
var mapButton = lobby.Get<ButtonWidget>("CHANGEMAP_BUTTON");
|
||||||
mapButton.OnClick = () =>
|
mapButton.OnClick = () =>
|
||||||
{
|
{
|
||||||
@@ -157,11 +159,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
randomMapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
|
randomMapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var assignTeams = lobby.GetOrNull<DropDownButtonWidget>("ASSIGNTEAMS_DROPDOWNBUTTON");
|
||||||
|
if (assignTeams != null)
|
||||||
|
{
|
||||||
|
assignTeams.IsVisible = () => Game.IsHost;
|
||||||
|
assignTeams.IsDisabled = () => gameStarting || orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
|
||||||
|
|
||||||
|
assignTeams.OnMouseDown = _ =>
|
||||||
|
{
|
||||||
|
var options = Enumerable.Range(2, orderManager.LobbyInfo.Clients.Count.Clamp(2, 8) - 1).Select(d => new DropDownOption
|
||||||
|
{
|
||||||
|
Title = "{0} Teams".F(d),
|
||||||
|
IsSelected = () => false,
|
||||||
|
OnClick = () => orderManager.IssueOrder(Order.Command("assignteams {0}".F(d.ToString())))
|
||||||
|
});
|
||||||
|
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||||
|
{
|
||||||
|
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
|
||||||
|
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
assignTeams.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
||||||
disconnectButton.OnClick = () => { CloseWindow(); onExit(); };
|
disconnectButton.OnClick = () => { CloseWindow(); onExit(); };
|
||||||
|
|
||||||
var gameStarting = false;
|
|
||||||
|
|
||||||
var allowCheats = lobby.Get<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
var allowCheats = lobby.Get<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
||||||
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
||||||
allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
|
allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
|
||||||
@@ -187,13 +211,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty;
|
difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty;
|
||||||
difficulty.OnMouseDown = _ =>
|
difficulty.OnMouseDown = _ =>
|
||||||
{
|
{
|
||||||
var options = Map.Difficulties.Select(d => new DifficultyDropDownOption
|
var options = Map.Difficulties.Select(d => new DropDownOption
|
||||||
{
|
{
|
||||||
Title = d,
|
Title = d,
|
||||||
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d,
|
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d,
|
||||||
OnClick = () => orderManager.IssueOrder(Order.Command("difficulty {0}".F(d)))
|
OnClick = () => orderManager.IssueOrder(Order.Command("difficulty {0}".F(d)))
|
||||||
});
|
});
|
||||||
Func<DifficultyDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||||
{
|
{
|
||||||
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
|
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
|
||||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
||||||
@@ -492,7 +516,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
orderManager.IssueOrder(Order.Command("ready"));
|
orderManager.IssueOrder(Order.Command("ready"));
|
||||||
}
|
}
|
||||||
|
|
||||||
class DifficultyDropDownOption
|
class DropDownOption
|
||||||
{
|
{
|
||||||
public string Title;
|
public string Title;
|
||||||
public Func<bool> IsSelected;
|
public Func<bool> IsSelected;
|
||||||
|
|||||||
@@ -386,22 +386,30 @@ Background@SERVER_LOBBY:
|
|||||||
Height:25
|
Height:25
|
||||||
Text:Random Map
|
Text:Random Map
|
||||||
Font:Bold
|
Font:Bold
|
||||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
DropDownButton@ASSIGNTEAMS_DROPDOWNBUTTON:
|
||||||
X:PARENT_RIGHT-154
|
X:PARENT_RIGHT-154
|
||||||
Y:PARENT_BOTTOM-229
|
Y:PARENT_BOTTOM-229
|
||||||
Width:120
|
Width:120
|
||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Visible:false
|
Visible:false
|
||||||
|
Text:Assign
|
||||||
|
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||||
|
X:PARENT_RIGHT-154
|
||||||
|
Y:PARENT_BOTTOM-199
|
||||||
|
Width:120
|
||||||
|
Height:25
|
||||||
|
Font:Bold
|
||||||
|
Visible:false
|
||||||
Checkbox@ALLOWCHEATS_CHECKBOX:
|
Checkbox@ALLOWCHEATS_CHECKBOX:
|
||||||
X: PARENT_RIGHT-154
|
X: PARENT_RIGHT-154
|
||||||
Y: PARENT_BOTTOM-179
|
Y: PARENT_BOTTOM-169
|
||||||
Width: 80
|
Width: 80
|
||||||
Height: 20
|
Height: 20
|
||||||
Text: Allow Cheats
|
Text: Allow Cheats
|
||||||
Checkbox@CRATES_CHECKBOX:
|
Checkbox@CRATES_CHECKBOX:
|
||||||
X: PARENT_RIGHT-154
|
X: PARENT_RIGHT-154
|
||||||
Y: PARENT_BOTTOM-154
|
Y: PARENT_BOTTOM-144
|
||||||
Width: 80
|
Width: 80
|
||||||
Height: 20
|
Height: 20
|
||||||
Text: Crates
|
Text: Crates
|
||||||
|
|||||||
Reference in New Issue
Block a user