will revert this later

This commit is contained in:
HJfod 2022-10-17 12:25:56 +03:00
parent 86c1956790
commit 843b1ac44f
8 changed files with 150 additions and 88 deletions

View file

@ -16,6 +16,10 @@ namespace geode::modifier {{
using Base = {class_name};
static void apply() {{
using namespace geode::core::meta;
if constexpr (HasStringIDProvider<Derived>) {{
geode::NodeStringIDManager::get()->registerProvider("{class_name}", &Derived::provideStringIDs);
}}
)GEN";
// requires: index, class_name, arg_types, function_name, raw_arg_types, non_virtual

View file

@ -0,0 +1,37 @@
#pragma once
#include "../DefaultInclude.hpp"
namespace cocos2d {
class CCNode;
}
namespace geode {
class GEODE_DLL NodeStringIDManager {
public:
template<class T>
using Provider = void(GEODE_CALL*)(T*);
protected:
std::unordered_map<std::string, Provider<cocos2d::CCNode>> m_providers;
public:
static NodeStringIDManager* get();
template<class T>
void registerProvider(std::string const& id, void(GEODE_CALL* fun)(T*)) {
m_providers.insert({ id, static_cast<Provider<cocos2d::CCNode>>(fun) });
}
bool provide(std::string const& id, cocos2d::CCNode* layer);
};
}
#define $register_ids(Layer_, Var_) \
void GEODE_CALL GEODE_CONCAT(addIDs, Layer_)(Layer_*);\
$execute {\
StringIDManager::get()->registerProvider(#Layer_, &GEODE_CONCAT(addIDs, Layer_));\
};\
void GEODE_CALL GEODE_CONCAT(addIDs, Layer_)(Layer_* Var_)

View file

@ -1,4 +1,5 @@
#include <type_traits>
#include "IDManager.hpp"
/**
* Main class implementation, it has the structure
@ -35,6 +36,10 @@ namespace {
derived##Intermediate, \
derived<derived##Parent> \
> m_fields; \
template<class = void> \
bool addStringIDs() { \
return geode::NodeStringIDManager::get()->provide(#base, this); \
} \
}; \
} \
template <> struct GEODE_HIDDEN derived<derived##Parent> : derived##Intermediate \
@ -49,6 +54,10 @@ namespace {
derived##Intermediate, \
derived \
> m_fields; \
template<class = void> \
bool addStringIDs() { \
return geode::NodeStringIDManager::get()->provide(#base, this); \
} \
}; \
} \
struct GEODE_HIDDEN derived : derived##Intermediate \

View file

@ -6,6 +6,7 @@
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Mod.hpp>
#include <iostream>
#include "IDManager.hpp"
#define GEODE_APPLY_MODIFY_FOR_FUNCTION(index, convention, className, functionName) \
using base##index = wrap::functionName<Base, types::pure##index>; \
@ -17,6 +18,10 @@ if constexpr (derived##index::uuid != nullptr && (void*)base##index::uuid != (vo
); \
} \
template<class T>
concept HasStringIDProvider = requires {
T::provideStringIDs();
};
namespace geode::modifier {
template <class Derived, class Base>

View file

@ -67,23 +67,6 @@ static void updateIndexProgress(
}
}
template<class T = CCNode>
requires std::is_base_of_v<CCNode, T>
T* setIDSafe(CCNode* node, int index, const char* id) {
if constexpr (std::is_same_v<CCNode, T>) {
if (auto child = getChild(node, index)) {
child->setID(id);
return child;
}
} else {
if (auto child = getChildOfType<T>(node, index)) {
child->setID(id);
return child;
}
}
return nullptr;
}
#include <Geode/modify/MenuLayer.hpp>
class $modify(CustomMenuLayer, MenuLayer) {
void destructor() {

View file

@ -0,0 +1,16 @@
#include <Geode/modify/IDManager.hpp>
using namespace geode;
NodeStringIDManager* NodeStringIDManager::get() {
static auto inst = new NodeStringIDManager;
return inst;
}
bool NodeStringIDManager::provide(std::string const& id, cocos2d::CCNode* layer) {
if (m_providers.count(id)) {
m_providers.at(id)(layer);
return true;
}
return false;
}

View file

@ -22,7 +22,7 @@ class $modify(LevelBrowserLayer) {
setIDSafe(menu, 0, "back-button");
}
if (search->m_searchType == SearchType::MyLevels) {
if (m_searchObject->m_searchType == SearchType::MyLevels) {
if (auto menu = getChildOfType<CCMenu>(this, 1)) {
menu->setID("new-level-menu");
setIDSafe(menu, 0, "new-level-button");

View file

@ -1,91 +1,99 @@
#include <Geode/Modify.hpp>
#include <Geode/Bindings.hpp>
#include <Geode/modify/MenuLayer.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/ui/EnterLayerEvent.hpp>
#include "AddIDs.hpp"
USE_GEODE_NAMESPACE();
void addIDsToMenuLayer(MenuLayer* layer) {
// set IDs to everything
layer->setID("MenuLayer");
setIDSafe(layer, 0, "main-menu-bg");
setIDSafe<CCSprite>(layer, 0, "main-title");
class $modify(CustomMenuLayer, MenuLayer) {
void provideStringIDs() {
// set IDs to everything
this->setID("MenuLayer");
setIDSafe(this, 0, "main-menu-bg");
setIDSafe<CCSprite>(this, 0, "main-title");
// controller
if (PlatformToolbox::isControllerConnected()) {
setIDSafe<CCSprite>(layer, 1, "play-gamepad-icon");
setIDSafe<CCSprite>(layer, 2, "editor-gamepad-icon");
setIDSafe<CCSprite>(layer, 3, "icon-kit-gamepad-icon");
// controller
if (PlatformToolbox::isControllerConnected()) {
setIDSafe<CCSprite>(this, 1, "play-gamepad-icon");
setIDSafe<CCSprite>(this, 2, "editor-gamepad-icon");
setIDSafe<CCSprite>(this, 3, "icon-kit-gamepad-icon");
setIDSafe<CCSprite>(layer, 4, "settings-gamepad-icon");
setIDSafe<CCSprite>(layer, 5, "mouse-gamepad-icon");
setIDSafe<CCSprite>(layer, 6, "click-gamepad-icon");
setIDSafe<CCSprite>(this, 4, "settings-gamepad-icon");
setIDSafe<CCSprite>(this, 5, "mouse-gamepad-icon");
setIDSafe<CCSprite>(this, 6, "click-gamepad-icon");
setIDSafe<CCLabelBMFont>(layer, 0, "mouse-gamepad-label");
setIDSafe<CCLabelBMFont>(layer, 1, "click-gamepad-label");
setIDSafe<CCLabelBMFont>(this, 0, "mouse-gamepad-label");
setIDSafe<CCLabelBMFont>(this, 1, "click-gamepad-label");
setIDSafe<CCLabelBMFont>(layer, 2, "player-username");
} else {
setIDSafe<CCLabelBMFont>(layer, 0, "player-username");
}
// main menu
if (auto menu = getChildOfType<CCMenu>(layer, 0)) {
menu->setID("main-menu");
auto playBtn = setIDSafe(menu, 0, "play-button");
auto iconBtn = setIDSafe(menu, 1, "icon-kit-button");
// the buttons are added in order play, icon, editor which doesn't work
// well with setLayout that deals with children in order
menu->swapChildIndices(playBtn, iconBtn);
setIDSafe(menu, 2, "editor-button");
if (auto pfp = setIDSafe(menu, 3, "profile-button")) {
pfp->setPositionHint(PositionHint::Absolute);
setIDSafe<CCLabelBMFont>(this, 2, "player-username");
} else {
setIDSafe<CCLabelBMFont>(this, 0, "player-username");
}
// main menu
if (auto menu = getChildOfType<CCMenu>(this, 0)) {
menu->setID("main-menu");
auto playBtn = setIDSafe(menu, 0, "play-button");
auto iconBtn = setIDSafe(menu, 1, "icon-kit-button");
menu->setLayout(RowLayout::create(18.f, 0.f));
}
// bottom menu
if (auto menu = getChildOfType<CCMenu>(layer, 1)) {
menu->setID("bottom-menu");
auto ach = setIDSafe(menu, 0, "achievements-button");
setIDSafe(menu, 1, "settings-button");
setIDSafe(menu, 2, "stats-button");
setIDSafe(menu, 3, "newgrounds-button");
// the buttons are added in order play, icon, editor which doesn't work
// well with setLayout that deals with children in order
menu->swapChildIndices(playBtn, iconBtn);
// move daily chest to its own menu
setIDSafe(menu, 2, "editor-button");
if (auto pfp = setIDSafe(menu, 3, "profile-button")) {
pfp->setPositionHint(PositionHint::Absolute);
}
if (auto dailyChest = setIDSafe(menu, -1, "daily-chest-button")) {
detachIntoOwnMenu(layer, dailyChest, "right-side-menu",
ColumnLayout::create(5.f, 0.f)
);
menu->setLayout(RowLayout::create(18.f, 0.f));
}
// bottom menu
if (auto menu = getChildOfType<CCMenu>(this, 1)) {
menu->setID("bottom-menu");
auto ach = setIDSafe(menu, 0, "achievements-button");
setIDSafe(menu, 1, "settings-button");
setIDSafe(menu, 2, "stats-button");
setIDSafe(menu, 3, "newgrounds-button");
menu->setLayout(RowLayout::create(5.f, ach->getPositionY()));
}
// social media menu
if (auto menu = getChildOfType<CCMenu>(layer, 2)) {
menu->setID("social-media-menu");
setIDSafe(menu, 0, "robtop-logo-button");
setIDSafe(menu, 1, "facebook-button");
setIDSafe(menu, 2, "twitter-button");
setIDSafe(menu, 3, "youtube-button");
}
// more games menu
if (auto menu = getChildOfType<CCMenu>(layer, 3)) {
menu->setID("more-games-menu");
setIDSafe(menu, 0, "more-games-button");
// move daily chest to its own menu
// move close button to its own menu
if (auto dailyChest = setIDSafe(menu, -1, "daily-chest-button")) {
detachIntoOwnMenu(this, dailyChest, "right-side-menu",
ColumnLayout::create(5.f, 0.f)
);
}
if (auto closeBtn = setIDSafe(menu, 1, "close-button")) {
detachIntoOwnMenu(layer, closeBtn, "close-menu",
RowLayout::create(5.f, 0.f)->setAlignment(Alignment::Begin)
);
menu->setLayout(RowLayout::create(5.f, ach->getPositionY()));
}
// social media menu
if (auto menu = getChildOfType<CCMenu>(this, 2)) {
menu->setID("social-media-menu");
setIDSafe(menu, 0, "robtop-logo-button");
setIDSafe(menu, 1, "facebook-button");
setIDSafe(menu, 2, "twitter-button");
setIDSafe(menu, 3, "youtube-button");
}
// more games menu
if (auto menu = getChildOfType<CCMenu>(this, 3)) {
menu->setID("more-games-menu");
setIDSafe(menu, 0, "more-games-button");
// move close button to its own menu
if (auto closeBtn = setIDSafe(menu, 1, "close-button")) {
detachIntoOwnMenu(this, closeBtn, "close-menu",
RowLayout::create(5.f, 0.f)->setAlignment(Alignment::Begin)
);
}
}
}
EnterLayerEvent("MenuLayer", layer).post();
}
bool init() {
if (!MenuLayer::init())
return false;
this->addStringIDs();
return true;
}
};