]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/menu.qc
Merge remote-tracking branch 'origin/master' into tzork/gm_nexball
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / menu.qc
index 36973c96f82d899c6bf906effdf8cb65e1a939c9..b541a7f0639f973e1063ba0c90f3af994973c21d 100644 (file)
@@ -16,12 +16,41 @@ float menuInitialized;
 float menuNotTheFirstFrame;
 float menuMouseMode;
 
-void SUB_Null() { };
+void SUB_Null() { }
 
-void() m_init =
+void m_sync()
 {
+       updateCompression();
+       updateConwidths();
+
+       loadAllCvars(main);
+}
+
+void m_gamestatus()
+{
+       gamestatus = 0;
+       if(isserver())
+               gamestatus = gamestatus | GAME_ISSERVER;
+       if(clientstate() == CS_CONNECTED || isdemo())
+               gamestatus = gamestatus | GAME_CONNECTED;
+       if(cvar("developer"))
+               gamestatus = gamestatus | GAME_DEVELOPER;
+}
+
+void m_init()
+{
+       float restarting = 0;
        cvar_set("_menu_alpha", "0");
-       prvm_language = strzone(cvar_string("prvm_language"));
+       prvm_language = cvar_string("prvm_language");
+       if(prvm_language == "")
+       {
+               prvm_language = "en";
+               cvar_set("prvm_language", prvm_language);
+               localcmd("\nmenu_restart\n");
+               restarting = 1;
+       }
+       prvm_language = strzone(prvm_language);
+       cvar_set("_menu_prvm_language", prvm_language);
 
        check_unacceptable_compiler_bugs();
 
@@ -42,6 +71,26 @@ void() m_init =
                        dprint(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION));
                }
        }
+
+       // needs to be done so early because of the constants they create
+       RegisterWeapons();
+       RegisterGametypes();
+
+       float ddsload = cvar("r_texture_dds_load");
+       float texcomp = cvar("gl_texturecompression");
+       updateCompression();
+       if(ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression"))
+               localcmd("\nr_restart\n");
+       initConwidths();
+
+       if(!restarting)
+       {
+               if(cvar("_menu_initialized")) // always show menu after menu_restart
+                       m_display();
+               else
+                       m_hide();
+               cvar_set("_menu_initialized", "1");
+       }
 }
 
 float MENU_ASPECT = 1.25; // 1280x1024
@@ -95,7 +144,8 @@ void UpdateConWidthHeight()
        }
 }
 
-void() m_init_delayed =
+string m_goto_buffer;
+void m_init_delayed()
 {
        float fh, glob, n, i;
        string s;
@@ -108,9 +158,6 @@ void() m_init_delayed =
        if(!preMenuInit())
                return;
        menuInitialized = 1;
-       GameCommand_Init();
-
-       RegisterWeapons();
 
        fh = -1;
        if(cvar_string("menu_skin") != "")
@@ -169,11 +216,20 @@ void() m_init_delayed =
        menuShiftState = 0;
        menuMousePos = '0.5 0.5 0';
 
+       m_sync();
+
+       if(m_goto_buffer)
+       {
+               m_goto(m_goto_buffer);
+               strunzone(m_goto_buffer);
+               m_goto_buffer = string_null;
+       }
+
        if(Menu_Active)
                m_display(); // delayed menu display
-};
+}
 
-void(float key, float ascii) m_keyup =
+void m_keyup (float key, float ascii)
 {
        if(!menuInitialized)
                return;
@@ -195,9 +251,9 @@ void(float key, float ascii) m_keyup =
        if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
        if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
        if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
-};
+}
 
-void(float key, float ascii) m_keydown =
+void m_keydown(float key, float ascii)
 {
        if(!menuInitialized)
                return;
@@ -233,7 +289,7 @@ void(float key, float ascii) m_keydown =
        if(key == K_ALT) menuShiftState |= S_ALT;
        if(key == K_CTRL) menuShiftState |= S_CTRL;
        if(key == K_SHIFT) menuShiftState |= S_SHIFT;
-};
+}
 
 float SCALEMODE_CROP = 0;
 float SCALEMODE_LETTERBOX = 1;
@@ -274,7 +330,7 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
        draw_Picture(org, img, isz, '1 1 1', a);
 }
 
-void(string img, float a, string algn, float force1) drawBackground =
+void drawBackground(string img, float a, string algn, float force1)
 {
        if(main.mainNexposee.ModalController_state == 0)
                return;
@@ -600,11 +656,15 @@ void m_tooltip(vector pos)
        }
 }
 
-void() m_draw =
+void m_draw()
 {
        float t;
        float realFrametime;
 
+       m_gamestatus();
+
+       execute_next_frame();
+
        menuMouseMode = cvar("menu_mouse_absolute");
 
        if (anim)
@@ -657,14 +717,6 @@ void() m_draw =
        if(cvar("cl_capturevideo"))
                frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
 
-       gamestatus = 0;
-       if(isserver())
-               gamestatus = gamestatus | GAME_ISSERVER;
-       if(clientstate() == CS_CONNECTED)
-               gamestatus = gamestatus | GAME_CONNECTED;
-       if(cvar("developer"))
-               gamestatus = gamestatus | GAME_DEVELOPER;
-
        prevMenuAlpha = menuAlpha;
        if(Menu_Active)
        {
@@ -777,9 +829,9 @@ void() m_draw =
        postMenuDraw();
 
        frametime = 0;
-};
+}
 
-void() m_display =
+void m_display()
 {
        Menu_Active = true;
        setkeydest(KEY_MENU);
@@ -794,9 +846,9 @@ void() m_display =
 
        main.focusEnter(main);
        main.showNotify(main);
-};
+}
 
-void() m_hide =
+void m_hide()
 {
        Menu_Active = false;
        setkeydest(KEY_GAME);
@@ -807,17 +859,25 @@ void() m_hide =
 
        main.focusLeave(main);
        main.hideNotify(main);
-};
+}
 
-void() m_toggle =
+void m_toggle(float mode)
 {
        if(Menu_Active)
+       {
+               if (mode == 1)
+                       return;
                m_hide();
+       }
        else
+       {
+               if (mode == 0)
+                       return;
                m_display();
-};
+       }
+}
 
-void() m_shutdown =
+void Shutdown()
 {
        entity e;
 
@@ -828,7 +888,7 @@ void() m_shutdown =
                        if(e.destroy)
                                e.destroy(e);
        }
-};
+}
 
 void m_focus_item_chain(entity outermost, entity innermost)
 {
@@ -884,15 +944,22 @@ void m_setpointerfocus(entity wnd)
        }
 }
 
-void(string itemname) m_goto =
+void m_goto(string itemname)
 {
        entity e;
        if(!menuInitialized)
+       {
+               if(m_goto_buffer)
+                       strunzone(m_goto_buffer);
+               m_goto_buffer = strzone(itemname);
                return;
+       }
        if(itemname == "") // this can be called by GameCommand
        {
                if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
+               {
                        m_hide();
+               }
                else
                {
                        m_activate_window(main.mainNexposee);
@@ -901,7 +968,7 @@ void(string itemname) m_goto =
        }
        else
        {
-               for(e = NULL; (e = findstring(e, name, itemname)); )
+               for(e = NULL; (e = find(e, name, itemname)); )
                        if(e.classname != "vtbl")
                                break;
                if(e)
@@ -913,27 +980,3 @@ void(string itemname) m_goto =
                }
        }
 }
-
-void() m_goto_skin_selector =
-{
-       if(!menuInitialized)
-               return;
-       // TODO add code to switch back to the skin selector (no idea how to do it now)
-       m_goto("skinselector");
-}
-
-void() m_goto_language_selector =
-{
-       if(!menuInitialized)
-               return;
-       // TODO add code to switch back to the language selector (no idea how to do it now)
-       m_goto("languageselector");
-}
-
-void() m_goto_video_settings =
-{
-       if(!menuInitialized)
-               return;
-       // TODO add code to switch back to the video settings (no idea how to do it now)
-       m_goto("videosettings");
-}