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

Implement weapon reload sound visualization #4200

Merged
merged 1 commit into from
Dec 6, 2023
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
2 changes: 2 additions & 0 deletions Source/CS2/Constants/SoundNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
1 change: 1 addition & 0 deletions Source/FeatureHelpers/HudInWorldPanelZOrder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum class HudInWorldPanelZOrder {
Footstep,
BombBeep,
WeaponScope,
WeaponReload,
BombPlant,
BombDefuse
};
4 changes: 3 additions & 1 deletion Source/FeatureHelpers/Sound/SoundWatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include "BombPlantSound.h"
#include "FootstepSound.h"
#include "SoundWatcherImpl.h"
#include "WeaponReloadSound.h"
#include "WeaponScopeSound.h"

using SoundWatcher = SoundWatcherImpl<
FootstepSound,
BombPlantSound,
BombBeepSound,
BombDefuseSound,
WeaponScopeSound
WeaponScopeSound,
WeaponReloadSound
>;
18 changes: 18 additions & 0 deletions Source/FeatureHelpers/Sound/WeaponReloadSound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <algorithm>
#include <cassert>
#include <string_view>

#include <CS2/Constants/SoundNames.h>

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));
}
};
4 changes: 4 additions & 0 deletions Source/Features/Sound/SoundFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "BombDefuseVisualizer.h"
#include "BombPlantVisualizer.h"
#include "FootstepVisualizer.h"
#include "WeaponReloadVisualizer.h"
#include "WeaponScopeVisualizer.h"
#include <Hooks/ViewRenderHook.h>

Expand All @@ -14,6 +15,7 @@ struct SoundFeatures {
, bombBeepVisualizer{ viewRenderHook, soundWatcher }
, bombDefuseVisualizer{ viewRenderHook, soundWatcher }
, weaponScopeVisualizer{ viewRenderHook, soundWatcher }
, weaponReloadVisualizer{ viewRenderHook, soundWatcher }
{
}

Expand All @@ -24,11 +26,13 @@ struct SoundFeatures {
bombBeepVisualizer.run(soundVisualizationHelpers);
bombDefuseVisualizer.run(soundVisualizationHelpers);
weaponScopeVisualizer.run(soundVisualizationHelpers);
weaponReloadVisualizer.run(soundVisualizationHelpers);
}

FootstepVisualizer footstepVisualizer;
BombPlantVisualizer bombPlantVisualizer;
BombBeepVisualizer bombBeepVisualizer;
BombDefuseVisualizer bombDefuseVisualizer;
WeaponScopeVisualizer weaponScopeVisualizer;
WeaponReloadVisualizer weaponReloadVisualizer;
};
37 changes: 37 additions & 0 deletions Source/Features/Sound/WeaponReloadVisualizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <CS2/Classes/Panorama.h>
#include <FeatureHelpers/HudInWorldPanelFactory.h>
#include <FeatureHelpers/HudInWorldPanelZOrder.h>
#include <FeatureHelpers/Sound/WeaponReloadSound.h>
#include <FeatureHelpers/Sound/SoundVisualizationFeature.h>
#include <GameClasses/PanoramaUiEngine.h>

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<WeaponReloadPanels, WeaponReloadSound>;
3 changes: 2 additions & 1 deletion Source/UI/Panorama/CreateGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
})();
Expand Down
2 changes: 2 additions & 0 deletions Source/UI/Panorama/SetCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down