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

Method launchSelectedButtonPressed

source/modes/MenuModeEditorNew.cpp:104–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104bool MenuModeEditorNew::launchSelectedButtonPressed(const CEGUI::EventArgs&)
105{
106 CEGUI::Window* window = getModeManager().getGui().getGuiSheet(Gui::guiSheet::editorNewMenu);
107
108 window->getChild(TEXT_LOADING)->setText("Creating Map...");
109
110 // Creating the filename
111 CEGUI::Combobox* levelTypeCb = static_cast<CEGUI::Combobox*>(getModeManager().getGui().
112 getGuiSheet(Gui::editorNewMenu)->getChild(LIST_LEVEL_TYPES));
113 std::string levelPath;
114 size_t selection = levelTypeCb->getItemIndex(levelTypeCb->getSelectedItem());
115 switch (selection)
116 {
117 default:
118 case 0:
119 levelPath = ResourceManager::getSingleton().getUserLevelPathSkirmish();
120 break;
121 case 1:
122 levelPath = ResourceManager::getSingleton().getUserLevelPathMultiplayer();
123 break;
124 }
125 CEGUI::Editbox* editWin = static_cast<CEGUI::Editbox*>(window->getChild("LevelWindowFrame/LevelFilenameEdit"));
126 std::string level = editWin->getText().c_str();
127 Helper::trim(level);
128 if (level.empty()) {
129 window->getChild(TEXT_LOADING)->setText("Please set a level filename.");
130 return true;
131 }
132
133 level = levelPath + "/" + level;
134 if (boost::filesystem::exists(level)) {
135 window->getChild(TEXT_LOADING)->setText("The level filename already exists.\nPlease set a different filename.");
136 return true;
137 }
138 if (boost::filesystem::extension(level) != ".level") {
139 level.append(".level");
140 }
141
142 // Get the map size.
143 editWin = static_cast<CEGUI::Editbox*>(window->getChild("LevelWindowFrame/LevelWidthEdit"));
144 std::string widthStr = editWin->getText().c_str();
145 uint32_t width = Helper::toUInt32(widthStr);
146 editWin = static_cast<CEGUI::Editbox*>(window->getChild("LevelWindowFrame/LevelHeightEdit"));
147 std::string heightStr = editWin->getText().c_str();
148 uint32_t height = Helper::toUInt32(heightStr);
149
150 if (width == 0 || height == 0) {
151 window->getChild(TEXT_LOADING)->setText("Invalid map size.");
152 return true;
153 }
154
155 // Create the level before opening it.
156 GameMap* gameMap = ODFrameListener::getSingleton().getClientGameMap();
157 gameMap->clearAll();
158 gameMap->setGamePaused(true);
159 gameMap->createNewMap(width, height);
160 gameMap->setLevelFileName(level);
161 editWin = static_cast<CEGUI::Editbox*>(window->getChild("LevelWindowFrame/LevelTitleEdit"));

Callers

nothing calls this directly

Calls 15

trimFunction · 0.85
toUInt32Function · 0.85
writeGameMapToFileFunction · 0.85
getGuiSheetMethod · 0.80
setTextMethod · 0.80
getClientGameMapMethod · 0.80
clearAllMethod · 0.80
setGamePausedMethod · 0.80
createNewMapMethod · 0.80
setLevelFileNameMethod · 0.80

Tested by

no test coverage detected