Skip to content

Commit

Permalink
Refactor PlayerInformationThroughWalls feature and rename it to Playe…
Browse files Browse the repository at this point in the history
…rInfoInWorld
  • Loading branch information
danielkrupinski committed Oct 1, 2024
1 parent 3c589bb commit 6833ea4
Show file tree
Hide file tree
Showing 36 changed files with 995 additions and 720 deletions.
6 changes: 3 additions & 3 deletions Source/Endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ void ViewRenderHook_onRenderStart_cpp(cs2::CViewRender* thisptr) noexcept
soundWatcher.update();
fullContext.features(dependencies).soundFeatures().runOnViewMatrixUpdate();

PlayerInformationThroughWalls playerInformationThroughWalls{fullContext.featuresStates.visualFeaturesStates.playerInformationThroughWallsState, dependencies};
RenderingHookEntityLoop{dependencies, playerInformationThroughWalls}.run();
playerInformationThroughWalls.hideUnusedPanels();
auto&& playerInfoInWorld = dependencies.make<PlayerInfoInWorld>();
RenderingHookEntityLoop{dependencies, playerInfoInWorld}.run();
playerInfoInWorld.hideUnusedPanels();
dependencies.make<GlowSceneObjects>().removeUnreferencedObjects();
}

Expand Down
6 changes: 3 additions & 3 deletions Source/FeatureHelpers/RenderingHookEntityLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <CS2/Classes/Entities/CEntityInstance.h>
#include <Features/Visuals/OutlineGlow/OutlineGlow.h>
#include <Features/Visuals/PlayerInformationThroughWalls/PlayerInformationThroughWalls.h>
#include <Features/Visuals/PlayerInfoInWorld/PlayerInfoInWorld.h>

template <typename HookContext>
class RenderingHookEntityLoop {
public:
explicit RenderingHookEntityLoop(HookContext& hookContext, PlayerInformationThroughWalls<HookContext>& playerInformationThroughWalls) noexcept
explicit RenderingHookEntityLoop(HookContext& hookContext, PlayerInfoInWorld<HookContext>& playerInformationThroughWalls) noexcept
: hookContext{hookContext}
, playerInformationThroughWalls{playerInformationThroughWalls}
{
Expand All @@ -31,5 +31,5 @@ class RenderingHookEntityLoop {
}

HookContext& hookContext;
PlayerInformationThroughWalls<HookContext>& playerInformationThroughWalls;
PlayerInfoInWorld<HookContext>& playerInformationThroughWalls;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "PlayerActiveWeaponAmmoPanelContext.h"
#include <GameClasses/PanoramaLabel.h>

template <typename HookContext, typename Context = PlayerActiveWeaponAmmoPanelContext<HookContext>>
class PlayerActiveWeaponAmmoPanel {
public:
template <typename... Args>
explicit PlayerActiveWeaponAmmoPanel(Args&&... args) noexcept
: context{std::forward<Args>(args)...}
{
}

void update(auto&& playerPawn) const noexcept
{
if (!context.shouldShowOn(playerPawn)) {
context.panel().setVisible(false);
return;
}

context.panel().setVisible(true);
const auto ammo = playerPawn.getActiveWeapon().clipAmmo().valueOr(-1);
context.panel().children()[0].clientPanel().template as<PanoramaLabel>().setText(StringBuilderStorage<10>{}.builder().put(ammo).cstring());
}

private:
Context context;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

template <typename HookContext>
class PlayerActiveWeaponAmmoPanelContext {
public:
PlayerActiveWeaponAmmoPanelContext(HookContext& hookContext, cs2::CUIPanel* panel) noexcept
: _hookContext{hookContext}
, _panel{panel}
{
}

[[nodiscard]] auto& state() const noexcept
{
return _hookContext.featuresStates().visualFeaturesStates.playerInfoInWorldState;
}

[[nodiscard]] bool shouldShowOn(auto&& playerPawn) const noexcept
{
return state().showPlayerActiveWeaponAmmo && playerPawn.getActiveWeapon().clipAmmo().greaterThan(-1).valueOr(true);
}

[[nodiscard]] decltype(auto) panel() const noexcept
{
return _hookContext.template make<PanoramaUiPanel>(_panel);
}

private:
HookContext& _hookContext;
cs2::CUIPanel* _panel;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include "PlayerActiveWeaponIconPanelContext.h"

template <typename HookContext, typename Context = PlayerActiveWeaponIconPanelContext<HookContext>>
class PlayerActiveWeaponIconPanel {
public:
template <typename... Args>
explicit PlayerActiveWeaponIconPanel(Args&&... args) noexcept
: context{std::forward<Args>(args)...}
{
}

void update(auto&& playerPawn) const noexcept
{
if (!context.state().showPlayerActiveWeapon) {
context.panel().setVisible(false);
return;
}

auto weaponName = CString{playerPawn.getActiveWeapon().getName()};
if (!weaponName.string)
return;
weaponName.skipPrefix("weapon_");

context.panel().setVisible(true);

StringBuilderStorage<100> weaponIconPathStorage;
auto weaponIconPathBuilder = weaponIconPathStorage.builder();
weaponIconPathBuilder.put("s2r://panorama/images/icons/equipment/", weaponName.string, ".svg");
const auto weaponIconPath = weaponIconPathBuilder.cstring();

auto&& weaponIconImagePanel = context.panel().clientPanel().template as<PanoramaImagePanel>();
if (shouldUpdateImagePanel(weaponIconImagePanel, weaponIconPath))
weaponIconImagePanel.setImageSvg(weaponIconPath, 24);
}

private:
[[nodiscard]] bool shouldUpdateImagePanel(auto&& imagePanel, const char* newImagePath) const noexcept
{
return imagePanel.getImagePath() != newImagePath;
}

Context context;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <CS2/Panorama/CUIPanel.h>
#include <GameClasses/PanoramaUiPanel.h>

template <typename HookContext>
class PlayerActiveWeaponIconPanelContext {
public:
PlayerActiveWeaponIconPanelContext(HookContext& hookContext, cs2::CUIPanel* panel) noexcept
: _hookContext{hookContext}
, _panel{panel}
{
}

[[nodiscard]] auto& state() const noexcept
{
return _hookContext.featuresStates().visualFeaturesStates.playerInfoInWorldState;
}

[[nodiscard]] decltype(auto) panel() const noexcept
{
return _hookContext.template make<PanoramaUiPanel>(_panel);
}

private:
HookContext& _hookContext;
cs2::CUIPanel* _panel;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "PlayerHealthPanelContext.h"

template <typename HookContext, typename Context = PlayerHealthPanelContext<HookContext>>
class PlayerHealthPanel {
public:
template <typename... Args>
explicit PlayerHealthPanel(Args&&... args) noexcept
: context{std::forward<Args>(args)...}
{
}

void update(auto&& playerPawn) const noexcept
{
if (!context.state().showPlayerHealth) {
context.panel().setVisible(false);
return;
}

context.panel().setVisible(true);

auto&& healthValuePanel = context.panel().children()[1];
healthValuePanel.setColor(getColor(playerPawn));
healthValuePanel.clientPanel().template as<PanoramaLabel>().setText(StringBuilderStorage<10>{}.builder().put(playerPawn.health().valueOr(0)).cstring());
}

private:
[[nodiscard]] cs2::Color getColor(auto&& playerPawn) const noexcept
{
if (context.state().playerHealthTextColor == PlayerHealthTextColor::HealthBased)
return playerPawn.healthColor().value_or(cs2::kColorWhite);
return cs2::kColorWhite;
}

Context context;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

template <typename HookContext>
class PlayerHealthPanelContext {
public:
PlayerHealthPanelContext(HookContext& hookContext, cs2::CUIPanel* panel) noexcept
: _hookContext{hookContext}
, _panel{panel}
{
}

[[nodiscard]] auto& state() const noexcept
{
return _hookContext.featuresStates().visualFeaturesStates.playerInfoInWorldState;
}

[[nodiscard]] decltype(auto) panel() const noexcept
{
return _hookContext.template make<PanoramaUiPanel>(_panel);
}

private:
HookContext& _hookContext;
cs2::CUIPanel* _panel;
};
Loading

0 comments on commit 6833ea4

Please sign in to comment.