void CMenus::RenderCrypt(CUIRect MainView) { CUIRect Button, Label, Temp; RenderTools()->DrawUIRect(&MainView, vec4(0.0f, 0.5f, 0.0f, 0.64f), CUI::CORNER_R, 10.0f); MainView.HSplitTop(8.0f, &Button, &Temp); Button.VSplitMid(&Button, &Label); MainView.HSplitTop(6.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(330.0f, &Button, 0); Button.x += 4.0f; if(DoButton_CheckBox(&g_Config.m_ClFlagChat, Localize("Receive hidden chat"), g_Config.m_ClFlagChat, &Button)) g_Config.m_ClFlagChat ^= 1; MainView.HSplitTop(4.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(60.0f, &Label, &Button); Button.VSplitLeft(264.0f, &Button, 0); Label.x += 4.0f; Button.x += 10.0f; UI()->DoLabelScaled(&Label, "RSA key:", 14.0, -1); static float s_OffsetKeyName = 0.0f; static char aKeyName[32] = {}; DoEditBox(&aKeyName, &Button, aKeyName, 32, 14.0f, &s_OffsetKeyName, false, CUI::CORNER_ALL, Localize("Key name")); MainView.HSplitTop(4.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(330.0f, &Button, 0); Label.x += 4.0f; Button.x += 5.0f; static int s_GenButton = 0; if(DoButton_Menu(&s_GenButton, Localize("Generate RSA key"), 0, &Button, Localize("Generates a (128 b) new RSA key you can then save and share"))) { m_pClient->m_pChat->GenerateKeyPair(256, 3); } MainView.HSplitTop(4.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(330.0f, &Button, 0); Button.x += 5.0f; static int s_LoadButton = 0; if(DoButton_Menu(&s_LoadButton, Localize("Load RSA key"), 0, &Button, Localize("Load key with the name you entered above"))) { m_pClient->m_pChat->LoadKeys(aKeyName); } MainView.HSplitTop(4.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(330.0f, &Button, 0); Button.x += 5.0f; static int s_SaveButton = 0; if(DoButton_Menu(&s_SaveButton, Localize("Save RSA key"), 0, &Button, Localize("Save key with the name you entered above"))) { m_pClient->m_pChat->SaveKeys(m_pClient->m_pChat->m_pKeyPair, aKeyName); } }
void CMenus::RenderIdents(CUIRect MainView) { const int NumIdentities = m_pClient->m_pIdentity->NumIdents(); CUIRect Button, Label, Temp; static float s_Scrollbar = 0; static float s_ScrollValue = 0; RenderTools()->DrawUIRect(&MainView, vec4(0.65f, 0.68f, 0.9f, 0.64f), CUI::CORNER_T, 10.0f); MainView.HSplitTop(8.0f, &Button, &Temp); Button.VSplitMid(&Button, &Label); // scrollbar Temp.HSplitTop(16.0f, &Button, &Temp); Button.VMargin(4.0f, &Button); s_ScrollValue = DoScrollbarH(&s_Scrollbar, &Button, s_ScrollValue); Temp.HSplitTop(68.0f, &Button, &Temp); UI()->ClipEnable(&Button); Button.HMargin(5.0f, &Button); Button.VSplitLeft(7.5f, 0, &Button); int Offset = 2*30.0f + 80 * (NumIdentities - 4); if(Offset > 0) Button.x -= Offset * s_ScrollValue; for(int i = 0; i < NumIdentities; i++) { CIdentity::CIdentEntry *pIdent = m_pClient->m_pIdentity->GetIdent(i); if(pIdent == NULL) continue; const CSkins::CSkin *pSkin = NULL; CTeeRenderInfo SkinInfo; pSkin = m_pClient->m_pSkins->Get(m_pClient->m_pSkins->Find(pIdent->m_aSkin)); if(pIdent->m_UseCustomColor) { SkinInfo.m_Texture = pSkin->m_ColorTexture; SkinInfo.m_ColorBody = m_pClient->m_pSkins->GetColorV4(pIdent->m_ColorBody); SkinInfo.m_ColorFeet = m_pClient->m_pSkins->GetColorV4(pIdent->m_ColorFeet); } else { SkinInfo.m_Texture = pSkin->m_OrgTexture; SkinInfo.m_ColorBody = vec4(1.0f, 1.0f, 1.0f, 1.0f); SkinInfo.m_ColorFeet = vec4(1.0f, 1.0f, 1.0f, 1.0f); } Button.VSplitLeft(80.0f, &Label, &Button); static int s_Button[512] = {0}; if(DoButton_Menu(&s_Button[i], "", 0, &Label, 0, CUI::CORNER_ALL, pIdent->m_UseCustomColor ? mix(SkinInfo.m_ColorBody, SkinInfo.m_ColorFeet, 0.4f)*0.7f : vec4(pSkin->m_BloodColor.r, pSkin->m_BloodColor.g, pSkin->m_BloodColor.b, 0.7f))) { CIdentity::CIdentEntry *pIdent = m_pClient->m_pIdentity->GetIdent(i); str_format(g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), pIdent->m_aName); str_format(g_Config.m_PlayerClan, sizeof(g_Config.m_PlayerClan), pIdent->m_aClan); str_format(g_Config.m_ClPlayerSkin, sizeof(g_Config.m_ClPlayerSkin), pIdent->m_aSkin); g_Config.m_ClPlayerUseCustomColor = pIdent->m_UseCustomColor; g_Config.m_ClPlayerColorBody = pIdent->m_ColorBody; g_Config.m_ClPlayerColorFeet = pIdent->m_ColorFeet; m_pClient->SendInfo(false); } SkinInfo.m_Size = 50.0f*UI()->Scale(); RenderTools()->RenderTee(CAnimState::GetIdle(), &SkinInfo, 0, vec2(1, 0), vec2(Label.x + Label.w * 0.5f, Label.y + Label.h * 0.5f + 8.0f)); Label.HSplitBottom(15.0f, 0, &Label); Label.y = Button.y; // some h4XoRinG right here to get awesome R41NB0W!! static float s_Hue = 1000.0f; if(s_Hue > 1.0f) s_Hue = RgbToHsl(vec3(1.0f, 0.0f, 0.0f)).h; s_Hue += 0.0007f; vec3 rgb = HslToRgb(vec3(s_Hue, 1.0f, 0.5f)); RenderTools()->DrawUIRect(&Label, GameClient()->m_pIdentity->UsingIdent(i) ? vec4(rgb.r, rgb.g, rgb.b, 0.71f) : vec4(pSkin->m_BloodColor.r * 0.3f, pSkin->m_BloodColor.g * 0.3f, pSkin->m_BloodColor.b * 0.3f, 0.95f), CUI::CORNER_T, 4.0f); UI()->DoLabelScaled(&Label, pIdent->m_aName, 10.0f, 0); Button.VSplitLeft(15.0f, 0, &Button); } UI()->ClipDisable(); }
// stolen from H-Client :3 void CMenus::RenderIRC(CUIRect MainView) { CALLSTACK_ADD(); static float YOffset = -500.0f; // dunno if a constant is optimal... if(!m_IRCActive) { YOffset = -500.0f; return; } smooth_set(&YOffset, 50.0f, 35.0f, Client()->RenderFrameTime()); // small0r MainView.x = 50; MainView.y = YOffset; MainView.w -= 100; MainView.h -= 100; CUIRect Screen = *UI()->Screen(); Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h); Graphics()->BlendNormal(); RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActiveIngame-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 5.0f); MainView.HSplitTop(15.0f, 0, &MainView); MainView.VSplitLeft(15.0f, 0, &MainView); MainView.Margin(5.0f, &MainView); RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActiveIngame-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 5.0f); CUIRect MainIRC, EntryBox, Button; MainView.Margin(10.0f, &MainIRC); /*if (m_GamePagePanel != PANEL_CHAT && UI()->MouseInside(&MainView) && Input()->KeyPressed(KEY_MOUSE_1)) { m_GamePagePanel = PANEL_CHAT; }*/ if(m_pClient->IRC()->GetState() == IIRC::STATE_DISCONNECTED) { EntryBox.x = MainIRC.x + (MainIRC.w / 2.0f - 300.0f / 2.0f); EntryBox.w = 300.0f; EntryBox.y = MainIRC.y + (MainIRC.h / 2.0f - 55.0f / 2.0f); EntryBox.h = 55.0f; RenderTools()->DrawUIRect(&EntryBox, ms_ColorTabbarActive-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 10.0f); EntryBox.Margin(5.0f, &EntryBox); EntryBox.HSplitTop(18.0f, &Button, &EntryBox); CUIRect Label; Button.VSplitLeft(40.0f, &Label, &Button); UI()->DoLabelScaled(&Label, Localize("Nick:"), 14.0f, -1); static float OffsetNick; if(g_Config.m_ClIRCNick[0] == 0) { str_copy(g_Config.m_ClIRCNick, g_Config.m_PlayerName, sizeof(g_Config.m_ClIRCNick)); str_irc_sanitize(g_Config.m_ClIRCNick); } //TODO_ here? static CButtonContainer s_EditboxIRCNick; DoEditBox(&s_EditboxIRCNick, &Button, g_Config.m_ClIRCNick, sizeof(g_Config.m_ClIRCNick), 12.0f, &OffsetNick, false, CUI::CORNER_ALL); EntryBox.HSplitTop(5.0f, 0x0, &EntryBox); EntryBox.HSplitTop(20.0f, &Button, &EntryBox); static CButtonContainer s_ButtonConnect; if(DoButton_Menu(&s_ButtonConnect, Localize("Connect"), 0, &Button)) m_pClient->m_pIRCBind->Connect(); } else if(m_pClient->IRC()->GetState() == IIRC::STATE_CONNECTING) { EntryBox.x = MainIRC.x + (MainIRC.w / 2.0f - 300.0f / 2.0f); EntryBox.w = 300.0f; EntryBox.y = MainIRC.y + (MainIRC.h / 2.0f - 25.0f / 2.0f); EntryBox.h = 25.0f; RenderTools()->DrawUIRect(&EntryBox, ms_ColorTabbarActive-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 10.0f); EntryBox.Margin(5.0f, &EntryBox); UI()->DoLabelScaled(&EntryBox, Localize("Connecting, please wait..."), 14.0f, -1); } else if(m_pClient->IRC()->GetState() == IIRC::STATE_CONNECTED) { CUIRect ButtonBox, InputBox; // channel list MainIRC.HSplitTop(20.0f, &ButtonBox, &EntryBox); ButtonBox.VSplitRight(80.0f, &ButtonBox, &Button); static CButtonContainer s_ButtonDisc; if(DoButton_Menu(&s_ButtonDisc, g_Config.m_ClIRCAutoconnect ? Localize("Reconnect") : Localize("Disconnect"), 0, &Button)) m_pClient->m_pIRCBind->Disconnect(g_Config.m_ClIRCLeaveMsg); // scroll through the tabs if(UI()->MouseInside(&ButtonBox) && m_pClient->m_pGameConsole->IsClosed()) { if(m_pClient->Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) m_pClient->IRC()->NextRoom(); else if(m_pClient->Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) m_pClient->IRC()->PrevRoom(); } float LW = (ButtonBox.w - ButtonBox.x) / m_pClient->IRC()->GetNumComs(); static CButtonContainer s_ButsID[64]; for(unsigned i = 0; i < m_pClient->IRC()->GetNumComs(); i++) { CIRCCom *pCom = m_pClient->IRC()->GetCom(i); // if(pCom == m_pClient->IRC()->GetActiveCom()) ButtonBox.VSplitLeft(LW - 25.0f, &Button, &ButtonBox); // else // { // ButtonBox.VSplitLeft(LW, &Button, &ButtonBox); // Button.VSplitRight(2.0f, &Button, 0x0); // } // close using middle mouse button if(UI()->MouseInside(&Button) && m_pClient->Input()->KeyPress(KEY_MOUSE_3) && m_pClient->IRC()->CanCloseCom(m_pClient->IRC()->GetCom(i))) m_pClient->IRC()->Part(g_Config.m_ClIRCLeaveMsg, m_pClient->IRC()->GetCom(i)); if(pCom->GetType() == CIRCCom::TYPE_CHANNEL) { CComChan *pChan = static_cast<CComChan*>(pCom); static float FadeVal[64] = { 0.0f }; static bool Add[64] = { true }; if(Add[i]) smooth_set(&FadeVal[i], 1.0f, 120.0f, Client()->RenderFrameTime()); else smooth_set(&FadeVal[i], 0.0f, 120.0f, Client()->RenderFrameTime()); if(FadeVal[i] >= 0.8f) Add[i] = false; if(FadeVal[i] <= 0.2f) Add[i] = true; char aTab[255]; if(pCom->m_NumUnreadMsg) { str_format(aTab, sizeof(aTab), "%s [%d]", pChan->Channel(), pCom->m_NumUnreadMsg); if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom->m_NumUnreadMsg, &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0, vec4(0.0f, FadeVal[i], 0.0f, 1.0f))) m_pClient->IRC()->SetActiveCom(i); } else { FadeVal[i] = 0.0f; Add[i] = true; str_copy(aTab, pChan->Channel(), sizeof(aTab)); if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom == m_pClient->IRC()->GetActiveCom(), &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0)) m_pClient->IRC()->SetActiveCom(i); } } else if(pCom->GetType() == CIRCCom::TYPE_QUERY) { CComQuery *pQuery = static_cast<CComQuery*>(pCom); static float FadeVal[64] = { 0.0f }; static bool Add[64] = { true }; if(Add[i]) smooth_set(&FadeVal[i], 1.0f, 120.0f, Client()->RenderFrameTime()); else smooth_set(&FadeVal[i], 0.0f, 120.0f, Client()->RenderFrameTime()); if(FadeVal[i] >= 0.8f) Add[i] = false; if(FadeVal[i] <= 0.2f) Add[i] = true; char aTab[255]; if(pCom->m_NumUnreadMsg) { str_format(aTab, sizeof(aTab), "%s [%d]", pQuery->User(), pCom->m_NumUnreadMsg); if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom->m_NumUnreadMsg, &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0, vec4(0.0f, FadeVal[i], 0.0f, 1.0f))) m_pClient->IRC()->SetActiveCom(i); } else { FadeVal[i] = 0.0f; Add[i] = true; str_copy(aTab, pQuery->User(), sizeof(aTab)); if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom == m_pClient->IRC()->GetActiveCom(), &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0)) m_pClient->IRC()->SetActiveCom(i); } } if(i > 0 && pCom == m_pClient->IRC()->GetActiveCom() && m_pClient->IRC()->GetNumComs() > 2 && str_comp_nocase(((CComChan*)pCom)->Channel(), "#AllTheHaxx")) { Button.VSplitRight(ButtonBox.h, 0, &Button); Button.Margin(3.0f, &Button); Button.x -= 5.0f; Button.h = Button.w; static CButtonContainer s_CloseButton; if(DoButton_Menu(&s_CloseButton, "×", 0, &Button, 0, CUI::CORNER_ALL, ms_ColorTabbarActive+vec4(0.3f,0.3f,0.3f,0))) m_pClient->IRC()->Part(g_Config.m_ClIRCLeaveMsg); } } static char aEntryText[512]; static int s_CurrBacklogIndex = -1; bool Update = false; if(Input()->KeyPress(KEY_UP)) { s_CurrBacklogIndex++; Update = true; } if(Input()->KeyPress(KEY_DOWN)) { s_CurrBacklogIndex--; Update = true; } s_CurrBacklogIndex = clamp(s_CurrBacklogIndex, -1, m_aIRCBacklog.size()-1); if(Update) { if(s_CurrBacklogIndex < 0) mem_zero(aEntryText, sizeof(aEntryText)); else if(m_aIRCBacklog.size() > 0) { int ActualEntry = m_aIRCBacklog.size()-1-s_CurrBacklogIndex; if(str_length(m_aIRCBacklog[ActualEntry].c_str()) > 0) str_copy(aEntryText, m_aIRCBacklog[ActualEntry].c_str(), sizeof(aEntryText)); } } // Input Box EntryBox.HSplitBottom(20.0f, &EntryBox, &InputBox); InputBox.VSplitRight(max(50.0f, TextRender()->TextWidth(0, (InputBox.h-2.0f)*ms_FontmodHeight, Localize("Send"), -1)), &InputBox, &Button); //Button.VSplitLeft(5.0f, 0x0, &Button); static float s_Offset; CPointerContainer s_EditboxInput(&m_IRCActive); DoEditBox(&s_EditboxInput, &InputBox, aEntryText, sizeof(aEntryText), 12.0f, &s_Offset, false, CUI::CORNER_L, "", -1); static CButtonContainer s_ButtonSend; if(DoButton_Menu(&s_ButtonSend, Localize("Send"), 0, &Button, 0, CUI::CORNER_R, vec4(1,1,1,0.6f)) || m_EnterPressed) { if(aEntryText[0] == '/'/* || (m_pClient->IRC()->GetActiveCom()->GetType() == CIRCCom::TYPE_QUERY && str_comp_nocase(((CComQuery*)m_pClient->IRC()->GetActiveCom())->m_User, "@Status") == 0)*/) { std::string strCmdRaw; //if(str_comp_nocase(((CComQuery*)m_pClient->IRC()->GetActiveCom())->m_User, "@Status") == 0) // strCmdRaw = aEntryText; //else strCmdRaw = aEntryText + 1; char aCmd[32] = { 0 }, aCmdParams[255] = { 0 }; size_t del = strCmdRaw.find_first_of(" "); if(del != std::string::npos) { str_copy(aCmd, strCmdRaw.substr(0, del).c_str(), sizeof(aCmd)); str_copy(aCmdParams, strCmdRaw.substr(del + 1).c_str(), sizeof(aCmdParams)); } else str_copy(aCmd, strCmdRaw.c_str(), sizeof(aCmd)); if(aCmd[0] != 0) m_pClient->IRC()->ExecuteCommand(aCmd, aCmdParams); } else m_pClient->IRC()->SendMsg(0x0, aEntryText); if(str_length(aEntryText) > 0) m_aIRCBacklog.add(std::string(aEntryText)); s_CurrBacklogIndex = -1; aEntryText[0] = 0; UI()->SetActiveItem(s_EditboxInput.GetID()); } if(!UI()->HotItem()) UI()->SetActiveItem(s_EditboxInput.GetID()); //Channel/Query CIRCCom *pCom = m_pClient->IRC()->GetActiveCom(); if(!pCom) return; if(pCom->GetType() == CIRCCom::TYPE_CHANNEL) { CComChan *pChan = static_cast<CComChan*>(pCom); CUIRect Chat, HorizScrollBar, UserList; EntryBox.Margin(5.0f, &EntryBox); EntryBox.VSplitRight(150.0f, &Chat, &UserList); Chat.HSplitBottom(15.0f, &Chat, &HorizScrollBar); static CButtonContainer s_HScrollbar; static float s_HScrollbarVal = 0.0f; s_HScrollbarVal = DoScrollbarH(&s_HScrollbar, &HorizScrollBar, s_HScrollbarVal); if(Input()->KeyIsPressed(KEY_LSHIFT) && m_pClient->m_pGameConsole->IsClosed()) { if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the right s_HScrollbarVal += 0.1f; if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the left s_HScrollbarVal -= 0.1f; s_HScrollbarVal = clamp(s_HScrollbarVal, 0.0f, 1.0f); } static int Selected = 0; static CButtonContainer s_UsersList; static float s_UsersScrollValue = 0; /*if(!Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&UserList)) { if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the right s_UsersScrollValue -= 0.1f; if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the left s_UsersScrollValue += 0.1f; s_UsersScrollValue = clamp(s_UsersScrollValue, 0.0f, 1.0f); }*/ char aBuff[50]; str_format(aBuff, sizeof(aBuff), Localize("Total: %d"), pChan->m_Users.size()); UiDoListboxStart(&s_UsersList, &UserList, 18.0f, Localize("Users"), aBuff, pChan->m_Users.size(), 1, Selected, s_UsersScrollValue, CUI::CORNER_TR); for(int u = 0; u < pChan->m_Users.size(); u++) { std::string& Name = pChan->m_Users[u].m_Nick; CPointerContainer Container(&Name); CListboxItem Item = UiDoListboxNextItem(&Container, false, UI()->MouseInside(&UserList) != 0); if(!Item.m_Visible) continue; // quick join button CUIRect Label, ButtonQS; Item.m_Rect.VSplitRight(Item.m_Rect.h, &Label, &ButtonQS); if(Selected == u) { if(UI()->DoButtonLogic(&Item.m_Selected, "", Selected, &Label)) { if(str_comp_nocase(Name.c_str()+1, m_pClient->IRC()->GetNick()) != 0) m_pClient->IRC()->OpenQuery(Name.c_str()); } } CComChan::CUser *pUser = &(pChan->m_Users[u]); dbg_assert(pUser != NULL, "in render: pChan->m_Users contains invalid pointer"); //DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_JOIN, &ButtonQS/*, vec4(0.47f, 0.58f, 0.72f, 1.0f)*/); CPointerContainer s_JoinButton(pUser); ButtonQS.Margin(2.0f, &ButtonQS); if(!pUser->IsVoice() && !pUser->IsAdmin() && str_comp(pUser->m_Nick.c_str(), m_pClient->IRC()->GetNick()) != 0) if(DoButton_Menu(&s_JoinButton, "→", 0, &ButtonQS, Localize("Join"), CUI::CORNER_ALL, vec4(0, 0, 1, 0.7f))) //if(UI()->DoButtonLogic(&Item.m_Visible, "", Selected, &ButtonQS)) { m_pClient->IRC()->SendGetServer(Name.c_str()); } // colors for admin and voice if(pUser->IsAdmin()) TextRender()->TextColor(0.2f, 0.7f, 0.2f, 1); else if(pUser->IsVoice()) TextRender()->TextColor(0.2f, 0.2f, 0.7f, 1); UI()->DoLabelScaled(&Item.m_Rect, Name.c_str(), 12.0f, -1); TextRender()->TextColor(1,1,1,1); } Selected = UiDoListboxEnd(&s_UsersScrollValue, 0); static CButtonContainer s_Chat; static float s_ChatScrollValue = 1.0f; /*if(!Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&Chat)) { if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the right s_ChatScrollValue -= 0.1f; if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the left s_ChatScrollValue += 0.1f; s_ChatScrollValue = clamp(s_ChatScrollValue, 0.0f, 1.0f); }*/ UiDoListboxStart(&s_Chat, &Chat, 12.0f, pChan->m_Topic.c_str()[0] ? pChan->m_Topic.c_str() : "", "", (int)pChan->m_Buffer.size(), 1, -1, s_ChatScrollValue, CUI::CORNER_TL); for(size_t i = 0; i < pChan->m_Buffer.size(); i++) { CPointerContainer Container(&pChan->m_Buffer[i]); CListboxItem Item = UiDoListboxNextItem(&Container, false, !Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&UserList)); if(Item.m_Visible) { Item.m_Rect.x -= 1.7f*Item.m_Rect.w * s_HScrollbarVal; const char *pSearchFrom = str_find(pChan->m_Buffer[i].c_str(), ">"); if(!pSearchFrom) pSearchFrom = pChan->m_Buffer[i].c_str(); if(str_find_nocase(pSearchFrom, m_pClient->IRC()->GetNick())) { vec3 rgb = HslToRgb(vec3((float)g_Config.m_ClMessageHighlightHue/255.0f, (float)g_Config.m_ClMessageHighlightSat/255.0f, (float)g_Config.m_ClMessageHighlightLht/255.0f)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f); } UI()->DoLabelScaled(&Item.m_Rect, pChan->m_Buffer[i].c_str(), 10.0f, -1); TextRender()->TextColor(1,1,1,1); } } UiDoListboxEnd(&s_ChatScrollValue, 0); } else if(pCom->GetType() == CIRCCom::TYPE_QUERY) { CComQuery *pQuery = static_cast<CComQuery*>(pCom); CUIRect Chat, HorizScrollBar; EntryBox.Margin(5.0f, &Chat); Chat.HSplitBottom(15.0f, &Chat, &HorizScrollBar); static CButtonContainer s_HScrollbar; static float s_HScrollbarVal = 0.0f; s_HScrollbarVal = DoScrollbarH(&s_HScrollbar, &HorizScrollBar, s_HScrollbarVal); if(Input()->KeyIsPressed(KEY_LSHIFT) && m_pClient->m_pGameConsole->IsClosed()) { if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the right s_HScrollbarVal += 0.1f; if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the left s_HScrollbarVal -= 0.1f; s_HScrollbarVal = clamp(s_HScrollbarVal, 0.0f, 1.0f); } static CButtonContainer s_Chat; static float s_ChatScrollValue = 1.0f; /*if(!Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&Chat)) { if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the right s_ChatScrollValue -= 0.1f; if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the left s_ChatScrollValue += 0.1f; s_ChatScrollValue = clamp(s_ChatScrollValue, 0.0f, 1.0f); }*/ UiDoListboxStart(&s_Chat, &Chat, 12.0f, pQuery->User(), "", (int)pQuery->m_Buffer.size(), 1, -1, s_ChatScrollValue); for(size_t i = 0; i < pQuery->m_Buffer.size(); i++) { CPointerContainer Container(&pQuery->m_Buffer[i]); CListboxItem Item = UiDoListboxNextItem(&Container, false, !Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&Chat)); if(Item.m_Visible) { Item.m_Rect.x -= 1.7f*Item.m_Rect.w * s_HScrollbarVal; if(pQuery->m_Buffer[i].c_str()) if(str_length(pQuery->m_Buffer[i].c_str())) UI()->DoLabelScaled(&Item.m_Rect, pQuery->m_Buffer[i].c_str(), 10.0f, -1); } } UiDoListboxEnd(&s_ChatScrollValue, 0); // the join button if(str_comp_nocase(pQuery->User(), "@status") != 0 && str_comp(pQuery->User(), m_pClient->IRC()->GetNick()) != 0 && ((CComChan*)m_pClient->IRC()->GetCom(1))->GetUser(std::string(pQuery->User())) && // this is kinda inefficient but whatever... !((CComChan*)m_pClient->IRC()->GetCom(1))->GetUser(std::string(pQuery->User()))->IsVoice() && !((CComChan*)m_pClient->IRC()->GetCom(1))->GetUser(std::string(pQuery->User()))->IsAdmin() ) { CUIRect ButtonQS; Chat.VSplitRight(32.0f, 0x0, &ButtonQS); ButtonQS.h = 32.0f; ButtonQS.x -= 20.0f; ButtonQS.y += 25.0f; RenderTools()->DrawUIRect(&ButtonQS, vec4(0.2f, 0.6f, 0.4f, UI()->MouseInside(&ButtonQS) ? 1.0f : 0.6f), CUI::CORNER_ALL, 15.0f); ButtonQS.x += 5.0f; ButtonQS.y += 7.0f; UI()->DoLabelScaled(&ButtonQS, Localize("Join"), 11.0f, -1); //DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_CONNECT, &ButtonQS, vec4(0.47f, 0.58f, 0.72f, 1.0f)); static int s_ButtonQSLog = 0; if(UI()->DoButtonLogic(&s_ButtonQSLog, "", 0, &ButtonQS)) { m_pClient->IRC()->SendGetServer(pQuery->User()); } } } } }
int CMenus::Render() { CUIRect Screen = *UI()->Screen(); Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h); static bool s_First = true; if(s_First) { if(g_Config.m_UiPage == PAGE_INTERNET) ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); else if(g_Config.m_UiPage == PAGE_LAN) ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); else if(g_Config.m_UiPage == PAGE_FAVORITES) ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); s_First = false; } if(Client()->State() == IClient::STATE_ONLINE) { ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame; ms_ColorTabbarActive = ms_ColorTabbarActiveIngame; } else { RenderBackground(); ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame; ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame; } CUIRect TabBar; CUIRect MainView; // some margin around the screen Screen.Margin(10.0f, &Screen); static bool s_SoundCheck = false; if(!s_SoundCheck && m_Popup == POPUP_NONE) { if(Client()->SoundInitFailed()) m_Popup = POPUP_SOUNDERROR; s_SoundCheck = true; } if(m_Popup == POPUP_NONE) { // do tab bar Screen.HSplitTop(24.0f, &TabBar, &MainView); TabBar.VMargin(20.0f, &TabBar); RenderMenubar(TabBar); // news is not implemented yet if(g_Config.m_UiPage <= PAGE_NEWS || g_Config.m_UiPage > PAGE_SETTINGS || (Client()->State() == IClient::STATE_OFFLINE && g_Config.m_UiPage >= PAGE_GAME && g_Config.m_UiPage <= PAGE_CALLVOTE)) { ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); g_Config.m_UiPage = PAGE_INTERNET; } // render current page if(Client()->State() != IClient::STATE_OFFLINE) { if(m_GamePage == PAGE_GAME) RenderGame(MainView); else if(m_GamePage == PAGE_PLAYERS) RenderPlayers(MainView); else if(m_GamePage == PAGE_SERVER_INFO) RenderServerInfo(MainView); else if(m_GamePage == PAGE_CALLVOTE) RenderServerControl(MainView); else if(m_GamePage == PAGE_SETTINGS) RenderSettings(MainView); } else if(g_Config.m_UiPage == PAGE_NEWS) RenderNews(MainView); else if(g_Config.m_UiPage == PAGE_INTERNET) RenderServerbrowser(MainView); else if(g_Config.m_UiPage == PAGE_LAN) RenderServerbrowser(MainView); else if(g_Config.m_UiPage == PAGE_DEMOS) RenderDemoList(MainView); else if(g_Config.m_UiPage == PAGE_FAVORITES) RenderServerbrowser(MainView); else if(g_Config.m_UiPage == PAGE_SETTINGS) RenderSettings(MainView); } else { // make sure that other windows doesn't do anything funnay! //UI()->SetHotItem(0); //UI()->SetActiveItem(0); char aBuf[128]; const char *pTitle = ""; const char *pExtraText = ""; const char *pButtonText = ""; int ExtraAlign = 0; if(m_Popup == POPUP_MESSAGE) { pTitle = m_aMessageTopic; pExtraText = m_aMessageBody; pButtonText = m_aMessageButton; } else if(m_Popup == POPUP_CONNECTING) { pTitle = Localize("Connecting to"); pExtraText = g_Config.m_UiServerAddress; // TODO: query the client about the address pButtonText = Localize("Abort"); if(Client()->MapDownloadTotalsize() > 0) { pTitle = Localize("Downloading map"); pExtraText = ""; } } else if(m_Popup == POPUP_DISCONNECTED) { pTitle = Localize("Disconnected"); pExtraText = Client()->ErrorString(); pButtonText = Localize("Ok"); ExtraAlign = -1; } else if(m_Popup == POPUP_PURE) { pTitle = Localize("Disconnected"); pExtraText = Localize("The server is running a non-standard tuning on a pure game type."); pButtonText = Localize("Ok"); ExtraAlign = -1; } else if(m_Popup == POPUP_DELETE_DEMO) { pTitle = Localize("Delete demo"); pExtraText = Localize("Are you sure that you want to delete the demo?"); ExtraAlign = -1; } else if(m_Popup == POPUP_RENAME_DEMO) { pTitle = Localize("Rename demo"); pExtraText = ""; ExtraAlign = -1; } else if(m_Popup == POPUP_REMOVE_FRIEND) { pTitle = Localize("Remove friend"); pExtraText = Localize("Are you sure that you want to remove the player from your friends list?"); ExtraAlign = -1; } else if(m_Popup == POPUP_SOUNDERROR) { pTitle = Localize("Sound error"); pExtraText = Localize("The audio device couldn't be initialised."); pButtonText = Localize("Ok"); ExtraAlign = -1; } else if(m_Popup == POPUP_PASSWORD) { pTitle = Localize("Password incorrect"); pExtraText = ""; pButtonText = Localize("Try again"); } else if(m_Popup == POPUP_QUIT) { pTitle = Localize("Quit"); pExtraText = Localize("Are you sure that you want to quit?"); ExtraAlign = -1; } else if(m_Popup == POPUP_FIRST_LAUNCH) { pTitle = Localize("Welcome to Teeworlds"); pExtraText = Localize("As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server."); pButtonText = Localize("Ok"); ExtraAlign = -1; } CUIRect Box, Part; Box = Screen; Box.VMargin(150.0f/UI()->Scale(), &Box); Box.HMargin(150.0f/UI()->Scale(), &Box); // render the box RenderTools()->DrawUIRect(&Box, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f); Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box); UI()->DoLabelScaled(&Part, pTitle, 24.f, 0); Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box); Part.VMargin(20.f/UI()->Scale(), &Part); if(ExtraAlign == -1) UI()->DoLabelScaled(&Part, pExtraText, 20.f, -1, (int)Part.w); else UI()->DoLabelScaled(&Part, pExtraText, 20.f, 0, -1); if(m_Popup == POPUP_QUIT) { CUIRect Yes, No; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); // additional info Box.HSplitTop(10.0f, 0, &Box); Box.VMargin(20.f/UI()->Scale(), &Box); if(m_pClient->Editor()->HasUnsavedData()) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "%s\n%s", Localize("There's an unsaved map in the editor, you might want to save it before you quit the game."), Localize("Quit anyway?")); UI()->DoLabelScaled(&Box, aBuf, 20.f, -1, Part.w-20.0f); } // buttons Part.VMargin(80.0f, &Part); Part.VSplitMid(&No, &Yes); Yes.VMargin(20.0f, &Yes); No.VMargin(20.0f, &No); static int s_ButtonAbort = 0; if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed) m_Popup = POPUP_NONE; static int s_ButtonTryAgain = 0; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed) Client()->Quit(); } else if(m_Popup == POPUP_PASSWORD) { CUIRect Label, TextBox, TryAgain, Abort; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); Part.VSplitMid(&Abort, &TryAgain); TryAgain.VMargin(20.0f, &TryAgain); Abort.VMargin(20.0f, &Abort); static int s_ButtonAbort = 0; if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed) m_Popup = POPUP_NONE; static int s_ButtonTryAgain = 0; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed) { Client()->Connect(g_Config.m_UiServerAddress); } Box.HSplitBottom(60.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VSplitLeft(60.0f, 0, &Label); Label.VSplitLeft(100.0f, 0, &TextBox); TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Password"), 18.0f, -1); static float Offset = 0.0f; DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true); } else if(m_Popup == POPUP_CONNECTING) { Box = Screen; Box.VMargin(150.0f, &Box); Box.HMargin(150.0f, &Box); Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(120.0f, &Part); static int s_Button = 0; if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed) { Client()->Disconnect(); m_Popup = POPUP_NONE; } if(Client()->MapDownloadTotalsize() > 0) { int64 Now = time_get(); if(Now-m_DownloadLastCheckTime >= time_freq()) { if(m_DownloadLastCheckSize > Client()->MapDownloadAmount()) { // map downloaded restarted m_DownloadLastCheckSize = 0; } // update download speed float Diff = (Client()->MapDownloadAmount()-m_DownloadLastCheckSize)/1024.0f; m_DownloadSpeed = absolute((m_DownloadSpeed*(1.0f-(1.0f/m_DownloadSpeed))) + (Diff*(1.0f/m_DownloadSpeed))); m_DownloadLastCheckTime = Now; m_DownloadLastCheckSize = Client()->MapDownloadAmount(); } Box.HSplitTop(64.f, 0, &Box); Box.HSplitTop(24.f, &Part, &Box); str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024, m_DownloadSpeed); UI()->DoLabel(&Part, aBuf, 20.f, 0, -1); // time left const char *pTimeLeftString; int TimeLeft = (Client()->MapDownloadTotalsize()-Client()->MapDownloadAmount())/(m_DownloadSpeed*1024)+1; if(TimeLeft >= 60) { TimeLeft /= 60; pTimeLeftString = TimeLeft == 1 ? Localize("%i minute left") : Localize("%i minutes left"); } else pTimeLeftString = TimeLeft == 1 ? Localize("%i second left") : Localize("%i seconds left"); Box.HSplitTop(20.f, 0, &Box); Box.HSplitTop(24.f, &Part, &Box); str_format(aBuf, sizeof(aBuf), pTimeLeftString, TimeLeft); UI()->DoLabel(&Part, aBuf, 20.f, 0, -1); // progress bar Box.HSplitTop(20.f, 0, &Box); Box.HSplitTop(24.f, &Part, &Box); Part.VMargin(40.0f, &Part); RenderTools()->DrawUIRect(&Part, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f); Part.w = max(10.0f, (Part.w*Client()->MapDownloadAmount())/Client()->MapDownloadTotalsize()); RenderTools()->DrawUIRect(&Part, vec4(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f); } } else if(m_Popup == POPUP_LANGUAGE) { Box = Screen; Box.VMargin(150.0f, &Box); Box.HMargin(150.0f, &Box); Box.HSplitTop(20.f, &Part, &Box); Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Box.HSplitBottom(20.f, &Box, 0); Box.VMargin(20.0f, &Box); RenderLanguageSelection(Box); Part.VMargin(120.0f, &Part); static int s_Button = 0; if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Part) || m_EscapePressed || m_EnterPressed) m_Popup = POPUP_FIRST_LAUNCH; } else if(m_Popup == POPUP_DELETE_DEMO) { CUIRect Yes, No; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); Part.VSplitMid(&No, &Yes); Yes.VMargin(20.0f, &Yes); No.VMargin(20.0f, &No); static int s_ButtonAbort = 0; if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed) m_Popup = POPUP_NONE; static int s_ButtonTryAgain = 0; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed) { m_Popup = POPUP_NONE; // delete demo if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir) { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); if(Storage()->RemoveFile(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType)) { DemolistPopulate(); DemolistOnUpdate(false); } else PopupMessage(Localize("Error"), Localize("Unable to delete the demo"), Localize("Ok")); } } } else if(m_Popup == POPUP_RENAME_DEMO) { CUIRect Label, TextBox, Ok, Abort; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); Part.VSplitMid(&Abort, &Ok); Ok.VMargin(20.0f, &Ok); Abort.VMargin(20.0f, &Abort); static int s_ButtonAbort = 0; if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed) m_Popup = POPUP_NONE; static int s_ButtonOk = 0; if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || m_EnterPressed) { m_Popup = POPUP_NONE; // rename demo if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir) { char aBufOld[512]; str_format(aBufOld, sizeof(aBufOld), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); int Length = str_length(m_aCurrentDemoFile); char aBufNew[512]; if(Length <= 4 || m_aCurrentDemoFile[Length-5] != '.' || str_comp_nocase(m_aCurrentDemoFile+Length-4, "demo")) str_format(aBufNew, sizeof(aBufNew), "%s/%s.demo", m_aCurrentDemoFolder, m_aCurrentDemoFile); else str_format(aBufNew, sizeof(aBufNew), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile); if(Storage()->RenameFile(aBufOld, aBufNew, m_lDemos[m_DemolistSelectedIndex].m_StorageType)) { DemolistPopulate(); DemolistOnUpdate(false); } else PopupMessage(Localize("Error"), Localize("Unable to rename the demo"), Localize("Ok")); } } Box.HSplitBottom(60.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VSplitLeft(60.0f, 0, &Label); Label.VSplitLeft(120.0f, 0, &TextBox); TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("New name:"), 18.0f, -1); static float Offset = 0.0f; DoEditBox(&Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &Offset); } else if(m_Popup == POPUP_REMOVE_FRIEND) { CUIRect Yes, No; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); Part.VSplitMid(&No, &Yes); Yes.VMargin(20.0f, &Yes); No.VMargin(20.0f, &No); static int s_ButtonAbort = 0; if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed) m_Popup = POPUP_NONE; static int s_ButtonTryAgain = 0; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed) { m_Popup = POPUP_NONE; // remove friend if(m_FriendlistSelectedIndex >= 0) { m_pClient->Friends()->RemoveFriend(m_FriendlistSelectedIndex); Client()->ServerBrowserUpdate(); } } } else if(m_Popup == POPUP_FIRST_LAUNCH) { CUIRect Label, TextBox; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); static int s_EnterButton = 0; if(DoButton_Menu(&s_EnterButton, Localize("Enter"), 0, &Part) || m_EnterPressed) m_Popup = POPUP_NONE; Box.HSplitBottom(40.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VSplitLeft(60.0f, 0, &Label); Label.VSplitLeft(100.0f, 0, &TextBox); TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Nickname"), 18.0f, -1); static float Offset = 0.0f; DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &Offset); } else { Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(120.0f, &Part); static int s_Button = 0; if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed) m_Popup = POPUP_NONE; } } return 0; }
void CMenus::RenderServerbrowserFriends(CUIRect View) { static int s_Inited = 0; if(!s_Inited) { FriendlistOnUpdate(); s_Inited = 1; } CUIRect ServerFriends = View, FilterHeader; const float FontSize = 10.0f; // header ServerFriends.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFriends); RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f); RenderTools()->DrawUIRect(&ServerFriends, vec4(0,0,0,0.15f), 0, 4.0f); UI()->DoLabelScaled(&FilterHeader, Localize("Friends"), FontSize+4.0f, 0); CUIRect Button, List; ServerFriends.Margin(3.0f, &ServerFriends); ServerFriends.VMargin(3.0f, &ServerFriends); ServerFriends.HSplitBottom(100.0f, &List, &ServerFriends); // friends list(remove friend) static float s_ScrollValue = 0; UiDoListboxStart(&m_lFriends, &List, 30.0f, "", "", m_lFriends.size(), 1, m_FriendlistSelectedIndex, s_ScrollValue); m_lFriends.sort_range(); for(int i = 0; i < m_lFriends.size(); ++i) { CListboxItem Item = UiDoListboxNextItem(&m_lFriends[i]); if(Item.m_Visible) { Item.m_Rect.Margin(1.5f, &Item.m_Rect); CUIRect OnState; Item.m_Rect.VSplitRight(30.0f, &Item.m_Rect, &OnState); RenderTools()->DrawUIRect(&Item.m_Rect, vec4(1.0f, 1.0f, 1.0f, 0.1f), CUI::CORNER_L, 4.0f); Item.m_Rect.VMargin(2.5f, &Item.m_Rect); Item.m_Rect.HSplitTop(12.0f, &Item.m_Rect, &Button); UI()->DoLabelScaled(&Item.m_Rect, m_lFriends[i].m_pFriendInfo->m_aName, FontSize, -1); UI()->DoLabelScaled(&Button, m_lFriends[i].m_pFriendInfo->m_aClan, FontSize, -1); RenderTools()->DrawUIRect(&OnState, m_lFriends[i].m_NumFound ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(1.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_R, 4.0f); OnState.HMargin((OnState.h-FontSize)/3, &OnState); OnState.VMargin(5.0f, &OnState); char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%i", m_lFriends[i].m_NumFound); UI()->DoLabelScaled(&OnState, aBuf, FontSize+2, 1); } } bool Activated = false; m_FriendlistSelectedIndex = UiDoListboxEnd(&s_ScrollValue, &Activated); // activate found server with friend if(Activated && !m_EnterPressed && m_lFriends[m_FriendlistSelectedIndex].m_NumFound) { bool Found = false; int NumServers = ServerBrowser()->NumSortedServers(); for (int i = 0; i < NumServers && !Found; i++) { int ItemIndex = m_SelectedIndex != -1 ? (m_SelectedIndex+i+1)%NumServers : i; const CServerInfo *pItem = ServerBrowser()->SortedGet(ItemIndex); if(pItem->m_FriendState != IFriends::FRIEND_NO) { for(int j = 0; j < pItem->m_NumClients && !Found; ++j) { if(pItem->m_aClients[j].m_FriendState != IFriends::FRIEND_NO && str_quickhash(pItem->m_aClients[j].m_aClan) == m_lFriends[m_FriendlistSelectedIndex].m_pFriendInfo->m_ClanHash && (!m_lFriends[m_FriendlistSelectedIndex].m_pFriendInfo->m_aName[0] || str_quickhash(pItem->m_aClients[j].m_aName) == m_lFriends[m_FriendlistSelectedIndex].m_pFriendInfo->m_NameHash)) { str_copy(g_Config.m_UiServerAddress, pItem->m_aAddress, sizeof(g_Config.m_UiServerAddress)); m_ScrollOffset = ItemIndex; m_SelectedIndex = ItemIndex; Found = true; } } } } } ServerFriends.HSplitTop(2.5f, 0, &ServerFriends); ServerFriends.HSplitTop(20.0f, &Button, &ServerFriends); if(m_FriendlistSelectedIndex != -1) { static int s_RemoveButton = 0; if(DoButton_Menu(&s_RemoveButton, Localize("Remove"), 0, &Button)) m_Popup = POPUP_REMOVE_FRIEND; } // add friend if(m_pClient->Friends()->NumFriends() < IFriends::MAX_FRIENDS) { ServerFriends.HSplitTop(10.0f, 0, &ServerFriends); ServerFriends.HSplitTop(19.0f, &Button, &ServerFriends); char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%s:", Localize("Name")); UI()->DoLabelScaled(&Button, aBuf, FontSize, -1); Button.VSplitLeft(80.0f, 0, &Button); static char s_aName[MAX_NAME_LENGTH] = {0}; static float s_OffsetName = 0.0f; DoEditBox(&s_aName, &Button, s_aName, sizeof(s_aName), FontSize, &s_OffsetName); ServerFriends.HSplitTop(3.0f, 0, &ServerFriends); ServerFriends.HSplitTop(19.0f, &Button, &ServerFriends); str_format(aBuf, sizeof(aBuf), "%s:", Localize("Clan")); UI()->DoLabelScaled(&Button, aBuf, FontSize, -1); Button.VSplitLeft(80.0f, 0, &Button); static char s_aClan[MAX_CLAN_LENGTH] = {0}; static float s_OffsetClan = 0.0f; DoEditBox(&s_aClan, &Button, s_aClan, sizeof(s_aClan), FontSize, &s_OffsetClan); ServerFriends.HSplitTop(3.0f, 0, &ServerFriends); ServerFriends.HSplitTop(20.0f, &Button, &ServerFriends); static int s_AddButton = 0; if(DoButton_Menu(&s_AddButton, Localize("Add Friend"), 0, &Button)) { m_pClient->Friends()->AddFriend(s_aName, s_aClan); FriendlistOnUpdate(); Client()->ServerBrowserUpdate(); } } }
void CMenus::RenderServerbrowserFriends(CUIRect View) { CUIRect ServerFriends = View, FilterHeader; const float FontSize = 12.0f; // header ServerFriends.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFriends); RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f); RenderTools()->DrawUIRect(&ServerFriends, vec4(0,0,0,0.15f), 0, 4.0f); UI()->DoLabelScaled(&FilterHeader, Localize("Friends"), FontSize+2.0f, 0); CUIRect Button, List; ServerFriends.VSplitLeft(5.0f, 0, &ServerFriends); ServerFriends.Margin(3.0f, &ServerFriends); ServerFriends.VMargin(5.0f, &ServerFriends); ServerFriends.HSplitBottom(100.0f, &List, &ServerFriends); // friends list(remove friend) static int s_FriendList = 0; static float s_ScrollValue = 0; UiDoListboxStart(&s_FriendList, &List, 40.0f, "", "", m_pClient->Friends()->NumFriends(), 1, m_FriendlistSelectedIndex, s_ScrollValue); for(int i = 0; i < m_pClient->Friends()->NumFriends(); ++i) { const CFriendInfo *pFriend = m_pClient->Friends()->GetFriend(i); CListboxItem Item = UiDoListboxNextItem(pFriend); if(Item.m_Visible) { Item.m_Rect.Margin(2.5f, &Item.m_Rect); RenderTools()->DrawUIRect(&Item.m_Rect, vec4(1.0f, 1.0f, 1.0f, 0.1f), CUI::CORNER_ALL, 4.0f); Item.m_Rect.Margin(2.5f, &Item.m_Rect); Item.m_Rect.HSplitTop(14.0f, &Item.m_Rect, &Button); UI()->DoLabelScaled(&Item.m_Rect, pFriend->m_aName, FontSize, -1); UI()->DoLabelScaled(&Button, pFriend->m_aClan, FontSize, -1); } } m_FriendlistSelectedIndex = UiDoListboxEnd(&s_ScrollValue, 0); ServerFriends.HSplitTop(2.5f, 0, &ServerFriends); ServerFriends.HSplitTop(20.0f, &Button, &ServerFriends); if(m_FriendlistSelectedIndex != -1) { static int s_RemoveButton = 0; if(DoButton_Menu(&s_RemoveButton, Localize("Remove"), 0, &Button)) m_Popup = POPUP_REMOVE_FRIEND; } // add friend if(m_pClient->Friends()->NumFriends() < IFriends::MAX_FRIENDS) { ServerFriends.HSplitTop(10.0f, 0, &ServerFriends); ServerFriends.HSplitTop(19.0f, &Button, &ServerFriends); char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%s:", Localize("Name")); UI()->DoLabelScaled(&Button, aBuf, FontSize, -1); Button.VSplitLeft(80.0f, 0, &Button); static char s_aName[MAX_NAME_LENGTH] = {0}; static float s_OffsetName = 0.0f; DoEditBox(&s_aName, &Button, s_aName, sizeof(s_aName), FontSize, &s_OffsetName); ServerFriends.HSplitTop(3.0f, 0, &ServerFriends); ServerFriends.HSplitTop(19.0f, &Button, &ServerFriends); str_format(aBuf, sizeof(aBuf), "%s:", Localize("Clan")); UI()->DoLabelScaled(&Button, aBuf, FontSize, -1); Button.VSplitLeft(80.0f, 0, &Button); static char s_aClan[MAX_CLAN_LENGTH] = {0}; static float s_OffsetClan = 0.0f; DoEditBox(&s_aClan, &Button, s_aClan, sizeof(s_aClan), FontSize, &s_OffsetClan); ServerFriends.HSplitTop(3.0f, 0, &ServerFriends); ServerFriends.HSplitTop(20.0f, &Button, &ServerFriends); static int s_RemoveButton = 0; if(DoButton_Menu(&s_RemoveButton, Localize("Add Friend"), 0, &Button)) { m_pClient->Friends()->AddFriend(s_aName, s_aClan); Client()->ServerBrowserUpdate(); } } }
void CMenus::RenderServerbrowserFilters(CUIRect View) { // filters CUIRect Button; View.HSplitTop(5.0f, 0, &View); View.VSplitLeft(5.0f, 0, &View); View.VSplitRight(5.0f, &View, 0); View.HSplitBottom(5.0f, &View, 0); // render filters View.HSplitTop(20.0f, &Button, &View); if (DoButton_CheckBox(&g_Config.m_BrFilterEmpty, Localize("Has people playing"), g_Config.m_BrFilterEmpty, &Button)) g_Config.m_BrFilterEmpty ^= 1; View.HSplitTop(20.0f, &Button, &View); if (DoButton_CheckBox(&g_Config.m_BrFilterFull, Localize("Server not full"), g_Config.m_BrFilterFull, &Button)) g_Config.m_BrFilterFull ^= 1; View.HSplitTop(20.0f, &Button, &View); if (DoButton_CheckBox(&g_Config.m_BrFilterPw, Localize("No password"), g_Config.m_BrFilterPw, &Button)) g_Config.m_BrFilterPw ^= 1; View.HSplitTop(20.0f, &Button, &View); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterCompatversion, Localize("Compatible version"), g_Config.m_BrFilterCompatversion, &Button)) g_Config.m_BrFilterCompatversion ^= 1; View.HSplitTop(20.0f, &Button, &View); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterPure, Localize("Standard gametype"), g_Config.m_BrFilterPure, &Button)) g_Config.m_BrFilterPure ^= 1; View.HSplitTop(20.0f, &Button, &View); //button.VSplitLeft(20.0f, 0, &button); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterPureMap, Localize("Standard map"), g_Config.m_BrFilterPureMap, &Button)) g_Config.m_BrFilterPureMap ^= 1; View.HSplitTop(5.0f, 0, &View); View.HSplitTop(19.0f, &Button, &View); UI()->DoLabelScaled(&Button, Localize("Game types:"), 12.0f, -1); Button.VSplitLeft(95.0f, 0, &Button); View.HSplitTop(3.0f, 0, &View); static float Offset = 0.0f; DoEditBox(&g_Config.m_BrFilterGametype, &Button, g_Config.m_BrFilterGametype, sizeof(g_Config.m_BrFilterGametype), 12.0f, &Offset); { View.HSplitTop(19.0f, &Button, &View); CUIRect EditBox; Button.VSplitRight(50.0f, &Button, &EditBox); EditBox.VSplitRight(5.0f, &EditBox, 0); UI()->DoLabelScaled(&Button, Localize("Maximum ping:"), 12.0f, -1); char aBuf[5]; str_format(aBuf, sizeof(aBuf), "%d", g_Config.m_BrFilterPing); static float Offset = 0.0f; DoEditBox(&g_Config.m_BrFilterPing, &EditBox, aBuf, sizeof(aBuf), 12.0f, &Offset); g_Config.m_BrFilterPing = str_toint(aBuf); } View.HSplitBottom(ms_ButtonHeight, &View, &Button); static int s_ClearButton = 0; if(DoButton_Menu(&s_ClearButton, Localize("Reset filter"), 0, &Button)) { g_Config.m_BrFilterFull = 0; g_Config.m_BrFilterEmpty = 0; g_Config.m_BrFilterPw = 0; g_Config.m_BrFilterPing = 999; g_Config.m_BrFilterGametype[0] = 0; g_Config.m_BrFilterCompatversion = 1; g_Config.m_BrFilterString[0] = 0; g_Config.m_BrFilterPure = 1; g_Config.m_BrFilterPureMap = 1; } }
void CMenus::RenderServerControl(CUIRect MainView) { if(m_pClient->m_LocalClientID == -1) return; static int s_ControlPage = 0; const char *pNotification = 0; char aBuf[64]; if(m_pClient->m_aClients[m_pClient->m_LocalClientID].m_Team == TEAM_SPECTATORS) pNotification = Localize("Spectators aren't allowed to start a vote."); else if(m_pClient->m_pVoting->IsVoting()) pNotification = Localize("Wait for current vote to end before calling a new one."); else if(m_pClient->m_pVoting->CallvoteBlockTime() != 0) { str_format(aBuf, sizeof(aBuf), Localize("You must wait %d seconds before making another vote"), m_pClient->m_pVoting->CallvoteBlockTime()); pNotification = aBuf; } bool Authed = Client()->RconAuthed(); if(pNotification && !Authed) { // only print notice CUIRect Bar; MainView.HSplitTop(45.0f, &Bar, &MainView); RenderTools()->DrawUIRect(&Bar, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 10.0f); Bar.HMargin(15.0f, &Bar); UI()->DoLabelScaled(&Bar, pNotification, 14.0f, CUI::ALIGN_CENTER); return; } // tab bar CUIRect Bottom, Extended, TabBar, Button; MainView.HSplitTop(20.0f, &Bottom, &MainView); RenderTools()->DrawUIRect(&Bottom, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_T, 10.0f); MainView.HSplitTop(20.0f, &TabBar, &MainView); { TabBar.VSplitLeft(TabBar.w/3, &Button, &TabBar); static int s_Button0 = 0; if(DoButton_MenuTab(&s_Button0, Localize("Change settings"), s_ControlPage == 0, &Button, 0)) s_ControlPage = 0; TabBar.VSplitMid(&Button, &TabBar); static int s_Button1 = 0; if(DoButton_MenuTab(&s_Button1, Localize("Kick player"), s_ControlPage == 1, &Button, 0)) s_ControlPage = 1; static int s_Button2 = 0; if(DoButton_MenuTab(&s_Button2, Localize("Move player to spectators"), s_ControlPage == 2, &TabBar, 0)) s_ControlPage = 2; } if(s_ControlPage == 1) { if(!m_pClient->m_ServerSettings.m_KickVote) pNotification = Localize("Server does not allow voting to kick players"); else if(m_pClient->m_GameInfo.m_aTeamSize[TEAM_RED]+m_pClient->m_GameInfo.m_aTeamSize[TEAM_BLUE] < m_pClient->m_ServerSettings.m_KickMin) { str_format(aBuf, sizeof(aBuf), Localize("Kick voting requires %d players on the server"), m_pClient->m_ServerSettings.m_KickMin); pNotification = aBuf; } } else if(s_ControlPage == 2 && !m_pClient->m_ServerSettings.m_SpecVote) pNotification = Localize("Server does not allow voting to move players to spectators"); if(pNotification && !Authed) { // only print notice CUIRect Bar; MainView.HSplitTop(45.0f, &Bar, &MainView); RenderTools()->DrawUIRect(&Bar, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_B, 10.0f); Bar.HMargin(15.0f, &Bar); UI()->DoLabelScaled(&Bar, pNotification, 14.0f, CUI::ALIGN_CENTER); return; } // render background RenderTools()->DrawUIRect(&MainView, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); MainView.HSplitBottom(90.0f, &MainView, &Extended); // render page MainView.HSplitBottom(ms_ButtonHeight + 5*2, &MainView, &Bottom); Bottom.HMargin(5.0f, &Bottom); if(s_ControlPage == 0) RenderServerControlServer(MainView); else if(s_ControlPage == 1) RenderServerControlKick(MainView, false); else if(s_ControlPage == 2) RenderServerControlKick(MainView, true); // vote menu { Bottom.VSplitRight(120.0f, &Bottom, &Button); // render kick reason CUIRect Reason, ClearButton; Bottom.VSplitRight(40.0f, &Bottom, 0); Bottom.VSplitRight(160.0f, &Bottom, &Reason); Reason.HSplitTop(5.0f, 0, &Reason); Reason.VSplitRight(Reason.h, &Reason, &ClearButton); const char *pLabel = Localize("Reason:"); UI()->DoLabelScaled(&Reason, pLabel, 14.0f, CUI::ALIGN_LEFT); float w = TextRender()->TextWidth(0, 14.0f, pLabel, -1); Reason.VSplitLeft(w+10.0f, 0, &Reason); static float s_Offset = 0.0f; DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, CUI::CORNER_L); // clear button { static CButtonContainer s_ClearButton; float Fade = ButtonFade(&s_ClearButton, 0.6f); RenderTools()->DrawUIRect(&ClearButton, vec4(1.0f, 1.0f, 1.0f, 0.33f+(Fade/0.6f)*0.165f), CUI::CORNER_R, 3.0f); UI()->DoLabel(&ClearButton, "x", ClearButton.h*ms_FontmodHeight, CUI::ALIGN_CENTER); if(UI()->DoButtonLogic(s_ClearButton.GetID(), "x", 0, &ClearButton)) m_aCallvoteReason[0] = 0; } if(pNotification == 0) { // call vote static CButtonContainer s_CallVoteButton; if(DoButton_Menu(&s_CallVoteButton, Localize("Call vote"), 0, &Button)) HandleCallvote(s_ControlPage, false); } else { // print notice UI()->DoLabelScaled(&Bottom, pNotification, 14.0f, CUI::ALIGN_LEFT, Bottom.w); } // extended features (only available when authed in rcon) if(Authed) { // background Extended.Margin(10.0f, &Extended); Extended.HSplitTop(20.0f, &Bottom, &Extended); Extended.HSplitTop(5.0f, 0, &Extended); // force vote Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(120.0f, &Button, &Bottom); static CButtonContainer s_ForceVoteButton; if(DoButton_Menu(&s_ForceVoteButton, Localize("Force vote"), 0, &Button)) HandleCallvote(s_ControlPage, true); if(s_ControlPage == 0) { // remove vote Bottom.VSplitRight(10.0f, &Bottom, 0); Bottom.VSplitRight(120.0f, 0, &Button); static CButtonContainer s_RemoveVoteButton; if(DoButton_Menu(&s_RemoveVoteButton, Localize("Remove"), 0, &Button)) m_pClient->m_pVoting->RemovevoteOption(m_CallvoteSelectedOption); // add vote Extended.HSplitTop(20.0f, &Bottom, &Extended); Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(250.0f, &Button, &Bottom); UI()->DoLabelScaled(&Button, Localize("Vote description:"), 14.0f, CUI::ALIGN_LEFT); Bottom.VSplitLeft(20.0f, 0, &Button); UI()->DoLabelScaled(&Button, Localize("Vote command:"), 14.0f, CUI::ALIGN_LEFT); static char s_aVoteDescription[64] = {0}; static char s_aVoteCommand[512] = {0}; Extended.HSplitTop(20.0f, &Bottom, &Extended); Bottom.VSplitRight(10.0f, &Bottom, 0); Bottom.VSplitRight(120.0f, &Bottom, &Button); static CButtonContainer s_AddVoteButton; if(DoButton_Menu(&s_AddVoteButton, Localize("Add"), 0, &Button)) if(s_aVoteDescription[0] != 0 && s_aVoteCommand[0] != 0) m_pClient->m_pVoting->AddvoteOption(s_aVoteDescription, s_aVoteCommand); Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(250.0f, &Button, &Bottom); static float s_OffsetDesc = 0.0f; DoEditBox(&s_aVoteDescription, &Button, s_aVoteDescription, sizeof(s_aVoteDescription), 14.0f, &s_OffsetDesc, false, CUI::CORNER_ALL); Bottom.VMargin(20.0f, &Button); static float s_OffsetCmd = 0.0f; DoEditBox(&s_aVoteCommand, &Button, s_aVoteCommand, sizeof(s_aVoteCommand), 14.0f, &s_OffsetCmd, false, CUI::CORNER_ALL); } } } }
void CMenus::RenderGame(CUIRect MainView) { if(m_pClient->m_LocalClientID == -1) return; char aBuf[128]; const char *pNotification = 0; int TeamMod = m_pClient->m_aClients[m_pClient->m_LocalClientID].m_Team != TEAM_SPECTATORS ? -1 : 0; bool AllowSpec = true; int TimeLeft = 0; if(TeamMod+m_pClient->m_GameInfo.m_aTeamSize[TEAM_RED]+m_pClient->m_GameInfo.m_aTeamSize[TEAM_BLUE] >= m_pClient->m_ServerSettings.m_PlayerSlots) { str_format(aBuf, sizeof(aBuf), Localize("Only %d active players are allowed"), m_pClient->m_ServerSettings.m_PlayerSlots); pNotification = aBuf; } else if(m_pClient->m_ServerSettings.m_TeamLock) pNotification = Localize("Teams are locked"); else if(m_pClient->m_TeamCooldownTick+1 >= Client()->GameTick()) { TimeLeft = (m_pClient->m_TeamCooldownTick-Client()->GameTick())/Client()->GameTickSpeed()+1; str_format(aBuf, sizeof(aBuf), Localize("Teams are locked. Time to wait before changing team: %02d:%02d"), TimeLeft/60, TimeLeft%60); pNotification = aBuf; AllowSpec = false; } CUIRect Button, BottomView, Left, Middle, Right; // cut view MainView.HSplitBottom(80.0f, &MainView, &BottomView); // MainView not used for now BottomView.HSplitTop(20.f, 0, &BottomView); float Spacing = 3.0f; float ButtonWidth = (BottomView.w/6.0f)-(Spacing*5.0)/6.0f; BottomView.VSplitLeft(ButtonWidth*3.0f+Spacing*2.0f, &Left, &Middle); Middle.VSplitLeft(Spacing, 0, &Middle); Middle.VSplitLeft(ButtonWidth, &Middle, &Right); Right.VSplitRight(ButtonWidth, 0, &Right); if(!(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)) Left.VSplitLeft(ButtonWidth, &Left, 0); // do backgrounds RenderTools()->DrawUIRect4(&Left, vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); RenderTools()->DrawUIRect4(&Middle, vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); RenderTools()->DrawUIRect4(&Right, vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); // do buttons Left.HSplitTop(25.0f, &Left, 0); Middle.HSplitTop(25.0f, &Middle, 0); Right.HSplitTop(25.0f, &Right, 0); if(pNotification != 0) { // print notice CUIRect Bar; MainView.HSplitTop(45.0f, &Bar, &MainView); RenderTools()->DrawUIRect(&Bar, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_B, 10.0f); Bar.HMargin(15.0f, &Bar); UI()->DoLabelScaled(&Bar, pNotification, 14.0f, 0); } // join buttons { // specator button int Team = m_pClient->m_aClients[m_pClient->m_LocalClientID].m_Team; if(pNotification && Team != TEAM_SPECTATORS) { if(TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_SPECTATORS ? "Spectate" : "Spactating"), sizeof(aBuf)); // Localize("Spectating"); Left.VSplitLeft(ButtonWidth, &Button, &Left); Left.VSplitLeft(Spacing, 0, &Left); static int s_SpectateButton = 0; if(DoButton_Menu(&s_SpectateButton, aBuf, Team == TEAM_SPECTATORS, &Button) && Team != TEAM_SPECTATORS && AllowSpec && !pNotification) { m_pClient->SendSwitchTeam(TEAM_SPECTATORS); SetActive(false); } // team button if(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS) { if(pNotification && Team != TEAM_RED) { if(TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_RED ? "Join red" : "Joined red"), sizeof(aBuf)); // Localize("Join red");Localize("Joined red"); Left.VSplitLeft(ButtonWidth, &Button, &Left); Left.VSplitLeft(Spacing, 0, &Left); static int s_RedButton = 0; if(DoButton_Menu(&s_RedButton, aBuf, Team == TEAM_RED, &Button, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.975f, 0.17f, 0.17f, 0.75f), false) && Team != TEAM_RED && !pNotification) { m_pClient->SendSwitchTeam(TEAM_RED); SetActive(false); } if(pNotification && Team != TEAM_BLUE) { if(TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_BLUE ? "Join blue" : "Joined blue"), sizeof(aBuf)); // Localize("Join blue");Localize("Joined blue"); Left.VSplitLeft(ButtonWidth, &Button, &Left); static int s_BlueButton = 0; if(DoButton_Menu(&s_BlueButton, aBuf, Team == TEAM_BLUE, &Button, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.17f, 0.46f, 0.975f, 0.75f), false) && Team != TEAM_BLUE && !pNotification) { m_pClient->SendSwitchTeam(TEAM_BLUE); SetActive(false); } } else { if(pNotification && Team != TEAM_RED) { if(TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_RED ? "Join" : "Joined"), sizeof(aBuf)); //Localize("Join");Localize("Joined"); Left.VSplitLeft(ButtonWidth, &Button, &Left); static int s_JoinButton = 0; if(DoButton_Menu(&s_JoinButton, aBuf, Team == TEAM_RED, &Button) && Team != TEAM_RED && !pNotification) { m_pClient->SendSwitchTeam(0); SetActive(false); } } } // Record button static int s_DemoButton = 0; bool Recording = DemoRecorder()->IsRecording(); if(DoButton_Menu(&s_DemoButton, Localize(Recording ? "Stop record" : "Record"), Recording, &Middle)) // Localize("Stop record");Localize("Record"); { if(!Recording) Client()->DemoRecorder_Start("demo", true); else Client()->DemoRecorder_Stop(); } // disconnect button static int s_DisconnectButton = 0; if(DoButton_Menu(&s_DisconnectButton, Localize("Disconnect"), 0, &Right)) Client()->Disconnect(); }
void CMenus::RenderDemoList(CUIRect MainView) { CUIRect BottomView; MainView.HSplitTop(20.0f, 0, &MainView); // back button RenderBackButton(MainView); // cut view MainView.HSplitBottom(80.0f, &MainView, &BottomView); RenderTools()->DrawUIRect(&MainView, vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), CUI::CORNER_ALL, 5.0f); BottomView.HSplitTop(20.f, 0, &BottomView); static int s_Inited = 0; if(!s_Inited) { DemolistPopulate(); DemolistOnUpdate(true); s_Inited = 1; } char aFooterLabel[128] = {0}; if(m_DemolistSelectedIndex >= 0) { CDemoItem *Item = &m_lDemos[m_DemolistSelectedIndex]; if(str_comp(Item->m_aFilename, "..") == 0) str_copy(aFooterLabel, Localize("Parent Folder"), sizeof(aFooterLabel)); else if(m_DemolistSelectedIsDir) str_copy(aFooterLabel, Localize("Folder"), sizeof(aFooterLabel)); else { if(!Item->m_InfosLoaded) { char aBuffer[512]; str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aCurrentDemoFolder, Item->m_aFilename); Item->m_Valid = DemoPlayer()->GetDemoInfo(Storage(), aBuffer, Item->m_StorageType, &Item->m_Info); Item->m_InfosLoaded = true; } if(!Item->m_Valid) str_copy(aFooterLabel, Localize("Invalid Demo"), sizeof(aFooterLabel)); else str_copy(aFooterLabel, Localize("Demo details"), sizeof(aFooterLabel)); } } static bool s_DemoDetailsActive = true; const int NumOptions = 8; const float ButtonHeight = 20.0f; const float ButtonSpacing = 2.0f; const float HMargin = 5.0f; const float BackgroundHeight = s_DemoDetailsActive ? (float)(NumOptions+1)*ButtonHeight+(float)NumOptions*ButtonSpacing : ButtonHeight; CUIRect ListBox, Button, FileIcon; MainView.HSplitTop(MainView.h - BackgroundHeight - 2 * HMargin, &ListBox, &MainView); static CListBoxState s_ListBoxState; UiDoListboxHeader(&s_ListBoxState, &ListBox, Localize("Recorded"), 20.0f, 2.0f); UiDoListboxStart(&s_ListBoxState, &s_ListBoxState, 20.0f, 0, m_lDemos.size(), 1, m_DemolistSelectedIndex); for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) { CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState, (void*)(&r.front())); // marker count const CDemoItem& DemoItem = r.front(); int DemoMarkerCount = 0; if(DemoItem.m_Valid && DemoItem.m_InfosLoaded) DemoMarkerCount = DemoGetMarkerCount(DemoItem.m_Info); if(Item.m_Visible) { Item.m_Rect.VSplitLeft(Item.m_Rect.h, &FileIcon, &Item.m_Rect); Item.m_Rect.VSplitLeft(5.0f, 0, &Item.m_Rect); FileIcon.Margin(3.0f, &FileIcon); FileIcon.x += 3.0f; vec4 IconColor = vec4(1, 1, 1, 1); if(!DemoItem.m_IsDir) { IconColor = vec4(0.6f, 0.6f, 0.6f, 1.0f); // not loaded if(DemoItem.m_Valid && DemoItem.m_InfosLoaded) IconColor = DemoMarkerCount > 0 ? vec4(0.5, 1, 0.5, 1) : vec4(1,1,1,1); } DoIconColor(IMAGE_FILEICONS, r.front().m_IsDir?SPRITE_FILE_FOLDER:SPRITE_FILE_DEMO1, &FileIcon, IconColor); if((&r.front() - m_lDemos.base_ptr()) == m_DemolistSelectedIndex) // selected { TextRender()->TextColor(0.0f, 0.0f, 0.0f, 1.0f); TextRender()->TextOutlineColor(1.0f, 1.0f, 1.0f, 0.25f); Item.m_Rect.y += 2.0f; UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); TextRender()->TextOutlineColor(0.0f, 0.0f, 0.0f, 0.3f); } else { Item.m_Rect.y += 2.0f; UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); } } } bool Activated = false; m_DemolistSelectedIndex = UiDoListboxEnd(&s_ListBoxState, &Activated); DemolistOnUpdate(false); MainView.HSplitTop(HMargin, 0, &MainView); static int s_DemoDetailsDropdown = 0; if(!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_lDemos[m_DemolistSelectedIndex].m_Valid) DoIndependentDropdownMenu(&s_DemoDetailsDropdown, &MainView, aFooterLabel, ButtonHeight, RenderDemoDetails, &s_DemoDetailsActive); else { CUIRect Header; MainView.HSplitTop(ButtonHeight, &Header, &MainView); RenderTools()->DrawUIRect(&Header, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 5.0f); Header.y += 2.0f; UI()->DoLabel(&Header, aFooterLabel, ButtonHeight*ms_FontmodHeight*0.8f, CUI::ALIGN_CENTER); } // demo buttons int NumButtons = m_DemolistSelectedIsDir ? 2 : 4; float Spacing = 3.0f; float ButtonWidth = (BottomView.w/6.0f)-(Spacing*5.0)/6.0f; float BackgroundWidth = ButtonWidth*(float)NumButtons+(float)(NumButtons-1)*Spacing; BottomView.VSplitRight(BackgroundWidth, 0, &BottomView); RenderTools()->DrawUIRect4(&BottomView, vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); BottomView.HSplitTop(25.0f, &BottomView, 0); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static CButtonContainer s_RefreshButton; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &Button) || (Input()->KeyPress(KEY_R) && (Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL)))) { DemolistPopulate(); DemolistOnUpdate(false); } if(!m_DemolistSelectedIsDir) { BottomView.VSplitLeft(Spacing, 0, &BottomView); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static CButtonContainer s_DeleteButton; if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &Button) || m_DeletePressed) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_DELETE_DEMO; return; } } BottomView.VSplitLeft(Spacing, 0, &BottomView); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static CButtonContainer s_RenameButton; if(DoButton_Menu(&s_RenameButton, Localize("Rename"), 0, &Button)) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_RENAME_DEMO; str_copy(m_aCurrentDemoFile, m_lDemos[m_DemolistSelectedIndex].m_aFilename, sizeof(m_aCurrentDemoFile)); return; } } } BottomView.VSplitLeft(Spacing, 0, &BottomView); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static CButtonContainer s_PlayButton; if(DoButton_Menu(&s_PlayButton, m_DemolistSelectedIsDir?Localize("Open"):Localize("Play", "DemoBrowser"), 0, &Button) || Activated) { if(m_DemolistSelectedIndex >= 0) { if(m_DemolistSelectedIsDir) // folder { if(str_comp(m_lDemos[m_DemolistSelectedIndex].m_aFilename, "..") == 0) // parent folder fs_parent_dir(m_aCurrentDemoFolder); else // sub folder { char aTemp[256]; str_copy(aTemp, m_aCurrentDemoFolder, sizeof(aTemp)); str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", aTemp, m_lDemos[m_DemolistSelectedIndex].m_aFilename); m_DemolistStorageType = m_lDemos[m_DemolistSelectedIndex].m_StorageType; } DemolistPopulate(); DemolistOnUpdate(true); } else // file { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); const char *pError = Client()->DemoPlayer_Play(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType); if(pError) PopupMessage(Localize("Error loading demo"), pError, Localize("Ok")); else { UI()->SetActiveItem(0); return; } } } } }
void CMenus::RenderGame(CUIRect MainView) { if(m_pClient->m_LocalClientID == -1) return; char aBuf[128]; CSwitchTeamInfo Info = { 0 }; GetSwitchTeamInfo(&Info); CUIRect Button, ButtonRow, Label; float Spacing = 3.0f; float ButtonWidth = (MainView.w/6.0f)-(Spacing*5.0)/6.0f; // cut view MainView.HSplitTop(20.0f, 0, &MainView); float NoteHeight = !Info.m_aNotification[0] ? 0.0f : 45.0f; MainView.HSplitTop(20.0f+20.0f+2*Spacing+ NoteHeight, &MainView, 0); RenderTools()->DrawUIRect(&MainView, vec4(0.0f, 0.0f, 0.0f, ms_BackgroundAlpha), CUI::CORNER_ALL, 5.0f); // 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); RenderTools()->DrawUIRect(&MainView, vec4(0.0, 0.0, 0.0, 0.25f), CUI::CORNER_ALL, 5.0f); if(Info.m_aNotification[0] != 0) { // print notice CUIRect Bar; MainView.HSplitBottom(NoteHeight, &MainView, &Bar); Bar.HMargin(15.0f, &Bar); UI()->DoLabelScaled(&Bar, Info.m_aNotification, 14.0f, CUI::ALIGN_CENTER); } // buttons { MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(20.0f, &ButtonRow, 0); ButtonRow.VMargin(Spacing, &ButtonRow); // specator button int Team = m_pClient->m_aClients[m_pClient->m_LocalClientID].m_Team; if(Info.m_aNotification[0] && Team != TEAM_SPECTATORS) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_SPECTATORS ? "Spectate" : "Spectating"), sizeof(aBuf)); // Localize("Spectating"); ButtonRow.VSplitLeft(ButtonWidth, &Button, &ButtonRow); ButtonRow.VSplitLeft(Spacing, 0, &ButtonRow); static CButtonContainer s_SpectateButton; if(DoButton_Menu(&s_SpectateButton, aBuf, Team == TEAM_SPECTATORS, &Button) && Team != TEAM_SPECTATORS && Info.m_AllowSpec && !(Info.m_aNotification[0])) { m_pClient->SendSwitchTeam(TEAM_SPECTATORS); SetActive(false); } // team button if(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS) { int RedTeamSizeNew = m_pClient->m_GameInfo.m_aTeamSize[TEAM_RED]; if(Team != TEAM_RED) ++RedTeamSizeNew; else if(Team == TEAM_RED) --RedTeamSizeNew; int BlueTeamSizeNew = m_pClient->m_GameInfo.m_aTeamSize[TEAM_BLUE]; if(Team != TEAM_BLUE) ++BlueTeamSizeNew; else if(Team == TEAM_BLUE) --BlueTeamSizeNew; bool BlockRed = m_pClient->m_ServerSettings.m_TeamBalance && (RedTeamSizeNew - BlueTeamSizeNew >= NUM_TEAMS); bool BlockBlue = m_pClient->m_ServerSettings.m_TeamBalance && (BlueTeamSizeNew - RedTeamSizeNew >= NUM_TEAMS); if((Info.m_aNotification[0] && Team != TEAM_RED) || BlockRed) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_RED ? "Join red" : "Joined red"), sizeof(aBuf)); // Localize("Join red");Localize("Joined red"); ButtonRow.VSplitLeft(ButtonWidth, &Button, &ButtonRow); ButtonRow.VSplitLeft(Spacing, 0, &ButtonRow); static CButtonContainer s_RedButton; if(DoButton_Menu(&s_RedButton, aBuf, Team == TEAM_RED, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.975f, 0.17f, 0.17f, 0.75f), false) && Team != TEAM_RED && !(Info.m_aNotification[0]) && !BlockRed) { m_pClient->SendSwitchTeam(TEAM_RED); SetActive(false); } if((Info.m_aNotification[0] && Team != TEAM_BLUE) || BlockBlue) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_BLUE ? "Join blue" : "Joined blue"), sizeof(aBuf)); // Localize("Join blue");Localize("Joined blue"); ButtonRow.VSplitLeft(ButtonWidth, &Button, &ButtonRow); ButtonRow.VSplitLeft(Spacing, 0, &ButtonRow); static CButtonContainer s_BlueButton; if(DoButton_Menu(&s_BlueButton, aBuf, Team == TEAM_BLUE, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.17f, 0.46f, 0.975f, 0.75f), false) && Team != TEAM_BLUE && !(Info.m_aNotification[0]) && !BlockBlue) { m_pClient->SendSwitchTeam(TEAM_BLUE); SetActive(false); } } else { if(Info.m_aNotification[0] && Team != TEAM_RED) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_RED ? "Join" : "Joined"), sizeof(aBuf)); //Localize("Join");Localize("Joined"); ButtonRow.VSplitLeft(ButtonWidth, &Button, &ButtonRow); static CButtonContainer s_JoinButton; if(DoButton_Menu(&s_JoinButton, aBuf, Team == TEAM_RED, &Button) && Team != TEAM_RED && !(Info.m_aNotification[0])) { m_pClient->SendSwitchTeam(TEAM_RED); SetActive(false); } } // disconnect button ButtonRow.VSplitRight(ButtonWidth, &ButtonRow, &Button); static CButtonContainer s_DisconnectButton; if(DoButton_Menu(&s_DisconnectButton, Localize("Disconnect"), 0, &Button)) Client()->Disconnect(); // Record button ButtonRow.VSplitRight(50.0f, &ButtonRow, 0); ButtonRow.VSplitRight(ButtonWidth, &ButtonRow, &Button); static CButtonContainer s_DemoButton; bool Recording = DemoRecorder()->IsRecording(); if(DoButton_Menu(&s_DemoButton, Localize(Recording ? "Stop record" : "Record"), Recording, &Button)) // Localize("Stop record");Localize("Record"); { if(!Recording) Client()->DemoRecorder_Start("demo", true); else Client()->DemoRecorder_Stop(); } } }
void CMenus::RenderSettingsIdent(CUIRect MainView) { CALLSTACK_ADD(); static int s_LegacyIsOpen = 0; if(s_LegacyIsOpen) { s_LegacyIsOpen = RenderSettingsIdentLegacy(MainView); return; } // render background CUIRect Temp, TabBar, Button, Label, View; static int Page = 0; int numID = m_pClient->m_pIdentity->NumIdents(); // add a new identity from current settings as we need at least one if(numID == 0) m_pClient->m_pIdentity->AddIdent(); MainView.VSplitLeft(240.0f, &TabBar, &MainView); TabBar.VSplitRight(2.0f, &TabBar, &Button); RenderTools()->DrawUIRect(&Button, vec4(0.0f, 0.8f, 0.6f, 0.5f), 0, 0); TabBar.HSplitTop(20.0f, &Button, &TabBar); static CButtonContainer s_ButtonOpenLegacy; if(DoButton_Menu(&s_ButtonOpenLegacy, Localize("Open legacy view"), 0, &Button, 0, CUI::CORNER_T)) s_LegacyIsOpen = 1; static CButtonContainer s_aDeleteIDs[512]; static CButtonContainer s_aUpIDs[512]; static CButtonContainer s_aDownIDs[512]; static CButtonContainer s_aPageIDs[512]; static CButtonContainer s_LeftListbox; static float s_LeftListboxScrollVal = 0.0f; UiDoListboxStart(&s_LeftListbox, &TabBar, 24.0f, "", "", numID+1, 1, -1, s_LeftListboxScrollVal, 0); for(int i = 0; i < numID+1; i++) { if(i >= 512) break; CIdentity::CIdentEntry *pEntry = m_pClient->m_pIdentity->GetIdent(i); CPointerContainer Container(pEntry); CListboxItem Item = UiDoListboxNextItem(&Container, false/*Page == i*/); if(!Item.m_Visible) continue; Button = Item.m_Rect; if(i == numID) { Button.HSplitBottom(4.0f, &Button, 0); Button.VSplitRight(240.0f, 0, &Temp); if(DoButton_MenuTab(&s_aPageIDs[i], Localize("Add Identity"), false, &Button, CUI::CORNER_B, vec4(0.7f, 0.7f, 0.2f, ms_ColorTabbarActive.a), vec4(0.7f, 0.7f, 0.2f, ms_ColorTabbarInactive.a))) m_pClient->m_pIdentity->AddIdent(); break; } if(DoButton_MenuTab(&s_aPageIDs[i], "", Page == i, &Button, i == 0 ? CUI::CORNER_T : 0, vec4(0.2f, 0.6f, 0.2f, ms_ColorTabbarActive.a), vec4(0.2f, 0.6f, 0.2f, ms_ColorTabbarInactive.a))) Page = i; Button.VSplitRight(Button.h, 0, &Temp); Temp.Margin(4.0f, &Temp); if(m_pClient->m_pIdentity->NumIdents() > 1) { if(DoButton_Menu(&s_aDeleteIDs[i], "×", 0, &Temp, 0, CUI::CORNER_R | (i < numID - 1 ? 0 : CUI::CORNER_L), vec4(0.7f, 0.2f, 0.2f, 0.9f))) { m_pClient->m_pIdentity->DeleteIdent(i); if(i < Page) Page--; } } if(i < numID-1) { Button.VSplitRight(Button.h, 0, &Temp); Temp.Margin(4.0f, &Temp); Temp.x -= 16.0f; if(DoButton_Menu(&s_aDownIDs[i], "↓", 0, &Temp, 0, i >= 1 ? 0 : CUI::CORNER_L)) { m_pClient->m_pIdentity->SwapIdent(i, 1); m_MousePos.y += 36.0f; if(Page == i) Page++; else if(i == Page-1) Page--; } } if(i >= 1) { Button.VSplitRight(Button.h, 0, &Temp); Temp.Margin(4.0f, &Temp); Temp.x -= 32.0f; if(DoButton_Menu(&s_aUpIDs[i], "↑", 0, &Temp, 0, i < numID-1 ? CUI::CORNER_L : CUI::CORNER_ALL)) { m_MousePos.y -= 36.0f; m_pClient->m_pIdentity->SwapIdent(i, -1); if(i == Page) Page--; else if(i == Page+1) Page++; } } Button.HSplitTop(Button.h*0.25f, 0, &Label); static int DefaultSkin = -1; if(DefaultSkin < 0) DefaultSkin = m_pClient->m_pSkins->Find("default"); int SkinID = m_pClient->m_pSkins->Find(pEntry->m_aSkin); if(SkinID < 0) SkinID = DefaultSkin; const CSkins::CSkin *pOwnSkin = m_pClient->m_pSkins->Get(SkinID); CTeeRenderInfo OwnSkinInfo; if(pEntry->m_UseCustomColor) { OwnSkinInfo.m_Texture = pOwnSkin->m_ColorTexture; OwnSkinInfo.m_ColorBody = m_pClient->m_pSkins->GetColorV4(pEntry->m_ColorBody); OwnSkinInfo.m_ColorFeet = m_pClient->m_pSkins->GetColorV4(pEntry->m_ColorFeet); } else { OwnSkinInfo.m_Texture = pOwnSkin->m_OrgTexture; OwnSkinInfo.m_ColorBody = vec4(1.0f, 1.0f, 1.0f, 1.0f); OwnSkinInfo.m_ColorFeet = vec4(1.0f, 1.0f, 1.0f, 1.0f); } OwnSkinInfo.m_Size = 26.0f*UI()->Scale(); RenderTools()->RenderTee(CAnimState::GetIdle(), &OwnSkinInfo, 0, vec2(1, 0), vec2(Button.x + OwnSkinInfo.m_Size, Button.y + Button.h *0.6f)); Button.HMargin(2.0f, &Button); Button.HSplitBottom(16.0f, 0, &Button); const bool IsMain = m_pClient->m_pIdentity->UsingIdent(i, false); const bool IsDummy = m_pClient->m_pIdentity->UsingIdent(i, true); vec3 rgb = IsMain && !IsDummy ? vec3(0.7f, 0.7f, 0.2f) : !IsMain && IsDummy ? vec3(0.2f, 0.7f, 0.7f) : IsMain && IsDummy ? vec3(0.2f, 0.7f, 0.2f) : vec3(1,1,1); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f); if(str_length(pEntry->m_aTitle) > 0) UI()->DoLabelScaled(&Button, pEntry->m_aTitle, 14.0f, 0); else UI()->DoLabelScaled(&Button, pEntry->m_aName, 14.0f, 0); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); } UiDoListboxEnd(&s_LeftListboxScrollVal, 0); MainView.HSplitTop(20.0f, &Temp, &View); Temp.VMargin(5.0f, &Temp); Temp.VSplitMid(&Button, &Temp); MainView.Margin(10.0f, &MainView); static int s_ControlPage = 0; CButtonContainer s_ButtonPlayer; if(DoButton_MenuTab(&s_ButtonPlayer, Localize("Player"), s_ControlPage == 0, &Button, CUI::CORNER_L)) s_ControlPage = 0; CButtonContainer s_ButtonTee; if(DoButton_MenuTab(&s_ButtonTee, Localize("Tee"), s_ControlPage == 1, &Temp, CUI::CORNER_R)) s_ControlPage = 1; if(s_ControlPage == 0) RenderSettingsIdentPlayer(View, Page); if(s_ControlPage == 1) RenderSettingsIdentTee(View, Page); }
void CMenus::RenderSettingsIdentPlayer(CUIRect MainView, int Page) { CIdentity::CIdentEntry *pEntry = m_pClient->m_pIdentity->GetIdent(Page); if(!m_pClient->m_pIdentity->NumIdents() || !pEntry) return; CUIRect Button, Label; // skin info const CSkins::CSkin *pOwnSkin = m_pClient->m_pSkins->Get(m_pClient->m_pSkins->Find(pEntry->m_aSkin)); CTeeRenderInfo OwnSkinInfo; if(pEntry->m_UseCustomColor) { OwnSkinInfo.m_Texture = pOwnSkin->m_ColorTexture; OwnSkinInfo.m_ColorBody = m_pClient->m_pSkins->GetColorV4(pEntry->m_ColorBody); OwnSkinInfo.m_ColorFeet = m_pClient->m_pSkins->GetColorV4(pEntry->m_ColorFeet); } else { OwnSkinInfo.m_Texture = pOwnSkin->m_OrgTexture; OwnSkinInfo.m_ColorBody = vec4(1.0f, 1.0f, 1.0f, 1.0f); OwnSkinInfo.m_ColorFeet = vec4(1.0f, 1.0f, 1.0f, 1.0f); } OwnSkinInfo.m_Size = 50.0f*UI()->Scale(); char aBuf[128]; MainView.Margin(10.0f, &MainView); MainView.HSplitTop(50.0f, &Label, &MainView); RenderTools()->DrawUIRect(&Label, vec4(1,1,1,0.2f), CUI::CORNER_ALL, 25.0f); Label.VSplitLeft(15.0f, 0, &Label); Label.HSplitTop(3.0f, 0, &Label); const bool IsMain = m_pClient->m_pIdentity->UsingIdent(Page, false); const bool IsDummy = m_pClient->m_pIdentity->UsingIdent(Page, true); str_format(aBuf, sizeof(aBuf), "%s", IsMain && !IsDummy ? Localize("Main Identity: ") : !IsMain && IsDummy ? Localize("Dummy's Identity: ") : IsMain && IsDummy ? Localize("Both's Identity: ") : ""); if(str_length(pEntry->m_aTitle) > 0) str_append(aBuf, pEntry->m_aTitle, sizeof(aBuf)); else str_append(aBuf, pEntry->m_aName, sizeof(aBuf)); UI()->DoLabelScaled(&Label, aBuf, 35.0f, -1, (int)Label.w); MainView.HSplitTop(10.0f, 0, &MainView); // skin view MainView.HSplitTop(50.0f, &Label, 0); Label.VSplitMid(0, &Label); RenderTools()->DrawUIRect(&Label, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 10.0f); RenderTools()->RenderTee(CAnimState::GetIdle(), &OwnSkinInfo, 0, vec2(1, 0), vec2(Label.x+30.0f, Label.y+28.0f)); Label.HSplitTop(15.0f, 0, &Label); Label.VSplitLeft(70.0f, 0, &Label); UI()->DoLabelScaled(&Label, pEntry->m_aSkin, 14.0f, -1, 150); // ident title MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(80.0f, &Label, &Button); Button.VSplitLeft(150.0f, &Button, 0); str_format(aBuf, sizeof(aBuf), "%s:", Localize("Title")); UI()->DoLabelScaled(&Label, aBuf, 14.0, -1); static float s_OffsetTitle[512] = {0.0f}; CPointerContainer ContainerTitle(&s_OffsetTitle[Page]); if(DoEditBox(&ContainerTitle, &Button, pEntry->m_aTitle, sizeof(pEntry->m_aTitle), 14.0f, &s_OffsetTitle[Page], false, CUI::CORNER_ALL, "", 0, Localize("a custom title to display this identity"))) m_NeedSendinfo = true; // player name MainView.HSplitTop(3.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(80.0f, &Label, &Button); Button.VSplitLeft(150.0f, &Button, 0); str_format(aBuf, sizeof(aBuf), "%s:", Localize("Name")); UI()->DoLabelScaled(&Label, aBuf, 14.0, -1); static float s_OffsetName[512] = {0.0f}; CPointerContainer ContainerName(&s_OffsetName[Page]); if(DoEditBox(&ContainerName, &Button, pEntry->m_aName, sizeof(g_Config.m_PlayerName), 14.0f, &s_OffsetName[Page])) m_NeedSendinfo = true; // player clan MainView.HSplitTop(3.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(80.0f, &Label, &Button); Button.VSplitLeft(150.0f, &Button, 0); str_format(aBuf, sizeof(aBuf), "%s:", Localize("Clan")); UI()->DoLabelScaled(&Label, aBuf, 14.0, -1); static float s_OffsetClan[512] = {0.0f}; CPointerContainer ContainerClan(&s_OffsetClan[Page]); if(DoEditBox(&ContainerClan, &Button, pEntry->m_aClan, sizeof(g_Config.m_PlayerClan), 14.0f, &s_OffsetClan[Page])) m_NeedSendinfo = true; // apply identity MainView.HSplitTop(3.0f, 0, &MainView); MainView.HSplitTop(20.0f, &Button, &MainView); Button.VSplitLeft(80.0f, &Label, &Button); Button.VSplitLeft(150.0f, &Button, 0); str_format(aBuf, sizeof(aBuf), "%s:", Localize("Apply as")); UI()->DoLabelScaled(&Label, aBuf, 14.0, -1); Button.VSplitMid(&Button, &Label); static CButtonContainer s_ApplyButtonMain[512], s_ApplyButtonDummy[512]; if(!IsMain) { if(DoButton_Menu(&s_ApplyButtonMain[Page], Localize("Main"), 0, &Button, "", CUI::CORNER_L|CUI::CORNER_R*IsDummy, vec4(0.7f, 0.7f, 0.2f, 1.0f))) GameClient()->m_pIdentity->ApplyIdent(Page, false); } if(!IsDummy) { if(DoButton_Menu(&s_ApplyButtonDummy[Page], Localize("Dummy"), 0, &Label, "", CUI::CORNER_R|CUI::CORNER_L*IsMain, vec4(0.2f, 0.7f, 0.7f, 1.0f))) GameClient()->m_pIdentity->ApplyIdent(Page, true); } // country flag selector int *Country = &pEntry->m_Country; MainView.HSplitTop(20.0f, 0, &MainView); static float s_ScrollValue = 0.0f; int OldSelected = -1; static CButtonContainer s_Listbox; UiDoListboxStart(&s_Listbox, &MainView, 50.0f, Localize("Country"), "", m_pClient->m_pCountryFlags->Num(), 6, OldSelected, s_ScrollValue); for(int i = 0; i < m_pClient->m_pCountryFlags->Num(); ++i) { const CCountryFlags::CCountryFlag *pFlag = m_pClient->m_pCountryFlags->GetByIndex(i); if(pFlag->m_CountryCode == *Country) OldSelected = i; CPointerContainer Container(&pFlag->m_CountryCode); CListboxItem Item = UiDoListboxNextItem(&Container, OldSelected == i); if(Item.m_Visible) { CUIRect FlagLabel; Item.m_Rect.Margin(5.0f, &Item.m_Rect); Item.m_Rect.HSplitBottom(10.0f, &Item.m_Rect, &FlagLabel); float OldWidth = Item.m_Rect.w; Item.m_Rect.w = Item.m_Rect.h*2; Item.m_Rect.x += (OldWidth-Item.m_Rect.w)/ 2.0f; vec4 Color(1.0f, 1.0f, 1.0f, 1.0f); m_pClient->m_pCountryFlags->Render(pFlag->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h); if(pFlag->m_Texture != -1) UI()->DoLabel(&FlagLabel, pFlag->m_aCountryCodeString, 10.0f, 0); } } const int NewSelected = UiDoListboxEnd(&s_ScrollValue, 0); if(OldSelected != NewSelected) { *Country = m_pClient->m_pCountryFlags->GetByIndex(NewSelected)->m_CountryCode; if(m_Dummy) m_NeedSendDummyinfo = true; else m_NeedSendinfo = true; } }
void CLuaUi::Tick() { if (!m_Used) return; if (m_Type == LUAUIBUTTON) { int state = DoButton_Menu(&m_Id, m_pText, m_Checked, &m_Rect, m_Corners, m_Color); if (state != 0) { if (!m_pLuaFile->FunctionExist(m_pCallback)) return; m_pLuaFile->FunctionPrepare(m_pCallback); m_pLuaFile->PushInteger(state); m_pLuaFile->PushInteger(m_Id); m_pLuaFile->FunctionExec(); } } else if(m_Type == LUAUIEDITBOX) { DoEditBox(&m_Id, &m_Rect, m_pText, sizeof(m_pText), m_FontSize, &m_Offset, m_Hidden, m_Corners, m_Color); } else if(m_Type == LUAUILABEL) { CUIRect *pRect = &m_Rect; CUIRect Temp; pRect->HMargin(pRect->h>=20.0f?2.0f:1.0f, &Temp); m_pClient->TextRender()->TextColor(m_Color.r, m_Color.g, m_Color.b, m_Color.a); if (m_Align == -1) m_pClient->UI()->DoLabelScaled(&Temp, m_pText, m_FontSize*ms_FontmodHeight, m_Align, Temp.w); else m_pClient->UI()->DoLabelScaled(&Temp, m_pText, m_FontSize*ms_FontmodHeight, m_Align); m_pClient->TextRender()->TextColor(1, 1, 1, 1); } else if(m_Type == LUAUIRECT) { CUIRect *pRect = &m_Rect; m_pClient->RenderTools()->DrawUIRect(pRect, m_Color, m_Corners, m_Rounding); } else if(m_Type == LUAUIIMAGE) { CUIRect *pRect = &m_Rect; int state = DoImage(&m_Id, m_TextureID, m_SpriteID, pRect); if (state != 0) { if (!m_pLuaFile->FunctionExist(m_pCallback)) return; m_pLuaFile->FunctionPrepare(m_pCallback); m_pLuaFile->PushInteger(state); m_pLuaFile->PushInteger(m_Id); m_pLuaFile->FunctionExec(); } } else if(m_Type == LUAUIIMAGEEX) { CUIRect *pRect = &m_Rect; int state = DoImageEx(&m_Id, m_TextureID, pRect, m_ClipX1, m_ClipY1, m_ClipX2, m_ClipY2); if (state != 0) { if (!m_pLuaFile->FunctionExist(m_pCallback)) return; m_pLuaFile->FunctionPrepare(m_pCallback); m_pLuaFile->PushInteger(state); m_pLuaFile->PushInteger(m_Id); m_pLuaFile->FunctionExec(); } } else if(m_Type == LUAUILINE) { m_pClient->Graphics()->TextureSet(-1); m_pClient->Graphics()->BlendNormal(); m_pClient->Graphics()->LinesBegin(); m_pClient->Graphics()->SetColor(m_Color.r, m_Color.g, m_Color.b, m_Color.a); IGraphics::CLineItem Line; Line = IGraphics::CLineItem(m_Rect.x, m_Rect.y, m_Rect.w, m_Rect.h); m_pClient->Graphics()->LinesDraw(&Line, 1); m_pClient->Graphics()->LinesEnd(); } else if(m_Type == LUAUISLIDER) { float NewValue = 0; if (m_Direction == 0) { NewValue = DoScrollbarH(&m_Id, &m_Rect, m_Value, m_Color); } else { NewValue = DoScrollbarV(&m_Id, &m_Rect, m_Value, m_Color); } if (m_Value != NewValue) { m_Value = NewValue; if (!m_pLuaFile->FunctionExist(m_pCallback)) return; m_pLuaFile->FunctionPrepare(m_pCallback); m_pLuaFile->PushFloat(m_Value); m_pLuaFile->PushInteger(m_Id); m_pLuaFile->FunctionExec(); } } }
void CMenus::RenderDemoList(CUIRect MainView) { CALLSTACK_ADD(); static int s_Inited = 0; if(!s_Inited) { DemolistPopulate(); DemolistOnUpdate(true); s_Inited = 1; } char aFooterLabel[128] = {0}; if(m_DemolistSelectedIndex >= 0) { CDemoItem *Item = &m_lDemos[m_DemolistSelectedIndex]; if(str_comp(Item->m_aFilename, "..") == 0) str_copy(aFooterLabel, Localize("Parent Folder"), sizeof(aFooterLabel)); else if(m_DemolistSelectedIsDir) str_copy(aFooterLabel, Localize("Folder"), sizeof(aFooterLabel)); else { if(!Item->m_InfosLoaded) { char aBuffer[512]; str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aCurrentDemoFolder, Item->m_aFilename); Item->m_Valid = DemoPlayer()->GetDemoInfo(Storage(), aBuffer, Item->m_StorageType, &Item->m_Info); Item->m_InfosLoaded = true; } if(!Item->m_Valid) str_copy(aFooterLabel, Localize("Invalid Demo"), sizeof(aFooterLabel)); else str_copy(aFooterLabel, Localize("Demo details"), sizeof(aFooterLabel)); } } // render background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); MainView.Margin(10.0f, &MainView); CUIRect ButtonBar, RefreshRect, PlayRect, DeleteRect, RenameRect, ListBox; MainView.HSplitBottom(ms_ButtonHeight+5.0f, &MainView, &ButtonBar); ButtonBar.HSplitTop(5.0f, 0, &ButtonBar); ButtonBar.VSplitRight(130.0f, &ButtonBar, &PlayRect); ButtonBar.VSplitLeft(130.0f, &RefreshRect, &ButtonBar); ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &DeleteRect, &ButtonBar); ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &RenameRect, &ButtonBar); MainView.HSplitBottom(140.0f, &ListBox, &MainView); // render demo info MainView.VMargin(5.0f, &MainView); MainView.HSplitBottom(5.0f, &MainView, 0); RenderTools()->DrawUIRect(&MainView, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f); if(!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_lDemos[m_DemolistSelectedIndex].m_Valid) { CUIRect Left, Right, Labels; MainView.Margin(20.0f, &MainView); MainView.VSplitMid(&Labels, &MainView); // left side Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Created:"), 14.0f, -1); char aTimestamp[256]; str_timestamp_ex(m_lDemos[m_DemolistSelectedIndex].m_Date, aTimestamp, sizeof(aTimestamp), "%Y-%m-%d %H:%M:%S"); UI()->DoLabelScaled(&Right, aTimestamp, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Type:"), 14.0f, -1); UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aType, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Length:"), 14.0f, -1); int Length = ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[0]<<24)&0xFF000000) | ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[1]<<16)&0xFF0000) | ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[2]<<8)&0xFF00) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[3]&0xFF); char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%d:%02d", Length/60, Length%60); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Version:"), 14.0f, -1); str_format(aBuf, sizeof(aBuf), "%d", m_lDemos[m_DemolistSelectedIndex].m_Info.m_Version); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); // right side Labels = MainView; Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Map:"), 14.0f, -1); UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapName, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(20.0f, 0, &Left); Left.VSplitLeft(130.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Size:"), 14.0f, -1); unsigned Size = (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[0]<<24) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[1]<<16) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[2]<<8) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[3]); if(Size > 1024*1024) str_format(aBuf, sizeof(aBuf), Localize("%.2f MiB"), float(Size)/(1024*1024)); else str_format(aBuf, sizeof(aBuf), Localize("%.2f KiB"), float(Size)/1024); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(20.0f, 0, &Left); Left.VSplitLeft(130.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Crc:"), 14.0f, -1); unsigned Crc = (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[0]<<24) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[1]<<16) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[2]<<8) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[3]); str_format(aBuf, sizeof(aBuf), "%08x", Crc); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Netversion:"), 14.0f, -1); UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aNetversion, 14.0f, -1); } // demo list CUIRect Headers; ListBox.HSplitTop(ms_ListheaderHeight, &Headers, &ListBox); struct CColumn { int m_ID; int m_Sort; CLocConstString m_Caption; int m_Direction; float m_Width; int m_Flags; CUIRect m_Rect; CUIRect m_Spacer; }; enum { COL_ICON=0, COL_DEMONAME, COL_DATE, SORT_DEMONAME=0, SORT_DATE, }; static CColumn s_aCols[] = { {COL_ICON, -1, " ", -1, 14.0f, 0, 0, 0}, {COL_DEMONAME, SORT_DEMONAME, "Demo", 0, 0.0f, 0, 0, 0}, {COL_DATE, SORT_DATE, "Date", 1, 300.0f, 0, 0, 0}, }; RenderTools()->DrawUIRect(&Headers, vec4(0.0f,0,0,0.15f), 0, 0); int NumCols = sizeof(s_aCols)/sizeof(CColumn); // do layout for(int i = 0; i < NumCols; i++) { if(s_aCols[i].m_Direction == -1) { Headers.VSplitLeft(s_aCols[i].m_Width, &s_aCols[i].m_Rect, &Headers); if(i+1 < NumCols) { //Cols[i].flags |= SPACER; Headers.VSplitLeft(2, &s_aCols[i].m_Spacer, &Headers); } } } for(int i = NumCols-1; i >= 0; i--) { if(s_aCols[i].m_Direction == 1) { Headers.VSplitRight(s_aCols[i].m_Width, &Headers, &s_aCols[i].m_Rect); Headers.VSplitRight(2, &Headers, &s_aCols[i].m_Spacer); } } for(int i = 0; i < NumCols; i++) { if(s_aCols[i].m_Direction == 0) s_aCols[i].m_Rect = Headers; } // do headers for(int i = 0; i < NumCols; i++) { CPointerContainer Container(s_aCols[i].m_Caption); if(DoButton_GridHeader(&Container, s_aCols[i].m_Caption, g_Config.m_BrDemoSort == s_aCols[i].m_Sort, &s_aCols[i].m_Rect)) { if(s_aCols[i].m_Sort != -1) { if(g_Config.m_BrDemoSort == s_aCols[i].m_Sort) g_Config.m_BrDemoSortOrder ^= 1; else g_Config.m_BrDemoSortOrder = 0; g_Config.m_BrDemoSort = s_aCols[i].m_Sort; } DemolistPopulate(); DemolistOnUpdate(false); } } // scrollbar CUIRect Scroll; #if defined(__ANDROID__) ListBox.VSplitRight(50, &ListBox, &Scroll); #else ListBox.VSplitRight(15, &ListBox, &Scroll); #endif int Num = (int)(ListBox.h/s_aCols[0].m_Rect.h) + 1; static CButtonContainer s_ScrollBar; static float s_ScrollValue = 0; Scroll.HMargin(5.0f, &Scroll); s_ScrollValue = DoScrollbarV(&s_ScrollBar, &Scroll, s_ScrollValue); int ScrollNum = m_lDemos.size()-Num+1; if(ScrollNum > 0) { if(m_ScrollOffset) { s_ScrollValue = (float)(m_ScrollOffset)/ScrollNum; m_ScrollOffset = 0; } if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP) && UI()->MouseInside(&ListBox) && m_pClient->m_pGameConsole->IsClosed()) s_ScrollValue -= 3.0f/ScrollNum; if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN) && UI()->MouseInside(&ListBox) && m_pClient->m_pGameConsole->IsClosed()) s_ScrollValue += 3.0f/ScrollNum; } else ScrollNum = 0; if(m_DemolistSelectedIndex > -1) { for(int i = 0; i < m_NumInputEvents; i++) { int NewIndex = -1; if(m_aInputEvents[i].m_Flags&IInput::FLAG_PRESS) { if(m_aInputEvents[i].m_Key == KEY_DOWN) NewIndex = m_DemolistSelectedIndex + 1; if(m_aInputEvents[i].m_Key == KEY_UP) NewIndex = m_DemolistSelectedIndex - 1; } if(NewIndex > -1 && NewIndex < m_lDemos.size()) { //scroll float IndexY = ListBox.y - s_ScrollValue*ScrollNum*s_aCols[0].m_Rect.h + NewIndex*s_aCols[0].m_Rect.h; int Scroll = ListBox.y > IndexY ? -1 : ListBox.y+ListBox.h < IndexY+s_aCols[0].m_Rect.h ? 1 : 0; if(Scroll) { if(Scroll < 0) { int NumScrolls = (ListBox.y-IndexY+s_aCols[0].m_Rect.h-1.0f)/s_aCols[0].m_Rect.h; s_ScrollValue -= (1.0f/ScrollNum)*NumScrolls; } else { int NumScrolls = (IndexY+s_aCols[0].m_Rect.h-(ListBox.y+ListBox.h)+s_aCols[0].m_Rect.h-1.0f)/s_aCols[0].m_Rect.h; s_ScrollValue += (1.0f/ScrollNum)*NumScrolls; } } m_DemolistSelectedIndex = NewIndex; str_copy(g_Config.m_UiDemoSelected, m_lDemos[NewIndex].m_aName, sizeof(g_Config.m_UiDemoSelected)); DemolistOnUpdate(false); } } } if(s_ScrollValue < 0) s_ScrollValue = 0; if(s_ScrollValue > 1) s_ScrollValue = 1; // set clipping UI()->ClipEnable(&ListBox); CUIRect OriginalView = ListBox; ListBox.y -= s_ScrollValue*ScrollNum*s_aCols[0].m_Rect.h; int NewSelected = -1; #if defined(__ANDROID__) int DoubleClicked = 0; #endif int ItemIndex = -1; for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) { ItemIndex++; CUIRect Row; CUIRect SelectHitBox; ListBox.HSplitTop(ms_ListheaderHeight, &Row, &ListBox); SelectHitBox = Row; int Selected = ItemIndex == m_DemolistSelectedIndex; // make sure that only those in view can be selected if(Row.y+Row.h > OriginalView.y && Row.y < OriginalView.y+OriginalView.h) { if(Selected) { CUIRect r = Row; r.Margin(1.5f, &r); RenderTools()->DrawUIRect(&r, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f); } // clip the selection if(SelectHitBox.y < OriginalView.y) // top { SelectHitBox.h -= OriginalView.y-SelectHitBox.y; SelectHitBox.y = OriginalView.y; } else if(SelectHitBox.y+SelectHitBox.h > OriginalView.y+OriginalView.h) // bottom SelectHitBox.h = OriginalView.y+OriginalView.h-SelectHitBox.y; if(UI()->DoButtonLogic(r.front().m_aName /* TODO: */, "", Selected, &SelectHitBox)) { NewSelected = ItemIndex; str_copy(g_Config.m_UiDemoSelected, r.front().m_aName, sizeof(g_Config.m_UiDemoSelected)); DemolistOnUpdate(false); #if defined(__ANDROID__) if(NewSelected == m_DoubleClickIndex) DoubleClicked = 1; #endif m_DoubleClickIndex = NewSelected; } } else { // don't render invisible items continue; } for(int c = 0; c < NumCols; c++) { CUIRect Button; Button.x = s_aCols[c].m_Rect.x; Button.y = Row.y; Button.h = Row.h; Button.w = s_aCols[c].m_Rect.w; int ID = s_aCols[c].m_ID; if (ID == COL_ICON) { DoButton_Icon(IMAGE_FILEICONS, r.front().m_IsDir?SPRITE_FILE_FOLDER:SPRITE_FILE_DEMO1, &Button); } else if(ID == COL_DEMONAME) { CTextCursor Cursor; TextRender()->SetCursor(&Cursor, Button.x, Button.y, 12.0f * UI()->Scale(), TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); Cursor.m_LineWidth = Button.w; TextRender()->TextEx(&Cursor, r.front().m_aName, -1); } else if (ID == COL_DATE && !r.front().m_IsDir) { CTextCursor Cursor; TextRender()->SetCursor(&Cursor, Button.x, Button.y, 12.0f * UI()->Scale(), TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); Cursor.m_LineWidth = Button.w; char aBuf[256]; str_timestamp_ex(r.front().m_Date, aBuf, sizeof(aBuf), "%Y-%m-%d %H:%M:%S"); TextRender()->TextEx(&Cursor, aBuf, -1); } } } UI()->ClipDisable(); bool Activated = false; #if defined(__ANDROID__) if (m_EnterPressed || (DoubleClicked && UI()->HotItem() == m_lDemos[m_DemolistSelectedIndex].m_aName)) #else if (m_EnterPressed || (Input()->MouseDoubleClick() && UI()->HotItem() == m_lDemos[m_DemolistSelectedIndex].m_aName)) #endif { UI()->SetActiveItem(0); Activated = true; } static CButtonContainer s_RefreshButton; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect) || Input()->KeyPress(KEY_F5) || (Input()->KeyPress(KEY_R) && (Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL)))) { DemolistPopulate(); DemolistOnUpdate(false); } static CButtonContainer s_PlayButton; if(DoButton_Menu(&s_PlayButton, m_DemolistSelectedIsDir?Localize("Open"):Localize("Play"), 0, &PlayRect) || Activated) { if(m_DemolistSelectedIndex >= 0) { if(m_DemolistSelectedIsDir) // folder { if(str_comp(m_lDemos[m_DemolistSelectedIndex].m_aFilename, "..") == 0) // parent folder fs_parent_dir(m_aCurrentDemoFolder); else // sub folder { char aTemp[256]; str_copy(aTemp, m_aCurrentDemoFolder, sizeof(aTemp)); str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", aTemp, m_lDemos[m_DemolistSelectedIndex].m_aFilename); m_DemolistStorageType = m_lDemos[m_DemolistSelectedIndex].m_StorageType; } DemolistPopulate(); DemolistOnUpdate(true); } else // file { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); const char *pError = Client()->DemoPlayer_Play(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType); if(pError) PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok")); else { UI()->SetActiveItem(0); return; } } } } if(!m_DemolistSelectedIsDir) { static CButtonContainer s_DeleteButton; if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_DELETE_DEMO; return; } } static CButtonContainer s_RenameButton; if(DoButton_Menu(&s_RenameButton, Localize("Rename"), 0, &RenameRect)) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_RENAME_DEMO; str_copy(m_aCurrentDemoFile, m_lDemos[m_DemolistSelectedIndex].m_aFilename, sizeof(m_aCurrentDemoFile)); return; } } } }
void CMenus::RenderGame(CUIRect MainView) { if(m_pClient->m_LocalClientID == -1) return; char aBuf[128]; CSwitchTeamInfo Info; GetSwitchTeamInfo(&Info); CUIRect Button, BottomView, Left, Middle, Right; // cut view MainView.HSplitBottom(80.0f, &MainView, &BottomView); // MainView not used for now BottomView.HSplitTop(20.f, 0, &BottomView); float Spacing = 3.0f; float ButtonWidth = (BottomView.w/6.0f)-(Spacing*5.0)/6.0f; BottomView.VSplitLeft(ButtonWidth*3.0f+Spacing*2.0f, &Left, &Middle); Middle.VSplitLeft(Spacing, 0, &Middle); Middle.VSplitLeft(ButtonWidth, &Middle, &Right); Right.VSplitRight(ButtonWidth, 0, &Right); if(!(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)) Left.VSplitLeft(ButtonWidth, &Left, 0); // do backgrounds RenderTools()->DrawUIRect4(&Left, vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); RenderTools()->DrawUIRect4(&Middle, vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); RenderTools()->DrawUIRect4(&Right, vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); // do buttons Left.HSplitTop(25.0f, &Left, 0); Middle.HSplitTop(25.0f, &Middle, 0); Right.HSplitTop(25.0f, &Right, 0); if(Info.m_aNotification[0] != 0) { // print notice CUIRect Bar; MainView.HSplitTop(45.0f, &Bar, &MainView); RenderTools()->DrawUIRect(&Bar, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_B, 10.0f); Bar.HMargin(15.0f, &Bar); UI()->DoLabelScaled(&Bar, Info.m_aNotification, 14.0f, CUI::ALIGN_CENTER); } // join buttons { // specator button int Team = m_pClient->m_aClients[m_pClient->m_LocalClientID].m_Team; if(Info.m_aNotification[0] && Team != TEAM_SPECTATORS) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_SPECTATORS ? "Spectate" : "Spectating"), sizeof(aBuf)); // Localize("Spectating"); Left.VSplitLeft(ButtonWidth, &Button, &Left); Left.VSplitLeft(Spacing, 0, &Left); static CButtonContainer s_SpectateButton; if(DoButton_Menu(&s_SpectateButton, aBuf, Team == TEAM_SPECTATORS, &Button) && Team != TEAM_SPECTATORS && Info.m_AllowSpec && !(Info.m_aNotification[0])) { m_pClient->SendSwitchTeam(TEAM_SPECTATORS); SetActive(false); } // team button if(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS) { if(Info.m_aNotification[0] && Team != TEAM_RED) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_RED ? "Join red" : "Joined red"), sizeof(aBuf)); // Localize("Join red");Localize("Joined red"); Left.VSplitLeft(ButtonWidth, &Button, &Left); Left.VSplitLeft(Spacing, 0, &Left); static CButtonContainer s_RedButton; if(DoButton_Menu(&s_RedButton, aBuf, Team == TEAM_RED, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.975f, 0.17f, 0.17f, 0.75f), false) && Team != TEAM_RED && !(Info.m_aNotification[0])) { m_pClient->SendSwitchTeam(TEAM_RED); SetActive(false); } if(Info.m_aNotification[0] && Team != TEAM_BLUE) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_BLUE ? "Join blue" : "Joined blue"), sizeof(aBuf)); // Localize("Join blue");Localize("Joined blue"); Left.VSplitLeft(ButtonWidth, &Button, &Left); static CButtonContainer s_BlueButton; if(DoButton_Menu(&s_BlueButton, aBuf, Team == TEAM_BLUE, &Button, 0, CUI::CORNER_ALL, 5.0f, 0.0f, vec4(0.17f, 0.46f, 0.975f, 0.75f), false) && Team != TEAM_BLUE && !(Info.m_aNotification[0])) { m_pClient->SendSwitchTeam(TEAM_BLUE); SetActive(false); } } else { if(Info.m_aNotification[0] && Team != TEAM_RED) { if(Info.m_TimeLeft) str_format(aBuf, sizeof(aBuf), "(%d)", Info.m_TimeLeft); else str_copy(aBuf, Localize("locked"), sizeof(aBuf)); } else str_copy(aBuf, Localize(Team != TEAM_RED ? "Join" : "Joined"), sizeof(aBuf)); //Localize("Join");Localize("Joined"); Left.VSplitLeft(ButtonWidth, &Button, &Left); static CButtonContainer s_JoinButton; if(DoButton_Menu(&s_JoinButton, aBuf, Team == TEAM_RED, &Button) && Team != TEAM_RED && !(Info.m_aNotification[0])) { m_pClient->SendSwitchTeam(TEAM_RED); SetActive(false); } } } // Record button static CButtonContainer s_DemoButton; bool Recording = DemoRecorder()->IsRecording(); if(DoButton_Menu(&s_DemoButton, Localize(Recording ? "Stop record" : "Record"), Recording, &Middle)) // Localize("Stop record");Localize("Record"); { if(!Recording) Client()->DemoRecorder_Start("demo", true); else Client()->DemoRecorder_Stop(); } // disconnect button static CButtonContainer s_DisconnectButton; if(DoButton_Menu(&s_DisconnectButton, Localize("Disconnect"), 0, &Right)) Client()->Disconnect(); }
int CMenus::Render() { CUIRect Screen = *UI()->Screen(); Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h); static bool s_First = true; if(s_First) { if(g_Config.m_UiPage == PAGE_INTERNET) ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); else if(g_Config.m_UiPage == PAGE_LAN) ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); else if(g_Config.m_UiPage == PAGE_FAVORITES) ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); s_First = false; } if(Client()->State() == IClient::STATE_ONLINE) { ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame; ms_ColorTabbarActive = ms_ColorTabbarActiveIngame; } else { RenderBackground(); ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame; ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame; } CUIRect TabBar; CUIRect MainView; // some margin around the screen Screen.Margin(10.0f, &Screen); if(m_Popup == POPUP_NONE) { // do tab bar Screen.HSplitTop(24.0f, &TabBar, &MainView); TabBar.VMargin(20.0f, &TabBar); RenderMenubar(TabBar); // news is not implemented yet if(g_Config.m_UiPage <= PAGE_NEWS || g_Config.m_UiPage > PAGE_SETTINGS || (Client()->State() == IClient::STATE_OFFLINE && g_Config.m_UiPage >= PAGE_GAME && g_Config.m_UiPage <= PAGE_CALLVOTE)) { ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); g_Config.m_UiPage = PAGE_INTERNET; } // render current page if(Client()->State() != IClient::STATE_OFFLINE) { if(m_GamePage == PAGE_GAME) RenderGame(MainView); else if(m_GamePage == PAGE_SERVER_INFO) RenderServerInfo(MainView); else if(m_GamePage == PAGE_CALLVOTE) RenderServerControl(MainView); else if(m_GamePage == PAGE_SETTINGS) RenderSettings(MainView); } else if(g_Config.m_UiPage == PAGE_NEWS) RenderNews(MainView); else if(g_Config.m_UiPage == PAGE_INTERNET) RenderServerbrowser(MainView); else if(g_Config.m_UiPage == PAGE_LAN) RenderServerbrowser(MainView); else if(g_Config.m_UiPage == PAGE_DEMOS) RenderDemoList(MainView); else if(g_Config.m_UiPage == PAGE_FAVORITES) RenderServerbrowser(MainView); else if(g_Config.m_UiPage == PAGE_SETTINGS) RenderSettings(MainView); } else { // make sure that other windows doesn't do anything funnay! //UI()->SetHotItem(0); //UI()->SetActiveItem(0); char aBuf[128]; const char *pTitle = ""; const char *pExtraText = ""; const char *pButtonText = ""; int ExtraAlign = 0; if(m_Popup == POPUP_MESSAGE) { pTitle = m_aMessageTopic; pExtraText = m_aMessageBody; pButtonText = m_aMessageButton; } else if(m_Popup == POPUP_CONNECTING) { pTitle = Localize("Connecting to"); pExtraText = g_Config.m_UiServerAddress; // TODO: query the client about the address pButtonText = Localize("Abort"); if(Client()->MapDownloadTotalsize() > 0) { pTitle = Localize("Downloading map"); str_format(aBuf, sizeof(aBuf), "%d/%d KiB", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024); pExtraText = aBuf; } } else if(m_Popup == POPUP_DISCONNECTED) { pTitle = Localize("Disconnected"); pExtraText = Client()->ErrorString(); pButtonText = Localize("Ok"); ExtraAlign = -1; } else if(m_Popup == POPUP_PURE) { pTitle = Localize("Disconnected"); pExtraText = Localize("The server is running a non-standard tuning on a pure game type."); pButtonText = Localize("Ok"); ExtraAlign = -1; } else if(m_Popup == POPUP_PASSWORD) { pTitle = Localize("Password incorrect"); pExtraText = Client()->ErrorString(); pButtonText = Localize("Try again"); } else if(m_Popup == POPUP_QUIT) { pTitle = Localize("Quit"); pExtraText = Localize("Are you sure that you want to quit?"); } else if(m_Popup == POPUP_FIRST_LAUNCH) { pTitle = Localize("Welcome to Teeworlds"); pExtraText = Localize("As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server."); pButtonText = Localize("Ok"); ExtraAlign = -1; } CUIRect Box, Part; Box = Screen; Box.VMargin(150.0f, &Box); Box.HMargin(150.0f, &Box); // render the box RenderTools()->DrawUIRect(&Box, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f); Box.HSplitTop(20.f, &Part, &Box); Box.HSplitTop(24.f, &Part, &Box); UI()->DoLabel(&Part, pTitle, 24.f, 0); Box.HSplitTop(20.f, &Part, &Box); Box.HSplitTop(24.f, &Part, &Box); Part.VMargin(20.f, &Part); if(ExtraAlign == -1) UI()->DoLabel(&Part, pExtraText, 20.f, -1, (int)Part.w); else UI()->DoLabel(&Part, pExtraText, 20.f, 0, -1); if(m_Popup == POPUP_QUIT) { CUIRect Yes, No; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); Part.VSplitMid(&No, &Yes); Yes.VMargin(20.0f, &Yes); No.VMargin(20.0f, &No); static int s_ButtonAbort = 0; if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed) m_Popup = POPUP_NONE; static int s_ButtonTryAgain = 0; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed) Client()->Quit(); } else if(m_Popup == POPUP_PASSWORD) { CUIRect Label, TextBox, TryAgain, Abort; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); Part.VSplitMid(&Abort, &TryAgain); TryAgain.VMargin(20.0f, &TryAgain); Abort.VMargin(20.0f, &Abort); static int s_ButtonAbort = 0; if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed) m_Popup = POPUP_NONE; static int s_ButtonTryAgain = 0; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed) { Client()->Connect(g_Config.m_UiServerAddress); } Box.HSplitBottom(60.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VSplitLeft(60.0f, 0, &Label); Label.VSplitLeft(100.0f, 0, &TextBox); TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Password"), 18.0f, -1); static float Offset = 0.0f; DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true); } else if(m_Popup == POPUP_FIRST_LAUNCH) { CUIRect Label, TextBox; Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(80.0f, &Part); static int s_EnterButton = 0; if(DoButton_Menu(&s_EnterButton, Localize("Enter"), 0, &Part) || m_EnterPressed) m_Popup = POPUP_NONE; Box.HSplitBottom(40.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VSplitLeft(60.0f, 0, &Label); Label.VSplitLeft(100.0f, 0, &TextBox); TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Nickname"), 18.0f, -1); static float Offset = 0.0f; DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &Offset); } else { Box.HSplitBottom(20.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part); Part.VMargin(120.0f, &Part); static int s_Button = 0; if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed) { if(m_Popup == POPUP_CONNECTING) Client()->Disconnect(); m_Popup = POPUP_NONE; } } } return 0; }
void CMenus::RenderDemoList(CUIRect MainView) { static int s_Inited = 0; if(!s_Inited) { DemolistPopulate(); DemolistOnUpdate(true); s_Inited = 1; } char aFooterLabel[128] = {0}; if(m_DemolistSelectedIndex >= 0) { CDemoItem *Item = &m_lDemos[m_DemolistSelectedIndex]; if(str_comp(Item->m_aFilename, "..") == 0) str_copy(aFooterLabel, Localize("Parent Folder"), sizeof(aFooterLabel)); else if(m_DemolistSelectedIsDir) str_copy(aFooterLabel, Localize("Folder"), sizeof(aFooterLabel)); else { if(!Item->m_InfosLoaded) { char aBuffer[512]; str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aCurrentDemoFolder, Item->m_aFilename); Item->m_Valid = DemoPlayer()->GetDemoInfo(Storage(), aBuffer, Item->m_StorageType, &Item->m_Info); Item->m_InfosLoaded = true; } if(!Item->m_Valid) str_copy(aFooterLabel, Localize("Invalid Demo"), sizeof(aFooterLabel)); else str_copy(aFooterLabel, Localize("Demo details"), sizeof(aFooterLabel)); } } // render background RenderTools()->DrawUIRect(&MainView, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 10.0f); MainView.Margin(10.0f, &MainView); CUIRect ButtonBar, RefreshRect, PlayRect, DeleteRect, RenameRect, FileIcon, ListBox; MainView.HSplitBottom(ms_ButtonHeight+5.0f, &MainView, &ButtonBar); ButtonBar.HSplitTop(5.0f, 0, &ButtonBar); ButtonBar.VSplitRight(130.0f, &ButtonBar, &PlayRect); ButtonBar.VSplitLeft(130.0f, &RefreshRect, &ButtonBar); ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &DeleteRect, &ButtonBar); ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &RenameRect, &ButtonBar); MainView.HSplitBottom(140.0f, &ListBox, &MainView); // render demo info MainView.VMargin(5.0f, &MainView); MainView.HSplitBottom(5.0f, &MainView, 0); RenderTools()->DrawUIRect(&MainView, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f); if(!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_lDemos[m_DemolistSelectedIndex].m_Valid) { CUIRect Left, Right, Labels; MainView.Margin(20.0f, &MainView); MainView.VSplitMid(&Labels, &MainView); // left side Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Created:"), 14.0f, -1); UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aTimestamp, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Type:"), 14.0f, -1); UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aType, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Length:"), 14.0f, -1); int Length = ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[0]<<24)&0xFF000000) | ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[1]<<16)&0xFF0000) | ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[2]<<8)&0xFF00) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[3]&0xFF); char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%d:%02d", Length/60, Length%60); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Version:"), 14.0f, -1); str_format(aBuf, sizeof(aBuf), "%d", m_lDemos[m_DemolistSelectedIndex].m_Info.m_Version); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); // right side Labels = MainView; Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Map:"), 14.0f, -1); UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapName, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(20.0f, 0, &Left); Left.VSplitLeft(130.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Size:"), 14.0f, -1); unsigned Size = (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[0]<<24) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[1]<<16) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[2]<<8) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[3]); str_format(aBuf, sizeof(aBuf), Localize("%d Bytes"), Size); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(20.0f, 0, &Left); Left.VSplitLeft(130.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Crc:"), 14.0f, -1); unsigned Crc = (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[0]<<24) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[1]<<16) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[2]<<8) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[3]); str_format(aBuf, sizeof(aBuf), "%08x", Crc); UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1); Labels.HSplitTop(5.0f, 0, &Labels); Labels.HSplitTop(20.0f, &Left, &Labels); Left.VSplitLeft(150.0f, &Left, &Right); UI()->DoLabelScaled(&Left, Localize("Netversion:"), 14.0f, -1); UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aNetversion, 14.0f, -1); } static int s_DemoListId = 0; static float s_ScrollValue = 0; UiDoListboxStart(&s_DemoListId, &ListBox, 17.0f, Localize("Demos"), aFooterLabel, m_lDemos.size(), 1, m_DemolistSelectedIndex, s_ScrollValue); for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) { CListboxItem Item = UiDoListboxNextItem((void*)(&r.front())); if(Item.m_Visible) { Item.m_Rect.VSplitLeft(Item.m_Rect.h, &FileIcon, &Item.m_Rect); Item.m_Rect.VSplitLeft(5.0f, 0, &Item.m_Rect); DoButton_Icon(IMAGE_FILEICONS, r.front().m_IsDir?SPRITE_FILE_FOLDER:SPRITE_FILE_DEMO1, &FileIcon); UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight, -1); } } bool Activated = false; m_DemolistSelectedIndex = UiDoListboxEnd(&s_ScrollValue, &Activated); DemolistOnUpdate(false); static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect)) { DemolistPopulate(); DemolistOnUpdate(false); } static int s_PlayButton = 0; if(DoButton_Menu(&s_PlayButton, m_DemolistSelectedIsDir?Localize("Open"):Localize("Play"), 0, &PlayRect) || Activated) { if(m_DemolistSelectedIndex >= 0) { if(m_DemolistSelectedIsDir) // folder { if(str_comp(m_lDemos[m_DemolistSelectedIndex].m_aFilename, "..") == 0) // parent folder fs_parent_dir(m_aCurrentDemoFolder); else // sub folder { char aTemp[256]; str_copy(aTemp, m_aCurrentDemoFolder, sizeof(aTemp)); str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", aTemp, m_lDemos[m_DemolistSelectedIndex].m_aFilename); m_DemolistStorageType = m_lDemos[m_DemolistSelectedIndex].m_StorageType; } DemolistPopulate(); DemolistOnUpdate(true); } else // file { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); const char *pError = Client()->DemoPlayer_Play(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType); if(pError) PopupMessage(Localize("Error loading demo"), pError, Localize("Ok")); else { UI()->SetActiveItem(0); return; } } } } if(!m_DemolistSelectedIsDir) { static int s_DeleteButton = 0; if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_DELETE_DEMO; return; } } static int s_RenameButton = 0; if(DoButton_Menu(&s_RenameButton, Localize("Rename"), 0, &RenameRect)) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_RENAME_DEMO; str_copy(m_aCurrentDemoFile, m_lDemos[m_DemolistSelectedIndex].m_aFilename, sizeof(m_aCurrentDemoFile)); return; } } } }
void CMenus::RenderDemoList(CUIRect MainView) { CUIRect BottomView; MainView.HSplitTop(20.0f, 0, &MainView); // back button RenderBackButton(MainView); // cut view MainView.HSplitBottom(80.0f, &MainView, &BottomView); BottomView.HSplitTop(20.f, 0, &BottomView); static int s_Inited = 0; if(!s_Inited) { DemolistPopulate(); DemolistOnUpdate(true); s_Inited = 1; } char aFooterLabel[128] = {0}; if(m_DemolistSelectedIndex >= 0) { CDemoItem *Item = &m_lDemos[m_DemolistSelectedIndex]; if(str_comp(Item->m_aFilename, "..") == 0) str_copy(aFooterLabel, Localize("Parent Folder"), sizeof(aFooterLabel)); else if(m_DemolistSelectedIsDir) str_copy(aFooterLabel, Localize("Folder"), sizeof(aFooterLabel)); else { if(!Item->m_InfosLoaded) { char aBuffer[512]; str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aCurrentDemoFolder, Item->m_aFilename); Item->m_Valid = DemoPlayer()->GetDemoInfo(Storage(), aBuffer, Item->m_StorageType, &Item->m_Info); Item->m_InfosLoaded = true; } if(!Item->m_Valid) str_copy(aFooterLabel, Localize("Invalid Demo"), sizeof(aFooterLabel)); else str_copy(aFooterLabel, Localize("Demo details"), sizeof(aFooterLabel)); } } CUIRect ListBox, Button, Label, FileIcon; MainView.HSplitTop(230.0f, &ListBox, &MainView); static int s_DemoListId = 0; static float s_ScrollValue = 0; UiDoListboxHeader(&ListBox, Localize("Recorded"), 20.0f, 2.0f); UiDoListboxStart(&s_DemoListId, 20.0f, 0, m_lDemos.size(), 1, m_DemolistSelectedIndex, s_ScrollValue); for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) { CListboxItem Item = UiDoListboxNextItem((void*)(&r.front())); if(Item.m_Visible) { Item.m_Rect.VSplitLeft(Item.m_Rect.h, &FileIcon, &Item.m_Rect); Item.m_Rect.VSplitLeft(5.0f, 0, &Item.m_Rect); FileIcon.Margin(3.0f, &FileIcon); FileIcon.x += 3.0f; DoButton_Icon(IMAGE_FILEICONS, r.front().m_IsDir?SPRITE_FILE_FOLDER:SPRITE_FILE_DEMO1, &FileIcon); if(!str_comp(m_lDemos[m_DemolistSelectedIndex].m_aName, r.front().m_aName)) { TextRender()->TextColor(0.0f, 0.0f, 0.0f, 1.0f); TextRender()->TextOutlineColor(1.0f, 1.0f, 1.0f, 0.25f); Item.m_Rect.y += 2.0f; UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, 0); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); TextRender()->TextOutlineColor(0.0f, 0.0f, 0.0f, 0.3f); } else { Item.m_Rect.y += 2.0f; UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight*0.8f, 0); } } } bool Activated = false; m_DemolistSelectedIndex = UiDoListboxEnd(&s_ScrollValue, &Activated); DemolistOnUpdate(false); // render demo info int NumOptions = (!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_lDemos[m_DemolistSelectedIndex].m_Valid) ? 8 : 0; float ButtonHeight = 20.0f; float Spacing = 2.0f; float BackgroundHeight = (float)(NumOptions+1)*ButtonHeight+(float)NumOptions*Spacing; MainView.HSplitTop(10.0f, 0, &MainView); MainView.HSplitTop(BackgroundHeight, &MainView, 0); RenderTools()->DrawUIRect(&MainView, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 5.0f); MainView.HSplitTop(ButtonHeight, &Label, &MainView); Label.y += 2.0f; UI()->DoLabel(&Label, aFooterLabel, ButtonHeight*ms_FontmodHeight*0.8f, 0); if(!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_lDemos[m_DemolistSelectedIndex].m_Valid) { MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); DoInfoBox(&Button, Localize("Created"), m_lDemos[m_DemolistSelectedIndex].m_Info.m_aTimestamp); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); DoInfoBox(&Button, Localize("Type"), m_lDemos[m_DemolistSelectedIndex].m_Info.m_aType); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); int Length = ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[0]<<24)&0xFF000000) | ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[1]<<16)&0xFF0000) | ((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[2]<<8)&0xFF00) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aLength[3]&0xFF); char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%d:%02d", Length/60, Length%60); DoInfoBox(&Button, Localize("Length"), aBuf); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); str_format(aBuf, sizeof(aBuf), "%d", m_lDemos[m_DemolistSelectedIndex].m_Info.m_Version); DoInfoBox(&Button, Localize("Version"), aBuf); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); DoInfoBox(&Button, Localize("Netversion"), m_lDemos[m_DemolistSelectedIndex].m_Info.m_aNetversion); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); DoInfoBox(&Button, Localize("Map"), m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapName); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); Button.VSplitLeft(ButtonHeight, 0, &Button); float Size = float((m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[0]<<24) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[1]<<16) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[2]<<8) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapSize[3]))/1024.0f; str_format(aBuf, sizeof(aBuf), Localize("%.3f KiB"), Size); DoInfoBox(&Button, Localize("Size"), aBuf); MainView.HSplitTop(Spacing, 0, &MainView); MainView.HSplitTop(ButtonHeight, &Button, &MainView); Button.VSplitLeft(ButtonHeight, 0, &Button); unsigned Crc = (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[0]<<24) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[1]<<16) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[2]<<8) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[3]); str_format(aBuf, sizeof(aBuf), "%08x", Crc); DoInfoBox(&Button, Localize("Crc"), aBuf); } // demo buttons int NumButtons = m_DemolistSelectedIsDir ? 2 : 4; Spacing = 3.0f; float ButtonWidth = (BottomView.w/6.0f)-(Spacing*5.0)/6.0f; float BackgroundWidth = ButtonWidth*(float)NumButtons+(float)(NumButtons-1)*Spacing; BottomView.VSplitRight(BackgroundWidth, 0, &BottomView); RenderTools()->DrawUIRect4(&BottomView, vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.25f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 5.0f); BottomView.HSplitTop(25.0f, &BottomView, 0); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &Button)) { DemolistPopulate(); DemolistOnUpdate(false); } if(!m_DemolistSelectedIsDir) { BottomView.VSplitLeft(Spacing, 0, &BottomView); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static int s_DeleteButton = 0; if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &Button) || m_DeletePressed) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_DELETE_DEMO; return; } } BottomView.VSplitLeft(Spacing, 0, &BottomView); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static int s_RenameButton = 0; if(DoButton_Menu(&s_RenameButton, Localize("Rename"), 0, &Button)) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_RENAME_DEMO; str_copy(m_aCurrentDemoFile, m_lDemos[m_DemolistSelectedIndex].m_aFilename, sizeof(m_aCurrentDemoFile)); return; } } } BottomView.VSplitLeft(Spacing, 0, &BottomView); BottomView.VSplitLeft(ButtonWidth, &Button, &BottomView); static int s_PlayButton = 0; if(DoButton_Menu(&s_PlayButton, m_DemolistSelectedIsDir?Localize("Open"):Localize("Play"), 0, &Button) || Activated) { if(m_DemolistSelectedIndex >= 0) { if(m_DemolistSelectedIsDir) // folder { if(str_comp(m_lDemos[m_DemolistSelectedIndex].m_aFilename, "..") == 0) // parent folder fs_parent_dir(m_aCurrentDemoFolder); else // sub folder { char aTemp[256]; str_copy(aTemp, m_aCurrentDemoFolder, sizeof(aTemp)); str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", aTemp, m_lDemos[m_DemolistSelectedIndex].m_aFilename); m_DemolistStorageType = m_lDemos[m_DemolistSelectedIndex].m_StorageType; } DemolistPopulate(); DemolistOnUpdate(true); } else // file { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); const char *pError = Client()->DemoPlayer_Play(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType); if(pError) PopupMessage(Localize("Error loading demo"), pError, Localize("Ok")); else { UI()->SetActiveItem(0); return; } } } } }
void CMenus::RenderServerbrowser(CUIRect MainView) { RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); CUIRect View; MainView.Margin(10.0f, &View); /* +-----------------+ +------+ | | | | | | | tool | | | | box | | | | | | | +------+ +-----------------+ button status toolbar box */ //CUIRect filters; CUIRect StatusToolBox; CUIRect ToolBox; CUIRect ButtonBox; // split off a piece for filters, details and scoreboard View.VSplitRight(200.0f, &View, &ToolBox); ToolBox.HSplitBottom(80.0f, &ToolBox, &ButtonBox); View.HSplitBottom(ms_ButtonHeight+5.0f, &View, &StatusToolBox); RenderServerbrowserServerList(View); int ToolboxPage = g_Config.m_UiToolboxPage; ToolBox.VSplitLeft(5.0f, 0, &ToolBox); // do tabbar { CUIRect TabBar; CUIRect TabButton0, TabButton1; ToolBox.HSplitTop(22.0f, &TabBar, &ToolBox); TabBar.VSplitMid(&TabButton0, &TabButton1); //TabButton0.VSplitRight(5.0f, &TabButton0, 0); //TabButton1.VSplitLeft(5.0f, 0, &TabButton1); static int s_FiltersTab = 0; if (DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage==0, &TabButton0, CUI::CORNER_TL)) ToolboxPage = 0; static int s_InfoTab = 0; if (DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage==1, &TabButton1, CUI::CORNER_TR)) ToolboxPage = 1; } g_Config.m_UiToolboxPage = ToolboxPage; RenderTools()->DrawUIRect(&ToolBox, vec4(0,0,0,0.15f), 0, 0); ToolBox.HSplitTop(5.0f, 0, &ToolBox); if(ToolboxPage == 0) RenderServerbrowserFilters(ToolBox); else if(ToolboxPage == 1) RenderServerbrowserServerDetail(ToolBox); { StatusToolBox.HSplitTop(5.0f, 0, &StatusToolBox); CUIRect Button; //buttons.VSplitRight(20.0f, &buttons, &button); StatusToolBox.VSplitRight(110.0f, &StatusToolBox, &Button); Button.VMargin(2.0f, &Button); static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &Button)) { if(g_Config.m_UiPage == PAGE_INTERNET) ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); else if(g_Config.m_UiPage == PAGE_LAN) ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); else if(g_Config.m_UiPage == PAGE_FAVORITES) ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); } char aBuf[512]; if(str_comp(Client()->LatestVersion(), "0") != 0) str_format(aBuf, sizeof(aBuf), Localize("Teeworlds %s is out! Download it at www.teeworlds.com!"), Client()->LatestVersion()); else str_format(aBuf, sizeof(aBuf), Localize("Current version: %s"), GAME_VERSION); UI()->DoLabelScaled(&StatusToolBox, aBuf, 14.0f, -1); } // do the button box { ButtonBox.VSplitLeft(5.0f, 0, &ButtonBox); ButtonBox.VSplitRight(5.0f, &ButtonBox, 0); CUIRect Button; ButtonBox.HSplitBottom(ms_ButtonHeight, &ButtonBox, &Button); Button.VSplitRight(120.0f, 0, &Button); Button.VMargin(2.0f, &Button); //button.VMargin(2.0f, &button); static int s_JoinButton = 0; if(DoButton_Menu(&s_JoinButton, Localize("Connect"), 0, &Button) || m_EnterPressed) { //dbg_msg("", "%s", g_Config.m_UiServerAddress); Client()->Connect(g_Config.m_UiServerAddress); m_EnterPressed = false; } ButtonBox.HSplitBottom(5.0f, &ButtonBox, &Button); ButtonBox.HSplitBottom(20.0f, &ButtonBox, &Button); static float Offset = 0.0f; DoEditBox(&g_Config.m_UiServerAddress, &Button, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 14.0f, &Offset); ButtonBox.HSplitBottom(20.0f, &ButtonBox, &Button); UI()->DoLabelScaled(&Button, Localize("Host address"), 14.0f, -1); } }
void CMenus::RenderStartMenu(CUIRect MainView) { CUIRect Menu; MainView.VMargin(MainView.w/2-190.0f, &Menu); Menu.HMargin(145.0f, &Menu); RenderTools()->DrawUIRect(&Menu, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 10.0f); Menu.Margin(5.0f, &Menu); CUIRect Button; Menu.HSplitTop(40.0f, &Button, &Menu); static int s_PlayButton = 0; if(DoButton_MenuImage(&s_PlayButton, Localize("Play Game"), 0, &Button, "play_game", 10.0f, 0.5f)) m_MenuPage = g_Config.m_UiBrowserPage; Menu.HSplitTop(5.0f, 0, &Menu); // little space Menu.HSplitTop(40.0f, &Button, &Menu); static int s_MapEditorButton = 0; if(DoButton_MenuImage(&s_MapEditorButton, Localize("Map Editor"), 0, &Button, "editor", 10.0f, 0.5f)) { g_Config.m_ClEditor = 1; Input()->MouseModeRelative(); } Menu.HSplitTop(5.0f, 0, &Menu); // little space Menu.HSplitTop(40.0f, &Button, &Menu); static int s_DemoButton = 0; if(DoButton_MenuImage(&s_DemoButton, Localize("Demos"), 0, &Button, "demos", 10.0f, 0.5f)) { m_MenuPage = PAGE_DEMOS; DemolistPopulate(); DemolistOnUpdate(false); } Menu.HSplitTop(5.0f, 0, &Menu); // little space Menu.HSplitTop(40.0f, &Button, &Menu); static int s_LocalServerButton = 0; if(DoButton_MenuImage(&s_LocalServerButton, Localize("Create Local Server"), 0, &Button, "local_server", 10.0f, 0.5f)) { } Menu.HSplitTop(5.0f, 0, &Menu); // little space Menu.HSplitTop(40.0f, &Button, &Menu); static int s_SettingsButton = 0; if(DoButton_MenuImage(&s_SettingsButton, Localize("Settings"), 0, &Button, "settings", 10.0f, 0.5f)) { m_MenuPage = PAGE_SETTINGS; } Menu.HSplitBottom(45.0f, &Menu, &Button); static int s_QuitButton = 0; if(DoButton_Menu(&s_QuitButton, Localize("Quit Game"), 0, &Button, 15.0f, 0.5f)) m_Popup = POPUP_QUIT; // render version CUIRect Version; MainView.HSplitBottom(50.0f, 0, &Version); Version.VMargin(50.0f, &Version); char aBuf[64]; if(str_comp(Client()->LatestVersion(), "0") != 0) { 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()->DoLabelScaled(&Version, aBuf, 14.0f, 0); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); } UI()->DoLabelScaled(&Version, GAME_VERSION, 14.0f, 1); }
void CMenus::RenderServerbrowserFilters(CUIRect View) { CUIRect ServerFilter = View, FilterHeader; const float FontSize = 12.0f; ServerFilter.HSplitBottom(42.5f, &ServerFilter, 0); // server filter ServerFilter.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFilter); RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f); RenderTools()->DrawUIRect(&ServerFilter, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f); UI()->DoLabelScaled(&FilterHeader, Localize("Server filter"), FontSize+2.0f, 0); CUIRect Button; ServerFilter.VSplitLeft(5.0f, 0, &ServerFilter); ServerFilter.Margin(3.0f, &ServerFilter); ServerFilter.VMargin(5.0f, &ServerFilter); ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox(&g_Config.m_BrFilterEmpty, Localize("Has people playing"), g_Config.m_BrFilterEmpty, &Button)) g_Config.m_BrFilterEmpty ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if(DoButton_CheckBox(&g_Config.m_BrFilterSpectators, Localize("Count players only"), g_Config.m_BrFilterSpectators, &Button)) g_Config.m_BrFilterSpectators ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox(&g_Config.m_BrFilterFull, Localize("Server not full"), g_Config.m_BrFilterFull, &Button)) g_Config.m_BrFilterFull ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox(&g_Config.m_BrFilterFriends, Localize("Show friends only"), g_Config.m_BrFilterFriends, &Button)) g_Config.m_BrFilterFriends ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox(&g_Config.m_BrFilterPw, Localize("No password"), g_Config.m_BrFilterPw, &Button)) g_Config.m_BrFilterPw ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterCompatversion, Localize("Compatible version"), g_Config.m_BrFilterCompatversion, &Button)) g_Config.m_BrFilterCompatversion ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterPure, Localize("Standard gametype"), g_Config.m_BrFilterPure, &Button)) g_Config.m_BrFilterPure ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterPureMap, Localize("Standard map"), g_Config.m_BrFilterPureMap, &Button)) g_Config.m_BrFilterPureMap ^= 1; ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterGametypeStrict, Localize("Strict gametype filter"), g_Config.m_BrFilterGametypeStrict, &Button)) g_Config.m_BrFilterGametypeStrict ^= 1; ServerFilter.HSplitTop(5.0f, 0, &ServerFilter); ServerFilter.HSplitTop(19.0f, &Button, &ServerFilter); UI()->DoLabelScaled(&Button, Localize("Game types:"), FontSize, -1); Button.VSplitRight(60.0f, 0, &Button); ServerFilter.HSplitTop(3.0f, 0, &ServerFilter); static float Offset = 0.0f; if(DoEditBox(&g_Config.m_BrFilterGametype, &Button, g_Config.m_BrFilterGametype, sizeof(g_Config.m_BrFilterGametype), FontSize, &Offset)) Client()->ServerBrowserUpdate(); { ServerFilter.HSplitTop(19.0f, &Button, &ServerFilter); CUIRect EditBox; Button.VSplitRight(60.0f, &Button, &EditBox); UI()->DoLabelScaled(&Button, Localize("Maximum ping:"), FontSize, -1); char aBuf[5]; str_format(aBuf, sizeof(aBuf), "%d", g_Config.m_BrFilterPing); static float Offset = 0.0f; DoEditBox(&g_Config.m_BrFilterPing, &EditBox, aBuf, sizeof(aBuf), FontSize, &Offset); g_Config.m_BrFilterPing = clamp(str_toint(aBuf), 0, 999); } // server address ServerFilter.HSplitTop(3.0f, 0, &ServerFilter); ServerFilter.HSplitTop(19.0f, &Button, &ServerFilter); UI()->DoLabelScaled(&Button, Localize("Server address:"), FontSize, -1); Button.VSplitRight(60.0f, 0, &Button); static float OffsetAddr = 0.0f; if(DoEditBox(&g_Config.m_BrFilterServerAddress, &Button, g_Config.m_BrFilterServerAddress, sizeof(g_Config.m_BrFilterServerAddress), FontSize, &OffsetAddr)) Client()->ServerBrowserUpdate(); // player country { CUIRect Rect; ServerFilter.HSplitTop(3.0f, 0, &ServerFilter); ServerFilter.HSplitTop(26.0f, &Button, &ServerFilter); Button.VSplitRight(60.0f, &Button, &Rect); Button.HMargin(3.0f, &Button); if(DoButton_CheckBox(&g_Config.m_BrFilterCountry, Localize("Player country:"), g_Config.m_BrFilterCountry, &Button)) g_Config.m_BrFilterCountry ^= 1; float OldWidth = Rect.w; Rect.w = Rect.h*2; Rect.x += (OldWidth-Rect.w)/2.0f; vec4 Color(1.0f, 1.0f, 1.0f, g_Config.m_BrFilterCountry?1.0f: 0.5f); m_pClient->m_pCountryFlags->Render(g_Config.m_BrFilterCountryIndex, &Color, Rect.x, Rect.y, Rect.w, Rect.h); if(g_Config.m_BrFilterCountry && UI()->DoButtonLogic(&g_Config.m_BrFilterCountryIndex, "", 0, &Rect)) m_Popup = POPUP_COUNTRY; } ServerFilter.HSplitBottom(5.0f, &ServerFilter, 0); ServerFilter.HSplitBottom(ms_ButtonHeight-2.0f, &ServerFilter, &Button); static int s_ClearButton = 0; if(DoButton_Menu(&s_ClearButton, Localize("Reset filter"), 0, &Button)) { g_Config.m_BrFilterString[0] = 0; g_Config.m_BrFilterFull = 0; g_Config.m_BrFilterEmpty = 0; g_Config.m_BrFilterSpectators = 0; g_Config.m_BrFilterFriends = 0; g_Config.m_BrFilterCountry = 0; g_Config.m_BrFilterCountryIndex = -1; g_Config.m_BrFilterPw = 0; g_Config.m_BrFilterPing = 999; g_Config.m_BrFilterGametype[0] = 0; g_Config.m_BrFilterGametypeStrict = 0; g_Config.m_BrFilterServerAddress[0] = 0; g_Config.m_BrFilterPure = 1; g_Config.m_BrFilterPureMap = 1; g_Config.m_BrFilterCompatversion = 1; Client()->ServerBrowserUpdate(); } }
void CMenus::RenderStartMenu(CUIRect MainView) { // render logo Graphics()->TextureSet(g_pData->m_aImages[IMAGE_BANNER].m_Id); Graphics()->QuadsBegin(); Graphics()->SetColor(1,1,1,1); IGraphics::CQuadItem QuadItem(MainView.w/2-140, 60, 280, 70); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); CUIRect TopMenu, BottomMenu; MainView.VMargin(MainView.w/2-190.0f, &TopMenu); TopMenu.HSplitTop(365.0f, &TopMenu, &BottomMenu); //TopMenu.HSplitBottom(145.0f, &TopMenu, 0); RenderTools()->DrawUIRect4(&TopMenu, vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), CUI::CORNER_B, 10.0f); TopMenu.HSplitTop(145.0f, 0, &TopMenu); CUIRect Button; int NewPage = -1; TopMenu.HSplitBottom(40.0f, &TopMenu, &Button); static CButtonContainer s_SettingsButton; if(DoButton_Menu(&s_SettingsButton, Localize("Settings"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "settings" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || CheckHotKey(KEY_S)) NewPage = PAGE_SETTINGS; /*TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space TopMenu.HSplitBottom(40.0f, &TopMenu, &Bottom); static int s_LocalServerButton = 0; if(g_Config.m_ClShowStartMenuImages) { if(DoButton_MenuImage(&s_LocalServerButton, Localize("Local server"), 0, &Button, "local_server", 10.0f, 0.5f)) { } } else { if(DoButton_Menu(&s_LocalServerButton, Localize("Local server"), 0, &Button, CUI::CORNER_ALL, 10.0f, 0.5f)) { } }*/ TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space TopMenu.HSplitBottom(40.0f, &TopMenu, &Button); static CButtonContainer s_DemoButton; if(DoButton_Menu(&s_DemoButton, Localize("Demos"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "demos" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || CheckHotKey(KEY_D)) { NewPage = PAGE_DEMOS; DemolistPopulate(); DemolistOnUpdate(false); } static bool EditorHotkeyWasPressed = true; static float EditorHotKeyChecktime = 0; TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space TopMenu.HSplitBottom(40.0f, &TopMenu, &Button); static CButtonContainer s_MapEditorButton; if(DoButton_Menu(&s_MapEditorButton, Localize("Editor"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "editor" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || (!EditorHotkeyWasPressed && Client()->LocalTime() - EditorHotKeyChecktime < 0.1f && CheckHotKey(KEY_E))) { g_Config.m_ClEditor = 1; Input()->MouseModeRelative(); EditorHotkeyWasPressed = true; } if(!Input()->KeyIsPressed(KEY_E)) { EditorHotkeyWasPressed = false; EditorHotKeyChecktime = Client()->LocalTime(); } TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space TopMenu.HSplitBottom(40.0f, &TopMenu, &Button); static CButtonContainer s_PlayButton; if(DoButton_Menu(&s_PlayButton, Localize("Play"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "play_game" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || m_EnterPressed || CheckHotKey(KEY_P)) NewPage = g_Config.m_UiBrowserPage; BottomMenu.HSplitTop(90.0f, 0, &BottomMenu); RenderTools()->DrawUIRect4(&BottomMenu, vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 10.0f); BottomMenu.HSplitTop(40.0f, &Button, &TopMenu); static CButtonContainer s_QuitButton; if(DoButton_Menu(&s_QuitButton, Localize("Quit"), 0, &Button, 0, CUI::CORNER_ALL, 10.0f, 0.5f) || m_EscapePressed || CheckHotKey(KEY_Q)) m_Popup = POPUP_QUIT; // render version CUIRect Version; MainView.HSplitBottom(50.0f, 0, &Version); Version.VMargin(50.0f, &Version); char aBuf[64]; if(str_comp(Client()->LatestVersion(), "0") != 0) { 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); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); } UI()->DoLabel(&Version, GAME_RELEASE_VERSION, 14.0f, CUI::ALIGN_RIGHT); if(NewPage != -1) SetMenuPage(NewPage); }
void CMenus::RenderServerbrowser(CUIRect MainView) { /* +-----------------+ +-------+ | | | | | | | tool | | server list | | box | | | | | | | | | +-----------------+ | | status box tab +-------+ */ CUIRect ServerList, ToolBox, StatusBox, TabBar; // background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); MainView.Margin(10.0f, &MainView); // create server list, status box, tab bar and tool box area MainView.VSplitRight(205.0f, &ServerList, &ToolBox); ServerList.HSplitBottom(70.0f, &ServerList, &StatusBox); StatusBox.VSplitRight(100.0f, &StatusBox, &TabBar); ServerList.VSplitRight(5.0f, &ServerList, 0); // server list { RenderServerbrowserServerList(ServerList); } int ToolboxPage = g_Config.m_UiToolboxPage; // tab bar { CUIRect TabButton0, TabButton1, TabButton2; TabBar.HSplitTop(5.0f, 0, &TabBar); TabBar.HSplitTop(20.0f, &TabButton0, &TabBar); TabBar.HSplitTop(2.5f, 0, &TabBar); TabBar.HSplitTop(20.0f, &TabButton1, &TabBar); TabBar.HSplitTop(2.5f, 0, &TabBar); TabBar.HSplitTop(20.0f, &TabButton2, 0); vec4 Active = ms_ColorTabbarActive; vec4 InActive = ms_ColorTabbarInactive; ms_ColorTabbarActive = vec4(0.0f, 0.0f, 0.0f, 0.3f); ms_ColorTabbarInactive = vec4(0.0f, 0.0f, 0.0f, 0.15f); static int s_FiltersTab = 0; if (DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage==0, &TabButton0, CUI::CORNER_L)) ToolboxPage = 0; static int s_InfoTab = 0; if (DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage==1, &TabButton1, CUI::CORNER_L)) ToolboxPage = 1; static int s_FriendsTab = 0; if (DoButton_MenuTab(&s_FriendsTab, Localize("Friends"), ToolboxPage==2, &TabButton2, CUI::CORNER_L)) ToolboxPage = 2; ms_ColorTabbarActive = Active; ms_ColorTabbarInactive = InActive; g_Config.m_UiToolboxPage = ToolboxPage; } // tool box { RenderTools()->DrawUIRect(&ToolBox, vec4(0.0f, 0.0f, 0.0f, 0.15f), CUI::CORNER_T, 4.0f); if(ToolboxPage == 0) RenderServerbrowserFilters(ToolBox); else if(ToolboxPage == 1) RenderServerbrowserServerDetail(ToolBox); else if(ToolboxPage == 2) RenderServerbrowserFriends(ToolBox); } // status box { CUIRect Button, ButtonArea; StatusBox.HSplitTop(5.0f, 0, &StatusBox); // version note StatusBox.HSplitBottom(15.0f, &StatusBox, &Button); char aBuf[64]; if(str_comp(Client()->LatestVersion(), "0") != 0) { 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); } else str_format(aBuf, sizeof(aBuf), Localize("Current version: %s"), GAME_VERSION); UI()->DoLabelScaled(&Button, aBuf, 14.0f, -1); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); // button area StatusBox.VSplitRight(80.0f, &StatusBox, 0); StatusBox.VSplitRight(170.0f, &StatusBox, &ButtonArea); ButtonArea.VSplitRight(150.0f, 0, &ButtonArea); ButtonArea.HSplitTop(20.0f, &Button, &ButtonArea); Button.VMargin(2.0f, &Button); static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &Button)) { if(g_Config.m_UiPage == PAGE_INTERNET) ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); else if(g_Config.m_UiPage == PAGE_LAN) ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); else if(g_Config.m_UiPage == PAGE_FAVORITES) ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); } ButtonArea.HSplitTop(5.0f, 0, &ButtonArea); ButtonArea.HSplitTop(20.0f, &Button, &ButtonArea); Button.VMargin(2.0f, &Button); static int s_JoinButton = 0; if(DoButton_Menu(&s_JoinButton, Localize("Connect"), 0, &Button) || m_EnterPressed) { Client()->Connect(g_Config.m_UiServerAddress); m_EnterPressed = false; } // address info StatusBox.VSplitLeft(20.0f, 0, &StatusBox); StatusBox.HSplitTop(20.0f, &Button, &StatusBox); UI()->DoLabelScaled(&Button, Localize("Host address"), 14.0f, -1); StatusBox.HSplitTop(20.0f, &Button, 0); static float Offset = 0.0f; DoEditBox(&g_Config.m_UiServerAddress, &Button, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 14.0f, &Offset); } }
void CMenus::RenderGame(CUIRect MainView) { CUIRect Button, ButtonBar; MainView.HSplitTop(45.0f, &ButtonBar, &MainView); RenderTools()->DrawUIRect(&ButtonBar, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); // button bar ButtonBar.HSplitTop(10.0f, 0, &ButtonBar); ButtonBar.HSplitTop(25.0f, &ButtonBar, 0); ButtonBar.VMargin(10.0f, &ButtonBar); ButtonBar.VSplitRight(120.0f, &ButtonBar, &Button); static int s_DisconnectButton = 0; if(DoButton_Menu(&s_DisconnectButton, Localize("Disconnect"), 0, &Button)) Client()->Disconnect(); if(m_pClient->m_Snap.m_pLocalInfo && m_pClient->m_Snap.m_pGameInfoObj) { if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS) { ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &Button, &ButtonBar); static int s_SpectateButton = 0; if(DoButton_Menu(&s_SpectateButton, Localize("Spectate"), 0, &Button)) { m_pClient->SendSwitchTeam(TEAM_SPECTATORS); SetActive(false); } } if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) { if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_RED) { ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &Button, &ButtonBar); static int s_SpectateButton = 0; if(DoButton_Menu(&s_SpectateButton, Localize("Join red"), 0, &Button)) { m_pClient->SendSwitchTeam(TEAM_RED); SetActive(false); } } if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_BLUE) { ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &Button, &ButtonBar); static int s_SpectateButton = 0; if(DoButton_Menu(&s_SpectateButton, Localize("Join blue"), 0, &Button)) { m_pClient->SendSwitchTeam(TEAM_BLUE); SetActive(false); } } } else { if(m_pClient->m_Snap.m_pLocalInfo->m_Team != 0) { ButtonBar.VSplitLeft(10.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &Button, &ButtonBar); static int s_SpectateButton = 0; if(DoButton_Menu(&s_SpectateButton, Localize("Join game"), 0, &Button)) { m_pClient->SendSwitchTeam(0); SetActive(false); } } } } ButtonBar.VSplitLeft(100.0f, 0, &ButtonBar); ButtonBar.VSplitLeft(150.0f, &Button, &ButtonBar); static int s_DemoButton = 0; bool Recording = DemoRecorder()->IsRecording(); if(DoButton_Menu(&s_DemoButton, Localize(Recording ? "Stop record" : "Record demo"), 0, &Button)) // Localize("Stop record");Localize("Record demo"); { if(!Recording) Client()->DemoRecorder_Start("demo", true); else Client()->DemoRecorder_Stop(); } }
void CMenus::RenderDemoList(CUIRect MainView) { static int s_Inited = 0; if(!s_Inited) DemolistPopulate(); s_Inited = 1; // render background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); MainView.Margin(10.0f, &MainView); CUIRect ButtonBar; MainView.HSplitBottom(ms_ButtonHeight+5.0f, &MainView, &ButtonBar); ButtonBar.HSplitTop(5.0f, 0, &ButtonBar); static int s_SelectedItem = -1; static int s_DemoListId = 0; static float s_ScrollValue = 0; UiDoListboxStart(&s_DemoListId, &MainView, 17.0f, Localize("Demos"), "", m_lDemos.size(), 1, s_SelectedItem, s_ScrollValue); //for(int i = 0; i < num_demos; i++) for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) { CListboxItem Item = UiDoListboxNextItem((void*)(&r.front())); if(Item.m_Visible) UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight, -1); } bool Activated = false; s_SelectedItem = UiDoListboxEnd(&s_ScrollValue, &Activated); CUIRect RefreshRect, PlayRect; ButtonBar.VSplitRight(250.0f, &ButtonBar, &RefreshRect); RefreshRect.VSplitRight(130.0f, &RefreshRect, &PlayRect); PlayRect.VSplitRight(120.0f, 0x0, &PlayRect); bool IsDir = false; if(!strncmp(m_lDemos[s_SelectedItem].m_aName, "..", 256)) //parent folder IsDir = true; else fs_listdir(m_lDemos[s_SelectedItem].m_aFilename, IsDirCallback, &IsDir); static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect)) { DemolistPopulate(); } static int s_PlayButton = 0; char aTitleButton[8]; if(IsDir) str_copy(aTitleButton, "Open", sizeof(aTitleButton)); else str_copy(aTitleButton, "Play", sizeof(aTitleButton)); // /!\ TODO: Add "Open" in Localization /!\ if(DoButton_Menu(&s_PlayButton, Localize(aTitleButton), 0, &PlayRect) || Activated) { if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) { if(!strncmp(m_lDemos[s_SelectedItem].m_aName, "..", 256)) { DemoSetParentDirectory(); DemolistPopulate(); s_SelectedItem = 0; } else if(IsDir) { str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", m_aCurrentDemoFolder, m_lDemos[s_SelectedItem].m_aName); DemolistPopulate(); s_SelectedItem = 0; } else { const char *pError = Client()->DemoPlayer_Play(m_lDemos[s_SelectedItem].m_aFilename); if(pError) PopupMessage(Localize("Error"), pError, Localize("Ok")); } } } }
void CMenus::RenderServerControl(CUIRect MainView) { static int s_ControlPage = 0; // render background CUIRect Bottom, Extended, TabBar, Button; MainView.HSplitTop(20.0f, &Bottom, &MainView); RenderTools()->DrawUIRect(&Bottom, ms_ColorTabbarActive, CUI::CORNER_T, 10.0f); MainView.HSplitTop(20.0f, &TabBar, &MainView); RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f); MainView.Margin(10.0f, &MainView); MainView.HSplitBottom(90.0f, &MainView, &Extended); // tab bar { TabBar.VSplitLeft(TabBar.w/3, &Button, &TabBar); static int s_Button0 = 0; if(DoButton_MenuTab(&s_Button0, Localize("Change settings"), s_ControlPage == 0, &Button, 0)) s_ControlPage = 0; TabBar.VSplitMid(&Button, &TabBar); static int s_Button1 = 0; if(DoButton_MenuTab(&s_Button1, Localize("Kick player"), s_ControlPage == 1, &Button, 0)) s_ControlPage = 1; static int s_Button2 = 0; if(DoButton_MenuTab(&s_Button2, Localize("Move player to spectators"), s_ControlPage == 2, &TabBar, 0)) s_ControlPage = 2; } // render page MainView.HSplitBottom(ms_ButtonHeight + 5*2, &MainView, &Bottom); Bottom.HMargin(5.0f, &Bottom); if(s_ControlPage == 0) RenderServerControlServer(MainView); else if(s_ControlPage == 1) RenderServerControlKick(MainView, false); else if(s_ControlPage == 2) RenderServerControlKick(MainView, true); // vote menu { CUIRect Button; Bottom.VSplitRight(120.0f, &Bottom, &Button); static int s_CallVoteButton = 0; if(DoButton_Menu(&s_CallVoteButton, Localize("Call vote"), 0, &Button)) { if(s_ControlPage == 0) m_pClient->m_pVoting->CallvoteOption(m_CallvoteSelectedOption, m_aCallvoteReason); else if(s_ControlPage == 1) { if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS && m_pClient->m_Snap.m_paPlayerInfos[m_CallvoteSelectedPlayer]) { m_pClient->m_pVoting->CallvoteKick(m_CallvoteSelectedPlayer, m_aCallvoteReason); SetActive(false); } } else if(s_ControlPage == 2) { if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS && m_pClient->m_Snap.m_paPlayerInfos[m_CallvoteSelectedPlayer]) { m_pClient->m_pVoting->CallvoteSpectate(m_CallvoteSelectedPlayer, m_aCallvoteReason); SetActive(false); } } m_aCallvoteReason[0] = 0; } // render kick reason CUIRect Reason; Bottom.VSplitRight(40.0f, &Bottom, 0); Bottom.VSplitRight(160.0f, &Bottom, &Reason); Reason.HSplitTop(5.0f, 0, &Reason); const char *pLabel = Localize("Reason:"); UI()->DoLabelScaled(&Reason, pLabel, 14.0f, -1); float w = TextRender()->TextWidth(0, 14.0f, pLabel, -1); Reason.VSplitLeft(w+10.0f, 0, &Reason); static float s_Offset = 0.0f; DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, CUI::CORNER_ALL); // extended features (only available when authed in rcon) if(Client()->RconAuthed()) { // background Extended.Margin(10.0f, &Extended); Extended.HSplitTop(20.0f, &Bottom, &Extended); Extended.HSplitTop(5.0f, 0, &Extended); // force vote Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(120.0f, &Button, &Bottom); static int s_ForceVoteButton = 0; if(DoButton_Menu(&s_ForceVoteButton, Localize("Force vote"), 0, &Button)) { if(s_ControlPage == 0) m_pClient->m_pVoting->CallvoteOption(m_CallvoteSelectedOption, m_aCallvoteReason, true); else if(s_ControlPage == 1) { if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS && m_pClient->m_Snap.m_paPlayerInfos[m_CallvoteSelectedPlayer]) { m_pClient->m_pVoting->CallvoteKick(m_CallvoteSelectedPlayer, m_aCallvoteReason, true); SetActive(false); } } else if(s_ControlPage == 2) { if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS && m_pClient->m_Snap.m_paPlayerInfos[m_CallvoteSelectedPlayer]) { m_pClient->m_pVoting->CallvoteSpectate(m_CallvoteSelectedPlayer, m_aCallvoteReason, true); SetActive(false); } } m_aCallvoteReason[0] = 0; } if(s_ControlPage == 0) { // remove vote Bottom.VSplitRight(10.0f, &Bottom, 0); Bottom.VSplitRight(120.0f, 0, &Button); static int s_RemoveVoteButton = 0; if(DoButton_Menu(&s_RemoveVoteButton, Localize("Remove"), 0, &Button)) m_pClient->m_pVoting->RemovevoteOption(m_CallvoteSelectedOption); // add vote Extended.HSplitTop(20.0f, &Bottom, &Extended); Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(250.0f, &Button, &Bottom); UI()->DoLabelScaled(&Button, Localize("Vote description:"), 14.0f, -1); Bottom.VSplitLeft(20.0f, 0, &Button); UI()->DoLabelScaled(&Button, Localize("Vote command:"), 14.0f, -1); static char s_aVoteDescription[64] = {0}; static char s_aVoteCommand[512] = {0}; Extended.HSplitTop(20.0f, &Bottom, &Extended); Bottom.VSplitRight(10.0f, &Bottom, 0); Bottom.VSplitRight(120.0f, &Bottom, &Button); static int s_AddVoteButton = 0; if(DoButton_Menu(&s_AddVoteButton, Localize("Add"), 0, &Button)) if(s_aVoteDescription[0] != 0 && s_aVoteCommand[0] != 0) m_pClient->m_pVoting->AddvoteOption(s_aVoteDescription, s_aVoteCommand); Bottom.VSplitLeft(5.0f, 0, &Bottom); Bottom.VSplitLeft(250.0f, &Button, &Bottom); static float s_OffsetDesc = 0.0f; DoEditBox(&s_aVoteDescription, &Button, s_aVoteDescription, sizeof(s_aVoteDescription), 14.0f, &s_OffsetDesc, false, CUI::CORNER_ALL); Bottom.VMargin(20.0f, &Button); static float s_OffsetCmd = 0.0f; DoEditBox(&s_aVoteCommand, &Button, s_aVoteCommand, sizeof(s_aVoteCommand), 14.0f, &s_OffsetCmd, false, CUI::CORNER_ALL); } } } }
void CMenus::RenderDemoList(CUIRect MainView) { static int s_Inited = 0; if(!s_Inited) { DemolistPopulate(); DemolistOnUpdate(true); s_Inited = 1; } char aFooterLabel[128] = {0}; if(m_DemolistSelectedIndex >= 0) { CDemoItem *Item = &m_lDemos[m_DemolistSelectedIndex]; if(str_comp(Item->m_aFilename, "..") == 0) str_copy(aFooterLabel, Localize("Parent Folder"), sizeof(aFooterLabel)); else if(m_DemolistSelectedIsDir) str_copy(aFooterLabel, Localize("Folder"), sizeof(aFooterLabel)); else { if(!Item->m_InfosLoaded) { char aBuffer[512]; str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aCurrentDemoFolder, Item->m_aFilename); Item->m_Valid = DemoPlayer()->GetDemoInfo(Storage(), aBuffer, Item->m_StorageType, Item->m_aMap, sizeof(Item->m_aMap)); Item->m_InfosLoaded = true; } if(!Item->m_Valid) str_copy(aFooterLabel, Localize("Invalid Demo"), sizeof(aFooterLabel)); else str_format(aFooterLabel, sizeof(aFooterLabel), "%s: %s", Localize("Map"), Item->m_aMap); } } // render background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); MainView.Margin(10.0f, &MainView); CUIRect ButtonBar, RefreshRect, PlayRect, DeleteRect, FileIcon; MainView.HSplitBottom(ms_ButtonHeight+5.0f, &MainView, &ButtonBar); ButtonBar.HSplitTop(5.0f, 0, &ButtonBar); ButtonBar.VSplitRight(130.0f, &ButtonBar, &PlayRect); ButtonBar.VSplitLeft(130.0f, &RefreshRect, &ButtonBar); ButtonBar.VSplitLeft(10.0f, &DeleteRect, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &DeleteRect, &ButtonBar); static int s_DemoListId = 0; static float s_ScrollValue = 0; UiDoListboxStart(&s_DemoListId, &MainView, 17.0f, Localize("Demos"), aFooterLabel, m_lDemos.size(), 1, m_DemolistSelectedIndex, s_ScrollValue); for(sorted_array<CDemoItem>::range r = m_lDemos.all(); !r.empty(); r.pop_front()) { CListboxItem Item = UiDoListboxNextItem((void*)(&r.front())); if(Item.m_Visible) { Item.m_Rect.VSplitLeft(Item.m_Rect.h, &FileIcon, &Item.m_Rect); Item.m_Rect.VSplitLeft(5.0f, 0, &Item.m_Rect); DoButton_Icon(IMAGE_FILEICONS, r.front().m_IsDir?SPRITE_FILE_FOLDER:SPRITE_FILE_DEMO1, &FileIcon); UI()->DoLabel(&Item.m_Rect, r.front().m_aName, Item.m_Rect.h*ms_FontmodHeight, -1); } } bool Activated = false; m_DemolistSelectedIndex = UiDoListboxEnd(&s_ScrollValue, &Activated); DemolistOnUpdate(false); static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect)) { DemolistPopulate(); DemolistOnUpdate(false); } static int s_PlayButton = 0; if(DoButton_Menu(&s_PlayButton, m_DemolistSelectedIsDir?Localize("Open"):Localize("Play"), 0, &PlayRect) || Activated) { if(m_DemolistSelectedIndex >= 0) { if(m_DemolistSelectedIsDir) // folder { if(str_comp(m_lDemos[m_DemolistSelectedIndex].m_aFilename, "..") == 0) // parent folder fs_parent_dir(m_aCurrentDemoFolder); else // sub folder { char aTemp[256]; str_copy(aTemp, m_aCurrentDemoFolder, sizeof(aTemp)); str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", aTemp, m_lDemos[m_DemolistSelectedIndex].m_aFilename); m_DemolistStorageType = m_lDemos[m_DemolistSelectedIndex].m_StorageType; } DemolistPopulate(); DemolistOnUpdate(true); } else // file { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); const char *pError = Client()->DemoPlayer_Play(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType); if(pError) PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok")); else { UI()->SetActiveItem(0); return; } } } } if(!m_DemolistSelectedIsDir) { static int s_DeleteButton = 0; if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) { if(m_DemolistSelectedIndex >= 0) { UI()->SetActiveItem(0); m_Popup = POPUP_DELETE_DEMO; } } } }
void CMenus::RenderDemoPlayer(CUIRect MainView) { CALLSTACK_ADD(); const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); const float SeekBarHeight = 15.0f; const float ButtonbarHeight = 20.0f; const float NameBarHeight = 20.0f; const float Margins = 5.0f; float TotalHeight; static int64 LastSpeedChange = 0; // render popups if (m_DemoPlayerState == DEMOPLAYER_SLICE_SAVE) { CUIRect Screen = *UI()->Screen(); CUIRect Box, Part, Part2; Box = Screen; Box.VMargin(150.0f/UI()->Scale(), &Box); #if defined(__ANDROID__) Box.HMargin(100.0f/UI()->Scale(), &Box); #else Box.HMargin(150.0f/UI()->Scale(), &Box); #endif // render the box RenderTools()->DrawUIRect(&Box, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f); Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box); UI()->DoLabelScaled(&Part, Localize("Select a name"), 24.f, 0); Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box); Part.VMargin(20.f/UI()->Scale(), &Part); UI()->DoLabelScaled(&Part, m_aDemoPlayerPopupHint, 24.f, 0); CUIRect Label, TextBox, Ok, Abort; Box.HSplitBottom(20.f, &Box, &Part); #if defined(__ANDROID__) Box.HSplitBottom(60.f, &Box, &Part); #else Box.HSplitBottom(24.f, &Box, &Part); #endif Part.VMargin(80.0f, &Part); Part.VSplitMid(&Abort, &Ok); Ok.VMargin(20.0f, &Ok); Abort.VMargin(20.0f, &Abort); static int s_RemoveChat = 0; static CButtonContainer s_ButtonAbort; if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed) m_DemoPlayerState = DEMOPLAYER_NONE; static CButtonContainer s_ButtonOk; if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || m_EnterPressed) { if (str_comp(m_lDemos[m_DemolistSelectedIndex].m_aFilename, m_aCurrentDemoFile) == 0) str_copy(m_aDemoPlayerPopupHint, Localize("Please use a different name"), sizeof(m_aDemoPlayerPopupHint)); else { m_DemoPlayerState = DEMOPLAYER_NONE; int len = str_length(m_aCurrentDemoFile); if(len < 5 || str_comp_nocase(&m_aCurrentDemoFile[len-5], ".demo")) str_append(m_aCurrentDemoFile, ".demo", sizeof(m_aCurrentDemoFile)); char aPath[512]; str_format(aPath, sizeof(aPath), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile); Client()->DemoSlice(aPath, s_RemoveChat); } } Box.HSplitBottom(60.f, &Box, &Part); Box.HSplitBottom(60.f, &Box, &Part2); #if defined(__ANDROID__) Box.HSplitBottom(60.f, &Box, &Part2); Box.HSplitBottom(60.f, &Box, &Part); #else Box.HSplitBottom(24.f, &Box, &Part2); Box.HSplitBottom(24.f, &Box, &Part); #endif Part2.VSplitLeft(60.0f, 0, &Label); static CButtonContainer s_RemoveChatCheckbox; if(DoButton_CheckBox(&s_RemoveChatCheckbox, Localize("Remove chat"), s_RemoveChat, &Label)) { s_RemoveChat ^= 1; } Part.VSplitLeft(60.0f, 0, &Label); Label.VSplitLeft(120.0f, 0, &TextBox); TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("New name:"), 18.0f, -1); static float Offset = 0.0f; static CButtonContainer s_NameEditbox; DoEditBox(&s_NameEditbox, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &Offset); } // handle mousewheel independent of active menu if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP) && m_pClient->m_pGameConsole->IsClosed()) { if(pInfo->m_Speed < 0.1f) DemoPlayer()->SetSpeed(0.1f); else if(pInfo->m_Speed < 0.25f) DemoPlayer()->SetSpeed(0.25f); else if(pInfo->m_Speed < 0.5f) DemoPlayer()->SetSpeed(0.5f); else if(pInfo->m_Speed < 0.75f) DemoPlayer()->SetSpeed(0.75f); else if(pInfo->m_Speed < 1.0f) DemoPlayer()->SetSpeed(1.0f); else if(pInfo->m_Speed < 2.0f) DemoPlayer()->SetSpeed(2.0f); else if(pInfo->m_Speed < 4.0f) DemoPlayer()->SetSpeed(4.0f); else DemoPlayer()->SetSpeed(8.0f); LastSpeedChange = time_get(); } else if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN) && m_pClient->m_pGameConsole->IsClosed()) { if(pInfo->m_Speed > 4.0f) DemoPlayer()->SetSpeed(4.0f); else if(pInfo->m_Speed > 2.0f) DemoPlayer()->SetSpeed(2.0f); else if(pInfo->m_Speed > 1.0f) DemoPlayer()->SetSpeed(1.0f); else if(pInfo->m_Speed > 0.75f) DemoPlayer()->SetSpeed(0.75f); else if(pInfo->m_Speed > 0.5f) DemoPlayer()->SetSpeed(0.5f); else if(pInfo->m_Speed > 0.25f) DemoPlayer()->SetSpeed(0.25f); else if(pInfo->m_Speed > 0.1f) DemoPlayer()->SetSpeed(0.1f); else DemoPlayer()->SetSpeed(0.05f); LastSpeedChange = time_get(); } TotalHeight = SeekBarHeight+ButtonbarHeight+NameBarHeight+Margins*3; // render speed info if (g_Config.m_ClDemoShowSpeed && time_get() - LastSpeedChange < time_freq() * 1) { CUIRect Screen = *UI()->Screen(); char aSpeedBuf[256]; str_format(aSpeedBuf, sizeof(aSpeedBuf), "×%.2f", pInfo->m_Speed); TextRender()->Text(0, 120.0f, Screen.y+Screen.h - 120.0f - TotalHeight, 60.0f, aSpeedBuf, -1); } if(!m_MenuActive) return; MainView.HSplitBottom(TotalHeight, 0, &MainView); MainView.VSplitLeft(50.0f, 0, &MainView); MainView.VSplitLeft(450.0f, &MainView, 0); RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_T, 10.0f); MainView.Margin(5.0f, &MainView); CUIRect SeekBar, ButtonBar, NameBar; int CurrentTick = pInfo->m_CurrentTick - pInfo->m_FirstTick; int TotalTicks = pInfo->m_LastTick - pInfo->m_FirstTick; MainView.HSplitTop(SeekBarHeight, &SeekBar, &ButtonBar); ButtonBar.HSplitTop(Margins, 0, &ButtonBar); ButtonBar.HSplitBottom(NameBarHeight, &ButtonBar, &NameBar); NameBar.HSplitTop(4.0f, 0, &NameBar); // do seekbar { static int s_SeekBarID = 0; void *id = &s_SeekBarID; char aBuffer[128]; // draw seek bar RenderTools()->DrawUIRect(&SeekBar, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 5.0f); // draw filled bar float Amount = CurrentTick/(float)TotalTicks; CUIRect FilledBar = SeekBar; FilledBar.w = 10.0f + (FilledBar.w-10.0f)*Amount; RenderTools()->DrawUIRect(&FilledBar, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 5.0f); // draw markers if(pInfo->m_NumTimelineMarkers < TotalTicks / 20) { for(int i = 0; i < pInfo->m_NumTimelineMarkers; i++) { float Ratio = (pInfo->m_aTimelineMarkers[i] - pInfo->m_FirstTick) / (float)TotalTicks; Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); IGraphics::CQuadItem QuadItem(SeekBar.x + (SeekBar.w - 10.0f) * Ratio, SeekBar.y, UI()->PixelSize(), SeekBar.h); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); } } else { TextRender()->TextColor(1,0,0,1); UI()->DoLabelScaled(&SeekBar, Localize("removed markers due to broken demo"), 9.0f, -1); TextRender()->TextColor(1,1,1,1); } // draw slice markers // begin if (g_Config.m_ClDemoSliceBegin != -1) { float Ratio = (g_Config.m_ClDemoSliceBegin-pInfo->m_FirstTick) / (float)TotalTicks; Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); Graphics()->SetColor(1.0f, 0.0f, 0.0f, 1.0f); IGraphics::CQuadItem QuadItem(10.0f + SeekBar.x + (SeekBar.w-10.0f)*Ratio, SeekBar.y, UI()->PixelSize(), SeekBar.h); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); } // end if (g_Config.m_ClDemoSliceEnd != -1) { float Ratio = (g_Config.m_ClDemoSliceEnd-pInfo->m_FirstTick) / (float)TotalTicks; Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); Graphics()->SetColor(1.0f, 0.0f, 0.0f, 1.0f); IGraphics::CQuadItem QuadItem(10.0f + SeekBar.x + (SeekBar.w-10.0f)*Ratio, SeekBar.y, UI()->PixelSize(), SeekBar.h); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); } // draw time 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, 0); // do the logic int Inside = UI()->MouseInside(&SeekBar); if(UI()->ActiveItem() == id) { if(!UI()->MouseButton(0)) UI()->SetActiveItem(0); else { static float PrevAmount = 0.0f; float Amount = (UI()->MouseX()-SeekBar.x)/(float)SeekBar.w; if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) { Amount = PrevAmount + (Amount-PrevAmount) * 0.05f; if(Amount > 0.0f && Amount < 1.0f && absolute(PrevAmount-Amount) >= 0.0001f) { //PrevAmount = Amount; m_pClient->OnReset(); m_pClient->m_SuppressEvents = true; DemoPlayer()->SetPos(Amount); m_pClient->m_SuppressEvents = false; m_pClient->m_pMapLayersBackGround->EnvelopeUpdate(); m_pClient->m_pMapLayersForeGround->EnvelopeUpdate(); } } else { if(Amount > 0.0f && Amount < 1.0f && absolute(PrevAmount-Amount) >= 0.001f) { PrevAmount = Amount; m_pClient->OnReset(); m_pClient->m_SuppressEvents = true; DemoPlayer()->SetPos(Amount); m_pClient->m_SuppressEvents = false; m_pClient->m_pMapLayersBackGround->EnvelopeUpdate(); m_pClient->m_pMapLayersForeGround->EnvelopeUpdate(); } } } } else if(UI()->HotItem() == id) { if(UI()->MouseButton(0)) UI()->SetActiveItem(id); } if(Inside) UI()->SetHotItem(id); } if(CurrentTick == TotalTicks) { m_pClient->OnReset(); DemoPlayer()->Pause(); DemoPlayer()->SetPos(0); } bool IncreaseDemoSpeed = false, DecreaseDemoSpeed = false; // do buttons CUIRect Button; // combined play and pause button ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_PlayPauseButton; if(!pInfo->m_Paused) { if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_PAUSE, false, &Button, CUI::CORNER_ALL)) DemoPlayer()->Pause(); } else { if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_PLAY, false, &Button, CUI::CORNER_ALL)) DemoPlayer()->Unpause(); } // stop button ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_ResetButton; if(DoButton_Sprite(&s_ResetButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_STOP, false, &Button, CUI::CORNER_ALL)) { m_pClient->OnReset(); DemoPlayer()->Pause(); DemoPlayer()->SetPos(0); } // slowdown ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SlowDownButton; if(DoButton_Sprite(&s_SlowDownButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_SLOWER, 0, &Button, CUI::CORNER_ALL) || Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) DecreaseDemoSpeed = true; // fastforward ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_FastForwardButton; if(DoButton_Sprite(&s_FastForwardButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_FASTER, 0, &Button, CUI::CORNER_ALL)) IncreaseDemoSpeed = true; // speed meter ButtonBar.VSplitLeft(Margins*3, 0, &ButtonBar); char aBuffer[64]; if(pInfo->m_Speed >= 1.0f) str_format(aBuffer, sizeof(aBuffer), "×%.0f", pInfo->m_Speed); else str_format(aBuffer, sizeof(aBuffer), "×%.2f", pInfo->m_Speed); UI()->DoLabel(&ButtonBar, aBuffer, Button.h*0.7f, -1); // slice begin button ButtonBar.VSplitLeft(Margins*10, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SliceBeginButton; if(DoButton_Sprite(&s_SliceBeginButton, IMAGE_DEMOBUTTONS2, SPRITE_DEMOBUTTON_SLICE_BEGIN, 0, &Button, CUI::CORNER_ALL)) Client()->DemoSliceBegin(); // slice end button ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SliceEndButton; if(DoButton_Sprite(&s_SliceEndButton, IMAGE_DEMOBUTTONS2, SPRITE_DEMOBUTTON_SLICE_END, 0, &Button, CUI::CORNER_ALL)) Client()->DemoSliceEnd(); // slice save button ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static CButtonContainer s_SliceSaveButton; if(DoButton_Sprite(&s_SliceSaveButton, IMAGE_FILEICONS, SPRITE_FILE_DEMO2, 0, &Button, CUI::CORNER_ALL)) { str_copy(m_aCurrentDemoFile, m_lDemos[m_DemolistSelectedIndex].m_aFilename, sizeof(m_aCurrentDemoFile)); m_aDemoPlayerPopupHint[0] = '\0'; m_DemoPlayerState = DEMOPLAYER_SLICE_SAVE; } // close button ButtonBar.VSplitRight(ButtonbarHeight*3, &ButtonBar, &Button); static CButtonContainer s_ExitButton; if(DoButton_DemoPlayer(&s_ExitButton, Localize("Close"), 0, &Button)) { Client()->Disconnect(); DemolistPopulate(); DemolistOnUpdate(false); } // demo name char aDemoName[64] = {0}; DemoPlayer()->GetDemoName(aDemoName, sizeof(aDemoName)); char aBuf[128]; str_format(aBuf, sizeof(aBuf), Localize("Demofile: %s"), aDemoName); CTextCursor Cursor; TextRender()->SetCursor(&Cursor, NameBar.x, NameBar.y, Button.h*0.5f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); Cursor.m_LineWidth = MainView.w; TextRender()->TextEx(&Cursor, aBuf, -1); if(IncreaseDemoSpeed) { if(pInfo->m_Speed < 0.1f) DemoPlayer()->SetSpeed(0.1f); else if(pInfo->m_Speed < 0.25f) DemoPlayer()->SetSpeed(0.25f); else if(pInfo->m_Speed < 0.5f) DemoPlayer()->SetSpeed(0.5f); else if(pInfo->m_Speed < 0.75f) DemoPlayer()->SetSpeed(0.75f); else if(pInfo->m_Speed < 1.0f) DemoPlayer()->SetSpeed(1.0f); else if(pInfo->m_Speed < 2.0f) DemoPlayer()->SetSpeed(2.0f); else if(pInfo->m_Speed < 4.0f) DemoPlayer()->SetSpeed(4.0f); else DemoPlayer()->SetSpeed(8.0f); LastSpeedChange = time_get(); } else if(DecreaseDemoSpeed) { if(pInfo->m_Speed > 4.0f) DemoPlayer()->SetSpeed(4.0f); else if(pInfo->m_Speed > 2.0f) DemoPlayer()->SetSpeed(2.0f); else if(pInfo->m_Speed > 1.0f) DemoPlayer()->SetSpeed(1.0f); else if(pInfo->m_Speed > 0.75f) DemoPlayer()->SetSpeed(0.75f); else if(pInfo->m_Speed > 0.5f) DemoPlayer()->SetSpeed(0.5f); else if(pInfo->m_Speed > 0.25f) DemoPlayer()->SetSpeed(0.25f); else if(pInfo->m_Speed > 0.1f) DemoPlayer()->SetSpeed(0.1f); else DemoPlayer()->SetSpeed(0.05f); LastSpeedChange = time_get(); } }