Prevent lock of UI

Co-authored-by: oy <tom_adams@web.de>
This commit is contained in:
Robert Müller 2022-05-27 10:55:32 +02:00
parent 7348bf4d56
commit 2b02bd449b
10 changed files with 58 additions and 32 deletions

View file

@ -502,7 +502,7 @@ int CMenus::DoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, bool
str_format(s_NumStr, sizeof(s_NumStr), "%d", Current);
}
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(!UI()->MouseButton(0))
{
@ -540,7 +540,7 @@ int CMenus::DoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, bool
}
else
{
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(UseScroll)
{
@ -615,7 +615,7 @@ int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key, int ModifierCo
if(!UI()->MouseButton(0) && !UI()->MouseButton(1) && pGrabbedID == pID)
MouseReleased = true;
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(m_Binder.m_GotKey)
{
@ -662,7 +662,7 @@ int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key, int ModifierCo
UI()->SetHotItem(pID);
// draw
if(UI()->ActiveItem() == pID && s_ButtonUsed == 0)
if(UI()->CheckActiveItem(pID) && s_ButtonUsed == 0)
DoButton_KeySelect(pID, "???", 0, pRect);
else
{
@ -2518,6 +2518,8 @@ void CMenus::OnStateChange(int NewState, int OldState)
void CMenus::OnRender()
{
UI()->StartCheck();
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
SetActive(true);
@ -2610,6 +2612,8 @@ void CMenus::OnRender()
TextRender()->TextEx(&Cursor, aBuf, -1);
}
UI()->FinishCheck();
m_EscapePressed = false;
m_EnterPressed = false;
m_DeletePressed = false;

View file

@ -178,7 +178,7 @@ class CMenus : public CComponent
}
// render
size_t Index = 2;
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
Index = 0;
else if(UI()->HotItem() == pID)
Index = 1;

View file

@ -311,7 +311,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

View file

@ -333,7 +333,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
// do the logic
const bool Inside = UI()->MouseInside(&SeekBar);
if(UI()->ActiveItem() == id)
if(UI()->CheckActiveItem(id))
{
if(!UI()->MouseButton(0))
UI()->SetActiveItem(0);

View file

@ -399,7 +399,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
}
static bool s_ListBoxUsed = false;
if(UI()->ActiveItem() == pClan || UI()->ActiveItem() == pName)
if(UI()->CheckActiveItem(pClan) || UI()->CheckActiveItem(pName))
s_ListBoxUsed = false;
// country flag selector

View file

@ -159,7 +159,7 @@ void CUI::ConvertMouseMove(float *x, float *y) const
float CUI::ButtonColorMul(const void *pID)
{
if(ActiveItem() == pID)
if(CheckActiveItem(pID))
return ButtonColorMulActive();
else if(HotItem() == pID)
return ButtonColorMulHot();
@ -432,7 +432,7 @@ int CUI::DoButtonLogic(const void *pID, int Checked, const CUIRect *pRect)
const bool Inside = MouseHovered(pRect);
static int s_ButtonUsed = 0;
if(ActiveItem() == pID)
if(CheckActiveItem(pID))
{
if(!MouseButton(s_ButtonUsed))
{
@ -467,10 +467,10 @@ int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *
if(HotItem() == pID && MouseButtonClicked(0))
SetActiveItem(pID);
if(ActiveItem() == pID && !MouseButton(0))
if(CheckActiveItem(pID) && !MouseButton(0))
SetActiveItem(0);
if(ActiveItem() != pID)
if(!CheckActiveItem(pID))
return 0;
if(pX)

View file

@ -197,6 +197,8 @@ class CUI
const void *m_pLastActiveItem;
const void *m_pBecomingHotItem;
const void *m_pActiveTooltipItem;
bool m_ActiveItemValid = false;
float m_MouseX, m_MouseY; // in gui space
float m_MouseDeltaX, m_MouseDeltaY; // in gui space
float m_MouseWorldX, m_MouseWorldY; // in world space
@ -264,18 +266,35 @@ public:
void SetHotItem(const void *pID) { m_pBecomingHotItem = 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 SetActiveTooltipItem(const void *pID) { m_pActiveTooltipItem = pID; }
void ClearLastActiveItem() { m_pLastActiveItem = 0; }
void ClearLastActiveItem() { m_pLastActiveItem = nullptr; }
const void *HotItem() const { return m_pHotItem; }
const void *NextHotItem() const { return m_pBecomingHotItem; }
const void *ActiveItem() const { return m_pActiveItem; }
const void *ActiveTooltipItem() const { return m_pActiveTooltipItem; }
const void *LastActiveItem() const { return m_pLastActiveItem; }
void StartCheck() { m_ActiveItemValid = false; }
void FinishCheck()
{
if(!m_ActiveItemValid)
SetActiveItem(nullptr);
}
bool MouseInside(const CUIRect *pRect) const;
bool MouseInsideClip() const { return !IsClipped() || MouseInside(ClipArea()); }
bool MouseHovered(const CUIRect *pRect) const { return MouseInside(pRect) && MouseInsideClip(); }

View file

@ -61,7 +61,7 @@ float CUIEx::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
const bool InsideHandle = UI()->MouseHovered(&Handle);
bool Grabbed = false; // whether to apply the offset
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(UI()->MouseButton(0))
{
@ -108,7 +108,7 @@ float CUIEx::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, Rail.w / 2.0f);
float ColorSlider;
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
ColorSlider = 0.9f;
else if(UI()->HotItem() == pID)
ColorSlider = 1.0f;
@ -141,7 +141,7 @@ float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current,
const bool InsideHandle = UI()->MouseHovered(&Handle);
bool Grabbed = false; // whether to apply the offset
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(UI()->MouseButton(0))
{
@ -199,7 +199,7 @@ float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current,
RenderTools()->DrawUIRect(&Rail, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, Rail.h / 2.0f);
float ColorSlider;
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
ColorSlider = 0.9f;
else if(UI()->HotItem() == pID)
ColorSlider = 1.0f;
@ -507,7 +507,7 @@ bool CUIEx::DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigne
DispCursorPos = minimum(DispCursorPos, str_length(pDisplayStr));
bool JustGotActive = false;
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(!UI()->MouseButton(0))
{

View file

@ -540,7 +540,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
str_format(s_aNumStr, sizeof(s_aNumStr), "%d", Current);
}
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(!UI()->MouseButton(0))
{
@ -580,7 +580,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
}
else
{
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(UI()->MouseButton(0))
{
@ -1243,7 +1243,7 @@ void CEditor::DoSoundSource(CSoundSource *pSource, int Index)
bool IgnoreGrid;
IgnoreGrid = Input()->KeyIsPressed(KEY_LALT) || Input()->KeyIsPressed(KEY_RALT);
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(m_MouseDeltaWx * m_MouseDeltaWx + m_MouseDeltaWy * m_MouseDeltaWy > 0.0f)
{
@ -1372,7 +1372,7 @@ void CEditor::DoQuad(CQuad *pQuad, int Index)
Graphics()->QuadsDraw(&QuadItem, 1);
}
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(m_MouseDeltaWx * m_MouseDeltaWx + m_MouseDeltaWy * m_MouseDeltaWy > 0.0f)
{
@ -1625,7 +1625,7 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
bool IgnoreGrid;
IgnoreGrid = Input()->KeyIsPressed(KEY_LALT) || Input()->KeyIsPressed(KEY_RALT);
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(!s_Moved)
{
@ -2184,7 +2184,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(nullptr))
{
UI()->SetHotItem(pID);
s_CurQIndex = QIndex;
@ -2193,7 +2193,7 @@ void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex)
bool IgnoreGrid;
IgnoreGrid = Input()->KeyIsPressed(KEY_LALT) || Input()->KeyIsPressed(KEY_RALT);
if(UI()->ActiveItem() == pID && s_CurQIndex == QIndex)
if(UI()->CheckActiveItem(pID) && s_CurQIndex == QIndex)
{
if(s_Operation == OP_MOVE)
{
@ -2479,7 +2479,7 @@ void CEditor::DoMapEditor(CUIRect View)
UI()->SetHotItem(s_pEditorID);
// do global operations like pan and zoom
if(UI()->ActiveItem() == 0 && (UI()->MouseButton(0) || UI()->MouseButton(2)))
if(UI()->CheckActiveItem(nullptr) && (UI()->MouseButton(0) || UI()->MouseButton(2)))
{
s_StartWx = wx;
s_StartWy = wy;
@ -2530,7 +2530,7 @@ void CEditor::DoMapEditor(CUIRect View)
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;
@ -2775,7 +2775,7 @@ void CEditor::DoMapEditor(CUIRect View)
}
// do panning
if(UI()->ActiveItem() == s_pEditorID)
if(UI()->CheckActiveItem(s_pEditorID))
{
if(s_Operation == OP_PAN_WORLD)
{
@ -2810,7 +2810,7 @@ void CEditor::DoMapEditor(CUIRect View)
m_WorldOffsetY += PanSpeed * m_WorldZoom;
}
}
else if(UI()->ActiveItem() == s_pEditorID)
else if(UI()->CheckActiveItem(s_pEditorID))
{
// release mouse
if(!UI()->MouseButton(0))
@ -5261,7 +5261,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
float ColorMod = 1.0f;
if(UI()->ActiveItem() == pID)
if(UI()->CheckActiveItem(pID))
{
if(!UI()->MouseButton(0))
{
@ -5355,7 +5355,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
pEnvelope->m_lPoints[i].m_aValues[c] = f2fx(str_tofloat(s_aStrCurValue));
}
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];
@ -6403,6 +6403,8 @@ void CEditor::UpdateAndRender()
m_AnimateTime = 0;
ms_pUiGotContext = 0;
UI()->StartCheck();
// handle mouse movement
float mx, my, Mwx, Mwy;
float rx = 0, ry = 0;
@ -6469,6 +6471,7 @@ void CEditor::UpdateAndRender()
m_ShowMousePointer = true;
}
UI()->FinishCheck();
Input()->Clear();
}

View file

@ -54,7 +54,7 @@ void CEditor::UiDoPopupMenu()
if(Inside)
m_MouseInsidePopup = true;
if(UI()->ActiveItem() == &s_UiPopups[i].m_pId)
if(UI()->CheckActiveItem(&s_UiPopups[i].m_pId))
{
if(!UI()->MouseButton(0))
{