diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index eabee2ba46..cd63e415a4 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -255,6 +255,7 @@ 'nano/templates/dna_modifier.tmpl', 'nano/templates/telescience_console.tmpl', 'nano/templates/pda.tmpl', + 'nano/templates/smes.tmpl', 'nano/templates/uplink.tmpl', 'nano/images/uiBackground.png', 'nano/images/uiIcons16.png', diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index efe77a439e..9ceeb4e21e 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -21,7 +21,7 @@ var/chargecount = 0 var/chargelevel = 50000 var/online = 1 - var/n_tag = null + var/name_tag = null var/obj/machinery/power/terminal/terminal = null //Holders for powerout event. var/last_output = 0 @@ -122,7 +122,6 @@ if(last_disp != chargedisplay() || last_chrg != charging || last_onln != online) updateicon() - updateDialog() return // called after all power processes are finished @@ -164,48 +163,45 @@ /obj/machinery/power/smes/attack_ai(mob/user) add_fingerprint(user) - if(stat & BROKEN) return - interact(user) + ui_interact(user) /obj/machinery/power/smes/attack_hand(mob/user) add_fingerprint(user) - if(stat & BROKEN) return - interact(user) + ui_interact(user) + + +/obj/machinery/power/smes/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null) - -/obj/machinery/power/smes/interact(mob/user) - if(get_dist(src, user) > 1 && !istype(user, /mob/living/silicon)) - user.unset_machine() - user << browse(null, "window=smes") + if(stat & BROKEN) return - user.set_machine(src) - - var/t = "SMES Power Storage Unit [n_tag? "([n_tag])" : null]
"
-
-	t += "Stored capacity : [round(100.0*charge/capacity, 0.1)]%

" - - t += "Input: [charging ? "Charging" : "Not Charging"] [chargemode ? "Auto Off" : "Auto Off "]
" - - - t += "Input level: M - - - [add_lspace(chargelevel,5)] + + + M
" - - t += "

" - - t += "Output: [online ? "Online Offline" : "Online Offline "]
" - - t += "Output level: M - - - [add_lspace(output,5)] + + + M
" - - t += "Output load: [round(loaddemand)] W
" - - t += "

Close" - - t += "
" - user << browse(t, "window=smes;size=460x300") - onclose(user, "smes") - return + // this is the data which will be sent to the ui + var/data[0] + data["nameTag"] = name_tag + data["storedCapacity"] = round(100.0*charge/capacity, 0.1) + data["charging"] = charging + data["chargeMode"] = chargemode + data["chargeLevel"] = chargelevel + data["chargeMax"] = SMESMAXCHARGELEVEL + data["outputOnline"] = online + data["outputLevel"] = output + data["outputMax"] = SMESMAXOUTPUT + data["outputLoad"] = round(loaddemand) + // update the ui if it exists, returns null if no ui is passed/found + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data) + if (!ui) + // the ui does not exist, so we'll create a new() one + // for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm + ui = new(user, src, ui_key, "smes.tmpl", "SMES Power Storage Unit", 540, 380) + // when the ui is first opened this is the data it will use + ui.set_initial_data(data) + // open the new ui window + ui.open() + // auto update every Master Controller tick + ui.set_auto_update(1) + /obj/machinery/power/smes/Topic(href, href_list) ..() @@ -219,85 +215,42 @@ //world << "[href] ; [href_list[href]]" - if (( usr.machine==src && ((get_dist(src, usr) <= 1) && istype(src.loc, /turf))) || (istype(usr, /mob/living/silicon/ai))) + if (!istype(src.loc, /turf) || istype(usr, /mob/living/silicon/ai)) + return 0 // Do not update ui + if( href_list["cmode"] ) + chargemode = !chargemode + if(!chargemode) + charging = 0 + updateicon() - if( href_list["close"] ) - usr << browse(null, "window=smes") - usr.unset_machine() - return + else if( href_list["online"] ) + online = !online + updateicon() + else if( href_list["input"] ) + switch( href_list["input"] ) + if("min") + chargelevel = 0 + if("max") + chargelevel = SMESMAXCHARGELEVEL //30000 + if("set") + chargelevel = input(usr, "Enter new input level (0-[SMESMAXCHARGELEVEL])", "SMES Input Power Control", chargelevel) as num + chargelevel = max(0, min(SMESMAXCHARGELEVEL, chargelevel)) // clamp to range - else if( href_list["cmode"] ) - chargemode = !chargemode - if(!chargemode) - charging = 0 - updateicon() - - else if( href_list["online"] ) - online = !online - updateicon() - else if( href_list["input"] ) - - var/i = text2num(href_list["input"]) - - var/d = 0 - switch(i) - if(-4) - chargelevel = 0 - if(4) - chargelevel = SMESMAXCHARGELEVEL //30000 - - if(1) - d = 100 - if(-1) - d = -100 - if(2) - d = 1000 - if(-2) - d = -1000 - if(3) - d = 10000 - if(-3) - d = -10000 - - chargelevel += d - chargelevel = max(0, min(SMESMAXCHARGELEVEL, chargelevel)) // clamp to range - - else if( href_list["output"] ) - - var/i = text2num(href_list["output"]) - - var/d = 0 - switch(i) - if(-4) - output = 0 - if(4) - output = SMESMAXOUTPUT //30000 - - if(1) - d = 100 - if(-1) - d = -100 - if(2) - d = 1000 - if(-2) - d = -1000 - if(3) - d = 10000 - if(-3) - d = -10000 - - output += d - output = max(0, min(SMESMAXOUTPUT, output)) // clamp to range - - investigate_log("input/output; [chargelevel>output?"":""][chargelevel]/[output] | Output-mode: [online?"on":"off"] | Input-mode: [chargemode?"auto":"off"] by [usr.key]","singulo") - src.updateUsrDialog() - - else - usr << browse(null, "window=smes") - usr.unset_machine() - return + else if( href_list["output"] ) + switch( href_list["output"] ) + if("min") + output = 0 + if("max") + output = SMESMAXOUTPUT //30000 + if("set") + output = input(usr, "Enter new output level (0-[SMESMAXOUTPUT])", "SMES Output Power Control", output) as num + output = max(0, min(SMESMAXOUTPUT, output)) // clamp to range + investigate_log("input/output; [chargelevel>output?"":""][chargelevel]/[output] | Output-mode: [online?"on":"off"] | Input-mode: [chargemode?"auto":"off"] by [usr.key]","singulo") + + return 1 + /obj/machinery/power/smes/proc/ion_act() if(src.z == 1) diff --git a/nano/templates/smes.tmpl b/nano/templates/smes.tmpl new file mode 100644 index 0000000000..c4431cd805 --- /dev/null +++ b/nano/templates/smes.tmpl @@ -0,0 +1,79 @@ +
+
+ Stored Capacity: +
+
+ {{:~displayBar(storedCapacity, 0, 100, charging ? 'good' : 'average')}} +
+ {{:~round(storedCapacity)}}% +
+
+
+ +

Input Management

+
+
+ Charge Mode: +
+
+ {{:~link('Auto', 'refresh', {'cmode' : 1}, chargeMode ? 'selected' : null)}}{{:~link('Off', 'close', {'cmode' : 1}, chargeMode ? null : 'selected')}} +   + {{if charging}} + [Charging] + {{else}} + [Not Charging] + {{/if}} +
+
+ +
+
+ Input Level: +
+
+ {{:~displayBar(chargeLevel, 0, chargeMax)}} +
+ {{:~link('MIN', null, {'input' : 'min'}, (chargeLevel > 0) ? null : 'disabled')}} + {{:~link('MAX', null, {'input' : 'max'}, (chargeLevel < chargeMax) ? null : 'disabled')}} + {{:~link('SET', null, {'input' : 'set'}, null)}} +
 {{:chargeLevel}} W 
+
+
+
+ +

Output Management

+
+
+ Output Status: +
+
+ {{:~link('Online', 'power', {'online' : 1}, outputOnline ? 'selected' : null)}}{{:~link('Offline', 'close', {'online' : 1}, outputOnline ? null : 'selected')}} +
+
+ +
+
+ Output Level: +
+
+ {{:~displayBar(outputLevel, 0, outputMax)}} +
+ {{:~link('MIN', null, {'output' : 'min'}, (outputLevel > 0) ? null : 'disabled')}} + {{:~link('MAX', null, {'output' : 'max'}, (outputLevel < outputMax) ? null : 'disabled')}} + {{:~link('SET', null, {'output' : 'set'}, null)}} +
 {{:outputLevel}} W 
+
+
+
+ +
+
+ Output Load: +
+
+ {{:~displayBar(outputLoad, 0, outputMax, (outputLoad < outputLevel) ? 'good' : 'average')}} +
+ {{:outputLoad}} W +
+
+
\ No newline at end of file