Skip to content

Commit

Permalink
Use EditorTab API (#7)
Browse files Browse the repository at this point in the history
* Use EditorTab API

* Use updated icon setting

No longer need to specify the sprite twice

* no idea why I casted that lol
  • Loading branch information
Alphalaneous authored Sep 17, 2024
1 parent e0badf8 commit 2c237ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 52 deletions.
7 changes: 6 additions & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "3.2.0",
"geode": "3.4.0",
"gd": {
"win": "2.206",
"android": "2.206",
Expand All @@ -16,6 +16,11 @@
"importance": "required",
"version": ">=1.11.0"
},
{
"id": "alphalaneous.editortab_api",
"importance": "required",
"version": ">=1.0.0"
},
{
"id": "geode.custom-keybinds",
"version": ">=1.7.1",
Expand Down
63 changes: 12 additions & 51 deletions src/hooks/EditorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <manager/BrushManager.hpp>
#include <ui/AlliumButtonBar.hpp>
#include <util/BrushDrawer.hpp>
#include <alphalaneous.editortab_api/include/EditorTabs.hpp>

#ifdef GEODE_IS_WINDOWS
#include <geode.custom-keybinds/include/Keybinds.hpp>
Expand All @@ -15,29 +16,8 @@ using namespace allium;
struct EditorUIHook : Modify<EditorUIHook, EditorUI> {
struct Fields {
geode::Ref<AlliumButtonBar> m_buttonBar;
int tabTag = 0;
};

$override
void toggleMode(CCObject* sender) {
auto tag = sender->getTag();

if (tag != 1 && m_fields->m_buttonBar) {
m_fields->m_buttonBar->resetToggles(sender);
}
EditorUI::toggleMode(sender);
}

$override
void onSelectBuildTab(CCObject* sender) {
auto tag = sender->getTag();

if (tag != m_fields->tabTag && m_fields->m_buttonBar) {
m_fields->m_buttonBar->resetToggles(sender);
}
EditorUI::onSelectBuildTab(sender);
}

$override
bool init(LevelEditorLayer* editorLayer) {
if (!EditorUI::init(editorLayer)) return false;
Expand All @@ -55,37 +35,18 @@ struct EditorUIHook : Modify<EditorUIHook, EditorUI> {

m_fields->m_buttonBar = AlliumButtonBar::create(this);

m_fields->m_buttonBar->getButtonBar()->setZOrder(10);
m_fields->m_buttonBar->getButtonBar()->setVisible(false);
m_createButtonBars->addObject(m_fields->m_buttonBar->getButtonBar());

auto spriteOn = CCSprite::createWithSpriteFrameName("EditorIcon.png"_spr);
spriteOn->setScale(0.2f);
auto onBg = CCSprite::createWithSpriteFrameName("GJ_tabOn_001.png");
onBg->addChildAtPosition(spriteOn, Anchor::Center, ccp(0, 0));

auto spriteOff = CCSprite::createWithSpriteFrameName("EditorIcon.png"_spr);
spriteOff->setScale(0.2f);
spriteOff->setOpacity(150);
auto offBg = CCSprite::createWithSpriteFrameName("GJ_tabOff_001.png");
offBg->addChildAtPosition(spriteOff, Anchor::Center, ccp(0, 0));
offBg->setOpacity(150);

m_fields->tabTag = m_tabsArray->count();

auto tabToggle = CCMenuItemExt::createToggler(
offBg, onBg, [this](CCObject* sender) {
this->onSelectBuildTab(sender);
static_cast<CCMenuItemToggler*>(sender)->toggle(false);
EditorTabs::addTab(this, TabType::BUILD, "allium"_spr, [this](EditorUI* ui, CCMenuItemToggler* toggler) -> CCNode* {
auto sprite = CCSprite::createWithSpriteFrameName("EditorIcon.png"_spr);
sprite->setScale(0.2f);
EditorTabUtils::setTabIcon(toggler, sprite);

return m_fields->m_buttonBar->getButtonBar();
}, [this](EditorUI*, bool state, CCNode*) {
if (!state) {
m_fields->m_buttonBar->resetToggles(nullptr);
}
);
tabToggle->setID("allium-tab-toggle"_spr);
tabToggle->setTag(m_fields->tabTag);
m_tabsArray->addObject(tabToggle);
m_tabsMenu->addChild(tabToggle);
m_tabsMenu->updateLayout();

this->addChild(m_fields->m_buttonBar->getButtonBar());
});


#ifdef GEODE_IS_WINDOWS
// Adds the keybind listener for panning in brush mode
Expand Down

0 comments on commit 2c237ca

Please sign in to comment.