mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-24 04:27:35 +01:00
Converts all tgui_ to ui_
This commit is contained in:
@@ -4,52 +4,52 @@
|
||||
* Allows the handling of logins using IDs within tgui.
|
||||
*
|
||||
* Two key procs:
|
||||
* * [/obj/proc/tgui_login_act] - Call in your tgui_act() proc to catch any login actions and handle them.
|
||||
* * [/obj/proc/tgui_login_data] - Call in your tgui_data() proc to pass login info.
|
||||
* * [/obj/proc/ui_login_act] - Call in your ui_act() proc to catch any login actions and handle them.
|
||||
* * [/obj/proc/ui_login_data] - Call in your ui_data() proc to pass login info.
|
||||
*
|
||||
* How to use (DM side):
|
||||
* 1. Call [/obj/proc/tgui_login_act] at the start of your tgui_act() proc
|
||||
* 2. Call [/obj/proc/tgui_login_data] in your tgui_data() proc while passing the data list
|
||||
* 3. In your object, call [/obj/proc/tgui_login_get] to get the current login state.
|
||||
* 4. Optional: call [/obj/proc/tgui_login_attackby] in your attackby() to make the login process easier.
|
||||
* 1. Call [/obj/proc/ui_login_act] at the start of your ui_act() proc
|
||||
* 2. Call [/obj/proc/ui_login_data] in your ui_data() proc while passing the data list
|
||||
* 3. In your object, call [/obj/proc/ui_login_get] to get the current login state.
|
||||
* 4. Optional: call [/obj/proc/ui_login_attackby] in your attackby() to make the login process easier.
|
||||
*
|
||||
* How to use (JS side): Use the <LoginScreen /> and <LoginInfo /> interfaces.
|
||||
*/
|
||||
|
||||
GLOBAL_LIST(tgui_logins)
|
||||
GLOBAL_LIST(ui_logins)
|
||||
|
||||
/**
|
||||
* Call this from a proc that is called in tgui_act() to process login actions
|
||||
* Call this from a proc that is called in ui_act() to process login actions
|
||||
*
|
||||
* Arguments:
|
||||
* * action - The called action
|
||||
* * params - The params to the action
|
||||
*/
|
||||
/obj/proc/tgui_login_act(action = "", params)
|
||||
/obj/proc/ui_login_act(action = "", params)
|
||||
. = null
|
||||
switch(action)
|
||||
if("login_insert")
|
||||
var/datum/tgui_login/state = tgui_login_get()
|
||||
var/datum/ui_login/state = ui_login_get()
|
||||
if(state.id) // An ID is already inserted, eject it
|
||||
return tgui_login_eject(state = state)
|
||||
return ui_login_eject(state = state)
|
||||
else // No ID, attempt to insert one in
|
||||
return tgui_login_insert(usr.get_active_hand(), state = state)
|
||||
return ui_login_insert(usr.get_active_hand(), state = state)
|
||||
if("login_eject")
|
||||
return tgui_login_eject()
|
||||
return ui_login_eject()
|
||||
if("login_login")
|
||||
return tgui_login_login(text2num(params["login_type"]))
|
||||
return ui_login_login(text2num(params["login_type"]))
|
||||
if("login_logout")
|
||||
return tgui_login_logout()
|
||||
return ui_login_logout()
|
||||
|
||||
/**
|
||||
* Appends login state data.
|
||||
*
|
||||
* Arguments:
|
||||
* * data - The data list to be returned
|
||||
* * user - The user calling tgui_data()
|
||||
* * user - The user calling ui_data()
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_data(list/data, mob/user, datum/tgui_login/state = tgui_login_get())
|
||||
/obj/proc/ui_login_data(list/data, mob/user, datum/ui_login/state = ui_login_get())
|
||||
data["loginState"] = list(
|
||||
"id" = state.id ? state.id.name : null,
|
||||
"name" = state.name,
|
||||
@@ -68,9 +68,9 @@ GLOBAL_LIST(tgui_logins)
|
||||
* * O - The object
|
||||
* * user - The user
|
||||
*/
|
||||
/obj/proc/tgui_login_attackby(obj/item/O, mob/user)
|
||||
if(istype(O, /obj/item/card/id) && tgui_login_insert(O))
|
||||
tgui_interact(user)
|
||||
/obj/proc/ui_login_attackby(obj/item/O, mob/user)
|
||||
if(istype(O, /obj/item/card/id) && ui_login_insert(O))
|
||||
ui_interact(user)
|
||||
return TRUE
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ GLOBAL_LIST(tgui_logins)
|
||||
* * O - The object to try inserting
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_insert(obj/item/O, datum/tgui_login/state = tgui_login_get())
|
||||
/obj/proc/ui_login_insert(obj/item/O, datum/ui_login/state = ui_login_get())
|
||||
if(state.id)
|
||||
return
|
||||
|
||||
@@ -100,7 +100,7 @@ GLOBAL_LIST(tgui_logins)
|
||||
* Arguments:
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_eject(datum/tgui_login/state = tgui_login_get())
|
||||
/obj/proc/ui_login_eject(datum/ui_login/state = ui_login_get())
|
||||
if(!state.id)
|
||||
return
|
||||
|
||||
@@ -121,7 +121,7 @@ GLOBAL_LIST(tgui_logins)
|
||||
* * login_type - The login type: LOGIN_TYPE_NORMAL (checks for inserted ID), LOGIN_TYPE_AI, LOGIN_TYPE_ROBOT and LOGIN_TYPE_ADMIN
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_login(login_type = LOGIN_TYPE_NORMAL, datum/tgui_login/state = tgui_login_get())
|
||||
/obj/proc/ui_login_login(login_type = LOGIN_TYPE_NORMAL, datum/ui_login/state = ui_login_get())
|
||||
if(state.logged_in)
|
||||
return
|
||||
|
||||
@@ -146,7 +146,7 @@ GLOBAL_LIST(tgui_logins)
|
||||
state.access = get_all_accesses() + get_all_centcom_access()
|
||||
|
||||
state.logged_in = TRUE
|
||||
tgui_login_on_login(state = state)
|
||||
ui_login_on_login(state = state)
|
||||
|
||||
return TRUE
|
||||
|
||||
@@ -156,7 +156,7 @@ GLOBAL_LIST(tgui_logins)
|
||||
* Arguments:
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_logout(datum/tgui_login/state = tgui_login_get())
|
||||
/obj/proc/ui_login_logout(datum/ui_login/state = ui_login_get())
|
||||
if(!state.logged_in)
|
||||
return
|
||||
|
||||
@@ -164,7 +164,7 @@ GLOBAL_LIST(tgui_logins)
|
||||
state.rank = ""
|
||||
state.access = null
|
||||
state.logged_in = FALSE
|
||||
tgui_login_on_logout(state = state)
|
||||
ui_login_on_logout(state = state)
|
||||
|
||||
return TRUE
|
||||
|
||||
@@ -174,12 +174,12 @@ GLOBAL_LIST(tgui_logins)
|
||||
* Arguments:
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_get()
|
||||
RETURN_TYPE(/datum/tgui_login)
|
||||
. = LAZYACCESS(GLOB.tgui_logins, UID())
|
||||
/obj/proc/ui_login_get()
|
||||
RETURN_TYPE(/datum/ui_login)
|
||||
. = LAZYACCESS(GLOB.ui_logins, UID())
|
||||
if(!.)
|
||||
LAZYINITLIST(GLOB.tgui_logins)
|
||||
. = GLOB.tgui_logins[UID()] = new /datum/tgui_login
|
||||
LAZYINITLIST(GLOB.ui_logins)
|
||||
. = GLOB.ui_logins[UID()] = new /datum/ui_login
|
||||
|
||||
/**
|
||||
* Called on successful login.
|
||||
@@ -187,7 +187,7 @@ GLOBAL_LIST(tgui_logins)
|
||||
* Arguments:
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_on_login(datum/tgui_login/state = tgui_login_get())
|
||||
/obj/proc/ui_login_on_login(datum/ui_login/state = ui_login_get())
|
||||
return
|
||||
|
||||
/**
|
||||
@@ -196,20 +196,20 @@ GLOBAL_LIST(tgui_logins)
|
||||
* Arguments:
|
||||
* * state - The current login state
|
||||
*/
|
||||
/obj/proc/tgui_login_on_logout(datum/tgui_login/state = tgui_login_get())
|
||||
/obj/proc/ui_login_on_logout(datum/ui_login/state = ui_login_get())
|
||||
return
|
||||
|
||||
/**
|
||||
* Login state (there should be only one for one datum)
|
||||
*/
|
||||
/datum/tgui_login
|
||||
/datum/ui_login
|
||||
var/obj/item/card/id/id = null
|
||||
var/name = ""
|
||||
var/rank = ""
|
||||
var/list/access = null
|
||||
var/logged_in = FALSE
|
||||
|
||||
/datum/tgui_login/New(id, name, rank, access)
|
||||
/datum/ui_login/New(id, name, rank, access)
|
||||
src.id = id
|
||||
src.name = name
|
||||
src.rank = rank
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/**
|
||||
* tgui modals
|
||||
* ui modals
|
||||
*
|
||||
* Allows creation of modals within tgui.
|
||||
*/
|
||||
|
||||
GLOBAL_LIST(tgui_modals)
|
||||
GLOBAL_LIST(ui_modals)
|
||||
|
||||
/**
|
||||
* Call this from a proc that is called in tgui_act() to process modal actions
|
||||
* Call this from a proc that is called in ui_act() to process modal actions
|
||||
*
|
||||
* Example: /obj/machinery/chem_master/proc/tgui_act_modal
|
||||
* Example: /obj/machinery/chem_master/proc/ui_act_modal
|
||||
* You can then switch based on the return value and show different
|
||||
* modals depending on the answer.
|
||||
* Arguments:
|
||||
@@ -17,34 +17,34 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * action - The called action
|
||||
* * params - The params to the action
|
||||
*/
|
||||
/datum/proc/tgui_modal_act(datum/source = src, action = "", params)
|
||||
/datum/proc/ui_modal_act(datum/source = src, action = "", params)
|
||||
ASSERT(istype(source))
|
||||
|
||||
. = null
|
||||
switch(action)
|
||||
if("modal_open") // Params: id, arguments
|
||||
return TGUI_MODAL_OPEN
|
||||
return UI_MODAL_OPEN
|
||||
if("modal_answer") // Params: id, answer, arguments
|
||||
params["answer"] = tgui_modal_preprocess_answer(source, params["answer"])
|
||||
if(tgui_modal_answer(source, params["id"], params["answer"])) // If there's a current modal with a delegate that returned TRUE, no need to continue
|
||||
. = TGUI_MODAL_DELEGATE
|
||||
params["answer"] = ui_modal_preprocess_answer(source, params["answer"])
|
||||
if(ui_modal_answer(source, params["id"], params["answer"])) // If there's a current modal with a delegate that returned TRUE, no need to continue
|
||||
. = UI_MODAL_DELEGATE
|
||||
else
|
||||
. = TGUI_MODAL_ANSWER
|
||||
tgui_modal_clear(source)
|
||||
. = UI_MODAL_ANSWER
|
||||
ui_modal_clear(source)
|
||||
if("modal_close") // Params: id
|
||||
tgui_modal_clear(source)
|
||||
return TGUI_MODAL_CLOSE
|
||||
ui_modal_clear(source)
|
||||
return UI_MODAL_CLOSE
|
||||
|
||||
/**
|
||||
* Call this from tgui_data() to return modal information if needed
|
||||
* Call this from ui_data() to return modal information if needed
|
||||
|
||||
* Arguments:
|
||||
* * source - The source datum
|
||||
*/
|
||||
/datum/proc/tgui_modal_data(datum/source = src)
|
||||
/datum/proc/ui_modal_data(datum/source = src)
|
||||
ASSERT(istype(source))
|
||||
|
||||
var/datum/tgui_modal/current = LAZYACCESS(GLOB.tgui_modals, source.UID())
|
||||
var/datum/ui_modal/current = LAZYACCESS(GLOB.ui_modals, source.UID())
|
||||
if(!current)
|
||||
return null
|
||||
|
||||
@@ -56,25 +56,25 @@ GLOBAL_LIST(tgui_modals)
|
||||
* Arguments:
|
||||
* * source - The source datum
|
||||
*/
|
||||
/datum/proc/tgui_modal_clear(datum/source = src)
|
||||
/datum/proc/ui_modal_clear(datum/source = src)
|
||||
ASSERT(istype(source))
|
||||
|
||||
LAZYINITLIST(GLOB.tgui_modals)
|
||||
var/datum/tgui_modal/previous = GLOB.tgui_modals[source.UID()]
|
||||
LAZYINITLIST(GLOB.ui_modals)
|
||||
var/datum/ui_modal/previous = GLOB.ui_modals[source.UID()]
|
||||
if(!previous)
|
||||
return FALSE
|
||||
|
||||
for(var/i in 1 to length(GLOB.tgui_modals))
|
||||
var/key = GLOB.tgui_modals[i]
|
||||
if(previous == GLOB.tgui_modals[key])
|
||||
GLOB.tgui_modals.Cut(i, i + 1)
|
||||
for(var/i in 1 to length(GLOB.ui_modals))
|
||||
var/key = GLOB.ui_modals[i]
|
||||
if(previous == GLOB.ui_modals[key])
|
||||
GLOB.ui_modals.Cut(i, i + 1)
|
||||
break
|
||||
|
||||
SStgui.update_uis(source)
|
||||
return TRUE
|
||||
|
||||
/**
|
||||
* Opens a message TGUI modal
|
||||
* Opens a message UI modal
|
||||
*
|
||||
* Arguments:
|
||||
* * source - The source datum
|
||||
@@ -83,14 +83,14 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * delegate - The proc to call when closed
|
||||
* * arguments - List of arguments passed to and from JS (mostly useful for chaining modals)
|
||||
*/
|
||||
/datum/proc/tgui_modal_message(datum/source = src, id, text = "Default modal message", delegate, arguments)
|
||||
/datum/proc/ui_modal_message(datum/source = src, id, text = "Default modal message", delegate, arguments)
|
||||
ASSERT(length(id))
|
||||
|
||||
var/datum/tgui_modal/modal = new(id, text, delegate, arguments)
|
||||
return tgui_modal_new(source, modal)
|
||||
var/datum/ui_modal/modal = new(id, text, delegate, arguments)
|
||||
return ui_modal_new(source, modal)
|
||||
|
||||
/**
|
||||
* Opens a text input TGUI modal
|
||||
* Opens a text input UI modal
|
||||
*
|
||||
* Arguments:
|
||||
* * source - The source datum
|
||||
@@ -101,15 +101,15 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * value - The default value of the input
|
||||
* * max_length - The maximum char length of the input
|
||||
*/
|
||||
/datum/proc/tgui_modal_input(datum/source = src, id, text = "Default modal message", delegate, arguments, value = "", max_length = TGUI_MODAL_INPUT_MAX_LENGTH)
|
||||
/datum/proc/ui_modal_input(datum/source = src, id, text = "Default modal message", delegate, arguments, value = "", max_length = UI_MODAL_INPUT_MAX_LENGTH)
|
||||
ASSERT(length(id))
|
||||
ASSERT(max_length > 0)
|
||||
|
||||
var/datum/tgui_modal/input/modal = new(id, text, delegate, arguments, value, max_length)
|
||||
return tgui_modal_new(source, modal)
|
||||
var/datum/ui_modal/input/modal = new(id, text, delegate, arguments, value, max_length)
|
||||
return ui_modal_new(source, modal)
|
||||
|
||||
/**
|
||||
* Opens a dropdown input TGUI modal
|
||||
* Opens a dropdown input UI modal
|
||||
*
|
||||
* Internally checks if the answer is in the list of choices.
|
||||
* Arguments:
|
||||
@@ -121,14 +121,14 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * value - The default value of the dropdown
|
||||
* * choices - The list of available choices in the dropdown
|
||||
*/
|
||||
/datum/proc/tgui_modal_choice(datum/source = src, id, text = "Default modal message", delegate, arguments, value = "", choices)
|
||||
/datum/proc/ui_modal_choice(datum/source = src, id, text = "Default modal message", delegate, arguments, value = "", choices)
|
||||
ASSERT(length(id))
|
||||
|
||||
var/datum/tgui_modal/input/choice/modal = new(id, text, delegate, arguments, value, choices)
|
||||
return tgui_modal_new(source, modal)
|
||||
var/datum/ui_modal/input/choice/modal = new(id, text, delegate, arguments, value, choices)
|
||||
return ui_modal_new(source, modal)
|
||||
|
||||
/**
|
||||
* Opens a bento input TGUI modal
|
||||
* Opens a bento input UI modal
|
||||
*
|
||||
* Internally checks if the answer is in the list of choices.
|
||||
* Arguments:
|
||||
@@ -140,14 +140,14 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * value - The default value of the bento
|
||||
* * choices - The list of available choices in the bento
|
||||
*/
|
||||
/datum/proc/tgui_modal_bento(datum/source = src, id, text = "Default modal message", delegate, arguments, value, choices)
|
||||
/datum/proc/ui_modal_bento(datum/source = src, id, text = "Default modal message", delegate, arguments, value, choices)
|
||||
ASSERT(length(id))
|
||||
|
||||
var/datum/tgui_modal/input/bento/modal = new(id, text, delegate, arguments, value, choices)
|
||||
return tgui_modal_new(source, modal)
|
||||
var/datum/ui_modal/input/bento/modal = new(id, text, delegate, arguments, value, choices)
|
||||
return ui_modal_new(source, modal)
|
||||
|
||||
/**
|
||||
* Opens a yes/no TGUI modal
|
||||
* Opens a yes/no UI modal
|
||||
*
|
||||
* Arguments:
|
||||
* * source - The source datum
|
||||
@@ -159,33 +159,33 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * yes_text - The text to show in the "Yes" button
|
||||
* * no_text - The text to show in the "No" button
|
||||
*/
|
||||
/datum/proc/tgui_modal_boolean(datum/source = src, id, text = "Default modal message", delegate, delegate_no, arguments, yes_text = "Yes", no_text = "No")
|
||||
/datum/proc/ui_modal_boolean(datum/source = src, id, text = "Default modal message", delegate, delegate_no, arguments, yes_text = "Yes", no_text = "No")
|
||||
ASSERT(length(id))
|
||||
|
||||
var/datum/tgui_modal/boolean/modal = new(id, text, delegate, delegate_no, arguments, yes_text, no_text)
|
||||
return tgui_modal_new(source, modal)
|
||||
var/datum/ui_modal/boolean/modal = new(id, text, delegate, delegate_no, arguments, yes_text, no_text)
|
||||
return ui_modal_new(source, modal)
|
||||
|
||||
/**
|
||||
* Registers a given modal to a source. Private.
|
||||
*
|
||||
* Arguments:
|
||||
* * source - The source datum
|
||||
* * modal - The datum/tgui_modal to register
|
||||
* * modal - The datum/ui_modal to register
|
||||
* * replace_previous - Whether any modal currently assigned to source should be replaced
|
||||
* * instant_update - Whether the changes should reflect immediately
|
||||
*/
|
||||
/datum/proc/tgui_modal_new(datum/source = src, datum/tgui_modal/modal = null, replace_previous = TRUE, instant_update = TRUE)
|
||||
/datum/proc/ui_modal_new(datum/source = src, datum/ui_modal/modal = null, replace_previous = TRUE, instant_update = TRUE)
|
||||
ASSERT(istype(source))
|
||||
ASSERT(istype(modal))
|
||||
|
||||
var/datum/tgui_modal/previous = LAZYACCESS(GLOB.tgui_modals, source.UID())
|
||||
var/datum/ui_modal/previous = LAZYACCESS(GLOB.ui_modals, source.UID())
|
||||
if(previous && !replace_previous)
|
||||
return FALSE
|
||||
|
||||
modal.owning_source = source
|
||||
|
||||
// Previous one should get GC'd
|
||||
LAZYSET(GLOB.tgui_modals, source.UID(), modal)
|
||||
LAZYSET(GLOB.ui_modals, source.UID(), modal)
|
||||
if(instant_update)
|
||||
SStgui.update_uis(source)
|
||||
return TRUE
|
||||
@@ -198,10 +198,10 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * id - The ID of the modal
|
||||
* * answer - The provided answer
|
||||
*/
|
||||
/datum/proc/tgui_modal_answer(datum/source = src, id, answer = "")
|
||||
/datum/proc/ui_modal_answer(datum/source = src, id, answer = "")
|
||||
ASSERT(istype(source))
|
||||
|
||||
var/datum/tgui_modal/current = LAZYACCESS(GLOB.tgui_modals, source.UID())
|
||||
var/datum/ui_modal/current = LAZYACCESS(GLOB.ui_modals, source.UID())
|
||||
if(!current)
|
||||
return FALSE
|
||||
|
||||
@@ -216,10 +216,10 @@ GLOBAL_LIST(tgui_modals)
|
||||
* * source - The source datum
|
||||
* * answer - The provided answer
|
||||
*/
|
||||
/datum/proc/tgui_modal_preprocess_answer(datum/source = src, answer = "")
|
||||
/datum/proc/ui_modal_preprocess_answer(datum/source = src, answer = "")
|
||||
ASSERT(istype(source))
|
||||
|
||||
var/datum/tgui_modal/current = LAZYACCESS(GLOB.tgui_modals, source.UID())
|
||||
var/datum/ui_modal/current = LAZYACCESS(GLOB.ui_modals, source.UID())
|
||||
if(!current)
|
||||
return answer
|
||||
|
||||
@@ -228,7 +228,7 @@ GLOBAL_LIST(tgui_modals)
|
||||
/**
|
||||
* Modal datum (contains base information for a modal)
|
||||
*/
|
||||
/datum/tgui_modal
|
||||
/datum/ui_modal
|
||||
var/datum/owning_source
|
||||
var/id
|
||||
var/text
|
||||
@@ -236,7 +236,7 @@ GLOBAL_LIST(tgui_modals)
|
||||
var/list/arguments
|
||||
var/modal_type = "message"
|
||||
|
||||
/datum/tgui_modal/New(id, text, delegate, list/arguments)
|
||||
/datum/ui_modal/New(id, text, delegate, list/arguments)
|
||||
src.id = id
|
||||
src.text = text
|
||||
src.delegate = delegate
|
||||
@@ -248,8 +248,8 @@ GLOBAL_LIST(tgui_modals)
|
||||
* Arguments:
|
||||
* * answer - The answer, a nullable text
|
||||
*/
|
||||
/datum/tgui_modal/proc/preprocess_answer(answer)
|
||||
return reject_bad_text(answer, TGUI_MODAL_INPUT_MAX_LENGTH) // bleh
|
||||
/datum/ui_modal/proc/preprocess_answer(answer)
|
||||
return reject_bad_text(answer, UI_MODAL_INPUT_MAX_LENGTH) // bleh
|
||||
|
||||
/**
|
||||
* Called when a modal receives an answer
|
||||
@@ -257,7 +257,7 @@ GLOBAL_LIST(tgui_modals)
|
||||
* Arguments:
|
||||
* * answer - The answer, a nullable text
|
||||
*/
|
||||
/datum/tgui_modal/proc/on_answer(answer)
|
||||
/datum/ui_modal/proc/on_answer(answer)
|
||||
if(delegate)
|
||||
return call(owning_source, delegate)(answer, arguments)
|
||||
return FALSE
|
||||
@@ -265,7 +265,7 @@ GLOBAL_LIST(tgui_modals)
|
||||
/**
|
||||
* Creates a list that describes a modal visually to be passed to JS
|
||||
*/
|
||||
/datum/tgui_modal/proc/to_data()
|
||||
/datum/ui_modal/proc/to_data()
|
||||
. = list()
|
||||
.["id"] = id
|
||||
.["text"] = text
|
||||
@@ -275,42 +275,42 @@ GLOBAL_LIST(tgui_modals)
|
||||
/**
|
||||
* Input modal - has a text entry that can be used to enter an answer
|
||||
*/
|
||||
/datum/tgui_modal/input
|
||||
/datum/ui_modal/input
|
||||
modal_type = "input"
|
||||
var/value
|
||||
var/max_length
|
||||
|
||||
/datum/tgui_modal/input/New(id, text, delegate, list/arguments, value, max_length)
|
||||
/datum/ui_modal/input/New(id, text, delegate, list/arguments, value, max_length)
|
||||
..(id, text, delegate, arguments)
|
||||
src.value = value
|
||||
src.max_length = max_length
|
||||
|
||||
/datum/tgui_modal/input/preprocess_answer(answer)
|
||||
/datum/ui_modal/input/preprocess_answer(answer)
|
||||
. = ..(answer)
|
||||
if(length(answer) > max_length)
|
||||
. = copytext(., 1, max_length + 1)
|
||||
|
||||
/datum/tgui_modal/input/to_data()
|
||||
/datum/ui_modal/input/to_data()
|
||||
. = ..()
|
||||
.["value"] = value
|
||||
|
||||
/**
|
||||
* Choice modal - has a dropdown menu that can be used to select an answer
|
||||
*/
|
||||
/datum/tgui_modal/input/choice
|
||||
/datum/ui_modal/input/choice
|
||||
modal_type = "choice"
|
||||
var/choices
|
||||
|
||||
/datum/tgui_modal/input/choice/New(id, text, delegate, list/arguments, value, choices)
|
||||
..(id, text, delegate, arguments, value, TGUI_MODAL_INPUT_MAX_LENGTH) // Max length doesn't really matter in dropdowns, but whatever
|
||||
/datum/ui_modal/input/choice/New(id, text, delegate, list/arguments, value, choices)
|
||||
..(id, text, delegate, arguments, value, UI_MODAL_INPUT_MAX_LENGTH) // Max length doesn't really matter in dropdowns, but whatever
|
||||
src.choices = choices
|
||||
|
||||
/datum/tgui_modal/input/choice/on_answer(answer)
|
||||
/datum/ui_modal/input/choice/on_answer(answer)
|
||||
if(answer in choices) // Make sure the answer is actually in our choices!
|
||||
return ..(answer, arguments)
|
||||
return FALSE
|
||||
|
||||
/datum/tgui_modal/input/choice/to_data()
|
||||
/datum/ui_modal/input/choice/to_data()
|
||||
. = ..()
|
||||
.["choices"] = choices
|
||||
|
||||
@@ -319,52 +319,52 @@ GLOBAL_LIST(tgui_modals)
|
||||
*
|
||||
* The returned answer is the index of the choice.
|
||||
*/
|
||||
/datum/tgui_modal/input/bento
|
||||
/datum/ui_modal/input/bento
|
||||
modal_type = "bento"
|
||||
var/choices
|
||||
|
||||
/datum/tgui_modal/input/bento/New(id, text, delegate, list/arguments, value, choices)
|
||||
..(id, text, delegate, arguments, text2num(value), TGUI_MODAL_INPUT_MAX_LENGTH) // Max length doesn't really matter in here, but whatever
|
||||
/datum/ui_modal/input/bento/New(id, text, delegate, list/arguments, value, choices)
|
||||
..(id, text, delegate, arguments, text2num(value), UI_MODAL_INPUT_MAX_LENGTH) // Max length doesn't really matter in here, but whatever
|
||||
src.choices = choices
|
||||
|
||||
/datum/tgui_modal/input/bento/preprocess_answer(answer)
|
||||
/datum/ui_modal/input/bento/preprocess_answer(answer)
|
||||
return text2num(answer) || 0
|
||||
|
||||
/datum/tgui_modal/input/bento/on_answer(answer)
|
||||
/datum/ui_modal/input/bento/on_answer(answer)
|
||||
if(answer >= 1 && answer <= length(choices)) // Make sure the answer index is actually in our indexes!
|
||||
return ..(answer, arguments)
|
||||
return FALSE
|
||||
|
||||
/datum/tgui_modal/input/bento/to_data()
|
||||
/datum/ui_modal/input/bento/to_data()
|
||||
. = ..()
|
||||
.["choices"] = choices
|
||||
|
||||
/**
|
||||
* Boolean modal - has yes/no buttons that do different actions depending on which is pressed
|
||||
*/
|
||||
/datum/tgui_modal/boolean
|
||||
/datum/ui_modal/boolean
|
||||
modal_type = "boolean"
|
||||
var/delegate_no
|
||||
var/yes_text
|
||||
var/no_text
|
||||
|
||||
/datum/tgui_modal/boolean/New(id, text, delegate, delegate_no, list/arguments, yes_text, no_text)
|
||||
/datum/ui_modal/boolean/New(id, text, delegate, delegate_no, list/arguments, yes_text, no_text)
|
||||
..(id, text, delegate, arguments)
|
||||
src.delegate_no = delegate_no
|
||||
src.yes_text = yes_text
|
||||
src.no_text = no_text
|
||||
|
||||
/datum/tgui_modal/boolean/preprocess_answer(answer)
|
||||
/datum/ui_modal/boolean/preprocess_answer(answer)
|
||||
return text2num(answer) || FALSE
|
||||
|
||||
/datum/tgui_modal/boolean/on_answer(answer)
|
||||
/datum/ui_modal/boolean/on_answer(answer)
|
||||
if(answer)
|
||||
return ..(answer, arguments)
|
||||
else if(delegate_no)
|
||||
return call(owning_source, delegate_no)(arguments)
|
||||
return FALSE
|
||||
|
||||
/datum/tgui_modal/boolean/to_data()
|
||||
/datum/ui_modal/boolean/to_data()
|
||||
. = ..()
|
||||
.["yes_text"] = yes_text
|
||||
.["no_text"] = no_text
|
||||
|
||||
Reference in New Issue
Block a user