Files
Bubberstation/code/modules/mod/mod_ui.dm
Stonetear 4756a44141 MODSuit procs now pass who clicked the UI button + misc code cleanup (#92424)
## About The Pull Request

Most of these changes are centered around removing `mod.wearer`
references in module function bubble alerts. However, I cleaned up a few
other things that I thought were easy fixes. ~~This PR should be
testmerged~~ nah send it. I think I did a pretty good job testing, but
there might be a bug or two I missed. (debug modsuit should allow
conflicting modules and have unlimited complexity btw)

### Track who clicks the activate button
* Adds `mob/activator` to `on_select()`, `activate()`, `deactivate()`,
`used()`, `on_activation()`, `on_deactivation()` and `on_use()`
* `mod_ui` now passes `ui.user`, which is who actually clicked the
button in the UI.1
* module action proc now passes the person clicking.
* **Alert bubbles:** Modifies many module code bubbles to pass the
activation bubble text to `mob/activator` instead of `mob.wearer` so
that pAIs get feedback on why clicking the button isn't working.

### Cargo clamp
* **Clamp code cleanup:** The cargo clamp now has a variable for the max
creature weight it can support, and the logic is changed around a bit to
support this.
* The cargo clamp uses an `accepted_items` typecache.

### Code cleanup
* **Button malfunction chance** is controlled by a
`MOD_MALFUNCTION_PROB` define.
* **Pathfinder runtime:** `mod_control`'s `GetAccess()` now checks if
there is an access before returning it. (This previously caused runtimes
when using the pathfinder module if you didn't swipe your ID)
* **Pathfinder code tweaks:** Reworks the code for the pathfinder module
a bit. Activation logic is now stored in the module instead of the
implant. The suit is prevented from being recalled by pAIs, which is
controlled by a variable.
* Adds `MODULE_ALLOW_UNWORN`, which lets you activate modules in suits
that aren't currently being worn. Module activation code now smoothly
supports modules being activated while not worn.
* Chameleon module now works when unworn.

This will probably be a Part 1, with a Part 2 to follow. Actions are
kinda funky and could probably be cleaned up a little better. Plus, I
want to make selectable modules theoretically usable by the AI, even if
I leave it disabled.

## Why It's Good For The Game

This PR doesn't contain any balance changes, and I manually disabled any
new serious functionality that pAIs might gain. (Such as being able to
activate the pathfinder implant) They *can* use the chameleon module
with no wearer- but I'm going to consider this a bug that they couldn't
before.

Paves the way for more pAI modsuit nonsense I'm doing downsteam.

## Changelog
🆑 Stonetear
refactor: MODsuit module code now knows who clicked the activation
button.
/🆑

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
2025-09-07 10:27:38 +00:00

135 lines
4.0 KiB
Plaintext

/obj/item/mod/control/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "MODsuit", name)
ui.open()
/obj/item/mod/control/ui_data(mob/user)
var/data = list()
// Suit information
var/suit_status = list(
"core_name" = core?.name,
"charge_current" = get_charge(),
"charge_max" = get_max_charge(),
"chargebar_color" = get_chargebar_color(),
"chargebar_string" = get_chargebar_string(),
"active" = active,
"ai_name" = ai_assistant?.name,
"has_pai" = ispAI(ai_assistant),
"is_ai" = ai_assistant && ai_assistant == user,
"link_id" = mod_link.id,
"link_freq" = mod_link.frequency,
"link_call" = mod_link.get_other()?.id,
// Wires
"open" = open,
"seconds_electrified" = seconds_electrified,
"malfunctioning" = malfunctioning,
"locked" = locked,
"interface_break" = interface_break,
// Modules
"complexity" = complexity,
)
data["suit_status"] = suit_status
// User information
var/user_status = list(
"user_name" = wearer ? (wearer.get_authentification_name("Unknown") || "Unknown") : "",
"user_assignment" = wearer ? wearer.get_assignment("Unknown", "Unknown", FALSE) : "",
)
data["user_status"] = user_status
// Module information
var/module_custom_status = list()
var/module_info = list()
for(var/obj/item/mod/module/module as anything in modules)
module_custom_status += module.add_ui_data()
module_info += list(list(
"module_name" = module.name,
"description" = module.desc,
"module_type" = module.module_type,
"module_active" = module.active,
"pinned" = module.pinned_to[REF(user)],
"idle_power" = module.idle_power_cost,
"active_power" = module.active_power_cost,
"use_energy" = module.use_energy_cost,
"module_complexity" = module.complexity,
"cooldown_time" = module.cooldown_time,
"cooldown" = round(COOLDOWN_TIMELEFT(module, cooldown_timer), 1 SECONDS),
"id" = module.tgui_id,
"ref" = REF(module),
"configuration_data" = module.get_configuration(user),
))
data["module_custom_status"] = module_custom_status
data["control"] = name
data["module_info"] = module_info
var/part_info = list()
for(var/obj/item/part as anything in get_parts())
part_info += list(list(
"slot" = english_list(parse_slot_flags(part.slot_flags)),
"name" = part.name,
"deployed" = part.loc != src,
"ref" = REF(part),
))
data["parts"] = part_info
return data
/obj/item/mod/control/ui_static_data(mob/user)
var/data = list()
data["ui_theme"] = ui_theme
data["complexity_max"] = complexity_max
return data
/obj/item/mod/control/ui_state(mob/user)
if(user == ai_assistant)
return GLOB.contained_state
return ..()
/obj/item/mod/control/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
if(malfunctioning && prob(MOD_MALFUNCTION_PROB))
balloon_alert(ui.user, "button malfunctions!")
return
switch(action)
if("lock")
if(!locked || allowed(ui.user))
locked = !locked
balloon_alert(ui.user, "[locked ? "locked" : "unlocked"]")
else
balloon_alert(ui.user, "access insufficent!")
playsound(src, 'sound/machines/scanner/scanbuzz.ogg', 25, TRUE, SILENCED_SOUND_EXTRARANGE)
if("call")
if(!mod_link.link_call)
call_link(ui.user, mod_link)
else
mod_link.end_call()
if("activate")
toggle_activate(ui.user)
if("select")
var/obj/item/mod/module/module = locate(params["ref"]) in modules
if(!module)
return
module.on_select(ui.user) // We can now
if("configure")
var/obj/item/mod/module/module = locate(params["ref"]) in modules
if(!module)
return
module.configure_edit(params["key"], params["value"])
if("pin")
var/obj/item/mod/module/module = locate(params["ref"]) in modules
if(!module)
return
module.pin(ui.user)
if("deploy")
var/obj/item/mod_part = locate(params["ref"]) in get_parts()
if(!mod_part)
return
if(mod_part.loc == src)
deploy(ui.user, mod_part)
else
retract(ui.user, mod_part)
if("eject_pai")
if (!ishuman(ui.user))
return
remove_pai(ui.user)
return TRUE