mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 17:36:05 -05:00
make modlistdisplay persistent
This commit is contained in:
parent
61b80a0114
commit
07d92a34ad
3 changed files with 43 additions and 7 deletions
|
@ -19,8 +19,6 @@
|
||||||
#include "ui/mods/sources/ModListSource.hpp"
|
#include "ui/mods/sources/ModListSource.hpp"
|
||||||
#include <loader/LoaderImpl.hpp>
|
#include <loader/LoaderImpl.hpp>
|
||||||
|
|
||||||
static ModListDisplay MOD_LIST_DISPLAY = ModListDisplay::SmallList;
|
|
||||||
|
|
||||||
bool ModsStatusNode::init() {
|
bool ModsStatusNode::init() {
|
||||||
if (!CCNode::init())
|
if (!CCNode::init())
|
||||||
return false;
|
return false;
|
||||||
|
@ -355,6 +353,8 @@ bool ModsLayer::init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_modListDisplay = Mod::get()->getSavedValue<ModListDisplay>("mod-list-display-type");
|
||||||
|
|
||||||
auto backMenu = CCMenu::create();
|
auto backMenu = CCMenu::create();
|
||||||
backMenu->setID("back-menu");
|
backMenu->setID("back-menu");
|
||||||
backMenu->setContentWidth(100.f);
|
backMenu->setContentWidth(100.f);
|
||||||
|
@ -651,7 +651,7 @@ void ModsLayer::gotoTab(ModListSource* src) {
|
||||||
m_currentSource = src;
|
m_currentSource = src;
|
||||||
|
|
||||||
// Update the state of the current list
|
// Update the state of the current list
|
||||||
m_lists.at(m_currentSource)->updateDisplay(MOD_LIST_DISPLAY);
|
m_lists.at(m_currentSource)->updateDisplay(m_modListDisplay);
|
||||||
m_lists.at(m_currentSource)->activateSearch(m_showSearch);
|
m_lists.at(m_currentSource)->activateSearch(m_showSearch);
|
||||||
m_lists.at(m_currentSource)->updateState();
|
m_lists.at(m_currentSource)->updateState();
|
||||||
}
|
}
|
||||||
|
@ -713,7 +713,7 @@ void ModsLayer::updateState() {
|
||||||
// Update display button
|
// Update display button
|
||||||
for (auto btn : m_displayBtns) {
|
for (auto btn : m_displayBtns) {
|
||||||
static_cast<GeodeSquareSprite*>(btn->getNormalImage())->setState(
|
static_cast<GeodeSquareSprite*>(btn->getNormalImage())->setState(
|
||||||
static_cast<ModListDisplay>(btn->getTag()) == MOD_LIST_DISPLAY
|
static_cast<ModListDisplay>(btn->getTag()) == m_modListDisplay
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -746,10 +746,12 @@ void ModsLayer::onGoToPage(CCObject*) {
|
||||||
popup->show();
|
popup->show();
|
||||||
}
|
}
|
||||||
void ModsLayer::onDisplay(CCObject* sender) {
|
void ModsLayer::onDisplay(CCObject* sender) {
|
||||||
MOD_LIST_DISPLAY = static_cast<ModListDisplay>(sender->getTag());
|
m_modListDisplay = static_cast<ModListDisplay>(sender->getTag());
|
||||||
|
Mod::get()->setSavedValue("mod-list-display-type", m_modListDisplay);
|
||||||
|
|
||||||
// Make sure to avoid a crash
|
// Make sure to avoid a crash
|
||||||
if (m_currentSource) {
|
if (m_currentSource) {
|
||||||
m_lists.at(m_currentSource)->updateDisplay(MOD_LIST_DISPLAY);
|
m_lists.at(m_currentSource)->updateDisplay(m_modListDisplay);
|
||||||
m_lists.at(m_currentSource)->reloadPage();
|
m_lists.at(m_currentSource)->reloadPage();
|
||||||
}
|
}
|
||||||
this->updateState();
|
this->updateState();
|
||||||
|
|
|
@ -67,6 +67,7 @@ protected:
|
||||||
EventListener<UpdateModListStateFilter> m_updateStateListener;
|
EventListener<UpdateModListStateFilter> m_updateStateListener;
|
||||||
bool m_showSearch = true;
|
bool m_showSearch = true;
|
||||||
std::vector<CCMenuItemSpriteExtra*> m_displayBtns;
|
std::vector<CCMenuItemSpriteExtra*> m_displayBtns;
|
||||||
|
ModListDisplay m_modListDisplay;
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,39 @@ enum class ModListDisplay {
|
||||||
Grid,
|
Grid,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// i made it this way just in case someone wanted to add to the enum in the future
|
||||||
|
// mat is allowed to judge
|
||||||
|
template<>
|
||||||
|
struct matjson::Serialize<ModListDisplay> {
|
||||||
|
static Result<ModListDisplay> fromJson(matjson::Value const& value) {
|
||||||
|
auto saved = GEODE_UNWRAP(value.asString());
|
||||||
|
if (saved == "small-list") {
|
||||||
|
return Ok(ModListDisplay::SmallList);
|
||||||
|
} else if (saved == "big-list") {
|
||||||
|
return Ok(ModListDisplay::BigList);
|
||||||
|
} else if (saved == "grid") {
|
||||||
|
return Ok(ModListDisplay::Grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Err("unknown display type");
|
||||||
|
}
|
||||||
|
|
||||||
|
static matjson::Value toJson(ModListDisplay const& value) {
|
||||||
|
switch (value) {
|
||||||
|
default:
|
||||||
|
case ModListDisplay::SmallList:
|
||||||
|
return "small-list";
|
||||||
|
break;
|
||||||
|
case ModListDisplay::BigList:
|
||||||
|
return "big-list";
|
||||||
|
break;
|
||||||
|
case ModListDisplay::Grid:
|
||||||
|
return "grid";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ModItem : public CCNode {
|
class ModItem : public CCNode {
|
||||||
protected:
|
protected:
|
||||||
ModSource m_source;
|
ModSource m_source;
|
||||||
|
|
Loading…
Reference in a new issue