コード例 #1
0
        public static Sprite getSprite(int itemId, int itemAmount, int type)
        {
            if (type == 0)
            {
                Sprite sprite = (Sprite)spriteCache.get(itemId);
                if (sprite != null && sprite.maxHeight != itemAmount && sprite.maxHeight != -1)
                {
                    sprite.unlink();
                    sprite = null;
                }

                if (sprite != null)
                {
                    return(sprite);
                }
            }

            ItemDefinition definition = getDefinition(itemId);

            if (definition.stackableIds == null)
            {
                itemAmount = -1;
            }
            if (itemAmount > 1)
            {
                int stackedId = -1;
                for (int amount = 0; amount < 10; amount++)
                {
                    if (itemAmount >= definition.stackableAmounts[amount] && definition.stackableAmounts[amount] != 0)
                    {
                        stackedId = definition.stackableIds[amount];
                    }
                }

                if (stackedId != -1)
                {
                    definition = getDefinition(stackedId);
                }
            }

            Model model = definition.getAmountModel(1);

            if (model == null)
            {
                return(null);
            }
            Sprite noteSprite = null;

            if (definition.noteTemplateId != -1)
            {
                noteSprite = getSprite(definition.noteId, 10, -1);
                if (noteSprite == null)
                {
                    return(null);
                }
            }

            Sprite itemSprite     = new Sprite(32, 32);
            int    textureCentreX = Rasterizer.centreX;
            int    textureCentreY = Rasterizer.centreY;

            int[] lineOffsets = Rasterizer.lineOffsets;
            int[] pixels      = DrawingArea.pixels;
            int   width       = DrawingArea.width;
            int   height      = DrawingArea.height;
            int   topX        = DrawingArea.topX;
            int   bottomX     = DrawingArea.bottomX;
            int   topY        = DrawingArea.topY;
            int   bottomY     = DrawingArea.bottomY;

            Rasterizer.textured = false;
            DrawingArea.initDrawingArea(32, 32, itemSprite.pixels);
            DrawingArea.drawFilledRectangle(0, 0, 32, 32, 0);
            Rasterizer.setDefaultBounds();
            int zoom = definition.modelZoom;

            if (type == -1)
            {
                zoom = (int)(zoom * 1.5D);
            }
            if (type > 0)
            {
                zoom = (int)(zoom * 1.04D);
            }
            int l3 = Rasterizer.SINE[definition.modelRotationX] * zoom >> 16;
            int i4 = Rasterizer.COSINE[definition.modelRotationX] * zoom >> 16;

            model.renderSingle(definition.modelRotationY, definition.modelRotationZ, definition.modelRotationX,
                               definition.modelOffset1, l3 + model.modelHeight / 2 + definition.modelOffset2,
                               i4 + definition.modelOffset2);
            for (int _x = 31; _x >= 0; _x--)
            {
                for (int _y = 31; _y >= 0; _y--)
                {
                    if (itemSprite.pixels[_x + _y * 32] == 0)
                    {
                        if (_x > 0 && itemSprite.pixels[(_x - 1) + _y * 32] > 1)
                        {
                            itemSprite.pixels[_x + _y * 32] = 1;
                        }
                        else if (_y > 0 && itemSprite.pixels[_x + (_y - 1) * 32] > 1)
                        {
                            itemSprite.pixels[_x + _y * 32] = 1;
                        }
                        else if (_x < 31 && itemSprite.pixels[_x + 1 + _y * 32] > 1)
                        {
                            itemSprite.pixels[_x + _y * 32] = 1;
                        }
                        else if (_y < 31 && itemSprite.pixels[_x + (_y + 1) * 32] > 1)
                        {
                            itemSprite.pixels[_x + _y * 32] = 1;
                        }
                    }
                }
            }

            if (type > 0)
            {
                for (int _x = 31; _x >= 0; _x--)
                {
                    for (int _y = 31; _y >= 0; _y--)
                    {
                        if (itemSprite.pixels[_x + _y * 32] == 0)
                        {
                            if (_x > 0 && itemSprite.pixels[(_x - 1) + _y * 32] == 1)
                            {
                                itemSprite.pixels[_x + _y * 32] = type;
                            }
                            else if (_y > 0 && itemSprite.pixels[_x + (_y - 1) * 32] == 1)
                            {
                                itemSprite.pixels[_x + _y * 32] = type;
                            }
                            else if (_x < 31 && itemSprite.pixels[_x + 1 + _y * 32] == 1)
                            {
                                itemSprite.pixels[_x + _y * 32] = type;
                            }
                            else if (_y < 31 && itemSprite.pixels[_x + (_y + 1) * 32] == 1)
                            {
                                itemSprite.pixels[_x + _y * 32] = type;
                            }
                        }
                    }
                }
            }
            else if (type == 0)
            {
                for (int _x = 31; _x >= 0; _x--)
                {
                    for (int _y = 31; _y >= 0; _y--)
                    {
                        if (itemSprite.pixels[_x + _y * 32] == 0 && _x > 0 && _y > 0 &&
                            itemSprite.pixels[(_x - 1) + (_y - 1) * 32] > 0)
                        {
                            itemSprite.pixels[_x + _y * 32] = 0x302020;
                        }
                    }
                }
            }

            if (definition.noteTemplateId != -1)
            {
                int _maxWidth  = noteSprite.maxWidth;
                int _maxHeight = noteSprite.maxHeight;
                noteSprite.maxWidth  = 32;
                noteSprite.maxHeight = 32;
                noteSprite.drawImage(0, 0);
                noteSprite.maxWidth  = _maxWidth;
                noteSprite.maxHeight = _maxHeight;
            }

            if (type == 0)
            {
                spriteCache.put(itemSprite, itemId);
            }
            DrawingArea.initDrawingArea(height, width, pixels);
            DrawingArea.setDrawingArea(bottomY, topX, bottomX, topY);
            Rasterizer.centreX     = textureCentreX;
            Rasterizer.centreY     = textureCentreY;
            Rasterizer.lineOffsets = lineOffsets;
            Rasterizer.textured    = true;
            if (definition.stackable)
            {
                itemSprite.maxWidth = 33;
            }
            else
            {
                itemSprite.maxWidth = 32;
            }
            itemSprite.maxHeight = itemAmount;
            return(itemSprite);
        }
コード例 #2
0
 public void initDrawingArea()
 {
     DrawingArea.initDrawingArea(height, width, pixels);
 }
コード例 #3
0
ファイル: GameFont.cs プロジェクト: ts-data/RS317.Sharp
        /**
         * Draws a string, including a shadow behind it if specified.
         *
         * Used for interface drawing where the text could be shadowed but also could be
         * shadowless.
         *
         * @param text          The text to draw.
         *
         * @param x             The x position of the text.
         *
         * @param y             The y position of the text.
         *
         * @param currentColour The colour to draw the text.
         *
         * @param shadowed      Whether the text is shadowed or not.
         */
        public void drawTextWithPotentialShadow(String text, int x, int y, int currentColour, bool shadowed)
        {
            strikethrough = false;
            int originalX = x;

            if (String.IsNullOrWhiteSpace(text))
            {
                return;
            }

            /*
             * Draw from the top-left rather than the bottom.
             */
            y -= fontHeight;

            /*
             * Iterate through every character in the text.
             */
            for (int c = 0; c < text.Length; c++)
            {
                /*
                 * Check if the current piece of text being processed is a colour for (@dre@ for
                 * example)
                 */
                if (text[c] == '@' && c + 4 < text.Length && text[c + 4] == '@')
                {
                    int colour = handleEmbeddedEffect(text.Substring(c + 1, 3));
                    if (colour != -1)
                    {
                        currentColour = colour;
                    }
                    c += 4;
                }
                else
                {
                    char character = text[c];

                    /*
                     * If the character is a space, we don't need to draw it (but we do still offset
                     * the current x pointer using the glyph's width).
                     */
                    if (character != ' ')
                    {
                        /*
                         * If the text has a shadow, we draw the shadow at a slight offset and then draw
                         * the normal coloured text on top of it.
                         */
                        if (shadowed)
                        {
                            drawGlyph(glyphPixels[character], x + horizontalKerning[character] + 1,
                                      y + verticalKerning[character] + 1, glyphWidth[character], glyphHeight[character], 0);
                        }

                        drawGlyph(glyphPixels[character], x + horizontalKerning[character], y + verticalKerning[character],
                                  glyphWidth[character], glyphHeight[character], currentColour);
                    }

                    x += glyphDisplayWidth[character];
                }
            }

            /*
             * If the current piece of text has a strikethrough applied, draw a horizontal
             * line from the start of the text to the current position.
             */
            if (strikethrough)
            {
                DrawingArea.drawHorizontalLine(y + (int)(fontHeight * 0.7D), originalX, x - originalX, 0x800000);
            }
        }