From c375978058724825c8452b8de8b64d06cd12cf31 Mon Sep 17 00:00:00 2001 From: Cvolton Date: Sat, 16 Dec 2023 23:39:19 +0100 Subject: [PATCH] add BIBaseLayer --- src/layers/CustomCreatorLayer.cpp | 36 +----------------- src/layers/CustomCreatorLayer.h | 5 ++- src/layers/_bases/BIBaseLayer.cpp | 61 +++++++++++++++++++++++++++++++ src/layers/_bases/BIBaseLayer.h | 15 ++++++++ 4 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 src/layers/_bases/BIBaseLayer.cpp create mode 100644 src/layers/_bases/BIBaseLayer.h diff --git a/src/layers/CustomCreatorLayer.cpp b/src/layers/CustomCreatorLayer.cpp index a434131..6ee17c8 100644 --- a/src/layers/CustomCreatorLayer.cpp +++ b/src/layers/CustomCreatorLayer.cpp @@ -17,34 +17,9 @@ CustomCreatorLayer* CustomCreatorLayer::create() { } bool CustomCreatorLayer::init() { - auto backgroundSprite = CCSprite::create("game_bg_14_001.png"); + if (!BIBaseLayer::init()) return false; auto winSize = CCDirector::sharedDirector()->getWinSize(); - auto size = backgroundSprite->getContentSize(); - - backgroundSprite->setScale(winSize.width / size.width); - - backgroundSprite->setAnchorPoint({0, 0}); - backgroundSprite->setPosition({0,-75}); - - backgroundSprite->setColor({164, 0, 255}); - - backgroundSprite->setZOrder(-2); - addChild(backgroundSprite); - - auto backBtn = CCMenuItemSpriteExtra::create( - CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png"), - this, - menu_selector(CustomCreatorLayer::onBack) - ); - - auto menuBack = CCMenu::create(); - menuBack->addChild(backBtn); - menuBack->setPosition({25, winSize.height - 25}); - - addChild(menuBack); - - setKeypadEnabled(true); auto menu = CCMenu::create(); menu->setID("bi-main-menu"); @@ -169,15 +144,6 @@ bool CustomCreatorLayer::init() { return true; } -void CustomCreatorLayer::keyBackClicked() { - CCDirector::sharedDirector()->popSceneWithTransition(0.5f, PopTransition::kPopTransitionFade); -} - - -void CustomCreatorLayer::onBack(CCObject* object) { - keyBackClicked(); -} - void CustomCreatorLayer::onInfo(CCObject* object) { FLAlertLayer::create( nullptr, diff --git a/src/layers/CustomCreatorLayer.h b/src/layers/CustomCreatorLayer.h index 63085fb..6e52509 100644 --- a/src/layers/CustomCreatorLayer.h +++ b/src/layers/CustomCreatorLayer.h @@ -2,12 +2,13 @@ #include +#include "_bases/BIBaseLayer.h" + using namespace geode::prelude; -class CustomCreatorLayer : public cocos2d::CCLayer { +class CustomCreatorLayer : public BIBaseLayer { protected: virtual bool init(); - virtual void keyBackClicked(); void onBack(cocos2d::CCObject*); void onFeatured(cocos2d::CCObject*); void onMostLiked(cocos2d::CCObject*); diff --git a/src/layers/_bases/BIBaseLayer.cpp b/src/layers/_bases/BIBaseLayer.cpp new file mode 100644 index 0000000..7dcd0b6 --- /dev/null +++ b/src/layers/_bases/BIBaseLayer.cpp @@ -0,0 +1,61 @@ +#include "BIBaseLayer.h" + +BIBaseLayer* BIBaseLayer::create() { + auto ret = new BIBaseLayer(); + if (ret && ret->init()) { + ret->autorelease(); + } else { + delete ret; + ret = nullptr; + } + return ret; +} + +bool BIBaseLayer::init() { + auto backgroundSprite = CCSprite::create("game_bg_14_001.png"); + + auto winSize = CCDirector::sharedDirector()->getWinSize(); + auto size = backgroundSprite->getContentSize(); + + backgroundSprite->setScale(winSize.width / size.width); + + backgroundSprite->setAnchorPoint({0, 0}); + backgroundSprite->setPosition({0,-75}); + + backgroundSprite->setColor({164, 0, 255}); + + backgroundSprite->setZOrder(-2); + addChild(backgroundSprite); + + auto backBtn = CCMenuItemSpriteExtra::create( + CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png"), + this, + menu_selector(BIBaseLayer::onBack) + ); + + auto menuBack = CCMenu::create(); + menuBack->addChild(backBtn); + menuBack->setPosition({25, winSize.height - 25}); + + addChild(menuBack); + + setKeypadEnabled(true); + + return true; +} + +void BIBaseLayer::keyBackClicked() { + CCDirector::sharedDirector()->popSceneWithTransition(0.5f, PopTransition::kPopTransitionFade); +} + + +void BIBaseLayer::onBack(CCObject* object) { + keyBackClicked(); +} + +CCScene* BIBaseLayer::scene() { + auto layer = BIBaseLayer::create(); + auto scene = CCScene::create(); + scene->addChild(layer); + return scene; +} diff --git a/src/layers/_bases/BIBaseLayer.h b/src/layers/_bases/BIBaseLayer.h new file mode 100644 index 0000000..33855bb --- /dev/null +++ b/src/layers/_bases/BIBaseLayer.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +using namespace geode::prelude; + +class BIBaseLayer : public cocos2d::CCLayer { +protected: + virtual bool init(); + virtual void keyBackClicked(); + void onBack(cocos2d::CCObject*); +public: + static BIBaseLayer* create(); + static cocos2d::CCScene* scene(); +}; \ No newline at end of file