From 8c0a11c25cb695fd5c193b1efabae0d6dcfa5382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Krupi=C5=84ski?= Date: Sat, 2 Nov 2024 11:44:45 +0100 Subject: [PATCH] Fix player bomb carrying / planting icon having its shadow cut Panorama has a bug which causes image shadow to be cut when wash-color style property is applied. As a workaround, svg fill color is set instead of wash-color. --- Source/CS2/Panorama/CImagePanel.h | 13 ++++++++++ .../PlayerInfoInWorldPanelFactory.h | 16 +++++++++---- .../PlayerStateIcons/PlayerBombIconPanel.h | 10 +++----- .../PlayerStateIconsPanelParams.h | 4 ++-- Source/GameClasses/PanoramaImagePanel.h | 24 +++++++++++++++++-- 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/Source/CS2/Panorama/CImagePanel.h b/Source/CS2/Panorama/CImagePanel.h index 41245ae1abe..e603cc3bda3 100644 --- a/Source/CS2/Panorama/CImagePanel.h +++ b/Source/CS2/Panorama/CImagePanel.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -8,11 +9,23 @@ namespace cs2 { +enum class SvgAttributeType { + FillColor = 0, + + Count = 11 +}; + +struct SvgAttribute { + std::byte value[4]; +}; + struct ImageProperties { PAD(16); int textureWidth; int textureHeight; float scale; + SvgAttribute svgAttributes[static_cast(SvgAttributeType::Count)]; + std::uint32_t presentSvgAttributes; }; struct CImagePanel : CPanel2D { diff --git a/Source/Features/Visuals/PlayerInfoInWorld/PlayerInfoInWorldPanelFactory.h b/Source/Features/Visuals/PlayerInfoInWorld/PlayerInfoInWorldPanelFactory.h index 1c134173981..ad6223fdde6 100644 --- a/Source/Features/Visuals/PlayerInfoInWorld/PlayerInfoInWorldPanelFactory.h +++ b/Source/Features/Visuals/PlayerInfoInWorld/PlayerInfoInWorldPanelFactory.h @@ -66,7 +66,7 @@ class PlayerInfoInWorldPanelFactory { createHostagePickupPanel(panel); createHostageRescuePanel(panel); createBlindedIconPanel(panel); - createBombIconPanel(panel); + createBombIconContainerPanel(panel); } void createPanel(std::type_identity>, cs2::CUIPanel* containerPanel) const noexcept @@ -176,17 +176,25 @@ class PlayerInfoInWorldPanelFactory { uiPanel.setImageShadow(kShadowParams); } - void createBombIconPanel(cs2::CUIPanel* containerPanel) const noexcept + void createBombIconContainerPanel(cs2::CUIPanel* parentPanel) const noexcept + { + using namespace player_state_icons_panel_params::bomb_icon_panel_params; + + auto&& containerPanel = hookContext.panelFactory().createPanel(parentPanel).uiPanel(); + createBombIconPanel(containerPanel, kColorCarryingC4); + createBombIconPanel(containerPanel, kColorPlantingC4); + } + + void createBombIconPanel(cs2::CUIPanel* containerPanel, cs2::Color color) const noexcept { using namespace player_state_icons_panel_params::bomb_icon_panel_params; auto&& imagePanel = hookContext.panelFactory().createImagePanel(containerPanel); - imagePanel.setImageSvg(kImageUrl, kTextureHeight); + imagePanel.setImageSvg(SvgImageParams{.imageUrl = kImageUrl, .textureHeight = kTextureHeight, .fillColor = color}); auto&& uiPanel = imagePanel.uiPanel(); uiPanel.setAlign(kAlignment); uiPanel.setImageShadow(kShadowParams); - uiPanel.setWashColor(kWashColorCarryingC4); } void createHealthIconPanel(cs2::CUIPanel* containerPanel) const diff --git a/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerBombIconPanel.h b/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerBombIconPanel.h index 10c24aa9fab..fcb53caa2ca 100644 --- a/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerBombIconPanel.h +++ b/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerBombIconPanel.h @@ -20,15 +20,11 @@ class PlayerBombIconPanel { } context.panel().setVisible(true); - context.panel().setWashColor(getColor(playerPawn)); + const auto shouldShowPlantingColor = context.shouldShowPlantingColor(playerPawn); + context.panel().children()[0].setVisible(!shouldShowPlantingColor); + context.panel().children()[1].setVisible(shouldShowPlantingColor); } private: - [[nodiscard]] auto getColor(auto&& playerPawn) const noexcept - { - using namespace player_state_icons_panel_params::bomb_icon_panel_params; - return context.shouldShowPlantingColor(playerPawn) ? kWashColorPlantingC4 : kWashColorCarryingC4; - } - Context context; }; diff --git a/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerStateIconsPanelParams.h b/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerStateIconsPanelParams.h index 4c7ebeb21a3..541a537e954 100644 --- a/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerStateIconsPanelParams.h +++ b/Source/Features/Visuals/PlayerInfoInWorld/PlayerStateIcons/PlayerStateIconsPanelParams.h @@ -72,8 +72,8 @@ namespace player_state_icons_panel_params::bomb_icon_panel_params static constexpr auto kAlignment = PanelAlignmentParams{ .verticalAlignment = cs2::k_EVerticalAlignmentCenter }; - static constexpr auto kWashColorCarryingC4 = cs2::Color{255, 255, 77}; - static constexpr auto kWashColorPlantingC4 = cs2::Color{255, 193, 77}; + static constexpr auto kColorCarryingC4 = cs2::Color{255, 255, 77}; + static constexpr auto kColorPlantingC4 = cs2::Color{255, 193, 77}; static constexpr auto kShadowParams = PanelShadowParams{ .horizontalOffset{cs2::CUILength::pixels(0)}, .verticalOffset{cs2::CUILength::pixels(0)}, diff --git a/Source/GameClasses/PanoramaImagePanel.h b/Source/GameClasses/PanoramaImagePanel.h index 05321e2ed7e..702525a224e 100644 --- a/Source/GameClasses/PanoramaImagePanel.h +++ b/Source/GameClasses/PanoramaImagePanel.h @@ -1,10 +1,19 @@ #pragma once +#include +#include + #include #include #include "PanoramaImagePanelContext.h" +struct SvgImageParams { + const char* imageUrl; + int textureHeight{-1}; + std::optional fillColor; +}; + template struct PanoramaImagePanel { explicit PanoramaImagePanel(Context context) noexcept @@ -36,6 +45,11 @@ struct PanoramaImagePanel { } void setImageSvg(const char* imageUrl, int textureHeight = -1) const noexcept + { + setImageSvg(SvgImageParams{.imageUrl = imageUrl, .textureHeight = textureHeight}); + } + + void setImageSvg(const SvgImageParams& params) const noexcept { if (context.panel == nullptr) return; @@ -45,9 +59,15 @@ struct PanoramaImagePanel { return; properties->scale = context.uiPanel().getUiScaleFactor().valueOr(1.0f); - properties->textureHeight = textureHeight; + properties->textureHeight = params.textureHeight; + + if (params.fillColor.has_value()) { + properties->svgAttributes[static_cast(cs2::SvgAttributeType::FillColor)] = std::bit_cast(*params.fillColor); + properties->presentSvgAttributes |= 1 << static_cast(cs2::SvgAttributeType::FillColor); + } + if (context.hookContext.clientPatternSearchResults().template get()) - context.hookContext.clientPatternSearchResults().template get()(context.panel, imageUrl, nullptr, properties); + context.hookContext.clientPatternSearchResults().template get()(context.panel, params.imageUrl, nullptr, properties); } private: