|
14 | 14 | * * multiline - Bool that determines if the input box is much larger. Good for large messages, laws, etc. |
15 | 15 | * * timeout - The timeout of the textbox, after which the modal will close and qdel itself. Set to zero for no timeout. |
16 | 16 | */ |
17 | | -/proc/tgui_input_text(mob/user, message = null, title = "Text Input", default = null, max_length = null, multiline = FALSE, timeout = 0) |
| 17 | +/proc/tgui_input_text(mob/user, message = null, title = "Text Input", default = null, max_length, multiline = FALSE, timeout = 0, ui_state = GLOB.always_state) |
18 | 18 | if (!user) |
19 | 19 | user = usr |
20 | 20 | if (!istype(user)) |
21 | 21 | if (istype(user, /client)) |
22 | 22 | var/client/client = user |
23 | 23 | user = client.mob |
24 | 24 | else |
25 | | - return |
| 25 | + return null |
| 26 | + if(isnull(user.client)) |
| 27 | + return null |
26 | 28 | /// Client does NOT have tgui_fancy on: Returns regular input |
27 | 29 | if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input)) |
28 | 30 | if(max_length) |
29 | 31 | if(multiline) |
30 | | - return stripped_multiline_input(user, message, title, default, max_length) |
| 32 | + return stripped_multiline_input(user, message, title, default, PREVENT_CHARACTER_TRIM_LOSS(max_length)) |
31 | 33 | else |
32 | | - return stripped_input(user, message, title, default, max_length) |
| 34 | + return stripped_input(user, message, title, default, PREVENT_CHARACTER_TRIM_LOSS(max_length)) |
33 | 35 | else |
34 | 36 | return input(user, message, title, default) |
35 | | - var/datum/tgui_input_text/textbox = new(user, message, title, default, max_length, multiline, timeout) |
| 37 | + var/datum/tgui_input_text/textbox = new(user, message, title, default, max_length, multiline, timeout, ui_state) |
36 | 38 | textbox.ui_interact(user) |
37 | 39 | textbox.wait() |
38 | 40 | if (textbox) |
|
90 | 92 | var/timeout |
91 | 93 | /// The title of the TGUI window |
92 | 94 | var/title |
| 95 | + /// The TGUI UI state that will be returned in ui_state(). Default: always_state |
| 96 | + var/datum/ui_state/state |
93 | 97 |
|
94 | 98 |
|
95 | | -/datum/tgui_input_text/New(mob/user, message, title, default, max_length, multiline, timeout) |
| 99 | +/datum/tgui_input_text/New(mob/user, message, title, default, max_length, multiline, timeout, ui_state) |
96 | 100 | src.default = default |
97 | 101 | src.max_length = max_length |
98 | 102 | src.message = message |
99 | 103 | src.multiline = multiline |
100 | 104 | src.title = title |
| 105 | + src.state = ui_state |
101 | 106 | if (timeout) |
102 | 107 | src.timeout = timeout |
103 | 108 | start_time = world.time |
104 | 109 | QDEL_IN(src, timeout) |
105 | 110 |
|
106 | 111 | /datum/tgui_input_text/Destroy(force, ...) |
107 | 112 | SStgui.close_uis(src) |
108 | | - . = ..() |
| 113 | + state = null |
| 114 | + return ..() |
109 | 115 |
|
110 | 116 | /** |
111 | 117 | * Waits for a user's response to the tgui_input_text's prompt before returning. Returns early if |
|
126 | 132 | closed = TRUE |
127 | 133 |
|
128 | 134 | /datum/tgui_input_text/ui_state(mob/user) |
129 | | - return GLOB.always_state |
| 135 | + return state |
130 | 136 |
|
131 | 137 | /datum/tgui_input_text/ui_static_data(mob/user) |
132 | 138 | . = list( |
|
163 | 169 | return TRUE |
164 | 170 |
|
165 | 171 | /datum/tgui_input_text/proc/set_entry(entry) |
166 | | - src.entry = entry |
| 172 | + if(!isnull(entry)) |
| 173 | + src.entry = max_length ? trim(entry, PREVENT_CHARACTER_TRIM_LOSS(max_length)) : entry |
167 | 174 |
|
168 | 175 | /** |
169 | 176 | * # async tgui_input_text |
|
0 commit comments