From 4e2bbcf4239d9a5480678488122f2d1b2c7fc610 Mon Sep 17 00:00:00 2001 From: "Dr. Jaska" Date: Wed, 6 Nov 2024 13:08:55 +0000 Subject: [PATCH] Settings: Mouse sensitivity: added a text input box next to the slider --- qcsrc/menu/item/inputbox.qc | 3 ++ qcsrc/menu/item/inputbox.qh | 1 + qcsrc/menu/item/slider.qc | 5 ++- qcsrc/menu/xonotic/dialog_settings_input.qc | 45 ++++++++++++++++++++- qcsrc/menu/xonotic/slider.qc | 6 +++ qcsrc/menu/xonotic/slider.qh | 2 + xonotic-client.cfg | 2 +- 7 files changed, 61 insertions(+), 3 deletions(-) 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 -- 2.39.2