Browse Source

Add keybind to toggle current map background

kiwec 2 months ago
parent
commit
b9574d7f0a

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

@@ -126,7 +126,7 @@ void BackgroundImageHandler::handleLoadImageForEntry(ENTRY &entry) {
 }
 
 Image *BackgroundImageHandler::getLoadBackgroundImage(const DatabaseBeatmap *beatmap) {
-    if(beatmap == NULL || !osu_load_beatmap_background_images.getBool()) return NULL;
+    if(beatmap == NULL || !osu_load_beatmap_background_images.getBool() || !beatmap->draw_background) return NULL;
 
     // NOTE: no references to beatmap are kept anywhere (database can safely be deleted/reloaded without having to
     // notify the BackgroundImageHandler)

+ 1 - 0
src/App/Osu/Changelog.cpp

@@ -29,6 +29,7 @@ Changelog::Changelog() : ScreenBackable() {
     CHANGELOG latest;
     latest.title =
         UString::format("%.2f (%s, %s)", convar->getConVarByName("osu_version")->getFloat(), __DATE__, __TIME__);
+    latest.changes.push_back("- Added keybind to toggle current map background");
     latest.changes.push_back("- Fixed beatmaps not getting selected properly in some cases");
     latest.changes.push_back("- Fixed crash when osu! folder couldn't be found");
     latest.changes.push_back("- Fixed mod selection not being restored properly");

+ 6 - 0
src/App/Osu/Database.cpp

@@ -1248,6 +1248,10 @@ void Database::loadDB(Packet *db) {
                 diff->m_timingpoints.resize(numTimingPoints);
                 read_bytes(&neosu_maps, (u8 *)diff->m_timingpoints.data(), sizeof(TIMINGPOINT) * numTimingPoints);
 
+                if(version >= 20240703) {
+                    diff->draw_background = read<u8>(&neosu_maps);
+                }
+
                 diffs->push_back(diff);
             }
 
@@ -1402,6 +1406,8 @@ void Database::saveMaps() {
             u32 numTimingPoints = diff->m_timingpoints.size();
             write<u32>(&maps, numTimingPoints);
             write_bytes(&maps, (u8 *)diff->m_timingpoints.data(), sizeof(TIMINGPOINT) * numTimingPoints);
+
+            write<u8>(&maps, diff->draw_background);
         }
     }
 

+ 1 - 1
src/App/Osu/Database.h

@@ -15,7 +15,7 @@ typedef DatabaseBeatmap BeatmapDifficulty;
 typedef DatabaseBeatmap BeatmapSet;
 
 #define STARS_CACHE_VERSION 20240430
-#define NEOSU_MAPS_DB_VERSION 20240628
+#define NEOSU_MAPS_DB_VERSION 20240703
 
 // Field ordering matters here
 #pragma pack(push, 1)

+ 1 - 0
src/App/Osu/DatabaseBeatmap.h

@@ -189,6 +189,7 @@ class DatabaseBeatmap {
     inline long getLocalOffset() const { return m_iLocalOffset; }
     inline long getOnlineOffset() const { return m_iOnlineOffset; }
 
+    bool draw_background = true;
     bool do_not_store = false;
 
     // song select mod-adjusted pp/stars

+ 2 - 0
src/App/Osu/KeyBindings.cpp

@@ -35,6 +35,7 @@ ConVar KeyBindings::INSTANT_REPLAY("osu_key_instant_replay", (int)KEY_F2, FCVAR_
 ConVar KeyBindings::TOGGLE_CHAT("osu_key_toggle_chat", (int)KEY_F8, FCVAR_DEFAULT);
 ConVar KeyBindings::SAVE_SCREENSHOT("osu_key_save_screenshot", (int)KEY_F12, FCVAR_DEFAULT);
 ConVar KeyBindings::DISABLE_MOUSE_BUTTONS("osu_key_disable_mouse_buttons", (int)KEY_F10, FCVAR_DEFAULT);
+ConVar KeyBindings::TOGGLE_MAP_BACKGROUND("key_toggle_map_background", 0, FCVAR_DEFAULT);
 ConVar KeyBindings::BOSS_KEY("osu_key_boss", (int)KEY_INSERT, FCVAR_DEFAULT);
 
 ConVar KeyBindings::TOGGLE_MODSELECT("osu_key_toggle_modselect", (int)KEY_F1, FCVAR_DEFAULT);
@@ -80,6 +81,7 @@ std::vector<ConVar*> KeyBindings::ALL = {&KeyBindings::LEFT_CLICK,
                                          &KeyBindings::TOGGLE_CHAT,
                                          &KeyBindings::SAVE_SCREENSHOT,
                                          &KeyBindings::DISABLE_MOUSE_BUTTONS,
+                                         &KeyBindings::TOGGLE_MAP_BACKGROUND,
                                          &KeyBindings::BOSS_KEY,
 
                                          &KeyBindings::TOGGLE_MODSELECT,

+ 1 - 0
src/App/Osu/KeyBindings.h

@@ -41,6 +41,7 @@ class KeyBindings {
     static ConVar TOGGLE_CHAT;
     static ConVar SAVE_SCREENSHOT;
     static ConVar DISABLE_MOUSE_BUTTONS;
+    static ConVar TOGGLE_MAP_BACKGROUND;
     static ConVar BOSS_KEY;
 
     static ConVar TOGGLE_MODSELECT;

+ 1 - 0
src/App/Osu/OptionsMenu.cpp

@@ -991,6 +991,7 @@ OptionsMenu::OptionsMenu() : ScreenBackable() {
     addKeyBindButton("Increase Volume", &KeyBindings::INCREASE_VOLUME);
     addKeyBindButton("Decrease Volume", &KeyBindings::DECREASE_VOLUME);
     addKeyBindButton("Disable Mouse Buttons", &KeyBindings::DISABLE_MOUSE_BUTTONS);
+    addKeyBindButton("Toggle Map Background", &KeyBindings::TOGGLE_MAP_BACKGROUND);
     addKeyBindButton("Boss Key (Minimize)", &KeyBindings::BOSS_KEY);
     addSubSection("Keys - Song Select", keyboardSectionTags);
     addKeyBindButton("Toggle Mod Selection Screen", &KeyBindings::TOGGLE_MODSELECT)

+ 9 - 0
src/App/Osu/Osu.cpp

@@ -1238,6 +1238,15 @@ void Osu::onKeyDown(KeyboardEvent &key) {
         }
     }
 
+    if(key == (KEYCODE)KeyBindings::TOGGLE_MAP_BACKGROUND.getInt()) {
+        auto diff = getSelectedBeatmap()->getSelectedDifficulty2();
+        if(!diff) {
+            m_notificationOverlay->addNotification("No beatmap is currently selected.");
+        } else {
+            diff->draw_background = !diff->draw_background;
+        }
+    }
+
     // F8 toggle chat
     if(key == (KEYCODE)KeyBindings::TOGGLE_CHAT.getInt()) {
         // When options menu is open, instead of toggling chat, close options menu and open chat