]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/menu.qc
Merge branch 'master' into terencehill/menu_tooltips_2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / menu.qc
index b8fee02a13263a8b9e24a7b43359c150bc1f9dad..ab940a3656481b1378c1bfffba10ce131c610665 100644 (file)
@@ -21,11 +21,12 @@ void SUB_Null() { };
 void() m_init =
 {
        cvar_set("_menu_alpha", "0");
+       prvm_language = strzone(cvar_string("prvm_language"));
 
        check_unacceptable_compiler_bugs();
 
 #ifdef WATERMARK
-       print("^4MQC Build information: ", WATERMARK(), "\n");
+       print(sprintf(_("^4MQC Build information: %s\n"), WATERMARK()));
 #endif
 
        // list all game dirs (TEST)
@@ -38,7 +39,7 @@ void() m_init =
                        s = getgamedirinfo(i, GETGAMEDIRINFO_NAME);
                        if not(s)
                                break;
-                       print(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION));
+                       dprint(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION));
                }
        }
 }
@@ -115,18 +116,18 @@ void() m_init_delayed =
        if(cvar_string("menu_skin") != "")
        {
                draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
-               fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
+               fh = fopen(language_filename(strcat(draw_currentSkin, "/skinvalues.txt")), FILE_READ);
        }
        if(fh < 0)
        if(cvar_defstring("menu_skin") != "")
        {
                draw_currentSkin = strcat("gfx/menu/", cvar_defstring("menu_skin"));
-               fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
+               fh = fopen(language_filename(strcat(draw_currentSkin, "/skinvalues.txt")), FILE_READ);
        }
        if(fh < 0)
        {
                draw_currentSkin = "gfx/menu/default";
-               fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
+               fh = fopen(language_filename(strcat(draw_currentSkin, "/skinvalues.txt")), FILE_READ);
        }
        draw_currentSkin = strzone(draw_currentSkin);
        while((s = fgets(fh)))
@@ -183,7 +184,7 @@ void(float key, float ascii) m_keyup =
                if(mouseButtonsPressed < 0)
                {
                        mouseButtonsPressed = 0;
-                       print("Warning: released an already released button\n");
+                       dprint("Warning: released an already released button\n");
                }
        }
        if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
@@ -221,7 +222,7 @@ void(float key, float ascii) m_keydown =
                if(mouseButtonsPressed > 10)
                {
                        mouseButtonsPressed = 10;
-                       print("Warning: pressed an already pressed button\n");
+                       dprint("Warning: pressed an already pressed button\n");
                }
        }
        if(key == K_ALT) menuShiftState |= S_ALT;
@@ -241,8 +242,8 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
 
        sz = draw_PictureSize(img);
        width_is_larger = (sz_x * draw_scale_y >= sz_y * draw_scale_x);
-       isz_w = '1 0 0' + '0 1 0' * ((sz_y / sz_x) * (draw_scale_x / draw_scale_y)); 
-       isz_h = '0 1 0' + '1 0 0' * ((sz_x / sz_y) * (draw_scale_y / draw_scale_x)); 
+       isz_w = '1 0 0' + '0 1 0' * ((sz_y / sz_x) * (draw_scale_x / draw_scale_y));
+       isz_h = '0 1 0' + '1 0 0' * ((sz_x / sz_y) * (draw_scale_y / draw_scale_x));
 
        switch(scalemode)
        {
@@ -270,6 +271,9 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
 
 void(string img, float a, string algn, float force1) drawBackground =
 {
+       if(main.mainNexposee.ModalController_state == 0)
+               return;
+
        vector v;
        float i, l;
        string c;
@@ -315,16 +319,19 @@ void(string img, float a, string algn, float force1) drawBackground =
        }
 }
 
+float menu_tooltips;
+float menu_tooltips_old;
 vector menuTooltipAveragedMousePos;
 entity menuTooltipItem;
 vector menuTooltipOrigin;
 vector menuTooltipSize;
 float menuTooltipAlpha;
-float menuTooltipState; // 0: no tooltip, 1: fading in, 2: displaying, 3: fading out
-float m_testmousetooltipbox(vector pos)
+string menuTooltipText;
+float menuTooltipState; // 0: static, 1: fading in, 2: fading out
+float m_testmousetooltipbox()
 {
-       if(pos_x >= menuTooltipOrigin_x && pos_x < menuTooltipOrigin_x + menuTooltipSize_x)
-       if(pos_y >= menuTooltipOrigin_y && pos_y < menuTooltipOrigin_y + menuTooltipSize_y)
+       if(menuMousePos_x >= menuTooltipOrigin_x && menuMousePos_x < menuTooltipOrigin_x + menuTooltipSize_x)
+       if(menuMousePos_y >= menuTooltipOrigin_y && menuMousePos_y < menuTooltipOrigin_y + menuTooltipSize_y)
                return FALSE;
        return TRUE;
 }
@@ -338,11 +345,6 @@ float m_testtooltipbox(vector tooltippos)
                return FALSE;
        if(tooltippos_y + menuTooltipSize_y > 1)
                return FALSE;
-       /*
-       menuTooltipOrigin_x = rint(tooltippos_x * cvar("vid_width")) / cvar("vid_width");
-       menuTooltipOrigin_y = rint(tooltippos_y * cvar("vid_height")) / cvar("vid_height");
-       menuTooltipOrigin_z = 0;
-       */
        menuTooltipOrigin = tooltippos;
        return TRUE;
 }
@@ -411,6 +413,8 @@ entity m_findtooltipitem(entity root, vector pos)
                        it = it.itemFromPoint(it, pos);
                        if(it.tooltip)
                                best = it;
+                       else if(menu_tooltips == 2 && (it.cvarName || it.onClickCommand))
+                               best = it;
                        it = world;
                }
                else if(it.instanceOfModalController)
@@ -421,28 +425,62 @@ entity m_findtooltipitem(entity root, vector pos)
                        break;
                if(it.tooltip)
                        best = it;
+               else if(menu_tooltips == 2 && (it.cvarName || it.onClickCommand))
+                       best = it;
                pos = globalToBox(pos, it.Container_origin, it.Container_size);
        }
 
        return best;
 }
-void m_tooltip(vector pos)
+string gettooltip()
+{
+       if (menu_tooltips == 2)
+       {
+               string s;
+               if (menuTooltipItem.cvarName)
+               {
+                       if (getCvarsMulti(menuTooltipItem))
+                               s = strcat("[", menuTooltipItem.cvarName, " ", getCvarsMulti(menuTooltipItem), "]");
+                       else
+                               s = strcat("[", menuTooltipItem.cvarName, "]");
+               }
+               else if (menuTooltipItem.onClickCommand)
+                       s = strcat("<", menuTooltipItem.onClickCommand, ">");
+               else
+                       return menuTooltipItem.tooltip;
+               if (menuTooltipItem.tooltip)
+                       return strcat(menuTooltipItem.tooltip, " ", s);
+               return s;
+       }
+       return menuTooltipItem.tooltip;
+}
+void m_tooltip()
 {
        float f, i, w;
        entity it;
        vector fontsize, p;
        string s;
 
-       fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
-
-       f = bound(0, frametime * 2, 1);
-       menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
-       f = vlen(pos - menuTooltipAveragedMousePos);
-
-       if(f < 0.01)
-               it = m_findtooltipitem(main, pos);
-       else    
+       menu_tooltips = cvar("menu_tooltips");
+       if (!menu_tooltips)
+       {
+               // don't return immediately, fade out the active tooltip first
+               if (menuTooltipItem == world)
+                       return;
                it = world;
+               menu_tooltips_old = menu_tooltips;
+       }
+       else
+       {
+               f = bound(0, frametime * 2, 1);
+               menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + menuMousePos * f;
+               f = vlen(menuMousePos - menuTooltipAveragedMousePos);
+               if(f < 0.01)
+                       it = m_findtooltipitem(main, menuMousePos);
+               else
+                       it = world;
+       }
+       fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
 
        // float menuTooltipState; // 0: static, 1: fading in, 2: fading out
        if(it != menuTooltipItem)
@@ -462,9 +500,11 @@ void m_tooltip(vector pos)
                                        menuTooltipItem = it;
 
                                        menuTooltipOrigin_x = -1; // unallocated
+
+                                       menuTooltipText = strzone(gettooltip());
                                        i = 0;
-                                       w =  0;
-                                       getWrappedLine_remaining = it.tooltip;
+                                       w = 0;
+                                       getWrappedLine_remaining = menuTooltipText;
                                        while(getWrappedLine_remaining)
                                        {
                                                s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
@@ -491,7 +531,7 @@ void m_tooltip(vector pos)
                menuTooltipState = 1;
 
        if(menuTooltipItem)
-               if(!m_testmousetooltipbox(pos))
+               if(!m_testmousetooltipbox())
                        menuTooltipState = 2; // fade out if mouse touches it
 
        switch(menuTooltipState)
@@ -513,8 +553,14 @@ void m_tooltip(vector pos)
 
        if(menuTooltipItem)
        {
-               if(menuTooltipOrigin_x < 0) // unallocated?
-                       m_allocatetooltipbox(pos);
+               if(menu_tooltips != menu_tooltips_old)
+               {
+                       if (menu_tooltips != 0 && menu_tooltips_old != 0)
+                               menuTooltipItem = world; // reload tooltip next frame
+                       menu_tooltips_old = menu_tooltips;
+               }
+               else if(menuTooltipOrigin_x < 0) // unallocated?
+                       m_allocatetooltipbox(menuMousePos);
 
                if(menuTooltipOrigin_x >= 0)
                {
@@ -526,7 +572,7 @@ void m_tooltip(vector pos)
                        p = menuTooltipOrigin;
                        p_x += SKINMARGIN_TOOLTIP_x / conwidth;
                        p_y += SKINMARGIN_TOOLTIP_y / conheight;
-                       getWrappedLine_remaining = menuTooltipItem.tooltip;
+                       getWrappedLine_remaining = menuTooltipText;
                        while(getWrappedLine_remaining)
                        {
                                s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
@@ -563,7 +609,7 @@ void() m_draw =
                if(!cvar("menu_video_played"))
                {
                        localcmd("set menu_video_played 1; cd loop $menu_cdtrack; play sound/announcer/default/welcome.ogg\n");
-                       menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
+                       menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME
                }
        }
 
@@ -702,7 +748,7 @@ void() m_draw =
        }
        main.draw(main);
 
-       m_tooltip(menuMousePos);
+       m_tooltip();
 
        draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
 
@@ -759,8 +805,9 @@ void() m_shutdown =
        m_hide();
        for(e = NULL; (e = nextent(e)) != NULL; )
        {
-               if(e.destroy)
-                       e.destroy(e);
+               if(e.classname != "vtbl")
+                       if(e.destroy)
+                               e.destroy(e);
        }
 };
 
@@ -792,7 +839,7 @@ void m_activate_window(entity wnd)
                // nexposee (sorry for violating abstraction here)
                par.selectedChild = wnd;
                par.animationState = 1;
-               setFocusContainer(par, NULL);
+               Container_setFocus(par, NULL);
        }
        else if(par.instanceOfContainer)
        {
@@ -835,7 +882,9 @@ void(string itemname) m_goto =
        }
        else
        {
-               e = findstring(NULL, name, itemname);
+               for(e = NULL; (e = findstring(e, name, itemname)); )
+                       if(e.classname != "vtbl")
+                               break;
                if(e)
                {
                        m_hide();
@@ -854,10 +903,18 @@ void() m_goto_skin_selector =
        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 skin selector (no idea how to do it now)
+       // TODO add code to switch back to the video settings (no idea how to do it now)
        m_goto("videosettings");
 }