/* ================= UI_PopMenu ================= */ void UI_PopMenu( void ) { UI_StartSound( uiSoundOut ); uiStatic.menuDepth--; if( uiStatic.menuDepth < 0 ) HOST_ERROR( "UI_PopMenu: menu stack underflow\n" ); UI_PopPButtonStack(); if( uiStatic.menuDepth ) { uiStatic.menuActive = uiStatic.menuStack[uiStatic.menuDepth-1]; uiStatic.firstDraw = true; } else if ( CL_IsActive( )) { UI_CloseMenu(); } else { // never trying the close menu when client isn't connected KEY_SetDest( KEY_MENU ); UI_Main_Menu(); } if( uiStatic.m_fDemosPlayed && uiStatic.m_iOldMenuDepth == uiStatic.menuDepth ) { CLIENT_COMMAND( FALSE, "demos\n" ); uiStatic.m_fDemosPlayed = false; uiStatic.m_iOldMenuDepth = 0; } }
/* ================= UI_UpdateMenu ================= */ void UI_UpdateMenu( float flTime ) { if( !uiStatic.initialized ) return; UI_DrawFinalCredits (); if( !uiStatic.visible ) return; if( !uiStatic.menuActive ) return; uiStatic.realTime = flTime * 1000; uiStatic.framecount++; if( CVAR_GET_FLOAT( "sv_background" ) && !g_engfuncs.pfnClientInGame()) return; // don't draw menu while level is loading if( uiStatic.firstDraw ) { // we loading background so skip SCR_Update if( UI_StartBackGroundMap( )) return; if( uiStatic.menuActive->activateFunc ) uiStatic.menuActive->activateFunc(); } // draw menu if( uiStatic.menuActive->drawFunc ) uiStatic.menuActive->drawFunc(); else UI_DrawMenu( uiStatic.menuActive ); if( uiStatic.firstDraw ) { uiStatic.firstDraw = false; static int first = TRUE; if( first ) { BACKGROUND_TRACK( "gamestartup.mp3", "gamestartup.mp3" ); first = FALSE; } } //CR UI_DrawTitleAnim(); // // draw cursor UI_DrawMouseCursor(); // delay playing the enter sound until after the menu has been // drawn, to avoid delay while caching images if( uiStatic.enterSound > 0.0f && uiStatic.enterSound <= gpGlobals->time ) { UI_StartSound( uiSoundIn ); uiStatic.enterSound = -1; } }
/* ================= UI_PopMenu ================= */ void UI_PopMenu( void ) { UI_StartSound( uiSoundOut ); uiStatic.menuDepth--; if( uiStatic.menuDepth < 0 ) HOST_ERROR( "UI_PopMenu: menu stack underflow\n" ); UI_PopPButtonStack(); if( uiStatic.menuDepth ) { uiStatic.menuActive = uiStatic.menuStack[uiStatic.menuDepth-1]; uiStatic.firstDraw = true; } else if ( CL_IsActive( )) { UI_CloseMenu(); } else { // never trying the close menu when client isn't connected KEY_SetDest( KEY_MENU ); UI_Main_Menu(); } }
/* ================= UI_PushMenu ================= */ void UI_PushMenu( menuframework_s *menu ) { int i; menucommon_s* item; // avoid stacking menus invoked by hotkeys for (i=0 ; i<uis.menusp ; i++) { if (uis.stack[i] == menu) { uis.menusp = i; break; } } if (i == uis.menusp) { if (uis.menusp >= MAX_MENUDEPTH) trap_Error("UI_PushMenu: menu stack overflow"); uis.stack[uis.menusp++] = menu; } uis.activemenu = menu; // default cursor position menu->cursor = 0; menu->cursor_prev = 0; // pushmenu pushmenu has more priority than popmenu soundTime = 0; UI_StartSound( menu_in_sound ); soundTime = uis.realtime + 150; trap_Key_SetCatcher( KEYCATCH_UI ); // force first available item to have focus for (i=0; i<menu->nitems; i++) { item = (menucommon_s *)menu->items[i]; if (!(item->flags & (QMF_GRAYED|QMF_MOUSEONLY|QMF_INACTIVE))) { menu->cursor_prev = -1; Menu_SetCursor( menu, i ); break; } } uis.firstdraw = qtrue; }
/* ================= UI_PopMenu ================= */ void UI_PopMenu (void) { // popmenu sound has some priority, but pushmenu has more priority UI_StartSound( menu_out_sound ); soundTime = uis.realtime + 150; uis.menusp--; if (uis.menusp < 0) trap_Error ("UI_PopMenu: menu stack underflow"); if (uis.menusp) { uis.activemenu = uis.stack[uis.menusp-1]; uis.firstdraw = qtrue; } else { UI_ForceMenuOff (); } }
/* ================= UI_KeyEvent ================= */ void UI_KeyEvent( int key, int down ) { const char *sound; if( !uiStatic.initialized ) return; if( !uiStatic.visible ) return; if( !uiStatic.menuActive ) return; if( uiStatic.menuActive->keyFunc ) sound = uiStatic.menuActive->keyFunc( key, down ); else sound = UI_DefaultKey( uiStatic.menuActive, key, down ); if( !down ) return; if( sound && sound != uiSoundNull ) UI_StartSound( sound ); }
/* ================= UI_Controls_KeyFunc ================= */ static const char *UI_Controls_KeyFunc( int key, int down ) { char cmd[128]; if( uiControls.msgBox1.generic.flags & QMF_HIDDEN ) { if( down && key == K_ESCAPE && uiControls.defaults.generic.flags & QMF_INACTIVE ) { UI_ResetToDefaultsDialog(); return uiSoundNull; } } if( down ) { if( uiControls.bind_grab ) // assume we are in grab-mode { // defining a key if( key == '`' || key == '~' ) { return uiSoundBuzz; } else if( key != K_ESCAPE ) { const char *bindName = uiControls.keysBind[uiControls.keysList.curItem]; sprintf( cmd, "bind \"%s\" \"%s\"\n", KEY_KeynumToString( key ), bindName ); CLIENT_COMMAND( TRUE, cmd ); } uiControls.bind_grab = false; UI_Controls_RestartMenu(); return uiSoundLaunch; } if( key == K_ENTER && uiControls.dlgMessage.generic.flags & QMF_HIDDEN ) { if( !strlen( uiControls.keysBind[uiControls.keysList.curItem] )) { // probably it's a seperator return uiSoundBuzz; } // entering to grab-mode const char *bindName = uiControls.keysBind[uiControls.keysList.curItem]; int keys[2]; UI_Controls_GetKeyBindings( bindName, keys ); if( keys[1] != -1 ) UI_UnbindCommand( bindName ); uiControls.bind_grab = true; UI_PromptDialog(); // show prompt return uiSoundKey; } if(( key == K_BACKSPACE || key == K_DEL ) && uiControls.dlgMessage.generic.flags & QMF_HIDDEN ) { // delete bindings if( !strlen( uiControls.keysBind[uiControls.keysList.curItem] )) { // probably it's a seperator return uiSoundNull; } const char *bindName = uiControls.keysBind[uiControls.keysList.curItem]; UI_UnbindCommand( bindName ); UI_StartSound( uiSoundRemoveKey ); UI_Controls_RestartMenu(); return uiSoundNull; } } return UI_DefaultKey( &uiControls.menu, key, down ); }
/* ================= UI_MouseMove ================= */ void UI_MouseMove( int x, int y ) { int i; menuCommon_s *item; if( !uiStatic.initialized ) return; if( !uiStatic.visible ) return; if( !uiStatic.menuActive ) return; // now menu uses absolute coordinates uiStatic.cursorX = x; uiStatic.cursorY = y; if( UI_CursorInRect( 1, 1, ScreenWidth - 1, ScreenHeight - 1 )) uiStatic.mouseInRect = true; else uiStatic.mouseInRect = false; uiStatic.cursorX = bound( 0, uiStatic.cursorX, ScreenWidth ); uiStatic.cursorY = bound( 0, uiStatic.cursorY, ScreenHeight ); // region test the active menu items for( i = 0; i < uiStatic.menuActive->numItems; i++ ) { item = (menuCommon_s *)uiStatic.menuActive->items[i]; if( item->flags & (QMF_GRAYED|QMF_INACTIVE|QMF_HIDDEN)) { if( item->flags & QMF_HASMOUSEFOCUS ) { if( !UI_CursorInRect( item->x, item->y, item->width, item->height )) item->flags &= ~QMF_HASMOUSEFOCUS; else item->lastFocusTime = uiStatic.realTime; } continue; } if( !UI_CursorInRect( item->x, item->y, item->width, item->height )) { item->bPressed = false; continue; } // set focus to item at cursor if( uiStatic.menuActive->cursor != i ) { UI_SetCursor( uiStatic.menuActive, i ); ((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursorPrev]))->flags &= ~QMF_HASMOUSEFOCUS; if (!(((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags & QMF_SILENT )) UI_StartSound( uiSoundMove ); } ((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags |= QMF_HASMOUSEFOCUS; ((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->lastFocusTime = uiStatic.realTime; return; } // out of any region if( uiStatic.menuActive->numItems ) { ((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags &= ~QMF_HASMOUSEFOCUS; ((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->bPressed = false; // a mouse only item restores focus to the previous item if(((menuCommon_s *)(uiStatic.menuActive->items[uiStatic.menuActive->cursor]))->flags & QMF_MOUSEONLY ) { if( uiStatic.menuActive->cursorPrev != -1 ) uiStatic.menuActive->cursor = uiStatic.menuActive->cursorPrev; } } }