]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
menu sounds improvements:
authorterencehill <piuntn@gmail.com>
Thu, 17 Feb 2011 21:27:59 +0000 (22:27 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 17 Feb 2011 21:27:59 +0000 (22:27 +0100)
- play menu2 sound on mouse release rather than on mouse press, it makes more sense (particularly for sliders)
- play menu1 sound in focusEnter rather in draw, with very simple (and less expensive) code; the behaviour is the same
- play menu1 sound in focusEnter for sliders too, it's more coherent this way

qcsrc/menu/item/button.c
qcsrc/menu/item/slider.c

index 871685f53797cfa38e11603e1297a15c3eb96a62..527672d254f41acb6795a336f05da00d3ffb7e45 100644 (file)
@@ -8,6 +8,7 @@ CLASS(Button) EXTENDS(Label)
        METHOD(Button, mousePress, float(entity, vector))
        METHOD(Button, mouseDrag, float(entity, vector))
        METHOD(Button, mouseRelease, float(entity, vector))
+       METHOD(Button, focusEnter, void(entity))
        ATTRIB(Button, onClick, void(entity, entity), SUB_Null)
        ATTRIB(Button, onClickEntity, entity, NULL)
        ATTRIB(Button, src, string, string_null)
@@ -69,12 +70,12 @@ float Button_mouseDrag(entity me, vector pos)
 float Button_mousePress(entity me, vector pos)
 {
        me.mouseDrag(me, pos); // verify coordinates
-       if(cvar("menu_sounds"))
-               localsound("sound/misc/menu2.wav");
        return 1;
 }
 float Button_mouseRelease(entity me, vector pos)
 {
+       if(cvar("menu_sounds"))
+               localsound("sound/misc/menu2.wav");
        me.mouseDrag(me, pos); // verify coordinates
        if(me.pressed)
        {
@@ -88,7 +89,12 @@ void Button_showNotify(entity me)
 {
        me.focusable = !me.disabled;
 }
-.float playedfocus;
+void Button_focusEnter(entity me)
+{
+       if(cvar("menu_sounds") > 1)
+               localsound("sound/misc/menu1.wav");
+       SUPER(Button).focusEnter(me);
+}
 void Button_draw(entity me)
 {
        vector bOrigin, bSize;
@@ -159,14 +165,5 @@ void Button_draw(entity me)
                        me.onClick(me, me.onClickEntity);
        }
        me.clickTime -= frametime;
-
-       if(cvar("menu_sounds") > 1)
-               if(me.focused && !me.playedfocus)
-               {
-                       localsound("sound/misc/menu1.wav");
-                       me.playedfocus = 1;
-               }
-               else if(!me.focused && me.playedfocus)
-                       me.playedfocus = 0;
 }
 #endif
index 9a8a35fdcbc699d03ba12742342bb45f0e7fe0f4..927e07f67423b67f77a470b46621bdb81e05da20 100644 (file)
@@ -10,6 +10,7 @@ CLASS(Slider) EXTENDS(Label)
        METHOD(Slider, mousePress, float(entity, vector))
        METHOD(Slider, mouseDrag, float(entity, vector))
        METHOD(Slider, mouseRelease, float(entity, vector))
+       METHOD(Slider, focusEnter, void(entity))
        METHOD(Slider, valueToText, string(entity, float))
        METHOD(Slider, toString, string(entity))
        METHOD(Slider, setValue, void(entity, float))
@@ -235,12 +236,12 @@ float Slider_mousePress(entity me, vector pos)
                        //me.mouseDrag(me, pos);
                }
        }
-       if(cvar("menu_sounds"))
-               localsound("sound/misc/menu2.wav");
        return 1;
 }
 float Slider_mouseRelease(entity me, vector pos)
 {
+       if(cvar("menu_sounds"))
+               localsound("sound/misc/menu2.wav");
        me.pressed = 0;
        if(me.disabled)
                return 0;
@@ -250,6 +251,12 @@ void Slider_showNotify(entity me)
 {
        me.focusable = !me.disabled;
 }
+void Slider_focusEnter(entity me)
+{
+       if(cvar("menu_sounds") > 1)
+               localsound("sound/misc/menu1.wav");
+       SUPER(Slider).focusEnter(me);
+}
 void Slider_draw(entity me)
 {
        float controlLeft;