Added connection page
This commit is contained in:
parent
54061d1a62
commit
53aa75df2b
56
PDGServer_WPF/ConnectionPage.xaml
Normal file
56
PDGServer_WPF/ConnectionPage.xaml
Normal file
@ -0,0 +1,56 @@
|
||||
<Page x:Class="RBG_Server_WPF.ConnectionPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:RBG_Server_WPF"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
Title="ConnectionPage" MinWidth="1024" MinHeight="762">
|
||||
|
||||
<Grid x:Name="RootGrid">
|
||||
<StackPanel x:Name="ServerSelectPanel" HorizontalAlignment="Center" VerticalAlignment="Center" d:IsHidden="True" >
|
||||
<Button x:Name="HostButton" Content="Host a Game" Margin="0,0,0,5" Click="HostButton_Click"/>
|
||||
<Button x:Name="ConnectButton" Content="Connect to Server" Margin="0,5,0,0" Click="ConnectButton_Click"/>
|
||||
</StackPanel>
|
||||
<Grid x:Name="ServerGrid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MaxWidth="400"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel>
|
||||
<Button x:Name="BackButton" Content="Back" HorizontalAlignment="Left" Margin="5,5,0,0" Click="BackButton_Click"/>
|
||||
<TextBlock Text="Game Board File Path" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,5,2,0"/>
|
||||
<TextBox x:Name="ImageSourceTextBox" TextWrapping="Wrap" LostFocus="ImageSourceTextBox_LostFocus" Margin="2,5,2,0"/>
|
||||
<Button x:Name="BrowseButton" Content="Browse" Click="BrowseButton_Click" Margin="10,5,10,0"/>
|
||||
<TextBlock Text="Game Sprites Files" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<TextBox x:Name="ImageSourceTextBox_Copy" TextWrapping="Wrap" LostFocus="ImageSourceTextBox_LostFocus" Margin="2,5,2,0"/>
|
||||
<Button x:Name="GameSpritesBrowser" Content="Browse" Click="GameSpritesBrowser_Click" Margin="10,5,10,0"/>
|
||||
<TextBlock Text="Number of Rows" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<Slider x:Name="NumberOfRows" IsSnapToTickEnabled="True" Minimum="1" TickPlacement="BottomRight" AutoToolTipPlacement="BottomRight" ValueChanged="NumberOfRows_ValueChanged" Value="9" Margin="2,0,2,0"/>
|
||||
<TextBlock Text="Number of Columns:" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<Slider x:Name="NumberOfColumns" IsSnapToTickEnabled="True" Minimum="1" TickPlacement="BottomRight" AutoToolTipPlacement="BottomRight" ValueChanged="NumberOfColumns_ValueChanged" Value="9" Margin="2,0,2,0"/>
|
||||
<TextBlock Text="Starting Row" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<Slider x:Name="StartingRow" IsSnapToTickEnabled="True" Value="8" AutoToolTipPlacement="BottomRight" TickPlacement="BottomRight" ValueChanged="Sliders_ValueChanged" Maximum="9" Margin="2,0,2,0"/>
|
||||
<TextBlock Text="Starting Column" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<Slider x:Name="StartingColumn" IsSnapToTickEnabled="True" AutoToolTipPlacement="BottomRight" TickPlacement="BottomRight" ValueChanged="Sliders_ValueChanged" Maximum="9" Margin="2,0,2,0"/>
|
||||
<TextBlock Text="Zoom Box Starting Row" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<Slider x:Name="ZoomBoxStartRow" IsSnapToTickEnabled="True" AutoToolTipPlacement="BottomRight" TickPlacement="BottomRight" Value="3" ValueChanged="Sliders_ValueChanged" Maximum="9" Margin="2,0,2,0"/>
|
||||
<TextBlock Text="Zoom Box Starting Column" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<Slider x:Name="ZoomBoxStartColumn" IsSnapToTickEnabled="True" AutoToolTipPlacement="BottomRight" TickPlacement="BottomRight" Value="3" ValueChanged="Sliders_ValueChanged" Maximum="9" Margin="2,0,2,0"/>
|
||||
<TextBlock Text="Zoom Box Span" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" Margin="2,0,2,0"/>
|
||||
<Slider x:Name="ZoomBoxSpan" IsSnapToTickEnabled="True" AutoToolTipPlacement="BottomRight" TickPlacement="BottomRight" Value="3" ValueChanged="Sliders_ValueChanged" Minimum="1" Maximum="6" Margin="2,0,2,0"/>
|
||||
<Button x:Name="GridVisibilityToggleButton" Content="Show/Hide Grid" Click="GridVisibilityToggleButton_Click" Margin="10,10,10,0"/>
|
||||
<Button x:Name="StartServerButton" Content="Start Server" HorizontalAlignment="Stretch" Margin="10,25,10,0" Click="StartServerButton_Click" Background="#955FF17A" Foreground="White"/>
|
||||
<Button x:Name="DrawRandomizedPlayers" Content="Draw Random Players" Margin="10,25,10,0" Click="DrawRandomizedPlayers_Click" d:IsHidden="True"/>
|
||||
<UniformGrid x:Name="LoadedSprites" Columns="6" Margin="2,0,2,0" Rows="6" MinHeight="120" />
|
||||
</StackPanel>
|
||||
<Grid x:Name="BoardPreview" Grid.Column="1" VerticalAlignment="Center">
|
||||
<Image x:Name="PreviewImage" MinHeight="150" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<Grid x:Name="PreviewImageOverlay" HorizontalAlignment="Center" VerticalAlignment="Center" Width="{Binding ActualWidth, ElementName=PreviewImage}" Height="{Binding ActualHeight, ElementName=PreviewImage}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
|
||||
</Grid>
|
||||
</Page>
|
47
PDGServer_WPF/ConnectionPage.xaml.cs
Normal file
47
PDGServer_WPF/ConnectionPage.xaml.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace RBG_Server_WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ConnectionPage.xaml
|
||||
/// </summary>
|
||||
public partial class ConnectionPage : Page
|
||||
{
|
||||
public ConnectionPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void HostButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Draw host window
|
||||
ServerGrid.Visibility = Visibility.Visible;
|
||||
ServerSelectPanel.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void ConnectButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Draw client window
|
||||
}
|
||||
|
||||
private void BackButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Hide host view, show connect view
|
||||
ServerGrid.Visibility = Visibility.Collapsed;
|
||||
ServerSelectPanel.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,9 @@ namespace RBG_Server
|
||||
/// </summary>
|
||||
public ConcurrentDictionary<string, CachedByteArray> ImageCollection { get; } = new();
|
||||
|
||||
public List<Player> Players { get; } = new List<Player>();
|
||||
public Dictionary<int,Player> Players { get; } = new Dictionary<int, Player>();
|
||||
|
||||
public Player Self { get;set; }
|
||||
|
||||
public List<string> ImageList { get; } = new();
|
||||
|
||||
@ -100,8 +102,11 @@ namespace RBG_Server
|
||||
Task dataLoader = InitDataLoader(dataRetriever.GetStream(), dataProgress);
|
||||
Task stateLoader = InitDataLoader(stateRetriever.GetStream(), gameProgress);
|
||||
|
||||
// Data loader starts first - we're waiting for the thumbs to load so the player can choose thier
|
||||
dataLoader.Start();
|
||||
// State
|
||||
stateLoader.Start();
|
||||
|
||||
}
|
||||
|
||||
struct ProgressData
|
||||
@ -187,7 +192,7 @@ namespace RBG_Server
|
||||
|
||||
private async Task InitGameLoader(NetworkStream stateStream, IProgress<ProgressData> progressUpdates)
|
||||
{
|
||||
// Get game board details
|
||||
// Coomunication has already been opened with the server; must ID
|
||||
byte[] buffer = new byte[] { 1, 0, 0, 0, 1 };
|
||||
stateStream.Write(buffer, 0, buffer.Length);
|
||||
// Response size
|
||||
@ -211,6 +216,8 @@ namespace RBG_Server
|
||||
stateResponse = await GetResponse(stateStream, GetInt32(stateResponse));
|
||||
// state response contains a player list;
|
||||
// Player ID (Int32)
|
||||
// Player hash length:
|
||||
// Player 'Unique' Hash
|
||||
// Player Name (null-terminated string)
|
||||
// Player Sprite (null-terminated string)
|
||||
// Player Column (Int32)
|
||||
@ -222,6 +229,12 @@ namespace RBG_Server
|
||||
int pos = start + 4;
|
||||
int responsePlayerID = GetInt32(stateResponse[start..pos]);
|
||||
start = pos;
|
||||
pos += 4;
|
||||
int length = GetInt32(stateResponse[start..pos]);
|
||||
start = pos;
|
||||
pos += length;
|
||||
byte[] playerHash = stateResponse[start..pos];
|
||||
start = pos;
|
||||
while (stateResponse[pos++] != 0) ; // skip the bytes that aren't null
|
||||
string responsePlayerName = Encoding.UTF8.GetString(stateResponse[start..pos]);
|
||||
start = pos;
|
||||
@ -234,8 +247,8 @@ namespace RBG_Server
|
||||
pos += 4;
|
||||
int playerRow = GetInt32(stateResponse[start..pos]);
|
||||
start = pos;
|
||||
Player player = new Player(responsePlayerName, responsePlayerSprite, playerRow, playerColumn);
|
||||
Players.Add(player);
|
||||
Player player = new Player(responsePlayerName, responsePlayerSprite, playerHash, playerRow, playerColumn);
|
||||
Players.Add(responsePlayerID, player); // We build a reference of response ID --> Player, and the players are ID'd by the hash. We can use this to modify
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user