Skip to content

Commit 9fa091f

Browse files
Merge PanoramaUiPanelContext with PanoramaUiPanel
1 parent 0212bbe commit 9fa091f

File tree

5 files changed

+129
-195
lines changed

5 files changed

+129
-195
lines changed

Source/CS2/Panorama/StyleProperties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <Platform/Macros/PlatformSpecific.h>
99

1010
#include "CStyleSymbol.h"
11+
#include "Transform3D.h"
1112

1213
namespace cs2
1314
{

Source/GameClient/Panorama/PanoramaUiPanel.h

Lines changed: 128 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,57 @@
55

66
#include <CS2/Classes/Color.h>
77
#include <CS2/Classes/CUtlVector.h>
8+
#include <CS2/Panorama/CPanelStyle.h>
89
#include <CS2/Panorama/CPanoramaSymbol.h>
910
#include <CS2/Panorama/CUILength.h>
1011
#include <CS2/Panorama/CUIPanel.h>
1112
#include <CS2/Panorama/StyleEnums.h>
13+
#include <CS2/Panorama/StyleProperties.h>
1214
#include <CS2/Panorama/Transform3D.h>
1315
#include <GameClient/Panorama/PanelAlignmentParams.h>
1416
#include <GameClient/Panorama/PanelFontParams.h>
1517
#include <GameClient/Panorama/PanelMarginParams.h>
1618
#include <GameClient/Panorama/PanelShadowParams.h>
19+
#include <MemoryPatterns/PatternTypes/PanelStylePatternTypes.h>
20+
#include <MemoryPatterns/PatternTypes/UiPanelPatternTypes.h>
1721
#include <Utils/Lvalue.h>
1822

19-
#include "PanoramaUiPanelContext.h"
23+
#include "ClientPanel.h"
24+
#include "PanelStylePropertyFactory.h"
25+
#include "PanoramaUiPanelChildPanels.h"
26+
#include "PanoramaUiPanelClasses.h"
27+
#include "PanoramaUiPanelMethodInvoker.h"
28+
#include "TopLevelWindow.h"
2029

21-
template <typename HookContext, typename Context = PanoramaUiPanelContext<HookContext>>
22-
struct PanoramaUiPanel {
23-
template <typename... Args>
24-
requires std::is_constructible_v<Context, Args...>
25-
explicit PanoramaUiPanel(Args&&... args) noexcept
26-
: context{std::forward<Args>(args)...}
30+
template <typename HookContext>
31+
class PanoramaUiPanel {
32+
public:
33+
PanoramaUiPanel(HookContext& hookContext, cs2::CUIPanel* panel) noexcept
34+
: hookContext{hookContext}
35+
, panel{panel}
2736
{
2837
}
2938

3039
template <template <typename...> typename T, typename... Args>
3140
[[nodiscard]] decltype(auto) as(Args&&... args) const noexcept
3241
{
33-
return context.template as<T>(std::forward<Args>(args)...);
42+
return hookContext.template make<T>(panel, std::forward<Args>(args)...);
3443
}
3544

3645
[[nodiscard]] decltype(auto) getHandle() const noexcept
3746
{
38-
return context.getHandle();
47+
return hookContext.patternSearchResults().template get<OffsetToPanelHandle>().of(panel).valueOr(cs2::PanelHandle{});
3948
}
4049

4150
[[nodiscard]] decltype(auto) clientPanel() const noexcept
4251
{
43-
return context.clientPanel();
52+
return hookContext.template make<ClientPanel>(clientPanelPointer());
4453
}
4554

46-
[[nodiscard]] std::string_view getId() const noexcept
47-
{
48-
if (auto&& id = context.getId())
49-
return id;
50-
return {};
51-
}
52-
5355
void setParent(cs2::CUIPanel* parent) const noexcept
5456
{
5557
if (parent) {
56-
if (auto&& setParentFn = context.setParent())
58+
if (auto&& setParentFn = setParent())
5759
setParentFn(parent);
5860
}
5961
}
@@ -77,17 +79,17 @@ struct PanoramaUiPanel {
7779
void setVisible(bool visible) const noexcept
7880
{
7981
if (isVisible() != visible) {
80-
if (auto&& setVisibleFn = context.setVisible())
82+
if (auto&& setVisibleFn = setVisible())
8183
setVisibleFn(visible);
8284
}
8385
}
8486

8587
[[nodiscard]] decltype(auto) findChildInLayoutFile(const char* childId) const noexcept
8688
{
87-
auto&& childPanels = context.childPanels();
89+
auto&& childPanels = children();
8890

8991
for (auto&& childPanel : childPanels) {
90-
if (childPanel.getId() == childId)
92+
if (std::strcmp(childPanel.getId(), childId) == 0)
9193
return utils::lvalue<decltype(childPanel)>(childPanel);
9294
}
9395

@@ -98,164 +100,237 @@ struct PanoramaUiPanel {
98100
}
99101
}
100102

101-
return context.nullPanel();
103+
return hookContext.template make<PanoramaUiPanel<HookContext>>(nullptr);
102104
}
103105

104106
[[nodiscard]] const char* getAttributeString(cs2::CPanoramaSymbol attributeName, const char* defaultValue) const noexcept
105107
{
106-
if (auto&& getAttributeStringFn = context.getAttributeString())
108+
if (auto&& getAttributeStringFn = getAttributeString())
107109
return getAttributeStringFn(attributeName, defaultValue);
108110
return defaultValue;
109111
}
110112

111113
void setAttributeString(cs2::CPanoramaSymbol attributeName, const char* value) const noexcept
112114
{
113-
if (auto&& setAttributeStringFn = context.setAttributeString())
115+
if (auto&& setAttributeStringFn = setAttributeString())
114116
return setAttributeStringFn(attributeName, value);
115117
}
116118

117119
[[nodiscard]] bool hasClass(cs2::CPanoramaSymbol className) const noexcept
118120
{
119-
return context.classes().hasClass(className);
121+
return classes().hasClass(className);
120122
}
121123

122124
[[nodiscard]] auto hasOwnLayoutFile() const noexcept
123125
{
124-
return context.hasFlag(cs2::k_EPanelFlag_HasOwnLayoutFile);
126+
return hasFlag(cs2::k_EPanelFlag_HasOwnLayoutFile);
125127
}
126128

127129
[[nodiscard]] auto isVisible() const noexcept
128130
{
129-
return context.hasFlag(cs2::k_EPanelFlag_IsVisible);
131+
return hasFlag(cs2::k_EPanelFlag_IsVisible);
130132
}
131133

132134
[[nodiscard]] decltype(auto) children() const noexcept
133135
{
134-
return context.childPanels();
136+
return PanoramaUiPanelChildPanels{hookContext, hookContext.patternSearchResults().template get<ChildPanelsVectorOffset>().of(panel).get()};
135137
}
136138

137139
explicit(false) operator cs2::CUIPanel*() const noexcept
138140
{
139-
return context.getRawPointer();
141+
return panel;
140142
}
141143

142144
explicit operator bool() const noexcept
143145
{
144-
return context.getRawPointer() != nullptr;
146+
return panel != nullptr;
145147
}
146148

147149
void setOpacity(float opacity) const noexcept
148150
{
149-
setStyleProperty(context.propertyFactory().opacity(opacity));
151+
setStyleProperty(propertyFactory().opacity(opacity));
150152
}
151153

152154
void setWidth(cs2::CUILength width) const noexcept
153155
{
154-
setStyleProperty(context.propertyFactory().width(width));
156+
setStyleProperty(propertyFactory().width(width));
155157
}
156158

157159
void setHeight(cs2::CUILength height) const noexcept
158160
{
159-
setStyleProperty(context.propertyFactory().height(height));
161+
setStyleProperty(propertyFactory().height(height));
160162
}
161163

162164
void setZIndex(float zIndex) const noexcept
163165
{
164-
setStyleProperty(context.propertyFactory().zIndex(zIndex));
166+
setStyleProperty(propertyFactory().zIndex(zIndex));
165167
}
166168

167169
void setImageShadow(const PanelShadowParams& params) const noexcept
168170
{
169-
setStyleProperty(context.propertyFactory().imageShadow(params));
171+
setStyleProperty(propertyFactory().imageShadow(params));
170172
}
171173

172174
void setPosition(cs2::CUILength x, cs2::CUILength y) const noexcept
173175
{
174-
setStyleProperty(context.propertyFactory().position(x, y));
176+
setStyleProperty(propertyFactory().position(x, y));
175177
}
176178

177179
void setTransformOrigin(cs2::CUILength x, cs2::CUILength y) const noexcept
178180
{
179-
setStyleProperty(context.propertyFactory().transformOrigin(x, y));
181+
setStyleProperty(propertyFactory().transformOrigin(x, y));
180182
}
181183

182184
void setAlign(const PanelAlignmentParams& params) const noexcept
183185
{
184-
setStyleProperty(context.propertyFactory().align(params));
186+
setStyleProperty(propertyFactory().align(params));
185187
}
186188

187189
void setWashColor(cs2::Color color) const noexcept
188190
{
189-
setStyleProperty(context.propertyFactory().washColor(color));
191+
setStyleProperty(propertyFactory().washColor(color));
190192
}
191193

192194
void setFlowChildren(cs2::EFlowDirection flowDirection) const noexcept
193195
{
194-
setStyleProperty(context.propertyFactory().flowChildren(flowDirection));
196+
setStyleProperty(propertyFactory().flowChildren(flowDirection));
195197
}
196198

197199
void setFont(const PanelFontParams& params) const noexcept
198200
{
199-
setStyleProperty(context.propertyFactory().font(params));
201+
setStyleProperty(propertyFactory().font(params));
200202
}
201203

202204
void setTextShadow(const PanelShadowParams& params) const noexcept
203205
{
204-
setStyleProperty(context.propertyFactory().textShadow(params));
206+
setStyleProperty(propertyFactory().textShadow(params));
205207
}
206208

207209
void setMargin(const PanelMarginParams& params) const noexcept
208210
{
209-
setStyleProperty(context.propertyFactory().margin(params));
211+
setStyleProperty(propertyFactory().margin(params));
210212
}
211213

212214
void setMixBlendMode(cs2::EMixBlendMode mode) const noexcept
213215
{
214-
setStyleProperty(context.propertyFactory().mixBlendMode(mode));
216+
setStyleProperty(propertyFactory().mixBlendMode(mode));
215217
}
216218

217219
void setTextAlign(cs2::ETextAlign textAlign) const noexcept
218220
{
219-
setStyleProperty(context.propertyFactory().textAlign(textAlign));
221+
setStyleProperty(propertyFactory().textAlign(textAlign));
220222
}
221223

222224
void setColor(cs2::Color color) const noexcept
223225
{
224-
setStyleProperty(context.propertyFactory().foregroundColor(color));
226+
setStyleProperty(propertyFactory().foregroundColor(color));
225227
}
226228

227229
void setBackgroundColor(cs2::Color color) const noexcept
228230
{
229-
setStyleProperty(context.propertyFactory().backgroundColor(color));
231+
setStyleProperty(propertyFactory().backgroundColor(color));
230232
}
231233

232234
void setTransform3D(std::span<cs2::CTransform3D*> transforms) const noexcept
233235
{
234-
setStyleProperty(context.propertyFactory().transform3D(transforms));
236+
setStyleProperty(propertyFactory().transform3D(transforms));
235237
}
236238

237239
void setBorder(cs2::CUILength width, cs2::Color color) const noexcept
238240
{
239-
setStyleProperty(context.propertyFactory().border(width, color));
241+
setStyleProperty(propertyFactory().border(width, color));
240242
}
241243

242244
void setBorderRadius(cs2::CUILength radius) const noexcept
243245
{
244-
setStyleProperty(context.propertyFactory().borderRadius(radius));
246+
setStyleProperty(propertyFactory().borderRadius(radius));
245247
}
246248

247249
[[nodiscard]] decltype(auto) getUiScaleFactor() const noexcept
248250
{
249-
return context.getParentWindow().getUiScaleFactor();
251+
return getParentWindow().getUiScaleFactor();
250252
}
251253

252254
private:
253255
template <typename StyleProperty>
254256
void setStyleProperty(std::optional<StyleProperty> styleProperty) const
255257
{
256258
if (styleProperty.has_value())
257-
context.setProperty(&*styleProperty);
259+
setProperty(&*styleProperty);
260+
}
261+
262+
void setProperty(cs2::CStyleProperty* styleProperty) const noexcept
263+
{
264+
if (!styleProperty)
265+
return;
266+
267+
const auto style = getStyle();
268+
if (!style)
269+
return;
270+
271+
if (const auto setPropertyFn{hookContext.patternSearchResults().template get<SetPanelStylePropertyFunctionPointer>()})
272+
setPropertyFn(style, styleProperty, true);
273+
}
274+
275+
[[nodiscard]] PanoramaUiPanelClasses classes() const noexcept
276+
{
277+
return PanoramaUiPanelClasses{hookContext.patternSearchResults().template get<PanelClassesVectorOffset>().of(panel).get()};
278+
}
279+
280+
[[nodiscard]] decltype(auto) getParentWindow() const noexcept
281+
{
282+
return hookContext.template make<TopLevelWindow>(hookContext.patternSearchResults().template get<ParentWindowOffset>().of(panel).valueOr(nullptr));
283+
}
284+
285+
[[nodiscard]] Optional<bool> hasFlag(cs2::EPanelFlag flag) const noexcept
286+
{
287+
return (hookContext.patternSearchResults().template get<OffsetToPanelFlags>().of(panel).toOptional() & flag) != 0;
288+
}
289+
290+
[[nodiscard]] auto setParent() const noexcept
291+
{
292+
return PanoramaUiPanelMethodInvoker{panel, hookContext.patternSearchResults().template get<SetParentFunctionOffset>()};
293+
}
294+
295+
[[nodiscard]] auto setVisible() const noexcept
296+
{
297+
return PanoramaUiPanelMethodInvoker{panel, hookContext.patternSearchResults().template get<SetVisibleFunctionOffset>()};
298+
}
299+
300+
[[nodiscard]] auto getAttributeString() const noexcept
301+
{
302+
return PanoramaUiPanelMethodInvoker{panel, hookContext.patternSearchResults().template get<GetAttributeStringFunctionOffset>()};
303+
}
304+
305+
[[nodiscard]] auto setAttributeString() const noexcept
306+
{
307+
return PanoramaUiPanelMethodInvoker{panel, hookContext.patternSearchResults().template get<SetAttributeStringFunctionOffset>()};
308+
}
309+
310+
[[nodiscard]] auto propertyFactory() const noexcept
311+
{
312+
return hookContext.template make<PanelStylePropertyFactory>(hookContext.stylePropertySymbolsAndVMTs());
313+
}
314+
315+
[[nodiscard]] cs2::CPanel2D* clientPanelPointer() const noexcept
316+
{
317+
if (panel)
318+
return panel->clientPanel;
319+
return nullptr;
320+
}
321+
322+
[[nodiscard]] cs2::CPanelStyle* getStyle() const noexcept
323+
{
324+
return hookContext.patternSearchResults().template get<PanelStyleOffset>().of(panel).get();
325+
}
326+
327+
[[nodiscard]] const char* getId() const noexcept
328+
{
329+
if (const auto id = hookContext.patternSearchResults().template get<OffsetToPanelId>().of(panel).get(); id && id->m_pString)
330+
return id->m_pString;
331+
return "";
258332
}
259333

260-
Context context;
334+
HookContext& hookContext;
335+
cs2::CUIPanel* panel;
261336
};

0 commit comments

Comments
 (0)