* Open the Script debug window and select the given company. * @param show_company Display debug information about this AI company. * @param new_window Show in new window instead of existing window. */
| 1262 | * @param new_window Show in new window instead of existing window. |
| 1263 | */ |
| 1264 | Window *ShowScriptDebugWindow(CompanyID show_company, bool new_window) |
| 1265 | { |
| 1266 | if (!_networking || _network_server) { |
| 1267 | int i = 0; |
| 1268 | if (new_window) { |
| 1269 | /* find next free window number for script debug */ |
| 1270 | while (FindWindowById(WC_SCRIPT_DEBUG, i) != nullptr) i++; |
| 1271 | } else { |
| 1272 | /* Find existing window showing show_company. */ |
| 1273 | for (Window *w : Window::Iterate()) { |
| 1274 | if (w->window_class == WC_SCRIPT_DEBUG && static_cast<ScriptDebugWindow *>(w)->filter.script_debug_company == show_company) { |
| 1275 | return BringWindowToFrontById(w->window_class, w->window_number); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | /* Maybe there's a window showing a different company which can be switched. */ |
| 1280 | ScriptDebugWindow *w = static_cast<ScriptDebugWindow *>(FindWindowByClass(WC_SCRIPT_DEBUG)); |
| 1281 | if (w != nullptr) { |
| 1282 | BringWindowToFrontById(w->window_class, w->window_number); |
| 1283 | w->ChangeToScript(show_company); |
| 1284 | return w; |
| 1285 | } |
| 1286 | } |
| 1287 | return new ScriptDebugWindow(_script_debug_desc, i, show_company); |
| 1288 | } else { |
| 1289 | ShowErrorMessage(GetEncodedString(STR_ERROR_AI_DEBUG_SERVER_ONLY), {}, WL_INFO); |
| 1290 | } |
| 1291 | |
| 1292 | return nullptr; |
| 1293 | } |
| 1294 | |
| 1295 | /** |
| 1296 | * Reset the Script windows to their initial state. |
no test coverage detected