/* * Draws menu header (logo and particles) */ private void drawMenuHeader(Graphics g) { g.setFont(Fonts.largefont); FontMetrics fm = g.getFontMetrics(); g.setColor(Color.YELLOW); // Draw logo Image img = game.imgs[0]; g.drawImage(img, (winSize.width - img.getWidth(null)) / 2, 30, null); g.setFont(Fonts.smallfont); fm = g.getFontMetrics(); g.drawString("by Ben Homer", 10, winSize.height - 20); if (DBClient.loggedIn) { g.drawString("Logged in as: " + DBClient.getName(), 10, 30); } }
private void handleSubMenuClick(int i) { if (i == 0) { // back button centralBox.setFinalPos(new Vector2D(boxs[0].getPos().x, boxs[0].getPos().y + Box.size)); centralBox.setFinalSize(Box.size, Box.size); centralBox.setImageVisible(true); // No longer draw submenu drawSubmenuScreen = -1; setTextBoxesVisible(false); // Special text cases i.e. depending on logged in/out // TODO: set up arrays for altTxt in different languages if (currSubMenu == Menu.CONNECTIVITY && DBClient.loggedIn) { subBoxs[0].setText("Sign out"); } // If going back from find opponent screen then remove player from waiting table if (currSubMenu == Menu.MAIN) { DBClient.removeFromWaitingTable(); } } else { switch (currMenu) { case MAIN: // Find opponent 'play' button pressed DBClient.createNewGame(); game.gameType = Game.ONLINE_MULTI; game.rPlayerTurn = true; game.startNewGame(); break; case OPTIONS: switch (currSubMenu) { case GENERAL: switch (drawSubmenuScreen) { // Sound case 0: switch (i) { case 1: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.sound = true; SoundManager.unmute(); break; case 2: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.sound = false; SoundManager.mute(); break; } break; // Language case 1: switch (i) { case 1: txt = english; break; case 2: txt = french; break; } changeLanguage(); break; // Animation case 2: switch (i) { case 1: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.animation = true; break; case 2: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.animation = false; } break; } break; case CONNECTIVITY: switch (drawSubmenuScreen) { // Login case 0: // TODO: encrpyt pass in db switch (i) { // Checkbox case 1: subMenuBoxs[1].invertChecked(); break; case 2: if (subMenuBoxs[1].isChecked()) { if (DBClient.newUser(textFields[0].getText(), textFields[1].getText())) handleSubMenuClick(0); } else { if (DBClient.tryLogin(textFields[0].getText(), textFields[1].getText())) handleSubMenuClick(0); } break; } break; } break; } break; } } }
/* * Called when submenu option is selected. Moves to submenu specific screen */ private void submenuSelected(int i) { // TODO:THIS METHOD GETS CALLED WHEN SUBMENU OPTION IS SELECTED // Use currMenu, currSubMenu and i (index of button clicked) to perform correct action // TODO: DO PROPERLY centralBox.setFinalPos(centralBoxSubmenuPos); centralBox.setFinalSize(2 * Box.size, 2 * Box.size); centralBox.setImageVisible(false); Vector2D p = centralBoxSubmenuPos; // Set all suboxes invisible (except for back button) for (int j = 1; j < NUM_SUB_BOXES; j++) { subMenuBoxs[j].reset(); } // TODO: update positions on subMenuBoxs here switch (currMenu) { case MAIN: // Find opponent if (DBClient.loggedIn) { if (DBClient.matchWithOpponent()) { int s = 30; int y = (int) (centralBoxSubmenuPos.y + 20); subMenuBoxs[1] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x, y)) .setSizeBoth(Box.size, 30) .onlyShowText(true) .setText(DBClient.getName()); subMenuBoxs[2] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x, y + s)) .setSizeBoth(Box.size, 30) .onlyShowText(true) .setText(String.valueOf(DBClient.getRanking())); subMenuBoxs[3] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + Box.size / 2, y + s / 2)) .setSizeBoth(Box.size, 30) .onlyShowText(true) .setText("VS"); subMenuBoxs[4] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + Box.size, y)) .setSizeBoth(Box.size, 30) .onlyShowText(true) .setText(DBClient.getOpponentName()); subMenuBoxs[5] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + Box.size, y + s)) .setSizeBoth(Box.size, 30) .onlyShowText(true) .setText(String.valueOf(DBClient.getOpponentRanking())); subMenuBoxs[6] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x, y + 4 * s)) .setSizeBoth(Box.size * 2, 30) .setText("PLAY"); } else { subMenuBoxs[1] .setVisible(true) .setPosBoth( new Vector2D( (int) centralBoxSubmenuPos.x + 20, (int) centralBoxSubmenuPos.y + 20)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Waiting for opponent..."); } } else { subMenuBoxs[1] .setVisible(true) .setPosBoth( new Vector2D( (int) centralBoxSubmenuPos.x + 20, (int) centralBoxSubmenuPos.y + 20)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("You must login before you can find an opponent"); } break; case OPTIONS: switch (currSubMenu) { case GENERAL: switch (i) { // Sound case 0: subMenuBoxs[1] .setVisible(true) .setPosBoth(new Vector2D(p.x + 20, p.y + 50)) .setSizeBoth(Box.iconSize, Box.iconSize) .setToCheckbox(game.imgs[4], game.imgs[5]); subMenuBoxs[2] .setVisible(true) .setPosBoth(new Vector2D(p.x + 2 * Box.size - 20 - Box.iconSize, p.y + 50)) .setSizeBoth(Box.iconSize, Box.iconSize) .setToCheckbox(game.imgs[4], game.imgs[5]); subMenuBoxs[3] .setVisible(true) .setPosBoth(new Vector2D(p.x + 20, p.y + 80)) .setSizeBoth(Box.iconSize, Box.iconSize) .onlyShowText(true) .setText("ON"); subMenuBoxs[4] .setVisible(true) .setPosBoth(new Vector2D(p.x + 2 * Box.size - 20 - Box.iconSize, p.y + 80)) .setSizeBoth(Box.iconSize, Box.iconSize) .onlyShowText(true) .setText("OFF"); int n = (game.sound) ? 1 : 2; subMenuBoxs[n].invertChecked(); break; // Language case 1: // Sets positions of sub menu boxes for (int j = 0; j < NUM_LANGUAGES; j++) { subMenuBoxs[j + 1] .setVisible(true) .setText(langs[j]) .setSizeBoth(Box.iconSize, Box.iconSize) .setPosBoth( new Vector2D( p.x + Box.iconSize + 2 * ((j) % 3) * Box.iconSize, p.y + Box.iconSize + 2 * (j / 3) * Box.iconSize)); } // Animation case 2: subMenuBoxs[1] .setVisible(true) .setPosBoth(new Vector2D(p.x + 20, p.y + 50)) .setSizeBoth(Box.iconSize, Box.iconSize) .setToCheckbox(game.imgs[4], game.imgs[5]); subMenuBoxs[2] .setVisible(true) .setPosBoth(new Vector2D(p.x + 2 * Box.size - 20 - Box.iconSize, p.y + 50)) .setSizeBoth(Box.iconSize, Box.iconSize) .setToCheckbox(game.imgs[4], game.imgs[5]); subMenuBoxs[3] .setVisible(true) .setPosBoth(new Vector2D(p.x + 20, p.y + 80)) .setSizeBoth(Box.iconSize, Box.iconSize) .onlyShowText(true) .setText("ON"); subMenuBoxs[4] .setVisible(true) .setPosBoth(new Vector2D(p.x + 2 * Box.size - 20 - Box.iconSize, p.y + 80)) .setSizeBoth(Box.iconSize, Box.iconSize) .onlyShowText(true) .setText("OFF"); int m = (game.animation) ? 1 : 2; subMenuBoxs[m].invertChecked(); break; } break; case CONNECTIVITY: switch (i) { // Sign in case 0: // TODO: Setup login screen w/ tickbox for new users textFields[0].setText("username"); textFields[0].setBackground(Color.BLUE); textFields[0].setForeground(Color.WHITE); textFields[0].setBounds( (int) centralBoxSubmenuPos.x + 20, (int) centralBoxSubmenuPos.y + 20, Box.size * 2 - 40, 30); textFields[1].setText("password"); textFields[1].setBackground(Color.BLUE); textFields[1].setForeground(Color.WHITE); textFields[1].setBounds( (int) centralBoxSubmenuPos.x + 20, (int) centralBoxSubmenuPos.y + 100, Box.size * 2 - 40, 30); subMenuBoxs[1] .setVisible(true) .setPosBoth(new Vector2D(p.x + 20, p.y + 150)) .setSizeBoth(Box.iconSize, Box.iconSize) .setToCheckbox( game.imgs[4], game.imgs[ 5]); // setSizeBoth(Box.size*2-40, 30).setText("Login as new user"); subMenuBoxs[2] .setVisible(true) .setPosBoth(new Vector2D(p.x + 20, p.y + 210)) .setSizeBoth(Box.size * 2 - 40, 30) .setText("LOGIN"); subMenuBoxs[3] .setVisible(true) .setPosBoth(new Vector2D(p.x + 50, p.y + 155)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Check to login as new player"); break; // Player stats case 1: if (DBClient.loggedIn) { int s = 30; int y = (int) (centralBoxSubmenuPos.y + 20); int[] wdl = DBClient.getWDL(); subMenuBoxs[1] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + 20, y)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Player name: " + DBClient.getName()); subMenuBoxs[2] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + 20, y += s)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Highscore: " + DBClient.getHighscore()); subMenuBoxs[3] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + 20, y += s)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Wins: " + wdl[0]); subMenuBoxs[4] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + 20, y += s)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Draws: " + wdl[1]); subMenuBoxs[5] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + 20, y += s)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Losses: " + wdl[2]); subMenuBoxs[6] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + 20, y += s)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("Last login: "******"Ranking: " + DBClient.getRanking()); } else { subMenuBoxs[1] .setVisible(true) .setPosBoth( new Vector2D( (int) centralBoxSubmenuPos.x + 20, (int) centralBoxSubmenuPos.y + 20)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText("You must login before you can see player stats"); } break; // Friends case 2: break; // Highscores/rankings case 3: LinkedHashMap<String, Integer> hsTable = DBClient.getHighScoreTable(); Set<String> names = hsTable.keySet(); int n = 0; int s = 20; int y = (int) (centralBoxSubmenuPos.y - 10); for (String name : names) { subMenuBoxs[++n] .setVisible(true) .setPosBoth(new Vector2D((int) centralBoxSubmenuPos.x + 20, y += s)) .setSizeBoth(Box.size * 2 - 40, 30) .onlyShowText(true) .setText(n + ". " + name + " - " + hsTable.get(name)); } break; } break; } break; } drawSubmenuScreen = i; }