MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / launchSelectedButtonPressed

Method launchSelectedButtonPressed

source/modes/MenuModeLoad.cpp:121–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121bool MenuModeLoad::launchSelectedButtonPressed(const CEGUI::EventArgs&)
122{
123 CEGUI::Window* tmpWin = getModeManager().getGui().getGuiSheet(Gui::loadSavedGameMenu)->getChild("LevelWindowFrame/SaveGameSelect");
124 CEGUI::Listbox* levelSelectList = static_cast<CEGUI::Listbox*>(tmpWin);
125
126 if(levelSelectList->getSelectedCount() == 0)
127 {
128 tmpWin = getModeManager().getGui().getGuiSheet(Gui::loadSavedGameMenu)->getChild("LoadingText");
129 tmpWin->setText("Please select a saved game first.");
130 tmpWin->show();
131 return true;
132 }
133
134 std::string nickname = ConfigManager::getSingleton().getGameValue(Config::NICKNAME, std::string(), false);
135 if (!nickname.empty())
136 ODFrameListener::getSingleton().getClientGameMap()->setLocalPlayerNick(nickname);
137
138 tmpWin = getModeManager().getGui().getGuiSheet(Gui::loadSavedGameMenu)->getChild("LoadingText");
139 tmpWin->setText("Loading...");
140 tmpWin->show();
141
142 CEGUI::ListboxItem* selItem = levelSelectList->getFirstSelectedItem();
143 int id = selItem->getID();
144
145 const std::string& level = mFilesList[id];
146 // In single player mode, we act as a server
147 if(!ODServer::getSingleton().startServer(nickname, level, ServerMode::ModeGameLoaded, false))
148 {
149 OD_LOG_ERR("Could not start server for single player game !!!");
150 tmpWin = getModeManager().getGui().getGuiSheet(Gui::loadSavedGameMenu)->getChild("LoadingText");
151 tmpWin->setText("ERROR: Could not start server for single player game !!!");
152 tmpWin->show();
153 return true;
154 }
155
156 int port = ODServer::getSingleton().getNetworkPort();
157 uint32_t timeout = ConfigManager::getSingleton().getClientConnectionTimeout();
158 std::string replayFilename = ResourceManager::getSingleton().getReplayDataPath()
159 + ResourceManager::getSingleton().buildReplayFilename();
160 if(!ODClient::getSingleton().connect("localhost", port, timeout, replayFilename))
161 {
162 OD_LOG_ERR("Could not connect to server for single player game !!!");
163 tmpWin = getModeManager().getGui().getGuiSheet(Gui::loadSavedGameMenu)->getChild("LoadingText");
164 tmpWin->setText("Error: Couldn't connect to local server!");
165 tmpWin->show();
166 return true;
167 }
168 return true;
169}
170
171bool MenuModeLoad::deleteSelectedButtonPressed(const CEGUI::EventArgs&)
172{

Callers

nothing calls this directly

Calls 11

getGuiSheetMethod · 0.80
setTextMethod · 0.80
showMethod · 0.80
getGameValueMethod · 0.80
setLocalPlayerNickMethod · 0.80
getClientGameMapMethod · 0.80
buildReplayFilenameMethod · 0.80
startServerMethod · 0.45
getNetworkPortMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected