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

Method OnInvalidateData

src/vehicle_gui.cpp:1127–1170  ·  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

1125 * @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.
1126 */
1127 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1128 {
1129 switch (data) {
1130 case VIWD_AUTOREPLACE: // Autoreplace replaced the vehicle; selected_vehicle became invalid.
1131 case VIWD_CONSIST_CHANGED: { // The consist has changed; rebuild the entire list.
1132 /* Clear the selection. */
1133 Vehicle *v = Vehicle::Get(this->window_number);
1134 this->selected_vehicle = v->index;
1135 this->num_vehicles = UINT8_MAX;
1136 [[fallthrough]];
1137 }
1138
1139 case 2: { // The vehicle selection has changed; rebuild the entire list.
1140 if (!gui_scope) break;
1141 this->BuildRefitList();
1142
1143 /* The vehicle width has changed too. */
1144 this->vehicle_width = GetVehicleWidth(Vehicle::Get(this->window_number), EIT_IN_DETAILS);
1145 uint max_width = 0;
1146
1147 /* Check the width of all cargo information strings. */
1148 for (const auto &list : this->refit_list) {
1149 for (const RefitOption &refit : list.second) {
1150 std::string string = this->GetCapacityString(refit);
1151 if (!string.empty()) {
1152 Dimension dim = GetStringBoundingBox(string);
1153 max_width = std::max(dim.width, max_width);
1154 }
1155 }
1156 }
1157
1158 if (this->information_width < max_width) {
1159 this->information_width = max_width;
1160 this->ReInit();
1161 }
1162 [[fallthrough]];
1163 }
1164
1165 case 1: // A new cargo has been selected.
1166 if (!gui_scope) break;
1167 this->RefreshScrollbar();
1168 break;
1169 }
1170 }
1171
1172 int GetClickPosition(int click_x)
1173 {

Callers 1

OnInitMethod · 0.95

Calls 7

BuildRefitListMethod · 0.95
GetCapacityStringMethod · 0.95
RefreshScrollbarMethod · 0.95
GetVehicleWidthFunction · 0.85
GetStringBoundingBoxFunction · 0.85
ReInitMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected