Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: BuildVehicleSmartGUI #7653

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
628 changes: 599 additions & 29 deletions src/build_vehicle_gui.cpp

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/engine_gui.h
Expand Up @@ -13,6 +13,7 @@
#define ENGINE_GUI_H

#include "engine_type.h"
#include "group_type.h"
#include "sortlist_type.h"
#include "gfx_type.h"
#include "vehicle_type.h"
Expand All @@ -36,10 +37,11 @@ extern bool _engine_sort_direction;
extern byte _engine_sort_last_criteria[];
extern bool _engine_sort_last_order[];
extern bool _engine_sort_show_hidden_engines[];
extern const StringID _engine_sort_listing[][12];
extern EngList_SortTypeFunction * const _engine_sort_functions[][11];
extern const StringID _engine_sort_listing[][15];
extern EngList_SortTypeFunction * const _engine_sort_functions[][14];

uint GetEngineListHeight(VehicleType type);
void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList* eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button);

#endif /* ENGINE_GUI_H */
35 changes: 35 additions & 0 deletions src/lang/english.txt
Expand Up @@ -316,6 +316,8 @@ STR_SORT_BY_CARGO_CAPACITY :Cargo capacity
STR_SORT_BY_RANGE :Range
STR_SORT_BY_POPULATION :Population
STR_SORT_BY_RATING :Rating
STR_SORT_BY_PRICE_BY_CAPACITY :Price/capacity
STR_SORT_BY_LENGTH_BY_CAPACITY :Length/capacity

# Tooltips for the main toolbar
STR_TOOLBAR_TOOLTIP_PAUSE_GAME :{BLACK}Pause game
Expand Down Expand Up @@ -5128,3 +5130,36 @@ STR_PLANE :{BLACK}{PLANE}
STR_SHIP :{BLACK}{SHIP}

STR_TOOLBAR_RAILTYPE_VELOCITY :{STRING} ({VELOCITY})

STR_BUILD_VEHICLE_SMART :Smart build vehicle menu
STR_BUILD_VEHICLE_SMART_HELPTEXT :Smart build vehicle menu
STR_BUILD_VEHICLE_DETAIL :{BLACK}Detail
STR_BUILD_VEHICLE_DETAIL_TOOLTIP :{BLACK}Extended options for comfortable unit select
STR_BUILD_VEHICLE_AUTO_TRAIN :{BLACK}Take the train parameters from the depot
STR_BUILD_VEHICLE_AUTO_TRAIN_TOOLTIP :{BLACK}Take parameters from the first train from the depot (maximum weight, available speed, train length)
STR_BUILD_VEHICLE_FILTER :{BLACK}Filter
STR_BUILD_VEHICLE_FILTER_TOOLTIP :{BLACK}Open filters panel
STR_BUILD_VEHICLE_INCLINE_LABEL :{BLACK}Allow slopes:
STR_BUILD_VEHICLE_INCLINE_EDITOR :{ORANGE}{NUM}%
STR_BUILD_VEHICLE_INCLINE_TOOLTIP :{BLACK}An opportunity to overcome the incline
STR_BUILD_VEHICLE_LOCOMOTIVES :{BLACK}Locomotives
STR_BUILD_VEHICLE_RAILCARS :{BLACK}Railcars
STR_BUILD_VEHICLE_WAGONS :{BLACK}Wagons
STR_BUILD_VEHICLE_TRAIN_WEIGHT_LABEL :{BLACK}Train weight:
STR_BUILD_VEHICLE_TRAIN_WEIGHT_EDITOR :{ORANGE}{WEIGHT_SHORT}
STR_BUILD_VEHICLE_TRAIN_WEIGHT_TOOLTIP :{BLACK}Preferred train weight (without locomotive)
STR_BUILD_VEHICLE_EDIT_TRAIN_WEIGHT :{BLACK}Enter preferred train weight
STR_BUILD_VEHICLE_CARGO_FILTER_LABEL :{BLACK}Cargo filter:
STR_BUILD_VEHICLE_CARGO_FILTER_LABEL_TOOLTIP :{BLACK}Cargo filter
STR_BUILD_VEHICLE_TRAIN_SPEED_LABEL :{BLACK}Train speed:
STR_BUILD_VEHICLE_TRAIN_SPEED_EDITOR :{ORANGE}{VELOCITY}
STR_BUILD_VEHICLE_TRAIN_SPEED_TOOLTIP :{BLACK}Preferred train speed
STR_BUILD_VEHICLE_EDIT_TRAIN_SPEED :{BLACK}Enter preferred train speed
STR_BUILD_VEHICLE_TRAIN_LENGTH_LABEL :{BLACK}Train length:
STR_BUILD_VEHICLE_TRAIN_LENGTH_EDITOR :{ORANGE}{NUM}
STR_BUILD_VEHICLE_TRAIN_LENGTH_TOOLTIP :{BLACK}Expected train length (power calculation for overcoming inclines)
STR_BUILD_VEHICLE_EDIT_TRAIN_LENGTH :{BLACK}Enter expected train length
STR_BUILD_VEHICLE_SLOPE_LENGTH_LABEL :{BLACK}Slope length:
STR_BUILD_VEHICLE_SLOPE_LENGTH_EDITOR :{ORANGE}{NUM}
STR_BUILD_VEHICLE_SLOPE_LENGTH_TOOLTIP :{BLACK}Expected slope length (power calculation for overcoming inclines)
STR_BUILD_VEHICLE_EDIT_SLOPE_LENGTH :{BLACK}Enter expected slope length
20 changes: 20 additions & 0 deletions src/script/api/script_window.hpp
Expand Up @@ -1000,6 +1000,26 @@ class ScriptWindow : public ScriptObject {
WID_BV_SHOW_HIDE = ::WID_BV_SHOW_HIDE, ///< Button to hide or show the selected engine.
WID_BV_BUILD_SEL = ::WID_BV_BUILD_SEL, ///< Build button.
WID_BV_RENAME = ::WID_BV_RENAME, ///< Rename button.
// build vehicle smart:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole-line comments are usually marked with /* */, the simple double-slash style is reserved for end-of-line comments with very short explanations.

WID_BV_FILTER_BUTTON = ::WID_BV_FILTER_BUTTON, ///< Show filters panel.
WID_BV_FILTER_CONTAINER = ::WID_BV_FILTER_CONTAINER, ///< Filters container.
WID_BV_RAIL_WAGON = ::WID_BV_RAIL_WAGON, ///< Show/hide wagons.
WID_BV_RAIL_MOTOR_WAGON = ::WID_BV_RAIL_MOTOR_WAGON, ///< Show/hide motor-wagons.
WID_BV_RAIL_LOCOMOTIVE = ::WID_BV_RAIL_LOCOMOTIVE, ///< Show/hide locomotive.
WID_BV_RAIL_WEIGHT_INCREASE = ::WID_BV_RAIL_WEIGHT_INCREASE, ///< Increase train weight.
WID_BV_RAIL_WEIGHT_DECREASE = ::WID_BV_RAIL_WEIGHT_DECREASE, ///< Decrease train weight.
WID_BV_RAIL_WEIGHT_EDIT = ::WID_BV_RAIL_WEIGHT_EDIT, ///< Edit train weight directly.
WID_BV_RAIL_SPEED_INCREASE = ::WID_BV_RAIL_SPEED_INCREASE, ///< Increase train speed.
WID_BV_RAIL_SPEED_DECREASE = ::WID_BV_RAIL_SPEED_DECREASE, ///< Decrease train speed.
WID_BV_RAIL_SPEED_EDIT = ::WID_BV_RAIL_SPEED_EDIT, ///< Edit train speed directly.
WID_BV_TRAIN_LENGTH_INCREASE = ::WID_BV_TRAIN_LENGTH_INCREASE, ///< Increase train length.
WID_BV_TRAIN_LENGTH_DECREASE = ::WID_BV_TRAIN_LENGTH_DECREASE, ///< Decrease train length.
WID_BV_TRAIN_LENGTH_EDIT = ::WID_BV_TRAIN_LENGTH_EDIT, ///< Edit train length directly.
WID_BV_SLOPE_LENGTH_INCREASE = ::WID_BV_SLOPE_LENGTH_INCREASE, ///< Increase slope length.
WID_BV_SLOPE_LENGTH_DECREASE = ::WID_BV_SLOPE_LENGTH_DECREASE, ///< Decrease slope length.
WID_BV_SLOPE_LENGTH_EDIT = ::WID_BV_SLOPE_LENGTH_EDIT, ///< Edit slope length directly.
WID_BV_SLOPE = ::WID_BV_SLOPE, ///< Calculate the effect of the slopes.
WID_BV_TRAIN_FROM_DEPOT = ::WID_BV_TRAIN_FROM_DEPOT, ///< Take settings from train in depot.
};

/* automatically generated from ../../widgets/cheat_widget.h */
Expand Down
1 change: 1 addition & 0 deletions src/settings_gui.cpp
Expand Up @@ -1552,6 +1552,7 @@ static SettingsContainer &GetSettingsTree()

SettingsPage *construction = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_CONSTRUCTION));
{
construction->Add(new SettingEntry("gui.build_vehicle_smart_gui"));
construction->Add(new SettingEntry("gui.link_terraform_toolbar"));
construction->Add(new SettingEntry("gui.enable_signal_gui"));
construction->Add(new SettingEntry("gui.persistent_buildingtools"));
Expand Down
2 changes: 2 additions & 0 deletions src/settings_type.h
Expand Up @@ -151,6 +151,8 @@ struct GUISettings {
uint16 console_backlog_timeout; ///< the minimum amount of time items should be in the console backlog before they will be removed in ~3 seconds granularity.
uint16 console_backlog_length; ///< the minimum amount of items in the console backlog before items will be removed.

bool build_vehicle_smart_gui; ///< build vehicle smart gui

uint8 station_gui_group_order; ///< the order of grouping cargo entries in the station gui
uint8 station_gui_sort_by; ///< sort cargo entries in the station gui by station name or amount
uint8 station_gui_sort_order; ///< the sort order of entries in the station gui - ascending or descending
Expand Down
9 changes: 9 additions & 0 deletions src/table/settings.ini
Expand Up @@ -3156,6 +3156,15 @@ str = STR_CONFIG_SETTING_EXPENSES_LAYOUT
strhelp = STR_CONFIG_SETTING_EXPENSES_LAYOUT_HELPTEXT
proc = RedrawScreen

[SDTC_BOOL]
base = GameSettings
var = gui.build_vehicle_smart_gui
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
def = true
str = STR_BUILD_VEHICLE_SMART
strhelp = STR_BUILD_VEHICLE_SMART_HELPTEXT
cat = SC_BASIC

[SDTC_VAR]
var = gui.station_gui_group_order
type = SLE_UINT8
Expand Down
66 changes: 64 additions & 2 deletions src/train.h
Expand Up @@ -174,6 +174,68 @@ struct Train FINAL : public GroundVehicle<Train, VEH_TRAIN> {
* vehicle. */
return this->gcache.cached_veh_length / 2 + (this->Next() != nullptr ? this->Next()->gcache.cached_veh_length + 1 : 0) / 2;
}
/**
* @return max weight (with cargo) of all train
*/
uint16 GetSummaryMaxWeight() const
{
uint16 weight = 0;
for (Train* u = this->First(); u != NULL; u = u->Next()) {
weight += u->GetMaxWeight();
}
return weight;
}

/**
* @return current length of all train in tile units.
*/
uint16 GetSummaryLength() const
{
uint16 length = 0;
for (Train* u = this->First(); u != NULL; u = u->Next()) {
length += u->GetLength();
}
return length;
}

/**
* @return current weight of all train
*/
uint16 GetSummaryWeight() const
{
uint16 weight = 0;
for (Train* u = this->First(); u != NULL; u = u->Next()) {
weight += u->GetWeight();
}
return weight;
}

/**
* @return length value from the engine in tile units.
*/
inline uint16 GetLength() const
{
return VEHICLE_LENGTH - this->GetEngine()->u.rail.shorten_factor;
}

/**
* Allows to know the weight value that this vehicle will use.
* @return Weight value from the engine in tonnes.
*/
inline uint16 GetWeight() const
{
return this->GetCustomWeight(this->cargo.StoredCount());
}

inline uint16 GetMinWeight() const
{
return this->GetCustomWeight(0);
}

inline uint16 GetMaxWeight() const
{
return this->GetCustomWeight(this->cargo_cap);
}

protected: // These functions should not be called outside acceleration code.

Expand Down Expand Up @@ -212,9 +274,9 @@ struct Train FINAL : public GroundVehicle<Train, VEH_TRAIN> {
* Allows to know the weight value that this vehicle will use.
* @return Weight value from the engine in tonnes.
*/
inline uint16 GetWeight() const
uint16 GetCustomWeight(uint16 cargo_amount) const
{
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.StoredCount() * FreightWagonMult(this->cargo_type)) / 16;
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * cargo_amount * FreightWagonMult(this->cargo_type)) / 16;

/* Vehicle weight is not added for articulated parts. */
if (!this->IsArticulatedPart()) {
Expand Down
20 changes: 20 additions & 0 deletions src/widgets/build_vehicle_widget.h
Expand Up @@ -26,6 +26,26 @@ enum BuildVehicleWidgets {
WID_BV_SHOW_HIDE, ///< Button to hide or show the selected engine.
WID_BV_BUILD_SEL, ///< Build button.
WID_BV_RENAME, ///< Rename button.
/* build vehicle smart: */
WID_BV_FILTER_BUTTON, ///< Show filters panel.
WID_BV_FILTER_CONTAINER, ///< Filters container.
WID_BV_RAIL_WAGON, ///< Show/hide wagons.
WID_BV_RAIL_MOTOR_WAGON, ///< Show/hide motor-wagons.
WID_BV_RAIL_LOCOMOTIVE, ///< Show/hide locomotive.
WID_BV_RAIL_WEIGHT_INCREASE, ///< Increase train weight.
WID_BV_RAIL_WEIGHT_DECREASE, ///< Decrease train weight.
WID_BV_RAIL_WEIGHT_EDIT, ///< Edit train weight directly.
WID_BV_RAIL_SPEED_INCREASE, ///< Increase train speed.
WID_BV_RAIL_SPEED_DECREASE, ///< Decrease train speed.
WID_BV_RAIL_SPEED_EDIT, ///< Edit train speed directly.
WID_BV_TRAIN_LENGTH_INCREASE, ///< Increase train length.
WID_BV_TRAIN_LENGTH_DECREASE, ///< Decrease train length.
WID_BV_TRAIN_LENGTH_EDIT, ///< Edit train length directly.
WID_BV_SLOPE_LENGTH_INCREASE, ///< Increase slope length.
WID_BV_SLOPE_LENGTH_DECREASE, ///< Decrease slope length.
WID_BV_SLOPE_LENGTH_EDIT, ///< Edit slope length directly.
WID_BV_SLOPE, ///< Calculate the effect of the slopes.
WID_BV_TRAIN_FROM_DEPOT, ///< Take settings from train in depot.
};

#endif /* WIDGETS_BUILD_VEHICLE_WIDGET_H */
24 changes: 17 additions & 7 deletions src/widgets/dropdown.cpp
Expand Up @@ -482,6 +482,19 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button,
ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, auto_width, instant_close);
}

void ShowDropDownMenu(Window* w, const std::vector<StringID>& strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
{
DropDownList list;

for (uint i = 0; i < strings.size(); i++) {
if (!HasBit(hidden_mask, i)) {
list.emplace_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)));
}
}

if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
}

/**
* Show a dropdown menu window near a widget of the parent window.
* The result code of the items is their index in the \a strings list.
Expand All @@ -495,17 +508,14 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button,
*/
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
{
DropDownList list;

std::vector<StringID> vec;
for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
if (!HasBit(hidden_mask, i)) {
list.emplace_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)));
}
vec.push_back(strings[i]);
}

if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
ShowDropDownMenu(w, vec, selected, button, disabled_mask, hidden_mask, width);
}


/**
* Delete the drop-down menu from window \a pw
* @param pw Parent window of the drop-down menu window
Expand Down
1 change: 1 addition & 0 deletions src/widgets/dropdown_func.h
Expand Up @@ -16,6 +16,7 @@

/* Show drop down menu containing a fixed list of strings */
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width = 0);
void ShowDropDownMenu(Window* w, const std::vector<StringID>& strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width = 0);

/* Hide drop down menu of a parent window */
int HideDropDownMenu(Window *pw);
Expand Down