// Properly set up and execute a chat command for the given client. This simulates the user hitting enter after // typing their command, including creating and dismissing the chat helper. void GamePair::runChatCmd(S32 clientIndex, const string &command) { GameUserInterface *ui = getGameUI(clientIndex); ui->activateHelper(HelperMenu::ChatHelperType, false); // Need this active when entering chat cmd ChatHelper *helper = dynamic_cast<ChatHelper *>(ui->mHelperManager.mHelperStack.last()); ASSERT_TRUE(helper) << "Where is our helper?"; helper->mLineEditor.setString(command); helper->mCurrentChatType = ChatHelper::GlobalChat; helper->issueChat(); }
// I think this function is broken... if you are in UIQueryServers, you don't get your message! // TODO: Verify or fix!!! RAPTOR! void AbstractChat::deliverPrivateMessage(const char *sender, const char *message) { // If player not in UIChat or UIQueryServers, then display message in-game if possible. 2 line message. if(!mGame->getUIManager()->isCurrentUI<QueryServersUserInterface>()) { GameUserInterface *gameUI = mGame->getUIManager()->getUI<GameUserInterface>(); gameUI->onChatMessageReceived(Colors::privateF5MessageDisplayedInGameColor, "Private message from %s: Press [%s] to enter chat mode", sender, gameUI->getInputCodeString(BINDING_LOBBYCHAT)); gameUI->onChatMessageReceived(Colors::privateF5MessageDisplayedInGameColor, "%s %s", ARROW, message); } }
void GamePair::sendKeyPress(S32 clientIndex, InputCode inputCode) { GameUserInterface *ui = getGameUI(clientIndex); ui->onKeyDown(inputCode); }
TEST(GameUserInterfaceTest, Engineer) { InputCodeManager::initializeKeyNames(); GamePair gamePair(getLevelCodeForTestingEngineer1(), 3); // See def for description of level ServerGame *serverGame = GameManager::getServerGame(); const Vector<ClientGame *> *clientGames = GameManager::getClientGames(); GameSettings *clientSettings = clientGames->first()->getSettings(); GameUserInterface *gameUI = clientGames->first()->getUIManager()->getUI<GameUserInterface>(); DEFINE_KEYS_AND_EVENTS(clientSettings); // Idle for a while, let things settle GamePair::idle(10, 5); // Verify that engineer is enabled ASSERT_TRUE(serverGame->getGameType()->isEngineerEnabled()) << "Engineer should be enabled on server!"; for(S32 i = 0; i < clientGames->size(); i++) { SCOPED_TRACE("i = " + itos(i)); ASSERT_TRUE(clientGames->get(i)->getGameType()) << "Clients should have a GameType by now!"; ASSERT_TRUE(clientGames->get(i)->getGameType()->isEngineerEnabled()) << "Engineer mode not propagating to clients!"; } ASSERT_TRUE(serverGame->getClientInfo(0)->getShip()->isInZone(LoadoutZoneTypeNumber)); // Check level is as we expected // Add engineer to current loadout ASSERT_FALSE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gameUI->activateHelper(HelperMenu::LoadoutHelperType); ASSERT_TRUE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gameUI->onKeyDown(LOADOUT_KEY_ENGR); gameUI->onKeyDown(LOADOUT_KEY_REPAIR); // First 2 modules... gameUI->onKeyDown(LOADOUT_KEY_PHASER); gameUI->onKeyDown(LOADOUT_KEY_BOUNCE); gameUI->onKeyDown(LOADOUT_KEY_TRIPLE); // ...then 3 weapons // On this level, the ship spawn is inside a loadout zone, so loadout should take effect immediately GamePair::idle(10, 5); ASSERT_EQ("Engineer,Repair,Phaser,Bouncer,Triple", serverGame->getClientInfo(0)->getShip()->getLoadoutString()); for(S32 i = 0; i < clientGames->size(); i++) { SCOPED_TRACE("i = " + itos(i)); ASSERT_EQ("Engineer,Repair,Phaser,Bouncer,Triple", clientGames->get(0)->getLocalPlayerShip()->getLoadoutString()); } // Fly down to pick up resource item -- to get flying to work, need to create events at a very basic level ClientGame *clientGame = clientGames->get(0); Point startPos = clientGame->getLocalPlayerShip()->getActualPos(); Event::onEvent(clientGame, &EventDownPressed); GamePair::idle(100, 5); Event::onEvent(clientGame, &EventDownReleased); Point endPos = clientGame->getLocalPlayerShip()->getActualPos(); ASSERT_TRUE(startPos.distSquared(endPos) > 0) << "Ship did not move!!"; for(S32 i = 0; i < clientGames->size(); i++) { SCOPED_TRACE("i = " + itos(i)); ASSERT_TRUE(clientGames->get(0)->getLocalPlayerShip()->isCarryingItem(ResourceItemTypeNumber)); } // Time to engineer! gameUI->onKeyDown(KEY_MOD1); ASSERT_TRUE(gameUI->isHelperActive(HelperMenu::EngineerHelperType)) << "Expect engineer helper menu to be active!"; InputCode key = EngineerHelper::getInputCodeForOption(EngineeredTeleporterEntrance, true); gameUI->onKeyDown(key); ASSERT_FALSE(static_cast<const EngineerHelper *>(gameUI->getActiveHelper())->isMenuBeingDisplayed()); gameUI->onKeyDown(KEY_MOD1); // Place entrance gameUI->onKeyDown(KEY_MOD1); // Place exit GamePair::idle(100, 5); // Let things mellow for(S32 i = 0; i < clientGames->size(); i++) { SCOPED_TRACE("i = " + itos(i)); Vector<DatabaseObject *> fillVector; clientGames->get(i)->getLevel()->findObjects(TeleporterTypeNumber, fillVector); EXPECT_EQ(1, fillVector.size()) << "Expected a teleporter!"; } }
// Scenario 11 -- Player is editing loadout when level changes --> TEST NOT COMPLETE!!!! static void doScenario11(GamePair &gamePair) { ClientGame *clientGame = gamePair.getClient(0); ServerGame *serverGame = gamePair.server; serverGame->setGameTime(.5); // 30 seconds GameUserInterface *gameUI = clientGame->getUIManager()->getUI<GameUserInterface>(); ASSERT_FALSE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gameUI->activateHelper(HelperMenu::LoadoutHelperType); ASSERT_TRUE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); ASSERT_EQ("", serverGame->getClientInfo(0)->getOnDeckLoadout().toString(true)); // Prove there's no on deck loadout // See static const OverlayMenuItem loadoutModuleMenuItems[] in loadoutHelper.cpp // Feed the UI some keys... like we're configuring a loadout! gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_3); // First 2 modules... gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_2); gameUI->onKeyDown(KEY_3); // ...then 3 weapons ASSERT_FALSE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gamePair.idle(10, 10); // Check the on deck loadout on server -- does not get set on the client ASSERT_EQ("Turbo,Repair,Phaser,Bouncer,Triple", serverGame->getClientInfo(0)->getOnDeckLoadout().toString(true)); gameUI->activateHelper(HelperMenu::LoadoutHelperType); ASSERT_TRUE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gamePair.idle(100, 350); // Idle until game ends gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_4); gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_2); gameUI->onKeyDown(KEY_3); ASSERT_FALSE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gamePair.idle(10, 10); ASSERT_EQ("Turbo,Sensor,Phaser,Bouncer,Triple", serverGame->getClientInfo(0)->getOnDeckLoadout().toString(true)); }