-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9541915
commit 19d4a4d
Showing
9 changed files
with
59 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,57 @@ | ||
#pragma once | ||
|
||
#include <GameClasses/Hud/Hud.h> | ||
#include <GameClasses/PanelHandle.h> | ||
#include <GameClasses/PanoramaUiPanel.h> | ||
#include <Helpers/PanoramaPanelPointer.h> | ||
|
||
class HudInWorldPanelContainer { | ||
public: | ||
HudInWorldPanelContainer() = default; | ||
HudInWorldPanelContainer(const HudInWorldPanelContainer&) = delete; | ||
HudInWorldPanelContainer(HudInWorldPanelContainer&&) = delete; | ||
HudInWorldPanelContainer& operator=(const HudInWorldPanelContainer&) = delete; | ||
HudInWorldPanelContainer& operator=(HudInWorldPanelContainer&&) = delete; | ||
struct InWorldPanelContainerState { | ||
cs2::PanelHandle containerPanelHandle; | ||
}; | ||
|
||
~HudInWorldPanelContainer() noexcept | ||
template <typename HookContext> | ||
struct InWorldPanelContainerUnloadHandler { | ||
explicit InWorldPanelContainerUnloadHandler(HookContext& hookContext) noexcept | ||
: hookContext{hookContext} | ||
{ | ||
if (containerPanel.getHandle().isValid()) | ||
PanoramaUiEngine::onDeletePanel(containerPanel.getHandle()); | ||
} | ||
|
||
template <typename Dependencies> | ||
[[nodiscard]] auto get(Hud<Dependencies> hud, auto& hookContext) noexcept | ||
void handleUnload() const noexcept | ||
{ | ||
if (const auto container = containerPanel.get()) | ||
return PanoramaUiPanel{PanoramaUiPanelContext{hookContext, container}}; | ||
return createPanel(hud, hookContext); | ||
hookContext.panels().deletePanelByHandle(hookContext.inWorldPanelContainerState().containerPanelHandle); | ||
} | ||
|
||
private: | ||
template <typename Dependencies> | ||
[[nodiscard]] auto createPanel(Hud<Dependencies> hud, auto& hookContext) noexcept | ||
HookContext& hookContext; | ||
}; | ||
|
||
template <typename HookContext> | ||
class InWorldPanelContainer { | ||
public: | ||
explicit InWorldPanelContainer(HookContext& hookContext) noexcept | ||
: hookContext{hookContext} | ||
{ | ||
} | ||
|
||
[[nodiscard]] auto get() noexcept | ||
{ | ||
return handle().getOrInit(createContainerPanel()); | ||
} | ||
|
||
private: | ||
[[nodiscard]] decltype(auto) handle() const noexcept | ||
{ | ||
return hookContext.template make<PanelHandle>(hookContext.inWorldPanelContainerState().containerPanelHandle); | ||
} | ||
|
||
[[nodiscard]] auto createContainerPanel() const noexcept | ||
{ | ||
if (const auto hudReticle = hud.getHudReticle()) { | ||
auto&& panel = hookContext.panelFactory().createPanel(hudReticle).uiPanel(); | ||
return [this] { | ||
auto&& panel = hookContext.panelFactory().createPanel(hookContext.hud().getHudReticle()).uiPanel(); | ||
panel.fitParent(); | ||
containerPanel.handle = panel.getHandle(); | ||
return panel; | ||
} | ||
return PanoramaUiPanel{PanoramaUiPanelContext{hookContext, nullptr}}; | ||
}; | ||
} | ||
|
||
PanoramaPanelPointer containerPanel; | ||
HookContext& hookContext; | ||
}; |
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
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
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
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