Skip to content

Commit

Permalink
work on pack selection
Browse files Browse the repository at this point in the history
  • Loading branch information
LimeGradient committed Sep 26, 2024
1 parent a04c043 commit e20f24e
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 31 deletions.
24 changes: 13 additions & 11 deletions src/ModProfilesLayer.cpp
Original file line number Diff line number Diff line change
@@ -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 <Geode/Geode.hpp>
#include <Geode/utils/ColorProvider.hpp>

Expand All @@ -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"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -152,6 +147,7 @@ void ModProfilesLayer::onSettings(CCObject*) {
void ModProfilesLayer::onTab(CCObject* sender) {
auto senderNode = static_cast<CCNode*>(sender);
auto id = senderNode->getID();
log::info("sender id: {}", id);

auto setSelectedTab = [=](std::string id) {
for (auto tab : m_tabs) {
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/ModProfilesLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ModpackInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void ModpackInfoPopup::onChooseLogo(CCObject*) {
}

void ModpackInfoPopup::onCreatePack(CCObject* sender) {
auto exportProfilesList = static_cast<ExportProfilesList*>(CCScene::get()->getChildByIDRecursive("ExportProfilesList"));
auto exportProfilesList = static_cast<ExportProfilesList*>(CCScene::get()->getChildByIDRecursive("export-pack-list"));
m_fileTaskListener.bind([=] (auto* e) {
m_packInfo->setPackInfo(
m_modpackTitle->getString(),
Expand Down
4 changes: 2 additions & 2 deletions src/lists/ExportProfilesList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/lists/ExportProfilesList.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ using FileTask = Task<Result<fs::path>>;

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<Mod*> modsToExport;

bool init(CCSize const& size);
void updateTopContainer();
void onPage(CCObject*);
void onExport(CCObject*);

public:
Expand Down
8 changes: 0 additions & 8 deletions src/lists/ImportProfilesList.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,18 @@ using FileTask = Task<Result<fs::path>>;

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<Mod*> 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);
};
19 changes: 18 additions & 1 deletion src/lists/PackCell.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
#include "PackCell.h"
#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);

}
28 changes: 27 additions & 1 deletion src/lists/PackCell.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
#pragma once

#include <Geode/Geode.hpp>
#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;
static PackCell* create(PackInfo* packInfo);
};
73 changes: 72 additions & 1 deletion src/lists/PackSelectList.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
#include "PackSelectList.h"
#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;
}
24 changes: 23 additions & 1 deletion src/lists/PackSelectList.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
#include <Geode/Geode.hpp>

using namespace geode::prelude;
using namespace geode::prelude;
#include <filesystem>
#include "utils/PackInfo.h"
#include "utils/ziputils.h"
using namespace geode::prelude;
namespace fs = std::filesystem;
using FileTask = Task<Result<fs::path>>;

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);
};
5 changes: 5 additions & 0 deletions src/utils/ziputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions src/utils/ziputils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit e20f24e

Please sign in to comment.