Skip to content

Commit

Permalink
commit current work
Browse files Browse the repository at this point in the history
  • Loading branch information
LimeGradient committed Jan 24, 2025
1 parent 21624f1 commit b2e8bf2
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 78 deletions.
20 changes: 8 additions & 12 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"geode": "3.8.1",
"geode": "4.1.2",
"gd": {
"android": "2.206",
"win": "2.206",
"mac": "2.206"
"android": "2.2074",
"win": "2.2074",
"mac": "2.2074",
"ios": "2.2074"
},
"version": "v2.0.0",
"id": "limegradient.modprofiles",
"name": "Mod Profiles",
"name": "Modpacks",
"developer": "LimeGradient",
"description": "Share your mods with others!",
"links": {
Expand All @@ -17,13 +18,8 @@
"resources": {
"spritesheets": {
"ModProfilesSheet": [
"resources/*.png",
"resources/geode/*.png"
"resources/*.png"
]
},
"sprites": [
"resources/geode/swelve/*.png",
"resources/geode/buttons/*.png"
]
}
}
}
20 changes: 20 additions & 0 deletions src/Backend/Mods.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Mods.hpp"

std::vector<ModCell*> ModBackend::getMods() {
// sort the list by mod name
auto sort_by_name = [](Mod* a, Mod* b) {
return a->getName() < b->getName();
};

std::list<Mod*> mods;
std::ranges::copy(Loader::get()->getAllMods(), std::back_inserter(mods));
mods.sort(sort_by_name);

std::vector<ModCell*> modCells;
for (Mod* mod : mods) {
modCells.push_back(ModCell::create(mod));
}

mods.clear();
return modCells;
}
19 changes: 19 additions & 0 deletions src/Backend/Mods.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <vector>
#include <list>

#include <Geode/Geode.hpp>

#include "UI/ModCell.hpp"
using namespace geode::prelude;

class ModBackend {
public:
static ModBackend* get() {
static ModBackend* instance;
return instance;
}

std::vector<ModCell*> getMods();
};
69 changes: 69 additions & 0 deletions src/UI/ModCell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "ModCell.hpp"

bool ModCell::init(Mod* mod) {
if (!CCNode::init()) return false;

this->m_mod = mod;

Build<CCScale9Sprite>::create("square02b_small.png")
.id(this->makeID("bg"))
.ignoreAnchorPointForPos(false)
.anchorPoint({0.f, 0.f})
.scale(0.7f)
.color(ccWHITE)
.opacity(25)
.parent(this)
.store(m_bg);

m_logo = geode::createModLogo(mod);
m_logo->setID("logo-sprite");
m_logo->setScale(0.5f);
m_logo->setAnchorPoint({.0f, .0f});
m_logo->setPositionY(m_logo->getPositionY() + 2.f);
this->addChild(m_logo);

Build<CCNode>::create()
.id(this->makeID("info-container"))
.scale(.4f)
.anchorPoint({0.f, 0.5f})
.layout(ColumnLayout::create()
->setAxisReverse(true)
->setAxisAlignment(AxisAlignment::Even)
->setCrossAxisLineAlignment(AxisAlignment::Start)
->setGap(0)
)
.parent(this)
.store(m_infoContainer);

this->m_infoContainer->getLayout()->ignoreInvisibleChildren(true);

Build<CCNode>::create()
.id(this->makeID("title-container"))
.anchorPoint({0.f, 0.5f})
.layout(RowLayout::create()
->setDefaultScaleLimits(.1f, 1.f)
->setAxisAlignment(AxisAlignment::Start)
)
.store(m_titleContainer)
.parent(m_infoContainer)
.center()
.intoNewChild(CCLabelBMFont::create(mod->getName().c_str(), "bigFont.fnt"));

this->setID(mod->getID());
this->setContentSize(CCSize{m_bg->getScaledContentWidth(), m_bg->getScaledContentHeight()});
return true;
}

std::string ModCell::makeID(std::string id) {
return fmt::format("{}-{}", this->m_mod->getID(), id);
}

ModCell* ModCell::create(Mod* mod) {
auto ret = new ModCell();
if (ret && ret->init(mod)) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
33 changes: 33 additions & 0 deletions src/UI/ModCell.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <Geode/Geode.hpp>
#include <Geode/loader/ModMetadata.hpp>
#include <Geode/ui/GeodeUI.hpp>
#include <UIBuilder.hpp>
using namespace geode::prelude;

class ModCell : public CCNode {
protected:
bool init(Mod* mod);
void updateState();

void onEnable(CCObject*);
std::string makeID(std::string id);

Mod* m_mod;

public:
static ModCell* create(Mod* mod);
void updateSize(float width, bool big);

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;
};
65 changes: 65 additions & 0 deletions src/UI/ModProfilesLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "ModProfilesLayer.hpp"

bool ModProfilesLayer::init() {
if (!CCLayer::init()) {
return false;
}

auto director = CCDirector::get();

CCSprite* backSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");

CCMenuItemSpriteExtra* backBtn = Build<CCMenuItemSpriteExtra>::create(backSpr, this, menu_selector(ModProfilesLayer::onClose))
.id("back-button")
.collect();

CCMenu* backMenu = Build<CCMenu>::create()
.id("back-menu")
.pos(ccp(director->getScreenLeft() + 25.f, director->getScreenTop() - 22.f))
.zOrder(1)
.parent(this)
.child(backBtn)
.collect();

this->setKeyboardEnabled(true);
this->setKeypadEnabled(true);

auto bg = geode::createLayerBG();
bg->setID("content-background");
this->addChild(bg);

Build<MPListLayer>::create(ModBackend::get()->getMods(), "Export Mods")
.id("mp-list-layer")
.parent(this)
.center()
.store(m_mpListLayer);

return true;
}

void ModProfilesLayer::onClose(CCObject*) {
auto mainMenu = MenuLayer::scene(false);
CCDirector::sharedDirector()->pushScene(CCTransitionFlipAngular::create(0.5f, mainMenu));
}

void ModProfilesLayer::keyBackClicked() {
this->onClose(nullptr);
}

ModProfilesLayer* ModProfilesLayer::create() {
auto ret = new ModProfilesLayer();
if (ret && ret->init()) {
ret->autorelease();
return ret;
}

CC_SAFE_DELETE(ret);
return nullptr;
}

CCScene* ModProfilesLayer::scene() {
auto layer = ModProfilesLayer::create();
auto scene = CCScene::create();
scene->addChild(layer);
return scene;
}
32 changes: 32 additions & 0 deletions src/UI/ModProfilesLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <Geode/Geode.hpp>
#include <UIBuilder.hpp>

#include "ModCell.hpp"
#include "Utils/MPListLayer.hpp"
#include "Backend/Mods.hpp"

using namespace geode::prelude;

class ModProfilesLayer : public CCLayer {
protected:
CCScale9Sprite* m_bg;
GJListLayer* m_listLayer;

CCMenu* m_tabButtonMenu;
TabButton* m_exportTab;
TabButton* m_importTab;
TabButton* m_packsTab;

MPListLayer* m_mpListLayer;

void onClose(CCObject*);

void keyBackClicked() override;

public:
static ModProfilesLayer* create();
static CCScene* scene();
bool init() override;
};
33 changes: 0 additions & 33 deletions src/UI/ModProfilesPopup.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions src/UI/ModProfilesPopup.hpp

This file was deleted.

Loading

0 comments on commit b2e8bf2

Please sign in to comment.