Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ports cogbars from TG #11120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion beestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "code\__DEFINES\directional.dm"
#include "code\__DEFINES\diseases.dm"
#include "code\__DEFINES\DNA.dm"
#include "code\__DEFINES\do_afters.dm"
#include "code\__DEFINES\dye_keys.dm"
#include "code\__DEFINES\dynamic.dm"
#include "code\__DEFINES\economy.dm"
Expand Down Expand Up @@ -174,7 +175,6 @@
#include "code\__DEFINES\tgs.dm"
#include "code\__DEFINES\tgui.dm"
#include "code\__DEFINES\time.dm"
#include "code\__DEFINES\timed_action.dm"
#include "code\__DEFINES\tools.dm"
#include "code\__DEFINES\toys.dm"
#include "code\__DEFINES\traitor.dm"
Expand Down Expand Up @@ -319,6 +319,7 @@
#include "code\_globalvars\lists\ambience.dm"
#include "code\_globalvars\lists\client.dm"
#include "code\_globalvars\lists\flavor_misc.dm"
#include "code\_globalvars\lists\icons.dm"
#include "code\_globalvars\lists\jobs.dm"
#include "code\_globalvars\lists\maintenance_loot.dm"
#include "code\_globalvars\lists\mapping.dm"
Expand Down Expand Up @@ -514,6 +515,7 @@
#include "code\datums\callback.dm"
#include "code\datums\chat_payload.dm"
#include "code\datums\chatmessage.dm"
#include "code\datums\cogbar.dm"
#include "code\datums\cinematic.dm"
#include "code\datums\dash_weapon.dm"
#include "code\datums\datacore.dm"
Expand Down
4 changes: 4 additions & 0 deletions code/__DEFINES/do_afters.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define DOAFTER_SOURCE_SURGERY "doafter_surgery"
#define DOAFTER_SOURCE_MECHADRILL "doafter_mechadrill"
#define DOAFTER_SOURCE_SURVIVALPEN "doafter_survivalpen"
#define DOAFTER_SOURCE_GETTING_UP "doafter_gettingup"
18 changes: 14 additions & 4 deletions code/__DEFINES/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
else if(!HAS_TRAIT(x, TRAIT_KEEP_TOGETHER))\
x.appearance_flags &= ~KEEP_TOGETHER

//religious_tool flags
#define RELIGION_TOOL_INVOKE (1<<0)
#define RELIGION_TOOL_SACRIFICE (1<<1)
#define RELIGION_TOOL_SECTSELECT (1<<2)

//dir macros
///Returns true if the dir is diagonal, false otherwise
#define ISDIAGONALDIR(d) (d&(d-1))
Expand All @@ -214,7 +219,12 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
///Turns the dir by 180 degrees
#define DIRFLIP(d) turn(d, 180)

//religious_tool flags
#define RELIGION_TOOL_INVOKE (1<<0)
#define RELIGION_TOOL_SACRIFICE (1<<1)
#define RELIGION_TOOL_SECTSELECT (1<<2)
// timed_action_flags parameter for `/proc/do_after`
/// Can do the action even if mob moves location
#define IGNORE_USER_LOC_CHANGE (1<<0)
/// Can do the action even if the target moves location
#define IGNORE_TARGET_LOC_CHANGE (1<<1)
/// Can do the action even if the item is no longer being held
#define IGNORE_HELD_ITEM (1<<2)
/// Can do the action even if the mob is incapacitated (ex. handcuffed)
#define IGNORE_INCAPACITATED (1<<3)
2 changes: 2 additions & 0 deletions code/__DEFINES/layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
#define BALLOON_CHAT_PLANE 651

///--------------- FULLSCREEN IMAGES ------------
///Anything that wants to be part of the game plane, but also wants to draw above literally everything else
#define HIGH_GAME_PLANE 499
#define FULLSCREEN_PLANE 500
#define FLASH_LAYER 1
#define FULLSCREEN_LAYER 2
Expand Down
6 changes: 5 additions & 1 deletion code/__DEFINES/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ GLOBAL_LIST_INIT(available_random_trauma_list, list(
#define HUMAN_CARRY_SLOWDOWN 0.35

#define SLEEP_CHECK_DEATH(X) sleep(X); if(QDELETED(src) || stat == DEAD) return;
#define INTERACTING_WITH(X, Y) (Y in X.do_afters)

#define DOING_INTERACTION(user, interaction_key) (LAZYACCESS(user.do_afters, interaction_key))
#define DOING_INTERACTION_LIMIT(user, interaction_key, max_interaction_count) ((LAZYACCESS(user.do_afters, interaction_key) || 0) >= max_interaction_count)
#define DOING_INTERACTION_WITH_TARGET(user, target) (LAZYACCESS(user.do_afters, target))
#define DOING_INTERACTION_WITH_TARGET_LIMIT(user, target, max_interaction_count) ((LAZYACCESS(user.do_afters, target) || 0) >= max_interaction_count)

#define SILENCE_RANGED_MESSAGE (1<<0)

Expand Down
22 changes: 13 additions & 9 deletions code/__DEFINES/time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ When using time2text(), please use "DDD" to find the weekday. Refrain from using

*/

#define MONDAY "Mon"
#define TUESDAY "Tue"
#define WEDNESDAY "Wed"
#define THURSDAY "Thu"
#define FRIDAY "Fri"
#define SATURDAY "Sat"
#define SUNDAY "Sun"
#define MONDAY "Mon"
#define TUESDAY "Tue"
#define WEDNESDAY "Wed"
#define THURSDAY "Thu"
#define FRIDAY "Fri"
#define SATURDAY "Sat"
#define SUNDAY "Sun"

#define INFINITE -1 // -1 is commonly used to indicate an infinite time duration

#define MILLISECONDS *0.01

#define DECISECONDS *1 //the base unit all of these defines are scaled by, because byond uses that as a unit of measurement for some fucking reason

#define SECONDS *10

Expand All @@ -49,8 +55,6 @@ When using time2text(), please use "DDD" to find the weekday. Refrain from using

#define TICKS *world.tick_lag

#define MILLISECONDS * 0.01

#define DS2TICKS(DS) ((DS)/world.tick_lag)

#define TICKS2DS(T) ((T) TICKS)
Expand Down
12 changes: 0 additions & 12 deletions code/__DEFINES/timed_action.dm

This file was deleted.

12 changes: 12 additions & 0 deletions code/__HELPERS/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,15 @@ B --><-- A
return get_step(ref, base_dir)

*/

/// Returns an x and y value require to reverse the transformations made to center an oversized icon
/atom/proc/get_oversized_icon_offsets()
if (pixel_x == 0 && pixel_y == 0)
return list("x" = 0, "y" = 0)
var/list/icon_dimensions = get_icon_dimensions(icon)
var/icon_width = icon_dimensions["width"]
var/icon_height = icon_dimensions["height"]
return list(
"x" = icon_width > world.icon_size && pixel_x != 0 ? (icon_width - world.icon_size) * 0.5 : 0,
"y" = icon_height > world.icon_size && pixel_y != 0 ? (icon_height - world.icon_size) * 0.5 : 0,
)
7 changes: 7 additions & 0 deletions code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1459,3 +1459,10 @@ GLOBAL_LIST_EMPTY(friendly_animal_types)
animate(src, pixel_x = pixel_x + shiftx, pixel_y = pixel_y + shifty, time = 0.2, loop = duration)
pixel_x = initialpixelx
pixel_y = initialpixely

/// Returns a list containing the width and height of an icon file
/proc/get_icon_dimensions(icon_path)
if (isnull(GLOB.icon_dimensions[icon_path]))
var/icon/my_icon = icon(icon_path)
GLOB.icon_dimensions[icon_path] = list("width" = my_icon.Width(), "height" = my_icon.Height())
return GLOB.icon_dimensions[icon_path]
67 changes: 31 additions & 36 deletions code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,19 @@ GLOBAL_LIST_EMPTY(species_list)
* * progress - if TRUE, a progress bar is displayed.
* * extra_checks - a callback that can be used to add extra checks to the do_after. Returning false in this callback will cancel the do_after.
*/
/proc/do_after(mob/user, delay = 3 SECONDS, atom/target, timed_action_flags = NONE, progress = TRUE, datum/callback/extra_checks)
/proc/do_after(mob/user, delay, atom/target, timed_action_flags = NONE, progress = TRUE, datum/callback/extra_checks, interaction_key, max_interact_count = 1, hidden = FALSE)
if(!user)
return FALSE
if(!isnum(delay))
CRASH("do_after was passed a non-number delay: [delay || "null"].")

if(target)
LAZYADD(user.do_afters, target)
LAZYADD(target.targeted_by, user)
if(!interaction_key && target)
interaction_key = target //Use the direct ref to the target
if(interaction_key) //Do we have a interaction_key now?
var/current_interaction_count = LAZYACCESS(user.do_afters, interaction_key) || 0
if(current_interaction_count >= max_interact_count) //We are at our peak
return
LAZYSET(user.do_afters, interaction_key, current_interaction_count + 1)

var/atom/user_loc = user.loc
var/atom/target_loc = target?.loc
Expand All @@ -279,60 +285,49 @@ GLOBAL_LIST_EMPTY(species_list)
delay *= user.cached_multiplicative_actions_slowdown

var/datum/progressbar/progbar
var/datum/cogbar/cog

if(progress)
if(target) // the progress bar needs a target, so if we don't have one just pass it the user.
progbar = new(user, delay, target)
else
progbar = new(user, delay, user)
if(user.client)
progbar = new(user, delay, target || user)

if(!hidden && delay >= 1 SECONDS)
cog = new(user)

var/endtime = world.time + delay
var/starttime = world.time
. = TRUE
while(world.time < endtime)
stoplag(1)

if(QDELETED(user))
. = FALSE
break

if(progress)
if(!QDELETED(progbar))
progbar.update(world.time - starttime)

if(drifting && SSmove_manager.processing_on(user, SSspacedrift))
drifting = FALSE
user_loc = user.loc

// Check flags
if(!(timed_action_flags & IGNORE_USER_LOC_CHANGE) && !drifting && user.loc != user_loc)
. = FALSE

if(!(timed_action_flags & IGNORE_HELD_ITEM) && user.get_active_held_item() != holding)
if(QDELETED(user) \
|| (!(timed_action_flags & IGNORE_USER_LOC_CHANGE) && !drifting && user.loc != user_loc) \
|| (!(timed_action_flags & IGNORE_HELD_ITEM) && user.get_active_held_item() != holding) \
|| (!(timed_action_flags & IGNORE_INCAPACITATED) && HAS_TRAIT(user, TRAIT_INCAPACITATED)) \
|| (extra_checks && !extra_checks.Invoke()))
. = FALSE
break

if(!(timed_action_flags & IGNORE_INCAPACITATED) && user.incapacitated(ignore_restraints = (timed_action_flags & IGNORE_RESTRAINED)))
. = FALSE


if(extra_checks && !extra_checks.Invoke())
. = FALSE

// If we have a target, we check for them moving here. We don't care about it if we're drifting or we ignore target loc change
if(!(timed_action_flags & IGNORE_TARGET_LOC_CHANGE) && !drifting)
if(target_loc && user != target && (QDELETED(target) || target_loc != target.loc))
. = FALSE

if(target && !(timed_action_flags & IGNORE_TARGET_IN_DOAFTERS) && !(target in user.do_afters))
if(target && (user != target) && \
(QDELETED(target) \
|| (!(timed_action_flags & IGNORE_TARGET_LOC_CHANGE) && target.loc != target_loc)))
. = FALSE

if(!.)
break

if(!QDELETED(progbar))
progbar.end_progress()

if(!QDELETED(target))
LAZYREMOVE(user.do_afters, target)
LAZYREMOVE(target.targeted_by, user)
cog?.remove()

if(interaction_key)
LAZYREMOVE(user.do_afters, interaction_key)

/proc/is_species(A, species_datum)
. = FALSE
Expand Down
6 changes: 3 additions & 3 deletions code/__HELPERS/turfs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ Turf and target are separate in case you want to teleport some distance from a t
var/pixel_y_offset = checked_atom.pixel_y + atom_matrix.get_y_shift()

//Irregular objects
var/icon/checked_atom_icon = icon(checked_atom.icon, checked_atom.icon_state)
var/checked_atom_icon_height = checked_atom_icon.Height()
var/checked_atom_icon_width = checked_atom_icon.Width()
var/list/icon_dimensions = get_icon_dimensions(checked_atom.icon)
var/checked_atom_icon_height = icon_dimensions["width"]
var/checked_atom_icon_width = icon_dimensions["height"]
if(checked_atom_icon_height != world.icon_size || checked_atom_icon_width != world.icon_size)
pixel_x_offset += ((checked_atom_icon_width / world.icon_size) - 1) * (world.icon_size * 0.5)
pixel_y_offset += ((checked_atom_icon_height / world.icon_size) - 1) * (world.icon_size * 0.5)
Expand Down
2 changes: 2 additions & 0 deletions code/_globalvars/lists/icons.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Cache of the width and height of icon files, to avoid repeating the same expensive operation
GLOBAL_LIST_EMPTY(icon_dimensions)
2 changes: 1 addition & 1 deletion code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@
screen_loc = ui_mood

/atom/movable/screen/splash
icon = 'icons/blank_title.png'
icon = 'icons/blanks/blank_title.png'
icon_state = ""
screen_loc = "1,1"
plane = SPLASHSCREEN_PLANE
Expand Down
87 changes: 87 additions & 0 deletions code/datums/cogbar.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#define COGBAR_ANIMATION_TIME 5 DECISECONDS

/**
* ### Cogbar
* Represents that the user is busy doing something.
*/
/datum/cogbar
/// Who's doing the thing
var/mob/user
/// The user client
var/client/user_client
/// The visible element to other players
var/obj/effect/overlay/vis/cog
/// The blank image that overlaps the cog - hides it from the source user
var/image/blank
/// The offset of the icon
var/offset_y


/datum/cogbar/New(mob/user)
src.user = user
src.user_client = user.client

var/list/icon_offsets = user.get_oversized_icon_offsets()
offset_y = icon_offsets["y"]

add_cog_to_user()

RegisterSignal(user, COMSIG_PARENT_QDELETING, PROC_REF(on_user_delete))


/datum/cogbar/Destroy()
if(user)
SSvis_overlays.remove_vis_overlay(user, user.managed_vis_overlays)
user_client?.images -= blank

user = null
user_client = null
cog = null
QDEL_NULL(blank)

return ..()


/// Adds the cog to the user, visible by other players
/datum/cogbar/proc/add_cog_to_user()
cog = SSvis_overlays.add_vis_overlay(user,
icon = 'icons/effects/progressbar.dmi',
iconstate = "cog",
plane = HIGH_GAME_PLANE,
add_appearance_flags = APPEARANCE_UI_IGNORE_ALPHA,
unique = TRUE,
alpha = 0,
)
cog.pixel_y = world.icon_size + offset_y
animate(cog, alpha = 255, time = COGBAR_ANIMATION_TIME)

if(isnull(user_client))
return

blank = image('icons/blanks/32x32.dmi', cog, "nothing")
blank.plane = HIGH_GAME_PLANE
blank.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA
blank.override = TRUE

user_client.images += blank


/// Removes the cog from the user
/datum/cogbar/proc/remove()
if(isnull(cog))
qdel(src)
return

animate(cog, alpha = 0, time = COGBAR_ANIMATION_TIME)

QDEL_IN(src, COGBAR_ANIMATION_TIME)


/// When the user is deleted, remove the cog
/datum/cogbar/proc/on_user_delete(datum/source)
SIGNAL_HANDLER

qdel(src)


#undef COGBAR_ANIMATION_TIME
3 changes: 3 additions & 0 deletions code/datums/components/butchering.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
Butcher(user, M)

/datum/component/butchering/proc/startNeckSlice(obj/item/source, mob/living/carbon/human/H, mob/living/user)
if(DOING_INTERACTION_WITH_TARGET(user, H))
to_chat(user, "<span class='warning'>You're already interacting with [H]!</span>")
return
user.visible_message("<span class='danger'>[user] is slitting [H]'s throat!</span>", \
"<span class='danger'>You start slicing [H]'s throat!</span>", \
"<span class='hear'>You hear a cutting noise!</span>")
Expand Down
Loading
Loading