diff --git a/code/__HELPERS/hearted.dm b/code/__HELPERS/hearted.dm index 06e8b222916..bfc487254f3 100644 --- a/code/__HELPERS/hearted.dm +++ b/code/__HELPERS/hearted.dm @@ -48,7 +48,7 @@ if(3) heart_nominee = tgui_input_text(src, "One more try, what was their name? Just a first or last name may be enough.", "<3?") - if(isnull(heart_nominee) || heart_nominee == "") + if(!heart_nominee) return heart_nominee = lowertext(heart_nominee) diff --git a/code/datums/components/material_container.dm b/code/datums/components/material_container.dm index d5ee4f19a56..d77abbf322a 100644 --- a/code/datums/components/material_container.dm +++ b/code/datums/components/material_container.dm @@ -147,29 +147,29 @@ user_insert(I, user, mat_container_flags) /// Proc used for when player inserts materials -/datum/component/material_container/proc/user_insert(obj/item/I, mob/living/user, breakdown_flags = mat_container_flags) +/datum/component/material_container/proc/user_insert(obj/item/held_item, mob/living/user, breakdown_flags = mat_container_flags) set waitfor = FALSE var/requested_amount var/active_held = user.get_active_held_item() // differs from I when using TK - if(istype(I, /obj/item/stack) && precise_insertion) + if(istype(held_item, /obj/item/stack) && precise_insertion) var/atom/current_parent = parent - var/obj/item/stack/S = I - requested_amount = round(tgui_input_number(user, "How much do you want to insert?", "Inserting [S.singular_name]s")) - if(isnull(requested_amount) || (requested_amount <= 0)) + var/obj/item/stack/item_stack = held_item + requested_amount = tgui_input_number(user, "How much do you want to insert?", "Inserting [item_stack.singular_name]s", item_stack.amount, item_stack.amount) + if(!requested_amount || QDELETED(held_item) || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - if(QDELETED(I) || QDELETED(user) || QDELETED(src) || parent != current_parent || user.physical_can_use_topic(current_parent) < UI_INTERACTIVE || user.get_active_held_item() != active_held) + if(parent != current_parent || user.get_active_held_item() != active_held) return - if(!user.temporarilyRemoveItemFromInventory(I)) - to_chat(user, span_warning("[I] is stuck to you and cannot be placed into [parent].")) + if(!user.temporarilyRemoveItemFromInventory(held_item)) + to_chat(user, span_warning("[held_item] is stuck to you and cannot be placed into [parent].")) return - var/inserted = insert_item(I, stack_amt = requested_amount, breakdown_flags= mat_container_flags) + var/inserted = insert_item(held_item, stack_amt = requested_amount, breakdown_flags= mat_container_flags) if(inserted) to_chat(user, span_notice("You insert a material total of [inserted] into [parent].")) - qdel(I) + qdel(held_item) if(after_insert) - after_insert.Invoke(I, last_inserted_id, inserted) - else if(I == active_held) - user.put_in_active_hand(I) + after_insert.Invoke(held_item, last_inserted_id, inserted) + else if(held_item == active_held) + user.put_in_active_hand(held_item) /// Proc specifically for inserting items, returns the amount of materials entered. /datum/component/material_container/proc/insert_item(obj/item/I, multiplier = 1, stack_amt, breakdown_flags = mat_container_flags) diff --git a/code/game/machinery/computer/security.dm b/code/game/machinery/computer/security.dm index fc21f78188b..1971bbd684b 100644 --- a/code/game/machinery/computer/security.dm +++ b/code/game/machinery/computer/security.dm @@ -797,10 +797,8 @@ What a mess.*/ if("age") if(istype(active1, /datum/data/record)) var/t1 = tgui_input_number(usr, "Input age", "Security records", active1.fields["age"], AGE_MAX, AGE_MIN) - if (!t1) return - if(!canUseSecurityRecordsConsole(usr, "age", a1)) return active1.fields["age"] = t1 @@ -884,15 +882,11 @@ What a mess.*/ var/maxFine = CONFIG_GET(number/maxfine) var/t1 = tgui_input_text(usr, "Input citation crime", "Security Records") - var/fine = round(tgui_input_number(usr, "Input citation fine", "Security Records", 50, maxFine, 1)) - - if (isnull(fine)) + if(!t1) return - fine = min(fine, maxFine) - - if(!canUseSecurityRecordsConsole(usr, t1, null, a2)) + var/fine = tgui_input_number(usr, "Input citation fine", "Security Records", 50, maxFine) + if (!fine || QDELETED(usr) || QDELETED(src) || !canUseSecurityRecordsConsole(usr, t1, null, a2)) return - var/datum/data/crime/crime = GLOB.data_core.createCrimeEntry(t1, "", authenticated, station_time_timestamp(), fine) for (var/obj/item/pda/P in GLOB.PDAs) if(P.owner == active1.fields["name"]) diff --git a/code/game/machinery/doors/poddoor.dm b/code/game/machinery/doors/poddoor.dm index f80344ccade..41c8f295e96 100644 --- a/code/game/machinery/doors/poddoor.dm +++ b/code/game/machinery/doors/poddoor.dm @@ -34,10 +34,10 @@ return if (deconstruction != BLASTDOOR_FINISHED) return - var/change_id = tgui_input_number(user, "Set the door controllers ID", "Door Controller ID", id, 100, 1) - if(isnull(change_id)) + var/change_id = tgui_input_number(user, "Set the door controllers ID", "Door Controller ID", id, 100) + if(!change_id || QDELETED(usr) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - id = round(change_id) + id = change_id to_chat(user, span_notice("You change the ID to [id].")) balloon_alert(user, "ID changed") diff --git a/code/game/machinery/launch_pad.dm b/code/game/machinery/launch_pad.dm index 655bfb7f20e..ba3eb0779da 100644 --- a/code/game/machinery/launch_pad.dm +++ b/code/game/machinery/launch_pad.dm @@ -406,7 +406,7 @@ our_pad.display_name = new_name if("remove") . = TRUE - if(usr && tgui_alert(usr, "Are you sure?", "Unlink Launchpad", list("I'm Sure", "Abort")) == "I'm Sure") + if(usr && tgui_alert(usr, "Are you sure?", "Unlink Launchpad", list("Confirm", "Abort")) == "I'm Sure") our_pad = null if("launch") sending = TRUE diff --git a/code/game/machinery/roulette_machine.dm b/code/game/machinery/roulette_machine.dm index 040b41b96bd..55c11d5b476 100644 --- a/code/game/machinery/roulette_machine.dm +++ b/code/game/machinery/roulette_machine.dm @@ -171,7 +171,7 @@ else var/obj/item/card/id/new_card = W if(new_card.registered_account) - var/msg = tgui_input_text(user, "Name of your roulette wheel", "Roulette Naming", "Roulette Machine", MAX_NAME_LEN) + var/msg = tgui_input_text(user, "Name of your roulette wheel", "Roulette Customization", "Roulette Machine", MAX_NAME_LEN) if(!msg) return name = msg diff --git a/code/game/machinery/syndicatebomb.dm b/code/game/machinery/syndicatebomb.dm index ebff633f102..fd9cab2e1a4 100644 --- a/code/game/machinery/syndicatebomb.dm +++ b/code/game/machinery/syndicatebomb.dm @@ -214,11 +214,9 @@ if(!user.canUseTopic(src, !issilicon(user))) return var/new_timer = tgui_input_number(user, "Set the timer", "Countdown", timer_set, maximum_timer, minimum_timer) - if (isnull(new_timer)) + if(!new_timer || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - if(!user.canUseTopic(src, !issilicon(user))) - return - timer_set = round(new_timer) + timer_set = new_timer loc.visible_message(span_notice("[icon2html(src, viewers(src))] timer set for [timer_set] seconds.")) var/choice = tgui_alert(user, "Would you like to start the countdown now?", "Bomb Timer", list("Yes","No")) if(choice != "Yes") diff --git a/code/game/objects/items/AI_modules.dm b/code/game/objects/items/AI_modules.dm index a76bbf03082..56df0cb7554 100644 --- a/code/game/objects/items/AI_modules.dm +++ b/code/game/objects/items/AI_modules.dm @@ -247,9 +247,9 @@ AI MODULES /obj/item/ai_module/supplied/freeform/attack_self(mob/user) var/newpos = tgui_input_number(user, "Please enter the priority for your new law. Can only write to law sectors 15 and above.", "Law Priority ", lawpos, 50, 15) - if(isnull(newpos)) + if(!newpos || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - lawpos = round(newpos) + lawpos = newpos var/targName = tgui_input_text(user, "Enter a new law for the AI.", "Freeform Law Entry", laws[1], CONFIG_GET(number/max_law_len), TRUE) if(!targName) return @@ -285,8 +285,8 @@ AI MODULES var/lawpos = 1 /obj/item/ai_module/remove/attack_self(mob/user) - lawpos = tgui_input_number(user, "Law to delete", "Law Removal", lawpos, 50, 1) - if(isnull(lawpos)) + lawpos = tgui_input_number(user, "Law to delete", "Law Removal", lawpos, 50) + if(!lawpos || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return to_chat(user, span_notice("Law [lawpos] selected.")) ..() diff --git a/code/game/objects/items/cards_ids.dm b/code/game/objects/items/cards_ids.dm index ebe89dbd3ce..65a3ea27051 100644 --- a/code/game/objects/items/cards_ids.dm +++ b/code/game/objects/items/cards_ids.dm @@ -608,19 +608,19 @@ /obj/item/card/id/proc/set_new_account(mob/living/user) . = FALSE var/datum/bank_account/old_account = registered_account - + if(loc != user) + to_chat(user, span_warning("You must be holding the ID to continue!")) + return FALSE var/new_bank_id = tgui_input_number(user, "Enter your account ID number", "Account Reclamation", 111111, 999999, 111111) - if(isnull(new_bank_id)) - return - if(!alt_click_can_use_id(user)) - return - if(registered_account && registered_account.account_id == new_bank_id) + if(!new_bank_id || QDELETED(user) || QDELETED(src) || issilicon(user) || !alt_click_can_use_id(user) || loc != user) + return FALSE + if(registered_account?.account_id == new_bank_id) to_chat(user, span_warning("The account ID was already assigned to this card.")) - return + return FALSE var/datum/bank_account/account = SSeconomy.bank_accounts_by_id["[new_bank_id]"] if(isnull(account)) to_chat(user, span_warning("The account ID number provided is invalid.")) - return + return FALSE if(old_account) old_account.bank_cards -= src account.bank_cards += src @@ -637,10 +637,11 @@ if (registered_account.being_dumped) registered_account.bank_card_talk(span_warning("内部服务器错误"), TRUE) return - var/amount_to_remove = round(tgui_input_number(user, "How much do you want to withdraw?", "Withdraw Funds", 1, registered_account.account_balance, 1)) - if(isnull(amount_to_remove)) + if(loc != user) + to_chat(user, span_warning("You must be holding the ID to continue!")) return - if(amount_to_remove < 1 || amount_to_remove > registered_account.account_balance) + var/amount_to_remove = tgui_input_number(user, "How much do you want to withdraw? (Max: [registered_account.account_balance] cr)", "Withdraw Funds", max_value = registered_account.account_balance) + if(!amount_to_remove || QDELETED(user) || QDELETED(src) || issilicon(user) || loc != user) return if(!alt_click_can_use_id(user)) return @@ -1105,7 +1106,10 @@ ..() var/list/id_access = C.GetAccess() if(!(ACCESS_BRIG in id_access)) - return + return FALSE + if(loc != user) + to_chat(user, span_warning("You must be holding the ID to continue!")) + return FALSE if(timed) timed = FALSE time_to_assign = initial(time_to_assign) @@ -1114,9 +1118,9 @@ to_chat(user, "Restating prisoner ID to default parameters.") return var/choice = tgui_input_number(user, "Sentence time in seconds", "Sentencing") - if(isnull(choice) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) - return - time_to_assign = round(choice) + if(!choice || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK) || loc != user) + return FALSE + time_to_assign = choice to_chat(user, "You set the sentence time to [time_to_assign] seconds.") timed = TRUE @@ -1390,7 +1394,7 @@ /obj/item/card/id/advanced/chameleon/attack_self(mob/user) if(isliving(user) && user.mind) - var/popup_input = tgui_alert(user, "Choose Action", "Agent ID", list("Show", "Forge/Reset", "Change Account ID")) + var/popup_input = tgui_input_list(user, "Choose Action", "Agent ID", list("Show", "Forge/Reset", "Change Account ID")) if(user.incapacitated()) return if(!user.is_holding(src)) @@ -1433,8 +1437,10 @@ assignment = target_occupation var/new_age = tgui_input_number(user, "Choose the ID's age", "Agent card age", AGE_MIN, AGE_MAX, AGE_MIN) + if(QDELETED(user) || QDELETED(src) || !user.canUseTopic(user, BE_CLOSE, NO_DEXTERITY, NO_TK)) + return if(new_age) - registered_age = round(new_age) + registered_age = new_age if(tgui_alert(user, "Activate wallet ID spoofing, allowing this card to force itself to occupy the visible ID slot in wallets?", "Wallet ID Spoofing", list("Yes", "No")) == "Yes") ADD_TRAIT(src, TRAIT_MAGNETIC_ID_CARD, CHAMELEON_ITEM_TRAIT) diff --git a/code/game/objects/items/circuitboards/machine_circuitboards.dm b/code/game/objects/items/circuitboards/machine_circuitboards.dm index dfb329caf18..81183b22b00 100644 --- a/code/game/objects/items/circuitboards/machine_circuitboards.dm +++ b/code/game/objects/items/circuitboards/machine_circuitboards.dm @@ -733,12 +733,12 @@ /obj/item/circuitboard/machine/medical_kiosk/multitool_act(mob/living/user) . = ..() var/new_cost = tgui_input_number(user, "New cost for using this medical kiosk", "Pricing", custom_cost, 1000, 10) - if(isnull(new_cost)) + if(!new_cost || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return if(loc != user) to_chat(user, span_warning("You must hold the circuitboard to change its cost!")) return - custom_cost = round(new_cost) + custom_cost = new_cost to_chat(user, span_notice("The cost is now set to [custom_cost].")) /obj/item/circuitboard/machine/medical_kiosk/examine(mob/user) diff --git a/code/game/objects/items/credit_holochip.dm b/code/game/objects/items/credit_holochip.dm index ff7272badf5..d7aecb345c2 100644 --- a/code/game/objects/items/credit_holochip.dm +++ b/code/game/objects/items/credit_holochip.dm @@ -99,14 +99,14 @@ qdel(H) /obj/item/holochip/AltClick(mob/user) - if(!user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, FALSE, !iscyborg(user))) + if(!user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, NO_TK, !iscyborg(user))) return - var/split_amount = tgui_input_number(user, "How many credits do you want to extract from the holochip?", "Holochip", 1, credits, 1) - if(isnull(split_amount)) + if(loc != user) + to_chat(user, span_warning("You must be holding the holochip to continue!")) + return FALSE + var/split_amount = tgui_input_number(user, "How many credits do you want to extract from the holochip? (Max: [credits] cr)", "Holochip", max_value = credits) + if(!split_amount || QDELETED(user) || QDELETED(src) || issilicon(user) || !usr.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, NO_TK, !iscyborg(user)) || loc != user) return - if(!user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, FALSE, !iscyborg(user))) - return - split_amount = round(split_amount) var/new_credits = spend(split_amount, TRUE) var/obj/item/holochip/H = new(user ? user : drop_location(), new_credits) if(user) diff --git a/code/game/objects/items/devices/desynchronizer.dm b/code/game/objects/items/devices/desynchronizer.dm index e00c1c71858..86457dbe765 100644 --- a/code/game/objects/items/devices/desynchronizer.dm +++ b/code/game/objects/items/devices/desynchronizer.dm @@ -35,11 +35,10 @@ /obj/item/desynchronizer/AltClick(mob/living/user) if(!user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, FALSE, !iscyborg(user))) return - var/new_duration = tgui_input_number(user, "Set the duration", "Desynchronizer", duration / 10, max_duration, 5 SECONDS) - if(isnull(new_duration)) + var/new_duration = tgui_input_number(user, "Set the duration", "Desynchronizer", duration / 10, max_duration, 5) + if(!new_duration || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, FALSE, !iscyborg(user))) return - new_duration = new_duration SECONDS - duration = round(new_duration) + duration = new_duration to_chat(user, span_notice("You set the duration to [DisplayTimeText(duration)].")) /obj/item/desynchronizer/proc/desync(mob/living/user) diff --git a/code/game/objects/items/grenades/chem_grenade.dm b/code/game/objects/items/grenades/chem_grenade.dm index 6760d0d5e67..13cf6f600fb 100644 --- a/code/game/objects/items/grenades/chem_grenade.dm +++ b/code/game/objects/items/grenades/chem_grenade.dm @@ -352,12 +352,9 @@ if (active) return var/newspread = tgui_input_number(user, "Please enter a new spread amount", "Grenade Spread", 5, 100, 5) - if(isnull(newspread)) + if(!newspread || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - if(!user.canUseTopic(src, BE_CLOSE)) - return - newspread = round(newspread) - unit_spread = clamp(newspread, 5, 100) + unit_spread = newspread to_chat(user, span_notice("You set the time release to [unit_spread] units per detonation.")) ..() diff --git a/code/game/objects/items/grenades/plastic.dm b/code/game/objects/items/grenades/plastic.dm index 245181fc722..ba6be18a1ee 100644 --- a/code/game/objects/items/grenades/plastic.dm +++ b/code/game/objects/items/grenades/plastic.dm @@ -18,6 +18,10 @@ var/aim_dir = NORTH var/boom_sizes = list(0, 0, 3) var/full_damage_on_mobs = FALSE + /// Minimum timer for c4 charges + var/minimum_timer = 10 + /// Maximum timer for c4 charges + var/maximum_timer = 60000 /obj/item/grenade/c4/Initialize(mapload) . = ..() @@ -75,12 +79,11 @@ detonate() /obj/item/grenade/c4/attack_self(mob/user) - var/newtime = tgui_input_number(usr, "Please set the timer", "C4 Timer", 10, 60000, 10) - if (isnull(newtime)) + var/newtime = tgui_input_number(user, "Please set the timer", "C4 Timer", minimum_timer, maximum_timer, minimum_timer) + if(!newtime || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - if(user.get_active_held_item() == src) - det_time = round(newtime) - to_chat(user, "Timer set for [det_time] seconds.") + det_time = newtime + to_chat(user, "Timer set for [det_time] seconds.") /obj/item/grenade/c4/afterattack(atom/movable/bomb_target, mob/user, flag) . = ..() diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm index dde7606dc6e..ff354b8db14 100644 --- a/code/game/objects/items/stacks/stack.dm +++ b/code/game/objects/items/stacks/stack.dm @@ -522,12 +522,9 @@ if(is_zero_amount(delete_if_zero = TRUE)) return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN var/max = get_amount() - var/stackmaterial = round(tgui_input_number(user, "How many sheets do you wish to take out of this stack?", "Stack Split", max_value = max)) - if(isnull(stackmaterial)) + var/stackmaterial = tgui_input_number(user, "How many sheets do you wish to take out of this stack?", "Stack Split", max_value = max) + if(!stackmaterial || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK, !iscyborg(user))) return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN - stackmaterial = min(max, stackmaterial) - if(stackmaterial <= 0 || !user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, FALSE, !iscyborg(user))) - return SECONDARY_ATTACK_CONTINUE_CHAIN split_stack(user, stackmaterial) to_chat(user, span_notice("You take [stackmaterial] sheets out of the stack.")) return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN diff --git a/code/game/objects/structures/displaycase.dm b/code/game/objects/structures/displaycase.dm index 654ecaf43bb..3b921c4971e 100644 --- a/code/game/objects/structures/displaycase.dm +++ b/code/game/objects/structures/displaycase.dm @@ -508,14 +508,15 @@ playsound(src, 'sound/machines/buzz-sigh.ogg', 50, TRUE) return - var/new_price_input = tgui_input_number(usr, "Sale price for this vend-a-tray", "New Price", 10, 1000, 1) - if(isnull(new_price_input) || (payments_acc != potential_acc.registered_account)) + var/new_price_input = tgui_input_number(usr, "Sale price for this vend-a-tray", "New Price", 10, 1000) + if(!new_price_input || QDELETED(usr) || QDELETED(src)) + return + if(payments_acc != potential_acc.registered_account) to_chat(usr, span_warning("[src] rejects your new price.")) return - if(!usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK) ) + if(!usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) to_chat(usr, span_warning("You need to get closer!")) return - new_price_input = round(new_price_input) sale_price = new_price_input to_chat(usr, span_notice("The cost is now set to [sale_price].")) SStgui.update_uis(src) diff --git a/code/game/objects/structures/reflector.dm b/code/game/objects/structures/reflector.dm index 6150c7b76da..b5b2f056cc1 100644 --- a/code/game/objects/structures/reflector.dm +++ b/code/game/objects/structures/reflector.dm @@ -161,11 +161,8 @@ to_chat(user, span_warning("The rotation is locked!")) return FALSE var/new_angle = tgui_input_number(user, "New angle for primary reflection face", "Reflector Angle", rotation_angle, 360) - if(isnull(new_angle)) + if(isnull(new_angle) || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return FALSE - if(!user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY, FALSE, !iscyborg(user))) - return FALSE - new_angle = round(new_angle) set_angle(SIMPLIFY_DEGREES(new_angle)) return TRUE diff --git a/code/modules/admin/sound_emitter.dm b/code/modules/admin/sound_emitter.dm index 9827a7553ee..20de4bfcf58 100644 --- a/code/modules/admin/sound_emitter.dm +++ b/code/modules/admin/sound_emitter.dm @@ -91,16 +91,15 @@ to_chat(user, span_notice("New sound file set to [sound_file]."), confidential = TRUE) if(href_list["edit_volume"]) var/new_volume = tgui_input_number(user, "Choose a volume", "Sound Emitter", sound_volume, 100) - if(isnull(new_volume)) + if(!new_volume) return - new_volume = clamp(new_volume, 0, 100) sound_volume = new_volume to_chat(user, span_notice("Volume set to [sound_volume]%."), confidential = TRUE) if(href_list["edit_mode"]) var/new_mode var/mode_list = list("Local (normal sound)" = SOUND_EMITTER_LOCAL, "Direct (not affected by environment/location)" = SOUND_EMITTER_DIRECT) new_mode = tgui_input_list(user, "Choose a new mode", "Sound Emitter", mode_list) - if(isnull(new_mode)) + if(!new_mode) return motus_operandi = mode_list[new_mode] to_chat(user, span_notice("Mode set to [motus_operandi]."), confidential = TRUE) @@ -108,15 +107,14 @@ var/new_range var/range_list = list("Radius (all mobs within a radius)" = SOUND_EMITTER_RADIUS, "Z-Level (all mobs on the same z)" = SOUND_EMITTER_ZLEVEL, "Global (all players)" = SOUND_EMITTER_GLOBAL) new_range = tgui_input_list(user, "Choose a new range", "Sound Emitter", range_list) - if(isnull(new_range)) + if(!new_range) return emitter_range = range_list[new_range] to_chat(user, span_notice("Range set to [emitter_range]."), confidential = TRUE) if(href_list["edit_radius"]) - var/new_radius = tgui_input_number(user, "Choose a radius.", "Sound Emitter", sound_volume, 127) - if(isnull(new_radius)) + var/new_radius = tgui_input_number(user, "Choose a radius", "Sound Emitter", sound_volume, 127) + if(!new_radius) return - new_radius = clamp(new_radius, 0, 127) play_radius = new_radius to_chat(user, span_notice("Audible radius set to [play_radius]."), confidential = TRUE) if(href_list["play"]) diff --git a/code/modules/admin/verbs/borgpanel.dm b/code/modules/admin/verbs/borgpanel.dm index c5ee63c199d..257e51fdbb2 100644 --- a/code/modules/admin/verbs/borgpanel.dm +++ b/code/modules/admin/verbs/borgpanel.dm @@ -85,9 +85,9 @@ switch (action) if ("set_charge") var/newcharge = tgui_input_number(usr, "Set new charge", borg.name, borg.cell.charge, borg.cell.maxcharge) - if (isnull(newcharge)) + if(isnull(newcharge)) return - borg.cell.charge = clamp(newcharge, 0, borg.cell.maxcharge) + borg.cell.charge = newcharge message_admins("[key_name_admin(user)] set the charge of [ADMIN_LOOKUPFLW(borg)] to [borg.cell.charge].") log_silicon("[key_name(user)] set the charge of [key_name(borg)] to [borg.cell.charge].") if ("remove_cell") diff --git a/code/modules/antagonists/blob/blob_mobs.dm b/code/modules/antagonists/blob/blob_mobs.dm index 69ebebff208..787a934564f 100644 --- a/code/modules/antagonists/blob/blob_mobs.dm +++ b/code/modules/antagonists/blob/blob_mobs.dm @@ -147,8 +147,8 @@ return if(key || stat) return - var/pod_ask = tgui_alert(usr,"Become a blob spore?", "Are you bulbous enough?", list("Yes", "No")) - if(pod_ask == "No" || !src || QDELETED(src)) + var/pod_ask = tgui_alert(usr, "Are you bulbous enough?", "Blob Spore", list("Yes", "No")) + if(pod_ask == "No" || QDELETED(src)) return if(key) to_chat(user, span_warning("Someone else already took this spore!")) diff --git a/code/modules/antagonists/changeling/powers/fakedeath.dm b/code/modules/antagonists/changeling/powers/fakedeath.dm index 6a02a6d2d37..32c29c05105 100644 --- a/code/modules/antagonists/changeling/powers/fakedeath.dm +++ b/code/modules/antagonists/changeling/powers/fakedeath.dm @@ -67,7 +67,7 @@ to_chat(user, span_warning("We are already reviving.")) return if(!user.stat && !revive_ready) //Confirmation for living changelings if they want to fake their death - switch(tgui_alert(usr,"Are we sure we wish to fake our own death?",,list("Yes", "No"))) + switch(tgui_alert(usr,"Are we sure we wish to fake our own death?", "Feign Death", list("Yes", "No"))) if("No") return return ..() diff --git a/code/modules/antagonists/cult/runes.dm b/code/modules/antagonists/cult/runes.dm index 7d85a311f2e..931fa81001e 100644 --- a/code/modules/antagonists/cult/runes.dm +++ b/code/modules/antagonists/cult/runes.dm @@ -836,7 +836,7 @@ structure_check() searches for nearby cultist structures required for the invoca . = ..() var/mob/living/user = invokers[1] var/turf/T = get_turf(src) - var/choice = tgui_alert(user,"You tear open a connection to the spirit realm...",,list("Summon a Cult Ghost","Ascend as a Dark Spirit","Cancel")) + var/choice = tgui_alert(user, "You tear open a connection to the spirit realm...", "Spirit Realm", list("Summon a Cult Ghost", "Ascend as a Dark Spirit")) if(choice == "Summon a Cult Ghost") if(!is_station_level(T.z)) to_chat(user, span_cultitalic("The veil is not weak enough here to manifest spirits, you must be on station!")) diff --git a/code/modules/art/paintings.dm b/code/modules/art/paintings.dm index a4f76b2a225..b3676d72999 100644 --- a/code/modules/art/paintings.dm +++ b/code/modules/art/paintings.dm @@ -170,28 +170,28 @@ var/mob/living/living_user = user var/obj/item/card/id/id_card = living_user.get_idcard(TRUE) if(!id_card) - to_chat(user,span_notice("You don't even have a id and you want to be an art patron?")) + to_chat(user, span_warning("You don't even have a id and you want to be an art patron?")) return if(!id_card.registered_account || !id_card.registered_account.account_job) - to_chat(user,span_notice("No valid non-departmental account found.")) + to_chat(user, span_warning("No valid non-departmental account found.")) return var/datum/bank_account/account = id_card.registered_account - if(account.account_balance < painting_metadata.credit_value) - to_chat(user,span_notice("You can't afford this.")) + if(!account.has_money(painting_metadata.credit_value)) + to_chat(user, span_warning("You can't afford this.")) return var/sniped_amount = painting_metadata.credit_value var/offer_amount = tgui_input_number(user, "How much do you want to offer?", "Patronage Amount", (painting_metadata.credit_value + 1), account.account_balance, painting_metadata.credit_value) - if(isnull(offer_amount)) + if(!offer_amount || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - if(offer_amount <= 0 || sniped_amount != painting_metadata.credit_value || offer_amount < painting_metadata.credit_value+1 || !user.canUseTopic(src)) + if(sniped_amount != painting_metadata.credit_value) return if(!account.adjust_money(-offer_amount)) - to_chat(user,span_warning("Transaction failure. Please try again.")) + to_chat(user, span_warning("Transaction failure. Please try again.")) return painting_metadata.patron_ckey = user.ckey painting_metadata.patron_name = user.real_name painting_metadata.credit_value = offer_amount - to_chat(user,span_notice("Nanotrasen Trust Foundation thanks you for your contribution. You're now offical patron of this painting.")) + to_chat(user, span_notice("Nanotrasen Trust Foundation thanks you for your contribution. You're now an official patron of this painting.")) /obj/item/canvas/update_overlays() . = ..() diff --git a/code/modules/assembly/doorcontrol.dm b/code/modules/assembly/doorcontrol.dm index 07c0d699883..e9e37e95d2f 100644 --- a/code/modules/assembly/doorcontrol.dm +++ b/code/modules/assembly/doorcontrol.dm @@ -14,10 +14,10 @@ . += span_notice("Its channel ID is '[id]'.") /obj/item/assembly/control/multitool_act(mob/living/user) - var/change_id = tgui_input_number(user, "Set the door controllers ID", "ID", id, 100, 1) - if(isnull(change_id)) + var/change_id = tgui_input_number(user, "Set the door controllers ID", "Door ID", id, 100) + if(!change_id || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - id = round(change_id) + id = change_id to_chat(user, span_notice("You change the ID to [id].")) /obj/item/assembly/control/activate() diff --git a/code/modules/atmospherics/machinery/portable/canister.dm b/code/modules/atmospherics/machinery/portable/canister.dm index cd1ed6e68bb..406c540506b 100644 --- a/code/modules/atmospherics/machinery/portable/canister.dm +++ b/code/modules/atmospherics/machinery/portable/canister.dm @@ -710,9 +710,9 @@ GLOBAL_LIST_INIT(gas_id_to_canister, init_gas_id_to_canister()) timer_set = min(maximum_timer_set, timer_set + 10) if("input") var/user_input = tgui_input_number(usr, "Set time to valve toggle", "Canister Timer", timer_set, maximum_timer_set, minimum_timer_set) - if(isnull(user_input)) + if(isnull(user_input) || QDELETED(usr) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, TRUE)) return - timer_set = clamp(user_input, minimum_timer_set, maximum_timer_set) + timer_set = user_input log_admin("[key_name(usr)] has activated a prototype valve timer") . = TRUE if("toggle_timer") diff --git a/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm b/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm index b31e9eb7eba..d48d292089a 100644 --- a/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm +++ b/code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm @@ -214,11 +214,11 @@ if (params["amount"]) desired = text2num(params["amount"]) else - desired = tgui_input_number(usr, "How many items would you like to take out?", "Release", 1, min_value = 1) - if(isnull(desired)) + desired = tgui_input_number(usr, "How many items would you like to take out?", "Release", max_value = 50) + if(!desired) return FALSE - desired = round(desired) - if(QDELETED(src) || QDELETED(usr) || !usr.Adjacent(src)) // Sanity checkin' in case stupid stuff happens while we wait for input() + + if(QDELETED(src) || QDELETED(usr) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) // Sanity checkin' in case stupid stuff happens while we wait for input() return FALSE for(var/obj/item/dispensed_item in src) diff --git a/code/modules/food_and_drinks/pizzabox.dm b/code/modules/food_and_drinks/pizzabox.dm index 2354b97902b..fa7f56096bb 100644 --- a/code/modules/food_and_drinks/pizzabox.dm +++ b/code/modules/food_and_drinks/pizzabox.dm @@ -150,17 +150,12 @@ update_appearance() return else - bomb_timer = tgui_input_number(user, "Set the timer for [bomb].", "Pizza Bomb", bomb_timer, bomb_timer_max, bomb_timer_min) - - if (isnull(bomb_timer)) + bomb_timer = tgui_input_number(user, "Set the bomb timer", "Pizza Bomb", bomb_timer, bomb_timer_max, bomb_timer_min) + if(!bomb_timer || QDELETED(user) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - - bomb_timer = round(bomb_timer) bomb_defused = FALSE - log_bomber(user, "has trapped a", src, "with [bomb] set to [bomb_timer] seconds") bomb.adminlog = "The [bomb.name] in [src.name] that [key_name(user)] activated has detonated!" - to_chat(user, span_warning("You trap [src] with [bomb].")) update_appearance() else if(boxes.len) diff --git a/code/modules/hydroponics/beekeeping/beebox.dm b/code/modules/hydroponics/beekeeping/beebox.dm index d9722386538..89988c1733f 100644 --- a/code/modules/hydroponics/beekeeping/beebox.dm +++ b/code/modules/hydroponics/beekeeping/beebox.dm @@ -213,11 +213,11 @@ else visible_message(span_danger("[user] disturbs the [name] to no effect!")) else - var/option = tgui_alert(user, "What action do you wish to perform?","Apiary",list("Remove a Honey Frame","Remove the Queen Bee", "Cancel")) - if(!Adjacent(user)) + var/option = tgui_alert(user, "Which piece do you wish to remove?", "Apiary Adjustment", list("Honey Frame", "Queen Bee")) + if(!option || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE)) return switch(option) - if("Remove a Honey Frame") + if("Honey Frame") if(!honey_frames.len) to_chat(user, span_warning("There are no honey frames to remove!")) return @@ -240,7 +240,7 @@ var/multiple = fallen > 1 visible_message(span_notice("[user] scrapes [multiple ? "[fallen]" : "a"] honeycomb[multiple ? "s" : ""] off of the frame.")) - if("Remove the Queen Bee") + if("Queen Bee") if(!queen_bee || queen_bee.loc != src) to_chat(user, span_warning("There is no queen bee to remove!")) return diff --git a/code/modules/instruments/songs/editor.dm b/code/modules/instruments/songs/editor.dm index 9cc7367e1a5..7dd8074344c 100644 --- a/code/modules/instruments/songs/editor.dm +++ b/code/modules/instruments/songs/editor.dm @@ -185,22 +185,22 @@ stop_playing() else if(href_list["setlinearfalloff"]) - var/amount = tgui_input_number(usr, "Set linear sustain duration in seconds", "Linear Sustain Duration") + var/amount = tgui_input_number(usr, "Set linear sustain duration in seconds", "Linear Sustain Duration", 0.1, INSTRUMENT_MAX_TOTAL_SUSTAIN, 0.1) 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") + 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) if(!isnull(amount)) set_exponential_drop_rate(amount) else if(href_list["setvolume"]) - var/amount = tgui_input_number(usr, "Set volume", "Volume") + var/amount = tgui_input_number(usr, "Set volume", "Volume", 1, 75, 1) if(!isnull(amount)) set_volume(amount) else if(href_list["setdropoffvolume"]) - var/amount = tgui_input_number(usr, "Set dropoff threshold", "Dropoff Threshold Volume") + var/amount = tgui_input_number(usr, "Set dropoff threshold", "Dropoff Volume", max_value = 100) if(!isnull(amount)) set_dropoff_volume(amount) diff --git a/code/modules/mining/machine_redemption.dm b/code/modules/mining/machine_redemption.dm index 5360ec8a910..d65b201acf0 100644 --- a/code/modules/mining/machine_redemption.dm +++ b/code/modules/mining/machine_redemption.dm @@ -284,11 +284,9 @@ if (params["sheets"]) desired = text2num(params["sheets"]) else - desired = tgui_input_number(usr, "How many sheets would you like to smelt?", "Smelt", 1, stored_amount, 1) - if(isnull(desired)) + desired = tgui_input_number(usr, "How many sheets would you like to smelt?", "Smelt", max_value = stored_amount) + if(!desired || QDELETED(usr) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - desired = round(desired) - var/sheets_to_remove = round(min(desired,50,stored_amount)) var/count = mat_container.retrieve_sheets(sheets_to_remove, mat, get_step(src, output_dir)) @@ -334,10 +332,9 @@ if (params["sheets"]) desired = text2num(params["sheets"]) else - desired = tgui_input_number(usr, "How many sheets would you like to smelt?", "Smelt", 1, smelt_amount, 1) - if(isnull(desired)) + desired = tgui_input_number(usr, "How many sheets would you like to smelt?", "Smelt", max_value = smelt_amount) + if(!desired || QDELETED(usr) || QDELETED(src) || !usr.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - desired = round(desired) var/amount = round(min(desired,50,smelt_amount)) mat_container.use_materials(alloy.materials, amount) materials.silo_log(src, "released", -amount, "sheets", alloy.materials) diff --git a/code/modules/mob/dead/observer/observer.dm b/code/modules/mob/dead/observer/observer.dm index 2be4bb5fd54..b08901a0881 100644 --- a/code/modules/mob/dead/observer/observer.dm +++ b/code/modules/mob/dead/observer/observer.dm @@ -318,7 +318,7 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp ghostize(TRUE) // Can return with TRUE return TRUE // SKYRAT EDIT ADDITION END - var/response = tgui_alert(usr, "Are you -sure- you want to ghost?\n(You are alive. If you ghost whilst still alive you may not play again this round! You can't change your mind so choose wisely!!)","Are you sure you want to ghost?",list("Ghost","Stay in body")) + var/response = tgui_alert(usr, "Are you sure you want to ghost? If you ghost whilst still alive you cannot re-enter your body!", "Confirm Ghost Observe", list("Ghost", "Stay in Body")) if(response != "Ghost") return FALSE//didn't want to ghost after-all ghostize(FALSE) // FALSE parameter is so we can never re-enter our body. U ded. @@ -329,7 +329,7 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp set name = "Ghost" set desc = "Relinquish your life and enter the land of the dead." - var/response = tgui_alert(usr, "Are you -sure- you want to ghost?\n(You are alive. If you ghost whilst still alive you may not play again this round! You can't change your mind so choose wisely!!)","Are you sure you want to ghost?",list("Ghost","Stay in body")) + var/response = tgui_alert(usr, "Are you sure you want to ghost? If you ghost whilst still alive you cannot re-enter your body!", "Confirm Ghost Observe", list("Ghost", "Stay in Body")) if(response != "Ghost") return ghostize(FALSE) @@ -395,7 +395,7 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp to_chat(usr, span_warning("You're already stuck out of your body!")) return FALSE - var/response = tgui_alert(usr, "Are you sure you want to prevent (almost) all means of resuscitation? This cannot be undone. ","Are you sure you want to stay dead?",list("DNR","Save Me")) + var/response = tgui_alert(usr, "Are you sure you want to prevent (almost) all means of resuscitation? This cannot be undone.", "Are you sure you want to stay dead?", list("DNR","Save Me")) if(response != "DNR") return diff --git a/code/modules/mob/living/brain/posibrain.dm b/code/modules/mob/living/brain/posibrain.dm index 809e11e1d0c..3b6730da297 100644 --- a/code/modules/mob/living/brain/posibrain.dm +++ b/code/modules/mob/living/brain/posibrain.dm @@ -122,7 +122,7 @@ GLOBAL_VAR(posibrain_notify_cooldown) if(user.suiciding) //if they suicided, they're out forever. to_chat(user, span_warning("[src] fizzles slightly. Sadly it doesn't take those who suicided!")) return - var/posi_ask = tgui_alert(usr,"Become a [name]? (Warning, You can no longer be revived, and all past lives will be forgotten!)","Are you positive?",list("Yes","No")) + var/posi_ask = tgui_alert(user, "Become a [name]? (Warning, You can no longer be revived, and all past lives will be forgotten!)", "Confirm", list("Yes","No")) if(posi_ask != "Yes" || QDELETED(src)) return if(brainmob.suiciding) //clear suicide status if the old occupant suicided. diff --git a/code/modules/mob/living/carbon/alien/humanoid/alien_powers.dm b/code/modules/mob/living/carbon/alien/humanoid/alien_powers.dm index 23749a0d9bf..5b484f3522a 100644 --- a/code/modules/mob/living/carbon/alien/humanoid/alien_powers.dm +++ b/code/modules/mob/living/carbon/alien/humanoid/alien_powers.dm @@ -132,10 +132,8 @@ Doesn't work on other aliens/AI.*/ if(isnull(donation_target)) return FALSE var/amount = tgui_input_number(user, "Amount", "Transfer Plasma to [donation_target]", max_value = user.getPlasma()) - if(isnull(amount)) + if(!amount || QDELETED(user) || QDELETED(donation_target)) return FALSE - - amount = min(abs(round(amount)), user.getPlasma()) if (get_dist(user, donation_target) <= 1) donation_target.adjustPlasma(amount) user.adjustPlasma(-amount) diff --git a/code/modules/mob/living/carbon/alien/larva/powers.dm b/code/modules/mob/living/carbon/alien/larva/powers.dm index 5e576a7029e..4b6774a7dd5 100644 --- a/code/modules/mob/living/carbon/alien/larva/powers.dm +++ b/code/modules/mob/living/carbon/alien/larva/powers.dm @@ -30,38 +30,39 @@ /obj/effect/proc_holder/alien/larva_evolve/fire(mob/living/carbon/alien/user) if(!islarva(user)) return - var/mob/living/carbon/alien/larva/L = user + var/mob/living/carbon/alien/larva/larva = user - if(L.handcuffed || L.legcuffed) // Cuffing larvas ? Eh ? + if(larva.handcuffed || larva.legcuffed) // Cuffing larvas ? Eh ? to_chat(user, span_warning("You cannot evolve when you are cuffed!")) return - if(L.amount_grown >= L.max_grown) //TODO ~Carn - to_chat(L, span_name("You are growing into a beautiful alien! It is time to choose a caste.")) - to_chat(L, span_info("There are three to choose from:")) - to_chat(L, span_name("Hunters are the most agile caste, tasked with hunting for hosts. They are faster than a human and can even pounce, but are not much tougher than a drone.")) - to_chat(L, span_name("Sentinels are tasked with protecting the hive. With their ranged spit, invisibility, and high health, they make formidable guardians and acceptable secondhand hunters.")) - to_chat(L, span_name("Drones are the weakest and slowest of the castes, but can grow into a praetorian and then queen if no queen exists, and are vital to maintaining a hive with their resin secretion abilities.")) - var/alien_caste = tgui_alert(L, "Please choose which alien caste you shall belong to.",,list("Hunter","Sentinel","Drone")) - - if(L.movement_type & VENTCRAWLING) - to_chat(user, span_warning("You cannot evolve while ventcrawling!")) - return - - if(user.incapacitated()) //something happened to us while we were choosing. - return - - var/mob/living/carbon/alien/humanoid/new_xeno - switch(alien_caste) - if("Hunter") - new_xeno = new /mob/living/carbon/alien/humanoid/hunter(L.loc) - if("Sentinel") - new_xeno = new /mob/living/carbon/alien/humanoid/sentinel(L.loc) - if("Drone") - new_xeno = new /mob/living/carbon/alien/humanoid/drone(L.loc) - - L.alien_evolve(new_xeno) - return - else + if(larva.amount_grown < larva.max_grown) to_chat(user, span_warning("You are not fully grown!")) return + + to_chat(larva, span_name("You are growing into a beautiful alien! It is time to choose a caste.")) + to_chat(larva, span_info("There are three to choose from:")) + to_chat(larva, span_name("Hunters are the most agile caste, tasked with hunting for hosts. They are faster than a human and can even pounce, but are not much tougher than a drone.")) + to_chat(larva, span_name("Sentinels are tasked with protecting the hive. With their ranged spit, invisibility, and high health, they make formidable guardians and acceptable secondhand hunters.")) + to_chat(larva, span_name("Drones are the weakest and slowest of the castes, but can grow into a praetorian and then queen if no queen exists, and are vital to maintaining a hive with their resin secretion abilities.")) + var/alien_caste = tgui_input_list(larva, "Please choose which alien caste you shall belong to.",,list("Hunter","Sentinel","Drone")) + + if(larva.movement_type & VENTCRAWLING) + to_chat(user, span_warning("You cannot evolve while ventcrawling!")) + return + + if(user.incapacitated()) //something happened to us while we were choosing. + return + + var/mob/living/carbon/alien/humanoid/new_xeno + switch(alien_caste) + if("Hunter") + new_xeno = new /mob/living/carbon/alien/humanoid/hunter(larva.loc) + if("Sentinel") + new_xeno = new /mob/living/carbon/alien/humanoid/sentinel(larva.loc) + if("Drone") + new_xeno = new /mob/living/carbon/alien/humanoid/drone(larva.loc) + + larva.alien_evolve(new_xeno) + return + diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 9a39ccdd480..1beceee84b0 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -306,7 +306,7 @@ var/maxFine = CONFIG_GET(number/maxfine) var/t1 = tgui_input_text(usr, "Citation crime", "Security HUD") var/fine = tgui_input_number(usr, "Citation fine", "Security HUD", 50, maxFine, 5) - if(isnull(fine)) + if(!fine) return //if(!R || !t1 || !allowed_access) // ORIGINAL if(!sec_record || !t1 || !allowed_access) // SKYRAT EDIT CHANGE - EXAMINE RECORDS @@ -315,8 +315,6 @@ return if(!HAS_TRAIT(H, TRAIT_SECURITY_HUD)) return - fine = round(fine) - fine = min(fine, maxFine) var/datum/data/crime/crime = GLOB.data_core.createCrimeEntry(t1, "", allowed_access, station_time_timestamp(), fine) for (var/obj/item/pda/P in GLOB.PDAs) diff --git a/code/modules/mob/living/silicon/ai/ai.dm b/code/modules/mob/living/silicon/ai/ai.dm index ceb93d99ad5..733123a10e9 100644 --- a/code/modules/mob/living/silicon/ai/ai.dm +++ b/code/modules/mob/living/silicon/ai/ai.dm @@ -598,9 +598,9 @@ if(incapacitated()) return var/input - switch(tgui_alert(usr,"Would you like to select a hologram based on a custom character, an animal, or switch to a unique avatar?",,list("Custom Character","Unique","Animal"))) + switch(tgui_input_list(usr, "Would you like to select a hologram based on a custom character, an animal, or switch to a unique avatar?", "Customize", list("Custom Character","Unique","Animal"))) if("Custom Character") - switch(tgui_alert(usr,"Would you like to base it off of your current character loadout, or a member on station?",,list("My Character","Station Member"))) + switch(tgui_alert(usr,"Would you like to base it off of your current character loadout, or a member on station?", "Customize", list("My Character","Station Member"))) if("Station Member") var/list/personnel_list = list() @@ -621,7 +621,7 @@ holo_icon = getHologramIcon(icon(character_icon)) if("My Character") - switch(tgui_alert(usr,"WARNING: Your AI hologram will take the appearance of your currently selected character ([usr.client.prefs?.read_preference(/datum/preference/name/real_name)]). Are you sure you want to proceed?",,list("Yes","No"))) + switch(tgui_alert(usr,"WARNING: Your AI hologram will take the appearance of your currently selected character ([usr.client.prefs?.read_preference(/datum/preference/name/real_name)]). Are you sure you want to proceed?", "Customize", list("Yes","No"))) if("Yes") var/mob/living/carbon/human/dummy/ai_dummy = new var/mutable_appearance/appearance = usr.client.prefs.render_new_preview_appearance(ai_dummy) diff --git a/code/modules/mob/living/simple_animal/friendly/drone/interaction.dm b/code/modules/mob/living/simple_animal/friendly/drone/interaction.dm index 790ed345d14..c2a3ec82b3d 100644 --- a/code/modules/mob/living/simple_animal/friendly/drone/interaction.dm +++ b/code/modules/mob/living/simple_animal/friendly/drone/interaction.dm @@ -6,28 +6,27 @@ //How the world interacts with drones -/mob/living/simple_animal/drone/attack_drone(mob/living/simple_animal/drone/D) - if(D != src && stat == DEAD) - var/d_input = tgui_alert(D,"Perform which action?","Drone Interaction",list("Reactivate","Cannibalize","Nothing")) - if(d_input) - switch(d_input) - if("Reactivate") - try_reactivate(D) - - if("Cannibalize") - if(D.health < D.maxHealth) - D.visible_message(span_notice("[D] begins to cannibalize parts from [src]."), span_notice("You begin to cannibalize parts from [src]...")) - if(do_after(D, 60, 0, target = src)) - D.visible_message(span_notice("[D] repairs itself using [src]'s remains!"), span_notice("You repair yourself using [src]'s remains.")) - D.adjustBruteLoss(-src.maxHealth) - new /obj/effect/decal/cleanable/oil/streak(get_turf(src)) - qdel(src) - else - to_chat(D, span_warning("You need to remain still to cannibalize [src]!")) - else - to_chat(D, span_warning("You're already in perfect condition!")) - if("Nothing") - return +/mob/living/simple_animal/drone/attack_drone(mob/living/simple_animal/drone/drone) + if(drone == src || stat != DEAD) + return FALSE + var/input = tgui_alert(drone, "Perform which action?", "Drone Interaction", list("Reactivate", "Cannibalize")) + if(!input) + return FALSE + switch(input) + if("Reactivate") + try_reactivate(drone) + if("Cannibalize") + if(drone.health >= drone.maxHealth) + to_chat(drone, span_warning("You're already in perfect condition!")) + return + drone.visible_message(span_notice("[drone] begins to cannibalize parts from [src]."), span_notice("You begin to cannibalize parts from [src]...")) + if(do_after(drone, 60, 0, target = src)) + drone.visible_message(span_notice("[drone] repairs itself using [src]'s remains!"), span_notice("You repair yourself using [src]'s remains.")) + drone.adjustBruteLoss(-src.maxHealth) + new /obj/effect/decal/cleanable/oil/streak(get_turf(src)) + qdel(src) + else + to_chat(drone, span_warning("You need to remain still to cannibalize [src]!")) //ATTACK HAND IGNORING PARENT RETURN VALUE /mob/living/simple_animal/drone/attack_hand(mob/user, list/modifiers) diff --git a/code/modules/paperwork/pen.dm b/code/modules/paperwork/pen.dm index f7674f46dfd..1381048fe05 100644 --- a/code/modules/paperwork/pen.dm +++ b/code/modules/paperwork/pen.dm @@ -126,11 +126,12 @@ . = ..() if(.) return - - var/deg = tgui_input_number(user, "What angle would you like to rotate the pen head to? (1-360)", "Rotate Pen Head", max_value = 360) - if(isnull(deg)) + if(loc != user) + to_chat(user, span_warning("You must be holding the pen to continue!")) + return + var/deg = tgui_input_number(user, "What angle would you like to rotate the pen head to? (0-360)", "Rotate Pen Head", max_value = 360) + if(isnull(deg) || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK) || loc != user) return - degrees = round(deg) to_chat(user, span_notice("You rotate the top of the pen to [degrees] degrees.")) SEND_SIGNAL(src, COMSIG_PEN_ROTATED, deg, user) @@ -148,7 +149,7 @@ . = ..() //Changing name/description of items. Only works if they have the UNIQUE_RENAME object flag set if(isobj(O) && proximity && (O.obj_flags & UNIQUE_RENAME)) - var/penchoice = tgui_alert(user, "What would you like to edit?", "Pen Setting", list("Rename","Description","Reset")) + var/penchoice = tgui_input_list(user, "What would you like to edit?", "Pen Setting", list("Rename", "Description", "Reset")) if(QDELETED(O) || !user.canUseTopic(O, BE_CLOSE)) return if(penchoice == "Rename") diff --git a/code/modules/photography/camera/camera.dm b/code/modules/photography/camera/camera.dm index db98f5a914d..524105db2c0 100644 --- a/code/modules/photography/camera/camera.dm +++ b/code/modules/photography/camera/camera.dm @@ -57,14 +57,18 @@ . += span_notice("Alt-click to change its focusing, allowing you to set how big of an area it will capture.") /obj/item/camera/proc/adjust_zoom(mob/user) + if(loc != user) + to_chat(user, span_warning("You must be holding the camera to continue!")) + return FALSE var/desired_x = tgui_input_number(user, "How wide do you want the camera to shoot?", "Zoom", picture_size_x, picture_size_x_max, picture_size_x_min) - if (isnull(desired_x)) - return + if(!desired_x || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK) || loc != user) + return FALSE var/desired_y = tgui_input_number(user, "How high do you want the camera to shoot", "Zoom", picture_size_y, picture_size_y_max, picture_size_y_min) - if (isnull(desired_y)) - return + if(!desired_y|| QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK) || loc != user) + return FALSE picture_size_x = min(clamp(desired_x, picture_size_x_min, picture_size_x_max), CAMERA_PICTURE_SIZE_HARD_LIMIT) picture_size_y = min(clamp(desired_y, picture_size_y_min, picture_size_y_max), CAMERA_PICTURE_SIZE_HARD_LIMIT) + return TRUE /obj/item/camera/AltClick(mob/user) if(!user.canUseTopic(src, BE_CLOSE)) diff --git a/code/modules/plumbing/plumbers/bottler.dm b/code/modules/plumbing/plumbers/bottler.dm index ca560240b8b..b83c073bb8f 100644 --- a/code/modules/plumbing/plumbers/bottler.dm +++ b/code/modules/plumbing/plumbers/bottler.dm @@ -67,10 +67,10 @@ if(!valid_output_configuration) to_chat(user, span_warning("A flashing notification on the screen reads: \"Output location error!\"")) return . - var/new_amount = tgui_input_number(user, "Set Amount to Fill", "Desired Amount", 1, 100, 1) - if(isnull(new_amount)) + var/new_amount = tgui_input_number(user, "Set Amount to Fill", "Desired Amount", max_value = 100) + if(!new_amount || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return . - wanted_amount = round(new_amount) + wanted_amount = new_amount to_chat(user, span_notice(" The [src] will now fill for [wanted_amount]u.")) /obj/machinery/plumbing/bottler/process() diff --git a/code/modules/plumbing/plumbers/plumbing_buffer.dm b/code/modules/plumbing/plumbers/plumbing_buffer.dm index 6d706abf0bf..4ffd7fe0874 100644 --- a/code/modules/plumbing/plumbers/plumbing_buffer.dm +++ b/code/modules/plumbing/plumbers/plumbing_buffer.dm @@ -78,10 +78,9 @@ . = SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN var/new_volume = tgui_input_number(user, "Enter new activation threshold", "Beepityboop", activation_volume, buffer) - if(isnull(new_volume)) + if(!new_volume || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - - activation_volume = round(new_volume) + activation_volume = new_volume to_chat(user, span_notice("New activation threshold is now [activation_volume].")) return diff --git a/code/modules/projectiles/pins.dm b/code/modules/projectiles/pins.dm index cd245580efb..e95657c816a 100644 --- a/code/modules/projectiles/pins.dm +++ b/code/modules/projectiles/pins.dm @@ -261,12 +261,12 @@ pin_owner = null owned = FALSE return - var/transaction_amount = tgui_input_number(user, "Insert valid deposit amount for gun purchase", "Money Deposit", 1, 10000, 1) - if(isnull(transaction_amount)) + var/transaction_amount = tgui_input_number(user, "Insert valid deposit amount for gun purchase", "Money Deposit") + if(!transaction_amount || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return pin_owner = id owned = TRUE - payment_amount = round(transaction_amount) + payment_amount = transaction_amount gun_owners += user to_chat(user, span_notice("You link the card to the firing pin.")) diff --git a/code/modules/tgui/tgui_alert.dm b/code/modules/tgui/tgui_alert.dm index 83a26c29632..d7821d7e7be 100644 --- a/code/modules/tgui/tgui_alert.dm +++ b/code/modules/tgui/tgui_alert.dm @@ -10,7 +10,7 @@ * * timeout - The timeout of the alert, after which the modal will close and qdel itself. Set to zero for no timeout. * * autofocus - The bool that controls if this alert should grab window focus. */ -/proc/tgui_alert(mob/user, message = null, title = null, list/buttons = list("Ok"), timeout = 0, autofocus = TRUE) +/proc/tgui_alert(mob/user, message = "", title, list/buttons = list("Ok"), timeout = 0, autofocus = TRUE) if (!user) user = usr if (!istype(user)) @@ -39,7 +39,7 @@ * * timeout - The timeout of the alert, after which the modal will close and qdel itself. Disabled by default, can be set to seconds otherwise. * * autofocus - The bool that controls if this alert should grab window focus. */ -/proc/tgui_alert_async(mob/user, message = null, title = null, list/buttons = list("Ok"), datum/callback/callback, timeout = 0, autofocus = TRUE) +/proc/tgui_alert_async(mob/user, message = "", title, list/buttons = list("Ok"), datum/callback/callback, timeout = 0, autofocus = TRUE) if (!user) user = usr if (!istype(user)) @@ -76,10 +76,10 @@ var/closed /datum/tgui_modal/New(mob/user, message, title, list/buttons, timeout, autofocus) - src.title = title - src.message = message - src.buttons = buttons.Copy() src.autofocus = autofocus + src.buttons = buttons.Copy() + src.message = message + src.title = title if (timeout) src.timeout = timeout start_time = world.time @@ -111,14 +111,19 @@ /datum/tgui_modal/ui_state(mob/user) return GLOB.always_state -/datum/tgui_modal/ui_data(mob/user) +/datum/tgui_modal/ui_static_data(mob/user) . = list( - "title" = title, - "message" = message, + "autofocus" = autofocus, "buttons" = buttons, - "autofocus" = autofocus + "message" = message, + "preferences" = list(), + "title" = title ) + .["preferences"]["large_buttons"] = user.client.prefs.read_preference(/datum/preference/toggle/tgui_input_large) + .["preferences"]["swapped_buttons"] = user.client.prefs.read_preference(/datum/preference/toggle/tgui_input_swapped) +/datum/tgui_modal/ui_data(mob/user) + . = list() if(timeout) .["timeout"] = CLAMP01((timeout - (world.time - start_time) - 1 SECONDS) / (timeout - 1 SECONDS)) @@ -129,8 +134,13 @@ switch(action) if("choose") if (!(params["choice"] in buttons)) - return + CRASH("[usr] entered a non-existent button choice: [params["choice"]]") set_choice(params["choice"]) + closed = TRUE + SStgui.close_uis(src) + return TRUE + if("cancel") + closed = TRUE SStgui.close_uis(src) return TRUE diff --git a/code/modules/tgui/tgui_input_list.dm b/code/modules/tgui/tgui_input_list.dm index 1838692dcb8..b7791f7eedd 100644 --- a/code/modules/tgui/tgui_input_list.dm +++ b/code/modules/tgui/tgui_input_list.dm @@ -167,11 +167,12 @@ if (!(params["entry"] in items)) return set_choice(items_map[params["entry"]]) + closed = TRUE SStgui.close_uis(src) return TRUE if("cancel") - SStgui.close_uis(src) closed = TRUE + SStgui.close_uis(src) return TRUE /datum/tgui_list_input/proc/set_choice(choice) diff --git a/code/modules/tgui/tgui_input_number.dm b/code/modules/tgui/tgui_input_number.dm index 3d23a9ef0da..8930dc2ed03 100644 --- a/code/modules/tgui/tgui_input_number.dm +++ b/code/modules/tgui/tgui_input_number.dm @@ -14,7 +14,7 @@ * * 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. */ -/proc/tgui_input_number(mob/user, message, title = "Number Input", default = 0, max_value, 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) if (!user) user = usr if (!istype(user)) @@ -25,7 +25,7 @@ return // Client does NOT have tgui_input on: Returns regular input if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input)) - return input(user, message, title, default) as null|num + 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) number_input.ui_interact(user) number_input.wait() @@ -48,7 +48,7 @@ * * 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. */ -/proc/tgui_input_number_async(mob/user, message, title = "Number Input", default = 0, max_value, 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) if (!user) user = usr if (!istype(user)) @@ -59,7 +59,7 @@ return // Client does NOT have tgui_input on: Returns regular input if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input)) - return input(user, message, title, default) as null|num + 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) number_input.ui_interact(user) @@ -108,6 +108,8 @@ /// Sanity check if(default < min_value) src.default = min_value + if(default > max_value) + CRASH("Default value is greater than max value.") /datum/tgui_input_number/Destroy(force, ...) SStgui.close_uis(src) @@ -158,15 +160,19 @@ return switch(action) if("submit") - if(max_value && (params["entry"] > max_value)) - return FALSE - if(min_value && (params["entry"] < min_value)) - return FALSE - set_entry(params["entry"]) + if(!isnum(params["entry"])) + CRASH("A non number was input into tgui input number by [usr]") + var/choice = round(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) + CRASH("A number less than the min value was input into tgui input number by [usr]") + set_entry(choice) + closed = TRUE SStgui.close_uis(src) return TRUE if("cancel") - set_entry(null) + closed = TRUE SStgui.close_uis(src) return TRUE diff --git a/code/modules/tgui/tgui_input_text.dm b/code/modules/tgui/tgui_input_text.dm index c7391ad724a..14a13afa6b2 100644 --- a/code/modules/tgui/tgui_input_text.dm +++ b/code/modules/tgui/tgui_input_text.dm @@ -68,13 +68,16 @@ return // Client does NOT have tgui_input on: Returns regular input if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input)) - if(max_length) + if(encode) if(multiline) return stripped_multiline_input(user, message, title, default, max_length) else return stripped_input(user, message, title, default, max_length) else - return input(user, message, title, default) as text|null + if(multiline) + return input(user, message, title, default) as message|null + else + return input(user, message, title, default) as text|null var/datum/tgui_input_text/async/text_input = new(user, message, title, default, max_length, multiline, encode, callback, timeout) text_input.ui_interact(user) @@ -170,23 +173,20 @@ if("submit") if(max_length) if(length(params["entry"]) > max_length) - return FALSE + CRASH("[usr] typed a text string longer than the max length") if(encode && (length(html_encode(params["entry"])) > max_length)) to_chat(usr, span_notice("Input uses special characters, thus reducing the maximum length.")) - if(!length(params["entry"])) - set_entry(null) - SStgui.close_uis(src) - return TRUE set_entry(params["entry"]) + closed = TRUE SStgui.close_uis(src) return TRUE if("cancel") - set_entry(null) + closed = TRUE SStgui.close_uis(src) return TRUE /datum/tgui_input_text/proc/set_entry(entry) - if(entry) + if(!isnull(entry)) var/converted_entry = encode ? html_encode(entry) : entry src.entry = trim(converted_entry, max_length) diff --git a/code/modules/vending/_vending.dm b/code/modules/vending/_vending.dm index d2cd7a45fbc..f2f80cb7f69 100644 --- a/code/modules/vending/_vending.dm +++ b/code/modules/vending/_vending.dm @@ -1303,10 +1303,13 @@ GLOBAL_LIST_EMPTY(vending_products) var/price = 1 /obj/item/price_tagger/attack_self(mob/user) - var/chosen_price = tgui_input_number(user, "Set price", "Price", price) - if(isnull(chosen_price)) + if(loc != user) + to_chat(user, span_warning("You must be holding the price tagger to continue!")) return - price = round(chosen_price) + var/chosen_price = tgui_input_number(user, "Set price", "Price", price) + if(!chosen_price || QDELETED(user) || QDELETED(src) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK) || loc != user) + return + price = chosen_price to_chat(user, span_notice(" The [src] will now give things a [price] cr tag.")) /obj/item/price_tagger/afterattack(atom/target, mob/user, proximity) diff --git a/tgui/packages/tgui/components/RestrictedInput.js b/tgui/packages/tgui/components/RestrictedInput.js index c4ee1ea1a0d..0a6e2cb440c 100644 --- a/tgui/packages/tgui/components/RestrictedInput.js +++ b/tgui/packages/tgui/components/RestrictedInput.js @@ -68,10 +68,10 @@ export class RestrictedInput extends Component { const safeNum = getClampedNumber(e.target.value, minValue, maxValue); this.setEditing(false); if (onChange) { - onChange(e, safeNum); + onChange(e, +safeNum); } if (onEnter) { - onEnter(e, safeNum); + onEnter(e, +safeNum); } e.target.blur(); return; diff --git a/tgui/packages/tgui/interfaces/AlertModal.js b/tgui/packages/tgui/interfaces/AlertModal.js deleted file mode 100644 index 08b78751fb4..00000000000 --- a/tgui/packages/tgui/interfaces/AlertModal.js +++ /dev/null @@ -1,136 +0,0 @@ -/** - * @file - * @copyright 2020 bobbahbrown (https://github.com/bobbahbrown) - * @license MIT - */ - -import { Loader } from "./common/Loader"; -import { useBackend } from '../backend'; -import { Component, createRef } from 'inferno'; -import { Box, Flex, Section } from '../components'; -import { Window } from '../layouts'; -import { - KEY_ENTER, - KEY_LEFT, - KEY_RIGHT, - KEY_SPACE, - KEY_TAB, -} from 'common/keycodes'; - -export class AlertModal extends Component { - constructor() { - super(); - - this.buttonRefs = [createRef()]; - this.state = { current: 0 }; - } - - componentDidMount() { - const { data } = useBackend(this.context); - const { buttons, autofocus } = data; - const { current } = this.state; - const button = this.buttonRefs[current].current; - - // Fill ref array with refs for other buttons - for (let i = 1; i < buttons.length; i++) { - this.buttonRefs.push(createRef()); - } - - if (autofocus) { - setTimeout(() => button.focus(), 1); - } - } - - setCurrent(current, isArrowKey) { - const { data } = useBackend(this.context); - const { buttons } = data; - - // Mimic alert() behavior for tabs and arrow keys - if (current >= buttons.length) { - current = isArrowKey ? current - 1 : 0; - } else if (current < 0) { - current = isArrowKey ? 0 : buttons.length - 1; - } - - const button = this.buttonRefs[current].current; - - // Prevents an error from occurring on close - if (button) { - setTimeout(() => button.focus(), 1); - } - this.setState({ current }); - } - - render() { - const { act, data } = useBackend(this.context); - const { title, message, buttons, timeout } = data; - const { current } = this.state; - const focusCurrentButton = () => this.setCurrent(current, false); - - return ( - - {timeout && } - -
- - - - - - {message} - - - - - - - {buttons.map((button, buttonIndex) => ( - -
act("choose", { choice: button })} - onKeyDown={e => { - const keyCode = window.event ? e.which : e.keyCode; - - /** - * Simulate a click when pressing space or enter, - * allow keyboard navigation, override tab behavior - */ - if (keyCode === KEY_SPACE || keyCode === KEY_ENTER) { - act("choose", { choice: button }); - } else if ( - keyCode === KEY_LEFT - || (e.shiftKey && keyCode === KEY_TAB) - ) { - this.setCurrent(current - 1, keyCode === KEY_LEFT); - } else if ( - keyCode === KEY_RIGHT || keyCode === KEY_TAB - ) { - this.setCurrent(current + 1, keyCode === KEY_RIGHT); - } - }}> - {button} -
-
- ))} -
-
-
-
-
-
- ); - } - -} - diff --git a/tgui/packages/tgui/interfaces/AlertModal.tsx b/tgui/packages/tgui/interfaces/AlertModal.tsx new file mode 100644 index 00000000000..accde324d62 --- /dev/null +++ b/tgui/packages/tgui/interfaces/AlertModal.tsx @@ -0,0 +1,151 @@ +import { Loader } from './common/Loader'; +import { Preferences } from './common/InputButtons'; +import { useBackend, useLocalState } from '../backend'; +import { + KEY_ESCAPE, + KEY_ENTER, + KEY_LEFT, + KEY_RIGHT, + KEY_SPACE, + KEY_TAB, +} from '../../common/keycodes'; +import { Autofocus, Box, Button, Flex, Section, Stack } from '../components'; +import { Window } from '../layouts'; + +type AlertModalData = { + autofocus: boolean; + buttons: string[]; + message: string; + preferences: Preferences; + timeout: number; + title: string; +}; + +const KEY_DECREMENT = -1; +const KEY_INCREMENT = 1; + +export const AlertModal = (_, context) => { + const { act, data } = useBackend(context); + const { autofocus, buttons = [], message, timeout, title } = data; + const { large_buttons } = data.preferences; + const [selected, setSelected] = useLocalState(context, 'selected', 0); + // Dynamically sets window height + const windowHeight + = 100 + + Math.ceil(message.length / 3) + + (message.length && large_buttons ? 5 : 0) + + (buttons.length > 2 ? buttons.length * 12 : 0); + const onKey = (direction: number) => { + if (selected === 0 && direction === KEY_DECREMENT) { + setSelected(buttons.length - 1); + } else if (selected === buttons.length - 1 && direction === KEY_INCREMENT) { + setSelected(0); + } else { + setSelected(selected + direction); + } + }; + + return ( + + {timeout && } + { + const keyCode = window.event ? e.which : e.keyCode; + /** + * Simulate a click when pressing space or enter, + * allow keyboard navigation, override tab behavior + */ + if (keyCode === KEY_SPACE || keyCode === KEY_ENTER) { + act('choose', { choice: buttons[selected] }); + } else if (keyCode === KEY_ESCAPE) { + act('cancel'); + } else if ( + keyCode === KEY_LEFT + || (e.shiftKey && keyCode === KEY_TAB) + ) { + onKey(KEY_DECREMENT); + } else if (keyCode === KEY_RIGHT || keyCode === KEY_TAB) { + onKey(KEY_INCREMENT); + } + }}> +
+ + + {message} + + + {autofocus && } + + + +
+
+
+ ); +}; + +/** + * Displays a list of buttons ordered by user prefs. + * Technically this handles more than 2 buttons, but you + * should just be using a list input in that case. + */ +const ButtonDisplay = (props, context) => { + const { data } = useBackend(context); + const { buttons = [] } = data; + const { selected } = props; + const { large_buttons, swapped_buttons } = data.preferences; + + return ( + + {buttons?.map((button, index) => + !large_buttons ? ( + + + + ) : ( + + + + ) + )} + + ); +}; + +/** + * Displays a button with variable sizing. + */ +const AlertButton = (props, context) => { + const { act, data } = useBackend(context); + const { button, selected } = props; + const { large_buttons } = data.preferences; + + return ( + + ); +}; diff --git a/tgui/packages/tgui/interfaces/ListInputModal.tsx b/tgui/packages/tgui/interfaces/ListInputModal.tsx index 0f2fe0b7db7..39929ad937c 100644 --- a/tgui/packages/tgui/interfaces/ListInputModal.tsx +++ b/tgui/packages/tgui/interfaces/ListInputModal.tsx @@ -162,7 +162,7 @@ export const ListInputModal = (_, context) => { selected={selected} /> )} - + diff --git a/tgui/packages/tgui/interfaces/NumberInputModal.tsx b/tgui/packages/tgui/interfaces/NumberInputModal.tsx index bad1e2df6f5..f216a219c0b 100644 --- a/tgui/packages/tgui/interfaces/NumberInputModal.tsx +++ b/tgui/packages/tgui/interfaces/NumberInputModal.tsx @@ -2,7 +2,7 @@ import { Loader } from './common/Loader'; import { InputButtons, Preferences } from './common/InputButtons'; import { KEY_ENTER, KEY_ESCAPE } from '../../common/keycodes'; import { useBackend, useLocalState } from '../backend'; -import { Box, Button, NumberInput, Section, Stack } from '../components'; +import { Box, Button, RestrictedInput, Section, Stack } from '../components'; import { Window } from '../layouts'; type NumberInputData = { @@ -34,7 +34,7 @@ export const NumberInputModal = (_, context) => { }; // Dynamically changes the window height based on the message. const windowHeight - = 125 + = 130 + Math.ceil(message.length / 3) + (message.length && large_buttons ? 5 : 0); @@ -53,13 +53,13 @@ export const NumberInputModal = (_, context) => { }}>
- + {message} - + @@ -71,7 +71,7 @@ export const NumberInputModal = (_, context) => { /** Gets the user input and invalidates if there's a constraint. */ const InputArea = (props, context) => { - const { data } = useBackend(context); + const { act, data } = useBackend(context); const { min_value, max_value, init_value } = data; const { input, onClick, onChange } = props; @@ -81,25 +81,25 @@ const InputArea = (props, context) => {