From 29d10f42cf037c39b3933a052614c90f7c0b7379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Krupi=C5=84ski?= Date: Wed, 6 Dec 2023 22:01:50 +0100 Subject: [PATCH] Implement weapon reload sound visualization (#4200) --- Source/CS2/Constants/SoundNames.h | 2 + Source/FeatureHelpers/HudInWorldPanelZOrder.h | 1 + Source/FeatureHelpers/Sound/SoundWatcher.h | 4 +- .../FeatureHelpers/Sound/WeaponReloadSound.h | 18 +++++++++ Source/Features/Sound/SoundFeatures.h | 4 ++ .../Features/Sound/WeaponReloadVisualizer.h | 37 +++++++++++++++++++ Source/UI/Panorama/CreateGUI.js | 3 +- Source/UI/Panorama/SetCommandHandler.h | 2 + 8 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 Source/FeatureHelpers/Sound/WeaponReloadSound.h create mode 100644 Source/Features/Sound/WeaponReloadVisualizer.h diff --git a/Source/CS2/Constants/SoundNames.h b/Source/CS2/Constants/SoundNames.h index 0f629b7c365..1bc244d6c77 100644 --- a/Source/CS2/Constants/SoundNames.h +++ b/Source/CS2/Constants/SoundNames.h @@ -23,5 +23,7 @@ constexpr std::string_view kZoomSoundNamePart = "zoom"; constexpr std::string_view kPlayerSuitSoundPrefix = "suit"; constexpr std::string_view kBombBeepSoundsPrefix = "c4_beep"; constexpr std::string_view kBombDefuseStartSoundName = "c4_disarmstart.vsnd"; +constexpr std::string_view kClipOutSoundSuffix = "clipout.vsnd"; +constexpr std::string_view kCoverUpSoundSuffix = "coverup.vsnd"; } diff --git a/Source/FeatureHelpers/HudInWorldPanelZOrder.h b/Source/FeatureHelpers/HudInWorldPanelZOrder.h index 799ff39f46a..40114e92e6b 100644 --- a/Source/FeatureHelpers/HudInWorldPanelZOrder.h +++ b/Source/FeatureHelpers/HudInWorldPanelZOrder.h @@ -4,6 +4,7 @@ enum class HudInWorldPanelZOrder { Footstep, BombBeep, WeaponScope, + WeaponReload, BombPlant, BombDefuse }; diff --git a/Source/FeatureHelpers/Sound/SoundWatcher.h b/Source/FeatureHelpers/Sound/SoundWatcher.h index 04a5f330814..a9cfd12c4c5 100644 --- a/Source/FeatureHelpers/Sound/SoundWatcher.h +++ b/Source/FeatureHelpers/Sound/SoundWatcher.h @@ -5,6 +5,7 @@ #include "BombPlantSound.h" #include "FootstepSound.h" #include "SoundWatcherImpl.h" +#include "WeaponReloadSound.h" #include "WeaponScopeSound.h" using SoundWatcher = SoundWatcherImpl< @@ -12,5 +13,6 @@ using SoundWatcher = SoundWatcherImpl< BombPlantSound, BombBeepSound, BombDefuseSound, - WeaponScopeSound + WeaponScopeSound, + WeaponReloadSound >; diff --git a/Source/FeatureHelpers/Sound/WeaponReloadSound.h b/Source/FeatureHelpers/Sound/WeaponReloadSound.h new file mode 100644 index 00000000000..c3c62d902bc --- /dev/null +++ b/Source/FeatureHelpers/Sound/WeaponReloadSound.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +#include + +struct WeaponReloadSound { + static constexpr auto kFadeAwayStart = 1.8f; + static constexpr auto kFadeAwayDuration = 0.8f; + static constexpr auto kMinScale = 0.5f; + + [[nodiscard]] static constexpr bool isSound(std::string_view soundName) noexcept + { + return soundName.starts_with(cs2::kWeaponSoundsPath) && (soundName.ends_with(cs2::kClipOutSoundSuffix) || soundName.ends_with(cs2::kCoverUpSoundSuffix)); + } +}; diff --git a/Source/Features/Sound/SoundFeatures.h b/Source/Features/Sound/SoundFeatures.h index c05e6ef22ae..c591fba5225 100644 --- a/Source/Features/Sound/SoundFeatures.h +++ b/Source/Features/Sound/SoundFeatures.h @@ -4,6 +4,7 @@ #include "BombDefuseVisualizer.h" #include "BombPlantVisualizer.h" #include "FootstepVisualizer.h" +#include "WeaponReloadVisualizer.h" #include "WeaponScopeVisualizer.h" #include @@ -14,6 +15,7 @@ struct SoundFeatures { , bombBeepVisualizer{ viewRenderHook, soundWatcher } , bombDefuseVisualizer{ viewRenderHook, soundWatcher } , weaponScopeVisualizer{ viewRenderHook, soundWatcher } + , weaponReloadVisualizer{ viewRenderHook, soundWatcher } { } @@ -24,6 +26,7 @@ struct SoundFeatures { bombBeepVisualizer.run(soundVisualizationHelpers); bombDefuseVisualizer.run(soundVisualizationHelpers); weaponScopeVisualizer.run(soundVisualizationHelpers); + weaponReloadVisualizer.run(soundVisualizationHelpers); } FootstepVisualizer footstepVisualizer; @@ -31,4 +34,5 @@ struct SoundFeatures { BombBeepVisualizer bombBeepVisualizer; BombDefuseVisualizer bombDefuseVisualizer; WeaponScopeVisualizer weaponScopeVisualizer; + WeaponReloadVisualizer weaponReloadVisualizer; }; diff --git a/Source/Features/Sound/WeaponReloadVisualizer.h b/Source/Features/Sound/WeaponReloadVisualizer.h new file mode 100644 index 00000000000..fe87d762a81 --- /dev/null +++ b/Source/Features/Sound/WeaponReloadVisualizer.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +struct WeaponReloadPanels { + [[nodiscard]] static cs2::CPanel2D* createContainerPanel(const HudInWorldPanelFactory& inWorldFactory) noexcept + { + return inWorldFactory.createPanel("WeaponReloadContainer", HudInWorldPanelZOrder::WeaponReload); + } + + static void createContentPanels(cs2::CUIPanel& containerPanel) noexcept + { + for (std::size_t i = 0; i < kMaxNumberOfPanels; ++i) { + PanoramaUiEngine::runScript(&containerPanel, + R"( +(function() { +var weaponReloadPanel = $.CreatePanel('Panel', $.GetContextPanel().FindChildInLayoutFile("WeaponReloadContainer"), '', { + style: 'width: 100px; height: 100px; x: -50px; y: -50px;' +}); + +$.CreatePanel('Image', weaponReloadPanel, '', { + src: "s2r://panorama/images/icons/ui/switch_teams_dead.svg", + style: "horizontal-align: center; vertical-align: center; img-shadow: 0px 0px 1px 3 #000000;" +}); +})();)", "", 0); + } + } + + static constexpr auto kMaxNumberOfPanels = 10; +}; + +using WeaponReloadVisualizer = SoundVisualizationFeature; diff --git a/Source/UI/Panorama/CreateGUI.js b/Source/UI/Panorama/CreateGUI.js index eb4e3e33a3e..24e5285a3e2 100644 --- a/Source/UI/Panorama/CreateGUI.js +++ b/Source/UI/Panorama/CreateGUI.js @@ -213,8 +213,9 @@ $.Osiris = (function () { createYesNoDropDown(bombSoundVisualization, "Visualize Bomb Defuse", 'sound', 'visualize_bomb_defuse'); var weaponSoundVisualization = createSection(sound, 'Weapon Sound Visualization'); - $.CreatePanel('Panel', weaponSoundVisualization, '', { class: "horizontal-separator" }); createYesNoDropDown(weaponSoundVisualization, "Visualize Weapon Scope Sound", 'sound', 'visualize_scope_sound'); + $.CreatePanel('Panel', weaponSoundVisualization, '', { class: "horizontal-separator" }); + createYesNoDropDown(weaponSoundVisualization, "Visualize Weapon Reload Sound", 'sound', 'visualize_reload_sound'); $.Osiris.navigateToTab('hud'); })(); diff --git a/Source/UI/Panorama/SetCommandHandler.h b/Source/UI/Panorama/SetCommandHandler.h index c79961fa1de..c537ea8d61e 100644 --- a/Source/UI/Panorama/SetCommandHandler.h +++ b/Source/UI/Panorama/SetCommandHandler.h @@ -45,6 +45,8 @@ struct SetCommandHandler { handleTogglableFeature(features.soundFeatures.bombDefuseVisualizer); } else if (feature == "visualize_scope_sound") { handleTogglableFeature(features.soundFeatures.weaponScopeVisualizer); + } else if (feature == "visualize_reload_sound") { + handleTogglableFeature(features.soundFeatures.weaponReloadVisualizer); } }