Added sprite loading,

resolved image clearing
This commit is contained in:
2021-10-18 12:23:54 +13:00
parent be4c8a2e64
commit f461603023
3 changed files with 56 additions and 1 deletions
+8
View File
@@ -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);
}
}
+30 -1
View File
@@ -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
}
}