Skip to content

Commit

Permalink
fix next free editor layer
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Dec 10, 2024
1 parent 1cd30fd commit c105c82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v6.10.0-alpha.3
* Add <cl>Create Loop</c> keybind
* Fix <cj>Next Free</c> not working for Editor Layers
* Fix <cj>Build Helper</c> keybind actually creating a loop
* Fix <co>32-bit Android crashing upon entering the editor</c>

Expand Down
32 changes: 21 additions & 11 deletions src/features/EditMixedValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Geode/binding/GameObject.hpp>
#include <Geode/binding/ButtonSprite.hpp>
#include <Geode/binding/EffectGameObject.hpp>
#include <Geode/binding/LevelEditorLayer.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/utils/string.hpp>
#include <Geode/ui/TextInput.hpp>
Expand Down Expand Up @@ -41,6 +42,7 @@ struct MixedValuesConfig final {
Type (*getDefault)(GameObject*);
Type (*get)(GameObject*);
Type (*set)(GameObject*, Type, Direction);
void (*useNextFreeValues)(GameObject*, std::set<T>&) = nullptr;
};

template <class T>
Expand All @@ -58,7 +60,7 @@ class MixedValuesInput : public CCMenu {
protected:
bool init(
GameObject* obj, CCArray* objs, MixedValuesConfig<T> const& config,
const char* title, const char* arrowSpr, bool showNextFree
const char* title, const char* arrowSpr
) {
if (!CCMenu::init())
return false;
Expand Down Expand Up @@ -112,7 +114,7 @@ class MixedValuesInput : public CCMenu {
m_arrowRightBtn->setID("arrow-right-button"_spr);
this->addChildAtPosition(m_arrowRightBtn, Anchor::Right, ccp(-15, -10));

if (showNextFree) {
if (m_config.useNextFreeValues) {
auto nextFreeSpr = CCSprite::createWithSpriteFrameName("GJ_plus2Btn_001.png");
nextFreeSpr->setScale(.8f);
m_nextFreeBtn = CCMenuItemSpriteExtra::create(
Expand Down Expand Up @@ -151,8 +153,8 @@ class MixedValuesInput : public CCMenu {
}
void onNextFree(CCObject*) {
std::set<T> usedLayers;
for (auto obj : m_targets) {
usedLayers.insert(m_config.get(obj));
for (auto obj : CCArrayExt<GameObject*>(LevelEditorLayer::get()->m_objects)) {
m_config.useNextFreeValues(obj, usedLayers);
}
T nextFree;
for (nextFree = m_config.limits.min; nextFree < m_config.limits.max; nextFree += 1) {
Expand Down Expand Up @@ -198,10 +200,10 @@ class MixedValuesInput : public CCMenu {
static MixedValuesInput* create(
GameObject* obj, CCArray* objs,
MixedValuesConfig<T> const& config,
const char* title, const char* arrowSpr, bool showNextFree
const char* title, const char* arrowSpr
) {
auto ret = new MixedValuesInput();
if (ret && ret->init(obj, objs, config, title, arrowSpr, showNextFree)) {
if (ret && ret->init(obj, objs, config, title, arrowSpr)) {
ret->autorelease();
return ret;
}
Expand Down Expand Up @@ -283,8 +285,12 @@ class $modify(SetGroupIDLayer) {
obj->m_editorLayer = value;
return value;
},
.useNextFreeValues = +[](GameObject* obj, std::set<short>& values) {
values.insert(obj->m_editorLayer);
values.insert(obj->m_editorLayer2);
},
},
"Editor L", "GJ_arrow_02_001.png", true
"Editor L", "GJ_arrow_02_001.png"
)->replace(m_editorLayerInput, m_mainLayer->querySelector("editor-layer-menu"));

MixedValuesInput<short>::create(
Expand All @@ -300,8 +306,12 @@ class $modify(SetGroupIDLayer) {
obj->m_editorLayer2 = value;
return value;
},
.useNextFreeValues = +[](GameObject* obj, std::set<short>& values) {
values.insert(obj->m_editorLayer);
values.insert(obj->m_editorLayer2);
},
},
"Editor L2", "GJ_arrow_03_001.png", true
"Editor L2", "GJ_arrow_03_001.png"
)->replace(m_editorLayer2Input, m_mainLayer->querySelector("editor-layer-2-menu"));

MixedValuesInput<int>::create(
Expand Down Expand Up @@ -332,7 +342,7 @@ class $modify(SetGroupIDLayer) {
return obj->m_zOrder;
},
},
"Z Order", "GJ_arrow_02_001.png", false
"Z Order", "GJ_arrow_02_001.png"
)->replace(m_zOrderInput, m_mainLayer->querySelector("z-order-menu"));

if (m_orderInput) {
Expand All @@ -353,7 +363,7 @@ class $modify(SetGroupIDLayer) {
return value;
}
},
nullptr, "GJ_arrow_02_001.png", false
nullptr, "GJ_arrow_02_001.png"
)->replace(m_orderInput, m_mainLayer->querySelector("channel-order-menu"));
}
if (m_channelInput) {
Expand All @@ -374,7 +384,7 @@ class $modify(SetGroupIDLayer) {
return value;
}
},
nullptr, "GJ_arrow_02_001.png", false
nullptr, "GJ_arrow_02_001.png"
)->replace(m_channelInput, m_mainLayer->querySelector("channel-menu"));
}

Expand Down

0 comments on commit c105c82

Please sign in to comment.