Esempio n. 1
0
        /// <summary>
        /// Removes a menu entry from this menu.
        /// </summary>
        /// <param name="entry">The entry to remove.</param>
        /// <returns>True if the entry is successfully removed; otherwise, false.</returns>
        public bool RemoveEntry(MenuEntry entry)
        {
            MenuEntry selectedEntry = _entries[_selectedEntryAbs];
            bool      removed       = _entries.Remove(entry);

            if (removed)
            {
                bool visRemoved = _visibleEntries.Remove(entry);
                if (visRemoved)
                {
                    _entriesSprite.Remove(entry.Sprite);
                }
                if (entry == selectedEntry)
                {
                    SetSelected(0); // move the focus off the now-defunct entry
                }
                else
                {
                    _selectedEntryAbs = MathHelperExtensions.Clamp(_selectedEntryAbs - 1, 0, _entries.Count); // fix the index
                    if (visRemoved)
                    {
                        _selectedEntryRel = MathHelperExtensions.Clamp(_selectedEntryRel - 1, 0, _visibleEntries.Count);
                    }
                }
            }
            return(removed);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the selected menu item.
        /// </summary>
        /// <param name="deltaIdx">The change in selected index.</param>
        protected virtual void SetSelected(int deltaIdx)
        {
            int selected = _selectedEntryAbs;

            _entries[_selectedEntryAbs].OnFocusChanged(false);

            int nextRelEntry = _selectedEntryRel + deltaIdx;
            int nextAbsEntry = _selectedEntryAbs + deltaIdx;

            if (nextRelEntry >= _visibleEntries.Count && nextAbsEntry < _entries.Count)
            {
                HideEntry(_visibleEntries[0]);
                ShowEntry(_entries[nextAbsEntry], _visibleEntries.Count);
                LayoutEntries();
                _listWindowBaseIndex += 1;
            }
            else if (nextRelEntry < 0 && nextAbsEntry >= 0)
            {
                HideEntry(_visibleEntries[_visibleEntries.Count - 1]);
                ShowEntry(_entries[nextAbsEntry], 0);
                LayoutEntries();
                _listWindowBaseIndex -= 1;
            }

            _selectedEntryRel = MathHelperExtensions.Clamp(nextRelEntry, 0, _visibleEntries.Count - 1);
            _selectedEntryAbs = MathHelperExtensions.Clamp(nextAbsEntry, 0, _entries.Count - 1);

            if (_entries.Count > NumVisibleEntries)
            {
                _screenDescriptor.GetSprite("ArrowUp").Color =
                    (_listWindowBaseIndex == 0) ? Color.TransparentWhite : Color.White;
                _screenDescriptor.GetSprite("ArrowDown").Color =
                    (_listWindowBaseIndex == _entries.Count - NumVisibleEntries) ? Color.TransparentWhite : Color.White;
            }
            _screenDescriptor.GetSprite("Select").Color =
                _entries[_selectedEntryAbs].IsSelectable ? Color.White : Color.TransparentWhite;
            _screenDescriptor.GetSprite <TextSprite>("TextSelect").Text =
                _entries[_selectedEntryAbs].SelectText;

            _entries[_selectedEntryAbs].OnFocusChanged(true);

            if (selected != _selectedEntryAbs)
            {
                _soundMove.Play();
            }
        }
Esempio n. 3
0
        private void DrawPlayfield()
        {
            // Draw as many playfield lines as needed from the beatmap key amount setting
            for (int i = 0; i < Beatmap.Settings.Difficulty.KeyAmount; i++)
            {
                int x        = Skin.Settings.PlayfieldPositionX + Skin.PlayfieldLineTexture.Width * i;
                var destRect = new Rectangle(x, 0, Skin.PlayfieldLineTexture.Width, Settings.WindowHeight);

                _spriteBatch.Draw(Skin.PlayfieldLineTexture, destRect, Color.White);
            }

            // Draw buttons
            _spriteBatch.Draw(Skin.ButtonTexture,
                              new Vector2(Skin.Settings.PlayfieldPositionX,
                                          Settings.WindowHeight - Skin.ButtonTexture.Height),
                              Color.White);


            // Initialize health bar settings
            float hpX = Skin.Settings.PlayfieldPositionX +
                        Skin.PlayfieldLineTexture.Width * Beatmap.Settings.Difficulty.KeyAmount;
            float hpY = _game.Services.GetService <GameSettings>().WindowHeight;
            float hpW = 20; // TODO: Link to GameSettings

            // Draw health bar background
            _spriteBatch.Draw(Skin.HealthBarBg, new Vector2(hpX, hpY - Skin.HealthBarBg.Height), null, Color.White,
                              0.0f, Vector2.One, new Vector2(1.0f, 1.0f), SpriteEffects.None, 0.0f);

            var curVal = FindSystem <HealthSystem>().Health;
            var maxVal = FindSystem <HealthSystem>().MaxHealth;
            var minVal = FindSystem <HealthSystem>().MinHealth;

            // Set source rectangle for making health bar dynamic
            var srcRect = new Rectangle(0, 0, (int)hpW, (int)MathHelperExtensions.InBetween(Skin.HealthBar.Height, curVal, minVal, maxVal));

            // Interpolate color from Red (min health) to Green (max health)
            Color col = Color.Lerp(Color.Red, Color.Green, curVal / 100.0f);

            // Draw health bar
            // We should rotate the health bar by 180 degrees (PI in radians) because rectangle can't get negative height
            _spriteBatch.Draw(Skin.HealthBar, new Vector2(hpX, hpY), srcRect, col, (float)Math.PI, new Vector2(hpW, 0),
                              Vector2.One, SpriteEffects.None, 0.0f);
        }
Esempio n. 4
0
        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.Begin();

            if (ShouldDrawBackground)
            {
                var posOffset  = new Vector2(Position.X - 4, Position.Y - 4);
                var sizeOffset = new Size2(Size.Width + 8, Size.Height + 8);

                _spriteBatch.FillRectangle(posOffset, sizeOffset, Color.Gray);
                _spriteBatch.DrawRectangle(Position, Size, Color.Black);
            }
            else
            {
                _spriteBatch.DrawLine(new Vector2(Position.X, Position.Y + Size.Height),
                                      new Vector2(Position.X + Size.Width, Position.Y + Size.Height), Color.Black);
            }

            if (_nodes.Count > 0)
            {
                foreach (var node in _nodes)
                {
                    var pos = new Vector2(
                        Position.X + node.XOffset + _xOffset,
                        Position.Y - MathHelperExtensions.InBetween(Size.Height, node.Value, MinValue, MaxValue) + Size.Height
                        );

                    if (pos.X >= Position.X)
                    {
                        var rect = new RectangleF(pos - Vector2.UnitX * (CellSize.Width / 2),
                                                  new Size2(CellSize.Width, Size.Height * node.Value / (MaxValue - MinValue)));

                        var mousePos  = Mouse.GetState().Position.ToVector2();
                        var mouseRect = new RectangleF(mousePos, new Size2(1, 1));

                        if (new RectangleF(new Point2(Position.X + node.XOffset + _xOffset, Position.Y), new Size2(CellSize.Width, Size.Height)).Intersects(mouseRect))
                        {
                            if (ShouldDrawBars)
                            {
                                _spriteBatch.FillRectangle(rect, Color.Red);
                                _spriteBatch.DrawRectangle(rect, Color.Green);
                            }

                            if (Font != null)
                            {
                                _spriteBatch.FillRectangle(new Vector2(pos.X, Position.Y + Size.Height),
                                                           new Size2(node.Value.ToString(CultureInfo.CurrentCulture).Length * 10, 16), Color.Yellow);
                                _spriteBatch.DrawString(Font, node.Value.ToString(),
                                                        new Vector2(pos.X, Position.Y + Size.Height), Color.Black);
                            }

                            _spriteBatch.DrawPoint(pos, Color.Orange, 4f);
                        }
                        else
                        {
                            if (ShouldDrawBars)
                            {
                                _spriteBatch.FillRectangle(rect, Color.LightCyan);
                                _spriteBatch.DrawRectangle(rect, Color.Green);
                            }
                        }

                        if (node.Next != null)
                        {
                            var nextPos = new Vector2(
                                Position.X + node.Next.XOffset + _xOffset,
                                Position.Y - MathHelperExtensions.InBetween(Size.Height, node.Next.Value, MinValue, MaxValue) + Size.Height
                                );
                            _spriteBatch.DrawLine(pos, nextPos, Color.White);
                        }
                        _spriteBatch.DrawPoint(pos, Color.Red, 2f);
                    }
                }

                if (Font != null)
                {
                    _spriteBatch.DrawString(Font, $"Avg: {_nodes.Average(n => n.Value):F1}\nMin: {MinPushedValue:F1}\nMax: {MaxPushedValue:F1}",
                                            Position + Vector2.UnitY * Size.Height, Color.Black);
                }
            }

            _spriteBatch.End();

            base.Draw(gameTime);
        }