Esempio n. 1
0
        /// <summary> Draws the currently open <see cref="MenuObject"/>s on the screen </summary>
        /// <param name="game"> <see cref="Game"/> to draw to </param>
        /// <param name="sheet"> <see cref="Sprite"/> to use as a sheet </param>
        /// <param name="offset"> Offset on screen </param>
        public void Draw(Game game, Sprite sheet, Vector2Int?offset)
        {
            if (!Panels.Any())
            {
                return;
            }
            Vector2Int screenOffset = offset ?? Vector2Int.zero;

            foreach (var panel in Panels)
            {
                panel.Draw(game, sheet, screenOffset);
                screenOffset += WindowOffset;
            }

            Pixel.Mode previousPixelMode = game.PixelMode;
            game.PixelMode = Pixel.Mode.Mask;
            MenuObject last      = Panels.Last();
            Vector2Int patchSize = last.PatchSize;

            game.DrawPartialSprite(last.CursorPos, sheet, CURSOR_PATCH * patchSize, patchSize.x * 2, 2 * patchSize.y);
            game.PixelMode = previousPixelMode;
        }
Esempio n. 2
0
        /// <summary> Draws only this panel on the game's screen. </summary>
        /// <param name="game"> <see cref="Game"/> to draw to </param>
        /// <param name="sheet"> <see cref="Sprite"/> sheet to draw with </param>
        /// <param name="offset"> Optional offset on screen </param>
        public void Draw(Game game, Sprite sheet, Vector2Int?offset = null)
        {
            Vector2Int screenOffset = offset ?? Vector2Int.zero;
            Vector2Int one          = Vector2Int.one;

            Pixel.Mode previousPixelMode = game.PixelMode;
            game.PixelMode = Pixel.Mode.Mask;

            // Draw panel and border
            for (Vector2Int pp = Vector2Int.zero; pp.y < SizeInPatches.y; pp.y++)
            {
                for (pp.x = 0; pp.x < SizeInPatches.x; pp.x++)
                {
                    Vector2Int screenLocation = pp * PatchSize + screenOffset;
                    Vector2Int sourcePatch    = Vector2Int.zero;

                    if (pp.x > 0)
                    {
                        sourcePatch.x = (pp.x == SizeInPatches.x - 1) ? 2 : 1;
                    }
                    if (pp.y > 0)
                    {
                        sourcePatch.y = (pp.y == SizeInPatches.y - 1) ? 2 : 1;
                    }

                    game.DrawPartialSprite(screenLocation, sheet, sourcePatch * PatchSize, PatchSize.x, PatchSize.y);
                }
            }

            int topLeft     = TopVisibleRow * Table.x;
            int bottomRight = Math.Min(Table.y * Table.x + topLeft, Items.Count);

            int visibleItems = bottomRight - topLeft;

            if (TopVisibleRow > 0)
            {
                Vector2Int screenLocation = new Vector2Int(SizeInPatches.x - 2, 0) * PatchSize + screenOffset;
                game.DrawPartialSprite(screenLocation, sheet, UP_SCROLL_PATCH * PatchSize, PatchSize.x, PatchSize.y);
            }
            if ((TotalRows - TopVisibleRow) > Table.y)
            {
                Vector2Int screenLocation = new Vector2Int(SizeInPatches.x - 2, SizeInPatches.y - 1) * PatchSize + screenOffset;
                game.DrawPartialSprite(screenLocation, sheet, DOWN_SCROLL_PATCH * PatchSize, PatchSize.x, PatchSize.y);
            }

            for (int i = 0; i < visibleItems; i++)
            {
                Vector2Int cell           = new Vector2Int(i % Table.x, i / Table.x);
                Vector2Int patchPosition  = cell * (Size + Padding) + one;
                Vector2Int screenLocation = patchPosition * PatchSize + screenOffset;

                var item = Items[topLeft + i];
                game.DrawText(screenLocation, item.Name, item.Enabled ? Pixel.Presets.White : Pixel.Presets.DarkGrey);

                if (item.HasChildren)
                {
                    patchPosition    = cell * (Size + Padding) + one;
                    patchPosition.x += Size.x;
                    screenLocation   = patchPosition * PatchSize + screenOffset;
                    game.DrawPartialSprite(screenLocation, sheet, EXPAND_PATCH * PatchSize, PatchSize.x, PatchSize.y);
                }
            }

            CursorPos    = new Vector2Int(Cursor.x, Cursor.y - TopVisibleRow) * (Size + Padding) * PatchSize + screenOffset;
            CursorPos.x -= PatchSize.x;
            CursorPos.y += PatchSize.x;


            game.PixelMode = previousPixelMode;
        }