Inheritance: VspBase
Exemplo n.º 1
1
        public void init(Map m)
        {
            currMap = m;
            currVsp = m.vsp;

            vspc.SetActiveVsp(currVsp);
            vspc.SetControllerMode(VSPController.ControllerMode.SelectorDual);

            //			n_start.Maximum = m.vsp.tileCount-1;
            //			n_end.Maximum = m.vsp.tileCount-1;

            foreach(VspAnimation va in currVsp.Animations)
            {
                anims.Add( va.Clone() );
            }
            foreach(VspAnimation va in anims)
            {
                ListViewItem lvi = new ListViewItem( new string[] { va.ID.ToString(), va.Name } );
                lvi.Tag = va;
                lv_anims.Items.Add(lvi);
            }
            DisableEditor();
        }
Exemplo n.º 2
0
        public static Vsp24 FromVsp8(Vsp8 src)
        {
            Vsp24 v24 = new Vsp24();
            foreach (Vsp8Tile v8t in src.Tiles)
            {
                int[] data = new int[256];
                for (int y = 0; y < Global.TILE_SIZE; y++)
                {
                    for (int x = 0; x < Global.TILE_SIZE; x++)
                    {
                        if (v8t.Pixels[y * Global.TILE_SIZE + x] > 0)
                        {
                            data[y * Global.TILE_SIZE + x] = v8t.parent.Palette[v8t.Pixels[y * Global.TILE_SIZE + x]].IntColor;
                        }
                        else
                        {
                            unchecked
                            {
                                data[y * Global.TILE_SIZE + x] = ((int)0xFFFF00FF);
                            }
                        }
                    }
                }

                Vsp24Tile v24t = new Vsp24Tile(v24, new pr2.BufferImage(Global.TILE_SIZE, Global.TILE_SIZE, data));
                v24.Tiles.Add(v24t);
            }
            v24.FileOnDisk = src.FileOnDisk;
            v24.Animations = src.Animations;
            return v24;
        }
Exemplo n.º 3
0
        public static Vsp24 FromVsp8(Vsp8 src)
        {
            Vsp24 v24 = new Vsp24();

            foreach (Vsp8Tile v8t in src.Tiles)
            {
                int[] data = new int[256];
                for (int y = 0; y < 16; y++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        if (v8t.Pixels[y * 16 + x] > 0)
                        {
                            data[y * 16 + x] = v8t.parent.Palette[v8t.Pixels[y * 16 + x]].IntColor;
                        }
                        else
                        {
                            unchecked {
                                data[y * 16 + x] = ((int)0xFFFF00FF);
                            }
                        }
                    }
                }

                Vsp24Tile v24t = new Vsp24Tile(v24, new pr2.BufferImage(16, 16, data));
                v24.Tiles.Add(v24t);
            }
            v24.FileOnDisk = src.FileOnDisk;
            v24.Animations = src.Animations;
            return(v24);
        }
Exemplo n.º 4
0
 public void CloneTile()
 {
     Vsp24 vsp = new Vsp24();
     Vsp24Tile tile = (Vsp24Tile)vsp.CreateTile();
     Vsp24Tile clone = (Vsp24Tile)tile.Clone();
     Assert.AreEqual(tile.ColorAverage, clone.ColorAverage);
     Assert.AreEqual(tile.Image.GetArray(), clone.Image.GetArray());
 }
Exemplo n.º 5
0
        void executeMove()
        {
            Map   map = Global.ActiveMap;
            Vsp24 vsp = Global.ActiveVsp;

            Operations.OperationManager om = Global.opManager;

            om.beginGroup("VSP Manager: Smart Tile Move");

            Ops.SetTileGroup     stg  = new Ops.SetTileGroup(0);
            Ops.SetTiledataGroup stdg = new Ops.SetTiledataGroup(Global.ActiveVsp);

            //move tiles
            for (int y = 0; y < originalSelection.height; y++)
            {
                for (int x = 0; x < originalSelection.width; x++)
                {
                    int xs = x + originalSelection.x;
                    int ys = y + originalSelection.y;
                    int xd = x + selection.x;
                    int yd = y + selection.y;
                    int ts = ys * TilesWide + xs;
                    int td = yd * TilesWide + xd;

                    if (ts >= vsp.Tiles.Count || ts < 0)
                    {
                        continue;
                    }

                    stdg.addRecord(td, ((Vsp24Tile)vsp.Tiles[ts]).Image.GetArray());

                    for (int l = 0; l < map.Layers.Count; l++)
                    {
                        MapLayer ml = (MapLayer)map.Layers[l];
                        if (ml.type != LayerType.Tile)
                        {
                            continue;
                        }
                        for (int yi = 0; yi < ml.Height; yi++)
                        {
                            for (int xi = 0; xi < ml.Width; xi++)
                            {
                                int t = ml.getTile(xi, yi);
                                if (t == ts)
                                {
                                    stg.addRecord(l, xi, yi, td);
                                }
                            }
                        }
                    }
                }
            }

            om.add(stg);
            om.add(stdg);
            om.endGroupExec();
        }
Exemplo n.º 6
0
        public ArrayList GetTiles(Vsp24 vsp)
        {
            ArrayList tiles = new ArrayList();

            foreach (Vsp24Tile vt in vsp.Tiles)
            {
                Vsp24Tile vtt = vt.Clone();
                vtt.parent = this;
                tiles.Add(vtt);
            }
            return(tiles);
        }
Exemplo n.º 7
0
        public ArrayList ImportObstructionTiles(Vsp24 vsp)
        {
            ArrayList tiles = new ArrayList();

            foreach (VspObstructionTile vt in vsp.ObstructionTiles)
            {
                VspObstructionTile vot = vt.Clone();
                vot.parent = this;
                tiles.Add(vot);
            }
            return(tiles);
        }
Exemplo n.º 8
0
        public void init(Vsp24 vsp, int leftSelection, int rightSelection)
        {
            working_vsp = vsp;
            gForegroundColor.SetController(colorPickerFront);
            gBackgroundColor.SetController(colorPickerBack);
            vspController.SetControllerMode(VSPController.ControllerMode.SelectorDual);
            vspController.SetActiveVsp(vsp);
            vspController.SetTileViewers(tve_a, tve_b);
            vspController.VspView.SelectedTileF = leftSelection;
            vspController.VspView.SelectedTileB = rightSelection;

            gForegroundColor.CheckedChanged += new EventHandler(gForegroundColor_CheckedChanged);
            gBackgroundColor.CheckedChanged += new EventHandler(gBackgroundColor_CheckedChanged);

            tve_a.TileDataChanged += new TileEditor.TileDataChangedEventHandler(tve_a_TileDataChanged);
            tve_b.TileDataChanged += new TileEditor.TileDataChangedEventHandler(tve_b_TileDataChanged);

            tve_a.SourceLeft  = colorPickerFront;
            tve_a.SourceRight = colorPickerBack;
            tve_b.SourceLeft  = colorPickerFront;
            tve_b.SourceRight = colorPickerBack;
        }
Exemplo n.º 9
0
        public void init(Vsp24 vsp, int leftSelection, int rightSelection)
        {
            working_vsp=vsp;
            gForegroundColor.SetController(colorPickerFront);
            gBackgroundColor.SetController(colorPickerBack);
            vspController.SetControllerMode(VSPController.ControllerMode.SelectorDual);
            vspController.SetActiveVsp(vsp);
            vspController.SetTileViewers(tve_a,tve_b);
            vspController.VspView.SelectedTileF = leftSelection;
            vspController.VspView.SelectedTileB = rightSelection;

            gForegroundColor.CheckedChanged += new EventHandler(gForegroundColor_CheckedChanged);
            gBackgroundColor.CheckedChanged += new EventHandler(gBackgroundColor_CheckedChanged);

            tve_a.TileDataChanged += new TileEditor.TileDataChangedEventHandler(tve_a_TileDataChanged);
            tve_b.TileDataChanged += new TileEditor.TileDataChangedEventHandler(tve_b_TileDataChanged);

            tve_a.SourceLeft = colorPickerFront;
            tve_a.SourceRight = colorPickerBack;
            tve_b.SourceLeft = colorPickerFront;
            tve_b.SourceRight = colorPickerBack;
        }
Exemplo n.º 10
0
        public void init(Map m)
        {
            currMap = m;
            currVsp = m.vsp;

            vspc.SetActiveVsp(currVsp);
            vspc.SetControllerMode(VSPController.ControllerMode.SelectorDual);

//			n_start.Maximum = m.vsp.tileCount-1;
//			n_end.Maximum = m.vsp.tileCount-1;

            foreach (VspAnimation va in currVsp.Animations)
            {
                anims.Add(va.Clone());
            }
            foreach (VspAnimation va in anims)
            {
                ListViewItem lvi = new ListViewItem(new string[] { va.ID.ToString(), va.Name });
                lvi.Tag = va;
                lv_anims.Items.Add(lvi);
            }
            DisableEditor();
        }
Exemplo n.º 11
0
 public Vsp24Tile(Vsp24 parent, pr2.IRenderImage image)
 {
     this.parent = parent;
     this.image = image;
     this.avg = GetAverageColor();
 }
Exemplo n.º 12
0
 public Vsp24Tile(Vsp24 parent)
     : this(parent, new pr2.BufferImage(16, 16))
 {
 }
Exemplo n.º 13
0
        public Map CreateMap()
        {
            Map  m       = new Map();
            int  l_count = (int)n_layers.Value;
            int  l_w     = (int)n_w.Value;
            int  l_h     = (int)n_h.Value;
            bool bNewvsp = rb_new.Checked;

            for (int i = 0; i < l_count; i++)
            {
                MapLayer ml = new MapLayer(m);
                ml.size(l_w, l_h);
                ml.name         = "Layer " + i;
                ml.type         = LayerType.Tile;
                ml.parallaxInfo = new ParallaxInfo();
                m.Layers.Add(ml);
            }
            MapLayer zl = new MapLayer(m);

            zl.type = LayerType.Zone;
            zl.name = "Zones";
            zl.size(l_w, l_h);

            m.ZoneLayer = zl;

            MapLayer ol = new MapLayer(m);

            ol.type = LayerType.Obs;
            ol.name = "Obstructions";
            ol.size(l_w, l_h);
            m.ObsLayer = ol;



            MapLayer el = new MapLayer(m);

            el.type = LayerType.Entity;
            el.name = "Entities";
            MapLayerSpecial rl = new MapLayerSpecial(m);

            rl.type = LayerType.Special_Retrace;


            m.Layers.Add(rl);
            m.Layers.Add(el);
            m.Layers.Add(ol);
            m.Layers.Add(zl);

            m.EntLayer = el;
            if (bNewvsp)
            {
                Vsp24 v = new Vsp24();

                //v.AddTiles(100);
                v.Tiles.AddRange(v.GetTiles(100));
                m.vsp = v;
            }
            else
            {
                Vsp24 v = InputOutput.ReadVsp(t_vspfile.Text);
                if (v == null)
                {
                    Errors.Error("Warning", "An error occured when attempting to load the vsp file.  A blank VSP has been created.");
                    v = new Vsp24();

                    v.Tiles.Add(v.GetTiles(100));
                    m.vsp = v;
                }
                else
                {
                    m.vsp = v;
                }
            }

            MapZone mz = new MapZone();

            mz.ID   = 0;
            mz.Name = "NULL_ZONE";
            m.Zones.Add(mz);


            m.Init();
            m.RenderString = "";
            return(m);
        }
Exemplo n.º 14
0
        private void renderTileLayer(pr2.IRenderImage backBuffer, MapLayer layer, Vsp24 vsp, int px, int py, bool drawZero)
        {
            int mtx  = px / 16;
            int mty  = py / 16;
            int mtox = px & 15;
            int mtoy = py & 15;

            //we add 2; one for the case where we are scrolled a little bit
            //(and so parts of two tiles are drawn instead of one complete)
            //and one for the case where the screen is a funny size and a remainder bit is shown
            int tw = backBuffer.Width / 16 + 2;
            int th = backBuffer.Height / 16 + 2;

            int layerWidth  = layer.Width;
            int layerHeight = layer.Height;
            int cpx         = -mtox;
            int cpy         = -mtoy;

            tw = System.Math.Min(tw, layerWidth - mtx);
            th = System.Math.Min(th, layerHeight - mty);

            int tp;
            int tile;
            int xmin = -mtox;
            int xmax = xmin + tw * 16;

            short[] tileMap = layer.Data;
            if (Global.RenderOptions.bTranslucentEffects)
            {
                for (int ty = 0; ty < th; ty++, cpy += 16)
                {
                    tp = (ty + mty) * layerWidth + mtx;
                    for (cpx = xmin; cpx < xmax; cpx += 16)
                    {
                        tile = tileMap[tp++];
                        if (Global.RenderOptions.bAnimate)
                        {
                            tile = Global.FrameCalc.getframe(tile);
                        }

                        if ((drawZero || tile != 0) && tile < vsp.tileCount)
                        {
                            Render.renderAlpha(backBuffer, cpx, cpy, vsp.GetTile(tile).Image, 100 - layer.Translucency, false);
                        }
                    }
                }
            }
            else
            {
                for (int ty = 0; ty < th; ty++, cpy += 16)
                {
                    tp = (ty + mty) * layerWidth + mtx;
                    for (cpx = xmin; cpx < xmax; cpx += 16)
                    {
                        tile = tileMap[tp++];
                        if (Global.RenderOptions.bAnimate)
                        {
                            tile = Global.FrameCalc.getframe(tile);
                        }

                        if (drawZero || tile != 0 && tile < vsp.tileCount)
                        {
                            Render.render(backBuffer, cpx, cpy, vsp.GetTile(tile).Image, false);
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public Map CreateMap()
        {
            Map m = new Map();
            int l_count = (int)n_layers.Value;
            int l_w = (int)n_w.Value;
            int l_h = (int)n_h.Value;
            bool bNewvsp = rb_new.Checked;
            for(int i=0;i<l_count;i++)
            {
                MapLayer ml = new MapLayer(m);
                ml.size(l_w,l_h);
                ml.name = "Layer " + i;
                ml.type = LayerType.Tile;
                ml.parallaxInfo = new ParallaxInfo();
                m.Layers.Add(ml);
            }
            MapLayer zl = new MapLayer(m);
            zl.type = LayerType.Zone;
            zl.name = "Zones";
            zl.size(l_w,l_h);

            m.ZoneLayer=zl;

            MapLayer ol = new MapLayer(m);
            ol.type = LayerType.Obs;
            ol.name = "Obstructions";
            ol.size(l_w,l_h);
            m.ObsLayer = ol;

            MapLayer el = new MapLayer(m);
            el.type = LayerType.Entity;
            el.name = "Entities";
            MapLayerSpecial rl = new MapLayerSpecial(m);
            rl.type=LayerType.Special_Retrace;

            m.Layers.Add(rl);
            m.Layers.Add(el);
            m.Layers.Add(ol);
            m.Layers.Add(zl);

            m.EntLayer = el;
            if(bNewvsp)
            {
                Vsp24 v = new Vsp24();

                //v.AddTiles(100);
                v.Tiles.AddRange(v.GetTiles(100));
                m.vsp = v;

            }
            else
            {
                Vsp24 v = InputOutput.ReadVsp(t_vspfile.Text);
                if(v==null)
                {
                    Errors.Error("Warning", "An error occured when attempting to load the vsp file.  A blank VSP has been created.");
                    v = new Vsp24();

                    v.Tiles.Add(v.GetTiles(100));
                    m.vsp = v;
                }
                else
                    m.vsp = v;
            }

            MapZone mz = new MapZone();
            mz.ID = 0;
            mz.Name = "NULL_ZONE";
            m.Zones.Add(mz);

            m.Init();
            m.RenderString = "";
            return m;
        }
Exemplo n.º 16
0
 private void te_VspDataChanged(Vsp24 vsp, int tileIndex)
 {
     throttleDisplay.signal();
 }
Exemplo n.º 17
0
        public unsafe static int WriteVsp(FileInfo fi, Vsp24 vsp)
        {
            if (fi.Exists)
            {
                fi.Delete();
            }
            FileStream   fs = fi.OpenWrite();
            BinaryWriter bw = new BinaryWriter(fs);

            vsp.FileOnDisk = fi;


            bw.Write(VSP_SIGNATURE);
            bw.Write(VSP_VERSION);


            bw.Write(VSP_TILESIZE);
            bw.Write(VSP_FORMAT);
            bw.Write(vsp.Tiles.Count);
            bw.Write(VSP_COMPRESSION);

            // build byte array of all tiles in our vsp
            MemoryStream ms_tiles = new MemoryStream();
            BinaryWriter bw_tiles = new BinaryWriter(ms_tiles);

            foreach (Vsp24Tile tile in vsp.Tiles)
            {
                for (int y = 0; y < 16; y++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        int p = tile.Image.GetPixel(x, y);
                        bw_tiles.Write((byte)((p & 0x00FF0000) >> 16));
                        bw_tiles.Write((byte)((p & 0x0000FF00) >> 8));
                        bw_tiles.Write((byte)((p & 0x000000FF)));
                    }
                }
            }
            bw_tiles.Close();
            byte[] zdata = ZLIB.Encode(ms_tiles.ToArray());
            bw.Write((int)16 * 16 * 3 * vsp.Tiles.Count);

            bw.Write(zdata.Length);
            bw.Write(zdata);

            bw.Write(vsp.Animations.Count);

            foreach (VspAnimation va in vsp.Animations)
            {
                bw.Write(Helper.StringToPaddedByteArray(va.Name, 256));
                bw.Write(va.Start);
                bw.Write(va.End);
                bw.Write(va.Delay);
                bw.Write(va.Mode);
            }

            bw.Write(vsp.ObstructionTiles.Count);

            byte[] odata = new byte[vsp.ObstructionTiles.Count * 256];
            for (int i = 0; i < vsp.ObstructionTiles.Count; i++)
            {
                int[] pixels = ((VspObstructionTile)vsp.ObstructionTiles[i]).Image.GetArray();
                for (int j = 0; j < 256; j++)
                {
                    odata[i * 256 + j] = (byte)pixels[j];
                }
            }
            byte[] ozdata = ZLIB.Encode(odata);
            bw.Write((int)odata.Length);
            bw.Write((int)ozdata.Length);
            bw.Write(ozdata);

            Global.pluginManager.tilesetSave(fs);

            bw.Close();
            return(0);
        }
Exemplo n.º 18
0
 public void init(Vsp24 vsp)
 {
     init(vsp, 0, 0);
 }
Exemplo n.º 19
0
 public void SetActiveVsp(Vsp24 vsp)
 {
     c_VspView.ActiveVsp = vsp;
 }
Exemplo n.º 20
0
 public SetTiledataGroup(Vsp24 vsp)
 {
     this.vsp = vsp;
 }
Exemplo n.º 21
0
        public static unsafe Vsp24 ReadVsp24(FileInfo fi)
        {
            //Errors.Error("loading vsp");
            Vsp24 vsp = new Vsp24();

            vsp.FileOnDisk = fi;

            FileStream fs = fi.OpenRead();
            BinaryReader br = new BinaryReader(fs);

            int sig = br.ReadInt32();
            int version = br.ReadInt32();
            if (sig != VSP_SIGNATURE || version != VSP_VERSION)
                return null;

            // assume Global.TILE_SIZE
            int tilesize = br.ReadInt32();

            // assume 24-bit
            int format = br.ReadInt32();

            int tilecount = br.ReadInt32();

            // assume zlib
            int compression = br.ReadInt32();

            int datalen = br.ReadInt32();
            int zdatalen = br.ReadInt32();

            byte[] zdata = br.ReadBytes(zdatalen);

            byte[] data = ZLIB.Decode(zdata, datalen);

            for (int tile = 0; tile < tilecount; tile++)
            {
                int[] px = new int[Global.TILE_SIZE * Global.TILE_SIZE];
                for (int i = 0; i < Global.TILE_SIZE * Global.TILE_SIZE; i++)
                {
                    int idx = tile * Global.TILE_SIZE * Global.TILE_SIZE + i;
                    int c = unchecked((int)0xFF000000);
                    c = c | (data[idx * 3] << 16);
                    c = c | (data[idx * 3 + 1] << 8);
                    c = c | data[idx * 3 + 2];
                    px[i] = c;
                }
                vsp.Tiles.Add(new Vsp24Tile(vsp, new pr2.BufferImage(Global.TILE_SIZE, Global.TILE_SIZE, px)));
            }

            int animcount = br.ReadInt32();
            for (int i = 0; i < animcount; i++)
            {
                VspAnimation va = new VspAnimation();
                va.Name = Helper.BytesToString(br.ReadBytes(256));
                va.Start = br.ReadInt32();
                va.End = br.ReadInt32();
                va.Delay = br.ReadInt32();
                va.Mode = br.ReadInt32();
                va.ID = i;

                vsp.Animations.Add(va);
            }
            int obscount = br.ReadInt32();
            int od_len = br.ReadInt32();
            int od_zlen = br.ReadInt32();
            byte[] zd = br.ReadBytes(od_zlen);
            byte[] od = ZLIB.Decode(zd, od_len);

            for (int i = 0; i < obscount; i++)
            {
                int[] tile = new int[256];
                for (int j = 0; j < 256; j++)
                    tile[j] = od[i * 256 + j];
                vsp.ObstructionTiles.Add(new VspObstructionTile(vsp, tile));
            }

            br.Close();

            return vsp;
        }
Exemplo n.º 22
0
        public static unsafe int WriteVsp(FileInfo fi, Vsp24 vsp)
        {
            if (fi.Exists) fi.Delete();
            FileStream fs = fi.OpenWrite();
            BinaryWriter bw = new BinaryWriter(fs);

            vsp.FileOnDisk = fi;

            bw.Write(VSP_SIGNATURE);
            bw.Write(VSP_VERSION);

            bw.Write(Global.TILE_SIZE);
            bw.Write(VSP_FORMAT);
            bw.Write(vsp.Tiles.Count);
            bw.Write(VSP_COMPRESSION);

            // build byte array of all tiles in our vsp
            MemoryStream ms_tiles = new MemoryStream();
            BinaryWriter bw_tiles = new BinaryWriter(ms_tiles);
            foreach (Vsp24Tile tile in vsp.Tiles)
            {
                for (int y = 0; y < Global.TILE_SIZE; y++)
                {
                    for (int x = 0; x < Global.TILE_SIZE; x++)
                    {
                        int p = tile.Image.GetPixel(x, y);
                        bw_tiles.Write((byte)((p & 0x00FF0000) >> 16));
                        bw_tiles.Write((byte)((p & 0x0000FF00) >> 8));
                        bw_tiles.Write((byte)((p & 0x000000FF)));
                    }
                }
            }
            bw_tiles.Close();
            byte[] zdata = ZLIB.Encode(ms_tiles.ToArray());
            bw.Write((int)Global.TILE_SIZE * Global.TILE_SIZE * 3 * vsp.Tiles.Count);

            bw.Write(zdata.Length);
            bw.Write(zdata);

            bw.Write(vsp.Animations.Count);

            foreach (VspAnimation va in vsp.Animations)
            {
                bw.Write(Helper.StringToPaddedByteArray(va.Name, 256));
                bw.Write(va.Start);
                bw.Write(va.End);
                bw.Write(va.Delay);
                bw.Write(va.Mode);
            }

            bw.Write(vsp.ObstructionTiles.Count);

            byte[] odata = new byte[vsp.ObstructionTiles.Count * 256];
            for (int i = 0; i < vsp.ObstructionTiles.Count; i++)
            {
                int[] pixels = ((VspObstructionTile)vsp.ObstructionTiles[i]).Image.GetArray();
                for (int j = 0; j < 256; j++)
                {
                    odata[i * 256 + j] = (byte)pixels[j];
                }
            }
            byte[] ozdata = ZLIB.Encode(odata);
            bw.Write((int)odata.Length);
            bw.Write((int)ozdata.Length);
            bw.Write(ozdata);

            Global.pluginManager.tilesetSave(fs);

            bw.Close();
            return 0;
        }
Exemplo n.º 23
0
 public VspObstructionTile(Vsp24 parent, int[] data)
 {
     this.parent = parent;
     this.image = new pr2.BufferImage(16, 16, data);
 }
Exemplo n.º 24
0
 public Vsp24Tile(Vsp24 parent)
     : this(parent, new pr2.BufferImage(Global.TILE_SIZE, Global.TILE_SIZE))
 {
 }
Exemplo n.º 25
0
        public unsafe static Vsp24 ReadVsp24(FileInfo fi)
        {
            //Errors.Error("loading vsp");
            Vsp24 vsp = new Vsp24();

            vsp.FileOnDisk = fi;

            FileStream   fs = fi.OpenRead();
            BinaryReader br = new BinaryReader(fs);

            int sig     = br.ReadInt32();
            int version = br.ReadInt32();

            if (sig != VSP_SIGNATURE || version != VSP_VERSION)
            {
                return(null);
            }

            // assume 16
            int tilesize = br.ReadInt32();

            // assume 24-bit
            int format = br.ReadInt32();

            int tilecount = br.ReadInt32();

            // assume zlib
            int compression = br.ReadInt32();

            int datalen  = br.ReadInt32();
            int zdatalen = br.ReadInt32();

            byte[] zdata = br.ReadBytes(zdatalen);

            byte[] data = ZLIB.Decode(zdata, datalen);

            for (int tile = 0; tile < tilecount; tile++)
            {
                int[] px = new int[256];
                for (int i = 0; i < 256; i++)
                {
                    int idx = tile * 256 + i;
                    int c   = unchecked ((int)0xFF000000);
                    c     = c | (data[idx * 3] << 16);
                    c     = c | (data[idx * 3 + 1] << 8);
                    c     = c | data[idx * 3 + 2];
                    px[i] = c;
                }
                vsp.Tiles.Add(new Vsp24Tile(vsp, new pr2.BufferImage(16, 16, px)));
            }

            int animcount = br.ReadInt32();

            for (int i = 0; i < animcount; i++)
            {
                VspAnimation va = new VspAnimation();
                va.Name  = Helper.BytesToString(br.ReadBytes(256));
                va.Start = br.ReadInt32();
                va.End   = br.ReadInt32();
                va.Delay = br.ReadInt32();
                va.Mode  = br.ReadInt32();
                va.ID    = i;

                vsp.Animations.Add(va);
            }
            int obscount = br.ReadInt32();
            int od_len   = br.ReadInt32();
            int od_zlen  = br.ReadInt32();

            byte[] zd = br.ReadBytes(od_zlen);
            byte[] od = ZLIB.Decode(zd, od_len);

            for (int i = 0; i < obscount; i++)
            {
                int[] tile = new int[256];
                for (int j = 0; j < 256; j++)
                {
                    tile[j] = od[i * 256 + j];
                }
                vsp.ObstructionTiles.Add(new VspObstructionTile(vsp, tile));
            }

            br.Close();

            return(vsp);
        }
Exemplo n.º 26
0
 public VspObstructionTile(Vsp24 parent, int[] data)
 {
     this.parent = parent;
     this.image  = new pr2.BufferImage(16, 16, data);
 }
Exemplo n.º 27
0
        private void SaveVsp(Vsp24 v, bool ForcePrompt)
        {
            string vspname;
            if (ForcePrompt || v.FileOnDisk == null)
            {
                saveVspDialog.ShowDialog();

                vspname = saveVspDialog.FileName;
                v.Write(vspname);
            }
            else
                v.Write();
        }
Exemplo n.º 28
0
        private void MoveToCursor(MouseEventArgs e)
        {
            if (Global.ActiveMap != null && lDown == true && Controller != null)
            {
                // get map
                Map map = Global.ActiveMap;
                // get base layer
                MapLayer BaseLayer = (MapLayer)Global.ActiveMap.Layers[0];
                // get the vsp
                Vsp24 mapVsp = Global.ActiveVsp;
                // get the mapview
                mapView mv = Global.MainMapController.MapView;


                int vw = 200, vh = 200;
                if (BaseLayer.Width > BaseLayer.Height)
                {
                    vh = (int)(vh * ((float)BaseLayer.Height / (float)BaseLayer.Width));
                }
                else
                {
                    vw = (int)(vw * ((float)BaseLayer.Width / (float)BaseLayer.Height));
                }


                float ratio_x = (float)BaseLayer.Width / vw;
                float ratio_y = (float)BaseLayer.Height / vh;

                int x = (200 - vw) / 2;
                int y = (200 - vh) / 2;

                int nx = (int)(ratio_x * (e.X - x) * 16);
                int ny = (int)(ratio_y * (e.Y - y) * 16);

                nx -= (mv.Width / Controller.ZoomLevel / 2);
                ny -= (mv.Height / Controller.ZoomLevel / 2);


                nx += x;
                ny += y;

                if (nx < 0)
                {
                    nx = 0;
                }
                if (ny < 0)
                {
                    ny = 0;
                }
                if (nx > Controller.hScrollBar.Maximum - mv.Width / Controller.ZoomLevel)
                {
                    nx = Controller.hScrollBar.Maximum - mv.Width / Controller.ZoomLevel;
                }
                if (ny > Controller.vScrollBar.Maximum - mv.Height / Controller.ZoomLevel)
                {
                    ny = Controller.vScrollBar.Maximum - mv.Height / Controller.ZoomLevel;
                }

                if (nx >= Controller.hScrollBar.Minimum)
                {
                    Controller.hScrollBar.Value = nx;
                }
                //Controller.hScrollBar.Value = nx;
                if (ny >= Controller.vScrollBar.Minimum)
                {
                    Controller.vScrollBar.Value = ny;
                }
                //Controller.vScrollBar.Value = ny;
                repaint();
            }
        }
Exemplo n.º 29
0
        private void renderTileLayer(pr2.IRenderImage backBuffer, MapLayer layer, Vsp24 vsp, int px, int py, bool drawZero)
        {
            int mtx = px / 16;
            int mty = py / 16;
            int mtox = px & 15;
            int mtoy = py & 15;

            //we add 2; one for the case where we are scrolled a little bit
            //(and so parts of two tiles are drawn instead of one complete)
            //and one for the case where the screen is a funny size and a remainder bit is shown
            int tw = backBuffer.Width / 16 + 2;
            int th = backBuffer.Height / 16 + 2;

            int layerWidth = layer.Width;
            int layerHeight = layer.Height;
            int cpx = -mtox;
            int cpy = -mtoy;

            tw = System.Math.Min(tw, layerWidth - mtx);
            th = System.Math.Min(th, layerHeight - mty);

            int tp;
            int tile;
            int xmin = -mtox;
            int xmax = xmin + tw * 16;

            short[] tileMap = layer.Data;
            if (Global.RenderOptions.bTranslucentEffects)
            {
                for (int ty = 0; ty < th; ty++, cpy += 16)
                {
                    tp = (ty + mty) * layerWidth + mtx;
                    for (cpx = xmin; cpx < xmax; cpx += 16)
                    {
                        tile = tileMap[tp++];
                        if (Global.RenderOptions.bAnimate)
                        {
                            tile = Global.FrameCalc.getframe(tile);
                        }

                        if (drawZero || tile != 0 && tile < vsp.tileCount)
                        {
                            Render.renderAlpha(backBuffer, cpx, cpy, vsp.GetTile(tile).Image, 100 - layer.Translucency, false);
                        }
                    }
                }
            }
            else
            {
                for (int ty = 0; ty < th; ty++, cpy += 16)
                {
                    tp = (ty + mty) * layerWidth + mtx;
                    for (cpx = xmin; cpx < xmax; cpx += 16)
                    {
                        tile = tileMap[tp++];
                        if (Global.RenderOptions.bAnimate)
                        {
                            tile = Global.FrameCalc.getframe(tile);
                        }

                        if (drawZero || tile != 0 && tile < vsp.tileCount)
                        {
                            Render.render(backBuffer, cpx, cpy, vsp.GetTile(tile).Image, false);
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
 public ArrayList GetTiles(Vsp24 vsp)
 {
     ArrayList tiles = new ArrayList();
     foreach (Vsp24Tile vt in vsp.Tiles) {
         Vsp24Tile vtt = vt.Clone();
         vtt.parent = this;
         tiles.Add(vtt);
     }
     return tiles;
 }
Exemplo n.º 31
0
 public void SetActiveVsp(Vsp24 vsp)
 {
     c_VspView.ActiveVsp = vsp;
 }
Exemplo n.º 32
0
 public ArrayList ImportObstructionTiles(Vsp24 vsp)
 {
     ArrayList tiles = new ArrayList();
     foreach (VspObstructionTile vt in vsp.ObstructionTiles) {
         VspObstructionTile vot = vt.Clone();
         vot.parent = this;
         tiles.Add(vot);
     }
     return tiles;
 }
Exemplo n.º 33
0
 public Vsp24Tile(Vsp24 parent, pr2.IRenderImage image)
 {
     this.parent = parent;
     this.image  = image;
     this.avg    = GetAverageColor();
 }
Exemplo n.º 34
0
 public SetTiledataGroup(Vsp24 vsp)
 {
     this.vsp = vsp;
 }
Exemplo n.º 35
0
 public Vsp24Tile(Vsp24 parent)
     : this(parent, new pr2.BufferImage(16, 16))
 {
 }
Exemplo n.º 36
0
        private unsafe void paint(Graphics g)
        {
            g.PixelOffsetMode    = PixelOffsetMode.HighSpeed;
            g.InterpolationMode  = InterpolationMode.NearestNeighbor;
            g.CompositingMode    = CompositingMode.SourceCopy;
            g.CompositingQuality = CompositingQuality.HighSpeed;

            Rectangle r = new Rectangle(0, 0, 100, 100);

            if (Global.ActiveMap != null && Controller != null)
            {
                // get map
                Map map = Global.ActiveMap;
                // get base layer
                MapLayer BaseLayer = (MapLayer)Global.ActiveMap.Layers[0];
                // get the vsp
                Vsp24 mapVsp = Global.ActiveVsp;

                int vw = 200, vh = 200;
                if (BaseLayer.Width > BaseLayer.Height)
                {
                    vh = (int)(vh * ((float)BaseLayer.Height / (float)BaseLayer.Width));
                }
                else
                {
                    vw = (int)(vw * ((float)BaseLayer.Width / (float)BaseLayer.Height));
                }


                float ratio_x = (float)BaseLayer.Width / vw;
                float ratio_y = (float)BaseLayer.Height / vh;

                float ratio_xn = (float)vw / (BaseLayer.Width * 16);
                float ratio_yn = (float)vh / (BaseLayer.Height * 16);

                mapView mv = Controller.MapView;

                int pw = BaseLayer.Width * 16;
                int ph = BaseLayer.Height * 16;

                //zero 1/18/03 - note the zoom alterations here
                int nw = mv.Width * vw / Controller.ZoomLevel / pw;
                int nh = mv.Height * vh / Controller.ZoomLevel / ph;

                r.Width  = nw;
                r.Height = nh;

                int ox = (int)(Controller.hScrollBar.Value * ratio_xn);
                int oy = (int)(Controller.vScrollBar.Value * ratio_yn);

                r.X = ox;
                r.Y = oy;



                if (bNeedsRedraw)
                {
                    BitmapData bmpd   = bmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
                    int *      imgptr = (int *)bmpd.Scan0.ToPointer();
                    if (mapVsp != null && mapVsp.tileCount > 0)
                    {
                        for (int l = 0; l < map.Layers.Count; l++)
                        {
                            MapLayer layer = (MapLayer)map.Layers[l];
                            if (layer.type != LayerType.Tile)
                            {
                                continue;
                            }

                            for (int i = 0; i < vh; i++)
                            {
                                for (int j = 0; j < vw; j++)
                                {
                                    int tx = (int)(ratio_x * j);
                                    int ty = (int)(ratio_y * i);
                                    if (tx >= layer.Width || tx < 0 || ty >= layer.Height || ty < 0)
                                    {
                                        continue;
                                    }
                                    int tidx = layer.Data[ty * layer.Width + tx];
                                    if ((l == 0 || tidx != 0) && 0 < tidx && tidx < mapVsp.Tiles.Count)
                                    {
                                        imgptr[i * 200 + j] = ((Vsp24Tile)mapVsp.Tiles[tidx]).ColorAverage;
                                    }
                                }
                            }
                        }
                    }
                    bmp.UnlockBits(bmpd);
                    bNeedsRedraw = false;
                }
                int xx = (200 - vw) / 2;
                int yy = (200 - vh) / 2;
                r.X += xx + 1;
                r.Y += yy + 1;



                // flicker reduce hack
                g.Clip = new Region(new Rectangle(xx, yy, vw + 1, vh + 1));
                g.DrawImageUnscaled(bmp, xx, yy, vw, vh);
                g.Clip = new Region(new Rectangle(0, 0, 200, 200));
                //


                g.DrawRectangle(rectPen, r);
                g.DrawRectangle(rectPenW, xx - 2, yy - 2, vw + 4, vh + 4);
            }
            else
            {
                g.FillRectangle(Brushes.Black, 0, 0, Width, Height);
            }
        }
Exemplo n.º 37
0
 public VspObstructionTile(Vsp24 parent, int[] data)
 {
     this.parent = parent;
     this.image = new pr2.BufferImage(Global.TILE_SIZE, Global.TILE_SIZE, data);
 }
Exemplo n.º 38
0
 public void init(Vsp24 vsp)
 {
     init(vsp, 0, 0);
 }