diff options
26 files changed, 587 insertions, 708 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b0c4de9aa..fc898417d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1469,7 +1469,6 @@ if(CLIENT) components/menus_demo.cpp components/menus_ingame.cpp components/menus_listbox.cpp - components/menus_popups.cpp components/menus_scrollregion.cpp components/menus_settings.cpp components/menus_start.cpp diff --git a/src/base/system.c b/src/base/system.c index 091a11034..8857c5b0f 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -2761,20 +2761,17 @@ void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num) str_copy(dst, src, cursor < dst_size ? cursor+1 : dst_size); } -void str_utf8_stats(const char *str, int max_size, int *size, int *count) +void str_utf8_stats(const char *str, int max_size, int max_count, int *size, int *count) { *size = 0; *count = 0; - while(str[*size] && *size < max_size) + while(*size < max_size && *count < max_count) { int new_size = str_utf8_forward(str, *size); - if(new_size != *size) - { - if(new_size >= max_size) - break; - *size = new_size; - ++(*count); - } + if(new_size == *size || new_size >= max_size) + break; + *size = new_size; + ++(*count); } } diff --git a/src/base/system.h b/src/base/system.h index 1f5d7fd43..b8af722fe 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -1740,19 +1740,20 @@ void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num); /* Function: str_utf8_stats - Determines the byte size and utf8 character count of a string. + Determines the byte size and utf8 character count of a utf8 string. Parameters: str - Pointer to the string. max_size - Maximum number of bytes to count. + max_count - Maximum number of utf8 characters to count. size - Pointer to store size (number of non-zero bytes) of the string. count - Pointer to store count of utf8 characters of the string. Remarks: - - Assumes nothing about the encoding of the string. - It's the users responsibility to make sure the bounds are aligned. + - The string is treated as zero-terminated utf8 string. + - It's the user's responsibility to make sure the bounds are aligned. */ -void str_utf8_stats(const char *str, int max_size, int *size, int *count); +void str_utf8_stats(const char *str, int max_size, int max_count, int *size, int *count); /* Function: secure_random_init diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 80f6176de..369087d6d 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -683,9 +683,19 @@ static void StrVariableCommand(IConsole::IResult *pResult, void *pUserData) } } +void CConsole::TraverseChain(FCommandCallback *ppfnCallback, void **ppUserData) +{ + while(*ppfnCallback == Con_Chain) + { + CChain *pChainInfo = static_cast<CChain *>(*ppUserData); + *ppfnCallback = pChainInfo->m_pfnCallback; + *ppUserData = pChainInfo->m_pCallbackUserData; + } +} + void CConsole::Con_EvalIf(IResult *pResult, void *pUserData) { - CConsole* pConsole = static_cast<CConsole *>(pUserData); + CConsole *pConsole = static_cast<CConsole *>(pUserData); CCommand *pCommand = pConsole->FindCommand(pResult->GetString(0), pConsole->m_FlagMask); char aBuf[128]; if(!pCommand) @@ -694,16 +704,19 @@ void CConsole::Con_EvalIf(IResult *pResult, void *pUserData) pConsole->Print(OUTPUT_LEVEL_STANDARD, "console", aBuf); return; } + FCommandCallback pfnCallback = pCommand->m_pfnCallback; + void *pCallbackUserData = pCommand->m_pUserData; + pConsole->TraverseChain(&pfnCallback, &pCallbackUserData); CResult Result; - pCommand->m_pfnCallback(&Result, pCommand->m_pUserData); + pfnCallback(&Result, pCallbackUserData); bool Condition = false; - if(pCommand->m_pfnCallback == IntVariableCommand) + if(pfnCallback == IntVariableCommand) Condition = Result.m_Value == atoi(pResult->GetString(2)); else Condition = !str_comp_nocase(Result.m_aValue, pResult->GetString(2)); if(!str_comp(pResult->GetString(1), "!=")) Condition = !Condition; - else if(str_comp(pResult->GetString(1), "==") && pCommand->m_pfnCallback == StrVariableCommand) + else if(str_comp(pResult->GetString(1), "==") && pfnCallback == StrVariableCommand) pConsole->Print(OUTPUT_LEVEL_STANDARD, "console", "Error: invalid comperator for type string"); else if(!str_comp(pResult->GetString(1), ">")) Condition = Result.m_Value > atoi(pResult->GetString(2)); @@ -727,22 +740,14 @@ void CConsole::Con_EvalIf(IResult *pResult, void *pUserData) void CConsole::ConToggle(IConsole::IResult *pResult, void *pUser) { - CConsole* pConsole = static_cast<CConsole *>(pUser); + CConsole *pConsole = static_cast<CConsole *>(pUser); char aBuf[128] = {0}; CCommand *pCommand = pConsole->FindCommand(pResult->GetString(0), pConsole->m_FlagMask); if(pCommand) { FCommandCallback pfnCallback = pCommand->m_pfnCallback; void *pUserData = pCommand->m_pUserData; - - // check for chain - if(pCommand->m_pfnCallback == Con_Chain) - { - CChain *pChainInfo = static_cast<CChain *>(pCommand->m_pUserData); - pfnCallback = pChainInfo->m_pfnCallback; - pUserData = pChainInfo->m_pCallbackUserData; - } - + pConsole->TraverseChain(&pfnCallback, &pUserData); if(pfnCallback == IntVariableCommand) { CIntVariableData *pData = static_cast<CIntVariableData *>(pUserData); @@ -757,26 +762,20 @@ void CConsole::ConToggle(IConsole::IResult *pResult, void *pUser) else str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0)); - if(aBuf[0] != 0) + if(aBuf[0]) pConsole->Print(OUTPUT_LEVEL_STANDARD, "console", aBuf); } void CConsole::ConToggleStroke(IConsole::IResult *pResult, void *pUser) { - CConsole* pConsole = static_cast<CConsole *>(pUser); + CConsole *pConsole = static_cast<CConsole *>(pUser); char aBuf[128] = {0}; CCommand *pCommand = pConsole->FindCommand(pResult->GetString(1), pConsole->m_FlagMask); if(pCommand) { FCommandCallback pfnCallback = pCommand->m_pfnCallback; - - // check for chain - if(pCommand->m_pfnCallback == Con_Chain) - { - CChain *pChainInfo = static_cast<CChain *>(pCommand->m_pUserData); - pfnCallback = pChainInfo->m_pfnCallback; - } - + void *pUserData = pCommand->m_pUserData; + pConsole->TraverseChain(&pfnCallback, &pUserData); if(pfnCallback == IntVariableCommand) { int Val = pResult->GetInteger(0)==0 ? pResult->GetInteger(3) : pResult->GetInteger(2); @@ -790,7 +789,7 @@ void CConsole::ConToggleStroke(IConsole::IResult *pResult, void *pUser) else str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(1)); - if(aBuf[0] != 0) + if(aBuf[0]) pConsole->Print(OUTPUT_LEVEL_STANDARD, "console", aBuf); } @@ -834,8 +833,16 @@ CConsole::~CConsole() { CCommand *pNext = pCommand->m_pNext; - if(pCommand->m_pfnCallback == Con_Chain) - mem_free(static_cast<CChain *>(pCommand->m_pUserData)); + FCommandCallback pfnCallback = pCommand->m_pfnCallback; + void *pUserData = pCommand->m_pUserData; + while(pfnCallback == Con_Chain) + { + CChain *pChainInfo = static_cast<CChain *>(pUserData); + pfnCallback = pChainInfo->m_pfnCallback; + pUserData = pChainInfo->m_pCallbackUserData; + mem_free(pChainInfo); + } + mem_free(pCommand); pCommand = pNext; diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index 3ea9c429b..7976d72ed 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -54,6 +54,8 @@ class CConsole : public IConsole CCommand *m_pRecycleList; CHeap m_TempCommands; + void TraverseChain(FCommandCallback *ppfnCallback, void **ppUserData); + static void Con_Chain(IResult *pResult, void *pUserData); static void Con_Echo(IResult *pResult, void *pUserData); static void Con_Exec(IResult *pResult, void *pUserData); diff --git a/src/game/client/components/camera.cpp b/src/game/client/components/camera.cpp index 5a85bbe15..337fa8e7b 100644 --- a/src/game/client/components/camera.cpp +++ b/src/game/client/components/camera.cpp @@ -138,8 +138,12 @@ void CCamera::OnRender() void CCamera::ChangePosition(int PositionNumber) { + if(m_pClient->Client()->State() == IClient::STATE_ONLINE) + return; //Do not change Main Menu Camera Positions while we are changing settings in-game + if(PositionNumber < 0 || PositionNumber > NUM_POS-1) return; + m_AnimationStartPos = m_Center; m_RotationCenter = m_Positions[PositionNumber]; m_CurrentPosition = PositionNumber; diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index fe45c20d8..437dd0c79 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -612,10 +612,10 @@ void CHud::RenderVoting() m_pClient->m_pBinds->GetKey("vote no", aBufNo, sizeof(aBufNo)); str_format(aBuf, sizeof(aBuf), "%s - %s", aBufYes, Localize("Vote yes")); Base.y += Base.h+1; - UI()->DoLabel(&Base, aBuf, 6.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Base, aBuf, 6.0f, TEXTALIGN_LEFT); str_format(aBuf, sizeof(aBuf), "%s - %s", Localize("Vote no"), aBufNo); - UI()->DoLabel(&Base, aBuf, 6.0f, CUI::ALIGN_RIGHT); + UI()->DoLabel(&Base, aBuf, 6.0f, TEXTALIGN_RIGHT); } void CHud::RenderCursor() diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index d833c28f0..9ff9c514f 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -33,10 +33,8 @@ #include "menus.h" #include "skins.h" -float CMenus::ms_ListheaderHeight = CUI::ms_ListheaderHeight; float CMenus::ms_FontmodHeight = CUI::ms_FontmodHeight; -CMenus *CMenus::CUIElementBase::m_pMenus = 0; CRenderTools *CMenus::CUIElementBase::m_pRenderTools = 0; CUI *CMenus::CUIElementBase::m_pUI = 0; IInput *CMenus::CUIElementBase::m_pInput = 0; @@ -77,8 +75,6 @@ CMenus::CMenus() SetMenuPage(PAGE_START); m_MenuPageOld = PAGE_START; - m_PopupActive = false; - m_aDemoLoadingFile[0] = 0; m_DemoLoadingPopupRendered = false; @@ -185,7 +181,7 @@ bool CMenus::DoButton_Menu(CButtonContainer *pBC, const char *pText, bool Checke TextRender()->TextColor(1.0f-FadeVal, 1.0f-FadeVal, 1.0f-FadeVal, 1.0f); TextRender()->TextSecondaryColor(0.0f+FadeVal, 0.0f+FadeVal, 0.0f+FadeVal, 0.25f); } - UI()->DoLabel(&Text, pText, Text.h*ms_FontmodHeight, CUI::ALIGN_CENTER); + UI()->DoLabel(&Text, pText, Text.h*ms_FontmodHeight, TEXTALIGN_CENTER); if(TextFade) { TextRender()->TextColor(CUI::ms_DefaultTextColor); @@ -204,7 +200,7 @@ void CMenus::DoButton_KeySelect(CButtonContainer *pBC, const char *pText, const pRect->HMargin(1.0f, &Label); TextRender()->TextColor(1.0f-FadeVal, 1.0f-FadeVal, 1.0f-FadeVal, 1.0f); TextRender()->TextSecondaryColor(0.0f+FadeVal, 0.0f+FadeVal, 0.0f+FadeVal, 0.25f); - UI()->DoLabel(&Label, pText, Label.h*ms_FontmodHeight, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, pText, Label.h*ms_FontmodHeight, TEXTALIGN_CENTER); TextRender()->TextColor(CUI::ms_DefaultTextColor); TextRender()->TextSecondaryColor(CUI::ms_DefaultTextOutlineColor); } @@ -221,13 +217,13 @@ bool CMenus::DoButton_MenuTabTop(CButtonContainer *pBC, const char *pText, bool Label.HMargin((Label.h*FontFactor)/2.0f, &Label); TextRender()->TextColor(1.0f-FadeVal, 1.0f-FadeVal, 1.0f-FadeVal, FontAlpha); TextRender()->TextSecondaryColor(0.0f+FadeVal, 0.0f+FadeVal, 0.0f+FadeVal, 0.25f*FontAlpha); - UI()->DoLabel(&Label, pText, Label.h*ms_FontmodHeight, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, pText, Label.h*ms_FontmodHeight, TEXTALIGN_CENTER); TextRender()->TextColor(CUI::ms_DefaultTextColor); TextRender()->TextSecondaryColor(CUI::ms_DefaultTextOutlineColor); return UI()->DoButtonLogic(pBC, pRect); } -bool CMenus::DoButton_GridHeader(const void *pID, const char *pText, bool Checked, CUI::EAlignment Align, const CUIRect *pRect, int Corners) +bool CMenus::DoButton_GridHeader(const void *pID, const char *pText, bool Checked, int Align, const CUIRect *pRect, int Corners) { if(Checked) { @@ -286,7 +282,7 @@ bool CMenus::DoButton_CheckBox(const void *pID, const char *pText, bool Checked, Graphics()->QuadsEnd(); Label.y += 1.0f; // lame fix - UI()->DoLabel(&Label, pText, Label.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, pText, Label.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); if(Locked) { @@ -356,7 +352,7 @@ float CMenus::DoIndependentDropdownMenu(void *pID, const CUIRect *pRect, const c // label Label = Header; Label.y += 2.0f; - UI()->DoLabel(&Label, pStr, Header.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, pStr, Header.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); if(UI()->DoButtonLogic(pID, &Header)) *pActive ^= 1; @@ -380,10 +376,10 @@ void CMenus::DoInfoBox(const CUIRect *pRect, const char *pLabel, const char *pVa char aBuf[32]; str_format(aBuf, sizeof(aBuf), "%s:", pLabel); Label.y += 2.0f; - UI()->DoLabel(&Label, aBuf, pRect->h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, aBuf, pRect->h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Value.y += 2.0f; - UI()->DoLabel(&Value, pValue, pRect->h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Value, pValue, pRect->h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); } void CMenus::DoJoystickBar(const CUIRect *pRect, float Current, float Tolerance, bool Active) @@ -702,7 +698,7 @@ void CMenus::RenderMenubar(CUIRect Rect) Box.HMargin(2.0f, &Box); TextRender()->TextColor(CUI::ms_HighlightTextColor); TextRender()->TextSecondaryColor(CUI::ms_HighlightTextOutlineColor); - UI()->DoLabel(&Box, Localize("Demos"), Box.h*ms_FontmodHeight, CUI::ALIGN_CENTER); + UI()->DoLabel(&Box, Localize("Demos"), Box.h*ms_FontmodHeight, TEXTALIGN_CENTER); TextRender()->TextColor(CUI::ms_DefaultTextColor); TextRender()->TextSecondaryColor(CUI::ms_DefaultTextOutlineColor); } @@ -766,7 +762,7 @@ void CMenus::RenderLoading(int WorkedAmount) Rect.y += 20; TextRender()->TextColor(CUI::ms_DefaultTextColor); TextRender()->TextSecondaryColor(CUI::ms_DefaultTextOutlineColor); - UI()->DoLabel(&Rect, "Teeworlds", 48.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Rect, "Teeworlds", 48.0f, TEXTALIGN_CENTER); const float Percent = m_LoadCurrent/(float)m_LoadTotal; const float Spacing = 40.0f; @@ -786,7 +782,7 @@ void CMenus::RenderLoading(int WorkedAmount) } char aBuf[8]; str_format(aBuf, sizeof(aBuf), "%d%%", (int)(100*Percent)); - UI()->DoLabel(&FullBar, aBuf, 20.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&FullBar, aBuf, 20.0f, TEXTALIGN_CENTER); if(Percent > 0.5f) { @@ -1111,7 +1107,7 @@ void CMenus::RenderMenu(CUIRect Screen) Button.Draw(Color, 5.0f, CUIRect::CORNER_BL); // draw non-blending X - UI()->DoLabel(&Button, "\xE2\x9C\x95", Button.h*ms_FontmodHeight, CUI::ALIGN_CENTER); + UI()->DoLabel(&Button, "\xE2\x9C\x95", Button.h*ms_FontmodHeight, TEXTALIGN_CENTER); if(UI()->DoButtonLogic(&s_QuitButton, &Button)) m_Popup = POPUP_QUIT; @@ -1167,8 +1163,7 @@ void CMenus::RenderMenu(CUIRect Screen) } } - // do overlay popups - DoPopupMenu(); + UI()->RenderPopupMenus(); } else { @@ -1255,7 +1250,7 @@ void CMenus::RenderMenu(CUIRect Screen) CUIRect Part; Box.HSplitTop(ButtonHeight+5.0f, &Part, &Box); Part.y += 3.0f; - UI()->DoLabel(&Part, pTitle, Part.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Part, pTitle, Part.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); // inner box CUIRect BottomBar; @@ -1270,15 +1265,15 @@ void CMenus::RenderMenu(CUIRect Screen) if(m_pClient->Editor()->HasUnsavedData()) { Box.HSplitTop(12.0f, 0, &Part); - UI()->DoLabel(&Part, pExtraText, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Part, pExtraText, FontSize, TEXTALIGN_CENTER); Part.HSplitTop(20.0f, 0, &Part); Part.VMargin(5.0f, &Part); - UI()->DoLabel(&Part, Localize("There's an unsaved map in the editor, you might want to save it before you quit the game."), FontSize, CUI::ALIGN_LEFT, Part.w); + UI()->DoLabel(&Part, Localize("There's an unsaved map in the editor, you might want to save it before you quit the game."), FontSize, TEXTALIGN_LEFT, Part.w); } else { Box.HSplitTop(27.0f, 0, &Box); - UI()->DoLabel(&Box, pExtraText, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Box, pExtraText, FontSize, TEXTALIGN_CENTER); } // buttons @@ -1299,7 +1294,7 @@ void CMenus::RenderMenu(CUIRect Screen) CUIRect Label; Box.HSplitTop(20.0f, &Label, &Box); - UI()->DoLabel(&Label, pExtraText, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, pExtraText, FontSize, TEXTALIGN_CENTER); CUIRect EditBox; Box.HSplitTop(20.0f, &EditBox, &Box); @@ -1372,7 +1367,7 @@ void CMenus::RenderMenu(CUIRect Screen) Box.HSplitTop(15.f, 0, &Box); Box.HSplitTop(ButtonHeight, &Part, &Box); str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024, m_DownloadSpeed/1024.0f); - UI()->DoLabel(&Part, aBuf, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Part, aBuf, FontSize, TEXTALIGN_CENTER); // time left int SecondsLeft = maximum(1, m_DownloadSpeed > 0.0f ? static_cast<int>((Client()->MapDownloadTotalsize()-Client()->MapDownloadAmount())/m_DownloadSpeed) : 1); @@ -1387,7 +1382,7 @@ void CMenus::RenderMenu(CUIRect Screen) } Box.HSplitTop(SpacingH, 0, &Box); Box.HSplitTop(ButtonHeight, &Part, &Box); - UI()->DoLabel(&Part, aBuf, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Part, aBuf, FontSize, TEXTALIGN_CENTER); // progress bar Box.HSplitTop(SpacingH, 0, &Box); @@ -1400,7 +1395,7 @@ void CMenus::RenderMenu(CUIRect Screen) else { Box.HSplitTop(27.0f, 0, &Box); - UI()->DoLabel(&Box, Client()->ServerAddress(), FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Box, Client()->ServerAddress(), FontSize, TEXTALIGN_CENTER); } } else if(m_Popup == POPUP_LOADING_DEMO) @@ -1417,7 +1412,7 @@ void CMenus::RenderMenu(CUIRect Screen) else { Box.HSplitTop(27.0f, 0, &Box); - UI()->DoLabel(&Box, m_aDemoLoadingFile, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Box, m_aDemoLoadingFile, FontSize, TEXTALIGN_CENTER); // wait until next frame to load the demo m_DemoLoadingPopupRendered = true; } @@ -1467,7 +1462,7 @@ void CMenus::RenderMenu(CUIRect Screen) TextRender()->TextColor(CUI::ms_HighlightTextColor); TextRender()->TextSecondaryColor(CUI::ms_HighlightTextOutlineColor); } - UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, TEXTALIGN_CENTER); if(i == OldSelected) { TextRender()->TextColor(CUI::ms_DefaultTextColor); @@ -1501,7 +1496,7 @@ void CMenus::RenderMenu(CUIRect Screen) { Box.HSplitTop(27.0f, 0, &Box); Box.VMargin(10.0f, &Box); - UI()->DoLabel(&Box, pExtraText, FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Box, pExtraText, FontSize, TEXTALIGN_LEFT); CUIRect EditBox; Box.HSplitBottom(Box.h/2.0f, 0, &Box); @@ -1550,7 +1545,7 @@ void CMenus::RenderMenu(CUIRect Screen) { Box.HSplitTop(24.0f, 0, &Box); Box.VMargin(10.0f, &Part); - UI()->DoLabel(&Part, pExtraText, FontSize, CUI::ALIGN_LEFT, Box.w-20.0f); + UI()->DoLabel(&Part, pExtraText, FontSize, TEXTALIGN_LEFT, Box.w-20.0f); CUIRect EditBox; Box.HSplitBottom(Box.h/2.0f, 0, &Box); @@ -1582,7 +1577,7 @@ void CMenus::RenderMenu(CUIRect Screen) { Box.HSplitTop(20.0f, 0, &Box); Box.VMargin(10.0f, &Part); - UI()->DoLabel(&Part, pExtraText, FontSize, CUI::ALIGN_LEFT, Box.w-20.0f); + UI()->DoLabel(&Part, pExtraText, FontSize, TEXTALIGN_LEFT, Box.w-20.0f); CUIRect EditBox; Box.HSplitBottom(ButtonHeight*2.0f, 0, &Box); @@ -1606,7 +1601,7 @@ void CMenus::RenderMenu(CUIRect Screen) // message Box.HSplitTop(27.0f, 0, &Box); Box.VMargin(5.0f, &Part); - UI()->DoLabel(&Part, pExtraText, FontSize, CUI::ALIGN_LEFT, Part.w); + UI()->DoLabel(&Part, pExtraText, FontSize, TEXTALIGN_LEFT, Part.w); if(m_Popup == POPUP_MESSAGE) { @@ -1827,7 +1822,7 @@ void CMenus::OnRender() bool CMenus::CheckHotKey(int Key) const { - return !m_KeyReaderIsActive && !m_KeyReaderWasActive && !UI()->IsInputActive() && !m_PopupActive + return !m_KeyReaderIsActive && !m_KeyReaderWasActive && !UI()->IsInputActive() && !UI()->IsPopupActive() && !Input()->KeyIsPressed(KEY_LSHIFT) && !Input()->KeyIsPressed(KEY_RSHIFT) && !Input()->KeyIsPressed(KEY_LCTRL) && !Input()->KeyIsPressed(KEY_RCTRL) && !Input()->KeyIsPressed(KEY_LALT) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 3e8c5bdf7..5ab6ea302 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -38,7 +38,6 @@ public: class CUIElementBase { protected: - static CMenus *m_pMenus; // TODO: Refactor in order to remove this reference to menus static CRenderTools *m_pRenderTools; static CUI *m_pUI; static IInput *m_pInput; @@ -46,7 +45,7 @@ public: static CConfig *m_pConfig; public: - static void Init(CMenus *pMenus) { m_pMenus = pMenus; m_pRenderTools = pMenus->RenderTools(); m_pUI = pMenus->UI(); m_pInput = pMenus->Input(); m_pClient = pMenus->Client(); m_pConfig = pMenus->Config(); } + static void Init(CMenus *pMenus) { m_pRenderTools = pMenus->RenderTools(); m_pUI = pMenus->UI(); m_pInput = pMenus->Input(); m_pClient = pMenus->Client(); m_pConfig = pMenus->Config(); } }; class CButtonContainer : public CUIElementBase @@ -70,7 +69,7 @@ private: bool DoButton_CheckBox(const void *pID, const char *pText, bool Checked, const CUIRect *pRect, bool Locked = false); void DoIcon(int ImageId, int SpriteId, const CUIRect *pRect, const vec4 *pColor = 0); - bool DoButton_GridHeader(const void *pID, const char *pText, bool Checked, CUI::EAlignment Align, const CUIRect *pRect, int Corners = CUIRect::CORNER_ALL); + bool DoButton_GridHeader(const void *pID, const char *pText, bool Checked, int Align, const CUIRect *pRect, int Corners = CUIRect::CORNER_ALL); float DoIndependentDropdownMenu(void *pID, const CUIRect *pRect, const char *pStr, float HeaderHeight, FDropdownCallback pfnCallback, bool *pActive); void DoInfoBox(const CUIRect *pRect, const char *pLable, const char *pValue); @@ -279,7 +278,6 @@ private: bool m_MenuActive; vec2 m_MousePos; vec2 m_PrevMousePos; - bool m_PopupActive; int m_ActiveListBox; int m_PopupCountrySelection; bool m_SkinModified; @@ -365,7 +363,6 @@ private: int64 m_LastInput; - static float ms_ListheaderHeight; static float ms_FontmodHeight; // for settings @@ -593,7 +590,7 @@ private: int m_Flags; CUIRect m_Rect; CUIRect m_Spacer; - CUI::EAlignment m_Align; + int m_Align; }; enum @@ -631,17 +628,17 @@ private: static CColumn ms_aBrowserCols[NUM_BROWSER_COLS]; static CColumn ms_aDemoCols[NUM_DEMO_COLS]; - CBrowserFilter* GetSelectedBrowserFilter() + CBrowserFilter *GetSelectedBrowserFilter() { const int Tab = ServerBrowser()->GetType(); - if(m_aSelectedFilters[Tab] == -1) + if(m_aSelectedFilters[Tab] < 0 || m_aSelectedFilters[Tab] >= m_lFilters.size()) return 0; return &m_lFilters[m_aSelectedFilters[Tab]]; } - const CServerInfo* GetSelectedServerInfo() + const CServerInfo *GetSelectedServerInfo() { - CBrowserFilter* pSelectedFilter = GetSelectedBrowserFilter(); + CBrowserFilter *pSelectedFilter = GetSelectedBrowserFilter(); if(!pSelectedFilter) return 0; const int Tab = ServerBrowser()->GetType(); @@ -680,8 +677,6 @@ private: void RenderMenubar(CUIRect r); void RenderNews(CUIRect MainView); void RenderBackButton(CUIRect MainView); - inline float GetListHeaderHeight() const { return ms_ListheaderHeight + (Config()->m_UiWideview ? 3.0f : 0.0f); } - inline float GetListHeaderHeightFactor() const { return 1.0f + (Config()->m_UiWideview ? (3.0f/ms_ListheaderHeight) : 0.0f); } static void ConchainUpdateMusicState(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); void UpdateMusicState(); @@ -772,9 +767,6 @@ private: void SetActive(bool Active); - void InvokePopupMenu(void *pID, int Flags, float X, float Y, float W, float H, int (*pfnFunc)(CMenus *pMenu, CUIRect Rect), void *pExtra=0); - void DoPopupMenu(); - // loading int m_LoadCurrent; int m_LoadTotal; diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 8231ef856..976494b52 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -25,12 +25,12 @@ #include "menus.h" CMenus::CColumn CMenus::ms_aBrowserCols[] = { // Localize("Server"); Localize("Type"); Localize("Map"); Localize("Players"); Localize("Ping"); - these strings are localized within CLocConstString - {COL_BROWSER_FLAG, -1, " ", -1, 4*16.0f+3*2.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, - {COL_BROWSER_NAME, IServerBrowser::SORT_NAME, "Server", 0, 310.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, - {COL_BROWSER_GAMETYPE, IServerBrowser::SORT_GAMETYPE, "Type", 1, 70.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, - {COL_BROWSER_MAP, IServerBrowser::SORT_MAP, "Map", 1, 100.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, - {COL_BROWSER_PLAYERS, IServerBrowser::SORT_NUMPLAYERS, "Players", 1, 50.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, - {COL_BROWSER_PING, IServerBrowser::SORT_PING, "Ping", 1, 40.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, + {COL_BROWSER_FLAG, -1, " ", -1, 4*16.0f+3*2.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, + {COL_BROWSER_NAME, IServerBrowser::SORT_NAME, "Server", 0, 310.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, + {COL_BROWSER_GAMETYPE, IServerBrowser::SORT_GAMETYPE, "Type", 1, 70.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, + {COL_BROWSER_MAP, IServerBrowser::SORT_MAP, "Map", 1, 100.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, + {COL_BROWSER_PLAYERS, IServerBrowser::SORT_NUMPLAYERS, "Players", 1, 50.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, + {COL_BROWSER_PING, IServerBrowser::SORT_PING, "Ping", 1, 40.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, }; CServerFilterInfo CMenus::CBrowserFilter::ms_FilterStandard = {IServerBrowser::FILTER_COMPAT_VERSION|IServerBrowser::FILTER_PURE|IServerBrowser::FILTER_PURE_MAP, 999, -1, 0, {{0}}, {0}}; @@ -408,7 +408,12 @@ void CMenus::InitDefaultFilters() m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_ALL, Localize("All"), ServerBrowser())); // expand the all filter tab by default if(UseDefaultFilters) - m_lFilters[m_lFilters.size()-1].Switch(); + { + const int AllFilterIndex = m_lFilters.size()-1; + for(unsigned i = 0; i < IServerBrowser::NUM_TYPES; ++i) + m_aSelectedFilters[i] = AllFilterIndex; // default to "all" if not set + m_lFilters[AllFilterIndex].Switch(); + } } // 1 = browser entry click, 2 = server info click @@ -565,7 +570,7 @@ int CMenus::DoBrowserEntry(const void *pID, CUIRect View, const CServerInfo *pEn Button.x += s_RenderOffset; if(!Num) TextRender()->TextColor(CUI::ms_TransparentTextColor); - UI()->DoLabel(&Button, aTemp, FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, aTemp, FontSize, TEXTALIGN_LEFT); Button.x += TextRender()->TextWidth(FontSize, aTemp, -1); } else if(ID == COL_BROWSER_PING) @@ -604,7 +609,7 @@ int CMenus::DoBrowserEntry(const void *pID, CUIRect View, const CServerInfo *pEn TextRender()->TextSecondaryColor(TextBaseOutlineColor); Button.y += (Button.h - FontSize/ms_FontmodHeight)/2.0f; Button.w -= 4.0f; - UI()->DoLabel(&Button, aTemp, FontSize, CUI::ALIGN_RIGHT); + UI()->DoLabel(&Button, aTemp, FontSize, TEXTALIGN_RIGHT); } else if(ID == COL_BROWSER_GAMETYPE) { @@ -668,12 +673,12 @@ void CMenus::RenderFilterHeader(CUIRect View, int FilterIndex) View.VSplitLeft(20.0f, 0, &View); // little space View.y += 2.0f; - UI()->DoLabel(&View, pFilter->Name(), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&View, pFilter->Name(), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); View.VSplitRight(20.0f, &View, 0); // little space char aBuf[128]; str_format(aBuf, sizeof(aBuf), Localize("%d servers, %d players"), pFilter->NumSortedServers(), pFilter->NumPlayers()); - UI()->DoLabel(&View, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_RIGHT); + UI()->DoLabel(&View, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_RIGHT); EditButtons.VSplitRight(ButtonHeight, &EditButtons, &Button); Button.Margin(2.0f, &Button); @@ -767,8 +772,8 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) const float SpacingH = 2.0f; const float ButtonHeight = 20.0f; - const float HeaderHeight = GetListHeaderHeight(); - const float HeightFactor = GetListHeaderHeightFactor(); + const float HeaderHeight = UI()->GetListHeaderHeight(); + const float HeightFactor = UI()->GetListHeaderHeightFactor(); // background View.Draw(vec4(0.0f, 0.0f, 0.0f, Config()->m_ClMenuAlpha/100.0f), 5.0f, (Client()->State() == IClient::STATE_OFFLINE) ? CUIRect::CORNER_ALL : CUIRect::CORNER_B|CUIRect::CORNER_TR); @@ -1116,7 +1121,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) if(pImportantMessage) { MsgBox.y += MsgBox.h/3.0f; - UI()->DoLabel(&MsgBox, pImportantMessage, 16.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&MsgBox, pImportantMessage, 16.0f, TEXTALIGN_CENTER); } } } @@ -1138,7 +1143,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) Label.VSplitLeft(2.0f, 0, &Label); Label.VSplitRight(ButtonWidth*2.0f+SpacingH, &Label, &EditBox); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Search:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, Localize("Search:"), FontSize, TEXTALIGN_LEFT); EditBox.VSplitRight(EditBox.h, &EditBox, &Button); static CLineInput s_FilterInput(Config()->m_BrFilterString, sizeof(Config()->m_BrFilterString)); if(UI()->DoEditBox(&s_FilterInput, &EditBox, FontSize, false, CUIRect::CORNER_L)) @@ -1163,7 +1168,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) Label.VSplitLeft(2.0f, 0, &Label); Label.VSplitRight(ButtonWidth*2.0f+SpacingH, &Label, &EditBox); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Host address:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, Localize("Host address:"), FontSize, TEXTALIGN_LEFT); if(BrowserType == IServerBrowser::TYPE_INTERNET) { @@ -1189,7 +1194,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) Status.HSplitTop(ButtonHeight + SpacingH, 0, &Status); str_format(aBuf, sizeof(aBuf), Localize("%d%% loaded"), ServerBrowser()->LoadingProgression()); Status.y += 2.0f; - UI()->DoLabel(&Status, aBuf, 14.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Status, aBuf, 14.0f, TEXTALIGN_CENTER); } else { @@ -1221,14 +1226,14 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) str_format(aBuf, sizeof(aBuf), Localize("%d servers"), ServerBrowser()->NumServers()); Label.y += 2.0f; Label.x += OffsetServer; - UI()->DoLabel(&Label, aBuf, 14.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, 14.0f, TEXTALIGN_LEFT); Status.HSplitTop(SpacingH, 0, &Status); Status.HSplitTop(ButtonHeight, &Label, 0); str_format(aBuf, sizeof(aBuf), Localize("%d players"), NumPlayers); Label.y += 2.0f; Label.x += OffsetPlayer; - UI()->DoLabel(&Label, aBuf, 14.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, 14.0f, TEXTALIGN_LEFT); } } @@ -1252,7 +1257,7 @@ void CMenus::RenderServerbrowserSidebar(CUIRect View) } // header - View.HSplitTop(GetListHeaderHeight(), &Header, &View); + View.HSplitTop(UI()->GetListHeaderHeight(), &Header, &View); float Width = Header.w; Header.VSplitLeft(Width*0.30f, &Button, &Header); static CButtonContainer s_TabInfo; @@ -1293,7 +1298,7 @@ void CMenus::RenderServerbrowserFriendTab(CUIRect View) const float FontSize = 10.0f; static bool s_ListExtended[NUM_FRIEND_TYPES] = { 1, 1, 0 }; static vec3 s_ListColor[NUM_FRIEND_TYPES] = { vec3(0.5f, 1.0f, 0.5f), vec3(0.4f, 0.4f, 1.0f), vec3(1.0f, 0.5f, 0.5f) }; - const float HeaderHeight = GetListHeaderHeight(); + const float HeaderHeight = UI()->GetListHeaderHeight(); const float SpacingH = 2.0f; View.HSplitBottom(3*HeaderHeight+2*SpacingH, &View, &BottomArea); @@ -1395,11 +1400,11 @@ void CMenus::RenderServerbrowserFriendTab(CUIRect View) // name Rect.HSplitTop(10.0f, &Button, &Rect); Button.VSplitLeft(2.0f, 0, &Button); - UI()->DoLabel(&Button, m_lFriendList[i][f].m_aName, FontSize - 2, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, m_lFriendList[i][f].m_aName, FontSize - 2, TEXTALIGN_LEFT); // clan Rect.HSplitTop(10.0f, &Button, &Rect); Button.VSplitLeft(2.0f, 0, &Button); - UI()->DoLabel(&Button, m_lFriendList[i][f].m_aClan, FontSize - 2, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, m_lFriendList[i][f].m_aClan, FontSize - 2, TEXTALIGN_LEFT); // info if(m_lFriendList[i][f].m_pServerInfo) { @@ -1410,7 +1415,7 @@ void CMenus::RenderServerbrowserFriendTab(CUIRect View) else str_format(aBuf, sizeof(aBuf), Localize("Watching '%s' on '%s'", "Watching '(gametype)' on '(map)'"), m_lFriendList[i][f].m_pServerInfo->m_aGameType, m_lFriendList[i][f].m_pServerInfo->m_aMap); Button.HMargin(2.0f, &Button); - UI()->DoLabel(&Button, aBuf, FontSize - 2, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, aBuf, FontSize - 2, TEXTALIGN_LEFT); } // delete button Icon.HSplitTop(14.0f, &Rect, 0); @@ -1454,7 +1459,7 @@ void CMenus::RenderServerbrowserFriendTab(CUIRect View) case 2: str_format(aBuf, sizeof(aBuf), Localize("Offline (%d)", "friends (server browser)"), ListSize); break; } Label.HMargin(2.0f, &Label); - UI()->DoLabel(&Label, aBuf, FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, FontSize, TEXTALIGN_LEFT); static int s_HeaderButton[NUM_FRIEND_TYPES] = { 0 }; if(UI()->DoButtonLogic(&s_HeaderButton[i], &Header)) { @@ -1467,7 +1472,7 @@ void CMenus::RenderServerbrowserFriendTab(CUIRect View) BottomArea.HSplitTop(HeaderHeight, &Button, &BottomArea); BottomArea.HSplitTop(SpacingH, 0, &BottomArea); Button.VSplitLeft(50.0f, &Label, &Button); - UI()->DoLabel(&Label, Localize("Name"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, Localize("Name"), FontSize, TEXTALIGN_LEFT); static char s_aName[MAX_NAME_ARRAY_SIZE] = { 0 }; static CLineInput s_NameInput(s_aName, sizeof(s_aName), MAX_NAME_LENGTH); UI()->DoEditBox(&s_NameInput, &Button, Button.h*ms_FontmodHeight*0.8f); @@ -1475,7 +1480,7 @@ void CMenus::RenderServerbrowserFriendTab(CUIRect View) BottomArea.HSplitTop(HeaderHeight, &Button, &BottomArea); BottomArea.HSplitTop(SpacingH, 0, &BottomArea); Button.VSplitLeft(50.0f, &Label, &Button); - UI()->DoLabel(&Label, Localize("Clan"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, Localize("Clan"), FontSize, TEXTALIGN_LEFT); static char s_aClan[MAX_CLAN_ARRAY_SIZE] = { 0 }; static CLineInput s_ClanInput(s_aClan, sizeof(s_aClan), MAX_CLAN_LENGTH); UI()->DoEditBox(&s_ClanInput, &Button, Button.h*ms_FontmodHeight*0.8f); @@ -1488,7 +1493,7 @@ void CMenus::RenderServerbrowserFriendTab(CUIRect View) Label = Button; Label.HMargin(2.0f, &Label); const char *pButtonText = (!s_aName[0] && !s_aClan[0]) ? Localize("Add friend/clan") : s_aName[0] ? Localize("Add friend") : Localize("Add clan"); - UI()->DoLabel(&Label, pButtonText, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, pButtonText, FontSize, TEXTALIGN_CENTER); if(s_aName[0] || s_aClan[0]) DoIcon(IMAGE_FRIENDICONS, UI()->MouseHovered(&Button) ? SPRITE_FRIEND_PLUS_A : SPRITE_FRIEND_PLUS_B, &Icon); static CButtonContainer s_AddFriend; @@ -1536,7 +1541,7 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) Button.Draw(vec4(1.0f, 1.0f, 1.0f, 0.25f), 5.0f, CUIRect::CORNER_R); Button.VSplitLeft(Button.h, &Icon, &Label); Label.HMargin(2.0f, &Label); - UI()->DoLabel(&Label, Localize("New filter"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, Localize("New filter"), FontSize, TEXTALIGN_LEFT); if(s_aFilterName[0]) { DoIcon(IMAGE_FRIENDICONS, UI()->MouseHovered(&Button) ? SPRITE_FRIEND_PLUS_A : SPRITE_FRIEND_PLUS_B, &Icon); @@ -1558,11 +1563,11 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) pFilter->GetFilter(&FilterInfo); // server filter - ServerFilter.HSplitTop(GetListHeaderHeight(), &FilterHeader, &ServerFilter); + ServerFilter.HSplitTop(UI()->GetListHeaderHeight(), &FilterHeader, &ServerFilter); FilterHeader.Draw(vec4(1, 1, 1, 0.25f), 4.0f, CUIRect::CORNER_T); ServerFilter.Draw(vec4(0, 0, 0, 0.15f), 4.0f, CUIRect::CORNER_B); FilterHeader.HMargin(2.0f, &FilterHeader); - UI()->DoLabel(&FilterHeader, Localize("Server filter"), FontSize + 2.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&FilterHeader, Localize("Server filter"), FontSize + 2.0f, TEXTALIGN_CENTER); int NewSortHash = FilterInfo.m_SortHash; ServerFilter.HSplitTop(LineSize, &Button, &ServerFilter); @@ -1622,7 +1627,7 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) { ServerFilter.HSplitTop(5.0f, 0, &ServerFilter); ServerFilter.HSplitTop(LineSize, &Button, &ServerFilter); - UI()->DoLabel(&Button, Localize("Game types:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, Localize("Game types:"), FontSize, TEXTALIGN_LEFT); ServerFilter.HSplitTop(LineSize, &Button, &ServerFilter); Button.Draw(vec4(0.0, 0.0, 0.0, 0.25f), 2.0f); @@ -1651,7 +1656,7 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) Button.VSplitLeft(ItemLength, &FilterItem, &Button); FilterItem.Draw(FilterInfo.m_aGametypeExclusive[i] ? vec4(0.75f, 0.25f, 0.25f, 0.25f) : vec4(0.25f, 0.75f, 0.25f, 0.25f), 3.0f); FilterItem.VSplitLeft(Spacing, 0, &FilterItem); - UI()->DoLabel(&FilterItem, FilterInfo.m_aGametype[i], FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&FilterItem, FilterInfo.m_aGametype[i], FontSize, TEXTALIGN_LEFT); FilterItem.VSplitRight(IconWidth, 0, &FilterItem); DoIcon(IMAGE_TOOLICONS, UI()->MouseHovered(&FilterItem) ? SPRITE_TOOL_X_A : SPRITE_TOOL_X_B, &FilterItem); if(UI()->DoButtonLogic(&FilterInfo.m_aGametype[i], &FilterItem)) @@ -1754,7 +1759,7 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%s %d", Localize("Maximum ping:"), Value); - UI()->DoLabel(&Button, aBuf, FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, aBuf, FontSize, TEXTALIGN_LEFT); ServerFilter.HSplitTop(LineSize, &Button, &ServerFilter); @@ -1772,7 +1777,7 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) // server address ServerFilter.HSplitTop(3.0f, 0, &ServerFilter); ServerFilter.HSplitTop(LineSize, &Button, &ServerFilter); - UI()->DoLabel(&Button, Localize("Server address:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, Localize("Server address:"), FontSize, TEXTALIGN_LEFT); Button.VSplitRight(60.0f, 0, &Button); static char s_aAddressFilter[sizeof(FilterInfo.m_aAddress)]; static CLineInput s_AddressInput(s_aAddressFilter, sizeof(s_aAddressFilter)); @@ -1787,7 +1792,7 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) CUIRect Rect; ServerFilter.HSplitTop(3.0f, 0, &ServerFilter); ServerFilter.HSplitTop(LineSize, &Button, &ServerFilter); - UI()->DoLabel(&Button, Localize("Flag:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, Localize("Flag:"), FontSize, TEXTALIGN_LEFT); Button.VSplitRight(60.0f, 0, &Rect); Rect.VSplitLeft(16.0f, &Button, &Rect); static int s_BrFilterCountry = 0; @@ -1808,7 +1813,7 @@ void CMenus::RenderServerbrowserFilterTab(CUIRect View) // level ServerFilter.HSplitTop(5.0f, 0, &ServerFilter); ServerFilter.HSplitTop(LineSize + 2, &Button, &ServerFilter); - UI()->DoLabel(&Button, Localize("Difficulty:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, Localize("Difficulty:"), FontSize, TEXTALIGN_LEFT); Button.VSplitRight(60.0f, 0, &Button); Button.y -= 2.0f; Button.VSplitLeft(Button.h, &Icon, &Button); @@ -1873,11 +1878,11 @@ void CMenus::RenderDetailInfo(CUIRect View, const CServerInfo *pInfo, const vec4 TextRender()->TextSecondaryColor(TextOutlineColor); CUIRect ServerHeader; - View.HSplitTop(GetListHeaderHeight(), &ServerHeader, &View); + View.HSplitTop(UI()->GetListHeaderHeight(), &ServerHeader, &View); ServerHeader.Draw(vec4(1, 1, 1, 0.25f), 5.0f, CUIRect::CORNER_T); View.Draw(vec4(0, 0, 0, 0.15f), 5.0f, CUIRect::CORNER_B); ServerHeader.HMargin(2.0f, &ServerHeader); - UI()->DoLabel(&ServerHeader, Localize("Server details"), FontSize + 2.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&ServerHeader, Localize("Server details"), FontSize + 2.0f, TEXTALIGN_CENTER); if(!pInfo) return; @@ -1905,12 +1910,12 @@ void CMenus::RenderDetailInfo(CUIRect View, const CServerInfo *pInfo, const vec4 for(unsigned int i = 0; i < sizeof(s_aLabels) / sizeof(s_aLabels[0]); i++) { LeftColumn.HSplitTop(RowHeight, &Row, &LeftColumn); - UI()->DoLabel(&Row, s_aLabels[i], FontSize, CUI::ALIGN_LEFT, Row.w, false); + UI()->DoLabel(&Row, s_aLabels[i], FontSize, TEXTALIGN_LEFT, Row.w, false); } // map RightColumn.HSplitTop(RowHeight, &Row, &RightColumn); - UI()->DoLabel(&Row, pInfo->m_aMap, FontSize, CUI::ALIGN_LEFT, Row.w, false); + UI()->DoLabel(&Row, pInfo->m_aMap, FontSize, TEXTALIGN_LEFT, Row.w, false); // game type RightColumn.HSplitTop(RowHeight, &Row, &RightColumn); @@ -1918,18 +1923,18 @@ void CMenus::RenderDetailInfo(CUIRect View, const CServerInfo *pInfo, const vec4 Row.VSplitLeft(Row.h, &Icon, &Row); Icon.y -= 2.0f; DoGameIcon(pInfo->m_aGameType, &Icon); - UI()->DoLabel(&Row, pInfo->m_aGameType, FontSize, CUI::ALIGN_LEFT, Row.w, false); + UI()->DoLabel(&Row, pInfo->m_aGameType, FontSize, TEXTALIGN_LEFT, Row.w, false); // version RightColumn.HSplitTop(RowHeight, &Row, &RightColumn); - UI()->DoLabel(&Row, pInfo->m_aVersion, FontSize, CUI::ALIGN_LEFT, Row.w, false); + UI()->DoLabel(&Row, pInfo->m_aVersion, FontSize, TEXTALIGN_LEFT, Row.w, false); // difficulty RightColumn.HSplitTop(RowHeight, &Row, &RightColumn); Row.VSplitLeft(Row.h, &Icon, &Row); Icon.y -= 2.0f; DoIcon(IMAGE_LEVELICONS, s_aDifficultySpriteIds[pInfo->m_ServerLevel], &Icon); - UI()->DoLabel(&Row, s_aDifficultyLabels[pInfo->m_ServerLevel], FontSize, CUI::ALIGN_LEFT, Row.w, false); + UI()->DoLabel(&Row, s_aDifficultyLabels[pInfo->m_ServerLevel], FontSize, TEXTALIGN_LEFT, Row.w, false); } void CMenus::RenderDetailScoreboard(CUIRect View, const CServerInfo *pInfo, int RowCount, const vec4 &TextColor, const vec4 &TextOutlineColor) @@ -2036,7 +2041,7 @@ void CMenus::RenderDetailScoreboard(CUIRect View, const CServerInfo *pInfo, int Score.y += (Score.h - FontSize/ms_FontmodHeight)/2.0f; char aTemp[16]; FormatScore(aTemp, sizeof(aTemp), pInfo->m_Flags&IServerBrowser::FLAG_TIMESCORE, &pInfo->m_aClients[i]); - UI()->DoLabel(&Score, aTemp, FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Score, aTemp, FontSize, TEXTALIGN_LEFT); } // name @@ -2066,10 +2071,10 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View, const CServerInfo *pI RenderDetailInfo(ServerDetails, pInfo, CUI::ms_DefaultTextColor, CUI::ms_DefaultTextOutlineColor); // server scoreboard - ServerScoreboard.HSplitTop(GetListHeaderHeight(), &ServerHeader, &ServerScoreboard); + ServerScoreboard.HSplitTop(UI()->GetListHeaderHeight(), &ServerHeader, &ServerScoreboard); ServerHeader.Draw(vec4(1, 1, 1, 0.25f), 4.0f, CUIRect::CORNER_T); ServerHeader.HMargin(2.0f, &ServerHeader); - UI()->DoLabel(&ServerHeader, Localize("Scoreboard"), 12.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&ServerHeader, Localize("Scoreboard"), 12.0f, TEXTALIGN_CENTER); RenderDetailScoreboard(ServerScoreboard, pInfo, 0, CUI::ms_DefaultTextColor, CUI::ms_DefaultTextOutlineColor); } diff --git a/src/game/client/components/menus_callback.cpp b/src/game/client/components/menus_callback.cpp index 0897cfa8f..6522afd58 100644 --- a/src/game/client/components/menus_callback.cpp +++ b/src/game/client/components/menus_callback.cpp @@ -82,7 +82,7 @@ void CMenus::DoSettingsControlsButtons(int Start, int Stop, CUIRect View, float str_format(aBuf, sizeof(aBuf), "%s:", (const char *)Key.m_Name); Label.y += 2.0f; - UI()->DoLabel(&Label, aBuf, 13.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, aBuf, 13.0f, TEXTALIGN_CENTER); int OldId = Key.m_KeyId, OldModifier = Key.m_Modifier, NewModifier; int NewId = DoKeyReader(&gs_aKeys[i].m_BC, &Button, OldId, OldModifier, &NewModifier); if(NewId != OldId || NewModifier != OldModifier) @@ -242,7 +242,7 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View) { View.HSplitTop((View.h-ButtonHeight)/2.0f, 0, &View); View.HSplitTop(ButtonHeight, &Button, &View); - m_pClient->UI()->DoLabel(&Button, Localize("No joysticks found. Plug in a joystick and restart the game."), 13.0f, CUI::ALIGN_CENTER); + m_pClient->UI()->DoLabel(&Button, Localize("No joysticks found. Plug in a joystick and restart the game."), 13.0f, TEXTALIGN_CENTER); } } @@ -396,13 +396,13 @@ void CMenus::DoJoystickAxisPicker(CUIRect View) View.HSplitTop(Spacing, 0, &View); View.HSplitTop(ButtonHeight, &Row, &View); Row.VSplitLeft(StatusWidth, &Button, &Row); - m_pClient->UI()->DoLabel(&Button, Localize("Device"), 13.0f, CUI::ALIGN_CENTER); + m_pClient->UI()->DoLabel(&Button, Localize("Device"), 13.0f, TEXTALIGN_CENTER); Row.VSplitLeft(StatusMargin, 0, &Row); Row.VSplitLeft(StatusWidth, &Button, &Row); - m_pClient->UI()->DoLabel(&Button, Localize("Status"), 13.0f, CUI::ALIGN_CENTER); + m_pClient->UI()->DoLabel(&Button, Localize("Status"), 13.0f, TEXTALIGN_CENTER); Row.VSplitLeft(2*StatusMargin, 0, &Row); Row.VSplitLeft(2*BindWidth, &Button, &Row); - m_pClient->UI()->DoLabel(&Button, Localize("Aim bind"), 13.0f, CUI::ALIGN_CENTER); + m_pClient->UI()->DoLabel(&Button, Localize("Aim bind"), 13.0f, TEXTALIGN_CENTER); static int s_aActive[g_MaxJoystickAxes][2]; for(int i = 0; i < minimum(m_pClient->Input()->GetJoystickNumAxes(), g_MaxJoystickAxes); i++) @@ -421,7 +421,7 @@ void CMenus::DoJoystickAxisPicker(CUIRect View) m_pClient->TextRender()->TextColor(0.7f, 0.7f, 0.7f, 1.0f); else m_pClient->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); - m_pClient->UI()->DoLabel(&Button, aBuf, 13.0f, CUI::ALIGN_CENTER); + m_pClient->UI()->DoLabel(&Button, aBuf, 13.0f, TEXTALIGN_CENTER); // Device status Row.VSplitLeft(StatusMargin, 0, &Row); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index e4d88bf77..1064a1075 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -21,9 +21,9 @@ #include "menus.h" CMenus::CColumn CMenus::ms_aDemoCols[] = { // Localize("Name"); Localize("Length"); Localize("Date"); - these strings are localized within CLocConstString - {COL_DEMO_NAME, CMenus::SORT_DEMONAME, "Name", 0, 100.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, - {COL_DEMO_LENGTH, CMenus::SORT_LENGTH, "Length", 1, 80.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, - {COL_DEMO_DATE, CMenus::SORT_DATE, "Date", 1, 170.0f, 0, {0}, {0}, CUI::ALIGN_CENTER}, + {COL_DEMO_NAME, CMenus::SORT_DEMONAME, "Name", 0, 100.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, + {COL_DEMO_LENGTH, CMenus::SORT_LENGTH, "Length", 1, 80.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, + {COL_DEMO_DATE, CMenus::SORT_DATE, "Date", 1, 170.0f, 0, {0}, {0}, TEXTALIGN_CENTER}, }; void CMenus::RenderDemoPlayer(CUIRect MainView) @@ -121,7 +121,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) str_format(aBuffer, sizeof(aBuffer), "%d:%02d / %d:%02d", CurrentTick/SERVER_TICK_SPEED/60, (CurrentTick/SERVER_TICK_SPEED)%60, TotalTicks/SERVER_TICK_SPEED/60, (TotalTicks/SERVER_TICK_SPEED)%60); - UI()->DoLabel(&SeekBar, aBuffer, SeekBar.h*0.70f, CUI::ALIGN_CENTER); + UI()->DoLabel(&SeekBar, aBuffer, SeekBar.h*0.70f, TEXTALIGN_CENTER); // do the logic if(UI()->CheckActiveItem(&s_PrevAmount)) @@ -314,7 +314,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) ButtonBar.VSplitLeft(Margins*3, 0, &ButtonBar); char aBuffer[64]; str_format(aBuffer, sizeof(aBuffer), pInfo->m_Speed >= 1.0f ? "x%.0f" : "x%.2f", pInfo->m_Speed); - UI()->DoLabel(&ButtonBar, aBuffer, Button.h*0.7f, CUI::ALIGN_LEFT); + UI()->DoLabel(&ButtonBar, aBuffer, Button.h*0.7f, TEXTALIGN_LEFT); // close button ButtonBar.VSplitRight(ButtonbarHeight*3, &ButtonBar, &Button); @@ -477,12 +477,12 @@ void CMenus::RenderDemoList(CUIRect MainView) // demo list header static CListBox s_ListBox; - s_ListBox.DoHeader(&ListBox, Localize("Recorded"), GetListHeaderHeight()); + s_ListBox.DoHeader(&ListBox, Localize("Recorded"), UI()->GetListHeaderHeight()); // demo list column headers CUIRect Headers; - ListBox.HMargin(GetListHeaderHeight() + 2.0f, &Headers); - Headers.h = GetListHeaderHeight(); + ListBox.HMargin(UI()->GetListHeaderHeight() + 2.0f, &Headers); + Headers.h = UI()->GetListHeaderHeight(); Headers.Draw(vec4(0.0f,0,0,0.15f), 0.0f, CUIRect::CORNER_NONE); @@ -541,7 +541,7 @@ void CMenus::RenderDemoList(CUIRect MainView) } } - s_ListBox.DoSpacing(GetListHeaderHeight()); + s_ListBox.DoSpacing(UI()->GetListHeaderHeight()); s_ListBox.DoStart(20.0f, m_lDemos.size(), 1, 3, m_DemolistSelectedIndex); for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) @@ -587,7 +587,7 @@ void CMenus::RenderDemoList(CUIRect MainView) if(ID == COL_DEMO_NAME) { Button.x += FileIcon.w + 10.0f; - UI()->DoLabel(&Button, DemoItem.m_aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, DemoItem.m_aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); } else if(ID == COL_DEMO_LENGTH && !DemoItem.m_IsDir && DemoItem.m_InfosLoaded && DemoItem.m_Valid) { @@ -597,7 +597,7 @@ void CMenus::RenderDemoList(CUIRect MainView) Button.VMargin(4.0f, &Button); if(!Item.m_Selected) TextRender()->TextColor(CUI::ms_TransparentTextColor); - UI()->DoLabel(&Button, aLength, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_RIGHT); + UI()->DoLabel(&Button, aLength, Item.m_Rect.h*ms_FontmodHeight*0.8f, TEXTALIGN_RIGHT); } else if(ID == COL_DEMO_DATE && !DemoItem.m_IsDir) { @@ -605,7 +605,7 @@ void CMenus::RenderDemoList(CUIRect MainView) str_timestamp_ex(DemoItem.m_Date, aDate, sizeof(aDate), FORMAT_SPACE); if(!Item.m_Selected) TextRender()->TextColor(CUI::ms_TransparentTextColor); - UI()->DoLabel(&Button, aDate, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Button, aDate, Item.m_Rect.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); } TextRender()->TextColor(CUI::ms_DefaultTextColor); if(Item.m_Selected) diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index e6b19fc35..efffdbeb9 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -70,7 +70,7 @@ void CMenus::RenderGame(CUIRect MainView) // game options MainView.HSplitTop(20.0f, &Label, &MainView); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Game options"), 20.0f*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Game options"), 20.0f*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); MainView.Draw(vec4(0.0, 0.0, 0.0, 0.25f)); if(Info.m_aNotification[0] != 0) @@ -79,7 +79,7 @@ void CMenus::RenderGame(CUIRect MainView) CUIRect Bar; MainView.HSplitBottom(NoteHeight, &MainView, &Bar); Bar.HMargin(15.0f, &Bar); - UI()->DoLabel(&Bar, Info.m_aNotification, 14.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Bar, Info.m_aNotification, 14.0f, TEXTALIGN_CENTER); } // buttons @@ -220,7 +220,7 @@ void CMenus::RenderPlayers(CUIRect MainView) // player options MainView.HSplitTop(ButtonHeight, &Label, &MainView); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Player options"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Player options"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); MainView.Draw(vec4(0.0, 0.0, 0.0, 0.25f)); // prepare headline @@ -244,7 +244,7 @@ void CMenus::RenderPlayers(CUIRect MainView) Row.VSplitLeft(ButtonHeight+Spacing, 0, &Row); Row.VSplitLeft(NameWidth, &Label, &Row); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Player"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, Localize("Player"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); Row.VSplitRight(2*ButtonHeight, &Row, &Label); Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GUIICONS].m_Id); @@ -306,12 +306,12 @@ void CMenus::RenderPlayers(CUIRect MainView) } char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%s", Config()->m_ClShowsocial ? m_pClient->m_aClients[i].m_aName : ""); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); Row.VSplitLeft(Spacing, 0, &Row); Row.VSplitLeft(ClanWidth, &Label, &Row); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s", Config()->m_ClShowsocial ? m_pClient->m_aClients[i].m_aClan : ""); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); // ignore button Row.VSplitRight(ButtonHeight/2, &Row, 0); @@ -372,33 +372,33 @@ void CMenus::RenderServerInfo(CUIRect MainView) ServerInfo.HSplitTop(ButtonHeight, &Label, &ServerInfo); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Server info"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Server info"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); ServerInfo.Draw(vec4(0.0, 0.0, 0.0, 0.25f)); ServerInfo.Margin(5.0f, &ServerInfo); ServerInfo.HSplitTop(2*ButtonHeight, &Label, &ServerInfo); Label.y += 2.0f; - UI()->DoLabel(&Label, CurrentServerInfo.m_aName, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT, Label.w); + UI()->DoLabel(&Label, CurrentServerInfo.m_aName, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT, Label.w); ServerInfo.HSplitTop(ButtonHeight, &Label, &ServerInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Address"), CurrentServerInfo.m_aHostname); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); ServerInfo.HSplitTop(ButtonHeight, &Label, &ServerInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %d", Localize("Ping"), m_pClient->m_Snap.m_pLocalInfo->m_Latency); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); ServerInfo.HSplitTop(ButtonHeight, &Label, &ServerInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Version"), CurrentServerInfo.m_aVersion); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); ServerInfo.HSplitTop(ButtonHeight, &Label, &ServerInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Password"), CurrentServerInfo.m_Flags&IServerBrowser::FLAG_PASSWORD ? Localize("Yes", "With") : Localize("No", "Without/None")); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); const bool IsFavorite = CurrentServerInfo.m_Favorite; ServerInfo.HSplitBottom(ButtonHeight, &ServerInfo, &Label); @@ -426,19 +426,19 @@ void CMenus::RenderServerInfo(CUIRect MainView) GameInfo.HSplitTop(ButtonHeight, &Label, &GameInfo); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Game info"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Game info"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); GameInfo.Draw(vec4(0.0, 0.0, 0.0, 0.25f)); GameInfo.Margin(5.0f, &GameInfo); GameInfo.HSplitTop(ButtonHeight, &Label, &GameInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Game type"), CurrentServerInfo.m_aGameType); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); GameInfo.HSplitTop(ButtonHeight, &Label, &GameInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Map"), CurrentServerInfo.m_aMap); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); GameInfo.HSplitTop(ButtonHeight, &Label, &GameInfo); Label.y += 2.0f; @@ -456,22 +456,22 @@ void CMenus::RenderServerInfo(CUIRect MainView) break; } str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Difficulty"), pLevelName); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); GameInfo.HSplitTop(ButtonHeight, &Label, &GameInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %d", Localize("Score limit"), m_pClient->m_GameInfo.m_ScoreLimit); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); GameInfo.HSplitTop(ButtonHeight, &Label, &GameInfo); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %d", Localize("Time limit"), m_pClient->m_GameInfo.m_TimeLimit); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); GameInfo.HSplitBottom(ButtonHeight, &GameInfo, &Label); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s: %d/%d", Localize("Players"), m_pClient->m_GameInfo.m_NumPlayers, CurrentServerInfo.m_MaxClients); - UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); // motd Motd.HSplitTop(2.0f, 0, &Motd); @@ -479,7 +479,7 @@ void CMenus::RenderServerInfo(CUIRect MainView) Motd.HSplitTop(ButtonHeight, &Label, &Motd); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("MOTD"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("MOTD"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Motd.Draw(vec4(0.0, 0.0, 0.0, 0.25f)); Motd.Margin(5.0f, &Motd); @@ -513,7 +513,7 @@ bool CMenus::RenderServerControlServer(CUIRect MainView) { static CListBox s_ListBox; CUIRect List = MainView; - s_ListBox.DoHeader(&List, Localize("Option"), GetListHeaderHeight()); + s_ListBox.DoHeader(&List, Localize("Option"), UI()->GetListHeaderHeight()); s_ListBox.DoStart(20.0f, m_pClient->m_pVoting->NumVoteOptions(), 1, 3, m_CallvoteSelectedOption, 0, true, 0, CUIRect::CORNER_NONE); for(const CVoteOptionClient *pOption = m_pClient->m_pVoting->FirstVoteOption(); pOption; pOption = pOption->m_pNext) @@ -533,7 +533,7 @@ bool CMenus::RenderServerControlServer(CUIRect MainView) for(int i = pOption->m_IsSubheader ? 1 : 0; i < pOption->m_Depth; i++) Item.m_Rect.VSplitLeft(10.0f, 0, &Item.m_Rect); - UI()->DoLabel(&Item.m_Rect, pOption->m_aDescription, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Item.m_Rect, pOption->m_aDescription, Item.m_Rect.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); } } @@ -567,7 +567,7 @@ void CMenus::RenderServerControlKick(CUIRect MainView, bool FilterSpectators) static CListBox s_ListBox; CUIRect List = MainView; - s_ListBox.DoHeader(&List, Localize("Player"), GetListHeaderHeight()); + s_ListBox.DoHeader(&List, Localize("Player"), UI()->GetListHeaderHeight()); s_ListBox.DoStart(20.0f, NumOptions, 1, 3, Selected, 0, true, 0, CUIRect::CORNER_NONE); for(int i = 0; i < NumOptions; i++) @@ -598,12 +598,12 @@ void CMenus::RenderServerControlKick(CUIRect MainView, bool FilterSpectators) Label.y += 2.0f; char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%s", Config()->m_ClShowsocial ? m_pClient->m_aClients[s_aPlayerIDs[i]].m_aName : ""); - UI()->DoLabel(&Label, aBuf, Label.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, Label.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); Row.VSplitLeft(Spacing, 0, &Row); Row.VSplitLeft(ClanWidth, &Label, &Row); Label.y += 2.0f; str_format(aBuf, sizeof(aBuf), "%s", Config()->m_ClShowsocial ? m_pClient->m_aClients[s_aPlayerIDs[i]].m_aClan : ""); - UI()->DoLabel(&Label, aBuf, Label.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, Label.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); } } @@ -681,7 +681,7 @@ void CMenus::RenderServerControl(CUIRect MainView) MainView.HSplitTop(45.0f, &Bar, &MainView); Bar.Draw(vec4(0.0f, 0.0f, 0.0f, 0.25f+Config()->m_ClMenuAlpha/100.0f)); Bar.HMargin(15.0f, &Bar); - UI()->DoLabel(&Bar, pNotification, 14.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Bar, pNotification, 14.0f, TEXTALIGN_CENTER); return; } @@ -726,7 +726,7 @@ void CMenus::RenderServerControl(CUIRect MainView) MainView.HSplitTop(45.0f, &MainView, 0); MainView.Draw(vec4(0.0f, 0.0f, 0.0f, Config()->m_ClMenuAlpha/100.0f), 5.0f, CUIRect::CORNER_B); MainView.HMargin(15.0f, &MainView); - UI()->DoLabel(&MainView, pNotification, 14.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&MainView, pNotification, 14.0f, TEXTALIGN_CENTER); return; } @@ -764,7 +764,7 @@ void CMenus::RenderServerControl(CUIRect MainView) CUIRect Label; Search.VSplitLeft(TextRender()->TextWidth(FontSize, pSearchLabel, -1) + 10.0f, &Label, &Search); Label.y += 2.0f; - UI()->DoLabel(&Label, pSearchLabel, FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, pSearchLabel, FontSize, TEXTALIGN_LEFT); static CLineInput s_FilterInput(m_aFilterString, sizeof(m_aFilterString)); if(UI()->DoEditBox(&s_FilterInput, &Search, FontSize)) m_CallvoteSelectedOption = 0; @@ -773,7 +773,7 @@ void CMenus::RenderServerControl(CUIRect MainView) if(pNotification) { Bottom.y += 2.0f; - UI()->DoLabel(&Bottom, pNotification, Bottom.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Bottom, pNotification, Bottom.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); } else { @@ -788,7 +788,7 @@ void CMenus::RenderServerControl(CUIRect MainView) const float FontSize = Reason.h*ms_FontmodHeight*0.8f; Reason.VSplitLeft(TextRender()->TextWidth(FontSize, pReasonLabel, -1) + 10.0f, &Label, &Reason); Label.y += 2.0f; - UI()->DoLabel(&Label, pReasonLabel, FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, pReasonLabel, FontSize, TEXTALIGN_LEFT); static CLineInput s_ReasonInput(m_aCallvoteReason, sizeof(m_aCallvoteReason)); UI()->DoEditBox(&s_ReasonInput, &Reason, FontSize, false, CUIRect::CORNER_L); @@ -837,10 +837,10 @@ void CMenus::RenderServerControl(CUIRect MainView) // add vote Extended.HSplitTop(LineHeight, &Bottom, &Extended); Bottom.VSplitLeft(2*ColumnWidth+Spacing, &Button, &Bottom); - UI()->DoLabel(&Button, Localize("Vote description:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, Localize("Vote description:"), FontSize, TEXTALIGN_LEFT); Bottom.VSplitLeft(2*Spacing, 0, &Button); - UI()->DoLabel(&Button, Localize("Vote command:"), FontSize, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, Localize("Vote command:"), FontSize, TEXTALIGN_LEFT); static char s_aVoteDescription[VOTE_DESC_LENGTH] = {0}; static char s_aVoteCommand[VOTE_CMD_LENGTH] = {0}; diff --git a/src/game/client/components/menus_listbox.cpp b/src/game/client/components/menus_listbox.cpp index f089babb7..be0f2fc06 100644 --- a/src/game/client/components/menus_listbox.cpp +++ b/src/game/client/components/menus_listbox.cpp @@ -37,7 +37,7 @@ void CMenus::CListBox::DoHeader(const CUIRect *pRect, const char *pTitle, // draw header View.HSplitTop(HeaderHeight, &Header, &View); Header.y += 2.0f; - m_pUI->DoLabel(&Header, pTitle, Header.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + m_pUI->DoLabel(&Header, pTitle, Header.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); View.HSplitTop(Spacing, &Header, &View); @@ -70,7 +70,7 @@ bool CMenus::CListBox::DoFilter(float FilterHeight, float Spacing) CUIRect Label, EditBox; Filter.VSplitLeft(Filter.w/5.0f, &Label, &EditBox); Label.y += Spacing; - m_pUI->DoLabel(&Label, Localize("Search:"), FontSize, CUI::ALIGN_CENTER); + m_pUI->DoLabel(&Label, Localize("Search:"), FontSize, TEXTALIGN_CENTER); bool Changed = m_pUI->DoEditBox(&m_FilterInput, &EditBox, FontSize); View.HSplitTop(Spacing, &Filter, &View); @@ -107,7 +107,7 @@ void CMenus::CListBox::DoStart(float RowHeight, int NumItems, int ItemsPerRow, i View.HSplitBottom(m_FooterHeight, &View, &Footer); Footer.VSplitLeft(10.0f, 0, &Footer); Footer.y += 2.0f; - m_pUI->DoLabel(&Footer, m_pBottomText, Footer.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + m_pUI->DoLabel(&Footer, m_pBottomText, Footer.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); } // setup the variables diff --git a/src/game/client/components/menus_popups.cpp b/src/game/client/components/menus_popups.cpp deleted file mode 100644 index ef9e1042c..000000000 --- a/src/game/client/components/menus_popups.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ -/* If you are missing that file, acquire a complete release at teeworlds.com. */ - -#include <base/tl/array.h> - -#include <engine/shared/config.h> - -#include <engine/console.h> -#include <engine/graphics.h> -#include <engine/input.h> -#include <engine/keys.h> -#include <engine/storage.h> -#include <engine/serverbrowser.h> -#include <engine/textrender.h> - -#include <generated/client_data.h> -#include <generated/protocol.h> - -#include "countryflags.h" -#include "menus.h" - - -// popup menu handling -static struct -{ - CUIRect m_Rect; - void *m_pId; - int (*m_pfnFunc)(CMenus *pMenu, CUIRect Rect); - int m_IsMenu; - void *m_pExtra; -} s_Popups; - -void CMenus::InvokePopupMenu(void *pID, int Flags, float x, float y, float Width, float Height, int (*pfnFunc)(CMenus *pMenu, CUIRect Rect), void *pExtra) -{ - if(m_PopupActive) - return; - if(x + Width > UI()->Screen()->w) - x = UI()->Screen()->w - Width; - if(y + Height > UI()->Screen()->h) - y = UI()->Screen()->h - Height; - s_Popups.m_pId = pID; - s_Popups.m_IsMenu = Flags; - s_Popups.m_Rect.x = x; - s_Popups.m_Rect.y = y; - s_Popups.m_Rect.w = Width; - s_Popups.m_Rect.h = Height; - s_Popups.m_pfnFunc = pfnFunc; - s_Popups.m_pExtra = pExtra; - m_PopupActive = true; -} - -void CMenus::DoPopupMenu() -{ - if(m_PopupActive) - { - UI()->SetHotItem(&s_Popups.m_pId); - - if(UI()->CheckActiveItem(&s_Popups.m_pId)) - { - if(!UI()->MouseButton(0)) - { - if(!UI()->MouseHovered(&s_Popups.m_Rect)) - m_PopupActive = false; - UI()->SetActiveItem(0); - } - } - else if(UI()->HotItem() == &s_Popups.m_pId) - { - if(UI()->MouseButton(0)) - UI()->SetActiveItem(&s_Popups.m_pId); - } - - int Corners = CUIRect::CORNER_ALL; - if(s_Popups.m_IsMenu) - Corners = CUIRect::CORNER_R|CUIRect::CORNER_B; - - CUIRect r = s_Popups.m_Rect; - r.Draw(vec4(0.5f,0.5f,0.5f,0.75f), 3.0f, Corners); - r.Margin(1.0f, &r); - r.Draw(vec4(0,0,0,0.75f), 3.0f, Corners); - r.Margin(4.0f, &r); - - if(s_Popups.m_pfnFunc(this, r)) - m_PopupActive = false; - - if(UI()->KeyPress(KEY_ESCAPE)) - m_PopupActive = false; - } -} - diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index ef4c8716f..b9dd42486 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -180,13 +180,13 @@ void CMenus::RenderHSLPicker(CUIRect MainView) // label Label.VSplitMid(&Label, &Button, 0.0f); Label.y += 4.0f; - UI()->DoLabel(&Label, apNames[i], SliderHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, apNames[i], SliderHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); // value label char aBuf[16]; str_format(aBuf, sizeof(aBuf), "%d", *apVars[i]); Button.y += 4.0f; - UI()->DoLabel(&Button, aBuf, SliderHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Button, aBuf, SliderHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); // button < Section.VSplitLeft(SliderHeight, &Button, &Bar); @@ -329,7 +329,7 @@ void CMenus::RenderSkinSelection(CUIRect MainView) m_pSelectedSkin = 0; int OldSelected = -1; - s_ListBox.DoHeader(&MainView, Localize("Skins"), GetListHeaderHeight()); + s_ListBox.DoHeader(&MainView, Localize("Skins"), UI()->GetListHeaderHeight()); m_RefreshSkinSelector = s_ListBox.DoFilter(); s_ListBox.DoStart(60.0f, s_paSkinList.size(), 10, 1, OldSelected); @@ -380,7 +380,7 @@ void CMenus::RenderSkinSelection(CUIRect MainView) TextRender()->TextColor(CUI::ms_HighlightTextColor); TextRender()->TextSecondaryColor(CUI::ms_HighlightTextOutlineColor); } - UI()->DoLabel(&Label, s->m_aName, 10.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, s->m_aName, 10.0f, TEXTALIGN_CENTER); if(Item.m_Selected) { TextRender()->TextColor(CUI::ms_DefaultTextColor); @@ -492,7 +492,7 @@ void CMenus::RenderSkinPartSelection(CUIRect MainView) TextRender()->TextColor(CUI::ms_HighlightTextColor); TextRender()->TextSecondaryColor(CUI::ms_HighlightTextOutlineColor); } - UI()->DoLabel(&Label, s->m_aName, 10.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, s->m_aName, 10.0f, TEXTALIGN_CENTER); if(Item.m_Selected) { TextRender()->TextColor(CUI::ms_DefaultTextColor); @@ -728,7 +728,7 @@ void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header) int OldSelected = s_SelectedLanguage; if(Header) - s_ListBox.DoHeader(&MainView, Localize("Language"), GetListHeaderHeight()); + s_ListBox.DoHeader(&MainView, Localize("Language"), UI()->GetListHeaderHeight()); bool IsActive = m_ActiveListBox == ACTLB_LANG; s_ListBox.DoStart(20.0f, s_Languages.size(), 1, 3, s_SelectedLanguage, Header?0:&MainView, Header, &IsActive); @@ -752,7 +752,7 @@ void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header) TextRender()->TextSecondaryColor(CUI::ms_HighlightTextOutlineColor); } Item.m_Rect.y += 2.0f; - UI()->DoLabel(&Item.m_Rect, r.front().m_Name, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Item.m_Rect, r.front().m_Name, Item.m_Rect.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); if(Item.m_Selected) { TextRender()->TextColor(CUI::ms_DefaultTextColor); @@ -796,7 +796,7 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) const int OldSelected = SelectedTheme; if(Header) - s_ListBox.DoHeader(&MainView, Localize("Theme"), GetListHeaderHeight()); + s_ListBox.DoHeader(&MainView, Localize("Theme"), UI()->GetListHeaderHeight()); bool IsActive = m_ActiveListBox == ACTLB_THEME; s_ListBox.DoStart(20.0f, m_lThemes.size(), 1, 3, SelectedTheme, Header?0:&MainView, Header, &IsActive); @@ -847,7 +847,7 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) TextRender()->TextSecondaryColor(CUI::ms_HighlightTextOutlineColor); } Item.m_Rect.y += 2.0f; - UI()->DoLabel(&Item.m_Rect, aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Item.m_Rect, aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); if(Item.m_Selected) { TextRender()->TextColor(CUI::ms_DefaultTextColor); @@ -903,7 +903,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) // render game menu Game.HSplitTop(ButtonHeight, &Label, &Game); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Game"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Game"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Game.VSplitMid(&GameLeft, &GameRight, Spacing); @@ -1015,7 +1015,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) // render client menu Client.HSplitTop(ButtonHeight, &Label, &Client); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Client"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Client"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Client.HSplitTop(Spacing, 0, &Client); Client.HSplitTop(ButtonHeight, &Button, &Client); @@ -1095,7 +1095,7 @@ void CMenus::RenderSettingsTeeCustom(CUIRect MainView) MainView.HSplitTop(ButtonHeight, &Label, &MainView); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Customize"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Customize"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); // skin part selection MainView.HSplitTop(SpacingH, 0, &MainView); @@ -1183,7 +1183,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) Left.HSplitTop(ButtonHeight, &Label, &Left); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Tee"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Tee"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); // Preview { @@ -1235,7 +1235,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) Top.VSplitLeft(Top.w/3.0f+SpacingW/2.0f, &Label, &Top); Label.y += 17.0f; - UI()->DoLabel(&Label, Localize("Normal:"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Normal:"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Top.Draw(vec4(0.0f, 0.0f, 0.0f, 0.25f)); @@ -1287,7 +1287,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) Bottom.VSplitLeft(Bottom.w/3.0f+SpacingW/2.0f, &Label, &Bottom); Label.y += 17.0f; - UI()->DoLabel(&Label, Localize("Team:"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Team:"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Bottom.VSplitMid(&TeeLeft, &TeeRight, SpacingW); @@ -1312,7 +1312,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) Right.HSplitTop(ButtonHeight, &Label, &Right); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Personal"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Personal"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); // Personal { @@ -1336,7 +1336,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) Bottom.VSplitLeft(100.0f, &Label, &Button); Label.y += 17.0f; - UI()->DoLabel(&Label, Localize("Flag:"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Flag:"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Button.w = (SkinHeight - 20.0f) * 2 + 20.0f; Button.Draw(vec4(0.0f, 0.0f, 0.0f, 0.25f)); @@ -1613,7 +1613,7 @@ bool CMenus::DoResolutionList(CUIRect* pRect, CListBox* pListBox, TextRender()->TextSecondaryColor(CUI::ms_HighlightTextOutlineColor); } Item.m_Rect.y += 2.0f; - UI()->DoLabel(&Item.m_Rect, aBuf, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Item.m_Rect, aBuf, Item.m_Rect.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); if(Item.m_Selected) { TextRender()->TextColor(CUI::ms_DefaultTextColor); @@ -1680,7 +1680,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) // render screen menu ScreenLeft.HSplitTop(ButtonHeight, &Label, &ScreenLeft); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Screen"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Screen"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); ScreenLeft.VSplitMid(&ScreenLeft, &ScreenRight, Spacing); @@ -1709,7 +1709,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) Button.VSplitLeft(100.0f-25.0f, &Text, &Button); // make button appear centered with FSAA str_format(aBuf, sizeof(aBuf), Localize("Screen:")); Text.y += 2.0f; - UI()->DoLabel(&Text, aBuf, Text.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Text, aBuf, Text.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); Button.VSplitLeft(120.0f, &Button, 0); str_format(aBuf, sizeof(aBuf), "#%d (%dx%d)", Config()->m_GfxScreen+1, Graphics()->DesktopWidth(), Graphics()->DesktopHeight()); @@ -1732,7 +1732,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) char aBuf[32]; str_format(aBuf, sizeof(aBuf), "%s:", Localize("Anti Aliasing")); Text.y += 2.0f; - UI()->DoLabel(&Text, aBuf, Text.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Text, aBuf, Text.h*ms_FontmodHeight*0.8f, TEXTALIGN_LEFT); Button.VSplitLeft(70.0f, &Button, 0); str_format(aBuf, sizeof(aBuf), "%dx", Config()->m_GfxFsaaSamples); @@ -1775,7 +1775,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) // render texture menu Texture.HSplitTop(ButtonHeight, &Label, &Texture); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Texture"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Texture"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Texture.HSplitTop(Spacing, 0, &Texture); Texture.HSplitTop(ButtonHeight, &Button, &Texture); @@ -1813,7 +1813,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) // draw header MainView.HSplitTop(ButtonHeight, &Header, &MainView); Header.y += 2.0f; - UI()->DoLabel(&Header, Localize("Resolution"), Header.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Header, Localize("Resolution"), Header.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); @@ -1826,11 +1826,11 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%s", Localize("Recommended")); HeaderLeft.y += 2; - UI()->DoLabel(&HeaderLeft, aBuf, HeaderLeft.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&HeaderLeft, aBuf, HeaderLeft.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); str_format(aBuf, sizeof(aBuf), "%s", Localize("Other")); HeaderRight.y += 2; - UI()->DoLabel(&HeaderRight, aBuf, HeaderRight.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&HeaderRight, aBuf, HeaderRight.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); MainView.HSplitTop(Spacing, 0, &MainView); @@ -1844,7 +1844,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) const float HiDPIScale = Graphics()->ScreenHiDPIScale(); str_format(aBuf, sizeof(aBuf), Localize("Current: %dx%d (%d:%d)"), (int)(s_GfxScreenWidth*HiDPIScale), (int)(s_GfxScreenHeight*HiDPIScale), s_GfxScreenWidth/g, s_GfxScreenHeight/g); Button.y += 2; - UI()->DoLabel(&Button, aBuf, Button.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Button, aBuf, Button.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); static int s_LastScreen = Config()->m_GfxScreen; if(s_LastScreen != Config()->m_GfxScreen) @@ -1927,7 +1927,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) // render sound menu Sound.HSplitTop(ButtonHeight, &Label, &Sound); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Sound"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Sound"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Sound.HSplitTop(Spacing, 0, &Sound); CUIRect UseSoundButton; @@ -1953,7 +1953,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) // render detail menu Detail.HSplitTop(ButtonHeight, &Label, &Detail); Label.y += 2.0f; - UI()->DoLabel(&Label, Localize("Detail"), ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Label, Localize("Detail"), ButtonHeight*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); // split menu CUIRect Left, Right; @@ -1972,10 +1972,10 @@ void CMenus::RenderSettingsSound(CUIRect MainView) char aBuf[32]; str_format(aBuf, sizeof(aBuf), "%s:", Localize("Sample rate")); Text.y += 2.0f; - UI()->DoLabel(&Text, aBuf, Text.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Text, aBuf, Text.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); Unit.y += 2.0f; - UI()->DoLabel(&Unit, "kHz", Unit.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Unit, "kHz", Unit.h*ms_FontmodHeight*0.8f, TEXTALIGN_CENTER); if(Config()->m_SndRate != 48000 && Config()->m_SndRate != 44100) Config()->m_SndRate = 48000; @@ -2143,16 +2143,16 @@ void CMenus::RenderSettings(CUIRect MainView) TextRender()->TextColor(0.973f, 0.863f, 0.207f, 1.0f); RestartWarning.y += 2.0f; if(m_NeedRestartGraphics || m_NeedRestartSound) - UI()->DoLabel(&RestartWarning, Localize("You must restart the game for all settings to take effect."), RestartWarning.h*ms_FontmodHeight*0.75f, CUI::ALIGN_CENTER); + UI()->DoLabel(&RestartWarning, Localize("You must restart the game for all settings to take effect."), RestartWarning.h*ms_FontmodHeight*0.75f, TEXTALIGN_CENTER); else if(Client()->State() == IClient::STATE_ONLINE) { if(m_NeedRestartPlayer || NeedRestartTee) - UI()->DoLabel(&RestartWarning, Localize("You must reconnect to change identity."), RestartWarning.h*ms_FontmodHeight*0.75f, CUI::ALIGN_CENTER); + UI()->DoLabel(&RestartWarning, Localize("You must reconnect to change identity."), RestartWarning.h*ms_FontmodHeight*0.75f, TEXTALIGN_CENTER); else if(m_SkinModified) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), Localize("You have to wait %1.0f seconds to change identity."), m_pClient->m_LastSkinChangeTime+6.5f - Client()->LocalTime()); - UI()->DoLabel(&RestartWarning, aBuf, RestartWarning.h*ms_FontmodHeight*0.75f, CUI::ALIGN_CENTER); + UI()->DoLabel(&RestartWarning, aBuf, RestartWarning.h*ms_FontmodHeight*0.75f, TEXTALIGN_CENTER); } } TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); diff --git a/src/game/client/components/menus_start.cpp b/src/game/client/components/menus_start.cpp index 2019db24b..7f41bea2e 100644 --- a/src/game/client/components/menus_start.cpp +++ b/src/game/client/components/menus_start.cpp @@ -108,10 +108,10 @@ void CMenus::RenderStartMenu(CUIRect MainView) { str_format(aBuf, sizeof(aBuf), Localize("Teeworlds %s is out! Download it at www.teeworlds.com!"), Client()->LatestVersion()); TextRender()->TextColor(1.0f, 0.4f, 0.4f, 1.0f); - UI()->DoLabel(&Version, aBuf, 14.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Version, aBuf, 14.0f, TEXTALIGN_CENTER); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); } - UI()->DoLabel(&Version, GAME_RELEASE_VERSION, 14.0f, CUI::ALIGN_RIGHT); + UI()->DoLabel(&Version, GAME_RELEASE_VERSION, 14.0f, TEXTALIGN_RIGHT); if(NewPage != -1) SetMenuPage(NewPage); diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 9c00e1745..0251ec2ce 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -1,10 +1,8 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ -#include <math.h> - #include <base/color.h> -#include <base/system.h> #include <base/math.h> +#include <base/system.h> #include <engine/graphics.h> #include <engine/storage.h> @@ -31,6 +29,11 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) if(IsDir || !str_endswith(pName, ".png")) return 0; + CSkinPart Part; + str_utf8_copy_num(Part.m_aName, pName, minimum(str_length(pName) - 3, int(sizeof(Part.m_aName))), MAX_SKIN_LENGTH); + if(pSelf->FindSkinPart(pSelf->m_ScanningPart, Part.m_aName, true) != -1) + return 0; + char aBuf[IO_MAX_PATH_LENGTH]; str_format(aBuf, sizeof(aBuf), "skins/%s/%s", CSkins::ms_apSkinPartNames[pSelf->m_ScanningPart], pName); CImageInfo Info; @@ -41,11 +44,10 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) return 0; } - CSkinPart Part; Part.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); Part.m_BloodColor = vec3(1.0f, 1.0f, 1.0f); - unsigned char *d = (unsigned char *)Info.m_pData; + unsigned char *pData = (unsigned char *)Info.m_pData; int Pitch = Info.m_Width*4; // dig out blood color @@ -60,11 +62,11 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) for(int y = PartY; y < PartY+PartHeight; y++) for(int x = PartX; x < PartX+PartWidth; x++) { - if(d[y*Pitch+x*4+3] > 128) + if(pData[y*Pitch+x*4+3] > 128) { - aColors[0] += d[y*Pitch+x*4+0]; - aColors[1] += d[y*Pitch+x*4+1]; - aColors[2] += d[y*Pitch+x*4+2]; + aColors[0] += pData[y*Pitch+x*4+0]; + aColors[1] += pData[y*Pitch+x*4+1]; + aColors[2] += pData[y*Pitch+x*4+2]; } } @@ -77,10 +79,10 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) // make the texture gray scale for(int i = 0; i < Info.m_Width*Info.m_Height; i++) { - int v = (d[i*Step]+d[i*Step+1]+d[i*Step+2])/3; - d[i*Step] = v; - d[i*Step+1] = v; - d[i*Step+2] = v; + const int Average = (pData[i*Step]+pData[i*Step+1]+pData[i*Step+2])/3; + pData[i*Step] = Average; + pData[i*Step+1] = Average; + pData[i*Step+2] = Average; } Part.m_ColorTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); @@ -92,7 +94,6 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) Part.m_Flags |= SKINFLAG_SPECIAL; if(DirType != IStorage::TYPE_SAVE) Part.m_Flags |= SKINFLAG_STANDARD; - str_utf8_copy_num(Part.m_aName, pName, minimum(str_length(pName) - 3, int(sizeof(Part.m_aName))), MAX_SKIN_LENGTH); if(pSelf->Config()->m_Debug) { str_format(aBuf, sizeof(aBuf), "load skin part %s", Part.m_aName); @@ -470,34 +471,34 @@ int CSkins::GetTeamColor(int UseCustomColors, int PartColor, int Team, int Part) return ColorVal; } -bool CSkins::ValidateSkinParts(char* aPartNames[NUM_SKINPARTS], int* aUseCustomColors, int* aPartColors, int GameFlags) const +bool CSkins::ValidateSkinParts(char *apPartNames[NUM_SKINPARTS], int *pUseCustomColors, int *pPartColors, int GameFlags) const { // force standard (black) eyes on team skins if(GameFlags&GAMEFLAG_TEAMS) { // TODO: adjust eye color here as well? - if(str_comp(aPartNames[SKINPART_EYES], "colorable") == 0 || str_comp(aPartNames[SKINPART_EYES], "negative") == 0) + if(str_comp(apPartNames[SKINPART_EYES], "colorable") == 0 || str_comp(apPartNames[SKINPART_EYES], "negative") == 0) { - str_copy(aPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); + str_copy(apPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); return false; } } else { - const int BodyColor = aPartColors[SKINPART_BODY]; - const int EyeColor = aPartColors[SKINPART_EYES]; + const int BodyColor = pPartColors[SKINPART_BODY]; + const int EyeColor = pPartColors[SKINPART_EYES]; vec3 BodyHsl(((BodyColor>>16)&0xff)/255.0f, ((BodyColor>>8)&0xff)/255.0f, (BodyColor&0xff)/255.0f); vec3 EyeHsl(((EyeColor>>16)&0xff)/255.0f, ((EyeColor>>8)&0xff)/255.0f, (EyeColor&0xff)/255.0f); - if(!aUseCustomColors[SKINPART_BODY]) + if(!pUseCustomColors[SKINPART_BODY]) BodyHsl = vec3(0, 0, 1); const vec3 BodyLab = RgbToLab(HslToRgb(BodyHsl)); - if(str_comp(aPartNames[SKINPART_EYES], "negative") == 0) + if(str_comp(apPartNames[SKINPART_EYES], "negative") == 0) { - if(!aUseCustomColors[SKINPART_EYES]) + if(!pUseCustomColors[SKINPART_EYES]) EyeHsl = vec3(0, 0, 1); vec3 OrgEyeHsl = EyeHsl; @@ -510,19 +511,19 @@ bool CSkins::ValidateSkinParts(char* aPartNames[NUM_SKINPARTS], int* aUseCustomC // white eye can't go to black because of our DARKEST_COLOR_LGT restriction, so switch to standard (black) eyes if(OrgEyeHsl.l < DARKEST_COLOR_LGT/255.f) - str_copy(aPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); // black + str_copy(apPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); // black else { - aUseCustomColors[SKINPART_EYES] = 1; - aPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); + pUseCustomColors[SKINPART_EYES] = 1; + pPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); } return false; } } - else if(str_comp(aPartNames[SKINPART_EYES], "colorable") == 0) + else if(str_comp(apPartNames[SKINPART_EYES], "colorable") == 0) { - if(!aUseCustomColors[SKINPART_EYES]) + if(!pUseCustomColors[SKINPART_EYES]) EyeHsl = vec3(0, 0, 1); vec3 OrgEyeHsl = EyeHsl; @@ -534,8 +535,8 @@ bool CSkins::ValidateSkinParts(char* aPartNames[NUM_SKINPARTS], int* aUseCustomC OrgEyeHsl.l -= 0.6f; OrgEyeHsl.l = clamp(OrgEyeHsl.l, 0.f, 1.f); - aUseCustomColors[SKINPART_EYES] = 1; - aPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); + pUseCustomColors[SKINPART_EYES] = 1; + pPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); return false; } diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index 5b79caaf4..cd96ec29a 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -74,7 +74,7 @@ public: int GetTeamColor(int UseCustomColors, int PartColor, int Team, int Part) const; // returns true if everything was valid and nothing changed - bool ValidateSkinParts(char *aPartNames[NUM_SKINPARTS], int *aUseCustomColors, int* aPartColors, int GameFlags) const; + bool ValidateSkinParts(char *apPartNames[NUM_SKINPARTS], int *pUseCustomColors, int *pPartColors, int GameFlags) const; void SaveSkinfile(const char *pSaveSkinName); diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index ea8d981ac..44c66cfa5 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -44,6 +44,8 @@ CUI::CUI() m_Screen.y = 0; m_NumClips = 0; + + m_NumPopupMenus = 0; } void CUI::Init(class CConfig *pConfig, class IGraphics *pGraphics, class IInput *pInput, class ITextRender *pTextRender) @@ -267,7 +269,7 @@ bool CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float return true; } -void CUI::DoLabel(const CUIRect *pRect, const char *pText, float FontSize, EAlignment Align, float LineWidth, bool MultiLine) +void CUI::DoLabel(const CUIRect *pRect, const char *pText, float FontSize, int Align, float LineWidth, bool MultiLine) { // TODO: FIX ME!!!! // Graphics()->BlendNormal(); @@ -279,21 +281,19 @@ void CUI::DoLabel(const CUIRect *pRect, const char *pText, float FontSize, EAlig s_Cursor.m_MaxWidth = LineWidth; s_Cursor.m_Align = Align; - switch(Align) - { - case CUI::ALIGN_LEFT: - s_Cursor.m_Align = TEXTALIGN_LEFT; - s_Cursor.MoveTo(pRect->x, pRect->y); - break; - case CUI::ALIGN_CENTER: - s_Cursor.m_Align = TEXTALIGN_CENTER; - s_Cursor.MoveTo(pRect->x + pRect->w / 2.0f, pRect->y); - break; - case CUI::ALIGN_RIGHT: - s_Cursor.m_Align = TEXTALIGN_RIGHT; - s_Cursor.MoveTo(pRect->x + pRect->w, pRect->y); - break; - } + float x = pRect->x; + if(Align&TEXTALIGN_CENTER) + x += pRect->w / 2.0f; + else if(Align&TEXTALIGN_RIGHT) + x += pRect->w; + + float y = pRect->y; + if(Align&TEXTALIGN_MIDDLE) + y += pRect->h / 2.0f; + else if(Align&TEXTALIGN_BOTTOM) + y += pRect->h; + + s_Cursor.MoveTo(x, y); TextRender()->TextOutlined(&s_Cursor, pText, -1); } @@ -452,7 +452,7 @@ bool CUI::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize ClipEnable(pRect); Textbox.x -= ScrollOffset; - DoLabel(&Textbox, pDisplayStr, FontSize, CUI::ALIGN_LEFT); + DoLabel(&Textbox, pDisplayStr, FontSize, TEXTALIGN_LEFT); // render the cursor if(LastActiveItem() == pLineInput && !JustGotActive) @@ -463,7 +463,7 @@ bool CUI::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize Textbox = *pRect; Textbox.VSplitLeft(Spacing, 0, &Textbox); Textbox.x += TextWidth - ScrollOffset - TextRender()->TextWidth(FontSize, "|", -1)/2; - DoLabel(&Textbox, "|", FontSize, CUI::ALIGN_LEFT); + DoLabel(&Textbox, "|", FontSize, TEXTALIGN_LEFT); } } ClipDisable(); @@ -484,27 +484,27 @@ void CUI::DoEditBoxOption(CLineInput *pLineInput, const CUIRect *pRect, const ch char aBuf[32]; str_format(aBuf, sizeof(aBuf), "%s:", pStr); Label.y += 2.0f; - DoLabel(&Label, aBuf, FontSize, CUI::ALIGN_CENTER); + DoLabel(&Label, aBuf, FontSize, TEXTALIGN_CENTER); DoEditBox(pLineInput, &EditBox, FontSize, Hidden); } float CUI::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) { - // layout - CUIRect Handle; - pRect->HSplitTop(minimum(pRect->h/8.0f, 33.0f), &Handle, 0); - Handle.y += (pRect->h-Handle.h)*Current; - Handle.VMargin(5.0f, &Handle); + Current = clamp(Current, 0.0f, 1.0f); + // layout CUIRect Rail; pRect->VMargin(5.0f, &Rail); + CUIRect Handle; + Rail.HSplitTop(clamp(33.0f, Rail.w, Rail.h / 8.0f), &Handle, 0); + Handle.y += (Rail.h - Handle.h) * Current; + // logic static float s_OffsetY; const bool InsideHandle = MouseHovered(&Handle); const bool InsideRail = MouseHovered(&Rail); - float ReturnValue = Current; bool Grabbed = false; // whether to apply the offset if(CheckActiveItem(pID)) @@ -518,14 +518,14 @@ float CUI::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) { if(MouseButton(0)) { - s_OffsetY = MouseY()-Handle.y; + s_OffsetY = MouseY() - Handle.y; SetActiveItem(pID); Grabbed = true; } } else if(MouseButtonClicked(0) && !InsideHandle && InsideRail) { - s_OffsetY = Handle.h * 0.5f; + s_OffsetY = Handle.h / 2.0f; SetActiveItem(pID); Grabbed = true; } @@ -535,45 +535,38 @@ float CUI::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current) SetHotItem(pID); } + float ReturnValue = Current; if(Grabbed) { - const float Min = pRect->y; - const float Max = pRect->h-Handle.h; - const float Cur = MouseY()-s_OffsetY; - ReturnValue = clamp((Cur-Min)/Max, 0.0f, 1.0f); + const float Min = Rail.y; + const float Max = Rail.h - Handle.h; + const float Cur = MouseY() - s_OffsetY; + ReturnValue = clamp((Cur - Min) / Max, 0.0f, 1.0f); } // render - Rail.Draw(vec4(1.0f, 1.0f, 1.0f, 0.25f), Rail.w/2.0f); - - vec4 Color; - if(Grabbed) - Color = vec4(0.9f, 0.9f, 0.9f, 1.0f); - else if(InsideHandle) - Color = vec4(1.0f, 1.0f, 1.0f, 1.0f); - else - Color = vec4(0.8f, 0.8f, 0.8f, 1.0f); - Handle.Draw(Color, Handle.w/2.0f); + Rail.Draw(vec4(1.0f, 1.0f, 1.0f, 0.25f), Rail.w / 2.0f); + Handle.Draw(ScrollBarColorFunction.GetColor(Grabbed, InsideHandle), Handle.w / 2.0f); return ReturnValue; } float CUI::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current) { - // layout - CUIRect Handle; - pRect->VSplitLeft(maximum(minimum(pRect->w/8.0f, 33.0f), pRect->h), &Handle, 0); - Handle.x += (pRect->w-Handle.w)*clamp(Current, 0.0f, 1.0f); - Handle.HMargin(5.0f, &Handle); + Current = clamp(Current, 0.0f, 1.0f); + // layout CUIRect Rail; pRect->HMargin(5.0f, &Rail); + CUIRect Handle; + Rail.VSplitLeft(clamp(33.0f, Rail.h, Rail.w / 8.0f), &Handle, 0); + Handle.x += (Rail.w - Handle.w) * Current; + // logic static float s_OffsetX; const bool InsideHandle = MouseHovered(&Handle); const bool InsideRail = MouseHovered(&Rail); - float ReturnValue = Current; bool Grabbed = false; // whether to apply the offset if(CheckActiveItem(pID)) @@ -587,14 +580,14 @@ float CUI::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current) { if(MouseButton(0)) { - s_OffsetX = MouseX()-Handle.x; + s_OffsetX = MouseX() - Handle.x; SetActiveItem(pID); Grabbed = true; } } else if(MouseButtonClicked(0) && !InsideHandle && InsideRail) { - s_OffsetX = Handle.w * 0.5f; + s_OffsetX = Handle.w / 2.0f; SetActiveItem(pID); Grabbed = true; } @@ -604,25 +597,18 @@ float CUI::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current) SetHotItem(pID); } + float ReturnValue = Current; if(Grabbed) { - const float Min = pRect->x; - const float Max = pRect->w-Handle.w; - const float Cur = MouseX()-s_OffsetX; - ReturnValue = clamp((Cur-Min)/Max, 0.0f, 1.0f); + const float Min = Rail.x; + const float Max = Rail.w - Handle.w; + const float Cur = MouseX() - s_OffsetX; + ReturnValue = clamp((Cur - Min) / Max, 0.0f, 1.0f); } // render - Rail.Draw(vec4(1.0f, 1.0f, 1.0f, 0.25f), Rail.h/2.0f); - - vec4 Color; - if(Grabbed) - Color = vec4(0.9f, 0.9f, 0.9f, 1.0f); - else if(InsideHandle) - Color = vec4(1.0f, 1.0f, 1.0f, 1.0f); - else - Color = vec4(0.8f, 0.8f, 0.8f, 1.0f); - Handle.Draw(Color, Handle.h/2.0f); + Rail.Draw(vec4(1.0f, 1.0f, 1.0f, 0.25f), Rail.h / 2.0f); + Handle.Draw(ScrollBarColorFunction.GetColor(Grabbed, InsideHandle), Handle.h / 2.0f); return ReturnValue; } @@ -655,7 +641,7 @@ void CUI::DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, pRect->VSplitLeft(pRect->h+10.0f+VSplitVal, &Label, &ScrollBar); Label.VSplitLeft(Label.h+5.0f, 0, &Label); Label.y += 2.0f; - DoLabel(&Label, aBuf, FontSize, CUI::ALIGN_LEFT); + DoLabel(&Label, aBuf, FontSize, TEXTALIGN_LEFT); ScrollBar.VMargin(4.0f, &ScrollBar); Value = pScale->ToAbsolute(DoScrollbarH(pID, &ScrollBar, pScale->ToRelative(Value, Min, Max)), Min, Max); @@ -681,7 +667,7 @@ void CUI::DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect pRect->VSplitLeft(pRect->h+5.0f, 0, &Label); Label.VSplitRight(60.0f, &Label, &ScrollBar); Label.y += 2.0f; - DoLabel(&Label, aBuf, FontSize, CUI::ALIGN_LEFT); + DoLabel(&Label, aBuf, FontSize, TEXTALIGN_LEFT); ScrollBar.VMargin(4.0f, &ScrollBar); Value = pScale->ToAbsolute(DoScrollbarH(pID, &ScrollBar, pScale->ToRelative(Value, 0, Max)), 0, Max); @@ -726,9 +712,67 @@ float CUI::DrawClientID(float FontSize, vec2 CursorPosition, int ID, const vec4& return Width + 0.2f * FontSize; } +void CUI::DoPopupMenu(int X, int Y, int Width, int Height, void *pContext, bool (*pfnFunc)(void *pContext, CUIRect View), int Corners) +{ + dbg_assert(m_NumPopupMenus < MAX_POPUP_MENUS, "max popup menus exceeded"); + + if(X + Width > Screen()->w) + X = Screen()->w - Width; + if(Y + Height > Screen()->h) + Y = Screen()->h - Height; + + m_aPopupMenus[m_NumPopupMenus].m_Rect.x = X; + m_aPopupMenus[m_NumPopupMenus].m_Rect.y = Y; + m_aPopupMenus[m_NumPopupMenus].m_Rect.w = Width; + m_aPopupMenus[m_NumPopupMenus].m_Rect.h = Height; + m_aPopupMenus[m_NumPopupMenus].m_pContext = pContext; + m_aPopupMenus[m_NumPopupMenus].m_pfnFunc = pfnFunc; + m_aPopupMenus[m_NumPopupMenus].m_Corners = Corners; + m_NumPopupMenus++; +} + +void CUI::RenderPopupMenus() +{ + const bool MousePressed = MouseButton(0) || MouseButton(1); + static bool s_MousePressed = MousePressed; + + for(unsigned i = 0; i < m_NumPopupMenus; i++) + { + const bool Inside = MouseInside(&m_aPopupMenus[i].m_Rect); + const bool Active = i == m_NumPopupMenus - 1; + + // prevent activation of UI elements outside of active popup + if(Active) + SetHotItem(&m_aPopupMenus[i]); + + CUIRect PopupRect = m_aPopupMenus[i].m_Rect; + PopupRect.Draw(vec4(0.5f, 0.5f, 0.5f, 0.75f), 3.0f, m_aPopupMenus[i].m_Corners); + PopupRect.Margin(1.0f, &PopupRect); + PopupRect.Draw(vec4(0.0f, 0.0f, 0.0f, 0.75f), 3.0f, m_aPopupMenus[i].m_Corners); + PopupRect.Margin(4.0f, &PopupRect); + + if(m_aPopupMenus[i].m_pfnFunc(m_aPopupMenus[i].m_pContext, PopupRect)) + m_NumPopupMenus = i; // close this popup and all above it + if(Active && ((!Inside && s_MousePressed && !MousePressed) || ConsumeHotkey(HOTKEY_ESCAPE))) + m_NumPopupMenus--; // close top-most popup by clicking outside and with escape + } + + s_MousePressed = MousePressed; +} + float CUI::GetClientIDRectWidth(float FontSize) { if(!m_pConfig->m_ClShowUserId) return 0; return 1.4f * FontSize + 0.2f * FontSize; } + +float CUI::GetListHeaderHeight() const +{ + return ms_ListheaderHeight + (m_pConfig->m_UiWideview ? 3.0f : 0.0f); +} + +float CUI::GetListHeaderHeightFactor() const +{ + return 1.0f + (m_pConfig->m_UiWideview ? (3.0f/ms_ListheaderHeight) : 0.0f); +} diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 2f6800ad5..45600a75b 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -3,7 +3,7 @@ #ifndef GAME_CLIENT_UI_H #define GAME_CLIENT_UI_H -#include <engine/input.h> +#include <engine/textrender.h> #include "lineinput.h" #include "ui_rect.h" @@ -87,13 +87,26 @@ public: return vec4(1.0f, 1.0f, 1.0f, 0.5f); } } const LightButtonColorFunction; +static class CScrollBarColorFunction : public IButtonColorFunction +{ +public: + vec4 GetColor(bool Active, bool Hovered) const + { + if(Active) + return vec4(0.9f, 0.9f, 0.9f, 1.0f); + else if(Hovered) + return vec4(1.0f, 1.0f, 1.0f, 1.0f); + return vec4(0.8f, 0.8f, 0.8f, 1.0f); + } +} const ScrollBarColorFunction; class CUI { enum { - MAX_CLIP_NESTING_DEPTH = 16 + MAX_CLIP_NESTING_DEPTH = 16, + MAX_POPUP_MENUS = 8, }; bool m_Enabled; @@ -118,6 +131,16 @@ class CUI unsigned m_NumClips; void UpdateClipping(); + class + { + public: + CUIRect m_Rect; + int m_Corners; + void *m_pContext; + bool (*m_pfnFunc)(void *pContext, CUIRect View); // returns true to close popup + } m_aPopupMenus[MAX_POPUP_MENUS]; + unsigned m_NumPopupMenus; + class CConfig *m_pConfig; class IGraphics *m_pGraphics; class IInput *m_pInput; @@ -142,13 +165,6 @@ public: CUI(); - enum EAlignment - { - ALIGN_LEFT, - ALIGN_CENTER, - ALIGN_RIGHT, - }; - enum { HOTKEY_ENTER = 1, @@ -208,7 +224,7 @@ public: bool DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY); // labels - void DoLabel(const CUIRect *pRect, const char *pText, float FontSize, EAlignment Align, float LineWidth = -1.0f, bool MultiLine = true); + void DoLabel(const CUIRect *pRect, const char *pText, float FontSize, int Align = TEXTALIGN_LEFT|TEXTALIGN_TOP, float LineWidth = -1.0f, bool MultiLine = true); void DoLabelHighlighted(const CUIRect *pRect, const char *pText, const char *pHighlighted, float FontSize, const vec4 &TextColor, const vec4 &HighlightColor); // editboxes @@ -221,10 +237,18 @@ public: void DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &LinearScrollbarScale, bool Infinite = false); void DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char *apLabels[], int NumLabels, const IScrollbarScale *pScale = &LinearScrollbarScale); + // popup menu + void DoPopupMenu(int X, int Y, int Width, int Height, void *pContext, bool (*pfnFunc)(void *pContext, CUIRect View), int Corners = CUIRect::CORNER_ALL); + void RenderPopupMenus(); + bool IsPopupActive() const { return m_NumPopupMenus > 0; } + // client ID float DrawClientID(float FontSize, vec2 Position, int ID, const vec4& BgColor = vec4(1.0f, 1.0f, 1.0f, 0.5f), const vec4& TextColor = vec4(0.1f, 0.1f, 0.1f, 1.0f)); float GetClientIDRectWidth(float FontSize); + + float GetListHeaderHeight() const; + float GetListHeaderHeightFactor() const; }; diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index adb09ddca..9d04435e7 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -319,18 +319,10 @@ int CEditor::DoButton_Editor_Common(const void *pID, const char *pText, int Chec return 0; } - int CEditor::DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { pRect->Draw(GetButtonColor(pID, Checked), 3.0f); - - static CTextCursor s_Cursor(10.0f); - s_Cursor.MoveTo(pRect->x + pRect->w/2, pRect->y + pRect->h/2); - s_Cursor.Reset(); - s_Cursor.m_MaxWidth = pRect->w; - s_Cursor.m_MaxLines = 1; - s_Cursor.m_Align = TEXTALIGN_MC; - TextRender()->TextOutlined(&s_Cursor, pText, -1); + UI()->DoLabel(pRect, pText, 10.0f, TEXTALIGN_MC); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -341,16 +333,9 @@ int CEditor::DoButton_Image(const void *pID, const char *pText, int Checked, con if(!Used) ButtonColor *= vec4(0.5f, 0.5f, 0.5f, 1.0f); + const float FontSize = clamp(8.0f * pRect->w / TextRender()->TextWidth(10.0f, pText, -1), 6.0f, 10.0f); pRect->Draw(ButtonColor, 3.0f); - - static CTextCursor s_Cursor; - s_Cursor.MoveTo(pRect->x + pRect->w/2, pRect->y + pRect->h/2); - s_Cursor.Reset(); - s_Cursor.m_FontSize = clamp(8.0f * pRect->w / TextRender()->TextWidth(10.0f, pText, -1), 6.0f, 10.0f); - s_Cursor.m_MaxWidth = pRect->w; - s_Cursor.m_MaxLines = 1; - s_Cursor.m_Align = TEXTALIGN_MC; - TextRender()->TextOutlined(&s_Cursor, pText, -1); + UI()->DoLabel(pRect, pText, FontSize, TEXTALIGN_MC); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -361,20 +346,19 @@ int CEditor::DoButton_File(const void *pID, const char *pText, int Checked, cons else if(UI()->HotItem() == pID) pRect->Draw(vec4(1,1,1,0.33f), 3.0f); - CUIRect t = *pRect; - t.VMargin(5.0f, &t); - UI()->DoLabel(&t, pText, 10, CUI::ALIGN_LEFT); + CUIRect Label = *pRect; + Label.VMargin(5.0f, &Label); + UI()->DoLabel(&Label, pText, 10.0f, TEXTALIGN_ML); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { - CUIRect r = *pRect; - r.Draw(vec4(0.5f, 0.5f, 0.5f, 1.0f), 3.0f, CUIRect::CORNER_T); + pRect->Draw(vec4(0.5f, 0.5f, 0.5f, 1.0f), 3.0f, CUIRect::CORNER_T); - r = *pRect; - r.VMargin(5.0f, &r); - UI()->DoLabel(&r, pText, 10, CUI::ALIGN_LEFT); + CUIRect Label = *pRect; + Label.VMargin(5.0f, &Label); + UI()->DoLabel(&Label, pText, 10.0f, TEXTALIGN_ML); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -383,45 +367,37 @@ int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, if(UI()->HotItem() == pID || Checked) pRect->Draw(GetButtonColor(pID, Checked), 3.0f); - CUIRect t = *pRect; - t.VMargin(5.0f, &t); - static CTextCursor s_Cursor(10.0f); - s_Cursor.Reset(); - s_Cursor.MoveTo(t.x, t.y - 1.0f); - s_Cursor.m_MaxWidth = t.w; - TextRender()->TextOutlined(&s_Cursor, pText, -1); + CUIRect Label = *pRect; + Label.VMargin(5.0f, &Label); + UI()->DoLabel(&Label, pText, 10.0f, TEXTALIGN_ML); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { pRect->Draw(GetButtonColor(pID, Checked), 5.0f, CUIRect::CORNER_T); - CUIRect NewRect = *pRect; - NewRect.y += NewRect.h/2.0f-7.0f; - UI()->DoLabel(&NewRect, pText, 10, CUI::ALIGN_CENTER); + UI()->DoLabel(pRect, pText, 10.0f, TEXTALIGN_MC); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize) { pRect->Draw(GetButtonColor(pID, Checked), 3.0f, Corners); - CUIRect NewRect = *pRect; - NewRect.HMargin(NewRect.h/2.0f-FontSize/2.0f-1.0f, &NewRect); - UI()->DoLabel(&NewRect, pText, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(pRect, pText, FontSize, TEXTALIGN_MC); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_ButtonInc(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { pRect->Draw(GetButtonColor(pID, Checked), 3.0f, CUIRect::CORNER_R); - UI()->DoLabel(pRect, pText?pText:"+", 10, CUI::ALIGN_CENTER); + UI()->DoLabel(pRect, pText?pText:"+", 10.0f, TEXTALIGN_MC); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_ButtonDec(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { pRect->Draw(GetButtonColor(pID, Checked), 3.0f, CUIRect::CORNER_L); - UI()->DoLabel(pRect, pText?pText:"-", 10, CUI::ALIGN_CENTER); + UI()->DoLabel(pRect, pText?pText:"-", 10.0f, TEXTALIGN_MC); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -537,7 +513,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in str_format(aBuf, sizeof(aBuf),"%s %d", pLabel, Current); pRect->Draw(GetButtonColor(pID, 0)); pRect->y += pRect->h/2.0f-7.0f; - UI()->DoLabel(pRect, aBuf, 10, CUI::ALIGN_CENTER); + UI()->DoLabel(pRect, aBuf, 10, TEXTALIGN_CENTER); return Current; } @@ -1068,8 +1044,7 @@ void CEditor::DoQuad(CQuad *q, int Index) { if(!UI()->MouseButton(1)) { - static int s_QuadPopupID = 0; - UiInvokePopupMenu(&s_QuadPopupID, 0, UI()->MouseX(), UI()->MouseY(), 120, 180, PopupQuad); + UI()->DoPopupMenu(UI()->MouseX(), UI()->MouseY(), 120, 180, this, PopupQuad); m_LockMouse = false; s_Operation = OP_NONE; UI()->SetActiveItem(0); @@ -1245,8 +1220,7 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V) { if(!UI()->MouseButton(1)) { - static int s_PointPopupID = 0; - UiInvokePopupMenu(&s_PointPopupID, 0, UI()->MouseX(), UI()->MouseY(), 120, 150, PopupPoint); + UI()->DoPopupMenu(UI()->MouseX(), UI()->MouseY(), 120, 150, this, PopupPoint); UI()->SetActiveItem(0); } } @@ -2177,7 +2151,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * CUIRect Label, Shifter; Slot.VSplitMid(&Label, &Shifter); Shifter.HMargin(1.0f, &Shifter); - UI()->DoLabel(&Label, pProps[i].m_pName, 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, pProps[i].m_pName, 10.0f, TEXTALIGN_LEFT); if(pProps[i].m_Type == PROPTYPE_INT_STEP) { @@ -2188,7 +2162,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * Shifter.VSplitLeft(10.0f, &Dec, &Shifter); str_format(aBuf, sizeof(aBuf),"%d", pProps[i].m_Value); Shifter.Draw(vec4(1,1,1,0.5f), 0.0f, CUIRect::CORNER_NONE); - UI()->DoLabel(&Shifter, aBuf, 10.0f,CUI::ALIGN_CENTER); + UI()->DoLabel(&Shifter, aBuf, 10.0f,TEXTALIGN_CENTER); if(DoButton_ButtonDec(&pIDs[i], 0, 0, &Dec, 0, "Decrease")) { @@ -2258,14 +2232,13 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * ((pProps[i].m_Value >> s_aShift[2])&0xff)/255.0f, 1.0f); - static int s_ColorPicker, s_ColorPickerID; - ColorBox.Draw(Color, 0.0f, CUIRect::CORNER_NONE); + static int s_ColorPicker; if(DoButton_Editor_Common(&s_ColorPicker, 0x0, 0, &ColorBox, 0, 0x0)) { m_InitialPickerColor = RgbToHsv(vec3(Color.r, Color.g, Color.b)); m_SelectedPickerColor = m_InitialPickerColor; - UiInvokePopupMenu(&s_ColorPickerID, 0, UI()->MouseX(), UI()->MouseY(), 180, 180, PopupColorPicker); + UI()->DoPopupMenu(UI()->MouseX(), UI()->MouseY(), 180, 180, this, PopupColorPicker); } if(m_InitialPickerColor != m_SelectedPickerColor) @@ -2306,11 +2279,11 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * Left.VSplitLeft(10.0f, &Left, &Shifter); Shifter.VSplitRight(10.0f, &Shifter, &Right); Shifter.Draw(vec4(1,1,1,0.5f), 0.0f, CUIRect::CORNER_NONE); - UI()->DoLabel(&Shifter, "X", 10.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Shifter, "X", 10.0f, TEXTALIGN_CENTER); Up.VSplitLeft(10.0f, &Up, &Shifter); Shifter.VSplitRight(10.0f, &Shifter, &Down); Shifter.Draw(vec4(1,1,1,0.5f), 0.0f, CUIRect::CORNER_NONE); - UI()->DoLabel(&Shifter, "Y", 10.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Shifter, "Y", 10.0f, TEXTALIGN_CENTER); if(DoButton_ButtonDec(&pIDs[i], "-", 0, &Left, 0, "Left")) { *pNewVal = 1; @@ -2418,9 +2391,8 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) m_SelectedGroup = g; m_SelectedLayer = 0; - static int s_GroupPopupId = 0; if(Result == 2) - UiInvokePopupMenu(&s_GroupPopupId, 0, UI()->MouseX(), UI()->MouseY(), 145, 220, PopupGroup); + UI()->DoPopupMenu(UI()->MouseX(), UI()->MouseY(), 145, 220, this, PopupGroup); if(m_Map.m_lGroups[g]->m_lLayers.size() && Input()->MouseDoubleClick()) m_Map.m_lGroups[g]->m_Collapse ^= 1; @@ -2469,9 +2441,8 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) { m_SelectedLayer = i; m_SelectedGroup = g; - static int s_LayerPopupID = 0; if(Result == 2) - UiInvokePopupMenu(&s_LayerPopupID, 0, UI()->MouseX(), UI()->MouseY(), 120, 245, PopupLayer); + UI()->DoPopupMenu(UI()->MouseX(), UI()->MouseY(), 120, 245, this, PopupLayer); } LayerCur += 14.0f; @@ -2671,7 +2642,7 @@ void CEditor::RenderImagesList(CUIRect ToolBox) if(ImageCur >= ImageStartAt) { ToolBox.HSplitTop(HeaderHeight, &Slot, &ToolBox); - UI()->DoLabel(&Slot, e == 0 ? "Embedded" : "External", 12.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Slot, e == 0 ? "Embedded" : "External", 12.0f, TEXTALIGN_CENTER); } ImageCur += HeaderHeight; @@ -2717,9 +2688,8 @@ void CEditor::RenderImagesList(CUIRect ToolBox) { m_SelectedImage = i; - static int s_PopupImageID = 0; if(Result == 2) - UiInvokePopupMenu(&s_PopupImageID, 0, UI()->MouseX(), UI()->MouseY(), 120, 80, PopupImage); + UI()->DoPopupMenu(UI()->MouseX(), UI()->MouseY(), 120, 80, this, PopupImage); } ToolBox.HSplitTop(2.0f, 0, &ToolBox); @@ -2869,7 +2839,7 @@ void CEditor::RenderFileDialog() // title Title.Draw(vec4(1, 1, 1, 0.25f), 4.0f); Title.VMargin(10.0f, &Title); - UI()->DoLabel(&Title, m_pFileDialogTitle, 12.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Title, m_pFileDialogTitle, 12.0f, TEXTALIGN_LEFT); // pathbox char aPath[128], aBuf[128]; @@ -2878,12 +2848,12 @@ void CEditor::RenderFileDialog() else aPath[0] = 0; str_format(aBuf, sizeof(aBuf), "Current path: %s", aPath); - UI()->DoLabel(&PathBox, aBuf, 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&PathBox, aBuf, 10.0f, TEXTALIGN_LEFT); // filebox if(m_FileDialogStorageType == IStorage::TYPE_SAVE) { - UI()->DoLabel(&FileBoxLabel, "Filename:", 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&FileBoxLabel, "Filename:", 10.0f, TEXTALIGN_LEFT); static CLineInput s_FileNameInput(m_aFileDialogFileName, sizeof(m_aFileDialogFileName)); if(DoEditBox(&s_FileNameInput, &FileBox, 10.0f)) { @@ -2897,7 +2867,7 @@ void CEditor::RenderFileDialog() else { // render search bar - UI()->DoLabel(&FileBoxLabel, "Search:", 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&FileBoxLabel, "Search:", 10.0f, TEXTALIGN_LEFT); if(DoEditBox(&m_FileDialogFilterInput, &FileBox, 10.0f)) { // reset scrolling @@ -3110,8 +3080,7 @@ void CEditor::RenderFileDialog() { m_aFileDialogNewFolderName[0] = 0; m_aFileDialogErrString[0] = 0; - static int s_NewFolderPopupID = 0; - UiInvokePopupMenu(&s_NewFolderPopupID, 0, Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, PopupNewFolder); + UI()->DoPopupMenu(Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, this, PopupNewFolder); UI()->SetActiveItem(0); } } @@ -3126,8 +3095,7 @@ void CEditor::RenderFileDialog() str_copy(m_Map.m_MapInfoTmp.m_aVersion, m_Map.m_MapInfo.m_aVersion, sizeof(m_Map.m_MapInfoTmp.m_aVersion)); str_copy(m_Map.m_MapInfoTmp.m_aCredits, m_Map.m_MapInfo.m_aCredits, sizeof(m_Map.m_MapInfoTmp.m_aCredits)); str_copy(m_Map.m_MapInfoTmp.m_aLicense, m_Map.m_MapInfo.m_aLicense, sizeof(m_Map.m_MapInfoTmp.m_aLicense)); - static int s_MapInfoPopupID = 0; - UiInvokePopupMenu(&s_MapInfoPopupID, 0, Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, PopupMapInfo); + UI()->DoPopupMenu(Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, this, PopupMapInfo); UI()->SetActiveItem(0); } } @@ -3218,10 +3186,10 @@ void CEditor::RenderStatusbar(CUIRect View) { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s Right click for context menu.", m_pTooltip); - UI()->DoLabel(&View, aBuf, 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&View, aBuf, 10.0f, TEXTALIGN_LEFT); } else - UI()->DoLabel(&View, m_pTooltip, 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&View, m_pTooltip, 10.0f, TEXTALIGN_LEFT); } } @@ -3299,7 +3267,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) char aBuf[IO_MAX_PATH_LENGTH]; str_format(aBuf, sizeof(aBuf),"%d/%d", m_SelectedEnvelope+1, m_Map.m_lEnvelopes.size()); Shifter.Draw(vec4(1,1,1,0.5f), 0.0f, CUIRect::CORNER_NONE); - UI()->DoLabel(&Shifter, aBuf, 10.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&Shifter, aBuf, 10.0f, TEXTALIGN_CENTER); static int s_PrevButton = 0; if(DoButton_ButtonDec(&s_PrevButton, 0, 0, &Dec, 0, "Previous Envelope")) @@ -3313,7 +3281,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) { ToolBar.VSplitLeft(15.0f, &Button, &ToolBar); ToolBar.VSplitLeft(35.0f, &Button, &ToolBar); - UI()->DoLabel(&Button, "Name:", 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, "Name:", 10.0f, TEXTALIGN_LEFT); ToolBar.VSplitLeft(80.0f, &Button, &ToolBar); @@ -3376,7 +3344,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) ToolBar.VSplitLeft(4.0f, &Button, &ToolBar); ToolBar.VSplitLeft(80.0f, &Button, &ToolBar); - UI()->DoLabel(&Button, "Synchronized", 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Button, "Synchronized", 10.0f, TEXTALIGN_LEFT); } float EndTime = pEnvelope->EndTime(); @@ -3862,21 +3830,20 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) char aBuf[512]; str_format(aBuf, sizeof(aBuf),"%.3f %.3f", CurrentTime/1000.0f, fx2f(CurrentValue)); - UI()->DoLabel(&ToolBar, aBuf, 10.0f, CUI::ALIGN_CENTER); + UI()->DoLabel(&ToolBar, aBuf, 10.0f, TEXTALIGN_CENTER); } } } void CEditor::RenderMenubar(CUIRect MenuBar) { - CUIRect ExitButton; - static CUIRect s_File /*, view, help*/; - - MenuBar.VSplitLeft(60.0f, &s_File, &MenuBar); - if(DoButton_Menu(&s_File, "File", 0, &s_File, 0, 0)) - UiInvokePopupMenu(&s_File, 1, s_File.x, s_File.y+s_File.h-1.0f, 120, 150, PopupMenuFile, this); + CUIRect FileButton; + static int s_FileButton; + MenuBar.VSplitLeft(60.0f, &FileButton, &MenuBar); + if(DoButton_Menu(&s_FileButton, "File", 0, &FileButton, 0, 0)) + UI()->DoPopupMenu(FileButton.x, FileButton.y+FileButton.h-1.0f, 120, 150, this, PopupMenuFile, CUIRect::CORNER_R|CUIRect::CORNER_B); - CUIRect Info; + CUIRect Info, ExitButton; MenuBar.VSplitRight(20.f, &MenuBar, &ExitButton); MenuBar.VSplitLeft(40.0f, 0, &MenuBar); MenuBar.VSplitLeft(MenuBar.w*0.75f, &MenuBar, &Info); @@ -3884,10 +3851,10 @@ void CEditor::RenderMenubar(CUIRect MenuBar) char aBuf[128]; str_format(aBuf, sizeof(aBuf), "File: %s", m_aFileName); - UI()->DoLabel(&MenuBar, aBuf, 10.0f, CUI::ALIGN_LEFT); + UI()->DoLabel(&MenuBar, aBuf, 10.0f, TEXTALIGN_LEFT); str_format(aBuf, sizeof(aBuf), "Z: %i, A: %.1f, G: %i", m_ZoomLevel, m_AnimateSpeed, m_GridFactor); - UI()->DoLabel(&Info, aBuf, 10.0f, CUI::ALIGN_RIGHT); + UI()->DoLabel(&Info, aBuf, 10.0f, TEXTALIGN_RIGHT); // Exit editor button static int s_ExitButton; @@ -4032,14 +3999,12 @@ void CEditor::Render() if(m_PopupEventActivated) { - static int s_PopupID = 0; - UiInvokePopupMenu(&s_PopupID, 0, Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, PopupEvent); + UI()->DoPopupMenu(Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, this, PopupEvent); m_PopupEventActivated = false; m_PopupEventWasActivated = true; } - - UiDoPopupMenu(); + UI()->RenderPopupMenus(); if(m_GuiActive) RenderStatusbar(StatusBar); diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 5271a7149..d90a86eab 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -781,26 +781,23 @@ public: void RenderGrid(CLayerGroup *pGroup); - void UiInvokePopupMenu(void *pID, int Flags, float X, float Y, float W, float H, int (*pfnFunc)(CEditor *pEditor, CUIRect Rect), void *pExtra=0); - void UiDoPopupMenu(); - int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip); - static int PopupGroup(CEditor *pEditor, CUIRect View); - static int PopupLayer(CEditor *pEditor, CUIRect View); - static int PopupQuad(CEditor *pEditor, CUIRect View); - static int PopupPoint(CEditor *pEditor, CUIRect View); - static int PopupNewFolder(CEditor *pEditor, CUIRect View); - static int PopupMapInfo(CEditor *pEditor, CUIRect View); - static int PopupEvent(CEditor *pEditor, CUIRect View); - static int PopupSelectImage(CEditor *pEditor, CUIRect View); - static int PopupSelectGametileOp(CEditor *pEditor, CUIRect View); - static int PopupImage(CEditor *pEditor, CUIRect View); - static int PopupMenuFile(CEditor *pEditor, CUIRect View); - static int PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View); - static int PopupSelectDoodadRuleSet(CEditor *pEditor, CUIRect View); - static int PopupDoodadAutoMap(CEditor *pEditor, CUIRect View); - static int PopupColorPicker(CEditor *pEditor, CUIRect View); + static bool PopupGroup(void *pContext, CUIRect View); + static bool PopupLayer(void *pContext, CUIRect View); + static bool PopupQuad(void *pContext, CUIRect View); + static bool PopupPoint(void *pContext, CUIRect View); + static bool PopupNewFolder(void *pContext, CUIRect View); + static bool PopupMapInfo(void *pContext, CUIRect View); + static bool PopupEvent(void *pContext, CUIRect View); + static bool PopupSelectImage(void *pContext, CUIRect View); + static bool PopupSelectGametileOp(void *pContext, CUIRect View); + static bool PopupImage(void *pContext, CUIRect View); + static bool PopupMenuFile(void *pContext, CUIRect View); + static bool PopupSelectConfigAutoMap(void *pContext, CUIRect View); + static bool PopupSelectDoodadRuleSet(void *pContext, CUIRect View); + static bool PopupDoodadAutoMap(void *pContext, CUIRect View); + static bool PopupColorPicker(void *pContext, CUIRect View); static void CallbackOpenMap(const char *pFileName, int StorageType, void *pUser); static void CallbackAppendMap(const char *pFileName, int StorageType, void *pUser); diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index a0ecd36a4..0ddd73e5c 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -13,85 +13,9 @@ #include "editor.h" - -// popup menu handling -static struct -{ - CUIRect m_Rect; - void *m_pId; - int (*m_pfnFunc)(CEditor *pEditor, CUIRect Rect); - int m_IsMenu; - void *m_pExtra; -} s_UiPopups[8]; - -static int g_UiNumPopups = 0; - -void CEditor::UiInvokePopupMenu(void *pID, int Flags, float x, float y, float Width, float Height, int (*pfnFunc)(CEditor *pEditor, CUIRect Rect), void *pExtra) -{ - if(x + Width > UI()->Screen()->w) - x -= Width; - if(y + Height > UI()->Screen()->h) - y -= Height; - s_UiPopups[g_UiNumPopups].m_pId = pID; - s_UiPopups[g_UiNumPopups].m_IsMenu = Flags; - s_UiPopups[g_UiNumPopups].m_Rect.x = x; - s_UiPopups[g_UiNumPopups].m_Rect.y = y; - s_UiPopups[g_UiNumPopups].m_Rect.w = Width; - s_UiPopups[g_UiNumPopups].m_Rect.h = Height; - s_UiPopups[g_UiNumPopups].m_pfnFunc = pfnFunc; - s_UiPopups[g_UiNumPopups].m_pExtra = pExtra; - g_UiNumPopups++; -} - -void CEditor::UiDoPopupMenu() -{ - for(int i = 0; i < g_UiNumPopups; i++) - { - bool Inside = UI()->MouseInside(&s_UiPopups[i].m_Rect); - UI()->SetHotItem(&s_UiPopups[i].m_pId); - - if(UI()->CheckActiveItem(&s_UiPopups[i].m_pId)) - { - if(!UI()->MouseButton(0)) - { - if(!Inside) - g_UiNumPopups--; - UI()->SetActiveItem(0); - } - } - else if(UI()->HotItem() == &s_UiPopups[i].m_pId) - { - if(UI()->MouseButton(0)) - UI()->SetActiveItem(&s_UiPopups[i].m_pId); - } - - int Corners = CUIRect::CORNER_ALL; - if(s_UiPopups[i].m_IsMenu) - Corners = CUIRect::CORNER_R|CUIRect::CORNER_B; - - CUIRect r = s_UiPopups[i].m_Rect; - r.Draw(vec4(0.5f,0.5f,0.5f,0.75f), 3.0f, Corners); - r.Margin(1.0f, &r); - r.Draw(vec4(0,0,0,0.75f), 3.0f, Corners); - r.Margin(4.0f, &r); - - if(s_UiPopups[i].m_pfnFunc(this, r)) - { - g_UiNumPopups--; - UI()->SetActiveItem(0); - } - - if(Input()->KeyPress(KEY_ESCAPE)) - { - g_UiNumPopups--; - UI()->SetActiveItem(0); - } - } -} - - -int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) +bool CEditor::PopupGroup(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; // remove group button CUIRect Button; View.HSplitBottom(12.0f, &View, &Button); @@ -104,7 +28,7 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) { pEditor->m_Map.DeleteGroup(pEditor->m_SelectedGroup); pEditor->m_SelectedGroup = maximum(0, pEditor->m_SelectedGroup-1); - return 1; + return true; } } else @@ -144,7 +68,7 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) } } - return 1; + return true; } } @@ -159,7 +83,7 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->AddLayer(l); pEditor->m_SelectedLayer = pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_lLayers.size()-1; pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_Collapse = false; - return 1; + return true; } // new tile layer @@ -173,7 +97,7 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->AddLayer(l); pEditor->m_SelectedLayer = pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_lLayers.size()-1; pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_Collapse = false; - return 1; + return true; } // group name @@ -181,7 +105,7 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) { View.HSplitBottom(5.0f, &View, &Button); View.HSplitBottom(16.0f, &View, &Button); - pEditor->UI()->DoLabel(&Button, "Name:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Button, "Name:", 10.0f, TEXTALIGN_LEFT); Button.VSplitLeft(40.0f, 0, &Button); static CLineInput s_NameInput; s_NameInput.SetBuffer(pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_aName, sizeof(pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_aName)); @@ -247,11 +171,12 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) else if(Prop == PROP_CLIP_H) pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipH = NewVal; } - return 0; + return false; } -int CEditor::PopupLayer(CEditor *pEditor, CUIRect View) +bool CEditor::PopupLayer(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CLayer *pCurrentLayer = pEditor->GetSelectedLayer(0); bool IsGameLayer = pEditor->m_Map.m_pGameLayer == pCurrentLayer; @@ -264,7 +189,7 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View) if(!IsGameLayer && pEditor->DoButton_Editor(&s_DeleteButton, "Delete layer", 0, &Button, 0, "Deletes the layer")) { pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->DeleteLayer(pEditor->m_SelectedLayer); - return 1; + return true; } // layer name @@ -272,7 +197,7 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View) { View.HSplitBottom(5.0f, &View, &Button); View.HSplitBottom(16.0f, &View, &Button); - pEditor->UI()->DoLabel(&Button, "Name:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Button, "Name:", 10.0f, TEXTALIGN_LEFT); Button.VSplitLeft(40.0f, 0, &Button); static CLineInput s_NameInput; s_NameInput.SetBuffer(pCurrentLayer->m_aName, sizeof(pCurrentLayer->m_aName)); @@ -333,8 +258,9 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View) return pCurrentLayer->RenderProperties(&View); } -int CEditor::PopupQuad(CEditor *pEditor, CUIRect View) +bool CEditor::PopupQuad(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CQuad *pQuad = pEditor->GetSelectedQuad(); CUIRect Button; @@ -351,7 +277,7 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View) pLayer->m_lQuads.remove_index(pEditor->m_SelectedQuad); pEditor->m_SelectedQuad--; } - return 1; + return true; } // aspect ratio button @@ -381,7 +307,7 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View) pQuad->m_aPoints[2].x = Left; pQuad->m_aPoints[2].y = Top+Height; pQuad->m_aPoints[3].x = Right; pQuad->m_aPoints[3].y = Top+Height; pEditor->m_Map.m_Modified = true; - return 1; + return true; } } @@ -397,7 +323,7 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View) pQuad->m_aPoints[k].y = 1000.0f * (int(pQuad->m_aPoints[k].y) / 1000); } pEditor->m_Map.m_Modified = true; - return 1; + return true; } // square button @@ -424,7 +350,7 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View) pQuad->m_aPoints[2].x = Left; pQuad->m_aPoints[2].y = Bottom; pQuad->m_aPoints[3].x = Right; pQuad->m_aPoints[3].y = Bottom; pEditor->m_Map.m_Modified = true; - return 1; + return true; } // center pivot button @@ -449,7 +375,7 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View) pQuad->m_aPoints[4].x = Left+int((Right-Left)/2); pQuad->m_aPoints[4].y = Top+int((Bottom-Top)/2); pEditor->m_Map.m_Modified = true; - return 1; + return true; } enum @@ -523,11 +449,12 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View) } if(Prop == PROP_COLOR_ENV_OFFSET) pQuad->m_ColorEnvOffset = NewVal; - return 0; + return false; } -int CEditor::PopupPoint(CEditor *pEditor, CUIRect View) +bool CEditor::PopupPoint(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CQuad *pQuad = pEditor->GetSelectedQuad(); enum @@ -615,17 +542,18 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View) pQuad->m_aTexcoords[v].y = f2fx(NewVal/1024.0f); } - return 0; + return false; } -int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View) +bool CEditor::PopupNewFolder(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CUIRect Label, ButtonBar; // title View.HSplitTop(10.0f, 0, &View); View.HSplitTop(30.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Create new folder", 20.0f, CUI::ALIGN_CENTER); + pEditor->UI()->DoLabel(&Label, "Create new folder", 20.0f, TEXTALIGN_CENTER); View.HSplitBottom(10.0f, &View, 0); View.HSplitBottom(20.0f, &View, &ButtonBar); @@ -639,7 +567,7 @@ int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View) static CLineInput s_FolderInput(pEditor->m_aFileDialogNewFolderName, sizeof(pEditor->m_aFileDialogNewFolderName)); pEditor->DoEditBox(&s_FolderInput, &Label, 15.0f); View.HSplitBottom(20.0f, &View, &Label); - pEditor->UI()->DoLabel(&Label, "Name:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "Name:", 10.0f, TEXTALIGN_LEFT); // button bar ButtonBar.VSplitLeft(30.0f, 0, &ButtonBar); @@ -655,7 +583,7 @@ int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View) if(pEditor->Storage()->CreateFolder(aBuf, IStorage::TYPE_SAVE)) { pEditor->FilelistPopulate(IStorage::TYPE_SAVE); - return 1; + return true; } else str_copy(pEditor->m_aFileDialogErrString, "Unable to create the folder", sizeof(pEditor->m_aFileDialogErrString)); @@ -665,7 +593,7 @@ int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View) ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label); static int s_AbortButton = 0; if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, 0)) - return 1; + return true; } else { @@ -673,28 +601,29 @@ int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View) View.HSplitTop(30.0f, 0, &View); View.VMargin(40.0f, &View); View.HSplitTop(20.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Error:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "Error:", 10.0f, TEXTALIGN_LEFT); View.HSplitTop(20.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Unable to create the folder", 10.0f, CUI::ALIGN_LEFT, View.w); + pEditor->UI()->DoLabel(&Label, "Unable to create the folder", 10.0f, TEXTALIGN_LEFT, View.w); // button ButtonBar.VMargin(ButtonBar.w/2.0f-55.0f, &ButtonBar); static int s_CreateButton = 0; if(pEditor->DoButton_Editor(&s_CreateButton, "Ok", 0, &ButtonBar, 0, 0)) - return 1; + return true; } - return 0; + return false; } -int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View) +bool CEditor::PopupMapInfo(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CUIRect Label, ButtonBar, Button; // title View.HSplitTop(10.0f, 0, &View); View.HSplitTop(30.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Map details", 20.0f, CUI::ALIGN_CENTER); + pEditor->UI()->DoLabel(&Label, "Map details", 20.0f, TEXTALIGN_CENTER); View.HSplitBottom(10.0f, &View, 0); View.HSplitBottom(20.0f, &View, &ButtonBar); @@ -703,7 +632,7 @@ int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View) // author box View.HSplitTop(20.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Author:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "Author:", 10.0f, TEXTALIGN_LEFT); Label.VSplitLeft(40.0f, 0, &Button); Button.HSplitTop(16.0f, &Button, 0); static CLineInput s_AuthorInput; @@ -712,7 +641,7 @@ int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View) // version box View.HSplitTop(20.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Version:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "Version:", 10.0f, TEXTALIGN_LEFT); Label.VSplitLeft(40.0f, 0, &Button); Button.HSplitTop(16.0f, &Button, 0); static CLineInput s_VersionInput; @@ -721,7 +650,7 @@ int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View) // credits box View.HSplitTop(20.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Credits:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "Credits:", 10.0f, TEXTALIGN_LEFT); Label.VSplitLeft(40.0f, 0, &Button); Button.HSplitTop(16.0f, &Button, 0); static CLineInput s_CreditsInput; @@ -730,7 +659,7 @@ int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View) // license box View.HSplitTop(20.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "License:", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "License:", 10.0f, TEXTALIGN_LEFT); Label.VSplitLeft(40.0f, 0, &Button); Button.HSplitTop(16.0f, &Button, 0); static CLineInput s_LicenseInput; @@ -747,35 +676,36 @@ int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View) str_copy(pEditor->m_Map.m_MapInfo.m_aVersion, pEditor->m_Map.m_MapInfoTmp.m_aVersion, sizeof(pEditor->m_Map.m_MapInfo.m_aVersion)); str_copy(pEditor->m_Map.m_MapInfo.m_aCredits, pEditor->m_Map.m_MapInfoTmp.m_aCredits, sizeof(pEditor->m_Map.m_MapInfo.m_aCredits)); str_copy(pEditor->m_Map.m_MapInfo.m_aLicense, pEditor->m_Map.m_MapInfoTmp.m_aLicense, sizeof(pEditor->m_Map.m_MapInfo.m_aLicense)); - return 1; + return true; } ButtonBar.VSplitRight(30.0f, &ButtonBar, 0); ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label); static int s_AbortButton = 0; if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, 0)) - return 1; + return true; - return 0; + return false; } -int CEditor::PopupEvent(CEditor *pEditor, CUIRect View) +bool CEditor::PopupEvent(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CUIRect Label, ButtonBar; // title View.HSplitTop(10.0f, 0, &View); View.HSplitTop(30.0f, &Label, &View); if(pEditor->m_PopupEventType == POPEVENT_EXIT) - pEditor->UI()->DoLabel(&Label, "Exit the editor", 20.0f, CUI::ALIGN_CENTER); + pEditor->UI()->DoLabel(&Label, "Exit the editor", 20.0f, TEXTALIGN_CENTER); else if(pEditor->m_PopupEventType == POPEVENT_LOAD) - pEditor->UI()->DoLabel(&Label, "Load map", 20.0f, CUI::ALIGN_CENTER); + pEditor->UI()->DoLabel(&Label, "Load map", 20.0f, TEXTALIGN_CENTER); else if(pEditor->m_PopupEventType == POPEVENT_LOAD_CURRENT) - pEditor->UI()->DoLabel(&Label, "Load current map", 20.0f, CUI::ALIGN_CENTER); + pEditor->UI()->DoLabel(&Label, "Load current map", 20.0f, TEXTALIGN_CENTER); else if(pEditor->m_PopupEventType == POPEVENT_NEW) - pEditor->UI()->DoLabel(&Label, "New map", 20.0f, CUI::ALIGN_CENTER); + pEditor->UI()->DoLabel(&Label, "New map", 20.0f, TEXTALIGN_CENTER); else if(pEditor->m_PopupEventType == POPEVENT_SAVE) - pEditor->UI()->DoLabel(&Label, "Save map", 20.0f, CUI::ALIGN_CENTER); + pEditor->UI()->DoLabel(&Label, "Save map", 20.0f, TEXTALIGN_CENTER); View.HSplitBottom(10.0f, &View, 0); View.HSplitBottom(20.0f, &View, &ButtonBar); @@ -785,15 +715,15 @@ int CEditor::PopupEvent(CEditor *pEditor, CUIRect View) View.VMargin(40.0f, &View); View.HSplitTop(20.0f, &Label, &View); if(pEditor->m_PopupEventType == POPEVENT_EXIT) - pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you exit the editor.\nContinue anyway?", 10.0f, CUI::ALIGN_LEFT, Label.w-10.0f); + pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you exit the editor.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Label.w-10.0f); else if(pEditor->m_PopupEventType == POPEVENT_LOAD) - pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you load a new map.\nContinue anyway?", 10.0f, CUI::ALIGN_LEFT, Label.w-10.0f); + pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you load a new map.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Label.w-10.0f); else if(pEditor->m_PopupEventType == POPEVENT_LOAD_CURRENT) - pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you load the current map.\nContinue anyway?", 10.0f, CUI::ALIGN_LEFT, Label.w-10.0f); + pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you load the current map.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Label.w-10.0f); else if(pEditor->m_PopupEventType == POPEVENT_NEW) - pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you create a new map.\nContinue anyway?", 10.0f, CUI::ALIGN_LEFT, Label.w-10.0f); + pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you create a new map.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Label.w-10.0f); else if(pEditor->m_PopupEventType == POPEVENT_SAVE) - pEditor->UI()->DoLabel(&Label, "The file already exists.\nDo you want to overwrite the map?", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "The file already exists.\nDo you want to overwrite the map?", 10.0f, TEXTALIGN_LEFT); // button bar ButtonBar.VSplitLeft(30.0f, 0, &ButtonBar); @@ -815,7 +745,7 @@ int CEditor::PopupEvent(CEditor *pEditor, CUIRect View) else if(pEditor->m_PopupEventType == POPEVENT_SAVE) pEditor->CallbackSaveMap(pEditor->m_aFileSaveName, IStorage::TYPE_SAVE, pEditor); pEditor->m_PopupEventWasActivated = false; - return 1; + return true; } ButtonBar.VSplitRight(30.0f, &ButtonBar, 0); ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label); @@ -823,24 +753,27 @@ int CEditor::PopupEvent(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, 0)) { pEditor->m_PopupEventWasActivated = false; - return 1; + return true; } - return 0; + return false; } static int g_SelectImageSelected = -100; static int g_SelectImageCurrent = -100; -int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View) +bool CEditor::PopupSelectImage(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CUIRect ButtonBar, ImageView; View.VSplitLeft(80.0f, &ButtonBar, &View); View.Margin(10.0f, &ImageView); int ShowImage = g_SelectImageCurrent; + bool ClosePopup = false; + static int s_NoImageButton; for(int i = -1; i < pEditor->m_Map.m_lImages.size(); i++) { CUIRect Button; @@ -850,15 +783,10 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View) if(pEditor->UI()->MouseInside(&Button)) ShowImage = i; - if(i == -1) - { - if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_lImages[i], "None", i==g_SelectImageCurrent, &Button)) - g_SelectImageSelected = -1; - } - else + if(pEditor->DoButton_MenuItem(i == -1 ? (void *)&s_NoImageButton : &pEditor->m_Map.m_lImages[i], i == -1 ? "None" : pEditor->m_Map.m_lImages[i]->m_aName, i == g_SelectImageCurrent, &Button)) { - if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_lImages[i], pEditor->m_Map.m_lImages[i]->m_aName, i==g_SelectImageCurrent, &Button)) - g_SelectImageSelected = i; + g_SelectImageSelected = i; + ClosePopup |= pEditor->Input()->MouseDoubleClick(); } } @@ -881,15 +809,14 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View) pEditor->Graphics()->WrapNormal(); } - return 0; + return ClosePopup; } void CEditor::PopupSelectImageInvoke(int Current, float x, float y) { - static int s_SelectImagePopupId = 0; g_SelectImageSelected = -100; g_SelectImageCurrent = Current; - UiInvokePopupMenu(&s_SelectImagePopupId, 0, x, y, 400, 300, PopupSelectImage); + UI()->DoPopupMenu(x, y, 400, 300, this, PopupSelectImage); } int CEditor::PopupSelectImageResult() @@ -904,8 +831,9 @@ int CEditor::PopupSelectImageResult() static int s_GametileOpSelected = -1; -int CEditor::PopupSelectGametileOp(CEditor *pEditor, CUIRect View) +bool CEditor::PopupSelectGametileOp(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; static const char *s_pButtonNames[] = { "Clear", "Collision", "Death", "Unhookable" }; static unsigned s_NumButtons = sizeof(s_pButtonNames) / sizeof(char*); CUIRect Button; @@ -918,14 +846,13 @@ int CEditor::PopupSelectGametileOp(CEditor *pEditor, CUIRect View) s_GametileOpSelected = i; } - return 0; + return false; } void CEditor::PopupSelectGametileOpInvoke(float x, float y) { - static int s_SelectGametileOpPopupId = 0; s_GametileOpSelected = -1; - UiInvokePopupMenu(&s_SelectGametileOpPopupId, 0, x, y, 120.0f, 70.0f, PopupSelectGametileOp); + UI()->DoPopupMenu(x, y, 120.0f, 70.0f, this, PopupSelectGametileOp); } int CEditor::PopupSelectGameTileOpResult() @@ -940,8 +867,9 @@ int CEditor::PopupSelectGameTileOpResult() static bool s_AutoMapProceedOrder = false; -int CEditor::PopupDoodadAutoMap(CEditor *pEditor, CUIRect View) +bool CEditor::PopupDoodadAutoMap(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CLayerTiles *pLayer = static_cast<CLayerTiles*>(pEditor->GetSelectedLayer(0)); IAutoMapper *pMapper = pEditor->m_Map.m_lImages[pLayer->m_Image]->m_pAutoMapper; CUIRect Rect; @@ -951,8 +879,8 @@ int CEditor::PopupDoodadAutoMap(CEditor *pEditor, CUIRect View) // ruleset selection static int s_ChooseDoodadRuleset = 0; if(pEditor->DoButton_Editor(&s_ChooseDoodadRuleset, pMapper->GetRuleSetName(pLayer->m_SelectedRuleSet), 0, &Rect, 0, 0)) - pEditor->UiInvokePopupMenu(&s_ChooseDoodadRuleset, 0, pEditor->UI()->MouseX(), pEditor->UI()->MouseY(), - 120.0f, 12.0f+14.0f*pMapper->RuleSetNum(), PopupSelectDoodadRuleSet); + pEditor->UI()->DoPopupMenu(pEditor->UI()->MouseX(), pEditor->UI()->MouseY(), + 120.0f, 12.0f+14.0f*pMapper->RuleSetNum(), pEditor, PopupSelectDoodadRuleSet); View.HMargin(3.f, &View); View.HSplitTop(15.0f, &Rect, &View); @@ -973,11 +901,12 @@ int CEditor::PopupDoodadAutoMap(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_Editor(&s_ButtonDoodadGenerate, "Generate", 0, &Rect, 0, 0)) s_AutoMapProceedOrder = true; - return 0; + return false; } -int CEditor::PopupSelectDoodadRuleSet(CEditor *pEditor, CUIRect View) +bool CEditor::PopupSelectDoodadRuleSet(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CLayerTiles *pLayer = static_cast<CLayerTiles*>(pEditor->GetSelectedLayer(0)); CUIRect Button; static int s_AutoMapperDoodadButtons[IAutoMapper::MAX_RULES]; @@ -990,15 +919,16 @@ int CEditor::PopupSelectDoodadRuleSet(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_Editor(&s_AutoMapperDoodadButtons[i], pMapper->GetRuleSetName(i), 0, &Button, 0, 0)) { pLayer->m_SelectedRuleSet = i; - return 1; // close the popup + return true; // close the popup } } - return 0; + return false; } -int CEditor::PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View) +bool CEditor::PopupSelectConfigAutoMap(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CLayerTiles *pLayer = static_cast<CLayerTiles*>(pEditor->GetSelectedLayer(0)); CUIRect Button; static int s_AutoMapperConfigButtons[IAutoMapper::MAX_RULES]; @@ -1022,7 +952,7 @@ int CEditor::PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View) CUIRect Label, Full, Live; View.VSplitMid(&Label, &View); - pEditor->UI()->DoLabel(&Label, "Type", 10.0f, CUI::ALIGN_LEFT); + pEditor->UI()->DoLabel(&Label, "Type", 10.0f, TEXTALIGN_LEFT); View.VSplitMid(&Full, &Live); if(pEditor->DoButton_ButtonDec(&s_aIds[0], "Full", !pLayer->m_LiveAutoMap, &Full, 0, "")) @@ -1034,21 +964,20 @@ int CEditor::PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View) pLayer->m_LiveAutoMap = true; } - return 0; + return false; } void CEditor::PopupSelectConfigAutoMapInvoke(float x, float y) { - static int s_AutoMapConfigSelectID = 0; CLayerTiles *pLayer = static_cast<CLayerTiles*>(GetSelectedLayer(0)); if(pLayer && pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size() && m_Map.m_lImages[pLayer->m_Image]->m_pAutoMapper->RuleSetNum()) { if(m_Map.m_lImages[pLayer->m_Image]->m_pAutoMapper->GetType() == IAutoMapper::TYPE_TILESET) - UiInvokePopupMenu(&s_AutoMapConfigSelectID, 0, x, y, 120.0f, 12.0f+14.0f*m_Map.m_lImages[pLayer->m_Image]->m_pAutoMapper->RuleSetNum()+14.0f, PopupSelectConfigAutoMap); + UI()->DoPopupMenu(x, y, 120.0f, 12.0f+14.0f*m_Map.m_lImages[pLayer->m_Image]->m_pAutoMapper->RuleSetNum()+14.0f, this, PopupSelectConfigAutoMap); else if(m_Map.m_lImages[pLayer->m_Image]->m_pAutoMapper->GetType() == IAutoMapper::TYPE_DOODADS) - UiInvokePopupMenu(&s_AutoMapConfigSelectID, 0, x, y, 120.0f, 60.0f, PopupDoodadAutoMap); + UI()->DoPopupMenu(x, y, 120.0f, 60.0f, this, PopupDoodadAutoMap); } } @@ -1064,8 +993,9 @@ bool CEditor::PopupAutoMapProceedOrder() return false; } -int CEditor::PopupColorPicker(CEditor *pEditor, CUIRect View) +bool CEditor::PopupColorPicker(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; CUIRect SVPicker, HuePicker, Palette; View.HSplitBottom(20.0f, &SVPicker, &Palette); SVPicker.VSplitRight(20.0f, &SVPicker, &HuePicker); @@ -1176,7 +1106,7 @@ int CEditor::PopupColorPicker(CEditor *pEditor, CUIRect View) pEditor->m_SelectedPickerColor = hsv; - return 0; + return false; } @@ -1189,8 +1119,9 @@ static void ModifyIndexDeleted(int *pIndex) *pIndex = *pIndex - 1; } -int CEditor::PopupImage(CEditor *pEditor, CUIRect View) +bool CEditor::PopupImage(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; static int s_ReplaceButton = 0; static int s_RemoveButton = 0; @@ -1205,7 +1136,7 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_MenuItem(&s_ExternalButton, "Embed", 0, &Slot, 0, "Embeds the image into the map file.")) { pImg->m_External = 0; - return 1; + return true; } } else @@ -1213,7 +1144,7 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_MenuItem(&s_ExternalButton, "Make external", 0, &Slot, 0, "Removes the image from the map file.")) { pImg->m_External = 1; - return 1; + return true; } } @@ -1222,7 +1153,7 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_MenuItem(&s_ReplaceButton, "Replace", 0, &Slot, 0, "Replaces the image with a new one")) { pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_IMG, "Replace Image", "Replace", "mapres", "", ReplaceImage, pEditor); - return 1; + return true; } View.HSplitTop(10.0f, &Slot, &View); @@ -1233,14 +1164,15 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View) pEditor->m_Map.m_lImages.remove_index(pEditor->m_SelectedImage); gs_ModifyIndexDeletedIndex = pEditor->m_SelectedImage; pEditor->m_Map.ModifyImageIndex(ModifyIndexDeleted); - return 1; + return true; } - return 0; + return false; } -int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) +bool CEditor::PopupMenuFile(void *pContext, CUIRect View) { + CEditor *pEditor = (CEditor *)pContext; static int s_NewMapButton = 0; static int s_SaveButton = 0; static int s_SaveAsButton = 0; @@ -1264,7 +1196,7 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) pEditor->Reset(); pEditor->m_aFileName[0] = 0; } - return 1; + return true; } View.HSplitTop(10.0f, &Slot, &View); @@ -1278,7 +1210,7 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) } else pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_MAP, "Load map", "Load", "maps", "", pEditor->CallbackOpenMap, pEditor); - return 1; + return true; } if(pEditor->Client()->State() == IClient::STATE_ONLINE) @@ -1294,7 +1226,7 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) } else pEditor->LoadCurrentMap(); - return 1; + return true; } } @@ -1303,7 +1235,7 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_MenuItem(&s_AppendButton, "Append", 0, &Slot, 0, "Opens a map and adds everything from that map to the current one")) { pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_MAP, "Append map", "Append", "maps", "", pEditor->CallbackAppendMap, pEditor); - return 1; + return true; } View.HSplitTop(10.0f, &Slot, &View); @@ -1318,7 +1250,7 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) } else pEditor->InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_MAP, "Save map", "Save", "maps", "", pEditor->CallbackSaveMap, pEditor); - return 1; + return true; } View.HSplitTop(2.0f, &Slot, &View); @@ -1326,7 +1258,7 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) if(pEditor->DoButton_MenuItem(&s_SaveAsButton, "Save As", 0, &Slot, 0, "Saves the current map under a new name")) { pEditor->InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_MAP, "Save map", "Save", "maps", "", pEditor->CallbackSaveMap, pEditor); - return 1; + return true; } View.HSplitTop(10.0f, &Slot, &View); @@ -1340,8 +1272,8 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) } else pEditor->Config()->m_ClEditor = 0; - return 1; + return true; } - return 0; + return false; } diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 2c52f9d99..dfe4f8ad4 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -32,7 +32,7 @@ CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, bool Dummy, bool AsSpe m_IsReadyToPlay = !GameServer()->m_pController->IsPlayerReadyMode(); m_RespawnDisabled = GameServer()->m_pController->GetStartRespawnState(); m_DeadSpecMode = false; - m_Spawning = 0; + m_Spawning = false; } CPlayer::~CPlayer() diff --git a/src/test/str.cpp b/src/test/str.cpp index c8adb8471..6d066299d 100644 --- a/src/test/str.cpp +++ b/src/test/str.cpp @@ -129,31 +129,35 @@ TEST(Str, Utf8Stats) { int Size, Count; - str_utf8_stats("abc", 4, &Size, &Count); + str_utf8_stats("abc", 4, 3, &Size, &Count); EXPECT_EQ(Size, 3); EXPECT_EQ(Count, 3); - str_utf8_stats("abc", 2, &Size, &Count); + str_utf8_stats("abc", 2, 3, &Size, &Count); EXPECT_EQ(Size, 1); EXPECT_EQ(Count, 1); - str_utf8_stats("", 1, &Size, &Count); + str_utf8_stats("", 1, 0, &Size, &Count); EXPECT_EQ(Size, 0); EXPECT_EQ(Count, 0); - str_utf8_stats("abcde", 6, &Size, &Count); + str_utf8_stats("abcde", 6, 5, &Size, &Count); EXPECT_EQ(Size, 5); EXPECT_EQ(Count, 5); - str_utf8_stats("любовь", 13, &Size, &Count); + str_utf8_stats("любовь", 13, 6, &Size, &Count); EXPECT_EQ(Size, 12); EXPECT_EQ(Count, 6); - str_utf8_stats("abc愛", 7, &Size, &Count); + str_utf8_stats("abc愛", 7, 4, &Size, &Count); EXPECT_EQ(Size, 6); EXPECT_EQ(Count, 4); - str_utf8_stats("abc愛", 6, &Size, &Count); + str_utf8_stats("abc愛", 6, 4, &Size, &Count); EXPECT_EQ(Size, 3); EXPECT_EQ(Count, 3); + + str_utf8_stats("любовь", 13, 3, &Size, &Count); + EXPECT_EQ(Size, 6); + EXPECT_EQ(Count, 3); } |