Skip to content

Commit

Permalink
Now it's time to get funky
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Sep 8, 2024
1 parent 1005754 commit e740fc7
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 67 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(SearchHistory VERSION 1.0.4)
project(SearchHistory VERSION 1.1.0)

add_library(${PROJECT_NAME} SHARED
src/main.cpp
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ A mod that allows you to view your search history.
- [hiimjustin000](https://gdbrowser.com/u/7466002) - Creator of the mod

## Gallery
![Search History Popup 1](./resources/image1.png)
![Search History Popup 2](./resources/image2.png)
![Search History Popup ](./resources/search-history.png)

# License
This mod is licensed under the [MIT License](./LICENSE).
3 changes: 1 addition & 2 deletions about.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ A mod that allows you to view your search history.
- [hiimjustin000](user:7466002) - Creator of the mod

## Gallery
![Search History Popup 1](hiimjustin000.search_history/image1.png?scale=0.625)\
![Search History Popup 2](hiimjustin000.search_history/image2.png?scale=0.625)
![Search History Popup](hiimjustin000.search_history/search-history.png?scale=0.625)
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Search History Changelog
## v1.1.0 (2024-09-08)
- Revamped the search history popup
- Expanded the number of search history entries per page from 5 to 10
- Removed duplicate search history entries from the same day

## v1.0.4 (2024-09-07)
- Removed properties from saved.json that are default values
- Changed the search history button texture and mod logo
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"win": "2.206",
"mac": "2.206"
},
"version": "v1.0.4",
"version": "v1.1.0",
"id": "hiimjustin000.search_history",
"name": "Search History",
"developer": "hiimjustin000",
Expand Down
Binary file removed resources/image1.png
Binary file not shown.
Binary file removed resources/image2.png
Binary file not shown.
Binary file added resources/search-history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/square-bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/square-middle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/square-top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/SearchHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
lengths.push_back(std::stoi(str));
}

history.insert(history.begin(), {
SearchHistoryObject obj = {
.time = time,
.type = type,
.query = search->m_searchQuery,
Expand All @@ -36,8 +36,16 @@ void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
.demonFilter = (int)search->m_demonFilter,
.noStar = search->m_noStarFilter,
.star = search->m_starFilter
};

auto found = std::find_if(history.begin(), history.end(), [&obj](SearchHistoryObject const& o) {
return obj == o;
});

if (found != history.end()) history.erase(found);

history.insert(history.begin(), obj);

Mod::get()->setSavedValue("search-history", history);
}

Expand Down
30 changes: 28 additions & 2 deletions src/SearchHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ struct SearchHistoryObject {
int demonFilter;
bool noStar;
bool star;

bool operator==(SearchHistoryObject const& other) const {
return floor(time / 86400.0) == floor(other.time / 86400.0) &&
type == other.type &&
query == other.query &&
difficulties == other.difficulties &&
lengths == other.lengths &&
uncompleted == other.uncompleted &&
completed == other.completed &&
featured == other.featured &&
original == other.original &&
twoPlayer == other.twoPlayer &&
coins == other.coins &&
epic == other.epic &&
legendary == other.legendary &&
mythic == other.mythic &&
song == other.song &&
(!song || (customSong == other.customSong && songID == other.songID)) &&
demonFilter == other.demonFilter &&
noStar == other.noStar &&
star == other.star;
}
};

class SearchHistory {
Expand Down Expand Up @@ -55,7 +77,7 @@ struct matjson::Serialize<std::vector<SearchHistoryObject>> {
}
}

vec.push_back({
SearchHistoryObject obj = {
.time = (int64_t)PROPERTY_OR_DEFAULT(elem, "time", is_number, as_double, 0),
.type = PROPERTY_OR_DEFAULT(elem, "type", is_number, as_int, 0),
.query = PROPERTY_OR_DEFAULT(elem, "query", is_string, as_string, ""),
Expand All @@ -76,7 +98,11 @@ struct matjson::Serialize<std::vector<SearchHistoryObject>> {
.demonFilter = PROPERTY_OR_DEFAULT(elem, "demon-filter", is_number, as_int, 0),
.noStar = PROPERTY_OR_DEFAULT(elem, "no-star", is_bool, as_bool, false),
.star = PROPERTY_OR_DEFAULT(elem, "star", is_bool, as_bool, false)
});
};

if (!std::any_of(vec.begin(), vec.end(), [&obj](SearchHistoryObject const& o) {
return obj == o;
})) vec.push_back(obj);
}

return vec;
Expand Down
113 changes: 64 additions & 49 deletions src/SearchHistoryNode.cpp
Original file line number Diff line number Diff line change
@@ -1,68 +1,76 @@
#include "SearchHistoryNode.hpp"

SearchHistoryNode* SearchHistoryNode::create(SearchHistoryObject const& object, int index, SearchCallback search, RemoveCallback remove, bool h12, bool white) {
SearchHistoryNode* SearchHistoryNode::create(
SearchHistoryObject const& object, int index, int count, SearchCallback search, RemoveCallback remove, bool h12, bool white, bool dark
) {
auto ret = new SearchHistoryNode();
if (ret->init(object, index, search, remove, h12, white)) {
if (ret->init(object, index, count, search, remove, h12, white, dark)) {
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}

bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, SearchCallback search, RemoveCallback remove, bool h12, bool white) {
bool SearchHistoryNode::init(
SearchHistoryObject const& object, int index, int count, SearchCallback search, RemoveCallback remove, bool h12, bool white, bool dark
) {
if (!CCNode::init()) return false;

setContentSize({ 400.0f, 100.0f });
setContentSize({ 400.0f, 50.0f });

m_object = object;
m_searchCallback = search;
m_removeCallback = remove;
m_index = index;

auto background = CCScale9Sprite::create("GJ_square01.png", { 0, 0, 80, 80 });
background->setContentSize({ 400.0f, 100.0f });
background->setPosition(200.0f, 50.0f);
m_count = count;

auto background = CCScale9Sprite::create(
index % 10 == 0 ? "square-top.png"_spr : index % 10 == 9 || index == count - 1 ? "square-bottom.png"_spr : "square-middle.png"_spr, { 0, 0, 80, 80 });
if (dark) background->setColor(index % 2 == 0 ? ccColor3B { 48, 48, 48 } : ccColor3B { 80, 80, 80 });
else background->setColor(index % 2 == 0 ? ccColor3B { 161, 88, 44 } : ccColor3B { 194, 114, 62 });
background->setContentSize({ 400.0f, 50.0f });
background->setPosition(200.0f, 25.0f);
addChild(background);

auto queryLabel = CCLabelBMFont::create(object.query.empty() ? "(No Query)" : object.query.c_str(), "bigFont.fnt");
queryLabel->setColor(object.query.empty() ? ccColor3B { 127, 127, 127 } : ccColor3B { 255, 255, 255 });
queryLabel->setScale(0.75f);
queryLabel->setScale(0.375f);
queryLabel->setAnchorPoint({ 0.0f, 0.5f });
queryLabel->setPositionX(100.0f);
queryLabel->limitLabelWidth(225.0f, 0.75f, 0.1f);
queryLabel->setPositionX(50.0f);
queryLabel->limitLabelWidth(225.0f, 0.375f, 0.1f);
addChild(queryLabel);

auto type = object.type;
switch (type) {
case 0: {
queryLabel->setPositionY(80.0f);
queryLabel->setPositionY(42.5f);
auto levelSprite = CCSprite::createWithSpriteFrameName("GJ_viewLevelsBtn_001.png");
levelSprite->setScale(1.75f);
levelSprite->setPosition({ 50.0f, 50.0f });
levelSprite->setScale(0.875f);
levelSprite->setPosition({ 25.0f, 25.0f });
addChild(levelSprite);
break;
}
case 1: {
queryLabel->setPositionY(65.0f);
queryLabel->setPositionY(32.5f);
auto listSprite = CCSprite::createWithSpriteFrameName("GJ_viewListsBtn_001.png");
listSprite->setScale(1.75f);
listSprite->setPosition({ 50.0f, 50.0f });
listSprite->setScale(0.875f);
listSprite->setPosition({ 25.0f, 25.0f });
addChild(listSprite);
break;
}
case 2: {
queryLabel->setPositionY(50.0f);
queryLabel->setPositionY(25.0f);
auto userSprite = CCSprite::createWithSpriteFrameName("GJ_profileButton_001.png");
userSprite->setScale(1.45f);
userSprite->setPosition({ 50.0f, 50.0f });
userSprite->setScale(0.725f);
userSprite->setPosition({ 25.0f, 25.0f });
addChild(userSprite);
break;
}
}

auto buttonMenu = CCMenu::create();
buttonMenu->setContentSize({ 400.0f, 100.0f });
buttonMenu->setContentSize({ 400.0f, 50.0f });
buttonMenu->setPosition(0.0f, 0.0f);
addChild(buttonMenu);

Expand All @@ -71,20 +79,20 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
if (btn2) m_removeCallback(m_index);
});
});
removeButton->setPosition(queryLabel->getScaledContentSize().width + 120.0f, queryLabel->getPositionY());
removeButton->setPosition(380.0f, 25.0f);
buttonMenu->addChild(removeButton);

auto searchButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_undoBtn_001.png", 0.6f, [this](auto) { m_searchCallback(m_object); });
searchButton->setPosition(queryLabel->getScaledContentSize().width + 150.0f, queryLabel->getPositionY());
searchButton->setPosition(350.0f, 25.0f);
buttonMenu->addChild(searchButton);

if (type < 2) {
if (type < 1) {
auto filtersNode = CCNode::create();
filtersNode->setAnchorPoint({ 0.0f, 0.5f });
filtersNode->setContentSize({ 300.0f, 15.0f });
filtersNode->setPosition(100.0f, 55.0f);
filtersNode->setLayout(RowLayout::create()->setGap(3.0f)->setAxisAlignment(AxisAlignment::Start)->setAutoScale(false));
filtersNode->setContentSize({ 250.0f, 8.0f });
filtersNode->setPosition(50.0f, 30.0f);
filtersNode->setLayout(RowLayout::create()->setGap(1.5f)->setAxisAlignment(AxisAlignment::Start)->setAutoScale(false));
addChild(filtersNode);

if (object.uncompleted) filtersNode->addChild(CCSprite::createWithSpriteFrameName("GJ_deleteIcon_001.png"));
Expand All @@ -99,26 +107,26 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
if (object.noStar) filtersNode->addChild(CCSprite::createWithSpriteFrameName("GJ_starsIcon_gray_001.png"));

for (auto child : CCArrayExt<CCNode*>(filtersNode->getChildren())) {
child->setScale(0.7f);
child->setScale(0.35f);
}

if (filtersNode->getChildrenCount() == 0) {
filtersNode->removeFromParent();
auto noFiltersLabel = CCLabelBMFont::create("(No Filters)", "bigFont.fnt");
noFiltersLabel->setAnchorPoint({ 0.0f, 0.5f });
noFiltersLabel->setColor({ 127, 127, 127 });
noFiltersLabel->setScale(0.5f);
noFiltersLabel->setPosition(100.0f, 55.0f);
noFiltersLabel->setScale(0.25f);
noFiltersLabel->setPosition(50.0f, 30.0f);
addChild(noFiltersLabel);
}
else filtersNode->updateLayout();
}

auto difficultiesNode = CCNode::create();
difficultiesNode->setAnchorPoint({ 0.0f, 0.5f });
difficultiesNode->setContentSize({ 300.0f, 15.0f });
difficultiesNode->setPosition(100.0f, 35.0f + (type >= 1 ? 5.0f : 0.0f));
difficultiesNode->setLayout(RowLayout::create()->setGap(3.0f)->setAxisAlignment(AxisAlignment::Start)->setAutoScale(false));
difficultiesNode->setContentSize({ 250.0f, 8.0f });
difficultiesNode->setPosition(50.0f, 18.0f + (type > 0 ? 2.0f : 0.0f));
difficultiesNode->setLayout(RowLayout::create()->setGap(1.5f)->setAxisAlignment(AxisAlignment::Start)->setAutoScale(false));
addChild(difficultiesNode);

for (auto difficulty : object.difficulties) {
Expand All @@ -131,13 +139,13 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
}

auto difficultySprite = CCSprite::createWithSpriteFrameName(difficultyFrame.c_str());
difficultySprite->setScale(0.5f);
difficultySprite->setScale(0.25f);
difficultiesNode->addChild(difficultySprite);
}

if (std::find(object.difficulties.begin(), object.difficulties.end(), -2) != object.difficulties.end() && object.demonFilter > 0) {
auto demonFilterSprite = CCSprite::createWithSpriteFrameName(fmt::format("diffIcon_{:02d}_btn_001.png", object.demonFilter).c_str());
demonFilterSprite->setScale(0.5f);
demonFilterSprite->setScale(0.25f);
difficultiesNode->addChild(demonFilterSprite);
}

Expand All @@ -153,46 +161,46 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
}

auto lengthLabel = CCLabelBMFont::create(length, "bigFont.fnt");
lengthLabel->setScale(0.3f);
lengthLabel->setScale(0.25f);
difficultiesNode->addChild(lengthLabel);
}

if (object.star) {
auto starSprite = CCSprite::createWithSpriteFrameName("GJ_starsIcon_001.png");
starSprite->setScale(0.7f);
starSprite->setScale(0.35f);
difficultiesNode->addChild(starSprite);
}

if (difficultiesNode->getChildrenCount() == 0) {
difficultiesNode->removeFromParent();
auto noDifficultiesLabel = CCLabelBMFont::create("(No Difficulties/Lengths)", "bigFont.fnt");
auto noDifficultiesLabel = CCLabelBMFont::create(type < 1 ? "(No Difficulties/Lengths)" : "(No Difficulties)", "bigFont.fnt");
noDifficultiesLabel->setAnchorPoint({ 0.0f, 0.5f });
noDifficultiesLabel->setColor({ 127, 127, 127 });
noDifficultiesLabel->setScale(0.5f);
noDifficultiesLabel->setPosition(100.0f, 35.0f + (type >= 1 ? 5.0f : 0.0f));
noDifficultiesLabel->setScale(0.25f);
noDifficultiesLabel->setPosition(50.0f, 18.0f + (type > 0 ? 2.0f : 0.0f));
addChild(noDifficultiesLabel);
}
else difficultiesNode->updateLayout();

if (type < 1 && object.song) {
auto songSprite = CCSprite::createWithSpriteFrameName("GJ_musicIcon_001.png");
songSprite->setScale(0.65f);
songSprite->setPosition({ 100.0f + (songSprite->getScaledContentSize().width / 2), 15.0f });
songSprite->setScale(0.325f);
songSprite->setPosition({ 50.0f + (songSprite->getScaledContentSize().width / 2), 7.0f });
addChild(songSprite);

auto songLabel = CCLabelBMFont::create(
(object.customSong ? std::to_string(object.songID) : std::string(LevelTools::getAudioTitle(object.songID - 1).c_str())).c_str(), "bigFont.fnt");
songLabel->setScale(0.4f);
object.customSong ? std::to_string(object.songID).c_str() : LevelTools::getAudioTitle(object.songID - 1).c_str(), "bigFont.fnt");
songLabel->setScale(0.25f);
songLabel->setAnchorPoint({ 0.0f, 0.5f });
songLabel->setPosition(120.0f, 15.0f);
songLabel->limitLabelWidth(280.0f, 0.4f, 0.1f);
songLabel->setPosition(60.0f, 7.0f);
songLabel->limitLabelWidth(280.0f, 0.25f, 0.1f);
addChild(songLabel);
} else if (type < 1) {
auto noSongLabel = CCLabelBMFont::create("(No Song)", "bigFont.fnt");
noSongLabel->setAnchorPoint({ 0.0f, 0.5f });
noSongLabel->setColor({ 127, 127, 127 });
noSongLabel->setScale(0.5f);
noSongLabel->setPosition(100.0f, 15.0f);
noSongLabel->setScale(0.25f);
noSongLabel->setPosition(50.0f, 7.0f);
addChild(noSongLabel);
}
}
Expand All @@ -210,10 +218,17 @@ bool SearchHistoryNode::init(SearchHistoryObject const& object, int index, Searc
auto timeLabel = CCLabelBMFont::create(ss.str().c_str(), "chatFont.fnt");
timeLabel->setColor(white ? ccColor3B { 255, 255, 255 } : ccColor3B { 51, 51, 51 });
timeLabel->setOpacity(white ? 200 : 152);
timeLabel->setScale(0.5f);
timeLabel->setScale(0.4f);
timeLabel->setAnchorPoint({ 1.0f, 0.0f });
timeLabel->setPosition(394.0f, 6.0f);
timeLabel->setPosition(399.0f, 1.0f);
addChild(timeLabel);

return true;
}

void SearchHistoryNode::draw() {
ccDrawColor4B(0, 0, 0, 75);
glLineWidth(2.0f);
if (m_index % 10 < 9 && m_index < m_count - 1) ccDrawLine({ 0.0f, 0.0f }, { 400.0f, 0.0f });
if (m_index % 10 > 0) ccDrawLine({ 0.0f, 50.0f }, { 400.0f, 50.0f });
}
8 changes: 5 additions & 3 deletions src/SearchHistoryNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class SearchHistoryNode : public CCNode {
SearchCallback m_searchCallback;
RemoveCallback m_removeCallback;
int m_index;

bool init(SearchHistoryObject const&, int, SearchCallback, RemoveCallback, bool, bool);
int m_count;
public:
static SearchHistoryNode* create(SearchHistoryObject const&, int, SearchCallback, RemoveCallback, bool, bool);
static SearchHistoryNode* create(SearchHistoryObject const&, int, int, SearchCallback, RemoveCallback, bool, bool, bool);

bool init(SearchHistoryObject const&, int, int, SearchCallback, RemoveCallback, bool, bool, bool);
void draw() override;
};
Loading

0 comments on commit e740fc7

Please sign in to comment.