private void drawStoreMessage(Graphics g) // PRE: g must be initialized. // POST: Draws the store's dialogue box beneath the store image. { int x1; // Upper-left x coordinate. int y1; // Upper-left y coordinate. int x2; // Bottom-right x coordinate. int y2; // Bottom-right y coordinate. int width; // Width of dialogue box. int height; // Height of dialogue box. int numLines; // Number of lines in dialogue box. String message; // Message to be printed. x1 = ScaledPoint.scalerToX(storeMessagePos[0].getXScaler() + 0.01); y1 = ScaledPoint.scalerToY(storeMessagePos[0].getYScaler() + 0.01); x2 = ScaledPoint.scalerToX(storeMessagePos[1].getXScaler() - 0.01); y2 = ScaledPoint.scalerToY(storeMessagePos[1].getYScaler() - 0.01); width = x2 - x1; height = y2 - y1; Drawing.drawRoundedRect(g, storeMessagePos, Color.WHITE); switch (store) // change message based on value of store. { case 0: message = "If yer lookin' for a weapon, you've come to the right place."; break; case 1: message = "Welcome! You'll not find tougher steel elsewhere."; break; case 2: message = "Come! I guarantee you'll find something that catches your eye!"; break; case 3: message = "Some say that many of my goods are trash... They're right."; break; default: message = "I don't know how you got here..."; } numLines = 1; while (!(Drawing.drawWrappedString(g, message, numLines++, x1, y1, width, height))) ; // while we need more lines for the message }
private void drawBalance(Graphics g) // POST: Draws the balance of the current player { Font font; // Font used to draw balance String message; // Message for balance Color oldColor; // Sets for color int x1; // Upper-left x coordinate int y1; // Upper-left y coordinate int x2; // Bottom-right x coordinate int y2; // Bottom-right y coordinate int width; // Width of the dialogue box int height; // Height of the dialogue box int offset; // Offset so the dialogue box is positioned int balance; // Offset so the dialogue box is positioned User player; // User value for the player player = usersArray[0]; balance = player.getBalance(); oldColor = g.getColor(); x1 = ScaledPoint.scalerToX(0.72); y1 = ScaledPoint.scalerToY(0.81); x2 = ScaledPoint.scalerToX(0.88); y2 = ScaledPoint.scalerToY(0.86); width = x2 - x1; height = y2 - y1; message = "Balance:"; font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE); offset = (width - getFontMetrics(font).stringWidth(message)) / 2; g.setColor(Color.WHITE); g.drawString(message, x1 + offset, y2); x1 = ScaledPoint.scalerToX(0.72); y1 = ScaledPoint.scalerToY(0.865); x2 = ScaledPoint.scalerToX(0.88); y2 = ScaledPoint.scalerToY(0.915); width = x2 - x1; height = y2 - y1; message = "$" + Integer.toString(balance); font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE); offset = (width - getFontMetrics(font).stringWidth(message)) / 2; g.drawString(message, x1 + offset, y2); g.setColor(oldColor); }
private void drawPageIndicator(Graphics g) // PRE: g must be initialized. // POST: Draws a page indicator above the OK button. The filled in circle represents which // page we're currently on. { int x1; // First x coordinate for drawing area. int y1; // First y coordinate for drawing area. int x2; // Second x coordinate for drawing area. int y2; // Second y coordinate for drawing area. int width; // Width of drawing area. int height; // Height of drawing area. int offset; // Offset between circles. Graphics2D g2; // Graphics2D to change brush stroke. x1 = ScaledPoint.scalerToX(0.275); x2 = ScaledPoint.scalerToX(0.325); y1 = ScaledPoint.scalerToY(0.85); y2 = ScaledPoint.scalerToY(0.89); width = (x2 - x1) / 2; height = y2 - y1; offset = ScaledPoint.scalerToX(0.005) / 2; g2 = (Graphics2D) g; g2.setColor(Color.WHITE); g2.setStroke(new BasicStroke(1)); if (currentPage == 0) // if we are on the first page { g.fillOval(x1 - offset, y1, width, height); g.drawOval(x1 + width + offset, y1, width, height); } else // if we are on the second page. { g.drawOval(x1 - offset, y1, width, height); g.fillOval(x1 + width + offset, y1, width, height); } }