From 34244784efef744709216a869f18584ec246dfa1 Mon Sep 17 00:00:00 2001 From: user666 Date: Fri, 12 Jul 2024 03:00:52 +0400 Subject: [PATCH] custom songs list --- mod.json | 31 +++++++++++-- src/songs.cpp | 124 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 146 insertions(+), 9 deletions(-) diff --git a/mod.json b/mod.json index 8e63b18..770d36d 100644 --- a/mod.json +++ b/mod.json @@ -4,7 +4,7 @@ "win": "2.206", "android": "*" }, - "version": "v7.0.0-beta.5", + "version": "v7.0.0-beta.6", "id": "user95401.mainlevelseditor", "name": "Main Levels Editor", "developer": "user95401", @@ -27,15 +27,15 @@ "default": false }, "start_id": { - "name": "Start ID", - "description": "its about populating the level list", + "name": "Level List Start ID", + "description": "its about populating the levels list", "type": "int", "min": 1, "default": 1 }, "max_id": { - "name": " Max ID", - "description": "its about populating the level list", + "name": " Level List Max ID", + "description": "its about populating the levels list", "type": "int", "min": 1, "max": 500, @@ -52,6 +52,27 @@ "description": "shows Coming Soon page", "type": "bool", "default": true + }, + "songs_start_id": { + "name": "Songs List Start ID", + "description": "its about populating the songs list", + "type": "int", + "min": 0, + "default": 0 + }, + "songs_max_id": { + "name": " Songs List Max ID", + "description": "its about populating the songs list", + "type": "int", + "min": 1, + "max": 500, + "default": 21 + }, + "practice_music": { + "name": "Practice Music", + "description": "add -1 song to list", + "type": "bool", + "default": true } } } diff --git a/src/songs.cpp b/src/songs.cpp index 6e290b4..8b6bcbd 100644 --- a/src/songs.cpp +++ b/src/songs.cpp @@ -30,11 +30,127 @@ class $modify(LevelTools) { }; #include -class $modify(SongsLayer) { +class $modify(SongsLayerExt, SongsLayer) { + void onView(CCObject* obj) { + auto audio = Audio(obj->getTag()); + auto artist = Artist(audio.m_artistID); + auto sobj = SongInfoObject::create(audio.m_audioID, audio.m_title, artist.m_name, artist.m_artistID, 1337.f, artist.m_ngURL, artist.m_ytURL, audio.m_url, 0, "", 0, 0, 0); + auto asd = CustomSongWidget::create(sobj, nullptr, 0, 0, 0, 1, 0, 0, 0); + asd->onMore(asd); + } + void addSongCell(int id, bool &altBg, CCContentLayer* contentLayer) { + auto width = contentLayer->getContentWidth(); + //hr + if (altBg) contentLayer->addChild(CCLayerColor::create( + ccColor4B(161 - 20, 88 - 20, 44 - 20, 255), + width, 1.00f + )); + //item a + auto entry = CCLayerColor::create( + altBg ? ccColor4B(161, 88, 44, 255) : ccColor4B(194, 114, 62, 255), + width, 60.000f + ); + entry->setLayout(AnchorLayout::create()); + //content + auto audio = Audio(id); + auto artist = Artist(audio.m_artistID); + auto btnAspectWidth = width - 100.0f; + if (auto nameLabel = CCLabelBMFont::create(audio.m_title.c_str(), "bigFont.fnt")) { + nameLabel->setScale(0.7f); + nameLabel->setAnchorPoint(CCPoint(0.f, 0.5f)); + //fitUpScale + if (nameLabel->getContentWidth() > btnAspectWidth) { + auto fitUpScale = btnAspectWidth / nameLabel->getContentWidth(); + if (fitUpScale < nameLabel->getScale()) nameLabel->setScale(fitUpScale); + } + //point + nameLabel->setLayoutOptions( + AnchorLayoutOptions::create() + ->setAnchor(Anchor::TopLeft) + ->setOffset(CCPoint(10.f, -20.f)) + ); + //add + entry->addChild(nameLabel); + entry->updateLayout(); + } + if (auto artistLabel = CCLabelBMFont::create(fmt::format("By {}", artist.m_name).c_str(), "goldFont.fnt")) { + artistLabel->setScale(0.7f); + artistLabel->setAnchorPoint(CCPoint(0.f, 0.5f)); + //fitUpScale + if (artistLabel->getContentWidth() > btnAspectWidth) { + auto fitUpScale = btnAspectWidth / artistLabel->getContentWidth(); + if (fitUpScale < artistLabel->getScale()) artistLabel->setScale(fitUpScale); + } + //point + artistLabel->setLayoutOptions( + AnchorLayoutOptions::create() + ->setAnchor(Anchor::BottomLeft) + ->setOffset(CCPoint(10.f, 19.f)) + ); + //add + entry->addChild(artistLabel); + entry->updateLayout(); + } + if (auto viewBtnSprite = ButtonSprite::create("View", 1.f)) { + viewBtnSprite->m_BGSprite->setContentSize(CCSize(62.65f, 30.f)); + viewBtnSprite->m_label->setFntFile("bigFont.fnt"); + viewBtnSprite->m_label->setScale(0.6f); + auto menu = CCMenu::createWithItem( + CCMenuItemSpriteExtra::create(viewBtnSprite, this, menu_selector(SongsLayerExt::onView)) + ); + cocos::getChildOfType(menu, 0)->setTag(id); + menu->setLayoutOptions( + AnchorLayoutOptions::create() + ->setAnchor(Anchor::Right) + ->setOffset(CCPoint(-42.f, 0.f)) + ); + entry->addChild(menu); + entry->updateLayout(); + } + //add + contentLayer->addChild(entry); + contentLayer->setContentHeight( + contentLayer->getContentHeight() + 1.1f + entry->getContentHeight() + ); + //hr + if (altBg) contentLayer->addChild(CCLayerColor::create( + ccColor4B(161 - 20, 88 - 20, 44 - 20, 255), + width, 1.00f + )); + //sw alt + altBg = !altBg; + } $override void customSetup() { SongsLayer::customSetup(); - //auto contentLayer = m_listLayer->m_listView;//->m_tableView->m_contentLayer; - //contentLayer->setRotation(12.f); - //contentLayer->removeAllChildrenWithCleanup(0); + auto customListView = cocos::findFirstChildRecursive(this->m_listLayer, [](auto e) { return true; }); + if (not customListView) return; + customListView->setVisible(0); + customListView->setPosition(CCPoint(customListView->getContentSize().width, 0.f)); + //ScrollLayer::create + auto scrollLayer = ScrollLayer::create(customListView->getContentSize()); + this->m_listLayer->addChild(scrollLayer); + //fill contentLayer + auto& contentLayer = scrollLayer->m_contentLayer; + contentLayer->setContentHeight(0.f); + contentLayer->setLayout( + ColumnLayout::create() + ->setGap(0) + ->setAxisReverse(true) + ->setAxisAlignment(AxisAlignment::End) + ); + auto altBg = false; + //amount + int id = SETTING(int64_t, "songs_start_id"); + int max_id = SETTING(int64_t, "songs_max_id"); + for (id; id <= max_id; id++) addSongCell(id, altBg, contentLayer); + //practice + if (SETTING(bool, "practice_music")) addSongCell(-1, altBg, contentLayer); + //update after adding + contentLayer->setContentHeight( + contentLayer->getContentHeight() > contentLayer->getParent()->getContentHeight() ? + contentLayer->getContentHeight() : + contentLayer->getParent()->getContentHeight() + ); + contentLayer->updateLayout(); } }; \ No newline at end of file