Skip to content

Commit

Permalink
Ported noticeboard from PC
Browse files Browse the repository at this point in the history
  • Loading branch information
NSGolova committed Dec 3, 2024
1 parent 058f707 commit 76344f2
Show file tree
Hide file tree
Showing 66 changed files with 2,781 additions and 27 deletions.
Binary file modified assets/bl.bundle
Binary file not shown.
24 changes: 24 additions & 0 deletions include/Assets/BundleLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ DECLARE_CLASS_CODEGEN(BeatLeader, Bundle, MonoBehaviour,
DECLARE_INSTANCE_FIELD(Material*, miniProfileBackgroundMaterial);
DECLARE_INSTANCE_FIELD(Material*, skillTriangleMaterial);
DECLARE_INSTANCE_FIELD(Material*, clanTagBackgroundMaterial);
DECLARE_INSTANCE_FIELD(Material*, roundTexture10Material);
DECLARE_INSTANCE_FIELD(Material*, roundTexture2Material);

DECLARE_INSTANCE_FIELD(Sprite*, locationIcon);
DECLARE_INSTANCE_FIELD(Sprite*, rowSeparatorIcon);
Expand Down Expand Up @@ -75,8 +77,30 @@ DECLARE_CLASS_CODEGEN(BeatLeader, Bundle, MonoBehaviour,
DECLARE_INSTANCE_FIELD(Sprite*, settingsIcon);

DECLARE_INSTANCE_FIELD(Sprite*, generalContextIcon);
DECLARE_INSTANCE_FIELD(Sprite*, unknownIcon);
DECLARE_INSTANCE_FIELD(Shader*, TMP_SpriteCurved);

DECLARE_INSTANCE_FIELD(Sprite*, BlackTransparentBG);
DECLARE_INSTANCE_FIELD(Sprite*, BlackTransparentBGOutline);
DECLARE_INSTANCE_FIELD(Sprite*, CyanBGOutline);
DECLARE_INSTANCE_FIELD(Sprite*, WhiteBG);
DECLARE_INSTANCE_FIELD(Sprite*, ClosedDoorIcon);
DECLARE_INSTANCE_FIELD(Sprite*, OpenedDoorIcon);
DECLARE_INSTANCE_FIELD(Sprite*, EditLayoutIcon);
DECLARE_INSTANCE_FIELD(Sprite*, ReplayerSettingsIcon);
DECLARE_INSTANCE_FIELD(Sprite*, LeftArrowIcon);
DECLARE_INSTANCE_FIELD(Sprite*, RightArrowIcon);
DECLARE_INSTANCE_FIELD(Sprite*, PlayIcon);
DECLARE_INSTANCE_FIELD(Sprite*, PauseIcon);
DECLARE_INSTANCE_FIELD(Sprite*, LockIcon);
DECLARE_INSTANCE_FIELD(Sprite*, WarningIcon);
DECLARE_INSTANCE_FIELD(Sprite*, CrossIcon);
DECLARE_INSTANCE_FIELD(Sprite*, PinIcon);
DECLARE_INSTANCE_FIELD(Sprite*, AlignIcon);
DECLARE_INSTANCE_FIELD(Sprite*, AnchorIcon);
DECLARE_INSTANCE_FIELD(Sprite*, ProgressRingIcon);
DECLARE_INSTANCE_FIELD(Sprite*, RotateRightIcon);

DECLARE_INSTANCE_METHOD(void, Init, AssetBundle* bundle);
DECLARE_INSTANCE_METHOD(Material*, GetAvatarMaterial, StringW effectName);
DECLARE_INSTANCE_METHOD(Sprite*, GetCountryIcon, StringW country);
Expand Down
92 changes: 92 additions & 0 deletions include/UI/Abstract/AbstractReeModal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#pragma once

#include "HMUI/ImageView.hpp"
#include "UI/ReeUIComponentV2.hpp"
#include "UI/Abstract/IReeModal.hpp"
#include "UnityEngine/GameObject.hpp"
#include "System/Action.hpp"
#include "main.hpp"

namespace BeatLeader {

template<typename C = BeatLeader::ReeComponent*>
requires(std::is_convertible_v<C, BeatLeader::ReeComponent*>)
class AbstractReeModal : public ReeUIComponentV2<C>, public IReeModal {
protected:
System::Action* closeAction;
bool offClickCloses;

public:
virtual void OnInitialize() override {
auto* bg = this->LocalComponent()->_content->template GetComponent<HMUI::ImageView*>();
if (bg != nullptr) {
bg->set_raycastTarget(true);
}
offClickCloses = true;
}

virtual void OnContextChanged() {
// Virtual - implemented by derived classes
}

virtual void OnResume() {
// Virtual - implemented by derived classes
}

virtual void OnPause() {
// Virtual - implemented by derived classes
}

virtual void OnInterrupt() {
// Virtual - implemented by derived classes
}

virtual void OnOffClick() {
BeatLeaderLogger.error("OnOffClick");
if (offClickCloses) {
Close();
}
}

void ClearContext() {
// Context handling will be implemented by derived classes
}

virtual void SetContext(Il2CppObject* context) {
// Context handling will be implemented by derived classes
OnContextChanged();
}

// IReeModal implementation
void Resume(void* state, System::Action* closeAction) override {
this->closeAction = closeAction;
SetContext(reinterpret_cast<Il2CppObject*>(state));
this->LocalComponent()->get_gameObject()->SetActive(true);
this->LocalComponent()->_content->get_gameObject()->SetActive(true);
OnResume();
}

void Pause() override {
this->LocalComponent()->get_gameObject()->SetActive(false);
this->LocalComponent()->_content->get_gameObject()->SetActive(false);
OnPause();
}

void Interrupt() override {
this->LocalComponent()->get_gameObject()->SetActive(false);
this->LocalComponent()->_content->get_gameObject()->SetActive(false);
OnInterrupt();
}

void Close() override {
if (closeAction != nullptr) {
closeAction->Invoke();
}
}

void HandleOffClick() override {
OnOffClick();
}
};

} // namespace BeatLeader
16 changes: 16 additions & 0 deletions include/UI/Abstract/IReeModal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "custom-types/shared/macros.hpp"
#include "System/Action.hpp"

namespace BeatLeader {
class IReeModal {
public:
virtual ~IReeModal() = default;
virtual void Resume(void* state, System::Action* closeAction) = 0;
virtual void Pause() = 0;
virtual void Interrupt() = 0;
virtual void Close() = 0;
virtual void HandleOffClick() = 0;
};
}
119 changes: 119 additions & 0 deletions include/UI/Abstract/ReeModalSystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#pragma once

#include "UnityEngine/Transform.hpp"
#include "UnityEngine/GameObject.hpp"
#include "HMUI/Screen.hpp"
#include "HMUI/ModalView.hpp"
#include "HMUI/ImageView.hpp"
#include "UnityEngine/MonoBehaviour.hpp"
#include "System/Collections/Generic/Dictionary_2.hpp"
#include "System/Collections/Generic/Stack_1.hpp"
#include "System/Action.hpp"
#include "UI/Abstract/AbstractReeModal.hpp"
#include "UI/ReeUIComponentV2.hpp"
#include "UnityEngine/SceneManagement/Scene.hpp"
#include "UnityEngine/SceneManagement/SceneManager.hpp"

#include <unordered_map>
#include <stack>

DECLARE_CLASS_CUSTOM(BeatLeader, ReeModalSystemComponent, BeatLeader::ReeComponent,
DECLARE_INSTANCE_FIELD(UnityEngine::Transform*, _container);
DECLARE_INSTANCE_FIELD(HMUI::ModalView*, _modalView);
DECLARE_INSTANCE_FIELD(HMUI::Screen*, _screen);
)

namespace BeatLeader {

class ReeModalSystem : public ReeUIComponentV2<BeatLeader::ReeModalSystemComponent*> {
private:
static std::unordered_map<int, ReeModalSystem*> activeModals;
static System::Action* interruptAllEvent;

std::unordered_map<std::string, IReeModal*> pool;
std::stack<std::pair<IReeModal*, Il2CppObject*>> modalStack;
IReeModal* activeModal;
Il2CppObject* activeModalState;
bool hasActiveModal;

void PopOpen(IReeModal* modal, Il2CppObject* state);
void OpenImmediately();
void CloseOrPop();
void OnActiveSceneChanged(UnityEngine::SceneManagement::Scene from, UnityEngine::SceneManagement::Scene to);

public:
void Construct(HMUI::Screen* screen);
void OnInitialize() override;
void OnDispose() override;
void OnDisable();
void InitializeModal();
void OnBlockerClicked();
void ShowModal(bool animated);
void HideModal(bool animated);
void InterruptAll();
void ForceUpdate();
StringW GetContent() override;

template<typename T>
static void OpenModal(UnityEngine::Transform* screenChild, Il2CppObject* state)
requires std::is_base_of_v<IReeModal, T> &&
std::is_base_of_v<ReeUIComponentV2<typename T::ComponentType>, T>
{
auto screen = screenChild->GetComponentInParent<HMUI::Screen*>();
OpenModal<T>(screen, state);
}

template<typename T>
static void OpenModal(HMUI::Screen* screen, Il2CppObject* state, bool interruptActiveModals = true)
requires std::is_base_of_v<IReeModal, T> &&
std::is_base_of_v<ReeUIComponentV2<typename T::ComponentType>, T>
{
ReeModalSystem* controller;
int key = screen->GetHashCode();

auto it = activeModals.find(key);
if (it != activeModals.end()) {
controller = it->second;
} else {
controller = ReeModalSystem::Instantiate<ReeModalSystem>(screen->get_transform());
controller->Construct(screen);
controller->LocalComponent()->ManualInit(screen->get_transform());
activeModals[key] = controller;
}

if (interruptActiveModals) {
if (interruptAllEvent) interruptAllEvent->Invoke();
}

controller->OpenModalInternal<T>(state);
}

template<typename T>
BeatLeader::IReeModal* GetOrInstantiateModal()
requires std::is_base_of_v<IReeModal, T> &&
std::is_base_of_v<ReeUIComponentV2<typename T::ComponentType>, T>
{
auto type = (std::string)typeid(T).name();
auto it = pool.find(type);
if (it != pool.end()) return it->second;

auto component = T::template Instantiate<T>(LocalComponent()->_container);
component->LocalComponent()->ManualInit(LocalComponent()->_container);

pool[type] = component;
return component;
}

template<typename T>
void OpenModalInternal(Il2CppObject* state)
requires std::is_base_of_v<IReeModal, T> &&
std::is_base_of_v<ReeUIComponentV2<typename T::ComponentType>, T>
{
auto modal = GetOrInstantiateModal<T>();
PopOpen(modal, state);
}

static void ForceUpdateAll();
};

} // namespace BeatLeader
16 changes: 16 additions & 0 deletions include/UI/BSML_Addons/BSMLAddonsLoader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// #pragma once

// #include <unordered_map>
// #include <string>
// #include "UnityEngine/Sprite.hpp"

// namespace BeatLeader::UI::BSML_Addons {
// class BSMLAddonsLoader {
// private:
// static bool ready;
// static std::unordered_map<std::string, UnityEngine::Sprite*> spritesToCache;

// public:
// static void LoadAddons();
// };
// }
15 changes: 15 additions & 0 deletions include/UI/BSML_Addons/BetterButtonHandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "bsml/shared/BSML/TypeHandlers/TypeHandler.hpp"
#include "UI/BSML_Addons/Components/BetterButton.hpp"

namespace BeatLeader::UI::TypeHandlers {
class BetterButtonHandler : public BSML::TypeHandler<BeatLeader::UI::BSML_Addons::BetterButton*> {
using Base = TypeHandler<BeatLeader::UI::BSML_Addons::BetterButton*>;
using Base::Base;

virtual Base::PropMap get_props() const override;
virtual Base::SetterMap get_setters() const override;
virtual void HandleType(const BSML::ComponentTypeWithData& componentType, BSML::BSMLParserParams& parserParams) override;
};
}
20 changes: 20 additions & 0 deletions include/UI/BSML_Addons/BetterImageHandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "bsml/shared/BSML/TypeHandlers/TypeHandler.hpp"
#include "UI/BSML_Addons/Components/BetterImage.hpp"
#include "UnityEngine/UI/Image.hpp"

namespace BeatLeader::UI::TypeHandlers {
class BetterImageHandler : public BSML::TypeHandler<BeatLeader::UI::BSML_Addons::BetterImage*> {
using Base = TypeHandler<BeatLeader::UI::BSML_Addons::BetterImage*>;
using Base::Base;

virtual Base::PropMap get_props() const override;
virtual Base::SetterMap get_setters() const override;
virtual void HandleType(const BSML::ComponentTypeWithData& componentType, BSML::BSMLParserParams& parserParams) override;

public:
static void HandleImage(const std::map<std::string, std::string>& data, UnityEngine::UI::Image* image);
static void HandleImage(const std::map<std::string, std::string>& data, UnityEngine::UI::Image* image, const std::string& prefix);
};
}
22 changes: 22 additions & 0 deletions include/UI/BSML_Addons/Components/BetterButton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "UnityEngine/UI/Button.hpp"
#include "UnityEngine/UI/Image.hpp"
#include "UnityEngine/MonoBehaviour.hpp"
#include "custom-types/shared/macros.hpp"
#include "UI/BSML_Addons/Tags/BetterButtonTag.hpp"

namespace BeatLeader::UI::BSML_Addons {
class BetterButtonTag;
}

DECLARE_CLASS_CODEGEN(BeatLeader::UI::BSML_Addons, BetterButton, UnityEngine::MonoBehaviour,
DECLARE_INSTANCE_FIELD(UnityEngine::UI::Button*, button);
DECLARE_INSTANCE_FIELD(UnityEngine::UI::Image*, targetGraphic);
DECLARE_CTOR(ctor);

DECLARE_INSTANCE_METHOD(void, Init, UnityEngine::UI::Button* btn, UnityEngine::UI::Image* graphic);

private:
friend class ::BeatLeader::UI::BSML_Addons::BetterButtonTag;
)
9 changes: 9 additions & 0 deletions include/UI/BSML_Addons/Components/BetterImage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "UnityEngine/MonoBehaviour.hpp"
#include "UI/BSML_Addons/Components/FixedImageView.hpp"
#include "custom-types/shared/macros.hpp"

DECLARE_CLASS_CODEGEN(BeatLeader::UI::BSML_Addons, BetterImage, UnityEngine::MonoBehaviour,
DECLARE_INSTANCE_FIELD(BeatLeader::UI::BSML_Addons::FixedImageView*, image);
)
6 changes: 6 additions & 0 deletions include/UI/BSML_Addons/Components/FixedImageView.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "HMUI/ImageView.hpp"
#include "custom-types/shared/macros.hpp"

DECLARE_CLASS_CODEGEN(BeatLeader::UI::BSML_Addons, FixedImageView, HMUI::ImageView)
12 changes: 12 additions & 0 deletions include/UI/BSML_Addons/Tags/BetterButtonTag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "bsml/shared/BSML/Tags/BSMLTag.hpp"

namespace BeatLeader::UI::BSML_Addons {
class BetterButtonTag : public BSML::BSMLTag {
public:
BetterButtonTag() : BSMLTag() {}
protected:
UnityEngine::GameObject* CreateObject(UnityEngine::Transform* parent) const override;
};
}
Loading

0 comments on commit 76344f2

Please sign in to comment.