MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / OnInvalidateData

Method OnInvalidateData

src/road_gui.cpp:376–415  ·  view source on GitHub ↗

* Some data on this window has become invalid. * @param data Information about the changed data. * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details. */

Source from the content-addressed store, hash-verified

374 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
375 */
376 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
377 {
378 if (!gui_scope) return;
379
380 if (!ValParamRoadType(this->roadtype)) {
381 /* Close toolbar if road type is not available. */
382 this->Close();
383 return;
384 }
385
386 RoadTramType rtt = GetRoadTramType(this->roadtype);
387
388 bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, rtt);
389 this->SetWidgetsDisabledState(!can_build,
390 WID_ROT_DEPOT,
391 WID_ROT_BUILD_WAYPOINT,
392 WID_ROT_BUS_STATION,
393 WID_ROT_TRUCK_STATION);
394 if (!can_build) {
395 CloseWindowById(WC_BUS_STATION, TRANSPORT_ROAD);
396 CloseWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD);
397 CloseWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD);
398 CloseWindowById(WC_BUILD_WAYPOINT, TRANSPORT_ROAD);
399 }
400
401 if (_game_mode != GM_EDITOR) {
402 if (!can_build) {
403 /* Show in the tooltip why this button is disabled. */
404 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
405 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
406 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
407 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
408 } else {
409 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT);
410 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT : STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT);
411 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION);
412 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION);
413 }
414 }
415 }
416
417 void OnInit() override
418 {

Callers 1

Calls 7

CloseMethod · 0.95
ValParamRoadTypeFunction · 0.85
GetRoadTramTypeFunction · 0.85
CloseWindowByIdFunction · 0.85
SetToolTipMethod · 0.80

Tested by

no test coverage detected