Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
official alpha release! please report any bugs, as i dont want to be sad :( will now try to work on savefiles / auto load dll, we'll see how that goes. suggestions are welcome as well!
  • Loading branch information
poweredbypie committed Oct 4, 2020
1 parent 1493de2 commit b702c60
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 35 deletions.
89 changes: 77 additions & 12 deletions src/classes/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void list::update() {
getLength();

if (m_displayedLength) {
if (!m_init) {
if (!m_entered) {
m_pArrListLabels[0] = label::create(m_listStrings[m_listOffset].c_str(), "bigFont.fnt");
node::setPos(m_pArrListLabels[0], m_x, m_y);
node::setScale(m_pArrListLabels[0], 1.3f / ((m_listStrings[m_listOffset].length() + 10) * 0.1f));
Expand Down Expand Up @@ -80,11 +80,11 @@ void list::enter(void* scene) {

node::addChild(scene, m_menu);

m_init = true;
m_entered = true;
}

void list::exit() {
m_init = false;
m_entered = false;
}

list::list(const char* title, int length) {
Expand All @@ -99,11 +99,44 @@ list::list(const char* title, int length) {
listManager::add(this);
}

void list::setArray(const std::vector<std::string>& arr) {
m_listStrings = arr;
void list::setVector(const std::vector<std::string>& vec) {
m_listStrings = vec;
}

const std::vector<std::string>& list::getArray() {
void list::removeIfNotFound(const std::vector<std::string>& other, bool isTarget) {
if (isTarget) {
for (int i{}; i < (int)other.size(); ++i) {
if (std::find(m_listStrings.begin(), m_listStrings.end(), other[i]) == m_listStrings.end()) {
m_listStrings.erase(m_listStrings.begin() + i);
--i;
}

}
}
else {
for (int i{}; i < (int)m_listStrings.size(); ++i) {
if (std::find(other.begin(), other.end(), m_listStrings[i]) == other.end()) {
m_listStrings.erase(m_listStrings.begin() + i);
--i;
}
}
}

getLength();

//not tested, maybe do it later but the use case isnt functional in this instance
if (!m_listStrings.empty()) {
if (m_listOffset > (int)m_listStrings.size() - 1)
m_listOffset = (int)m_listStrings.size() - 1;
}
else {
m_listOffset = 0;
}

update();
}

std::vector<std::string>& list::getVector() {
return m_listStrings;
}

Expand Down Expand Up @@ -146,13 +179,13 @@ void listExt::navigate(bool up) {

void listExt::swap(bool up) {
if (up) {
if (m_moveIndex + m_listOffset != 0) {
if (m_moveIndex > 0) {
std::iter_swap(m_listStrings.begin() + m_moveIndex + m_listOffset, m_listStrings.begin() + m_moveIndex + m_listOffset - 1);
--m_moveIndex;
}
}
else {
if (m_moveIndex + m_listOffset + 1 != m_listStrings.size()) {
if (m_moveIndex < m_displayedLength - 1) {
std::iter_swap(m_listStrings.begin() + m_moveIndex + m_listOffset, m_listStrings.begin() + m_moveIndex + m_listOffset + 1);
++m_moveIndex;
}
Expand All @@ -179,7 +212,7 @@ void listExt::updateLabels() {

getLength();

if (!m_init) {
if (!m_entered) {

for (int i{}; i < m_maxDisplayedLength; ++i) {
if (i < m_displayedLength) {
Expand Down Expand Up @@ -211,7 +244,7 @@ void listExt::updateLabels() {
void listExt::updateSelector() {
using namespace cocos;

if (!m_init) {
if (!m_entered) {
void* navSprite = sprite::create("navArrowBtn_001.png");
m_moveBtn = menuItem::createSpr(navSprite, navSprite, 0, m_menu, m_moveFn);

Expand Down Expand Up @@ -309,11 +342,11 @@ void listExt::enter(void* scene) {

node::addChild(scene, m_menu);

m_init = true;
m_entered = true;
}

void listExt::exit() {
m_init = false;
m_entered = false;
}

listExt::listExt(const char* title, int length, listExt* target) : list(title, length) {
Expand All @@ -323,6 +356,38 @@ listExt::listExt(const char* title, int length, listExt* target) : list(title, l
m_target = target;
}

void listExt::removeIfNotFound(const std::vector<std::string>& other, bool isTarget) {
if (isTarget) {
for (int i{}; i < (int)other.size(); ++i) {
if (std::find(m_listStrings.begin(), m_listStrings.end(), other[i]) == m_listStrings.end()) {
m_listStrings.erase(m_listStrings.begin() + i);
--i;
}

}
}
else {
for (int i{}; i < (int)m_listStrings.size(); ++i) {
if (std::find(other.begin(), other.end(), m_listStrings[i]) == other.end()) {
m_listStrings.erase(m_listStrings.begin() + i);
--i;
}
}
}

getLength();

//make this better. if you move more than 10 items, it'll look weird. i dont think it breaks, but it just isn't very clean.
if (m_moveIndex + 1 > m_displayedLength) {
if (m_displayedLength > 1)
m_moveIndex = m_displayedLength - 1;
else
m_moveIndex = 0;
}

update();
}

//listManager

void listManager::add(list* list) {
Expand Down
8 changes: 5 additions & 3 deletions src/classes/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class list {
void** m_pArrListLabels{};
int m_maxDisplayedLength{};
int m_displayedLength{};
bool m_init{ false };
bool m_entered{ false };
float m_x{}, m_y{};

BUTTON_T m_upBtn{};
Expand All @@ -43,8 +43,9 @@ class list {

public:
list(const char* title, int length);
void setArray(const std::vector<std::string>& arr);
const std::vector<std::string>& getArray();
void setVector(const std::vector<std::string>& vec);
virtual void removeIfNotFound(const std::vector<std::string>& other, bool isTarget);
std::vector<std::string>& getVector();
const int getCurrentIndex();

void setPosition(float x, float y);
Expand Down Expand Up @@ -85,6 +86,7 @@ class listExt : public list {

public:
listExt(const char* title, int length, listExt* target);
virtual void removeIfNotFound(const std::vector<std::string>& other, bool isTarget);

friend class listManager;
};
Expand Down
51 changes: 31 additions & 20 deletions src/ldr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace ldr {
list quality{ "quality", 1 };

extern listExt applied;
listExt all{ "available", 10, &applied};
listExt applied{ "applied", 10, &all};
listExt all{ "available", 10, &applied };
listExt applied{ "applied", 10, &all };

bool bTransition{ true };

Expand All @@ -21,8 +21,8 @@ namespace ldr {
void COCOS_HOOK addPath(void* CCFileUtils, void* __EDX, const char* path) {
using namespace vars;

for (int i{}; i < (int)applied.getArray().size(); ++i) {
gAddPath(CCFileUtils, ("packs\\" + applied.getArray()[i]).c_str());
for (int i{}; i < (int)applied.getVector().size(); ++i) {
gAddPath(CCFileUtils, ("packs\\" + applied.getVector()[i]).c_str());
}
return gAddPath(CCFileUtils, path);
}
Expand All @@ -35,18 +35,19 @@ namespace ldr {
}
}

std::vector<std::string> getPacks() {
BTN_CALLBACK(getPacks) {
using namespace std::filesystem;
using namespace vars;

std::vector<std::string> packList{};
std::vector<std::string> packsList{};

path packs = current_path() / "packs";
if (exists(packs)) {
if (is_directory(packs)) {
directory_iterator packsIter{ packs };
for (directory_entry pack : packsIter) {
if (is_directory(pack))
packList.push_back(pack.path().filename().string());
packsList.push_back(pack.path().filename().string());
}
}
else {
Expand All @@ -58,7 +59,22 @@ namespace ldr {
create_directories(packs);
MessageBox(0, "created packs folder.", "textureldr", MB_OK);
}
return packList;

if (!(all.getVector().empty() && applied.getVector().empty())) {
std::vector<std::string> oldPacks{ all.getVector() };
oldPacks.insert(oldPacks.end(), applied.getVector().begin(), applied.getVector().end());

for (std::string pack : packsList) {
if (std::find(oldPacks.begin(), oldPacks.end(), pack) == oldPacks.end()) {
all.getVector().insert(all.getVector().begin(), pack);
}
}
all.removeIfNotFound(packsList, false);
applied.removeIfNotFound(packsList, false);
}
else {
all.setVector(packsList);
}
}

BTN_CALLBACK(enterScene) {
Expand Down Expand Up @@ -86,14 +102,11 @@ namespace ldr {
node::setPos(backBtn, -winSize.x / 2 + 25.0f, winSize.y / 2 - 25.0f);
node::addChild(miscBtns, backBtn);

void* navSprite = sprite::create("navArrowBtn_001.png");
/*void* leftBtn = menuItem::createSpr(navSprite, navSprite, 0, miscBtns, left);
node::setPos(leftBtn, -winSize.x / 2 + 25.0f, 0.0f);
node::setRot(leftBtn, 180.0f);
node::addChild(miscBtns, leftBtn);
void* rightBtn = menuItem::createSpr(navSprite, navSprite, 0, miscBtns, right);
node::setPos(rightBtn, winSize.x / 2 - 25.0f, 0.0f);
node::addChild(miscBtns, rightBtn);*/
void* reloadSprite = sprite::create("GJ_updateBtn_001.png");
void* reloadBtn = menuItem::createSpr(reloadSprite, reloadSprite, 0, miscBtns, getPacks);
node::setPos(reloadBtn, winSize.x / 2 - 35.0f, -winSize.y / 2 + 35.0f);
node::setScale(reloadBtn, 1.1f);
node::addChild(miscBtns, reloadBtn);

void* transition = transition::create(0.5f, ldrScene);
director::replaceScene(director, transition);
Expand Down Expand Up @@ -128,8 +141,6 @@ namespace ldr {
using namespace gd;
using namespace vars;



void* director = director::get();
director::updateScale(director, quality.getCurrentIndex() + 1);
*(gd::gamemanager::ptr + 0xB8) = quality.getCurrentIndex() + 1;
Expand All @@ -139,10 +150,10 @@ namespace ldr {
bool init() {
using namespace vars;

quality.setArray({"LOW", "MEDIUM", "HIGH"});
quality.setVector({"LOW", "MEDIUM", "HIGH"});
quality.setPosition(0.0f, -130.0f);

all.setArray(getPacks());
getPacks(0);
all.setPosition(-90.0f, 95.0f);
applied.setPosition(90.0f, 95.0f);

Expand Down

0 comments on commit b702c60

Please sign in to comment.