bool CFolderMenu::ShouldShowCharacterOnly() { C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer(); if (!pPlayer) return true; // If the player has anything, show the weapons version if (pPlayer->GetLoadoutWeight()) return false; if (pPlayer->m_Shared.m_iStyleSkill != SKILL_NONE) return false; if (m_pPage) { if (FStrEq(m_pPage->GetName(), PANEL_BUY) || FStrEq(m_pPage->GetName(), PANEL_BUY_EQUIP_CT)) return false; } return true; }
void CFolderMenu::Update() { ReloadControlSettings(false, false); MoveToCenterOfScreen(); Button *entry = dynamic_cast<Button *>(FindChildByName("ApproveButton")); if (entry) entry->SetVisible(true); C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer(); if (!pPlayer) return; if (pPlayer->HasCharacterBeenChosen()) Q_strcpy(m_szCharacter, pPlayer->GetCharacter()); else m_szCharacter[0] = '\0'; if (ShouldShowCharacterOnly() && !ShouldShowTeams()) { m_pProfileInfo->SetVisible(true); if (m_szPreviewCharacter[0]) m_pProfileInfo->SetText((std::string("#DA_CharacterInfo_") + m_szPreviewCharacter).c_str()); else if (m_szCharacter[0]) m_pProfileInfo->SetText((std::string("#DA_CharacterInfo_") + m_szCharacter).c_str()); else m_pProfileInfo->SetText("#DA_CharacterInfo_None"); } else m_pProfileInfo->SetVisible(false); CFolderLabel *pCharacterName = dynamic_cast<CFolderLabel *>(FindChildByName("AgentName")); if (pCharacterName && !ShouldShowTeams()) { std::string sCharacter; if (m_szPreviewCharacter[0]) sCharacter = std::string("#DA_Character_") + m_szPreviewCharacter; else if (m_szCharacter[0]) sCharacter = std::string("#DA_Character_") + m_szCharacter; std::wstring sLocalized; wchar_t* pszLocalized = g_pVGuiLocalize->Find( sCharacter.c_str() ); if (pszLocalized) sLocalized += pszLocalized; if (pPlayer->m_Shared.m_iStyleSkill) { std::string sSkill = std::string("#DA_Skill_") + SkillIDToAlias((SkillID)pPlayer->m_Shared.m_iStyleSkill.Get()) + "_Adjective"; pszLocalized = g_pVGuiLocalize->Find( sSkill.c_str() ); if (pszLocalized) sLocalized += pszLocalized; } pCharacterName->SetText(sLocalized.c_str()); } else pCharacterName->SetText(""); CFolderLabel* pLabels[2]; pLabels[0] = dynamic_cast<CFolderLabel *>(FindChildByName("RequestedArmament1")); pLabels[1] = dynamic_cast<CFolderLabel *>(FindChildByName("RequestedArmament2")); int iArmamentsOn1 = 0; std::wostringstream sLabel1; std::wostringstream sLabel2; SDKWeaponID eFirst = WEAPON_NONE; for (int i = 0; i < MAX_LOADOUT; i++) { if (!pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i)) continue; CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo((SDKWeaponID)i); if (!pWeaponInfo) continue; if (!eFirst) { eFirst = (SDKWeaponID)i; if (pPlayer->GetLoadoutWeaponCount(eFirst) > 1) { CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo(eFirst); if (pWeaponInfo && pWeaponInfo->m_szAkimbo[0]) { // If we have two of this weapon and this weapon has an akimbo, use the akimbo instead. eFirst = AliasToWeaponID(pWeaponInfo->m_szAkimbo); } } } else { if (pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i) > 1) { CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo((SDKWeaponID)i); if (pWeaponInfo && pWeaponInfo->m_szAkimbo[0]) { SDKWeaponID eAkimbo = AliasToWeaponID(pWeaponInfo->m_szAkimbo); if (eAkimbo < eFirst) { // If we have this akimbo and it's preferred to the current weapon, use it instead. // (Preferred means lower weapon ID.) eFirst = eAkimbo; } } } } std::wostringstream sLabel; const wchar_t *pchFmt = g_pVGuiLocalize->Find( pWeaponInfo->szPrintName ); if ( pchFmt && pchFmt[0] ) sLabel << pchFmt; else sLabel << pWeaponInfo->szPrintName; if (pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i) > 1) sLabel << " x" << pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i) << "\n"; else sLabel << "\n"; if (iArmamentsOn1 >= 2) sLabel2 << sLabel.str(); else sLabel1 << sLabel.str(); iArmamentsOn1++; } if (pLabels[0]) pLabels[0]->SetText(sLabel1.str().c_str()); if (pLabels[1]) pLabels[1]->SetText(sLabel2.str().c_str()); const char szPlayerPreviewTemplate[] = " \"model\"\n" " {\n" " \"spotlight\" \"1\"\n" " \"modelname\" \"models/player/frank.mdl\"\n" " \"origin_z\" \"-57\"\n" " \"origin_y\" \"10\"\n" " \"origin_x\" \"110\"\n" " \"angles_y\" \"180\"\n" " \"animation\"\n" " {\n" " \"sequence\" \"m1911_idle\"\n" " \"pose_parameters\"\n" " {\n" " \"body_yaw\" \"25.0\"\n" " \"body_pitch\" \"-30.0\"\n" " }\n" " }\n" " \"attached_model\"\n" " {\n" " \"modelname\" \"models/weapons/m1911.mdl\"\n" " }\n" " }"; CModelPanel *pPlayerPreview = dynamic_cast<CModelPanel *>(FindChildByName("player_preview")); CSDKWeaponInfo* pWeaponInfo = NULL; if (eFirst) pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo(eFirst); if ((m_szCharacter[0] || m_szPreviewCharacter[0]) && pPlayerPreview && !ShouldShowTeams()) { KeyValues* pValues = new KeyValues("preview"); pValues->LoadFromBuffer("model", szPlayerPreviewTemplate); const char* pCharacter = m_szCharacter; if (m_szPreviewCharacter[0]) pCharacter = m_szPreviewCharacter; pValues->SetString("modelname", VarArgs("models/player/%s.mdl", pCharacter)); if (ShouldShowCharacterOnly() || ShouldShowCharacterAndWeapons()) { pValues->SetFloat("origin_x", hud_characterpreview_x.GetFloat()); pValues->SetFloat("origin_y", hud_characterpreview_y.GetFloat()); pValues->SetFloat("origin_z", hud_characterpreview_z.GetFloat()); } else { pValues->SetFloat("origin_x", hud_playerpreview_x.GetFloat()); pValues->SetFloat("origin_y", hud_playerpreview_y.GetFloat()); pValues->SetFloat("origin_z", hud_playerpreview_z.GetFloat()); } if (m_pPage && FStrEq(m_pPage->GetName(), "class") && m_szPreviewSequence[0] && m_szPreviewWeaponModel[0] && !pPlayer->GetLoadoutWeight()) { KeyValues* pAnimation = pValues->FindKey("animation"); if (pAnimation) pAnimation->SetString("sequence", m_szPreviewSequence); KeyValues* pWeapon = pValues->FindKey("attached_model"); if (pWeapon) pWeapon->SetString("modelname", m_szPreviewWeaponModel); } else if (pWeaponInfo) { KeyValues* pAnimation = pValues->FindKey("animation"); if (pAnimation) pAnimation->SetString("sequence", VarArgs("%s_idle", WeaponIDToAlias(eFirst))); KeyValues* pWeapon = pValues->FindKey("attached_model"); if (pWeapon) pWeapon->SetString("modelname", pWeaponInfo->szWorldModel); } else { KeyValues* pAnimation = pValues->FindKey("animation"); if (pAnimation) pAnimation->SetString("sequence", "idle"); KeyValues* pWeapon = pValues->FindKey("attached_model"); if (pWeapon) pWeapon->SetString("modelname", ""); } if (SDKGameRules()->IsTeamplay()) { if (pPlayer->GetTeamNumber() == SDK_TEAM_BLUE) pValues->SetInt("skin", 1); else if (pPlayer->GetTeamNumber() == SDK_TEAM_RED) pValues->SetInt("skin", 2); else pValues->SetInt("skin", 0); } else pValues->SetInt("skin", 0); pPlayerPreview->ParseModelInfo(pValues); pValues->deleteThis(); } else if (pPlayerPreview) pPlayerPreview->SwapModel(""); for ( int i = 0; i < m_apWeaponIcons.Count(); i++) { if (m_apWeaponIcons[i].m_pWeaponName) m_apWeaponIcons[i].m_pWeaponName->DeletePanel(); if (m_apWeaponIcons[i].m_pSlots) m_apWeaponIcons[i].m_pSlots->DeletePanel(); if (m_apWeaponIcons[i].m_pImage) m_apWeaponIcons[i].m_pImage->DeletePanel(); if (m_apWeaponIcons[i].m_pDelete) m_apWeaponIcons[i].m_pDelete->DeletePanel(); } m_apWeaponIcons.RemoveAll(); const char szWeaponPreviewTemplate[] = " \"model\"\n" " {\n" " \"spotlight\" \"1\"\n" " \"modelname\" \"models/weapons/beretta.mdl\"\n" " \"origin_x\" \"30\"\n" " \"origin_y\" \"3\"\n" " \"origin_z\" \"-3\"\n" " \"angles_y\" \"200\"\n" " }"; Panel *pWeaponIconArea = FindChildByName("WeaponIconArea"); if ((ShouldShowCharacterAndWeapons() || ShouldShowEverything()) && pWeaponIconArea) { int iWeaponAreaX, iWeaponAreaY, iWeaponAreaW, iWeaponAreaH; pWeaponIconArea->GetPos(iWeaponAreaX, iWeaponAreaY); pWeaponIconArea->GetSize(iWeaponAreaW, iWeaponAreaH); int iMargin = 5; int iBoxSize = (iWeaponAreaW-5)/2; int iWeapon = 0; for (int i = 0; i < MAX_LOADOUT; i++) { if (!pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i)) continue; CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo((SDKWeaponID)i); if (!pWeaponInfo) continue; for (int j = 0; j < pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i); j++) { float flMoveRight = 0; if (iWeapon%2 == 1) flMoveRight = iBoxSize + iMargin; CWeaponIcon* pIcon = &m_apWeaponIcons[m_apWeaponIcons.AddToTail()]; pIcon->m_pWeaponName = new CFolderLabel(this, NULL); pIcon->m_pWeaponName->SetText(VarArgs("#DA_Weapon_Obituary_%s", pWeaponInfo->szClassName+7)); // Use the obit version because it's shorter pIcon->m_pWeaponName->SetPos(iWeaponAreaX + flMoveRight, iWeaponAreaY + 10 + (iWeapon/2) * (iBoxSize+iMargin)); pIcon->m_pWeaponName->SetSize(iBoxSize, 15); pIcon->m_pWeaponName->SetContentAlignment(Label::a_center); pIcon->m_pWeaponName->SetZPos(-5); pIcon->m_pWeaponName->SetFont(vgui::scheme()->GetIScheme(GetScheme())->GetFont("FolderLarge")); pIcon->m_pWeaponName->SetScheme("FolderScheme"); std::wostringstream sSlotsLabel; if (pWeaponInfo->iWeight) { const wchar_t *pchFmt = g_pVGuiLocalize->Find( "#DA_BuyMenu_Weapon_Slots" ); if ( pchFmt && pchFmt[0] ) sSlotsLabel << pchFmt; else sSlotsLabel << "Slots: "; sSlotsLabel << pWeaponInfo->iWeight; pIcon->m_pSlots = new CFolderLabel(this, NULL); pIcon->m_pSlots->SetText(sSlotsLabel.str().c_str()); pIcon->m_pSlots->SetPos(iWeaponAreaX + flMoveRight, iWeaponAreaY + iBoxSize - 10 + (iWeapon/2) * (iBoxSize+iMargin)); pIcon->m_pSlots->SetSize(iBoxSize, 15); pIcon->m_pSlots->SetContentAlignment(Label::a_center); pIcon->m_pSlots->SetZPos(-5); pIcon->m_pSlots->SetFont(vgui::scheme()->GetIScheme(GetScheme())->GetFont("FolderSmall")); pIcon->m_pSlots->SetScheme("FolderScheme"); } KeyValues* pValues = new KeyValues("preview"); pValues->LoadFromBuffer("model", szWeaponPreviewTemplate); pValues->SetString("modelname", pWeaponInfo->szWorldModel); if (pWeaponInfo->m_eWeaponType == WT_PISTOL) { pValues->SetInt("origin_x", 20); } else if (pWeaponInfo->m_eWeaponType == WT_RIFLE) { pValues->SetInt("origin_x", 50); pValues->SetInt("angles_y", 210); } else if (pWeaponInfo->m_eWeaponType == WT_SHOTGUN) { pValues->SetInt("origin_x", 50); pValues->SetInt("origin_y", 10); pValues->SetInt("angles_y", 150); } else if (pWeaponInfo->m_eWeaponType == WT_SMG) { } else if (pWeaponInfo->m_eWeaponType == WT_GRENADE) { pValues->SetInt("origin_x", 20); } pIcon->m_pImage = new CModelPanel(this, NULL); pIcon->m_pImage->SetPos(iWeaponAreaX + flMoveRight, iWeaponAreaY + (iWeapon/2) * (iBoxSize+iMargin)); pIcon->m_pImage->SetSize(iBoxSize, iBoxSize); pIcon->m_pImage->SetZPos(-15); pIcon->m_pImage->SetScheme("FolderScheme"); pIcon->m_pImage->ParseModelInfo(pValues); pValues->deleteThis(); pIcon->m_pDelete = new CImageButton(this, VarArgs("delete_%d", iWeapon)); pIcon->m_pDelete->SetDimensions(iWeaponAreaX + iBoxSize - 8 + flMoveRight, iWeaponAreaY + 30 + (iWeapon/2) * (iBoxSize+iMargin), 12, 12); pIcon->m_pDelete->SetZPos(15); pIcon->m_pDelete->SetImage("folder_delete"); pIcon->m_pDelete->SetPaintBorderEnabled(false); pIcon->m_pDelete->SetPaintBackgroundEnabled(true); pIcon->m_pDelete->SetCommand(VarArgs("buy remove %d", i)); iWeapon++; } } } CFolderLabel* pWeaponTotalWeightNumber = dynamic_cast<CFolderLabel*>(FindChildByName("WeaponTotalWeightNumber")); CFolderLabel* pWeaponTotalWeight = dynamic_cast<CFolderLabel*>(FindChildByName("WeaponTotalWeight")); if ((ShouldShowCharacterAndWeapons() || ShouldShowEverything()) && pPlayer->GetLoadoutWeight()) { if (pWeaponTotalWeightNumber) { wchar_t szText[20]; _snwprintf( szText, ARRAYSIZE(szText) - 1, L"%d/%d", pPlayer->GetLoadoutWeight(), MAX_LOADOUT_WEIGHT ); pWeaponTotalWeightNumber->SetText(szText); pWeaponTotalWeightNumber->SetVisible(true); } if (pWeaponTotalWeight) pWeaponTotalWeight->SetVisible(true); } else { if (pWeaponTotalWeightNumber) pWeaponTotalWeightNumber->SetVisible(false); if (pWeaponTotalWeight) pWeaponTotalWeight->SetVisible(false); } if (ShouldShowEverything()) { CFolderLabel *pSkillInfo = dynamic_cast<CFolderLabel *>(FindChildByName("SkillInfo")); CPanelTexture *pSkillIcon = dynamic_cast<CPanelTexture *>(FindChildByName("SkillIcon")); if (pSkillInfo && pSkillIcon) { if (pPlayer->m_Shared.m_iStyleSkill) { pSkillInfo->SetText((std::string("#DA_SkillInfo_") + SkillIDToAlias((SkillID)pPlayer->m_Shared.m_iStyleSkill.Get())).c_str()); pSkillIcon->SetImage(SkillIDToAlias((SkillID)pPlayer->m_Shared.m_iStyleSkill.Get())); } else { pSkillInfo->SetText(""); pSkillIcon->SetImage(""); } } } m_pSuicideOption->SetVisible(pPlayer->IsAlive() && !ShouldShowTeams()); Button *pProceedButton = dynamic_cast<Button *>(FindChildByName("ProceedButton")); if (pProceedButton) pProceedButton->SetVisible(m_pPage && FStrEq(m_pPage->GetName(), PANEL_BUY)); Button *pApproveButton = dynamic_cast<Button *>(FindChildByName("ApproveButton")); if (pApproveButton) pApproveButton->SetVisible(IsLoadoutComplete()); Button *pAgentsTab = dynamic_cast<Button *>(FindChildByName("AgentsTab")); if (pAgentsTab) pAgentsTab->SetVisible(pPlayer->HasCharacterBeenChosen()); Button *pWeaponsTab = dynamic_cast<Button *>(FindChildByName("WeaponsTab")); if (pWeaponsTab) pWeaponsTab->SetVisible(pPlayer->HasCharacterBeenChosen()); Button *pSkillsTab = dynamic_cast<Button *>(FindChildByName("SkillsTab")); if (pSkillsTab) pSkillsTab->SetVisible(pPlayer->HasSkillsTabBeenSeen()); Button *pChangeTeams = dynamic_cast<Button *>(FindChildByName("ChangeTeamsButton")); if (pChangeTeams) pChangeTeams->SetVisible(SDKGameRules()->IsTeamplay()); }