From 75cdd8042cc9892c214c95227cad0cf40c1d5438 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Thu, 1 Apr 2021 16:48:38 +0200 Subject: [PATCH] Fix out of list clip clickable/hoverable items --- src/game/client/components/menus.h | 2 ++ src/game/client/components/menus_browser.cpp | 4 ++-- src/game/client/components/menus_demo.cpp | 23 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 76cdd83ff..638e53044 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -220,6 +220,8 @@ class CMenus : public CComponent CListboxItem UiDoListboxNextRow(); int UiDoListboxEnd(float *pScrollValue, bool *pItemActivated, bool *pListBoxActive = 0); + int UiLogicGetCurrentClickedItem(); + //static void demolist_listdir_callback(const char *name, int is_dir, void *user); //static void demolist_list_callback(const CUIRect *rect, int index, void *user); diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 691bb1583..5f13a81d5 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1066,14 +1066,14 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) for(int i = 0; i < pSelectedServer->m_NumReceivedClients; i++) { - CListboxItem Item = UiDoListboxNextItem(&i); + CListboxItem Item = UiDoListboxNextItem(&pSelectedServer->m_aClients[i]); if(!Item.m_Visible) continue; CUIRect Name, Clan, Score, Flag; Item.m_Rect.HSplitTop(25.0f, &Name, &Item.m_Rect); - if(UI()->DoButtonLogic(&pSelectedServer->m_aClients[i], "", 0, &Name)) + if(UiLogicGetCurrentClickedItem() == i) { if(pSelectedServer->m_aClients[i].m_FriendState == IFriends::FRIEND_PLAYER) m_pClient->Friends()->RemoveFriend(pSelectedServer->m_aClients[i].m_aName, pSelectedServer->m_aClients[i].m_aClan); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index b8fbb780e..fa1b36934 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -620,7 +620,18 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected, CListboxItem Item = UiDoListboxNextRow(); - if(Item.m_Visible && UI()->DoButtonLogic(pId, "", gs_ListBoxSelectedIndex == gs_ListBoxItemIndex, &Item.m_HitRect)) + CUIRect HitRect = Item.m_HitRect; + + if(HitRect.y < gs_ListBoxOriginalView.y) + { + float TmpDiff = gs_ListBoxOriginalView.y - HitRect.y; + HitRect.y = gs_ListBoxOriginalView.y; + HitRect.h -= TmpDiff; + } + + HitRect.h = minimum(HitRect.h, (gs_ListBoxOriginalView.y + gs_ListBoxOriginalView.h) - HitRect.y); + + if(Item.m_Visible && UI()->DoButtonLogic(pId, "", gs_ListBoxSelectedIndex == gs_ListBoxItemIndex, &HitRect)) { gs_ListBoxClicked = true; gs_ListBoxNewSelected = ThisItemIndex; @@ -696,7 +707,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected, r.Margin(1.5f, &r); RenderTools()->DrawUIRect(&r, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_ALL, 4.0f); } - else if(UI()->MouseInside(&Item.m_Rect) && !NoHoverEffects) + else if(UI()->MouseInside(&HitRect) && !NoHoverEffects) { CUIRect r = Item.m_Rect; r.Margin(1.5f, &r); @@ -718,6 +729,14 @@ int CMenus::UiDoListboxEnd(float *pScrollValue, bool *pItemActivated, bool *pLis return gs_ListBoxNewSelected; } +int CMenus::UiLogicGetCurrentClickedItem() +{ + if(gs_ListBoxClicked) + return gs_ListBoxNewSelected; + else + return -1; +} + int CMenus::DemolistFetchCallback(const char *pName, time_t Date, int IsDir, int StorageType, void *pUser) { CMenus *pSelf = (CMenus *)pUser;