Skip to content

Commit

Permalink
i alone am the honoured one
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Atlas committed Sep 27, 2023
1 parent 86bdf91 commit f900006
Show file tree
Hide file tree
Showing 16 changed files with 1,313 additions and 15 deletions.
4 changes: 4 additions & 0 deletions aurorastation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -3373,6 +3373,10 @@
#include "code\modules\tgui\states\reverse_contained.dm"
#include "code\modules\tgui\states\self.dm"
#include "code\modules\tgui\states\zlevel.dm"
#include "code\modules\tgui_input\alert.dm"
#include "code\modules\tgui_input\list.dm"
#include "code\modules\tgui_input\number.dm"
#include "code\modules\tgui_input\text.dm"
#include "code\modules\tgui_panel\audio.dm"
#include "code\modules\tgui_panel\external.dm"
#include "code\modules\tgui_panel\tgui_panel.dm"
Expand Down
12 changes: 6 additions & 6 deletions code/__defines/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@

// 0x1 is free.
// 0x2 is free.
#define PROGRESS_BARS 0x4
#define PARALLAX_IS_STATIC 0x8
#define FLOATING_MESSAGES 0x10
#define HOTKEY_DEFAULT 0x20
#define FULLSCREEN_MODE 0x40
#define ACCENT_TAG_TEXT 0x80
#define PROGRESS_BARS 0x4
#define PARALLAX_IS_STATIC 0x8
#define FLOATING_MESSAGES 0x10
#define HOTKEY_DEFAULT 0x20
#define FULLSCREEN_MODE 0x40
#define ACCENT_TAG_TEXT 0x80

#define TOGGLES_DEFAULT (SOUND_ADMINHELP | SOUND_MIDI | SOUND_LOBBY | CHAT_OOC | CHAT_DEAD | CHAT_GHOSTEARS | CHAT_GHOSTSIGHT | CHAT_PRAYER | CHAT_RADIO | CHAT_ATTACKLOGS | CHAT_LOOC | CHAT_GHOSTLOOC)

Expand Down
12 changes: 12 additions & 0 deletions code/_helpers/lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,15 @@
. += M
else
. += flatten_list(M)

///takes an input_key, as text, and the list of keys already used, outputting a replacement key in the format of "[input_key] ([number_of_duplicates])" if it finds a duplicate
///use this for lists of things that might have the same name, like mobs or objects, that you plan on giving to a player as input
/proc/avoid_assoc_duplicate_keys(input_key, list/used_key_list)
if(!input_key || !istype(used_key_list))
return
if(used_key_list[input_key])
used_key_list[input_key]++
input_key = "[input_key] ([used_key_list[input_key]])"
else
used_key_list[input_key] = 1
return input_key
38 changes: 38 additions & 0 deletions code/_helpers/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -767,3 +767,41 @@
return "[text]es"
return "[text]s"
return ""

/**
* Used to get a properly sanitized input. Returns null if cancel is pressed.
*
* Arguments
** user - Target of the input prompt.
** message - The text inside of the prompt.
** title - The window title of the prompt.
** max_length - If you intend to impose a length limit - default is 1024.
** no_trim - Prevents the input from being trimmed if you intend to parse newlines or whitespace.
*/
/proc/stripped_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN, no_trim=FALSE)
var/user_input = input(user, message, title, default) as text|null
if(isnull(user_input)) // User pressed cancel
return
if(no_trim)
return copytext(html_encode(user_input), 1, max_length)
else
return trim(html_encode(user_input), max_length) //trim is "outside" because html_encode can expand single symbols into multiple symbols (such as turning < into &lt;)

/**
* Used to get a properly sanitized input in a larger box. Works very similarly to stripped_input.
*
* Arguments
** user - Target of the input prompt.
** message - The text inside of the prompt.
** title - The window title of the prompt.
** max_length - If you intend to impose a length limit - default is 1024.
** no_trim - Prevents the input from being trimmed if you intend to parse newlines or whitespace.
*/
/proc/stripped_multiline_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN, no_trim=FALSE)
var/user_input = input(user, message, title, default) as message|null
if(isnull(user_input)) // User pressed cancel
return
if(no_trim)
return copytext(html_encode(user_input), 1, max_length)
else
return trim(html_encode(user_input), max_length)
15 changes: 9 additions & 6 deletions code/game/verbs/ooc.dm
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@

/client/verb/ooc(msg as text)
/client/verb/ooc()
set name = "OOC"
set category = "OOC"

if(say_disabled) //This is here to try to identify lag problems
to_chat(usr, "<span class='warning'>Speech is currently admin-disabled.</span>")
return

if(!mob) return
if(!mob)
return

if(IsGuestKey(key))
to_chat(src, "Guests may not use OOC.")
return

msg = sanitize(msg)
if(!msg) return
var/msg = tgui_input_text(src, "Enter an OOC message.", "OOC")
if(!msg)
return

if(!(prefs.toggles & CHAT_OOC))
to_chat(src, "<span class='warning'>You have OOC muted.</span>")
Expand Down Expand Up @@ -62,7 +65,7 @@
else
to_chat(target, "<span class='ooc'><span class='[ooc_style]'>" + create_text_tag("OOC", target) + " <EM>[display_name]:</EM> <span class='message linkify'>[msg]</span></span></span>")

/client/verb/looc(msg as text)
/client/verb/looc()
set name = "LOOC"
set desc = "Local OOC, seen only by those in view."
set category = "OOC"
Expand All @@ -78,7 +81,7 @@
to_chat(src, "Guests may not use OOC.")
return

msg = sanitize(msg)
var/msg = tgui_input_text(src, "Enter an LOOC message.", "OOC")
msg = process_chat_markup(msg, list("*"))
if(!msg)
return
Expand Down
15 changes: 15 additions & 0 deletions code/modules/client/preference_setup/global/01_ui.dm
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
dat += "<b>Tooltip Style:</b> <a href='?src=\ref[src];select_tooltip_style=1'><b>[pref.tooltip_style]</b></a><br>"
dat += "<b>TGUI Fancy:</b> <a href='?src=\ref[src];select_tguif=1'><b>[pref.tgui_fancy ? "ON" : "OFF"]</b></a><br>"
dat += "<b>TGUI Lock:</b> <a href='?src=\ref[src];select_tguil=1'><b>[pref.tgui_lock ? "ON" : "OFF"]</b></a><br>"
dat += "<b>TGUI Inputs:</b> <a href='?src=\ref[src];tgui_inputs=1'><b>[pref.tgui_inputs ? "ON" : "OFF"]</b></a><br>"
dat += "<b>TGUI Input Large Buttons:</b> <a href='?src=\ref[src];tgui_inputs_large=1'><b>[pref.tgui_inputs_large_buttons ? "ON" : "OFF"]</b></a><br>"
dat += "<b>TGUI Input Swapped Buttons:</b> <a href='?src=\ref[src];tgui_inputs_swapped=1'><b>[pref.tgui_inputs_swapped_buttons ? "ON" : "OFF"]</b></a><br>"
dat += "<b>FPS:</b> <a href='?src=\ref[src];select_fps=1'><b>[pref.clientfps]</b></a> - <a href='?src=\ref[src];reset=fps'>reset</a><br>"
if(can_select_ooc_color(user))
dat += "<b>OOC Color:</b> "
Expand Down Expand Up @@ -124,6 +127,18 @@
pref.tgui_lock = !pref.tgui_lock
return TOPIC_REFRESH

else if(href_list["tgui_inputs"])
pref.tgui_inputs = !pref.tgui_inputs
return TOPIC_REFRESH

else if(href_list["tgui_inputs_large"])
pref.tgui_inputs_large_buttons = !pref.tgui_inputs_large_buttons
return TOPIC_REFRESH

else if(href_list["tgui_inputs_swapped"])
pref.tgui_inputs_swapped_buttons = !pref.tgui_inputs_swapped_buttons
return TOPIC_REFRESH

else if(href_list["select_ooc_color"])
var/new_ooccolor = input(user, "Choose OOC color:", "Global Preference") as color|null
if(new_ooccolor && can_select_ooc_color(user) && CanUseTopic(user))
Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var/list/preferences_datums = list()
var/UI_style_alpha = 255
var/tgui_fancy = TRUE
var/tgui_lock = FALSE
var/tgui_inputs = TRUE
var/tgui_inputs_large_buttons = FALSE
var/tgui_inputs_swapped_buttons = FALSE
//Style for popup tooltips
var/tooltip_style = "Midnight"
var/motd_hash = "" //Hashes for the new server greeting window.
Expand Down
6 changes: 3 additions & 3 deletions code/modules/mob/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
set name = ".Say"
set hidden = TRUE
SStyping.set_indicator_state(client, TRUE)
var/message = input("","say (text)") as text|null
var/message = tgui_input_text(src, "Enter a Say message." ,"Say")
SStyping.set_indicator_state(client, FALSE)
if (message)
say_verb(message)
Expand All @@ -100,7 +100,7 @@
set name = ".Me"
set hidden = TRUE
SStyping.set_indicator_state(client, TRUE)
var/message = input("","me (text)") as text|null
var/message = tgui_input_text(src, "Enter a Me message.", "Me")
SStyping.set_indicator_state(client, FALSE)
if (message)
me_verb(message)
Expand All @@ -109,7 +109,7 @@
set name = ".Whisper"
set hidden = TRUE
SStyping.set_indicator_state(client, TRUE)
var/message = input("","me (text)") as text|null
var/message = tgui_input_text(src, "Enter a Whisper message.", "Whisper")
SStyping.set_indicator_state(client, FALSE)
if (message)
whisper(message)
Expand Down
133 changes: 133 additions & 0 deletions code/modules/tgui_input/alert.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* Creates a TGUI alert window and returns the user's response.
*
* This proc should be used to create alerts that the caller will wait for a response from.
* Arguments:
* * user - The user to show the alert to.
* * message - The content of the alert, shown in the body of the TGUI window.
* * title - The of the alert modal, shown on the top of the TGUI window.
* * buttons - The options that can be chosen by the user, each string is assigned a button on the UI.
* * 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 = "", title, list/buttons = list("Ok"), timeout = 0, autofocus = TRUE)
if (!user)
user = usr
if (!istype(user))
if (istype(user, /client))
var/client/client = user
user = client.mob
else
return
// A gentle nudge - you should not be using TGUI alert for anything other than a simple message.
if(length(buttons) > 3)
log_tgui(user, "Error: TGUI Alert initiated with too many buttons. Use a list.", "TguiAlert")
return tgui_input_list(user, message, title, buttons, timeout, autofocus)
// Client does NOT have tgui_input on: Returns regular input
if(!user.client.prefs.tgui_inputs)
if(length(buttons) == 2)
return alert(user, message, title, buttons[1], buttons[2])
if(length(buttons) == 3)
return alert(user, message, title, buttons[1], buttons[2], buttons[3])
var/datum/tgui_alert/alert = new(user, message, title, buttons, timeout, autofocus)
alert.ui_interact(user)
alert.wait()
if (alert)
. = alert.choice
qdel(alert)

/**
* # tgui_alert
*
* Datum used for instantiating and using a TGUI-controlled modal that prompts the user with
* a message and has buttons for responses.
*/
/datum/tgui_alert
/// The title of the TGUI window
var/title
/// The textual body of the TGUI window
var/message
/// The list of buttons (responses) provided on the TGUI window
var/list/buttons
/// The button that the user has pressed, null if no selection has been made
var/choice
/// The time at which the tgui_alert was created, for displaying timeout progress.
var/start_time
/// The lifespan of the tgui_alert, after which the window will close and delete itself.
var/timeout
/// The bool that controls if this modal should grab window focus
var/autofocus
/// Boolean field describing if the tgui_alert was closed by the user.
var/closed

/datum/tgui_alert/New(mob/user, message, title, list/buttons, timeout, autofocus)
src.autofocus = autofocus
src.buttons = buttons.Copy()
src.message = message
src.title = title
if (timeout)
src.timeout = timeout
start_time = world.time
QDEL_IN(src, timeout)

/datum/tgui_alert/Destroy(force, ...)
SStgui.close_uis(src)
QDEL_NULL(buttons)
return ..()

/**
* Waits for a user's response to the tgui_alert's prompt before returning. Returns early if
* the window was closed by the user.
*/
/datum/tgui_alert/proc/wait()
while (!choice && !closed && !QDELETED(src))
stoplag(1)

/datum/tgui_alert/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "AlertModal")
ui.open()

/datum/tgui_alert/ui_close(mob/user)
. = ..()
closed = TRUE

/datum/tgui_alert/ui_state(mob/user)
return always_state

/datum/tgui_alert/ui_static_data(mob/user)
var/list/data = list()
data["autofocus"] = autofocus
data["buttons"] = buttons
data["message"] = message
data["large_buttons"] = user.client.prefs.tgui_inputs_large_buttons
data["swapped_buttons"] = user.client.prefs.tgui_inputs_swapped_buttons
data["title"] = title
return data

/datum/tgui_alert/ui_data(mob/user)
var/list/data = list()
if(timeout)
data["timeout"] = CLAMP01((timeout - (world.time - start_time) - 1 SECONDS) / (timeout - 1 SECONDS))
return data

/datum/tgui_alert/ui_act(action, list/params)
. = ..()
if (.)
return
switch(action)
if("choose")
if (!(params["choice"] in buttons))
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

/datum/tgui_alert/proc/set_choice(choice)
src.choice = choice
Loading

0 comments on commit f900006

Please sign in to comment.