Esempio n. 1
0
        public static void drawString(SpriteBatch b, string s, int x, int y, int characterPosition = 999999, int width = -1, int height = 999999, float alpha = 1f, float layerDepth = 0.88f, bool junimoText = false, int drawBGScroll = -1, string placeHolderScrollWidthText = "", int color = -1, ScrollTextAlignment scroll_text_alignment = ScrollTextAlignment.Left)
        {
            setUpCharacterMap();
            bool width_specified = true;

            if (width == -1)
            {
                width_specified = false;
                width           = Game1.graphics.GraphicsDevice.Viewport.Width - x;
                if (drawBGScroll == 1)
                {
                    width = getWidthOfString(s) * 2;
                }
            }
            if (fontPixelZoom < 4f && LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.ko)
            {
                y += (int)((4f - fontPixelZoom) * 4f);
            }
            Vector2 position = new Vector2(x, y);
            int     accumulatedHorizontalSpaceBetweenCharacters = 0;

            if (drawBGScroll != 1)
            {
                if (position.X + (float)width > (float)(Game1.graphics.GraphicsDevice.Viewport.Width - 4))
                {
                    position.X = Game1.graphics.GraphicsDevice.Viewport.Width - width - 4;
                }
                if (position.X < 0f)
                {
                    position.X = 0f;
                }
            }
            switch (drawBGScroll)
            {
            case 0:
            case 2:
            {
                int scroll_width = getWidthOfString((placeHolderScrollWidthText.Length > 0) ? placeHolderScrollWidthText : s);
                if (width_specified)
                {
                    scroll_width = width;
                }
                switch (drawBGScroll)
                {
                case 0:
                    b.Draw(Game1.mouseCursors, position + new Vector2(-12f, -3f) * 4f, new Rectangle(325, 318, 12, 18), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, layerDepth - 0.001f);
                    b.Draw(Game1.mouseCursors, position + new Vector2(0f, -3f) * 4f, new Rectangle(337, 318, 1, 18), Color.White * alpha, 0f, Vector2.Zero, new Vector2(scroll_width, 4f), SpriteEffects.None, layerDepth - 0.001f);
                    b.Draw(Game1.mouseCursors, position + new Vector2(scroll_width, -12f), new Rectangle(338, 318, 12, 18), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, layerDepth - 0.001f);
                    break;

                case 2:
                    b.Draw(Game1.mouseCursors, position + new Vector2(-3f, -3f) * 4f, new Rectangle(327, 281, 3, 17), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, layerDepth - 0.001f);
                    b.Draw(Game1.mouseCursors, position + new Vector2(0f, -3f) * 4f, new Rectangle(330, 281, 1, 17), Color.White * alpha, 0f, Vector2.Zero, new Vector2(scroll_width + 4, 4f), SpriteEffects.None, layerDepth - 0.001f);
                    b.Draw(Game1.mouseCursors, position + new Vector2(scroll_width + 4, -12f), new Rectangle(333, 281, 3, 17), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, layerDepth - 0.001f);
                    break;
                }
                switch (scroll_text_alignment)
                {
                case ScrollTextAlignment.Center:
                    x         += (scroll_width - getWidthOfString(s)) / 2;
                    position.X = x;
                    break;

                case ScrollTextAlignment.Right:
                    x         += scroll_width - getWidthOfString(s);
                    position.X = x;
                    break;
                }
                position.Y += (4f - fontPixelZoom) * 4f;
                break;
            }

            case 1:
            {
                int     text_width      = getWidthOfString((placeHolderScrollWidthText.Length > 0) ? placeHolderScrollWidthText : s);
                Vector2 speech_position = position;
                if (Game1.currentLocation != null && Game1.currentLocation.map != null && Game1.currentLocation.map.Layers[0] != null)
                {
                    int left_edge  = -Game1.viewport.X + 28;
                    int right_edge = -Game1.viewport.X + Game1.currentLocation.map.Layers[0].LayerWidth * 64 - 28;
                    if (position.X < (float)left_edge)
                    {
                        position.X = left_edge;
                    }
                    if (position.X + (float)text_width > (float)right_edge)
                    {
                        position.X = right_edge - text_width;
                    }
                    speech_position.X += text_width / 2;
                    if (speech_position.X < position.X)
                    {
                        position.X += speech_position.X - position.X;
                    }
                    if (speech_position.X > position.X + (float)text_width - 24f)
                    {
                        position.X += speech_position.X - (position.X + (float)text_width - 24f);
                    }
                    speech_position.X = Utility.Clamp(speech_position.X, position.X, position.X + (float)text_width - 24f);
                }
                b.Draw(Game1.mouseCursors, position + new Vector2(-7f, -3f) * 4f, new Rectangle(324, 299, 7, 17), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, layerDepth - 0.001f);
                b.Draw(Game1.mouseCursors, position + new Vector2(0f, -3f) * 4f, new Rectangle(331, 299, 1, 17), Color.White * alpha, 0f, Vector2.Zero, new Vector2(getWidthOfString((placeHolderScrollWidthText.Length > 0) ? placeHolderScrollWidthText : s), 4f), SpriteEffects.None, layerDepth - 0.001f);
                b.Draw(Game1.mouseCursors, position + new Vector2(text_width, -12f), new Rectangle(332, 299, 7, 17), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, layerDepth - 0.001f);
                b.Draw(Game1.mouseCursors, speech_position + new Vector2(0f, 52f), new Rectangle(341, 308, 6, 5), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, layerDepth - 0.0001f);
                x = (int)position.X;
                if (placeHolderScrollWidthText.Length > 0)
                {
                    x         += getWidthOfString(placeHolderScrollWidthText) / 2 - getWidthOfString(s) / 2;
                    position.X = x;
                }
                position.Y += (4f - fontPixelZoom) * 4f;
                break;
            }
            }
            if (LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko)
            {
                position.Y -= 8f;
            }
            s = s.Replace(Environment.NewLine, "");
            if (!junimoText && (LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ja || LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.zh || LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.th))
            {
                position.Y -= (4f - fontPixelZoom) * 4f;
            }
            s = s.Replace('♡', '<');
            for (int i = 0; i < Math.Min(s.Length, characterPosition); i++)
            {
                if (LocalizedContentManager.CurrentLanguageLatin || IsSpecialCharacter(s[i]) || junimoText || forceEnglishFont)
                {
                    float tempzoom = fontPixelZoom;
                    if (IsSpecialCharacter(s[i]) || junimoText || forceEnglishFont)
                    {
                        fontPixelZoom = 3f;
                    }
                    if (s[i] == '^')
                    {
                        position.Y += 18f * fontPixelZoom;
                        position.X  = x;
                        accumulatedHorizontalSpaceBetweenCharacters = 0;
                        fontPixelZoom = tempzoom;
                        continue;
                    }
                    accumulatedHorizontalSpaceBetweenCharacters = (int)(0f * fontPixelZoom);
                    bool    upper            = char.IsUpper(s[i]) || s[i] == 'ß';
                    Vector2 spriteFontOffset = new Vector2(0f, -1 + ((!junimoText && upper) ? (-3) : 0));
                    if (s[i] == 'Ç')
                    {
                        spriteFontOffset.Y += 2f;
                    }
                    if (positionOfNextSpace(s, i, (int)position.X - x, accumulatedHorizontalSpaceBetweenCharacters) >= width)
                    {
                        position.Y += 18f * fontPixelZoom;
                        accumulatedHorizontalSpaceBetweenCharacters = 0;
                        position.X = x;
                        if (s[i] == ' ')
                        {
                            fontPixelZoom = tempzoom;
                            continue;
                        }
                    }
                    b.Draw((color != -1) ? coloredTexture : spriteTexture, position + spriteFontOffset * fontPixelZoom, getSourceRectForChar(s[i], junimoText), ((IsSpecialCharacter(s[i]) || junimoText) ? Color.White : getColorFromIndex(color)) * alpha, 0f, Vector2.Zero, fontPixelZoom, SpriteEffects.None, layerDepth);
                    if (i < s.Length - 1)
                    {
                        position.X += 8f * fontPixelZoom + (float)accumulatedHorizontalSpaceBetweenCharacters + (float)getWidthOffsetForChar(s[i + 1]) * fontPixelZoom;
                    }
                    if (s[i] != '^')
                    {
                        position.X += (float)getWidthOffsetForChar(s[i]) * fontPixelZoom;
                    }
                    fontPixelZoom = tempzoom;
                    continue;
                }
                if (s[i] == '^')
                {
                    position.Y += (float)(FontFile.Common.LineHeight + 2) * fontPixelZoom;
                    position.X  = x;
                    accumulatedHorizontalSpaceBetweenCharacters = 0;
                    continue;
                }
                if (i > 0 && IsSpecialCharacter(s[i - 1]))
                {
                    position.X += 24f;
                }
                if (_characterMap.TryGetValue(s[i], out var fc))
                {
                    Rectangle sourcerect = new Rectangle(fc.X, fc.Y, fc.Width, fc.Height);
                    Texture2D _texture   = fontPages[fc.Page];
                    if (positionOfNextSpace(s, i, (int)position.X, accumulatedHorizontalSpaceBetweenCharacters) >= x + width - 4)
                    {
                        position.Y += (float)(FontFile.Common.LineHeight + 2) * fontPixelZoom;
                        accumulatedHorizontalSpaceBetweenCharacters = 0;
                        position.X = x;
                    }
                    Vector2 position2 = new Vector2(position.X + (float)fc.XOffset * fontPixelZoom, position.Y + (float)fc.YOffset * fontPixelZoom);
                    if (drawBGScroll != -1 && LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko)
                    {
                        position2.Y -= 8f;
                    }
                    if (LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ru)
                    {
                        Vector2 offset = new Vector2(-1f, 1f) * fontPixelZoom;
                        b.Draw(_texture, position2 + offset, sourcerect, getColorFromIndex(color) * alpha * shadowAlpha, 0f, Vector2.Zero, fontPixelZoom, SpriteEffects.None, layerDepth);
                        b.Draw(_texture, position2 + new Vector2(0f, offset.Y), sourcerect, getColorFromIndex(color) * alpha * shadowAlpha, 0f, Vector2.Zero, fontPixelZoom, SpriteEffects.None, layerDepth);
                        b.Draw(_texture, position2 + new Vector2(offset.X, 0f), sourcerect, getColorFromIndex(color) * alpha * shadowAlpha, 0f, Vector2.Zero, fontPixelZoom, SpriteEffects.None, layerDepth);
                    }
                    b.Draw(_texture, position2, sourcerect, getColorFromIndex(color) * alpha, 0f, Vector2.Zero, fontPixelZoom, SpriteEffects.None, layerDepth);
                    position.X += (float)fc.XAdvance * fontPixelZoom;
                }
            }
        }
Esempio n. 2
0
 public static void drawStringWithScrollBackground(SpriteBatch b, string s, int x, int y, string placeHolderWidthText = "", float alpha = 1f, int color = -1, ScrollTextAlignment scroll_text_alignment = ScrollTextAlignment.Left)
 {
     drawString(b, s, x, y, 999999, -1, 999999, alpha, 0.88f, junimoText: false, 0, placeHolderWidthText, color, scroll_text_alignment);
 }