Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 963a4a8

Browse files
givin up
1 parent 6f03cc1 commit 963a4a8

File tree

9 files changed

+94
-58
lines changed

9 files changed

+94
-58
lines changed

code/__DEFINES/text.dm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
/// Removes everything enclose in < and > inclusive of the bracket, and limits the length of the message.
1515
#define STRIP_HTML_FULL(text, limit) (GLOB.html_tags.Replace(copytext(text, 1, limit), ""))
1616

17+
/**
18+
* stuff like `copytext(input, length(input))` will trim the last character of the input,
19+
* because DM does it so it copies until the char BEFORE the `end` arg, so we need to bump `end` by 1 in these cases.
20+
*/
21+
#define PREVENT_CHARACTER_TRIM_LOSS(integer) (integer + 1)
22+
1723
/**
1824
* Pixel-perfect scaled fonts for use in the MAP element as defined in skin.dmf
1925
*

code/modules/tgui_input/alert.dm

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
* * timeout - The timeout of the alert, after which the modal will close and qdel itself. Set to zero for no timeout.
1111
* * * autofocus - The bool that controls if this alert should grab window focus.
1212
*/
13-
/proc/tgui_alert(mob/user, message = null, title = null, list/buttons = list("Ok"), timeout = 0, autofocus = TRUE)
13+
/proc/tgui_alert(mob/user, message = null, title = null, list/buttons = list("Ok"), timeout = 0, autofocus = TRUE, ui_state = GLOB.always_state)
1414
if (!user)
1515
user = usr
1616
if (!istype(user))
1717
if (istype(user, /client))
1818
var/client/client = user
1919
user = client.mob
2020
else
21-
return
22-
var/datum/tgui_modal/alert = new(user, message, title, buttons, timeout, autofocus)
21+
return null
22+
if(isnull(user.client))
23+
return null
24+
var/datum/tgui_modal/alert = new(user, message, title, buttons, timeout, autofocus, ui_state)
2325
alert.ui_interact(user)
2426
alert.wait()
2527
if (alert)
@@ -74,21 +76,25 @@
7476
var/autofocus
7577
/// Boolean field describing if the tgui_modal was closed by the user.
7678
var/closed
79+
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
80+
var/datum/ui_state/state
7781

78-
/datum/tgui_modal/New(mob/user, message, title, list/buttons, timeout, autofocus)
82+
/datum/tgui_modal/New(mob/user, message, title, list/buttons, timeout, autofocus, ui_state)
7983
src.title = title
8084
src.message = message
8185
src.buttons = buttons.Copy()
8286
src.autofocus = autofocus
87+
src.state = ui_state
8388
if (timeout)
8489
src.timeout = timeout
8590
start_time = world.time
8691
QDEL_IN(src, timeout)
8792

8893
/datum/tgui_modal/Destroy(force, ...)
8994
SStgui.close_uis(src)
95+
state = null
9096
QDEL_NULL(buttons)
91-
. = ..()
97+
return ..()
9298

9399
/**
94100
* Waits for a user's response to the tgui_modal's prompt before returning. Returns early if
@@ -109,7 +115,7 @@
109115
closed = TRUE
110116

111117
/datum/tgui_modal/ui_state(mob/user)
112-
return GLOB.always_state
118+
return state
113119

114120
/datum/tgui_modal/ui_data(mob/user)
115121
. = list(

code/modules/tgui_input/checkboxes.dm

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
* max_checked - The maximum number of checkboxes that can be checked (optional)
1111
* timeout - The timeout for the input (optional)
1212
*/
13-
/proc/tgui_input_checkboxes(mob/user, message, title = "Select", list/items, min_checked = 1, max_checked = 50, timeout = 0)
13+
/proc/tgui_input_checkboxes(mob/user, message, title = "Select", list/items, min_checked = 1, max_checked = 50, timeout = 0, ui_state = GLOB.always_state)
1414
if (!user)
1515
user = usr
1616
if(!length(items))
17-
return
17+
return null
1818
if (!istype(user))
1919
if (istype(user, /client))
2020
var/client/client = user
2121
user = client.mob
2222
else
23-
return
23+
return null
24+
if(isnull(user.client))
25+
return null
2426
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
2527
return input(user, message, title) as null|anything in items
26-
var/datum/tgui_checkbox_input/input = new(user, message, title, items, min_checked, max_checked, timeout)
28+
var/datum/tgui_checkbox_input/input = new(user, message, title, items, min_checked, max_checked, timeout, ui_state)
2729
input.ui_interact(user)
2830
input.wait()
2931
if (input)
@@ -50,13 +52,16 @@
5052
var/min_checked
5153
/// Maximum number of checkboxes that can be checked
5254
var/max_checked
55+
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
56+
var/datum/ui_state/state
5357

54-
/datum/tgui_checkbox_input/New(mob/user, message, title, list/items, min_checked, max_checked, timeout)
58+
/datum/tgui_checkbox_input/New(mob/user, message, title, list/items, min_checked, max_checked, timeout, ui_state)
5559
src.title = title
5660
src.message = message
5761
src.items = items.Copy()
5862
src.min_checked = min_checked
5963
src.max_checked = max_checked
64+
src.state = ui_state
6065

6166
if (timeout)
6267
src.timeout = timeout
@@ -65,6 +70,7 @@
6570

6671
/datum/tgui_checkbox_input/Destroy(force, ...)
6772
SStgui.close_uis(src)
73+
state = null
6874
QDEL_NULL(items)
6975

7076
return ..()
@@ -84,7 +90,7 @@
8490
closed = TRUE
8591

8692
/datum/tgui_checkbox_input/ui_state(mob/user)
87-
return GLOB.always_state
93+
return state
8894

8995
/datum/tgui_checkbox_input/ui_data(mob/user)
9096
var/list/data = list()

code/modules/tgui_input/list.dm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
* * buttons - The options that can be chosen by the user, each string is assigned a button on the UI.
1010
* * timeout - The timeout of the input box, after which the input box will close and qdel itself. Set to zero for no timeout.
1111
*/
12-
/proc/tgui_input_list(mob/user, message, title = "Select", list/buttons, default, timeout = 0)
12+
/proc/tgui_input_list(mob/user, message, title = "Select", list/buttons, default, timeout = 0, ui_state = GLOB.always_state)
1313
if (!user)
1414
user = usr
1515
if(!length(buttons))
16-
return
16+
return null
1717
if (!istype(user))
1818
if (istype(user, /client))
1919
var/client/client = user
@@ -27,7 +27,7 @@
2727
/// Client does NOT have tgui_input on: Returns regular input
2828
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
2929
return input(user, message, title, default) as null|anything in buttons
30-
var/datum/tgui_list_input/input = new(user, message, title, buttons, default, timeout)
30+
var/datum/tgui_list_input/input = new(user, message, title, buttons, default, timeout, ui_state)
3131
if(input.invalid)
3232
qdel(input)
3333
return
@@ -88,15 +88,18 @@
8888
var/timeout
8989
/// Boolean field describing if the tgui_list_input was closed by the user.
9090
var/closed
91+
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
92+
var/datum/ui_state/state
9193
/// Whether the tgui list input is invalid or not (i.e. due to all list entries being null)
9294
var/invalid = FALSE
9395

94-
/datum/tgui_list_input/New(mob/user, message, title, list/buttons, default, timeout)
96+
/datum/tgui_list_input/New(mob/user, message, title, list/buttons, default, timeout, ui_state)
9597
src.title = title
9698
src.message = message
9799
src.buttons = list()
98100
src.buttons_map = list()
99101
src.default = default
102+
src.state = ui_state
100103

101104
// Gets rid of illegal characters
102105
var/static/regex/whitelistedWords = regex(@{"([^\u0020-\u8000]+)"})
@@ -118,6 +121,7 @@
118121

119122
/datum/tgui_list_input/Destroy(force)
120123
SStgui.close_uis(src)
124+
state = null
121125
QDEL_NULL(buttons)
122126
return ..()
123127

@@ -140,7 +144,7 @@
140144
closed = TRUE
141145

142146
/datum/tgui_list_input/ui_state(mob/user)
143-
return GLOB.always_state
147+
return state
144148

145149
/datum/tgui_list_input/ui_static_data(mob/user)
146150
var/list/data = list()

code/modules/tgui_input/number.dm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@
1515
* * timeout - The timeout of the number input, after which the modal will close and qdel itself. Set to zero for no timeout.
1616
* * round_value - whether the inputted number is rounded down into an integer.
1717
*/
18-
/proc/tgui_input_number(mob/user, message = null, title = "Number Input", default = null, max_value = null, min_value = 0, timeout = 0)
18+
/proc/tgui_input_number(mob/user, message = null, title = "Number Input", default = null, max_value = null, min_value = 0, timeout = 0, ui_state = GLOB.always_state)
1919
if (!user)
2020
user = usr
2121
if (!istype(user))
2222
if (istype(user, /client))
2323
var/client/client = user
2424
user = client.mob
2525
else
26-
return
26+
return null
27+
if (isnull(user.client))
28+
return null
2729
/// Client does NOT have tgui_fancy on: Returns regular input
2830
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
2931
return input(user, message, title, default) as null | num
30-
var/datum/tgui_input_number/numbox = new(user, message, title, default, max_value, min_value, timeout)
32+
var/datum/tgui_input_number/numbox = new(user, message, title, default, max_value, min_value, timeout, ui_state)
3133
numbox.ui_interact(user)
3234
numbox.wait()
3335
if (numbox)
@@ -86,22 +88,26 @@
8688
var/timeout
8789
/// The title of the TGUI window
8890
var/title
91+
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
92+
var/datum/ui_state/state
8993

9094

91-
/datum/tgui_input_number/New(mob/user, message, title, default, max_value, min_value, timeout)
95+
/datum/tgui_input_number/New(mob/user, message, title, default, max_value, min_value, timeout, ui_state)
9296
src.default = default
9397
src.max_value = max_value
9498
src.message = message
9599
src.min_value = min_value
96100
src.title = title
101+
src.state = ui_state
97102
if (timeout)
98103
src.timeout = timeout
99104
start_time = world.time
100105
QDEL_IN(src, timeout)
101106

102107
/datum/tgui_input_number/Destroy(force, ...)
103108
SStgui.close_uis(src)
104-
. = ..()
109+
state = null
110+
return ..()
105111

106112
/**
107113
* Waits for a user's response to the tgui_input_number's prompt before returning. Returns early if
@@ -122,7 +128,7 @@
122128
closed = TRUE
123129

124130
/datum/tgui_input_number/ui_state(mob/user)
125-
return GLOB.always_state
131+
return state
126132

127133
/datum/tgui_input_number/ui_static_data(mob/user)
128134
. = list(
@@ -161,7 +167,7 @@
161167
return TRUE
162168

163169
/datum/tgui_input_number/proc/set_entry(entry)
164-
src.entry = entry
170+
src.entry = entry
165171

166172
/**
167173
* # async tgui_input_number

code/modules/tgui_input/text.dm

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,27 @@
1414
* * multiline - Bool that determines if the input box is much larger. Good for large messages, laws, etc.
1515
* * timeout - The timeout of the textbox, after which the modal will close and qdel itself. Set to zero for no timeout.
1616
*/
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)
1818
if (!user)
1919
user = usr
2020
if (!istype(user))
2121
if (istype(user, /client))
2222
var/client/client = user
2323
user = client.mob
2424
else
25-
return
25+
return null
26+
if(isnull(user.client))
27+
return null
2628
/// Client does NOT have tgui_fancy on: Returns regular input
2729
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
2830
if(max_length)
2931
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))
3133
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))
3335
else
3436
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)
3638
textbox.ui_interact(user)
3739
textbox.wait()
3840
if (textbox)
@@ -90,22 +92,26 @@
9092
var/timeout
9193
/// The title of the TGUI window
9294
var/title
95+
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
96+
var/datum/ui_state/state
9397

9498

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)
96100
src.default = default
97101
src.max_length = max_length
98102
src.message = message
99103
src.multiline = multiline
100104
src.title = title
105+
src.state = ui_state
101106
if (timeout)
102107
src.timeout = timeout
103108
start_time = world.time
104109
QDEL_IN(src, timeout)
105110

106111
/datum/tgui_input_text/Destroy(force, ...)
107112
SStgui.close_uis(src)
108-
. = ..()
113+
state = null
114+
return ..()
109115

110116
/**
111117
* Waits for a user's response to the tgui_input_text's prompt before returning. Returns early if
@@ -126,7 +132,7 @@
126132
closed = TRUE
127133

128134
/datum/tgui_input_text/ui_state(mob/user)
129-
return GLOB.always_state
135+
return state
130136

131137
/datum/tgui_input_text/ui_static_data(mob/user)
132138
. = list(
@@ -163,7 +169,8 @@
163169
return TRUE
164170

165171
/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
167174

168175
/**
169176
* # async tgui_input_text

tgui/global.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ const Byond: ByondType;
201201

202202
interface Window {
203203
Byond: ByondType;
204+
__store__: Store<unknown, AnyAction>;
205+
__augmentStack__: (store: Store) => StackAugmentor;
206+
204207
// IE IndexedDB stuff.
205208
msIndexedDB: IDBFactory;
206209
msIDBTransaction: IDBTransaction;

0 commit comments

Comments
 (0)