From 8527da554180099c8a32d00915ff23e07cb43e05 Mon Sep 17 00:00:00 2001 From: Ghom <42542238+Ghommie@users.noreply.github.com> Date: Sun, 6 Mar 2022 02:52:46 +0100 Subject: [PATCH] Fixes the inputs for the linear and exponential sustain options of the song editor. (#65008) --- code/modules/instruments/songs/_song.dm | 2 +- code/modules/instruments/songs/editor.dm | 4 ++-- code/modules/tgui/tgui_input_number.dm | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/code/modules/instruments/songs/_song.dm b/code/modules/instruments/songs/_song.dm index 35408eaa35d..9ce10835c3e 100644 --- a/code/modules/instruments/songs/_song.dm +++ b/code/modules/instruments/songs/_song.dm @@ -370,7 +370,7 @@ * Setter for setting linear falloff duration. */ /datum/song/proc/set_linear_falloff_duration(duration) - sustain_linear_duration = clamp(round(duration * 10, world.tick_lag), 0.1, INSTRUMENT_MAX_TOTAL_SUSTAIN) + sustain_linear_duration = clamp(round(duration * 10, world.tick_lag), world.tick_lag, INSTRUMENT_MAX_TOTAL_SUSTAIN) update_sustain() updateDialog() diff --git a/code/modules/instruments/songs/editor.dm b/code/modules/instruments/songs/editor.dm index 7dd8074344c..2e16eed4df5 100644 --- a/code/modules/instruments/songs/editor.dm +++ b/code/modules/instruments/songs/editor.dm @@ -185,12 +185,12 @@ stop_playing() else if(href_list["setlinearfalloff"]) - var/amount = tgui_input_number(usr, "Set linear sustain duration in seconds", "Linear Sustain Duration", 0.1, INSTRUMENT_MAX_TOTAL_SUSTAIN, 0.1) + var/amount = tgui_input_number(usr, "Set linear sustain duration in seconds", "Linear Sustain Duration", 0.1, INSTRUMENT_MAX_TOTAL_SUSTAIN, 0.1, round_value = FALSE) if(!isnull(amount)) set_linear_falloff_duration(amount) else if(href_list["setexpfalloff"]) - var/amount = tgui_input_number(usr, "Set exponential sustain factor", "Exponential sustain factor", INSTRUMENT_EXP_FALLOFF_MIN, INSTRUMENT_EXP_FALLOFF_MAX, INSTRUMENT_EXP_FALLOFF_MIN) + var/amount = tgui_input_number(usr, "Set exponential sustain factor", "Exponential sustain factor", INSTRUMENT_EXP_FALLOFF_MIN, INSTRUMENT_EXP_FALLOFF_MAX, INSTRUMENT_EXP_FALLOFF_MIN, round_value = FALSE) if(!isnull(amount)) set_exponential_drop_rate(amount) diff --git a/code/modules/tgui/tgui_input_number.dm b/code/modules/tgui/tgui_input_number.dm index 7fccf26cfaf..9bf1981d2fc 100644 --- a/code/modules/tgui/tgui_input_number.dm +++ b/code/modules/tgui/tgui_input_number.dm @@ -13,8 +13,9 @@ * * max_value - Specifies a maximum value. If none is set, any number can be entered. Pressing "max" defaults to 1000. * * min_value - Specifies a minimum value. Often 0. * * timeout - The timeout of the number input, after which the modal will close and qdel itself. Set to zero for no timeout. + * * round_value - whether the inputted number is rounded down into an integer. */ -/proc/tgui_input_number(mob/user, message, title = "Number Input", default = 0, max_value = 10000, min_value = 0, timeout = 0) +/proc/tgui_input_number(mob/user, message, title = "Number Input", default = 0, max_value = 10000, min_value = 0, timeout = 0, round_value = TRUE) if (!user) user = usr if (!istype(user)) @@ -25,8 +26,9 @@ return // Client does NOT have tgui_input on: Returns regular input if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input)) - return clamp(round(input(user, message, title, default) as null|num), min_value, max_value) - var/datum/tgui_input_number/number_input = new(user, message, title, default, max_value, min_value, timeout) + var/input_number = input(user, message, title, default) as null|num + return clamp(round_value ? round(input_number) : input_number, min_value, max_value) + var/datum/tgui_input_number/number_input = new(user, message, title, default, max_value, min_value, timeout, round_value) number_input.ui_interact(user) number_input.wait() if (number_input) @@ -47,8 +49,9 @@ * * min_value - Specifies a minimum value. Often 0. * * callback - The callback to be invoked when a choice is made. * * timeout - The timeout of the number input, after which the modal will close and qdel itself. Set to zero for no timeout. + * * round_value - whether the inputted number is rounded down into an integer. */ -/proc/tgui_input_number_async(mob/user, message, title = "Number Input", default = 0, max_value = 10000, min_value = 0, datum/callback/callback, timeout = 60 SECONDS) +/proc/tgui_input_number_async(mob/user, message, title = "Number Input", default = 0, max_value = 10000, min_value = 0, datum/callback/callback, timeout = 60 SECONDS, round_value = TRUE) if (!user) user = usr if (!istype(user)) @@ -59,8 +62,9 @@ return // Client does NOT have tgui_input on: Returns regular input if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input)) - return clamp(round(input(user, message, title, default) as null|num), min_value, max_value) - var/datum/tgui_input_number/async/number_input = new(user, message, title, default, max_value, min_value, callback, timeout) + var/input_number = input(user, message, title, default) as null|num + return clamp(round_value ? round(input_number) : input_number, min_value, max_value) + var/datum/tgui_input_number/async/number_input = new(user, message, title, default, max_value, min_value, callback, timeout, round_value) number_input.ui_interact(user) /** @@ -88,14 +92,17 @@ var/timeout /// The title of the TGUI window var/title + /// Whether the submitted number is rounded down into an integer. + var/round_value -/datum/tgui_input_number/New(mob/user, message, title, default, max_value, min_value, timeout) +/datum/tgui_input_number/New(mob/user, message, title, default, max_value, min_value, timeout, round_value) src.default = default src.max_value = max_value src.message = message src.min_value = min_value src.title = title + src.round_value = round_value if (timeout) src.timeout = timeout start_time = world.time @@ -159,7 +166,7 @@ if("submit") if(!isnum(params["entry"])) CRASH("A non number was input into tgui input number by [usr]") - var/choice = round(params["entry"]) + var/choice = round_value ? round(params["entry"]) : params["entry"] if(choice > max_value) CRASH("A number greater than the max value was input into tgui input number by [usr]") if(choice < min_value)