//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: Generic in-game abuse reporting // // $NoKeywords: $ //=============================================================================// #include "cbase.h" #include "abuse_report_ui.h" #include "econ/econ_controls.h" #include "ienginevgui.h" #include "vgui/ISurface.h" #include #include #include #include "vgui_bitmappanel.h" #include "vgui_avatarimage.h" #include "gc_clientsystem.h" #include "econ/tool_items/tool_items.h" #include "econ/econ_gcmessages.h" #include "econ/confirm_dialog.h" #include "tool_items/custom_texture_cache.h" vgui::DHANDLE g_AbuseReportDlg; CAbuseReportDlg::CAbuseReportDlg( vgui::Panel *parent, AbuseIncidentData_t *pIncidentData ) : EditablePanel( parent, "AbuseReportSubmitDialog" ) , m_pSubmitButton( NULL ) , m_pScreenShot( NULL ) , m_pScreenShotAttachCheckButton( NULL ) , m_pOffensiveImage( NULL ) , m_pDescriptionTextEntry( NULL ) , m_pPlayerLabel( NULL ) , m_pPlayerRadio( NULL ) , m_pGameServerRadio( NULL ) , m_pPlayerCombo( NULL ) , m_pAbuseContentLabel( NULL ) , m_pAbuseContentCombo( NULL ) , m_pAbuseTypeLabel( NULL ) , m_pAbuseTypeCombo( NULL ) , m_pScreenShotBitmap( NULL ) , m_pAvatarImage( NULL ) , m_pNoAvatarLabel( NULL ) , m_pCustomTextureImagePanel( NULL ) , m_pNoCustomTexturesLabel( NULL ) , m_pCustomTextureNextButton( NULL ) , m_pCustomTexturePrevButton( NULL ) , m_iUserImageIndex( 0 ) , m_pIncidentData( pIncidentData ) { vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme" ); SetScheme(scheme); SetProportional( true ); //m_pContainer = new vgui::EditablePanel( this, "Container" ); Assert( g_AbuseReportDlg.Get() == NULL ); g_AbuseReportDlg.Set( this ); engine->ExecuteClientCmd("gameui_preventescape"); } CAbuseReportDlg::~CAbuseReportDlg() { Assert( g_AbuseReportDlg.Get() == this ); if ( g_AbuseReportDlg.Get() == this ) { engine->ExecuteClientCmd("gameui_allowescape"); g_AbuseReportDlg = NULL; } } void CAbuseReportDlg::OnCommand( const char *command ) { if ( !Q_stricmp( command, "cancel" ) ) { Close(); return; } if ( !Q_stricmp( command, "discard" ) ) { Close(); g_AbuseReportMgr->DestroyIncidentData(); return; } if ( !Q_stricmp( command, "submit" ) ) { OnSubmitReport(); return; } if ( !Q_stricmp( command, "nextcustomtexture" ) ) { ++m_iUserImageIndex; UpdateCustomTextures(); return; } if ( !Q_stricmp( command, "prevcustomtexture" ) ) { --m_iUserImageIndex; UpdateCustomTextures(); return; } } void CAbuseReportDlg::MakeModal() { TFModalStack()->PushModal( this ); MakePopup(); MoveToFront(); SetKeyBoardInputEnabled( true ); SetMouseInputEnabled( true ); // !KLUDGE! Initially set the dialog to be hidden, so we can take a screenshot! SetEnabled( m_pIncidentData != NULL ); //SetVisible( m_pIncidentData != NULL ); } void CAbuseReportDlg::Close() { TFModalStack()->PopModal( this ); SetVisible( false ); MarkForDeletion(); } const char *CAbuseReportDlg::GetResFilename() { return "Resource/UI/AbuseReportSubmitDialog.res"; //return "Resource/UI/QuickplayDialog.res"; } void CAbuseReportDlg::PerformLayout() { BaseClass::PerformLayout(); // Center it, keeping requested size int x, y, ww, wt, wide, tall; vgui::surface()->GetWorkspaceBounds( x, y, ww, wt ); GetSize(wide, tall); SetPos(x + ((ww - wide) / 2), y + ((wt - tall) / 2)); // @todo setup } class CCustomTextureImagePanel : public vgui::Panel { public: CCustomTextureImagePanel( Panel *parent, const char *panelName ) : vgui::Panel( parent, panelName ) { m_ugcHandle = 0; } uint64 m_ugcHandle; virtual void Paint() { if ( m_ugcHandle == 0 ) { return; } int iTextureHandle = GetCustomTextureGuiHandle( m_ugcHandle ); if ( iTextureHandle <= 0) { return; } vgui::surface()->DrawSetColor(COLOR_WHITE); vgui::surface()->DrawSetTexture( iTextureHandle ); int iWide, iTall; GetSize( iWide, iTall ); vgui::Vertex_t verts[4]; verts[0].Init( Vector2D( 0, 0 ), Vector2D( 0.0f, 0.0f ) ); verts[1].Init( Vector2D( iWide, 0 ), Vector2D( 1.0f, 0.0f ) ); verts[2].Init( Vector2D( iWide, iTall ), Vector2D( 1.0f, 1.0f ) ); verts[3].Init( Vector2D( 0, iTall ), Vector2D( 0.0f, 1.0f ) ); vgui::surface()->DrawTexturedPolygon( 4, verts ); vgui::surface()->DrawSetColor(COLOR_WHITE); } }; class CAbuseReportScreenShotPanel : public CBitmapPanel { public: CAbuseReportScreenShotPanel( CAbuseReportDlg *pDlg, const char *panelName ) : CBitmapPanel( pDlg, panelName ) , m_pDlg( pDlg ) {} CAbuseReportDlg *m_pDlg; virtual void Paint() { CBitmapPanel::Paint(); const AbuseIncidentData_t::PlayerData_t *p = m_pDlg->GetAccusedPlayerPtr(); if ( p == NULL || !p->m_bRenderBoundsValid ) { return; } int w, t; GetSize( w, t ); int x0 = int( p->m_screenBoundsMin.x * (float)w ); int y0 = int( p->m_screenBoundsMin.y * (float)t ); int x1 = int( p->m_screenBoundsMax.x * (float)w ); int y1 = int( p->m_screenBoundsMax.y * (float)t ); vgui::surface()->DrawSetColor( Color(200, 10, 10, 200 ) ); vgui::surface()->DrawOutlinedRect( x0, y0, x1, y1 ); vgui::surface()->DrawSetColor( COLOR_WHITE ); } }; void CAbuseReportDlg::ApplySchemeSettings( vgui::IScheme *pScheme ) { EditablePanel::ApplySchemeSettings( pScheme ); m_pScreenShotBitmap = new CAbuseReportScreenShotPanel( this, "ScreenShotBitmap" ); m_pCustomTextureImagePanel = new CCustomTextureImagePanel( this, "CustomTextureImage" ); LoadControlSettings( GetResFilename() ); m_pPlayerRadio = dynamic_cast(FindChildByName( "PlayerRadio", true )); Assert( m_pPlayerRadio ); if ( m_pPlayerRadio ) { m_pPlayerRadio->SetVisible( m_pIncidentData->m_bCanReportGameServer ); } m_pGameServerRadio = dynamic_cast(FindChildByName( "GameServerRadio", true )); Assert( m_pGameServerRadio ); if ( m_pGameServerRadio ) { m_pGameServerRadio->SetVisible( m_pIncidentData->m_bCanReportGameServer ); } m_pPlayerLabel = FindChildByName( "PlayerLabel", true ); Assert( m_pPlayerLabel ); m_pScreenShotAttachCheckButton = dynamic_cast(FindChildByName( "ScreenShotAttachCheckButton", true )); Assert( m_pScreenShotAttachCheckButton ); if ( m_pScreenShotAttachCheckButton ) { m_pScreenShotAttachCheckButton->SetSelected( true ); } m_pSubmitButton = dynamic_cast(FindChildByName( "SubmitButton", true )); Assert( m_pSubmitButton ); m_pDescriptionTextEntry = dynamic_cast(FindChildByName( "DescriptionTextEntry", true )); Assert( m_pDescriptionTextEntry ); if ( m_pDescriptionTextEntry ) { m_pDescriptionTextEntry->SetMultiline( true ); } m_pAvatarImage = dynamic_cast(FindChildByName( "AvatarImage", true )); Assert( m_pAvatarImage ); m_pNoAvatarLabel = FindChildByName( "NoAvatarLabel", true ); Assert( m_pNoAvatarLabel ); m_pNoCustomTexturesLabel = FindChildByName( "NoCustomTexturesLabel", true ); Assert( m_pNoCustomTexturesLabel ); m_pCustomTextureNextButton = dynamic_cast(FindChildByName( "CustomTextureNextButton", true )); Assert( m_pCustomTextureNextButton ); m_pCustomTexturePrevButton = dynamic_cast(FindChildByName( "CustomTexturePrevButton", true )); Assert( m_pCustomTexturePrevButton ); m_pPlayerCombo = dynamic_cast(FindChildByName( "PlayerComboBox", true )); Assert( m_pPlayerCombo ); m_pAbuseContentLabel = FindChildByName( "AbuseContentLabel", true ); Assert( m_pAbuseContentLabel ); m_pAbuseContentCombo = dynamic_cast(FindChildByName( "AbuseContentComboBox", true )); Assert( m_pAbuseContentCombo ); if ( m_pAbuseContentCombo ) { m_pAbuseContentCombo->AddItem( "#AbuseReport_SelectOne", new KeyValues( "AbuseContent", "code", k_EAbuseReportContentNoSelection ) ); m_pAbuseContentCombo->AddItem( "#AbuseReport_ContentAvatarImage", new KeyValues( "AbuseContent", "code", k_EAbuseReportContentAvatarImage ) ); m_pAbuseContentCombo->AddItem( "#AbuseReport_ContentPlayerName", new KeyValues( "AbuseContent", "code", k_EAbuseReportContentPersonaName ) ); m_pAbuseContentCombo->AddItem( "#AbuseReport_ContentItemDecal", new KeyValues( "AbuseContent", "code", k_EAbuseReportContentUGCImage ) ); m_pAbuseContentCombo->AddItem( "#AbuseReport_ContentChatText", new KeyValues( "AbuseContent", "code", k_EAbuseReportContentComments ) ); m_pAbuseContentCombo->AddItem( "#AbuseReport_ContentCheating", new KeyValues( "AbuseContent", "code", k_EAbuseReportContentCheating ) ); m_pAbuseContentCombo->AddItem( "#AbuseReport_ContentOther", new KeyValues( "AbuseContent", "code", k_EAbuseReportContentUnspecified ) ); m_pAbuseContentCombo->SilentActivateItemByRow( 0 ); m_pAbuseContentCombo->SetNumberOfEditLines( m_pAbuseContentCombo->GetItemCount() ); } m_pAbuseTypeLabel = FindChildByName( "AbuseTypeLabel", true ); Assert( m_pAbuseTypeLabel ); m_pAbuseTypeCombo = dynamic_cast(FindChildByName( "AbuseTypeComboBox", true )); Assert( m_pAbuseTypeCombo ); Assert( m_pScreenShotBitmap ); if ( m_pScreenShotBitmap && m_pIncidentData->m_bitmapScreenshot.IsValid() ) { m_pScreenShotBitmap->SetBitmap( m_pIncidentData->m_bitmapScreenshot ); } PopulatePlayerList(); SetIsAccusingGameServer( false ); SetEnabled( true ); SetVisible( true ); } bool CAbuseReportDlg::IsAccusingGameServer() { return m_pIncidentData && m_pIncidentData->m_bCanReportGameServer && m_pGameServerRadio && m_pGameServerRadio->IsSelected(); } EAbuseReportContentType CAbuseReportDlg::GetAbuseContentType() { if ( m_pAbuseContentCombo == NULL || IsAccusingGameServer() ) { Assert( m_pAbuseContentCombo ); return k_EAbuseReportContentNoSelection; } KeyValues *pUserData = m_pAbuseContentCombo->GetActiveItemUserData(); if ( pUserData == NULL ) { return k_EAbuseReportContentNoSelection; } return (EAbuseReportContentType)pUserData->GetInt( "code", k_EAbuseReportContentNoSelection ); } EAbuseReportType CAbuseReportDlg::GetAbuseType() { if ( m_pAbuseTypeCombo == NULL || IsAccusingGameServer() ) { Assert( m_pAbuseTypeCombo ); return k_EAbuseReportTypeNoSelection; } KeyValues *pUserData = m_pAbuseTypeCombo->GetActiveItemUserData(); if ( pUserData == NULL ) { return k_EAbuseReportTypeNoSelection; } return (EAbuseReportType)pUserData->GetInt( "code", k_EAbuseReportTypeNoSelection ); } CUtlString CAbuseReportDlg::GetAbuseDescription() { char buf[ 1024 ] = ""; if ( m_pDescriptionTextEntry ) { m_pDescriptionTextEntry->GetText( buf, ARRAYSIZE(buf) ); } return CUtlString( buf ); } int CAbuseReportDlg::GetAccusedPlayerIndex() { // If accusing a game server, then there's no player if ( IsAccusingGameServer() ) { return -1; } if ( m_pPlayerCombo == NULL ) { Assert( m_pPlayerCombo ); return -1; } // Item 0 is the "