ChatPlexSDK-BS 1.0.1-v6.2.0
C++ ChatPlex BeatSaber SDK
Loading...
Searching...
No Matches
XUIPOrSButton.hpp
1#pragma once
2
3#include "../../UI/Components/CPrimaryButton.hpp"
4#include "../../UI/Components/CSecondaryButton.hpp"
5#include "IXUIElement.hpp"
6#include "IXUIBindable.hpp"
7#include "IXUIElementReady.hpp"
8
9namespace CP_SDK::XUI {
10
14 template<class t_Base, class t_Component>
16 : public IXUIElement,
17 public IXUIElementReady<t_Base, t_Component>,
18 public IXUIBindable<t_Base>,
19 public std::enable_shared_from_this<t_Base>
20 {
21 CP_SDK_NO_COPYMOVE_CTORS(_XUIPOrSButton);
22
23 private:
25
27
28 public:
29 std::shared_ptr<t_Base> AsShared() { return std::enable_shared_from_this<t_Base>::shared_from_this(); }
30
31 virtual _v::UIFieldRef<_u::RectTransform> RTransform() override
32 {
33 return m_Element ? m_Element->RTransform() : _v::UIFieldDefault<_u::RectTransform>::Value;
34 }
35 virtual _v::UIFieldRef<t_Component> Element()
36 {
37 return m_Element;
38 }
39
40 protected:
46 _XUIPOrSButton(std::u16string_view p_Name, IXUIElement::ETypeID p_TypeID, std::u16string_view p_Label, _v::CActionRef<> p_OnClick)
47 : IXUIElement(p_Name, p_TypeID)
48 {
49 if (p_OnClick.IsValid())
50 OnClick(p_OnClick);
51
52 SetText(std::u16string(p_Label));
53 }
55 virtual ~_XUIPOrSButton() = default;
56
57 public:
60 virtual void BuildUI(_u::Transform* p_Parent) override
61 {
62 if constexpr (std::is_same_v<t_Component, _v::CPrimaryButton>)
63 m_Element = _v::UISystem::PrimaryButtonFactory->Create(IXUIElement::GetInitialName(), p_Parent);
64 else
65 m_Element = _v::UISystem::SecondaryButtonFactory->Create(IXUIElement::GetInitialName(), p_Parent);
66
67 try { m_OnReady(m_Element.Ptr()); m_OnReady.Clear(); }
68 catch (const std::exception& l_Exception)
69 {
70 if constexpr (std::is_same_v<t_Component, _v::CPrimaryButton>)
71 ChatPlexSDK::Logger()->Error(u"[CP_SDK.XUI][_XUIPOrSButton<CPrimaryButton>.BuildUI] Error OnReady:");
72 else
73 ChatPlexSDK::Logger()->Error(u"[CP_SDK.XUI][_XUIPOrSButton<CSecondaryButton>.BuildUI] Error OnReady:");
74 ChatPlexSDK::Logger()->Error(l_Exception);
75 }
76 }
77
78 public:
81 virtual t_Base* OnReady(_v::CActionRef<t_Component*> p_Functor) override
82 {
83 if (m_Element) p_Functor(m_Element.Ptr());
84 else m_OnReady += p_Functor;
85 return reinterpret_cast<t_Base*>(this);
86 }
89 virtual t_Base* Bind(std::shared_ptr<t_Base>* p_Target) override
90 {
91 *p_Target = std::enable_shared_from_this<t_Base>::shared_from_this();
92 return reinterpret_cast<t_Base*>(this);
93 }
94
95 public:
99 t_Base* OnClick(_v::Action<> p_Functor, bool p_Add = true) XUI_PROXY_IMPL_EX(t_Component, { x->OnClick(p_Functor, p_Add); })
100
101 public:
104 t_Base* SetActive(bool p_Active) XUI_PROXY_IMPL_EX(t_Component, { x->get_gameObject()->SetActive(p_Active); })
105
106 public:
109 t_Base* SetWidth(float p_Width) XUI_PROXY_IMPL_EX(t_Component, { x->SetWidth(p_Width); })
112 t_Base* SetHeight(float p_Height) XUI_PROXY_IMPL_EX(t_Component, { x->SetHeight(p_Height); })
113
114 public:
117 t_Base* SetBackgroundSprite(_u::Sprite* p_Sprite) XUI_PROXY_IMPL_EX(t_Component, { x->SetBackgroundSprite(p_Sprite); })
120 t_Base* SetFontSize(float p_Size) XUI_PROXY_IMPL_EX(t_Component, { x->SetFontSize(p_Size); })
123 t_Base* SetIconSprite(_u::Sprite* p_Sprite) XUI_PROXY_IMPL_EX(t_Component, { x->SetIconSprite(p_Sprite); })
126 t_Base* SetInteractable(bool p_Interactable) XUI_PROXY_IMPL_EX(t_Component, { x->SetInteractable(p_Interactable); })
129 t_Base* SetOverflowMode(_u::TextOverflowModes p_OverflowMode) XUI_PROXY_IMPL_EX(t_Component, { x->SetOverflowMode(p_OverflowMode); })
132 t_Base* SetText(std::u16string p_Text) XUI_PROXY_IMPL_EX(t_Component, { x->SetText(p_Text); })
135 t_Base* SetTooltip(std::u16string p_Tooltip) XUI_PROXY_IMPL_EX(t_Component, { x->SetTooltip(p_Tooltip); })
136
137 };
138
139}
static Logging::ILogger * Logger()
Logger instance.
Event class helper.
Definition Event.hpp:100
CPOrSButton abstract XUI Element.
t_Base t_Base t_Base t_Base t_Base t_Base t_Base * SetTooltip(std::u16string p_Tooltip) XUI_PROXY_IMPL_EX(t_Component
Set tooltip.
virtual ~_XUIPOrSButton()=default
Destructor.
t_Base * SetWidth(float p_Width) XUI_PROXY_IMPL_EX(t_Component
Set preferred width.
t_Base t_Base t_Base t_Base t_Base t_Base * SetText(std::u16string p_Text) XUI_PROXY_IMPL_EX(t_Component
Set button text.
t_Base * SetActive(bool p_Active) XUI_PROXY_IMPL_EX(t_Component
Set game object active state.
_XUIPOrSButton(std::u16string_view p_Name, IXUIElement::ETypeID p_TypeID, std::u16string_view p_Label, _v::CActionRef<> p_OnClick)
Constructor.
virtual void BuildUI(_u::Transform *p_Parent) override
BuildUI for this element into p_Parent transform.
t_Base t_Base t_Base * SetIconSprite(_u::Sprite *p_Sprite) XUI_PROXY_IMPL_EX(t_Component
Set button icon sprite.
t_Base * OnClick(_v::Action<> p_Functor, bool p_Add=true) XUI_PROXY_IMPL_EX(t_Component
On click event.
t_Base t_Base * SetFontSize(float p_Size) XUI_PROXY_IMPL_EX(t_Component
Set font size.
t_Base * SetBackgroundSprite(_u::Sprite *p_Sprite) XUI_PROXY_IMPL_EX(t_Component
Set button background sprite.
virtual t_Base * Bind(std::shared_ptr< t_Base > *p_Target) override
On ready, bind.
t_Base t_Base t_Base t_Base t_Base * SetOverflowMode(_u::TextOverflowModes p_OverflowMode) XUI_PROXY_IMPL_EX(t_Component
Set overflow mode.
virtual t_Base * OnReady(_v::CActionRef< t_Component * > p_Functor) override
IXUIElement OnReady functor interface.
t_Base t_Base t_Base t_Base * SetInteractable(bool p_Interactable) XUI_PROXY_IMPL_EX(t_Component
Set button interactable state.
t_Base t_Base * SetHeight(float p_Height) XUI_PROXY_IMPL_EX(t_Component
Set preferred height.
IXUIElement Bind interface.
Element interface.
std::u16string_view GetInitialName()
Get initial name.
IXUIElement OnReady functor interface.
Tree like syntax CP_SDK::UI builder.