mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
prevent lock of the ingame GUI. Closes #828
This commit is contained in:
parent
d107e34e1f
commit
e98921593b
|
@ -477,7 +477,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
|
|||
|
||||
bool JustGotActive = false;
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
@ -678,7 +678,7 @@ float CMenus::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
|
|||
float ReturnValue = Current;
|
||||
int Inside = UI()->MouseInside(&Handle);
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
UI()->SetActiveItem(0);
|
||||
|
@ -727,7 +727,7 @@ float CMenus::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current)
|
|||
float ReturnValue = Current;
|
||||
int Inside = UI()->MouseInside(&Handle);
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
UI()->SetActiveItem(0);
|
||||
|
@ -930,7 +930,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected)
|
|||
{
|
||||
gs_ListBoxDoneEvents = 1;
|
||||
|
||||
if(m_EnterPressed || (UI()->ActiveItem() == pId && Input()->MouseDoubleClick()))
|
||||
if(m_EnterPressed || (UI()->CheckActiveItem(pId) && Input()->MouseDoubleClick()))
|
||||
{
|
||||
gs_ListBoxItemActivated = true;
|
||||
UI()->SetActiveItem(0);
|
||||
|
@ -1006,7 +1006,7 @@ int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key)
|
|||
if(!UI()->MouseButton(0) && !UI()->MouseButton(1) && pGrabbedID == pID)
|
||||
MouseReleased = true;
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(m_Binder.m_GotKey)
|
||||
{
|
||||
|
@ -1050,7 +1050,7 @@ int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key)
|
|||
UI()->SetHotItem(pID);
|
||||
|
||||
// draw
|
||||
if (UI()->ActiveItem() == pID && ButtonUsed == 0)
|
||||
if (UI()->CheckActiveItem(pID) && ButtonUsed == 0)
|
||||
DoButton_KeySelect(pID, "???", 0, pRect);
|
||||
else
|
||||
{
|
||||
|
@ -2383,6 +2383,8 @@ void CMenus::OnRender()
|
|||
Graphics()->QuadsEnd();
|
||||
return;*/
|
||||
|
||||
UI()->StartCheck();
|
||||
|
||||
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
||||
SetActive(true);
|
||||
|
||||
|
@ -2443,12 +2445,13 @@ void CMenus::OnRender()
|
|||
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
|
||||
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "%p %p %p", UI()->HotItem(), UI()->ActiveItem(), UI()->LastActiveItem());
|
||||
str_format(aBuf, sizeof(aBuf), "%p %p %p", UI()->HotItem(), UI()->GetActiveItem(), UI()->LastActiveItem());
|
||||
CTextCursor Cursor;
|
||||
TextRender()->SetCursor(&Cursor, 10, 10, 10, TEXTFLAG_RENDER);
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
}
|
||||
|
||||
UI()->FinishCheck();
|
||||
m_EscapePressed = false;
|
||||
m_EnterPressed = false;
|
||||
m_DeletePressed = false;
|
||||
|
|
|
@ -166,7 +166,7 @@ int CMenus::DoBrowserEntry(const void *pID, CUIRect *pRect, const CServerInfo *p
|
|||
int ReturnValue = 0;
|
||||
int Inside = UI()->MouseInside(pRect);
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
@ -1056,7 +1056,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
|
|||
else
|
||||
{
|
||||
// reset active item, if not visible
|
||||
if(UI()->ActiveItem() == pItem)
|
||||
if(UI()->CheckActiveItem(pItem))
|
||||
UI()->SetActiveItem(0);
|
||||
|
||||
// don't render invisible items
|
||||
|
|
|
@ -123,7 +123,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
// do the logic
|
||||
int Inside = UI()->MouseInside(&SeekBar);
|
||||
|
||||
if(UI()->ActiveItem() == id)
|
||||
if(UI()->CheckActiveItem(id))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
UI()->SetActiveItem(0);
|
||||
|
|
|
@ -52,7 +52,7 @@ void CMenus::DoPopupMenu()
|
|||
bool Inside = UI()->MouseInside(&s_Popups[i].m_Rect);
|
||||
UI()->SetHotItem(&s_Popups[i].m_pId);
|
||||
|
||||
if(UI()->ActiveItem() == &s_Popups[i].m_pId)
|
||||
if(UI()->CheckActiveItem(&s_Popups[i].m_pId))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
|
|
@ -275,7 +275,7 @@ int CUI::DoButtonLogic(const void *pID, const char *pText, int Checked, const CU
|
|||
int Inside = MouseInside(pRect);
|
||||
static int ButtonUsed = 0;
|
||||
|
||||
if(ActiveItem() == pID)
|
||||
if(CheckActiveItem(pID))
|
||||
{
|
||||
if(!MouseButton(ButtonUsed))
|
||||
{
|
||||
|
@ -309,7 +309,7 @@ int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *
|
|||
{
|
||||
int Inside = MouseInside(pRect);
|
||||
|
||||
if(ActiveItem() == pID)
|
||||
if(CheckActiveItem(pID))
|
||||
{
|
||||
if(!MouseButton(0))
|
||||
SetActiveItem(0);
|
||||
|
@ -322,7 +322,7 @@ int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *
|
|||
else if(Inside)
|
||||
SetHotItem(pID);
|
||||
|
||||
if(ActiveItem() != pID)
|
||||
if(!CheckActiveItem(pID))
|
||||
return 0;
|
||||
|
||||
if(pX)
|
||||
|
|
|
@ -29,6 +29,7 @@ class CUI
|
|||
const void *m_pActiveItem;
|
||||
const void *m_pLastActiveItem;
|
||||
const void *m_pBecommingHotItem;
|
||||
bool m_ActiveItemValid;
|
||||
float m_MouseX, m_MouseY; // in gui space
|
||||
float m_MouseWorldX, m_MouseWorldY; // in world space
|
||||
unsigned m_MouseButtons;
|
||||
|
@ -88,13 +89,17 @@ public:
|
|||
int MouseButtonClicked(int Index) const { return MouseButton(Index) && !((m_LastMouseButtons>>Index)&1) ; }
|
||||
|
||||
void SetHotItem(const void *pID) { m_pBecommingHotItem = pID; }
|
||||
void SetActiveItem(const void *pID) { m_pActiveItem = pID; if (pID) m_pLastActiveItem = pID; }
|
||||
void SetActiveItem(const void *pID) { m_ActiveItemValid = true; m_pActiveItem = pID; if (pID) m_pLastActiveItem = pID; }
|
||||
bool CheckActiveItem(const void *pID) { if(m_pActiveItem == pID) { m_ActiveItemValid = true; return true; } return false; };
|
||||
void ClearLastActiveItem() { m_pLastActiveItem = 0; }
|
||||
const void *HotItem() const { return m_pHotItem; }
|
||||
const void *NextHotItem() const { return m_pBecommingHotItem; }
|
||||
const void *ActiveItem() const { return m_pActiveItem; }
|
||||
const void *GetActiveItem() const { return m_pActiveItem; }
|
||||
const void *LastActiveItem() const { return m_pLastActiveItem; }
|
||||
|
||||
void StartCheck() { m_ActiveItemValid = false; };
|
||||
void FinishCheck() { if(!m_ActiveItemValid) SetActiveItem(0); };
|
||||
|
||||
int MouseInside(const CUIRect *pRect) const;
|
||||
void ConvertMouseMove(float *x, float *y) const;
|
||||
|
||||
|
|
|
@ -349,7 +349,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
|
|||
|
||||
bool JustGotActive = false;
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
@ -436,7 +436,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
|
|||
|
||||
vec4 CEditor::ButtonColorMul(const void *pID)
|
||||
{
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
return vec4(1,1,1,0.5f);
|
||||
else if(UI()->HotItem() == pID)
|
||||
return vec4(1,1,1,1.5f);
|
||||
|
@ -455,7 +455,7 @@ float CEditor::UiDoScrollbarV(const void *pID, const CUIRect *pRect, float Curre
|
|||
float Ret = Current;
|
||||
int Inside = UI()->MouseInside(&Handle);
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
UI()->SetActiveItem(0);
|
||||
|
@ -697,7 +697,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
|
|||
static float s_Value;
|
||||
int Inside = UI()->MouseInside(pRect);
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0) || Input()->KeyDown(KEY_ESCAPE))
|
||||
{
|
||||
|
@ -1164,7 +1164,7 @@ void CEditor::DoQuad(CQuad *q, int Index)
|
|||
|
||||
vec4 PivotColor;
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(m_MouseDeltaWx*m_MouseDeltaWx+m_MouseDeltaWy*m_MouseDeltaWy > 0.5f)
|
||||
{
|
||||
|
@ -1363,7 +1363,7 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
|
|||
|
||||
vec4 pointColor;
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
float dx = m_MouseDeltaWx;
|
||||
float dy = m_MouseDeltaWy;
|
||||
|
@ -1661,7 +1661,7 @@ void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex)
|
|||
|
||||
float dx = (CenterX - wx)/m_WorldZoom;
|
||||
float dy = (CenterY - wy)/m_WorldZoom;
|
||||
if(dx*dx+dy*dy < 50.0f && UI()->ActiveItem() == 0)
|
||||
if(dx*dx+dy*dy < 50.0f && UI()->CheckActiveItem(0))
|
||||
{
|
||||
UI()->SetHotItem(pID);
|
||||
s_ActQIndex = QIndex;
|
||||
|
@ -1673,7 +1673,7 @@ void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex)
|
|||
else
|
||||
IgnoreGrid = false;
|
||||
|
||||
if(UI()->ActiveItem() == pID && s_ActQIndex == QIndex)
|
||||
if(UI()->CheckActiveItem(pID) && s_ActQIndex == QIndex)
|
||||
{
|
||||
if(s_Operation == OP_MOVE)
|
||||
{
|
||||
|
@ -1886,7 +1886,7 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
|
|||
UI()->SetHotItem(s_pEditorID);
|
||||
|
||||
// do global operations like pan and zoom
|
||||
if(UI()->ActiveItem() == 0 && (UI()->MouseButton(0) || UI()->MouseButton(2)))
|
||||
if(UI()->CheckActiveItem(0) && (UI()->MouseButton(0) || UI()->MouseButton(2)))
|
||||
{
|
||||
s_StartWx = wx;
|
||||
s_StartWy = wy;
|
||||
|
@ -1909,7 +1909,7 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
|
|||
else
|
||||
m_pTooltip = "Use left mouse button to paint with the brush. Right button clears the brush.";
|
||||
|
||||
if(UI()->ActiveItem() == s_pEditorID)
|
||||
if(UI()->CheckActiveItem(s_pEditorID))
|
||||
{
|
||||
CUIRect r;
|
||||
r.x = s_StartWx;
|
||||
|
@ -2127,7 +2127,7 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
|
|||
}
|
||||
|
||||
// do panning
|
||||
if(UI()->ActiveItem() == s_pEditorID)
|
||||
if(UI()->CheckActiveItem(s_pEditorID))
|
||||
{
|
||||
if(s_Operation == OP_PAN_WORLD)
|
||||
{
|
||||
|
@ -2149,7 +2149,7 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if(UI()->ActiveItem() == s_pEditorID)
|
||||
else if(UI()->CheckActiveItem(s_pEditorID))
|
||||
{
|
||||
// release mouse
|
||||
if(!UI()->MouseButton(0))
|
||||
|
@ -3681,7 +3681,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
|
||||
float ColorMod = 1.0f;
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
@ -3750,7 +3750,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
m_pTooltip = "Left mouse to drag. Hold ctrl to be more precise. Hold shift to alter time point aswell. Right click to delete.";
|
||||
}
|
||||
|
||||
if(UI()->ActiveItem() == pID || UI()->HotItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID) || UI()->HotItem() == pID)
|
||||
{
|
||||
CurrentTime = pEnvelope->m_lPoints[i].m_Time;
|
||||
CurrentValue = pEnvelope->m_lPoints[i].m_aValues[c];
|
||||
|
@ -3791,7 +3791,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
if(UI()->MouseInside(&Final))
|
||||
UI()->SetHotItem(pID);
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
@ -3839,7 +3839,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
m_pTooltip = "Left mouse to drag. Hold ctrl to be more precise.";
|
||||
}
|
||||
|
||||
if(UI()->ActiveItem() == pID || UI()->HotItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID) || UI()->HotItem() == pID)
|
||||
{
|
||||
CurrentTime = pEnvelope->m_lPoints[i].m_Time + pEnvelope->m_lPoints[i].m_aOutTangentdx[c];
|
||||
CurrentValue = pEnvelope->m_lPoints[i].m_aValues[c] + pEnvelope->m_lPoints[i].m_aOutTangentdy[c];
|
||||
|
@ -3876,7 +3876,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
if(UI()->MouseInside(&Final))
|
||||
UI()->SetHotItem(pID);
|
||||
|
||||
if(UI()->ActiveItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
@ -3923,7 +3923,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
m_pTooltip = "Left mouse to drag. Hold ctrl to be more precise.";
|
||||
}
|
||||
|
||||
if(UI()->ActiveItem() == pID || UI()->HotItem() == pID)
|
||||
if(UI()->CheckActiveItem(pID) || UI()->HotItem() == pID)
|
||||
{
|
||||
CurrentTime = pEnvelope->m_lPoints[i].m_Time + pEnvelope->m_lPoints[i].m_aInTangentdx[c];
|
||||
CurrentValue = pEnvelope->m_lPoints[i].m_aValues[c] + pEnvelope->m_lPoints[i].m_aInTangentdy[c];
|
||||
|
@ -4471,6 +4471,7 @@ void CEditor::UpdateAndRender()
|
|||
else
|
||||
m_AnimateTime = 0;
|
||||
ms_pUiGotContext = 0;
|
||||
UI()->StartCheck();
|
||||
|
||||
// handle mouse movement
|
||||
float mx, my, Mwx, Mwy;
|
||||
|
@ -4535,6 +4536,7 @@ void CEditor::UpdateAndRender()
|
|||
m_ShowMousePointer = true;
|
||||
}
|
||||
|
||||
UI()->FinishCheck();
|
||||
Input()->ClearEvents();
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ void CEditor::UiDoPopupMenu()
|
|||
bool Inside = UI()->MouseInside(&s_UiPopups[i].m_Rect);
|
||||
UI()->SetHotItem(&s_UiPopups[i].m_pId);
|
||||
|
||||
if(UI()->ActiveItem() == &s_UiPopups[i].m_pId)
|
||||
if(UI()->CheckActiveItem(&s_UiPopups[i].m_pId))
|
||||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue