-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
284 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "EditorLayerInput.hpp" | ||
#include "LayerManager.hpp" | ||
|
||
void updateEditorLayerButtons(EditorUI* editorUI) { | ||
if(!editorUI) | ||
return; | ||
|
||
auto menu = editorUI->getChildByID("layer-menu"); | ||
auto layer = LayerManager::get()->getLayer(editorUI->m_editorLayer->m_currentLayer); | ||
|
||
// update layer lock button | ||
if(auto lockLayerBtn = as<CCMenuItemSpriteExtra*>(menu->getChildByTag(LOCKLAYER_TAG))) { | ||
const char* lockSpr = "GJ_lockGray_001.png"; | ||
|
||
if (layer) { | ||
lockSpr = layer->m_locked ? "GJ_lock_001.png" : "GJ_lock_open_001.png"; | ||
} | ||
|
||
auto btnSpr = CCSprite::createWithSpriteFrameName(lockSpr); | ||
btnSpr->setScale(.7f); | ||
btnSpr->setPosition(lockLayerBtn->getNormalImage()->getPosition()); | ||
btnSpr->setOpacity(layer ? 255 : 120); | ||
|
||
lockLayerBtn->setNormalImage(btnSpr); | ||
|
||
// for some reason setNormalImage resets the anchor point | ||
if (!strcmp(lockSpr, "GJ_lock_open_001.png")) { | ||
lockLayerBtn->getNormalImage()->setAnchorPoint({ 0.52f, 0.2f }); | ||
} | ||
else { | ||
lockLayerBtn->getNormalImage()->setAnchorPoint({ 0.5f, 0.5f }); | ||
} | ||
lockLayerBtn->setEnabled(layer); | ||
} | ||
} | ||
|
||
void updateEditorLayerInputText(EditorUI* editorUI) { | ||
if(!editorUI) | ||
return; | ||
|
||
auto menu = editorUI->getChildByID("layer-menu"); | ||
auto layer = LayerManager::get()->getLayer(editorUI->m_editorLayer->m_currentLayer); | ||
|
||
updateEditorLayerButtons(editorUI); | ||
|
||
// update layer input | ||
if(auto layerInput = menu->getChildByTag(LAYERINPUT_TAG)) { | ||
as<InputNode*>(layerInput)->setString(editorUI->m_currentLayerLabel->getString()); | ||
} | ||
} | ||
|
||
EUITextDelegate* EUITextDelegate::create() { | ||
auto ret = new EUITextDelegate(); | ||
|
||
if (ret && ret->init()) { | ||
ret->autorelease(); | ||
return ret; | ||
} | ||
|
||
CC_SAFE_DELETE(ret); | ||
return nullptr; | ||
} | ||
|
||
int strToInt(const char* str, bool* is = nullptr) { | ||
bool isStr = true; | ||
for (auto i = 0u; i < strlen(str); i++) | ||
if (!isdigit(str[i]) && str[i] != '-') | ||
isStr = false; | ||
|
||
if (is) *is = isStr; | ||
|
||
return isStr ? std::atoi(str) : -1; | ||
} | ||
|
||
void EUITextDelegate::textChanged(CCTextInputNode* input) { | ||
auto editor = LevelEditorLayer::get(); | ||
|
||
if (input->getString() && strlen(input->getString())) { | ||
editor->m_currentLayer = strToInt(input->getString()); | ||
} | ||
else { | ||
editor->m_currentLayer = -1; | ||
} | ||
|
||
if(editor->m_editorUI) { | ||
editor->m_editorUI->m_currentLayerLabel->setString(fmt::format("{}", editor->m_currentLayer).c_str()); | ||
|
||
updateEditorLayerButtons(editor->m_editorUI); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <Geode/Geode.hpp> | ||
|
||
using namespace geode::prelude; | ||
|
||
static constexpr const int LAYERINPUT_TAG = 6978; | ||
static constexpr const int LAYERINPUTBG_TAG = 6977; | ||
static constexpr const int NEXTFREELAYER_TAG = 7001; | ||
static constexpr const int LOCKLAYER_TAG = 7002; | ||
static constexpr const int VIEWLAYERS_TAG = 7003; | ||
|
||
void updateEditorLayerButtons(EditorUI*); | ||
void updateEditorLayerInputText(EditorUI*); | ||
|
||
class EUITextDelegate : public CCNode, public TextInputDelegate { | ||
public: | ||
virtual void textChanged(CCTextInputNode*) override; | ||
|
||
static EUITextDelegate* create(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters