diff --git a/include/ctrl/euiAnimButton.h b/include/ctrl/euiAnimButton.h new file mode 100644 index 0000000..f15e37d --- /dev/null +++ b/include/ctrl/euiAnimButton.h @@ -0,0 +1,71 @@ +#pragma once + +#include +#include +#include + +namespace nn::ui2d { +class ControlSrc; +class Pane; +} + +namespace sead { +class Heap; +} + +namespace eui { + +class AnimatorSet; +class LayoutEx; + +class AnimButton : public ButtonBase { +public: + virtual const char* getClassName() const override { return "AnimButton"; } + + AnimButton(); + + virtual void Build(const nn::ui2d::ControlSrc& controlSrc, LayoutEx* layout); + void SetTouch(bool isTouch); + virtual void BuildStateAnim(const nn::ui2d::ControlSrc& controlSrc, LayoutEx* layout); + void DownOff(bool isDownOff); + void Down(); + virtual bool HitTest(const sead::Vector2f& touchPos) const; + virtual void StartDrag(const sead::Vector2f& touchPos); + virtual void UpdateDrag(const sead::Vector2f* touchPos); + virtual void FinishDrag(const sead::Vector2f* touchPos); + void PlayDisableAnim(bool isPlay); + void SetDisableAnimDirect(bool isDisabled); + bool IsPlayDisableAnim() const; + virtual void ActivateByBoxCursor(); + virtual void InactivateByBoxCursor(); + void ForceOff(); + void SelectStateAnim(s32 index); + void ForceOn(); + void ForceDown(); + void StartOn() override; + void StartOff() override; + void StartDown() override; + bool UpdateOn() override; + bool UpdateOff() override; + bool UpdateDown() override; + void ProcessOn() override; + void ProcessOff() override; + void ProcessCancel() override; + void FinishDown() override; + void ChangeState(State state) override; + void ForceChangeState(State state) override; + + const nn::font::detail::RuntimeTypeInfo* GetRuntimeTypeInfo() const override; + +protected: + void CloneImpl_(const AnimButton& other, LayoutEx* layout, sead::Heap* heap); + + AnimatorSet* mStateAnimatorSet = nullptr; + Animator* mDisableAnimator = nullptr; + nn::ui2d::Pane* mHitPane = nullptr; + void* mBoxCursorControl = nullptr; +}; + +static_assert(sizeof(AnimButton) == 0x68); + +} // namespace eui diff --git a/include/ctrl/euiButtonBase.h b/include/ctrl/euiButtonBase.h new file mode 100644 index 0000000..e89a19d --- /dev/null +++ b/include/ctrl/euiButtonBase.h @@ -0,0 +1,84 @@ +#pragma once + +#include +#include + +namespace eui { + +class ButtonBase : public ControlBase { +public: + enum State : s32 { + State_Off = 0, + State_On = 1, + State_Down = 2, + State_Cancel = 3, + }; + + enum Action : s32 { + Action_Off = 0, + Action_On = 1, + Action_Down = 2, + Action_Cancel = 3, + }; + + struct ActionQueue { + void PushWithOmit(Action action); + Action Pop(); + bool IsDownExist() const; + + u8 mActions[4] = {}; + s32 mCount = 0; + }; + + virtual const char* getClassName() const { return "ButtonBase"; } + + ButtonBase(); + + void On(); + void ResumeUpdate(); + void Off(); + void Down(); + void Cancel(); + void ForceOff(); + void ForceOn(); + void ForceDown(); + void Update(f32 delta) override; + void ProcessActionFromQueue(); + void SetActive(bool isActive); + + virtual void ProcessOn(); + virtual void ProcessOff(); + virtual void ProcessDown(); + virtual void ProcessCancel(); + virtual bool UpdateOn(); + virtual bool UpdateOff(); + virtual bool UpdateDown(); + virtual bool UpdateCancel(); + virtual void StartOn(); + virtual void StartOff(); + virtual void StartDown(); + virtual void StartCancel(); + virtual void FinishOn(); + virtual void FinishOff(); + virtual void FinishDown(); + virtual void FinishCancel(); + virtual void ChangeState(State state); + virtual void ForceChangeState(State state); + + bool IsDowning() const; + + const nn::font::detail::RuntimeTypeInfo* GetRuntimeTypeInfo() const override; + +private: + void* mPrev = nullptr; + void* mNext = nullptr; + bool mIsActive = false; + bool mIsUpdatePaused = false; + u16 mFlags = 0x1F; + ActionQueue mActionQueue; +}; + +static_assert(sizeof(ButtonBase::ActionQueue) == 0x8); +static_assert(sizeof(ButtonBase) == 0x48); + +} // namespace eui diff --git a/include/ctrl/euiCheckButton.h b/include/ctrl/euiCheckButton.h new file mode 100644 index 0000000..47268f0 --- /dev/null +++ b/include/ctrl/euiCheckButton.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +namespace nn::ui2d { +class ControlSrc; +} + +namespace sead { +class Heap; +} + +namespace eui { + +class LayoutEx; + +class CheckButton : public AnimButton { +public: + virtual const char* getClassName() const override { return "CheckButton"; } + + CheckButton(const CheckButton& other, LayoutEx* layout, sead::Heap* heap); + + void Build(const nn::ui2d::ControlSrc& controlSrc, LayoutEx* layout) override; + void ForceSetChecked(bool isChecked); + void StartDown() override; + bool UpdateDown() override; + + static const nn::font::detail::RuntimeTypeInfo* GetRuntimeTypeInfoStatic(); + const nn::font::detail::RuntimeTypeInfo* GetRuntimeTypeInfo() const override { + return GetRuntimeTypeInfoStatic(); + } + +protected: + bool mIsChecked = false; + bool mIsCheckEnabled = false; + Animator* mCheckAnimator = nullptr; +}; + +static_assert(sizeof(CheckButton) == 0x78); + +} // namespace eui diff --git a/include/ctrl/euiCheckKeepButton.h b/include/ctrl/euiCheckKeepButton.h new file mode 100644 index 0000000..d6d29ff --- /dev/null +++ b/include/ctrl/euiCheckKeepButton.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace sead { +class Heap; +} + +namespace eui { + +class LayoutEx; + +class CheckKeepButton : public CheckButton { +public: + const char* getClassName() const override; + + CheckKeepButton(const CheckKeepButton& other, LayoutEx* layout, sead::Heap* heap); + + void Uncheck(); + void StartDown() override; + + const nn::font::detail::RuntimeTypeInfo* GetRuntimeTypeInfo() const override { + static const nn::font::detail::RuntimeTypeInfo s_TypeInfo( + CheckButton::GetRuntimeTypeInfoStatic()); + return &s_TypeInfo; + } +}; + +static_assert(sizeof(CheckKeepButton) == 0x78); + +} // namespace eui diff --git a/include/sys/euiAnimator.h b/include/sys/euiAnimator.h new file mode 100644 index 0000000..2efb844 --- /dev/null +++ b/include/sys/euiAnimator.h @@ -0,0 +1,88 @@ +#pragma once + +#include + +namespace nn::font::detail { +class RuntimeTypeInfo; +} + +namespace nn::ui2d { +class AnimResource; +class Group; +class GroupContainer; +class Pane; +} + +namespace sead { +class Heap; +} + +namespace eui { + +class LayoutEx; + +class AnimatorVtableBase { +public: + virtual ~AnimatorVtableBase(); + + virtual void _10(); + virtual void _18(); + virtual void _20(); + virtual void _28(); + virtual void _30(); + virtual void _38(); + virtual void _40(); + virtual void _48(); + virtual void _50(); + virtual void _58(); + virtual void _60(); + virtual void _68(); + virtual void _70(); + virtual void _78(); + virtual void _80(); + virtual void _88(); + virtual void _90(); + virtual void _98(); + virtual void _a0(); +}; + +class Animator : public AnimatorVtableBase { +public: + enum PlayType : s32 { + Once = 0, + Loop = 1, + }; + + Animator(); + ~Animator() override; + + void SetupBasic(const nn::ui2d::AnimResource& resource, LayoutEx* layout, bool isEnabled); + void SetupWithPane(const nn::ui2d::AnimResource& resource, LayoutEx* layout, + nn::ui2d::Pane* pane, bool isEnabled); + void SetupWithGroup(const nn::ui2d::AnimResource& resource, LayoutEx* layout, + nn::ui2d::Group* group, bool isEnabled); + void SetupWithGroupIndex(const nn::ui2d::AnimResource& resource, LayoutEx* layout, + nn::ui2d::GroupContainer* container, u32 groupIndex, + bool isEnabled); + void SetupWithGroupAll(const nn::ui2d::AnimResource& resource, LayoutEx* layout, + nn::ui2d::GroupContainer* container, bool isEnabled); + + virtual bool Play(PlayType playType, f32 frame); + virtual bool PlayAuto(f32 frame); + virtual bool PlayFromCurrent(PlayType playType, f32 frame); + virtual bool PlayFromFrame(f32 startFrame, PlayType playType, f32 frame); + virtual bool PlayRandom(PlayType playType, f32 frame); + + void Synchronize(const Animator& other); + void Stop(f32 frame); + void StopCurrent(); + + virtual void StopAtMin(); + virtual void StopAtMax(); + virtual void SetEnabled(bool isEnabled); + virtual void DisableAndEraseFromActiveList(); + virtual void UpdateFrame(f32 delta); + virtual const nn::font::detail::RuntimeTypeInfo* GetRuntimeTypeInfo() const; +}; + +} // namespace eui diff --git a/src/ctrl/euiCheckKeepButton.cpp b/src/ctrl/euiCheckKeepButton.cpp new file mode 100644 index 0000000..3a7f30e --- /dev/null +++ b/src/ctrl/euiCheckKeepButton.cpp @@ -0,0 +1,39 @@ +#include "euiCheckKeepButton.h" + +namespace eui { + +const char* CheckKeepButton::getClassName() const { + return "CheckKeepButton"; +} + +CheckKeepButton::CheckKeepButton(const CheckKeepButton& other, LayoutEx* layout, sead::Heap* heap) + : CheckButton(other, layout, heap) {} + +void CheckKeepButton::Uncheck() { + if (mIsCheckEnabled) { + if (mIsChecked) { + if (!AnimButton::IsPlayDisableAnim()) { + if (mCheckAnimator) { + mCheckAnimator->Play(Animator::Once, -1.0); + } + mIsChecked = false; + } + } + } +} + +void CheckKeepButton::StartDown() { + AnimButton::StartDown(); + if (mIsCheckEnabled) { + if (!mIsChecked) { + if (!AnimButton::IsPlayDisableAnim()) { + if (mCheckAnimator) { + mCheckAnimator->Play(Animator::Once, 1.0); + } + mIsChecked = true; + } + } + } +} + +} // namespace eui