Ejemplo n.º 1
0
        /// <summary>
        /// Instantiates the bytes-table as a Form.
        /// </summary>
        /// <param name="sprite">the sprite whose bytes to display</param>
        /// <param name="formClosedCallBack">function pointer that unchecks the
        /// menuitem in PckViewForm</param>
        internal static void LoadBytesTable(
            XCImage sprite,
            MethodInvoker formClosedCallBack)
        {
            _sprite = sprite;

            if (_fBytes == null)
            {
                _fBytes              = new Form();
                _fBytes.Size         = new Size(960, 620);
                _fBytes.Font         = new Font("Verdana", 7);
                _fBytes.Text         = "Bytes Table";
                _fBytes.FormClosing += (sender, e) => formClosedCallBack();
                _fBytes.FormClosing += OnFormClosing;

                _rtbBytes          = new RichTextBox();
                _rtbBytes.Dock     = DockStyle.Fill;
                _rtbBytes.Font     = new Font("Courier New", 8);
                _rtbBytes.WordWrap = false;
                _rtbBytes.ReadOnly = true;

                _fBytes.Controls.Add(_rtbBytes);
            }

            PrintBytesTable();
            _fBytes.Show();
        }
Ejemplo n.º 2
0
        public EditorPane(XCImage img)
        {
            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.img = img;
            pal      = null;
            lines    = false;

            imgWidth  = PckImage.Width * square;
            imgHeight = PckImage.Height * square;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// cTor.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="spriteset"></param>
        /// <param name="record"></param>
        internal Tilepart(
            int id,
            SpriteCollection spriteset,
            McdRecord record)
            :
            base(id)
        {
            _spriteset = spriteset;
            Record     = record;

            Anisprites = new XCImage[8];             // every tile-part contains refs to 8 sprites.
            InitializeSprites();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// cTor.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="spriteset"></param>
        /// <param name="record"></param>
        internal Tilepart(
            int id,
            SpriteCollection spriteset,
            McdRecord record)
            :
            base(id)
        {
//			if (spriteset != null && record != null)
//			{
            _spriteset = spriteset;
            Record     = record;

            Images = new XCImage[8];             // every tile-part contains refs to 8 sprites.
            InitializeSprites();
//			}
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads new sprite information when the table is already open/visible.
        /// </summary>
        /// <param name="sprite"></param>
        internal static void ReloadBytesTable(XCImage sprite)
        {
            _sprite = sprite;

            if (_fBytes != null && _fBytes.Visible)
            {
                if (_sprite != null)
                {
                    PrintBytesTable();
                }
                else
                {
                    _rtbBytes.Clear();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Selects and shows status-information for a sprite. Overrides core
        /// implementation for the MouseDown event.
        /// NOTE: This fires before PckViewForm.OnSpriteClick().
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
//			base.OnMouseDown(e);

            if (e.Button == MouseButtons.Left &&
                Spriteset != null && Spriteset.Count != 0)
            {
                // IMPORTANT: 'SelectedId' is currently allowed only 1 entry.

                int terrainId = GetTileId(e);
                if (terrainId != SelectedId)
                {
                    XCImage sprite = null;

                    if ((SelectedId = terrainId) != -1)
                    {
                        SelectedId = Spriteset[SelectedId].TerrainId;                         // use the proper Id of the sprite itself.
                        sprite     = Spriteset[SelectedId];

//						if (ModifierKeys == Keys.Control)
//						{
//							SpriteSelected spritePre = null;
//							foreach (var sprite in _selectedSprites)
//								if (sprite.X == tileX && sprite.Y == tileY)
//									spritePre = sprite;
//							if (spritePre != null)
//								_selectedSprites.Remove(spritePre);
//							else
//								_selectedSprites.Add(selected);
//						}
//						else
//							Selected.Add(selected);
                    }

                    EditorPanel.Instance.Sprite = sprite;

                    PrintStatusSpriteSelected();
                    Refresh();
                }
                ScrollToTile(SelectedId);
            }
        }
Ejemplo n.º 7
0
        public XCTile(int id, PckFile file, McdEntry info, XCTile[] tiles) : base(id)
        {
            this.info = info;
            _info     = info;
            Tiles     = tiles;
            _myFile   = file;

            image = new XCImage[NUM_IMAGES];

            if (!info.UFODoor && !info.HumanDoor)
            {
                MakeAnimate();
            }
            else
            {
                StopAnimate();
            }

            Dead      = null;
            Alternate = null;
        }
Ejemplo n.º 8
0
 public void ChangeItem(int index, XCImage image)
 {
     view.ChangeItem(index, image);
 }
Ejemplo n.º 9
0
 public EditorPanel(XCImage img)
 {
     editor          = new EditorPane(img);
     editor.Location = new Point(0, 0);
     Controls.Add(editor);
 }
Ejemplo n.º 10
0
        internal static int SaveSpritesetSprite(BinaryWriter bw, XCImage sprite)
        {
            var binlist = new List <byte>();

            int  lenTransparent = 0;
            bool first          = true;

            for (int id = 0; id != sprite.Bindata.Length; ++id)
            {
                byte b = sprite.Bindata[id];

                if (b == Palette.TransparentId)
                {
                    ++lenTransparent;
                }
                else
                {
                    if (lenTransparent != 0)
                    {
                        if (first)
                        {
                            first = false;

                            binlist.Add((byte)(lenTransparent / sprite.Sprite.Width));                                  // qty of initial transparent rows
                            lenTransparent = (byte)(lenTransparent % sprite.Sprite.Width);                              // qty of transparent pixels starting on the next row
                        }

                        while (lenTransparent >= ByteMaximumValue)
                        {
                            lenTransparent -= ByteMaximumValue;

                            binlist.Add(SpriteTransparencyByte);
                            binlist.Add(ByteMaximumValue);
                        }

                        if (lenTransparent != 0)
                        {
                            binlist.Add(SpriteTransparencyByte);
                            binlist.Add((byte)lenTransparent);
                        }
                        lenTransparent = 0;
                    }
                    binlist.Add(b);
                }
            }

            // So, question. Is one obligated to account for transparent pixels
            // to the end of an image, or can one just assume that the program
            // that reads and decompresses the data will force them to transparent ...
            //
            // It looks like both OpenXcom and MapView will fill the sprite with
            // all transparent pixels when each sprite is initialized. Therefore,
            // it's not *required* to encode any pixels that are transparent to
            // the end of the sprite.
            //
            // And when looking at some of the stock PCK's things look non-standardized.
            // It's sorta like if there's at least one full row of transparent
            // pixels at the end of an image, it gets 0xFE,0xFF tacked on before
            // the final 0xFF (end of image) marker.
            //
            // Note that this algorithm can and will tack on multiple 0xFE,0xFF
            // if there's more than 256 transparent pixels at the end of an image.


//			bool appendStopByte = false;
//			while (lenTransparent >= ByteMaximumValue)
//			{
//				lenTransparent -= ByteMaximumValue;
//
//				binlist.Add(SpriteTransparencyByte);
//				binlist.Add(ByteMaximumValue);
//
//				appendStopByte = true;
//			}
//
//			if (appendStopByte
//				|| (byte)binlist[binlist.Count - 1] != SpriteStopByte)
//			{
            binlist.Add(SpriteStopByte);
//			}

            // Okay. That seems to be the algorithm that was used. Ie, no need
            // to go through that final looping mechanism.
            //
            // In fact I'll bet it's even better than stock, since it no longer
            // appends superfluous 0xFE,0xFF markers at all.

            bw.Write(binlist.ToArray());

            return(binlist.Count);
        }
Ejemplo n.º 11
0
        public static int EncodePck(System.IO.BinaryWriter output, XCImage tile)
        {
            int  count = 0;
            bool flag  = true;

            byte[]      input = tile.Bytes;
            List <byte> bytes = new List <byte>();
//			Color trans = pal.Transparent;
//			pal.SetTransparent(false);

            int totalCount = 0;

            for (int i = 0; i < input.Length; i++)
            {
                byte idx = input[i];
                totalCount++;

                if (idx == TransIdx)
                {
                    count++;
                }
                else
                {
                    if (count != 0)
                    {
                        if (flag)
                        {
                            bytes.Add((byte)(count / tile.Image.Width));                                // # of initial rows to skip
                            count = (byte)(count % tile.Image.Width);                                   // where we currently are in the transparent row
                            flag  = false;
                            //Console.WriteLine("count, lines: {0}, cells {1}",count/PckImage.IMAGE_WIDTH,count%PckImage.IMAGE_WIDTH);
                        }

                        while (count >= 255)
                        {
                            bytes.Add(TransIdx);
                            bytes.Add(255);
                            count -= 255;
                        }

                        if (count != 0)
                        {
                            bytes.Add(TransIdx);
                            bytes.Add((byte)count);
                        }
                        count = 0;
                    }
                    bytes.Add(idx);
                }
            }

            bool throughLoop = false;

            while (count >= 255)
            {
                bytes.Add(254);
                bytes.Add(255);
                count      -= 255;
                throughLoop = true;
            }

            if ((byte)bytes[bytes.Count - 1] != 255 || throughLoop)
            {
                bytes.Add(255);
            }

//			if (bytes.Count % 2 == 1 || throughLoop)
//				bytes.Add(255);

            output.Write(bytes.ToArray());

            return(bytes.Count);
        }
Ejemplo n.º 12
0
 public void ChangeItem(int index, XCImage image)
 {
     myFile[index] = image;
 }