-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor PlayerInformationThroughWalls feature and rename it to Playe…
…rInfoInWorld
- Loading branch information
1 parent
3c589bb
commit 6833ea4
Showing
36 changed files
with
995 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
Source/Features/Visuals/PlayerInfoInWorld/ActiveWeaponAmmo/PlayerActiveWeaponAmmoPanel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
30 changes: 30 additions & 0 deletions
30
.../Features/Visuals/PlayerInfoInWorld/ActiveWeaponAmmo/PlayerActiveWeaponAmmoPanelContext.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
File renamed without changes.
45 changes: 45 additions & 0 deletions
45
Source/Features/Visuals/PlayerInfoInWorld/ActiveWeaponIcon/PlayerActiveWeaponIconPanel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
28 changes: 28 additions & 0 deletions
28
.../Features/Visuals/PlayerInfoInWorld/ActiveWeaponIcon/PlayerActiveWeaponIconPanelContext.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
37 changes: 37 additions & 0 deletions
37
Source/Features/Visuals/PlayerInfoInWorld/PlayerHealth/PlayerHealthPanel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
25 changes: 25 additions & 0 deletions
25
Source/Features/Visuals/PlayerInfoInWorld/PlayerHealth/PlayerHealthPanelContext.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.