Skip to content

Commit

Permalink
Merge pull request #13002 from rob-v/LobbyOptionsEditableByHost
Browse files Browse the repository at this point in the history
Host can change Team and Spawn of any player. #12936
  • Loading branch information
reaperrr committed May 4, 2017
2 parents c4e79a1 + bd02587 commit ea29cce
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
18 changes: 14 additions & 4 deletions OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ void UpdatePlayerList()
if (orderManager.LocalClient == null)
return;

var isHost = Game.IsHost;
var idx = 0;
foreach (var kv in orderManager.LobbyInfo.Slots)
{
Expand All @@ -659,7 +660,7 @@ void UpdatePlayerList()
if (template == null || template.Id != emptySlotTemplate.Id)
template = emptySlotTemplate.Clone();

if (Game.IsHost)
if (isHost)
LobbyUtils.SetupEditableSlotWidget(this, template, slot, client, orderManager);
else
LobbyUtils.SetupSlotWidget(template, slot, client);
Expand All @@ -670,7 +671,7 @@ void UpdatePlayerList()
join.OnClick = () => orderManager.IssueOrder(Order.Command("slot " + key));
}
else if ((client.Index == orderManager.LocalClient.Index) ||
(client.Bot != null && Game.IsHost))
(client.Bot != null && isHost))
{
// Editable player in slot
if (template == null || template.Id != editablePlayerTemplate.Id)
Expand Down Expand Up @@ -701,8 +702,17 @@ void UpdatePlayerList()
() => panel = PanelType.Kick, () => panel = PanelType.Players);
LobbyUtils.SetupColorWidget(template, slot, client);
LobbyUtils.SetupFactionWidget(template, slot, client, factions);
LobbyUtils.SetupTeamWidget(template, slot, client);
LobbyUtils.SetupSpawnWidget(template, slot, client);
if (isHost)
{
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map);
}
else
{
LobbyUtils.SetupTeamWidget(template, slot, client);
LobbyUtils.SetupSpawnWidget(template, slot, client);
}

LobbyUtils.SetupReadyWidget(template, slot, client);
}

Expand Down
27 changes: 19 additions & 8 deletions OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ public static void SetupEditableSlotWidget(LobbyLogic logic, Widget parent, Sess
slot.OnMouseDown = _ => ShowSlotDropDown(logic, slot, s, c, orderManager);

// Ensure Name selector (if present) is hidden
var name = parent.GetOrNull("NAME");
if (name != null)
name.IsVisible = () => false;
HideChildWidget(parent, "NAME");
}

public static void SetupSlotWidget(Widget parent, Session.Slot s, Session.Client c)
Expand All @@ -325,9 +323,7 @@ public static void SetupSlotWidget(Widget parent, Session.Slot s, Session.Client
name.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";

// Ensure Slot selector (if present) is hidden
var slot = parent.GetOrNull("SLOT_OPTIONS");
if (slot != null)
slot.IsVisible = () => false;
HideChildWidget(parent, "SLOT_OPTIONS");
}

public static void SetupKickWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Widget lobby, Action before, Action after)
Expand Down Expand Up @@ -427,20 +423,25 @@ public static void SetupFactionWidget(Widget parent, Session.Slot s, Session.Cli

public static void SetupEditableTeamWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
{
var dropdown = parent.Get<DropDownButtonWidget>("TEAM");
var dropdown = parent.Get<DropDownButtonWidget>("TEAM_DROPDOWN");
dropdown.IsVisible = () => true;
dropdown.IsDisabled = () => s.LockTeam || orderManager.LocalClient.IsReady;
dropdown.OnMouseDown = _ => ShowTeamDropDown(dropdown, c, orderManager, map.PlayerCount);
dropdown.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();

HideChildWidget(parent, "TEAM");
}

public static void SetupTeamWidget(Widget parent, Session.Slot s, Session.Client c)
{
parent.Get<LabelWidget>("TEAM").GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
HideChildWidget(parent, "TEAM_DROPDOWN");
}

public static void SetupEditableSpawnWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
{
var dropdown = parent.Get<DropDownButtonWidget>("SPAWN");
var dropdown = parent.Get<DropDownButtonWidget>("SPAWN_DROPDOWN");
dropdown.IsVisible = () => true;
dropdown.IsDisabled = () => s.LockSpawn || orderManager.LocalClient.IsReady;
dropdown.OnMouseDown = _ =>
{
Expand All @@ -450,11 +451,21 @@ public static void SetupEditableSpawnWidget(Widget parent, Session.Slot s, Sessi
ShowSpawnDropDown(dropdown, c, orderManager, spawnPoints);
};
dropdown.GetText = () => (c.SpawnPoint == 0) ? "-" : Convert.ToChar('A' - 1 + c.SpawnPoint).ToString();

HideChildWidget(parent, "SPAWN");
}

static void HideChildWidget(Widget parent, string widgetId)
{
var widget = parent.GetOrNull(widgetId);
if (widget != null)
widget.IsVisible = () => false;
}

public static void SetupSpawnWidget(Widget parent, Session.Slot s, Session.Client c)
{
parent.Get<LabelWidget>("SPAWN").GetText = () => (c.SpawnPoint == 0) ? "-" : Convert.ToChar('A' - 1 + c.SpawnPoint).ToString();
HideChildWidget(parent, "SPAWN_DROPDOWN");
}

public static void SetupEditableReadyWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
Expand Down
16 changes: 14 additions & 2 deletions mods/cnc/chrome/lobby-players.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ Container@LOBBY_PLAYER_BIN:
Width: 60
Height: 25
Text: Faction
DropDownButton@TEAM:
DropDownButton@TEAM_DROPDOWN:
X: 416
Width: 50
Height: 25
Font: Regular
DropDownButton@SPAWN:
DropDownButton@SPAWN_DROPDOWN:
X: 471
Width: 50
Height: 25
Expand Down Expand Up @@ -226,6 +226,18 @@ Container@LOBBY_PLAYER_BIN:
Width: 25
Height: 25
Align: Center
DropDownButton@TEAM_DROPDOWN:
X: 416
Width: 50
Height: 25
Font: Regular
Visible: false
DropDownButton@SPAWN_DROPDOWN:
X: 471
Width: 50
Height: 25
Font: Regular
Visible: false
Image@STATUS_IMAGE:
X: 527
Y: 4
Expand Down
14 changes: 12 additions & 2 deletions mods/common/chrome/lobby-players.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ Container@LOBBY_PLAYER_BIN:
Width: 60
Height: 25
Text: Faction
DropDownButton@TEAM:
DropDownButton@TEAM_DROPDOWN:
X: 410
Width: 48
Height: 25
Text: Team
DropDownButton@SPAWN:
DropDownButton@SPAWN_DROPDOWN:
X: 468
Width: 48
Height: 25
Expand Down Expand Up @@ -220,6 +220,16 @@ Container@LOBBY_PLAYER_BIN:
Width: 23
Height: 25
Align: Center
DropDownButton@TEAM_DROPDOWN:
X: 410
Width: 48
Height: 25
Visible: false
DropDownButton@SPAWN_DROPDOWN:
X: 468
Width: 48
Height: 25
Visible: false
Image@STATUS_IMAGE:
X: 527
Y: 4
Expand Down
14 changes: 12 additions & 2 deletions mods/d2k/chrome/lobby-players.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ Container@LOBBY_PLAYER_BIN:
Width: 70
Height: 25
Text: Faction
DropDownButton@TEAM:
DropDownButton@TEAM_DROPDOWN:
X: 410
Width: 48
Height: 25
Text: Team
DropDownButton@SPAWN:
DropDownButton@SPAWN_DROPDOWN:
X: 468
Width: 48
Height: 25
Expand Down Expand Up @@ -220,6 +220,16 @@ Container@LOBBY_PLAYER_BIN:
Width: 23
Height: 25
Align: Center
DropDownButton@TEAM_DROPDOWN:
X: 410
Width: 48
Height: 25
Visible: false
DropDownButton@SPAWN_DROPDOWN:
X: 468
Width: 48
Height: 25
Visible: false
Image@STATUS_IMAGE:
X: 527
Y: 4
Expand Down

0 comments on commit ea29cce

Please sign in to comment.