Build (fund or prospect) a new industry, */
| 297 | |
| 298 | /** Build (fund or prospect) a new industry, */ |
| 299 | class BuildIndustryWindow : public Window { |
| 300 | IndustryType selected_type = IT_INVALID; ///< industry corresponding to the above index |
| 301 | std::vector<IndustryType> list{}; ///< List of industries. |
| 302 | bool enabled = false; ///< Availability state of the selected industry. |
| 303 | Scrollbar *vscroll = nullptr; |
| 304 | Dimension legend{}; ///< Dimension of the legend 'blob'. |
| 305 | GUIBadgeClasses badge_classes{}; |
| 306 | |
| 307 | /** The largest allowed minimum-width of the window, given in line heights */ |
| 308 | static const int MAX_MINWIDTH_LINEHEIGHTS = 20; |
| 309 | |
| 310 | void UpdateAvailability() |
| 311 | { |
| 312 | this->enabled = this->selected_type != IT_INVALID && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0); |
| 313 | } |
| 314 | |
| 315 | void SetupArrays() |
| 316 | { |
| 317 | this->list.clear(); |
| 318 | |
| 319 | /* Fill the arrays with industries. |
| 320 | * The tests performed after the enabled allow to load the industries |
| 321 | * In the same way they are inserted by grf (if any) |
| 322 | */ |
| 323 | for (IndustryType ind : _sorted_industry_types) { |
| 324 | const IndustrySpec *indsp = GetIndustrySpec(ind); |
| 325 | if (indsp->enabled) { |
| 326 | /* Rule is that editor mode loads all industries. |
| 327 | * In game mode, all non raw industries are loaded too |
| 328 | * and raw ones are loaded only when setting allows it */ |
| 329 | if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) { |
| 330 | /* Unselect if the industry is no longer in the list */ |
| 331 | if (this->selected_type == ind) this->selected_type = IT_INVALID; |
| 332 | continue; |
| 333 | } |
| 334 | |
| 335 | this->list.push_back(ind); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /* First industry type is selected if the current selection is invalid. */ |
| 340 | if (this->selected_type == IT_INVALID && !this->list.empty()) this->selected_type = this->list[0]; |
| 341 | |
| 342 | this->UpdateAvailability(); |
| 343 | |
| 344 | this->vscroll->SetCount(this->list.size()); |
| 345 | } |
| 346 | |
| 347 | /** Update status of the fund and display-chain widgets. */ |
| 348 | void SetButtons() |
| 349 | { |
| 350 | this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != IT_INVALID && !this->enabled); |
| 351 | this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == IT_INVALID && this->enabled); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Build a string of cargo names with suffixes attached. |
| 356 | * This is distinct from the CARGO_LIST string formatting code in two ways: |
nothing calls this directly
no test coverage detected