Skip to content

Commit

Permalink
card list can be disabled by the host in the pregame lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
brine authored and kellyelton committed Dec 4, 2020
1 parent 6c2c459 commit 08b4b5f
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 19 deletions.
15 changes: 15 additions & 0 deletions octgnFX/Octgn.Core/GameSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class GameSettings : INotifyPropertyChanged
private bool _changeTwoSidedTable = true;
private bool _hideBoard = false;
private bool _allowSpectators = false;
private bool _allowCardList= false;
private bool _muteSpectators = false;

public GameSettings()
Expand Down Expand Up @@ -71,6 +72,20 @@ public bool AllowSpectators
}
}
}
public bool AllowCardList
{
get { return _allowCardList; }
set
{
if (value == _allowCardList)
return;
_allowCardList = value;
if (_initialized)
{
OnPropertyChanged("AllowCardList");
}
}
}

public bool MuteSpectators
{
Expand Down
9 changes: 9 additions & 0 deletions octgnFX/Octgn.JodsEngine/Controls/PreGameLobby.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@
<TextBlock Text="No Spectators" TextWrapping="Wrap"></TextBlock>
</toggleSwitch:HorizontalToggleSwitch.UncheckedContent>
</toggleSwitch:HorizontalToggleSwitch>
<toggleSwitch:HorizontalToggleSwitch Width="170" DataContext="{x:Static o:Program.GameSettings}" IsChecked="{Binding AllowCardList, Mode=TwoWay}" Margin="10,0,0,0"
IsEnabled="{Binding ElementName=me,Path=CanChangeSettings}">
<toggleSwitch:HorizontalToggleSwitch.CheckedContent>
<TextBlock Text="Allow Card List" TextWrapping="Wrap"></TextBlock>
</toggleSwitch:HorizontalToggleSwitch.CheckedContent>
<toggleSwitch:HorizontalToggleSwitch.UncheckedContent>
<TextBlock Text="Hidden Card List" TextWrapping="Wrap"></TextBlock>
</toggleSwitch:HorizontalToggleSwitch.UncheckedContent>
</toggleSwitch:HorizontalToggleSwitch>
</StackPanel>
</Border>
<Border Grid.Row="2" Margin="0,8,8,8" Style="{StaticResource PanelControl}" >
Expand Down
4 changes: 2 additions & 2 deletions octgnFX/Octgn.JodsEngine/Controls/PreGameLobby.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void PlayerOnOnLocalPlayerWelcomed()
if (Player.LocalPlayer.Id == 1 && !Program.GameEngine.IsReplay)
{
Dispatcher.BeginInvoke(new Action(() => { startBtn.Visibility = Visibility.Visible; }));
Program.Client.Rpc.Settings(Program.GameSettings.UseTwoSidedTable, Program.GameSettings.AllowSpectators, Program.GameSettings.MuteSpectators);
Program.Client.Rpc.Settings(Program.GameSettings.UseTwoSidedTable, Program.GameSettings.AllowSpectators, Program.GameSettings.MuteSpectators, Program.GameSettings.AllowCardList);
}
Player.LocalPlayer.SetPlayerColor(Player.LocalPlayer.Id);
this.StartingGame = true;
Expand All @@ -191,7 +191,7 @@ private void SettingsChanged(object sender, PropertyChangedEventArgs e)
{
if (DesignerProperties.GetIsInDesignMode(this)) return;
if (Program.IsHost)
Program.Client.Rpc.Settings(Program.GameSettings.UseTwoSidedTable, Program.GameSettings.AllowSpectators, Program.GameSettings.MuteSpectators);
Program.Client.Rpc.Settings(Program.GameSettings.UseTwoSidedTable, Program.GameSettings.AllowSpectators, Program.GameSettings.MuteSpectators, Program.GameSettings.AllowCardList);
}

private bool calledStart = false;
Expand Down
3 changes: 2 additions & 1 deletion octgnFX/Octgn.JodsEngine/Networking/BinaryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public void Parse(byte[] data)
var arg0 = reader.ReadBoolean();
var arg1 = reader.ReadBoolean();
var arg2 = reader.ReadBoolean();
var arg3 = reader.ReadBoolean();
Log.Debug($"OCTGN IN: Settings");
handler.Settings(arg0, arg1, arg2);
handler.Settings(arg0, arg1, arg2, arg3);
break;
}
case 7:
Expand Down
3 changes: 2 additions & 1 deletion octgnFX/Octgn.JodsEngine/Networking/BinaryStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void HelloAgain(byte pid, string nick, string userId, ulong pkey, string
Send(stream.ToArray());
}

public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators)
public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators, bool allowCardList)
{
Log.Debug($"OCTGN OUT: {nameof(Settings)}");
if(Program.Client == null)return;
Expand All @@ -116,6 +116,7 @@ public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectato
writer.Write(twoSidedTable);
writer.Write(allowSpectators);
writer.Write(muteSpectators);
writer.Write(allowCardList);
writer.Flush(); writer.Seek(0, SeekOrigin.Begin);
writer.Write((int)stream.Length);
writer.Close();
Expand Down
3 changes: 2 additions & 1 deletion octgnFX/Octgn.JodsEngine/Networking/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void Start()
}
}

public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators)
public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators, bool allowCardList)
{
WriteReplayAction();
// The host is the driver for this flag and should ignore notifications,
Expand All @@ -153,6 +153,7 @@ public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectato
Program.GameSettings.UseTwoSidedTable = twoSidedTable;
Program.GameSettings.AllowSpectators = allowSpectators;
Program.GameSettings.MuteSpectators = muteSpectators;
Program.GameSettings.AllowCardList = allowCardList;
}
}

Expand Down
2 changes: 1 addition & 1 deletion octgnFX/Octgn.JodsEngine/Networking/IServerCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IServerCalls
void Boot(Player player, string reason);
void Hello(string nick, string userId, ulong pkey, string client, Version clientVer, Version octgnVer, Guid gameId, Version gameVersion, string password, bool spectator);
void HelloAgain(byte pid, string nick, string userId, ulong pkey, string client, Version clientVer, Version octgnVer, Guid gameId, Version gameVersion, string password);
void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators);
void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators, bool allowCardList);
void PlayerSettings(Player playerId, bool invertedTable, bool spectator);
void Leave(Player player);
void Start();
Expand Down
2 changes: 1 addition & 1 deletion octgnFX/Octgn.JodsEngine/Play/PlayWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</MenuItem>
<MenuItem Header="Reset Screen Position" Command="gui:Commands.ResetScreen" />
<MenuItem Header="Extended Tooltips" IsCheckable="True" IsChecked="{Binding ShowExtendedTooltips, BindsDirectlyToSource=True, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type play:PlayWindow}}}" />
<MenuItem Header="Card List" IsCheckable="True" IsChecked="{Binding Source={x:Static octgn:Program.GameEngine}, Path=DeckStats.IsVisible}"></MenuItem>
<MenuItem Header="Card List" IsCheckable="True" IsEnabled="{Binding Source={x:Static octgn:Program.GameSettings}, Path=AllowCardList}" IsChecked="{Binding Source={x:Static octgn:Program.GameEngine}, Path=DeckStats.IsVisible}"></MenuItem>
<MenuItem x:Name="CardPreviewToggleChecked" Header="Undock Card Preview" Click="ToggleCardPreviewWindow" IsCheckable="True"></MenuItem>
<MenuItem x:Name="ChatToggleChecked" Header="Undock Chat" Click="ToggleChatDockPanel" IsCheckable="True"></MenuItem>
<MenuItem Header="Console" Click="ConsoleClicked" Visibility="Collapsed" x:Name="MenuConsole"/>
Expand Down
6 changes: 4 additions & 2 deletions octgnFX/Octgn.JodsEngine/Play/PlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public PlayWindow()
if (Program.IsHost) {
Program.Client.Rpc.Settings(Program.GameSettings.UseTwoSidedTable,
Program.GameSettings.AllowSpectators,
Program.GameSettings.MuteSpectators);
Program.GameSettings.MuteSpectators,
Program.GameSettings.AllowCardList);
}
};
} else {
Expand Down Expand Up @@ -705,7 +706,8 @@ protected override void OnKeyDown(KeyEventArgs e)
protected override void OnKeyUp(KeyEventArgs e)
{
if(e.Key == Key.F9) {
Program.GameEngine.DeckStats.IsVisible = !Program.GameEngine.DeckStats.IsVisible;
if (Program.GameSettings.AllowCardList)
Program.GameEngine.DeckStats.IsVisible = !Program.GameEngine.DeckStats.IsVisible;

e.Handled = true;

Expand Down
3 changes: 2 additions & 1 deletion octgnFX/Octgn.Server/BinaryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ public void Parse(byte[] data)
bool arg0 = reader.ReadBoolean();
bool arg1 = reader.ReadBoolean();
bool arg2 = reader.ReadBoolean();
bool arg3 = reader.ReadBoolean();
Log.Debug($"SERVER IN: Settings");
_socket.Handler.Settings(arg0, arg1, arg2);
_socket.Handler.Settings(arg0, arg1, arg2, arg3);
break;
}
case 7:
Expand Down
3 changes: 2 additions & 1 deletion octgnFX/Octgn.Server/BinaryStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void Welcome(byte id, Guid gameSessionId, string gameName, bool waitForGa
}
}

public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators)
public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators, bool allowCardList)
{
Log.Debug($"SERVER OUT: {nameof(Settings)}");
using(var stream = new MemoryStream(512)) {
Expand All @@ -83,6 +83,7 @@ public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectato
writer.Write(twoSidedTable);
writer.Write(allowSpectators);
writer.Write(muteSpectators);
writer.Write(allowCardList);
writer.Flush(); writer.Seek(0, SeekOrigin.Begin);
writer.Write((int)stream.Length);
writer.Close();
Expand Down
4 changes: 2 additions & 2 deletions octgnFX/Octgn.Server/Broadcaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public void Welcome(byte id, Guid gameSessionId, string gameName, bool waitForGa
}
}

public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators)
public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators, bool allowCardList)
{
foreach(var ply in _players.Players){
if(ply.Connected){
ply.Rpc.Settings(twoSidedTable, allowSpectators, muteSpectators);
ply.Rpc.Settings(twoSidedTable, allowSpectators, muteSpectators, allowCardList);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions octgnFX/Octgn.Server/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,21 @@ public void Start() {
}
}

public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators) {
public void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators, bool allowCardList) {
var player = _player;

if (player.Id != Player.HOSTPLAYERID) return;

_context.State.Settings.AllowSpectators = allowSpectators;
_context.State.Settings.MuteSpectators = muteSpectators;
_context.State.Settings.AllowCardList = allowCardList;
_context.Game.Spectators = allowSpectators;

// We can't change this after the game is started, so don't change it
if (!GameStarted)
_context.State.Settings.UseTwoSidedTable = twoSidedTable;

_context.Broadcaster.Settings(_context.State.Settings.UseTwoSidedTable, allowSpectators, muteSpectators);
_context.Broadcaster.Settings(_context.State.Settings.UseTwoSidedTable, allowSpectators, muteSpectators, allowCardList);
}

public void PlayerSettings(byte player, bool invertedTable, bool spectator) {
Expand Down Expand Up @@ -226,7 +227,7 @@ public void Hello(string nick, string userId, ulong pkey, string client, Version
_player.Rpc.NewPlayer(player.Id, player.Nick, player.UserId, player.Pkey, player.Settings.InvertedTable, player.Settings.IsSpectator);

// Notify the newcomer of table sides
_player.Rpc.Settings(_context.State.Settings.UseTwoSidedTable, _context.State.Settings.AllowSpectators, _context.State.Settings.MuteSpectators);
_player.Rpc.Settings(_context.State.Settings.UseTwoSidedTable, _context.State.Settings.AllowSpectators, _context.State.Settings.MuteSpectators, _context.State.Settings.AllowCardList);

// Add it to our lists
if (GameStarted) {
Expand Down Expand Up @@ -275,7 +276,7 @@ public void HelloAgain(byte pid, string nick, string userId, ulong pkey, string
oldPlayerInfo.Rpc.NewPlayer(player.Id, player.Nick, player.UserId, player.Pkey, player.Settings.InvertedTable, player.Settings.IsSpectator);

// Notify the newcomer of some shared settings
oldPlayerInfo.Rpc.Settings(_context.State.Settings.UseTwoSidedTable, _context.State.Settings.AllowSpectators, _context.State.Settings.MuteSpectators);
oldPlayerInfo.Rpc.Settings(_context.State.Settings.UseTwoSidedTable, _context.State.Settings.AllowSpectators, _context.State.Settings.MuteSpectators, _context.State.Settings.AllowCardList);
foreach (var player in _context.State.Players.Players)
oldPlayerInfo.Rpc.PlayerSettings(player.Id, player.Settings.InvertedTable, player.Settings.IsSpectator);

Expand Down
2 changes: 1 addition & 1 deletion octgnFX/Octgn.Server/IClientCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IClientCalls
void Error(string msg);
void Kick(string reason);
void Welcome(byte id, Guid gameSessionId, string gameName, bool waitForGameState);
void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators);
void Settings(bool twoSidedTable, bool allowSpectators, bool muteSpectators, bool allowCardList);
void PlayerSettings(byte playerId, bool invertedTable, bool spectator);
void NewPlayer(byte id, string nick, string userId, ulong pkey, bool tableSide, bool spectator);
void Leave(byte player);
Expand Down
1 change: 1 addition & 0 deletions octgnFX/Octgn.Server/Protocol.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<param name="twoSidedTable" type="bool" />
<param name="allowSpectators" type="bool"/>
<param name="muteSpectators" type="bool"/>
<param name="allowCardList" type="bool"/>
</msg>
<msg name="PlayerSettings" server="true" client="true" allowedbyspectator="true">
<param name="playerId" type="PlayerOrSpectator" />
Expand Down
2 changes: 1 addition & 1 deletion recentchanges.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

Host can enable the card list panel in the pre-game lobby (disabled by default)

0 comments on commit 08b4b5f

Please sign in to comment.