diff --git a/src/Client/AndroidUI.h b/src/Client/AndroidUI.h index fa80b0a..708fbea 100644 --- a/src/Client/AndroidUI.h +++ b/src/Client/AndroidUI.h @@ -125,6 +125,8 @@ class AndroidUI : public cocos2d::CCLayerColor { this->runAction(CCFadeTo::create(0.5f, 100)); + this->setID("android-ui"); + #pragma region Back auto backMenu = CCMenu::create(); @@ -299,6 +301,9 @@ class AndroidUI : public cocos2d::CCLayerColor { static void addToScene() { + if (CCDirector::get()->getRunningScene()->getChildByID("android-ui")) + return; + auto l = AndroidUI::create(); CCDirector::get()->getRunningScene()->addChild(l, 69420); @@ -513,7 +518,7 @@ class $modify (PlayLayer) CCDirector::get()->getRunningScene()->addChild(andBall); } }; - +/* class $modify (PauseLayer) { static PauseLayer* create(bool p0) @@ -525,7 +530,7 @@ class $modify (PauseLayer) return v; } }; - +*/ class $modify (LoadingLayer) { bool init(bool p0) @@ -538,7 +543,7 @@ class $modify (LoadingLayer) return true; } }; - +/* //todo: fix android //no longer todo i fixed it :3 @@ -560,12 +565,12 @@ class $modify (MenuLaunchFix, MenuLayer) if (!MenuLayer::init()) return false; - this->scheduleOnce(schedule_selector(MenuLaunchFix::fix), 0.1f); + this->scheduleOnce(schedule_selector(MenuLaunchFix::fix), 10); return true; } }; - +*/ class $modify (CCScene) { int getHighestChildZ() @@ -578,7 +583,7 @@ class $modify (CCScene) if (AndroidBall::instance) AndroidBall::instance->setZOrder(68419); - this->scheduleOnce(schedule_selector(MenuLaunchFix::fix), 0.1f); + //this->scheduleOnce(schedule_selector(MenuLaunchFix::fix), 0.1f); return value; } @@ -617,6 +622,5 @@ class $modify (AchievementNotifier) p0->addChild(AndroidBall::create()); cocos::handleTouchPriority(AndroidBall::instance); - AndroidBall::instance->setTouchPriority(AndroidBall::instance->getTouchPriority() - 1); } }; diff --git a/src/Client/Module.h b/src/Client/Module.h index 14304dc..7808368 100644 --- a/src/Client/Module.h +++ b/src/Client/Module.h @@ -243,7 +243,7 @@ class InputModule : public Module, public TextInputDelegate text = geode::prelude::Mod::get()->getSavedValue(id + "_value", text); } - void makeAndroid(CCMenu* menu, CCPoint pos) + void makeAndroid(CCMenu* menu, CCPoint pos/*, bool useless, SEL_MenuHandler event*/) { auto label = CCLabelBMFont::create(name.c_str(), "bigFont.fnt"); label->setAnchorPoint(ccp(0, 0.5f)); diff --git a/src/Client/Window.h b/src/Client/Window.h index ddee41b..eead546 100644 --- a/src/Client/Window.h +++ b/src/Client/Window.h @@ -173,7 +173,7 @@ class Window } }; -class Speedhack : public Window +class Speedhack : public Window//, public TextInputDelegate { public: Speedhack() @@ -182,34 +182,108 @@ class Speedhack : public Window id = "speedhack-window"; } + static inline Slider* slider = nullptr; + void clear(CCObject* sender) { SpeedhackTop::instance->text = ""; reinterpret_cast(static_cast(sender)->getParent()->getChildByID("speedhack-top"))->setString(""); + slider->setValue(unscaleValue(1)); + } + + float scaleValue(float originalValue) { + float minValue = 0.1; + float maxValue = 3.0; + float scaledValue = (maxValue - minValue) * originalValue + minValue; + return scaledValue; + } + + float unscaleValue(float scaledValue) { + float minValue = 0.1; + float maxValue = 3.0; + float originalValue = (scaledValue - minValue) / (maxValue - minValue); + return originalValue; + } + + void sliderChanged(CCObject* sender) + { + float v = ((slider->getThumb()->getPositionX() + 100) / 200.0f); + + std::stringstream ss; + ss << round(scaleValue(v) * 100.0) / 100.0; + + auto inp = static_cast(static_cast(sender)->getParent()->getParent()->getParent()->getChildByID("speedhack-top")); + inp->setString(ss.str().c_str()); + SpeedhackTop::instance->text = ss.str(); + + SpeedhackTop::instance->save(); } void cocosCreate(CCMenu* menu) { + float v = 1.0f; + + if (SpeedhackTop::instance->text.size() != 0 && !SpeedhackTop::instance->text.ends_with(".")) + { + v = std::stof(SpeedhackTop::instance->text); + } + + if (v < 0.01f) + v = 0.01f; + + if (v > 99999) + v = 99999; + + auto back = CCScale9Sprite::create("square02_small.png"); back->setContentSize(menu->getContentSize() / 0.5f); back->setPosition(ccp(0, 0)); back->setAnchorPoint(ccp(0, 0)); back->setScale(0.5f); back->setOpacity(100); - menu->addChild(back); - for (size_t m = 0; m < modules.size(); m++) - { - modules[m]->makeAndroid(menu, {20, (menu->getContentSize().height - 20 - 20) - 7 - (28.0f * (m - 1.0f))}); - } + slider = Slider::create(menu, menu_selector(Speedhack::sliderChanged)); + slider->setPosition(ccp(menu->getContentSize().width / 2, menu->getContentSize().height - 80)); + slider->setScale(0.875f); + slider->setContentSize(ccp(0, 0)); + slider->ignoreAnchorPointForPosition(false); + slider->setValue(clampf(unscaleValue(v), 0, 1)); + menu->addChild(slider, 2); + + modules[0]->makeAndroid(menu, ccp(menu->getContentSize().width / 2, menu->getContentSize().height - 50) - ccp(180 / 2, 0) + ccp(10, 0)); + modules[1]->makeAndroid(menu, ccp(menu->getContentSize().width / 2, menu->getContentSize().height - 200) - ccp(180 / 2, 0) + ccp(10, 0)); + modules[2]->makeAndroid(menu, ccp(menu->getContentSize().width / 2, menu->getContentSize().height - 250) - ccp(180 / 2, 0) + ccp(10, 0)); + //static_cast(menu->getChildByID("speedhack-top"))->getInput()->setDelegate(this); auto trash = CCMenuItemSpriteExtra::create(CCSprite::createWithSpriteFrameName("GJ_trashBtn_001.png"), menu, menu_selector(Speedhack::clear)); trash->m_baseScale = 0.725f; trash->setScale(0.725f); - trash->setPosition(ccp(210, menu->getContentSize().height - 20)); + trash->setPosition(ccp((menu->getContentSize().width / 2) + (180 / 2) + 20, menu->getContentSize().height - 50)); menu->addChild(trash); } + + virtual void textChanged(CCTextInputNode* p0) + { + SpeedhackTop::instance->text = p0->getString(); + + float v = 1.0f; + + if (SpeedhackTop::instance->text.size() != 0 && !SpeedhackTop::instance->text.ends_with(".")) + { + v = std::stof(SpeedhackTop::instance->text); + } + + if (v < 0.01f) + v = 0.01f; + + if (v > 99999) + v = 99999; + + slider->setValue(clampf(unscaleValue(v), 0, 1)); + + modules[0]->save(); + } }; class Credits : public Window