Переглянути джерело

Add cvar to start initial main menu song at preview point

Clément Wolf 1 місяць тому
батько
коміт
1c4d002118

+ 1 - 27
src/App/Osu/Osu.cpp

@@ -140,6 +140,7 @@ ConVar flashlight_radius("flashlight_radius", 100.f, FCVAR_CHEAT);
 ConVar flashlight_follow_delay("flashlight_follow_delay", 0.120f, FCVAR_CHEAT);
 ConVar flashlight_always_hard("flashlight_always_hard", false, FCVAR_NONE, "always use 200+ combo flashlight radius");
 
+ConVar start_first_main_menu_song_at_preview_point("start_first_main_menu_song_at_preview_point", false, FCVAR_NONE);
 ConVar nightcore_enjoyer("nightcore_enjoyer", false, FCVAR_NONE, "automatically select nightcore when speed modifying");
 ConVar scoreboard_animations("scoreboard_animations", true, FCVAR_NONE, "animate in-game scoreboard");
 
@@ -505,16 +506,6 @@ Osu::Osu(int instanceID) {
     m_screens.push_back(m_mainMenu);
     m_screens.push_back(m_tooltipOverlay);
 
-    // make primary screen visible
-    // m_optionsMenu->setVisible(true);
-    // m_modSelector->setVisible(true);
-    // m_songBrowser2->setVisible(true);
-    // m_pauseMenu->setVisible(true);
-    // m_rankingScreen->setVisible(true);
-    // m_changelog->setVisible(true);
-    // m_editor->setVisible(true);
-    // m_userStatsScreen->setVisible(true);
-
     // Init online functionality (multiplayer/leaderboards/etc)
     bancho.osu = this;
     init_networking_thread();
@@ -527,23 +518,6 @@ Osu::Osu(int instanceID) {
 
     m_updateHandler->checkForUpdates();
 
-    /*
-    // DEBUG: immediately start diff of a beatmap
-    {
-            UString debugFolder = "S:/GAMES/osu!/Songs/41823 The Quick Brown Fox - The Big Black/";
-            UString debugDiffFileName = "The Quick Brown Fox - The Big Black (Blue Dragon) [WHO'S AFRAID OF THE BIG
-    BLACK].osu";
-
-            UString beatmapPath = debugFolder;
-            beatmapPath.append(debugDiffFileName);
-
-            OsuDatabaseBeatmap *debugDiff = new OsuDatabaseBeatmap(this, beatmapPath, debugFolder);
-
-            m_songBrowser2->onDifficultySelected(debugDiff, true);
-            // WARNING: this will leak memory (one OsuDatabaseBeatmap object), but who cares (since debug only)
-    }
-    */
-
     // memory/performance optimization; if osu_mod_mafham is not enabled, reduce the two rendertarget sizes to 64x64,
     m_osu_mod_mafham_ref->setCallback(fastdelegate::MakeDelegate(this, &Osu::onModMafhamChange));
     m_osu_mod_fposu_ref->setCallback(fastdelegate::MakeDelegate(this, &Osu::onModFPoSuChange));

+ 16 - 5
src/App/Osu/OsuBeatmap.cpp

@@ -1562,7 +1562,9 @@ bool OsuBeatmap::canUpdate() {
 }
 
 void OsuBeatmap::handlePreviewPlay() {
-    if(m_music != NULL && (!m_music->isPlaying() || m_music->getPosition() > 0.95f) && m_selectedDifficulty2 != NULL) {
+    if(m_music == nullptr) return;
+
+    if((!m_music->isPlaying() || m_music->getPosition() > 0.95f) && m_selectedDifficulty2 != NULL) {
         // this is an assumption, but should be good enough for most songs
         // reset playback position when the song has nearly reached the end (when the user switches back to the results
         // screen or the songbrowser after playing)
@@ -1574,14 +1576,23 @@ void OsuBeatmap::handlePreviewPlay() {
             if(m_music->getFrequency() < m_fMusicFrequencyBackup)  // player has died, reset frequency
                 m_music->setFrequency(m_fMusicFrequencyBackup);
 
-            if(m_osu->getMainMenu()->isVisible())
+            // When McOsu is initialized, it starts playing a random song in the main menu.
+            // Users can set a convar to make it start at its preview point instead.
+            // The next songs will start at the beginning regardless.
+            static bool should_start_song_at_preview_point =
+                convar->getConVarByName("start_first_main_menu_song_at_preview_point")->getBool();
+            bool start_at_song_beginning = m_osu->getMainMenu()->isVisible() && !should_start_song_at_preview_point;
+            should_start_song_at_preview_point = false;
+
+            if(start_at_song_beginning) {
                 m_music->setPositionMS(0);
-            else if(m_iContinueMusicPos != 0)
+            } else if(m_iContinueMusicPos != 0) {
                 m_music->setPositionMS(m_iContinueMusicPos);
-            else
+            } else {
                 m_music->setPositionMS(m_selectedDifficulty2->getPreviewTime() < 0
                                            ? (unsigned long)(m_music->getLengthMS() * 0.40f)
                                            : m_selectedDifficulty2->getPreviewTime());
+            }
 
             m_music->setVolume(m_osu_volume_music_ref->getFloat());
             m_music->setSpeed(m_osu->getSpeedMultiplier());
@@ -1589,7 +1600,7 @@ void OsuBeatmap::handlePreviewPlay() {
     }
 
     // always loop during preview
-    if(m_music != NULL) m_music->setLoop(osu_beatmap_preview_music_loop.getBool());
+    m_music->setLoop(osu_beatmap_preview_music_loop.getBool());
 }
 
 void OsuBeatmap::loadMusic(bool stream, bool prescan) {

+ 2 - 2
src/App/Osu/OsuMainMenu.cpp

@@ -1267,7 +1267,7 @@ void OsuMainMenu::mouse_update(bool *propagate_clicks) {
         anim->moveQuadInOut(&m_fUpdateButtonAnim, 1.0f, 0.5f, true);
     }
 
-    // handle pause button pause detection
+    // Update pause button and shuffle songs
     if(m_osu->getSelectedBeatmap() != NULL) {
         if(m_osu->getSelectedBeatmap()->isPreviewMusicPlaying()) {
             m_osu->getSelectedBeatmap()->getMusic()->setLoop(false);
@@ -1286,7 +1286,7 @@ void OsuMainMenu::selectRandomBeatmap() {
     shuffling = true;
 
     if(m_osu->getSongBrowser()->getDatabase()->isFinished()) {
-        m_osu->getSongBrowser()->selectRandomBeatmap(false);
+        m_osu->getSongBrowser()->selectRandomBeatmap();
     } else {
         // Database is not loaded yet, load a random map and select it
         // XXX: Also pick from McOsu maps/ directory

+ 2 - 8
src/App/Osu/OsuSongBrowser.cpp

@@ -1,9 +1,4 @@
-//================ Copyright (c) 2016, PG, All rights reserved. =================//
-//
-// Purpose:		beatmap browser and selector
-//
-// $NoKeywords: $osusb
-//===============================================================================//
+#include "OsuSongBrowser.h"
 
 #include "AnimationHandler.h"
 #include "Bancho.h"
@@ -35,7 +30,6 @@
 #include "OsuRoom.h"
 #include "OsuSkin.h"
 #include "OsuSkinImage.h"
-#include "OsuSongBrowser.h"
 #include "OsuUIBackButton.h"
 #include "OsuUIContextMenu.h"
 #include "OsuUISearchOverlay.h"
@@ -4116,7 +4110,7 @@ void OsuSongBrowser::selectSongButton(OsuUISongBrowserButton *songButton) {
     }
 }
 
-void OsuSongBrowser::selectRandomBeatmap(bool playMusicFromPreviewPoint) {
+void OsuSongBrowser::selectRandomBeatmap() {
     // filter songbuttons or independent diffs
     const std::vector<CBaseUIElement *> &elements = m_songBrowser->getContainer()->getElements();
     std::vector<OsuUISongBrowserSongButton *> songButtons;

+ 2 - 13
src/App/Osu/OsuSongBrowser.h

@@ -1,13 +1,4 @@
-//================ Copyright (c) 2016, PG, All rights reserved. =================//
-//
-// Purpose:		beatmap browser and selector
-//
-// $NoKeywords: $osusb
-//===============================================================================//
-
-#ifndef OSUSONGBROWSER2_H
-#define OSUSONGBROWSER2_H
-
+#pragma once
 #include "MouseListener.h"
 #include "OsuScreenBackable.h"
 
@@ -124,7 +115,7 @@ class OsuSongBrowser : public OsuScreenBackable {
     void onCollectionButtonContextMenu(OsuUISongBrowserCollectionButton *collectionButton, UString text, int id);
 
     void highlightScore(uint64_t unixTimestamp);
-    void selectRandomBeatmap(bool playMusicFromPreviewPoint = true);
+    void selectRandomBeatmap();
     void playNextRandomBeatmap() {
         selectRandomBeatmap();
         playSelectedDifficulty();
@@ -393,5 +384,3 @@ class OsuSongBrowser : public OsuScreenBackable {
     bool m_bBackgroundStarCalcScheduledForce;
     OsuDatabaseBeatmapStarCalculator *m_dynamicStarCalculator;
 };
-
-#endif