Add: NewGRF Badges.
This commit is contained in:
committed by
Peter Nelson
parent
ca3b5ed6c1
commit
8f14894024
+33
-3
@@ -39,6 +39,7 @@
|
||||
#include "waypoint_cmd.h"
|
||||
#include "road_cmd.h"
|
||||
#include "tunnelbridge_cmd.h"
|
||||
#include "newgrf_badge.h"
|
||||
#include "newgrf_roadstop.h"
|
||||
#include "picker_gui.h"
|
||||
#include "timer/timer.h"
|
||||
@@ -1184,6 +1185,8 @@ class RoadStopPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass>
|
||||
public:
|
||||
RoadStopPickerCallbacks(const std::string &ini_group) : PickerCallbacksNewGRFClass<RoadStopClass>(ini_group) {}
|
||||
|
||||
GrfSpecFeature GetFeature() const override { return GSF_ROADSTOPS; }
|
||||
|
||||
StringID GetClassTooltip() const override;
|
||||
StringID GetTypeTooltip() const override;
|
||||
|
||||
@@ -1231,6 +1234,14 @@ public:
|
||||
return (spec == nullptr) ? STR_STATION_CLASS_DFLT_ROADSTOP : spec->name;
|
||||
}
|
||||
|
||||
std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
|
||||
{
|
||||
const auto *spec = this->GetSpec(cls_id, id);
|
||||
if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return {};
|
||||
if (spec == nullptr) return {};
|
||||
return spec->badges;
|
||||
}
|
||||
|
||||
bool IsTypeAvailable(int cls_id, int id) const override
|
||||
{
|
||||
const auto *spec = this->GetSpec(cls_id, id);
|
||||
@@ -1347,6 +1358,8 @@ public:
|
||||
|
||||
void OnPaint() override
|
||||
{
|
||||
const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
|
||||
|
||||
this->DrawWidgets();
|
||||
|
||||
int rad = _settings_game.station.modified_catchment ? ((this->window_class == WC_BUS_STATION) ? CA_BUS : CA_TRUCK) : CA_UNMODIFIED;
|
||||
@@ -1363,6 +1376,7 @@ public:
|
||||
Rect r = this->GetWidget<NWidgetBase>(WID_BROS_ACCEPTANCE)->GetCurrentRect();
|
||||
const int bottom = r.bottom;
|
||||
r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
|
||||
if (spec != nullptr) r.top = DrawBadgeNameList(r, spec->badges, GSF_ROADSTOPS);
|
||||
r.top = DrawStationCoverageAreaText(r, sct, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
r.top = DrawStationCoverageAreaText(r, sct, rad, true);
|
||||
/* Resize background if the window is too small.
|
||||
@@ -1603,6 +1617,8 @@ class RoadWaypointPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopCl
|
||||
public:
|
||||
RoadWaypointPickerCallbacks() : PickerCallbacksNewGRFClass<RoadStopClass>("fav_road_waypoints") {}
|
||||
|
||||
GrfSpecFeature GetFeature() const override { return GSF_ROADSTOPS; }
|
||||
|
||||
StringID GetClassTooltip() const override { return STR_PICKER_WAYPOINT_CLASS_TOOLTIP; }
|
||||
StringID GetTypeTooltip() const override { return STR_PICKER_WAYPOINT_TYPE_TOOLTIP; }
|
||||
|
||||
@@ -1642,6 +1658,13 @@ public:
|
||||
return (spec == nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
|
||||
}
|
||||
|
||||
std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
|
||||
{
|
||||
const auto *spec = this->GetSpec(cls_id, id);
|
||||
if (spec == nullptr) return {};
|
||||
return spec->badges;
|
||||
}
|
||||
|
||||
bool IsTypeAvailable(int cls_id, int id) const override
|
||||
{
|
||||
return IsRoadStopAvailable(this->GetSpec(cls_id, id), StationType::RoadWaypoint);
|
||||
@@ -1765,6 +1788,9 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
|
||||
}
|
||||
}
|
||||
|
||||
/* Shared list so that each item can take ownership. */
|
||||
auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_ROADTYPES);
|
||||
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
/* If it's not used ever, don't show it to the user. */
|
||||
if (!HasBit(used_roadtypes, rt)) continue;
|
||||
@@ -1774,10 +1800,10 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
|
||||
SetDParam(0, rti->strings.menu_text);
|
||||
SetDParam(1, rti->max_speed / 2);
|
||||
if (for_replacement) {
|
||||
list.push_back(MakeDropDownListStringItem(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt)));
|
||||
list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt)));
|
||||
} else {
|
||||
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
||||
list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
|
||||
list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1808,6 +1834,10 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
|
||||
d = maxdim(d, GetSpriteSize(rti->gui_sprites.build_x_road));
|
||||
}
|
||||
|
||||
/* Shared list so that each item can take ownership. */
|
||||
auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_ROADTYPES);
|
||||
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
if (!HasBit(used_roadtypes, rt)) continue;
|
||||
|
||||
@@ -1816,7 +1846,7 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
|
||||
SetDParam(0, rti->strings.menu_text);
|
||||
SetDParam(1, rti->max_speed / 2);
|
||||
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
||||
list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
|
||||
list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
|
||||
}
|
||||
|
||||
if (list.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user