//============================================================================= void InGameChapterSelect::PaintBackground() { Panel *pDrpChapter = FindChildByName( "DrpChapter" ); bool bChapter = ( pDrpChapter && pDrpChapter->IsEnabled() ); char const *szTitle = bChapter ? "#L4D360UI_ChapterSelect_Title" : "#L4D360UI_ChangeScenario"; char const *szTip = bChapter ? "#L4D360UI_ChapterSelect_Description" : "#L4D360UI_ChangeScenario_Tip"; BaseClass::DrawDialogBackground( szTitle, NULL, szTip, NULL, NULL, true ); }
//----------------------------------------------------------------------------- // Purpose: finds the panel which is activated by the specified key // Input : code - the keycode of the hotkey // Output : Panel * - NULL if no panel found //----------------------------------------------------------------------------- Panel *FocusNavGroup::FindPanelByHotkey(wchar_t key) { for (int i = 0; i < _mainPanel->GetChildCount(); i++) { Panel *child = _mainPanel->GetChild(i); if ( !child ) continue; Panel *hot = child->HasHotkey(key); if (hot && hot->IsVisible() && hot->IsEnabled()) { return hot; } } return NULL; }
//----------------------------------------------------------------------------- // Purpose: Gets the panel with the specified hotkey //----------------------------------------------------------------------------- Panel *EditablePanel::HasHotkey(wchar_t key) { if( !IsVisible() || !IsEnabled()) // not visible, so can't respond to a hot key { return NULL; } for (int i = 0; i < GetChildCount(); i++) { Panel *hot = GetChild(i)->HasHotkey(key); if (hot && hot->IsVisible() && hot->IsEnabled()) { return hot; } } return NULL; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void WizardPanel::ResetKeyFocus() { // set the focus on the default FocusNavGroup &navGroup = GetFocusNavGroup(); Panel *def = navGroup.GetDefaultPanel(); if (def) { if (def->IsEnabled() && def->IsVisible()) { def->RequestFocus(); } else { def->RequestFocusNext(); } } ResetDefaultButton(); }
//----------------------------------------------------------------------------- // Purpose: Sets the focus to the previous panel in the tab order // Input : *panel - panel currently with focus //----------------------------------------------------------------------------- bool FocusNavGroup::RequestFocusPrev(VPANEL panel) { if(panel==NULL) return false; _currentFocus = NULL; int newPosition = 9999999; if (panel) { newPosition = ipanel()->GetTabPosition(panel); } bool bFound = false; bool bRepeat = true; Panel *best = NULL; while (1) { newPosition--; if (newPosition > 0) { int bestPosition = 0; // look for the next tab position for (int i = 0; i < _mainPanel->GetChildCount(); i++) { Panel *child = _mainPanel->GetChild(i); if (child && child->IsVisible() && child->IsEnabled() && child->GetTabPosition()) { int tabPosition = child->GetTabPosition(); if (tabPosition == newPosition) { // we've found the right tab best = child; bestPosition = newPosition; // don't loop anymore since we've found the correct panel break; } else if (tabPosition < newPosition && tabPosition > bestPosition) { // record the match since this is the closest so far bestPosition = tabPosition; best = child; } } } if (!bRepeat) break; if (best) break; } else { // reset new position for next loop newPosition = 9999999; } // haven't found an item if (!_topLevelFocus) { // check to see if we should push the focus request up if (_mainPanel->GetVParent() && _mainPanel->GetVParent() != surface()->GetEmbeddedPanel()) { // we're not a top level panel, so forward up the request instead of looping if (ipanel()->RequestFocusPrev(_mainPanel->GetVParent(), _mainPanel->GetVPanel())) { bFound = true; SetCurrentDefaultButton(NULL); break; } } } // not found an item, loop back newPosition = 9999999; bRepeat = false; } if (best) { _currentFocus = best->GetVPanel(); best->RequestFocus(-1); bFound = true; if (!CanButtonBeDefault(best->GetVPanel())) { if (_defaultButton) { SetCurrentDefaultButton(_defaultButton); } else { SetCurrentDefaultButton(NULL); // we need to ask the parent to set its default button if (_mainPanel->GetVParent()) { ivgui()->PostMessage(_mainPanel->GetVParent(), new KeyValues("FindDefaultButton"), NULL); } } } else { SetCurrentDefaultButton(best->GetVPanel()); } } return bFound; }
//----------------------------------------------------------------------------- // Purpose: Sets the focus to the previous panel in the tab order // Input : *panel - panel currently with focus //----------------------------------------------------------------------------- bool FocusNavGroup::RequestFocusNext(VPANEL panel) { // basic recursion guard, in case user has set up a bad focus hierarchy static int stack_depth = 0; stack_depth++; _currentFocus = NULL; int newPosition = 0; if (panel) { newPosition = ipanel()->GetTabPosition(panel); } bool bFound = false; bool bRepeat = true; Panel *best = NULL; while (1) { newPosition++; int bestPosition = 999999; // look for the next tab position for (int i = 0; i < _mainPanel->GetChildCount(); i++) { Panel *child = _mainPanel->GetChild(i); if ( !child ) continue; if (child && child->IsVisible() && child->IsEnabled() && child->GetTabPosition()) { int tabPosition = child->GetTabPosition(); if (tabPosition == newPosition) { // we've found the right tab best = child; bestPosition = newPosition; // don't loop anymore since we've found the correct panel break; } else if (tabPosition > newPosition && tabPosition < bestPosition) { // record the match since this is the closest so far bestPosition = tabPosition; best = child; } } } if (!bRepeat) break; if (best) break; // haven't found an item // check to see if we should push the focus request up if (!_topLevelFocus) { if (_mainPanel->GetVParent() && _mainPanel->GetVParent() != surface()->GetEmbeddedPanel()) { // we're not a top level panel, so forward up the request instead of looping if (stack_depth < 15) { if (ipanel()->RequestFocusNext(_mainPanel->GetVParent(), _mainPanel->GetVPanel())) { bFound = true; SetCurrentDefaultButton(NULL); break; } // if we find one then we break, otherwise we loop } } } // loop back newPosition = 0; bRepeat = false; } if (best) { _currentFocus = best->GetVPanel(); best->RequestFocus(1); bFound = true; if (!CanButtonBeDefault(best->GetVPanel())) { if (_defaultButton) { SetCurrentDefaultButton(_defaultButton); } else { SetCurrentDefaultButton(NULL); // we need to ask the parent to set its default button if (_mainPanel->GetVParent()) { ivgui()->PostMessage(_mainPanel->GetVParent(), new KeyValues("FindDefaultButton"), NULL); } } } else { SetCurrentDefaultButton(best->GetVPanel()); } } stack_depth--; return bFound; }
//============================================================================= void InGameChapterSelect::OnCommand(const char *command) { if ( const char* szMissionItem = StringAfterPrefix( command, "cmd_campaign_" ) ) { if ( !Q_stricmp( szMissionItem, m_chCampaign ) ) return; // Setting to same mission Q_strncpy( m_chCampaign, szMissionItem, ARRAYSIZE( m_chCampaign ) ); // Determine current game settings KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL ); KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings ); if ( !pGameSettings ) return; DropDownMenu *pMissionDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpMission" ) ); if( pMissionDropDown ) //we should become a listener for events pertaining to the mission flyout { FlyoutMenu* missionFlyout = pMissionDropDown->GetCurrentFlyout(); if( missionFlyout ) { missionFlyout->SetListener( this ); if ( vgui::Button *pAddonBtn = missionFlyout->FindChildButtonByCommand( "cmd_addoncampaign" ) ) { pAddonBtn->SetEnabled( false ); } // Disable all other campaigns that cannot be used for a vote for ( int k = 0, kNum = missionFlyout->GetChildCount(); k < kNum; ++ k ) { Panel *child = missionFlyout->GetChild( k ); if ( BaseModHybridButton* button = dynamic_cast< BaseModHybridButton* >( child ) ) { if ( const char* commandValue = button->GetCommand()->GetString( "command", NULL ) ) { if ( char const *szMissionName = StringAfterPrefix( commandValue, "cmd_campaign_" ) ) { pGameSettings->SetString( "game/campaign", szMissionName ); pGameSettings->SetInt( "game/chapter", 1 ); if ( !g_pMatchExtSwarm->GetMapInfo( pGameSettings ) ) { button->SetEnabled( false ); } } } } } } } } else if ( char const *szChapterSelected = StringAfterPrefix( command, "#L4D360UI_Chapter_" ) ) { m_nChapter = atoi( szChapterSelected ); UpdateChapterImage( m_chCampaign, m_nChapter ); } else if ( !Q_stricmp( command, "Select" ) ) { KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL ); KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings ); if ( !GameModeIsSingleChapter( pGameSettings->GetString( "game/mode" ) ) ) m_nChapter = 1; pGameSettings->SetString( "game/campaign", m_chCampaign ); pGameSettings->SetInt( "game/chapter", m_nChapter ); char const *szVoteCommand = "ChangeChapter"; int iUser = GetGameUIActiveSplitScreenPlayerSlot(); GAMEUI_ACTIVE_SPLITSCREEN_PLAYER_GUARD( iUser ); Panel *pDrpChapter = FindChildByName( "DrpChapter" ); if ( !pDrpChapter || !pDrpChapter->IsEnabled() ) { szVoteCommand = "ChangeMission"; m_nChapter = 1; engine->ClientCmd( CFmtStr( "callvote %s %s;", szVoteCommand, m_chCampaign ) ); } else if ( KeyValues *pInfoMap = g_pMatchExtSwarm->GetMapInfo( pGameSettings ) ) { engine->ClientCmd( CFmtStr( "callvote %s %s;", szVoteCommand, pInfoMap->GetString( "map" ) ) ); } GameUI().AllowEngineHideGameUI(); engine->ClientCmd( "gameui_hide" ); Close(); } else if ( !Q_strcmp( command, "Cancel" ) ) { GameUI().AllowEngineHideGameUI(); engine->ClientCmd("gameui_hide"); Close(); } }