Merge branch 'master' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/aircraft_cmd.cpp
#	src/airport_gui.cpp
#	src/articulated_vehicles.cpp
#	src/console_cmds.cpp
#	src/date_gui.cpp
#	src/engine.cpp
#	src/genworld_gui.cpp
#	src/gfx_layout_fallback.cpp
#	src/group_gui.cpp
#	src/hotkeys.cpp
#	src/network/core/tcp_connect.cpp
#	src/network/core/tcp_listen.h
#	src/newgrf.cpp
#	src/newgrf.h
#	src/newgrf_engine.cpp
#	src/newgrf_gui.cpp
#	src/newgrf_station.cpp
#	src/openttd.cpp
#	src/order_gui.cpp
#	src/os/macosx/osx_main.cpp
#	src/pathfinder/yapf/yapf_node_rail.hpp
#	src/rail_gui.cpp
#	src/saveload/afterload.cpp
#	src/saveload/cargopacket_sl.cpp
#	src/saveload/linkgraph_sl.cpp
#	src/saveload/station_sl.cpp
#	src/script/api/script_industrytype.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/settings_table.cpp
#	src/settingsgen/settingsgen.cpp
#	src/station.cpp
#	src/station_cmd.cpp
#	src/strings.cpp
#	src/timer/timer_game_calendar.cpp
#	src/timer/timer_game_calendar.h
#	src/timer/timer_manager.h
#	src/timer/timer_window.cpp
#	src/timetable_cmd.cpp
#	src/toolbar_gui.cpp
#	src/town_cmd.cpp
#	src/town_gui.cpp
#	src/train_gui.cpp
#	src/vehicle_cmd.h
#	src/vehicle_gui.cpp
#	src/viewport.cpp
#	src/widgets/dropdown.cpp
#	src/window_func.h
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2023-11-25 13:29:58 +00:00
175 changed files with 1086 additions and 1177 deletions

View File

@@ -204,7 +204,7 @@ void TCPConnecter::OnResolved(addrinfo *ai)
}
if (_debug_net_level >= 6) {
if (this->addresses.size() == 0) {
if (this->addresses.empty()) {
DEBUG(net, 6, "%s did not resolve", this->connection_string.c_str());
} else {
DEBUG(net, 6, "%s resolved in:", this->connection_string.c_str());

View File

@@ -142,7 +142,7 @@ public:
*/
static bool Listen(uint16 port)
{
assert(sockets.size() == 0);
assert(sockets.empty());
NetworkAddressList addresses;
GetBindAddresses(&addresses, port);
@@ -151,7 +151,7 @@ public:
address.Listen(SOCK_STREAM, &sockets);
}
if (sockets.size() == 0) {
if (sockets.empty()) {
DEBUG(net, 0, "Could not start network: could not create listening socket");
ShowNetworkError(STR_NETWORK_ERROR_SERVER_START);
return false;

View File

@@ -52,7 +52,7 @@ bool NetworkUDPSocketHandler::Listen()
addr.Listen(SOCK_DGRAM, &this->sockets);
}
return this->sockets.size() != 0;
return !this->sockets.empty();
}
/**
@@ -75,7 +75,7 @@ void NetworkUDPSocketHandler::CloseSocket()
*/
void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast, bool short_mtu)
{
if (this->sockets.size() == 0) this->Listen();
if (this->sockets.empty()) this->Listen();
const uint MTU = short_mtu ? UDP_MTU_SHORT : UDP_MTU;

View File

@@ -777,7 +777,7 @@ void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
}
/* No address, so bind to everything. */
if (addresses->size() == 0) {
if (addresses->empty()) {
addresses->emplace_back("", port);
}
}

View File

@@ -74,7 +74,7 @@ static uint8 *_chatmessage_backup = nullptr; ///< Backup in case text is moved.
*/
static inline bool HaveChatMessages(bool show_all)
{
if (show_all) return _chatmsg_list.size() != 0;
if (show_all) return !_chatmsg_list.empty();
auto now = std::chrono::steady_clock::now();
for (auto &cmsg : _chatmsg_list) {
@@ -314,7 +314,7 @@ struct NetworkChatWindow : public Window {
PositionNetworkChatWindow(this);
}
void Close() override
void Close([[maybe_unused]] int data = 0) override
{
InvalidateWindowData(WC_NEWS_WINDOW, 0, 0);
this->Window::Close();

View File

@@ -109,7 +109,7 @@ BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow(W
this->InitNested(WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
}
void BaseNetworkContentDownloadStatusWindow::Close()
void BaseNetworkContentDownloadStatusWindow::Close([[maybe_unused]] int data)
{
_network_content_client.RemoveCallback(this);
this->Window::Close();
@@ -201,7 +201,7 @@ public:
this->parent = FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
}
void Close() override
void Close([[maybe_unused]] int data = 0) override
{
TarScanner::Mode mode = TarScanner::NONE;
for (auto ctype : this->receivedTypes) {
@@ -574,7 +574,7 @@ public:
this->InvalidateData();
}
void Close() override
void Close([[maybe_unused]] int data = 0) override
{
_network_content_client.RemoveCallback(this);
this->Window::Close();
@@ -828,7 +828,7 @@ public:
case WID_NCL_NAME:
if (this->content.SortType() == widget - WID_NCL_CHECKBOX) {
this->content.ToggleSortOrder();
if (this->content.size() > 0) this->list_pos = (int)this->content.size() - this->list_pos - 1;
if (!this->content.empty()) this->list_pos = (int)this->content.size() - this->list_pos - 1;
} else {
this->content.SetSortType(widget - WID_NCL_CHECKBOX);
this->content.ForceResort();
@@ -903,7 +903,7 @@ public:
}
}
if (this->content.size() == 0) {
if (this->content.empty()) {
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
this->InvalidateData();

View File

@@ -32,7 +32,7 @@ public:
*/
BaseNetworkContentDownloadStatusWindow(WindowDesc *desc);
void Close() override;
void Close([[maybe_unused]] int data = 0) override;
void UpdateWidgetSize(int widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override;
void DrawWidget(const Rect &r, int widget) const override;
void OnDownloadProgress(const ContentInfo *ci, int bytes) override;

View File

@@ -648,7 +648,7 @@ void ClientNetworkCoordinatorSocketHandler::CloseStunHandler(const std::string &
*/
void ClientNetworkCoordinatorSocketHandler::CloseTurnHandler(const std::string &token)
{
CloseWindowByClass(WC_NETWORK_ASK_RELAY);
CloseWindowByClass(WC_NETWORK_ASK_RELAY, NRWCD_HANDLED);
auto turn_it = this->turn_handlers.find(token);
if (turn_it == this->turn_handlers.end()) return;

View File

@@ -76,9 +76,9 @@ static DropDownList BuildVisibilityDropDownList()
{
DropDownList list;
list.emplace_back(new DropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_LOCAL, SERVER_GAME_TYPE_LOCAL, false));
list.emplace_back(new DropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY, SERVER_GAME_TYPE_INVITE_ONLY, false));
list.emplace_back(new DropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_PUBLIC, SERVER_GAME_TYPE_PUBLIC, false));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NETWORK_SERVER_VISIBILITY_LOCAL, SERVER_GAME_TYPE_LOCAL, false));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY, SERVER_GAME_TYPE_INVITE_ONLY, false));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NETWORK_SERVER_VISIBILITY_PUBLIC, SERVER_GAME_TYPE_PUBLIC, false));
return list;
}
@@ -154,7 +154,7 @@ public:
NWidgetBase *child_wid = this->head->next;
/* The first and last widget are always visible, determine which other should be visible */
for (uint i = 1; i < lengthof(this->visible) - 1; i++) {
if (given_width > MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER + child_wid->smallest_x && this->visible[i - 1]) {
if (given_width > ScaleGUITrad(MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER) + child_wid->smallest_x && this->visible[i - 1]) {
this->visible[i] = true;
given_width -= child_wid->smallest_x;
} else {
@@ -523,7 +523,7 @@ public:
this->servers.ForceRebuild();
}
void Close() override
void Close(int data = 0) override
{
this->last_sorting = this->servers.GetListing();
this->Window::Close();
@@ -1567,8 +1567,8 @@ private:
static void OnClickClientAdmin([[maybe_unused]] NetworkClientListWindow *w, [[maybe_unused]] Point pt, ClientID client_id)
{
DropDownList list;
list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_KICK, DD_CLIENT_ADMIN_KICK, false));
list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_BAN, DD_CLIENT_ADMIN_BAN, false));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_KICK, DD_CLIENT_ADMIN_KICK, false));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_BAN, DD_CLIENT_ADMIN_BAN, false));
Rect wi_rect;
wi_rect.left = pt.x;
@@ -1589,8 +1589,8 @@ private:
static void OnClickCompanyAdmin([[maybe_unused]] NetworkClientListWindow *w, [[maybe_unused]] Point pt, CompanyID company_id)
{
DropDownList list;
list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_RESET, DD_COMPANY_ADMIN_RESET, NetworkCompanyHasClients(company_id)));
list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_UNLOCK, DD_COMPANY_ADMIN_UNLOCK, !NetworkCompanyIsPassworded(company_id)));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_RESET, DD_COMPANY_ADMIN_RESET, NetworkCompanyHasClients(company_id)));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_UNLOCK, DD_COMPANY_ADMIN_UNLOCK, !NetworkCompanyIsPassworded(company_id)));
Rect wi_rect;
wi_rect.left = pt.x;
@@ -1621,9 +1621,9 @@ private:
{
ButtonCommon *chat_button = new CompanyButton(SPR_CHAT, company_id == COMPANY_SPECTATOR ? STR_NETWORK_CLIENT_LIST_CHAT_SPECTATOR_TOOLTIP : STR_NETWORK_CLIENT_LIST_CHAT_COMPANY_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyChat);
if (_network_server) this->buttons[line_count].emplace_back(new CompanyButton(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_TOOLTIP, COLOUR_RED, company_id, &NetworkClientListWindow::OnClickCompanyAdmin, company_id == COMPANY_SPECTATOR));
if (_network_server) this->buttons[line_count].push_back(std::make_unique<CompanyButton>(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_TOOLTIP, COLOUR_RED, company_id, &NetworkClientListWindow::OnClickCompanyAdmin, company_id == COMPANY_SPECTATOR));
this->buttons[line_count].emplace_back(chat_button);
if (client_playas != company_id) this->buttons[line_count].emplace_back(new CompanyButton(SPR_JOIN, STR_NETWORK_CLIENT_LIST_JOIN_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyJoin, company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai));
if (client_playas != company_id) this->buttons[line_count].push_back(std::make_unique<CompanyButton>(SPR_JOIN, STR_NETWORK_CLIENT_LIST_JOIN_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyJoin, company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai));
this->line_count += 1;
@@ -1632,8 +1632,8 @@ private:
if (ci->client_playas != company_id) continue;
has_players = true;
if (_network_server) this->buttons[line_count].emplace_back(new ClientButton(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_TOOLTIP, COLOUR_RED, ci->client_id, &NetworkClientListWindow::OnClickClientAdmin, _network_own_client_id == ci->client_id));
if (_network_own_client_id != ci->client_id) this->buttons[line_count].emplace_back(new ClientButton(SPR_CHAT, STR_NETWORK_CLIENT_LIST_CHAT_CLIENT_TOOLTIP, COLOUR_ORANGE, ci->client_id, &NetworkClientListWindow::OnClickClientChat));
if (_network_server) this->buttons[line_count].push_back(std::make_unique<ClientButton>(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_TOOLTIP, COLOUR_RED, ci->client_id, &NetworkClientListWindow::OnClickClientAdmin, _network_own_client_id == ci->client_id));
if (_network_own_client_id != ci->client_id) this->buttons[line_count].push_back(std::make_unique<ClientButton>(SPR_CHAT, STR_NETWORK_CLIENT_LIST_CHAT_CLIENT_TOOLTIP, COLOUR_ORANGE, ci->client_id, &NetworkClientListWindow::OnClickClientChat));
if (ci->client_id == _network_own_client_id) {
this->player_self_index = this->line_count;
@@ -1663,7 +1663,7 @@ private:
/* As spectator, show a line to create a new company. */
if (client_playas == COMPANY_SPECTATOR && !NetworkMaxCompaniesReached()) {
this->buttons[line_count].emplace_back(new CompanyButton(SPR_JOIN, STR_NETWORK_CLIENT_LIST_NEW_COMPANY_TOOLTIP, COLOUR_ORANGE, COMPANY_SPECTATOR, &NetworkClientListWindow::OnClickCompanyNew));
this->buttons[line_count].push_back(std::make_unique<CompanyButton>(SPR_JOIN, STR_NETWORK_CLIENT_LIST_NEW_COMPANY_TOOLTIP, COLOUR_ORANGE, COMPANY_SPECTATOR, &NetworkClientListWindow::OnClickCompanyNew));
this->line_count += 1;
}
@@ -2436,6 +2436,12 @@ struct NetworkAskRelayWindow : public Window {
this->InitNested(0);
}
void Close(int data = 0) override
{
if (data == NRWCD_UNHANDLED) _network_coordinator_client.ConnectFailure(this->token, 0);
this->Window::Close();
}
void UpdateWidgetSize(int widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
{
if (widget == WID_NAR_TEXT) {
@@ -2475,18 +2481,18 @@ struct NetworkAskRelayWindow : public Window {
switch (widget) {
case WID_NAR_NO:
_network_coordinator_client.ConnectFailure(this->token, 0);
this->Close();
this->Close(NRWCD_HANDLED);
break;
case WID_NAR_YES_ONCE:
_network_coordinator_client.StartTurnConnection(this->token);
this->Close();
this->Close(NRWCD_HANDLED);
break;
case WID_NAR_YES_ALWAYS:
_settings_client.network.use_relay_service = URS_ALLOW;
_network_coordinator_client.StartTurnConnection(this->token);
this->Close();
this->Close(NRWCD_HANDLED);
break;
}
}
@@ -2522,7 +2528,7 @@ static WindowDesc _network_ask_relay_desc(
*/
void ShowNetworkAskRelay(const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token)
{
CloseWindowByClass(WC_NETWORK_ASK_RELAY);
CloseWindowByClass(WC_NETWORK_ASK_RELAY, NRWCD_HANDLED);
Window *parent = GetMainWindow();
new NetworkAskRelayWindow(&_network_ask_relay_desc, parent, server_connection_string, relay_connection_string, token);

View File

@@ -40,5 +40,9 @@ struct NetworkCompanyInfo : NetworkCompanyStats {
std::string clients; ///< The clients that control this company (Name1, name2, ..)
};
enum NetworkRelayWindowCloseData {
NRWCD_UNHANDLED = 0, ///< Relay request is unhandled.
NRWCD_HANDLED = 1, ///< Relay request is handled, either by user or by timeout.
};
#endif /* NETWORK_GUI_H */