From c33e97afb562d8968b00959f41231b7b7b2fe4fe Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Sat, 26 Dec 2015 14:45:15 -0800 Subject: [PATCH 1/4] Ghost popup re-work Part 1, the main frame work. --- code/__HELPERS/game.dm | 17 +++---- code/datums/browser.dm | 100 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 12 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 90c7b7ff0399..b098af535414 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 7a218a85367a..2b24f33e52e5 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... From 69a70daebd9bea4cde05cbbdedc754f77ac3961c Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Thu, 31 Dec 2015 01:53:05 -0800 Subject: [PATCH 2/4] Ghost popup part 2: The didn't do much-a-ning Fixes button3, does the remie --- code/controllers/subsystem/pai.dm | 2 +- code/datums/browser.dm | 49 ++++++++++++++++++------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/code/controllers/subsystem/pai.dm b/code/controllers/subsystem/pai.dm index 3549b64f1e55..7c6678e5c367 100644 --- a/code/controllers/subsystem/pai.dm +++ b/code/controllers/subsystem/pai.dm @@ -201,7 +201,7 @@ var/datum/subsystem/pai/SSpai if(!C) return asked.Add(C.key) asked[C.key] = world.time - var/response = alert(C, "Someone is requesting a pAI personality. Would you like to play as a personal AI?", "pAI Request", "Yes", "No", "Never for this round") + var/response = tgalert(C, "Someone is requesting a pAI personality. Would you like to play as a personal AI?", "pAI Request", "Yes", "No", "Never for this round", StealFocus=0, Timeout=askDelay) if(!C) return //handle logouts that happen whilst the alert is waiting for a response. if(response == "Yes") recruitWindow(C.mob) diff --git a/code/datums/browser.dm b/code/datums/browser.dm index 2b24f33e52e5..e4b268c929c7 100644 --- a/code/datums/browser.dm +++ b/code/datums/browser.dm @@ -102,8 +102,10 @@ if (use_onclose) spawn(0) //winexists sleeps, so we don't need to. - for (var/i = 0, !winexists(user, window_id) && i < 3, i++) + for (var/i in 1 to 10) + if (user && winexists(user, window_id)) onclose(user, window_id, ref) + break /datum/browser/proc/close() @@ -118,15 +120,18 @@ /datum/browser/alert/New(User,Message,Title,Button1="Ok",Button2,Button3,StealFocus = 1,Timeout=6000) if (!User) return + var/output = {"
[Message]

- [Button1]"} +
+ [Button1]"} if (Button2) - output += {"[Button2]"} + output += {"[Button2]"} if (Button3) - EXCEPTION("button 3 is not impimented yet") + output += {"[Button1]"} + output += {"
"} ..(User, ckey("[User]-[Message]-[Title]-[world.time]-[rand(1,10000)]"), Title, 350, 150, src) set_content(output) @@ -147,11 +152,13 @@ //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") + for (var/i in 1 to 10) + if (user && winexists(user, window_id)) + if (focusedwindow) + winset(user, focusedwindow, "focus=true") + else + winset(user, "mapwindow", "focus=true") + break if (timeout) spawn(timeout) close() @@ -175,7 +182,19 @@ opentime = 0 close() +//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 +//Same shit, but it returns the button number, could at some point support unlimited button amounts. /proc/askuser(var/mob/User,Message, Title, Button1="Ok", Button2, Button3, StealFocus = 1, Timeout = 6000) if (!istype(User)) if (istype(User, /client/)) @@ -189,18 +208,6 @@ 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... From ba660d98ba156607a8c91dfdded732daa70199b3 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Thu, 31 Dec 2015 02:23:53 -0800 Subject: [PATCH 3/4] Some minor ghost popup fixes --- code/datums/browser.dm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/datums/browser.dm b/code/datums/browser.dm index e4b268c929c7..7a1228357cec 100644 --- a/code/datums/browser.dm +++ b/code/datums/browser.dm @@ -102,10 +102,10 @@ if (use_onclose) spawn(0) //winexists sleeps, so we don't need to. - for (var/i in 1 to 10) - if (user && winexists(user, window_id)) - onclose(user, window_id, ref) - break + for (var/i in 1 to 10) + if (user && winexists(user, window_id)) + onclose(user, window_id, ref) + break /datum/browser/proc/close() @@ -129,7 +129,7 @@ output += {"[Button2]"} if (Button3) - output += {"[Button1]"} + output += {"[Button3]"} output += {""} From 3ebc6749af3f10e3bbaed60fca300b8bd14c4194 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Thu, 31 Dec 2015 14:15:49 -0800 Subject: [PATCH 4/4] Brings shade selection into the pollCanidates system --- code/game/gamemodes/wizard/soulstone.dm | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/code/game/gamemodes/wizard/soulstone.dm b/code/game/gamemodes/wizard/soulstone.dm index ce031d5d4d28..84b9e6da663a 100644 --- a/code/game/gamemodes/wizard/soulstone.dm +++ b/code/game/gamemodes/wizard/soulstone.dm @@ -238,27 +238,11 @@ /obj/item/device/soulstone/proc/getCultGhost(obj/item/device/soulstone/C, mob/living/carbon/human/T, mob/U) - var/list/candidates = get_candidates(ROLE_CULTIST) - shuffle(candidates) - - var/time_passed = world.time - var/list/consenting_candidates = list() - - for(var/candidate in candidates) - - spawn(0) - switch(alert(candidate, "Would you like to play as a Shade? Please choose quickly!","Confirmation","Yes","No")) - if("Yes") - if((world.time-time_passed)>=50 || !src) - return - consenting_candidates += candidate - - sleep(50) + var/list/consenting_candidates = pollCandidates("Would you like to play as a Shade?", be_special_flag = ROLE_CULTIST, poll_time = 100) if(!T) //target mob got soulstoned or gibbed during sleep(50) return 0 - listclearnulls(consenting_candidates) //some candidates might have left during sleep(50) if(consenting_candidates.len) var/client/ghost = null