// ------------------------------------------------------------------- // AddSprite // ------------------------------------------------------------------- public void AddSprite(int[] coords, SystemEvent ev) { if (!Sprites.ContainsKey(ev.Pages[0].Graphic)) { Sprites[ev.Pages[0].Graphic] = new Dictionary <int[], Sprites>(new IntArrayComparer()); } if (ev.Pages[0].Graphic.IsTileset()) { int[] texture = new int[] { (int)ev.Pages[0].Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetX], (int)ev.Pages[0].Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetY], (int)ev.Pages[0].Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetWidth], (int)ev.Pages[0].Graphic.Options[(int)SystemGraphic.OptionsEnum.TilesetHeight] }; if (!Sprites[ev.Pages[0].Graphic].ContainsKey(texture)) { Sprites[ev.Pages[0].Graphic][texture] = new Sprites(); } Sprites[ev.Pages[0].Graphic][texture].Add(coords, new Sprite(ev.Pages[0].GraphicDrawType, new int[] { 0, 0 }, 0)); } else { int frames = (int)ev.Pages[0].Graphic.Options[(int)SystemGraphic.OptionsEnum.Frames]; int index = (int)ev.Pages[0].Graphic.Options[(int)SystemGraphic.OptionsEnum.Index]; MapEditor.LoadSystemGraphic(ev.Pages[0].Graphic, WANOK.MapEditor.GraphicsDevice); int width = MapEditor.TexCharacters[ev.Pages[0].Graphic].Width / frames; int height = MapEditor.TexCharacters[ev.Pages[0].Graphic].Height / ((int)ev.Pages[0].Graphic.Options[(int)SystemGraphic.OptionsEnum.Diagonal] == 0 ? 4 : 8); int[] texture = new int[] { (index % frames) * width, (index / frames) * height, width, height }; if (!Sprites[ev.Pages[0].Graphic].ContainsKey(texture)) { Sprites[ev.Pages[0].Graphic][texture] = new Sprites(); } Sprites[ev.Pages[0].Graphic][texture].Add(coords, new Sprite(ev.Pages[0].GraphicDrawType, new int[] { 0, 0 }, 0)); } }
// ------------------------------------------------------------------- // LoadEventSpriteTexture // ------------------------------------------------------------------- public void LoadSpriteTexture(SystemGraphic graphic) { if (!graphic.IsTileset()) { MapEditor.LoadSystemGraphic(graphic, Device); } }
// ------------------------------------------------------------------- // AddMountain // ------------------------------------------------------------------- public bool AddMountain(int[] coords, int newId, Mountain newMountain) { bool modified = false; int height = WANOK.GetCoordsPixelHeight(coords); object[] before = ContainsMountain(height, coords); // Remplacing if (before == null) { modified = true; } else { int beforeId = (int)before[0]; Mountain beforeMountain = (Mountain)before[1]; if (beforeId != newId) { modified = true; } Mountains[height].Remove(coords, beforeId, height); } if (!Mountains.ContainsKey(height)) { Mountains[height] = new Mountains(); } Mountains[height].Add(coords, newId, newMountain, height); SystemTileset tileset = MapEditor.GetMapTileset(); object[] reliefTop = tileset.ReliefTop[tileset.Reliefs.IndexOf(newId)]; switch ((DrawType)reliefTop[0]) { case DrawType.Floors: AddFloor(new int[] { coords[0], coords[1] + newMountain.SquareHeight, coords[2] + newMountain.PixelHeight, coords[3] }, (int[])reliefTop[1]); break; case DrawType.Autotiles: int id = ((int[])reliefTop[1])[0]; if (id > 0) { AddAutotile(new int[] { coords[0], coords[1] + newMountain.SquareHeight, coords[2] + newMountain.PixelHeight, coords[3] }, id, true); } break; } return(modified); }
// ------------------------------------------------------------------- // UpdatePage // ------------------------------------------------------------------- public void UpdatePage(int i) { conditionsPanel1.InitializeListParameters(Control.Model.Pages[i].ConditionsTree.Tree); graphicControl1.InitializeListParameters(Control.Model.Pages[i].Graphic, MapEditor.GetMapTileset().Graphic); graphicControl1.GetComboBox().SelectedIndex = (int)Control.Model.Pages[i].GraphicDrawType; foreach (EventTrigger trigger in Enum.GetValues(typeof(EventTrigger))) { RadiosTrigger[trigger].Checked = false; } RadiosTrigger[Control.Model.Pages[i].Trigger].Checked = true; CommandsView.Nodes.Clear(); AddCommandNodes(Control.Model.Pages[i].CommandsTree, CommandsView.Nodes); // Move page tabControl1.TabPages[i].Controls.Clear(); tabControl1.TabPages[i].Controls.Add(panel1); panel1.Controls.Clear(); panel1.Controls.Add(tableLayoutMainPage); }
// ------------------------------------------------------------------- // Constructor // ------------------------------------------------------------------- public Map(GraphicsDevice device, string mapName) { Device = device; Stopwatch sw = new Stopwatch(); bool dialogOpened = false, newTemp = false; sw.Start(); // Temp files + mapInfos string pathTemp = Path.Combine(WANOK.MapsDirectoryPath, mapName, "temp"); if (Directory.GetFiles(pathTemp).Length == 0) { newTemp = true; string[] filePaths = Directory.GetFiles(Path.Combine(WANOK.MapsDirectoryPath, mapName)); foreach (string filePath in filePaths) { File.Copy(filePath, Path.Combine(pathTemp, Path.GetFileName(filePath))); } } MapInfos = WANOK.LoadBinaryDatas <MapInfos>(Path.Combine(WANOK.MapsDirectoryPath, mapName, "temp", "infos.map")); Events = WANOK.LoadBinaryDatas <Events>(Path.Combine(WANOK.MapsDirectoryPath, mapName, "temp", "events.map")); Saved = !WANOK.ListMapToSave.Contains(mapName); if (newTemp) { WANOK.CreateCancelMap(MapInfos.RealMapName); } // Start position if (mapName == WANOK.Game.System.StartMapName) { SetStartInfos(WANOK.Game.System, WANOK.Game.System.StartPosition); } // Event position EventSquare = new Square(Device, MapEditor.TexEventSelectCursor, new int[] { 0, 0, WANOK.BASIC_SQUARE_SIZE, WANOK.BASIC_SQUARE_SIZE }); // Dispose textures if (MapEditor.TexTileset != null) { MapEditor.TexTileset.Dispose(); MapEditor.TexTileset = null; } foreach (int i in MapEditor.TexAutotiles.Keys) { MapEditor.TexAutotiles[i].Dispose(); } MapEditor.TexAutotiles.Clear(); foreach (int i in MapEditor.TexReliefs.Keys) { MapEditor.TexReliefs[i].Dispose(); } MapEditor.TexReliefs.Clear(); foreach (Texture2D texture in MapEditor.TexCharacters.Values) { texture.Dispose(); } MapEditor.TexCharacters.Clear(); // Loading textures SystemTileset tileset = WANOK.Game.Tilesets.GetTilesetById(MapInfos.Tileset); MapEditor.TexTileset = tileset.Graphic.LoadTexture(device); for (int i = 0; i < tileset.Autotiles.Count; i++) { MapEditor.TexAutotiles[tileset.Autotiles[i]] = MapEditor.GetCharacterTexture(device, WANOK.Game.Tilesets.GetAutotileById(tileset.Autotiles[i]).Graphic.LoadTexture(Device)); } for (int i = 0; i < tileset.Reliefs.Count; i++) { MapEditor.TexReliefs[tileset.Reliefs[i]] = WANOK.Game.Tilesets.GetReliefById(tileset.Reliefs[i]).Graphic.LoadTexture(Device); } LoadEventTextures(); // Grid CreateGrid(MapInfos.Width, MapInfos.Height); // Map Portions = new Dictionary <int[], GameMapPortion>(new IntArrayComparer()); EventsPortions = new Dictionary <int[], EventsPortion>(new IntArrayComparer()); int count = 0; double coef = (WANOK.PORTION_RADIUS + 1) * (WANOK.PORTION_RADIUS + 1) * 4; for (int i = -WANOK.PORTION_RADIUS - 1; i <= WANOK.PORTION_RADIUS + 1; i++) { for (int j = -WANOK.PORTION_RADIUS - 1; j <= WANOK.PORTION_RADIUS + 1; j++) { if (!dialogOpened) { if (sw.ElapsedMilliseconds > 50) { WANOK.StartProgressBar("Loading map infos...", 0); dialogOpened = true; } } else { int v = (int)((count / coef) * 100); if (v <= 100) { WANOK.DialogProgressBar.SetValue(v); } } LoadPortion(i, j, i, j); count++; } } sw.Stop(); if (dialogOpened) { WANOK.DisposeProgressBar(); } }