//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======= // // Purpose: // //============================================================================= #include "commentarydialog.h" #include "basepanel.h" #include "convar.h" #include "engineinterface.h" #include "gameui_interface.h" #include "vgui/ISurface.h" #include "vgui/IInput.h" #include using namespace vgui; // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CCommentaryDialog::CCommentaryDialog(vgui::Panel *parent) : BaseClass(parent, "CommentaryDialog") { SetDeleteSelfOnClose(true); SetSizeable( false ); input()->SetAppModalSurface(GetVPanel()); vgui::surface()->RestrictPaintToSinglePanel(GetVPanel()); GameUI().PreventEngineHideGameUI(); SetTitle("#GameUI_CommentaryDialogTitle", true); LoadControlSettings("Resource/CommentaryDialog.res"); MoveToCenterOfScreen(); bool bCommentaryOn = false; ConVarRef commentary( "commentary" ); if ( commentary.IsValid() ) { bCommentaryOn = commentary.GetBool(); } // Setup the buttons & labels to reflect the current state of the commentary if ( bCommentaryOn ) { SetControlString( "ModeLabel", "#GAMEUI_Commentary_LabelOn" ); SetControlString( "TurnOnButton", "#GAMEUI_Commentary_LeaveOn" ); SetControlString( "TurnOffButton", "#GAMEUI_Commentary_TurnOff" ); } else { SetControlString( "ModeLabel", "#GAMEUI_Commentary_LabelOff" ); SetControlString( "TurnOnButton", "#GAMEUI_Commentary_TurnOn" ); SetControlString( "TurnOffButton", "#GAMEUI_Commentary_LeaveOff" ); } } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CCommentaryDialog::~CCommentaryDialog() { } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CCommentaryDialog::OnClose( void ) { BaseClass::OnClose(); vgui::surface()->RestrictPaintToSinglePanel(NULL); GameUI().AllowEngineHideGameUI(); // Bring up the post dialog DHANDLE hPostCommentaryDialog; if ( !hPostCommentaryDialog.Get() ) { hPostCommentaryDialog = new CPostCommentaryDialog( BasePanel() ); } hPostCommentaryDialog->Activate(); } //----------------------------------------------------------------------------- // Purpose: // Input : *command - //----------------------------------------------------------------------------- void CCommentaryDialog::OnCommand( const char *command ) { if ( !Q_stricmp( command, "TurnOn" ) ) { ConVarRef commentary("commentary"); commentary.SetValue( 1 ); Close(); } else if ( !Q_stricmp( command, "TurnOff" ) ) { ConVarRef commentary("commentary"); commentary.SetValue( 0 ); Close(); } else { BaseClass::OnCommand( command ); } } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CCommentaryDialog::OnKeyCodePressed(KeyCode code) { // Ignore escape key if (code == KEY_ESCAPE) return; BaseClass::OnKeyCodePressed(code); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void OpenCommentaryDialog( void ) { DHANDLE hCommentaryDialog; if ( !hCommentaryDialog.Get() ) { hCommentaryDialog = new CCommentaryDialog( BasePanel() ); } GameUI().ActivateGameUI(); hCommentaryDialog->Activate(); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- ConVar commentary_firstrun("commentary_firstrun", "0", FCVAR_ARCHIVE ); void CC_CommentaryTestFirstRun( void ) { if ( !commentary_firstrun.GetBool() ) { commentary_firstrun.SetValue(1); OpenCommentaryDialog(); } } static ConCommand commentary_testfirstrun("commentary_testfirstrun", CC_CommentaryTestFirstRun, 0 ); //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CPostCommentaryDialog::CPostCommentaryDialog(vgui::Panel *parent) : BaseClass(parent, "PostCommentaryDialog") { SetDeleteSelfOnClose(true); SetSizeable( false ); input()->SetAppModalSurface(GetVPanel()); vgui::surface()->RestrictPaintToSinglePanel(GetVPanel()); m_bResetPaintRestrict = false; SetTitle("#GameUI_CommentaryDialogTitle", true); LoadControlSettings("Resource/PostCommentaryDialog.res"); MoveToCenterOfScreen(); bool bCommentaryOn = false; ConVarRef commentary("commentary"); if ( commentary.IsValid() ) { bCommentaryOn = commentary.GetBool(); } // Setup the buttons & labels to reflect the current state of the commentary if ( bCommentaryOn ) { SetControlString( "PostModeLabel", "#GAMEUI_PostCommentary_ModeLabelOn" ); } else { SetControlString( "PostModeLabel", "#GAMEUI_PostCommentary_ModeLabelOff" ); } } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CPostCommentaryDialog::~CPostCommentaryDialog() { } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPostCommentaryDialog::OnFinishedClose( void ) { BaseClass::OnFinishedClose(); if ( !m_bResetPaintRestrict ) { m_bResetPaintRestrict = true; vgui::surface()->RestrictPaintToSinglePanel(NULL); GameUI().HideGameUI(); } } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPostCommentaryDialog::OnKeyCodePressed(KeyCode code) { if (code == KEY_ESCAPE) { Close(); vgui::surface()->RestrictPaintToSinglePanel(NULL); m_bResetPaintRestrict = true; } else { BaseClass::OnKeyCodePressed(code); } }