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

Added widget showing company slots remaining #10054

Closed
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,7 @@ STR_NETWORK_CLIENT_LIST_NEW_COMPANY :(New company)
STR_NETWORK_CLIENT_LIST_NEW_COMPANY_TOOLTIP :{BLACK}Create a new company and join it
STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP :{BLACK}This is you
STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP :{BLACK}This is the host of the game
STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_REMAINING :{BLACK}{NUM} open slot{P "" s}
STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT :{BLACK}{NUM} client{P "" s} / {NUM} compan{P y ies}

# Matches ConnectionType
Expand Down
5 changes: 5 additions & 0 deletions src/network/network_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ static const NWidgetPart _nested_client_list_widgets[] = {
NWidget(NWID_VERTICAL),
NWidget(WWT_MATRIX, COLOUR_GREY, WID_CL_MATRIX), SetMinimalSize(180, 0), SetResize(1, 1), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_CL_SCROLLBAR),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_CLIENT_COMPANY_REMAINING), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetPadding(2, 1, 2, 1), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_REMAINING, STR_NULL),
NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_CLIENT_COMPANY_COUNT), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetPadding(2, 1, 2, 1), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT, STR_NULL),
EndContainer(),
EndContainer(),
Expand Down Expand Up @@ -1785,6 +1786,10 @@ struct NetworkClientListWindow : Window {
break;
}

case WID_CL_CLIENT_COMPANY_REMAINING:
SetDParam(0, _settings_client.network.max_companies - Company::GetNumItems());
Copy link
Contributor

Choose a reason for hiding this comment

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

This setting does not get updated from the server. So, it will not be right when joining the server and whenever the server changes it won't be right. Unless "accidentally" the configuration value at the server happens to be the same as for your client, which is quite likely when testing it locally.

I would suggest you look at NetworkMaxCompaniesReached and add a similar function at those locations that returns the number of companies that are remaining. I would then also suggest changing NetworkMaxCompaniesReached so it uses that new function and compares that count with 0. That way the logic that chooses between the variables containing the maximum number of companies does not get duplicated and if the logic requires changes it is less likely that the other function is missed.

break;

case WID_CL_CLIENT_COMPANY_COUNT:
SetDParam(0, NetworkClientInfo::GetNumItems());
SetDParam(1, Company::GetNumItems());
Expand Down
1 change: 1 addition & 0 deletions src/widgets/network_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ enum ClientListWidgets {
WID_CL_MATRIX, ///< Company/client list.
WID_CL_SCROLLBAR, ///< Scrollbar for company/client list.
WID_CL_COMPANY_JOIN, ///< Used for QueryWindow when a company has a password.
WID_CL_CLIENT_COMPANY_REMAINING, ///< Number of companies that can still be formed.
WID_CL_CLIENT_COMPANY_COUNT, ///< Count of clients and companies.
};

Expand Down