Added sprite loading,
resolved image clearing
This commit is contained in:
parent
be4c8a2e64
commit
f461603023
@ -188,7 +188,15 @@ namespace RBG_Server
|
||||
source.CopyTo(ms);
|
||||
_ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_RAW + Path.GetExtension(path), new CachedByteArray(ms.ToArray()));
|
||||
}
|
||||
// Destroy old board if we are replacing
|
||||
if (!string.IsNullOrEmpty(GameCommunicationHandler.BoardName))
|
||||
{
|
||||
GameCommunicationHandler.ImageCollection.Remove(GameCommunicationHandler.BoardName, out CachedByteArray val);
|
||||
val.Dispose();
|
||||
}
|
||||
GameCommunicationHandler.BoardName = path;
|
||||
}
|
||||
GameCommunicationHandler.ImageList.Add(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,8 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
// Not using Shapes.Path so specify Path = System.IO
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace RBG_Server_WPF
|
||||
{
|
||||
@ -343,9 +345,36 @@ namespace RBG_Server_WPF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the selected sprites into the image list
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void GameSpritesBrowser_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CommunicationHandler host = App.Context.GameCommunicationHandler;
|
||||
OpenFileDialog ofd = new();
|
||||
ofd.Filter = "Image Files|*.png;*.jpg;*.gif";
|
||||
ofd.Multiselect = true;
|
||||
if (ofd.ShowDialog() == true)
|
||||
{
|
||||
string[] resultFiles = ofd.FileNames;
|
||||
// Clear existing sprites
|
||||
host.ClearSprites();
|
||||
// Finally, load the sprites
|
||||
foreach (string file in resultFiles)
|
||||
{
|
||||
using FileStream fs = File.OpenRead(file);
|
||||
string fileName = Path.GetFileName(file);
|
||||
host.ImageList.Add(fileName);
|
||||
App.Context.LoadStream(fs, fileName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,24 @@ namespace RBG_Server
|
||||
});
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Clears all sprites, but not the board image, from the collection; disposing data as required
|
||||
/// </summary>
|
||||
public void ClearSprites()
|
||||
{
|
||||
// Remove all existing except the board image
|
||||
foreach (string image in ImageList)
|
||||
{
|
||||
if (image != BoardName)
|
||||
{
|
||||
ImageCollection.Remove(image, out CachedByteArray removed);
|
||||
removed.Dispose();
|
||||
}
|
||||
}
|
||||
// Reset the image list
|
||||
ImageList.Clear();
|
||||
ImageList.Add(BoardName);
|
||||
}
|
||||
|
||||
private void AcceptConnections(TcpClient client)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user