-
Notifications
You must be signed in to change notification settings - Fork 6
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
3 changed files
with
117 additions
and
0 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
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,49 @@ | ||
#include "FolderButton.h" | ||
|
||
bool FolderButton::init(const char* texture, const std::function<void(int)>& callback) { | ||
if(!CCMenuItemSpriteExtra::init(CCSprite::createWithSpriteFrameName(texture), nullptr, this, nullptr)) return false; | ||
|
||
m_callback = callback; | ||
m_label = CCLabelBMFont::create("0", "bigFont.fnt"); | ||
m_label->setPosition(this->getNormalImage()->getContentSize() / 2); | ||
m_label->setScale(.55f); | ||
this->getNormalImage()->addChild(m_label); | ||
|
||
return true; | ||
} | ||
|
||
FolderButton* FolderButton::create(const char* texture, const std::function<void(int)>& callback) { | ||
auto ret = new FolderButton(); | ||
if(ret && ret->init(texture, callback)) { | ||
ret->autorelease(); | ||
return ret; | ||
} | ||
CC_SAFE_DELETE(ret); | ||
return nullptr; | ||
} | ||
|
||
FolderButton* FolderButton::create(const std::function<void(int)>& callback) { | ||
return FolderButton::create("gj_folderBtn_001.png", callback); | ||
} | ||
|
||
void FolderButton::setDisplayFolder(int folderID) { | ||
m_label->setString(std::to_string(folderID).c_str()); | ||
m_folderID = folderID; | ||
} | ||
|
||
void FolderButton::setIsCreated(bool isCreated) { | ||
m_isCreated = isCreated; | ||
} | ||
|
||
void FolderButton::activate() { | ||
CCMenuItemSpriteExtra::activate(); | ||
|
||
auto popup = SetFolderPopup::create(m_folderID, m_isCreated, m_popupLabel.c_str()); | ||
popup->m_delegate = this; | ||
popup->show(); | ||
} | ||
|
||
void FolderButton::setIDPopupClosed(SetIDPopup* popup, int id) { | ||
if(m_callback) m_callback(id); | ||
this->setDisplayFolder(id); | ||
} |
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,22 @@ | ||
#pragma once | ||
#include <Geode/Geode.hpp> | ||
#include "../utils.hpp" | ||
|
||
using namespace geode::prelude; | ||
|
||
class BI_DLL FolderButton : public CCMenuItemSpriteExtra, public SetIDPopupDelegate { | ||
std::function<void(int)> m_callback; | ||
CCLabelBMFont* m_label = nullptr; | ||
std::string m_popupLabel = "Set Folder"; | ||
int m_folderID = 0; | ||
bool m_isCreated = false; | ||
protected: | ||
bool init(const char* texture, const std::function<void(int)>& callback); | ||
public: | ||
static FolderButton* create(const char* texture, const std::function<void(int)>& callback); | ||
static FolderButton* create(const std::function<void(int)>& callback); | ||
void setDisplayFolder(int folderID); | ||
void setIsCreated(bool isCreated); | ||
void activate(); | ||
void setIDPopupClosed(SetIDPopup*, int); | ||
}; |