public static string Normalize(string fileName, string[] extensions) { #if WINRT if (MetroHelper.AppDataFileExists(fileName)) { return(fileName); } #else if (File.Exists(fileName)) { return(fileName); } #endif foreach (string ext in extensions) { // Concat the file name with valid extensions string fileNamePlusExt = fileName + ext; #if WINRT if (MetroHelper.AppDataFileExists(fileNamePlusExt)) { return(fileNamePlusExt); } #else if (File.Exists(fileNamePlusExt)) { return(fileNamePlusExt); } #endif } return(null); }
/// <summary> /// /// </summary> /// <param name="fntFilePath"></param> /// <param name="fontTexturePath"></param> /// <param name="name"></param> /// <returns></returns> public static BitmapFontRenderer AddBMFont(string fntFilePath, string fontTexturePath, string name) { if (!fontRenderers.ContainsKey(name)) { string _fntFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, fntFilePath); string _textureFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, fontTexturePath); #if WINDOWS if (File.Exists(_fntFilePath) && File.Exists(_textureFilePath)) #elif WINRT if (MetroHelper.AppDataFileExists(_fntFilePath) && MetroHelper.AppDataFileExists(_textureFilePath)) #endif { FontFile fontFile = FontLoader.Load(_fntFilePath); Texture2D fontTexture = TextureLoader.FromFile(_textureFilePath); BitmapFontRenderer fr = new BitmapFontRenderer(fontFile, fontTexture); fontRenderers[name] = fr; return(fr); } } return(null); }
public void SetItemDescriptions() { if (SourceItems == null) { return; } foreach (var item in SourceItems) { item.Description = MetroHelper.GetRailwayDescription(item.RailwayIds[0], Settings.Current.LanguageTag); } }
private void LoadData() { string _fntFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, fntFilePath); string _textureFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, textureFilePath); #if WINDOWS if (File.Exists(_fntFilePath) && File.Exists(_textureFilePath)) #elif WINRT if (MetroHelper.AppDataFileExists(_fntFilePath) && MetroHelper.AppDataFileExists(_textureFilePath)) #endif { this.fontFile = FontLoader.Load(_fntFilePath); this.fontTexture = TextureLoader.FromFile(_textureFilePath); this.fontRenderer = new BitmapFontRenderer(this.fontFile, this.fontTexture); } }
/// <summary> /// Loads a texture from a file. /// </summary> /// <param name="filename">The filename of the texture to load</param> /// <returns>The loaded texture, null if not loaded</returns> public static Texture2D FromFile(string filename) { if (SceneManager.GraphicsDevice == null) { return(null); } // The image was already loaded to memory? if (!textures.ContainsKey(filename) || SceneManager.IsEditor) { #if WINDOWS FileInfo aTexturePath = new FileInfo(filename); // The file exists? if (!aTexturePath.Exists) { return(null); } FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); Texture2D texture = Texture2D.FromStream(SceneManager.GraphicsDevice, fs); fs.Close(); // Store in the dictionary the loaded texture textures[filename] = texture; #elif WINRT if (!MetroHelper.AppDataFileExists(filename)) { return(null); } using (Stream stream = Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForReadAsync(filename).Result) { Texture2D texture = Texture2D.FromStream(SceneManager.GraphicsDevice, stream); textures[filename] = texture; } #endif } return(textures[filename]); }