Skip to content

Commit

Permalink
add song option to level filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 17, 2023
1 parent 40db470 commit 9485e37
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
6 changes: 6 additions & 0 deletions src/delegates/NumberDialogCloseDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

class NumberDialogCloseDelegate {
public:
virtual void onNumberDialogClosed(int number, int additional) = 0;
};
6 changes: 6 additions & 0 deletions src/delegates/SongDialogCloseDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

class SongDialogCloseDelegate {
public:
virtual void onSongDialogClosed(bool custom, int songID) = 0;
};
15 changes: 9 additions & 6 deletions src/layers/LevelFiltering/ProfileSearchOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void ProfileSearchOptions::drawTogglesPrimary(){
createToggle("featured", "Featured", 90, 80);
createToggle("original", "Original", -170, 35);
createToggle("epic", "Epic", -40, 35);
if(!m_prefix.empty()) createToggle("song", "Song", 90, 35, menu_selector(ProfileSearchOptions::onSong));
createToggle("song", "Song", 90, 35, menu_selector(ProfileSearchOptions::onSong));
createToggle("nostar", "No Star", -170, -10);
createToggle("coins", "Coins", -40, -10);
createToggle("nocoins", "No Coins", 90, -10);
Expand Down Expand Up @@ -312,7 +312,10 @@ void ProfileSearchOptions::drawTogglesTerciary(){
createToggle("uncompletedcoins", "Uc. Coins", -40, -50);
}

void ProfileSearchOptions::onDialogClosed(){
void ProfileSearchOptions::onSongDialogClosed(bool custom, int songID){
setOption("song_custom", custom);
setOptionInt("song_id", songID);

reloadBrowser();
}

Expand Down Expand Up @@ -418,8 +421,8 @@ BISearchObject ProfileSearchOptions::getSearchObject() {
searchObj.epic = getOption("epic");
searchObj.folder = 0;
searchObj.song = getOption("song");
searchObj.songCustom = false;
searchObj.songID = 0;
searchObj.songCustom = getOption("song_custom");
searchObj.songID = getOptionInt("song_id");
searchObj.copied = getOption("copied");
searchObj.downloaded = getOption("downloaded");
searchObj.ldm = getOption("ldm");
Expand Down Expand Up @@ -481,8 +484,8 @@ void ProfileSearchOptions::setSearchObject(const BISearchObject& searchObj) {
setOption("epic", searchObj.epic);
//searchObj.folder = 0;
setOption("song", searchObj.song);
//searchObj.songCustom = false;
//searchObj.songID = 0;
setOption("song_custom", searchObj.songCustom);
setOptionInt("song_id", searchObj.songID);
setOption("copied", searchObj.copied);
setOption("downloaded", searchObj.downloaded);
setOption("ldm", searchObj.ldm);
Expand Down
6 changes: 3 additions & 3 deletions src/layers/LevelFiltering/ProfileSearchOptions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "../_bases/CvoltonOptionsLayer.h"
#include "../../delegates/DialogCloseDelegate.h"
#include "../../delegates/SongDialogCloseDelegate.h"
#include "../../delegates/IDRangeDelegate.h"
#include "../../delegates/BISearchObjectDelegate.h"
#include "../../objects/BISearchObject.h"
Expand All @@ -9,7 +9,7 @@

using namespace geode::prelude;

class ProfileSearchOptions : public CvoltonOptionsLayer, public DialogCloseDelegate, public IDRangeDelegate {
class ProfileSearchOptions : public CvoltonOptionsLayer, public SongDialogCloseDelegate, public IDRangeDelegate {
std::map<std::string, bool> m_options;
std::map<std::string, int> m_optionInts;
LevelBrowserLayer* m_levelBrowserLayer = nullptr;
Expand Down Expand Up @@ -42,7 +42,7 @@ class ProfileSearchOptions : public CvoltonOptionsLayer, public DialogCloseDeleg
void drawTogglesTerciary();
void createToggle(const char* option, const char* name, float x, float y);
void createToggle(const char* option, const char* name, float x, float y, cocos2d::SEL_MenuHandler additional);
void onDialogClosed();
void onSongDialogClosed(bool custom, int songID);
void onIDRangeFinished(int min, int max, int additional);
bool getOption(const std::string& option) const;
int getOptionInt(const std::string& option) const;
Expand Down
27 changes: 13 additions & 14 deletions src/layers/LevelFiltering/ProfileSearchOptionsSongSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const int completedMax = 6;

ProfileSearchOptionsSongSelect* ProfileSearchOptionsSongSelect::create(DialogCloseDelegate* delegate){
ProfileSearchOptionsSongSelect* ProfileSearchOptionsSongSelect::create(SongDialogCloseDelegate* delegate){
auto ret = new ProfileSearchOptionsSongSelect();
if (ret && ret->init(delegate)) {
//robert 1 :D
Expand All @@ -17,31 +17,30 @@ ProfileSearchOptionsSongSelect* ProfileSearchOptionsSongSelect::create(DialogClo

void ProfileSearchOptionsSongSelect::onClose(cocos2d::CCObject* sender)
{
setOptionInt("user_search_song_id", songID());
destroyToggles();
delegate->onDialogClosed();
m_delegate->onSongDialogClosed(getOption("user_search_song_custom"), songID());
setKeypadEnabled(false);
removeFromParentAndCleanup(true);
}

bool ProfileSearchOptionsSongSelect::init(DialogCloseDelegate* delegate){
bool ProfileSearchOptionsSongSelect::init(SongDialogCloseDelegate* delegate){
bool init = createBasics({240.0f, 150.0f}, menu_selector(ProfileSearchOptionsSongSelect::onClose), .8f, {0x00, 0x00, 0x00, 0x96});
if(!init) return false;

this->delegate = delegate;
m_delegate = delegate;

auto winSize = CCDirector::sharedDirector()->getWinSize();

createTitle("Song Filter", .45f, .9f);

textNode = CCTextInputNode::create(100, 30, "Num", "bigFont.fnt");
textNode->setLabelPlaceholderColor({0x75, 0xAA, 0xF0});
textNode->setString(std::to_string(getOptionInt("user_search_song_id")).c_str());
textNode->setAllowedChars("0123456789");
textNode->setMaxLabelScale(0.7f);
textNode->setMaxLabelWidth(11);
textNode->setPosition({0,-37});
m_buttonMenu->addChild(textNode);
m_textNode = CCTextInputNode::create(100, 30, "Num", "bigFont.fnt");
m_textNode->setLabelPlaceholderColor({0x75, 0xAA, 0xF0});
m_textNode->setString(std::to_string(getOptionInt("user_search_song_id")).c_str());
m_textNode->setAllowedChars("0123456789");
m_textNode->setMaxLabelScale(0.7f);
m_textNode->setMaxLabelWidth(11);
m_textNode->setPosition({0,-37});
m_buttonMenu->addChild(m_textNode);

auto infoBg = cocos2d::extension::CCScale9Sprite::create("square02b_001.png", { 0.0f, 0.0f, 80.0f, 80.0f });
infoBg->setContentSize({200,60});
Expand Down Expand Up @@ -99,7 +98,7 @@ void ProfileSearchOptionsSongSelect::drawToggles(){
int ProfileSearchOptionsSongSelect::songID(){
int songID = 0;
try{
songID = std::stoi(textNode->getString());
songID = std::stoi(m_textNode->getString());
}catch(...){}
return songID;
}
10 changes: 5 additions & 5 deletions src/layers/LevelFiltering/ProfileSearchOptionsSongSelect.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once
#include "../_bases/CvoltonOptionsLayer.h"
#include "../../delegates/DialogCloseDelegate.h"
#include "../../delegates/SongDialogCloseDelegate.h"

class ProfileSearchOptionsSongSelect : public CvoltonOptionsLayer {
DialogCloseDelegate* delegate;
CCTextInputNode* textNode = nullptr;
SongDialogCloseDelegate* m_delegate;
CCTextInputNode* m_textNode = nullptr;
public:
static ProfileSearchOptionsSongSelect* create(DialogCloseDelegate* delegate);
static ProfileSearchOptionsSongSelect* create(SongDialogCloseDelegate* delegate);
void onClose(cocos2d::CCObject* sender);
bool init(DialogCloseDelegate* delegate);
bool init(SongDialogCloseDelegate* delegate);
void destroyToggles();
void drawToggles();
int songID();
Expand Down

0 comments on commit 9485e37

Please sign in to comment.