summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-04-24 13:06:59 +0200
committerPatric Stout <github@truebrain.nl>2021-04-24 21:43:58 +0200
commitfda1a590f6978f906ed21b6732f80c9aefa02b47 (patch)
treea90f190c05ed0d14f5dfbb0b7eec593887debb7f /src
parenta924b2ff81844c8d43ad1eaa25dea9642815738c (diff)
downloadopenttd-fda1a590f6978f906ed21b6732f80c9aefa02b47.tar.xz
Change: use icons to indicate you/host in Online Players GUI
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt4
-rw-r--r--src/network/network_gui.cpp60
-rw-r--r--src/table/sprites.h4
3 files changed, 56 insertions, 12 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 33ccca2a4..dbf0a82d0 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -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
@@ -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
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index e76500f09..68208ee3f 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1756,6 +1756,8 @@ private:
uint line_height; ///< Current lineheight of each entry in the matrix.
uint line_count; ///< Amount of lines in the matrix.
int hover_index; ///< Index of the current line we are hovering over, or -1 if none.
+ int player_self_index; ///< The line the current player is on.
+ int player_host_index; ///< The line the host is on.
std::map<uint, std::vector<std::unique_ptr<ButtonCommon>>> buttons; ///< Per line which buttons are available.
@@ -1870,7 +1872,7 @@ 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));
+ 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));
@@ -1884,6 +1886,12 @@ private:
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;
}
@@ -1900,6 +1908,8 @@ private:
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()) {
@@ -1959,7 +1969,10 @@ private:
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);
@@ -2057,6 +2070,30 @@ public:
{
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;
@@ -2267,17 +2304,22 @@ public:
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;
diff --git a/src/table/sprites.h b/src/table/sprites.h
index 039d50b9d..b7bb91020 100644
--- a/src/table/sprites.h
+++ b/src/table/sprites.h
@@ -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;
@@ -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;