From f1df55e6c325c4895e2f3c192823950a521810ef Mon Sep 17 00:00:00 2001 From: Cvolton Date: Sat, 7 Dec 2024 15:15:51 +0100 Subject: [PATCH] make extendedlevelinfo copyable --- src/layers/ExtendedLevelInfo.cpp | 99 +++++++++++++++++++++++++++----- src/layers/ExtendedLevelInfo.h | 3 + 2 files changed, 87 insertions(+), 15 deletions(-) diff --git a/src/layers/ExtendedLevelInfo.cpp b/src/layers/ExtendedLevelInfo.cpp index 39a1c40..b882fdb 100644 --- a/src/layers/ExtendedLevelInfo.cpp +++ b/src/layers/ExtendedLevelInfo.cpp @@ -2,6 +2,7 @@ #include "../utils.hpp" //#include "../managers/BetterInfoStatsV2.h" #include "../managers/BetterInfoCache.h" +#include "../ui/CopyableLabel.h" #include #include @@ -42,6 +43,14 @@ void ExtendedLevelInfo::onCopyDesc(cocos2d::CCObject* sender) BetterInfo::copyToClipboard(m_level->getUnpackedLevelDescription().c_str(), this); } +void ExtendedLevelInfo::onCopyInfo(cocos2d::CCObject* sender) +{ + auto& info = m_page % 2 == 0 ? m_primaryValues : m_secondaryValues; + if(info.size() <= sender->getTag()) return; + + BetterInfo::copyToClipboard(info[sender->getTag()].c_str(), this); +} + void ExtendedLevelInfo::onNext(cocos2d::CCObject* sender) { loadPage(m_page+1); @@ -74,30 +83,59 @@ void ExtendedLevelInfo::loadPage(int page) { void ExtendedLevelInfo::refreshInfoTexts() { auto cache = BetterInfoCache::sharedState(); + std::ostringstream infoText; + + m_primaryValues.clear(); + m_secondaryValues.clear(); + + //first page auto uploadDateStd = std::string(m_level->m_uploadDate); auto updateDateStd = std::string(m_level->m_updateDate); int levelPassword = m_level->m_password; - std::ostringstream infoText; - infoText << "\nUploaded: " << LevelMetadata::stringDate(!uploadDateStd.empty() ? uploadDateStd : LevelMetadata::addPlus(cache->getLevelInfo(m_level->m_levelID, "upload-date"))) - << "\nUpdated: " << LevelMetadata::stringDate(!updateDateStd.empty() ? updateDateStd : LevelMetadata::addPlus(cache->getLevelInfo(m_level->m_levelID, "update-date"))) + + m_primaryValues.push_back(LevelMetadata::stringDate(!uploadDateStd.empty() ? uploadDateStd : LevelMetadata::addPlus(cache->getLevelInfo(m_level->m_levelID, "upload-date")))); + m_primaryValues.push_back(LevelMetadata::stringDate(!updateDateStd.empty() ? updateDateStd : LevelMetadata::addPlus(cache->getLevelInfo(m_level->m_levelID, "update-date")))); + m_primaryValues.push_back(LevelMetadata::zeroIfNA(m_level->m_originalLevel)); + m_primaryValues.push_back(LevelMetadata::getGameVersionName(m_level->m_gameVersion)); + m_primaryValues.push_back(LevelMetadata::passwordString(levelPassword)); + m_primaryValues.push_back(TimeUtils::workingTime(m_level->m_workingTime)); + m_primaryValues.push_back(TimeUtils::workingTime(m_level->m_workingTime2)); + + infoText << "\nUploaded: " << m_primaryValues[0] + << "\nUpdated: " << m_primaryValues[1] //<< "\nStars Requested: " << m_level->m_starsRequested - << "\nOriginal: " << LevelMetadata::zeroIfNA(m_level->m_originalLevel) + << "\nOriginal: " << m_primaryValues[2] //<< "\nFeature score: " << LevelMetadata::zeroIfNA(m_level->m_featured) - << "\nGame Version: " << LevelMetadata::getGameVersionName(m_level->m_gameVersion) + << "\nGame Version: " << m_primaryValues[3] //<< "\nFeature Score: " << m_level->m_featured - << "\nPassword: " << LevelMetadata::passwordString(levelPassword) - << "\nIn Editor: " << TimeUtils::workingTime(m_level->m_workingTime) - << "\nEditor (C): " << TimeUtils::workingTime(m_level->m_workingTime2); + << "\nPassword: " << m_primaryValues[4] + << "\nIn Editor: " << m_primaryValues[5] + << "\nEditor (C): " << m_primaryValues[6]; m_primary = infoText.str(); + + //second page + size_t offset = 0; + infoText.str(""); - if(!ServerUtils::isGDPS()) infoText << "\nUploaded: " << TimeUtils::isoTimeToString(m_uploadDateEstimated); - infoText << "\nObjects: " << LevelMetadata::zeroIfNA(m_level->m_objectCount) - << "\nObjects (est.): " << LevelMetadata::zeroIfNA(m_objectsEstimated) - << "\nGame Ver (est.): " << m_maxGameVersion - << "\nFeature Score: " << LevelMetadata::zeroIfNA(m_level->m_featured) - << "\nTwo-player: " << LevelMetadata::boolString(m_level->m_twoPlayerMode) - << "\nSize: " << m_fileSizeCompressed << " / " << m_fileSizeUncompressed; + if(!ServerUtils::isGDPS()) { + m_secondaryValues.push_back(TimeUtils::isoTimeToString(m_uploadDateEstimated)); + infoText << "\nUploaded: " << m_secondaryValues[offset++]; + } + + m_secondaryValues.push_back(LevelMetadata::zeroIfNA(m_level->m_objectCount)); + m_secondaryValues.push_back(LevelMetadata::zeroIfNA(m_objectsEstimated)); + m_secondaryValues.push_back(m_maxGameVersion); + m_secondaryValues.push_back(LevelMetadata::zeroIfNA(m_level->m_featured)); + m_secondaryValues.push_back(LevelMetadata::boolString(m_level->m_twoPlayerMode)); + m_secondaryValues.push_back(m_fileSizeCompressed + " / " + m_fileSizeUncompressed); + + infoText << "\nObjects: " << m_secondaryValues[offset++] + << "\nObjects (est.): " << m_secondaryValues[offset++] + << "\nGame Ver (est.): " << m_secondaryValues[offset++] + << "\nFeature Score: " << m_secondaryValues[offset++] + << "\nTwo-player: " << m_secondaryValues[offset++] + << "\nSize: " << m_secondaryValues[offset++]; ; m_secondary = infoText.str(); @@ -136,6 +174,8 @@ void ExtendedLevelInfo::setupAdditionalInfo() { bool ExtendedLevelInfo::init(GJGameLevel* level){ if(!CvoltonAlertLayerStub::init({440.0f, 290.0f})) return false; + auto winSize = CCDirector::sharedDirector()->getWinSize(); + this->m_level = level; auto levelName = CCLabelBMFont::create(m_level->m_levelName.c_str(), "bigFont.fnt"); @@ -284,6 +324,35 @@ bool ExtendedLevelInfo::init(GJGameLevel* level){ m_nextBtn->setID("next-button"_spr); m_buttonMenu->addChild(m_nextBtn); + /* + copy buttons + */ + auto copyMenu = CCMenu::create(); + copyMenu->setLayout( + ColumnLayout::create() + ->setAxisReverse(true) + ->setGap(-1.5f) + ); + copyMenu->setContentSize({170,148}); + copyMenu->setPosition({winSize.width / 2 - 83, winSize.height / 2 - 56}); + copyMenu->setID("copy-menu"_spr); + copyMenu->setZOrder(11); + m_mainLayer->addChild(copyMenu); + + for(size_t i = 0; i < 7; i++) { + auto btn = CCMenuItemSpriteExtra::create( + ButtonSprite::create("h", 170, true, "bigFont.fnt", "GJ_button_01.png", 20, 1), + this, + menu_selector(ExtendedLevelInfo::onCopyInfo) + ); + btn->getNormalImage()->setVisible(false); + btn->setTag(i); + btn->setID(fmt::format("copy-button-{}"_spr, i)); + copyMenu->addChild(btn); + } + + copyMenu->updateLayout(); + loadPage(0); return true; diff --git a/src/layers/ExtendedLevelInfo.h b/src/layers/ExtendedLevelInfo.h index 15bc962..2d725c9 100644 --- a/src/layers/ExtendedLevelInfo.h +++ b/src/layers/ExtendedLevelInfo.h @@ -14,6 +14,8 @@ class BI_DLL ExtendedLevelInfo : public CvoltonAlertLayerStub, public UploadDate std::string m_fileSizeUncompressed = "NA"; std::string m_maxGameVersion = "NA"; std::string m_uploadDateEstimated = "NA"; + std::vector m_primaryValues; + std::vector m_secondaryValues; Ref m_level; TextArea* m_info; CCMenuItemSpriteExtra* m_prevBtn; @@ -26,6 +28,7 @@ class BI_DLL ExtendedLevelInfo : public CvoltonAlertLayerStub, public UploadDate void onCopyName(cocos2d::CCObject* sender); void onCopyAuthor(cocos2d::CCObject* sender); void onCopyDesc(cocos2d::CCObject* sender); + void onCopyInfo(cocos2d::CCObject* sender); void onNext(cocos2d::CCObject* sender); void onPrev(cocos2d::CCObject* sender); void onUploadDateLoaded(int levelID, const std::string& date);