diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm
index 90c7b7ff039..b098af53541 100644
--- a/code/__HELPERS/game.dm
+++ b/code/__HELPERS/game.dm
@@ -389,22 +389,19 @@
continue
spawn(0)
G << 'sound/misc/notice2.ogg' //Alerting them to their consideration
- switch(alert(G,Question,"Please answer in [poll_time/10] seconds!","Yes","No"))
- if("Yes")
+ switch(askuser(G,Question,"Please answer in [poll_time/10] seconds!","Yes","No", StealFocus=0, Timeout=poll_time))
+ if(1)
G << "Choice registered: Yes."
- if((world.time-time_passed)>poll_time)//If more than 30 game seconds passed.
+ if((world.time-time_passed)>poll_time)
G << "Sorry, you were too late for the consideration!"
G << 'sound/machines/buzz-sigh.ogg'
- return
- candidates += G
- if("No")
+ else
+ candidates += G
+ if(2)
G << "Choice registered: No."
- return
- else
- return
sleep(poll_time)
- //Check all our candidates, to make sure they didn't log off during the 30 second wait period.
+ //Check all our candidates, to make sure they didn't log off during the wait period.
for(var/mob/dead/observer/G in candidates)
if(!G.key || !G.client)
candidates.Remove(G)
diff --git a/code/datums/browser.dm b/code/datums/browser.dm
index 7a218a85367..2b24f33e52e 100644
--- a/code/datums/browser.dm
+++ b/code/datums/browser.dm
@@ -5,7 +5,7 @@
var/width = 0
var/height = 0
var/atom/ref = null
- var/window_options = "focus=0;can_close=1;can_minimize=1;can_maximize=0;can_resize=1;titlebar=1;" // window option is set using window_id
+ var/window_options = "can_close=1;can_minimize=1;can_maximize=0;can_resize=1;titlebar=1;" // window option is set using window_id
var/stylesheets[0]
var/scripts[0]
var/title_image
@@ -100,11 +100,107 @@
window_size = "size=[width]x[height];"
user << browse(get_content(), "window=[window_id];[window_size][window_options]")
if (use_onclose)
- onclose(user, window_id, ref)
+ spawn(0)
+ //winexists sleeps, so we don't need to.
+ for (var/i = 0, !winexists(user, window_id) && i < 3, i++)
+ onclose(user, window_id, ref)
+
/datum/browser/proc/close()
user << browse(null, "window=[window_id]")
+/datum/browser/alert
+ var/selectedbutton = 0
+ var/opentime = 0
+ var/timeout
+ var/stealfocus
+
+/datum/browser/alert/New(User,Message,Title,Button1="Ok",Button2,Button3,StealFocus = 1,Timeout=6000)
+ if (!User)
+ return
+ var/output = {"
[Message]
+ [Button1]"}
+
+ if (Button2)
+ output += {"[Button2]"}
+
+ if (Button3)
+ EXCEPTION("button 3 is not impimented yet")
+
+
+ ..(User, ckey("[User]-[Message]-[Title]-[world.time]-[rand(1,10000)]"), Title, 350, 150, src)
+ set_content(output)
+ stealfocus = StealFocus
+ if (!StealFocus)
+ window_options += "focus=false;"
+ timeout = Timeout
+
+/datum/browser/alert/open()
+ set waitfor = 0
+ opentime = world.time
+
+ if (stealfocus)
+ . = ..(use_onclose = 1)
+ else
+ var/focusedwindow = winget(user, null, "focus")
+ . = ..(use_onclose = 1)
+
+ //waits for the window to show up client side before attempting to un-focus it
+ //winexists sleeps until it gets a reply from the client, so we don't need to bother sleeping
+ for (var/i = 0, user && !winexists(user, window_id) && i < 10, i++)
+ if (focusedwindow)
+ winset(user, focusedwindow, "focus=true")
+ else
+ winset(user, "mapwindow", "focus=true")
+ if (timeout)
+ spawn(timeout)
+ close()
+
+/datum/browser/alert/close()
+ .=..()
+ opentime = 0
+
+/datum/browser/alert/proc/wait()
+ while (opentime && selectedbutton <= 0 && (!timeout || opentime+timeout >= world.time))
+ sleep (1)
+
+/datum/browser/alert/Topic(href,href_list)
+ if (href_list["close"] || !user || !user.client)
+ opentime = 0
+ return
+ if (href_list["button"])
+ var/button = text2num(href_list["button"])
+ if (button <= 3 && button >= 1)
+ selectedbutton = button
+ opentime = 0
+ close()
+
+
+/proc/askuser(var/mob/User,Message, Title, Button1="Ok", Button2, Button3, StealFocus = 1, Timeout = 6000)
+ if (!istype(User))
+ if (istype(User, /client/))
+ var/client/C = User
+ User = C.mob
+ else
+ return
+ var/datum/browser/alert/A = new(User, Message, Title, Button1, Button2, Button3, StealFocus, Timeout)
+ A.open()
+ A.wait()
+ if (A.selectedbutton)
+ return A.selectedbutton
+
+//designed as a drop in replacement for alert(); functions the same. (outside of needing User specified)
+/proc/tgalert(var/mob/User, Message, Title, Button1="Ok", Button2, Button3, StealFocus = 1, Timeout = 6000)
+ if (!User)
+ User = usr
+ switch(askuser(User, Message, Title, Button1, Button2, Button3, StealFocus, Timeout))
+ if (1)
+ return Button1
+ if (2)
+ return Button2
+ if (3)
+ return Button3
+
// This will allow you to show an icon in the browse window
// This is added to mob so that it can be used without a reference to the browser object
// There is probably a better place for this...