Merge pull request #49604 from Arkatos1/ParticleUI

tgui: Particle Accelerator
This commit is contained in:
skoglol
2020-02-29 21:51:24 +01:00
committed by GitHub
4 changed files with 129 additions and 76 deletions
@@ -9,15 +9,17 @@
idle_power_usage = 500
active_power_usage = 10000
dir = NORTH
mouse_opacity = MOUSE_OPACITY_OPAQUE
ui_x = 350
ui_y = 185
var/strength_upper_limit = 2
var/interface_control = 1
var/interface_control = TRUE
var/list/obj/structure/particle_accelerator/connected_parts
var/assembled = FALSE
var/construction_state = PA_CONSTRUCTION_UNSECURED
var/active = FALSE
var/strength = 0
var/powered = FALSE
mouse_opacity = MOUSE_OPACITY_OPAQUE
/obj/machinery/particle_accelerator/control_box/Initialize()
. = ..()
@@ -75,36 +77,6 @@
else
icon_state = "control_boxc"
/obj/machinery/particle_accelerator/control_box/Topic(href, href_list)
if(..())
return
if(!interface_control)
to_chat(usr, "<span class='alert'>ERROR: Request timed out. Check wire contacts.</span>")
return
if(href_list["close"])
usr << browse(null, "window=pacontrol")
usr.unset_machine()
return
if(href_list["togglep"])
if(!wires.is_cut(WIRE_POWER))
toggle_power()
else if(href_list["scan"])
part_scan()
else if(href_list["strengthup"])
if(!wires.is_cut(WIRE_STRENGTH))
add_strength()
else if(href_list["strengthdown"])
if(!wires.is_cut(WIRE_STRENGTH))
remove_strength()
updateDialog()
update_icon()
/obj/machinery/particle_accelerator/control_box/proc/strength_change()
for(var/CP in connected_parts)
var/obj/structure/particle_accelerator/part = CP
@@ -120,7 +92,6 @@
log_game("PA Control Computer increased to [strength] by [key_name(usr)] in [AREACOORD(src)]")
investigate_log("increased to <font color='red'>[strength]</font> by [key_name(usr)] at [AREACOORD(src)]", INVESTIGATE_SINGULO)
/obj/machinery/particle_accelerator/control_box/proc/remove_strength(s)
if(assembled && (strength > 0))
strength--
@@ -130,7 +101,6 @@
log_game("PA Control Computer decreased to [strength] by [key_name(usr)] in [AREACOORD(src)]")
investigate_log("decreased to <font color='green'>[strength]</font> by [key_name(usr)] at [AREACOORD(src)]", INVESTIGATE_SINGULO)
/obj/machinery/particle_accelerator/control_box/power_change()
. = ..()
if(machine_stat & NOPOWER)
@@ -200,7 +170,6 @@
return TRUE
return FALSE
/obj/machinery/particle_accelerator/control_box/proc/toggle_power()
active = !active
investigate_log("turned [active?"<font color='green'>ON</font>":"<font color='red'>OFF</font>"] by [usr ? key_name(usr) : "outside forces"] at [AREACOORD(src)]", INVESTIGATE_SINGULO)
@@ -222,44 +191,6 @@
part.update_icon()
return TRUE
/obj/machinery/particle_accelerator/control_box/ui_interact(mob/user)
. = ..()
if(construction_state == PA_CONSTRUCTION_PANEL_OPEN)
wires.interact(user)
return
if(construction_state != PA_CONSTRUCTION_COMPLETE)
return
if((get_dist(src, user) > 1) || (machine_stat & (BROKEN|NOPOWER)))
if(!issilicon(user))
user.unset_machine()
user << browse(null, "window=pacontrol")
return
var/dat = ""
dat += "<A href='?src=[REF(src)];close=1'>Close</A><BR><BR>"
dat += "<h3>Status</h3>"
if(!assembled)
dat += "Unable to detect all parts!<BR>"
dat += "<A href='?src=[REF(src)];scan=1'>Run Scan</A><BR><BR>"
else
dat += "All parts in place.<BR><BR>"
dat += "Power:"
if(active)
dat += "On<BR>"
else
dat += "Off <BR>"
dat += "<A href='?src=[REF(src)];togglep=1'>Toggle Power</A><BR><BR>"
dat += "Particle Strength: [strength] "
dat += "<A href='?src=[REF(src)];strengthdown=1'>--</A>|<A href='?src=[REF(src)];strengthup=1'>++</A><BR><BR>"
var/datum/browser/popup = new(user, "pacontrol", name, 420, 300)
popup.set_content(dat)
popup.set_title_image(user.browse_rsc_icon(icon, icon_state))
popup.open()
/obj/machinery/particle_accelerator/control_box/examine(mob/user)
. = ..()
switch(construction_state)
@@ -270,7 +201,6 @@
if(PA_CONSTRUCTION_PANEL_OPEN)
. += "The panel is open."
/obj/machinery/particle_accelerator/control_box/attackby(obj/item/W, mob/user, params)
var/did_something = FALSE
@@ -328,6 +258,65 @@
if(prob(50))
qdel(src)
/obj/machinery/particle_accelerator/control_box/interact(mob/user)
if(construction_state == PA_CONSTRUCTION_PANEL_OPEN)
wires.interact(user)
else
..()
/obj/machinery/particle_accelerator/control_box/proc/is_interactive(mob/user)
if(!interface_control)
to_chat(user, "<span class='alert'>ERROR: Request timed out. Check wire contacts.</span>")
return FALSE
if(construction_state != PA_CONSTRUCTION_COMPLETE)
return FALSE
return TRUE
/obj/machinery/particle_accelerator/control_box/ui_status(mob/user)
if(is_interactive(user))
return ..()
return UI_CLOSE
/obj/machinery/particle_accelerator/control_box/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, \
datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "particle_accelerator", name, ui_x, ui_y, master_ui, state)
ui.open()
/obj/machinery/particle_accelerator/control_box/ui_data(mob/user)
var/list/data = list()
data["assembled"] = assembled
data["power"] = active
data["strength"] = strength
return data
/obj/machinery/particle_accelerator/control_box/ui_act(action, params)
if(..())
return
switch(action)
if("power")
if(wires.is_cut(WIRE_POWER))
return
toggle_power()
. = TRUE
if("scan")
part_scan()
. = TRUE
if("add_strength")
if(wires.is_cut(WIRE_STRENGTH))
return
add_strength()
. = TRUE
if("remove_strength")
if(wires.is_cut(WIRE_STRENGTH))
return
remove_strength()
. = TRUE
update_icon()
#undef PA_CONSTRUCTION_UNSECURED
#undef PA_CONSTRUCTION_UNWIRED
#undef PA_CONSTRUCTION_PANEL_OPEN