From 2d9913af94f5f1a4f785b89bc1cd58c19b3587d5 Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Tue, 20 Aug 2024 21:47:06 -0400 Subject: [PATCH 1/3] Update EditorUIScaling.cpp --- src/features/scaling/EditorUIScaling.cpp | 90 +++++++++++++++--------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/src/features/scaling/EditorUIScaling.cpp b/src/features/scaling/EditorUIScaling.cpp index b3d0e8e..4df9226 100644 --- a/src/features/scaling/EditorUIScaling.cpp +++ b/src/features/scaling/EditorUIScaling.cpp @@ -98,6 +98,8 @@ class $modify(ScaledUI, EditorUI) { if (Mod::get()->getSettingValue("scale-build-tabs")) { objTabs->setScale(scale); } + + m_toolbarHeight = objTabs->getPositionY(); } if (auto leftTabs = this->getChildByID("toolbar-categories-menu")) { @@ -139,9 +141,7 @@ class $modify(ScaledUI, EditorUI) { auto winSize = CCDirector::get()->getWinSize(); this->getChildByID("build-tabs-menu")->setPositionX(winSize.width / 2); - // This is so silly. If you don't do this, the menu is wrongly positioned, - // but only the first time. I have no clue what's going on - this->centerBuildTabs(); + // Reload EditButtonBars to recenter for (auto c : CCArrayExt(this->getChildren())) { if (auto bar = typeinfo_cast(c)) { bar->reloadItems( @@ -150,46 +150,68 @@ class $modify(ScaledUI, EditorUI) { ); } } - this->centerBuildTabs(); return true; } - - void centerBuildTabs() { - // This centers the build tab - auto winSize = CCDirector::get()->getWinSize(); - for (auto c : CCArrayExt(this->getChildren())) { - if (auto bar = typeinfo_cast(c)) { - if (bar->getChildrenCount() > 0) { - getChild(bar, 0)->setPositionX(-winSize.width / 2 + 5); - if (auto menu = getChildOfType(bar, 0)) { - menu->setPositionX(winSize.width / 2 + 5); - } - } - bar->setPositionX(winSize.width / 2); - } - } - } }; -class $modify(EditButtonBar) { +class $modify(BetterEditButtonBar, EditButtonBar) { + $override void loadFromItems(CCArray* items, int r, int c, bool unkBool) { + EditButtonBar::loadFromItems(items, r, c, unkBool); - if (auto ui = static_cast(EditorUI::get())) { - ui->centerBuildTabs(); + + //fix visible pages when opening editor, can be assumed as 0 as loadFromItems resets the page to 0 + for (auto barPages : CCArrayExt(m_pagesArray)) { + barPages->setVisible(false); + } + if (CCNode* firstPage = typeinfo_cast(m_pagesArray->objectAtIndex(0))){ + firstPage->setVisible(true); } - } -}; -class $modify(EditorPauseLayer) { - static void onModify(auto& self) { - (void)self.setHookPriority("EditorPauseLayer::onResume", -100); - } + if (auto ui = typeinfo_cast(getParent())) { + auto winSize = CCDirector::get()->getWinSize(); - $override - void onResume(CCObject* pSender) { - EditorPauseLayer::onResume(pSender); - static_cast(EditorUI::get())->centerBuildTabs(); + setPositionX(winSize.width / 2); + + if (auto scrollLayer = getChildOfType(this, 0)) { + scrollLayer->setPositionX(-winSize.width / 2 + 5); + } + + if (auto menu = getChildOfType(this, 0)) { + menu->setVisible(false); + + //easier to create a new menu than work with the old one + CCMenu* navMenu = CCMenu::create(); + + navMenu->setPosition({-winSize.width / 2, 0}); + navMenu->setContentSize(menu->getContentSize()); + navMenu->setScale(menu->getScale()); + + float xOffset = 180 / getScale(); + float yOffset = 2; + + CCSprite* prevSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_02_001.png"); + prevSpr->setScale(0.6f); + CCSprite* nextSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_02_001.png"); + nextSpr->setFlipX(true); + nextSpr->setScale(0.6f); + + CCMenuItemSpriteExtra* prevButton = CCMenuItemSpriteExtra::create(prevSpr, this, menu_selector(EditButtonBar::onLeft)); + CCMenuItemSpriteExtra* nextButton = CCMenuItemSpriteExtra::create(nextSpr, this, menu_selector(EditButtonBar::onRight)); + + prevButton->setPositionX(menu->getContentWidth()/2 - xOffset); + prevButton->setPositionY((ui->m_toolbarHeight/2 + yOffset) / getScale()); + + nextButton->setPositionX(menu->getContentWidth()/2 + xOffset); + nextButton->setPositionY((ui->m_toolbarHeight/2 + yOffset) / getScale()); + + navMenu->addChild(prevButton); + navMenu->addChild(nextButton); + + addChild(navMenu); + } + } } -}; +}; \ No newline at end of file From d7211ee4e9c0d994bad8f41bb55e1fa5821ae8ad Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Tue, 20 Aug 2024 21:49:50 -0400 Subject: [PATCH 2/3] Fix position of visibility fix --- src/features/scaling/EditorUIScaling.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/features/scaling/EditorUIScaling.cpp b/src/features/scaling/EditorUIScaling.cpp index 4df9226..c7da9b8 100644 --- a/src/features/scaling/EditorUIScaling.cpp +++ b/src/features/scaling/EditorUIScaling.cpp @@ -162,15 +162,16 @@ class $modify(BetterEditButtonBar, EditButtonBar) { EditButtonBar::loadFromItems(items, r, c, unkBool); - //fix visible pages when opening editor, can be assumed as 0 as loadFromItems resets the page to 0 - for (auto barPages : CCArrayExt(m_pagesArray)) { - barPages->setVisible(false); - } - if (CCNode* firstPage = typeinfo_cast(m_pagesArray->objectAtIndex(0))){ - firstPage->setVisible(true); - } - if (auto ui = typeinfo_cast(getParent())) { + + //fix visible pages when opening editor, can be assumed as 0 as loadFromItems resets the page to 0 + for (auto barPages : CCArrayExt(m_pagesArray)) { + barPages->setVisible(false); + } + if (CCNode* firstPage = typeinfo_cast(m_pagesArray->objectAtIndex(0))){ + firstPage->setVisible(true); + } + auto winSize = CCDirector::get()->getWinSize(); setPositionX(winSize.width / 2); From 181b66983d941ff74776b2abd0c51ac62b1d3400 Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Wed, 28 Aug 2024 00:25:21 -0400 Subject: [PATCH 3/3] Fix arrow position --- src/features/scaling/EditorUIScaling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/scaling/EditorUIScaling.cpp b/src/features/scaling/EditorUIScaling.cpp index c7da9b8..dac8ebd 100644 --- a/src/features/scaling/EditorUIScaling.cpp +++ b/src/features/scaling/EditorUIScaling.cpp @@ -190,7 +190,7 @@ class $modify(BetterEditButtonBar, EditButtonBar) { navMenu->setContentSize(menu->getContentSize()); navMenu->setScale(menu->getScale()); - float xOffset = 180 / getScale(); + float xOffset = (winSize.width / getScale())/2 - 104; float yOffset = 2; CCSprite* prevSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_02_001.png");