protected void ListMenuItemsSelected(List <string> Items) { if (Items == null) { return; } for (int I = 0; I < Items.Count; I++) { switch (ItemSelectionChoice) { case ItemSelectionChoices.Map: string MapLogicName = Items[0].Substring(0, Items[0].Length - 4).Substring(24); BattleMapViewer.Preload(); DeathmatchMap NewMap = new DeathmatchMap(MapLogicName, string.Empty, new Dictionary <string, List <Core.Units.Squad> >()); Helper = new DeathmatchMapHelper(NewMap); NewMap.ListGameScreen = new List <GameScreen>(); NewMap.Content = BattleMapViewer.content; NewMap.Load(); NewMap.TogglePreview(false); NewMap.CursorPositionVisible = new Vector3(-1, -1, 0); BattleMapViewer.SetListMapScript(NewMap.ListMapScript); BattleMapViewer.Helper.OnSelect = (SelectedObject, RightClick) => { if (RightClick && SelectedObject != null) { BattleMapViewer.cmsScriptMenu.Show(BattleMapViewer, PointToClient(Cursor.Position)); } }; for (int S = NewMap.ListMapScript.Count - 1; S >= 0; --S) { BattleMapViewer.Helper.InitScript(NewMap.ListMapScript[S]); } for (int T = 0; T < TerrainAttribute.ListTerrainChangeLocation.Count; T++) { Vector3 NewDestinationPoint = TerrainAttribute.ListTerrainChangeLocation[T].Position; NewMap.LayerManager[0].ListSingleplayerSpawns.Add(new EventPoint(NewDestinationPoint, T.ToString(), 255, 255, 255)); } Matrix Projection = Matrix.CreateOrthographicOffCenter(0, BattleMapViewer.Width, BattleMapViewer.Height, 0, 0, -1f); Matrix HalfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0); Matrix projectionMatrix = HalfPixelOffset * Projection; NewMap.fxOutline.Parameters["Projection"].SetValue(projectionMatrix); #region Tiles for (int T = 0; T < TerrainAttribute.ListTileset.Count; ++T) { bool AlreadyExist = false; for (int P = 0; P < NewMap.ListTilesetPreset.Count; ++P) { if (TerrainAttribute.ListTileset[T] == NewMap.ListTilesetPreset[P].TilesetName) { AlreadyExist = true; break; } } if (!AlreadyExist) { Texture2D sprTileset = NewMap.Content.Load <Texture2D>("Maps/Tilesets/" + TerrainAttribute.ListTileset[T]); if (!NewMap.ListTileSet.Contains(sprTileset)) { NewMap.ListTilesetPreset.Add(new Terrain.TilesetPreset(TerrainAttribute.ListTileset[T], sprTileset.Width, sprTileset.Height, NewMap.TileSize.X, NewMap.TileSize.Y, NewMap.ListTilesetPreset.Count)); NewMap.ListTileSet.Add(sprTileset); } } } for (int T = 0; T < NewMap.ListTilesetPreset.Count; T++) { if (!TerrainAttribute.ListTileset.Contains(NewMap.ListTilesetPreset[T].TilesetName)) { TerrainAttribute.ListTileset.Add(NewMap.ListTilesetPreset[T].TilesetName); } ItemInfo Item = BaseEditor.GetItemByKey(BaseEditor.GUIRootPathMapTilesetImages, NewMap.ListTilesetPreset[T].TilesetName); if (Item.Path != null) { if (Item.Name.StartsWith("Tileset presets")) { cboTiles.Items.Add(Item.Name); } else { cboTiles.Items.Add(Item.Name); } } else { MessageBox.Show(NewMap.ListTilesetPreset[T].TilesetName + " not found, loading default tileset instead."); cboTiles.Items.Add("Default"); } } #endregion for (int T = 0; T < TerrainAttribute.ListTerrainChangeLocation.Count; T++) { Terrain ActiveTerrain = TerrainAttribute.ListTerrainChangeLocation[T]; int PosX = (int)ActiveTerrain.Position.X; int PosY = (int)ActiveTerrain.Position.Y; DrawableTile ActiveTile = TerrainAttribute.ListTileChangeLocation[T]; Helper.ReplaceTerrain(PosX, PosY, ActiveTerrain, 0); Helper.ReplaceTile(PosX, PosY, ActiveTile, 0); } BattleMapViewer.ActiveMap = NewMap; BattleMapViewer.RefreshScrollbars(); if (NewMap.ListTilesetPreset.Count > 0) { cboTiles.SelectedIndex = 0; } if (cboTiles.SelectedIndex >= 0) { TilesetViewer.InitTileset(NewMap.ListTileSet[cboTiles.SelectedIndex], NewMap.TileSize); } else { TilesetViewer.InitTileset(string.Empty, NewMap.TileSize); } TileAttributesEditor = Helper.GetTileEditor(); break; case ItemSelectionChoices.Tile: string TilePath = Items[I]; if (TilePath != null) { if (TilePath.StartsWith("Content/Maps/Tileset Presets")) { string Name = TilePath.Substring(0, TilePath.Length - 4).Substring(29); Terrain.TilesetPreset NewTileset = Terrain.TilesetPreset.FromFile(Name, BattleMapViewer.ActiveMap.ListTilesetPreset.Count); string Output = BaseEditor.GetItemPathInRoot(BaseEditor.GUIRootPathMapTilesets, NewTileset.TilesetName); BattleMapViewer.ActiveMap.ListTilesetPreset.Add(NewTileset); BattleMapViewer.ActiveMap.ListTileSet.Add(TilesetViewer.content.Load <Microsoft.Xna.Framework.Graphics.Texture2D>("Maps/Tilesets/" + NewTileset.TilesetName)); cboTiles.Items.Add(Name); TerrainAttribute.ListTileset.Add(Name); } else { string Name = TilePath.Substring(0, TilePath.Length - 4).Substring(22); if (cboTiles.Items.Contains(Name)) { MessageBox.Show("This tile is already listed.\r\n" + Name); return; } Microsoft.Xna.Framework.Graphics.Texture2D Tile = TilesetViewer.content.Load <Microsoft.Xna.Framework.Graphics.Texture2D>("Maps/Tilesets/" + Name); BattleMapViewer.ActiveMap.ListTilesetPreset.Add(new Terrain.TilesetPreset(Name, Tile.Width, Tile.Height, BattleMapViewer.ActiveMap.TileSize.X, BattleMapViewer.ActiveMap.TileSize.Y, BattleMapViewer.ActiveMap.ListTilesetPreset.Count)); BattleMapViewer.ActiveMap.ListTileSet.Add(Tile); //Add the file name to the tile combo box. cboTiles.Items.Add(Name); TerrainAttribute.ListTileset.Add(Name); } cboTiles.SelectedIndex = BattleMapViewer.ActiveMap.ListTilesetPreset.Count - 1; if (BattleMapViewer.ActiveMap.ListTileSet.Count == 1) { Terrain PresetTerrain = ActiveMap.ListTilesetPreset[0].ArrayTerrain[0, 0]; DrawableTile PresetTile = ActiveMap.ListTilesetPreset[0].ArrayTiles[0, 0]; //Asign a new tile at the every position, based on its atribtues. for (int X = BattleMapViewer.ActiveMap.MapSize.X - 1; X >= 0; --X) { for (int Y = BattleMapViewer.ActiveMap.MapSize.Y - 1; Y >= 0; --Y) { Helper.ReplaceTerrain(X, Y, new Terrain(PresetTerrain), 0); Helper.ReplaceTile(X, Y, new DrawableTile(PresetTile), 0); } } } } break; case ItemSelectionChoices.TileAsBackground: string TileAsBackgroundPath = Items[I]; if (TileAsBackgroundPath != null) { string TileName = Path.GetFileNameWithoutExtension(TileAsBackgroundPath); if (cboTiles.Items.Contains(TileName)) { MessageBox.Show("This tile is already listed.\r\n" + TileName); return; } BattleMapViewer.ActiveMap.ListTileSet.Add(TilesetViewer.content.Load <Texture2D>("Maps/Tilesets/" + TileName)); //Add the file name to the tile combo box. cboTiles.Items.Add(TileName); TerrainAttribute.ListTileset.Add(TileName); cboTiles.SelectedIndex = BattleMapViewer.ActiveMap.ListTileSet.Count - 1; //Asign a new tile at the every position, based on its atribtues. for (int X = BattleMapViewer.ActiveMap.MapSize.X - 1; X >= 0; --X) { for (int Y = BattleMapViewer.ActiveMap.MapSize.Y - 1; Y >= 0; --Y) { Helper.ReplaceTerrain(X, Y, new Terrain(X, Y, 0, 0, 1, new TerrainActivation[0], new TerrainBonus[0], new int[0]), 0); Helper.ReplaceTile(X, Y, new DrawableTile( new Rectangle((X % (ActiveMap.ListTilesetPreset.Last().ArrayTerrain.GetLength(0))) * ActiveMap.TileSize.X, (Y % (ActiveMap.ListTilesetPreset.Last().ArrayTerrain.GetLength(1))) * ActiveMap.TileSize.Y, ActiveMap.TileSize.X, ActiveMap.TileSize.Y), cboTiles.Items.Count - 1), 0); } } } break; } } }
private void cboTiles_SelectedIndexChanged(object sender, EventArgs e) { TilesetViewer.InitTileset(BattleMapViewer.ActiveMap.ListTileSet[cboTiles.SelectedIndex], BattleMapViewer.ActiveMap.TileSize); }