Skip to content

Commit

Permalink
Merge pull request #4 from CGray1234/ui-rewrite
Browse files Browse the repository at this point in the history
UI rewrite
  • Loading branch information
CGray1234 authored Nov 6, 2022
2 parents ab0262f + 48abdef commit 31d48e6
Show file tree
Hide file tree
Showing 21 changed files with 558 additions and 189 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"format": "cpp"
"format": "cpp",
"stop_token": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
1 change: 1 addition & 0 deletions include/Config.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "config-utils/shared/config-utils.hpp"
#include "UnityEngine/Color.hpp"

DECLARE_CONFIG(ModConfig,

Expand Down
5 changes: 5 additions & 0 deletions include/Images/MiscSettingsIcon.hpp

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions include/Images/PositionSettingsIcon.hpp

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions include/Images/RotationSettingsIcon.hpp

Large diffs are not rendered by default.

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

#include "custom-types/shared/macros.hpp"
#include "custom-types/shared/register.hpp"
#include "questui/shared/BeatSaberUI.hpp"
#include "questui/shared/QuestUI.hpp"
#include "ViewController.hpp"
#include "main.hpp"

DECLARE_CLASS_CODEGEN(InGameText, InGameTextFlowCoordinator, HMUI::FlowCoordinator,
DECLARE_INSTANCE_FIELD(InGameText::InGameTextViewController*, inGameTextViewController);
DECLARE_INSTANCE_FIELD(HMUI::ViewController*, currentViewController);

DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "FlowCoordinator", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling);
DECLARE_OVERRIDE_METHOD(void, BackButtonWasPressed, il2cpp_utils::FindMethodUnsafe("HMUI", "FlowCoordinator", "BackButtonWasPressed", 1), HMUI::ViewController* topViewController);
)
32 changes: 32 additions & 0 deletions include/UI/GameplaySetupView.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "custom-types/shared/macros.hpp"
#include "UnityEngine/MonoBehaviour.hpp"

#include "questui/shared/CustomTypes/Components/Settings/ColorSetting.hpp"
#include "questui/shared/CustomTypes/Components/Settings/IncrementSetting.hpp"

#include "HMUI/InputFieldView.hpp"

using namespace UnityEngine;

DECLARE_CLASS_CODEGEN(InGameText, gameplaySetupView, UnityEngine::MonoBehaviour,
//Misc
DECLARE_INSTANCE_FIELD(QuestUI::ColorSetting*, QolorPicker);
DECLARE_INSTANCE_FIELD(HMUI::InputFieldView*, TextSetting);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, SizeSetting);

//Pos
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, PosX);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, PosY);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, PosZ);

//Rot
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, RotX);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, RotY);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, RotZ);

DECLARE_INSTANCE_METHOD(void, DidActivate, bool firstActivation);


);
13 changes: 13 additions & 0 deletions include/UI/MiscViewController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "main.hpp"

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

#define GET_FIND_METHOD(mPtr) il2cpp_utils::il2cpp_type_check::MetadataGetter<mPtr>::get()

DECLARE_CLASS_CODEGEN(InGameText, MiscViewController, HMUI::ViewController,
DECLARE_OVERRIDE_METHOD(void, DidActivate, GET_FIND_METHOD(&ViewController::DidActivate), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling);
)
13 changes: 13 additions & 0 deletions include/UI/PositionViewController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "main.hpp"

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

#define GET_FIND_METHOD(mPtr) il2cpp_utils::il2cpp_type_check::MetadataGetter<mPtr>::get()

DECLARE_CLASS_CODEGEN(InGameText, PositionViewController, HMUI::ViewController,
DECLARE_OVERRIDE_METHOD(void, DidActivate, GET_FIND_METHOD(&ViewController::DidActivate), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling);
)
13 changes: 13 additions & 0 deletions include/UI/RotationViewController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "main.hpp"

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

#define GET_FIND_METHOD(mPtr) il2cpp_utils::il2cpp_type_check::MetadataGetter<mPtr>::get()

DECLARE_CLASS_CODEGEN(InGameText, RotationViewController, HMUI::ViewController,
DECLARE_OVERRIDE_METHOD(void, DidActivate, GET_FIND_METHOD(&ViewController::DidActivate), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling);
)
20 changes: 14 additions & 6 deletions include/UI/ViewController.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#pragma once

#include "custom-types/shared/register.hpp"
#include "custom-types/shared/macros.hpp"
#include "HMUI/ViewController.hpp"
#include "custom-types/shared/register.hpp"
#include "questui/shared/BeatSaberUI.hpp"
#include "questui/shared/QuestUI.hpp"

DECLARE_CLASS_CODEGEN(InGameText, InGameTextViewController, HMUI::ViewController,
DECLARE_INSTANCE_FIELD(HMUI::FlowCoordinator*, flowCoordinator);

DECLARE_INSTANCE_FIELD(UnityEngine::UI::Button*, positionButton);
DECLARE_INSTANCE_FIELD(UnityEngine::UI::Button*, miscButton);
DECLARE_INSTANCE_FIELD(UnityEngine::UI::Button*, rotationButton);

DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling);

#define GET_FIND_METHOD(mPtr) il2cpp_utils::il2cpp_type_check::MetadataGetter<mPtr>::get()
public:

DECLARE_CLASS_CODEGEN(InGameText, TextViewController, HMUI::ViewController,
DECLARE_OVERRIDE_METHOD(void, DidActivate, GET_FIND_METHOD(&ViewController::DidActivate), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling);
DECLARE_OVERRIDE_METHOD(void, DidDeactivate, GET_FIND_METHOD(&ViewController::DidDeactivate), bool removedFromHierarchy, bool screenSystemDisabling);
UnityEngine::UI::Button* CreateViewControllerButton(UnityEngine::Transform* parent, std::string title, std::string description, HMUI::ViewController* viewController);
)
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "In-Game Text",
"id": "InGameText",
"author": "CGray1234",
"version": "0.3.2",
"version": "1.0.0",
"packageId": "com.beatgames.beatsaber",
"packageVersion": "1.25.1",
"description": "Add in some text in-game while you're playing a level! Like ImageFactory, but text",
Expand Down
2 changes: 1 addition & 1 deletion qpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"info": {
"name": "In-Game Text",
"id": "InGameText",
"version": "0.3.2",
"version": "1.0.0",
"url": null,
"additionalData": {
"overrideSoName": "libInGameText.so"
Expand Down
40 changes: 40 additions & 0 deletions src/UI/FlowCoordinator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "UI/FlowCoordinator.hpp"
#include "UI/ViewController.hpp"
#include "GlobalNamespace/MenuTransitionsHelper.hpp"
#include "HMUI/ViewController_AnimationDirection.hpp"
#include "HMUI/ViewController_AnimationType.hpp"

DEFINE_TYPE(InGameText, InGameTextFlowCoordinator);

void InGameText::InGameTextFlowCoordinator::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) {
using namespace HMUI;

if (firstActivation) {
SetTitle(ID, ViewController::AnimationType::Out);

showBackButton = true;

inGameTextViewController = QuestUI::BeatSaberUI::CreateViewController<InGameText::InGameTextViewController*>();
inGameTextViewController->flowCoordinator = this;

currentViewController = nullptr;

ProvideInitialViewControllers(inGameTextViewController, nullptr, nullptr, nullptr, nullptr);
}
}

void InGameText::InGameTextFlowCoordinator::BackButtonWasPressed(
HMUI::ViewController* topViewController
) {
using namespace HMUI;
using namespace UnityEngine;

if (currentViewController) {
SetTitle(ID, ViewController::AnimationType::In);
ReplaceTopViewController(inGameTextViewController, this, this, nullptr, ViewController::AnimationType::Out, ViewController::AnimationDirection::Horizontal);

currentViewController = nullptr;
} else {
parentFlowCoordinator->DismissFlowCoordinator(this, ViewController::AnimationDirection::Horizontal, nullptr, false);
}
}
86 changes: 86 additions & 0 deletions src/UI/GameplaySetupView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "questui/shared/BeatSaberUI.hpp"
#include "questui/shared/QuestUI.hpp"
#include "Config.hpp"
#include "UI/GameplaySetupView.hpp"

#include "UnityEngine/RectOffset.hpp"

DEFINE_TYPE(InGameText, gameplaySetupView);

using namespace UnityEngine::UI;
using namespace UnityEngine;
using namespace QuestUI::BeatSaberUI;

void InGameText::gameplaySetupView::DidActivate(bool firstActivation) {
if (!firstActivation) return;

auto verticalLayoutGroup = CreateVerticalLayoutGroup(get_transform());
verticalLayoutGroup->get_rectTransform()->set_anchoredPosition({0.0f, 0.0f});
verticalLayoutGroup->set_padding(RectOffset::New_ctor(2, 2, 2, 2));
auto verticalLayoutGroupElement = verticalLayoutGroup->GetComponent<LayoutElement*>();
verticalLayoutGroupElement->set_preferredHeight(65.0f);
verticalLayoutGroupElement->set_preferredWidth(70.0f);
auto verticalLayoutGroupFitter = verticalLayoutGroup->GetComponent<ContentSizeFitter*>();
verticalLayoutGroupFitter->set_verticalFit(ContentSizeFitter::FitMode::PreferredSize);
verticalLayoutGroupFitter->set_horizontalFit(ContentSizeFitter::FitMode::PreferredSize);

CreateText(verticalLayoutGroup->get_transform(), "----Miscellaneous Settings----")->set_alignment(TMPro::TextAlignmentOptions::Center);

InGameText::gameplaySetupView::TextSetting = CreateStringSetting(verticalLayoutGroup->get_transform(), "In-Game Text", getModConfig().InGameText.GetValue(),
[](std::string value) {
getModConfig().InGameText.SetValue(value);
}
);

InGameText::gameplaySetupView::QolorPicker = CreateColorPicker(verticalLayoutGroup->get_transform(), "Text Color", getModConfig().TextQolor.GetValue(),
[=](UnityEngine::Color value) {
getModConfig().TextQolor.SetValue(value);
}
);

InGameText::gameplaySetupView::SizeSetting = CreateIncrementSetting(verticalLayoutGroup->get_transform(), "Text Size", 1, 0.5, getModConfig().TextSize.GetValue(),
[=](float value) {
getModConfig().TextSize.SetValue(value);
}
);

CreateText(verticalLayoutGroup->get_transform(), "----Position Settings----")->set_alignment(TMPro::TextAlignmentOptions::Center);

InGameText::gameplaySetupView::PosX = CreateIncrementSetting(verticalLayoutGroup->get_transform(), "Text Position X", 1, 0.1, getModConfig().PositionX.GetValue(),
[=](float value) {
getModConfig().PositionX.SetValue(value);
}
);

InGameText::gameplaySetupView::PosY = CreateIncrementSetting(verticalLayoutGroup->get_transform(), "Text Position Y", 1, 0.1, getModConfig().PositionY.GetValue(),
[=](float value) {
getModConfig().PositionY.SetValue(value);
}
);

InGameText::gameplaySetupView::PosZ = CreateIncrementSetting(verticalLayoutGroup->get_transform(), "Text Position Z", 1, 0.1, getModConfig().PositionZ.GetValue(),
[=](float value) {
getModConfig().PositionZ.SetValue(value);
}
);

CreateText(verticalLayoutGroup->get_transform(), "----Rotation Settings----")->set_alignment(TMPro::TextAlignmentOptions::Center);

InGameText::gameplaySetupView::RotX = CreateIncrementSetting(verticalLayoutGroup->get_transform(), "Text Rotation X", 1, 1, getModConfig().RotationX.GetValue(),
[=](float value) {
getModConfig().RotationX.SetValue(value);
}
);

InGameText::gameplaySetupView::RotX = CreateIncrementSetting(verticalLayoutGroup->get_transform(), "Text Rotation Y", 1, 1, getModConfig().RotationY.GetValue(),
[=](float value) {
getModConfig().RotationY.SetValue(value);
}
);

InGameText::gameplaySetupView::RotX = CreateIncrementSetting(verticalLayoutGroup->get_transform(), "Text Rotation Z", 1, 1, getModConfig().RotationZ.GetValue(),
[=](float value) {
getModConfig().RotationZ.SetValue(value);
}
);
}
74 changes: 74 additions & 0 deletions src/UI/MiscViewController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "Config.hpp"
#include "UI/MiscViewController.hpp"

#include "TMPro/TextMeshProUGUI.hpp"

#include "questui/shared/BeatSaberUI.hpp"
#include "questui/shared/QuestUI.hpp"

#include "Images/MiscSettingsIcon.hpp"

#include "GlobalNamespace/SimpleLevelStarter.hpp"
#include "GlobalNamespace/BeatmapLevelSO.hpp"
#include "GlobalNamespace/GameplayModifiers.hpp"

DEFINE_TYPE(InGameText, MiscViewController);

void StartTestLevel(InGameText::MiscViewController* self) {
ArrayW<GlobalNamespace::SimpleLevelStarter*> levelStartArray = UnityEngine::Resources::FindObjectsOfTypeAll<GlobalNamespace::SimpleLevelStarter*>();
for (int i = 0; i < sizeof(levelStartArray); i++)
{
GlobalNamespace::SimpleLevelStarter* start = (GlobalNamespace::SimpleLevelStarter*)levelStartArray->values[i];
if (start->get_gameObject()->get_name()->Contains("PerformanceTestLevelButton"))
{
start->gameplayModifiers->zenMode = true;
start->level->songName = ("In-Game Text Config Test");
start->StartLevel();
return;
}
}
}

void InGameText::MiscViewController::DidActivate(
bool firstActivation,
bool addedToHierarchy,
bool screenSystemEnabling
) {
using namespace UnityEngine;
using namespace QuestUI::BeatSaberUI;
using namespace UnityEngine::UI;

if (firstActivation) {
GameObject* container = CreateScrollableSettingsContainer(get_transform());

UnityEngine::Sprite* MiscImage = Base64ToSprite(MiscSettingsIcon);

CreateImage(container->get_transform(), MiscImage, Vector2::get_zero(), Vector2(75.0f, 75.0f));

QuestUI::BeatSaberUI::CreateStringSetting(container->get_transform(), "In-Game Text", getModConfig().InGameText.GetValue(),
[=](std::string value) {
getModConfig().InGameText.SetValue(value);
}
);

QuestUI::BeatSaberUI::CreateColorPicker(container->get_transform(), "Text Color", getModConfig().TextQolor.GetValue(),
[=](UnityEngine::Color value) {
getModConfig().TextQolor.SetValue(value);
}
);

QuestUI::BeatSaberUI::CreateIncrementSetting(container->get_transform(), "Text Size", 1, 0.5, getModConfig().TextSize.GetValue(),
[=](float value) {
getModConfig().TextSize.SetValue(value);
}
);

QuestUI::BeatSaberUI::CreateText(container->get_transform(), "");

auto testButton = QuestUI::BeatSaberUI::CreateUIButton(container->get_transform(), "Test Configuration", "PlayButton",
[&]() {
StartTestLevel(this);
}
);
}
}
Loading

0 comments on commit 31d48e6

Please sign in to comment.