From: terencehill Date: Thu, 10 Dec 2015 14:08:04 +0000 (+0100) Subject: Reduce duplicated code in sliders.qc X-Git-Tag: xonotic-v0.8.2~1213^2~5 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=73dc5baa1ce835664978521da4fe4a816b86031c;p=xonotic%2Fxonotic-data.pk3dir.git Reduce duplicated code in sliders.qc --- diff --git a/qcsrc/menu/item/slider.qc b/qcsrc/menu/item/slider.qc index 073d2eb79..5cbd53b46 100644 --- a/qcsrc/menu/item/slider.qc +++ b/qcsrc/menu/item/slider.qc @@ -118,50 +118,45 @@ float Slider_keyDown(entity me, float key, float ascii, float shift) { float inRange; + float ret_value = 0; if (me.disabled) return 0; inRange = (almost_in_bounds(me.valueMin, me.value, me.valueMax)); if (key == K_LEFTARROW || key == K_KP_LEFTARROW || key == K_MWHEELDOWN) { if (inRange) me.setValue(me, median(me.valueMin, me.value - me.valueKeyStep, me.valueMax)); else me.setValue(me, me.valueMax); - if(me.applyButton) - me.applyButton.disabled = false; - return 1; + ret_value = 1; } if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW || key == K_MWHEELUP) { if (inRange) me.setValue(me, median(me.valueMin, me.value + me.valueKeyStep, me.valueMax)); else me.setValue(me, me.valueMin); - if(me.applyButton) - me.applyButton.disabled = false; - return 1; + ret_value = 1; } if (key == K_PGDN || key == K_KP_PGDN) { if (inRange) me.setValue(me, median(me.valueMin, me.value - me.valuePageStep, me.valueMax)); else me.setValue(me, me.valueMax); - if(me.applyButton) - me.applyButton.disabled = false; - return 1; + ret_value = 1; } if (key == K_PGUP || key == K_KP_PGUP) { if (inRange) me.setValue(me, median(me.valueMin, me.value + me.valuePageStep, me.valueMax)); else me.setValue(me, me.valueMin); - if(me.applyButton) - me.applyButton.disabled = false; - return 1; + ret_value = 1; } if (key == K_HOME || key == K_KP_HOME) { me.setValue(me, me.valueMin); - if(me.applyButton) - me.applyButton.disabled = false; - return 1; + ret_value = 1; } if (key == K_END || key == K_KP_END) { me.setValue(me, me.valueMax); + ret_value = 1; + } + if(ret_value == 1) + { if(me.applyButton) me.applyButton.disabled = false; return 1; @@ -246,21 +241,17 @@ pageValue = me.value - me.valuePageStep; if (me.valueStep) clickValue = floor(clickValue / me.valueStep) * me.valueStep; pageValue = max(pageValue, clickValue); - if (inRange) me.setValue(me, median(me.valueMin, pageValue, me.valueMax)); - else me.setValue(me, me.valueMax); - if(me.applyButton) - me.applyButton.disabled = false; } else { pageValue = me.value + me.valuePageStep; if (me.valueStep) clickValue = ceil(clickValue / me.valueStep) * me.valueStep; pageValue = min(pageValue, clickValue); - if (inRange) me.setValue(me, median(me.valueMin, pageValue, me.valueMax)); - else me.setValue(me, me.valueMax); - if(me.applyButton) - me.applyButton.disabled = false; } + if (inRange) me.setValue(me, median(me.valueMin, pageValue, me.valueMax)); + else me.setValue(me, me.valueMax); + if(me.applyButton) + me.applyButton.disabled = false; if (pageValue == clickValue) { controlCenter = (me.value - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.textSpace - me.controlWidth) + 0.5 * me.controlWidth;