Пример #1
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;
            }
        }
Пример #2
0
        private void DoodadPalleteDraw()
        {
            if (mapeditor.mapDataBinding.DOODAD_SELECTMODE)
            {
                return;
            }

            if (mouse_LeftDown)
            {
                if (mapeditor.doodad_PasteMode)
                {
                    int gridsize = 32;

                    Vector2 mappos = MouseMapPos;

                    //생성모드
                    if ((LastCreatePos - mappos).Length() >= Math.Max(gridsize, 4))
                    {
                        LastCreatePos = mappos;

                        for (int i = 0; i < mapeditor.CopyedDoodad.Count; i++)
                        {
                            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];
                            DoodadPallet pallete  = t[(ushort)doodadid];


                            CDD2 _cDD2 = mapeditor.CopyedDoodad[i];

                            //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;



                            if (DoodadCollsionCheck(mappos, pallete))
                            {
                                LastCreatePos = mappos;

                                CDD2 cDD2 = new CDD2(mapeditor.mapdata);
                                cDD2.X      = (ushort)mappos.X;
                                cDD2.Y      = (ushort)mappos.Y;
                                cDD2.ID     = (ushort)doodadid;
                                cDD2.PLAYER = (byte)_cDD2.PLAYER;

                                mapeditor.mapdata.DD2.Add(cDD2);
                                cDD2.ImageReset();

                                mapeditor.mapdata.DD2ToMTXM(cDD2);
                                mapeditor.taskManager.TaskAdd(new DoodadEvent(mapeditor, cDD2, true));
                            }
                        }
                    }
                }
                else
                {
                    int gridsize = 32;
                    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;
                    }


                    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);


                    //생성모드
                    if ((LastCreatePos - mappos).Length() >= Math.Max(gridsize, 4))
                    {
                        if (DoodadCollsionCheck(mappos, pallete))
                        {
                            LastCreatePos = mappos;

                            CDD2 cDD2 = new CDD2(mapeditor.mapdata);
                            cDD2.X      = (ushort)mappos.X;
                            cDD2.Y      = (ushort)mappos.Y;
                            cDD2.ID     = (ushort)doodadid;
                            cDD2.PLAYER = (byte)playerid;

                            mapeditor.mapdata.DD2.Add(cDD2);
                            cDD2.ImageReset();

                            mapeditor.mapdata.DD2ToMTXM(cDD2);
                            mapeditor.taskManager.TaskAdd(new DoodadEvent(mapeditor, cDD2, true));
                        }
                    }
                }
            }
        }
Пример #3
0
        private void DrawDooDad(CDD2 cDD2, List <CImage> templist = null, bool IsPallete = false)
        {
            var t = tileSet.DoodadPallets[mapeditor.mapdata.TILETYPE];

            if (!t.ContainsKey(cDD2.ID))
            {
                return;
            }

            DoodadPallet pallete = t[cDD2.ID];

            ushort X;
            ushort Y;

            if (IsPallete)
            {
                X = cDD2.PalleteX;
                Y = cDD2.PalleteY;
            }
            else
            {
                X = cDD2.X;
                Y = cDD2.Y;
            }



            bool IsSelect = false;
            bool IsHover  = false;

            if (mapeditor.PalleteLayer == Control.MapEditor.Layer.Doodad)
            {
                if (mapeditor.mapDataBinding.DOODAD_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) & (min.Y - 8 < Y & Y < max.Y + 8)))
                        {
                            hoverDoodad.Add(cDD2);
                        }
                    }
                    if (mapeditor.SelectDoodad.Contains(cDD2))
                    {
                        IsSelect = true;
                    }
                    else if (hoverDoodad.Contains(cDD2))
                    {
                        IsHover = true;
                    }
                }
            }


            int _x = X / 32 * 32 - (pallete.dddWidth / 2) * 32;
            int _y = Y / 32 * 32 - (pallete.dddHeight / 2) * 32;


            Vector2 screen       = mapeditor.PosMapToScreen(new Vector2(_x, _y));
            Vector2 spritescreen = mapeditor.PosMapToScreen(new Vector2(X, Y));



            int grpwidth  = (int)(pallete.dddWidth * 32 * mapeditor.opt_scalepercent);
            int grpheight = (int)(pallete.dddHeight * 32 * mapeditor.opt_scalepercent);


            float mag = (float)(32 * mapeditor.opt_scalepercent);


            float minX = 0 - grpwidth;
            float minY = 0 - grpheight;
            float maxX = screenwidth + grpwidth * 2;
            float maxY = screenheight + grpheight * 2;

            if ((minX < screen.X) & (screen.X < maxX))
            {
                if ((minY < screen.Y) & (screen.Y < maxY))
                {
                    if (cDD2.Images.Count == 0)
                    {
                        cDD2.ImageReset();
                    }
                    for (int i = 0; i < cDD2.Images.Count; i++)
                    {
                        cDD2.Images[i].screen = spritescreen;

                        if (templist != null)
                        {
                            templist.Add(cDD2.Images[i]);
                        }
                        else
                        {
                            ImageList.Add(cDD2.Images[i]);
                        }
                        cDD2.Images[i].PlayScript();
                    }
                    for (int y = 0; y < pallete.dddHeight; y++)
                    {
                        for (int x = 0; x < pallete.dddWidth; x++)
                        {
                            ushort group = (ushort)(pallete.dddGroup + y);
                            ushort index = (ushort)x;


                            if (tileSet.IsBlack(mapeditor.mapdata.TILETYPE, group, index))
                            {
                                continue;
                            }
                            Color color = Color.White;
                            if (mapeditor.view_DoodadColor)
                            {
                                color = mapeditor.DoodadOverlay;
                            }
                            Vector2 StartPoint = screen + new Vector2(x, y) * mag;

                            switch (mapeditor.opt_drawType)
                            {
                            case Control.MapEditor.DrawType.SD:
                            {
                                Texture2D texture2D = tileSet.GetTile(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, group, index);
                                _spriteBatch.Draw(texture2D, StartPoint, null, color, 0, Vector2.Zero, (float)mapeditor.opt_scalepercent, SpriteEffects.None, 0);
                            }
                            break;

                            case Control.MapEditor.DrawType.HD:
                            case Control.MapEditor.DrawType.CB:
                            {
                                Texture2D texture2D = tileSet.GetTile(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, group, index);
                                _spriteBatch.Draw(texture2D, StartPoint, null, color, 0, Vector2.Zero, (float)mapeditor.opt_scalepercent / 2, SpriteEffects.None, 0);
                            }
                            break;
                            }

                            if (IsSelect)
                            {
                                _spriteBatch.Draw(gridtexture, StartPoint, null, new Color(128, 255, 128, 128), 0, Vector2.Zero, (float)mapeditor.opt_scalepercent * 32, SpriteEffects.None, 0);
                                DrawRect(_spriteBatch, StartPoint, StartPoint + new Vector2((float)(mapeditor.opt_scalepercent * 32)), Color.Yellow, 3);
                            }
                            if (IsHover)
                            {
                                _spriteBatch.Draw(gridtexture, StartPoint, null, new Color(128, 128, 255, 128), 0, Vector2.Zero, (float)mapeditor.opt_scalepercent * 32, SpriteEffects.None, 0);
                                DrawRect(_spriteBatch, StartPoint, StartPoint + new Vector2((float)(mapeditor.opt_scalepercent * 32)), Color.Yellow, 3);
                            }


                            if (IsPallete)
                            {
                                DrawRect(_spriteBatch, StartPoint, StartPoint + new Vector2((float)(mapeditor.opt_scalepercent * 32)), Color.Lime, 3);
                            }
                        }
                    }


                    if (IsPallete)
                    {
                        Vector2      pos = new Vector2(cDD2.PalleteX, cDD2.PalleteY);
                        DoodadPallet paldoodad;

                        paldoodad = tileSet.DoodadPallets[mapeditor.mapdata.TILETYPE][cDD2.ID];



                        int x = (ushort)pos.X / 32 * 32 - (paldoodad.dddWidth / 2) * 32;
                        int y = (ushort)pos.Y / 32 * 32 - (paldoodad.dddHeight / 2) * 32;

                        Rect rect = new Rect(new Point(x, y), new Point(x + paldoodad.dddWidth * 32, y + paldoodad.dddHeight * 32));

                        for (int i = 0; i < mapeditor.mapdata.DD2.Count; i++)
                        {
                            CDD2 mcDD2 = mapeditor.mapdata.DD2[i];

                            DoodadPallet mapdoodad = tileSet.DoodadPallets[mapeditor.mapdata.TILETYPE][mcDD2.ID];

                            int tx = (ushort)mcDD2.X / 32 * 32 - (mapdoodad.dddWidth / 2) * 32;
                            int ty = (ushort)mcDD2.Y / 32 * 32 - (mapdoodad.dddHeight / 2) * 32;


                            Rect _rect = new Rect(new Point(tx, ty), new Point(tx + mapdoodad.dddWidth * 32, ty + mapdoodad.dddHeight * 32));

                            Rect interRect = Rect.Intersect(rect, _rect);
                            if (interRect != Rect.Empty)
                            {
                                //if (tileSet.IsBlack(mapeditor.mapdata.TILETYPE, group, index))
                                //{
                                //    continue;
                                //}
                                //충돌상황
                                //하나하나 비교시작
                                for (int iy = 0; iy < (int)(interRect.Height / 32); iy++)
                                {
                                    for (int ix = 0; ix < (int)(interRect.Width / 32); ix++)
                                    {
                                        int mx = (int)(interRect.X - tx) / 32;
                                        int my = (int)(interRect.Y - ty) / 32;
                                        int px = (int)(interRect.X - x) / 32;
                                        int py = (int)(interRect.Y - y) / 32;


                                        ushort mg = (ushort)(mapdoodad.dddGroup + my + iy);
                                        ushort mi = (ushort)(mx + ix);
                                        ushort pg = (ushort)(paldoodad.dddGroup + py + iy);
                                        ushort pi = (ushort)(px + ix);



                                        if (!tileSet.IsBlack(mapeditor.mapdata.TILETYPE, mg, mi) & !tileSet.IsBlack(mapeditor.mapdata.TILETYPE, pg, pi))
                                        {
                                            Vector2 _spos = mapeditor.PosMapToScreen(new Vector2((float)interRect.X + ix * 32, (float)interRect.Y + iy * 32));
                                            DrawRect(_spriteBatch, _spos, _spos + new Vector2((float)(mapeditor.opt_scalepercent * 32)), Color.Red, 3);
                                        }
                                    }
                                }
                            }
                        }



                        //if (DoodadCollsionCheckTile(new Vector2(_mapx + x, _mapy + y)))
                        //{
                        //    DrawRect(_spriteBatch, StartPoint, StartPoint + new Vector2((float)(mapeditor.opt_scalepercent * 32)), Color.Lime, 3);
                        //}
                        //else
                        //{
                        //    DrawRect(_spriteBatch, StartPoint, StartPoint + new Vector2((float)(mapeditor.opt_scalepercent * 32)), Color.Red, 3);
                        //}
                    }
                }
            }
        }