From: Severin Meyer Date: Fri, 23 Jan 2015 18:05:11 +0000 (+0100) Subject: Revise focus sound, use a time guard to prevent "Geiger counter" effect X-Git-Tag: xonotic-v0.8.1~147^2~12 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6fece5bf19016b023b84f0dcd738e19b27b037a1;p=xonotic%2Fxonotic-data.pk3dir.git Revise focus sound, use a time guard to prevent "Geiger counter" effect --- diff --git a/qcsrc/menu/item.c b/qcsrc/menu/item.c index d055b1a05..d0bd40b03 100644 --- a/qcsrc/menu/item.c +++ b/qcsrc/menu/item.c @@ -17,6 +17,7 @@ CLASS(Item) EXTENDS(Object) METHOD(Item, destroy, void(entity)) ATTRIB(Item, focused, float, 0) ATTRIB(Item, focusable, float, 0) + ATTRIB(Item, allowFocusSound, float, 0) ATTRIB(Item, parent, entity, NULL) ATTRIB(Item, preferredFocusPriority, float, 0) ATTRIB(Item, origin, vector, '0 0 0') @@ -121,6 +122,8 @@ float Item_mouseRelease(entity me, vector pos) void Item_focusEnter(entity me) { + if(me.allowFocusSound) + m_play_focus_sound(); } void Item_focusLeave(entity me) diff --git a/qcsrc/menu/item/button.c b/qcsrc/menu/item/button.c index 8bbdfa704..3af4d4787 100644 --- a/qcsrc/menu/item/button.c +++ b/qcsrc/menu/item/button.c @@ -8,7 +8,6 @@ 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), func_null) ATTRIB(Button, onClickEntity, entity, NULL) ATTRIB(Button, src, string, string_null) @@ -18,6 +17,7 @@ CLASS(Button) EXTENDS(Label) ATTRIB(Button, srcMulti, float, 1) // 0: button square left, text right; 1: button stretched, text over it ATTRIB(Button, buttonLeftOfText, float, 0) ATTRIB(Button, focusable, float, 1) + ATTRIB(Button, allowFocusSound, float, 1) ATTRIB(Button, pressed, float, 0) ATTRIB(Button, clickTime, float, 0) ATTRIB(Button, disabled, float, 0) @@ -92,12 +92,6 @@ void Button_showNotify(entity me) { me.focusable = !me.disabled; } -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; diff --git a/qcsrc/menu/item/inputbox.c b/qcsrc/menu/item/inputbox.c index 1c1bf5189..e4ad0ef27 100644 --- a/qcsrc/menu/item/inputbox.c +++ b/qcsrc/menu/item/inputbox.c @@ -18,6 +18,7 @@ CLASS(InputBox) EXTENDS(Label) ATTRIB(InputBox, scrollPos, float, 0) // widths ATTRIB(InputBox, focusable, float, 1) + ATTRIB(InputBox, allowFocusSound, float, 1) ATTRIB(InputBox, disabled, float, 0) ATTRIB(InputBox, lastChangeTime, float, 0) ATTRIB(InputBox, dragScrollTimer, float, 0) diff --git a/qcsrc/menu/item/listbox.c b/qcsrc/menu/item/listbox.c index 275b99735..3466b134b 100644 --- a/qcsrc/menu/item/listbox.c +++ b/qcsrc/menu/item/listbox.c @@ -9,6 +9,7 @@ CLASS(ListBox) EXTENDS(Item) METHOD(ListBox, mouseRelease, float(entity, vector)) METHOD(ListBox, focusLeave, void(entity)) ATTRIB(ListBox, focusable, float, 1) + ATTRIB(ListBox, allowFocusSound, float, 1) ATTRIB(ListBox, selectedItem, float, 0) ATTRIB(ListBox, size, vector, '0 0 0') ATTRIB(ListBox, origin, vector, '0 0 0') diff --git a/qcsrc/menu/item/slider.c b/qcsrc/menu/item/slider.c index c92db27e9..1f7c287c7 100644 --- a/qcsrc/menu/item/slider.c +++ b/qcsrc/menu/item/slider.c @@ -10,7 +10,6 @@ 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)) @@ -18,6 +17,7 @@ CLASS(Slider) EXTENDS(Label) METHOD(Slider, showNotify, void(entity)) ATTRIB(Slider, src, string, string_null) ATTRIB(Slider, focusable, float, 1) + ATTRIB(Slider, allowFocusSound, float, 1) ATTRIB(Slider, value, float, 0) ATTRIB(Slider, animated, float, 1) ATTRIB(Slider, sliderValue, float, 0) @@ -250,12 +250,6 @@ 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; diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index aa771649d..0a93992ef 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -1001,3 +1001,14 @@ void m_goto(string itemname) } } } + +float menuLastFocusSoundTime; +void m_play_focus_sound() +{ + if(cvar("menu_sounds") > 1) + if(time - menuLastFocusSoundTime > 0.25) + { + localsound("sound/menu/focus.wav"); + menuLastFocusSoundTime = time; + } +} diff --git a/qcsrc/menu/menu.qh b/qcsrc/menu/menu.qh index b6c0795a8..17c4291fa 100644 --- a/qcsrc/menu/menu.qh +++ b/qcsrc/menu/menu.qh @@ -38,3 +38,7 @@ void preMenuDraw(); // this is run before the menu is drawn. You may put some st void postMenuDraw(); // this is run just after the menu is drawn (or not). Useful to draw something over everything else. void m_sync(); + +// sounds + +void m_play_focus_sound(); diff --git a/qcsrc/menu/xonotic/serverlist.c b/qcsrc/menu/xonotic/serverlist.c index c78cba0e0..fdbe9c3dd 100644 --- a/qcsrc/menu/xonotic/serverlist.c +++ b/qcsrc/menu/xonotic/serverlist.c @@ -561,6 +561,7 @@ void XonoticServerList_refreshServerList(entity me, float mode) } void XonoticServerList_focusEnter(entity me) { + SUPER(XonoticServerList).focusEnter(me); if(time < me.nextRefreshTime) { //print("sorry, no refresh yet\n");