Beispiel #1
0
        private void CopyCurrentFont(object sender)
        {
            CharacterSet characterSet = null;

            if (sender is ToolStripItem item && item.Owner is ContextMenuStrip owner && owner.Tag is CharacterSet contextCharacterSet)
            {
                characterSet = contextCharacterSet;
            }
Beispiel #2
0
        public static Map Load(MapSet mapSet, String path, String mapFileName, CharacterSet characterSet)
        {
            Map map = Map.CreateNewMap(mapSet, characterSet);

            map.Path    = PathHelper.GetExactPath(path, mapFileName);
            map.MapData = map.UseRleCompression() ? DecodeRLE(File.ReadAllBytes(map.Path)) : DecodeLZ4(map.Path);
            map.SetLoaded();
            return(map);
        }
Beispiel #3
0
        internal void AddMap(string mapFileName, string fontFileName)
        {
            CharacterSet characterSet = findExistingCharsetByFileName(fontFileName);

            if (characterSet == null)
            {
                characterSet = CharacterSet.CreateFromFileName(fontFileName);
                AddCharSet(characterSet, false);
            }

            AddMap(MapDeserializer.Load(this, Path, mapFileName, characterSet));
        }
Beispiel #4
0
        public FormBitmapToFnt(Image image, CharacterSet characterSet, DLI[] dLIS)
        {
            InitializeComponent();

            pictureGrid1.OnColorPicked += new EventHandler(pictureGrid1_OnColorPicked);
            fiveColorPickerUserControl1.OnPickColor += new EventHandler(fiveColorPickerUserControl1_onPickColor);
            charSetUserControl1.DirtyChanged        += new EventHandler(charSetUserControl1_DirtyChanged);

            CharacterSet = characterSet;
            this.dLIS    = dLIS;
            pictureGrid1.OriginalImage = image;
        }
Beispiel #5
0
        public void AddMap(String fontFileName)
        {
            CharacterSet characterSet = findExistingCharsetByFileName(fontFileName);

            if (characterSet == null)
            {
                characterSet = CharacterSet.CreateFromFileName(fontFileName);
                AddCharSet(characterSet, false);
            }

            AddMap(Map.CreateNewMap(this, characterSet));
        }
Beispiel #6
0
        public FormBitmapToMap(MapSet mapset, Image originalImage, string fileName, CharacterSet characterSet = null)
        {
            InitializeComponent();

            pictureGrid1.OnColorPicked += new EventHandler(pictureGrid1_OnColorPicked);
            fiveColorPickerUserControl1.OnPickColor += new EventHandler(fiveColorPickerUserControl1_onPickColor);

            this.OriginalImage = originalImage;
            this.fileName      = fileName;
            MapSet             = mapset;

            fnt = characterSet == null ? Properties.Resources.font0 : (byte[])characterSet.Data.Clone();
        }
Beispiel #7
0
        public FormFntEdit(CharacterSet characterSet, DLI[] dLIS = null)
        {
            InitializeComponent();


            CharacterSet = characterSet;
            this.dLIS    = dLIS;

            glyphEditUserControl1.OnDLISelected += new EventHandler(glyphEditUserControl1_OnDLISelected);
            glyphEditUserControl1.DLIs           = dLIS;
            glyphEditUserControl1.GlyphEdited   += glyphEditUserControl1_GlyphEdited;

            charSetUserControl1.TileSelected += new EventHandler(charSetUserControl1_TileSelected);
        }
Beispiel #8
0
        public void AddCharSet(CharacterSet newCharSet, bool sendChangedEvent = true)
        {
            if (!charSets.Contains(newCharSet))
            {
                charSets.Add(newCharSet);

                IsDirty = true;

                if (sendChangedEvent)
                {
                    StrutureTreeChanged?.Invoke(this, null);
                }
            }
        }
Beispiel #9
0
        public FormFntToFnt(CharacterSet characterSet, DLI[] dLIS, CharacterSet characterSetFrom)
        {
            InitializeComponent();

            charSetUserControl1.OnDLISelected += new EventHandler(charSetUserControl1_OnDLISelected);

            CharacterSet = characterSet;

            CharacterSetFrom = characterSetFrom;

            DLIS = dLIS;

            charSetUserControl2.Drag = true;
        }
Beispiel #10
0
        internal static Map CreateNewMap(MapSet mapset, CharacterSet characterSet, String uid = null)
        {
            if (characterSet == null || mapset == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            Map result = new Map
            {
                FontID = characterSet.UID,
                UID    = GuidHelper.parse(uid) ?? Guid.NewGuid(),
                MapSet = mapset
            };

            return(result);
        }
Beispiel #11
0
        public void Load(String fileName)
        {
            Clear(false);

            Path = fileName;

            XElement xml = XElement.Load(fileName);

            foreach (XElement node in xml.Elements("font"))
            {
                AddCharSet(CharacterSet.Load(this, node), false);
            }

            foreach (XElement node in xml.Elements("include"))
            {
                AddInclude(node.Value, false);
            }

            foreach (XElement node in xml.Elements("map"))
            {
                Map loadedMap = MapDeserializer.Load(this, node);

                AddMap(loadedMap, false);

                CharacterSet characterSet = CharSets.FirstOrDefault(set => set.UID == loadedMap.FontID);
                if (characterSet == null)
                {
                    MessageBox.Show("Unknown font: " + loadedMap.FontID);
                }
            }

            IsNew   = false;
            IsDirty = false;

            StrutureTreeChanged?.Invoke(this, null);
        }
Beispiel #12
0
 public FontTreeNode(MapSet mapSet, CharacterSet CharacterSet) : base(PathHelper.RelativizePath(mapSet.Path, CharacterSet.Path))
 {
     this.CharacterSet = CharacterSet;
     Tag = pbx1.TypeNode.FontFile;
 }
Beispiel #13
0
 internal void PreLoad(MapSet mapSet, CharacterSet characterSet, DLI[] dLIS = null)
 {
     preloadCharacterSet = characterSet;
     this.dLIS           = dLIS;
     this.mapSet         = mapSet;
 }
Beispiel #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (_Ori2ginalImage != null)
            {
                using (Bitmap bmp = new Bitmap(_Ori2ginalImage))
                {
                    HashSet <Color> colorsSet = ExtractColors(bmp);

                    List <Color> colorsList = new List <Color>(colorsSet);
                    Dictionary <List <byte>, int> charset = new Dictionary <List <byte>, int>(new SequenceComparer <byte>());
                    List <bool?> bits7 = new List <bool?>();
                    List <int>   map   = new List <int>();

                    PrefillCharset(charset);

                    int PrefillCharsetSize = charset.Keys.Count;

                    int curchar = -1;

                    for (int row = 0; row < _Ori2ginalImage.Height / 8; row++)
                    {
                        for (int col = 0; col < _Ori2ginalImage.Width / 4; col++)
                        {
                            List <byte> bitc = new List <byte>();
                            bool?       bit7 = null;
                            for (int y = 0; y < 8; y++)
                            {
                                int b = 0;
                                for (int x = 0; x < 4; x++)
                                {
                                    int colindex = 0;

                                    Color customColor = bmp.GetPixel(col * 4 + x, row * 8 + y);

                                    if (fiveColorPickerUserControl1.Colbks.Contains(customColor))
                                    {
                                        colindex = 0;
                                    }
                                    else if (fiveColorPickerUserControl1.Colpf0s.Contains(customColor))
                                    {
                                        colindex = 1;
                                    }
                                    else if (fiveColorPickerUserControl1.Colpf1s.Contains(customColor))
                                    {
                                        colindex = 2;
                                    }
                                    else if (fiveColorPickerUserControl1.Colpf2s.Contains(customColor))
                                    {
                                        colindex = 3;
                                        if (bit7 == true)
                                        {
                                            MessageBox.Show($"Problem at {col * 4 + x},{row * 8 + y}");
                                            return;
                                        }
                                        bit7 = false;
                                    }
                                    else if (fiveColorPickerUserControl1.Colpf3s.Contains(customColor))
                                    {
                                        colindex = 3;
                                        if (bit7 == false)
                                        {
                                            MessageBox.Show($"Problem at {col * 4 + x},{row * 8 + y}");
                                            return;
                                        }
                                        bit7 = true;
                                    }

                                    b = b * 4 + colindex;
                                }

                                bitc.Add((byte)b);
                            }

                            if (!charset.ContainsKey(bitc))
                            {
                                while (charset.ContainsValue(curchar))
                                {
                                    curchar--;
                                }

                                charset.Add(bitc, curchar);
                            }

                            map.Add(charset[bitc]);
                            bits7.Add(bit7);
                        }
                    }

                    int[] usedByEngine =
                    {
                        0x00, // * *Full colbk tile
                        0x02, // + $80 Exit1
                        0x03, // + $80 Exit2
                        0x04, // + $80 Exit3
                        0x05, // + $80 Exit4
                        0x06, // + $80 * *Full colpf3 tile = black border tile **
                        //   0x0F, // + $80 Fatal
                        0x12, // + $80 Lamp3 Off
                        0x13, // + $80 Lamp1
                        0x14, // + $80 Lamp2
                        0x1E, // + $80 Lamp1 Off
                        0x1F, // + $80 Lamp2 Off
                        0x2D, // Only for map $10 - Yin - Yang extra life bonus in the castle
                        0x2E, // Only for map $10 - Yin - Yang extra life bonus in the castle
                        0x31, // + $80 Lamp3

                        /*  0x40, // + $80 Fatal
                         * 0x54, // + $80 Fatal
                         * 0x55, // + $80 Fatal
                         * 0x56, // + $80 Fatal
                         * 0x58, // + $80 Fatal
                         * 0x59, // + $80 Fatal
                         * 0x5A, // + $80 Fatal*/
                        0x60, // + $80 Tree
                        0x62, // Vine ???

                        /* 0x64, // + $80 Fatal
                        *  0x66, // + $80 Fatal if < Map 10
                        *  0x72, // + $80 Fatal
                        *  0x73, // + $80 Fatal
                        *  0x74, // + $80 Fatal
                        *  0x75, // + $80 Fatal
                        *  0x76, // + $80 Fatal
                        *  0x77, // + $80 Fatal
                        *  0x78, // + $80 Fatal
                        *  0x79, // + $80 Fatal
                        *  0x7a, // + $80 Fatal
                        *  0x7b, // + $80 Fatal
                        *  0x7C  // + $80 Fatal */
                    };

                    if (charset.Count - PrefillCharsetSize <= 128 - usedByEngine.Length)
                    {
                        Dictionary <int, int> mapping   = new Dictionary <int, int>();
                        List <int>            indexesKO = new List <int>(usedByEngine);
                        List <int>            indexes   = new List <int>();



                        int reservedIndex = 128;
                        if (this.radioButtonReserve5.Checked)
                        {
                            reservedIndex -= 5;
                        }
                        else if (this.radioButtonReserve10.Checked)
                        {
                            reservedIndex -= 10;
                        }
                        else if (this.radioButtonReserve15.Checked)
                        {
                            reservedIndex -= 15;
                        }

                        for (int i = 0; i < reservedIndex; i++)
                        {
                            if (!indexesKO.Contains(i))
                            {
                                indexes.Add(i);
                            }
                        }

                        foreach (KeyValuePair <List <byte>, int> entry in charset)
                        {
                            int c = entry.Value;
                            if (c < 0 && !mapping.ContainsKey(c) && indexes.Count > 0)
                            {
                                int indexe = indexes[0];
                                indexes.RemoveAt(0);
                                mapping.Add(c, indexe);
                            }
                        }

                        foreach (KeyValuePair <List <byte>, int> entry in charset)
                        {
                            int c = entry.Value;
                            if (c < 0 && mapping.ContainsKey(c))
                            {
                                int i = mapping[c] * 8;
                                foreach (byte b in entry.Key)
                                {
                                    fnt[i++] = b;
                                }
                            }
                        }

                        List <byte> mapByte = new List <byte>();

                        for (int i = 0; i < map.Count; i++)
                        {
                            int b = map[i];
                            if (b < 0)
                            {
                                mapByte.Add((byte)(mapping[b] + ((bits7[i] ?? false) ? 0x80 : 0)));
                            }
                            else
                            {
                                mapByte.Add((byte)(b + ((bits7[i] ?? false) ? 0x80 : 0)));
                            }
                        }

                        ReturnCharactedSet = CharacterSet.CreateFromData(fnt);

                        ReturnMap = Map.CreateNewMap(MapSet, ReturnCharactedSet);

                        List <DLI>    dlis        = new List <DLI>();
                        RbgPFColors   rbgPFColors = new RbgPFColors(fiveColorPickerUserControl1.Colbks[0], fiveColorPickerUserControl1.Colpf3s[0], fiveColorPickerUserControl1.Colpf2s[0], fiveColorPickerUserControl1.Colpf1s[0], fiveColorPickerUserControl1.Colpf0s[0]);
                        AtariPFColors dliColors   = rbgPFColors.ToNearestAtariPFColors();
                        dlis.Add(new DLI(ReturnMap, dliColors, 0, -1));

                        ReturnMap.DLIS    = dlis.ToArray();
                        ReturnMap.MapData = mapByte.ToArray();

                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Too much tiles needed: {0} for {1} maximum", charset.Count, 128 - usedByEngine.Length));

                        this.DialogResult = DialogResult.Abort;
                    }

                    this.Close();
                }
            }
        }