static void setupMenu(void) { clearMenuItems(); if (state == STATE_PLAYING) { addMenuItem(F("CONTINUE"), onMenuContine); } addMenuItem(F("RESTART"), onMenuRestart); int menuW; if (gameMode == GAME_MODE_PUZZLE) { if (issue < COUNT_ISSUES - 1) addMenuItem(F("NEXT ISSUE"), onMenuNextIssue); if (issue > 0) addMenuItem(F("PREV ISSUE"), onMenuPreviousIssue); addMenuItem(F("ISSUES LIST"), onMenuSelectIssue); menuW = 77; } else { addMenuItem(F("BACK TO TITLE"), onMenuBackToTitle); menuW = 89; } int menuH = getMenuItemCount() * 6 - 1; int menuY; bool flg; if (state == STATE_OVER) { menuY = 53; flg = false; state = STATE_RESULT; } else { menuY = 31 - menuH / 2; flg = true; state = STATE_MENU; } setMenuCoords(63 - menuW / 2, menuY, menuW, menuH, flg, flg); setMenuItemPos(0); playSoundClick(); }
void PlayerMenuUserInterface::playerSelected(U32 index) const { // When we created the menu, names were not sorted, and item indices were assigned in "natural order". Then // the menu items were sorted by name, and now the indices are now jumbled. This bit here tries to get the // new, actual list index of an item given its original index. for(S32 i = 0; i < getMenuItemCount(); i++) if(getMenuItem(i)->getIndex() == (S32)index) { index = i; break; } GameType *gt = getGame()->getGameType(); if(action == PlayerActionChangeTeam) { TeamMenuUserInterface *ui = getUIManager()->getUI<TeamMenuUserInterface>(); ui->mNameToChange = getMenuItem(index)->getPrompt(); getUIManager()->activate<TeamMenuUserInterface>(); // Show menu to let player select a new team } else if(gt) // action == Kick gt->c2sKickPlayer(getMenuItem(index)->getPrompt()); if(action != PlayerActionChangeTeam) // Unless we need to move on to the change team screen... getUIManager()->reactivateGameUI(); // ...it's back to the game! }
// Return index of next level starting with specified string; if none exists, returns current index. // If startingWith is only one character, the entry we're looking for could be behind us. See tests // for examples of this. S32 ItemListSelectUserInterface::getIndexOfNext(const string &startingWithLc) const { TNLAssert(startingWithLc.length() > 0, "Did not expect an empty string here!"); TNLAssert(startingWithLc == lcase(startingWithLc), "Expected a lowercased string here"); bool first = true; bool multiChar = startingWithLc.length() > 1; S32 offset = multiChar ? 0 : 1; // Loop until we hit the end of the list, or we hit an item that sorts > our startingString (meaning we overshot). // But we only care about overshoots in multiChar mode because there could well be single-char hits behind us in the list. while(true) { if(mSelectedIndex + offset >= getMenuItemCount()) // Hit end of list -- loop to beginning offset = -mSelectedIndex; string prospectiveItem = lcase(getMenuItem(mSelectedIndex + offset)->getValue()); if(prospectiveItem.substr(0, startingWithLc.size()) == startingWithLc) return mSelectedIndex + offset; if(offset == 0 && !first) break; offset++; first = false; } // Found no match; return current index return mSelectedIndex; }
void GameParamUserInterface::updateMenuItems(const GameType *gameType) { TNLAssert(gameType, "Missing game type!"); string filename = mLevelFilename; // Grab the level filename from the menuitem if it has been built already. // This let's us persist a changed filename without having to leave the menu first if(getMenuItemCount() > 0) filename = getMenuItem(1)->getValue(); clearMenuItems(); // Note that on some gametypes instructions[1] is NULL string instructs = string(gameType->getInstructionString()[0]) + (gameType->getInstructionString()[1] ? string(" ") + gameType->getInstructionString()[1] : ""); addMenuItem(new ToggleMenuItem("Game Type:", getGameTypes(), getGameTypes().getIndex(gameType->getGameTypeName()), true, changeGameTypeCallback, instructs)); addMenuItem(new TextEntryMenuItem("Filename:", // name filename, // val EditorUserInterface::UnnamedFile, // empty val "File where this level is stored", // help MAX_FILE_NAME_LEN)); const Vector<string> *keys = gameType->getGameParameterMenuKeys(); for(S32 i = 0; i < keys->size(); i++) { MenuItemMap::iterator iter = mMenuItemMap.find(keys->get(i)); boost::shared_ptr<MenuItem> menuItem; if(iter != mMenuItemMap.end()) // What is this supposed to do? I can't seem to make this condition occur. menuItem = iter->second; else // Item not found { menuItem = gameType->getMenuItem(keys->get(i)); TNLAssert(menuItem, "Failed to make a new menu item!"); mMenuItemMap.insert(pair<string, boost::shared_ptr<MenuItem> >(keys->get(i), menuItem)); } addWrappedMenuItem(menuItem); } }