1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 03:23:15 +01:00

Merge pull request #15624 from vijfhoek/serverlist-screencoordsxy

This commit is contained in:
Tulio Leao
2021-10-27 00:20:02 -03:00
committed by GitHub

View File

@@ -109,10 +109,9 @@ enum
DDIDX_FAVOURITE
};
static int32_t _hoverButtonIndex = -1;
static bool _showNetworkVersionTooltip = false;
static std::string _version;
static void server_list_get_item_button(int32_t buttonIndex, int32_t x, int32_t y, int32_t width, int32_t* outX, int32_t* outY);
static void join_server(std::string address);
static void server_list_fetch_servers_begin();
static void server_list_fetch_servers_check(rct_window* w);
@@ -281,45 +280,28 @@ static void window_server_list_scroll_mousedown(rct_window* w, int32_t scrollInd
static void window_server_list_scroll_mouseover(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
{
// Item
int32_t index = screenCoords.y / ITEM_HEIGHT;
if (index < 0 || index >= w->no_list_items)
{
index = -1;
}
int32_t hoverButtonIndex = -1;
auto& listWidget = w->widgets[WIDX_LIST];
if (index != -1)
{
int32_t width = listWidget.width();
int32_t sy = index * ITEM_HEIGHT;
for (int32_t i = 0; i < 2; i++)
{
int32_t bx, by;
server_list_get_item_button(i, 0, sy, width, &bx, &by);
if (screenCoords.x >= bx && screenCoords.y >= by && screenCoords.x < bx + 24 && screenCoords.y < by + 24)
{
hoverButtonIndex = i;
break;
}
}
int32_t itemIndex = screenCoords.y / ITEM_HEIGHT;
bool showNetworkVersionTooltip = false;
if (itemIndex < 0 || itemIndex >= w->no_list_items)
{
itemIndex = -1;
}
else
{
const int32_t iconX = listWidget.width() - SCROLLBAR_WIDTH - 7 - 10;
showNetworkVersionTooltip = screenCoords.x > iconX;
}
int32_t width = listWidget.width();
int32_t right = width - 3 - 14 - 10;
if (screenCoords.x < right)
if (w->selected_list_item != itemIndex || _showNetworkVersionTooltip != showNetworkVersionTooltip)
{
listWidget.tooltip = STR_NONE;
window_tooltip_close();
}
w->selected_list_item = itemIndex;
_showNetworkVersionTooltip = showNetworkVersionTooltip;
if (w->selected_list_item != index || _hoverButtonIndex != hoverButtonIndex)
{
w->selected_list_item = index;
_hoverButtonIndex = hoverButtonIndex;
listWidget.tooltip = showNetworkVersionTooltip ? static_cast<rct_string_id>(STR_NETWORK_VERSION_TIP) : STR_NONE;
window_tooltip_close();
w->Invalidate();
}
}
@@ -429,7 +411,6 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi
ScreenCoordsXY screenCoords;
screenCoords.y = 0;
listWidget.tooltip = STR_NONE;
for (int32_t i = 0; i < w->no_list_items; i++)
{
if (screenCoords.y >= dpi->y + dpi->height)
@@ -443,7 +424,6 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi
{
gfx_filter_rect(dpi, { 0, screenCoords.y, width, screenCoords.y + ITEM_HEIGHT }, FilterPaletteID::PaletteDarken1);
_version = serverDetails.Version;
listWidget.tooltip = STR_NETWORK_VERSION_TIP;
}
colour_t colour = w->colours[1];
@@ -516,12 +496,6 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi
}
}
static void server_list_get_item_button(int32_t buttonIndex, int32_t x, int32_t y, int32_t width, int32_t* outX, int32_t* outY)
{
*outX = width - 3 - 36 - (30 * buttonIndex);
*outY = y + 2;
}
static void join_server(std::string address)
{
int32_t port = NETWORK_DEFAULT_PORT;