Merge pull request #4332 from Faerdan/dev

NanoUI Gas Cooling/Heating System
This commit is contained in:
Ccomp5950
2014-01-24 18:52:12 -08:00
3 changed files with 191 additions and 125 deletions
@@ -26,7 +26,7 @@
process()
..()
if(!on)
if(!on || !network)
return 0
var/air_heat_capacity = air_contents.heat_capacity()
var/combined_heat_capacity = current_heat_capacity + air_heat_capacity
+141 -124
View File
@@ -1,5 +1,5 @@
/obj/machinery/atmospherics/unary/cold_sink/freezer
name = "Freezer"
name = "gas cooling system"
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "freezer_0"
density = 1
@@ -8,84 +8,91 @@
current_heat_capacity = 1000
New()
..()
initialize_directions = dir
/obj/machinery/atmospherics/unary/cold_sink/freezer/New()
..()
initialize_directions = dir
initialize()
if(node) return
/obj/machinery/atmospherics/unary/cold_sink/freezer/initialize()
if(node) return
var/node_connect = dir
for(var/obj/machinery/atmospherics/target in get_step(src,node_connect))
if(target.initialize_directions & get_dir(target,src))
node = target
break
update_icon()
var/node_connect = dir
for(var/obj/machinery/atmospherics/target in get_step(src,node_connect))
if(target.initialize_directions & get_dir(target,src))
node = target
break
update_icon()
if(src.node)
if(src.on)
icon_state = "freezer_1"
else
icon_state = "freezer"
/obj/machinery/atmospherics/unary/cold_sink/freezer/update_icon()
if(src.node)
if(src.on)
icon_state = "freezer_1"
else
icon_state = "freezer_0"
return
icon_state = "freezer"
else
icon_state = "freezer_0"
return
attack_ai(mob/user as mob)
return src.attack_hand(user)
/obj/machinery/atmospherics/unary/cold_sink/freezer/attack_ai(mob/user as mob)
src.ui_interact(user)
attack_paw(mob/user as mob)
return src.attack_hand(user)
/obj/machinery/atmospherics/unary/cold_sink/freezer/attack_paw(mob/user as mob)
src.ui_interact(user)
attack_hand(mob/user as mob)
user.set_machine(src)
var/temp_text = ""
if(air_contents.temperature > (T0C - 20))
temp_text = "<FONT color=red>[air_contents.temperature]</FONT>"
else if(air_contents.temperature < (T0C - 20) && air_contents.temperature > (T0C - 100))
temp_text = "<FONT color=black>[air_contents.temperature]</FONT>"
/obj/machinery/atmospherics/unary/cold_sink/freezer/attack_hand(mob/user as mob)
src.ui_interact(user)
/obj/machinery/atmospherics/unary/cold_sink/freezer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
// this is the data which will be sent to the ui
var/data[0]
data["on"] = on ? 1 : 0
data["gasPressure"] = round(air_contents.return_pressure())
data["gasTemperature"] = round(air_contents.temperature)
data["minGasTemperature"] = round(T0C - 200)
data["maxGasTemperature"] = round(T20C)
data["targetGasTemperature"] = round(current_temperature)
var/temp_class = "good"
if (air_contents.temperature > (T0C - 20))
temp_class = "bad"
else if (air_contents.temperature < (T0C - 20) && air_contents.temperature > (T0C - 100))
temp_class = "average"
data["gasTemperatureClass"] = temp_class
// 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, "freezer.tmpl", "Gas Cooling System", 440, 300)
// 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/atmospherics/unary/cold_sink/freezer/Topic(href, href_list)
if (href_list["toggleStatus"])
src.on = !src.on
update_icon()
if(href_list["temp"])
var/amount = text2num(href_list["temp"])
if(amount > 0)
src.current_temperature = min(T20C, src.current_temperature+amount)
else
temp_text = "<FONT color=blue>[air_contents.temperature]</FONT>"
var/dat = {"<B>Cryo gas cooling system</B><BR>
Current status: [ on ? "<A href='?src=\ref[src];start=1'>Off</A> <B>On</B>" : "<B>Off</B> <A href='?src=\ref[src];start=1'>On</A>"]<BR>
Current gas temperature: [temp_text]<BR>
Current air pressure: [air_contents.return_pressure()]<BR>
Target gas temperature: <A href='?src=\ref[src];temp=-100'>-</A> <A href='?src=\ref[src];temp=-10'>-</A> <A href='?src=\ref[src];temp=-1'>-</A> [current_temperature] <A href='?src=\ref[src];temp=1'>+</A> <A href='?src=\ref[src];temp=10'>+</A> <A href='?src=\ref[src];temp=100'>+</A><BR>
"}
user << browse(dat, "window=freezer;size=400x500")
onclose(user, "freezer")
Topic(href, href_list)
if ((usr.contents.Find(src) || ((get_dist(src, usr) <= 1) && istype(src.loc, /turf))) || (istype(usr, /mob/living/silicon/ai)))
usr.set_machine(src)
if (href_list["start"])
src.on = !src.on
update_icon()
if(href_list["temp"])
var/amount = text2num(href_list["temp"])
if(amount > 0)
src.current_temperature = min(T20C, src.current_temperature+amount)
else
src.current_temperature = max((T0C - 200), src.current_temperature+amount)
src.updateUsrDialog()
src.add_fingerprint(usr)
return
process()
..()
src.updateUsrDialog()
src.current_temperature = max((T0C - 200), src.current_temperature+amount)
src.add_fingerprint(usr)
return 1
/obj/machinery/atmospherics/unary/cold_sink/freezer/process()
..()
/obj/machinery/atmospherics/unary/heat_reservoir/heater
name = "Heater"
name = "gas heating system"
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "freezer_0"
density = 1
@@ -94,73 +101,83 @@
current_heat_capacity = 1000
New()
..()
initialize_directions = dir
/obj/machinery/atmospherics/unary/heat_reservoir/heater/New()
..()
initialize_directions = dir
initialize()
if(node) return
/obj/machinery/atmospherics/unary/heat_reservoir/heater/initialize()
if(node) return
var/node_connect = dir
for(var/obj/machinery/atmospherics/target in get_step(src,node_connect))
if(target.initialize_directions & get_dir(target,src))
node = target
break
update_icon()
var/node_connect = dir
for(var/obj/machinery/atmospherics/target in get_step(src,node_connect))
if(target.initialize_directions & get_dir(target,src))
node = target
break
update_icon()
if(src.node)
if(src.on)
icon_state = "heater_1"
else
icon_state = "heater"
/obj/machinery/atmospherics/unary/heat_reservoir/heater/update_icon()
if(src.node)
if(src.on)
icon_state = "heater_1"
else
icon_state = "heater_0"
return
icon_state = "heater"
else
icon_state = "heater_0"
return
attack_ai(mob/user as mob)
return src.attack_hand(user)
/obj/machinery/atmospherics/unary/heat_reservoir/heater/attack_ai(mob/user as mob)
src.ui_interact(user)
attack_paw(mob/user as mob)
return src.attack_hand(user)
/obj/machinery/atmospherics/unary/heat_reservoir/heater/attack_paw(mob/user as mob)
src.ui_interact(user)
attack_hand(mob/user as mob)
user.set_machine(src)
var/temp_text = ""
if(air_contents.temperature > (T20C+40))
temp_text = "<FONT color=red>[air_contents.temperature]</FONT>"
/obj/machinery/atmospherics/unary/heat_reservoir/heater/attack_hand(mob/user as mob)
src.ui_interact(user)
/obj/machinery/atmospherics/unary/heat_reservoir/heater/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
// this is the data which will be sent to the ui
var/data[0]
data["on"] = on ? 1 : 0
data["gasPressure"] = round(air_contents.return_pressure())
data["gasTemperature"] = round(air_contents.temperature)
data["minGasTemperature"] = round(T20C)
data["maxGasTemperature"] = round(T20C+280)
data["targetGasTemperature"] = round(current_temperature)
var/temp_class = "normal"
if (air_contents.temperature > (T20C+40))
temp_class = "bad"
data["gasTemperatureClass"] = temp_class
// 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, "freezer.tmpl", "Gas Heating System", 440, 300)
// 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/atmospherics/unary/heat_reservoir/heater/Topic(href, href_list)
if (href_list["toggleStatus"])
src.on = !src.on
update_icon()
if(href_list["temp"])
var/amount = text2num(href_list["temp"])
if(amount > 0)
src.current_temperature = min((T20C+280), src.current_temperature+amount)
else
temp_text = "<FONT color=black>[air_contents.temperature]</FONT>"
src.current_temperature = max(T20C, src.current_temperature+amount)
src.add_fingerprint(usr)
return 1
var/dat = {"<B>Heating system</B><BR>
Current status: [ on ? "<A href='?src=\ref[src];start=1'>Off</A> <B>On</B>" : "<B>Off</B> <A href='?src=\ref[src];start=1'>On</A>"]<BR>
Current gas temperature: [temp_text]<BR>
Current air pressure: [air_contents.return_pressure()]<BR>
Target gas temperature: <A href='?src=\ref[src];temp=-100'>-</A> <A href='?src=\ref[src];temp=-10'>-</A> <A href='?src=\ref[src];temp=-1'>-</A> [current_temperature] <A href='?src=\ref[src];temp=1'>+</A> <A href='?src=\ref[src];temp=10'>+</A> <A href='?src=\ref[src];temp=100'>+</A><BR>
"}
user << browse(dat, "window=heater;size=400x500")
onclose(user, "heater")
Topic(href, href_list)
if ((usr.contents.Find(src) || ((get_dist(src, usr) <= 1) && istype(src.loc, /turf))) || (istype(usr, /mob/living/silicon/ai)))
usr.set_machine(src)
if (href_list["start"])
src.on = !src.on
update_icon()
if(href_list["temp"])
var/amount = text2num(href_list["temp"])
if(amount > 0)
src.current_temperature = min((T20C+280), src.current_temperature+amount)
else
src.current_temperature = max(T20C, src.current_temperature+amount)
src.updateUsrDialog()
src.add_fingerprint(usr)
return
process()
..()
src.updateUsrDialog()
/obj/machinery/atmospherics/unary/heat_reservoir/heater/process()
..()
+49
View File
@@ -0,0 +1,49 @@
<div class="item">
<div class="itemLabel">
Status:
</div>
<div class="itemContent">
{{:~link('On', 'power', {'toggleStatus' : 1}, on ? 'selected' : null)}}{{:~link('Off', 'close', {'toggleStatus' : 1}, on ? null : 'selected')}}
</div>
</div>
<div class="item">
<div class="itemLabel">
Gas Pressure:
</div>
<div class="itemContent">
{{:gasPressure}} kPa
</div>
</div>
<h3>Gas Temperature</h3>
<div class="item">
<div class="itemLabel">
Current:
</div>
<div class="itemContent">
{{:~displayBar(gasTemperature, minGasTemperature, maxGasTemperature, gasTemperatureClass)}}
<div class="statusValue">
<span class="{{:gasTemperatureClass}}">{{:gasTemperature}} K</span>
</div>
</div>
</div>
<div class="item">
<div class="itemLabel">
Target:
</div>
<div class="itemContent">
{{:~displayBar(targetGasTemperature, minGasTemperature, maxGasTemperature)}}
<div style="clear: both; padding-top: 4px;">
{{:~link('-', null, {'temp' : -100}, (targetGasTemperature > minGasTemperature) ? null : 'disabled')}}
{{:~link('-', null, {'temp' : -10}, (targetGasTemperature > minGasTemperature) ? null : 'disabled')}}
{{:~link('-', null, {'temp' : -1}, (targetGasTemperature > minGasTemperature) ? null : 'disabled')}}
<div style="float: left; width: 80px; text-align: center;">&nbsp;{{:targetGasTemperature}} K&nbsp;</div>
{{:~link('+', null, {'temp' : 1}, (targetGasTemperature < maxGasTemperature) ? null : 'disabled')}}
{{:~link('+', null, {'temp' : 10}, (targetGasTemperature < maxGasTemperature) ? null : 'disabled')}}
{{:~link('+', null, {'temp' : 100}, (targetGasTemperature < maxGasTemperature) ? null : 'disabled')}}
</div>
</div>
</div>