Skip to content

Commit

Permalink
2.207
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Nov 14, 2024
1 parent e740fc7 commit a6f4536
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 129 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.1.0)
project(SearchHistory VERSION 1.1.1)

add_library(${PROJECT_NAME} SHARED
src/main.cpp
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Search History Changelog
## v1.1.1-beta.1 (2024-11-13)
- Ported to Geometry Dash v2.207

## v1.1.0 (2024-09-08)
- Revamped the search history popup
- Expanded the number of search history entries per page from 5 to 10
Expand Down
11 changes: 5 additions & 6 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"geode": "3.4.0",
"geode": "4.0.0-alpha.1",
"gd": {
"android": "2.206",
"win": "2.206",
"mac": "2.206"
"android": "2.2074",
"win": "2.2074",
"mac": "2.2074"
},
"version": "v1.1.0",
"version": "v1.1.1-beta.1",
"id": "hiimjustin000.search_history",
"name": "Search History",
"developer": "hiimjustin000",
"description": "A mod that allows you to view your search history.",
"repository": "https://github.com/hiimjustin000/SearchHistory",
"dependencies": [
{
"id": "geode.node-ids",
Expand Down
2 changes: 2 additions & 0 deletions src/SearchHistory.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SearchHistory.hpp"

using namespace geode::prelude;

void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
auto history = Mod::get()->getSavedValue<std::vector<SearchHistoryObject>>("search-history");

Expand Down
78 changes: 36 additions & 42 deletions src/SearchHistory.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <Geode/Geode.hpp>

using namespace geode::prelude;
#pragma once

struct SearchHistoryObject {
int64_t time;
Expand All @@ -25,7 +23,7 @@ struct SearchHistoryObject {
bool star;

bool operator==(SearchHistoryObject const& other) const {
return floor(time / 86400.0) == floor(other.time / 86400.0) &&
return floor(time / 86400.0) == floor(other.time / 86400.0) &&
type == other.type &&
query == other.query &&
difficulties == other.difficulties &&
Expand Down Expand Up @@ -55,74 +53,74 @@ class SearchHistory {
static void remove(int);
};

#define PROPERTY_OR_DEFAULT(obj, prop, isFunc, asFunc, def) (obj.contains(prop) && obj[prop].isFunc() ? obj[prop].asFunc() : def)

template<>
struct matjson::Serialize<std::vector<SearchHistoryObject>> {
static std::vector<SearchHistoryObject> from_json(matjson::Value const& value) {
static geode::Result<std::vector<SearchHistoryObject>> fromJson(matjson::Value const& value) {
if (!value.isArray()) return geode::Err("Expected array");

std::vector<SearchHistoryObject> vec;

for (auto const& elem : value.as_array()) {
for (auto const& elem : value.asArray().unwrap()) {
std::vector<int> difficulties;
if (elem.contains("difficulties") && elem["difficulties"].is_array()) {
for (auto const& e : elem["difficulties"].as_array()) {
difficulties.push_back(e.as_int());
if (elem.contains("difficulties") && elem["difficulties"].isArray()) {
for (auto const& e : elem["difficulties"].asArray().unwrap()) {
difficulties.push_back(e.asInt().unwrapOr(0));
}
}

std::vector<int> lengths;
if (elem.contains("lengths") && elem["lengths"].is_array()) {
for (auto const& e : elem["lengths"].as_array()) {
lengths.push_back(e.as_int());
if (elem.contains("lengths") && elem["lengths"].isArray()) {
for (auto const& e : elem["lengths"].asArray().unwrap()) {
lengths.push_back(e.asInt().unwrapOr(0));
}
}

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, ""),
.time = (int64_t)elem["time"].asInt().unwrapOr(0),
.type = (int)elem["type"].asInt().unwrapOr(0),
.query = elem["query"].asString().unwrapOr(""),
.difficulties = difficulties,
.lengths = lengths,
.uncompleted = PROPERTY_OR_DEFAULT(elem, "uncompleted", is_bool, as_bool, false),
.completed = PROPERTY_OR_DEFAULT(elem, "completed", is_bool, as_bool, false),
.featured = PROPERTY_OR_DEFAULT(elem, "featured", is_bool, as_bool, false),
.original = PROPERTY_OR_DEFAULT(elem, "original", is_bool, as_bool, false),
.twoPlayer = PROPERTY_OR_DEFAULT(elem, "two-player", is_bool, as_bool, false),
.coins = PROPERTY_OR_DEFAULT(elem, "coins", is_bool, as_bool, false),
.epic = PROPERTY_OR_DEFAULT(elem, "epic", is_bool, as_bool, false),
.legendary = PROPERTY_OR_DEFAULT(elem, "legendary", is_bool, as_bool, false),
.mythic = PROPERTY_OR_DEFAULT(elem, "mythic", is_bool, as_bool, false),
.song = PROPERTY_OR_DEFAULT(elem, "song", is_bool, as_bool, false),
.customSong = PROPERTY_OR_DEFAULT(elem, "custom-song", is_bool, as_bool, false),
.songID = PROPERTY_OR_DEFAULT(elem, "song-id", is_number, as_int, 0),
.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)
.uncompleted = elem["uncompleted"].asBool().unwrapOr(false),
.completed = elem["completed"].asBool().unwrapOr(false),
.featured = elem["featured"].asBool().unwrapOr(false),
.original = elem["original"].asBool().unwrapOr(false),
.twoPlayer = elem["two-player"].asBool().unwrapOr(false),
.coins = elem["coins"].asBool().unwrapOr(false),
.epic = elem["epic"].asBool().unwrapOr(false),
.legendary = elem["legendary"].asBool().unwrapOr(false),
.mythic = elem["mythic"].asBool().unwrapOr(false),
.song = elem["song"].asBool().unwrapOr(false),
.customSong = elem["custom-song"].asBool().unwrapOr(false),
.songID = (int)elem["song-id"].asInt().unwrapOr(0),
.demonFilter = (int)elem["demon-filter"].asInt().unwrapOr(0),
.noStar = elem["no-star"].asBool().unwrapOr(false),
.star = elem["star"].asBool().unwrapOr(false)
};

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

return vec;
return geode::Ok(vec);
}

static matjson::Value to_json(std::vector<SearchHistoryObject> const& vec) {
matjson::Array arr;
static matjson::Value toJson(std::vector<SearchHistoryObject> const& vec) {
std::vector<matjson::Value> arr;

for (auto const& obj : vec) {
matjson::Array difficulties;
std::vector<matjson::Value> difficulties;
for (int const& e : obj.difficulties) {
difficulties.push_back(e);
}

matjson::Array lengths;
std::vector<matjson::Value> lengths;
for (int const& e : obj.lengths) {
lengths.push_back(e);
}

matjson::Object historyObject;
matjson::Value historyObject;
historyObject["time"] = obj.time;
historyObject["type"] = obj.type;
if (!obj.query.empty()) historyObject["query"] = obj.query;
Expand Down Expand Up @@ -151,8 +149,4 @@ struct matjson::Serialize<std::vector<SearchHistoryObject>> {

return arr;
}

static bool is_json(matjson::Value const& value) {
return value.is_array();
}
};
28 changes: 15 additions & 13 deletions src/SearchHistoryNode.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "SearchHistoryNode.hpp"

using namespace geode::prelude;

SearchHistoryNode* SearchHistoryNode::create(
SearchHistoryObject const& object, int index, int count, SearchCallback search, RemoveCallback remove, bool h12, bool white, bool dark
SearchHistoryObject const& object, int index, int count, SearchCallback const& search, RemoveCallback const& remove, bool h12, bool white, bool dark
) {
auto ret = new SearchHistoryNode();
if (ret->init(object, index, count, search, remove, h12, white, dark)) {
Expand All @@ -13,7 +15,7 @@ SearchHistoryNode* SearchHistoryNode::create(
}

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

Expand All @@ -30,7 +32,7 @@ bool SearchHistoryNode::init(
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);
background->setPosition({ 200.0f, 25.0f });
addChild(background);

auto queryLabel = CCLabelBMFont::create(object.query.empty() ? "(No Query)" : object.query.c_str(), "bigFont.fnt");
Expand Down Expand Up @@ -71,27 +73,27 @@ bool SearchHistoryNode::init(

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

auto removeButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_deleteBtn_001.png", 0.5f, [this](auto) {
createQuickPopup("Remove Search", "Are you sure you want to remove this search history entry?", "No", "Yes", [this](auto, bool btn2) {
if (btn2) m_removeCallback(m_index);
});
});
removeButton->setPosition(380.0f, 25.0f);
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(350.0f, 25.0f);
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({ 250.0f, 8.0f });
filtersNode->setPosition(50.0f, 30.0f);
filtersNode->setPosition({ 50.0f, 30.0f });
filtersNode->setLayout(RowLayout::create()->setGap(1.5f)->setAxisAlignment(AxisAlignment::Start)->setAutoScale(false));
addChild(filtersNode);

Expand All @@ -116,7 +118,7 @@ bool SearchHistoryNode::init(
noFiltersLabel->setAnchorPoint({ 0.0f, 0.5f });
noFiltersLabel->setColor({ 127, 127, 127 });
noFiltersLabel->setScale(0.25f);
noFiltersLabel->setPosition(50.0f, 30.0f);
noFiltersLabel->setPosition({ 50.0f, 30.0f });
addChild(noFiltersLabel);
}
else filtersNode->updateLayout();
Expand All @@ -125,7 +127,7 @@ bool SearchHistoryNode::init(
auto difficultiesNode = CCNode::create();
difficultiesNode->setAnchorPoint({ 0.0f, 0.5f });
difficultiesNode->setContentSize({ 250.0f, 8.0f });
difficultiesNode->setPosition(50.0f, 18.0f + (type > 0 ? 2.0f : 0.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);

Expand Down Expand Up @@ -177,7 +179,7 @@ bool SearchHistoryNode::init(
noDifficultiesLabel->setAnchorPoint({ 0.0f, 0.5f });
noDifficultiesLabel->setColor({ 127, 127, 127 });
noDifficultiesLabel->setScale(0.25f);
noDifficultiesLabel->setPosition(50.0f, 18.0f + (type > 0 ? 2.0f : 0.0f));
noDifficultiesLabel->setPosition({ 50.0f, 18.0f + (type > 0 ? 2.0f : 0.0f) });
addChild(noDifficultiesLabel);
}
else difficultiesNode->updateLayout();
Expand All @@ -192,15 +194,15 @@ bool SearchHistoryNode::init(
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(60.0f, 7.0f);
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.25f);
noSongLabel->setPosition(50.0f, 7.0f);
noSongLabel->setPosition({ 50.0f, 7.0f });
addChild(noSongLabel);
}
}
Expand All @@ -220,7 +222,7 @@ bool SearchHistoryNode::init(
timeLabel->setOpacity(white ? 200 : 152);
timeLabel->setScale(0.4f);
timeLabel->setAnchorPoint({ 1.0f, 0.0f });
timeLabel->setPosition(399.0f, 1.0f);
timeLabel->setPosition({ 399.0f, 1.0f });
addChild(timeLabel);

return true;
Expand Down
10 changes: 5 additions & 5 deletions src/SearchHistoryNode.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "SearchHistory.hpp"

typedef MiniFunction<void(SearchHistoryObject const&)> SearchCallback;
typedef MiniFunction<void(int)> RemoveCallback;
typedef std::function<void(SearchHistoryObject const&)> SearchCallback;
typedef std::function<void(int)> RemoveCallback;

class SearchHistoryNode : public CCNode {
class SearchHistoryNode : public cocos2d::CCNode {
protected:
SearchHistoryObject m_object;
SearchCallback m_searchCallback;
RemoveCallback m_removeCallback;
int m_index;
int m_count;
public:
static SearchHistoryNode* create(SearchHistoryObject const&, int, int, SearchCallback, RemoveCallback, bool, bool, bool);
static SearchHistoryNode* create(SearchHistoryObject const&, int, int, SearchCallback const&, RemoveCallback const&, bool, bool, bool);

bool init(SearchHistoryObject const&, int, int, SearchCallback, RemoveCallback, bool, bool, bool);
bool init(SearchHistoryObject const&, int, int, SearchCallback const&, RemoveCallback const&, bool, bool, bool);
void draw() override;
};
21 changes: 12 additions & 9 deletions src/SearchHistoryPopup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "SearchHistoryNode.hpp"
#include "SearchHistoryPopup.hpp"

SearchHistoryPopup* SearchHistoryPopup::create(SearchHistoryCallback callback) {
using namespace geode::prelude;

SearchHistoryPopup* SearchHistoryPopup::create(SearchHistoryCallback const& callback) {
auto ret = new SearchHistoryPopup();
if (ret->initAnchored(440.0f, 290.0f, callback, "GJ_square02.png")) {
ret->autorelease();
Expand All @@ -10,19 +13,19 @@ SearchHistoryPopup* SearchHistoryPopup::create(SearchHistoryCallback callback) {
return nullptr;
}

bool SearchHistoryPopup::setup(SearchHistoryCallback callback) {
bool SearchHistoryPopup::setup(SearchHistoryCallback const& callback) {
setTitle("Search History", "bigFont.fnt", 0.53f);

m_searchCallback = callback;

auto background = CCScale9Sprite::create("square02_001.png", { 0, 0, 80, 80 });
background->setContentSize({ 400.0f, 195.0f });
background->setPosition(220.0f, 117.5f);
background->setPosition({ 220.0f, 117.5f });
background->setOpacity(127);
m_mainLayer->addChild(background);

m_scrollLayer = ScrollLayer::create({ 400.0f, 195.0f });
m_scrollLayer->setPosition(20.0f, 20.0f);
m_scrollLayer->setPosition({ 20.0f, 20.0f });
m_scrollLayer->m_contentLayer->setLayout(
ColumnLayout::create()
->setAxisReverse(true)
Expand All @@ -35,15 +38,15 @@ bool SearchHistoryPopup::setup(SearchHistoryCallback callback) {
m_prevButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_arrow_01_001.png", 1.0f, [this](auto) {
page(m_page - 1);
});
m_prevButton->setPosition(-34.5f, 145.0f);
m_prevButton->setPosition({ -34.5f, 145.0f });
m_buttonMenu->addChild(m_prevButton);

auto nextButtonSprite = CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png");
nextButtonSprite->setFlipX(true);
m_nextButton = CCMenuItemExt::createSpriteExtra(nextButtonSprite, [this](auto) {
page(m_page + 1);
});
m_nextButton->setPosition(474.5f, 145.0f);
m_nextButton->setPosition({ 474.5f, 145.0f });
m_buttonMenu->addChild(m_nextButton);

auto clearButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_deleteBtn_001.png", 0.6f, [this](auto) {
Expand All @@ -54,19 +57,19 @@ bool SearchHistoryPopup::setup(SearchHistoryCallback callback) {
}
});
});
clearButton->setPosition(420.0f, 270.0f);
clearButton->setPosition({ 420.0f, 270.0f });
m_buttonMenu->addChild(clearButton);

m_countLabel = CCLabelBMFont::create("", "goldFont.fnt");
m_countLabel->setAnchorPoint({ 1.0f, 0.0f });
m_countLabel->setScale(0.5f);
m_countLabel->setPosition(435.0f, 7.0f);
m_countLabel->setPosition({ 435.0f, 7.0f });
m_mainLayer->addChild(m_countLabel);

m_searchInput = TextInput::create(400.0f, "Search History...");
m_searchInput->setCommonFilter(CommonFilter::Any);
m_searchInput->setTextAlign(TextInputAlign::Left);
m_searchInput->setPosition(220.0f, 235.0f);
m_searchInput->setPosition({ 220.0f, 235.0f });
m_searchInput->setCallback([this](auto) { page(0); });
m_mainLayer->addChild(m_searchInput);

Expand Down
Loading

0 comments on commit a6f4536

Please sign in to comment.