| 1159 | }; |
| 1160 | |
| 1161 | WindowBase* LoadsaveOpen( |
| 1162 | LoadSaveAction action, LoadSaveType type, std::string_view defaultPath, LoadSaveCallback callback, bool isJsCallback, |
| 1163 | TrackDesign* trackDesign) |
| 1164 | { |
| 1165 | _trackDesign = trackDesign; |
| 1166 | _defaultPath = defaultPath; |
| 1167 | |
| 1168 | auto* windowMgr = GetWindowManager(); |
| 1169 | auto* w = static_cast<LoadSaveWindow*>(windowMgr->BringToFrontByClass(WindowClass::loadsave)); |
| 1170 | if (w == nullptr) |
| 1171 | { |
| 1172 | auto& config = Config::Get().general; |
| 1173 | if (config.fileBrowserWidth < kWindowSizeMin.width || config.fileBrowserHeight < kWindowSizeMin.height |
| 1174 | || config.fileBrowserWidth > kWindowSizeMax.width || config.fileBrowserHeight > kWindowSizeMax.height) |
| 1175 | { |
| 1176 | config.fileBrowserWidth = kWindowSize.width; |
| 1177 | config.fileBrowserHeight = kWindowSize.height; |
| 1178 | Config::Save(); |
| 1179 | } |
| 1180 | |
| 1181 | ScreenSize windowSize = { config.fileBrowserWidth, config.fileBrowserHeight }; |
| 1182 | |
| 1183 | RegisterCallback(callback, isJsCallback); |
| 1184 | |
| 1185 | w = windowMgr->Create<LoadSaveWindow>( |
| 1186 | WindowClass::loadsave, windowSize, |
| 1187 | { WindowFlag::stickToFront, WindowFlag::resizable, WindowFlag::autoPosition, WindowFlag::centreScreen }, action, |
| 1188 | type); |
| 1189 | } |
| 1190 | |
| 1191 | bool isSave = action == LoadSaveAction::save; |
| 1192 | |
| 1193 | if (type == LoadSaveType::heightmap && isSave) |
| 1194 | { |
| 1195 | Guard::Fail("Cannot save images through loadsave window"); |
| 1196 | } |
| 1197 | |
| 1198 | w->widgets[WIDX_TITLE].text = GetTitleStringId(type, isSave); |
| 1199 | if (w->widgets[WIDX_TITLE].text == kStringIdNone) |
| 1200 | { |
| 1201 | Guard::Fail("Unsupported load/save type: %d", EnumValue(type)); |
| 1202 | } |
| 1203 | |
| 1204 | return w; |
| 1205 | } |
| 1206 | |
| 1207 | void WindowLoadSaveInputKey(WindowBase* w, uint32_t keycode) |
| 1208 | { |
no test coverage detected