Merge branch 'master' into jgrpp
Replace build and refit, and group collapse implementations Fix template creation build and refit # Conflicts: # Makefile.bundle.in # config.lib # src/animated_tile.cpp # src/blitter/32bpp_anim.hpp # src/blitter/32bpp_base.hpp # src/blitter/8bpp_base.hpp # src/blitter/null.hpp # src/build_vehicle_gui.cpp # src/command.cpp # src/command_func.h # src/console_gui.cpp # src/core/smallstack_type.hpp # src/date.cpp # src/debug.cpp # src/genworld_gui.cpp # src/ground_vehicle.hpp # src/group_gui.cpp # src/lang/korean.txt # src/linkgraph/linkgraph_gui.h # src/main_gui.cpp # src/misc_gui.cpp # src/network/core/game.h # src/network/core/packet.cpp # src/network/core/udp.cpp # src/network/core/udp.h # src/network/network_content.cpp # src/network/network_type.h # src/network/network_udp.cpp # src/newgrf_house.h # src/openttd.cpp # src/order_cmd.cpp # src/order_gui.cpp # src/os/unix/crashlog_unix.cpp # src/os/windows/crashlog_win.cpp # src/osk_gui.cpp # src/pathfinder/opf/opf_ship.cpp # src/rail_cmd.cpp # src/rail_gui.cpp # src/saveload/saveload.cpp # src/settings.cpp # src/settings_gui.cpp # src/smallmap_gui.h # src/station_base.h # src/station_cmd.cpp # src/table/gameopt_settings.ini # src/table/newgrf_debug_data.h # src/table/settings.ini # src/timetable_gui.cpp # src/toolbar_gui.cpp # src/train_gui.cpp # src/vehicle.cpp # src/vehicle_gui.cpp # src/vehiclelist.cpp # src/viewport.cpp # src/widgets/dropdown.cpp # src/window_gui.h
This commit is contained in:
@@ -82,9 +82,6 @@ static const NWidgetPart _nested_build_vehicle_widgets[] = {
|
||||
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_SEL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_BUILD), SetResize(1, 0), SetFill(1, 0),
|
||||
EndContainer(),
|
||||
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_REFIT_SEL),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_BUILD_REFIT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_BUTTON, STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_TOOLTIP),
|
||||
EndContainer(),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_RENAME), SetResize(1, 0), SetFill(1, 0),
|
||||
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
||||
@@ -100,7 +97,6 @@ byte _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Las
|
||||
bool _engine_sort_last_order[] = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type.
|
||||
bool _engine_sort_show_hidden_engines[] = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type.
|
||||
static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_ANY}; ///< Last set filter criteria, for each vehicle type.
|
||||
static bool _refit_on_buy = false; ///< to save user's choice for at least this game session
|
||||
|
||||
/**
|
||||
* Determines order of engines by engineID
|
||||
@@ -537,11 +533,11 @@ static GUIEngineList::FilterFunction * const _filter_funcs[] = {
|
||||
&CargoFilter,
|
||||
};
|
||||
|
||||
static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine)
|
||||
static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, TestedEngineDetails &te)
|
||||
{
|
||||
CargoArray cap;
|
||||
CargoTypes refits;
|
||||
GetArticulatedVehicleCargoesAndRefits(engine, &cap, &refits);
|
||||
GetArticulatedVehicleCargoesAndRefits(engine, &cap, &refits, te.cargo, te.capacity);
|
||||
|
||||
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
||||
if (cap[c] == 0) continue;
|
||||
@@ -557,19 +553,25 @@ static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine)
|
||||
}
|
||||
|
||||
/* Draw rail wagon specific details */
|
||||
static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
|
||||
static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine_number);
|
||||
|
||||
/* Purchase cost */
|
||||
SetDParam(0, e->GetCost());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
|
||||
if (te.cost != 0) {
|
||||
SetDParam(0, e->GetCost() + te.cost);
|
||||
SetDParam(1, te.cost);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
|
||||
} else {
|
||||
SetDParam(0, e->GetCost());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
|
||||
}
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
||||
/* Wagon weight - (including cargo) */
|
||||
uint weight = e->GetDisplayWeight();
|
||||
SetDParam(0, weight);
|
||||
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * GetTotalCapacityOfArticulatedParts(engine_number) / 16 : 0);
|
||||
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
|
||||
SetDParam(1, cargo_weight + weight);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
@@ -595,14 +597,21 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine
|
||||
}
|
||||
|
||||
/* Draw locomotive specific details */
|
||||
static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
|
||||
static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine_number);
|
||||
|
||||
/* Purchase Cost - Engine weight */
|
||||
SetDParam(0, e->GetCost());
|
||||
SetDParam(1, e->GetDisplayWeight());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
|
||||
if (te.cost != 0) {
|
||||
SetDParam(0, e->GetCost() + te.cost);
|
||||
SetDParam(1, te.cost);
|
||||
SetDParam(2, e->GetDisplayWeight());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
|
||||
} else {
|
||||
SetDParam(0, e->GetCost());
|
||||
SetDParam(1, e->GetDisplayWeight());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
|
||||
}
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
||||
/* Max speed - Engine power */
|
||||
@@ -637,20 +646,26 @@ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engin
|
||||
}
|
||||
|
||||
/* Draw road vehicle specific details */
|
||||
static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number)
|
||||
static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine_number);
|
||||
|
||||
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
|
||||
/* Purchase Cost */
|
||||
SetDParam(0, e->GetCost());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
|
||||
if (te.cost != 0) {
|
||||
SetDParam(0, e->GetCost() + te.cost);
|
||||
SetDParam(1, te.cost);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
|
||||
} else {
|
||||
SetDParam(0, e->GetCost());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
|
||||
}
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
||||
/* Road vehicle weight - (including cargo) */
|
||||
int16 weight = e->GetDisplayWeight();
|
||||
SetDParam(0, weight);
|
||||
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * GetTotalCapacityOfArticulatedParts(engine_number) / 16 : 0);
|
||||
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
|
||||
SetDParam(1, cargo_weight + weight);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
@@ -667,9 +682,16 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
} else {
|
||||
/* Purchase cost - Max speed */
|
||||
SetDParam(0, e->GetCost());
|
||||
SetDParam(1, e->GetDisplayMaxSpeed());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
||||
if (te.cost != 0) {
|
||||
SetDParam(0, e->GetCost() + te.cost);
|
||||
SetDParam(1, te.cost);
|
||||
SetDParam(2, e->GetDisplayMaxSpeed());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
|
||||
} else {
|
||||
SetDParam(0, e->GetCost());
|
||||
SetDParam(2, e->GetDisplayMaxSpeed());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
||||
}
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
|
||||
@@ -682,7 +704,7 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
|
||||
}
|
||||
|
||||
/* Draw ship specific details */
|
||||
static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable)
|
||||
static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine_number);
|
||||
|
||||
@@ -691,13 +713,27 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
|
||||
uint ocean_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, true);
|
||||
uint canal_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, false);
|
||||
|
||||
SetDParam(0, e->GetCost());
|
||||
if (ocean_speed == canal_speed) {
|
||||
SetDParam(1, ocean_speed);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
||||
if (te.cost != 0) {
|
||||
SetDParam(0, e->GetCost() + te.cost);
|
||||
SetDParam(1, te.cost);
|
||||
SetDParam(2, ocean_speed);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
|
||||
} else {
|
||||
SetDParam(0, e->GetCost());
|
||||
SetDParam(1, ocean_speed);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
||||
}
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
} else {
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
|
||||
if (te.cost != 0) {
|
||||
SetDParam(0, e->GetCost() + te.cost);
|
||||
SetDParam(1, te.cost);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
|
||||
} else {
|
||||
SetDParam(0, e->GetCost());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
|
||||
}
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
||||
SetDParam(0, ocean_speed);
|
||||
@@ -710,8 +746,8 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
|
||||
}
|
||||
|
||||
/* Cargo type + capacity */
|
||||
SetDParam(0, e->GetDefaultCargoType());
|
||||
SetDParam(1, e->GetDisplayDefaultCapacity());
|
||||
SetDParam(0, te.cargo);
|
||||
SetDParam(1, te.capacity);
|
||||
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
@@ -733,31 +769,35 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
|
||||
* @param refittable If set, the aircraft can be refitted.
|
||||
* @return Bottom of the used area.
|
||||
*/
|
||||
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable)
|
||||
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine_number);
|
||||
CargoID cargo = e->GetDefaultCargoType();
|
||||
|
||||
/* Purchase cost - Max speed */
|
||||
SetDParam(0, e->GetCost());
|
||||
SetDParam(1, e->GetDisplayMaxSpeed());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
||||
if (te.cost != 0) {
|
||||
SetDParam(0, e->GetCost() + te.cost);
|
||||
SetDParam(1, te.cost);
|
||||
SetDParam(2, e->GetDisplayMaxSpeed());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
|
||||
} else {
|
||||
SetDParam(0, e->GetCost());
|
||||
SetDParam(1, e->GetDisplayMaxSpeed());
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
||||
}
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
||||
/* Cargo capacity */
|
||||
uint16 mail_capacity;
|
||||
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
|
||||
if (mail_capacity > 0) {
|
||||
SetDParam(0, cargo);
|
||||
SetDParam(1, capacity);
|
||||
if (te.mail_capacity > 0) {
|
||||
SetDParam(0, te.cargo);
|
||||
SetDParam(1, te.capacity);
|
||||
SetDParam(2, CT_MAIL);
|
||||
SetDParam(3, mail_capacity);
|
||||
SetDParam(3, te.mail_capacity);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
|
||||
} else {
|
||||
/* Note, if the default capacity is selected by the refit capacity
|
||||
* callback, then the capacity shown is likely to be incorrect. */
|
||||
SetDParam(0, cargo);
|
||||
SetDParam(1, capacity);
|
||||
SetDParam(0, te.cargo);
|
||||
SetDParam(1, te.capacity);
|
||||
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
|
||||
}
|
||||
@@ -814,7 +854,7 @@ static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
|
||||
* @param engine_number the engine of which to draw the info of
|
||||
* @return y after drawing all the text
|
||||
*/
|
||||
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
|
||||
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine_number);
|
||||
YearMonthDay ymd;
|
||||
@@ -826,30 +866,30 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
|
||||
default: NOT_REACHED();
|
||||
case VEH_TRAIN:
|
||||
if (e->u.rail.railveh_type == RAILVEH_WAGON) {
|
||||
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail);
|
||||
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
|
||||
} else {
|
||||
y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail);
|
||||
y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
|
||||
}
|
||||
articulated_cargo = true;
|
||||
break;
|
||||
|
||||
case VEH_ROAD:
|
||||
y = DrawRoadVehPurchaseInfo(left, right, y, engine_number);
|
||||
y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
|
||||
articulated_cargo = true;
|
||||
break;
|
||||
|
||||
case VEH_SHIP:
|
||||
y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable);
|
||||
y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
|
||||
break;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable);
|
||||
y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
|
||||
break;
|
||||
}
|
||||
|
||||
if (articulated_cargo) {
|
||||
/* Cargo type + capacity, or N/A */
|
||||
int new_y = DrawCargoCapacityInfo(left, right, y, engine_number);
|
||||
int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, te);
|
||||
|
||||
if (new_y == y) {
|
||||
SetDParam(0, CT_INVALID);
|
||||
@@ -901,7 +941,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
|
||||
static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
|
||||
|
||||
/* Obligatory sanity checks! */
|
||||
assert(max <= eng_list->Length());
|
||||
assert(max <= eng_list->size());
|
||||
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
int step_size = GetEngineListHeight(type);
|
||||
@@ -993,9 +1033,30 @@ struct BuildVehicleWindow : Window {
|
||||
byte cargo_filter_criteria; ///< Selected cargo filter
|
||||
int details_height; ///< Minimal needed height of the details panels (found so far).
|
||||
Scrollbar *vscroll;
|
||||
bool build_and_refit; ///< Build and refit. This is beauty, but we need some persistence to save user choice for this game session at least
|
||||
bool virtual_train_mode; ///< Are we building a virtual train?
|
||||
Train **virtual_train_out; ///< Virtual train ptr
|
||||
TestedEngineDetails te; ///< Tested cost and capacity after refit.
|
||||
|
||||
void SetBuyVehicleText()
|
||||
{
|
||||
NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
|
||||
|
||||
bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter[this->cargo_filter_criteria] != CF_ANY && this->cargo_filter[this->cargo_filter_criteria] != CF_NONE;
|
||||
if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter[this->cargo_filter_criteria];
|
||||
|
||||
if (this->virtual_train_mode) {
|
||||
widget->widget_data = STR_TMPL_CONFIRM;
|
||||
widget->tool_tip = STR_TMPL_CONFIRM;
|
||||
} else {
|
||||
if (refit) {
|
||||
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type;
|
||||
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type;
|
||||
} else {
|
||||
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type;
|
||||
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type, Train **virtual_train_out) : Window(desc)
|
||||
{
|
||||
@@ -1033,7 +1094,6 @@ struct BuildVehicleWindow : Window {
|
||||
* So we just hide it, and enlarge the Rename button by the now vacant place. */
|
||||
if (this->listview_mode) {
|
||||
this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
|
||||
this->GetWidget<NWidgetStacked>(WID_BV_BUILD_REFIT_SEL)->SetDisplayedPlane(SZSP_NONE);
|
||||
}
|
||||
|
||||
/* disable renaming engines in network games if you are not the server */
|
||||
@@ -1045,18 +1105,6 @@ struct BuildVehicleWindow : Window {
|
||||
widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
|
||||
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type;
|
||||
|
||||
this->build_and_refit = _refit_on_buy;
|
||||
this->SetWidgetLoweredState(WID_BV_BUILD_REFIT, this->build_and_refit);
|
||||
|
||||
widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
|
||||
if (this->virtual_train_mode) {
|
||||
widget->widget_data = STR_TMPL_CONFIRM;
|
||||
widget->tool_tip = STR_TMPL_CONFIRM;
|
||||
} else {
|
||||
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + type;
|
||||
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + type;
|
||||
}
|
||||
|
||||
widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
|
||||
widget->widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
|
||||
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
|
||||
@@ -1075,7 +1123,11 @@ struct BuildVehicleWindow : Window {
|
||||
this->eng_list.ForceRebuild();
|
||||
this->GenerateBuildList(); // generate the list, since we need it in the next line
|
||||
/* Select the first engine in the list as default when opening the window */
|
||||
if (this->eng_list.Length() > 0) this->sel_engine = this->eng_list[0];
|
||||
if (this->eng_list.size() > 0) {
|
||||
this->SelectEngine(this->eng_list[0]);
|
||||
} else {
|
||||
this->SelectEngine(INVALID_ENGINE);
|
||||
}
|
||||
}
|
||||
|
||||
/** Populate the filter list and set the cargo filter criteria. */
|
||||
@@ -1122,7 +1174,42 @@ struct BuildVehicleWindow : Window {
|
||||
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
|
||||
}
|
||||
|
||||
void OnInit()
|
||||
void SelectEngine(EngineID engine)
|
||||
{
|
||||
CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
|
||||
if (cargo == CF_ANY) cargo = CF_NONE;
|
||||
|
||||
this->sel_engine = engine;
|
||||
this->SetBuyVehicleText();
|
||||
|
||||
if (this->sel_engine == INVALID_ENGINE) return;
|
||||
|
||||
const Engine *e = Engine::Get(this->sel_engine);
|
||||
if (!e->CanCarryCargo()) {
|
||||
this->te.cost = 0;
|
||||
this->te.cargo = CT_INVALID;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->listview_mode) {
|
||||
/* Query for cost and refitted capacity */
|
||||
CommandCost ret = DoCommand(this->window_number, this->sel_engine | (cargo << 24), 0, DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type), NULL);
|
||||
if (ret.Succeeded()) {
|
||||
this->te.cost = ret.GetCost() - e->GetCost();
|
||||
this->te.capacity = _returned_refit_capacity;
|
||||
this->te.mail_capacity = _returned_mail_refit_capacity;
|
||||
this->te.cargo = (cargo == CT_INVALID) ? e->GetDefaultCargoType() : cargo;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Purchase test was not possible or failed, fill in the defaults instead. */
|
||||
this->te.cost = 0;
|
||||
this->te.capacity = e->GetDisplayDefaultCapacity(&this->te.mail_capacity);
|
||||
this->te.cargo = e->GetDefaultCargoType();
|
||||
}
|
||||
|
||||
void OnInit() override
|
||||
{
|
||||
this->SetCargoFilterArray();
|
||||
}
|
||||
@@ -1131,10 +1218,10 @@ struct BuildVehicleWindow : Window {
|
||||
void FilterEngineList()
|
||||
{
|
||||
this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
|
||||
if (0 == this->eng_list.Length()) { // no engine passed through the filter, invalidate the previously selected engine
|
||||
this->sel_engine = INVALID_ENGINE;
|
||||
} else if (!this->eng_list.Contains(this->sel_engine)) { // previously selected engine didn't pass the filter, select the first engine of the list
|
||||
this->sel_engine = this->eng_list[0];
|
||||
if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
|
||||
this->SelectEngine(INVALID_ENGINE);
|
||||
} else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
|
||||
this->SelectEngine(this->eng_list[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1154,7 +1241,7 @@ struct BuildVehicleWindow : Window {
|
||||
|
||||
this->filter.railtype = (this->listview_mode || this->virtual_train_mode) ? RAILTYPE_END : GetRailType(this->window_number);
|
||||
|
||||
this->eng_list.Clear();
|
||||
this->eng_list.clear();
|
||||
|
||||
/* Make list of all available train engines and wagons.
|
||||
* Also check to see if the previously selected engine is still available,
|
||||
@@ -1172,7 +1259,7 @@ struct BuildVehicleWindow : Window {
|
||||
/* Filter now! So num_engines and num_wagons is valid */
|
||||
if (!FilterSingleEngine(eid)) continue;
|
||||
|
||||
*this->eng_list.Append() = eid;
|
||||
this->eng_list.push_back(eid);
|
||||
|
||||
if (rvi->railveh_type != RAILVEH_WAGON) {
|
||||
num_engines++;
|
||||
@@ -1183,7 +1270,7 @@ struct BuildVehicleWindow : Window {
|
||||
if (eid == this->sel_engine) sel_id = eid;
|
||||
}
|
||||
|
||||
this->sel_engine = sel_id;
|
||||
this->SelectEngine(sel_id);
|
||||
|
||||
/* make engines first, and then wagons, sorted by selected sort_criteria */
|
||||
_engine_sort_direction = false;
|
||||
@@ -1202,7 +1289,7 @@ struct BuildVehicleWindow : Window {
|
||||
{
|
||||
EngineID sel_id = INVALID_ENGINE;
|
||||
|
||||
this->eng_list.Clear();
|
||||
this->eng_list.clear();
|
||||
|
||||
const Engine *e;
|
||||
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
|
||||
@@ -1210,29 +1297,29 @@ struct BuildVehicleWindow : Window {
|
||||
EngineID eid = e->index;
|
||||
if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
|
||||
if (!HasBit(this->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
|
||||
*this->eng_list.Append() = eid;
|
||||
this->eng_list.push_back(eid);
|
||||
|
||||
if (eid == this->sel_engine) sel_id = eid;
|
||||
}
|
||||
this->sel_engine = sel_id;
|
||||
this->SelectEngine(sel_id);
|
||||
}
|
||||
|
||||
/* Figure out what ship EngineIDs to put in the list */
|
||||
void GenerateBuildShipList()
|
||||
{
|
||||
EngineID sel_id = INVALID_ENGINE;
|
||||
this->eng_list.Clear();
|
||||
this->eng_list.clear();
|
||||
|
||||
const Engine *e;
|
||||
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) {
|
||||
if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
|
||||
EngineID eid = e->index;
|
||||
if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
|
||||
*this->eng_list.Append() = eid;
|
||||
this->eng_list.push_back(eid);
|
||||
|
||||
if (eid == this->sel_engine) sel_id = eid;
|
||||
}
|
||||
this->sel_engine = sel_id;
|
||||
this->SelectEngine(sel_id);
|
||||
}
|
||||
|
||||
/* Figure out what aircraft EngineIDs to put in the list */
|
||||
@@ -1240,7 +1327,7 @@ struct BuildVehicleWindow : Window {
|
||||
{
|
||||
EngineID sel_id = INVALID_ENGINE;
|
||||
|
||||
this->eng_list.Clear();
|
||||
this->eng_list.clear();
|
||||
|
||||
const Station *st = this->listview_mode ? NULL : Station::GetByTile(this->window_number);
|
||||
|
||||
@@ -1256,11 +1343,11 @@ struct BuildVehicleWindow : Window {
|
||||
/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
|
||||
if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
|
||||
|
||||
*this->eng_list.Append() = eid;
|
||||
this->eng_list.push_back(eid);
|
||||
if (eid == this->sel_engine) sel_id = eid;
|
||||
}
|
||||
|
||||
this->sel_engine = sel_id;
|
||||
this->SelectEngine(sel_id);
|
||||
}
|
||||
|
||||
/* Generate the list of vehicles */
|
||||
@@ -1271,7 +1358,7 @@ struct BuildVehicleWindow : Window {
|
||||
default: NOT_REACHED();
|
||||
case VEH_TRAIN:
|
||||
this->GenerateBuildTrainList();
|
||||
this->eng_list.Compact();
|
||||
this->eng_list.shrink_to_fit();
|
||||
this->eng_list.RebuildDone();
|
||||
return; // trains should not reach the last sorting
|
||||
case VEH_ROAD:
|
||||
@@ -1290,11 +1377,11 @@ struct BuildVehicleWindow : Window {
|
||||
_engine_sort_direction = this->descending_sort_order;
|
||||
EngList_Sort(&this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]);
|
||||
|
||||
this->eng_list.Compact();
|
||||
this->eng_list.shrink_to_fit();
|
||||
this->eng_list.RebuildDone();
|
||||
}
|
||||
|
||||
void OnClick(Point pt, int widget, int click_count)
|
||||
void OnClick(Point pt, int widget, int click_count) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_BV_SORT_ASCENDING_DESCENDING:
|
||||
@@ -1314,8 +1401,8 @@ struct BuildVehicleWindow : Window {
|
||||
|
||||
case WID_BV_LIST: {
|
||||
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BV_LIST);
|
||||
size_t num_items = this->eng_list.Length();
|
||||
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
|
||||
size_t num_items = this->eng_list.size();
|
||||
this->SelectEngine((i < num_items) ? this->eng_list[i] : INVALID_ENGINE);
|
||||
this->SetDirty();
|
||||
if (_ctrl_pressed) {
|
||||
this->OnClick(pt, WID_BV_SHOW_HIDE, 1);
|
||||
@@ -1341,13 +1428,6 @@ struct BuildVehicleWindow : Window {
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_BV_BUILD_REFIT: {
|
||||
_refit_on_buy = this->build_and_refit = !this->build_and_refit;
|
||||
this->SetWidgetLoweredState(WID_BV_BUILD_REFIT, this->build_and_refit);
|
||||
this->SetDirty();
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_BV_BUILD: {
|
||||
EngineID sel_eng = this->sel_engine;
|
||||
if (sel_eng != INVALID_ENGINE) {
|
||||
@@ -1361,19 +1441,9 @@ struct BuildVehicleWindow : Window {
|
||||
? CcBuildWagon : CcBuildPrimaryVehicle;
|
||||
cmd = GetCmdBuildVeh(this->vehicle_type);
|
||||
}
|
||||
if (!this->IsWidgetDisabled(WID_BV_BUILD_REFIT) && this->build_and_refit) {
|
||||
/* build and refit */
|
||||
char text_buffer[2];
|
||||
text_buffer[0] = 'R';
|
||||
text_buffer[1] = this->cargo_filter[this->cargo_filter_criteria];
|
||||
if ((cmd & 0xFFFF) == CMD_BUILD_VEHICLE) {
|
||||
cmd = (cmd & ~0xFFFF) | CMD_BUILD_VEHICLE_NT;
|
||||
}
|
||||
DoCommandP(this->window_number, sel_eng, 0, cmd, callback, text_buffer, true, 2);
|
||||
} else {
|
||||
/* build only */
|
||||
DoCommandP(this->window_number, sel_eng, 0, cmd, callback);
|
||||
}
|
||||
CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
|
||||
if (cargo == CF_ANY) cargo = CF_NONE;
|
||||
DoCommandP(this->window_number, sel_eng | (cargo << 24), 0, cmd, callback);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1395,7 +1465,7 @@ struct BuildVehicleWindow : Window {
|
||||
* @param data Information about the changed data.
|
||||
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
||||
*/
|
||||
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
||||
{
|
||||
if (!gui_scope) return;
|
||||
/* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
|
||||
@@ -1408,7 +1478,7 @@ struct BuildVehicleWindow : Window {
|
||||
this->eng_list.ForceRebuild();
|
||||
}
|
||||
|
||||
virtual void SetStringParameters(int widget) const
|
||||
void SetStringParameters(int widget) const override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_BV_CAPTION:
|
||||
@@ -1440,7 +1510,7 @@ struct BuildVehicleWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_BV_LIST:
|
||||
@@ -1461,6 +1531,13 @@ struct BuildVehicleWindow : Window {
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_BV_BUILD:
|
||||
*size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type);
|
||||
*size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type));
|
||||
size->width += padding.width;
|
||||
size->height += padding.height;
|
||||
break;
|
||||
|
||||
case WID_BV_SHOW_HIDE:
|
||||
*size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
|
||||
*size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type));
|
||||
@@ -1470,11 +1547,11 @@ struct BuildVehicleWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DrawWidget(const Rect &r, int widget) const
|
||||
void DrawWidget(const Rect &r, int widget) const override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_BV_LIST:
|
||||
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.Length()), this->sel_engine, false, DEFAULT_GROUP);
|
||||
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size()), this->sel_engine, false, DEFAULT_GROUP);
|
||||
break;
|
||||
|
||||
case WID_BV_SORT_ASCENDING_DESCENDING:
|
||||
@@ -1483,20 +1560,13 @@ struct BuildVehicleWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
void OnPaint() override
|
||||
{
|
||||
this->GenerateBuildList();
|
||||
this->vscroll->SetCount(this->eng_list.Length());
|
||||
this->vscroll->SetCount(this->eng_list.size());
|
||||
|
||||
this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD, WID_BV_RENAME, WIDGET_LIST_END);
|
||||
|
||||
// disable build and refit if all or none cargo type selected
|
||||
if (this->cargo_filter[this->cargo_filter_criteria] == CF_ANY || this->cargo_filter[this->cargo_filter_criteria] == CF_NONE) {
|
||||
this->DisableWidget(WID_BV_BUILD_REFIT);
|
||||
} else {
|
||||
this->EnableWidget(WID_BV_BUILD_REFIT);
|
||||
}
|
||||
|
||||
this->DrawWidgets();
|
||||
|
||||
if (!this->IsShaded()) {
|
||||
@@ -1505,7 +1575,7 @@ struct BuildVehicleWindow : Window {
|
||||
if (this->sel_engine != INVALID_ENGINE) {
|
||||
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_BV_PANEL);
|
||||
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
|
||||
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine);
|
||||
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine, this->te);
|
||||
needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
|
||||
}
|
||||
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
|
||||
@@ -1517,14 +1587,14 @@ struct BuildVehicleWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
void OnQueryTextFinished(char *str) override
|
||||
{
|
||||
if (str == NULL) return;
|
||||
|
||||
DoCommandP(0, this->rename_engine, 0, CMD_RENAME_ENGINE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type), NULL, str);
|
||||
}
|
||||
|
||||
virtual void OnDropdownSelect(int widget, int index)
|
||||
void OnDropdownSelect(int widget, int index) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_BV_SORT_DROPDOWN:
|
||||
@@ -1542,13 +1612,14 @@ struct BuildVehicleWindow : Window {
|
||||
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
||||
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
|
||||
this->eng_list.ForceRebuild();
|
||||
this->SelectEngine(this->sel_engine);
|
||||
}
|
||||
break;
|
||||
}
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
virtual void OnResize()
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_BV_LIST);
|
||||
}
|
||||
|
Reference in New Issue
Block a user