Skip to content

Commit

Permalink
upgraded level cell
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMC9730 committed Nov 5, 2024
1 parent 366f1a3 commit 8c3f109
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 8 deletions.
Binary file modified resources/spritesheets/main/Icons/ach.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/discord.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/download.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/like-lvl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/moons_lvl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/orbs_lvl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/rank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/song_lvl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/spritesheets/main/Icons/time_lvl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 84 additions & 8 deletions src/_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class SimpleProgressBar : public cocos2d::CCLayer {
CC_SYNTHESIZE(float, _pPercentage, Percentage);
};

#include "iAndy.hpp"

class NPUiLevelCell : public cocos2d::CCNode {
private:
CCScale9Sprite* _bg;
Expand All @@ -92,6 +94,36 @@ class NPUiLevelCell : public cocos2d::CCNode {
}
};

std::string getLengthString() {
switch (_level->m_levelLength) {
case 0: {
return std::string((const char *)u8"Êîðîòêèé");
}
case 1: {
return std::string((const char*)u8"Ñðåäíèé");
}
case 2: {
return std::string((const char*)u8"Äëèííûé");
}
case 3: {
return std::string((const char*)u8"Ïëàòôîðìåð");
}
}

return "???";
}

std::string getLikeAmount() {
float mult = 1.f;

return iAndy::intToFormatString(_level->m_likes + _level->m_dislikes, mult);
}
std::string getDownloadAmount() {
float mult = 1.f;

return iAndy::intToFormatString(_level->m_downloads, mult);
}

bool init(GJGameLevel* level) {
if (!CCNode::init()) return false;

Expand Down Expand Up @@ -121,6 +153,52 @@ class NPUiLevelCell : public cocos2d::CCNode {
_titleLabel->setPositionY(10.f);
_titleLabel->setAnchorPoint({ 0.f, 0.5f });

std::string length = getLengthString();
std::string likes = getLikeAmount();
std::string downloads = getDownloadAmount();

{
CCSprite* spr = CCSprite::createWithSpriteFrameName("time_lvl.png"_spr);

CCSize sz = { 140, 70 };
CCLabelTTF* label = CCLabelTTF::create(length.c_str(), "ARIAL.ttf"_spr, 10.f, sz, CCTextAlignment::kCCTextAlignmentLeft);

spr->setScale(0.5f);
spr->setPosition({ -10.f, -7.f });
label->setPosition({ 71.f, -38.f });

_infoContainer->addChild(spr);
_infoContainer->addChild(label);
}

{
CCSprite* spr = CCSprite::createWithSpriteFrameName("download.png"_spr);

CCSize sz = { 140, 70 };
CCLabelTTF* label = CCLabelTTF::create(downloads.c_str(), "ARIAL.ttf"_spr, 10.f, sz, CCTextAlignment::kCCTextAlignmentLeft);

spr->setScale(0.5f);
spr->setPosition({ 53.f, -7.f });
label->setPosition({ 132.f, -38.f });

_infoContainer->addChild(spr);
_infoContainer->addChild(label);
}

{
CCSprite* spr = CCSprite::createWithSpriteFrameName("like-lvl.png"_spr);

CCSize sz = { 140, 70 };
CCLabelTTF* label = CCLabelTTF::create(likes.c_str(), "ARIAL.ttf"_spr, 10.f, sz, CCTextAlignment::kCCTextAlignmentLeft);

spr->setScale(0.5f);
spr->setPosition({ 110.f, -7.f });
label->setPosition({ 191.f, -38.f });

_infoContainer->addChild(spr);
_infoContainer->addChild(label);
}

if (_titleLabel->getContentWidth() > 196.f) {
float sc = _titleLabel->getContentWidth() / 196.f;
_titleLabel->setScale(_titleLabel->getScale() / sc);
Expand All @@ -146,22 +224,18 @@ class NPUiLevelCell : public cocos2d::CCNode {

CCNode* progressNode = CCNode::create();

ColumnLayout* layout = ColumnLayout::create();
layout->setAutoScale(false);

progressNode->setLayout(layout);

SimpleProgressBar* bar = SimpleProgressBar::create();
bar->setPercentage(level->m_normalPercent.value());
bar->update(0.f);
bar->setPosition({ 5.f, 1.f });
progressNode->addChild(bar);

bar = SimpleProgressBar::create();
bar->setPercentage(level->m_practicePercent);
bar->update(0.f);
bar->setPosition({ 5.f, 19.f });
bar->setBarColor({ 255, 255, 0 });
progressNode->addChild(bar);

progressNode->updateLayout();

progressNode->setScale(0.575f);
progressNode->setPosition({ 145.f, 4.f });
Expand Down Expand Up @@ -339,10 +413,12 @@ class NPUiSearch : public CCLayer {
static const auto author = u8"Ãóùèí";

GJGameLevel* leveltest = GJGameLevel::create();
leveltest->m_levelName = "test";
leveltest->m_levelName = "tesaaaaaaaaaaaaat";
leveltest->m_creatorName = (const char*)author;
leveltest->m_normalPercent = 50;
leveltest->m_practicePercent = 90;
leveltest->m_downloads = 50000;
leveltest->m_likes = 10000000;
leveltest->retain();

NPUiLevelCell* cell = NPUiLevelCell::create(leveltest);
Expand Down
77 changes: 77 additions & 0 deletions src/iAndy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* LevelAPI - Geometry Dash level cacher with search functionality and more.
Copyright (C) 2023 Sergei Baigerov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "iAndy.hpp"

#include <algorithm>

std::string iAndy::thousandSeparator(int n) {
std::string ans = "";
std::string num = std::to_string(n);

// Initialise count
int count = 0;

// Traverse the string in reverse
for (int i = num.size() - 1; i >= 0; i--) {
count++;
ans.push_back(num[i]);

// If three characters
// are traversed
if (count == 3) {
ans.push_back('.');
count = 0;
}
}

// Reverse the string to get
// the desired output
std::reverse(ans.begin(), ans.end());

// If the given string is
// less than 1000
if (ans.size() % 4 == 0) {
// Remove ','
ans.erase(ans.begin());
}

return ans;
}

std::string iAndy::intToFormatString(int n, float& scaleMult) {
if (n < 1000 || n > 100000000) return std::to_string(n);

std::string str = thousandSeparator(n);
str = str.substr(0, str.find(".") + 2);

std::string suffix;

if (n < 1000000) {
suffix = std::string((const char*)u8"òûñ.");
scaleMult = 1.1f;
}
else if (n < 100000000) {
suffix = std::string((const char*)u8"ìëí");
scaleMult = 1.5f;
}

str += suffix;

return str;
}
26 changes: 26 additions & 0 deletions src/iAndy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* LevelAPI - Geometry Dash level cacher with search functionality and more.
Copyright (C) 2023 Sergei Baigerov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <string>

namespace iAndy {
std::string thousandSeparator(int n);
std::string intToFormatString(int n, float& scaleMult);
}

0 comments on commit 8c3f109

Please sign in to comment.