Skip to content

Commit

Permalink
Merge pull request #23 from GalacticStation/upstream-merge-80379
Browse files Browse the repository at this point in the history
[MIRROR] Circuit action button refactor
  • Loading branch information
vinylspiders authored Dec 23, 2023
2 parents a55eca1 + 8677d42 commit 0743224
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 184 deletions.
6 changes: 6 additions & 0 deletions code/__DEFINES/dcs/signals/signals_circuit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@

///Called when an Ntnet sender is sending Ntnet data
#define COMSIG_GLOB_CIRCUIT_NTNET_DATA_SENT "!circuit_ntnet_data_sent"

/// Called when an equipment action component is added to a shell (/obj/item/circuit_component/equipment_action/action_comp)
#define COMSIG_CIRCUIT_ACTION_COMPONENT_REGISTERED "circuit_action_component_registered"

/// Called when an equipment action component is removed from a shell (/obj/item/circuit_component/equipment_action/action_comp)
#define COMSIG_CIRCUIT_ACTION_COMPONENT_UNREGISTERED "circuit_action_component_unregistered"
54 changes: 30 additions & 24 deletions code/modules/mod/mod_actions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,43 @@
/datum/action/item_action/mod/panel/ai
ai_action = TRUE

/datum/action/item_action/mod/pinned_module
/datum/action/item_action/mod/pinnable
/// A reference to the mob we are pinned to.
var/mob/pinner

/datum/action/item_action/mod/pinnable/New(Target, mob/user)
. = ..()
var/obj/item/mod/control/mod = Target
if(user == mod.ai_assistant)
ai_action = TRUE
pinner = user
RegisterSignal(user, COMSIG_QDELETING, PROC_REF(pinner_deleted))

/datum/action/item_action/mod/pinnable/Grant(mob/user)
if(pinner != user)
return
return ..()

/// If the guy whose UI we are pinned to got deleted
/datum/action/item_action/mod/pinnable/proc/pinner_deleted()
SIGNAL_HANDLER
pinner = null
qdel(src)

/datum/action/item_action/mod/pinnable/module
desc = "Activate the module."
/// Overrides the icon applications.
var/override = FALSE
/// Module we are linked to.
var/obj/item/mod/module/module
/// A reference to the mob we are pinned to.
var/mob/pinner
/// Timer until we remove our cooldown overlay
var/cooldown_timer

/datum/action/item_action/mod/pinned_module/New(Target, obj/item/mod/module/linked_module, mob/user)
var/obj/item/mod/control/mod = Target
if(user == mod.ai_assistant)
ai_action = TRUE
/datum/action/item_action/mod/pinnable/module/New(Target, mob/user, obj/item/mod/module/linked_module)
button_icon = linked_module.icon
button_icon_state = linked_module.icon_state
. = ..()
module = linked_module
pinner = user
module.pinned_to[REF(user)] = src
if(linked_module.allow_flags & MODULE_ALLOW_INCAPACITATED)
// clears check hands and check conscious
Expand All @@ -149,9 +166,8 @@
COMSIG_MODULE_USED,
), PROC_REF(module_interacted_with))
RegisterSignal(linked_module, COMSIG_MODULE_COOLDOWN_STARTED, PROC_REF(cooldown_started))
RegisterSignal(user, COMSIG_QDELETING, PROC_REF(pinner_deleted))

/datum/action/item_action/mod/pinned_module/Destroy()
/datum/action/item_action/mod/pinnable/module/Destroy()
deltimer(cooldown_timer)
UnregisterSignal(module, list(
COMSIG_MODULE_ACTIVATED,
Expand All @@ -164,23 +180,13 @@
pinner = null
return ..()

/datum/action/item_action/mod/pinned_module/Grant(mob/user)
if(pinner != user)
return
return ..()

/datum/action/item_action/mod/pinned_module/Trigger(trigger_flags)
/datum/action/item_action/mod/pinnable/module/Trigger(trigger_flags)
. = ..()
if(!.)
return
module.on_select()

/// If the guy whose UI we are pinned to got deleted
/datum/action/item_action/mod/pinned_module/proc/pinner_deleted()
pinner = null
qdel(src)

/datum/action/item_action/mod/pinned_module/apply_button_overlay(atom/movable/screen/movable/action_button/current_button, force)
/datum/action/item_action/mod/pinnable/module/apply_button_overlay(atom/movable/screen/movable/action_button/current_button, force)
current_button.cut_overlays()
if(override)
return ..()
Expand All @@ -194,12 +200,12 @@
current_button.add_overlay(image(icon = 'icons/hud/radial.dmi', icon_state = "module_cooldown"))
return ..()

/datum/action/item_action/mod/pinned_module/proc/module_interacted_with(datum/source)
/datum/action/item_action/mod/pinnable/module/proc/module_interacted_with(datum/source)
SIGNAL_HANDLER

build_all_button_icons(UPDATE_BUTTON_OVERLAY|UPDATE_BUTTON_STATUS)

/datum/action/item_action/mod/pinned_module/proc/cooldown_started(datum/source, cooldown_time)
/datum/action/item_action/mod/pinnable/module/proc/cooldown_started(datum/source, cooldown_time)
SIGNAL_HANDLER

deltimer(cooldown_timer)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mod/mod_control.dm
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@

// Grant pinned actions to pin owners, gives AI pinned actions to the AI and not the wearer
/obj/item/mod/control/grant_action_to_bearer(datum/action/action)
if (!istype(action, /datum/action/item_action/mod/pinned_module))
if (!istype(action, /datum/action/item_action/mod/pinnable))
return ..()
var/datum/action/item_action/mod/pinned_module/pinned = action
var/datum/action/item_action/mod/pinnable/pinned = action
give_item_action(action, pinned.pinner, slot_flags)

/obj/item/mod/control/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mod/mod_ui.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"cooldown" = round(COOLDOWN_TIMELEFT(module, cooldown_timer), 1 SECONDS),
"id" = module.tgui_id,
"ref" = REF(module),
"configuration_data" = module.get_configuration()
"configuration_data" = module.get_configuration(user)
))
data["module_custom_status"] = module_custom_status
data["module_info"] = module_info
Expand Down
6 changes: 3 additions & 3 deletions code/modules/mod/modules/_module.dm
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
return list()

/// Creates a list of configuring options for this module
/obj/item/mod/module/proc/get_configuration()
/obj/item/mod/module/proc/get_configuration(mob/user)
return list()

/// Generates an element of the get_configuration list with a display name, type and value
Expand Down Expand Up @@ -325,12 +325,12 @@
if(module_type == MODULE_PASSIVE)
return

var/datum/action/item_action/mod/pinned_module/existing_action = pinned_to[REF(user)]
var/datum/action/item_action/mod/pinnable/module/existing_action = pinned_to[REF(user)]
if(existing_action)
mod.remove_item_action(existing_action)
return

var/datum/action/item_action/mod/pinned_module/new_action = new(mod, src, user)
var/datum/action/item_action/mod/pinnable/module/new_action = new(mod, user, src)
mod.add_item_action(new_action)

/// On drop key, concels a device item.
Expand Down
18 changes: 4 additions & 14 deletions code/modules/research/designs/wiremod_designs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,10 @@
id = "comp_pinpointer"
build_path = /obj/item/circuit_component/pinpointer

/datum/design/component/bci
category = list(
RND_CATEGORY_CIRCUITRY + RND_SUBCATEGORY_CIRCUITRY_BCI_COMPONENTS
)

/datum/design/component/bci/bci_action
name = "BCI Action Component"
id = "comp_bci_action"
build_path = /obj/item/circuit_component/equipment_action/bci
/datum/design/component/equipment_action
name = "Equipment Action Component"
id = "comp_equip_action"
build_path = /obj/item/circuit_component/equipment_action

/datum/design/component/bci/object_overlay
name = "Object Overlay Component"
Expand Down Expand Up @@ -417,11 +412,6 @@
id = "comp_filter_list"
build_path = /obj/item/circuit_component/filter_list

/datum/design/component/mod_action
name = "MOD Action Component"
id = "comp_mod_action"
build_path = /obj/item/circuit_component/equipment_action/mod

/datum/design/component/id_getter
name = "ID Getter Component"
id = "comp_id_getter"
Expand Down
3 changes: 1 addition & 2 deletions code/modules/research/techweb/all_nodes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@
design_ids = list(
"assembly_shell",
"bot_shell",
"comp_mod_action",
"comp_equip_action",
"controller_shell",
"dispenser_shell",
"door_shell",
Expand All @@ -876,7 +876,6 @@
"bci_implanter",
"bci_shell",
"comp_bar_overlay",
"comp_bci_action",
"comp_counter_overlay",
"comp_install_detector",
"comp_object_overlay",
Expand Down
65 changes: 0 additions & 65 deletions code/modules/wiremod/components/abstract/equpiment_action.dm

This file was deleted.

92 changes: 92 additions & 0 deletions code/modules/wiremod/components/action/equpiment_action.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/obj/item/circuit_component/equipment_action
display_name = "Equipment Action"
desc = "Represents an action the user can take when using supported shells."
required_shells = list(/obj/item/organ/internal/cyberimp/bci, /obj/item/mod/module/circuit)

/// The icon of the button
var/datum/port/input/option/icon_options

/// The name to use for the button
var/datum/port/input/button_name

/// The mob who activated their granted action
var/datum/port/output/user

/// Called when the user presses the button
var/datum/port/output/signal

/// An assoc list of datum REF()s, linked to the actions granted.
var/list/granted_to = list()

/obj/item/circuit_component/equipment_action/Initialize(mapload, default_icon)
. = ..()

if (!isnull(default_icon))
icon_options.set_input(default_icon)

button_name = add_input_port("Name", PORT_TYPE_STRING)

user = add_output_port("User", PORT_TYPE_USER)
signal = add_output_port("Signal", PORT_TYPE_SIGNAL)

/obj/item/circuit_component/equipment_action/Destroy()
QDEL_LIST_ASSOC_VAL(granted_to)
return ..()

/obj/item/circuit_component/equipment_action/populate_options()
var/static/action_options = list(
"Blank",

"One",
"Two",
"Three",
"Four",
"Five",

"Blood",
"Bomb",
"Brain",
"Brain Damage",
"Cross",
"Electricity",
"Exclamation",
"Heart",
"Id",
"Info",
"Injection",
"Magnetism",
"Minus",
"Network",
"Plus",
"Power",
"Question",
"Radioactive",
"Reaction",
"Repair",
"Say",
"Scan",
"Shield",
"Skull",
"Sleep",
"Wireless",
)

icon_options = add_option_port("Icon", action_options)

/obj/item/circuit_component/equipment_action/register_shell(atom/movable/shell)
. = ..()
SEND_SIGNAL(shell, COMSIG_CIRCUIT_ACTION_COMPONENT_REGISTERED, src)

/obj/item/circuit_component/equipment_action/unregister_shell(atom/movable/shell)
. = ..()
SEND_SIGNAL(shell, COMSIG_CIRCUIT_ACTION_COMPONENT_UNREGISTERED, src)

/obj/item/circuit_component/equipment_action/input_received(datum/port/input/port)
if (length(granted_to))
update_actions()

/obj/item/circuit_component/equipment_action/proc/update_actions()
for(var/ref in granted_to)
var/datum/action/granted_action = granted_to[ref]
granted_action.name = button_name.value || "Action"
granted_action.button_icon_state = "bci_[replacetextEx(lowertext(icon_options.value), " ", "_")]"
Loading

0 comments on commit 0743224

Please sign in to comment.