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()); }
void CDABuyMenu::Update() { m_pWeaponInfo = dynamic_cast<CFolderLabel*>(FindChildByName("WeaponInfo")); m_pWeaponInfo->SetText(""); m_pWeaponImage = dynamic_cast<CModelPanel*>(FindChildByName("WeaponImage")); m_pWeaponImage->SwapModel(""); Button *entry = dynamic_cast<Button *>(FindChildByName("CancelButton")); if (entry) entry->SetVisible(true); CFolderLabel* pWeaponWeight = dynamic_cast<CFolderLabel*>(FindChildByName("WeaponWeight")); int iWeaponWeightX, iWeaponWeightY; pWeaponWeight->GetPos(iWeaponWeightX, iWeaponWeightY); C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer(); if (!pPlayer) return; for ( int i = 0; i < m_apWeights.Count(); i++) { m_apWeights[i]->DeletePanel(); m_apWeights[i] = NULL; } for ( int i = 0; i < m_apCheckMarks.Count(); i++) { m_apCheckMarks[i]->DeletePanel(); m_apCheckMarks[i] = NULL; } m_apWeights.RemoveAll(); m_apCheckMarks.RemoveAll(); CUtlVector<CWeaponButton*> apWeaponButtons; for ( int i = 0 ; i < GetChildCount() ; ++i ) { // Hide the subpanel for the CWeaponButtons CWeaponButton *pPanel = dynamic_cast<CWeaponButton *>( GetChild( i ) ); if (!pPanel) continue; if (pPanel->GetWeaponID() != WEAPON_NONE) apWeaponButtons.AddToTail(pPanel); pPanel->SetEnabled(true); if (!pPanel->GetName()) continue; if (strlen(pPanel->GetName()) < 7) continue; SDKWeaponID eWeapon = AliasToWeaponID(pPanel->GetName() + 7); if (!eWeapon) continue; pPanel->SetEnabled(pPlayer->CanAddToLoadout(eWeapon)); pPanel->InvalidateLayout(true); } for (int i = 0; i < apWeaponButtons.Count(); i++) { CWeaponButton* pPanel = apWeaponButtons[i]; int iWeaponX, iWeaponY; pPanel->GetPos(iWeaponX, iWeaponY); CSDKWeaponInfo* pInfo = CSDKWeaponInfo::GetWeaponInfo(pPanel->GetWeaponID()); m_apWeights.AddToTail(new CFolderLabel(this, NULL)); std::ostringstream sWeight; sWeight << pInfo->iWeight; m_apWeights.Tail()->SetText(sWeight.str().c_str()); m_apWeights.Tail()->SetPos(iWeaponWeightX, iWeaponY); m_apWeights.Tail()->SetZPos(-5); m_apWeights.Tail()->SetFont(vgui::scheme()->GetIScheme(GetScheme())->GetFont("FolderMedium")); m_apWeights.Tail()->SetScheme("FolderScheme"); int iWeaponInfoX, iWeaponInfoY; m_pWeaponInfo->GetPos(iWeaponInfoX, iWeaponInfoY); m_apCheckMarks.AddToTail(new CImageButton(this, "checkmark")); m_apCheckMarks.Tail()->SetDimensions(iWeaponInfoX, iWeaponY, pPanel->GetTall(), pPanel->GetTall()); m_apCheckMarks.Tail()->SetZPos(5); m_apCheckMarks.Tail()->SetVisible(true); if (pPlayer->GetLoadoutWeaponCount(pPanel->GetWeaponID())) { m_apCheckMarks.Tail()->SetImage("folder_check"); m_apCheckMarks.Tail()->SetCommand(VarArgs("buy remove %s", pInfo->szClassName+7)); } else if (pPlayer->CanAddToLoadout(pPanel->GetWeaponID())) { m_apCheckMarks.Tail()->SetImage("folder_nocheck"); m_apCheckMarks.Tail()->SetCommand(VarArgs("buy %s", pInfo->szClassName+7)); } else { m_apCheckMarks.Tail()->SetImage("folder_nocheck"); m_apCheckMarks.Tail()->SetImageColor(Color(255, 255, 255, 100)); } if (pInfo->m_szAkimbo[0]) { m_apCheckMarks.AddToTail(new CImageButton(this, "checkmark")); m_apCheckMarks.Tail()->SetDimensions(iWeaponInfoX + pPanel->GetTall() + 5, iWeaponY, pPanel->GetTall(), pPanel->GetTall()); m_apCheckMarks.Tail()->SetZPos(5); m_apCheckMarks.Tail()->SetVisible(true); if (pPlayer->GetLoadoutWeaponCount(pPanel->GetWeaponID()) == 2) { m_apCheckMarks.Tail()->SetImage("folder_check"); m_apCheckMarks.Tail()->SetCommand(VarArgs("buy remove %s", pInfo->szClassName+7)); } else if (pPlayer->GetLoadoutWeaponCount(pPanel->GetWeaponID()) == 0) { m_apCheckMarks.Tail()->SetImage("folder_nocheck"); m_apCheckMarks.Tail()->SetImageColor(Color(255, 255, 255, 100)); } else if (pPlayer->CanAddToLoadout(pPanel->GetWeaponID())) { m_apCheckMarks.Tail()->SetImage("folder_nocheck"); m_apCheckMarks.Tail()->SetCommand(VarArgs("buy %s", pInfo->szClassName+7)); } else { m_apCheckMarks.Tail()->SetImage("folder_nocheck"); m_apCheckMarks.Tail()->SetImageColor(Color(255, 255, 255, 100)); } } } }