private PlayerUI(WorldState world, Player entity, bool noOffset) { _world = world; _entity = entity; _offsetY = new TweenedDouble(world.Game, noOffset ? 0.0 : 1.0); }
public Camera(MapEditorState state) { _state = state; Zoom = new TweenedDouble(state.Game, 2); _prevTotalSize = TotalSizeOnScreen; _prevMapSize = new Vector2(state.Map.Width, state.Map.Height); }
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; }
public TileMenu(Map.Environment environment, Engine.Game game) { _environment = environment; Game = game; Rectangle = new TweenedRectangle(game, new Rectangle(0, 0, (int)TotalArea.X, 28)); _screenFade = new TweenedDouble(game, 0); Recreate(); }
public MenuUI(GameState state, string initialPageId, MenuPage initialPage, bool startClosed) { Parent = state; _pages.Add(initialPageId, initialPage); SelectedPageID = initialPageId; initialPage.Parent = this; SelectedPage.OnPageEnter(""); State = startClosed ? MenuUIState.Closed : MenuUIState.Open; _alpha = new TweenedDouble(state.Game, startClosed ? 0 : 1); Area = new TweenedVector2(state.Game, startClosed ? new Vector2(RecalculateArea(SelectedPageID).X, 7 * 2) : RecalculateArea(SelectedPageID)); _pageTransition = new TweenedDouble(state.Game, 0); }
private InventoryUI(WorldState world, LivingEntity entity, bool noOffset = false) { _state = world; _entity = entity; UpdateSortedList(); _offsetY = new TweenedDouble(world.Game, noOffset ? 0.0 : 1.0); if (_entity.Inventory.OccupiedSlots == 0) { _selectedSlot = -1; } _state.Coroutine.AddExisting(ChangeSelectedSlot(_selectedSlot)); }
public override void OnEnter(GameState previousState) { Menu = new CombatMenu(this); if (_transitionRenderTarget == null) { _transitionRenderTarget = new RenderTarget2D(Game.GraphicsDevice, 480, 270, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); } _offset = new TweenedDouble(Game, 0); _transition = new TweenedDouble(Game, 1); Coroutine.Start(RunCombat); }
/// <summary> /// Creates a standalone inventory UI that needs to be updated manually. /// </summary> /// <param name="entity">The entity to use the inventory with.</param> public InventoryUI(LivingEntity entity, GameState state, bool noOffset = false) { _entity = entity; _offsetY = new TweenedDouble(state.Game, noOffset ? 0.0 : 1.0); _state = state; UpdateSortedList(); state.Coroutine.Start(ShowCoroutine); if (_entity.Inventory.OccupiedSlots == 0) { _selectedSlot = -1; } state.Coroutine.AddExisting(ChangeSelectedSlot(_selectedSlot)); }
public override void OnEnter(GameState previousState) { _exitTransition = new TweenedDouble(Game, 0); MenuPage startGamePage = new MenuPage(150); startGamePage.Add(new MenuLabel(startGamePage, "Choose a name to begin")); startGamePage.Add(new MenuSpacer(4)); startGamePage.Add(new MenuTextInput(startGamePage, "Player", "Name: ")); startGamePage.Add(new MenuButton(startGamePage, "Start Game")).RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { _doneWithName = true; } }); MenuPage mainPage = new MenuPage(150); mainPage.Add(new MenuButton(mainPage, "Start New Game", "icons/start_game.png")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h && Coroutine.Active.Count == 0) { Coroutine.Start(TransitionToStoryCoroutine); } }); mainPage.Add(new MenuButton(mainPage, "Load Game", "icons/load_game.png")); mainPage.Add(new MenuSpacer(4)); mainPage.Add(new MenuButton(mainPage, "Options", "icons/settings.png", "", "")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { OptionsUI.SwitchToOptionsPage(); } }); mainPage.Add(new MenuButton(mainPage, "Credits", "icons/credits.png", "", "")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { UI.SwitchPage("credits", false); } }); mainPage.Add(new MenuSpacer(4)); mainPage.Add(new MenuButton(mainPage, "Exit Game", "icons/arrow_left.png")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { Game.Exit(); } }); MenuPage creditsPage = new MenuPage(250); creditsPage.Add(new MenuLabel(creditsPage, "Age of Darkness " + Program.VERSION)); creditsPage.Add(new MenuLabel(creditsPage, "Made with MonoGame and Team STOR Engine")); creditsPage.Add(new MenuLabel(creditsPage, "")); creditsPage.Add(new MenuLabel(creditsPage, "Programming")); creditsPage.Add(new MenuLabel(creditsPage, "Hannes Mann", "", "", 0.8f)); creditsPage.Add(new MenuLabel(creditsPage, "")); creditsPage.Add(new MenuLabel(creditsPage, "Game Design and Art")); creditsPage.Add(new MenuLabel(creditsPage, "Kasper Kjällström", "", "", 0.8f)); creditsPage.Add(new MenuLabel(creditsPage, "Henrik Eriksson", "", "", 0.8f)); creditsPage.Add(new MenuSpacer(4)); creditsPage.Add(new MenuButton(creditsPage, "Back", "icons/arrow_left.png")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { UI.SwitchPage("main", true); } }); UI = new MenuUI(this, "main", mainPage, true); UI.AddPage("credits", creditsPage); UI.AddPage("start-game", startGamePage); OptionsUI = new MenuOptions(UI, "main"); UI.Toggle(); Game.IsMouseVisible = false; }
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(); }
public CombatMenu(CombatState combat) { AttackSlotAnimation = new TweenedDouble(combat.Game, 0); }
private TextBox(WorldState world, TextBoxContent content) { _world = world; _content = content; _offsetY = new TweenedDouble(world.Game, 1.0); }
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(); } }
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; }