Skip to content

Commit

Permalink
Codechange: Pass WindowDesc by reference instead of pointer. (OpenTTD…
Browse files Browse the repository at this point in the history
…#12771)

WindowDesc as passed to Windows is not optional so don't allow to it to be nullptr.
  • Loading branch information
PeterN authored Jun 11, 2024
1 parent 18bce69 commit 4cf6d1d
Show file tree
Hide file tree
Showing 68 changed files with 293 additions and 301 deletions.
2 changes: 1 addition & 1 deletion src/ai/ai_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct AIConfigWindow : public Window {
int line_height; ///< Height of a single AI-name line.
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.

AIConfigWindow() : Window(&_ai_config_desc)
AIConfigWindow() : Window(_ai_config_desc)
{
this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
Expand Down
8 changes: 4 additions & 4 deletions src/airport_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void PlaceAirport(TileIndex tile)
struct BuildAirToolbarWindow : Window {
int last_user_action; // Last started user action.

BuildAirToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
BuildAirToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
{
this->InitNested(window_number);
this->OnInvalidateData();
Expand Down Expand Up @@ -228,7 +228,7 @@ Window *ShowBuildAirToolbar()
if (!Company::IsValidID(_local_company)) return nullptr;

CloseWindowByClass(WC_BUILD_TOOLBAR);
return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
return AllocateWindowDescFront<BuildAirToolbarWindow>(_air_toolbar_desc, TRANSPORT_AIR);
}

class BuildAirportWindow : public PickerWindowBase {
Expand All @@ -249,7 +249,7 @@ class BuildAirportWindow : public PickerWindowBase {
}

public:
BuildAirportWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
BuildAirportWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
{
this->CreateNestedTree();

Expand Down Expand Up @@ -626,7 +626,7 @@ static WindowDesc _build_airport_desc(

static void ShowBuildAirportPicker(Window *parent)
{
new BuildAirportWindow(&_build_airport_desc, parent);
new BuildAirportWindow(_build_airport_desc, parent);
}

void InitializeAirportGui()
Expand Down
10 changes: 4 additions & 6 deletions src/autoreplace_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class ReplaceVehicleWindow : public Window {
}

public:
ReplaceVehicleWindow(WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
ReplaceVehicleWindow(WindowDesc &desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
{
this->sel_railtype = INVALID_RAILTYPE;
this->sel_roadtype = INVALID_ROADTYPE;
Expand Down Expand Up @@ -889,11 +889,9 @@ static WindowDesc _replace_vehicle_desc(
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
{
CloseWindowById(WC_REPLACE_VEHICLE, vehicletype);
WindowDesc *desc;
switch (vehicletype) {
case VEH_TRAIN: desc = &_replace_rail_vehicle_desc; break;
case VEH_ROAD: desc = &_replace_road_vehicle_desc; break;
default: desc = &_replace_vehicle_desc; break;
case VEH_TRAIN: new ReplaceVehicleWindow(_replace_rail_vehicle_desc, vehicletype, id_g); break;
case VEH_ROAD: new ReplaceVehicleWindow(_replace_road_vehicle_desc, vehicletype, id_g); break;
default: new ReplaceVehicleWindow(_replace_vehicle_desc, vehicletype, id_g); break;
}
new ReplaceVehicleWindow(desc, vehicletype, id_g);
}
8 changes: 4 additions & 4 deletions src/bootstrap_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static WindowDesc _background_desc(
/** The background for the game. */
class BootstrapBackground : public Window {
public:
BootstrapBackground() : Window(&_background_desc)
BootstrapBackground() : Window(_background_desc)
{
this->InitNested(0);
CLRBITS(this->flags, WF_WHITE_BORDER);
Expand Down Expand Up @@ -86,7 +86,7 @@ static WindowDesc _bootstrap_errmsg_desc(
/** The window for a failed bootstrap. */
class BootstrapErrorWindow : public Window {
public:
BootstrapErrorWindow() : Window(&_bootstrap_errmsg_desc)
BootstrapErrorWindow() : Window(_bootstrap_errmsg_desc)
{
this->InitNested(1);
}
Expand Down Expand Up @@ -145,7 +145,7 @@ static WindowDesc _bootstrap_download_status_window_desc(
struct BootstrapContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
public:
/** Simple call the constructor of the superclass. */
BootstrapContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(&_bootstrap_download_status_window_desc)
BootstrapContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(_bootstrap_download_status_window_desc)
{
}

Expand Down Expand Up @@ -198,7 +198,7 @@ class BootstrapAskForDownloadWindow : public Window, ContentCallback {

public:
/** Start listening to the content client events. */
BootstrapAskForDownloadWindow() : Window(&_bootstrap_query_desc)
BootstrapAskForDownloadWindow() : Window(_bootstrap_query_desc)
{
this->InitNested(WN_CONFIRM_POPUP_QUERY_BOOTSTRAP);
_network_content_client.AddCallback(this);
Expand Down
4 changes: 2 additions & 2 deletions src/bridge_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class BuildBridgeWindow : public Window {
}

public:
BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type, GUIBridgeList &&bl) : Window(desc),
BuildBridgeWindow(WindowDesc &desc, TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type, GUIBridgeList &&bl) : Window(desc),
start_tile(start),
end_tile(end),
transport_type(transport_type),
Expand Down Expand Up @@ -435,7 +435,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
}

if (!bl.empty()) {
new BuildBridgeWindow(&_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
new BuildBridgeWindow(_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
} else {
ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
}
Expand Down
4 changes: 2 additions & 2 deletions src/build_vehicle_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ struct BuildVehicleWindow : Window {
}
}

BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc), vehicle_editbox(MAX_LENGTH_VEHICLE_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_VEHICLE_NAME_CHARS)
BuildVehicleWindow(WindowDesc &desc, TileIndex tile, VehicleType type) : Window(desc), vehicle_editbox(MAX_LENGTH_VEHICLE_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_VEHICLE_NAME_CHARS)
{
this->vehicle_type = type;
this->listview_mode = tile == INVALID_TILE;
Expand Down Expand Up @@ -1938,5 +1938,5 @@ void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)

CloseWindowById(WC_BUILD_VEHICLE, num);

new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
new BuildVehicleWindow(_build_vehicle_desc, tile, type);
}
4 changes: 2 additions & 2 deletions src/cheat_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ struct CheatWindow : Window {
uint line_height;
Dimension icon; ///< Dimension of company icon sprite

CheatWindow(WindowDesc *desc) : Window(desc)
CheatWindow(WindowDesc &desc) : Window(desc)
{
this->InitNested();
}
Expand Down Expand Up @@ -436,5 +436,5 @@ static WindowDesc _cheats_desc(
void ShowCheatWindow()
{
CloseWindowById(WC_CHEATS, 0);
new CheatWindow(&_cheats_desc);
new CheatWindow(_cheats_desc);
}
24 changes: 12 additions & 12 deletions src/company_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ struct CompanyFinancesWindow : Window {
static Money max_money; ///< The maximum amount of money a company has had this 'run'
bool small; ///< Window is toggled to 'small'.

CompanyFinancesWindow(WindowDesc *desc, CompanyID company) : Window(desc)
CompanyFinancesWindow(WindowDesc &desc, CompanyID company) : Window(desc)
{
this->small = false;
this->CreateNestedTree();
Expand Down Expand Up @@ -548,7 +548,7 @@ void ShowCompanyFinances(CompanyID company)
if (!Company::IsValidID(company)) return;
if (BringWindowToFrontById(WC_FINANCES, company)) return;

new CompanyFinancesWindow(&_company_finances_desc, company);
new CompanyFinancesWindow(_company_finances_desc, company);
}

/* Association of liveries to livery classes */
Expand Down Expand Up @@ -670,7 +670,7 @@ struct SelectCompanyLiveryWindow : public Window {
}

public:
SelectCompanyLiveryWindow(WindowDesc *desc, CompanyID company, GroupID group) : Window(desc)
SelectCompanyLiveryWindow(WindowDesc &desc, CompanyID company, GroupID group) : Window(desc)
{
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_SCL_MATRIX_SCROLLBAR);
Expand Down Expand Up @@ -1089,7 +1089,7 @@ void ShowCompanyLiveryWindow(CompanyID company, GroupID group)
{
SelectCompanyLiveryWindow *w = (SelectCompanyLiveryWindow *)BringWindowToFrontById(WC_COMPANY_COLOUR, company);
if (w == nullptr) {
new SelectCompanyLiveryWindow(&_select_company_livery_desc, company, group);
new SelectCompanyLiveryWindow(_select_company_livery_desc, company, group);
} else if (group != INVALID_GROUP) {
w->SetSelectedGroup(company, group);
}
Expand Down Expand Up @@ -1349,7 +1349,7 @@ class SelectCompanyManagerFaceWindow : public Window
}

public:
SelectCompanyManagerFaceWindow(WindowDesc *desc, Window *parent) : Window(desc)
SelectCompanyManagerFaceWindow(WindowDesc &desc, Window *parent) : Window(desc)
{
this->advanced = false;
this->CreateNestedTree();
Expand Down Expand Up @@ -1720,7 +1720,7 @@ static void DoSelectCompanyManagerFace(Window *parent)
if (!Company::IsValidID((CompanyID)parent->window_number)) return;

if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc, parent);
new SelectCompanyManagerFaceWindow(_select_company_manager_face_desc, parent);
}

static constexpr NWidgetPart _nested_company_infrastructure_widgets[] = {
Expand Down Expand Up @@ -1770,7 +1770,7 @@ struct CompanyInfrastructureWindow : Window

uint total_width; ///< String width of the total cost line.

CompanyInfrastructureWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
CompanyInfrastructureWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
{
this->UpdateRailRoadTypes();

Expand Down Expand Up @@ -2094,7 +2094,7 @@ static WindowDesc _company_infrastructure_desc(
static void ShowCompanyInfrastructure(CompanyID company)
{
if (!Company::IsValidID(company)) return;
AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
AllocateWindowDescFront<CompanyInfrastructureWindow>(_company_infrastructure_desc, company);
}

static constexpr NWidgetPart _nested_company_widgets[] = {
Expand Down Expand Up @@ -2196,7 +2196,7 @@ struct CompanyWindow : Window
CWP_RELOCATE_HIDE, ///< Hide the relocate HQ button.
};

CompanyWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
CompanyWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
{
this->InitNested(window_number);
this->owner = (Owner)this->window_number;
Expand Down Expand Up @@ -2567,7 +2567,7 @@ void ShowCompany(CompanyID company)
{
if (!Company::IsValidID(company)) return;

AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
AllocateWindowDescFront<CompanyWindow>(_company_desc, company);
}

/**
Expand All @@ -2581,7 +2581,7 @@ void DirtyCompanyInfrastructureWindows(CompanyID company)
}

struct BuyCompanyWindow : Window {
BuyCompanyWindow(WindowDesc *desc, WindowNumber window_number, bool hostile_takeover) : Window(desc), hostile_takeover(hostile_takeover)
BuyCompanyWindow(WindowDesc &desc, WindowNumber window_number, bool hostile_takeover) : Window(desc), hostile_takeover(hostile_takeover)
{
this->InitNested(window_number);

Expand Down Expand Up @@ -2702,6 +2702,6 @@ void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
{
auto window = BringWindowToFrontById(WC_BUY_COMPANY, company);
if (window == nullptr) {
new BuyCompanyWindow(&_buy_company_desc, company, hostile_takeover);
new BuyCompanyWindow(_buy_company_desc, company, hostile_takeover);
}
}
2 changes: 1 addition & 1 deletion src/console_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct IConsoleWindow : Window
int line_offset;
int cursor_width;

IConsoleWindow() : Window(&_console_window_desc)
IConsoleWindow() : Window(_console_window_desc)
{
_iconsole_mode = ICONSOLE_OPENED;

Expand Down
4 changes: 2 additions & 2 deletions src/date_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct SetDateWindow : Window {
* @param max_year the maximum year (inclusive) to show in the year dropdown
* @param callback the callback to call once a date has been selected
*/
SetDateWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data) :
SetDateWindow(WindowDesc &desc, WindowNumber window_number, Window *parent, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data) :
Window(desc),
callback(callback),
callback_data(callback_data),
Expand Down Expand Up @@ -216,5 +216,5 @@ static WindowDesc _set_date_desc(
void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data)
{
CloseWindowByClass(WC_SET_DATE);
new SetDateWindow(&_set_date_desc, window_number, parent, initial_date, min_year, max_year, callback, callback_data);
new SetDateWindow(_set_date_desc, window_number, parent, initial_date, min_year, max_year, callback, callback_data);
}
13 changes: 5 additions & 8 deletions src/depot_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ struct DepotWindow : Window {
Scrollbar *hscroll; ///< Only for trains.
Scrollbar *vscroll;

DepotWindow(WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc)
DepotWindow(WindowDesc &desc, TileIndex tile, VehicleType type) : Window(desc)
{
assert(IsCompanyBuildableVehicleType(type)); // ensure that we make the call with a valid type

Expand Down Expand Up @@ -1142,16 +1142,13 @@ void ShowDepotWindow(TileIndex tile, VehicleType type)
{
if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != nullptr) return;

WindowDesc *desc;
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: desc = &_train_depot_desc; break;
case VEH_ROAD: desc = &_road_depot_desc; break;
case VEH_SHIP: desc = &_ship_depot_desc; break;
case VEH_AIRCRAFT: desc = &_aircraft_depot_desc; break;
case VEH_TRAIN: new DepotWindow(_train_depot_desc, tile, type); break;
case VEH_ROAD: new DepotWindow(_road_depot_desc, tile, type); break;
case VEH_SHIP: new DepotWindow(_ship_depot_desc, tile, type); break;
case VEH_AIRCRAFT: new DepotWindow(_aircraft_depot_desc, tile, type); break;
}

new DepotWindow(desc, tile, type);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/dock_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = n
struct BuildDocksToolbarWindow : Window {
DockToolbarWidgets last_clicked_widget; ///< Contains the last widget that has been clicked on this toolbar.

BuildDocksToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
BuildDocksToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
{
this->last_clicked_widget = WID_DT_INVALID;
this->InitNested(window_number);
Expand Down Expand Up @@ -364,7 +364,7 @@ Window *ShowBuildDocksToolbar()
if (!Company::IsValidID(_local_company)) return nullptr;

CloseWindowByClass(WC_BUILD_TOOLBAR);
return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
return AllocateWindowDescFront<BuildDocksToolbarWindow>(_build_docks_toolbar_desc, TRANSPORT_WATER);
}

/**
Expand Down Expand Up @@ -402,7 +402,7 @@ static WindowDesc _build_docks_scen_toolbar_desc(
*/
Window *ShowBuildDocksScenToolbar()
{
return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
return AllocateWindowDescFront<BuildDocksToolbarWindow>(_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
}

/** Widget numbers of the build-dock GUI. */
Expand All @@ -416,7 +416,7 @@ enum BuildDockStationWidgets {

struct BuildDocksStationWindow : public PickerWindowBase {
public:
BuildDocksStationWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
BuildDocksStationWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
{
this->InitNested(TRANSPORT_WATER);
this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
Expand Down Expand Up @@ -507,7 +507,7 @@ static WindowDesc _build_dock_station_desc(

static void ShowBuildDockStationPicker(Window *parent)
{
new BuildDocksStationWindow(&_build_dock_station_desc, parent);
new BuildDocksStationWindow(_build_dock_station_desc, parent);
}

struct BuildDocksDepotWindow : public PickerWindowBase {
Expand All @@ -522,7 +522,7 @@ struct BuildDocksDepotWindow : public PickerWindowBase {
}

public:
BuildDocksDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
BuildDocksDepotWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
{
this->InitNested(TRANSPORT_WATER);
this->LowerWidget(WID_BDD_X + _ship_depot_direction);
Expand Down Expand Up @@ -603,7 +603,7 @@ static WindowDesc _build_docks_depot_desc(

static void ShowBuildDocksDepotPicker(Window *parent)
{
new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
new BuildDocksDepotWindow(_build_docks_depot_desc, parent);
}


Expand Down
2 changes: 1 addition & 1 deletion src/dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct DropdownWindow : Window {
* @param persist Dropdown menu will persist.
*/
DropdownWindow(Window *parent, DropDownList &&list, int selected, WidgetID button, const Rect wi_rect, bool instant_close, Colours wi_colour, bool persist)
: Window(&_dropdown_desc)
: Window(_dropdown_desc)
, parent_button(button)
, wi_rect(wi_rect)
, list(std::move(list))
Expand Down
Loading

0 comments on commit 4cf6d1d

Please sign in to comment.