]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/crosshairbutton.c
Merge branch 'master' into terencehill/vehicles_fixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / crosshairbutton.c
index 7ed683d01e11c1b8107f38ed9e36841e3be70dae..7fe3a600f2e57d49338a1f7b3ac358fa9f09590e 100644 (file)
@@ -33,11 +33,15 @@ void XonoticCrosshairButton_configureXonoticCrosshairButton(entity me, float the
        me.loadCvars(me);
        me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0);
        me.srcMulti = 1;
-       me.src3 = strzone(strcat("/gfx/crosshair", ftos(me.cvarValueFloat)));
+       if(me.cvarValueFloat == -1)
+               me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
+       else
+               me.src3 = strzone(strcat("/gfx/crosshair", ftos(me.cvarValueFloat)));
        me.src4 = "/gfx/crosshairdot";
 }
 void XonoticCrosshairButton_setChecked(entity me, float val)
 {
+       if(me.cvarValueFloat != -1) // preview shouldn't work as a button
        if(val != me.checked)
        {
                me.checked = val;
@@ -46,14 +50,14 @@ void XonoticCrosshairButton_setChecked(entity me, float val)
 }
 void XonoticCrosshairButton_loadCvars(entity me)
 {
-       if not(me.cvarName)
+       if (!me.cvarName)
                return;
 
        me.checked = (cvar(me.cvarName) == me.cvarValueFloat);
 }
 void XonoticCrosshairButton_saveCvars(entity me)
 {
-       if not(me.cvarName)
+       if (!me.cvarName)
                return;
 
        if(me.checked)
@@ -65,27 +69,60 @@ void XonoticCrosshairButton_draw(entity me)
        vector sz, rgb;
        float a;
 
-       rgb = stov(cvar_string("crosshair_color"));
-       a = cvar("crosshair_alpha");
 
-       if(!me.checked && !me.focused)
+       if(me.cvarValueFloat == -1)
        {
-               a *= me.disabledAlpha;
+               rgb = stov(cvar_string("crosshair_color"));
+               a = cvar("crosshair_alpha");
+       }
+       else if(me.checked || me.focused)
+       {
+               a = 1;
+               rgb = '1 1 1';
+       }
+       else
+       {
+               a = me.disabledAlpha;
                rgb = '1 1 1';
        }
 
+       if(me.cvarValueFloat == -1) // update the preview if this is the preview button
+       {
+               if(me.src3)
+                       strunzone(me.src3);
+               me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
+               me.focused = 1;
+               me.checked = 0;
+       }
+
        SUPER(XonoticCrosshairButton).draw(me);
 
        sz = draw_PictureSize(me.src3);
-       sz = globalToBoxSize(sz, draw_scale);
-       sz = (10 * '1 1 0' + sz * cvar("crosshair_size")) * 0.05; // (10 * '1 1 0' + ...) * 0.05 here to make visible size changes happen also at bigger sizes
-       if(sz_x > 0.95)
+       sz = globalToBoxSize(sz, me.size);
+       if(me.cvarValueFloat == -1)
+       {
+               sz = sz * cvar("crosshair_size"); // (6 * '1 1 0' + ...) * 0.08 here to make visible size changes happen also at bigger sizes
+               /*
+               if(sz_x > 0.95)
+                       sz = sz * (0.95 / sz_x);
+               if(sz_y > 0.95)
+                       sz = sz * (0.95 / sz_y);
+               */
+       }
+       else // show the crosshair picker at full size
+       {
                sz = sz * (0.95 / sz_x);
-       if(sz_y > 0.95)
-               sz = sz * (0.95 / sz_y);
+               if(sz_y > 0.95)
+                       sz = sz * (0.95 / sz_y);
+       }
 
        draw_Picture('0.5 0.5 0' - 0.5 * sz, me.src3, sz, rgb, a);
        if(cvar("crosshair_dot"))
+       {
+               if(cvar("crosshair_dot_color_custom") && (cvar_string("crosshair_dot_color") != "0"))
+                       rgb = stov(cvar_string("crosshair_dot_color"));
+
                draw_Picture('0.5 0.5 0' - 0.5 * sz * cvar("crosshair_dot_size"), me.src4, sz * cvar("crosshair_dot_size"), rgb, a * cvar("crosshair_dot_alpha"));
+       }
 }
 #endif