From 01c7a06c2227b1e014a38c530f8c20258af6a15b Mon Sep 17 00:00:00 2001 From: SushiTee Date: Wed, 7 Nov 2012 17:59:05 +0100 Subject: [PATCH] made overlay enterable --- src/game/client/components/menus.cpp | 3 ++ src/game/client/components/menus.h | 2 + src/game/client/components/menus_browser.cpp | 47 +++++++++++++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 441a76c08..4cc928580 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2212,6 +2212,9 @@ bool CMenus::OnMouseMove(float x, float y) if(!m_MenuActive) return false; + // prev mouse position + m_PrevMousePos = m_MousePos; + UI()->ConvertMouseMove(&x, &y); m_MousePos.x += x; m_MousePos.y += y; diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 5023a1ef7..0443a29ff 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -150,6 +150,7 @@ class CMenus : public CComponent bool m_MenuActive; bool m_UseMouseButtons; vec2 m_MousePos; + vec2 m_PrevMousePos; bool m_InfoMode; // images @@ -332,6 +333,7 @@ class CMenus : public CComponent const void *m_pData; float m_X; float m_Y; + bool m_Reset; }; CInfoOverlay m_InfoOverlay; diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index ea94157ce..9127670d9 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -142,11 +142,15 @@ void CMenus::Move(bool Up, int Filter) void CMenus::SetOverlay(int Type, float x, float y, const void *pData) { - m_InfoOverlayActive = true; - m_InfoOverlay.m_Type = Type; - m_InfoOverlay.m_X = x; - m_InfoOverlay.m_Y = y; - m_InfoOverlay.m_pData = pData; + if(m_InfoOverlay.m_Reset) + { + m_InfoOverlayActive = true; + m_InfoOverlay.m_Type = Type; + m_InfoOverlay.m_X = x; + m_InfoOverlay.m_Y = y; + m_InfoOverlay.m_pData = pData; + m_InfoOverlay.m_Reset = false; + } } int CMenus::DoBrowserEntry(const void *pID, CUIRect *pRect, const CServerInfo *pEntry, bool Selected) @@ -524,16 +528,23 @@ bool CMenus::RenderFilterHeader(CUIRect View, int FilterIndex) void CMenus::RenderServerbrowserOverlay() { if(!m_InfoOverlayActive) + { + m_InfoOverlay.m_Reset = true; return; + } int Type = m_InfoOverlay.m_Type; + CUIRect View; if(Type == CInfoOverlay::OVERLAY_HEADERINFO) { CBrowserFilter *pFilter = (CBrowserFilter*)m_InfoOverlay.m_pData; // get position - CUIRect View = { m_InfoOverlay.m_X-100.0f, m_InfoOverlay.m_Y, 100.0f, 30.0f }; + View.x = m_InfoOverlay.m_X-100.0f; + View.y = m_InfoOverlay.m_Y; + View.w = 100.0f; + View.h = 30.0f; // render background RenderTools()->DrawUIRect(&View, vec4(0.25f, 0.25f, 0.25f, 1.0f), CUI::CORNER_ALL, 6.0f); @@ -553,7 +564,10 @@ void CMenus::RenderServerbrowserOverlay() const CServerInfo *pInfo = (CServerInfo*)m_InfoOverlay.m_pData; // get position - CUIRect View = { m_InfoOverlay.m_X-210.0f, m_InfoOverlay.m_Y, 210.0f, pInfo->m_NumClients ? 98.0f + pInfo->m_NumClients*25.0f : 72.0f }; + View.x = m_InfoOverlay.m_X-210.0f; + View.y = m_InfoOverlay.m_Y; + View.w = 210.0f; + View.h = pInfo->m_NumClients ? 98.0f + pInfo->m_NumClients*25.0f : 72.0f; if(View.y+View.h >= 590.0f) View.y -= View.y+View.h - 590.0f; @@ -575,7 +589,10 @@ void CMenus::RenderServerbrowserOverlay() if(pInfo && pInfo->m_NumClients) { // get position - CUIRect View = { m_InfoOverlay.m_X+25.0f, m_InfoOverlay.m_Y, 250.0f, pInfo->m_NumClients*ButtonHeight }; + View.x = m_InfoOverlay.m_X+25.0f; + View.y = m_InfoOverlay.m_Y; + View.w = 250.0f; + View.h = pInfo->m_NumClients*ButtonHeight; if(View.x+View.w > Screen.w-5.0f) { View.y += 25.0f; @@ -674,7 +691,10 @@ void CMenus::RenderServerbrowserOverlay() } else { - CUIRect View = { m_InfoOverlay.m_X+25.0f, m_InfoOverlay.m_Y, 150.0f, ButtonHeight }; + View.x = m_InfoOverlay.m_X+25.0f; + View.y = m_InfoOverlay.m_Y; + View.w = 150.0f; + View.h = ButtonHeight; if(View.x+View.w > Screen.w-5.0f) { View.y += 25.0f; @@ -695,7 +715,14 @@ void CMenus::RenderServerbrowserOverlay() } // deactivate it - m_InfoOverlayActive = false; + vec2 OverlayCenter = vec2(View.x+View.w/2.0f, View.y+View.h/2.0f); + float MouseDistance = distance(m_MousePos, OverlayCenter); + float PrefMouseDistance = distance(m_PrevMousePos, OverlayCenter); + if(PrefMouseDistance > MouseDistance && !UI()->MouseInside(&View)) + { + m_InfoOverlayActive = false; + m_InfoOverlay.m_Reset = true; + } } void CMenus::RenderServerbrowserServerList(CUIRect View)