Skip to content

Commit

Permalink
convert assembly-related UIs to TGUI (#8342)
Browse files Browse the repository at this point in the history
* replace ugly type-checking procs with macro

* replace NanoUI state check with TGUI

* add basic TGUI support to assembly

* convert timer UI to TGUI

* convert signaler UI to TGUI

* convert proximity sensor UI to TGUI

* convert transfer valve UI to TGUI

* update TGUI bundle

* fix signaler component export
  • Loading branch information
intercepti0n authored Oct 20, 2023
1 parent 0ba0462 commit d624f0e
Show file tree
Hide file tree
Showing 26 changed files with 612 additions and 523 deletions.
3 changes: 1 addition & 2 deletions cev_eris.dme
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,6 @@
#include "code\modules\alarm\power_alarm.dm"
#include "code\modules\assembly\assembly.dm"
#include "code\modules\assembly\bomb.dm"
#include "code\modules\assembly\helpers.dm"
#include "code\modules\assembly\holder.dm"
#include "code\modules\assembly\igniter.dm"
#include "code\modules\assembly\infrared.dm"
Expand Down Expand Up @@ -2271,7 +2270,6 @@
#include "code\modules\nano\interaction\contained.dm"
#include "code\modules\nano\interaction\default.dm"
#include "code\modules\nano\interaction\exosuits.dm"
#include "code\modules\nano\interaction\hands.dm"
#include "code\modules\nano\interaction\interactive.dm"
#include "code\modules\nano\interaction\inventory.dm"
#include "code\modules\nano\interaction\inventory_deep.dm"
Expand Down Expand Up @@ -2749,6 +2747,7 @@
#include "code\modules\tgui\tgui.dm"
#include "code\modules\tgui\tgui_window.dm"
#include "code\modules\tgui\states\always.dm"
#include "code\modules\tgui\states\hands.dm"
#include "code\modules\tgui\states\machinery.dm"
#include "code\modules\tgui\states\notcontained.dm"
#include "code\modules\tips_and_tricks\gameplay.dm"
Expand Down
13 changes: 13 additions & 0 deletions code/__DEFINES/is_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,16 @@
#define ismachinery(A) (istype(A, /obj/machinery))

#define isProjectile(A) (istype(A, /obj/item/projectile))

// Assembly specific checks
#define isassembly(A) (istype(A, /obj/item/device/assembly))

#define isigniter(A) (istype(A, /obj/item/device/assembly/igniter))

#define isinfrared(A) (istype(A, /obj/item/device/assembly/infra))

#define isproxsensor(A) (istype(A, /obj/item/device/assembly/prox_sensor))

#define issignaler(A) (istype(A, /obj/item/device/assembly/signaler))

#define istimer(A) (istype(A, /obj/item/device/assembly/timer))
2 changes: 1 addition & 1 deletion code/game/machinery/portable_turret.dm
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ var/list/turret_icons
//attack_hand() removes the gun

if(4)
if(is_proximity_sensor(I))
if(isproxsensor(I))
build_step = 5
if(!user.unEquip(I))
to_chat(user, SPAN_NOTICE("\the [I] is stuck to your hand, you cannot put it in \the [src]"))
Expand Down
96 changes: 49 additions & 47 deletions code/game/objects/items/devices/transfer_valve.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
log_game("[key_name_admin(user)] attached both tanks to a transfer valve.")

update_icon()
SSnano.update_uis(src) // update all UIs attached to src
//TODO: Have this take an assemblyholder
else if(is_assembly(item))
else if(isassembly(item))
var/obj/item/device/assembly/A = item
if(A.secured)
to_chat(user, SPAN_NOTICE("The device is secured."))
Expand All @@ -56,7 +55,6 @@
message_admins("[key_name_admin(user)] attached a [item] to a transfer valve. (<A HREF='?_src_=holder;adminplayerobservecoodjump=1;X=[location.x];Y=[location.y];Z=[location.z]'>JMP</a>)")
log_game("[key_name_admin(user)] attached a [item] to a transfer valve.")
attacher = user
SSnano.update_uis(src) // update all UIs attached to src
return


Expand All @@ -66,53 +64,48 @@
return


/obj/item/device/transfer_valve/attack_self(mob/user as mob)
nano_ui_interact(user)
/obj/item/device/transfer_valve/attack_self(mob/user)
ui_interact(user)

/obj/item/device/transfer_valve/nano_ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = NANOUI_FOCUS)
/obj/item/device/transfer_valve/ui_state(mob/user)
return GLOB.hands_state

// this is the data which will be sent to the ui
var/data[0]
data["attachmentOne"] = tank_one ? tank_one.name : null
data["attachmentTwo"] = tank_two ? tank_two.name : null
data["valveAttachment"] = attached_device ? attached_device.name : null
data["valveOpen"] = valve_open ? 1 : 0

// update the ui if it exists, returns null if no ui is passed/found
ui = SSnano.try_update_ui(user, src, ui_key, ui, data, force_open)
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, "transfer_valve.tmpl", "Tank Transfer Valve", 460, 280)
// when the ui is first opened this is the data it will use
ui.set_initial_data(data)
// open the new ui window
/obj/item/device/transfer_valve/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "TransferValve", name)
ui.open()
// auto update every Master Controller tick
//ui.set_auto_update(1)

/obj/item/device/transfer_valve/Topic(href, href_list)
..()
if ( usr.stat || usr.restrained() )
return 0
if (src.loc != usr)
return 0
if(tank_one && href_list["tankone"])
remove_tank(tank_one)
else if(tank_two && href_list["tanktwo"])
remove_tank(tank_two)
else if(href_list["open"])
toggle_valve()
else if(attached_device)
if(href_list["rem_device"])
attached_device.loc = get_turf(src)
attached_device:holder = null
attached_device = null
update_icon()
if(href_list["device"])
attached_device.attack_self(usr)
src.add_fingerprint(usr)
return 1 // Returning 1 sends an update to attached UIs

/obj/item/device/transfer_valve/ui_data(mob/user)
var/list/data = list(
"attachmentOne" = tank_one ? tank_one.name : null,
"attachmentTwo" = tank_two ? tank_two.name : null,
"attachment" = attached_device ? attached_device.name : null,
"isOpen" = valve_open
)
return data

/obj/item/device/transfer_valve/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return

switch(action)
if("toggle")
toggle_valve()
. = TRUE
if("device")
attached_device?.attack_self(usr)
. = TRUE
if("remove_device")
remove_device()
. = TRUE
if("tankone")
remove_tank(tank_one)
. = TRUE
if("tanktwo")
remove_tank(tank_two)
. = TRUE

/obj/item/device/transfer_valve/process_activation(var/obj/item/device/D)
if(toggle)
Expand All @@ -139,6 +132,15 @@
if(attached_device)
overlays += "device"

/obj/item/device/transfer_valve/proc/remove_device()
if(isnull(attached_device))
return

attached_device.forceMove(get_turf(src))
attached_device:holder = null // Very-very bad, somebody fix.
attached_device = null
update_icon()

/obj/item/device/transfer_valve/proc/remove_tank(obj/item/tank/T)
if(tank_one == T)
split_gases()
Expand Down
14 changes: 7 additions & 7 deletions code/game/objects/items/weapons/grenades/chem_grenade.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
return
if(istype(W,/obj/item/device/assembly_holder) && stage != READY && path != 2)
var/obj/item/device/assembly_holder/det = W
if(istype(det.left_assembly,det.right_assembly.type) || (!is_igniter(det.left_assembly) && !is_igniter(det.right_assembly)))
if(istype(det.left_assembly,det.right_assembly.type) || (!isigniter(det.left_assembly) && !isigniter(det.right_assembly)))
to_chat(user, SPAN_WARNING("Assembly must contain one igniter."))
return
if(!det.secured)
Expand All @@ -70,10 +70,10 @@
user.remove_from_mob(det)
det.loc = src
detonator = det
if(is_timer(detonator.left_assembly))
if(istimer(detonator.left_assembly))
var/obj/item/device/assembly/timer/T = detonator.left_assembly
det_time = 10*T.time
if(is_timer(detonator.right_assembly))
if(istimer(detonator.right_assembly))
var/obj/item/device/assembly/timer/T = detonator.right_assembly
det_time = 10*T.time
icon_state = initial(icon_state) +"_ass"
Expand Down Expand Up @@ -128,11 +128,11 @@
if(active) return

if(detonator)
if(!is_igniter(detonator.left_assembly))
if(!isigniter(detonator.left_assembly))
detonator.left_assembly.activate()
active = TRUE
log_and_message_admins("primed via detonator \a [src]")
if(!is_igniter(detonator.right_assembly))
if(!isigniter(detonator.right_assembly))
detonator.right_assembly.activate()
active = TRUE
log_and_message_admins("primed via detonator \a [src]")
Expand Down Expand Up @@ -160,10 +160,10 @@
icon_state = initial(icon_state) +"_locked"
playsound(loc, 'sound/items/Screwdriver2.ogg', 50, 1)
spawn(0) //Otherwise det_time is erroneously set to 0 after this
if(is_timer(detonator.left_assembly)) //Make sure description reflects that the timer has been reset
if(istimer(detonator.left_assembly)) //Make sure description reflects that the timer has been reset
var/obj/item/device/assembly/timer/T = detonator.left_assembly
det_time = 10*T.time
if(is_timer(detonator.right_assembly))
if(istimer(detonator.right_assembly))
var/obj/item/device/assembly/timer/T = detonator.right_assembly
det_time = 10*T.time
return
Expand Down
32 changes: 21 additions & 11 deletions code/modules/assembly/assembly.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@


/obj/item/device/assembly/attackby(obj/item/I, mob/user)
if(is_assembly(I))
if(isassembly(I))
var/obj/item/device/assembly/A = I
if((!A.secured) && (!secured))
attach_assembly(A, user)
Expand Down Expand Up @@ -103,24 +103,34 @@

/obj/item/device/assembly/attack_self(mob/user)
if(!user)
return 0
user.set_machine(src)
interact(user)
return 1
return FALSE

interact(user)
return TRUE

/obj/item/device/assembly/interact(mob/user)
return //HTML MENU FOR WIRES GOES HERE
return ui_interact(user)

/obj/item/device/assembly/proc/holder_movement()
return

/obj/item/device/assembly/nano_host()
if(istype(loc, /obj/item/device/assembly_holder))
return loc.nano_host()
return ..()

/obj/item/device/assembly/proc/is_attachable()
if(secured)
return FALSE
return TRUE

/obj/item/device/assembly/proc/is_secured(mob/user)
if(!secured)
to_chat(user, SPAN_WARNING("The [name] is unsecured!"))
return FALSE

return TRUE

/obj/item/device/assembly/ui_host(mob/user)
if(holder)
return holder

return ..()

/obj/item/device/assembly/ui_state(mob/user)
return GLOB.hands_state
2 changes: 1 addition & 1 deletion code/modules/assembly/bomb.dm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
var/mob/M = user
if(!S.secured) //Check if the assembly is secured
return
if(is_igniter(S.left_assembly) == is_igniter(S.right_assembly)) //Check if either part of the assembly has an igniter, but if both parts are igniters, then fuck it
if(isigniter(S.left_assembly) == isigniter(S.right_assembly)) //Check if either part of the assembly has an igniter, but if both parts are igniters, then fuck it
return

var/obj/item/device/onetankbomb/R = new /obj/item/device/onetankbomb(loc)
Expand Down
29 changes: 0 additions & 29 deletions code/modules/assembly/helpers.dm

This file was deleted.

Loading

0 comments on commit d624f0e

Please sign in to comment.