Initial implementation of trace restrict slots
This commit is contained in:
@@ -38,6 +38,9 @@
|
||||
#include "station_base.h"
|
||||
#include "tilehighlight_func.h"
|
||||
#include "zoom_func.h"
|
||||
#include "tracerestrict.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
@@ -176,6 +179,9 @@ DropDownList *BaseVehicleListWindow::BuildActionDropdownList(bool show_autorepla
|
||||
*list->Append() = new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false);
|
||||
*list->Append() = new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false);
|
||||
}
|
||||
if (this->vli.vtype == VEH_TRAIN) {
|
||||
*list->Append() = new DropDownListStringItem(STR_TRACE_RESTRICT_SLOT_MANAGE, ADI_TRACERESTRICT_SLOT_MGMT, false);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -1668,6 +1674,12 @@ public:
|
||||
DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : (DepotCommand)0), this->window_number, GetCmdSendToDepot(this->vli.vtype));
|
||||
break;
|
||||
|
||||
case ADI_TRACERESTRICT_SLOT_MGMT: {
|
||||
extern void ShowTraceRestrictSlotWindow(CompanyID company);
|
||||
ShowTraceRestrictSlotWindow(this->owner);
|
||||
break;
|
||||
}
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
@@ -1867,6 +1879,7 @@ struct VehicleDetailsWindow : Window {
|
||||
TrainDetailsWindowTabs tab; ///< For train vehicles: which tab is displayed.
|
||||
Scrollbar *vscroll;
|
||||
bool vehicle_weight_ratio_line_shown;
|
||||
bool vehicle_slots_line_shown;
|
||||
|
||||
/** Initialize a newly created vehicle details window */
|
||||
VehicleDetailsWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
||||
@@ -1933,6 +1946,12 @@ struct VehicleDetailsWindow : Window {
|
||||
return (v->type == VEH_TRAIN && _settings_client.gui.show_train_weight_ratios_in_details);
|
||||
}
|
||||
|
||||
bool ShouldShowSlotsLine(const Vehicle *v) const
|
||||
{
|
||||
if (v->type != VEH_TRAIN) return false;
|
||||
return HasBit(Train::From(v)->flags, VRF_HAVE_SLOT);
|
||||
}
|
||||
|
||||
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||
{
|
||||
switch (widget) {
|
||||
@@ -1940,8 +1959,10 @@ struct VehicleDetailsWindow : Window {
|
||||
const Vehicle *v = Vehicle::Get(this->window_number);
|
||||
Dimension dim = { 0, 0 };
|
||||
this->vehicle_weight_ratio_line_shown = ShouldShowWeightRatioLine(v);
|
||||
this->vehicle_slots_line_shown = ShouldShowSlotsLine(v);
|
||||
int lines = 4;
|
||||
if (this->vehicle_weight_ratio_line_shown) lines++;
|
||||
if (this->vehicle_slots_line_shown) lines++;
|
||||
size->height = WD_FRAMERECT_TOP + lines * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
|
||||
|
||||
for (uint i = 0; i < 4; i++) SetDParamMaxValue(i, INT16_MAX);
|
||||
@@ -2117,8 +2138,29 @@ struct VehicleDetailsWindow : Window {
|
||||
SetDParam(0, ToPercent16(v->reliability));
|
||||
SetDParam(1, v->breakdowns_since_last_service);
|
||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
||||
if (this->vehicle_weight_ratio_line_shown != should_show_weight_ratio) {
|
||||
bool should_show_slots = this->ShouldShowSlotsLine(v);
|
||||
if (should_show_slots) {
|
||||
std::vector<TraceRestrictSlotID> slots;
|
||||
TraceRestrictGetVehicleSlots(v->index, slots);
|
||||
|
||||
char text_buffer[512];
|
||||
char *buffer = text_buffer;
|
||||
const char * const last = lastof(text_buffer);
|
||||
SetDParam(0, slots.size());
|
||||
buffer = GetString(buffer, STR_TRACE_RESTRICT_SLOT_LIST_HEADER, last);
|
||||
|
||||
for (size_t i = 0; i < slots.size(); i++) {
|
||||
if (i != 0) buffer = GetString(buffer, STR_TRACE_RESTRICT_SLOT_LIST_SEPARATOR, last);
|
||||
buffer = strecpy(buffer, TraceRestrictSlot::Get(slots[i])->name.c_str(), last);
|
||||
}
|
||||
SetDParamStr(0, text_buffer);
|
||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_JUST_RAW_STRING);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
|
||||
if (this->vehicle_weight_ratio_line_shown != should_show_weight_ratio || this->vehicle_slots_line_shown != should_show_slots) {
|
||||
const_cast<VehicleDetailsWindow *>(this)->ReInit();
|
||||
}
|
||||
break;
|
||||
|
Reference in New Issue
Block a user