From: drjaska Date: Thu, 11 May 2023 19:59:39 +0000 (+0300) Subject: complete refactor hack abomination X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=477d845800b9bb9b9551b7eaeacc7d285bba7a27;p=xonotic%2Fxonotic-data.pk3dir.git complete refactor hack abomination --- diff --git a/qcsrc/menu/item/slider.qc b/qcsrc/menu/item/slider.qc index b98f59bbb4..ce80fcdde3 100644 --- a/qcsrc/menu/item/slider.qc +++ b/qcsrc/menu/item/slider.qc @@ -18,6 +18,9 @@ me.setSliderValue(me, val); } me.value = val; + + if(me.onChange) + me.onChange(me, me.onChangeEntity); } void Slider_setValue_noAnim(entity me, float val) { diff --git a/qcsrc/menu/item/slider.qh b/qcsrc/menu/item/slider.qh index b70d3880ba..c5f9e292d9 100644 --- a/qcsrc/menu/item/slider.qh +++ b/qcsrc/menu/item/slider.qh @@ -47,4 +47,6 @@ CLASS(Slider, Label) ATTRIB(Slider, colorC, vector, '1 1 1'); ATTRIB(Slider, colorF, vector, '1 1 1'); ATTRIB(Slider, disabledAlpha, float, 0.3); + ATTRIB(Slider, onChange, void(entity, entity)); + ATTRIB(Slider, onChangeEntity, entity); ENDCLASS(Slider) diff --git a/qcsrc/menu/xonotic/dialog_settings_input.qc b/qcsrc/menu/xonotic/dialog_settings_input.qc index 22e164fdda..ac03e625bb 100644 --- a/qcsrc/menu/xonotic/dialog_settings_input.qc +++ b/qcsrc/menu/xonotic/dialog_settings_input.qc @@ -12,6 +12,28 @@ #include "checkbox.qh" #include "inputbox.qh" +void updateSensSlider(entity field, entity slider) +{ + XonoticSlider_setValue(slider, stof(field.text)); +} + +void updateSensField(entity slider, entity field) +{ + if (slider.value) + SUPER(XonoticInputBox).setText(field, ftos_mindecimals(stof((sprintf("%0.4f", slider.value))))); + // don't use that to avoid infinite onChange looping, just steal its content + //XonoticInputBox_setText(field, ftos(slider.value)); +} + +void linkSensitivities(entity slider, entity field) +{ + slider.onChange = updateSensField; + slider.onChangeEntity = field; + + field.onChange = updateSensSlider; + field.onChangeEntity = slider; +} + entity makeXonoticInputSettingsTab() { entity me; @@ -58,9 +80,17 @@ void XonoticInputSettingsTab_fill(entity me) me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Mouse"))); me.TR(me); + entity sensitivitySlider; me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Sensitivity:"))); - me.TD(me, 1, 2, e = makeXonoticInputBox_T(0, "sensitivity", + me.TD(me, 1, 1.5, e = makeXonoticSlider_T(0.1, 9.9, 0.1, "sensitivity", + _("Mouse speed multiplier"))); + sensitivitySlider = e; + e.fontSize = 0; + me.currentColumn -= 0.35; + me.TD(me, 1, 1, e = makeXonoticInputBox_T(0, "sensitivity", _("Mouse speed multiplier"))); + e.saveImmediately = 1; + linkSensitivities(sensitivitySlider, e); me.TR(me); me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "m_filter", _("Smooth aiming"), _("Smoothes the mouse movement, but makes aiming slightly less responsive")));