protected void ListMenuItemsSelected(List <string> Items)
        {
            if (Items == null)
            {
                return;
            }

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

            BattleMapViewer.ActiveMap = 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 = BattleMapViewer.ActiveMap.ListMapScript.Count - 1; S >= 0; --S)
            {
                BattleMapViewer.Helper.InitScript(BattleMapViewer.ActiveMap.ListMapScript[S]);
            }

            for (int T = 0; T < ListTerrainChangeLocation.Count; T++)
            {
                Vector2 NewDestinationPoint = ListTerrainChangeLocation[T];
                ActiveMap.LayerManager[0].ListSingleplayerSpawns.Add(new BattleMapScreen.EventPoint(new Vector3(NewDestinationPoint.X, NewDestinationPoint.Y, 0), T.ToString(), 255, 255, 255));
            }
        }
예제 #2
0
        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;
                }
            }
        }
 public void InitMap()
 {
     ActiveMap.Load();
     ActiveMap.Init();
 }
예제 #4
0
        public override void Update(GameTime gameTime)
        {
            EllapsedTime += gameTime.ElapsedGameTime.TotalSeconds;

            if (EllapsedTime >= 10)
            {
                RemoveScreen(this);
                MultiplayerScreen Autoplay = new MultiplayerScreen();
                Autoplay.Load();
                Constants.ShowAnimation = false;
                PushScreen(Autoplay.LoadAutoplay());
            }

            if (InputHelper.InputUpPressed())
            {
                EllapsedTime = 0;

                SelectedChoice--;
                sndSelection.Play();

                if (SelectedChoice == -1)
                {
                    SelectedChoice = 4;
                }
            }
            else if (InputHelper.InputDownPressed())
            {
                EllapsedTime = 0;

                SelectedChoice++;
                sndSelection.Play();

                if (SelectedChoice == 5)
                {
                    SelectedChoice = 0;
                }
            }
            else if (InputHelper.InputConfirmPressed())
            {
                switch ((MenuChoices)SelectedChoice)
                {
                case MenuChoices.NewGame:
                    sndIntroSong.Stop();
                    sndConfirm.Play();

                    int           OldNumberOfGameScreen = ListGameScreen.Count;
                    StreamReader  BR     = new StreamReader("Content/Map path.ini");
                    DeathmatchMap NewMap = new DeathmatchMap(BR.ReadLine(), string.Empty, new Dictionary <string, List <Squad> >());
                    BR.Close();
                    NewMap.ListGameScreen = ListGameScreen;
                    NewMap.PlayerRoster   = new Roster();
                    NewMap.PlayerRoster.LoadRoster();
                    NewMap.Load();
                    NewMap.Init();
                    NewMap.TogglePreview(true);

                    //Remove any GameScreen created by the map so they don't show up immediately.
                    List <GameScreen> ListGameScreenCreatedByMap = new List <GameScreen>(ListGameScreen.Count - OldNumberOfGameScreen);
                    for (int S = ListGameScreen.Count - 1 - OldNumberOfGameScreen; S >= 0; --S)
                    {
                        ListGameScreenCreatedByMap.Add(ListGameScreen[S]);
                        ListGameScreen.RemoveAt(S);
                    }

                    RemoveAllScreens();
                    ListGameScreen.Insert(0, NewMap);
                    NewMap.Update(gameTime);

                    for (int S = 0; S < ListGameScreenCreatedByMap.Count; ++S)
                    {
                        ListGameScreen.Insert(0, ListGameScreenCreatedByMap[S]);
                        ListGameScreenCreatedByMap[S].Update(gameTime);
                    }

                    ListGameScreenCreatedByMap.Clear();
                    break;

                case MenuChoices.QuickLoad:
                    if (File.Exists("User Data/Saves/TempSave.sav"))
                    {
                        sndIntroSong.Stop();
                        sndConfirm.Play();
                        BattleMap QuickLoadMap = BattleMap.LoadTemporaryMap(ListGameScreen);
                        QuickLoadMap.TogglePreview(true);
                        ListGameScreen.Insert(0, QuickLoadMap);
                    }
                    else
                    {
                        sndDeny.Play();
                    }
                    break;

                case MenuChoices.Encyclopedia:
                    sndDeny.Play();
                    break;

                case MenuChoices.Option:
                    PushScreen(new OptionMenu());
                    sndConfirm.Play();
                    break;

                case MenuChoices.LoadGame:
                    if (File.Exists("User Data/Saves/SRWE Save.bin"))
                    {
                        sndIntroSong.Stop();
                        sndConfirm.Play();

                        Roster PlayerRoster = new Roster();
                        PlayerRoster.LoadRoster();
                        Dictionary <string, Unit> DicUnitType = Unit.LoadAllUnits();
                        Dictionary <string, BaseSkillRequirement>     DicRequirement          = BaseSkillRequirement.LoadAllRequirements();
                        Dictionary <string, BaseEffect>               DicEffect               = BaseEffect.LoadAllEffects();
                        Dictionary <string, AutomaticSkillTargetType> DicAutomaticSkillTarget = AutomaticSkillTargetType.LoadAllTargetTypes();
                        Dictionary <string, ManualSkillTarget>        DicManualSkillTarget    = ManualSkillTarget.LoadAllTargetTypes();
                        DataScreen.LoadProgression(PlayerRoster, DicUnitType, DicRequirement, DicEffect, DicAutomaticSkillTarget, DicManualSkillTarget);
                        PushScreen(new NewIntermissionScreen(PlayerRoster));
                    }
                    else
                    {
                        sndDeny.Play();
                    }
                    break;
                }
            }
        }