4 // debug process output functions
5 bool _menu_process_filtered;
6 void( float pMode, float pSelectState ) _Menu_Process_Debug_Filter =
8 if( !sys_debug_process )
9 _menu_process_filtered = false;
10 else if( sys_debug_process_filter )
11 _menu_process_filtered = (pMode & sys_debug_process_filter);
13 _menu_process_filtered = true;
14 if( _menu_process_filtered == MENU_PROCESS_MOUSE && pSelectState == MENU_SELECT_NEVER )
15 _menu_process_filtered = false;
19 void( string pText ) _Menu_Process_Debug_Print =
21 if( _menu_process_filtered )
25 #define _Menu_Process_Debug_Print(pText) if( _menu_process_filtered ) print( pText )
30 void() Menu_Process_Setup =
32 Menu_Origin = '0 0 0';
33 Menu_Clip_Position = '0 0 0';
34 Menu_Clip_Size = '0 0 0';
37 void( entity pItem ) _Menu_Env_LoadClipArea
39 Menu_Clip_Position = pItem._cache_clip_pos;
40 Menu_Clip_Size = pItem._cache_clip_size;
42 if( sys_debug_mgfx && _menu_process_filtered )
43 print( "MGFX Loaded clip area = (", vtos( Menu_Clip_Position ), "; ", vtos( Menu_Clip_Size ), ")\n" );
46 void( entity pItem ) _Menu_Env_LoadOrigin =
48 Menu_Origin = pItem._cache_origin;
49 Menu_Cursor_Position = Cursor_Position - Menu_Origin;
51 if( sys_debug_mgfx && _menu_process_filtered )
52 print( "MGFX Loaded org = ", vtos( Menu_Origin ), "\n" );
55 void( entity pItem ) _Menu_Env_Reload =
57 Menu_Origin = pItem._cache_origin;
58 Menu_Cursor_Position = Cursor_Position - Menu_Origin;
59 Menu_Clip_Position = pItem._cache_clip_pos;
60 Menu_Clip_Size = pItem._cache_clip_size;
62 if( sys_debug_mgfx && _menu_process_filtered )
63 print( "MGFX Reloaded env for: org = ", vtos( Menu_Origin ), "; clip area = (", vtos( Menu_Clip_Position ), "; ", vtos( Menu_Clip_Size ), ")\n" );
66 void() _MGX_SetClipArea =
68 if( Menu_Clip_Position == '0 0 0' && Menu_Clip_Size == '0 0 0' )
71 Gfx_SetClipArea( Menu_Clip_Position_x, Menu_Clip_Position_y, Menu_Clip_Size_x, Menu_Clip_Size_y );
74 void( entity pItem ) _Menu_Env_SetupClipArea
76 local vector lDelta, lPos, lSize;
80 if( lPos != '0 0 0' || lSize != '0 0 0' ) {
81 if( (Menu_Clip_Position != '0 0 0' || Menu_Clip_Size != '0 0 0') ) {
82 lPos = Menu_Origin + lPos;
83 lDelta = Util_GetClipDelta( lPos, Menu_Clip_Position, Menu_Clip_Size );
85 lSize = Util_ClipRect( lPos, lSize - lDelta, Menu_Clip_Position, Menu_Clip_Size );
88 Menu_Clip_Position = lPos;
89 Menu_Clip_Size = lSize;
91 pItem._cache_clip_pos = Menu_Clip_Position;
92 pItem._cache_clip_size = Menu_Clip_Size;
94 if( sys_debug_mgfx && _menu_process_filtered ) {
95 print( "MGFX Setup clip area: (", vtos( pItem.pos ), "; ", vtos( pItem.size ) );
96 print( ") clipped to (", vtos( Menu_Clip_Position ), "; ", vtos( Menu_Clip_Size ), ")\n" );
100 void( entity pItem ) _Menu_Env_SetupOrigin =
102 Menu_Origin = Menu_Origin + pItem.origin + pItem.pos;
103 pItem._cache_origin = Menu_Origin;
105 if( sys_debug_mgfx && _menu_process_filtered )
106 print( "MGFX Setup org = ", vtos( Menu_Origin ), "\n" );
109 void( entity pItem ) _Menu_ProcessRunFlag =
112 local bool lWasHidden;
113 local float lOldRunFlag;
115 _Menu_Process_Debug_Print( strcat( "R ", pItem.name, "\n" ) );
117 // setup the cache and the Menu_* variables
118 _Menu_Env_SetupClipArea( pItem );
120 lWasHidden = Menu_HasRunFlag( pItem, RUNFLAG_HIDDEN );
122 lOldRunFlag = pItem._runFlag;
123 Menu_SetRunFlag( pItem );
125 // AK LATE: This should speed up things a bit
126 if( /*lOldRunFlag == pItem._runFlag &&*/ lWasHidden && Menu_HasRunFlag( pItem, RUNFLAG_HIDDEN ) ) {
127 _Menu_Process_Debug_Print( "Aborted branching (RUNFLAG_HIDDEN)\n" );
131 // we adjust the origin for the children
132 _Menu_Env_SetupOrigin( pItem );
134 for( lChild = pItem._child ; lChild ; lChild = lChild._next ) {
135 Menu_InheritRunFlag( pItem, lChild );
136 _Menu_ProcessRunFlag( lChild );
137 // reload the cached state
138 _Menu_Env_Reload( pItem );
142 void( entity pItem ) _Menu_ProcessDraw =
146 _Menu_Process_Debug_Print( strcat( "D ", pItem.name, " " ) );
148 if( !Menu_IsVisible( pItem ) ) {
149 _Menu_Process_Debug_Print( "Failed (Not visible)\n" );
152 _Menu_Process_Debug_Print( "\n" );
154 _Menu_Env_LoadClipArea( pItem );
159 _Menu_Env_LoadOrigin( pItem );
160 for( lChild = pItem._child ; lChild ; lChild = lChild._next ) {
161 _Menu_ProcessDraw( lChild );
163 _Menu_Env_Reload( pItem );
168 void( entity pItem ) _Menu_ProcessUpdate =
172 _Menu_Process_Debug_Print( strcat( "U ", pItem.name, " " ) );
174 if( Menu_HasRunFlag( pItem, RUNFLAG_CHILDDRAWONLY ) ) {
175 _Menu_Process_Debug_Print( "Failed (RUNFLAG_CHILDDRAWONLY)\n" );
179 _Menu_Env_LoadClipArea( pItem );
180 Raise_Update( pItem );
182 if( Menu_HasRunFlag( pItem, RUNFLAG_HIDDEN ) ) {
183 _Menu_Process_Debug_Print( "Aborted branching (RUNFLAG_HIDDEN)\n" );
186 _Menu_Process_Debug_Print( "\n" );
188 _Menu_Env_LoadOrigin( pItem );
189 for( lChild = pItem._child ; lChild ; lChild = lChild._next ) {
190 _Menu_ProcessUpdate( lChild );
191 _Menu_Env_Reload( lChild );
195 void( entity pItem, float pSelectMode ) _Menu_ProcessMouse =
199 if( _menu_process_filtered ) {
201 switch( pSelectMode ) {
202 case MENU_SELECT_SELECTABLE:
205 case MENU_SELECT_ALWAYS:
208 case MENU_SELECT_NEVER:
212 print( pItem.name, " " );
215 if( !Menu_IsVisible( pItem ) ) {
216 _Menu_Process_Debug_Print( "Failed (Not visible)\n" );
220 _Menu_Env_LoadClipArea( pItem );
221 // check if the mouse is even in the clip area
222 if( Util_InRect( Cursor_Position, Menu_Clip_Position, Menu_Clip_Size ) ||
223 ( Menu_Clip_Position == '0 0 0' && Menu_Clip_Size == '0 0 0' ) ) {
224 pItem._runFlag = pItem._runFlag | RUNFLAG_MOUSEINAREA;
226 if( !Menu_HasRunFlag( pItem, RUNFLAG_HADMOUSE ) && Menu_HasEvents( pItem ) )
227 Raise_MouseEnter( pItem );
228 if( pSelectMode != MENU_SELECT_NEVER && Menu_HasFlag( pItem, FLAG_SEALOFFMOUSE ) )
229 Menu_ActiveItem = null_entity;
230 if( ( pSelectMode == MENU_SELECT_ALWAYS ) ||
231 ( Menu_IsSelectable( pItem ) && pSelectMode == MENU_SELECT_SELECTABLE ) )
232 Menu_ActiveItem = pItem;
233 } else { // if the mouse isnt in the clip area, neither the children will be!
234 if( Menu_HasRunFlag( pItem, RUNFLAG_HADMOUSE ) && Menu_HasEvents( pItem ) )
235 Raise_MouseLeave( pItem );
236 _Menu_Process_Debug_Print( "Aborted branching (Outside the clip area)\n" );
239 _Menu_Process_Debug_Print( "\n" );
241 _Menu_Env_LoadOrigin( pItem );
242 for( lChild = pItem._child ; lChild ; lChild = lChild._next ) {
243 if( !Menu_HasRunFlag( pItem, RUNFLAG_CHILDDRAWUPDATEONLY ) || !Menu_HasRunFlag( pItem, RUNFLAG_CHILDDRAWONLY ) )
244 _Menu_ProcessMouse( lChild, pSelectMode );
246 _Menu_ProcessMouse( lChild, MENU_SELECT_NEVER );
247 _Menu_Env_Reload( pItem );
251 float( float pRetValue ) _Menu_Process_Debug_Return =
253 if( _menu_process_filtered )
254 switch( pRetValue ) {
255 case MENU_EVENT_NORMAL:
256 case MENU_EVENT_CONTINUE:
257 print( "MENU_EVENT_CONTINUE\n" );
259 case MENU_EVENT_RAISEPARENT:
260 print( "MENU_EVENT_RAISEPARENT\n" );
262 case MENU_EVENT_PROCESSED:
263 print( "MENU_EVENT_PROCESSED\n" );
270 float( entity pItem, float pKey, float pAscii ) _Menu_ProcessKey =
275 _Menu_Process_Debug_Print( strcat( "K ", ftos( pKey ), " ", pItem.name, " " ) );
276 if( Menu_HasRunFlag( pItem, RUNFLAG_CHILDDRAWUPDATEONLY ) || Menu_HasRunFlag( pItem, RUNFLAG_CHILDDRAWONLY ) )
277 return _Menu_Process_Debug_Return( MENU_EVENT_CONTINUE );
279 _Menu_Env_LoadClipArea( pItem );
281 if( Menu_ActiveItem == pItem ) {
282 if( Raise_Key( pItem, pKey, pAscii ) )
283 lResult = MENU_EVENT_PROCESSED;
285 lResult = MENU_EVENT_RAISEPARENT;
287 return _Menu_Process_Debug_Return( lResult );
290 _Menu_Env_LoadOrigin( pItem );
291 for( lChild = pItem._child ; lChild ; lChild = lChild._next ) {
292 lResult = _Menu_ProcessKey( lChild, pKey, pAscii );
293 _Menu_Env_Reload( pItem );
295 if( lResult == MENU_EVENT_PROCESSED )
296 return _Menu_Process_Debug_Return( MENU_EVENT_PROCESSED );
297 else if( lResult == MENU_EVENT_RAISEPARENT )
298 if( Raise_Key( pItem, pKey, pAscii ) )
299 return _Menu_Process_Debug_Return( MENU_EVENT_PROCESSED );
301 return _Menu_Process_Debug_Return( MENU_EVENT_RAISEPARENT );
304 return _Menu_Process_Debug_Return( MENU_EVENT_CONTINUE );
307 float( entity pItem, float pMode, float pSelectMode, float pKey, float pAscii ) Menu_Process =
309 local vector lSize, lPos, lOrigin;
312 lSize = Menu_Clip_Size;
313 lPos = Menu_Clip_Position;
314 lOrigin = Menu_Origin;
316 _Menu_Process_Debug_Filter( pMode, pSelectMode );
320 case MENU_PROCESS_RUNFLAG:
321 _Menu_ProcessRunFlag( pItem );
323 case MENU_PROCESS_UPDATE:
324 _Menu_ProcessUpdate( pItem );
326 case MENU_PROCESS_DRAW:
327 _Menu_ProcessDraw( pItem );
329 case MENU_PROCESS_MOUSE:
330 _Menu_ProcessMouse( pItem, pSelectMode );
332 case MENU_PROCESS_KEY:
333 lResult = _Menu_ProcessKey( pItem, pKey, pAscii );
337 Menu_Clip_Size = lSize;
338 Menu_Clip_Position = lPos;
339 Menu_Origin = lOrigin;
340 Menu_Cursor_Position = Cursor_Position - Menu_Origin;
341 if( pMode == MENU_PROCESS_DRAW )
350 if( sys_debug_halt ) {
354 Menu_UpdateRunFlags();
356 Menu_Process_Setup();
357 // if mouse was moved, select an item
358 if( Cursor_Relative != '0 0 0' ) {
361 lOld = Menu_ActiveItem;
362 Menu_ProcessMouse( Menu_ActiveWindow, MENU_SELECT_SELECTABLE );
364 if( !Menu_ActiveItem )
365 Menu_ActiveItem = lOld;
366 else if( lOld != Menu_ActiveItem ) {
367 Raise_Select( lOld, false, true );
368 Raise_Select( Menu_ActiveItem, true, true );
370 } else // just update mouseinarea
371 Menu_ProcessMouse( Menu_ActiveWindow, MENU_SELECT_NEVER );
373 // process the update event
374 Menu_Process_Setup();
375 Menu_ProcessUpdate( Menu_ActiveWindow, MENU_PROCESS_UPDATE );
378 Menu_CollectGarbage( false );
380 if(cvar_string("scmenu_campaign_goto") != "") { // debug code for the campaign
382 level = cvar("scmenu_campaign_goto");
383 cvar_set( "scmenu_campaign_goto", "" );
384 Campaign_JumpLevel(level);
385 } else if(cvar_string("scmenu_campaign_dump") != "") {
386 cvar_set( "scmenu_campaign_dump", "" );
387 Campaign_DumpLevels();
393 if( sys_debug_halt ) {
396 // if Menu_ActiveWindow is visible loop though it
397 if( Menu_IsVisible( Menu_ActiveWindow ) )
399 Menu_Process_Setup();
400 Menu_ProcessDraw( Menu_ActiveWindow );
406 void( float pKey, float pAscii) Menu_Key =
408 if( sys_debug_halt ) {
412 // is a keyhook set ?
413 if( Menu_KeyHook != Util_NullFunction ) {
415 Menu_KeyHook( pKey, pAscii );
418 // before calling the current keydown functions, process the mouse again
419 // to make sure the correct item is called
420 // (except mouse wheel up and down)
421 // if the mouse doesnt point to an item, there wont be a reaction on the clicking
422 if(K_MOUSE1 <= pKey && pKey <= K_MOUSE10) {
425 lOld = Menu_ActiveItem;
426 Menu_ActiveItem = null_entity;
427 Menu_ProcessMouse( Menu_ActiveWindow, MENU_SELECT_SELECTABLE );
429 if( !Menu_ActiveItem ) {
430 Menu_ActiveItem = lOld;
432 } else if( lOld != Menu_ActiveItem ) {
433 Raise_Select( lOld, false, true );
434 Raise_Select( Menu_ActiveItem, true, true );
438 // call current selected keydown function
439 // if nothing is selected -> window has no items -> call window key
440 if(Menu_ActiveItem == null_entity)
441 Menu_Reselect( false );
443 if( ( !Menu_IsSelectable( Menu_ActiveItem ) && Menu_ActiveItem != Menu_ActiveWindow ) ||
444 Menu_ProcessKey( Menu_ActiveWindow, pKey, pAscii ) != MENU_EVENT_PROCESSED )
445 // If it goes really wrong:
446 if( pKey == K_ESCAPE )
447 if( gamestatus & GAME_DEVELOPER )
448 error( " K_ESCAPE wasnt processed!\n" );
451 cmd( "menu_restart\n" );
453 else if( gamestatus & GAME_DEVELOPER ) {
454 print( " Key ", ftos( pKey ), " ('" );
455 print( chr( pAscii ), "') wasn't processed!\n" );
461 // only let the qc toggle the menu if we are ingame or a developer
462 if( gamestatus & GAME_CONNECTED || gamestatus & GAME_DEVELOPER ) {
463 // then allow toggling