// -------------------------------------------------------------------
        // DeleteMapEvents
        // -------------------------------------------------------------------

        public void DeleteMapEvents(Events events, int i, int j)
        {
            int[] portion = new int[] { i, j };
            if (events.CompleteList.ContainsKey(portion))
            {
                Dictionary <int[], SystemEvent> dictionary = events.CompleteList[portion];

                if (dictionary.Count > 0)
                {
                    WANOK.AddPortionsToAddCancel(Model.RealMapName, portion, 1);

                    List <int[]> coordsEvents = new List <int[]>();
                    foreach (int[] coords in dictionary.Keys)
                    {
                        if (coords[0] >= Width || coords[3] >= Height)
                        {
                            coordsEvents.Add(coords);
                        }
                    }
                    for (int k = 0; k < coordsEvents.Count; k++)
                    {
                        dictionary.Remove(coordsEvents[k]);
                    }
                    if (dictionary.Count == 0)
                    {
                        events.CompleteList.Remove(portion);
                    }
                }
            }
        }
        // -------------------------------------------------------------------
        // DeleteMapComplete
        // -------------------------------------------------------------------

        public void DeleteMapComplete(Events events, int i, int j)
        {
            string path = Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp", i + "-" + j + ".pmap");

            int[] portion = new int[] { i, j };
            if (File.Exists(path))
            {
                WANOK.AddPortionsToAddCancel(Model.RealMapName, portion, 0);
                File.Delete(path);
            }
            if (events.CompleteList.ContainsKey(portion))
            {
                WANOK.AddPortionsToAddCancel(Model.RealMapName, portion, 1);
                events.CompleteList.Remove(portion);
            }
        }
        // -------------------------------------------------------------------
        // CreateMap
        // -------------------------------------------------------------------

        public void CreateMap()
        {
            if (!Directory.Exists(Path.Combine(WANOK.MapsDirectoryPath, RealMapName)))
            {
                Directory.CreateDirectory(Path.Combine(WANOK.MapsDirectoryPath, RealMapName));
                Directory.CreateDirectory(Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp"));
                Directory.CreateDirectory(Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "tempCancelRedo"));
                WANOK.SaveBinaryDatas(Model, Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "infos.map"));
                WANOK.SaveBinaryDatas(new Events(), Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "events.map"));
            }
            else
            {
                WANOK.CreateCancel(Model.RealMapName, true);
                ResizingMap();
                WANOK.AddPortionsToAddCancel(Model.RealMapName, new int[] { 0 }, 2);
                WANOK.SaveBinaryDatas(Model, Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp", "infos.map"));
                WANOK.LoadCancel(Model.RealMapName);
            }
        }
        // -------------------------------------------------------------------
        // ResizingMap 120 120 75 20
        // -------------------------------------------------------------------

        public void ResizingMap()
        {
            int difWidth = PreviousWidth - Width, difHeight = PreviousHeight - Height;

            if (difWidth > 0 || difHeight > 0)
            {
                Events events = WANOK.LoadEvents(RealMapName);
                int    portionMaxX = (PreviousWidth - 1) / 16, portionMaxY = (PreviousHeight - 1) / 16;
                int    newPortionMaxX = (Width - 1) / 16, newPortionMaxY = (Height - 1) / 16;

                for (int i = newPortionMaxX + 1; i <= portionMaxX; i++)
                {
                    for (int j = 0; j <= portionMaxY; j++)
                    {
                        DeleteMapComplete(events, i, j);
                    }
                }
                for (int j = newPortionMaxY + 1; j <= portionMaxY; j++)
                {
                    for (int i = 0; i <= portionMaxX; i++)
                    {
                        DeleteMapComplete(events, i, j);
                    }
                }

                for (int i = 0; i <= newPortionMaxX; i++)
                {
                    DeleteMapItems(i, newPortionMaxY);
                    DeleteMapEvents(events, i, newPortionMaxY);
                }
                for (int j = 0; j <= newPortionMaxY; j++)
                {
                    DeleteMapItems(newPortionMaxX, j);
                    DeleteMapEvents(events, newPortionMaxX, j);
                }

                WANOK.SaveEventsMap(events, RealMapName);
                WANOK.LoadCancel(Model.RealMapName);
            }
        }
Exemplo n.º 5
0
        // -------------------------------------------------------------------
        // Checks
        // -------------------------------------------------------------------

        public void CheckSelection(int index)
        {
            WANOK.CheckControls(SelectionItems, index);
        }
        // -------------------------------------------------------------------
        // Constructors
        // -------------------------------------------------------------------

        public DialogNewMapControl()
        {
            Model = new MapInfos(WANOK.GenerateMapName(), DEFAULT_SIZE, DEFAULT_SIZE);
        }
        // -------------------------------------------------------------------
        // DeleteMapItems
        // -------------------------------------------------------------------

        public void DeleteMapItems(int i, int j)
        {
            string path = Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp", i + "-" + j + ".pmap");

            if (File.Exists(path))
            {
                GameMapPortion gamePortion = WANOK.LoadBinaryDatas <GameMapPortion>(path);
                WANOK.AddPortionsToAddCancel(Model.RealMapName, new int[] { i, j }, 0);


                // Floors
                List <int[]> coordsFloors = new List <int[]>();
                foreach (int[] coords in gamePortion.Floors.Keys)
                {
                    if (coords[0] >= Width || coords[3] >= Height)
                    {
                        coordsFloors.Add(coords);
                    }
                }
                for (int k = 0; k < coordsFloors.Count; k++)
                {
                    gamePortion.Floors.Remove(coordsFloors[k]);
                }

                // Autotiles
                Dictionary <int, List <int[]> > coordsAutotiles = new Dictionary <int, List <int[]> >();
                foreach (KeyValuePair <int, Autotiles> entry in gamePortion.Autotiles)
                {
                    coordsAutotiles[entry.Key] = new List <int[]>();
                    foreach (int[] coords in entry.Value.Tiles.Keys)
                    {
                        if (coords[0] >= Width || coords[3] >= Height)
                        {
                            coordsAutotiles[entry.Key].Add(coords);
                        }
                    }
                }
                foreach (int id in coordsAutotiles.Keys)
                {
                    for (int k = 0; k < coordsAutotiles[id].Count; k++)
                    {
                        gamePortion.Autotiles[id].Tiles.Remove(coordsAutotiles[id][k]);
                    }
                    if (gamePortion.Autotiles[id].IsEmpty())
                    {
                        gamePortion.Autotiles.Remove(id);
                    }
                }

                // Sprites
                Dictionary <int[], List <int[]> > coordsSprites = new Dictionary <int[], List <int[]> >(new IntArrayComparer());
                foreach (KeyValuePair <int[], Sprites> entry in gamePortion.Sprites)
                {
                    coordsSprites[entry.Key] = new List <int[]>();
                    foreach (int[] coords in entry.Value.ListSprites.Keys)
                    {
                        if (coords[0] >= Width || coords[3] >= Height)
                        {
                            coordsSprites[entry.Key].Add(coords);
                        }
                    }
                }
                foreach (int[] texture in coordsSprites.Keys)
                {
                    for (int k = 0; k < coordsSprites[texture].Count; k++)
                    {
                        gamePortion.Sprites[texture].ListSprites.Remove(coordsSprites[texture][k]);
                    }
                    if (gamePortion.Sprites[texture].IsEmpty())
                    {
                        gamePortion.Sprites.Remove(texture);
                    }
                }

                // Mountains
                Dictionary <int, Dictionary <int, List <int[]> > > coordsMountains = new Dictionary <int, Dictionary <int, List <int[]> > >();
                foreach (KeyValuePair <int, Mountains> entry in gamePortion.Mountains)
                {
                    coordsMountains[entry.Key] = new Dictionary <int, List <int[]> >();
                    foreach (KeyValuePair <int, MountainsGroup> entry2 in entry.Value.Groups)
                    {
                        coordsMountains[entry.Key][entry2.Key] = new List <int[]>();
                        foreach (int[] coords in entry2.Value.Tiles.Keys)
                        {
                            if (coords[0] >= Width || coords[3] >= Height)
                            {
                                coordsMountains[entry.Key][entry2.Key].Add(coords);
                            }
                        }
                    }
                }
                foreach (int height in coordsMountains.Keys)
                {
                    foreach (int id in coordsMountains[height].Keys)
                    {
                        for (int k = 0; k < coordsMountains[height][id].Count; k++)
                        {
                            gamePortion.Mountains[height].Groups[id].Tiles.Remove(coordsMountains[height][id][k]);
                        }
                        if (gamePortion.Mountains[height].Groups[id].Tiles.Count == 0)
                        {
                            gamePortion.Mountains[height].Groups.Remove(id);
                        }
                    }
                    if (gamePortion.Mountains[height].IsEmpty())
                    {
                        gamePortion.Mountains.Remove(height);
                    }
                }


                // Saving
                if (gamePortion.IsEmpty())
                {
                    File.Delete(path);
                }
                else
                {
                    WANOK.SaveBinaryDatas(gamePortion, path);
                }
            }
        }
Exemplo n.º 8
0
 private void Button_Click(object sender, EventArgs e)
 {
     WANOK.ShowActionMessage();
 }
        // -------------------------------------------------------------------
        // CreateProject
        // -------------------------------------------------------------------

        public string CreateProject()
        {
            if (Directory.Exists(DirPath))
            {
                if (ProjectName.Contains("/") || ProjectName.Contains("\\") || ProjectName.Contains(":") || ProjectName.Contains("*") || ProjectName.Contains("?") || ProjectName.Contains("<") || ProjectName.Contains(">") || ProjectName.Contains("\"") || ProjectName.Contains("|") || ProjectName.Trim().Equals("") || ProjectName.Replace('.', ' ').Trim().Equals("") || ProjectName.Contains("..") || ProjectName.Trim()[ProjectName.Trim().Length - 1] == '.')
                {
                    return("Could not create a directory with that name.Do not use / \\ : ? * | < > \". You can't name with an empty field, or \".\" or \"..\" field.");
                }
                else
                {
                    string fullPath = Path.Combine(DirPath, ProjectName);
                    if (!Directory.Exists(fullPath))
                    {
                        try
                        {
                            Directory.CreateDirectory(fullPath);
                            try
                            {
                                string executablePath = Path.GetDirectoryName(WANOK.ExcecutablePath);
                                string basicPath      = Path.Combine(executablePath, "Basic");
                                WANOK.CopyAll(new DirectoryInfo(basicPath), new DirectoryInfo(fullPath));
                                WANOK.SaveBinaryDatas(new SystemDatas(ProjectName), Path.Combine(fullPath, "Content", "Datas", "System.rpmd"));
                                WANOK.SaveBinaryDatas(new BattleSystemDatas(), Path.Combine(fullPath, "Content", "Datas", "BattleSystem.rpmd"));
                                WANOK.SaveBinaryDatas(new TilesetsDatas(), Path.Combine(fullPath, "Content", "Datas", "Tilesets.rpmd"));
                                WANOK.SaveBinaryDatas(new HeroesDatas(), Path.Combine(fullPath, "Content", "Datas", "Heroes.rpmd"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "Textures2D"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "Textures2D", "Characters"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "Textures2D", "Tilesets"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "Textures2D", "Autotiles"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "Textures2D", "Reliefs"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "UI", "Others"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "UI", "Icons"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Pictures", "UI", "Bars"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Datas", "Maps", "MAP0001"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Datas", "Maps", "MAP0001", "temp"));
                                Directory.CreateDirectory(Path.Combine(fullPath, "Content", "Datas", "Maps", "MAP0001", "tempCancelRedo"));
                                WANOK.SaveBinaryDatas(new MapInfos(), Path.Combine(fullPath, "Content", "Datas", "Maps", "MAP0001", "infos.map"));
                                WANOK.SaveBinaryDatas(new Events(), Path.Combine(fullPath, "Content", "Datas", "Maps", "MAP0001", "events.map"));
                                ProjectName = ProjectName.Trim();
                                DirPath     = Path.Combine(DirPath, ProjectName);

                                return(null);
                            }
                            catch
                            {
                                return("Could not generate the project. See if you have \"Basic\" folder in the main folder.");
                            }
                        }
                        catch
                        {
                            return("Could not create the directory. Report it to the dev.");
                        }
                    }
                    else
                    {
                        return("This project already exist in this folder. Please change your project name or your folder.");
                    }
                }
            }
            else
            {
                return("The directory path is incorrect.");
            }
        }