Skip to content

Commit

Permalink
Move player bomb carrying/planting icon next to the active weapon icon
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Nov 2, 2024
1 parent 8c0a11c commit c8b56ca
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 104 deletions.
31 changes: 29 additions & 2 deletions Source/Features/Visuals/PlayerInfoInWorld/PlayerInfoInWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,35 @@ struct PlayerActiveWeaponAmmoToggle : public FeatureToggle<PlayerActiveWeaponAmm
PlayerInfoInWorldState& state;
};

struct BombIconToggle : public FeatureToggle<BombIconToggle> {
explicit BombIconToggle(PlayerInfoInWorldState& state) noexcept
: state{state}
{
}

[[nodiscard]] auto& enabledVariable(ToggleMethod) const noexcept
{
return state.showBombCarrierIcon;
}

PlayerInfoInWorldState& state;
};

struct BombPlantingIconToggle : public FeatureToggle<BombPlantingIconToggle> {
explicit BombPlantingIconToggle(PlayerInfoInWorldState& state) noexcept
: state{state}
{
}

[[nodiscard]] auto& enabledVariable(ToggleMethod) const noexcept
{
return state.showBombPlantingIcon;
}

PlayerInfoInWorldState& state;
};


template <typename IconPanel>
struct PlayerStateIconToggle {
explicit PlayerStateIconToggle(PlayerStateIconsToShow& playerStateIconsToShow) noexcept
Expand All @@ -138,8 +167,6 @@ using PlayerDefuseIconToggle = PlayerStateIconToggle<DefuseIconPanel>;
using HostagePickupIconToggle = PlayerStateIconToggle<HostagePickupPanel>;
using HostageRescueIconToggle = PlayerStateIconToggle<HostageRescuePanel>;
using BlindedIconToggle = PlayerStateIconToggle<BlindedIconPanel>;
using BombIconToggle = PlayerStateIconToggle<BombIconPanel>;
using BombPlantingIconToggle = PlayerStateIconToggle<BombPlantingIcon>;

template <typename HookContext>
struct PlayerInfoInWorldToggle : FeatureToggleOnOff<PlayerInfoInWorldToggle<HookContext>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include <GameClasses/PanelFactory.h>

#include "ActiveWeaponAmmo/ActiveWeaponAmmoPanelParams.h"
#include "ActiveWeaponIcon/ActiveWeaponIconPanelParams.h"
#include "PlayerHealth/PlayerHealthPanelParams.h"
#include "PlayerInfoContainerPanelParams.h"
#include "PlayerPositionArrow/PlayerPositionArrowPanelParams.h"
#include "PlayerStateIcons/PlayerStateIconsPanelParams.h"
#include "PlayerWeaponIcon/ActiveWeaponIcon/ActiveWeaponIconPanelParams.h"
#include "PlayerWeaponIcon/BombIcon/PlayerBombIconPanelParams.h"
#include "PlayerWeaponIcon/PlayerWeaponIconPanelParams.h"

template <typename HookContext>
class PlayerInfoInWorldPanelFactory {
Expand Down Expand Up @@ -66,17 +68,19 @@ class PlayerInfoInWorldPanelFactory {
createHostagePickupPanel(panel);
createHostageRescuePanel(panel);
createBlindedIconPanel(panel);
createBombIconContainerPanel(panel);
}

void createPanel(std::type_identity<PlayerActiveWeaponIconPanel<HookContext>>, cs2::CUIPanel* containerPanel) const noexcept
void createPanel(std::type_identity<PlayerWeaponIconPanel<HookContext>>, cs2::CUIPanel* parentPanel) const noexcept
{
using namespace active_weapon_icon_panel_params;
using namespace player_weapon_icon_panel_params;

auto&& panel = hookContext.panelFactory().createImagePanel(containerPanel).uiPanel();
panel.setAlign(kAlignment);
panel.setMargin(kMargin);
panel.setImageShadow(kShadowParams);
auto&& containerPanel = hookContext.panelFactory().createPanel(parentPanel).uiPanel();
containerPanel.setFlowChildren(kChildrenFlow);
containerPanel.setAlign(kAlignment);
containerPanel.setMargin(kMargin);

createPlayerActiveWeaponIconPanel(containerPanel);
createBombIconContainerPanel(containerPanel);
}

void createPanel(std::type_identity<PlayerHealthPanel<HookContext>>, cs2::CUIPanel* containerPanel) const noexcept
Expand Down Expand Up @@ -178,23 +182,23 @@ class PlayerInfoInWorldPanelFactory {

void createBombIconContainerPanel(cs2::CUIPanel* parentPanel) const noexcept
{
using namespace player_state_icons_panel_params::bomb_icon_panel_params;
using namespace player_bomb_icon_panel_params::container_panel_params;

auto&& containerPanel = hookContext.panelFactory().createPanel(parentPanel).uiPanel();
containerPanel.setAlign(kAlignment);
containerPanel.setMargin(kMargin);

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;
using namespace player_bomb_icon_panel_params::bomb_icon_panel_params;

auto&& imagePanel = hookContext.panelFactory().createImagePanel(containerPanel);
imagePanel.setImageSvg(SvgImageParams{.imageUrl = kImageUrl, .textureHeight = kTextureHeight, .fillColor = color});

auto&& uiPanel = imagePanel.uiPanel();
uiPanel.setAlign(kAlignment);
uiPanel.setImageShadow(kShadowParams);
imagePanel.uiPanel().setImageShadow(kShadowParams);
}

void createHealthIconPanel(cs2::CUIPanel* containerPanel) const
Expand All @@ -220,5 +224,14 @@ class PlayerInfoInWorldPanelFactory {
label.setTextShadow(kShadowParams);
}

void createPlayerActiveWeaponIconPanel(cs2::CUIPanel* parentPanel) const noexcept
{
using namespace active_weapon_icon_panel_params;

auto&& panel = hookContext.panelFactory().createImagePanel(parentPanel).uiPanel();
panel.setAlign(kAlignment);
panel.setImageShadow(kShadowParams);
}

HookContext& hookContext;
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ struct PlayerInfoInWorldState {
bool showPlayerHealth{true};
PlayerHealthTextColor playerHealthTextColor{PlayerHealthTextColor::HealthBased};
bool showPlayerActiveWeapon{true};
bool showBombCarrierIcon{true};
bool showBombPlantingIcon{true};
bool showPlayerActiveWeaponAmmo{true};
PlayerStateIconsToShow playerStateIconsToShow{
PlayerStateIconsToShow{}
.set<DefuseIconPanel>()
.set<HostagePickupPanel>()
.set<HostageRescuePanel>()
.set<BlindedIconPanel>()
.set<BombIconPanel>()
.set<BombPlantingIcon>()};
.set<BlindedIconPanel>()};

cs2::PanelHandle containerPanelHandle;
DynamicArray<HudInWorldPanelIndex> panelIndices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include <tuple>

#include "ActiveWeaponAmmo/PlayerActiveWeaponAmmoPanel.h"
#include "ActiveWeaponIcon/PlayerActiveWeaponIconPanel.h"
#include "PlayerHealth/PlayerHealthPanel.h"
#include "PlayerPositionArrow/PlayerPositionArrowPanel.h"
#include "PlayerStateIcons/PlayerStateIconsPanel.h"
#include "PlayerWeaponIcon/PlayerWeaponIconPanel.h"

template <typename HookContext>
using PlayerInfoPanelTypes = std::tuple<
PlayerPositionArrowPanel<HookContext>,
PlayerHealthPanel<HookContext>,
PlayerActiveWeaponIconPanel<HookContext>,
PlayerWeaponIconPanel<HookContext>,
PlayerActiveWeaponAmmoPanel<HookContext>,
PlayerStateIconsPanel<HookContext>>;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PlayerStateIconsPanel {
playerStateChildren[1].setVisible(context.state().playerStateIconsToShow.template has<HostagePickupPanel>() && playerPawn.isPickingUpHostage().valueOr(false));
playerStateChildren[2].setVisible(context.state().playerStateIconsToShow.template has<HostageRescuePanel>() && playerPawn.isRescuingHostage());
updateBlindedIconPanel(playerStateChildren[3], playerPawn);
context.bombIconPanel().update(playerPawn);
// context.bombIconPanel().update(playerPawn);
}

private:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <GameClasses/PanoramaUiPanel.h>
#include "PlayerBombIconPanel.h"

template <typename HookContext>
class PlayerStateIconsPanelContext {
Expand All @@ -22,11 +21,6 @@ class PlayerStateIconsPanelContext {
return _hookContext.template make<PanoramaUiPanel>(_panel);
}

[[nodiscard]] decltype(auto) bombIconPanel() const noexcept
{
return _hookContext.template make<PlayerBombIconPanel<HookContext>>(panel().children()[4]);
}

private:
HookContext& _hookContext;
cs2::CUIPanel* _panel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,3 @@ namespace player_state_icons_panel_params::blinded_icon_panel_params
.color{cs2::kColorBlack}
};
}

namespace player_state_icons_panel_params::bomb_icon_panel_params
{
static constexpr auto kImageUrl = "s2r://panorama/images/icons/equipment/c4.svg";
static constexpr auto kTextureHeight = 24;
static constexpr auto kAlignment = PanelAlignmentParams{
.verticalAlignment = cs2::k_EVerticalAlignmentCenter
};
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)},
.blurRadius{cs2::CUILength::pixels(3)},
.strength = 3,
.color{cs2::kColorBlack}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ struct DefuseIconPanel;
struct HostagePickupPanel;
struct HostageRescuePanel;
struct BlindedIconPanel;
struct BombIconPanel;
struct BombPlantingIcon;

using PlayerStateIconsToShow = TypeBitFlags<DefuseIconPanel, HostagePickupPanel, HostageRescuePanel, BlindedIconPanel, BombIconPanel, BombPlantingIcon>;
using PlayerStateIconsToShow = TypeBitFlags<DefuseIconPanel, HostagePickupPanel, HostageRescuePanel, BlindedIconPanel>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
namespace active_weapon_icon_panel_params
{
static constexpr auto kAlignment = PanelAlignmentParams{
.horizontalAlignment = cs2::k_EHorizontalAlignmentCenter,
.verticalAlignment = cs2::k_EVerticalAlignmentTop
.verticalAlignment = cs2::k_EVerticalAlignmentCenter
};
static constexpr auto kMargin = PanelMarginParams{.marginTop = cs2::CUILength::pixels(3)};
static constexpr auto kMargin = PanelMarginParams{.marginLeft = cs2::CUILength::pixels(2.5), .marginRight = cs2::CUILength::pixels(2.5)};
static constexpr auto kShadowParams = PanelShadowParams{
.horizontalOffset{cs2::CUILength::pixels(0)},
.verticalOffset{cs2::CUILength::pixels(0)},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <Common/Visibility.h>
#include "PlayerActiveWeaponIconPanelContext.h"

template <typename HookContext, typename Context = PlayerActiveWeaponIconPanelContext<HookContext>>
Expand All @@ -11,9 +12,9 @@ class PlayerActiveWeaponIconPanel {
{
}

void update(auto&& playerPawn) const noexcept
void update(auto&& playerPawn, Visibility bombIconVisibility) const noexcept
{
if (!context.state().showPlayerActiveWeapon) {
if (!context.state().showPlayerActiveWeapon || (bombIconVisibility == Visibility::Visible && playerPawn.getActiveWeapon().is<C4>())) {
context.panel().setVisible(false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Common/Visibility.h>
#include "PlayerBombIconPanelContext.h"
#include "PlayerStateIconsPanelParams.h"

template <typename HookContext, typename Context = PlayerBombIconPanelContext<HookContext>>
class PlayerBombIconPanel {
Expand All @@ -12,17 +12,18 @@ class PlayerBombIconPanel {
{
}

void update(auto&& playerPawn) const noexcept
[[nodiscard]] Visibility update(auto&& playerPawn) const noexcept
{
if (!context.shouldShowOnPlayer(playerPawn)) {
context.panel().setVisible(false);
return;
return Visibility::Hidden;
}

context.panel().setVisible(true);
const auto shouldShowPlantingColor = context.shouldShowPlantingColor(playerPawn);
context.panel().children()[0].setVisible(!shouldShowPlantingColor);
context.panel().children()[1].setVisible(shouldShowPlantingColor);
return Visibility::Visible;
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <CS2/Panorama/CUIPanel.h>
#include <GameClasses/PanoramaUiPanel.h>

#include "PlayerStateIconsToShow.h"

template <typename HookContext>
class PlayerBombIconPanelContext {
public:
Expand All @@ -16,16 +14,16 @@ class PlayerBombIconPanelContext {

[[nodiscard]] bool shouldShowOnPlayer(auto&& playerPawn) const noexcept
{
if (state().playerStateIconsToShow.template has<BombIconPanel>())
if (state().showBombCarrierIcon)
return playerPawn.isCarryingC4();
if (state().playerStateIconsToShow.template has<BombPlantingIcon>())
if (state().showBombPlantingIcon)
return playerPawn.carriedC4().isBeingPlanted().valueOr(false);
return false;
}

[[nodiscard]] bool shouldShowPlantingColor(auto&& playerPawn) const noexcept
{
return state().playerStateIconsToShow.template has<BombPlantingIcon>() && playerPawn.carriedC4().isBeingPlanted().valueOr(false);
return state().showBombPlantingIcon && playerPawn.carriedC4().isBeingPlanted().valueOr(false);
}

[[nodiscard]] auto& state() const noexcept
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <CS2/Classes/Color.h>
#include <CS2/Constants/ColorConstants.h>
#include <CS2/Panorama/CUILength.h>
#include <CS2/Panorama/StyleEnums.h>
#include <FeatureHelpers/PanelShadowParams.h>
#include <GameClasses/PanelAlignmentParams.h>
#include <GameClasses/PanelMarginParams.h>

namespace player_bomb_icon_panel_params::bomb_icon_panel_params
{
static constexpr auto kImageUrl = "s2r://panorama/images/icons/equipment/c4.svg";
static constexpr auto kTextureHeight = 24;
static constexpr auto kShadowParams = PanelShadowParams{
.horizontalOffset{cs2::CUILength::pixels(0)},
.verticalOffset{cs2::CUILength::pixels(0)},
.blurRadius{cs2::CUILength::pixels(3)},
.strength = 3,
.color{cs2::kColorBlack}
};
}

namespace player_bomb_icon_panel_params::container_panel_params
{
static constexpr auto kAlignment = PanelAlignmentParams{
.verticalAlignment = cs2::k_EVerticalAlignmentCenter
};
static constexpr auto kMargin = PanelMarginParams{.marginLeft = cs2::CUILength::pixels(2.5), .marginRight = cs2::CUILength::pixels(2.5)};
static constexpr auto kColorCarryingC4 = cs2::Color{255, 255, 77};
static constexpr auto kColorPlantingC4 = cs2::Color{255, 193, 77};
}
Loading

0 comments on commit c8b56ca

Please sign in to comment.