//----------------------------------------------------------------------------- // Description //----------------------------------------------------------------------------- public void ResetDescription() { ISlotItem item = currentSlotGroup.CurrentSlot.SlotItem; description = FormatCodes.FormatString(item != null ? item.Name : ""); textPosition = 0; textTimer = 0; textStart = 0; if (!description.IsEmpty) { if (description.Length % 2 == 1) { description.Add(' '); } if (description.Length == 16) { description.Add(' '); textStart = 0; } else { for (int i = (8 - description.Length / 2); i > 0; i--) { description.Add(' '); } textStart = (16 - description.Length) * 8; } description.AddRange(FormatCodes.FormatString(item.Description)); } }
// Draws the scrolling item description at the bottom of the screen. public void DrawDescription(Graphics2D g) { int position = textPosition - textStart; int textIndex = position / 8; if (position < 0) { // Round down always. textIndex = (position - 7) / 8; position = ((position - 7) / 8) * 8; } else { position = (position / 8) * 8; } int startIndex = GMath.Max(0, textIndex); int endIndex = GMath.Clamp(textIndex + 16, 0, description.Length); LetterString text = description.Substring(startIndex, endIndex - startIndex); if (position < 0) { g.DrawLetterString(GameData.FONT_LARGE, text, new Point2I(16 - (position / 8) * 8, 108), new Color(16, 40, 88)); } else { g.DrawLetterString(GameData.FONT_LARGE, text, new Point2I(16, 108), new Color(16, 40, 88)); } }
//----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- public InventoryMenu(GameManager gameManager) : base(gameManager) { this.previousMenu = null; this.nextMenu = null; this.drawHUD = true; this.description = new LetterString(); this.textPosition = 0; this.textTimer = 0; this.textStart = 0; this.inSubMenu = false; }
// Draws a formatted game string at the specified position public void DrawLetterString(GameFont font, LetterString letterString, Point2I position, Color color, float depth = 0.0f) { for (int i = 0; i < letterString.Length; i++) { spriteBatch.Draw( font.SpriteSheet.Image, NewRect(new Rectangle2I( position.X + i * (font.SpriteSheet.CellSize.X + font.CharacterSpacing), position.Y, font.SpriteSheet.CellSize.X, font.SpriteSheet.CellSize.Y )), (Rectangle) new Rectangle2I( font.SpriteSheet.Offset.X + ((int)letterString[i].Char % font.CharactersPerRow) * (font.SpriteSheet.CellSize.X + font.SpriteSheet.Spacing.X), font.SpriteSheet.Offset.Y + ((int)letterString[i].Char / font.CharactersPerRow) * (font.SpriteSheet.CellSize.Y + font.SpriteSheet.Spacing.Y), font.SpriteSheet.CellSize.X, font.SpriteSheet.CellSize.Y ), (letterString[i].Color == Letter.DefaultColor ? color : letterString[i].Color), 0.0f, Vector2.Zero, SpriteEffects.None, depth ); } }
//----------------------------------------------------------------------------- // Strings //----------------------------------------------------------------------------- // Returns the wrapped and formatted string of the text. public WrappedLetterString WrapString(string text, int width) { List <LetterString> lines = new List <LetterString>(); List <int> lineLengths = new List <int>(); int currentLine = 0; int currentCharacter = 0; LetterString word = new LetterString(); int wordStart = 0; int wordLength = 0; int wordLineCount = 0; bool firstChar = true; LetterString letterString = FormatCodes.FormatString(text); while (currentCharacter < letterString.Length) { lines.Add(new LetterString()); lineLengths.Add(0); // Remove starting spaces in the line. while (letterString[currentCharacter].Char == ' ') { currentCharacter++; } wordStart = currentCharacter; word.Clear(); wordLength = 0; wordLineCount = 0; firstChar = true; do { if (currentCharacter >= letterString.Length || letterString[currentCharacter].Char == ' ' || letterString[currentCharacter].Char == FormatCodes.ParagraphCharacter || letterString[currentCharacter].Char == '\n') { if (wordLineCount > 0) { lines[currentLine].Add(' '); } lines[currentLine].AddRange(word); lineLengths[currentLine] += (wordLineCount > 0 ? (characterSpacing + spriteSheet.CellSize.X) : 0) + wordLength; wordLineCount++; wordLength = 0; wordStart = currentCharacter + 1; word.Clear(); if (currentCharacter < letterString.Length && (letterString[currentCharacter].Char == FormatCodes.ParagraphCharacter || letterString[currentCharacter].Char == '\n')) { if (letterString[currentCharacter].Char == FormatCodes.ParagraphCharacter) { lines[currentLine].Add(letterString[currentCharacter]); } currentCharacter++; break; } } else { word.Add(letterString[currentCharacter]); wordLength += (firstChar ? 0 : characterSpacing) + spriteSheet.CellSize.X; firstChar = false; } currentCharacter++; } while (lineLengths[currentLine] + wordLength + characterSpacing + spriteSheet.CellSize.X <= width); currentCharacter = wordStart; currentLine++; } WrappedLetterString wrappedString = new WrappedLetterString(); wrappedString.Lines = lines.ToArray(); wrappedString.LineLengths = lineLengths.ToArray(); wrappedString.Bounds = new Rectangle2I(width, (lines.Count - 1) * lineSpacing + spriteSheet.CellSize.Y); return(wrappedString); }