Ejemplo n.º 1
0
        public SpriteEvent(MapEditor mapEditor, CTHG2 cTHG2, bool IsCreate)
        {
            this.mapEditor = mapEditor;
            this.cTHG2     = cTHG2;

            this.IsCreate  = IsCreate;
            IsCreateAction = true;
        }
Ejemplo n.º 2
0
        private void GetCHKAll(BinaryWriter bw)
        {
            LoadString();

            DDDTHG2.Clear();
            MTXM = (ushort[])TILE.Clone();
            //Doodad풀기
            for (int i = 0; i < DD2.Count; i++)
            {
                CDD2 cDD2 = DD2[i];

                DoodadPallet pallete = UseMapEditor.Global.WindowTool.MapViewer.tileSet.DoodadPallets[TILETYPE][cDD2.ID];
                DD2ToMTXM(cDD2);

                CTHG2 cTHG2 = new CTHG2();
                cTHG2.FLAG = pallete.dddFlags;
                cTHG2.X    = cDD2.X;
                cTHG2.Y    = cDD2.Y;
                cTHG2.ID   = pallete.dddOverlayID;

                if (((cTHG2.FLAG & (0b1 << 12)) != 0) | ((cTHG2.FLAG & (0b1 << 13)) != 0))
                {
                    DDDTHG2.Add(cTHG2);
                }
            }



            TriggerSave();



            //에디터로부터 CHK데이터를 가져오는 함수
            for (int i = 0; i < cHKTokens.Count; i++)
            {
                if (cHKTokens[i].tokentype == TOKENTYPE.NULL)
                {
                    GetCHK(bw, cHKTokens[i], TOKENTYPE.NULL);
                }
            }


            foreach (TOKENTYPE cHKTYPE in Enum.GetValues(typeof(TOKENTYPE)))
            {
                if (cHKTYPE != TOKENTYPE.NULL)
                {
                    GetCHK(bw, new CHKToken(), cHKTYPE);
                }
            }
        }
Ejemplo n.º 3
0
        private void SpriteEditList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (SpriteEditList.SelectedIndex == -1)
            {
                return;
            }

            ListBoxItem listBoxItem = (ListBoxItem)SpriteEditList.SelectedItem;
            CTHG2       spdata      = (CTHG2)listBoxItem.Tag;

            SpriteName.Text = spdata.NAME(this);


            SpriteEditPanel.DataContext = spdata;
        }
Ejemplo n.º 4
0
        private bool Applychk(BinaryReader br)
        {
            CHKToken cHKToken = GetNextCHK(br);

            br.BaseStream.Position = cHKToken.start;



            //Byte로부터 에디터로 넣는 함수
            switch (cHKToken.tokentype)
            {
            case TOKENTYPE.ENCD:
                SetEncoding(br.ReadInt32());

                break;

            case TOKENTYPE.IOWN:
                IOWN = br.ReadBytes(12);

                break;

            case TOKENTYPE.OWNR:
                //넘기기
                OWNR = br.ReadBytes(12);

                break;

            case TOKENTYPE.SIDE:
                SIDE = br.ReadBytes(12);

                break;

            case TOKENTYPE.ERA:
                ushort tile = br.ReadUInt16();
                if (tile > 7)
                {
                    throw new Exception("");
                }
                TILETYPE = (TileType)tile;


                break;

            case TOKENTYPE.COLR:
                COLR = br.ReadBytes(8);
                for (int i = 0; i < 8; i++)
                {
                    if (COLR[i] >= ColorName.Count())
                    {
                        COLR[i] = 0;
                    }


                    CRGB[i] = new Microsoft.Xna.Framework.Color(0, 0, COLR[i]);
                }


                break;

            case TOKENTYPE.CRGB:
                for (int i = 0; i < 8; i++)
                {
                    byte[] colors = br.ReadBytes(3);
                    CRGB[i] = new Microsoft.Xna.Framework.Color(colors[0], colors[1], colors[2]);
                }
                CRGBIND = br.ReadBytes(8);

                break;

            case TOKENTYPE.UNIT:
                UNIT.Clear();
                for (int i = 0; i < cHKToken.size / 36; i++)
                {
                    CUNIT cUNIT = new CUNIT(br);
                    cUNIT.SetMapEditor(mapEditor);
                    UNIT.Add(cUNIT);
                }

                break;

            case TOKENTYPE.DIM:
                WIDTH  = br.ReadUInt16();
                HEIGHT = br.ReadUInt16();
                break;

            case TOKENTYPE.TILE:
                TILE = new ushort[cHKToken.size / 2];
                for (int i = 0; i < cHKToken.size / 2; i++)
                {
                    TILE[i] = br.ReadUInt16();
                }

                break;

            case TOKENTYPE.MTXM:
                MTXM = new ushort[cHKToken.size / 2];
                for (int i = 0; i < cHKToken.size / 2; i++)
                {
                    MTXM[i] = br.ReadUInt16();
                }

                break;

            case TOKENTYPE.DD2:
                for (int i = 0; i < cHKToken.size / 8; i++)
                {
                    CDD2 cDD2 = new CDD2(br, this);

                    DD2.Add(cDD2);
                }
                break;

            case TOKENTYPE.THG2:
                for (int i = 0; i < cHKToken.size / 10; i++)
                {
                    CTHG2 cTHG2 = new CTHG2(br);

                    THG2.Add(cTHG2);
                }

                break;

            case TOKENTYPE.MASK:
                MASK = br.ReadBytes((int)cHKToken.size);

                break;

            case TOKENTYPE.STR:
            {
                long startpoint = br.BaseStream.Position;

                LOADSTR = new string[br.ReadUInt16()];
                BYTESTR = new List <byte[]>();

                ushort[] ptrs = new ushort[LOADSTR.Length];
                for (int i = 0; i < ptrs.Length; i++)
                {
                    ptrs[i] = br.ReadUInt16();
                }


                for (int i = 0; i < ptrs.Length; i++)
                {
                    br.BaseStream.Position = startpoint + ptrs[i];

                    List <byte> strs     = new List <byte>();
                    byte        readbyte = br.ReadByte();


                    if (readbyte != 0)
                    {
                        strs.Add(readbyte);
                        while (true)
                        {
                            readbyte = br.ReadByte();
                            if (readbyte == 0)
                            {
                                break;
                            }
                            strs.Add(readbyte);
                        }
                    }


                    BYTESTR.Add(strs.ToArray());

                    //LOADSTR[i] = System.Text.Encoding.GetEncoding(949).GetString(strs.ToArray());
                }
            }
            break;

            case TOKENTYPE.STRx:
            {
                long startpoint = br.BaseStream.Position;

                LOADSTRx = new string[br.ReadUInt32()];
                BYTESTRx = new List <byte[]>();

                uint[] ptrs = new uint[LOADSTRx.Length];
                for (int i = 0; i < ptrs.Length; i++)
                {
                    ptrs[i] = br.ReadUInt32();
                }


                for (int i = 0; i < ptrs.Length; i++)
                {
                    br.BaseStream.Position = startpoint + ptrs[i];

                    List <byte> strs     = new List <byte>();
                    byte        readbyte = br.ReadByte();

                    if (readbyte != 0)
                    {
                        strs.Add(readbyte);
                        while (true)
                        {
                            readbyte = br.ReadByte();
                            if (readbyte == 0)
                            {
                                break;
                            }
                            strs.Add(readbyte);
                        }
                    }


                    BYTESTRx.Add(strs.ToArray());

                    //LOADSTRx[i] = System.Text.Encoding.UTF8.GetString(strs.ToArray());
                }
            }
            break;

            case TOKENTYPE.SPRP:
                SCEARIONAME = new StringData(this, br.ReadUInt16());
                SCEARIODES  = new StringData(this, br.ReadUInt16());


                break;

            case TOKENTYPE.FORC:
                FORCE = br.ReadBytes(8);

                FORCENAME    = new StringData[4];
                FORCENAME[0] = new StringData(this, br.ReadUInt16());
                FORCENAME[1] = new StringData(this, br.ReadUInt16());
                FORCENAME[2] = new StringData(this, br.ReadUInt16());
                FORCENAME[3] = new StringData(this, br.ReadUInt16());

                FORCEFLAG = br.ReadBytes(4);
                break;

            case TOKENTYPE.MRGN:
                LocationDatas.Clear();
                LocationDatas.Add(new LocationData(mapEditor));
                for (int i = 0; i < 255; i++)
                {
                    LocationData locationData = new LocationData(mapEditor);

                    locationData.INDEX = i + 1;

                    locationData.L      = br.ReadUInt32();
                    locationData.T      = br.ReadUInt32();
                    locationData.R      = br.ReadUInt32();
                    locationData.B      = br.ReadUInt32();
                    locationData.STRING = new StringData(this, br.ReadUInt16());
                    locationData.FLAG   = br.ReadUInt16();

                    if (locationData.L == 0 & locationData.T == 0 & locationData.L == 0 & locationData.T == 0 &
                        locationData.STRING.LoadedIndex == -1 & locationData.FLAG == 0)
                    {
                        continue;
                    }


                    LocationDatas.Add(locationData);
                }
                //u32: Left(X1) coordinate of location, in pixels(usually 32 pt grid aligned)
                //u32: Top(Y1) coordinate of location, in pixels
                //u32: Right(X2) coordinate of location, in pixels
                //u32: Bottom(Y2) coordinate of location, in pixels
                //u16: String number of the name of this location
                //u16: Location elevation flags.If an elevation is disabled in the location, it's bit will be on (1)
                //Bit 0 - Low elevation
                //Bit 1 - Medium elevation
                //Bit 2 - High elevation
                //Bit 3 - Low air
                //Bit 4 - Medium air
                //Bit 5 - High air
                //Bit 6 - 15 - Unused


                break;

            case TOKENTYPE.UPRP:
                UPRP = new CUPRP[64];
                for (int i = 0; i < 64; i++)
                {
                    CUPRP cUPRP = new CUPRP();
                    cUPRP.STATUSVALID = br.ReadUInt16();
                    cUPRP.POINTVALID  = br.ReadUInt16();

                    cUPRP.PLAYER      = br.ReadByte();
                    cUPRP.HITPOINT    = br.ReadByte();
                    cUPRP.SHIELDPOINT = br.ReadByte();
                    cUPRP.ENERGYPOINT = br.ReadByte();


                    cUPRP.RESOURCE   = br.ReadUInt32();
                    cUPRP.HANGAR     = br.ReadUInt16();
                    cUPRP.STATUSFLAG = br.ReadUInt16();
                    cUPRP.UNUSED     = br.ReadUInt32();

                    UPRP[i] = cUPRP;
                }
                break;

            case TOKENTYPE.UPUS:
                UPUS = br.ReadBytes(64);
                break;

            case TOKENTYPE.WAV:
                WAV = new StringData[512];
                for (int i = 0; i < 512; i++)
                {
                    WAV[i] = new StringData(this, br.ReadInt32());
                }
                break;

            case TOKENTYPE.SWNM:
                SWNM = new StringData[256];
                for (int i = 0; i < 256; i++)
                {
                    SWNM[i] = new StringData(this, br.ReadInt32());
                }
                break;

            case TOKENTYPE.PUNI:
                PUNI = new CPUNI();
                for (int i = 0; i < 12; i++)
                {
                    PUNI.UNITENABLED[i] = br.ReadBytes(228);
                }
                PUNI.DEFAULT = br.ReadBytes(228);
                for (int i = 0; i < 12; i++)
                {
                    PUNI.USEDEFAULT[i] = br.ReadBytes(228);
                }

                break;

            case TOKENTYPE.PUPx:
                PUPx = new CPUPx();
                for (int i = 0; i < 12; i++)
                {
                    PUPx.MAXLEVEL[i] = br.ReadBytes(61);
                }
                for (int i = 0; i < 12; i++)
                {
                    PUPx.STARTLEVEL[i] = br.ReadBytes(61);
                }
                PUPx.DEFAULTMAXLEVEL   = br.ReadBytes(61);
                PUPx.DEFAULTSTARTLEVEL = br.ReadBytes(61);
                for (int i = 0; i < 12; i++)
                {
                    PUPx.USEDEFAULT[i] = br.ReadBytes(61);
                }

                break;

            case TOKENTYPE.PTEx:
                PTEx = new CPTEx();
                for (int i = 0; i < 12; i++)
                {
                    PTEx.MAXLEVEL[i] = br.ReadBytes(44);
                }
                for (int i = 0; i < 12; i++)
                {
                    PTEx.STARTLEVEL[i] = br.ReadBytes(44);
                }
                PTEx.DEFAULTMAXLEVEL   = br.ReadBytes(44);
                PTEx.DEFAULTSTARTLEVEL = br.ReadBytes(44);
                for (int i = 0; i < 12; i++)
                {
                    PTEx.USEDEFAULT[i] = br.ReadBytes(44);
                }

                break;

            case TOKENTYPE.UNIx:
                UNIx = new CUNIx();
                for (int i = 0; i < 228; i++)
                {
                    UNIx.USEDEFAULT[i] = br.ReadByte();
                }

                for (int i = 0; i < 228; i++)
                {
                    UNIx.HIT[i] = br.ReadUInt32();
                }
                for (int i = 0; i < 228; i++)
                {
                    UNIx.SHIELD[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 228; i++)
                {
                    UNIx.ARMOR[i] = br.ReadByte();
                }
                for (int i = 0; i < 228; i++)
                {
                    UNIx.BUILDTIME[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 228; i++)
                {
                    UNIx.MIN[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 228; i++)
                {
                    UNIx.GAS[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 228; i++)
                {
                    UNIx.STRING[i] = new StringData(this, br.ReadUInt16());
                }
                for (int i = 0; i < 130; i++)
                {
                    UNIx.DMG[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 130; i++)
                {
                    UNIx.BONUSDMG[i] = br.ReadUInt16();
                }

                break;

            case TOKENTYPE.UPGx:
                UPGx = new CUPGx();
                for (int i = 0; i < 61; i++)
                {
                    UPGx.USEDEFAULT[i] = br.ReadByte();
                }
                br.ReadByte();
                for (int i = 0; i < 61; i++)
                {
                    UPGx.BASEMIN[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 61; i++)
                {
                    UPGx.BONUSMIN[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 61; i++)
                {
                    UPGx.BASEGAS[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 61; i++)
                {
                    UPGx.BONUSGAS[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 61; i++)
                {
                    UPGx.BASETIME[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 61; i++)
                {
                    UPGx.BONUSTIME[i] = br.ReadUInt16();
                }

                break;

            case TOKENTYPE.TECx:
                TECx = new CTECx();
                for (int i = 0; i < 44; i++)
                {
                    TECx.USEDEFAULT[i] = br.ReadByte();
                }
                for (int i = 0; i < 44; i++)
                {
                    TECx.MIN[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 44; i++)
                {
                    TECx.GAS[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 44; i++)
                {
                    TECx.BASETIME[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 44; i++)
                {
                    TECx.ENERGY[i] = br.ReadUInt16();
                }

                break;

            case TOKENTYPE.TRIG:
                TRIG.Clear();

                for (int i = 0; i < cHKToken.size / 2400; i++)
                {
                    RAWTRIGMBRF trig = new RAWTRIGMBRF(br);

                    TRIG.Add(trig);
                }


                break;

            case TOKENTYPE.MBRF:
                MBRF.Clear();

                for (int i = 0; i < cHKToken.size / 2400; i++)
                {
                    RAWTRIGMBRF mbrf = new RAWTRIGMBRF(br);

                    MBRF.Add(mbrf);
                }


                break;
            }



            for (int i = 0; i < cHKTokens.Count; i++)
            {
                if (cHKTokens[i].code == cHKToken.code)
                {
                    cHKTokens.RemoveAt(i);
                    break;
                }
            }
            cHKTokens.Add(cHKToken);
            br.BaseStream.Position = cHKToken.end;
            return(true);
        }
Ejemplo n.º 5
0
        private bool ApplychkAll(BinaryReader br)
        {
            cHKTokens = new List <CHKToken>();

            br.BaseStream.Position = 0;

            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                if (!Applychk(br))
                {
                    return(false);
                }
            }


            if (TILE == null)
            {
                TILE = (ushort[])MTXM.Clone();
            }


            if (BYTESTRx == null)
            {
                BYTESTRx = BYTESTR;
            }

            if (LOADSTRx == null)
            {
                LOADSTRx = (string[])LOADSTR.Clone();
            }

            if (IOWN == null)
            {
                //IOWN = (byte[])OWNR.Clone();
                throw new Exception("");
            }

            //만약 인코딩이 없을 경우
            if (ENCODING == null)
            {
                ENCODING = System.Text.Encoding.UTF8;

                EncodingSelectDialog encodingSelectDialog = new EncodingSelectDialog(this);
                encodingSelectDialog.ShowDialog();
            }

            for (int i = 0; i < BYTESTRx.Count; i++)
            {
                //여기서 작업해준다.
                string s = ENCODING.GetString(BYTESTRx[i]);

                LOADSTRx[i] = UseMapEditor.Tools.StringTool.ReadRawString(s);
            }

            for (int i = 0; i < DD2.Count; i++)
            {
                DoodadPallet pallete = UseMapEditor.Global.WindowTool.MapViewer.tileSet.DoodadPallets[TILETYPE][DD2[i].ID];;

                if (THG2.Exists(x => (x.X == DD2[i].X) & (x.Y == DD2[i].Y)))
                {
                    CTHG2 s = THG2.Find(x => (x.X == DD2[i].X) & (x.Y == DD2[i].Y));

                    if (s.ID == pallete.dddOverlayID)
                    {
                        THG2.Remove(s);
                    }
                }
            }



            TriggerLoad();



            //soundDatas
            uint hmpq = OpenArchive();

            soundDatas.Clear();
            for (int i = 0; i < WAV.Length; i++)
            {
                string d = WAV[i].String;
                if (WAV[i].IsLoaded)
                {
                    SoundData soundData = new SoundData();
                    soundData.path  = d;
                    soundData.bytes = ReadMPQFileC(hmpq, d);
                    if (soundData.bytes.Length != 0)
                    {
                        soundDatas.Add(soundData);
                    }
                }
            }
            CloseArchive(hmpq);



            return(true);
        }
Ejemplo n.º 6
0
        private void DrawSprite(CTHG2 cTHG2)
        {
            int     _x     = cTHG2.X;
            int     _y     = cTHG2.Y;
            Vector2 screen = mapeditor.PosMapToScreen(new Vector2(_x, _y));

            bool IsSelect = false;
            bool IsHover  = false;

            if (mapeditor.PalleteLayer == Control.MapEditor.Layer.Sprite)
            {
                if (mapeditor.mapDataBinding.SPRITE_SELECTMODE)
                {
                    if (mouse_IsDrag)
                    {
                        //선택모드
                        Vector2 min = new Vector2(Math.Min(mouse_DragMapStart.X, MouseMapPos.X), Math.Min(mouse_DragMapStart.Y, MouseMapPos.Y));
                        Vector2 max = new Vector2(Math.Max(mouse_DragMapStart.X, MouseMapPos.X), Math.Max(mouse_DragMapStart.Y, MouseMapPos.Y));

                        if (min.X - 8 < _x & _x < max.X + 8)
                        {
                            if (min.Y - 8 < _y & _y < max.Y + 8)
                            {
                                hoverSprite.Add(cTHG2);
                            }
                        }
                    }
                    if (mapeditor.SelectSprite.Contains(cTHG2))
                    {
                        IsSelect = true;
                    }
                    else if (hoverSprite.Contains(cTHG2))
                    {
                        IsHover = true;
                    }
                }
            }

            int objID = cTHG2.ID;

            int objwidth  = (int)(cTHG2.BoxWidth * mapeditor.opt_scalepercent);
            int objheight = (int)(cTHG2.BoxHeight * mapeditor.opt_scalepercent);

            float minX = 0 - objwidth;
            float minY = 0 - objheight;
            float maxX = screenwidth + objwidth;
            float maxY = screenheight + objheight;

            if ((minX < screen.X) & (screen.X < maxX))
            {
                if ((minY < screen.Y) & (screen.Y < maxY))
                {
                    if (cTHG2.Images.Count == 0)
                    {
                        cTHG2.ImageReset();
                    }

                    for (int i = 0; i < cTHG2.Images.Count; i++)
                    {
                        cTHG2.Images[i].IsSelect = false;
                        cTHG2.Images[i].IsHover  = false;
                        if (i == 0)
                        {
                            if (IsSelect)
                            {
                                cTHG2.Images[i].IsSelect = true;
                            }
                            else if (IsHover)
                            {
                                cTHG2.Images[i].IsHover = true;
                            }
                        }
                        cTHG2.Images[i].color  = cTHG2.PLAYER;
                        cTHG2.Images[i].screen = screen;
                        ImageList.Add(cTHG2.Images[i]);
                        cTHG2.Images[i].PlayScript();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void DrawPalleteCursor()
        {
            //우클릭하면 선택모드로 변경됨

            bool IsDrawSelectRect = false;
            bool IsRetrun         = false;

            switch (mapeditor.PalleteLayer)
            {
            case Control.MapEditor.Layer.Sprite:
                if (mapeditor.mapDataBinding.SPRITE_SELECTMODE)
                {
                    if (mouse_IsDrag)
                    {
                        IsDrawSelectRect = true;
                    }
                    IsRetrun = true;
                }
                break;

            case Control.MapEditor.Layer.Unit:
                if (mapeditor.mapDataBinding.UNIT_SELECTMODE)
                {
                    if (mouse_IsDrag)
                    {
                        IsDrawSelectRect = true;
                    }
                    IsRetrun = true;
                }
                break;

            case Control.MapEditor.Layer.Doodad:
                if (mapeditor.mapDataBinding.DOODAD_SELECTMODE)
                {
                    if (mouse_IsDrag)
                    {
                        IsDrawSelectRect = true;
                    }
                    IsRetrun = true;
                }
                break;
            }
            if (IsDrawSelectRect)
            {
                _spriteBatch.Begin(blendState: BlendState.NonPremultiplied);
                //Q하면 유닛 선택

                Vector2 dragpos = mapeditor.PosMapToScreen(mouse_DragMapStart);

                Vector2 min  = new Vector2(Math.Min(dragpos.X, MousePos.X), Math.Min(dragpos.Y, MousePos.Y));
                Vector2 max  = new Vector2(Math.Max(dragpos.X, MousePos.X), Math.Max(dragpos.Y, MousePos.Y));
                Vector2 size = max - min;

                DrawRect(_spriteBatch, dragpos, MousePos, Color.LimeGreen, 2);
                _spriteBatch.Draw(gridtexture, new Rectangle((int)min.X, (int)min.Y, (int)size.X, (int)size.Y), null, new Color(128, 255, 128, 64), 0, new Vector2(), SpriteEffects.None, 0);
                _spriteBatch.End();
            }
            if (IsRetrun)
            {
                return;
            }



            List <CImage> templist = new List <CImage>();
            int           gridsize = mapeditor.opt_grid;

            switch (mapeditor.PalleteLayer)
            {
            case Control.MapEditor.Layer.Unit:
            {
                if (mapeditor.unit_PasteMode)
                {
                    for (int i = 0; i < mapeditor.CopyedUnit.Count; i++)
                    {
                        CUNIT cUNIT = mapeditor.CopyedUnit[i];
                        if (cUNIT.Images.Count == 0)
                        {
                            cUNIT.ImageReset();
                        }
                        Vector2 mappos  = MouseMapPos;
                        byte    sflag   = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Special Ability Flags", cUNIT.unitID).Data;
                        ushort  bwidth  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "StarEdit Placement Box Width", cUNIT.unitID).Data;
                        ushort  bheight = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "StarEdit Placement Box Height", cUNIT.unitID).Data;

                        ushort uleft  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Left", cUNIT.unitID).Data;
                        ushort uup    = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Up", cUNIT.unitID).Data;
                        ushort uright = (byte)(Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Right", cUNIT.unitID).Data + 1);
                        ushort udown  = (byte)(Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Down", cUNIT.unitID).Data + 1);

                        bool IsBuilding = false;
                        if ((sflag & 0x1) > 0)
                        {
                            //건물
                            IsBuilding = true;
                        }
                        if (mapeditor.UnitPalleteGridFix)
                        {
                            //그리드 픽스
                            if (gridsize != 0)
                            {
                                mappos.X = (float)(Math.Round(mappos.X / gridsize) * gridsize);
                                mappos.Y = (float)(Math.Round(mappos.Y / gridsize) * gridsize);
                            }
                        }


                        mappos += new Vector2((short)cUNIT.X, (short)cUNIT.Y);

                        mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                        mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));

                        mappos.X = (float)Math.Floor(mappos.X);
                        mappos.Y = (float)Math.Floor(mappos.Y);

                        Vector2 mousepos = mapeditor.PosMapToScreen(mappos);

                        DrawUnit(cUNIT, templist, (int)mappos.X, (int)mappos.Y);
                        DrawImageList(templist);
                        if (IsBuilding)
                        {
                            double _w = bwidth * mapeditor.opt_scalepercent;
                            double _h = bheight * mapeditor.opt_scalepercent;
                            _spriteBatch.Begin(blendState: BlendState.NonPremultiplied);
                            _spriteBatch.Draw(gridtexture, new Rectangle((int)(mousepos.X - _w / 2), (int)(mousepos.Y - _h / 2), (int)_w, (int)_h), null, new Color(128, 255, 128, 64), 0, new Vector2(), SpriteEffects.None, 0);
                            _spriteBatch.End();
                        }



                        double _l = uleft * mapeditor.opt_scalepercent;
                        double _u = uup * mapeditor.opt_scalepercent;
                        double _r = uright * mapeditor.opt_scalepercent;
                        double _d = udown * mapeditor.opt_scalepercent;

                        _spriteBatch.Begin();
                        if (UnitCollsionCheck(mappos, cUNIT.unitID, IsBuilding, true))
                        {
                            //유닛 배치 가능
                            DrawRect(_spriteBatch, new Vector2(mousepos.X - (float)_l, mousepos.Y - (float)_u), new Vector2(mousepos.X + (float)_r, mousepos.Y + (float)_d), Color.Lime, 1);
                        }
                        else
                        {
                            DrawRect(_spriteBatch, new Vector2(mousepos.X - (float)_l, mousepos.Y - (float)_u), new Vector2(mousepos.X + (float)_r, mousepos.Y + (float)_d), Color.Red, 1);
                        }
                        _spriteBatch.End();
                        templist.Clear();
                    }
                }
                else
                {
                    int unitid   = (ushort)mapeditor.UnitPallete.SelectIndex;
                    int playerid = (ushort)mapeditor.unit_player;
                    if (unitid == -1)
                    {
                        return;
                    }
                    if (UnitPalleteCursor == null)
                    {
                        UnitPalleteCursor = new CUNIT();
                        //UnitPalleteCursor.stateFlag = 0b1;
                        UnitPalleteCursor.unitID = (ushort)unitid;
                    }

                    if (UnitPalleteCursor.unitID != unitid)
                    {
                        UnitPalleteCursor.unitID = (ushort)unitid;
                        UnitPalleteCursor.ImageReset();
                    }

                    if (UnitPalleteCursor.player != playerid)
                    {
                        UnitPalleteCursor.player = (byte)playerid;
                        UnitPalleteCursor.ImageReset();
                    }

                    if (UnitPalleteCursor.Images.Count == 0)
                    {
                        UnitPalleteCursor.ImageReset();
                    }

                    Vector2 mappos  = MouseMapPos;
                    byte    sflag   = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Special Ability Flags", unitid).Data;
                    ushort  bwidth  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "StarEdit Placement Box Width", unitid).Data;
                    ushort  bheight = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "StarEdit Placement Box Height", unitid).Data;

                    ushort uleft  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Left", unitid).Data;
                    ushort uup    = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Up", unitid).Data;
                    ushort uright = (byte)(Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Right", unitid).Data + 1);
                    ushort udown  = (byte)(Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Down", unitid).Data + 1);

                    bool IsBuilding = false;
                    if ((sflag & 0x1) > 0)
                    {
                        //건물
                        IsBuilding = true;
                    }

                    if (mapeditor.UnitPalleteBuildingFix & IsBuilding)
                    {
                        //빌딩 그리드 픽스
                        mappos.X = (float)(Math.Round(mappos.X / 32) * 32);
                        mappos.Y = (float)(Math.Round(mappos.Y / 32) * 32);

                        mappos.X += (bwidth / 2) % 32;
                        mappos.Y += (bheight / 2) % 32;
                    }
                    else if (mapeditor.UnitPalleteGridFix)
                    {
                        //그리드 픽스
                        if (gridsize != 0)
                        {
                            mappos.X = (float)(Math.Round(mappos.X / gridsize) * gridsize);
                            mappos.Y = (float)(Math.Round(mappos.Y / gridsize) * gridsize);
                        }
                    }

                    mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                    mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));

                    mappos.X = (float)Math.Floor(mappos.X);
                    mappos.Y = (float)Math.Floor(mappos.Y);

                    UnitPalleteCursor.X = (ushort)mappos.X;
                    UnitPalleteCursor.Y = (ushort)mappos.Y;

                    Vector2 mousepos = mapeditor.PosMapToScreen(mappos);

                    DrawUnit(UnitPalleteCursor, templist, AlwaysDraw: true);
                    DrawImageList(templist);
                    if (MousePos.X > screenwidth)
                    {
                        //밖으로 나갔을 경우 미리보기 그리기
                        DrawImageListPreview(templist, new Vector2(screenwidth - 128, 256));
                    }
                    if (IsBuilding)
                    {
                        double _w = bwidth * mapeditor.opt_scalepercent;
                        double _h = bheight * mapeditor.opt_scalepercent;
                        _spriteBatch.Begin(blendState: BlendState.NonPremultiplied);
                        _spriteBatch.Draw(gridtexture, new Rectangle((int)(mousepos.X - _w / 2), (int)(mousepos.Y - _h / 2), (int)_w, (int)_h), null, new Color(128, 255, 128, 64), 0, new Vector2(), SpriteEffects.None, 0);
                        _spriteBatch.End();
                    }



                    double _l = uleft * mapeditor.opt_scalepercent;
                    double _u = uup * mapeditor.opt_scalepercent;
                    double _r = uright * mapeditor.opt_scalepercent;
                    double _d = udown * mapeditor.opt_scalepercent;

                    _spriteBatch.Begin();
                    if (UnitCollsionCheck(mappos, unitid, IsBuilding, true))
                    {
                        //유닛 배치 가능
                        DrawRect(_spriteBatch, new Vector2(mousepos.X - (float)_l, mousepos.Y - (float)_u), new Vector2(mousepos.X + (float)_r, mousepos.Y + (float)_d), Color.Lime, 1);
                    }
                    else
                    {
                        DrawRect(_spriteBatch, new Vector2(mousepos.X - (float)_l, mousepos.Y - (float)_u), new Vector2(mousepos.X + (float)_r, mousepos.Y + (float)_d), Color.Red, 1);
                    }
                    _spriteBatch.End();
                }
            }

            break;

            case Control.MapEditor.Layer.Sprite:
            {
                if (mapeditor.sprite_PasteMode)
                {
                    //복사모드
                    for (int i = 0; i < mapeditor.CopyedSprite.Count; i++)
                    {
                        CTHG2   cTHG2  = mapeditor.CopyedSprite[i];
                        Vector2 mappos = MouseMapPos;
                        if (mapeditor.SpritePalleteGridFix)
                        {
                            //그리드 픽스
                            if (gridsize != 0)
                            {
                                mappos.X = (float)(Math.Round(mappos.X / gridsize) * gridsize);
                                mappos.Y = (float)(Math.Round(mappos.Y / gridsize) * gridsize);
                            }
                        }


                        mappos += new Vector2((short)cTHG2.X, (short)cTHG2.Y);

                        mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                        mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));



                        if (cTHG2.Images.Count == 0)
                        {
                            cTHG2.ImageReset();
                        }

                        for (int c = 0; c < cTHG2.Images.Count; c++)
                        {
                            Vector2 mp = mapeditor.PosMapToScreen(mappos);


                            cTHG2.Images[c].IsHover = true;
                            cTHG2.Images[c].screen  = mp;
                            templist.Add(cTHG2.Images[c]);
                            cTHG2.Images[c].PlayScript();
                        }
                    }

                    DrawImageList(templist);
                }
                else
                {
                    int spriteid;

                    if (mapeditor.sprite_SpritBrush)
                    {
                        spriteid = mapeditor.SpritePallete.SelectIndex;
                    }
                    else
                    {
                        int unitID  = mapeditor.SpritePallete_Unit.SelectIndex;
                        int fligyID = (int)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Graphics", unitID).Data;
                        spriteid = (int)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.flingy, "Sprite", fligyID).Data;
                    }


                    Vector2 mappos = MouseMapPos;
                    mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                    mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));

                    if (mapeditor.SpritePalleteGridFix)
                    {
                        //그리드 픽스
                        if (gridsize != 0)
                        {
                            mappos.X = (float)(Math.Round(mappos.X / gridsize) * gridsize);
                            mappos.Y = (float)(Math.Round(mappos.Y / gridsize) * gridsize);
                        }
                    }


                    if (SpritePalleteCursor == null)
                    {
                        SpritePalleteCursor = new List <CImage>();
                        SpritePalleteCursor.Add(new CImage(int.MaxValue, SpritePalleteCursor, 0, 0, 0));
                    }

                    if (SpritePalleteCursor.Count != 0)
                    {
                        if (spriteid != -1)
                        {
                            int imageid = (int)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.sprites, "Image File", spriteid).Data;
                            if (SpritePalleteCursor[0].imageID != imageid)
                            {
                                SpritePalleteCursor.Clear();
                                SpritePalleteCursor.Add(new CImage(0, SpritePalleteCursor, imageid, 0, 0, level: 30));
                            }
                        }
                        else
                        {
                            SpritePalleteCursor.Clear();
                        }
                    }
                    else
                    {
                        if (spriteid != -1)
                        {
                            int imageid = (int)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.sprites, "Image File", spriteid).Data;
                            SpritePalleteCursor.Add(new CImage(0, SpritePalleteCursor, imageid, 0, 0, level: 30));
                        }
                        else
                        {
                            SpritePalleteCursor.Clear();
                        }
                    }

                    if (spriteid == -1)
                    {
                        return;
                    }



                    for (int i = 0; i < SpritePalleteCursor.Count; i++)
                    {
                        SpritePalleteCursor[i].color = mapeditor.sprite_player;


                        Vector2 mp = mapeditor.PosMapToScreen(mappos);

                        SpritePalleteCursor[i].screen = mp;
                        templist.Add(SpritePalleteCursor[i]);
                        SpritePalleteCursor[i].PlayScript();
                    }
                    DrawImageList(templist);
                    if (MousePos.X > screenwidth)
                    {
                        //밖으로 나갔을 경우 미리보기 그리기
                        DrawImageListPreview(templist, new Vector2(screenwidth - 128, 256));
                    }
                }
            }
            break;

            case Control.MapEditor.Layer.Doodad:
            {
                if (mapeditor.doodad_PasteMode)
                {
                    for (int i = 0; i < mapeditor.CopyedDoodad.Count; i++)
                    {
                        Vector2 mappos = MouseMapPos;


                        mappos.X = (float)(Math.Round(mappos.X / 32) * 32);
                        mappos.Y = (float)(Math.Round(mappos.Y / 32) * 32);


                        int doodadid = mapeditor.CopyedDoodad[i].ID;
                        var t        = tileSet.DoodadPallets[mapeditor.mapdata.TILETYPE];


                        CDD2 cDD2 = mapeditor.CopyedDoodad[i];
                        if (cDD2.Images.Count == 0)
                        {
                            cDD2.ImageReset();
                        }


                        Vector2 DoodadPos = mappos + new Vector2(cDD2.X, cDD2.Y);


                        //if (pallete.dddHeight % 2 == 1)
                        //{
                        //    mappos.Y -= 16;
                        //}

                        mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                        mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));

                        mappos.X = (float)Math.Floor(mappos.X);
                        mappos.Y = (float)Math.Floor(mappos.Y);


                        mappos.X += (float)cDD2.X;
                        mappos.Y += (float)cDD2.Y;


                        cDD2.PalleteX = (ushort)mappos.X;
                        cDD2.PalleteY = (ushort)mappos.Y;



                        //Vector2 mousepos = mapeditor.PosMapToScreen(mappos);

                        _spriteBatch.Begin(samplerState: SamplerState.PointClamp);
                        DrawDooDad(cDD2, templist, IsPallete: true);
                        //_spriteBatch.DrawString(_font, doodadid.ToString(), mousepos, Color.Red);
                        _spriteBatch.End();
                        DrawImageList(templist);
                    }
                }
                else
                {
                    int doodadid = mapeditor.doodad_index;
                    var t        = tileSet.DoodadPallets[mapeditor.mapdata.TILETYPE];

                    if (!t.ContainsKey((ushort)doodadid))
                    {
                        return;
                    }

                    DoodadPallet pallete = t[(ushort)doodadid];


                    int playerid = 12;
                    if (doodadid == -1)
                    {
                        return;
                    }
                    if (DoodadPalleteCursor == null)
                    {
                        DoodadPalleteCursor        = new CDD2(mapeditor.mapdata);
                        DoodadPalleteCursor.ID     = (ushort)doodadid;
                        DoodadPalleteCursor.PLAYER = (byte)playerid;
                    }

                    if (DoodadPalleteCursor.ID != doodadid)
                    {
                        DoodadPalleteCursor.ID = (ushort)doodadid;
                        DoodadPalleteCursor.ImageReset();
                    }



                    if (DoodadPalleteCursor.Images.Count == 0)
                    {
                        DoodadPalleteCursor.ImageReset();
                    }

                    Vector2 mappos = MouseMapPos;


                    mappos.X = (float)(Math.Round(mappos.X / 32) * 32);
                    mappos.Y = (float)(Math.Round(mappos.Y / 32) * 32);
                    if (pallete.dddHeight % 2 == 1)
                    {
                        mappos.Y -= 16;
                    }



                    mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                    mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));

                    mappos.X = (float)Math.Floor(mappos.X);
                    mappos.Y = (float)Math.Floor(mappos.Y);

                    DoodadPalleteCursor.PalleteX = (ushort)mappos.X;
                    DoodadPalleteCursor.PalleteY = (ushort)mappos.Y;

                    //Vector2 mousepos = mapeditor.PosMapToScreen(mappos);

                    _spriteBatch.Begin(samplerState: SamplerState.PointClamp);
                    DrawDooDad(DoodadPalleteCursor, templist, IsPallete: true);
                    //_spriteBatch.DrawString(_font, doodadid.ToString(), mousepos, Color.Red);
                    _spriteBatch.End();
                    DrawImageList(templist);
                }
            }
            break;
            }
        }
Ejemplo n.º 8
0
        private void SpritePalleteDraw()
        {
            int gridsize = mapeditor.opt_grid;

            if (mapeditor.mapDataBinding.SPRITE_SELECTMODE)
            {
                return;
            }

            if (mouse_LeftDown)
            {
                if (mapeditor.sprite_PasteMode)
                {
                    Vector2 mappos = mapeditor.PosScreenToMap(MousePos);
                    if (mapeditor.SpritePalleteGridFix)
                    {
                        //그리드 픽스
                        if (gridsize != 0)
                        {
                            mappos.X = (float)(Math.Round(mappos.X / gridsize) * gridsize);
                            mappos.Y = (float)(Math.Round(mappos.Y / gridsize) * gridsize);
                        }
                    }
                    if ((LastCreatePos - mappos).Length() >= Math.Max(gridsize, 4))
                    {
                        LastCreatePos = mappos;

                        for (int i = 0; i < mapeditor.CopyedSprite.Count; i++)
                        {
                            CTHG2 csTHG2 = mapeditor.CopyedSprite[i];
                            mappos = MouseMapPos;
                            if (mapeditor.SpritePalleteGridFix)
                            {
                                //그리드 픽스
                                if (gridsize != 0)
                                {
                                    mappos.X = (float)(Math.Round(mappos.X / gridsize) * gridsize);
                                    mappos.Y = (float)(Math.Round(mappos.Y / gridsize) * gridsize);
                                }
                            }

                            mappos += new Vector2((short)csTHG2.X, (short)csTHG2.Y);

                            mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                            mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));


                            CTHG2 cTHG2 = new CTHG2();
                            cTHG2.ID     = (ushort)mapeditor.CopyedSprite[i].ID;
                            cTHG2.FLAG   = mapeditor.CopyedSprite[i].FLAG;
                            cTHG2.PLAYER = (byte)mapeditor.CopyedSprite[i].PLAYER;
                            cTHG2.X      = (ushort)(mappos.X);
                            cTHG2.Y      = (ushort)(mappos.Y);


                            mapeditor.mapdata.THG2.Add(cTHG2);
                            cTHG2.ImageReset();

                            mapeditor.taskManager.TaskAdd(new SpriteEvent(mapeditor, cTHG2, true));
                        }
                    }
                }
                else
                {
                    Vector2 mappos = mapeditor.PosScreenToMap(MousePos);
                    mappos = Tools.VectorTool.Max(mappos, new Vector2(0));
                    mappos = Tools.VectorTool.Min(mappos, new Vector2(mapeditor.mapdata.WIDTH * 32, mapeditor.mapdata.HEIGHT * 32));
                    if (mapeditor.SpritePalleteGridFix)
                    {
                        //그리드 픽스
                        if (gridsize != 0)
                        {
                            mappos.X = (float)(Math.Round(mappos.X / gridsize) * gridsize);
                            mappos.Y = (float)(Math.Round(mappos.Y / gridsize) * gridsize);
                        }
                    }
                    //생성모드
                    if ((LastCreatePos - mappos).Length() >= Math.Max(gridsize, 4))
                    {
                        LastCreatePos = mappos;

                        CTHG2 cTHG2 = new CTHG2();

                        cTHG2.FLAG = (0b1 << 7) + (0b1 << 9);
                        if (mapeditor.sprite_SpritBrush)
                        {
                            cTHG2.ID    = (ushort)mapeditor.SpritePallete.SelectIndex;
                            cTHG2.FLAG += (0b1 << 12);
                        }
                        else
                        {
                            int unitID = mapeditor.SpritePallete_Unit.SelectIndex;
                            cTHG2.ID    = (ushort)unitID;
                            cTHG2.FLAG += (0b1 << 13);
                        }
                        cTHG2.PLAYER = (byte)mapeditor.sprite_player;
                        cTHG2.X      = (ushort)mappos.X;
                        cTHG2.Y      = (ushort)mappos.Y;


                        mapeditor.mapdata.THG2.Add(cTHG2);
                        cTHG2.ImageReset();

                        mapeditor.taskManager.TaskAdd(new SpriteEvent(mapeditor, cTHG2, true));
                    }
                }
            }
        }