Changeset - r25258:66d1fbacd966
[Not reviewed]
master
0 3 0
Patric Stout - 3 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
 
@@ -2113,49 +2113,50 @@ STR_NETWORK_CONNECTING_SPECIAL_2        
 
############ End of leave-in-this-order
 
STR_NETWORK_CONNECTING_WAITING                                  :{BLACK}{NUM} client{P "" s} in front of you
 
STR_NETWORK_CONNECTING_DOWNLOADING_1                            :{BLACK}{BYTES} downloaded so far
 
STR_NETWORK_CONNECTING_DOWNLOADING_2                            :{BLACK}{BYTES} / {BYTES} downloaded so far
 

	
 
STR_NETWORK_CONNECTION_DISCONNECT                               :{BLACK}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
 
STR_NETWORK_CLIENT_LIST_SERVER_NAME_EDIT_TOOLTIP                :{BLACK}Edit the name of your server
 
STR_NETWORK_CLIENT_LIST_SERVER_NAME_QUERY_CAPTION               :Name of the server
 
STR_NETWORK_CLIENT_LIST_SERVER_VISIBILITY                       :{BLACK}Visibility
 
STR_NETWORK_CLIENT_LIST_SERVER_VISIBILITY_TOOLTIP               :{BLACK}Whether other people can see your server in the public listing
 
STR_NETWORK_CLIENT_LIST_PLAYER                                  :{BLACK}Player
 
STR_NETWORK_CLIENT_LIST_PLAYER_NAME                             :{BLACK}Name
 
STR_NETWORK_CLIENT_LIST_PLAYER_NAME_TOOLTIP                     :{BLACK}Your player name
 
STR_NETWORK_CLIENT_LIST_PLAYER_NAME_EDIT_TOOLTIP                :{BLACK}Edit your player name
 
STR_NETWORK_CLIENT_LIST_PLAYER_NAME_QUERY_CAPTION               :Your player name
 
STR_NETWORK_CLIENT_LIST_PLAYER_HOST                             :{WHITE}(host) {BLACK}{RAW_STRING}
 
STR_NETWORK_CLIENT_LIST_PLAYER_SELF                             :{WHITE}(you) {BLACK}{RAW_STRING}
 
STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_TOOLTIP                    :{BLACK}Administrative actions to perform for this client
 
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
 

	
 
STR_NETWORK_CLIENT_LIST_ASK_CAPTION                             :{WHITE}Admin action
 
STR_NETWORK_CLIENT_LIST_ASK_CLIENT_KICK                         :{YELLOW}Are you sure you want to kick player '{RAW_STRING}'?
 
STR_NETWORK_CLIENT_LIST_ASK_CLIENT_BAN                          :{YELLOW}Are you sure you want to ban player '{RAW_STRING}'?
 
STR_NETWORK_CLIENT_LIST_ASK_COMPANY_RESET                       :{YELLOW}Are you sure you want to delete company '{COMPANY}'?
 
STR_NETWORK_CLIENT_LIST_ASK_COMPANY_UNLOCK                      :{YELLOW}Are you sure you want to reset the password of company '{COMPANY}'?
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -1784,24 +1784,39 @@ private:
 
			NetworkServerDoMove(CLIENT_ID_SERVER, company_id);
 
			MarkWholeScreenDirty();
 
		} else if (NetworkCompanyIsPassworded(company_id)) {
 
			w->query_widget = WID_CL_COMPANY_JOIN;
 
			w->join_company = company_id;
 
			ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_PASSWORD);
 
		} 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)
 
	{
 
		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));
 

	
 
		Rect wi_rect;
 
@@ -1877,26 +1892,38 @@ private:
 
	}
 

	
 
	/**
 
	 * Rebuild the list, meaning: calculate the lines needed and what buttons go on which line.
 
	 */
 
	void RebuildList()
 
	{
 
		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);
 

	
 
		this->vscroll->SetCount(this->line_count);
 
	}
 

	
 
	/**
 
	 * Get the button at a specific point on the WID_CL_MATRIX.
 
	 * @param pt The point to look for a button.
 
@@ -2168,31 +2195,31 @@ public:
 
			DrawSprite(button->sprite, PAL_NONE, left + ScaleGUITrad(WD_FRAMERECT_LEFT), y + offset + ScaleGUITrad(WD_FRAMERECT_TOP));
 
			if (button->disabled) {
 
				GfxFillRect(left + 1, y + offset + 1, right - 1, y + offset + button->height - 1, _colour_gradient[button->colour & 0xF][2], FILLRECT_CHECKER);
 
			}
 

	
 
			int width = button->width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
			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);
 

	
 
		uint text_left = left + (rtl ? (uint)WD_FRAMERECT_LEFT : d.width + 8);
 
		uint text_right = right - (rtl ? d.width + 8 : (uint)WD_FRAMERECT_RIGHT);
 

	
 
		uint line_start = this->vscroll->GetPosition();
 
		uint line_end = line_start + this->vscroll->GetCapacity();
 
@@ -2200,42 +2227,44 @@ public:
 
		uint y = top + (this->line_height * (line - line_start));
 

	
 
		/* Draw the company 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 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. */
 
				auto button_find = this->buttons.find(line);
 
				if (button_find != this->buttons.end()) {
 
					this->DrawButtons(x, y, button_find->second);
 
				}
 

	
 
				StringID client_string = STR_JUST_RAW_STRING;
 
@@ -2258,29 +2287,40 @@ public:
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		switch (widget) {
 
			case WID_CL_MATRIX: {
 
				uint line = 0;
 

	
 
				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;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnMouseLoop() override
 
	{
 
		if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) != WID_CL_MATRIX) {
 
			this->hover_index = -1;
 
			this->SetDirty();
 
			return;
src/toolbar_gui.cpp
Show inline comments
 
@@ -195,47 +195,42 @@ static void PopupMainToolbMenu(Window *w
 
 */
 
static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
 
{
 
	DropDownList list;
 
	for (int i = 0; i < count; i++) {
 
		list.emplace_back(new DropDownListStringItem(string + i, i, false));
 
	}
 
	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.
 
 */
 
static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0)
 
{
 
	DropDownList list;
 

	
 
	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;
 

	
 
		case WID_TN_GOAL:
 
			list.emplace_back(new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false));
 
			break;
 
	}
 

	
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
@@ -599,32 +594,24 @@ static CallBackFunction ToolbarCompanies
 
 * Handle click on the entry in the Company menu.
 
 *
 
 * @param index Menu entry to handle.
 
 * @return #CBF_NONE
 
 */
 
static CallBackFunction MenuClickCompany(int index)
 
{
 
	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;
 
}
 

	
 
/* --- Story button menu --- */
 

	
 
static CallBackFunction ToolbarStoryClick(Window *w)
 
{
 
	PopupMainCompanyToolbMenu(w, WID_TN_STORY, 0);
 
	return CBF_NONE;
0 comments (0 inline, 0 general)