public static void ReloadTextures(EventHandler <LoadProgressUpdatedEventArgs> updateEventHandler) { ITextureLoadStrategy resourceLoadStrategy; if (!LoadingWindowViewModel.Settings.GraphicsIsPackedResource) { resourceLoadStrategy = new FolderLoadStrategy(LoadingWindowViewModel.Settings.GraphicsFormat); } else { resourceLoadStrategy = new TCDLoadStrategy( LoadingWindowViewModel.Settings.GraphicsResourceFile, LoadingWindowViewModel.Settings.GraphicsResourceFilePassword, LoadingWindowViewModel.Settings.GraphicsResourceFileFormat); } var progressUpdateAction = default(EventHandler <LoadProgressUpdatedEventArgs>); progressUpdateAction = (sender, args) => { updateEventHandler(sender, args); if (args == null) { resourceLoadStrategy.ProgressUpdated -= progressUpdateAction; } }; resourceLoadStrategy.ProgressUpdated += progressUpdateAction; resourceLoadStrategy.Load(); Constants.TextureLoadStrategy = resourceLoadStrategy; }
public OpenGLRenderer(string tcdFile, string password, string graphicsFormat, double initialScaleX, double initialScaleY) { var loadStrategy = new TCDLoadStrategy(tcdFile, password, graphicsFormat); //var loadStrategy = new FolderTextureLoadStrategy("Graphics/{0}.png"); loadStrategy.ProgressUpdated += this.Load_ProgressUpdate; loadStrategy.Load(); this.renderer = new SpriteRendererPanel(loadStrategy, initialScaleX, initialScaleY); this.lastWasText = false; var usedFont = default(Font); var usedMiniFont = default(Font); var usedMicroFont = default(Font); if ((new InstalledFontCollection().Families).Any(f => f.Name == "Microsoft Sans Serif")) { usedFont = new Font("Microsoft Sans Serif", 15f, FontStyle.Regular); usedMiniFont = new Font("Microsoft Sans Serif", 12f, FontStyle.Regular); usedMicroFont = new Font("Microsoft Sans Serif", 11f, FontStyle.Regular); } else { this.customFontInstance = new PrivateFontCollection(); var assembly = Assembly.GetExecutingAssembly(); string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith(OpenGLRenderer.FallbackFont, StringComparison.InvariantCultureIgnoreCase)); byte[] fontBytes; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { fontBytes = new byte[stream.Length]; stream.Read(fontBytes, 0, fontBytes.Length); stream.Close(); } IntPtr handle = Marshal.AllocCoTaskMem(fontBytes.Length); Marshal.Copy(fontBytes, 0, handle, fontBytes.Length); this.customFontInstance.AddMemoryFont(handle, fontBytes.Length); Marshal.FreeCoTaskMem(handle); usedFont = new Font(this.customFontInstance.Families[0], 15, FontStyle.Regular); usedMiniFont = new Font(this.customFontInstance.Families[0], 12, FontStyle.Regular); usedMicroFont = new Font(this.customFontInstance.Families[0], 11, FontStyle.Regular); } this.regularFont = usedFont; this.miniFont = usedMiniFont; this.microFont = usedMicroFont; this.measurer = new GLTextMeasurer(usedFont, usedMiniFont, usedMicroFont); }
public static void ReloadSound(EventHandler <LoadProgressUpdatedEventArgs> updateEventHandler) { ISoundLoadStrategy resourceLoadStrategy; if (!LoadingWindowViewModel.Settings.SoundIsPackedResource) { resourceLoadStrategy = new FolderLoadStrategy(LoadingWindowViewModel.Settings.SoundFormat); } else { resourceLoadStrategy = new TCDLoadStrategy( LoadingWindowViewModel.Settings.SoundResourceFile, LoadingWindowViewModel.Settings.SoundResourceFilePassword, LoadingWindowViewModel.Settings.SoundResourceFileFormat); } var progressUpdateAction = default(EventHandler <LoadProgressUpdatedEventArgs>); progressUpdateAction = (sender, args) => { updateEventHandler(sender, args); if (args == null) { resourceLoadStrategy.ProgressUpdated -= progressUpdateAction; Application.Current.Dispatcher.Invoke(() => { Constants.SoundEffects.Clear(); var soundEffects = resourceLoadStrategy.GetProvidableFiles(); foreach (var se in soundEffects) { Constants.SoundEffects.Add(se); } Constants.SoundEffects.Add("none"); }); } }; resourceLoadStrategy.ProgressUpdated += progressUpdateAction; resourceLoadStrategy.Load(); Constants.SoundLoadStrategy = resourceLoadStrategy; }