diff --git a/src/ModProfilesLayer.cpp b/src/ModProfilesLayer.cpp index 309dbba..56ab4c9 100644 --- a/src/ModProfilesLayer.cpp +++ b/src/ModProfilesLayer.cpp @@ -1,9 +1,3 @@ -/* -A lot (if not all) of the UI code is straight from Geode github -i wanted it to look as close as possible to the actual geode menu -https://github.com/geode-sdk/geode -*/ - #include #include @@ -12,6 +6,7 @@ using namespace geode::prelude; #include "ModProfilesLayer.h" #include "SettingsPopup.h" #include "lists/ExportProfilesList.h" +#include "lists/PackSelectList.h" #include "geode_impl/GeodeTabSprite.h" #include "geode_impl/SwelvyBG.h" @@ -92,7 +87,7 @@ bool ModProfilesLayer::init() { }) { auto btn = CCMenuItemSpriteExtra::create( GeodeTabSprite::create(std::get<0>(item), std::get<1>(item), 120), - this, menu_selector(ModProfilesLayer::onClose) + this, menu_selector(ModProfilesLayer::onTab) ); btn->setID(std::get<2>(item)); mainTabs->addChild(btn); @@ -125,9 +120,9 @@ bool ModProfilesLayer::init() { ); this->addChildAtPosition(actionsMenu, Anchor::BottomLeft, ccp(35, 12), false); - auto list = ExportProfilesList::create(m_frame->getContentSize() - ccp(30, 0)); - list->setPosition(m_frame->getContentSize() / 2); - m_frame->addChild(list); + m_currentList = ExportProfilesList::create(m_frame->getContentSize() - ccp(30, 0)); + m_currentList->setPosition(m_frame->getContentSize() / 2); + m_frame->addChild(m_currentList); return true; } @@ -152,6 +147,7 @@ void ModProfilesLayer::onSettings(CCObject*) { void ModProfilesLayer::onTab(CCObject* sender) { auto senderNode = static_cast(sender); auto id = senderNode->getID(); + log::info("sender id: {}", id); auto setSelectedTab = [=](std::string id) { for (auto tab : m_tabs) { @@ -163,9 +159,15 @@ void ModProfilesLayer::onTab(CCObject* sender) { }; // wow this is dumb but it is what it is + m_frame->removeChild(m_currentList); if (id == "export-button") { - auto list = ExportProfilesList::create(m_frame->getContentSize() - ccp(30, 0)); + m_currentList = ExportProfilesList::create(m_frame->getContentSize() - ccp(30, 0)); + } + if (id == "packs-button") { + m_currentList = PackSelectList::create(m_frame->getContentSize() - ccp(30, 0)); } + m_currentList->setPosition(m_frame->getContentSize() / 2); + m_frame->addChild(m_currentList); } ModProfilesLayer* ModProfilesLayer::create() { diff --git a/src/ModProfilesLayer.h b/src/ModProfilesLayer.h index c0c77da..3b64024 100644 --- a/src/ModProfilesLayer.h +++ b/src/ModProfilesLayer.h @@ -9,6 +9,7 @@ class ModProfilesLayer : public CCLayer { ScrollLayer* scrollLayer = nullptr; CCSprite* outline; CCNode* m_frame; + CCNode* m_currentList; void keyBackClicked() override; void switchList(CCNode* list); diff --git a/src/ModpackInfoPopup.cpp b/src/ModpackInfoPopup.cpp index ce3a7b3..8a12c68 100644 --- a/src/ModpackInfoPopup.cpp +++ b/src/ModpackInfoPopup.cpp @@ -99,7 +99,7 @@ void ModpackInfoPopup::onChooseLogo(CCObject*) { } void ModpackInfoPopup::onCreatePack(CCObject* sender) { - auto exportProfilesList = static_cast(CCScene::get()->getChildByIDRecursive("ExportProfilesList")); + auto exportProfilesList = static_cast(CCScene::get()->getChildByIDRecursive("export-pack-list")); m_fileTaskListener.bind([=] (auto* e) { m_packInfo->setPackInfo( m_modpackTitle->getString(), diff --git a/src/lists/ExportProfilesList.cpp b/src/lists/ExportProfilesList.cpp index bd9d4b4..7845e72 100644 --- a/src/lists/ExportProfilesList.cpp +++ b/src/lists/ExportProfilesList.cpp @@ -21,7 +21,7 @@ bool ExportProfilesList::init(CCSize const& size) { this->setContentSize(size); this->setAnchorPoint({.5f, .5f}); - this->setID("ExportProfilesList"); + this->setID("export-pack-list"); m_list = ScrollLayer::create(size); m_list->m_contentLayer->setLayout( @@ -101,7 +101,7 @@ void ExportProfilesList::exportProfile(FileTask::Event* e, PackInfo* packInfo) { for (auto mod : toggledMods) { if (file.path().filename().string() == fmt::format("{}.geode", mod)) { filePaths.push_back(file.path().string()); - modFilenames.push_back(fmt::format("{}.geode", mod)); + modFilenames.push_back(fmt::format("mods/{}.geode", mod)); } } } diff --git a/src/lists/ExportProfilesList.h b/src/lists/ExportProfilesList.h index 25177a5..1fbde92 100644 --- a/src/lists/ExportProfilesList.h +++ b/src/lists/ExportProfilesList.h @@ -9,19 +9,14 @@ using FileTask = Task>; class ExportProfilesList : public CCNode { protected: - size_t m_page = 0; ScrollLayer* m_list; CCNode* m_topContainer; - CCMenuItemSpriteExtra* m_pagePrevBtn; - CCMenuItemSpriteExtra* m_pageNextBtn; CCMenu* m_btnMenu; CCMenuItemSpriteExtra* m_exportBtn; std::vector modsToExport; bool init(CCSize const& size); - void updateTopContainer(); - void onPage(CCObject*); void onExport(CCObject*); public: diff --git a/src/lists/ImportProfilesList.h b/src/lists/ImportProfilesList.h index 76d53cc..4fdc8e4 100644 --- a/src/lists/ImportProfilesList.h +++ b/src/lists/ImportProfilesList.h @@ -8,26 +8,18 @@ using FileTask = Task>; class ImportProfilesList : public CCNode { protected: - size_t m_page = 0; ScrollLayer* m_list; CCNode* m_topContainer; - CCMenuItemSpriteExtra* m_pagePrevBtn; - CCMenuItemSpriteExtra* m_pageNextBtn; CCMenu* m_btnMenu; CCMenuItemSpriteExtra* m_exportBtn; std::vector modsToExport; bool init(CCSize const& size); - void updateTopContainer(); - void onPage(CCObject*); void onExport(CCObject*); void importProfile(FileTask::Event* e); public: static ImportProfilesList* create(CCSize const& size); - size_t getPage() const; - void reloadPage(); - void gotoPage(size_t page, bool update = false); }; \ No newline at end of file diff --git a/src/lists/PackCell.cpp b/src/lists/PackCell.cpp index 581a012..48fce0c 100644 --- a/src/lists/PackCell.cpp +++ b/src/lists/PackCell.cpp @@ -1 +1,18 @@ -#include "PackCell.h" \ No newline at end of file +#include "PackCell.h" + +bool PackCell::init(PackInfo* packInfo) { + if (!CCNode::init()) return false; + + this->m_packInfo = packInfo; + + m_bg = CCScale9Sprite::create("square02b_small.png"); + m_bg->setID("bg"); + m_bg->setOpacity(0); + m_bg->ignoreAnchorPointForPosition(false); + m_bg->setAnchorPoint({ .0f, .0f }); + m_bg->setScale(.7f); + m_bg->setColor(ccWHITE); + m_bg->setOpacity(25); + this->addChild(m_bg); + +} \ No newline at end of file diff --git a/src/lists/PackCell.h b/src/lists/PackCell.h index 72ef1ad..e37a7be 100644 --- a/src/lists/PackCell.h +++ b/src/lists/PackCell.h @@ -1,3 +1,29 @@ +#pragma once + #include +#include "utils/PackInfo.h" + +using namespace geode::prelude; + +class PackCell : public CCNode { +protected: + bool init(PackInfo* packInfo); + + void onEnable(CCObject*); + +public: + CCScale9Sprite* m_bg; + CCNode* m_logo; + CCNode* m_infoContainer; + CCNode* m_titleContainer; + CCLabelBMFont* m_titleLabel; + CCLabelBMFont* m_versionLabel; + CCNode* m_developers; + CCLabelBMFont* m_developerLabel; + CCMenu* m_viewMenu; + CCMenuItemToggler* m_enableToggle = nullptr; + + PackInfo* m_packInfo; -using namespace geode::prelude; \ No newline at end of file + static PackCell* create(PackInfo* packInfo); +}; \ No newline at end of file diff --git a/src/lists/PackSelectList.cpp b/src/lists/PackSelectList.cpp index c57b7d6..87db467 100644 --- a/src/lists/PackSelectList.cpp +++ b/src/lists/PackSelectList.cpp @@ -1 +1,72 @@ -#include "PackSelectList.h" \ No newline at end of file +#include "PackSelectList.h" + +using namespace geode::prelude; + +bool PackSelectList::init(CCSize const& size) { + if (!CCNode::init()) return false; + + this->setContentSize(size); + this->setAnchorPoint({.5f, .5f}); + this->setID("pack-select-list"); + + m_list = ScrollLayer::create(size); + m_list->m_contentLayer->setLayout( + ColumnLayout::create() + ->setAxisReverse(true) + ->setAxisAlignment(AxisAlignment::End) + ->setAutoGrowAxis(size.height) + ->setGap(2.5f) + ); + m_list->scrollToTop(); + this->addChildAtPosition(m_list, Anchor::Bottom, ccp(-m_list->getScaledContentWidth() / 2, 0)); + + m_topContainer = CCNode::create(); + m_topContainer->setID("top-container"); + m_topContainer->ignoreAnchorPointForPosition(false); + m_topContainer->setContentWidth(size.width); + m_topContainer->setAnchorPoint({ .5f, 1.f }); + + float totalHeight = .0f; + + m_btnMenu = CCMenu::create(); + m_btnMenu->setID("button-menu"); + + auto importPackBtnSpr = ButtonSprite::create("Import Pack", "bigFont.fnt", "geode-button.png"_spr); + importPackBtnSpr->setScale(0.65f); + m_importPackBtn = CCMenuItemSpriteExtra::create( + importPackBtnSpr, this, menu_selector(PackSelectList::onImportPack) + ); + m_btnMenu->addChild(m_importPackBtn); + m_btnMenu->setLayout(RowLayout::create()); + m_btnMenu->getLayout()->ignoreInvisibleChildren(true); + + this->addChildAtPosition(m_btnMenu, Anchor::Bottom, ccp(0, -13.f)); + + this->getAllPacks(); + + return true; +} + +void PackSelectList::getAllPacks() { + Zip* zip = new Zip(""); + if (!fs::exists(fmt::format("{}/geodepacks", geode::dirs::getGeodeDir()))) { + fs::create_directory(fmt::format("{}/geodepacks", geode::dirs::getGeodeDir())); + } + for (auto file : fs::directory_iterator(fmt::format("{}/geodepacks", geode::dirs::getGeodeDir()))) { + zip->unzipIntoFolder(file.path().string(), fmt::format("{}/geodepacks/{}", geode::dirs::getGeodeDir(), file.path().stem().string())); + } +} + +void PackSelectList::onImportPack(CCObject*) { + +} + +PackSelectList* PackSelectList::create(CCSize const& size) { + auto ret = new PackSelectList(); + if (ret && ret->init(size)) { + ret->autorelease(); + return ret; + } + CC_SAFE_DELETE(ret); + return nullptr; +} \ No newline at end of file diff --git a/src/lists/PackSelectList.h b/src/lists/PackSelectList.h index 72ef1ad..1a86872 100644 --- a/src/lists/PackSelectList.h +++ b/src/lists/PackSelectList.h @@ -1,3 +1,25 @@ #include -using namespace geode::prelude; \ No newline at end of file +using namespace geode::prelude; +#include +#include "utils/PackInfo.h" +#include "utils/ziputils.h" +using namespace geode::prelude; +namespace fs = std::filesystem; +using FileTask = Task>; + +class PackSelectList : public CCNode { +protected: + ScrollLayer* m_list; + CCNode* m_topContainer; + CCMenu* m_btnMenu; + CCMenuItemSpriteExtra* m_importPackBtn; + + bool init(CCSize const& size); + void getAllPacks(); + + void onImportPack(CCObject*); + +public: + static PackSelectList* create(CCSize const& size); +}; \ No newline at end of file diff --git a/src/utils/ziputils.cpp b/src/utils/ziputils.cpp index ad2b499..5007819 100644 --- a/src/utils/ziputils.cpp +++ b/src/utils/ziputils.cpp @@ -37,4 +37,9 @@ void Zip::writeStringToZip(std::string filename, std::string content) { void Zip::close() { zip_close(this->m_zip); +} + +void Zip::unzipIntoFolder(std::string filename, std::string dest) { + int arg = 2; + zip_extract(filename.c_str(), dest.c_str(), NULL, &arg); } \ No newline at end of file diff --git a/src/utils/ziputils.h b/src/utils/ziputils.h index e2a8505..02ef180 100644 --- a/src/utils/ziputils.h +++ b/src/utils/ziputils.h @@ -17,5 +17,7 @@ class Zip { void writeStringToZip(std::string filename, std::string content); void close(); + void unzipIntoFolder(std::string filename, std::string dest); + zip_t* m_zip; }; \ No newline at end of file