* Changes the Script of the current slot. */
| 166 | * Changes the Script of the current slot. |
| 167 | */ |
| 168 | void ChangeScript() |
| 169 | { |
| 170 | if (this->selected == -1) { |
| 171 | GetConfig(this->slot)->Change(std::nullopt); |
| 172 | } else { |
| 173 | ScriptInfoList::const_iterator it = this->info_list->cbegin(); |
| 174 | std::advance(it, this->selected); |
| 175 | GetConfig(this->slot)->Change(it->second->GetName(), it->second->GetVersion()); |
| 176 | } |
| 177 | if (_game_mode == GM_EDITOR) { |
| 178 | if (this->slot == OWNER_DEITY) { |
| 179 | if (Game::GetInstance() != nullptr) Game::ResetInstance(); |
| 180 | Game::StartNew(); |
| 181 | } else { |
| 182 | Company *c = Company::GetIfValid(this->slot); |
| 183 | if (c != nullptr && c->ai_instance != nullptr) { |
| 184 | c->ai_instance.reset(); |
| 185 | AI::StartNew(this->slot); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | InvalidateWindowData(WC_GAME_OPTIONS, this->slot == OWNER_DEITY ? WN_GAME_OPTIONS_GS : WN_GAME_OPTIONS_AI); |
| 190 | InvalidateWindowClassesData(WC_SCRIPT_SETTINGS); |
| 191 | InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1); |
| 192 | CloseWindowByClass(WC_QUERY_STRING); |
| 193 | InvalidateWindowClassesData(WC_TEXTFILE); |
| 194 | } |
| 195 | |
| 196 | void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override |
| 197 | { |
no test coverage detected