mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-20 20:45:28 +01:00
Nano UI for SMES
Screenshot: http://imgur.com/63D3f8b Buttons are greyed because there's no input available.
This commit is contained in:
@@ -81,8 +81,8 @@
|
||||
if(istype(get_area(S), /area/turret_protected) || S.z != 1)
|
||||
continue
|
||||
S.charge = 0
|
||||
S.output = 0
|
||||
S.online = 0
|
||||
S.output_level = 0
|
||||
S.outputting = 0
|
||||
S.updateicon()
|
||||
S.power_change()
|
||||
|
||||
@@ -133,8 +133,8 @@
|
||||
if(S.z != 1)
|
||||
continue
|
||||
S.charge = S.capacity
|
||||
S.output = 200000
|
||||
S.online = 1
|
||||
S.output_level = 200000
|
||||
S.outputting = 1
|
||||
S.updateicon()
|
||||
S.power_change()
|
||||
for(var/area/A in world)
|
||||
@@ -153,8 +153,8 @@
|
||||
if(S.z != 1)
|
||||
continue
|
||||
S.charge = S.capacity
|
||||
S.output = 200000
|
||||
S.online = 1
|
||||
S.output_level = 200000
|
||||
S.outputting = 1
|
||||
S.updateicon()
|
||||
S.power_change()
|
||||
|
||||
|
||||
@@ -1087,7 +1087,7 @@ var/global/list/g_fancy_list_of_safe_types = null
|
||||
|
||||
for(var/obj/machinery/power/smes/SMES in world)
|
||||
if(SMES.anchored)
|
||||
SMES.chargemode = 1
|
||||
SMES.input_attempt = 1
|
||||
|
||||
/client/proc/cmd_debug_mob_lists()
|
||||
set category = "Debug"
|
||||
|
||||
@@ -236,6 +236,7 @@ var/next_external_rsc = 0
|
||||
'nano/css/shared.css',
|
||||
'nano/css/icons.css',
|
||||
'nano/templates/chem_dispenser.tmpl',
|
||||
'nano/templates/smes.tmpl',
|
||||
'nano/templates/apc.tmpl',
|
||||
'nano/templates/cryo.tmpl',
|
||||
'nano/images/uiBackground.png',
|
||||
|
||||
+108
-145
@@ -1,8 +1,8 @@
|
||||
// the SMES
|
||||
// stores power
|
||||
|
||||
#define SMESMAXCHARGELEVEL 200000
|
||||
#define SMESMAXOUTPUT 200000
|
||||
#define SMES_MAX_INPUT_LEVEL 200000
|
||||
#define SMES_MAX_OUTPUT_LEVEL 200000
|
||||
|
||||
/obj/machinery/power/smes
|
||||
name = "power storage unit"
|
||||
@@ -11,17 +11,18 @@
|
||||
density = 1
|
||||
anchored = 1
|
||||
use_power = 0
|
||||
var/output = 50000
|
||||
var/lastout = 0
|
||||
var/loaddemand = 0
|
||||
var/capacity = 5e6
|
||||
var/charge = 1e6
|
||||
var/charging = 0
|
||||
var/chargemode = 0
|
||||
var/chargecount = 0
|
||||
var/chargelevel = 50000
|
||||
var/online = 1
|
||||
var/n_tag = null
|
||||
var/capacity = 5e6 // maximum charge
|
||||
var/charge = 1e6 //actual charge
|
||||
|
||||
var/input_attempt = 0 // 1 = attempting to charge, 0 = not attempting to charge
|
||||
var/inputting = 0 // 1 = actually inputting, 0 = not inputting
|
||||
var/input_level = 50000 // amount of power the SMES attempts to charge by
|
||||
var/input_available = 0 //amount of charge available from input last tick
|
||||
|
||||
var/outputting = 1 //1 = actually outputting, 0 = not outputting
|
||||
var/output_level = 50000 // amount of power the SMES attempts to output
|
||||
var/output_used = 0 // amount of power actually outputted. may be less than output_level if the powernet returns excess power
|
||||
|
||||
var/obj/machinery/power/terminal/terminal = null
|
||||
|
||||
|
||||
@@ -52,12 +53,12 @@
|
||||
overlays.Cut()
|
||||
if(stat & BROKEN) return
|
||||
|
||||
overlays += image('icons/obj/power.dmi', "smes-op[online]")
|
||||
overlays += image('icons/obj/power.dmi', "smes-op[outputting]")
|
||||
|
||||
if(charging)
|
||||
if(inputting)
|
||||
overlays += image('icons/obj/power.dmi', "smes-oc1")
|
||||
else
|
||||
if(chargemode)
|
||||
if(input_attempt)
|
||||
overlays += image('icons/obj/power.dmi', "smes-oc0")
|
||||
|
||||
var/clevel = chargedisplay()
|
||||
@@ -78,51 +79,42 @@
|
||||
|
||||
//store machine state to see if we need to update the icon overlays
|
||||
var/last_disp = chargedisplay()
|
||||
var/last_chrg = charging
|
||||
var/last_onln = online
|
||||
var/last_chrg = inputting
|
||||
var/last_onln = outputting
|
||||
|
||||
if(terminal)
|
||||
var/excess = terminal.surplus()
|
||||
input_available = terminal.surplus()
|
||||
|
||||
if(charging)
|
||||
if(excess >= 0) // if there's power available, try to charge
|
||||
if(inputting)
|
||||
if(input_available > 0 && input_available >= input_level) // if there's power available, try to charge
|
||||
|
||||
var/load = min((capacity-charge)/SMESRATE, chargelevel) // charge at set rate, limited to spare capacity
|
||||
var/load = min((capacity-charge)/SMESRATE, input_level) // charge at set rate, limited to spare capacity
|
||||
|
||||
charge += load * SMESRATE // increase the charge
|
||||
|
||||
add_load(load) // add the load to the terminal side network
|
||||
|
||||
else // if not enough capcity
|
||||
charging = 0 // stop charging
|
||||
chargecount = 0
|
||||
inputting = 0 // stop inputting
|
||||
|
||||
else
|
||||
if(chargemode)
|
||||
if(chargecount > rand(3,6))
|
||||
charging = 1
|
||||
chargecount = 0
|
||||
else if(input_attempt)
|
||||
if(input_available > 0 && input_available >= input_level)
|
||||
inputting = 1
|
||||
|
||||
if(excess > chargelevel)
|
||||
chargecount++
|
||||
else
|
||||
chargecount = 0
|
||||
else
|
||||
chargecount = 0
|
||||
|
||||
if(online) // if outputting
|
||||
lastout = min( charge/SMESRATE, output) //limit output to that stored
|
||||
if(outputting)
|
||||
output_used = min( charge/SMESRATE, output_level) //limit output to that stored
|
||||
|
||||
charge -= lastout*SMESRATE // reduce the storage (may be recovered in /restore() if excessive)
|
||||
charge -= output_used*SMESRATE // reduce the storage (may be recovered in /restore() if excessive)
|
||||
|
||||
add_avail(lastout) // add output to powernet (smes side)
|
||||
add_avail(output_used) // add output to powernet (smes side)
|
||||
|
||||
if(charge < 0.0001)
|
||||
online = 0 // stop output if charge falls to zero
|
||||
outputting = 0
|
||||
investigate_log("lost power and turned <font color='red'>off</font>","singulo")
|
||||
|
||||
// only update icon if state changed
|
||||
if(last_disp != chargedisplay() || last_chrg != charging || last_onln != online)
|
||||
if(last_disp != chargedisplay() || last_chrg != inputting || last_onln != outputting)
|
||||
updateicon()
|
||||
|
||||
updateDialog()
|
||||
@@ -136,13 +128,13 @@
|
||||
if(stat & BROKEN)
|
||||
return
|
||||
|
||||
if(!online)
|
||||
loaddemand = 0
|
||||
if(!outputting)
|
||||
output_used = 0
|
||||
return
|
||||
|
||||
var/excess = powernet.netexcess // this was how much wasn't used on the network last ptick, minus any removed by other SMESes
|
||||
|
||||
excess = min(lastout, excess) // clamp it to how much was actually output by this SMES last ptick
|
||||
excess = min(output_used, excess) // clamp it to how much was actually output by this SMES last ptick
|
||||
|
||||
excess = min((capacity-charge)/SMESRATE, excess) // for safety, also limit recharge by space capacity of SMES (shouldn't happen)
|
||||
|
||||
@@ -153,7 +145,7 @@
|
||||
charge += excess * SMESRATE
|
||||
powernet.netexcess -= excess // remove the excess from the powernet, so later SMESes don't try to use it
|
||||
|
||||
loaddemand = lastout-excess
|
||||
output_used -= excess
|
||||
|
||||
if(clev != chargedisplay() )
|
||||
updateicon()
|
||||
@@ -178,37 +170,39 @@
|
||||
|
||||
|
||||
/obj/machinery/power/smes/interact(mob/user)
|
||||
if(get_dist(src, user) > 1 && !istype(user, /mob/living/silicon/ai))
|
||||
user.unset_machine()
|
||||
user << browse(null, "window=smes")
|
||||
return ui_interact(user)
|
||||
|
||||
/obj/machinery/power/smes/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
|
||||
if(!user)
|
||||
return
|
||||
|
||||
user.set_machine(src)
|
||||
var/list/data = list(
|
||||
"capacityPercent" = round(100.0*charge/capacity, 0.1),
|
||||
"capacity" = capacity,
|
||||
"charge" = charge,
|
||||
|
||||
var/t = "<TT><B>SMES Power Storage Unit</B> [n_tag? "([n_tag])" : null]<HR><PRE>"
|
||||
"inputAttempt" = input_attempt,
|
||||
"inputting" = inputting,
|
||||
"inputLevel" = input_level,
|
||||
"inputAvailable" = input_available,
|
||||
|
||||
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
|
||||
"outputting" = outputting,
|
||||
"outputLevel" = output_level,
|
||||
"outputUsed" = output_used
|
||||
)
|
||||
|
||||
// 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 - [name]", 540, 360)
|
||||
// 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)
|
||||
if(..())
|
||||
@@ -216,82 +210,51 @@
|
||||
|
||||
//world << "[href] ; [href_list[href]]"
|
||||
|
||||
if( href_list["close"] )
|
||||
usr << browse(null, "window=smes")
|
||||
usr.unset_machine()
|
||||
return
|
||||
|
||||
else if( href_list["cmode"] )
|
||||
chargemode = !chargemode
|
||||
if(!chargemode)
|
||||
charging = 0
|
||||
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")
|
||||
else if( href_list["input_attempt"] )
|
||||
input_attempt = text2num(href_list["input_attempt"])
|
||||
if(!input_attempt)
|
||||
inputting = 0
|
||||
investigate_log("input/output; [input_level>output_level?"<font color='green'>":"<font color='red'>"][input_level]/[output_level]</font> | Output-mode: [outputting?"<font color='green'>on</font>":"<font color='red'>off</font>"] | Input-mode: [input_attempt?"<font color='green'>auto</font>":"<font color='red'>off</font>"] by [usr.key]","singulo")
|
||||
updateicon()
|
||||
|
||||
else if( href_list["online"] )
|
||||
online = !online
|
||||
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")
|
||||
else if( href_list["outputting"] )
|
||||
outputting = text2num(href_list["outputting"])
|
||||
investigate_log("input/output; [input_level>output_level?"<font color='green'>":"<font color='red'>"][input_level]/[output_level]</font> | Output-mode: [outputting?"<font color='green'>on</font>":"<font color='red'>off</font>"] | Input-mode: [input_attempt?"<font color='green'>auto</font>":"<font color='red'>off</font>"] by [usr.key]","singulo")
|
||||
updateicon()
|
||||
|
||||
else if( href_list["input"] )
|
||||
else if( href_list["set_input_level"] )
|
||||
switch(href_list["set_input_level"])
|
||||
if("max")
|
||||
input_level = SMES_MAX_INPUT_LEVEL
|
||||
if("custom")
|
||||
var/custom = input(usr, "What rate would you like this SMES to attempt to charge at? Max is [SMES_MAX_INPUT_LEVEL].") as null|num
|
||||
if(isnum(custom))
|
||||
input_level = custom
|
||||
else
|
||||
var/n = text2num(href_list["set_input_level"])
|
||||
if(isnum(n))
|
||||
input_level = n
|
||||
|
||||
var/i = text2num(href_list["input"])
|
||||
input_level = Clamp(input_level, 0, SMES_MAX_INPUT_LEVEL)
|
||||
investigate_log("input/output; [input_level>output_level?"<font color='green'>":"<font color='red'>"][input_level]/[output_level]</font> | Output-mode: [outputting?"<font color='green'>on</font>":"<font color='red'>off</font>"] | Input-mode: [input_attempt?"<font color='green'>auto</font>":"<font color='red'>off</font>"] by [usr.key]","singulo")
|
||||
|
||||
var/d = 0
|
||||
switch(i)
|
||||
if(-4)
|
||||
chargelevel = 0
|
||||
if(4)
|
||||
chargelevel = SMESMAXCHARGELEVEL //30000
|
||||
else if(href_list["set_output_level"])
|
||||
switch(href_list["set_output_level"])
|
||||
if("max")
|
||||
output_level = SMES_MAX_OUTPUT_LEVEL
|
||||
if("custom")
|
||||
var/custom = input(usr, "What rate would you like this SMES to attempt to output at? Max is [SMES_MAX_OUTPUT_LEVEL].") as null|num
|
||||
if(isnum(custom))
|
||||
output_level = custom
|
||||
else
|
||||
var/n = text2num(href_list["set_output_level"])
|
||||
if(isnum(n))
|
||||
output_level = n
|
||||
|
||||
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
|
||||
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 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()
|
||||
output_level = Clamp(output_level, 0, SMES_MAX_OUTPUT_LEVEL)
|
||||
investigate_log("input/output; [input_level>output_level?"<font color='green'>":"<font color='red'>"][input_level]/[output_level]</font> | Output-mode: [outputting?"<font color='green'>on</font>":"<font color='red'>off</font>"] | Input-mode: [input_attempt?"<font color='green'>auto</font>":"<font color='red'>off</font>"] by [usr.key]","singulo")
|
||||
|
||||
add_fingerprint(usr)
|
||||
|
||||
/obj/machinery/power/smes/proc/ion_act()
|
||||
if(src.z == 1)
|
||||
@@ -325,16 +288,16 @@
|
||||
|
||||
|
||||
/obj/machinery/power/smes/emp_act(severity)
|
||||
online = 0
|
||||
charging = 0
|
||||
output = 0
|
||||
outputting = 0
|
||||
inputting = 0
|
||||
output_level = 0
|
||||
charge -= 1e6/severity
|
||||
if (charge < 0)
|
||||
charge = 0
|
||||
spawn(100)
|
||||
output = initial(output)
|
||||
charging = initial(charging)
|
||||
online = initial(online)
|
||||
output_level = initial(output_level)
|
||||
inputting = initial(inputting)
|
||||
outputting = initial(outputting)
|
||||
..()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user