mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-07-21 03:56:47 +01:00
The final action buttons PR (#16514)
* Make action button target datum * Initial working action palette * Action related refactors * tgstation/tgstation/pull/71339
This commit is contained in:
@@ -115,8 +115,10 @@
|
||||
|
||||
/obj/item/New()
|
||||
..()
|
||||
|
||||
for(var/path in actions_types)
|
||||
new path(src)
|
||||
add_item_action(path)
|
||||
|
||||
if(embed_chance < 0)
|
||||
if(sharp)
|
||||
embed_chance = max(5, round(force/w_class))
|
||||
@@ -137,10 +139,55 @@
|
||||
m.update_inv_r_hand()
|
||||
m.update_inv_l_hand()
|
||||
src.loc = null
|
||||
for(var/X in actions)
|
||||
qdel(X)
|
||||
|
||||
// Handle celaning up our actions list
|
||||
for(var/datum/action/action as anything in actions)
|
||||
remove_item_action(action)
|
||||
|
||||
return ..()
|
||||
|
||||
|
||||
/// Called when an action associated with our item is deleted
|
||||
/obj/item/proc/on_action_deleted(datum/source)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(!(source in actions))
|
||||
CRASH("An action ([source.type]) was deleted that was associated with an item ([src]), but was not found in the item's actions list.")
|
||||
|
||||
LAZYREMOVE(actions, source)
|
||||
|
||||
/// Adds an item action to our list of item actions.
|
||||
/// Item actions are actions linked to our item, that are granted to mobs who equip us.
|
||||
/// This also ensures that the actions are properly tracked in the actions list and removed if they're deleted.
|
||||
/// Can be be passed a typepath of an action or an instance of an action.
|
||||
/obj/item/proc/add_item_action(action_or_action_type)
|
||||
var/datum/action/action
|
||||
if(ispath(action_or_action_type, /datum/action))
|
||||
action = new action_or_action_type(src)
|
||||
else if(istype(action_or_action_type, /datum/action))
|
||||
action = action_or_action_type
|
||||
else
|
||||
CRASH("item add_item_action got a type or instance of something that wasn't an action.")
|
||||
|
||||
LAZYADD(actions, action)
|
||||
RegisterSignal(action, COMSIG_PARENT_QDELETING, PROC_REF(on_action_deleted))
|
||||
if(ismob(loc))
|
||||
// We're being held or are equipped by someone while adding an action?
|
||||
// Then they should also probably be granted the action, given it's in a correct slot
|
||||
var/mob/holder = loc
|
||||
give_item_action(action, holder, holder.get_inventory_slot(src))
|
||||
|
||||
return action
|
||||
|
||||
/// Removes an instance of an action from our list of item actions.
|
||||
/obj/item/proc/remove_item_action(datum/action/action)
|
||||
if(!action)
|
||||
return
|
||||
|
||||
UnregisterSignal(action, COMSIG_PARENT_QDELETING)
|
||||
LAZYREMOVE(actions, action)
|
||||
qdel(action)
|
||||
|
||||
// Check if target is reasonable for us to operate on.
|
||||
/obj/item/proc/check_allowed_items(atom/target, not_inside, target_self)
|
||||
if(((src in target) && !target_self) || ((!istype(target.loc, /turf)) && (!istype(target, /turf)) && (not_inside)))
|
||||
@@ -335,8 +382,9 @@
|
||||
if(zoom)
|
||||
zoom() //binoculars, scope, etc
|
||||
appearance_flags &= ~NO_CLIENT_COLOR
|
||||
for(var/datum/action/A as anything in actions)
|
||||
A.Remove(user)
|
||||
// Remove any item actions we temporary gave out.
|
||||
for(var/datum/action/action_item_has as anything in actions)
|
||||
action_item_has.Remove(user)
|
||||
|
||||
// called just as an item is picked up (loc is not yet changed)
|
||||
/obj/item/proc/pickup(mob/user)
|
||||
@@ -362,10 +410,9 @@
|
||||
// for items that can be placed in multiple slots
|
||||
// note this isn't called during the initial dressing of a player
|
||||
/obj/item/proc/equipped(var/mob/user, var/slot)
|
||||
for(var/X in actions)
|
||||
var/datum/action/A = X
|
||||
if(item_action_slot_check(slot, user)) //some items only give their actions buttons when in a specific slot.
|
||||
A.Grant(user)
|
||||
// Give out actions our item has to people who equip it.
|
||||
for(var/datum/action/action as anything in actions)
|
||||
give_item_action(action, user, slot)
|
||||
hud_layerise()
|
||||
user.position_hud_item(src,slot)
|
||||
if(user.client) user.client.screen |= src
|
||||
@@ -379,6 +426,18 @@
|
||||
playsound(src, pickup_sound, 20, preference = /datum/preference/toggle/pickup_sounds)
|
||||
return
|
||||
|
||||
/// Gives one of our item actions to a mob, when equipped to a certain slot
|
||||
/obj/item/proc/give_item_action(datum/action/action, mob/to_who, slot)
|
||||
// Some items only give their actions buttons when in a specific slot.
|
||||
if(!item_action_slot_check(slot, to_who))
|
||||
// There is a chance we still have our item action currently,
|
||||
// and are moving it from a "valid slot" to an "invalid slot".
|
||||
// So call Remove() here regardless, even if excessive.
|
||||
action.Remove(to_who)
|
||||
return
|
||||
|
||||
action.Grant(to_who)
|
||||
|
||||
//sometimes we only want to grant the item's action if it's equipped in a specific slot.
|
||||
/obj/item/proc/item_action_slot_check(slot, mob/user)
|
||||
if(slot == SLOT_BACK || slot == LEGS) //these aren't true slots, so avoid granting actions there
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
playsound(src, 'sound/weapons/empty.ogg', 15, 1, -3) // VOREStation Edit
|
||||
update_brightness()
|
||||
user.update_action_buttons_icon()
|
||||
user.update_mob_action_buttons()
|
||||
return 1
|
||||
|
||||
/obj/item/flashlight/emp_act(severity)
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
set_light(0)
|
||||
light_applied = 0
|
||||
update_icon(user)
|
||||
user.update_action_buttons_icon()
|
||||
user.update_mob_action_buttons()
|
||||
playsound(src, 'sound/weapons/empty.ogg', 15, 1, -3)
|
||||
|
||||
/obj/item/shield/riot/explorer/update_icon()
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
if (ismob(usr))
|
||||
var/mob/M = usr
|
||||
M.update_inv_back()
|
||||
M.update_action_buttons_icon()
|
||||
M.update_mob_action_buttons()
|
||||
|
||||
to_chat(usr, "You toggle the thrusters [on? "on":"off"].")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user