From 672780f1a4ec1e07c0ad6da8e3d225262de428cb Mon Sep 17 00:00:00 2001 From: mac-tf2 Date: Mon, 8 Apr 2024 17:44:44 +0100 Subject: [PATCH] feat: added timers for defrag powerups --- images/hud/damageboost.svg | 4 ++++ images/hud/haste.svg | 4 ++++ layout/hud/hud.xml | 1 + layout/hud/powerup-timer.xml | 25 +++++++++++++++++++++ scripts/hud/powerup-timer.js | 35 +++++++++++++++++++++++++++++ scripts/util/panel-registration.js | 1 + styles/hud/_index.scss | 1 + styles/hud/powerup-timer.scss | 36 ++++++++++++++++++++++++++++++ 8 files changed, 107 insertions(+) create mode 100644 images/hud/damageboost.svg create mode 100644 images/hud/haste.svg create mode 100644 layout/hud/powerup-timer.xml create mode 100644 scripts/hud/powerup-timer.js create mode 100644 styles/hud/powerup-timer.scss diff --git a/images/hud/damageboost.svg b/images/hud/damageboost.svg new file mode 100644 index 00000000..75c3a4ae --- /dev/null +++ b/images/hud/damageboost.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/images/hud/haste.svg b/images/hud/haste.svg new file mode 100644 index 00000000..108dd613 --- /dev/null +++ b/images/hud/haste.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/layout/hud/hud.xml b/layout/hud/hud.xml index 694ce0b2..37601d8a 100644 --- a/layout/hud/hud.xml +++ b/layout/hud/hud.xml @@ -44,6 +44,7 @@ + diff --git a/layout/hud/powerup-timer.xml b/layout/hud/powerup-timer.xml new file mode 100644 index 00000000..88a85f78 --- /dev/null +++ b/layout/hud/powerup-timer.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/hud/powerup-timer.js b/scripts/hud/powerup-timer.js new file mode 100644 index 00000000..20a47f4f --- /dev/null +++ b/scripts/hud/powerup-timer.js @@ -0,0 +1,35 @@ +class PowerupTimer { + static panels = { + panelDamageBoost: $('#DamageBoostTimer'), + labelDamageBoost: $('#DamageBoostLabel'), + panelHaste: $('#HasteTimer'), + labelHaste: $('#HasteLabel'), + panelSlick: $('#SlickTimer'), + labelSlick: $('#SlickLabel') + }; + + static onUpdate() { + const { damageBoostTime, hasteTime, slickTime } = MomentumMovementAPI.GetLastMoveData(); + if (!damageBoostTime) { + this.panels.panelDamageBoost.visible = false; + } else { + this.panels.labelDamageBoost.text = damageBoostTime < 0 ? '∞' : Math.ceil(damageBoostTime / 1000); + this.panels.panelDamageBoost.visible = true; + } + if (!hasteTime) { + this.panels.panelHaste.visible = false; + } else { + this.panels.labelHaste.text = hasteTime < 0 ? '∞' : Math.ceil(hasteTime / 1000); + this.panels.panelHaste.visible = true; + } + if (!slickTime) { + this.panels.panelSlick.visible = false; + } else { + this.panels.labelSlick.text = slickTime < 0 ? '∞' : Math.ceil(slickTime / 1000); + this.panels.panelSlick.visible = true; + } + } + static { + RegisterEventForGamemodes([GameMode.DEFRAG], 'HudProcessInput', $.GetContextPanel(), this.onUpdate.bind(this)); + } +} diff --git a/scripts/util/panel-registration.js b/scripts/util/panel-registration.js index 79ce3332..d9d24b11 100644 --- a/scripts/util/panel-registration.js +++ b/scripts/util/panel-registration.js @@ -17,6 +17,7 @@ UiToolkitAPI.RegisterHUDPanel2d('MomHudDFJump', 'file://{resources}/layout/hud/d UiToolkitAPI.RegisterHUDPanel2d('MomHudJumpStats', 'file://{resources}/layout/hud/jump-stats.xml'); UiToolkitAPI.RegisterHUDPanel2d('MomHudSpecInfo', 'file://{resources}/layout/hud/spec-info.xml'); UiToolkitAPI.RegisterHUDPanel2d('MomHudSynchronizer', 'file://{resources}/layout/hud/synchronizer.xml'); +UiToolkitAPI.RegisterHUDPanel2d('MomHudPowerupTimer', 'file://{resources}/layout/hud/powerup-timer.xml'); UiToolkitAPI.RegisterPanel2d('ToastManager', 'file://{resources}/layout/util/toast-manager.xml'); UiToolkitAPI.RegisterPanel2d('ToastGeneric', 'file://{resources}/layout/modals/toasts/generic.xml'); diff --git a/styles/hud/_index.scss b/styles/hud/_index.scss index 9dac36db..a6b0a5c7 100644 --- a/styles/hud/_index.scss +++ b/styles/hud/_index.scss @@ -18,6 +18,7 @@ @use 'jump-stats'; @use 'key-press'; @use 'map-info'; +@use 'powerup-timer'; @use 'replay-controls'; @use 'show-pos'; @use 'spec-info'; diff --git a/styles/hud/powerup-timer.scss b/styles/hud/powerup-timer.scss new file mode 100644 index 00000000..7d8cbd45 --- /dev/null +++ b/styles/hud/powerup-timer.scss @@ -0,0 +1,36 @@ +@use '../config' as *; +@use '../abstract/mixin'; + +.powerup-timer { + margin: 10px; + flow-children: down; + padding-left: 16px; + + &__item { + flow-children: right; + } + + &__label { + @include mixin.font-styles($use-header: true); + font-size: 64px; + padding-left: 16px; + horizontal-align: left; + vertical-align: center; + text-overflow: ellipsis; + color: $white; + } + + &__icon { + vertical-align: center; + height: 50px; + width: 50px; + + &--haste { + wash-color: #ec931f; + } + + &--damageboost { + wash-color: #1896d3ff; + } + } +}