Changeset - r25258:66d1fbacd966
[Not reviewed]
master
0 3 0
Patric Stout - 4 years ago 2021-04-23 14:22:01
truebrain@openttd.org
Add: move "New Company" inside the Online Players GUI
3 files changed with 55 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -2119,13 +2119,12 @@ STR_NETWORK_CONNECTION_DISCONNECT       
 

	
 
STR_NETWORK_NEED_GAME_PASSWORD_CAPTION                          :{WHITE}Server is protected. Enter password
 
STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION                       :{WHITE}Company is protected. Enter password
 

	
 
# Network company list added strings
 
STR_NETWORK_COMPANY_LIST_CLIENT_LIST                            :Online players
 
STR_NETWORK_COMPANY_LIST_NEW_COMPANY                            :New company
 

	
 
# Network client list
 
STR_NETWORK_CLIENT_LIST_CAPTION                                 :{WHITE}Multiplayer
 
STR_NETWORK_CLIENT_LIST_SERVER                                  :{BLACK}Server
 
STR_NETWORK_CLIENT_LIST_SERVER_NAME                             :{BLACK}Name
 
STR_NETWORK_CLIENT_LIST_SERVER_NAME_TOOLTIP                     :{BLACK}Name of the server you are playing on
 
@@ -2144,12 +2143,14 @@ STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_TOO
 
STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_TOOLTIP                   :{BLACK}Administrative actions to perform for this company
 
STR_NETWORK_CLIENT_LIST_JOIN_TOOLTIP                            :{BLACK}Join this company
 
STR_NETWORK_CLIENT_LIST_CHAT_CLIENT_TOOLTIP                     :{BLACK}Send a message to this player
 
STR_NETWORK_CLIENT_LIST_CHAT_COMPANY_TOOLTIP                    :{BLACK}Send a message to all players of this company
 
STR_NETWORK_CLIENT_LIST_CHAT_SPECTATOR_TOOLTIP                  :{BLACK}Send a message to all spectators
 
STR_NETWORK_CLIENT_LIST_SPECTATORS                              :Spectators
 
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_ADMIN_CLIENT_KICK                       :Kick
 
STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_BAN                        :Ban
 
STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_RESET                     :Delete
 
STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_UNLOCK                    :Password unlock
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -1790,12 +1790,27 @@ private:
 
		} else {
 
			NetworkClientRequestMove(company_id);
 
		}
 
	}
 

	
 
	/**
 
	 * Crete new company button is clicked.
 
	 * @param w The instance of this window.
 
	 * @param pt The point where this button was clicked.
 
	 * @param company_id The company this button was assigned to.
 
	 */
 
	static void OnClickCompanyNew(NetworkClientListWindow *w, Point pt, CompanyID company_id)
 
	{
 
		if (_network_server) {
 
			DoCommandP(0, CCA_NEW, _network_own_client_id, CMD_COMPANY_CTRL);
 
		} else {
 
			NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company);
 
		}
 
	}
 

	
 
	/**
 
	 * Admin button on a Client is clicked.
 
	 * @param w The instance of this window.
 
	 * @param pt The point where this button was clicked.
 
	 * @param client_id The client this button was assigned to.
 
	 */
 
	static void OnClickClientAdmin(NetworkClientListWindow *w, Point pt, ClientID client_id)
 
@@ -1883,14 +1898,26 @@ private:
 
	{
 
		const NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
 

	
 
		this->buttons.clear();
 
		this->line_count = 0;
 

	
 
		/* As spectator, show a line to create a new company. */
 
		if (own_ci->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->line_count += 1;
 
		}
 

	
 
		if (own_ci->client_playas != COMPANY_SPECTATOR) {
 
			this->RebuildListCompany(own_ci->client_playas, own_ci);
 
		}
 

	
 
		/* Companies */
 
		for (const Company *c : Company::Iterate()) {
 
			if (c->index == own_ci->client_playas) continue;
 

	
 
			this->RebuildListCompany(c->index, own_ci);
 
		}
 

	
 
		/* Spectators */
 
		this->RebuildListCompany(COMPANY_SPECTATOR, own_ci);
 

	
 
@@ -2174,19 +2201,19 @@ public:
 
			x += rtl ? width : -width;
 
		}
 
	}
 

	
 
	/**
 
	 * Draw a company and its clients on the matrix.
 
	 * @param c The company to draw.
 
	 * @param company_id The company to draw.
 
	 * @param left The most left pixel of the line.
 
	 * @param right The most right pixel of the line.
 
	 * @param top The top of the first line.
 
	 * @param line The Nth line we are drawing. Updated during this function.
 
	 */
 
	void DrawCompany(const Company *c, uint left, uint right, uint top, uint &line) const
 
	void DrawCompany(CompanyID company_id, uint left, uint right, uint top, uint &line) const
 
	{
 
		bool rtl = _current_text_dir == TD_RTL;
 
		int text_y_offset = std::max(0, ((int)(this->line_height + 1) - (int)FONT_HEIGHT_NORMAL) / 2) + WD_MATRIX_BOTTOM;
 

	
 
		Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
 
		int offset = std::max(0, ((int)(this->line_height + 1) - (int)d.height) / 2);
 
@@ -2206,30 +2233,32 @@ public:
 
			/* If there are buttons for this company, draw them. */
 
			auto button_find = this->buttons.find(line);
 
			if (button_find != this->buttons.end()) {
 
				this->DrawButtons(x, y, button_find->second);
 
			}
 

	
 
			if (c == nullptr) {
 
			if (company_id == COMPANY_SPECTATOR) {
 
				DrawSprite(SPR_COMPANY_ICON, PALETTE_TO_GREY, rtl ? right - d.width - 4 : left + 4, y + offset);
 
				DrawString(rtl ? x : text_left, rtl ? text_right : x, y + text_y_offset, STR_NETWORK_CLIENT_LIST_SPECTATORS, TC_SILVER);
 
			} else if (company_id == COMPANY_NEW_COMPANY) {
 
				DrawSprite(SPR_COMPANY_ICON, PALETTE_TO_GREY, rtl ? right - d.width - 4 : left + 4, y + offset);
 
				DrawString(rtl ? x : text_left, rtl ? text_right : x, y + text_y_offset, STR_NETWORK_CLIENT_LIST_NEW_COMPANY, TC_WHITE);
 
			} else {
 
				DrawCompanyIcon(c->index, rtl ? right - d.width - 4 : left + 4, y + offset);
 

	
 
				SetDParam(0, c->index);
 
				SetDParam(1, c->index);
 
				DrawCompanyIcon(company_id, rtl ? right - d.width - 4 : left + 4, y + offset);
 

	
 
				SetDParam(0, company_id);
 
				SetDParam(1, company_id);
 
				DrawString(rtl ? x : text_left, rtl ? text_right : x, y + text_y_offset, STR_COMPANY_NAME, TC_SILVER);
 
			}
 
		}
 

	
 
		y += this->line_height;
 
		line++;
 

	
 
		for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
 
			if (c != nullptr && ci->client_playas != c->index) continue;
 
			if (c == nullptr && ci->client_playas != COMPANY_SPECTATOR) continue;
 
			if (ci->client_playas != company_id) continue;
 

	
 
			/* Draw the player line (if in range of scrollbar). */
 
			if (IsInsideMM(line, line_start, line_end)) {
 
				uint x = rtl ? text_left : text_right;
 

	
 
				/* If there are buttons for this client, draw them. */
 
@@ -2264,17 +2293,28 @@ public:
 

	
 
				if (this->hover_index >= 0) {
 
					uint offset = this->hover_index * this->line_height;
 
					GfxFillRect(r.left + 2, r.top + offset, r.right - 1, r.top + offset + this->line_height - 1, GREY_SCALE(9));
 
				}
 

	
 
				for (const Company *c : Company::Iterate()) {
 
					this->DrawCompany(c, r.left, r.right, r.top, line);
 
				NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
 
				if (own_ci->client_playas == COMPANY_SPECTATOR && !NetworkMaxCompaniesReached()) {
 
					this->DrawCompany(COMPANY_NEW_COMPANY, r.left, r.right, r.top, line);
 
				}
 

	
 
				if (own_ci->client_playas != COMPANY_SPECTATOR) {
 
					this->DrawCompany(own_ci->client_playas, r.left, r.right, r.top, line);
 
				}
 

	
 
				for (const Company *c : Company::Iterate()) {
 
					if (own_ci->client_playas == c->index) continue;
 
					this->DrawCompany(c->index, r.left, r.right, r.top, line);
 
				}
 

	
 
				/* Specators */
 
				this->DrawCompany(nullptr, r.left, r.right, r.top, line);
 
				this->DrawCompany(COMPANY_SPECTATOR, r.left, r.right, r.top, line);
 

	
 
				break;
 
			}
 
		}
 
	}
 

	
src/toolbar_gui.cpp
Show inline comments
 
@@ -201,14 +201,13 @@ static void PopupMainToolbMenu(Window *w
 
	}
 
	PopupMainToolbMenu(w, widget, std::move(list), 0);
 
}
 

	
 
/** Enum for the Company Toolbar's network related buttons */
 
static const int CTMN_CLIENT_LIST = -1; ///< Show the client list
 
static const int CTMN_NEW_COMPANY = -2; ///< Create a new company
 
static const int CTMN_SPECTATOR   = -3; ///< Show a company window as spectator
 
static const int CTMN_SPECTATOR   = -2; ///< Show a company window as spectator
 

	
 
/**
 
 * Pop up a generic company list menu.
 
 * @param w The toolbar window.
 
 * @param widget The button widget id.
 
 * @param grey A bitbask of which items to mark as disabled.
 
@@ -220,16 +219,12 @@ static void PopupMainCompanyToolbMenu(Wi
 
	switch (widget) {
 
		case WID_TN_COMPANIES:
 
			if (!_networking) break;
 

	
 
			/* Add the client list button for the companies menu */
 
			list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false));
 

	
 
			if (_local_company == COMPANY_SPECTATOR) {
 
				list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached()));
 
			}
 
			break;
 

	
 
		case WID_TN_STORY:
 
			list.emplace_back(new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false));
 
			break;
 

	
 
@@ -605,20 +600,12 @@ static CallBackFunction MenuClickCompany
 
{
 
	if (_networking) {
 
		switch (index) {
 
			case CTMN_CLIENT_LIST:
 
				ShowClientList();
 
				return CBF_NONE;
 

	
 
			case CTMN_NEW_COMPANY:
 
				if (_network_server) {
 
					DoCommandP(0, CCA_NEW, _network_own_client_id, CMD_COMPANY_CTRL);
 
				} else {
 
					NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company);
 
				}
 
				return CBF_NONE;
 
		}
 
	}
 
	ShowCompany((CompanyID)index);
 
	return CBF_NONE;
 
}
 

	
0 comments (0 inline, 0 general)