diff options
author | SamuXarick <43006711+SamuXarick@users.noreply.github.com> | 2021-09-14 21:10:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 22:10:00 +0200 |
commit | a57c2b073a6f40a90479cf9eeb916b282fe7c999 (patch) | |
tree | 5a80f33e7a82b1a3ef410d5116fb1cd065da90d0 | |
parent | 37de87812994be72399a9588473ece1c514397c0 (diff) | |
download | openttd-a57c2b073a6f40a90479cf9eeb916b282fe7c999.tar.xz |
Feature: Display icon/text whether vehicle is lost in vehicle (list) window (#9543)
-rw-r--r-- | src/lang/english.txt | 5 | ||||
-rw-r--r-- | src/vehicle.cpp | 4 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 18 |
3 files changed, 20 insertions, 7 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index b6578ac8d..6162906a9 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4137,6 +4137,11 @@ STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL :{LTBLUE}Heading STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL :{ORANGE}Heading for {DEPOT}, {VELOCITY} STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL :{LTBLUE}Service at {DEPOT}, {VELOCITY} +STR_VEHICLE_STATUS_CANNOT_REACH_STATION_VEL :{LTBLUE}Cannot reach {STATION}, {VELOCITY} +STR_VEHICLE_STATUS_CANNOT_REACH_WAYPOINT_VEL :{LTBLUE}Cannot reach {WAYPOINT}, {VELOCITY} +STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_VEL :{ORANGE}Cannot reach {DEPOT}, {VELOCITY} +STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL :{LTBLUE}Cannot reach {DEPOT}, {VELOCITY} + # Vehicle stopped/started animations ###length 2 STR_VEHICLE_COMMAND_STOPPED_SMALL :{TINY_FONT}{RED}Stopped diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 6df16caf6..9e2292751 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -778,6 +778,8 @@ void Vehicle::HandlePathfindingResult(bool path_found) /* Clear the flag as the PF's problem was solved. */ ClrBit(this->vehicle_flags, VF_PATHFINDER_LOST); + SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); + InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type)); /* Delete the news item. */ DeleteVehicleNews(this->index, STR_NEWS_VEHICLE_IS_LOST); return; @@ -788,6 +790,8 @@ void Vehicle::HandlePathfindingResult(bool path_found) /* It is first time the problem occurred, set the "lost" flag. */ SetBit(this->vehicle_flags, VF_PATHFINDER_LOST); + SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); + InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type)); /* Notify user about the event. */ AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index)); if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index ed55e9f1d..da6e446bf 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1542,6 +1542,10 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int case GB_NONE: { const Vehicle *v = vehgroup.GetSingleVehicle(); + if (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) { + DrawSprite(SPR_WARNING_SIGN, PAL_NONE, vehicle_button_x, y + FONT_HEIGHT_NORMAL + 3 + GetSpriteSize(SPR_PROFIT_LOT).height); + } + DrawVehicleImage(v, image_left, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0); if (!v->name.empty()) { @@ -2732,7 +2736,7 @@ public: const Vehicle *v = Vehicle::Get(this->window_number); switch (widget) { case WID_VV_START_STOP: - size->height = std::max(size->height, std::max(GetSpriteSize(SPR_FLAG_VEH_STOPPED).height, GetSpriteSize(SPR_FLAG_VEH_RUNNING).height) + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM); + size->height = std::max({size->height, GetSpriteSize(SPR_WARNING_SIGN).height, GetSpriteSize(SPR_FLAG_VEH_STOPPED).height, GetSpriteSize(SPR_FLAG_VEH_RUNNING).height}) + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM; break; case WID_VV_FORCE_PROCEED: @@ -2821,7 +2825,7 @@ public: case OT_GOTO_STATION: { SetDParam(0, v->current_order.GetDestination()); SetDParam(1, v->GetDisplaySpeed()); - str = STR_VEHICLE_STATUS_HEADING_FOR_STATION_VEL; + str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_STATION_VEL : STR_VEHICLE_STATUS_HEADING_FOR_STATION_VEL; break; } @@ -2838,9 +2842,9 @@ public: * evaluating the string in the status bar. */ str = STR_EMPTY; } else if (v->current_order.GetDepotActionType() & ODATFB_HALT) { - str = STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL; + str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL; } else { - str = STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL; + str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL; } break; } @@ -2852,7 +2856,7 @@ public: case OT_GOTO_WAYPOINT: { assert(v->type == VEH_TRAIN || v->type == VEH_SHIP); SetDParam(0, v->current_order.GetDestination()); - str = STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL; + str = HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_WAYPOINT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL; SetDParam(1, v->GetDisplaySpeed()); break; } @@ -2876,12 +2880,12 @@ public: /* Draw the flag plus orders. */ bool rtl = (_current_text_dir == TD_RTL); - uint text_offset = std::max(GetSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetSpriteSize(SPR_FLAG_VEH_RUNNING).width) + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT; + uint text_offset = std::max({GetSpriteSize(SPR_WARNING_SIGN).width, GetSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetSpriteSize(SPR_FLAG_VEH_RUNNING).width}) + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT; int height = r.bottom - r.top; int text_left = r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : text_offset); int text_right = r.right - (rtl ? text_offset : (uint)WD_FRAMERECT_RIGHT); int text_top = r.top + WD_FRAMERECT_TOP + (height - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM - FONT_HEIGHT_NORMAL) / 2; - int image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING; + int image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING; int image_left = (rtl ? text_right + 1 : r.left) + WD_IMGBTN_LEFT; int image_top = r.top + WD_IMGBTN_TOP + (height - WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM - GetSpriteSize(image).height) / 2; int lowered = this->IsWidgetLowered(WID_VV_START_STOP) ? 1 : 0; |