Merged image loading from MainWindow in server context
This commit is contained in:
parent
236af4e9ab
commit
be4c8a2e64
@ -57,7 +57,7 @@ namespace RBG_Server
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadStream(Stream source, string path, bool isSprite)
|
public void LoadStream(Stream source, string path, bool isSprite)
|
||||||
{
|
{
|
||||||
long srcStart = source.Position;
|
long srcStart = source.Position;
|
||||||
byte[] vs = new byte[6]; // First 6 bytes is the gif specifier
|
byte[] vs = new byte[6]; // First 6 bytes is the gif specifier
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<Button x:Name="HostButton" Content="Host a Game" Margin="0,0,0,5" Click="HostButton_Click"/>
|
<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"/>
|
<Button x:Name="ConnectButton" Content="Connect to Server" Margin="0,5,0,0" Click="ConnectButton_Click"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Grid x:Name="ServerGrid" d:IsHidden="True">
|
<Grid x:Name="ServerGrid">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition MaxWidth="400"/>
|
<ColumnDefinition MaxWidth="400"/>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
@ -50,7 +50,7 @@
|
|||||||
<Grid x:Name="PreviewImageOverlay" HorizontalAlignment="Center" VerticalAlignment="Center" Width="{Binding ActualWidth, ElementName=PreviewImage}" Height="{Binding ActualHeight, ElementName=PreviewImage}"/>
|
<Grid x:Name="PreviewImageOverlay" HorizontalAlignment="Center" VerticalAlignment="Center" Width="{Binding ActualWidth, ElementName=PreviewImage}" Height="{Binding ActualHeight, ElementName=PreviewImage}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid x:Name="ClientGrid">
|
<Grid x:Name="ClientGrid" d:IsHidden="True">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Button x:Name="ClientBackButton" Content="Back" Margin="0,5,0,0" HorizontalAlignment="Center" Click="ClientBackButton_Click"/>
|
<Button x:Name="ClientBackButton" Content="Back" Margin="0,5,0,0" HorizontalAlignment="Center" Click="ClientBackButton_Click"/>
|
||||||
<TextBlock Text="Server Address:" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" HorizontalAlignment="Center"/>
|
<TextBlock Text="Server Address:" TextWrapping="Wrap" Padding="0,10,0,0" Foreground="White" HorizontalAlignment="Center"/>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using RBG_Server;
|
using Microsoft.Win32;
|
||||||
|
using RBG_Server;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -247,6 +248,103 @@ namespace RBG_Server_WPF
|
|||||||
// *************** Server Connection Logic *******************
|
// *************** Server Connection Logic *******************
|
||||||
// ************************************************************
|
// ************************************************************
|
||||||
#region server connection logic
|
#region server connection logic
|
||||||
|
private static readonly SolidColorBrush borderBrush = new(Color.FromRgb(255, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
|
private void BrowseButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
OpenFileDialog ofd = new();
|
||||||
|
ofd.Filter = "Image Files|*.png;*.jpg";
|
||||||
|
if (ofd.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
ImageSourceTextBox.Text = ofd.FileName;
|
||||||
|
UpdateImage().Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Update the image when the text box looses focus
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ImageSourceTextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateImage().Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task UpdateImage()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CommunicationHandler host = App.Context.GameCommunicationHandler;
|
||||||
|
using FileStream fs = File.OpenRead(ImageSourceTextBox.Text);
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
|
||||||
|
fs.CopyTo(ms);
|
||||||
|
// Calc mips
|
||||||
|
ms.Position = 0;
|
||||||
|
App.Context.LoadStream(ms, Name, false);
|
||||||
|
ms.Position = 0;
|
||||||
|
BitmapImage gameBoardImage = new();
|
||||||
|
gameBoardImage.BeginInit();
|
||||||
|
gameBoardImage.StreamSource = ms;
|
||||||
|
gameBoardImage.EndInit();
|
||||||
|
PreviewImage.Source = gameBoardImage;
|
||||||
|
RedrawGrid();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws the overlay grid, clearing existing elements if necessary
|
||||||
|
/// </summary>
|
||||||
|
private void RedrawGrid()
|
||||||
|
{
|
||||||
|
|
||||||
|
PreviewImageOverlay.RowDefinitions.Clear();
|
||||||
|
PreviewImageOverlay.ColumnDefinitions.Clear();
|
||||||
|
PreviewImageOverlay.Children.Clear();
|
||||||
|
for (int i = 0; i < NumberOfColumns.Value; i++)
|
||||||
|
{
|
||||||
|
PreviewImageOverlay.ColumnDefinitions.Add(new ColumnDefinition());
|
||||||
|
}
|
||||||
|
for (int i = 0; i < NumberOfRows.Value; i++)
|
||||||
|
{
|
||||||
|
PreviewImageOverlay.RowDefinitions.Add(new RowDefinition());
|
||||||
|
}
|
||||||
|
// Draw the overlay
|
||||||
|
Rectangle overlay = new();
|
||||||
|
overlay.Fill = new SolidColorBrush(Color.FromArgb(128, 0, 128, 255));
|
||||||
|
_ = PreviewImageOverlay.Children.Add(overlay);
|
||||||
|
Grid.SetRow(overlay, (int)ZoomBoxStartRow.Value);
|
||||||
|
Grid.SetColumn(overlay, (int)ZoomBoxStartColumn.Value);
|
||||||
|
Grid.SetRowSpan(overlay, (int)ZoomBoxSpan.Value);
|
||||||
|
Grid.SetColumnSpan(overlay, (int)ZoomBoxSpan.Value);
|
||||||
|
// Draw the starting position
|
||||||
|
overlay = new();
|
||||||
|
overlay.Fill = new SolidColorBrush(Color.FromArgb(64, 0, 255, 128));
|
||||||
|
_ = PreviewImageOverlay.Children.Add(overlay);
|
||||||
|
Grid.SetRow(overlay, (int)StartingRow.Value);
|
||||||
|
Grid.SetColumn(overlay, (int)StartingColumn.Value);
|
||||||
|
// Draw grids onto the preview image
|
||||||
|
for (int v = 0; v < PreviewImageOverlay.RowDefinitions.Count; v++)
|
||||||
|
{
|
||||||
|
for (int u = 0; u < PreviewImageOverlay.ColumnDefinitions.Count; u++)
|
||||||
|
{
|
||||||
|
Border border = new();
|
||||||
|
border.BorderBrush = borderBrush;
|
||||||
|
border.BorderThickness = new Thickness(2);
|
||||||
|
_ = PreviewImageOverlay.Children.Add(border);
|
||||||
|
Grid.SetRow(border, v);
|
||||||
|
Grid.SetColumn(border, u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user