[Orxonox-commit 3183] r7876 - in code/trunk: data/gui/scripts src/libraries/core src/orxonox/gamestates
dafrick at orxonox.net
dafrick at orxonox.net
Sun Feb 13 17:49:43 CET 2011
Author: dafrick
Date: 2011-02-13 17:49:41 +0100 (Sun, 13 Feb 2011)
New Revision: 7876
Modified:
code/trunk/data/gui/scripts/HostMenu.lua
code/trunk/data/gui/scripts/MultiplayerMenu.lua
code/trunk/data/gui/scripts/SingleplayerMenu.lua
code/trunk/src/libraries/core/GUIManager.cc
code/trunk/src/orxonox/gamestates/GSLevel.cc
code/trunk/src/orxonox/gamestates/GSLevel.h
code/trunk/src/orxonox/gamestates/GSMainMenu.cc
code/trunk/src/orxonox/gamestates/GSMainMenu.h
Log:
Extending startGame and similar console commands, now also the level to be started (or in case of startClient, the destination) can be specified (but doesn't have to).
Additionally startMainMenu is now in GSLevel and can only be executed in a Level, as opposed to only in the MainMenu as it was before.
Added changeGame console command which works in a level in standalone mode to change to a different level.
Modified: code/trunk/data/gui/scripts/HostMenu.lua
===================================================================
--- code/trunk/data/gui/scripts/HostMenu.lua 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/data/gui/scripts/HostMenu.lua 2011-02-13 16:49:41 UTC (rev 7876)
@@ -103,8 +103,7 @@
local index = listbox:getItemIndex(choice)
local level = P.levelList[index+1]
if level ~= nil then
- orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
- orxonox.execute(P.multiplayerMode)
+ orxonox.execute(P.multiplayerMode .. " " .. level:getXMLFilename())
hideAllMenuSheets()
end
end
Modified: code/trunk/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/trunk/data/gui/scripts/MultiplayerMenu.lua 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/data/gui/scripts/MultiplayerMenu.lua 2011-02-13 16:49:41 UTC (rev 7876)
@@ -74,15 +74,15 @@
function P.MultiplayerJoinButton_clicked(e)
- local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
+ local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
+ local destination = nil
if choice then
- local client = orxonox.Client:getInstance()
local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
- client:setDestination( P.serverList[index][2], 55556 )
+ destination = P.serverList[index][2]
else
return
end
- orxonox.execute("startClient")
+ orxonox.execute("startClient " .. destination)
hideAllMenuSheets()
end
Modified: code/trunk/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/trunk/data/gui/scripts/SingleplayerMenu.lua 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/data/gui/scripts/SingleplayerMenu.lua 2011-02-13 16:49:41 UTC (rev 7876)
@@ -73,8 +73,7 @@
local index = listbox:getItemIndex(choice)
local level = P.levelList[index+1]
if level ~= nil then
- orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
- orxonox.execute("startGame")
+ orxonox.execute("startGame " .. level:getXMLFilename())
hideAllMenuSheets()
end
end
Modified: code/trunk/src/libraries/core/GUIManager.cc
===================================================================
--- code/trunk/src/libraries/core/GUIManager.cc 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/src/libraries/core/GUIManager.cc 2011-02-13 16:49:41 UTC (rev 7876)
@@ -61,6 +61,7 @@
#include "ConfigValueIncludes.h"
#include "Core.h"
#include "CoreIncludes.h"
+#include "Game.h"
#include "GraphicsManager.h"
#include "LuaState.h"
#include "PathConfig.h"
@@ -521,4 +522,5 @@
if (!bFocus)
this->mouseLeft();
}
+
}
Modified: code/trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSLevel.cc 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/src/orxonox/gamestates/GSLevel.cc 2011-02-13 16:49:41 UTC (rev 7876)
@@ -50,6 +50,12 @@
{
DeclareGameState(GSLevel, "level", false, false);
+ static const std::string __CC_startMainMenu_name = "startMainMenu";
+ static const std::string __CC_changeGame_name = "changeGame";
+
+ SetConsoleCommand(__CC_startMainMenu_name, &GSLevel::startMainMenu).deactivate();
+ SetConsoleCommand(__CC_changeGame_name, &GSLevel::changeGame).defaultValues(BLANKSTRING).deactivate();
+
GSLevel::GSLevel(const GameStateInfo& info)
: GameState(info)
, gameInputState_(0)
@@ -93,7 +99,12 @@
// connect the HumanPlayer to the game
PlayerManager::getInstance().clientConnected(0);
+
+ ModifyConsoleCommand(__CC_startMainMenu_name).activate();
}
+
+ if (GameMode::isStandalone())
+ ModifyConsoleCommand(__CC_changeGame_name).activate();
}
void GSLevel::deactivate()
@@ -120,7 +131,12 @@
InputManager::getInstance().destroyState("game");
InputManager::getInstance().destroyState("guiKeysOnly");
InputManager::getInstance().destroyState("guiMouseOnly");
+
+ ModifyConsoleCommand(__CC_startMainMenu_name ).deactivate();
}
+
+ if (GameMode::isStandalone())
+ ModifyConsoleCommand(__CC_changeGame_name).deactivate();
}
void GSLevel::update(const Clock& time)
@@ -165,4 +181,32 @@
else
COUT(3) << " Try harder!" << std::endl;
}
+
+ /**
+ @brief
+ Starts the MainMenu.
+ */
+ /*static*/ void GSLevel::startMainMenu(void)
+ {
+ // HACK
+ Game::getInstance().popState();
+ Game::getInstance().popState();
+ }
+
+ /**
+ @brief
+ Terminates the current game and starts a new game.
+ @param level
+ The filename of the level to be started.
+ */
+ /*static*/ void GSLevel::changeGame(const std::string& level)
+ {
+ if(level != BLANKSTRING)
+ LevelManager::getInstance().setDefaultLevel(level);
+
+ // HACK
+ Game::getInstance().popState();
+ Game::getInstance().popState();
+ Game::getInstance().requestStates("standalone, level");
+ }
}
Modified: code/trunk/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSLevel.h 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/src/orxonox/gamestates/GSLevel.h 2011-02-13 16:49:41 UTC (rev 7876)
@@ -48,6 +48,9 @@
void deactivate();
void update(const Clock& time);
+ static void startMainMenu(void); //!< Starts the MainMenu
+ static void changeGame(const std::string& level); //!< Terminates the current game and starts a new game.
+
protected:
void loadLevel();
void unloadLevel();
Modified: code/trunk/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMainMenu.cc 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/src/orxonox/gamestates/GSMainMenu.cc 2011-02-13 16:49:41 UTC (rev 7876)
@@ -30,13 +30,16 @@
#include <OgreSceneManager.h>
-#include "core/input/KeyBinderManager.h"
-#include "core/Game.h"
#include "core/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
+#include "core/Game.h"
#include "core/GraphicsManager.h"
#include "core/GUIManager.h"
#include "core/command/ConsoleCommand.h"
+#include "core/input/KeyBinderManager.h"
+#include "network/Client.h"
+#include "util/StringUtils.h"
+#include "LevelManager.h"
#include "Scene.h"
#include "sound/AmbientSound.h"
// HACK
@@ -51,14 +54,12 @@
static const std::string __CC_startServer_name = "startServer";
static const std::string __CC_startClient_name = "startClient";
static const std::string __CC_startDedicated_name = "startDedicated";
- static const std::string __CC_startMainMenu_name = "startMainMenu";
static const std::string __CC_setMainMenuSoundPath_name = "setMMSoundPath";
- SetConsoleCommand(__CC_startStandalone_name, &GSMainMenu::startStandalone).deactivate();
- SetConsoleCommand(__CC_startServer_name, &GSMainMenu::startServer ).deactivate();
- SetConsoleCommand(__CC_startClient_name, &GSMainMenu::startClient ).deactivate();
- SetConsoleCommand(__CC_startDedicated_name, &GSMainMenu::startDedicated ).deactivate();
- SetConsoleCommand(__CC_startMainMenu_name, &GSMainMenu::startMainMenu ).deactivate();
+ SetConsoleCommand(__CC_startStandalone_name, &GSMainMenu::startStandalone).defaultValues(BLANKSTRING).deactivate();
+ SetConsoleCommand(__CC_startServer_name, &GSMainMenu::startServer ).defaultValues(BLANKSTRING).deactivate();
+ SetConsoleCommand(__CC_startClient_name, &GSMainMenu::startClient ).defaultValues(BLANKSTRING).deactivate();
+ SetConsoleCommand(__CC_startDedicated_name, &GSMainMenu::startDedicated ).defaultValues(BLANKSTRING).deactivate();
SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath).hide();
GSMainMenu::GSMainMenu(const GameStateInfo& info)
@@ -105,7 +106,6 @@
ModifyConsoleCommand(__CC_startServer_name ).activate();
ModifyConsoleCommand(__CC_startClient_name ).activate();
ModifyConsoleCommand(__CC_startDedicated_name ).activate();
- ModifyConsoleCommand(__CC_startMainMenu_name ).activate();
ModifyConsoleCommand(__CC_setMainMenuSoundPath_name).setObject(this);
KeyBinderManager::getInstance().setToDefault();
@@ -137,7 +137,6 @@
ModifyConsoleCommand(__CC_startServer_name ).deactivate();
ModifyConsoleCommand(__CC_startClient_name ).deactivate();
ModifyConsoleCommand(__CC_startDedicated_name ).deactivate();
- ModifyConsoleCommand(__CC_startMainMenu_name ).deactivate();
ModifyConsoleCommand(__CC_setMainMenuSoundPath_name).setObject(0);
}
@@ -170,39 +169,69 @@
ModifyConfigValue(soundPathMain_, set, path);
}
- void GSMainMenu::startStandalone()
+ /**
+ @brief
+ Start a level in standalone mode.
+ @param level
+ The filename of the level to be started. If empty, the default level is started.
+ */
+ void GSMainMenu::startStandalone(const std::string& level)
{
- // HACK - HACK
+ if(level != BLANKSTRING)
+ LevelManager::getInstance().setDefaultLevel(level);
+
+ // HACK
Game::getInstance().popState();
Game::getInstance().requestStates("standalone, level");
}
- void GSMainMenu::startServer()
+ /**
+ @brief
+ Start a level in server mode.
+ @param level
+ The filename of the level to be started. If empty, the default level is started.
+ */
+ void GSMainMenu::startServer(const std::string& level)
{
- // HACK - HACK
+ if(level != BLANKSTRING)
+ LevelManager::getInstance().setDefaultLevel(level);
+
+ // HACK
Game::getInstance().popState();
Game::getInstance().requestStates("server, level");
}
- void GSMainMenu::startClient()
+ /**
+ @brief
+ Connect to a game as client.
+ @param destination
+ The destination to connect to. If empty, the client connects to the default destination.
+ */
+ void GSMainMenu::startClient(const std::string& destination)
{
- // HACK - HACK
+ if(destination != BLANKSTRING)
+ Client::getInstance()->setDestination(destination, NETWORK_PORT);
+
+ // HACK
Game::getInstance().popState();
Game::getInstance().requestStates("client, level");
}
- void GSMainMenu::startDedicated()
+ /**
+ @brief
+ Start a level in dedicated mode.
+ @param level
+ The filename of the level to be started. If empty, the default level is started.
+ */
+ void GSMainMenu::startDedicated(const std::string& level)
{
- // HACK - HACK
+ if(level != BLANKSTRING)
+ LevelManager::getInstance().setDefaultLevel(level);
+
+ // HACK
Game::getInstance().popState();
Game::getInstance().popState();
Game::getInstance().requestStates("server, level");
}
- void GSMainMenu::startMainMenu()
- {
- // HACK - HACK
- Game::getInstance().popState();
- Game::getInstance().popState();
- Game::getInstance().requestStates("mainmenu");
- }
+
}
Modified: code/trunk/src/orxonox/gamestates/GSMainMenu.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMainMenu.h 2011-02-13 13:29:30 UTC (rev 7875)
+++ code/trunk/src/orxonox/gamestates/GSMainMenu.h 2011-02-13 16:49:41 UTC (rev 7876)
@@ -52,11 +52,10 @@
const std::string& getMainMenuSoundPath();
void setMainMenuSoundPath(const std::string& path);
- static void startStandalone();
- static void startServer();
- static void startClient();
- static void startDedicated();
- static void startMainMenu();
+ static void startStandalone(const std::string& level = BLANKSTRING); //!< Start a level in standalone mode.
+ static void startServer(const std::string& level = BLANKSTRING); //!< Start a level in server mode.
+ static void startClient(const std::string& destination = BLANKSTRING); //!< Connect to a game as client.
+ static void startDedicated(const std::string& level = BLANKSTRING); //!< Start a level in dedicated mode.
static void startIOConsole();
private:
More information about the Orxonox-commit
mailing list