Skip to content

Commit

Permalink
Change: use icons to indicate you/host in Online Players GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed Apr 24, 2021
1 parent d2bf487 commit 0b1f3f6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
Binary file modified media/baseset/openttd.grf
Binary file not shown.
4 changes: 3 additions & 1 deletion media/baseset/openttd/openttdgui.nfo
Expand Up @@ -4,7 +4,7 @@
// See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
//
-1 * 0 0C "OpenTTD GUI graphics"
-1 * 3 05 15 \b 189 // OPENTTD_SPRITE_COUNT
-1 * 3 05 15 \b 191 // OPENTTD_SPRITE_COUNT
-1 sprites/openttdgui.png 8bpp 66 8 64 31 -31 7 normal
-1 sprites/openttdgui.png 8bpp 146 8 64 31 -31 7 normal
-1 sprites/openttdgui.png 8bpp 226 8 64 31 -31 7 normal
Expand Down Expand Up @@ -194,3 +194,5 @@
-1 sprites/openttdgui.png 8bpp 539 440 12 10 0 0 normal
-1 sprites/openttdgui.png 8bpp 553 440 12 10 0 0 normal
-1 sprites/openttdgui.png 8bpp 567 440 12 10 0 0 normal
-1 sprites/openttdgui.png 8bpp 581 440 10 10 0 0 normal
-1 sprites/openttdgui.png 8bpp 593 440 10 10 0 0 normal
Binary file modified media/baseset/openttd/openttdgui.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/lang/english.txt
Expand Up @@ -2137,8 +2137,6 @@ 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
Expand All @@ -2148,6 +2146,8 @@ STR_NETWORK_CLIENT_LIST_CHAT_SPECTATOR_TOOLTIP :{BLACK}Send a m
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_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_ADMIN_CLIENT_KICK :Kick
STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_BAN :Ban
Expand Down
60 changes: 51 additions & 9 deletions src/network/network_gui.cpp
Expand Up @@ -1750,6 +1750,8 @@ struct NetworkClientListWindow : Window {
uint line_height;
uint line_count;
int hover_index;
int player_self_index;
int player_host_index;

std::map<uint, std::vector<std::unique_ptr<ButtonCommon>>> buttons;

Expand Down Expand Up @@ -1844,7 +1846,7 @@ struct NetworkClientListWindow : Window {
{
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));
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));
this->buttons[line_count].emplace_back(chat_button);
if (own_ci->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));

Expand All @@ -1858,6 +1860,12 @@ struct NetworkClientListWindow : Window {
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 (ci->client_id == _network_own_client_id) {
this->player_self_index = this->line_count;
} else if (ci->client_id == CLIENT_ID_SERVER) {
this->player_host_index = this->line_count;
}

this->line_count += 1;
}

Expand All @@ -1874,6 +1882,8 @@ struct NetworkClientListWindow : Window {

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

/* As spectator, show a line to create a new company. */
if (own_ci->client_playas == COMPANY_SPECTATOR && !NetworkMaxCompaniesReached()) {
Expand Down Expand Up @@ -1933,7 +1943,10 @@ struct NetworkClientListWindow : Window {

public:
NetworkClientListWindow(WindowDesc *desc, WindowNumber window_number) :
Window(desc)
Window(desc),
hover_index(-1),
player_self_index(-1),
player_host_index(-1)
{
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_CL_SCROLLBAR);
Expand Down Expand Up @@ -2031,6 +2044,30 @@ struct NetworkClientListWindow : Window {
{
switch (widget) {
case WID_CL_MATRIX: {
int index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CL_MATRIX);

bool rtl = _current_text_dir == TD_RTL;
NWidgetBase *widget_matrix = this->GetWidget<NWidgetBase>(WID_CL_MATRIX);

Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
uint text_left = widget_matrix->pos_x + (rtl ? (uint)WD_FRAMERECT_LEFT : d.width + 8);
uint text_right = widget_matrix->pos_x + widget_matrix->current_x - (rtl ? d.width + 8 : (uint)WD_FRAMERECT_RIGHT);

Dimension d2 = GetSpriteSize(SPR_PLAYER_SELF);
uint offset_x = CLIENT_OFFSET_LEFT - d2.width - 3;

uint player_icon_x = rtl ? text_right - offset_x - d2.width : text_left + offset_x;

if (IsInsideMM(pt.x, player_icon_x, player_icon_x + d2.width)) {
if (index == this->player_self_index) {
GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP, 0, nullptr, close_cond);
return true;
} else if (index == this->player_host_index) {
GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP, 0, nullptr, close_cond);
return true;
}
}

ButtonCommon *button = this->GetButtonAtPoint(pt);
if (button == nullptr) return false;

Expand Down Expand Up @@ -2241,17 +2278,22 @@ struct NetworkClientListWindow : Window {
this->DrawButtons(x, y, button_find->second);
}

StringID client_string = STR_JUST_RAW_STRING;

if (ci->client_id == CLIENT_ID_SERVER) {
client_string = STR_NETWORK_CLIENT_LIST_PLAYER_HOST;
}
SpriteID player_icon = 0;
if (ci->client_id == _network_own_client_id) {
client_string = STR_NETWORK_CLIENT_LIST_PLAYER_SELF;
player_icon = SPR_PLAYER_SELF;
} else if (ci->client_id == CLIENT_ID_SERVER) {
player_icon = SPR_PLAYER_HOST;
}

if (player_icon != 0) {
Dimension d2 = GetSpriteSize(player_icon);
uint offset_x = CLIENT_OFFSET_LEFT - 3;
int offset_y = std::max(0, ((int)(this->line_height + 1) - (int)d2.height) / 2);
DrawSprite(player_icon, PALETTE_TO_GREY, rtl ? text_right - offset_x : text_left + offset_x - d2.width, y + offset_y);
}

SetDParamStr(0, ci->client_name);
DrawString(rtl ? x : text_left + CLIENT_OFFSET_LEFT, rtl ? text_right - CLIENT_OFFSET_LEFT : x, y + text_y_offset, client_string, TC_BLACK);
DrawString(rtl ? x : text_left + CLIENT_OFFSET_LEFT, rtl ? text_right - CLIENT_OFFSET_LEFT : x, y + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK);
}

y += this->line_height;
Expand Down
4 changes: 3 additions & 1 deletion src/table/sprites.h
Expand Up @@ -54,7 +54,7 @@ static const SpriteID SPR_LARGE_SMALL_WINDOW = 682;

/** Extra graphic spritenumbers */
static const SpriteID SPR_OPENTTD_BASE = 4896;
static const uint16 OPENTTD_SPRITE_COUNT = 189;
static const uint16 OPENTTD_SPRITE_COUNT = 191;

/* Halftile-selection sprites */
static const SpriteID SPR_HALFTILE_SELECTION_FLAT = SPR_OPENTTD_BASE;
Expand Down Expand Up @@ -169,6 +169,8 @@ static const SpriteID SPR_GOTO_LOCATION = SPR_OPENTTD_BASE + 185;
static const SpriteID SPR_CHAT = SPR_OPENTTD_BASE + 186;
static const SpriteID SPR_ADMIN = SPR_OPENTTD_BASE + 187;
static const SpriteID SPR_JOIN = SPR_OPENTTD_BASE + 188;
static const SpriteID SPR_PLAYER_SELF = SPR_OPENTTD_BASE + 189;
static const SpriteID SPR_PLAYER_HOST = SPR_OPENTTD_BASE + 190;

static const SpriteID SPR_IMG_CARGOFLOW = SPR_OPENTTD_BASE + 174;

Expand Down

0 comments on commit 0b1f3f6

Please sign in to comment.