From: Dr. Jaska Date: Wed, 6 Nov 2024 13:08:55 +0000 (+0000) Subject: Settings: Mouse sensitivity: added a text input box next to the slider X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4e2bbcf4239d9a5480678488122f2d1b2c7fc610;p=xonotic%2Fxonotic-data.pk3dir.git Settings: Mouse sensitivity: added a text input box next to the slider --- diff --git a/qcsrc/menu/item/inputbox.qc b/qcsrc/menu/item/inputbox.qc index 30c325ca4..0d77e67b4 100644 --- a/qcsrc/menu/item/inputbox.qc +++ b/qcsrc/menu/item/inputbox.qc @@ -110,7 +110,10 @@ { int len = strlen(ch); for (int i = 0; i < len; ++i) + { if (strstrofs(me.forbiddenCharacters, substring(ch, i, 1), 0) > -1) return; + if (strstrofs(me.allowedCharacters, substring(ch, i, 1), 0) == -1) return; + } if (me.maxLength > 0) { if (len + strlen(me.text) > me.maxLength) return; diff --git a/qcsrc/menu/item/inputbox.qh b/qcsrc/menu/item/inputbox.qh index 5b0c28f9e..f6b178eba 100644 --- a/qcsrc/menu/item/inputbox.qh +++ b/qcsrc/menu/item/inputbox.qh @@ -28,6 +28,7 @@ CLASS(InputBox, Label) ATTRIB(InputBox, pressed, float, 0); ATTRIB(InputBox, editColorCodes, float, 1); ATTRIB(InputBox, forbiddenCharacters, string, ""); + ATTRIB(InputBox, allowedCharacters, string, ""); ATTRIB(InputBox, color, vector, '1 1 1'); ATTRIB(InputBox, colorF, vector, '1 1 1'); ATTRIB(InputBox, maxLength, float, 255); // if negative, it counts bytes, not chars diff --git a/qcsrc/menu/item/slider.qc b/qcsrc/menu/item/slider.qc index b98f59bbb..30f27f9fb 100644 --- a/qcsrc/menu/item/slider.qc +++ b/qcsrc/menu/item/slider.qc @@ -263,6 +263,9 @@ if (me.valueMax > me.valueMin) // valid? me.setText(me, me.valueToText(me, me.value)); draw_alpha = save; - SUPER(Slider).draw(me); + if (me.textSpace > 0) + { + SUPER(Slider).draw(me); + } me.text = string_null; // TEMPSTRING! } diff --git a/qcsrc/menu/xonotic/dialog_settings_input.qc b/qcsrc/menu/xonotic/dialog_settings_input.qc index b025c3aff..659e41533 100644 --- a/qcsrc/menu/xonotic/dialog_settings_input.qc +++ b/qcsrc/menu/xonotic/dialog_settings_input.qc @@ -10,6 +10,41 @@ #include "button.qh" #include "slider.qh" #include "checkbox.qh" +#include "inputbox.qh" + +void updateSensSlider(entity field, entity slider) +{ + if (slider == NULL) + return; + + // Avoid onChange causing jittering + slider.onChangeEntity = NULL; + slider.setValue(slider, stof(field.text)); + slider.onChangeEntity = field; +} + +void updateSensField(entity slider, entity field) +{ + if (field == NULL) + return; + + if (slider.value) + { + // Avoid onChange causing jittering + field.onChangeEntity = NULL; + field.setText(field, ftos_mindecimals(slider.value)); + field.onChangeEntity = slider; + } +} + +void linkSensitivities(entity slider, entity field) +{ + slider.onChange = updateSensField; + slider.onChangeEntity = field; + + field.onChange = updateSensSlider; + field.onChangeEntity = slider; +} entity makeXonoticInputSettingsTab() { @@ -57,9 +92,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 = makeXonoticSlider_T(1, 32, 0.2, "sensitivity", + me.TD(me, 1, 1, e = makeXonoticSlider_T(0.1, 9.9, 0.1, "sensitivity", + _("Mouse speed multiplier"))); + sensitivitySlider = e; + e.textSpace = 0; + me.TD(me, 1, 1, e = makeXonoticInputBox_T(0, "sensitivity", _("Mouse speed multiplier"))); + e.saveImmediately = 1; + e.allowedCharacters = "0.123456789"; + 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"))); diff --git a/qcsrc/menu/xonotic/slider.qc b/qcsrc/menu/xonotic/slider.qc index d0a1cfb75..ac14723b0 100644 --- a/qcsrc/menu/xonotic/slider.qc +++ b/qcsrc/menu/xonotic/slider.qc @@ -36,6 +36,9 @@ void XonoticSlider_setValue(entity me, float val) { SUPER(XonoticSlider).setValue( me, val ); me.saveCvars(me); + + if(me.onChange) + me.onChange(me, me.onChangeEntity); } } void XonoticSlider_setValue_noAnim(entity me, float val) @@ -44,6 +47,9 @@ void XonoticSlider_setValue_noAnim(entity me, float val) { SUPER(XonoticSlider).setValue_noAnim(me, val); me.saveCvars(me); + + if(me.onChange) + me.onChange(me, me.onChangeEntity); } } void XonoticSlider_loadCvars(entity me) diff --git a/qcsrc/menu/xonotic/slider.qh b/qcsrc/menu/xonotic/slider.qh index de66fb95e..aeb51aa0c 100644 --- a/qcsrc/menu/xonotic/slider.qh +++ b/qcsrc/menu/xonotic/slider.qh @@ -5,6 +5,8 @@ CLASS(XonoticSlider, Slider) METHOD(XonoticSlider, configureXonoticSlider, void(entity, float, float, float, string, string)); METHOD(XonoticSlider, setValue, void(entity, float)); METHOD(XonoticSlider, setValue_noAnim, void(entity, float)); + ATTRIB(XonoticSlider, onChange, void(entity, entity)); + ATTRIB(XonoticSlider, onChangeEntity, entity); ATTRIB(XonoticSlider, fontSize, float, SKINFONTSIZE_NORMAL); ATTRIB(XonoticSlider, valueSpace, float, SKINWIDTH_SLIDERTEXT); ATTRIB(XonoticSlider, image, string, SKINGFX_SLIDER); diff --git a/xonotic-client.cfg b/xonotic-client.cfg index d3009cd34..332c4b741 100644 --- a/xonotic-client.cfg +++ b/xonotic-client.cfg @@ -77,7 +77,7 @@ seta cl_spawn_point_particles 1 "pointparticles effect at all spawn points" // m seta cl_spawn_point_dist_max 1200 "maximum distance from which spawnpoint particles will be visible" freelook 1 -sensitivity 3 +sensitivity 3.0 v_gamma 1 viewsize 100 bgmvolume 0.75