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

click cooldown hud #3461

Merged
merged 2 commits into from
Nov 3, 2024
Merged
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
3 changes: 3 additions & 0 deletions code/__DEFINES/dcs/signals/signals_mob/signals_mob_carbon.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// from base of [/mob/living/changeNext_Move()] (next_move)
#define COMSIG_LIVING_CHANGENEXT_MOVE "living_changenext_move"

///Called from /mob/living/carbon/help_shake_act, before any hugs have ocurred. (mob/living/helper)
#define COMSIG_CARBON_PRE_HELP_ACT "carbon_pre_help"
/// Stops the rest of help act (hugging, etc) from occuring
Expand Down
2 changes: 2 additions & 0 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
adj += S.nextmove_adjust()
next_move = world.time + ((num + adj)*mod)

SEND_SIGNAL(src, COMSIG_LIVING_CHANGENEXT_MOVE, next_move)

/**
* Before anything else, defer these calls to a per-mobtype handler. This allows us to
* remove istype() spaghetti code, but requires the addition of other handler procs to simplify it.
Expand Down
3 changes: 3 additions & 0 deletions code/_onclick/hud/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ GLOBAL_LIST_INIT(available_ui_styles, list(
var/atom/movable/screen/healths
var/atom/movable/screen/healthdoll
var/atom/movable/screen/internals

var/atom/movable/screen/progbar_container/use_timer
// subtypes can override this to force a specific UI style
var/ui_style

Expand Down Expand Up @@ -117,6 +119,7 @@ GLOBAL_LIST_INIT(available_ui_styles, list(
QDEL_LIST(screenoverlays)
mymob = null
QDEL_NULL(screentip_text)
QDEL_NULL(use_timer)

return ..()

Expand Down
4 changes: 4 additions & 0 deletions code/_onclick/hud/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@
ammo_counter = new /atom/movable/screen/ammo_counter(null, src)
infodisplay += ammo_counter

use_timer = new(null, src)
use_timer.RegisterSignal(mymob, COMSIG_LIVING_CHANGENEXT_MOVE, TYPE_PROC_REF(/atom/movable/screen/progbar_container, on_changenext))
static_inventory += use_timer

for(var/atom/movable/screen/inventory/inv in (static_inventory + toggleable_inventory))
if(inv.slot_id)
inv.hud = src
Expand Down
39 changes: 39 additions & 0 deletions code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -711,3 +711,42 @@
intent_icon.pixel_x = 16 * (i - 1) - 8 * length(streak)
add_overlay(intent_icon)
return ..()

/atom/movable/screen/progbar_container
name = "swing cooldown"
icon_state = ""
screen_loc = "CENTER,SOUTH:16"
var/datum/world_progressbar/progbar
var/iteration = 0

/atom/movable/screen/progbar_container/Initialize(mapload)
. = ..()
progbar = new(src)
progbar.qdel_when_done = FALSE
progbar.bar.vis_flags = VIS_INHERIT_ID | VIS_INHERIT_LAYER | VIS_INHERIT_PLANE
progbar.bar.appearance_flags = APPEARANCE_UI

/atom/movable/screen/progbar_container/Destroy()
QDEL_NULL(progbar)
return ..()

/atom/movable/screen/progbar_container/proc/on_changenext(datum/source, next_move)
SIGNAL_HANDLER

iteration++
progbar.goal = next_move - world.time
progbar.bar.icon_state = "prog_bar_0"

progbar_process(next_move)

/atom/movable/screen/progbar_container/proc/progbar_process(next_move)
set waitfor = FALSE

var/start_time = world.time
var/iteration = src.iteration
while(iteration == src.iteration && (world.time < next_move))
progbar.update(world.time - start_time)
sleep(1)

if(iteration == src.iteration)
progbar.end_progress()
79 changes: 79 additions & 0 deletions code/datums/progressbar.dm
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,84 @@
/datum/progressbar/dump_harddel_info()
return "Owner's type: [location_type]"


/datum/world_progressbar
///The progress bar visual element.
var/obj/effect/abstract/progbar/bar
///The atom who "created" the bar
var/atom/movable/owner
///Effectively the number of steps the progress bar will need to do before reaching completion.
var/goal = 1
///Control check to see if the progress was interrupted before reaching its goal.
var/last_progress = 0
///Variable to ensure smooth visual stacking on multiple progress bars.
var/listindex = 0
///Does this qdelete on completion?
var/qdel_when_done = TRUE

/datum/world_progressbar/New(atom/movable/_owner, _goal, image/underlay)
if(!_owner)
return

owner = _owner
goal = _goal

bar = new()

if(underlay)
if(!istype(underlay))
underlay = image(underlay, dir = SOUTH)
underlay.filters += filter(type = "outline", size = 1)

underlay.pixel_y += 2
underlay.alpha = 200
underlay.plane = GAME_PLANE
underlay.layer = FLY_LAYER
underlay.appearance_flags = APPEARANCE_UI
bar.underlays += underlay

owner:vis_contents += bar

animate(bar, alpha = 255, time = PROGRESSBAR_ANIMATION_TIME, easing = SINE_EASING)

RegisterSignal(owner, COMSIG_PARENT_QDELETING, PROC_REF(owner_delete))

/datum/world_progressbar/Destroy()
owner = null
QDEL_NULL(bar)
return ..()


/datum/world_progressbar/proc/owner_delete()
qdel(src)

///Updates the progress bar image visually.
/datum/world_progressbar/proc/update(progress)
progress = clamp(progress, 0, goal)
if(progress == last_progress)
return
last_progress = progress
bar.icon_state = "prog_bar_[round(((progress / goal) * 100), 5)]"

/datum/world_progressbar/proc/end_progress()
if(last_progress != goal)
bar.icon_state = "[bar.icon_state]_fail"

if(qdel_when_done)
animate(bar, alpha = 0, time = PROGRESSBAR_ANIMATION_TIME)
QDEL_IN(src, PROGRESSBAR_ANIMATION_TIME)
else
bar.icon_state = "prog_bar_0"

#undef PROGRESSBAR_ANIMATION_TIME
#undef PROGRESSBAR_HEIGHT

/obj/effect/abstract/progbar
icon = 'icons/effects/progressbar.dmi'
icon_state = "prog_bar_0"
plane = ABOVE_HUD_PLANE
appearance_flags = APPEARANCE_UI | KEEP_APART
pixel_y = 32
alpha = 0
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
vis_flags = NONE //We don't want VIS_INHERIT_PLANE
Loading