コード例 #1
0
ファイル: MenuUI.cs プロジェクト: teamstor/aod
        private IEnumerator <ICoroutineOperation> ToggleCoroutine(bool closing)
        {
            if (!UseTransitions)
            {
                State  = closing ? MenuUIState.Closed : MenuUIState.Open;
                _alpha = new TweenedDouble(Parent.Game, closing ? 0 : 1);
                Area   = new TweenedVector2(Parent.Game, closing ? new Vector2(RecalculateArea(SelectedPageID).X, 7 * 2) : RecalculateArea(SelectedPageID));

                yield break;
            }

            if (closing)
            {
                Area.TweenTo(new Vector2(RecalculateArea(SelectedPageID).X, 7 * 2), TweenEaseType.EaseInOutSine, 0.14f);
                yield return(Wait.Seconds(Parent.Game, 0.14f - 0.06f));

                _alpha.TweenTo(closing ? 0 : 1, TweenEaseType.EaseInOutSine, 0.06f);
                yield return(Wait.Seconds(Parent.Game, 0.06f));
            }
            else
            {
                Area.TweenTo(RecalculateArea(SelectedPageID), TweenEaseType.EaseInOutSine, 0.14f);
                _alpha.TweenTo(closing ? 0 : 1, TweenEaseType.EaseInOutSine, 0.06f);
                yield return(Wait.Seconds(Parent.Game, 0.14f));
            }

            State = closing ? MenuUIState.Closed : MenuUIState.Open;
        }
コード例 #2
0
        private IEnumerator <ICoroutineOperation> OpenInventoryAction(CombatActionArgs args)
        {
            _offset.TweenTo(0, TweenEaseType.EaseInOutCubic, 0.3f);
            while (!_offset.IsComplete)
            {
                yield return(null);
            }

            _inventoryUI = new InventoryUI(Combatant, this);
            _inventoryUI.CloseOnAction = true;

            while (!_inventoryUI.IsShowingCompleted)
            {
                yield return(null);
            }

            args.BackToPlayerTurn = !_inventoryUI.WasActionPerformedOnClose;
            _inventoryUI          = null;

            _offset.TweenTo(40, TweenEaseType.EaseInOutCubic, 0.3f);
            while (!_offset.IsComplete)
            {
                yield return(null);
            }

            if (args.BackToPlayerTurn)
            {
                Menu.Page           = CombatMenuPage.ActionSelection;
                Menu.SelectedButton = Menu.Buttons[CombatMenuPage.ActionSelection].IndexOf("Inventory");
            }
        }
コード例 #3
0
ファイル: Inventory.cs プロジェクト: teamstor/aod
        private IEnumerator <ICoroutineOperation> ShowCoroutine()
        {
            if (_state is WorldState)
            {
                (_state as WorldState).Paused      = true;
                (_state as WorldState).UpdateHook += UpdateHook;
                (_state as WorldState).DrawHook   += DrawHook;
            }

            _offsetY.TweenTo(0.0, TweenEaseType.EaseOutQuad, 0.1);
            while (!_offsetY.IsComplete)
            {
                yield return(null);
            }

            yield return(Wait.Seconds(_state.Game, 0.1));

            while (!_closed)
            {
                yield return(null);
            }

            if (_transitioning)
            {
                yield return(Wait.Seconds(_state.Game, 0.1));
            }
            else
            {
                _offsetY.TweenTo(1.0, TweenEaseType.EaseInQuad, 0.1);
                while (!_offsetY.IsComplete)
                {
                    yield return(null);
                }
            }

            if (_state is WorldState)
            {
                if (!_transitioning)
                {
                    (_state as WorldState).Paused = false;
                }
                (_state as WorldState).UpdateHook -= UpdateHook;
                (_state as WorldState).DrawHook   -= DrawHook;
            }

            if (_completedEvent != null)
            {
                _completedEvent(_entity);
            }

            IsShowingCompleted = true;
        }
コード例 #4
0
ファイル: MenuUI.cs プロジェクト: teamstor/aod
        private IEnumerator <ICoroutineOperation> SwitchCoroutine()
        {
            string lastID = SelectedPageID;

            SelectedPage.OnPageLeave(_nextPageID);
            Area.TweenTo(RecalculateArea(_nextPageID), TweenEaseType.EaseInOutSine, 0.2f);
            _pageTransition.TweenTo(1, TweenEaseType.EaseInOutSine, 0.2f);

            yield return(Wait.Seconds(Parent.Game, 0.2f));

            SelectedPageID = _nextPageID;
            SelectedPage.OnPageEnter(lastID);
            _nextPageID = "";

            State = MenuUIState.Open;
        }
コード例 #5
0
ファイル: WorldState.cs プロジェクト: teamstor/aod
        private void LoadMapAndTransition(string newMapFile, bool transition, SpawnArgs?spawnArgs = null)
        {
            Map newMap = Map.Load(AppDomain.CurrentDomain.BaseDirectory + newMapFile);

            WorldState newState =
                spawnArgs.HasValue ? new WorldState(newMap, spawnArgs.Value, transition) :
                new WorldState(newMap, new SpawnArgs(new Point(-1, -1), Direction.Down, Player), transition);

            if (transition)
            {
                _transition.TweenTo(1, TweenEaseType.Linear, 0.4);
                Coroutine.AddExisting(WaitForTransition(newState));
            }
            else
            {
                Game.CurrentState = newState;
            }
        }
コード例 #6
0
        private IEnumerator <ICoroutineOperation> TransitionToStoryCoroutine()
        {
            foreach (MenuElement e in UI.SelectedPage)
            {
                if (e is MenuButton && (e as MenuButton).IconLeft == "icons/start_game.png")
                {
                    for (int i = 0; i < 3; i++)
                    {
                        e.OnDeselected(null);
                        yield return(Wait.Seconds(Game, 0.08f));

                        e.OnSelected(null);
                        yield return(Wait.Seconds(Game, 0.08f));
                    }

                    e.OnDeselected(null);
                    yield return(Wait.Seconds(Game, 0.4f));
                }
            }

            UI.SwitchPage("start-game");

            while (!_doneWithName)
            {
                yield return(null);
            }

            UI.Toggle();
            yield return(Wait.Seconds(Game, 0.3f));

            _exitTransition.TweenTo(1, TweenEaseType.Linear, 1.5f);
            yield return(Wait.Seconds(Game, 2f));

            string pname = "";

            foreach (MenuElement e in UI.SelectedPage)
            {
                if (e is MenuTextInput)
                {
                    pname = (e as MenuTextInput).Text.Trim();
                }
            }

            if (pname == "")
            {
                pname = "Player";
            }

            Game.CurrentState = new StoryMenuState(pname);
        }
コード例 #7
0
        private IEnumerator <ICoroutineOperation> RunCombat()
        {
            DrawToScreenOrRenderTarget(Game.Batch, new Vector2(480, 270), _transitionRenderTarget);

            _transition.TweenTo(0, TweenEaseType.EaseOutCubic, 0.5);
            yield return(Wait.Seconds(Game, 0.8));

            for (int i = 0; i < 12; i++)
            {
                _showWarning = !_showWarning;
                yield return(Wait.Seconds(Game, 0.15));
            }

            yield return(Wait.Seconds(Game, 0.7));

            _offset.TweenTo(40, TweenEaseType.EaseInOutCubic, 0.6f);

            while (!_offset.IsComplete)
            {
                yield return(null);
            }

            CombatActionArgs args = new CombatActionArgs();

            while (true)
            {
                args.Stop = args.BackToPlayerTurn = false;
                Menu.NewTurn();

                while (Menu.PendingAction == CombatPendingPlayerAction.None)
                {
                    yield return(null);
                }

                IEnumerator <ICoroutineOperation> subAction;

                switch (Menu.PendingAction)
                {
                case CombatPendingPlayerAction.AttackMelee:
                    subAction = AttackAction(false, args);
                    while (subAction.MoveNext())
                    {
                        yield return(subAction.Current);
                    }
                    break;

                case CombatPendingPlayerAction.AttemptRunAway:
                    subAction = RunAwayAction(args);
                    while (subAction.MoveNext())
                    {
                        yield return(subAction.Current);
                    }
                    break;

                case CombatPendingPlayerAction.OpenInventory:
                    subAction = OpenInventoryAction(args);
                    while (subAction.MoveNext())
                    {
                        yield return(subAction.Current);
                    }
                    break;
                }

                if (args.Stop)
                {
                    break;
                }

                if (!args.BackToPlayerTurn)
                {
                    subAction = AttackAction(true, args);
                    while (subAction.MoveNext())
                    {
                        yield return(subAction.Current);
                    }

                    if (args.Stop)
                    {
                        break;
                    }
                }

                args.BackToPlayerTurn = false;
            }

            _offset.TweenTo(0, TweenEaseType.EaseInOutCubic, 0.6f);

            while (!_offset.IsComplete)
            {
                yield return(null);
            }

            yield return(Wait.Seconds(Game, 0.3));

            DrawToScreenOrRenderTarget(Game.Batch, new Vector2(480, 270), _transitionRenderTarget);
            _transitionType = TransitionType.CombatOut;
            _transition.TweenTo(1, TweenEaseType.EaseInCubic, 0.5);

            yield return(Wait.Seconds(Game, 0.6));

            if (Combatant.Health <= 0)
            {
                Game.CurrentState = new GameOverState();
            }
            else
            {
                typeof(Game).GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(Game, Combatant.World);
                OnLeave(Combatant.World);
            }
        }
コード例 #8
0
ファイル: TileMenu.cs プロジェクト: teamstor/aod
        public void Update(Game game)
        {
            if (!Disabled && ((Rectangle.Value.Contains(game.Input.MousePosition) && !Rectangle.Value.Contains(game.Input.PreviousMousePosition)) || (Game.Input.KeyPressed(Keys.S) && !_isSearching)))
            {
                Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, Math.Min((int)TotalArea.Y, MaxHeight)), TweenEaseType.EaseOutQuad, 0.1f);
                _screenFade.TweenTo(1, TweenEaseType.EaseOutQuad, 0.1f);

                if (Game.Input.KeyPressed(Keys.S))
                {
                    _isSearching = true;
                    _quitQueued  = true;

                    TextInputEXT.TextInput += OnSearchInput;
                    TextInputEXT.StartTextInput();
                    game.OnStateChange += RemoveSearchInput;
                }
            }
            else if (_quitQueued || (!Rectangle.Value.Contains(game.Input.MousePosition) && Rectangle.Value.Contains(game.Input.PreviousMousePosition)))
            {
                if (_isScrolling || _isSearching)
                {
                    _quitQueued = true;
                }
                else
                {
                    if (!Rectangle.Value.Contains(game.Input.MousePosition))
                    {
                        Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, 28), TweenEaseType.EaseOutQuad, 0.1f);
                        _screenFade.TweenTo(0, TweenEaseType.EaseOutQuad, 0.1f);
                    }

                    _quitQueued = false;
                }
            }

            if (_isSearching && game.Input.KeyPressed(Keys.Tab))
            {
                string s = _searchTerm.ToLowerInvariant().Trim().Replace(" ", "");

                foreach (Category category in Categories)
                {
                    Tile searched = Search(s, category);

                    if (searched != null)
                    {
                        _searchTerm = searched.Name(null, _environment);
                        break;
                    }
                }
            }

            if (_isSearching && game.Input.KeyPressed(Keys.Enter))
            {
                _searchTerm = _searchTerm.ToLowerInvariant().Trim().Replace(" ", "");

                foreach (Category category in Categories)
                {
                    Tile searched = Search(_searchTerm, category);
                    if (searched != null)
                    {
                        SelectedTile = searched;
                        if (SelectionChanged != null)
                        {
                            SelectionChanged(this, SelectedTile);
                        }
                    }
                }

                _isSearching = false;
                _searchTerm  = "";

                TextInputEXT.TextInput -= OnSearchInput;
                TextInputEXT.StopTextInput();
                game.OnStateChange -= RemoveSearchInput;
            }
            else if (_isSearching && game.Input.KeyPressed(Keys.Escape))
            {
                _isSearching            = false;
                _searchTerm             = "";
                TextInputEXT.TextInput -= OnSearchInput;
                TextInputEXT.StopTextInput();
                game.OnStateChange -= RemoveSearchInput;
            }

            if (IsHovered && CanInteractWith)
            {
                float changed = _scrollTarget;

                if (game.Input.KeyPressed(Keys.Home))
                {
                    _scrollTarget = 0;
                }

                if (game.Input.KeyPressed(Keys.PageUp))
                {
                    _scrollTarget = Scroll - 180;
                }
                if (game.Input.KeyPressed(Keys.PageDown))
                {
                    _scrollTarget = Scroll + 180;
                }

                if (game.Input.KeyPressed(Keys.End))
                {
                    _scrollTarget = ScrollableAmount;
                }

                if (changed != _scrollTarget)
                {
                    if (_scrollTarget < 0)
                    {
                        _scrollTarget = 0;
                    }
                    if (_scrollTarget > ScrollableAmount)
                    {
                        _scrollTarget = ScrollableAmount;
                    }
                }
            }

            if (CanInteractWith)
            {
                if (_scrollTarget != -1)
                {
                    Scroll = MathHelper.Lerp(Scroll, _scrollTarget, (float)Game.DeltaTime * 14f);
                    if (Math.Abs(Scroll - _scrollTarget) <= 0.75f)
                    {
                        _scrollTarget = -1;
                    }
                }
                else if (Rectangle.Value.Contains(game.Input.MousePosition))
                {
                    if ((game.Input.MouseScroll < 0 && Scroll < ScrollableAmount) ||
                        (game.Input.MouseScroll > 0 && Scroll > 0))
                    {
                        Scroll -= game.Input.MouseScroll / 4f;
                    }

                    if (game.Input.Key(Keys.Up) && Scroll > 0)
                    {
                        Scroll = Math.Max(0, Scroll - ((float)game.DeltaTime * 140f));
                    }
                    if (game.Input.Key(Keys.Down) && Scroll < ScrollableAmount)
                    {
                        Scroll = Math.Min(ScrollableAmount, Scroll + ((float)game.DeltaTime * 140f));
                    }
                }

                if (_isScrolling)
                {
                    float at         = game.Input.MousePosition.Y - (Rectangle.Value.Top + 8);
                    float percentage = at / (Rectangle.Value.Height - 16);
                    Scroll = percentage * ScrollableAmount;

                    if (game.Input.MouseReleased(Engine.MouseButton.Left))
                    {
                        _isScrolling = false;
                    }
                }

                Scroll = MathHelper.Clamp(Scroll, 0, ScrollableAmount);
            }
        }
コード例 #9
0
ファイル: MapEditorState.cs プロジェクト: teamstor/aod
        public override void OnEnter(GameState previousState)
        {
            if (!Directory.Exists(Settings.SettingsDirectory + "/maps"))
            {
                // creates directories recursively
                Directory.CreateDirectory(Settings.SettingsDirectory + "/maps");
            }

            Game.IsMouseVisible = true;
            if (previousState is WorldState)
            {
                Map = (previousState as WorldState).Map;
            }
            else
            {
                Map = new Map(50, 50, new Map.Information("Untitled", Map.Environment.Forest, Map.Weather.Sunny));
            }

            if (Map.TransitionCache != null)
            {
                Map.TransitionCache.Clear();
            }
            if (Map.Atlas != null)
            {
                Map.Atlas.Clear();
            }

            Camera = new Camera(this);

            Buttons.Add("edit-tiles-mode", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/tiles.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 114)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    MapEditorTileEditState state = new MapEditorTileEditState();
                    if (CurrentState is MapEditorEditAttributesState)
                    {
                        state.Layer = (CurrentState as MapEditorEditAttributesState).Layer;
                    }

                    CurrentState = state;
                },

                Active = false
            });

            Buttons.Add("edit-attributes-mode", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/attributes.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 114 + 32)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    MapEditorEditAttributesState state = new MapEditorEditAttributesState();
                    if (CurrentState is MapEditorTileEditState)
                    {
                        state.Layer = (CurrentState as MapEditorTileEditState).Layer;
                    }

                    CurrentState = state;
                },

                Active = false
            });

            Buttons.Add("edit-info-mode", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/info.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 114 + 32 * 2)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    CurrentState = new MapEditorEditInfoState();
                },

                Active = false
            });

            Buttons.Add("keybinds-help-mode", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/keybinds.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 114 + 32 * 3)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    CurrentState = new MapEditorShowKeybindsState();
                },

                Active = false
            });

            Buttons.Add("player-view-mode", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/player.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 114 + 32 * 4)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    CurrentState = new MapEditorPlayerViewState();
                },

                Active = false
            });

            Buttons.Add("playtest", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/arrow.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 118 + 32 * 5)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    _doPlaytest = true;
                },

                Active = false
            });

            Buttons.Add("load", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/load.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 118 + 32 * 6)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    OpenFileDialog dialog = new OpenFileDialog();

                    dialog.Filter           = "Map files (*.json)|*.json|All files (*.*)|*.*";
                    dialog.RestoreDirectory = true;
                    dialog.InitialDirectory = Settings.SettingsDirectory + Path.DirectorySeparatorChar + "maps";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        _dataOperation = DataOperation.Loading;
                        Task.Run(() =>
                        {
                            Map            = Map.Load(dialog.FileName);
                            _dataOperation = DataOperation.None;
                        });
                    }

                    dialog.Dispose();
                    Application.DoEvents();
                },

                Active = false
            });

            Buttons.Add("save", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/save.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 118 + 32 * 7)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) =>
                {
                    SaveFileDialog dialog = new SaveFileDialog();

                    dialog.Filter           = "Map files (*.json)|*.json|All files (*.*)|*.*";
                    dialog.RestoreDirectory = true;
                    dialog.InitialDirectory = Settings.SettingsDirectory + Path.DirectorySeparatorChar + "maps";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        _dataOperation = DataOperation.Saving;
                        Task.Run(() => {
                            Map.Save(new FileStream(dialog.FileName, FileMode.Create));
                            _dataOperation = DataOperation.None;
                        });
                    }

                    dialog.Dispose();
                    Application.DoEvents();
                },

                Active = false
            });

            Buttons.Add("exit", new Button
            {
                Text     = "",
                Icon     = Assets.Get <Texture2D>("editor/exit.png"),
                Position = new TweenedVector2(Game, new Vector2(-200, 118 + 32 * 8)),
                Font     = Game.DefaultFonts.Normal,
                Clicked  = (btn) => { _exiting = true; },

                Active = false
            });

            Buttons["edit-tiles-mode"].Position.TweenTo(new Vector2(10, 114), TweenEaseType.EaseOutQuad, 0.65f);
            Buttons["edit-attributes-mode"].Position.TweenTo(new Vector2(10, 114 + 32), TweenEaseType.EaseOutQuad, 0.65f);
            Buttons["edit-info-mode"].Position.TweenTo(new Vector2(10, 114 + 32 * 2), TweenEaseType.EaseOutQuad, 0.65f);
            Buttons["keybinds-help-mode"].Position.TweenTo(new Vector2(10, 114 + 32 * 3), TweenEaseType.EaseOutQuad, 0.65f);
            Buttons["player-view-mode"].Position.TweenTo(new Vector2(10, 114 + 32 * 4), TweenEaseType.EaseOutQuad, 0.65f);

            Buttons["playtest"].Position.TweenTo(new Vector2(10, 118 + 32 * 5), TweenEaseType.EaseOutQuad, 0.65f);
            Buttons["load"].Position.TweenTo(new Vector2(10, 118 + 32 * 6), TweenEaseType.EaseOutQuad, 0.65f);
            Buttons["save"].Position.TweenTo(new Vector2(10, 118 + 32 * 7), TweenEaseType.EaseOutQuad, 0.65f);
            Buttons["exit"].Position.TweenTo(new Vector2(10, 118 + 32 * 8), TweenEaseType.EaseOutQuad, 0.65f);

            _topTextY = new TweenedDouble(Game, -300);
            _topTextY.TweenTo(10, TweenEaseType.EaseOutQuad, 0.65f);

            _fade = new TweenedDouble(Game, 1.0);
            _fade.TweenTo(0, TweenEaseType.Linear, 0.5f);

            _topTextFade = new TweenedDouble(Game, 2.0);

            CurrentState = new MapEditorTileEditState();
        }
コード例 #10
0
ファイル: MapEditorState.cs プロジェクト: teamstor/aod
        public override void Update(double deltaTime, double totalTime, long count)
        {
            if (!CurrentState.PauseEditor && _dataOperation == DataOperation.None)
            {
                int xadd = Input.Key(Keys.LeftAlt) || Input.Key(Keys.RightAlt) ? -1 : 1;
                if (Input.Key(Keys.LeftControl) || Input.Key(Keys.RightControl))
                {
                    xadd *= 5;
                }

                int yadd = xadd;

                while (Map.Width + xadd < 1)
                {
                    xadd++;
                }

                while (Map.Width + xadd > 256)
                {
                    xadd--;
                }

                while (Map.Height + yadd < 1)
                {
                    yadd++;
                }

                while (Map.Height + yadd > 256)
                {
                    yadd--;
                }

                if (Input.Key(Keys.LeftShift) || Input.Key(Keys.RightShift))
                {
                    if (Input.KeyPressed(Keys.Left))
                    {
                        Map.Resize(Map.Width + xadd, Map.Height, xadd, 0);
                    }

                    if (Input.KeyPressed(Keys.Right))
                    {
                        Map.Resize(Map.Width + xadd, Map.Height, 0, 0);
                    }

                    if (Input.KeyPressed(Keys.Up))
                    {
                        Map.Resize(Map.Width, Map.Height + yadd, 0, yadd);
                    }

                    if (Input.KeyPressed(Keys.Down))
                    {
                        Map.Resize(Map.Width, Map.Height + yadd, 0, 0);
                    }
                }
            }

            Camera.Update(deltaTime, totalTime);

            Buttons["edit-tiles-mode"].Active      = CurrentState is MapEditorTileEditState;
            Buttons["edit-attributes-mode"].Active = CurrentState is MapEditorEditAttributesState;
            Buttons["edit-info-mode"].Active       = CurrentState is MapEditorEditInfoState;
            Buttons["keybinds-help-mode"].Active   = CurrentState is MapEditorShowKeybindsState;
            Buttons["player-view-mode"].Active     = CurrentState is MapEditorPlayerViewState;

            if (_dataOperation == DataOperation.None && !CurrentState.IsPointObscured(Game.Input.MousePosition))
            {
                foreach (Button button in Buttons.Values.ToArray())
                {
                    button.Update(Game);
                }

                foreach (SelectionMenu menu in SelectionMenus.Values.ToArray())
                {
                    menu.Update(Game);
                }

                foreach (TextField field in TextFields.Values.ToArray())
                {
                    field.Update(Game);
                }

                foreach (ScrollableTextField field in ScrollableTextFields.Values.ToArray())
                {
                    field.Update(Game);
                }

                foreach (ChoiceField field in ChoiceFields.Values.ToArray())
                {
                    field.Update(Game);
                }
            }

            string str =
                "Map Editor\n" +
                "Name: \"" + Map.Info.Name + "\"\n" +
                "Size: " + Map.Width + "x" + Map.Height + "\n" +
                "[PLACEHOLDER PLACEHOLDER PLACEHOLDER]";

            Vector2   measure          = Game.DefaultFonts.Bold.Measure(15, str);
            Rectangle topTextRectangle = new Rectangle(10, (int)_topTextY, (int)(measure.X + 20), (int)(measure.Y + 20));

            if (topTextRectangle.Contains(Input.MousePosition) && !topTextRectangle.Contains(Input.PreviousMousePosition))
            {
                _topTextFade.TweenTo(0.6, TweenEaseType.EaseOutQuad, 0.4f);
            }
            else if (!topTextRectangle.Contains(Input.MousePosition) && topTextRectangle.Contains(Input.PreviousMousePosition))
            {
                _topTextFade.TweenTo(2.0, TweenEaseType.EaseOutQuad, 0.4f);
            }

            if (_dataOperation == DataOperation.None)
            {
                CurrentState.Update(deltaTime, totalTime, count);
            }

            if (_exiting)
            {
                Game.CurrentState = new MainMenuState();
            }

            if (_doPlaytest)
            {
                WorldState world = new WorldState(Map, "Map Editor Player", true);
                EventHandler <Engine.Game.UpdateEventArgs> watcher = null;
                watcher = (s, e) =>
                {
                    if (Game.CurrentState != world)
                    {
                        // galet
                        Game.CurrentState.OnLeave(world);
                        // helt bananas
                        typeof(Engine.Game).GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(Game, world);

                        MapEditorState mapState = new MapEditorState();
                        Game.CurrentState        = mapState;
                        Game.OnUpdateAfterState -= watcher;
                    }
                };

                Game.OnUpdateAfterState += watcher;

                world.UpdateHook += (s, e) =>
                {
                    if (Game.Input.KeyPressed(Keys.Escape))
                    {
                        MapEditorState mapState = new MapEditorState();
                        Game.CurrentState        = mapState;
                        Game.OnUpdateAfterState -= watcher;
                    }
                };

                world.DrawHook += (s, e) =>
                {
                    Matrix oldTransform = e.Batch.Transform;
                    e.Batch.Transform = Matrix.Identity;

                    e.Batch.Text(FontStyle.ItalicBold,
                                 16,
                                 "Playtesting map \"" + Map.Info.Name + "\"\nPress ESC to return to the map editor",
                                 new Vector2(8, 8),
                                 Color.White * (0.8f + (float)(0.2f * Math.Sin(Game.Time * 4))));

                    e.Batch.Transform = oldTransform;
                };

                Game.CurrentState = world;
            }
        }
コード例 #11
0
ファイル: Camera.cs プロジェクト: teamstor/aod
        public void Update(double deltaTime, double totalTime)
        {
            if (!_state.CurrentState.PauseEditor)
            {
                if (_state.Input.KeyPressed(Keys.D2))
                {
                    if (Zoom.TargetValue <= 4)
                    {
                        Zoom.TweenTo(Zoom.TargetValue * 2, TweenEaseType.EaseInOutSine, 0.15);
                    }
                }

                if (_state.Input.KeyPressed(Keys.D1))
                {
                    if (Zoom.TargetValue >= 2)
                    {
                        Zoom.TweenTo(Zoom.TargetValue / 2, TweenEaseType.EaseInOutSine, 0.15);
                    }
                }

                if (_state.Input.Mouse(MouseButton.Right))
                {
                    Translation += _state.Input.MouseDelta;
                }
            }

            Vector2 mapSize = new Vector2(_state.Map.Width, _state.Map.Height);

            if (mapSize != _prevMapSize)
            {
                Translation -= (TotalSizeOnScreen - _prevTotalSize) / 2;
            }
            else
            {
                // vet INTE vad som händer här men det funkar
                Vector2 mouseThing = ((_state.Input.MousePosition - Translation) / _prevTotalSize);
                Translation -= (TotalSizeOnScreen - _prevTotalSize) * mouseThing;
            }

            _prevTotalSize = TotalSizeOnScreen;
            _prevMapSize   = mapSize;

            if (Translation.X > 200)
            {
                Translation.X = 200;
            }
            if (Translation.Y > 200)
            {
                Translation.Y = 200;
            }
            if (Translation.X < -(_state.Map.Width * (16 * Zoom) - _state.Game.GraphicsDevice.Viewport.Bounds.Width) - 200)
            {
                Translation.X = -(_state.Map.Width * (16 * Zoom) - _state.Game.GraphicsDevice.Viewport.Bounds.Width) - 200;
            }
            if (Translation.Y < -(_state.Map.Height * (16 * Zoom) - _state.Game.GraphicsDevice.Viewport.Bounds.Height) - 200)
            {
                Translation.Y = -(_state.Map.Height * (16 * Zoom) - _state.Game.GraphicsDevice.Viewport.Bounds.Height) - 200;
            }

            if (_state.Game.GraphicsDevice.Viewport.Bounds.Width / 2 > _state.Map.Width * 8 * Zoom)
            {
                Translation.X = _state.Game.GraphicsDevice.Viewport.Bounds.Width / 2 - _state.Map.Width * 8 * Zoom;
            }
            if (_state.Game.GraphicsDevice.Viewport.Bounds.Height / 2 > _state.Map.Height * 8 * Zoom)
            {
                Translation.Y = _state.Game.GraphicsDevice.Viewport.Bounds.Height / 2 - _state.Map.Height * 8 * Zoom;
            }
        }
コード例 #12
0
        private IEnumerator <ICoroutineOperation> ShowCoroutine()
        {
            _world.Paused    = true;
            _world.DrawHook += DrawHook;

            bool wasHeldAtStart = InputMap.FindMapping(InputAction.Action).Held(_world.Input);

            _offsetY.TweenTo(0.0, TweenEaseType.EaseOutQuad, 0.1);
            while (!_offsetY.IsComplete)
            {
                yield return(null);
            }

            yield return(Wait.Seconds(_world.Game, 0.1));

            while (true)
            {
                if (InputMap.FindMapping(InputAction.Action).Pressed(_world.Input) && _textWrittenYet.Length == _content.Text.Length)
                {
                    break;
                }

                if (InputMap.FindMapping(InputAction.Action).Held(_world.Input) && !wasHeldAtStart)
                {
                    if (_textWrittenYet.Length < _content.Text.Length)
                    {
                        _textWrittenYet = _content.Text;
                        _completionTime = _world.Game.TotalFixedUpdates;
                    }
                }

                if (wasHeldAtStart && !InputMap.FindMapping(InputAction.Action).Held(_world.Input))
                {
                    wasHeldAtStart = false;
                }

                if (_textWrittenYet.Length < _content.Text.Length)
                {
                    _textWrittenYet += _content.Text[_textWrittenYet.Length];
                    if (_textWrittenYet.Length == _content.Text.Length)
                    {
                        _completionTime = _world.Game.TotalFixedUpdates;
                    }
                    yield return(Wait.Seconds(_world.Game, 0.03));
                }
                else
                {
                    yield return(null);
                }
            }

            _offsetY.TweenTo(1.0, TweenEaseType.EaseInQuad, 0.1);
            while (!_offsetY.IsComplete)
            {
                yield return(null);
            }

            _world.DrawHook -= DrawHook;
            _world.Paused    = false;

            if (_completedEvent != null)
            {
                _completedEvent();
            }
        }
コード例 #13
0
ファイル: WorldState.cs プロジェクト: teamstor/aod
        public override void OnEnter(GameState previousState)
        {
            if (_transitionRenderTarget == null)
            {
                _transitionRenderTarget = new RenderTarget2D(Game.GraphicsDevice, 480, 270, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
            }

            if (_spawnArgs.OldPlayer != null)
            {
                Player = new Player(this, _spawnArgs.OldPlayer);
            }
            else
            {
                Player = new Player(this, _playerName);
            }

            if (_spawnArgs.Position != new Point(-1, -1))
            {
                Player.MoveInstantly(_spawnArgs.Position);
            }

            _lastPlayerPos = Player.Position;

            Player.Heading = _spawnArgs.Direction;

            for (int x = 0; x < Map.Width; x++)
            {
                for (int y = 0; y < Map.Height; y++)
                {
                    if (Map[Tile.MapLayer.NPC, x, y] != DefaultTiles.EmptyNPC)
                    {
                        SpawnNPC(NPCTemplate.FromTile(Map[Tile.MapLayer.NPC, x, y]), new Point(x, y));
                    }
                }
            }

            if (_useTransiton)
            {
                _transition = new TweenedDouble(Game, 1);
                _transition.TweenTo(0, TweenEaseType.Linear, 0.4);
                Paused = true;
            }
            else
            {
                _transition = new TweenedDouble(Game, 0);
                Coroutine.Start(ShowMapName);
            }

            Camera = new Camera(this);

            Game.IsMouseVisible = false;

            if (Map.TransitionCache != null)
            {
                Map.TransitionCache.Clear();
            }
            if (Map.Atlas != null)
            {
                Map.Atlas.Clear();
            }
        }
コード例 #14
0
ファイル: PauseMenu.cs プロジェクト: teamstor/aod
        private IEnumerator <ICoroutineOperation> ShowCoroutine()
        {
            MenuPage mainPage = new MenuPage(150);

            mainPage.Add(new MenuLabel(mainPage, "Level " + _world.Player.Level + " " + _world.Player.Name + ", " + _world.Map.Info.Name));
            mainPage.Add(new MenuSpacer(8));
            mainPage.Add(new MenuButton(mainPage, "Resume Game", "icons/start_game.png")).
            RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h)
                                                                     {
                                                                         _closed = true;
                                                                     }
                          });
            mainPage.Add(new MenuButton(mainPage, "Options", "icons/settings.png", "", "")).
            RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h)
                                                                     {
                                                                         _options.SwitchToOptionsPage();
                                                                     }
                          });
            mainPage.Add(new MenuButton(mainPage, "Return To Main Menu", "icons/arrow_left.png")).
            RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h)
                                                                     {
                                                                         _menu.SwitchPage("confirm");
                                                                     }
                          });

            MenuPage confirmPage = new MenuPage(180);

            confirmPage.Add(new MenuLabel(confirmPage, "Are you sure you want to quit?"));
            confirmPage.Add(new MenuLabel(confirmPage, "Unsaved progress will be lost", "", "", 0.8f));
            confirmPage.Add(new MenuSpacer(4));
            confirmPage.Add(new MenuButton(confirmPage, "Go Back", "icons/arrow_right.png")).
            RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h)
                                                                     {
                                                                         _menu.SwitchPage("main", true);
                                                                     }
                          });
            confirmPage.Add(new MenuButton(confirmPage, "Return To Main Menu", "icons/arrow_left.png")).
            RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h)
                                                                     {
                                                                         _world.Game.CurrentState = new MainMenuState();
                                                                     }
                          });

            _menu    = new MenuUI(_world, "main", mainPage, true);
            _options = new MenuOptions(_menu, "main");
            _menu.AddPage("confirm", confirmPage);

            _alpha = new TweenedDouble(_world.Game, 0);

            _world.Paused      = true;
            _world.UpdateHook += UpdateHook;
            _world.DrawHook   += DrawHook;

            IEnumerator <ICoroutineOperation> uiEnumerator = _menu.Toggle();

            _alpha.TweenTo(1, TweenEaseType.Linear, 0.08f);
            yield return(Wait.Seconds(_world.Game, 0.18f));

            while (!_closed)
            {
                yield return(null);
            }

            uiEnumerator = _menu.Toggle();
            yield return(Wait.Seconds(_world.Game, 0.18f - 0.08f));

            _alpha.TweenTo(0, TweenEaseType.Linear, 0.08f);
            yield return(Wait.Seconds(_world.Game, 0.08f));

            _world.UpdateHook -= UpdateHook;
            _world.DrawHook   -= DrawHook;
            _world.Paused      = false;

            if (_completedEvent != null)
            {
                _completedEvent();
            }

            IsShowingCompleted = true;
        }