Skip to content

Commit

Permalink
Auto Color Trigger and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ninXout committed Oct 8, 2023
1 parent 9d63e68 commit de2391e
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ file(GLOB SOURCES
src/features/BuildTools/*.cpp
src/features/BuildTools/IDRemap/*.cpp
src/features/BuildTools/PasteString/*.cpp
src/features/BuildTools/AutoColorTrigger/*.cpp
src/features/*.cpp
src/other/*.cpp
src/*.cpp
Expand Down
121 changes: 121 additions & 0 deletions src/features/BuildTools/AutoColorTrigger/ColorTriggerPopup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include "ColorTriggerPopup.hpp"

bool ColorTriggerPopup::setup() {
this->setTitle("Auto Color Trigger");
auto winSize = CCDirector::sharedDirector()->getWinSize();

m_pRangeStartInput = CCTextInputNode::create(60.f, 60.f, "0", "bigFont.fnt");
m_pRangeStartInput->setAllowedChars("0123456789");
m_pRangeStartInput->setPosition(ccp(winSize.width / 2 - 60.0f, winSize.height / 2));
this->m_mainLayer->addChild(m_pRangeStartInput);

m_pRangeEndInput = CCTextInputNode::create(60.f, 60.f, "0", "bigFont.fnt");
m_pRangeEndInput->setAllowedChars("0123456789");
m_pRangeEndInput->setPosition(ccp(winSize.width / 2 + 60.0f, winSize.height / 2));
this->m_mainLayer->addChild(m_pRangeEndInput);

auto idek = CCLabelBMFont::create("-", "bigFont.fnt");
idek->setPosition(winSize / 2);
idek->setScale(.7f);
this->m_mainLayer->addChild(idek);

auto startID = CCLabelBMFont::create("Start ID:", "goldFont.fnt");
startID->setPosition(ccp(winSize.width / 2 - 60.0f, winSize.height / 2 + 30.0f));
startID->setScale(.6f);
this->m_mainLayer->addChild(startID);

auto endID = CCLabelBMFont::create("End ID:", "goldFont.fnt");
endID->setPosition(ccp(winSize.width / 2 + 60.0f, winSize.height / 2 + 30.0f));
endID->setScale(.6f);
this->m_mainLayer->addChild(endID);

auto colorBtnSpr = ButtonSprite::create("Create", 0, 0, .8f, false, "goldFont.fnt", "GJ_button_01.png", 0.f);
colorBtnSpr->setScale(.8f);

auto colorBtn = CCMenuItemSpriteExtra::create(colorBtnSpr, this, menu_selector(ColorTriggerPopup::onCreate));
colorBtn->setPosition(ccp(0.0f, - 170.f / 2 + 25.0f));
this->m_buttonMenu->addChild(colorBtn);
return true;
}

void ColorTriggerPopup::onCreate(CCObject* pSender) {
int rangeStart = 0;
int rangeEnd = 1012;

if (this->m_pRangeStartInput &&
this->m_pRangeStartInput->getString() &&
strlen(this->m_pRangeStartInput->getString()))
rangeStart = std::atoi(this->m_pRangeStartInput->getString());

if (this->m_pRangeEndInput &&
this->m_pRangeEndInput->getString() &&
strlen(this->m_pRangeEndInput->getString()))
rangeEnd = std::atoi(this->m_pRangeEndInput->getString());

auto lel = GameManager::sharedState()->getEditorLayer();

auto dict = lel->m_levelSettings->m_effectManager->m_colorActions;
CCDictElement* el;
auto pos = lel->getObjectLayer()->convertToNodeSpace(CCDirector::sharedDirector()->getWinSize() / 2);
float y = pos.y;
std::stringstream ss;

EditorUI::get()->deselectAll();

auto objs = CCArray::create();

for (int i = 0; i < dict->count(); i++) {
auto el = dict->valueForKey(i);

const auto colorID = i;
if (colorID < rangeStart || colorID > rangeEnd) continue;

auto color = static_cast<ColorAction*>(GJEffectManager::get()->getColorAction(i));

auto obj = static_cast<EffectGameObject*>(lel->createObject(899, { pos.x, y }, false));

obj->m_targetColorID = colorID;
obj->m_colColor = color->m_color;
obj->m_blending = color->m_blending;
obj->m_opacity = color->m_opacity;
obj->m_playerColor1 = color->m_playerColor == 1;
obj->m_playerColor2 = color->m_playerColor == 2;
obj->m_copyColorID = color->m_copyID;
obj->m_hsvValue = color->m_copyHSV;
obj->updateLabel();

if (lel->m_currentLayer != -1)
obj->m_editorLayer = lel->m_currentLayer;

objs->addObject(obj);

y += 30.0f;
}

EditorUI::get()->selectObjects(objs, true);
objs->release();

EditorUI::get()->updateButtons();

if (this->m_pPauseLayer)
this->m_pPauseLayer->onResume(pSender);

this->onClose(pSender);
}

void ColorTriggerPopup::onInfo(CCObject*) {

}

ColorTriggerPopup* ColorTriggerPopup::create(EditorPauseLayer* pl) {
auto pRet = new ColorTriggerPopup();

if (pRet && pRet->init(250.0f, 170.0f)) {
pRet->m_pPauseLayer = pl;
pRet->autorelease();
return pRet;
}

CC_SAFE_DELETE(pRet);
return nullptr;
}
20 changes: 20 additions & 0 deletions src/features/BuildTools/AutoColorTrigger/ColorTriggerPopup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <Geode/Geode.hpp>

using namespace geode::prelude;

class ColorTriggerPopup : public Popup<> {
protected:
CCTextInputNode* m_pRangeStartInput;
CCTextInputNode* m_pRangeEndInput;
EditorPauseLayer* m_pPauseLayer;

bool setup() override;

void onCreate(cocos2d::CCObject*);
void onInfo(cocos2d::CCObject*);

public:
static ColorTriggerPopup* create(EditorPauseLayer* = nullptr);
};
6 changes: 6 additions & 0 deletions src/features/BuildTools/BuildTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <MoreTabs.hpp>
#include "IDRemap/IDRemapPopup.hpp"
#include "PasteString/PasteObjectString.hpp"
#include "AutoColorTrigger/ColorTriggerPopup.hpp"

using namespace geode::prelude;

Expand Down Expand Up @@ -45,6 +46,7 @@ class BuildToolsBar : public CCMenu {
this->addChild(createBuildTool(CCSprite::createWithSpriteFrameName("plus.png"_spr), menu_selector(BuildToolsBar::onBuildHelp)));
this->addChild(createBuildTool(CCSprite::createWithSpriteFrameName("move.png"_spr), menu_selector(BuildToolsBar::onRemapID)));
this->addChild(createBuildTool(CCSprite::createWithSpriteFrameName("deselect.png"_spr), menu_selector(BuildToolsBar::onPasteString)));
this->addChild(createBuildTool(CCSprite::createWithSpriteFrameName("select.png"_spr), menu_selector(BuildToolsBar::onColorMap)));

return true;
}
Expand All @@ -62,6 +64,10 @@ class BuildToolsBar : public CCMenu {
PasteStringPopup::create()->show();
}

void onColorMap(CCObject*) {
ColorTriggerPopup::create()->show();
}

public:
static BuildToolsBar* create(LevelEditorLayer* lel) {
auto ret = new BuildToolsBar;
Expand Down
6 changes: 3 additions & 3 deletions src/features/BuildTools/PasteString/PasteObjectString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ bool PasteStringPopup::setup() {
m_stringInput->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->m_mainLayer->addChild(m_stringInput);

auto pasteBtnSpr = ButtonSprite::create("Remap", 0, 0, .8f, false, "goldFont.fnt", "GJ_button_01.png", 0.f);
auto pasteBtnSpr = ButtonSprite::create("Paste", 0, 0, .8f, false, "goldFont.fnt", "GJ_button_01.png", 0.f);
pasteBtnSpr->setScale(.8f);

auto pasteBtn = CCMenuItemSpriteExtra::create(pasteBtnSpr, this, menu_selector(PasteStringPopup::onPaste));
pasteBtn->setPosition(ccp(0.0f, - 120.f / 2 + 25.0f));
pasteBtn->setPosition(ccp(0.0f, - 150.f / 2 + 25.0f));
this->m_buttonMenu->addChild(pasteBtn);

return true;
Expand All @@ -26,7 +26,7 @@ void PasteStringPopup::onPaste(CCObject*) {
PasteStringPopup* PasteStringPopup::create() {
auto pRet = new PasteStringPopup();

if (pRet && pRet->init(300.0f, 120.0f)) {
if (pRet && pRet->init(300.0f, 150.0f)) {
pRet->autorelease();
return pRet;
}
Expand Down

0 comments on commit de2391e

Please sign in to comment.