Files
Bubberstation/code/datums/actions/innate_action.dm
T
MrMelbertandGitHub 329921639a Rewrites how action buttons icons are generated, makes them layer nicer. Allows observers to see a mob's action buttons. (#71339)
## About The Pull Request

- Rewrites how action button icons are generated.
- Prior, generated an action button icon was fairly simplistic and
didn't allow for many changes. Someone recently added the option for
overlays to be generated over action buttons, but the framework was very
weak.
- Now, action button icon generation is split across multiple procs,
like atom icon updates.
      - The background of action buttons are underlays
- The actual icon of the action button is the icon and icon state of the
action button movable
- The rim / border of the button is an overlay, layered overtop the
button.

- Allows observers to see what action buttons a mob has. They even
update in real time! And no, the observers cannot click on them.

## Why It's Good For The Game

- Runechat text of action buttons are no longer hidden behind the actual
icon. This was very ugly with cooldown actions, as the cooldown text was
hidden behind a lot of spell icons.
- Cuts down on a lot of icon duplication. 
- Gives much finer control over action button icons
- Saves a bit of processing from generating full action button icons
when not necessary. Not implemented in many places, but is in some.


![image](https://user-images.githubusercontent.com/51863163/202816617-342e87e6-2cc6-488e-9af2-4b2053dc3dc6.png)


![image](https://user-images.githubusercontent.com/51863163/202816604-da8d4821-0e2b-45af-b289-7442367f98ce.png)

## Changelog

🆑 Melbert
add: Observers can now see what action buttons an observed mob has. No,
you can't click them. And no it doesn't show EVERY action.
refactor: Refactored how action button icons are generated. Some actions
will now use a colored border when active instead of just turning green.
Cooldown text will also appear on the top layer of actions too. If you
see any funky lookin' icons (namely their borders), let me know.
refactor: Bluespace Golem's teleport action is now a cooldown action.
fix: Construct actions go to the middle of the screen like expected. 
/🆑
2022-12-03 19:01:08 -08:00

96 lines
3.0 KiB
Plaintext

//Preset for general and toggled actions
/datum/action/innate
check_flags = NONE
/// Whether we're active or not, if we're a innate - toggle action.
var/active = FALSE
/// Whether we're a click action or not, if we're a innate - click action.
var/click_action = FALSE
/// If we're a click action, the mouse pointer we use
var/ranged_mousepointer
/// If we're a click action, the text shown on enable
var/enable_text
/// If we're a click action, the text shown on disable
var/disable_text
/datum/action/innate/Trigger(trigger_flags)
if(!..())
return FALSE
// We're a click action, trigger just sets it as active or not
if(click_action)
if(owner.click_intercept == src)
unset_ranged_ability(owner, disable_text)
else
set_ranged_ability(owner, enable_text)
build_all_button_icons(UPDATE_BUTTON_STATUS)
return TRUE
// We're not a click action (we're a toggle or otherwise)
else
var/active_status = active
if(active_status)
Deactivate()
else
Activate()
if(active != active_status)
build_all_button_icons(UPDATE_BUTTON_STATUS)
return TRUE
/datum/action/innate/is_action_active(atom/movable/screen/movable/action_button/current_button)
if(click_action)
return current_button.our_hud?.mymob?.click_intercept == src
else
return active
/datum/action/innate/proc/Activate()
return
/datum/action/innate/proc/Deactivate()
return
/**
* This is gross, but a somewhat-required bit of copy+paste until action code becomes slightly more sane.
* Anything that uses these functions should eventually be moved to use cooldown actions.
* (Either that, or the click ability of cooldown actions should be moved down a type.)
*
* If you're adding something that uses these, rethink your choice in subtypes.
*/
/// Sets this action as the active ability for the passed mob
/datum/action/innate/proc/set_ranged_ability(mob/living/on_who, text_to_show)
if(ranged_mousepointer)
on_who.client?.mouse_override_icon = ranged_mousepointer
on_who.update_mouse_pointer()
if(text_to_show)
to_chat(on_who, text_to_show)
on_who.click_intercept = src
/// Removes this action as the active ability of the passed mob
/datum/action/innate/proc/unset_ranged_ability(mob/living/on_who, text_to_show)
if(ranged_mousepointer)
on_who.client?.mouse_override_icon = initial(owner.client?.mouse_pointer_icon)
on_who.update_mouse_pointer()
if(text_to_show)
to_chat(on_who, text_to_show)
on_who.click_intercept = null
/// Handles whenever a mob clicks on something
/datum/action/innate/proc/InterceptClickOn(mob/living/caller, params, atom/clicked_on)
if(!IsAvailable(feedback = TRUE))
unset_ranged_ability(caller)
return FALSE
if(!clicked_on)
return FALSE
return do_ability(caller, clicked_on)
/// Actually goes through and does the click ability
/datum/action/innate/proc/do_ability(mob/living/caller, atom/clicked_on)
return FALSE
/datum/action/innate/Remove(mob/removed_from)
if(removed_from.click_intercept == src)
unset_ranged_ability(removed_from)
return ..()