Updates the Mech Bay Power Control Console to have a TGUI interface.

This commit is contained in:
Remie Richards
2016-05-16 02:24:41 +01:00
parent 60237bbb31
commit 2b646e2c0f
4 changed files with 83 additions and 45 deletions
+26 -32
View File
@@ -94,36 +94,35 @@
return
interact(user)
/obj/machinery/computer/mech_bay_power_console/interact(mob/user)
var/data
if(!recharge_port)
data += "<div class='statusDisplay'>No recharging port detected.</div><BR>"
data += "<A href='?src=\ref[src];reconnect=1'>Reconnect</A>"
else
data += "<h3>Mech status</h3>"
if(!recharge_port.recharging_mech)
data += "<div class='statusDisplay'>No mech detected.</div>"
else
data += "<div class='statusDisplay'>Integrity: [recharge_port.recharging_mech.health]<BR>"
/obj/machinery/computer/mech_bay_power_console/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = 0, datum/tgui/master_ui = null, datum/ui_state/state = default_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "mech_bay_power_console", "Mech Bay Power Control Console", 400, 170, master_ui, state)
ui.open()
if(!recharge_port.recharging_mech.cell)
data += "<span class='bad'>WARNING : the mech cell is missing!</span></div>"
else if(recharge_port.recharging_mech.cell.crit_fail)
data += "<span class='bad'>WARNING : the mech cell seems faulty!</span></div>"
else
data += "Power: [recharge_port.recharging_mech.cell.charge]/[recharge_port.recharging_mech.cell.maxcharge]</div>"
var/datum/browser/popup = new(user, "mech recharger", name, 300, 300)
popup.set_content(data)
popup.open()
return
/obj/machinery/computer/mech_bay_power_console/Topic(href, href_list)
/obj/machinery/computer/mech_bay_power_console/ui_act(action, params)
if(..())
return
if(href_list["reconnect"])
reconnect()
updateUsrDialog()
switch(action)
if("reconnect")
reconnect()
. = TRUE
update_icon()
/obj/machinery/computer/mech_bay_power_console/ui_data(mob/user)
var/list/data = list()
if(recharge_port && !qdeleted(recharge_port))
data["recharge_port"] = list("mech" = null)
if(recharge_port.recharging_mech && !qdeleted(recharge_port.recharging_mech))
data["recharge_port"]["mech"] = list("health" = recharge_port.recharging_mech.health, "maxhealth" = initial(recharge_port.recharging_mech.health), "cell" = null)
if(recharge_port.recharging_mech.cell && !qdeleted(recharge_port.recharging_mech.cell))
data["recharge_port"]["mech"]["cell"] = list(
"critfail" = recharge_port.recharging_mech.cell.crit_fail,
"charge" = recharge_port.recharging_mech.cell.charge,
"maxcharge" = recharge_port.recharging_mech.cell.maxcharge
)
return data
/obj/machinery/computer/mech_bay_power_console/proc/reconnect()
if(recharge_port)
@@ -142,11 +141,6 @@
else
recharge_port = null
/obj/machinery/computer/mech_bay_power_console/process()
if(recharge_port && recharge_port.recharging_mech && recharge_port.recharging_mech.cell)
updateDialog()
/obj/machinery/computer/mech_bay_power_console/update_icon()
..()
if(!recharge_port || !recharge_port.recharging_mech || !recharge_port.recharging_mech.cell || !(recharge_port.recharging_mech.cell.charge < recharge_port.recharging_mech.cell.maxcharge) || stat & (NOPOWER|BROKEN))
+1 -1
View File
File diff suppressed because one or more lines are too long
+12 -12
View File
File diff suppressed because one or more lines are too long
@@ -0,0 +1,44 @@
<script>
component.exports = {
data: {
mechChargeState(charge) {
let maxcharge = this.get('data.recharge_port.mech.cell.maxcharge')
if(charge >= (maxcharge/1.5)) return 'good'
else if(charge >= (maxcharge/3)) return 'average'
else return 'bad'
},
mechHealthState(health) {
let maxhealth = this.get('data.recharge_port.mech.maxhealth')
if(health > (maxhealth/1.5)) return 'good'
else if(health > (maxhealth/3)) return 'average'
else return 'bad'
}
}
}
</script>
<ui-display title='Mech Status'>
{{#if data.recharge_port}}
{{#if data.recharge_port.mech}}
<ui-section label='Integrity'>
<ui-bar min='0' max='{{adata.recharge_port.mech.maxhealth}}' value='{{adata.recharge_port.mech.health}}'state='{{mechHealthState(adata.recharge_port.mech.health)}}'>{{Math.round(adata.recharge_port.mech.health)}}/{{adata.recharge_port.mech.maxhealth}}</ui-bar>
</ui-section>
{{#if data.recharge_port.mech.cell}}
{{#if data.recharge_port.mech.cell.critfail}}
<ui-section label='Power'><span class='bad'>Cell Critical Failure</span></ui-section>
{{else}}
<ui-section label='Power'>
<ui-bar min='0' max='{{adata.recharge_port.mech.cell.maxcharge}}' value='{{adata.recharge_port.mech.cell.charge}}'state='{{mechChargeState(adata.recharge_port.mech.cell.charge)}}'>{{Math.round(adata.recharge_port.mech.cell.charge)}}/{{Math.round(adata.recharge_port.mech.cell.maxcharge)}}</ui-bar>
</ui-section>
{{/if}}
{{else}}
<ui-section label='Power'><span class='bad'>Cell Missing</span></ui-section>
{{/if}}
{{else}}
<ui-section>Mech Not Found</ui-section>
{{/if}}
{{else}}
<ui-section>Recharging Port Not Found</ui-section>
<ui-button icon='refresh' action='reconnect'>Reconnect</ui-button>
{{/if}}
</ui-display>