Added UI for new canister label system

This commit is contained in:
Artorp
2015-02-11 23:19:46 +01:00
parent a883af922b
commit 7e4e3acedc
2 changed files with 354 additions and 210 deletions
+218 -149
View File
@@ -5,55 +5,24 @@
density = 1
var/health = 100.0
flags = FPRINT | CONDUCT
var/menu = 0
//used by nanoui: 0 = main menu, 1 = relabel
var/valve_open = 0
var/release_pressure = ONE_ATMOSPHERE
var/list/_color = list("yellow", null, null, null)//variable that stores colours
var/list/decals = list() // var that stores the decals, NOTE: Not the actual POSSIBLE decals, but the ones currently used
var/list/oldcolor = list()//lists for check_change()
var/list/olddecals = list()
var/list/possibledecals = list( //var that stores all possible decals, here for adminbus I guess? NOTE: LEAVE "done" IN HERE
"Low temperature canister" = "cold",
"High temperature canister" = "hot",
"Plasma containing canister" = "plasma",
"Done" = "DONE"
)
var/list/possiblemaincolor = list( //these lists contain the possible colors of a canister, here for adminbus
"\[N2O\]" = "redws",
"\[N2\]" = "red",
"\[O2\]" = "blue",
"\[Toxin (Bio)\]" = "orange",
"\[CO2\]" = "black",
"\[Air\]" = "grey",
"\[CAUTION\]" = "yellow",
"\[SPECIAL\]" = "whiters"
)
var/list/possibleseccolor = list( // no point in having the N2O and "whiters" ones in these lists
"\[N2\]" = "red-c",
"\[O2\]" = "blue-c",
"\[Toxin (Bio)\]" = "orange-c",
"\[CO2\]" = "black-c",
"\[Air\]" = "grey-c",
"\[CAUTION\]" = "yellow-c"
)
var/list/possibletertcolor = list(
"\[N2\]" = "red-c-1",
"\[O2\]" = "blue-c-1",
"\[Toxin (Bio)\]" = "orange-c-1",
"\[CO2\]" = "black-c-1",
"\[Air\]" = "grey-c-1",
"\[CAUTION\]" = "yellow-c-1"
)
var/list/possiblequartcolor = list(
"\[N2\]" = "red-c-2",
"\[O2\]" = "blue-c-2",
"\[Toxin (Bio)\]" = "orange-c-2",
"\[CO2\]" = "black-c-2",
"\[Air\]" = "grey-c-2",
"\[CAUTION\]" = "yellow-c-2"
)
var/list/_color //variable that stores colours
var/list/decals // list that stores the decals
var/list/possibledecals
var/list/oldcolor//lists for check_change()
var/list/olddecals
var/list/possiblemaincolor //these lists contain the possible colors of a canister
var/list/possibleseccolor
var/list/possibletertcolor
var/list/possiblequartcolor
var/list/colorcontainer //passed to the ui to render the color lists
var/can_label = 1
var/filled = 0.5
pressure_resistance = 7*ONE_ATMOSPHERE
@@ -63,43 +32,81 @@
var/release_log = ""
var/busy = 0
var/update_flag = 0
/obj/machinery/portable_atmospherics/canister/sleeping_agent
name = "Canister: \[N2O\]"
icon_state = "redws"
_color = list("redws", null, null, null)
can_label = 0
/obj/machinery/portable_atmospherics/canister/nitrogen
name = "Canister: \[N2\]"
icon_state = "red"
_color = list("red", null, null, null)
decals = list("plasma")
can_label = 0
/obj/machinery/portable_atmospherics/canister/oxygen
name = "Canister: \[O2\]"
icon_state = "blue"
_color = list("blue", null, null, null)
can_label = 0
/obj/machinery/portable_atmospherics/canister/toxins
name = "Canister \[Toxin (Plasma)\]"
icon_state = "orange"
_color = list("orange", null, null, null)
can_label = 0
/obj/machinery/portable_atmospherics/canister/carbon_dioxide
name = "Canister \[CO2\]"
icon_state = "black"
_color = list("black", null, null, null)
can_label = 0
/obj/machinery/portable_atmospherics/canister/air
name = "Canister \[Air\]"
icon_state = "grey"
_color = list("grey", null, null, null)
can_label = 0
/obj/machinery/portable_atmospherics/canister/custom_mix
name = "Canister \[Custom\]"
icon_state = "whiters"
_color = list("whiters", null, null, null)
can_label = 0
New()
..()
_color = list(
"prim" = "yellow",
"sec" = null,
"ter" = null,
"quart" = null)
oldcolor = list()
decals = list()
olddecals = list()
possibledecals = list( //var that stores all possible decals, used by ui
list("name" = "Low temperature canister", "icon" = "cold", "active" = 0),
list("name" = "High temperature canister", "icon" = "hot", "active" = 0),
list("name" = "Plasma containing canister", "icon" = "plasma", "active" = 0)
)
possiblemaincolor = list( //these lists contain the possible colors of a canister
list("name" = "\[N2O\]", "icon" = "redws"),
list("name" = "\[N2\]", "icon" = "red"),
list("name" = "\[O2\]", "icon" = "blue"),
list("name" = "\[Toxin (Bio)\]", "icon" = "orange"),
list("name" = "\[CO2\]", "icon" = "black"),
list("name" = "\[Air\]", "icon" = "grey"),
list("name" = "\[CAUTION\]", "icon" = "yellow"),
list("name" = "\[SPECIAL\]", "icon" = "whiters")
)
possibleseccolor = list( // no point in having the N2O and "whiters" ones in these lists
list("name" = "\[N2\]", "icon" = "red-c"),
list("name" = "\[O2\]", "icon" = "blue-c"),
list("name" = "\[Toxin (Bio)\]", "icon" = "orange-c"),
list("name" = "\[CO2\]", "icon" = "black-c"),
list("name" = "\[Air\]", "icon" = "grey-c"),
list("name" = "\[CAUTION\]", "icon" = "yellow-c")
)
possibletertcolor = list(
list("name" = "\[N2\]", "icon" = "red-c-1"),
list("name" = "\[O2\]", "icon" = "blue-c-1"),
list("name" = "\[Toxin (Bio)\]", "icon" = "orange-c-1"),
list("name" = "\[CO2\]", "icon" = "black-c-1"),
list("name" = "\[Air\]", "icon" = "grey-c-1"),
list("name" = "\[CAUTION\]", "icon" = "yellow-c-1")
)
possiblequartcolor = list(
list("name" = "\[N2\]", "icon" = "red-c-2"),
list("name" = "\[O2\]", "icon" = "blue-c-2"),
list("name" = "\[Toxin (Bio)\]", "icon" = "orange-c-2"),
list("name" = "\[CO2\]", "icon" = "black-c-2"),
list("name" = "\[Air\]", "icon" = "grey-c-2"),
list("name" = "\[CAUTION\]", "icon" = "yellow-c-2")
)
colorcontainer = list(//passed to the ui to render the color lists
"prim" = list(
"options" = possiblemaincolor,
"name" = "Primary color",
"anycolor" = -1,//0: no color applied. 1: color selected. Not used for primary color.
),
"sec" = list(
"options" = possibleseccolor,
"name" = "Secondary color",
"anycolor" = 0,
),
"ter" = list(
"options" = possibletertcolor,
"name" = "Tertiary color",
"anycolor" = 0,
),
"quart" = list(
"options" = possiblequartcolor,
"name" = "Quaternary color",
"anycolor" = 0,
)
)
update_icon()
spawn(1)
update_icon()
/obj/machinery/portable_atmospherics/canister/proc/check_change()
var/old_flag = update_flag
@@ -119,17 +126,15 @@
else
update_flag |= 32
if(list2params(oldcolor) == list2params(_color))
if(list2params(oldcolor) != list2params(_color))
update_flag |= 64
else
oldcolor = _color
if(list2params(olddecals) == list2params(decals))
oldcolor = _color.Copy()
if(list2params(olddecals) != list2params(decals))
update_flag |= 128
else
olddecals = decals
if(update_flag == old_flag)
olddecals = decals.Copy()
if(update_flag == old_flag || (update_flag & 64) || (update_flag & 128))
return 1
else
return 0
@@ -149,25 +154,25 @@ update_flag
if (src.destroyed)
src.overlays = 0
src.icon_state = text("[]-1", src._color[1])//yes, I KNOW the colours don't reflect when the can's borked, whatever.
src.icon_state = text("[]-1", src._color["prim"])//yes, I KNOW the colours don't reflect when the can's borked, whatever.
if(icon_state != src._color[1])
icon_state = src._color[1]
if(icon_state != src._color["prim"])
icon_state = src._color["prim"]
if(check_change()) //Returns 1 if no change needed to icons.
return
src.overlays = 0
if (_color["sec"])//COLORS!
overlays.Add(_color["sec"])
if (_color[2])//COLORS!
overlays.Add(_color[2])
if (_color[3])
overlays.Add(_color[3])
if (_color[4])
overlays.Add(_color[4])
if (_color["ter"])
overlays.Add(_color["ter"])
if (_color["quart"])
overlays.Add(_color["quart"])
for(var/D in decals)
overlays.Add("decal-" + D)
@@ -183,7 +188,6 @@ update_flag
overlays += "can-o2"
else if(update_flag & 32)
overlays += "can-o3"
check_change()//call this here to update the bitflag, incase the canister gets relabeled instantly after again
return
/obj/machinery/portable_atmospherics/canister/fire_act(datum/gas_mixture/air, exposed_temperature, exposed_volume)
@@ -337,7 +341,11 @@ update_flag
// this is the data which will be sent to the ui
var/data[0]
data["name"] = name
data["menu"] = menu ? 1 : 0
data["canLabel"] = can_label ? 1 : 0
data["_color"] = _color
data["colorContainer"] = colorcontainer
data["possibleDecals"] = possibledecals
data["portConnected"] = connected_port ? 1 : 0
data["tankPressure"] = round(air_contents.return_pressure() ? air_contents.return_pressure() : 0)
data["releasePressure"] = round(release_pressure ? release_pressure : 0)
@@ -372,6 +380,9 @@ update_flag
usr << browse(null, "window=canister")
onclose(usr, "canister")
return
if (href_list["choice"] == "menu")
menu = text2num(href_list["mode_target"])
if(href_list["toggle"])
if (valve_open)
@@ -400,54 +411,107 @@ update_flag
release_pressure = min(10*ONE_ATMOSPHERE, release_pressure+diff)
else
release_pressure = max(ONE_ATMOSPHERE/10, release_pressure+diff)
if (href_list["relabel"])
if (href_list["rename"])
if (can_label)
var/T = input("Choose canister label", "Name", name)
if (can_label) //Exploit prevention
if (T)
name = T
else
name = "Canister"
else
usr << "\red As you attempted to rename it the pressure rose!"
var/label1 = input("Choose canister label", "Primary color") as null|anything in possiblemaincolor
var/label2 = input("Choose canister label", "Secondary color") as null|anything in possibleseccolor
var/label3 = input("Choose canister label", "Tertiary color") as null|anything in possibletertcolor
var/label4 = input("Choose canister label", "Quaternary color") as null|anything in possiblequartcolor
decals = list()
_color = list(
(label1 ? possiblemaincolor[label1] : color[1]),//if the user didn't specify a primary colour, keep the current one.
possibleseccolor[label2],
possibletertcolor[label3],
possiblequartcolor[label4]
)
decals = list()
var/list/tempposdecals = list()
for(var/d in possibledecals)//populate the temp list
tempposdecals.Add(d)
tempposdecals[d] = possibledecals[d]
while (src && !src.gc_destroyed && usr)//allow the user to select (theoretically) INFINITE DECALS!!!
var/newdecal = input("Choose canister label", "Decal") as anything in tempposdecals
if (newdecal == "Done")
break
decals.Add(tempposdecals[newdecal])
tempposdecals.Remove(newdecal)
src.name = (input("Choose canister label", "Name") as text) + " canister"
if (href_list["choice"] == "Primary color")
_color["prim"] = href_list["icon"]
update_icon()
if (href_list["choice"] == "Secondary color")
if (href_list["icon"] == "none")
_color["sec"] = ""
colorcontainer["sec"]["anycolor"] = 0
else
_color["sec"] = href_list["icon"]
colorcontainer["sec"]["anycolor"] = 1
update_icon()
if (href_list["choice"] == "Tertiary color")
if (href_list["icon"] == "none")
_color["ter"] = ""
colorcontainer["ter"]["anycolor"] = 0
else
_color["ter"] = href_list["icon"]
colorcontainer["ter"]["anycolor"] = 1
update_icon()
if (href_list["choice"] == "Quaternary color")
if (href_list["icon"] == "none")
_color["quart"] = ""
colorcontainer["quart"]["anycolor"] = 0
else
_color["quart"] = href_list["icon"]
colorcontainer["quart"]["anycolor"] = 1
update_icon()
if (href_list["choice"] == "decals")
switch(href_list["icon"])
if ("cold")
possibledecals[1]["active"] = (possibledecals[1]["active"] == 0)
if ("hot")
possibledecals[2]["active"] = (possibledecals[2]["active"] == 0)
if ("plasma")
possibledecals[3]["active"] = (possibledecals[3]["active"] == 0)
decals = list()
if (possibledecals[1]["active"])
if (!("cold" in decals))
decals.Add("cold")
if (possibledecals[2]["active"])
if (!("hot" in decals))
decals.Add("hot")
if (possibledecals[3]["active"])
if (!("plasma" in decals))
decals.Add("plasma")
update_icon()
src.add_fingerprint(usr)
update_icon()
return 1
/obj/machinery/portable_atmospherics/canister/toxins
name = "Canister \[Toxin (Plasma)\]"
icon_state = "orange" //See New()
can_label = 0
/obj/machinery/portable_atmospherics/canister/oxygen
name = "Canister: \[O2\]"
icon_state = "blue" //See New()
can_label = 0
/obj/machinery/portable_atmospherics/canister/sleeping_agent
name = "Canister: \[N2O\]"
icon_state = "redws" //See New()
can_label = 0
/obj/machinery/portable_atmospherics/canister/nitrogen
name = "Canister: \[N2\]"
icon_state = "red" //See New()
can_label = 0
/obj/machinery/portable_atmospherics/canister/carbon_dioxide
name = "Canister \[CO2\]"
icon_state = "black" //See New()
can_label = 0
/obj/machinery/portable_atmospherics/canister/air
name = "Canister \[Air\]"
icon_state = "grey" //See New()
can_label = 0
/obj/machinery/portable_atmospherics/canister/custom_mix
name = "Canister \[Custom\]"
icon_state = "whiters" //See New()
can_label = 0
/obj/machinery/portable_atmospherics/canister/toxins/New()
..()
_color["prim"] = "orange"
src.air_contents.toxins = (src.maximum_pressure*filled)*air_contents.volume/(R_IDEAL_GAS_EQUATION*air_contents.temperature)
air_contents.update_values()
@@ -455,18 +519,18 @@ update_flag
return 1
/obj/machinery/portable_atmospherics/canister/oxygen/New()
..()
_color["prim"] = "blue"
src.air_contents.oxygen = (src.maximum_pressure*filled)*air_contents.volume/(R_IDEAL_GAS_EQUATION*air_contents.temperature)
air_contents.update_values()
src.update_icon()
return 1
/obj/machinery/portable_atmospherics/canister/sleeping_agent/New()
..()
_color["prim"] = "redws"
var/datum/gas/sleeping_agent/trace_gas = new
air_contents.trace_gases += trace_gas
trace_gas.moles = (src.maximum_pressure*filled)*air_contents.volume/(R_IDEAL_GAS_EQUATION*air_contents.temperature)
@@ -492,9 +556,11 @@ update_flag
/obj/machinery/portable_atmospherics/canister/nitrogen/New()
..()
_color["prim"] = "red"
decals = list("plasma")
possibledecals[3]["active"] = 1
src.air_contents.nitrogen = (src.maximum_pressure*filled)*air_contents.volume/(R_IDEAL_GAS_EQUATION*air_contents.temperature)
air_contents.update_values()
@@ -502,8 +568,9 @@ update_flag
return 1
/obj/machinery/portable_atmospherics/canister/carbon_dioxide/New()
..()
_color["prim"] = "black"
src.air_contents.carbon_dioxide = (src.maximum_pressure*filled)*air_contents.volume/(R_IDEAL_GAS_EQUATION*air_contents.temperature)
air_contents.update_values()
@@ -512,8 +579,9 @@ update_flag
/obj/machinery/portable_atmospherics/canister/air/New()
..()
_color["prim"] = "grey"
src.air_contents.oxygen = (O2STANDARD*src.maximum_pressure*filled)*air_contents.volume/(R_IDEAL_GAS_EQUATION*air_contents.temperature)
src.air_contents.nitrogen = (N2STANDARD*src.maximum_pressure*filled)*air_contents.volume/(R_IDEAL_GAS_EQUATION*air_contents.temperature)
air_contents.update_values()
@@ -524,6 +592,7 @@ update_flag
/obj/machinery/portable_atmospherics/canister/custom_mix/New()
..()
_color["prim"] = "whiters"
src.update_icon() // Otherwise new canisters do not have their icon updated with the pressure light, likely want to add this to the canister class constructor, avoiding at current time to refrain from screwing up code for other canisters. --DZD
return 1