private Vector2 _v2SelectionBoundInitial = s_v2OutOfBounds; //< Given points are in world-space. #endregion Fields #region Constructors public HUD(ViewRoot root) : base(root) { root.OnResize += () => { Size = Parent.Size; }; //< Force ourselves to remake our layout. OnInputButton += (eButton, bReleased) => { switch (eButton) { // Only interested in MouseA for selection purposes case Buttons.A: Selection (bReleased); break; case Buttons.B: IssueOrder(bReleased); break; } }; OnInputKey += (eKey, bRelease) => { switch (eKey) { case Keys.Escape: { if (!bRelease) break; root.Menu.Visible = true; } break; } }; OnInputWheel += delta => root.ViewZoom = MathEx.Clamp(root.ViewZoom + delta / 1440f, 1 / 4f, 1); Map = new Map (this); Crew = new CrewUI(this); }
public Menu(ViewRoot parent) : base(parent) { var families = ContentLoadAuto.Get<Menu, DMI>("Planet").Families; var planet = new PanelImage(this, families["planet"].Directions[0].Image(0)); planet.Size = new Vector2(527, 495); planet.Position = new Vector2(50, 100); _pnlEntries = new PanelList(this); _lblTitle = new Label(this, "Marooned", ContentLoadAuto.Get<Menu, SpriteFont>("Minecraftia_big")); _pnlCredits = new Credits(this); /// \note Assume mono-spaced font. var btnNewGame = new ButtonLabel(_pnlEntries, " New Game", ContentLoadAuto.Get<Menu, SpriteFont>("Minecraftia")); var btnOptions = new ButtonLabel(_pnlEntries, "Options ", ContentLoadAuto.Get<Menu, SpriteFont>("Minecraftia")); var btnCredits = new ButtonLabel(_pnlEntries, "Credits ", ContentLoadAuto.Get<Menu, SpriteFont>("Minecraftia")); var btnExit = new ButtonLabel(_pnlEntries, "Exit ", ContentLoadAuto.Get<Menu, SpriteFont>("Minecraftia")); btnNewGame.ContentsEncompass(); btnNewGame.ColourHovered.ValueActive = Color.Orange; btnOptions.ContentsEncompass(); btnOptions.ColourHovered.ValueActive = Color.Orange; btnCredits.ContentsEncompass(); btnCredits.ColourHovered.ValueActive = Color.Orange; btnExit .ContentsEncompass(); btnExit .ColourHovered.ValueActive = Color.Red; btnOptions.InputEnabledMouse = false; _lblTitle.ContentsEncompass(); _pnlEntries.Size = new Vector2(_pnlEntries.Select(p => p.Size.X).Max() ,_pnlEntries.Sum (p => p.Size.Y)); btnNewGame.OnClicked += (eButton) => { if (eButton != Buttons.A) return; parent.Game = new GameInfo(); Visible = false; }; btnExit .OnClicked += (eButton) => { if (eButton != Buttons.A) return; Marooned.Instance.Exit(); }; btnCredits.OnClicked += (eButton) => { ItsGameOverManGameOver(Credits.PlayType.GameOver); }; btnCredits.OnClickedDouble += (eButton) => { ItsGameOverManGameOver(Credits.PlayType.Success ); }; OnResize += () => LayoutInvalidate(); parent.OnResize += () => Size = parent.Size; OnVisibilityChanged += () => { if (Visible) { CellActive = null; if (parent.Game == null) return; CellActive = parent.Game.World.ActiveCell; parent.Game.World.ActiveCell = null; } else parent.Game.World.ActiveCell = CellActive ?? parent.Game.World.ActiveCell; }; OnInputKey += (eKey, bRelease) => { if (!bRelease ) return; if (eKey != Keys.Escape) return; if (_pnlCredits.Play != Credits.PlayType.None) { _pnlCredits.Play = Credits.PlayType.None; return; } if (parent.Game == null) return; Visible = false; }; }
protected override void LoadContent() { base.LoadContent(); _batch = new SpriteBatch(GraphicsDevice); TextureWhite = new Texture2D(GraphicsDevice, 1, 1); TextureGradient = new Texture2D(GraphicsDevice, 255, 1); var aryShades = new Color[255]; for (int i = 0; i < 255; ++i) aryShades[i] = new Color(Vector3.One * (i / 255f)); TextureWhite .SetData<Color>(new Color[] { Color.White }); TextureGradient.SetData<Color>(aryShades); if (ContentLoadUnload != null) ContentLoadUnload(true); ContentLoaded = true; View = new ViewRoot(); View.Size = new Vector2(Window.ClientBounds.Width, Window.ClientBounds.Height); snd_windLoop = Content.Load<SoundEffect>("sound/wind_loopable").CreateInstance(); snd_windLoop.IsLooped = true; snd_windLoop.Play(); }