private void button_LoadFont_Click(object sender, EventArgs e)
        {
            if (_modifiedImage == null)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "Conan Font File|FONT.BIN";

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    _fontFile = new FONTFile(openFileDialog.FileName);
                }
            }
            else
            {
                PKNFile  graphPkn = _modifiedImage.PKNFiles?.Find(pkn => pkn.Name == "GRAPH");
                BaseFile fontFile = graphPkn?.Files?.Find(file => file.FileName == "FONT.BIN");
                if (fontFile == null)
                {
                    return;
                }

                _fontFile = new FONTFile(fontFile.FilePath);
            }
            _fontFile.Load();

            FontList = _fontFile.Characters.Select(character => character.GetBitmap()).ToList();
            pictureBox_CharacterMap.Image = Graphic.CombineBitmaps(FontList, 42);
            MessageBox.Show("Symbols loaded: " + FontList.Count + " (default engine maximum)");
        }
Exemple #2
0
        private void GenerateFont()
        {
            PKNFile pknFile = ApplicationState.Instance.ProjectFile.ModifiedImage.PKNFiles.FirstOrDefault(p => p.Name == "GRAPH");

            if (pknFile != null)
            {
                BaseFile baseFile = pknFile.Files.FirstOrDefault(f => f.FileName == "FONT.BIN");
                if (baseFile != null)
                {
                    FONTFile fontFile = (FONTFile)baseFile;
                    fontFile.Characters = ScriptFile.GeneratedFont;
                    fontFile.Save();
                    return;
                }
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "FONT.BIN|FONT.BIN";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                FONTFile fontFile = new FONTFile(saveFileDialog.FileName);
                fontFile.Characters = ScriptFile.GeneratedFont;
                fontFile.Save();
            }
        }
        public ScriptAnalyseWindow(ScriptCollection scriptFileCollection)
        {
            InitializeComponent();
            _scriptFileCollection = scriptFileCollection;
            List <string> lines = ParseScripts();

            foreach (string line in lines)
            {
                richTextBox1.AppendText(line + "\n");
            }

            HashSet <string> dictionary = CreateDictionary(lines);

            richTextBox1.AppendText("\nDictionary( " + dictionary.Count + " Symbols ):");
            foreach (string characters in dictionary)
            {
                richTextBox1.AppendText(characters + "\n");
            }

            string[] unsortedDictionary = dictionary.ToArray();
            string[] sortedDictionary   = dictionary.OrderBy(entry => entry).ToArray();

            if (ApplicationState.Instance.ProjectFile != null)
            {
                _modifiedImage = ApplicationState.Instance.ProjectFile.ModifiedImage;
            }

            if (_modifiedImage == null)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "Conan Font File|FONT.BIN";

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    _fontFile = new FONTFile(openFileDialog.FileName);
                }
            }
            else
            {
                PKNFile  graphPkn = _modifiedImage.PKNFiles?.Find(pkn => pkn.Name == "GRAPH");
                BaseFile fontFile = graphPkn?.Files?.Find(file => file.FileName == "FONT.BIN");
                if (fontFile == null)
                {
                    return;
                }

                _fontFile = new FONTFile(fontFile.FilePath);
            }
            _fontFile.Load();

            _fontFile.Generate(unsortedDictionary, new Font("ConanFont", 12));
            _fontFile.Save();
        }
        private void InitializeCharacters()
        {
            _fontFile = ApplicationState.Instance.ProjectFile.ModifiedImage.FONTFile;
            _fontFile.Load();

            ImageList imageList = new ImageList();

            imageList.ImageSize = new Size(16, 16);
            foreach (FontCharacter character in _fontFile.Characters)
            {
                imageList.Images.Add(character.Index.ToString(), character.GetBitmap());
            }

            Invoke((MethodInvoker) delegate()
            {
                listView_FontCharacters.LargeImageList = imageList;
            });


            List <ListViewItem> items = new List <ListViewItem>();

            foreach (FontCharacter character in _fontFile.Characters)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.ImageKey = character.Index.ToString();
                lvi.Text     = character.IndexString;

                if (_scriptFile.LockedCharacters.Any(c => c.Index == character.Index))
                {
                    lvi.Checked = true;
                }

                //Blacklist for chars, that crash the game-engine!
                if (lvi.Text.StartsWith("88D") == true)
                {
                    lvi.Checked = true;                                         //causes crashes (C111 softlock)
                }
                if (lvi.Text.StartsWith("899") == true)
                {
                    lvi.Checked = true;                                         //causes crashes (C141 softlock)
                }
                items.Add(lvi);
            }
            Invoke((MethodInvoker) delegate()
            {
                listView_FontCharacters.Items.AddRange(items.ToArray());
            });
        }
        /// <summary>
        /// Generates the font characters for the given 2 char dictionary and font.
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="font"></param>
        public void GenerateFont(HashSet <string> dictionary, Font font)
        {
            FONTFile fontFile = ApplicationState.Instance.ProjectFile.ModifiedImage.FONTFile;

            fontFile.Load();
            GeneratedFont = fontFile.Characters;

            //GeneratedFont = FONTFile.EmptyFontCharacters();
            //foreach (FontCharacter fontCharacter in GeneratedFont) { fontCharacter.Data = new byte[32]; }

            int fontOffset = 1;

            string[] unsortedDictionary = dictionary.ToArray();
            string[] sortedDictionary   = dictionary.OrderBy(e => e).ToArray();
            for (int i = 0; i < unsortedDictionary.Length; i++)
            {
                FontCharacter fontCharacter = GeneratedFont[i + fontOffset];
                while (LockedCharacters.Any(c => c.Index == fontCharacter.Index))
                {
                    fontOffset++;
                    fontCharacter = GeneratedFont[i + fontOffset];
                }

                fontCharacter.Data   = new byte[32];
                fontCharacter.Symbol = unsortedDictionary[i];

                Bitmap bitmap = fontCharacter.GetBitmap();
                using (Graphics graphic = Graphics.FromImage(bitmap))
                {
                    RectangleF firstChar  = new RectangleF(-2, 0, 16, 16);
                    RectangleF secondChar = new RectangleF(6, 0, 16, 16);

                    graphic.SmoothingMode     = SmoothingMode.None;
                    graphic.InterpolationMode = InterpolationMode.NearestNeighbor;
                    graphic.PixelOffsetMode   = PixelOffsetMode.None;
                    graphic.DrawString("" + fontCharacter.Symbol[0], font, Brushes.White, firstChar);
                    if (fontCharacter.Symbol.Length == 1)
                    {
                        continue;                                   //should not appear actually
                    }
                    graphic.DrawString("" + fontCharacter.Symbol[1], font, Brushes.White, secondChar);
                }
                fontCharacter.SetBitmap(bitmap);
            }
        }