Skip to content

Commit

Permalink
click cooldown hud (#3461)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

A port of this pr
DaedalusDock/daedalusdock#732

Adds a bar to the bottom of the screen that shows click cooldown

https://github.com/user-attachments/assets/8824ba1a-2596-4dcf-ae16-2dafdd380666


<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game
I can tell when i can attack next
<!-- Please add a short description of why you think these changes would
benefit the game. If you can't justify it in words, it might not be
worth adding. -->

## Changelog

:cl: FalloutFalcon, Kapu1178
add: New bar above your items to show your attack cooldown
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

Co-authored-by: Sun-Soaked <[email protected]>
  • Loading branch information
FalloutFalcon and Sun-Soaked authored Nov 3, 2024
1 parent 39a673e commit 8aa89a3
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 0 deletions.
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

0 comments on commit 8aa89a3

Please sign in to comment.