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

Method UpdateButtonState

src/order_gui.cpp:898–1057  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

896 }
897
898 void UpdateButtonState()
899 {
900 if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
901
902 bool shared_orders = this->vehicle->IsOrderListShared();
903 VehicleOrderID sel = this->OrderGetSel();
904 const Order *order = this->vehicle->GetOrder(sel);
905
906 /* Second row. */
907 /* skip */
908 this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
909
910 /* delete / stop sharing */
911 NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
912 if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
913 /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
914 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
915 } else {
916 /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
917 delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
918 this->SetWidgetDisabledState(WID_O_DELETE,
919 (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
920
921 /* Set the tooltip of the 'delete' button depending on whether the
922 * 'End of Orders' order or a regular order is selected. */
923 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
924 if (this->selected_order == this->vehicle->GetNumOrders()) {
925 nwi->SetStringTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
926 } else {
927 nwi->SetStringTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
928 }
929 }
930
931 /* First row. */
932 this->RaiseWidget(WID_O_FULL_LOAD);
933 this->RaiseWidget(WID_O_UNLOAD);
934
935 /* Selection widgets. */
936 /* Train or road vehicle. */
937 NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
938 NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
939 NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
940 NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
941 /* Ship or airplane. */
942 NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
943 assert(row_sel != nullptr || (train_row_sel != nullptr && left_sel != nullptr && middle_sel != nullptr && right_sel != nullptr));
944
945
946 if (order == nullptr) {
947 if (row_sel != nullptr) {
948 row_sel->SetDisplayedPlane(DP_ROW_LOAD);
949 } else {
950 train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
951 left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
952 middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
953 right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
954 this->DisableWidget(WID_O_NON_STOP);
955 this->RaiseWidget(WID_O_NON_STOP);

Callers 5

OrderClick_DeleteMethod · 0.95
OnInvalidateDataMethod · 0.95
OnClickMethod · 0.95
OnDragDropMethod · 0.95

Calls 15

OrderGetSelMethod · 0.95
to_underlyingFunction · 0.85
IsOrderListSharedMethod · 0.80
GetOrderMethod · 0.80
SetDisplayedPlaneMethod · 0.80
SetStringTipMethod · 0.80
RaiseWidgetMethod · 0.80
DisableWidgetMethod · 0.80
TestMethod · 0.80
GetNonStopTypeMethod · 0.80
EnableWidgetMethod · 0.80

Tested by

no test coverage detected