|
23 | 23 | var/existing_browser = FALSE
|
24 | 24 |
|
25 | 25 |
|
26 |
| -/datum/browser/New(nuser, nwindow_id, ntitle = 0, nstylesheet = "common.css", nwidth = 0, nheight = 0, atom/nref = null) |
| 26 | +/datum/browser/New(client/nuser, nwindow_id, ntitle = 0, nstylesheet = "common.css", nwidth = 0, nheight = 0, atom/nref = null) |
| 27 | + if(!nuser) |
| 28 | + return |
| 29 | + if(!istype(nuser)) |
| 30 | + if(ismob(nuser)) |
| 31 | + var/mob/mob_user = nuser |
| 32 | + nuser = mob_user.client |
| 33 | + else |
| 34 | + CRASH("Passed [nuser] ([nuser?.type]) as a client!") |
| 35 | + |
27 | 36 | user = nuser
|
28 | 37 | window_id = nwindow_id
|
29 |
| - if (ntitle) |
| 38 | + if(ntitle) |
30 | 39 | title = format_text(ntitle)
|
31 |
| - if (nwidth) |
| 40 | + if(nwidth) |
32 | 41 | width = nwidth
|
33 |
| - if (nheight) |
| 42 | + if(nheight) |
34 | 43 | height = nheight
|
35 |
| - if (nref) |
| 44 | + if(nref) |
36 | 45 | ref = nref
|
37 | 46 | stylesheet = nstylesheet
|
38 | 47 |
|
|
49 | 58 | window_options = nwindow_options
|
50 | 59 |
|
51 | 60 | /datum/browser/proc/add_stylesheet(name, file)
|
52 |
| - if (istype(name, /datum/asset/spritesheet)) |
| 61 | + if(istype(name, /datum/asset/spritesheet)) |
53 | 62 | var/datum/asset/spritesheet/sheet = name
|
54 | 63 | stylesheets["spritesheet_[sheet.name].css"] = "data/spritesheets/[sheet.name]"
|
55 | 64 | else
|
56 | 65 | var/asset_name = "[name].css"
|
57 | 66 |
|
58 | 67 | stylesheets[asset_name] = file
|
59 | 68 |
|
60 |
| - if (!SSassets.cache[asset_name]) |
| 69 | + if(!SSassets.cache[asset_name]) |
61 | 70 | SSassets.transport.register_asset(asset_name, file)
|
62 | 71 |
|
63 | 72 | /datum/browser/proc/add_script(name, file)
|
|
83 | 92 | </style>
|
84 | 93 | "}
|
85 | 94 |
|
86 |
| - for (var/file in stylesheets) |
| 95 | + for(var/file in stylesheets) |
87 | 96 | head_content += "<link rel='stylesheet' type='text/css' href='[SSassets.transport.get_asset_url(file)]'>"
|
88 | 97 |
|
89 | 98 |
|
90 |
| - for (var/file in scripts) |
| 99 | + for(var/file in scripts) |
91 | 100 | head_content += "<script type='text/javascript' src='[SSassets.transport.get_asset_url(file)]'></script>"
|
92 | 101 | head_content += "<script type='text/javascript' src='[other_asset.get_url_mappings()["search.js"]]'></script>"
|
93 | 102 |
|
94 | 103 | var/title_attributes = "class='uiTitle'"
|
95 |
| - if (title_image) |
| 104 | + if(title_image) |
96 | 105 | title_attributes = "class='uiTitle icon' style='background-image: url([title_image]);'"
|
97 | 106 |
|
98 | 107 | return {"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
126 | 135 | to_chat(user, SPAN_USERDANGER("The [title] browser you tried to open failed a sanity check! Please report this on github!"))
|
127 | 136 | return
|
128 | 137 | var/window_size = ""
|
129 |
| - if (width && height) |
| 138 | + if(width && height) |
130 | 139 | if(user?.window_scaling && user.prefs.window_scale)
|
131 | 140 | window_size = "size=[width * user.window_scaling]x[height * user.window_scaling];"
|
132 | 141 | else
|
133 | 142 | window_size = "size=[width]x[height];"
|
134 | 143 | common_asset.send(user)
|
135 | 144 | other_asset.send(user)
|
136 |
| - if (length(stylesheets)) |
| 145 | + if(length(stylesheets)) |
137 | 146 | SSassets.transport.send_assets(user, stylesheets)
|
138 |
| - if (length(scripts)) |
| 147 | + if(length(scripts)) |
139 | 148 | SSassets.transport.send_assets(user, scripts)
|
140 | 149 |
|
141 | 150 | user << browse(get_content(), "window=[window_id];[window_size][window_options]")
|
142 | 151 |
|
143 | 152 | if(existing_browser)
|
144 | 153 | winset(user, existing_browser, window_size)
|
145 | 154 |
|
146 |
| - if (use_onclose) |
| 155 | + if(use_onclose) |
147 | 156 | setup_onclose()
|
148 | 157 |
|
149 | 158 | /datum/browser/proc/setup_onclose()
|
150 | 159 | set waitfor = 0 //winexists sleeps, so we don't need to.
|
151 |
| - for (var/i in 1 to 10) |
152 |
| - if (user && winexists(user, window_id)) |
| 160 | + for(var/i in 1 to 10) |
| 161 | + if(user && winexists(user, window_id)) |
153 | 162 | onclose(user, window_id, ref)
|
154 | 163 | break
|
155 | 164 |
|
|
163 | 172 | /mob/proc/browse_rsc_icon(icon, icon_state, dir = -1)
|
164 | 173 | /*
|
165 | 174 | var/icon/I
|
166 |
| - if (dir >= 0) |
| 175 | + if(dir >= 0) |
167 | 176 | I = new /icon(icon, icon_state, dir)
|
168 | 177 | else
|
169 | 178 | I = new /icon(icon, icon_state)
|
|
190 | 199 | // Topic() proc for special handling.
|
191 | 200 | // Otherwise, the user mob's machine var will be reset directly.
|
192 | 201 | //
|
193 |
| -/proc/onclose(user, windowid, atom/ref, list/params) |
194 |
| - var/client/C = user |
195 |
| - |
196 |
| - if (ismob(user)) |
197 |
| - var/mob/M = user |
198 |
| - C = M.client |
199 |
| - |
200 |
| - if (!istype(C)) |
| 202 | +/proc/onclose(client/user, windowid, atom/ref, list/params) |
| 203 | + if(!user) |
201 | 204 | return
|
| 205 | + if(!istype(user)) |
| 206 | + if(ismob(user)) |
| 207 | + var/mob/mob_user = user |
| 208 | + user = mob_user.client |
| 209 | + else |
| 210 | + CRASH("Passed [user] ([user?.type]) as a client!") |
202 | 211 |
|
203 | 212 | var/ref_string = "null"
|
204 |
| - if (ref) |
| 213 | + if(ref) |
205 | 214 | ref_string = "\ref[ref]"
|
206 | 215 |
|
207 | 216 | var/params_string = "null"
|
208 |
| - if (params) |
| 217 | + if(params) |
209 | 218 | params_string = ""
|
210 |
| - for (var/param in params) |
| 219 | + for(var/param in params) |
211 | 220 | params_string += "[param]=[params[param]];"
|
212 | 221 | params_string = copytext(params_string, 1, -1)
|
213 | 222 |
|
214 |
| - winset(C, windowid, "on-close=\".windowclose \\\"[ref_string]\\\" \\\"[params_string]\\\"\"") |
| 223 | + winset(user, windowid, "on-close=\".windowclose \\\"[ref_string]\\\" \\\"[params_string]\\\"\"") |
215 | 224 |
|
216 | 225 |
|
217 | 226 | // the on-close client verb
|
|
231 | 240 | var/param_string = "close=1"
|
232 | 241 | var/list/param_list = list("close"="1")
|
233 | 242 |
|
234 |
| - if (params && params != "null") |
| 243 | + if(params && params != "null") |
235 | 244 | param_string = params
|
236 | 245 | param_list = params2list(params)
|
237 | 246 |
|
|
245 | 254 | mob.unset_interaction()
|
246 | 255 | return
|
247 | 256 |
|
248 |
| -/proc/show_browser(target, browser_content, browser_name, id = null, window_options = null, closeref, width, height, existing_container = FALSE) |
249 |
| - var/client/C = target |
250 |
| - |
251 |
| - if (ismob(target)) |
252 |
| - var/mob/M = target |
253 |
| - C = M.client |
254 |
| - |
255 |
| - if (!istype(C)) |
| 257 | +/proc/show_browser(client/target, browser_content, browser_name, id = null, window_options = null, closeref, width, height, existing_container = FALSE) |
| 258 | + if(!target) |
256 | 259 | return
|
| 260 | + if(!istype(target)) |
| 261 | + if(ismob(target)) |
| 262 | + var/mob/mob_user = target |
| 263 | + target = mob_user.client |
| 264 | + else |
| 265 | + CRASH("Passed [target] ([target?.type]) as a client!") |
257 | 266 |
|
258 |
| - var/stylesheet = C.prefs.stylesheet |
259 |
| - if (!(stylesheet in GLOB.stylesheets)) |
260 |
| - C.prefs.stylesheet = "Modern" |
| 267 | + var/stylesheet = target.prefs.stylesheet |
| 268 | + if(!(stylesheet in GLOB.stylesheets)) |
| 269 | + target.prefs.stylesheet = "Modern" |
261 | 270 | stylesheet = "Modern"
|
262 | 271 |
|
263 |
| - var/datum/browser/popup = new(C, id ? id : browser_name, browser_name, GLOB.stylesheets[stylesheet], nwidth = width, nheight = height, nref = closeref) |
| 272 | + var/datum/browser/popup = new(target, id ? id : browser_name, browser_name, GLOB.stylesheets[stylesheet], nwidth = width, nheight = height, nref = closeref) |
264 | 273 |
|
265 | 274 | if(existing_container)
|
266 | 275 | popup.existing_browser = existing_container
|
267 | 276 |
|
268 | 277 | popup.set_content(browser_content)
|
269 |
| - if (window_options) |
| 278 | + if(window_options) |
270 | 279 | popup.set_window_options(window_options)
|
271 | 280 | popup.open()
|
272 | 281 |
|
|
276 | 285 | var/selectedbutton = 0
|
277 | 286 | var/stealfocus
|
278 | 287 |
|
279 |
| -/datum/browser/modal/New(nuser, nwindow_id, ntitle = 0, nstylesheet = "common.css", nwidth = 0, nheight = 0, atom/nref = null, StealFocus = 1, Timeout = 6000) |
| 288 | +/datum/browser/modal/New(client/nuser, nwindow_id, ntitle = 0, nstylesheet = "common.css", nwidth = 0, nheight = 0, atom/nref = null, stealfocus = 1, timeout = 6000) |
280 | 289 | ..()
|
281 |
| - stealfocus = StealFocus |
282 |
| - if (!StealFocus) |
| 290 | + src.stealfocus = stealfocus |
| 291 | + if(!stealfocus) |
283 | 292 | window_options += "focus=false;"
|
284 |
| - timeout = Timeout |
| 293 | + src.timeout = timeout |
285 | 294 |
|
286 | 295 |
|
287 | 296 | /datum/browser/modal/close()
|
|
292 | 301 | set waitfor = FALSE
|
293 | 302 | opentime = world.time
|
294 | 303 |
|
295 |
| - if (stealfocus) |
| 304 | + if(stealfocus) |
296 | 305 | . = ..(use_onclose = 1)
|
297 | 306 | else
|
298 | 307 | var/focusedwindow = winget(user, null, "focus")
|
299 | 308 | . = ..(use_onclose = 1)
|
300 | 309 |
|
301 | 310 | //waits for the window to show up client side before attempting to un-focus it
|
302 | 311 | //winexists sleeps until it gets a reply from the client, so we don't need to bother sleeping
|
303 |
| - for (var/i in 1 to 10) |
304 |
| - if (user && winexists(user, window_id)) |
305 |
| - if (focusedwindow) |
| 312 | + for(var/i in 1 to 10) |
| 313 | + if(user && winexists(user, window_id)) |
| 314 | + if(focusedwindow) |
306 | 315 | winset(user, focusedwindow, "focus=true")
|
307 | 316 | else
|
308 | 317 | winset(user, "mapwindow", "focus=true")
|
309 | 318 | break
|
310 |
| - if (timeout) |
| 319 | + if(timeout) |
311 | 320 | addtimer(CALLBACK(src, PROC_REF(close)), timeout)
|
312 | 321 |
|
313 | 322 | /datum/browser/modal/proc/wait()
|
314 |
| - while (opentime && selectedbutton <= 0 && (!timeout || opentime+timeout > world.time)) |
| 323 | + while(opentime && selectedbutton <= 0 && (!timeout || opentime+timeout > world.time)) |
315 | 324 | stoplag(1)
|
| 325 | + |
316 | 326 | /datum/browser/modal/listpicker
|
317 | 327 | var/valueslist = list()
|
318 | 328 |
|
319 |
| -/datum/browser/modal/listpicker/New(User,Message,Title,Button1="Ok",Button2,Button3,StealFocus = 1, Timeout = FALSE,list/values,inputtype="checkbox", width, height) |
320 |
| - if (!User) |
| 329 | +/datum/browser/modal/listpicker/New(client/user, message, title, button1="Ok", button2, button3, stealfocus=TRUE, timeout=FALSE, list/values, inputtype="checkbox", width, height) |
| 330 | + if(!user) |
321 | 331 | return
|
322 | 332 |
|
323 | 333 | var/output = {"<form><input type="hidden" name="src" value="[REF(src)]"><ul class="sparse">"}
|
324 |
| - if (inputtype == "checkbox" || inputtype == "radio") |
| 334 | + if(inputtype == "checkbox" || inputtype == "radio") |
325 | 335 | output += {"<table border=1 cellspacing=0 cellpadding=3 style='border: 1px solid black;'>"}
|
326 |
| - for (var/i in values) |
| 336 | + for(var/i in values) |
327 | 337 | output += {"<tr>
|
328 | 338 | <td><input type="[inputtype]" value="1" name="[i["name"]]"[i["checked"] ? " checked" : ""][i["allowed_edit"] ? "" : " onclick='return false' onkeydown='return false'"]></td>
|
329 | 339 | <td>[i["name"]]</td>
|
330 | 340 | </tr>"}
|
331 | 341 | output += {"</table>"}
|
332 | 342 | else
|
333 |
| - for (var/i in values) |
| 343 | + for(var/i in values) |
334 | 344 | output += {"<li><input id="name="[i["name"]]"" style="width: 50px" type="[type]" name="[i["name"]]" value="[i["value"]]">
|
335 | 345 | <label for="[i["name"]]">[i["name"]]</label></li>"}
|
336 | 346 | output += {"</ul><div style="text-align:center">
|
337 |
| - <button type="submit" name="button" value="[Button1]" style="font-size:large;float:[( Button2 ? "left" : "right" )]">[Button1]</button>"} |
| 347 | + <button type="submit" name="button" value="[button1]" style="font-size:large;float:[( button2 ? "left" : "right" )]">[button1]</button>"} |
338 | 348 |
|
339 |
| - if (Button2) |
340 |
| - output += {"<button type="submit" name="button" value="[Button2]" style="font-size:large;[( Button3 ? "" : "float:right" )]">[Button2]</button>"} |
| 349 | + if(button2) |
| 350 | + output += {"<button type="submit" name="button" value="[button2]" style="font-size:large;[( button3 ? "" : "float:right" )]">[button2]</button>"} |
341 | 351 |
|
342 |
| - if (Button3) |
343 |
| - output += {"<button type="submit" name="button" value="[Button3]" style="font-size:large;float:right">[Button3]</button>"} |
| 352 | + if(button3) |
| 353 | + output += {"<button type="submit" name="button" value="[button3]" style="font-size:large;float:right">[button3]</button>"} |
344 | 354 |
|
345 | 355 | output += {"</form></div>"}
|
346 |
| - ..(User, ckey("[User]-[Message]-[Title]-[world.time]-[rand(1,10000)]"), Title, "common.css", width, height, src, StealFocus, Timeout) |
| 356 | + ..(user, ckey("[user]-[message]-[title]-[world.time]-[rand(1,10000)]"), title, "common.css", width, height, src, stealfocus, timeout) |
347 | 357 | set_content(output)
|
348 | 358 |
|
349 |
| -/datum/browser/modal/listpicker/Topic(href,href_list) |
350 |
| - if (href_list["close"] || !user) |
| 359 | +/datum/browser/modal/listpicker/Topic(href, href_list) |
| 360 | + if(href_list["close"] || !user) |
351 | 361 | opentime = 0
|
352 | 362 | return
|
353 |
| - if (href_list["button"]) |
| 363 | + if(href_list["button"]) |
354 | 364 | selectedbutton = href_list["button"]
|
355 |
| - for (var/item in href_list) |
| 365 | + for(var/item in href_list) |
356 | 366 | switch(item)
|
357 |
| - if ("close", "button", "src") |
| 367 | + if("close", "button", "src") |
358 | 368 | continue
|
359 | 369 | else
|
360 | 370 | valueslist[item] = href_list[item]
|
361 | 371 | opentime = 0
|
362 | 372 | close()
|
363 | 373 |
|
364 |
| -/proc/presentpicker(mob/User,Message, Title, Button1="Ok", Button2, Button3, StealFocus = 1,Timeout = 6000,list/values, inputtype = "checkbox", width, height) |
365 |
| - if (!istype(User)) |
366 |
| - if (istype(User, /client/)) |
367 |
| - var/client/C = User |
368 |
| - User = C.mob |
369 |
| - else |
370 |
| - return |
371 |
| - var/datum/browser/modal/listpicker/A = new(User, Message, Title, Button1, Button2, Button3, StealFocus,Timeout, values, inputtype, width, height) |
372 |
| - A.open() |
373 |
| - A.wait() |
374 |
| - if (A.selectedbutton) |
375 |
| - return list("button" = A.selectedbutton, "values" = A.valueslist) |
376 |
| - |
377 |
| -/proc/input_bitfield(mob/User, title, bitfield, current_value, nwidth = 350, nheight = 350, allowed_edit_list = null) |
378 |
| - if (!User || !(bitfield in GLOB.bitfields)) |
| 374 | +/proc/presentpicker(mob/user, message, title, button1="Ok", button2, button3, steal_focus=TRUE, timeout=6000, list/values, input_type="checkbox", width, height) |
| 375 | + // We actually want to pass user as a client, but it already handles mob vs client |
| 376 | + var/datum/browser/modal/listpicker/picker = new(user, message, title, button1, button2, button3, steal_focus, timeout, values, input_type, width, height) |
| 377 | + picker.open() |
| 378 | + picker.wait() |
| 379 | + if(picker.selectedbutton) |
| 380 | + return list("button" = picker.selectedbutton, "values" = picker.valueslist) |
| 381 | + |
| 382 | +/proc/input_bitfield(mob/user, title, bitfield, current_value, nwidth = 350, nheight = 350, allowed_edit_list = null) |
| 383 | + if(!user || !(bitfield in GLOB.bitfields)) |
379 | 384 | return
|
380 | 385 | var/list/pickerlist = list()
|
381 |
| - for (var/i in GLOB.bitfields[bitfield]) |
382 |
| - var/can_edit = 1 |
| 386 | + for(var/i in GLOB.bitfields[bitfield]) |
| 387 | + var/can_edit = TRUE |
383 | 388 | if(!isnull(allowed_edit_list) && !(allowed_edit_list & GLOB.bitfields[bitfield][i]))
|
384 |
| - can_edit = 0 |
385 |
| - if (current_value & GLOB.bitfields[bitfield][i]) |
| 389 | + can_edit = FALSE |
| 390 | + if(current_value & GLOB.bitfields[bitfield][i]) |
386 | 391 | pickerlist += list(list("checked" = 1, "value" = GLOB.bitfields[bitfield][i], "name" = i, "allowed_edit" = can_edit))
|
387 | 392 | else
|
388 | 393 | pickerlist += list(list("checked" = 0, "value" = GLOB.bitfields[bitfield][i], "name" = i, "allowed_edit" = can_edit))
|
389 |
| - var/list/result = presentpicker(User, "", title, Button1="Save", Button2 = "Cancel", Timeout=FALSE, values = pickerlist, width = nwidth, height = nheight) |
390 |
| - if (islist(result)) |
391 |
| - if (result["button"] != "Save") // If the user pressed the cancel button |
| 394 | + var/list/result = presentpicker(user, "", title, button1="Save", button2 = "Cancel", timeout=FALSE, values=pickerlist, width=nwidth, height=nheight) |
| 395 | + if(islist(result)) |
| 396 | + if(result["button"] != "Save") // If the user pressed the cancel button |
392 | 397 | return
|
393 | 398 | . = 0
|
394 |
| - for (var/flag in result["values"]) |
| 399 | + for(var/flag in result["values"]) |
395 | 400 | . |= GLOB.bitfields[bitfield][flag]
|
396 | 401 | else
|
397 | 402 | return
|
0 commit comments