Пример #1
0
 public Playing(LevelRep context, State sourceState, ILevelManager runningLevel)
     : base(context)
 {
     this.RunningLevel    = runningLevel;
     this.sourceState     = sourceState;
     runningLevel.Ending += RunningLevelEnding;
 }
Пример #2
0
 /// <summary>
 /// Returns loader that can load the level into editing mode, where players are just placeholders.
 /// </summary>
 /// <param name="levelRep">Presentation of the level for the user.</param>
 /// <param name="storedLevel">Stored serialized state of the level.</param>
 /// <param name="parentProgress">Progress watcher for the parent process.</param>
 /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param>
 /// <returns>Loader that can load the level into editing mode.</returns>
 public static ILevelLoader GetLoaderForEditing(LevelRep levelRep,
                                                StLevel storedLevel,
                                                IProgressEventWatcher parentProgress = null,
                                                double loadingSubsectionSize         = 100)
 {
     return(new SavedLevelEditorLoader(levelRep, storedLevel, parentProgress, loadingSubsectionSize));
 }
Пример #3
0
            async void SaveAsButtonReleased(ReleasedEventArgs args)
            {
                if (Level.LevelRep.GamePack.TryGetLevel(name, out LevelRep oldLevel))
                {
                    bool confirm = await MenuUIManager.ConfirmationPopUp.RequestConfirmation("Override level",
                                                                                             "Do you want to override existing level with the same name?",
                                                                                             null,
                                                                                             proxy);

                    if (!confirm)
                    {
                        return;
                    }
                }

                LevelRep newLevelRep = null;

                try {
                    newLevelRep = Level.LevelRep.CreateClone(name, description, ThumbnailPath);
                    newLevelRep.SaveToGamePack(true);
                    MenuUIManager.SwitchBack();
                }
                catch (Exception) {
                    newLevelRep?.Dispose();
                    await MenuUIManager.ErrorPopUp.DisplayError("Package Error",
                                                                "There was an error while saving the level to package, see log for details.",
                                                                proxy);
                }
            }
Пример #4
0
 /// <summary>
 /// Returns loader that can generate new level based on provided data.
 /// </summary>
 /// <param name="levelRep">Presentation of the level for the user.</param>
 /// <param name="mapSize">Size of the map to generate.</param>
 /// <param name="parentProgress">Progress watcher for the parent process.</param>
 /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param>
 /// <returns>Loader that can generate new level.</returns>
 public static ILevelLoader GetLoaderForDefaultLevel(LevelRep levelRep,
                                                     IntVector2 mapSize,
                                                     IProgressEventWatcher parentProgress = null,
                                                     double loadingSubsectionSize         = 100)
 {
     return(new DefaultLevelLoader(levelRep, mapSize, parentProgress, loadingSubsectionSize));
 }
Пример #5
0
        public LevelPickingLevelItem(LevelRep level, MHUrhoApp game)
            : base(game, "UI/LevelItemStyle.xml", true)
        {
            this.Level = level;


            XmlFile styleFile = game.PackageManager.GetXmlFile("UI/LevelItemStyle.xml", true);

            UIElement fixedElementContents = game.UI.LoadLayout(game.PackageManager.GetXmlFile("UI/LevelItemFixedLayout.xml", true),
                                                                styleFile);

            FixedElement.AddChild(fixedElementContents);


            UIElement expandingElementContents = game.UI.LoadLayout(game.PackageManager.GetXmlFile("UI/LevelItemExpandingLayout.xml", true),
                                                                    styleFile);

            ExpandingElement.AddChild(expandingElementContents);

            var thumbnailElement = (BorderImage)fixedElementContents.GetChild("Thumbnail", true);

            thumbnailElement.Texture   = level.Thumbnail;
            thumbnailElement.ImageRect = new IntRect(0, 0, level.Thumbnail.Width, level.Thumbnail.Height);

            var nameElement = (Text)CheckBox.GetChild("NameText", true);

            nameElement.Value = level.Name;

            ((Text)ExpandingElement.GetChild("DescriptionText", true)).Value = level.Description;
        }
Пример #6
0
            //1 for finishloading

            /// <summary>
            /// Creates loader to generate the level represented by <paramref name="levelRep"/>.
            /// </summary>
            /// <param name="levelRep">Presentation part of the level.</param>
            /// <param name="mapSize">Size of the map to generate the level with.</param>
            /// <param name="parentProgress">Progress watcher for the parent process.</param>
            /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param>
            public DefaultLevelLoader(LevelRep levelRep,
                                      IntVector2 mapSize,
                                      IProgressEventWatcher parentProgress = null,
                                      double loadingSubsectionSize         = 100)
                : base(levelRep, true, parentProgress, loadingSubsectionSize)
            {
                this.mapSize = mapSize;

                if (LevelRep.MaxNumberOfPlayers < 1)
                {
                    throw new ArgumentException("Level without players does not make sense", nameof(levelRep));
                }

                if (mapSize.X < WorldMap.Map.MinSize.X || WorldMap.Map.MaxSize.X < mapSize.X ||
                    mapSize.Y < WorldMap.Map.MinSize.Y || WorldMap.Map.MaxSize.Y < mapSize.Y)
                {
                    throw new ArgumentOutOfRangeException(nameof(mapSize),
                                                          mapSize,
                                                          "MapSize was out of bounds set by Map.MinSize and Map.MaxSize");
                }

                if (mapSize.X % WorldMap.Map.ChunkSize.X != 0 || mapSize.Y % WorldMap.Map.ChunkSize.Y != 0)
                {
                    throw new ArgumentException("MapSize has to be an integer multiple of Map.ChunkSize", nameof(mapSize));
                }
            }
Пример #7
0
 public ILevelLoader GetLevelLoaderForPlaying(LevelRep level,
                                              PlayerSpecification players,
                                              LevelLogicCustomSettings customSettings,
                                              IProgressEventWatcher parentProgress = null,
                                              double subsectionSize = 100)
 {
     throw new NotImplementedException();
 }
Пример #8
0
 void DescriptionChanged(TextChangedEventArgs args)
 {
     if (!LevelRep.IsDescriptionValid(args.Text))
     {
         descriptionEdit.Text = description;
     }
     description = descriptionEdit.Text;
 }
Пример #9
0
 void NameChanged(TextChangedEventArgs args)
 {
     if (!LevelRep.IsNameValid(args.Text))
     {
         nameEdit.Text = name;
     }
     name = nameEdit.Text;
 }
Пример #10
0
 /// <summary>
 /// Creates loader to load the level represented by <paramref name="levelRep"/> into the mode specified by <paramref name="editorMode"/>.
 /// Can be added as part of bigger process with <paramref name="parentProgress"/> and <paramref name="loadingSubsectionSize"/>.
 /// </summary>
 /// <param name="levelRep">The rep of the level to load.</param>
 /// <param name="editorMode">If the level should be loaded into editor mode or playing mode.</param>
 /// <param name="parentProgress">Progress watcher for the parent process.</param>
 /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param>
 protected BaseLoader(LevelRep levelRep, bool editorMode, IProgressEventWatcher parentProgress, double loadingSubsectionSize)
 {
     this.LevelRep           = levelRep;
     this.EditorMode         = editorMode;
     this.Progress           = new ProgressWatcher(parentProgress, loadingSubsectionSize);
     this.Progress.Finished += LoadingFinished;
     this.Progress.Failed   += LoadingFailed;
 }
Пример #11
0
 /// <summary>
 /// Returns loader that can load the level into playing mode.
 /// </summary>
 /// <param name="levelRep">Presentation of the level for the user.</param>
 /// <param name="storedLevel">Stored serialized state of the level.</param>
 /// <param name="players">Data to initialize the players.</param>
 /// <param name="customSettings">Data to initialize the level logic instance plugin.</param>
 /// <param name="parentProgress">Progress watcher for the parent process.</param>
 /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param>
 /// <returns>Loader that can load the level into playing mode.</returns>
 public static ILevelLoader GetLoaderForPlaying(LevelRep levelRep,
                                                StLevel storedLevel,
                                                PlayerSpecification players,
                                                LevelLogicCustomSettings customSettings,
                                                IProgressEventWatcher parentProgress = null,
                                                double loadingSubsectionSize         = 100)
 {
     return(new SavedLevelPlayingLoader(levelRep, storedLevel, players, customSettings, parentProgress, loadingSubsectionSize));
 }
Пример #12
0
        /// <summary>
        /// If there is a paused running level, ends it and then creates a loader for loading <paramref name="level"/>
        /// for editing.
        /// Can send loading updates if given <paramref name="parentProgress"/>.
        /// Scales the percentage updates by <paramref name="subsectionSize"/>, to enable us and the parent to go from 0 to 100.
        /// </summary>
        /// <param name="level">The level to create the loader for.</param>
        /// <param name="parentProgress">The progress watcher for the parent.</param>
        /// <param name="subsectionSize">The precentage size of the level loading in the whole loading process.</param>
        /// <returns>A loader for the <paramref name="level"/> that can be used to load the <paramref name="level"/> for editing.</returns>
        public ILevelLoader GetLevelLoaderForEditing(LevelRep level, IProgressEventWatcher parentProgress = null, double subsectionSize = 100)
        {
            if (pausedLevelController != null)
            {
                EndPausedLevel();
            }

            return(level.GetLoaderForEditing(parentProgress, subsectionSize));
        }
Пример #13
0
        /// <summary>
        /// If there is a paused running level, ends it and then creates a loader for loading <paramref name="level"/>
        /// for playing.
        /// Initializes players based on <paramref name="players"/>.
        /// Initializes level logic based on <paramref name="customSettings"/>.
        /// Can send loading updates if given <paramref name="parentProgress"/>.
        /// Scales the percentage updates by <paramref name="subsectionSize"/>, to enable us and the parent to go from 0 to 100.
        /// </summary>
        /// <param name="level">The level to create the loader for.</param>
        /// <param name="players">Data to use for player initialization.</param>
        /// <param name="customSettings">Settings to use for level logic plugin initialization.</param>
        /// <param name="parentProgress">The progress watcher for the parent.</param>
        /// <param name="subsectionSize">The precentage size of the level loading in the whole loading process.</param>
        /// <returns>A loader for the <paramref name="level"/> that can be used to load the <paramref name="level"/> for editing.</returns>
        public ILevelLoader GetLevelLoaderForPlaying(LevelRep level,
                                                     PlayerSpecification players,
                                                     LevelLogicCustomSettings customSettings,
                                                     IProgressEventWatcher parentProgress = null,
                                                     double subsectionSize = 100)
        {
            if (pausedLevelController != null)
            {
                EndPausedLevel();
            }

            return(level.GetLoaderForPlaying(players, customSettings, parentProgress, subsectionSize));
        }
Пример #14
0
            /// <summary>
            /// Creates a loader that loads saved level into a playing mode.
            /// </summary>
            /// <param name="levelRep">Presentation part of the level.</param>
            /// <param name="storedLevel">Saved level.</param>
            /// <param name="players">Data for player initialization.</param>
            /// <param name="customSettings">Data for level logic initialization.</param>
            /// <param name="parentProgress">Progress watcher for the parent process.</param>
            /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param>
            public SavedLevelPlayingLoader(LevelRep levelRep,
                                           StLevel storedLevel,
                                           PlayerSpecification players,
                                           LevelLogicCustomSettings customSettings,
                                           IProgressEventWatcher parentProgress = null,
                                           double loadingSubsectionSize         = 100)
                : base(levelRep, storedLevel, false, parentProgress, loadingSubsectionSize)
            {
                this.players        = players;
                this.customSettings = customSettings;

                if ((players == PlayerSpecification.LoadFromSavedGame) !=
                    (customSettings == LevelLogicCustomSettings.LoadFromSavedGame))
                {
                    throw new
                          ArgumentException("Argument mismatch, one argument is loaded from save and the other is not");
                }
            }
Пример #15
0
        /// <summary>
        /// Creates level manager that controls a level presented by <paramref name="levelRep"/> to the user,
        /// represented by <paramref name="levelNode"/> in the game engine.
        /// </summary>
        /// <param name="levelNode">The <see cref="Node"/> representing the level in the game engine.</param>
        /// <param name="levelRep">Presentation of the level for the user.</param>
        /// <param name="app">Current running application.</param>
        /// <param name="octree">Engine component used for raycasting.</param>
        /// <param name="editorMode">If the level is in editor mode or playig mode.</param>
        protected LevelManager(Node levelNode, LevelRep levelRep, MHUrhoApp app, Octree octree, bool editorMode)
        {
            this.LevelNode  = levelNode;
            this.LevelRep   = levelRep;
            this.EditorMode = editorMode;
            //Plugin is set in the loader after the creation of LevelManager
            //this.Plugin = plugin;

            this.units        = new Dictionary <int, IUnit>();
            this.players      = new Dictionary <int, IPlayer>();
            this.buildings    = new Dictionary <int, IBuilding>();
            this.projectiles  = new Dictionary <int, IProjectile>();
            this.entities     = new Dictionary <int, IEntity>();
            this.rangeTargets = new Dictionary <int, IRangeTarget>();
            this.nodeToEntity = new Dictionary <Node, IEntity>();
            this.rng          = new Random();

            this.App    = app;
            this.octree = octree;
            this.DefaultComponentFactory = new DefaultComponentFactory();
            this.IsEnding       = false;
            ReceiveSceneUpdates = true;
        }
Пример #16
0
 public override State CloneToNewContext(LevelRep newContext)
 {
     throw new
           InvalidOperationException("Cannot clone freshly created level, load it, save it, then clone it");
 }
Пример #17
0
 public ILevelLoader GetLevelLoaderForEditing(LevelRep level,
                                              IProgressEventWatcher parentProgress = null,
                                              double subsectionSize = 100)
 {
     throw new NotImplementedException();
 }
Пример #18
0
 /// <inheritdoc />
 public void ChangeRep(LevelRep newLevelRep)
 {
     LevelRep.DetachFromLevel();
     LevelRep = newLevelRep;
 }
Пример #19
0
 public Prototype(LevelRep context)
     : base(context)
 {
 }
Пример #20
0
 public Editing(LevelRep context, ILevelManager runningLevel)
     : base(context)
 {
     this.RunningLevel    = runningLevel;
     runningLevel.Ending += RunningLevelEnding;
 }
Пример #21
0
 public override State CloneToNewContext(LevelRep newContext)
 {
     return(new ClonedEditing(newContext, RunningLevel));
 }
Пример #22
0
 public override State CloneToNewContext(LevelRep newContext)
 {
     return(new ClonedPrototype(newContext, sourceState));
 }
Пример #23
0
 public LevelCreationScreen SwitchToLevelCreationScreen(LevelRep level)
 {
     LevelCreationScreen.Level = level;
     SwitchToScreen(LevelCreationScreen);
     return(LevelCreationScreen);
 }
Пример #24
0
 public LevelSettingsScreen SwitchToLevelSettingsScreen(LevelRep level)
 {
     LevelSettingsScreen.Level = level;
     SwitchToScreen(LevelSettingsScreen);
     return(LevelSettingsScreen);
 }
Пример #25
0
 public NewlyCreated(IntVector2 mapSize, LevelRep context)
     : base(context)
 {
     this.mapSize = mapSize;
 }
Пример #26
0
 public override State CloneToNewContext(LevelRep newContext)
 {
     throw new InvalidOperationException("Cannot clone loaded saved level");
 }
Пример #27
0
 public LoadedSaved(LevelRep context, string savedLevelPath, StLevel savedLevel)
     : base(context)
 {
     this.savedLevelPath = savedLevelPath;
     this.savedLevel     = savedLevel;
 }
Пример #28
0
 public override State CloneToNewContext(LevelRep newContext)
 {
     throw new InvalidOperationException("Cannot clone level in play mode");
 }
Пример #29
0
 public ClonedEditing(LevelRep context, ILevelManager runningLevel)
     : base(context, runningLevel)
 {
 }
Пример #30
0
 public ClonedPrototype(LevelRep context, Prototype sourceState)
     : base(context)
 {
     this.sourceState = sourceState;
 }