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

Function DrawOrderString

src/order_gui.cpp:223–359  ·  view source on GitHub ↗

* Draws an order in order or timetable GUI * @param v Vehicle the order belongs to * @param order The order to draw * @param order_index Index of the order in the orders of the vehicle * @param y Y position for drawing * @param selected True, if the order is selected * @param timetable True, when drawing in the timetable GUI * @param left Left border for text drawing * @param middle X posi

Source from the content-addressed store, hash-verified

221 * @param right Right border for text drawing
222 */
223void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_index, int y, bool selected, bool timetable, int left, int middle, int right)
224{
225 bool rtl = _current_text_dir == TD_RTL;
226
227 SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
228 Dimension sprite_size = GetSpriteSize(sprite);
229 if (v->cur_real_order_index == order_index) {
230 /* Draw two arrows before the next real order. */
231 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)GetCharacterHeight(FS_NORMAL) - (int)sprite_size.height) / 2);
232 DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)GetCharacterHeight(FS_NORMAL) - (int)sprite_size.height) / 2);
233 } else if (v->cur_implicit_order_index == order_index) {
234 /* Draw one arrow before the next implicit order; the next real order will still get two arrows. */
235 DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)GetCharacterHeight(FS_NORMAL) - (int)sprite_size.height) / 2);
236 }
237
238 TextColour colour = TC_BLACK;
239 if (order->IsType(OT_IMPLICIT)) {
240 colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
241 } else if (selected) {
242 colour = TC_WHITE;
243 }
244
245 DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, GetString(STR_ORDER_INDEX, order_index + 1), colour, SA_RIGHT | SA_FORCE);
246
247 std::string line;
248
249 switch (order->GetType()) {
250 case OT_DUMMY:
251 line = GetString(STR_INVALID_ORDER);
252 break;
253
254 case OT_IMPLICIT:
255 line = GetString(STR_ORDER_GO_TO_STATION, STR_ORDER_GO_TO, order->GetDestination());
256 if (!timetable) line += GetString(STR_ORDER_IMPLICIT);
257 break;
258
259 case OT_GOTO_STATION: {
260 OrderLoadType load = order->GetLoadType();
261 OrderUnloadType unload = order->GetUnloadType();
262 bool valid_station = CanVehicleUseStation(v, Station::Get(order->GetDestination().ToStationID()));
263
264 line = GetString(valid_station ? STR_ORDER_GO_TO_STATION : STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : OrderNonStopFlags{}).base(), order->GetDestination());
265 if (timetable) {
266 /* Show only wait time in the timetable window. */
267 if (order->GetWaitTime() > 0) {
268 auto [str, value] = GetTimetableParameters(order->GetWaitTime());
269 line += GetString(order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED, str, value);
270 }
271 } else {
272 /* Show non-stop, refit and stop location only in the order window. */
273 if (!order->GetNonStopType().Test(OrderNonStopFlag::NoDestination)) {
274 StringID str = _station_load_types[order->IsRefit()][to_underlying(unload)][to_underlying(load)];
275 if (str != INVALID_STRING_ID) {
276 if (order->IsRefit()) {
277 line += GetString(str, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
278 } else {
279 line += GetString(str);
280 }

Callers 2

DrawWidgetMethod · 0.85
DrawTimetablePanelMethod · 0.85

Calls 15

GetSpriteSizeFunction · 0.85
DrawSpriteFunction · 0.85
GetCharacterHeightFunction · 0.85
CanVehicleUseStationFunction · 0.85
GetTimetableParametersFunction · 0.85
to_underlyingFunction · 0.85
GetOrderGoToStringFunction · 0.85
NOT_REACHEDFunction · 0.85
GetOrderDistanceFunction · 0.85
IsTypeMethod · 0.80
GetDestinationMethod · 0.80

Tested by

no test coverage detected