SMES NanoUI

* Converted SMES to NanoUI.
This commit is contained in:
Mark Aherne (Faerdan)
2014-01-12 01:28:03 +00:00
parent cbcd3d1468
commit 1f50cae6c2
3 changed files with 144 additions and 111 deletions

View File

@@ -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',

View File

@@ -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 = "<TT><B>SMES Power Storage Unit</B> [n_tag? "([n_tag])" : null]<HR><PRE>"
t += "Stored capacity : [round(100.0*charge/capacity, 0.1)]%<BR><BR>"
t += "Input: [charging ? "Charging" : "Not Charging"] [chargemode ? "<B>Auto</B> <A href = '?src=\ref[src];cmode=1'>Off</A>" : "<A href = '?src=\ref[src];cmode=1'>Auto</A> <B>Off</B> "]<BR>"
t += "Input level: <A href = '?src=\ref[src];input=-4'>M</A> <A href = '?src=\ref[src];input=-3'>-</A> <A href = '?src=\ref[src];input=-2'>-</A> <A href = '?src=\ref[src];input=-1'>-</A> [add_lspace(chargelevel,5)] <A href = '?src=\ref[src];input=1'>+</A> <A href = '?src=\ref[src];input=2'>+</A> <A href = '?src=\ref[src];input=3'>+</A> <A href = '?src=\ref[src];input=4'>M</A><BR>"
t += "<BR><BR>"
t += "Output: [online ? "<B>Online</B> <A href = '?src=\ref[src];online=1'>Offline</A>" : "<A href = '?src=\ref[src];online=1'>Online</A> <B>Offline</B> "]<BR>"
t += "Output level: <A href = '?src=\ref[src];output=-4'>M</A> <A href = '?src=\ref[src];output=-3'>-</A> <A href = '?src=\ref[src];output=-2'>-</A> <A href = '?src=\ref[src];output=-1'>-</A> [add_lspace(output,5)] <A href = '?src=\ref[src];output=1'>+</A> <A href = '?src=\ref[src];output=2'>+</A> <A href = '?src=\ref[src];output=3'>+</A> <A href = '?src=\ref[src];output=4'>M</A><BR>"
t += "Output load: [round(loaddemand)] W<BR>"
t += "<BR></PRE><HR><A href='?src=\ref[src];close=1'>Close</A>"
t += "</TT>"
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?"<font color='green'>":"<font color='red'>"][chargelevel]/[output]</font> | Output-mode: [online?"<font color='green'>on</font>":"<font color='red'>off</font>"] | Input-mode: [chargemode?"<font color='green'>auto</font>":"<font color='red'>off</font>"] 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?"<font color='green'>":"<font color='red'>"][chargelevel]/[output]</font> | Output-mode: [online?"<font color='green'>on</font>":"<font color='red'>off</font>"] | Input-mode: [chargemode?"<font color='green'>auto</font>":"<font color='red'>off</font>"] by [usr.key]","singulo")
return 1
/obj/machinery/power/smes/proc/ion_act()
if(src.z == 1)

79
nano/templates/smes.tmpl Normal file
View File

@@ -0,0 +1,79 @@
<div class="item">
<div class="itemLabel">
Stored Capacity:
</div>
<div class="itemContent">
{{:~displayBar(storedCapacity, 0, 100, charging ? 'good' : 'average')}}
<div class="statusValue">
{{:~round(storedCapacity)}}%
</div>
</div>
</div>
<h3>Input Management</h3>
<div class="item">
<div class="itemLabel">
Charge Mode:
</div>
<div class="itemContent">
{{:~link('Auto', 'refresh', {'cmode' : 1}, chargeMode ? 'selected' : null)}}{{:~link('Off', 'close', {'cmode' : 1}, chargeMode ? null : 'selected')}}
&nbsp;
{{if charging}}
[<span class='good'>Charging</span>]
{{else}}
[<span class='average'>Not Charging</span>]
{{/if}}
</div>
</div>
<div class="item">
<div class="itemLabel">
Input Level:
</div>
<div class="itemContent">
{{:~displayBar(chargeLevel, 0, chargeMax)}}
<div style="clear: both; padding-top: 4px;">
{{:~link('MIN', null, {'input' : 'min'}, (chargeLevel > 0) ? null : 'disabled')}}
{{:~link('MAX', null, {'input' : 'max'}, (chargeLevel < chargeMax) ? null : 'disabled')}}
{{:~link('SET', null, {'input' : 'set'}, null)}}
<div style="float: left; width: 80px; text-align: center;">&nbsp;{{:chargeLevel}} W&nbsp;</div>
</div>
</div>
</div>
<h3>Output Management</h3>
<div class="item">
<div class="itemLabel">
Output Status:
</div>
<div class="itemContent">
{{:~link('Online', 'power', {'online' : 1}, outputOnline ? 'selected' : null)}}{{:~link('Offline', 'close', {'online' : 1}, outputOnline ? null : 'selected')}}
</div>
</div>
<div class="item">
<div class="itemLabel">
Output Level:
</div>
<div class="itemContent">
{{:~displayBar(outputLevel, 0, outputMax)}}
<div style="clear: both; padding-top: 4px;">
{{:~link('MIN', null, {'output' : 'min'}, (outputLevel > 0) ? null : 'disabled')}}
{{:~link('MAX', null, {'output' : 'max'}, (outputLevel < outputMax) ? null : 'disabled')}}
{{:~link('SET', null, {'output' : 'set'}, null)}}
<div style="float: left; width: 80px; text-align: center;">&nbsp;{{:outputLevel}} W&nbsp;</div>
</div>
</div>
</div>
<div class="item">
<div class="itemLabel">
Output Load:
</div>
<div class="itemContent">
{{:~displayBar(outputLoad, 0, outputMax, (outputLoad < outputLevel) ? 'good' : 'average')}}
<div class="statusValue">
{{:outputLoad}} W
</div>
</div>
</div>