updated the AllowSpectate variable to be AllowSpectators

added KickSpectatorsLogic for a confimation of kicking spectators & changed the toggle buttons to be a checkbox
This commit is contained in:
Matthew Uzzell
2014-02-16 12:51:45 +00:00
parent 88121b272d
commit c6b0e37f7e
17 changed files with 945 additions and 825 deletions

View File

@@ -49,6 +49,7 @@ Also thanks to:
* Maarten Meuris (Nyerguds)
* Mark Olson (markolson)
* Matthew Gatland (mgatland)
* Matthew Uzzell (MUzzell)
* Max621
* Max Ugrumov (katzsmile)
* Nukem

View File

@@ -15,6 +15,7 @@ NEW:
Fixed units staying selected and contributing to control groups when becoming cloaked or hidden in fog.
Swapped the cursors used for sabotaging and capturing buildings/units.
Added Ctrl+T shortcut for selection of all units matching the types of the currently selected ones across the screen and map.
Added a toggle spectators to multiplayer.
Dune 2000:
Added the Atreides grenadier from the 1.06 patch.
Added randomized tiles for Sand and Rock terrain.

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Network
public int RandomSeed = 0;
public bool FragileAlliances = false; // Allow diplomatic stance changes after game start.
public bool AllowCheats = false;
public bool AllowSpectate = true;
public bool AllowSpectators = true;
public bool Dedicated;
public string Difficulty;
public bool Crates = true;

View File

@@ -276,7 +276,7 @@ namespace OpenRA.Server
IsAdmin = !LobbyInfo.Clients.Any(c1 => c1.IsAdmin)
};
if (client.IsObserver && !LobbyInfo.GlobalSettings.AllowSpectate)
if (client.IsObserver && !LobbyInfo.GlobalSettings.AllowSpectators)
{
SendOrderTo(newConn, "ServerError", "The game is full");
DropClient(newConn);
@@ -324,7 +324,7 @@ namespace OpenRA.Server
LobbyInfo.Clients.Add(client);
Log.Write("server", "Client {0}: Accepted connection from {1}.",
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
foreach (var t in serverTraits.WithInterface<IClientJoined>())
t.ClientJoined(this, newConn);

View File

@@ -390,6 +390,7 @@
<Compile Include="WaterPaletteRotation.cs" />
<Compile Include="Widgets\BuildPaletteWidget.cs" />
<Compile Include="Widgets\LogicTickerWidget.cs" />
<Compile Include="Widgets\Logic\KickSpectatorsLogic.cs" />
<Compile Include="Widgets\Logic\IngameMenuLogic.cs" />
<Compile Include="Widgets\Logic\IrcLogic.cs" />
<Compile Include="Widgets\Logic\KickClientLogic.cs" />

File diff suppressed because it is too large Load Diff

View File

@@ -75,8 +75,7 @@ namespace OpenRA.Mods.RA.Server
numBots,
"{0}@{1}".F(mod.Id, mod.Version),
server.LobbyInfo.GlobalSettings.Map,
server.Map.PlayerCount,
server.LobbyInfo.GlobalSettings.AllowSpectate));
server.Map.PlayerCount));
if (isInitialPing)
{

View File

@@ -0,0 +1,36 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
{
class KickSpectatorsLogic
{
[ObjectCreator.UseCtor]
public KickSpectatorsLogic(Widget widget, string clientCount, Action okPressed, Action cancelPressed)
{
widget.Get<LabelWidget>("TEXT").GetText = () => "Are you sure you want to kick {0} spectators?".F(clientCount);
widget.Get<ButtonWidget>("OK_BUTTON").OnClick = () =>
{
widget.Parent.RemoveChild(widget);
okPressed();
};
widget.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
{
widget.Parent.RemoveChild(widget);
cancelPressed();
};
}
}
}

View File

@@ -38,7 +38,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
readonly Action OnGameStart;
readonly Action onExit;
readonly OrderManager orderManager;
readonly OrderManager orderManager;
readonly bool skirmishMode;
// Listen for connection failures
void ConnectionStateChanged(OrderManager om)
@@ -54,7 +55,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
{ "onExit", onExit },
{ "onStart", OnGameStart },
{ "addBots", false }
{ "skirmishMode", false }
});
};
@@ -85,12 +86,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
[ObjectCreator.UseCtor]
internal LobbyLogic(Widget widget, World world, OrderManager orderManager,
Action onExit, Action onStart, bool addBots)
Action onExit, Action onStart, bool skirmishMode)
{
lobby = widget;
this.orderManager = orderManager;
this.OnGameStart = () => { CloseWindow(); onStart(); };
this.onExit = onExit;
this.onExit = onExit;
this.skirmishMode = skirmishMode;
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
@@ -173,7 +175,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
};
}
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
if (slotsButton != null)
{
@@ -471,7 +472,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ { "onExit", () => {} } });
// Add a bot on the first lobbyinfo update
if (addBots)
if (this.skirmishMode)
Game.LobbyInfoChanged += WidgetUtils.Once(() =>
{
var slot = orderManager.LobbyInfo.FirstEmptySlot();
@@ -614,7 +615,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
idx++;
}
// Add spectators
foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
{
@@ -655,48 +655,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic
idx++;
}
// Spectate button
if (orderManager.LocalClient.Slot != null)
{
// Spectate button
if (orderManager.LocalClient.Slot != null)
{
Widget spec = null;
if (idx < Players.Children.Count)
spec = Players.Children[idx];
if (spec == null || spec.Id != NewSpectatorTemplate.Id)
spec = NewSpectatorTemplate.Clone();
Widget spec = null;
if (idx < Players.Children.Count)
spec = Players.Children[idx];
if (spec == null || spec.Id != NewSpectatorTemplate.Id)
spec = NewSpectatorTemplate.Clone();
var block = spec.Get<ButtonWidget>("BLOCK_SPECTATE");
block.OnClick = () =>
{
orderManager.IssueOrder(Order.Command("allow_spectate False"));
orderManager.IssueOrders(
orderManager.LobbyInfo.Clients.Where(
c => c.IsObserver && !c.IsAdmin).Select(
client => Order.Command(String.Format("kick {0} {1}", client.Index, client.Name
))).ToArray());
};
block.IsVisible = () => orderManager.LocalClient.IsAdmin && orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
block.IsDisabled = () => !orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
var allow = spec.Get<ButtonWidget>("ALLOW_SPECTATE");
allow.OnClick = () => orderManager.IssueOrder(Order.Command("allow_spectate True"));
allow.IsVisible = () => orderManager.LocalClient.IsAdmin && !orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
allow.IsDisabled = () => orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
LobbyUtils.SetupKickSpectatorsWidget(spec, orderManager, lobby,
() => panel = PanelType.Kick, () => panel = PanelType.Players, this.skirmishMode);
var btn = spec.Get<ButtonWidget>("SPECTATE");
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
btn.IsDisabled = () => orderManager.LocalClient.IsReady;
btn.IsVisible = () => orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
spec.IsVisible = () => true;
var btn = spec.Get<ButtonWidget>("SPECTATE");
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
btn.IsDisabled = () => orderManager.LocalClient.IsReady;
btn.IsVisible = () => orderManager.LobbyInfo.GlobalSettings.AllowSpectators
|| orderManager.LocalClient.IsAdmin;
spec.IsVisible = () => true;
if (idx >= Players.Children.Count)
Players.AddChild(spec);
else if (Players.Children[idx].Id != spec.Id)
Players.ReplaceChild(Players.Children[idx], spec);
idx++;
}
if (idx >= Players.Children.Count)
Players.AddChild(spec);
else if (Players.Children[idx].Id != spec.Id)
Players.ReplaceChild(Players.Children[idx], spec);
idx++;
}
while (Players.Children.Count > idx)
Players.RemoveChild(Players.Children[idx]);

View File

@@ -293,6 +293,47 @@ namespace OpenRA.Mods.RA.Widgets.Logic
};
}
public static void SetupKickSpectatorsWidget(Widget parent, OrderManager orderManager, Widget lobby, Action before, Action after, bool skirmishMode)
{
var checkBox = parent.Get<CheckboxWidget>("TOGGLE_SPECTATORS");
checkBox.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowSpectators;
checkBox.IsVisible = () => orderManager.LocalClient.IsAdmin && !skirmishMode;
checkBox.IsDisabled = () => false;
Action okPressed = () =>
{
orderManager.IssueOrder(Order.Command("allow_spectators {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowSpectators)));
orderManager.IssueOrders(
orderManager.LobbyInfo.Clients.Where(
c => c.IsObserver && !c.IsAdmin).Select(
client => Order.Command(String.Format("kick {0} {1}", client.Index, client.Name
))).ToArray());
after();
};
checkBox.OnClick = () =>
{
before();
int spectatorCount = orderManager.LobbyInfo.Clients.Count(c => c.IsObserver);
if (spectatorCount > 0)
{
Game.LoadWidget(null, "KICK_SPECTATORS_DIALOG", lobby, new WidgetArgs
{
{ "clientCount", "{0}".F(spectatorCount) },
{ "okPressed", okPressed },
{ "cancelPressed", after }
});
}
else
{
orderManager.IssueOrder(Order.Command("allow_spectators {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowSpectators)));
after();
}
};
}
public static void SetupEditableColorWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, ColorPreviewManagerWidget colorPreview)
{
var color = parent.Get<DropDownButtonWidget>("COLOR");

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
{ "onExit", () => { Game.Disconnect(); menuType = MenuType.Main; } },
{ "onStart", RemoveShellmapUI },
{ "addBots", true }
{ "skirmishMode", true }
});
}

View File

@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
{ "onExit", Game.Disconnect },
{ "onStart", onStart },
{ "addBots", false }
{ "skirmishMode", false }
});
}

View File

@@ -199,6 +199,44 @@ Background@KICK_CLIENT_DIALOG:
Height:25
Text:Cancel
Font:Bold
Background@KICK_SPECTATORS_DIALOG:
X:15
Y:30
Width:501
Height:219
Logic:KickSpectatorsLogic
Background:scrollpanel-bg
Children:
Label@TITLE:
X:0
Y:40
Width:PARENT_RIGHT
Height:25
Font:Bold
Align:Center
Text:Kick Spectators
Label@TEXT:
X:0
Y:85
Width:PARENT_RIGHT
Height:25
Font:Regular
Align:Center
Button@OK_BUTTON:
X:(PARENT_RIGHT - WIDTH)/2 + 75
Y:155
Width:120
Height:25
Text:Ok
Font:Bold
Button@CANCEL_BUTTON:
X:(PARENT_RIGHT - WIDTH)/2 - 75
Y:155
Width:120
Height:25
Text:Cancel
Font:Bold
Background@LOBBY_OPTIONS_BIN:
X:15

View File

@@ -307,20 +307,13 @@ ScrollPanel@LOBBY_PLAYER_BIN:
Height:25
Visible:false
Children:
Button@ALLOW_SPECTATE:
Text:Allow Spectators
Checkbox@TOGGLE_SPECTATORS:
Font:Regular
Width:190
Height:25
Y:0
Height:20
X:15
Button@BLOCK_SPECTATE:
Text:Block Spectators
Font:Regular
Width:190
Height:25
Y:0
X:15
Text:Allow Spectators?
Button@SPECTATE:
Text:Spectate
Font:Regular

View File

@@ -298,20 +298,13 @@ ScrollPanel@LOBBY_PLAYER_BIN:
Height:25
Visible:false
Children:
Button@ALLOW_SPECTATE:
Text:Allow Spectators
Checkbox@TOGGLE_SPECTATORS:
Font:Regular
Width:165
Height:25
X:15
Y:0
Button@BLOCK_SPECTATE:
Text:Block Spectators
Font:Regular
Width:165
Height:25
Height:20
X:15
Y:0
Text:Allow Spectators?
Button@SPECTATE:
Text:Spectate
Font:Regular

View File

@@ -50,6 +50,44 @@ Background@KICK_CLIENT_DIALOG:
Text:Cancel
Font:Bold
Background@KICK_SPECTATORS_DIALOG:
X:20
Y:67
Width:535
Height:235
Logic:KickSpectatorsLogic
Background:dialog3
Children:
Label@TITLE:
X:0
Y:40
Width:PARENT_RIGHT
Height:25
Font:Bold
Align:Center
Text:Kick Spectators
Label@TEXT:
X:0
Y:85
Width:PARENT_RIGHT
Height:25
Font:Regular
Align:Center
Button@OK_BUTTON:
X:(PARENT_RIGHT - WIDTH)/2 + 75
Y:155
Width:120
Height:25
Text:Ok
Font:Bold
Button@CANCEL_BUTTON:
X:(PARENT_RIGHT - WIDTH)/2 - 75
Y:155
Width:120
Height:25
Text:Cancel
Font:Bold
Background@LOBBY_OPTIONS_BIN:
X:20
Y:67

View File

@@ -298,20 +298,13 @@ ScrollPanel@LOBBY_PLAYER_BIN:
Height:25
Visible:false
Children:
Button@ALLOW_SPECTATE:
Text:Allow Spectators
Checkbox@TOGGLE_SPECTATORS:
Font:Regular
Width:165
Height:25
X:15
Y:0
Button@BLOCK_SPECTATE:
Text:Block Spectators
Font:Regular
Width:165
Height:25
Height:20
X:15
Y:0
Text:Allow Spectators?
Button@SPECTATE:
Text:Spectate
Font:Regular