Another bunch of fixes for TGUI inputs (I'll be cursed...) (#25009)

* Oh god, oh fuck, WHY DIDN'T I USE isnull()???

* More correct checks

* That's all

* That's all x2

* Flavor fix
This commit is contained in:
Aylong
2024-04-12 18:51:36 +00:00
committed by GitHub
parent bc4cd8bceb
commit 6fe23a6a20
28 changed files with 87 additions and 88 deletions
+4 -4
View File
@@ -546,16 +546,16 @@ GLOBAL_LIST_INIT(view_runtimes_verbs, list(
explosion(epicenter, 3, 5, 7, 5)
if("Custom Bomb")
var/devastation_range = tgui_input_number(src, "Devastation range (in tiles):", "Custom Bomb", max_value = 255)
if(devastation_range == null)
if(isnull(devastation_range))
return
var/heavy_impact_range = tgui_input_number(src, "Heavy impact range (in tiles):", "Custom Bomb", max_value = 255)
if(heavy_impact_range == null)
if(isnull(heavy_impact_range))
return
var/light_impact_range = tgui_input_number(src, "Light impact range (in tiles):", "Custom Bomb", max_value = 255)
if(light_impact_range == null)
if(isnull(light_impact_range))
return
var/flash_range = tgui_input_number(src, "Flash range (in tiles):", "Custom Bomb", max_value = 255)
if(flash_range == null)
if(isnull(flash_range))
return
explosion(epicenter, devastation_range, heavy_impact_range, light_impact_range, flash_range, 1, 1)
log_admin("[key_name(usr)] created an admin explosion at [epicenter.loc]")
@@ -921,10 +921,8 @@
if(!(varname in list("min1", "min2", "max1", "max2"))) // uh oh
message_admins("[key_name_admin(usr)] attempted to href edit vars on [src]!!!")
return
var/datum/tlv/tlv = TLV[env]
var/newval = tgui_input_number(usr, "Enter [varname] for [env]", "Alarm triggers", tlv.vars[varname], round_value = FALSE)
if(isnull(newval) || ..()) // No setting if you walked away
return
if(newval < 0)
@@ -1118,7 +1118,7 @@
if("screentip_mode")
var/desired_screentip_mode = tgui_input_number(user, "Pick a screentip size, pick 0 to disable screentips. (We suggest a number between 8 and 15):", "Screentip Size", screentip_mode, 20, 0)
if(!desired_screentip_mode)
if(isnull(desired_screentip_mode))
return
screentip_mode = desired_screentip_mode
@@ -96,7 +96,7 @@
var/attempt_code = tgui_input_number(user, "Re-enter the current EFTPOS access code:", "Confirm old EFTPOS code", max_value = 9999, min_value = 1000)
if(attempt_code == access_code)
var/trycode = tgui_input_number(user, "Enter a new access code for this device:", "Enter new EFTPOS code", max_value = 9999, min_value = 1000)
if(!trycode)
if(isnull(trycode))
return
access_code = trycode
print_reference()
@@ -122,7 +122,7 @@
transaction_purpose = purpose
if("trans_value")
var/try_num = tgui_input_number(user, "Enter amount for EFTPOS transaction", "Transaction amount", transaction_amount, MAX_EFTPOS_CHARGE)
if(!check_user_position(user) || !try_num)
if(!check_user_position(user) || isnull(try_num))
return
transaction_amount = try_num
if("toggle_lock")
@@ -474,7 +474,7 @@
icon_state = "pizzabox_bomb"
timer_set = TRUE
var/new_timer = tgui_input_number(user, "Set a timer, from one second to ten seconds.", "Timer", timer / 10, 10, 1)
if(!new_timer)
if(isnull(new_timer))
return
if(!in_range(src, user) || issilicon(user) || HAS_TRAIT(user, TRAIT_HANDS_BLOCKED) || user.restrained())
timer_set = FALSE
+2 -2
View File
@@ -191,8 +191,8 @@
for(var/mob/living/player in viewers(3))
if(!player.incapacitated())
players += player
var/dcard = tgui_input_number(usr, "How many card(s) do you wish to deal? You may deal up to [length(cards)] cards.", "Deal Cards", max_value = length(cards))
if(!dcard)
var/dcard = tgui_input_number(usr, "How many card(s) do you wish to deal? You may deal up to [length(cards)] cards.", "Deal Cards", 1, length(cards), 1)
if(isnull(dcard))
return
var/mob/living/M = tgui_input_list(usr, "Who do you wish to deal [dcard] card(s)?", "Deal Card", players)
if(!usr || !src || !M || !Adjacent(usr))
+5 -5
View File
@@ -214,7 +214,7 @@
switch(choice)
if("Title")
var/newtitle = reject_bad_text(tgui_input_text(user, "Write a new title:", "Title", title))
if(!newtitle)
if(isnull(newtitle))
to_chat(user, "<span class='notice'>You change your mind.</span>")
return
//Like with paper, the name (not title) of the book should indicate that THIS IS A BOOK when actions are performed with it
@@ -223,13 +223,13 @@
title = newtitle
if("Author")
var/newauthor = tgui_input_text(user, "Write the author's name:", "Author", author, MAX_NAME_LEN)
if(!newauthor)
if(isnull(newauthor))
to_chat(user, "<span class='notice'>You change your mind.</span>")
return
author = newauthor
if("Summary")
var/newsummary = tgui_input_text(user, "Write the new summary:", "Summary", summary, MAX_SUMMARY_LEN, multiline = TRUE)
if(!newsummary)
if(isnull(newsummary))
to_chat(user, "<span class='notice'>You change your mind.</span>")
return
summary = newsummary
@@ -245,7 +245,7 @@
to_chat(user, "<span class='notice'>There's not enough space left on this page to write anything!</span>")
return
var/content = tgui_input_text(user, "Add Text to this page, you have [character_space_remaining] characters of space left:", "Edit Current Page", max_length = MAX_CHARACTERS_PER_BOOKPAGE, multiline = TRUE)
if(!content)
if(isnull(content))
to_chat(user, "<span class='notice'>You change your mind.</span>")
return
//check if length of current text content + what player is adding is larger than our character limit
@@ -268,7 +268,7 @@
to_chat(user, "<span class='notice'>There aren't any pages in this book!</span>")
return
var/page_choice = tgui_input_number(user, "There are [length(pages)] pages, which page number would you like to remove?", "Input Page Number", max_value = length(pages))
if(!page_choice)
if(isnull(page_choice))
to_chat(user, "<span class='notice'>You change your mind.</span>")
return
if(page_choice <= 0 || page_choice > length(pages))
@@ -288,6 +288,7 @@
so quickly that it generally doesn't matter. You're remarkably resilient to any damage besides this and it's hard for you to really die at all. You should go around and bring happiness and \
free cake to the station!</b>")
var/new_name = tgui_input_text(src, "Enter your name, or press \"Cancel\" to stick with Keeki.", "Name Change", name)
if(new_name)
to_chat(src, "<span class='notice'>Your name is now <b>\"[new_name]\"</b>!</span>")
name = new_name
if(!new_name)
return
to_chat(src, "<span class='notice'>Your name is now <b>\"[new_name]\"</b>!</span>")
name = new_name
+9 -11
View File
@@ -752,22 +752,20 @@ GLOBAL_LIST_INIT(slot_equipment_priority, list( \
to_chat(usr, "<span class='notice'>You have to be conscious to change your flavor text</span>")
return
var/msg = tgui_input_text(usr, "Set the flavor text in your 'examine' verb. The flavor text should be a physical descriptor of your character at a glance. SFW Drawn Art of your character is acceptable.", "Flavor Text", flavor_text, multiline = TRUE, encode = FALSE)
if(msg != null)
if(stat)
to_chat(usr, "<span class='notice'>You have to be conscious to change your flavor text</span>")
return
msg = copytext(msg, 1, MAX_MESSAGE_LEN)
msg = msg
flavor_text = msg
var/msg = tgui_input_text(usr, "Set the flavor text in your 'examine' verb. The flavor text should be a physical descriptor of your character at a glance. SFW Drawn Art of your character is acceptable.", "Flavor Text", flavor_text, multiline = TRUE)
if(isnull(msg))
return
if(stat)
to_chat(usr, "<span class='notice'>You have to be conscious to change your flavor text</span>")
return
msg = copytext(msg, 1, MAX_MESSAGE_LEN)
flavor_text = msg
/mob/proc/print_flavor_text(shrink = TRUE)
if(flavor_text && flavor_text != "")
var/msg = replacetext(flavor_text, "\n", " ")
if(length(msg) <= 40 || !shrink)
return "<span class='notice'>[html_encode(msg)]</span>" //Repeat after me, "I will not give players access to decoded HTML."
return "<span class='notice'>[msg]</span>" // There is already encoded by tgui_input
else
return "<span class='notice'>[copytext_preserve_html(msg, 1, 37)]... <a href='byond://?src=[UID()];flavor_more=1'>More...</a></span>"
+2 -2
View File
@@ -26,11 +26,11 @@
switch(text2num(params["msgnum"]))
if(1)
message1 = tgui_input_text(usr, "Line 1", "Enter Message Text", message1, encode = FALSE)
if(!message1)
if(isnull(message1))
return
if(2)
message2 = tgui_input_text(usr, "Line 2", "Enter Message Text", message2, encode = FALSE)
if(!message2)
if(isnull(message2))
return
if("Status")
+1 -1
View File
@@ -74,7 +74,7 @@
switch(action)
if("Edit")
var/n = tgui_input_text(usr, "Please enter message", name, note, multiline = TRUE, encode = FALSE)
if(!n)
if(isnull(n))
return
if(pda.loc == usr)
-2
View File
@@ -122,8 +122,6 @@
/datum/data/pda/app/messenger/proc/create_message(mob/living/U, obj/item/pda/P)
var/t = tgui_input_text(U, "Please enter your message", name)
if(!t)
return
if(!t || !istype(P))
return
if(!in_range(pda, U) && pda.loc != U)
+1 -1
View File
@@ -242,7 +242,7 @@
/datum/data/pda/app/nanobank/proc/input_account_pin(mob/user)
var/attempt_pin = tgui_input_number(user, "Enter pin code", "NanoBank Account Auth", max_value = 99999)
if(!user_account || !attempt_pin)
if(!user_account || isnull(attempt_pin))
return
return attempt_pin
+4 -5
View File
@@ -277,15 +277,14 @@
return
if(!P.singleton && params["multiple"])
var/num_input = tgui_input_number(user, "Amount", "How many crates?", max_value = MULTIPLE_CRATE_MAX)
if(!num_input || (!is_public && !is_authorized(user)) || ..()) // Make sure they dont walk away
var/num_input = tgui_input_number(user, "Amount", "How many crates?", max_value = MULTIPLE_CRATE_MAX, min_value = 1)
if(isnull(num_input) || (!is_public && !is_authorized(user)) || ..()) // Make sure they dont walk away
return
amount = clamp(round(num_input), 1, MULTIPLE_CRATE_MAX)
var/timeout = world.time + (60 SECONDS) // If you dont type the reason within a minute, theres bigger problems here
var/reason = tgui_input_text(user, "Reason", "Why do you require this item?", encode = FALSE)
if(world.time > timeout || !reason || (!is_public && !is_authorized(user)) || ..())
// Cancel if they take too long, they dont give a reason, they aint authed, or if they walked away
var/reason = tgui_input_text(user, "Reason", "Why do you require this item?", encode = FALSE, timeout = timeout)
if(!reason || (!is_public && !is_authorized(user)) || ..())
return
reason = sanitize(copytext_char(reason, 1, 75)) // very long reasons are bad
+2 -2
View File
@@ -41,13 +41,13 @@
// Its custom, lets ask
var/question = tgui_input_text(usr, "What is the vote for?", "Create Vote", encode = FALSE)
if(!question)
if(isnull(question))
return
var/list/choices = list()
for(var/i in 1 to 10)
var/option = tgui_input_text(usr, "Please enter an option or hit cancel to finish", "Create Vote", encode = FALSE)
if(!option || !usr.client)
if(isnull(option) || !usr.client)
break
choices |= option