コード例 #1
0
        public void LoadFile(string path)
        {
            if (path == null)
            {
                return;
            }

            // Check if its a PCK
            if (path.ToLowerInvariant().Contains(".pck"))
            {
                LoadFontPCK(path);
                return;
            }

            // Check if file is valid and make sure FilePath is the .code
            if (path.ToLowerInvariant().Contains("_data.tex") || path.ToLowerInvariant().Contains(".code"))
            {
                FilePath = path.Replace("_data.tex", ".code");
            }
            else
            {
                MessageBox.Show($"Unknown file type\n{path}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Recreate Objects
            FontImageTexFile           = new TEXFile();
            FontCodeFile               = new FontFile();
            FontCodeFile.MonospaceOnly = MonospaceOnly;

            try
            {
                // Load Font TEX
                FontImageTexFile.Load(FilePath.Replace(".code", "_data.tex"));
                UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap());
            }
            catch
            {
                MessageBox.Show("Failed to load Texture!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            LastIndex  = -1;
            HoverIndex = -1;

            // Load FontCode
            FontCodeFile.Load(FilePath);

            // Reload
            ReloadUI();

            UI_SaveButton.IsEnabled = true;
        }
コード例 #2
0
ファイル: MainMenuGameState.cs プロジェクト: HotPrawns/Jiemyu
        /// <summary>
        ///
        /// </summary>
        override public void Initialize()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            var fontFilePath = Path.Combine(Game.Content.RootDirectory, "calibri32.fnt");

            using (var stream = TitleContainer.OpenStream(fontFilePath))
            {
                var fontFile    = FontFile.Load(stream);
                var fontTexture = Game.Content.Load <Texture2D>("calibri32_0.png");

                textRenderer = new TextRenderer(fontFile, fontTexture);
                stream.Close();
            }

            base.Initialize();
        }
コード例 #3
0
        public void LoadFontPCK(string path)
        {
            FilePath       = path;
            PCKFontArchive = new PCKFile();
            PCKFontArchive.Load(path);

            var textureFilePath  = PCKFontArchive.SearchForFile(".tex");
            var fontCodeFilePath = PCKFontArchive.SearchForFile(".code");

            FontImageTexFile           = new TEXFile();
            FontCodeFile               = new FontFile();
            FontCodeFile.MonospaceOnly = MonospaceOnly;

            // Load Font Code
            if (fontCodeFilePath != null)
            {
                FontCodeFile.Load(PCKFontArchive.GetFileStream(fontCodeFilePath));
            }
            else
            {
                MessageBox.Show("Failed to load Code File!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (textureFilePath != null)
            {
                // Load Texture
                FontImageTexFile.Load(PCKFontArchive.GetFileStream(textureFilePath));
                // Set Texture
                UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap());
            }
            else
            {
                MessageBox.Show("Failed to load Texture!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            LastIndex  = -1;
            HoverIndex = -1;

            // Reload
            ReloadUI();

            UI_SaveButton.IsEnabled = true;
        }