forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaseToolSystem.cpp
1156 lines (948 loc) · 30.3 KB
/
BaseToolSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Core Movie Maker UI API
//
//=============================================================================
#include "toolutils/basetoolsystem.h"
#include "toolframework/ienginetool.h"
#include "vgui/IPanel.h"
#include "vgui_controls/Controls.h"
#include "vgui_controls/Menu.h"
#include "vgui/ISurface.h"
#include "vgui_controls/Panel.h"
#include "vgui_controls/FileOpenDialog.h"
#include "vgui_controls/MessageBox.h"
#include "vgui/Cursor.h"
#include "vgui/iinput.h"
#include "vgui/ivgui.h"
#include "vgui_controls/AnimationController.h"
#include "ienginevgui.h"
#include "toolui.h"
#include "toolutils/toolmenubar.h"
#include "vgui/ilocalize.h"
#include "toolutils/enginetools_int.h"
#include "toolutils/vgui_tools.h"
#include "icvar.h"
#include "tier1/convar.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "filesystem.h"
#include "vgui_controls/savedocumentquery.h"
#include "vgui_controls/perforcefilelistframe.h"
#include "toolutils/miniviewport.h"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imesh.h"
#include "toolutils/BaseStatusBar.h"
#include "movieobjects/movieobjects.h"
#include "vgui_controls/KeyBoardEditorDialog.h"
#include "vgui_controls/KeyBindingHelpDialog.h"
#include "dmserializers/idmserializers.h"
#include "tier2/renderutils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
extern IMaterialSystem *MaterialSystem();
class CGlobalFlexController : public IGlobalFlexController
{
public:
virtual int FindGlobalFlexController( const char *name )
{
return clienttools->FindGlobalFlexcontroller( name );
}
virtual const char *GetGlobalFlexControllerName( int idx )
{
return clienttools->GetGlobalFlexControllerName( idx );
}
};
static CGlobalFlexController g_GlobalFlexController;
extern IGlobalFlexController *g_pGlobalFlexController;
//-----------------------------------------------------------------------------
// Singleton interfaces
//-----------------------------------------------------------------------------
IServerTools *servertools = NULL;
IClientTools *clienttools = NULL;
//-----------------------------------------------------------------------------
// External functions
//-----------------------------------------------------------------------------
void RegisterTool( IToolSystem *tool );
//-----------------------------------------------------------------------------
// Base tool system constructor
//-----------------------------------------------------------------------------
CBaseToolSystem::CBaseToolSystem( const char *pToolName /*="CBaseToolSystem"*/ ) :
BaseClass( NULL, pToolName ),
m_pBackground( 0 ),
m_pLogo( 0 )
{
RegisterTool( this );
SetAutoDelete( false );
m_bGameInputEnabled = false;
m_bFullscreenMode = false;
m_bIsActive = false;
m_bFullscreenToolModeEnabled = false;
m_MostRecentlyFocused = NULL;
SetKeyBoardInputEnabled( true );
input()->RegisterKeyCodeUnhandledListener( GetVPanel() );
m_pFileOpenStateMachine = new vgui::FileOpenStateMachine( this, this );
m_pFileOpenStateMachine->AddActionSignalTarget( this );
}
void CBaseToolSystem::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
SetKeyBoardInputEnabled( true );
}
//-----------------------------------------------------------------------------
// Called at the end of engine startup (after client .dll and server .dll have been loaded)
//-----------------------------------------------------------------------------
bool CBaseToolSystem::Init( )
{
// Read shared localization info
g_pVGuiLocalize->AddFile( "resource/dmecontrols_%language%.txt" );
g_pVGuiLocalize->AddFile( "resource/toolshared_%language%.txt" );
g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt" );
g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt" );
g_pVGuiLocalize->AddFile( "resource/boxrocket_%language%.txt" );
// Create the tool workspace
SetParent( VGui_GetToolRootPanel() );
// Deal with scheme
vgui::HScheme hToolScheme = GetToolScheme();
if ( hToolScheme != 0 )
{
SetScheme( hToolScheme );
}
m_KeyBindingsHandle = Panel::CreateKeyBindingsContext( GetBindingsContextFile(), "GAME" );
SetKeyBindingsContext( m_KeyBindingsHandle );
LoadKeyBindings();
const char *pszBackground = GetBackgroundTextureName();
if ( pszBackground )
{
m_pBackground = materials->FindMaterial( GetBackgroundTextureName() , TEXTURE_GROUP_VGUI );
m_pBackground->IncrementReferenceCount();
}
const char *pszLogo = GetLogoTextureName();
if ( pszLogo )
{
m_pLogo = materials->FindMaterial( GetLogoTextureName(), TEXTURE_GROUP_VGUI );
m_pLogo->IncrementReferenceCount();
}
// Make the tool workspace the size of the screen
int w, h;
surface()->GetScreenSize( w, h );
SetBounds( 0, 0, w, h );
SetPaintBackgroundEnabled( true );
SetPaintBorderEnabled( false );
SetPaintEnabled( false );
SetCursor( vgui::dc_none );
SetVisible( false );
// Create the tool UI
m_pToolUI = new CToolUI( this, "ToolUI", this );
// Create the mini viewport
m_hMiniViewport = CreateMiniViewport( GetClientArea() );
Assert( m_hMiniViewport.Get() );
return true;
}
void CBaseToolSystem::ShowMiniViewport( bool state )
{
if ( !m_hMiniViewport.Get() )
return;
m_hMiniViewport->SetVisible( state );
}
void CBaseToolSystem::SetMiniViewportBounds( int x, int y, int width, int height )
{
if ( m_hMiniViewport )
{
m_hMiniViewport->SetBounds( x, y, width, height );
}
}
void CBaseToolSystem::SetMiniViewportText( const char *pText )
{
if ( m_hMiniViewport )
{
m_hMiniViewport->SetOverlayText( pText );
}
}
void CBaseToolSystem::GetMiniViewportEngineBounds( int &x, int &y, int &width, int &height )
{
if ( m_hMiniViewport )
{
m_hMiniViewport->GetEngineBounds( x, y, width, height );
}
}
vgui::Panel *CBaseToolSystem::GetMiniViewport( void )
{
return m_hMiniViewport;
}
//-----------------------------------------------------------------------------
// Shut down
//-----------------------------------------------------------------------------
void CBaseToolSystem::Shutdown()
{
if ( m_pBackground )
{
m_pBackground->DecrementReferenceCount();
}
if ( m_pLogo )
{
m_pLogo->DecrementReferenceCount();
}
if ( m_hMiniViewport.Get() )
{
delete m_hMiniViewport.Get();
}
// Make sure anything "marked for deletion"
// actually gets deleted before this dll goes away
vgui::ivgui()->RunFrame();
}
//-----------------------------------------------------------------------------
// Can the tool quit?
//-----------------------------------------------------------------------------
bool CBaseToolSystem::CanQuit()
{
return true;
}
//-----------------------------------------------------------------------------
// Client, server init + shutdown
//-----------------------------------------------------------------------------
bool CBaseToolSystem::ServerInit( CreateInterfaceFn serverFactory )
{
servertools = ( IServerTools * )serverFactory( VSERVERTOOLS_INTERFACE_VERSION, NULL );
if ( !servertools )
{
Error( "CBaseToolSystem::PostInit: Unable to get '%s' interface from game .dll\n", VSERVERTOOLS_INTERFACE_VERSION );
}
return true;
}
bool CBaseToolSystem::ClientInit( CreateInterfaceFn clientFactory )
{
clienttools = ( IClientTools * )clientFactory( VCLIENTTOOLS_INTERFACE_VERSION, NULL );
if ( !clienttools )
{
Error( "CBaseToolSystem::PostInit: Unable to get '%s' interface from client .dll\n", VCLIENTTOOLS_INTERFACE_VERSION );
}
else
{
g_pGlobalFlexController = &g_GlobalFlexController; // don't set this until clienttools is connected
}
return true;
}
void CBaseToolSystem::ServerShutdown()
{
servertools = NULL;
}
void CBaseToolSystem::ClientShutdown()
{
clienttools = NULL;
}
//-----------------------------------------------------------------------------
// Level init, shutdown for server
//-----------------------------------------------------------------------------
void CBaseToolSystem::ServerLevelInitPreEntity()
{
}
void CBaseToolSystem::ServerLevelInitPostEntity()
{
}
void CBaseToolSystem::ServerLevelShutdownPreEntity()
{
}
void CBaseToolSystem::ServerLevelShutdownPostEntity()
{
}
//-----------------------------------------------------------------------------
// Think methods
//-----------------------------------------------------------------------------
void CBaseToolSystem::ServerFrameUpdatePreEntityThink()
{
}
void CBaseToolSystem::Think( bool finalTick )
{
// run vgui animations
vgui::GetAnimationController()->UpdateAnimations( enginetools->Time() );
}
void CBaseToolSystem::PostMessage( HTOOLHANDLE hEntity, KeyValues *message )
{
if ( !Q_stricmp( message->GetName(), "ReleaseLayoffTexture" ) )
{
if ( m_hMiniViewport.Get() )
{
m_hMiniViewport->ReleaseLayoffTexture();
}
return;
}
}
void CBaseToolSystem::ServerFrameUpdatePostEntityThink()
{
}
void CBaseToolSystem::ServerPreClientUpdate()
{
}
void CBaseToolSystem::ServerPreSetupVisibility()
{
}
const char* CBaseToolSystem::GetEntityData( const char *pActualEntityData )
{
return pActualEntityData;
}
//-----------------------------------------------------------------------------
// Level init, shutdown for client
//-----------------------------------------------------------------------------
void CBaseToolSystem::ClientLevelInitPreEntity()
{
}
void CBaseToolSystem::ClientLevelInitPostEntity()
{
}
void CBaseToolSystem::ClientLevelShutdownPreEntity()
{
}
void CBaseToolSystem::ClientLevelShutdownPostEntity()
{
}
void CBaseToolSystem::ClientPreRender()
{
}
void CBaseToolSystem::ClientPostRender()
{
}
//-----------------------------------------------------------------------------
// Tool activation/deactivation
//-----------------------------------------------------------------------------
void CBaseToolSystem::OnToolActivate()
{
m_bIsActive = true;
UpdateUIVisibility( );
// FIXME: Note that this is necessary because IsGameInputEnabled depends on m_bIsActive at the moment
OnModeChanged();
input()->SetModalSubTree( VGui_GetToolRootPanel(), GetVPanel(), IsGameInputEnabled() );
input()->SetModalSubTreeReceiveMessages( !IsGameInputEnabled() );
m_pToolUI->UpdateMenuBarTitle();
}
void CBaseToolSystem::OnToolDeactivate()
{
m_bIsActive = false;
UpdateUIVisibility( );
// FIXME: Note that this is necessary because IsGameInputEnabled depends on m_bIsActive at the moment
OnModeChanged();
input()->ReleaseModalSubTree();
}
//-----------------------------------------------------------------------------
// Let tool override key events (ie ESC and ~)
//-----------------------------------------------------------------------------
bool CBaseToolSystem::TrapKey( ButtonCode_t key, bool down )
{
// Don't hook keyboard if not topmost
if ( !m_bIsActive )
return false; // didn't trap, continue processing
// If in fullscreen toolMode, don't let ECSAPE bring up the game menu
if ( !m_bGameInputEnabled && m_bFullscreenMode && ( key == KEY_ESCAPE ) )
return true; // trapping this key, stop processing
if ( down )
{
if ( key == TOGGLE_WINDOWED_KEY_CODE )
{
SetMode( m_bGameInputEnabled, !m_bFullscreenMode );
return true; // trapping this key, stop processing
}
if ( key == TOGGLE_INPUT_KEY_CODE )
{
if ( input()->IsKeyDown( KEY_LCONTROL ) || input()->IsKeyDown( KEY_RCONTROL ) )
{
ToggleForceToolCamera();
}
else
{
SetMode( !m_bGameInputEnabled, m_bFullscreenMode );
}
return true; // trapping this key, stop processing
}
// If in IFM mode, let ~ switch to gameMode and toggle console
if ( !IsGameInputEnabled() && ( key == '~' || key == '`' ) )
{
SetMode( true, m_bFullscreenMode );
return false; // didn't trap, continue processing
}
}
return false; // didn't trap, continue processing
}
//-----------------------------------------------------------------------------
// Shows, hides the tool ui (menu, client area, status bar)
//-----------------------------------------------------------------------------
void CBaseToolSystem::SetToolUIVisible( bool bVisible )
{
if ( bVisible != m_pToolUI->IsVisible() )
{
m_pToolUI->SetVisible( bVisible );
m_pToolUI->InvalidateLayout();
}
}
//-----------------------------------------------------------------------------
// Computes whether vgui is visible or not
//-----------------------------------------------------------------------------
void CBaseToolSystem::UpdateUIVisibility()
{
bool bIsVisible = m_bIsActive && ( !IsGameInputEnabled() || !m_bFullscreenMode );
ShowUI( bIsVisible );
}
//-----------------------------------------------------------------------------
// Changes game input + fullscreen modes
//-----------------------------------------------------------------------------
void CBaseToolSystem::EnableFullscreenToolMode( bool bEnable )
{
m_bFullscreenToolModeEnabled = bEnable;
}
//-----------------------------------------------------------------------------
// Changed whether camera is forced to be tool camera
//-----------------------------------------------------------------------------
void CBaseToolSystem::ToggleForceToolCamera()
{
}
//-----------------------------------------------------------------------------
// Changes game input + fullscreen modes
//-----------------------------------------------------------------------------
void CBaseToolSystem::SetMode( bool bGameInputEnabled, bool bFullscreen )
{
Assert( m_bIsActive );
if ( !m_bFullscreenToolModeEnabled )
{
if ( !bGameInputEnabled )
{
bFullscreen = false;
}
}
if ( ( m_bFullscreenMode == bFullscreen ) && ( m_bGameInputEnabled == bGameInputEnabled ) )
return;
bool bOldGameInputEnabled = m_bGameInputEnabled;
m_bFullscreenMode = bFullscreen;
m_bGameInputEnabled = bGameInputEnabled;
UpdateUIVisibility();
if ( bOldGameInputEnabled != m_bGameInputEnabled )
{
Warning( "Input is now being sent to the %s\n", m_bGameInputEnabled ? "Game" : "Tools" );
// The subtree starts at the tool system root panel. If game input is enabled then
// the subtree should not receive or process input messages, otherwise it should
Assert( input()->GetModalSubTree() );
if ( input()->GetModalSubTree() )
{
input()->SetModalSubTreeReceiveMessages( !m_bGameInputEnabled );
}
}
if ( m_pToolUI )
{
m_pToolUI->UpdateMenuBarTitle();
}
OnModeChanged( );
}
//-----------------------------------------------------------------------------
// Keybinding
//-----------------------------------------------------------------------------
void CBaseToolSystem::LoadKeyBindings()
{
ReloadKeyBindings( m_KeyBindingsHandle );
}
void CBaseToolSystem::ShowKeyBindingsEditor( Panel *panel, KeyBindingContextHandle_t handle )
{
if ( !m_hKeyBindingsEditor.Get() )
{
// Show the editor
m_hKeyBindingsEditor = new CKeyBoardEditorDialog( GetClientArea(), panel, handle );
m_hKeyBindingsEditor->DoModal();
}
}
void CBaseToolSystem::ShowKeyBindingsHelp( Panel *panel, KeyBindingContextHandle_t handle, vgui::KeyCode boundKey, int modifiers )
{
if ( m_hKeyBindingsHelp.Get() )
{
m_hKeyBindingsHelp->HelpKeyPressed();
return;
}
m_hKeyBindingsHelp = new CKeyBindingHelpDialog( GetClientArea(), panel, handle, boundKey, modifiers );
}
vgui::KeyBindingContextHandle_t CBaseToolSystem::GetKeyBindingsHandle()
{
return m_KeyBindingsHandle;
}
void CBaseToolSystem::OnEditKeyBindings()
{
Panel *tool = GetMostRecentlyFocusedTool();
if ( tool )
{
ShowKeyBindingsEditor( tool, tool->GetKeyBindingsContext() );
}
}
void CBaseToolSystem::OnKeyBindingHelp()
{
Panel *tool = GetMostRecentlyFocusedTool();
if ( tool )
{
CUtlVector< BoundKey_t * > list;
LookupBoundKeys( "keybindinghelp", list );
if ( list.Count() > 0 )
{
ShowKeyBindingsHelp( tool, tool->GetKeyBindingsContext(), (KeyCode)list[ 0 ]->keycode, list[ 0 ]->modifiers );
}
}
}
//-----------------------------------------------------------------------------
// Registers tool window
//-----------------------------------------------------------------------------
void CBaseToolSystem::RegisterToolWindow( vgui::PHandle hPanel )
{
int i = m_Tools.AddToTail( hPanel );
m_Tools[i]->SetKeyBindingsContext( m_KeyBindingsHandle );
}
void CBaseToolSystem::UnregisterAllToolWindows()
{
m_Tools.RemoveAll();
m_MostRecentlyFocused = NULL;
}
Panel *CBaseToolSystem::GetMostRecentlyFocusedTool()
{
VPANEL focus = input()->GetFocus();
int c = m_Tools.Count();
for ( int i = 0; i < c; ++i )
{
Panel *p = m_Tools[ i ].Get();
if ( !p )
continue;
// Not a visible tool
if ( !p->GetParent() )
continue;
bool hasFocus = p->HasFocus();
bool focusOnChild = focus && ipanel()->HasParent(focus, p->GetVPanel());
if ( !hasFocus && !focusOnChild )
{
continue;
}
return p;
}
return m_MostRecentlyFocused.Get();
}
void CBaseToolSystem::PostMessageToActiveTool( KeyValues *pKeyValues, float flDelay )
{
Panel *pMostRecent = GetMostRecentlyFocusedTool();
if ( pMostRecent )
{
Panel::PostMessage( pMostRecent->GetVPanel(), pKeyValues, flDelay );
}
}
void CBaseToolSystem::PostMessageToActiveTool( const char *msg, float flDelay )
{
Panel *pMostRecent = GetMostRecentlyFocusedTool();
if ( pMostRecent )
{
Panel::PostMessage( pMostRecent->GetVPanel(), new KeyValues( msg ), flDelay );
}
}
void CBaseToolSystem::PostMessageToAllTools( KeyValues *message )
{
int nCount = enginetools->GetToolCount();
for ( int i = 0; i < nCount; ++i )
{
IToolSystem *pToolSystem = const_cast<IToolSystem*>( enginetools->GetToolSystem( i ) );
pToolSystem->PostMessage( HTOOLHANDLE_INVALID, message );
}
}
void CBaseToolSystem::OnThink()
{
BaseClass::OnThink();
VPANEL focus = input()->GetFocus();
int c = m_Tools.Count();
for ( int i = 0; i < c; ++i )
{
Panel *p = m_Tools[ i ].Get();
if ( !p )
continue;
// Not a visible tool
if ( !p->GetParent() )
continue;
bool hasFocus = p->HasFocus();
bool focusOnChild = focus && ipanel()->HasParent(focus, p->GetVPanel());
if ( !hasFocus && !focusOnChild )
continue;
m_MostRecentlyFocused = p;
break;
}
}
//-----------------------------------------------------------------------------
// Let tool override viewport for engine
//-----------------------------------------------------------------------------
void CBaseToolSystem::AdjustEngineViewport( int& x, int& y, int& width, int& height )
{
if ( !m_hMiniViewport.Get() )
return;
bool enabled;
int vpx, vpy, vpw, vph;
m_hMiniViewport->GetViewport( enabled, vpx, vpy, vpw, vph );
if ( !enabled )
return;
x = vpx;
y = vpy;
width = vpw;
height = vph;
}
//-----------------------------------------------------------------------------
// Let tool override view/camera
//-----------------------------------------------------------------------------
bool CBaseToolSystem::SetupEngineView( Vector &origin, QAngle &angles, float &fov )
{
return false;
}
//-----------------------------------------------------------------------------
// Let tool override microphone
//-----------------------------------------------------------------------------
bool CBaseToolSystem::SetupAudioState( AudioState_t &audioState )
{
return false;
}
//-----------------------------------------------------------------------------
// Should the game be allowed to render the view?
//-----------------------------------------------------------------------------
bool CBaseToolSystem::ShouldGameRenderView()
{
// Render through mini viewport unless in fullscreen mode
if ( !IsVisible() )
{
return true;
}
if ( !m_hMiniViewport.Get() )
return true;
if ( !m_hMiniViewport->IsVisible() )
{
return true;
}
// Route through mini viewport
return false;
}
bool CBaseToolSystem::IsThirdPersonCamera()
{
return false;
}
bool CBaseToolSystem::IsToolRecording()
{
return false;
}
IMaterialProxy *CBaseToolSystem::LookupProxy( const char *proxyName )
{
return NULL;
}
bool CBaseToolSystem::GetSoundSpatialization( int iUserData, int guid, SpatializationInfo_t& info )
{
// Always hearable (no changes)
return true;
}
void CBaseToolSystem::HostRunFrameBegin()
{
}
void CBaseToolSystem::HostRunFrameEnd()
{
}
void CBaseToolSystem::RenderFrameBegin()
{
// If we can't see the engine window, do nothing
if ( !IsVisible() || !IsActiveTool() )
return;
if ( !m_hMiniViewport.Get() || !m_hMiniViewport->IsVisible() )
return;
m_hMiniViewport->RenderFrameBegin();
}
void CBaseToolSystem::RenderFrameEnd()
{
}
void CBaseToolSystem::VGui_PreRender( int paintMode )
{
}
void CBaseToolSystem::VGui_PostRender( int paintMode )
{
}
void CBaseToolSystem::VGui_PreSimulate()
{
if ( !m_bIsActive )
return;
// only show the gameUI when in gameMode
vgui::VPANEL gameui = enginevgui->GetPanel( PANEL_GAMEUIDLL );
if ( gameui != 0 )
{
bool wantsToBeSeen = IsGameInputEnabled() && (enginetools->IsGamePaused() || !enginetools->IsInGame() || enginetools->IsConsoleVisible());
vgui::ipanel()->SetVisible(gameui, wantsToBeSeen);
}
// if there's no map loaded and we're in fullscreen toolMode, switch to gameMode
// otherwise there's nothing to see or do...
if ( !IsGameInputEnabled() && !IsVisible() && !enginetools->IsInGame() )
{
SetMode( true, m_bFullscreenMode );
}
}
void CBaseToolSystem::VGui_PostSimulate()
{
}
const char *CBaseToolSystem::MapName() const
{
return enginetools->GetCurrentMap();
}
//-----------------------------------------------------------------------------
// Shows or hides the UI
//-----------------------------------------------------------------------------
bool CBaseToolSystem::ShowUI( bool bVisible )
{
bool bPrevVisible = IsVisible();
if ( bPrevVisible == bVisible )
return bPrevVisible;
SetMouseInputEnabled( bVisible );
SetVisible( bVisible );
// Hide loading image if using bx movie UI
// A bit of a hack because it more or less tunnels through to the client .dll, but the moviemaker assumes
// single player anyway...
if ( bVisible )
{
ConVar *pCv = ( ConVar * )cvar->FindVar( "cl_showpausedimage" );
if ( pCv )
{
pCv->SetValue( 0 );
}
}
return bPrevVisible;
}
//-----------------------------------------------------------------------------
// Gets the action target to sent to panels so that the tool system's OnCommand is called
//-----------------------------------------------------------------------------
vgui::Panel *CBaseToolSystem::GetActionTarget()
{
return this;
}
//-----------------------------------------------------------------------------
// Derived classes implement this to create a custom menubar
//-----------------------------------------------------------------------------
vgui::MenuBar *CBaseToolSystem::CreateMenuBar(CBaseToolSystem *pParent )
{
return new vgui::MenuBar( pParent, "ToolMenuBar" );
}
//-----------------------------------------------------------------------------
// Purpose: Derived classes implement this to create a custom status bar, or return NULL for no status bar
//-----------------------------------------------------------------------------
vgui::Panel *CBaseToolSystem::CreateStatusBar( vgui::Panel *pParent )
{
return new CBaseStatusBar( this, "Status Bar" );
}
//-----------------------------------------------------------------------------
// Gets at the action menu
//-----------------------------------------------------------------------------
vgui::Menu *CBaseToolSystem::GetActionMenu()
{
return m_hActionMenu;
}
//-----------------------------------------------------------------------------
// Returns the client area
//-----------------------------------------------------------------------------
vgui::Panel* CBaseToolSystem::GetClientArea()
{
return m_pToolUI->GetClientArea();
}
//-----------------------------------------------------------------------------
// Pops up the action menu
//-----------------------------------------------------------------------------
void CBaseToolSystem::OnMousePressed( vgui::MouseCode code )
{
if ( code == MOUSE_RIGHT )
{
InitActionMenu();
}
else
{
BaseClass::OnMousePressed( code );
}
}
//-----------------------------------------------------------------------------
// Creates the action menu
//-----------------------------------------------------------------------------
void CBaseToolSystem::InitActionMenu()
{
ShutdownActionMenu();
// Let the tool system create the action menu
m_hActionMenu = CreateActionMenu( this );
if ( m_hActionMenu.Get() )
{
m_hActionMenu->SetVisible(true);
PositionActionMenu();
m_hActionMenu->RequestFocus();
}
}
//-----------------------------------------------------------------------------
// Destroy action menu
//-----------------------------------------------------------------------------
void CBaseToolSystem::ShutdownActionMenu()
{
if ( m_hActionMenu.Get() )
{
m_hActionMenu->MarkForDeletion();
m_hActionMenu = NULL;
}
}
void CBaseToolSystem::UpdateMenu( vgui::Menu *menu )
{
// Nothing
}
//-----------------------------------------------------------------------------
// Positions the action menu when it's time to pop it up
//-----------------------------------------------------------------------------
void CBaseToolSystem::PositionActionMenu()
{
// get cursor position, this is local to this text edit window
int cursorX, cursorY;
input()->GetCursorPos(cursorX, cursorY);
// relayout the menu immediately so that we know it's size
m_hActionMenu->InvalidateLayout(true);
// Get the menu size
int menuWide, menuTall;
m_hActionMenu->GetSize( menuWide, menuTall );
// work out where the cursor is and therefore the best place to put the menu
int wide, tall;
GetSize( wide, tall );
if (wide - menuWide > cursorX)
{
// menu hanging right
if (tall - menuTall > cursorY)
{
// menu hanging down
m_hActionMenu->SetPos(cursorX, cursorY);
}
else
{
// menu hanging up
m_hActionMenu->SetPos(cursorX, cursorY - menuTall);
}
}
else
{
// menu hanging left
if (tall - menuTall > cursorY)
{
// menu hanging down
m_hActionMenu->SetPos(cursorX - menuWide, cursorY);
}
else