Skip to content

Commit c27aa67

Browse files
committed
improve song-preview ui a bit
1 parent c2e821a commit c27aa67

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

song-preview/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
add_library(song-preview SHARED main.cpp)
22

33
target_link_libraries(song-preview UIBuilder)
4-
setup_geode_mod(song-preview)
4+
setup_geode_mod(song-preview)
5+
6+
target_compile_definitions(song-preview PRIVATE _CRT_SECURE_NO_WARNINGS=1)

song-preview/about.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,3 @@ Waveform code based off [config's code for his 2.1 mod](https://github.com/cgytr
66

77
To use this mod, go into the editor and press play when picking a custom song. There you can
88
seek the song by clicking on the waveform, and pick a start offset by dragging the cursor on top.
9-
10-
## TODO:
11-
- [X] Actually be able to type in the start offset input
12-
- [X] Add song title to popup
13-
- [ ] Design custom button for seek to start offset
14-
- [ ] Clean up code

song-preview/main.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class DetailedAudioPreviewPopup : public geode::Popup<SongInfoObject*, CustomSon
165165
CCSize m_widgetSize;
166166
CCSize m_barSize;
167167
CustomSongWidget* m_parentWidget = nullptr;
168+
CCMenuItemSpriteExtra* m_playButton = nullptr;
169+
bool m_isAlreadyChosenSong = false;
168170

169171
EventListener<SampleInfo::SampleTask> m_sampleTaskListener;
170172

@@ -175,8 +177,10 @@ class DetailedAudioPreviewPopup : public geode::Popup<SongInfoObject*, CustomSon
175177
m_parentWidget = parent;
176178

177179
if (auto* editor = LevelEditorLayer::get()) {
178-
if (editor->m_level->m_songID == m_songID)
180+
if (editor->m_level->m_songID == m_songID) {
179181
m_startOffset = editor->m_levelSettings->m_songOffset;
182+
m_isAlreadyChosenSong = true;
183+
}
180184
}
181185

182186
auto winSize = CCDirector::sharedDirector()->getWinSize();
@@ -271,11 +275,12 @@ class DetailedAudioPreviewPopup : public geode::Popup<SongInfoObject*, CustomSon
271275
->setAutoGrowAxis(1.f)
272276
->setGap(0.f)
273277
)
274-
.child(Build<CCSprite>::createSpriteName("GJ_undoBtn_001.png")
278+
.child(Build(CircleButtonSprite::createWithSprite("back.png"_spr, 1.f, CircleBaseColor::Green, CircleBaseSize::Small))
275279
.intoMenuItem(this, menu_selector(DetailedAudioPreviewPopup::onGoToStartOffset))
276280
)
277-
.child(Build<CCSprite>::createSpriteName("GJ_playMusicBtn_001.png")
281+
.child(Build<CCSprite>::createSpriteName("GJ_pauseBtn_001.png")
278282
.intoMenuItem(this, menu_selector(DetailedAudioPreviewPopup::onPlay))
283+
.store(m_playButton)
279284
)
280285
.updateLayout()
281286
)
@@ -474,11 +479,15 @@ class DetailedAudioPreviewPopup : public geode::Popup<SongInfoObject*, CustomSon
474479
void onPlay(CCObject*) {
475480
auto path = MusicDownloadManager::sharedState()->pathForSong(m_songID);
476481
auto* engine = FMODAudioEngine::sharedEngine();
482+
const char* sprite;
477483
if (engine->isMusicPlaying(0)) {
478484
engine->pauseMusic(0);
485+
sprite = "GJ_playMusicBtn_001.png";
479486
} else {
480487
engine->playMusic(path, false, 0.f, 0);
488+
sprite = "GJ_pauseBtn_001.png";
481489
}
490+
m_playButton->setNormalImage(CCSprite::createWithSpriteFrameName(sprite));
482491
}
483492

484493
void onGoToStartOffset(CCObject*) {
@@ -496,6 +505,14 @@ class DetailedAudioPreviewPopup : public geode::Popup<SongInfoObject*, CustomSon
496505
this->onClose(nullptr);
497506
}
498507

508+
void onClose(CCObject* obj) override {
509+
if (auto* editor = LevelEditorLayer::get(); editor && m_isAlreadyChosenSong) {
510+
editor->m_levelSettings->m_songOffset = m_startOffset;
511+
}
512+
513+
Popup::onClose(obj);
514+
}
515+
499516
void textChanged(CCTextInputNode* input) override {
500517
// try to parse it, ignore if it fails
501518
auto str = input->getString();

song-preview/mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"android": "2.2074",
66
"mac": "2.2074"
77
},
8-
"version": "1.1.1",
8+
"version": "1.2.0",
99
"id": "mat.song-preview",
1010
"name": "Advanced Song Preview",
1111
"developer": "mat",
@@ -18,7 +18,7 @@
1818
],
1919
"resources": {
2020
"sprites": [
21-
"res/cursor.png"
21+
"res/*.png"
2222
]
2323
},
2424
"links": {

song-preview/res/back.png

2.06 KB
Loading

0 commit comments

Comments
 (0)