public void draw(SpriteBatchWrapper sprites) { if (!this.listening) return; this.drawGlassPane(sprites); Vector2 center = sprites.getCenterOfScreen(); int boxWidth = 500; int boxHeight = 150; int boxX = (int)(center.X - (boxWidth / 2)); int boxY = (int)(center.Y - (boxHeight / 2)); this.drawBox(sprites, boxWidth, boxHeight, boxX, boxY); if (null != this.message) { int msgHeight = sprites.getHeightOfText(this.message, 1.0f, MESSAGE_FONT_NAME); int msgWidth = sprites.getWidthOfText(this.message, 1.0f, MESSAGE_FONT_NAME); int msgY = boxY + (boxHeight / 4) - (msgHeight / 2); int msgX = (int) center.X - (msgWidth / 2); sprites.drawTextAt(this.message, msgX, msgY, 1.0f, Color.LightGray, MESSAGE_FONT_NAME); } this.drawTextBox(sprites, center, boxWidth); }
private void drawTextBox(SpriteBatchWrapper sprites, Vector2 center, int boxWidth) { int textboxWidth = (boxWidth * 8) / 10; int textHeight = sprites.getHeightOfText("Foo", 1.0f, INPUT_FONT_NAME); int textBoxHeight = textHeight + (textHeight / 5); int textboxX = (int) center.X - ((boxWidth * 4) / 10); int textX = textboxX + 15; int textboxY = (int) center.Y; int textY = textboxY + (textHeight / 10); int visibleChars = 32; sprites.drawColorAt(Color.Black, 1.0f, textboxWidth, textBoxHeight, textboxX, textboxY); String textToDraw = this.text; bool cutoff = this.text.Length > visibleChars; if (cutoff) { textToDraw = this.text.Substring( this.text.Length - visibleChars); sprites.drawColorAt(Color.Orange, 1.0f, 5, textBoxHeight, textboxX, textboxY); } if (this.showCursor) { textToDraw += "_"; } sprites.drawTextAt(textToDraw, textX, textY, 1.0f, Color.Orange, INPUT_FONT_NAME); }