Skip to content

Commit 3d2350e

Browse files
committed
tweak floating btn
1 parent f0aa33a commit 3d2350e

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

mod.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"Geode"
8080
]
8181
},
82-
"floating-button": {
82+
"floating-btn": {
8383
"type": "bool",
8484
"name": "Floating Menu Button",
8585
"description": "Show a floating button on the main menu to quickly access the <cg>Horrible Options</c> menu.",
@@ -90,14 +90,14 @@
9090
"ios": true
9191
}
9292
},
93-
"floating-button-level": {
93+
"floating-btn-level": {
9494
"type": "bool",
9595
"name": "Show Button in Level",
9696
"description": "Show the floating menu button while playing a level.",
9797
"default": false,
98-
"enable-if": "floating-button"
98+
"enable-if": "floating-btn"
9999
},
100-
"floating-button-scale": {
100+
"floating-btn-scale": {
101101
"type": "float",
102102
"name": "Floating Button Scale",
103103
"description": "Change the size of the floating button.",
@@ -113,9 +113,9 @@
113113
"big-arrows": true,
114114
"big-arrow-step": 0.5
115115
},
116-
"enable-if": "floating-button"
116+
"enable-if": "floating-btn"
117117
},
118-
"floating-button-opacity": {
118+
"floating-btn-opacity": {
119119
"type": "int",
120120
"name": "Floating Button Opacity",
121121
"description": "Change the opacity of the floating button.",
@@ -131,7 +131,7 @@
131131
"big-arrows": true,
132132
"big-arrow-step": 20
133133
},
134-
"enable-if": "floating-button"
134+
"enable-if": "floating-btn"
135135
},
136136
"chances": {
137137
"type": "title",

src/Utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace horrible {
4949
// For convenience
5050
namespace setting {
5151
inline constexpr auto SafeMode = "safe-mode";
52-
inline constexpr auto FloatingBtn = "floating-button";
52+
inline constexpr auto FloatingBtn = "floating-btn";
5353
};
5454

5555
// Default option categories

src/main.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ inline static std::vector<Hook*> floatingBtnHooks;
6969
});
7070

7171
listenForSettingChanges<bool>(
72-
"floating-button-level",
72+
"floating-btn-level",
7373
[](bool value) {
7474
if (auto fb = OptionMenuButton::get()) fb->setShowInLevel(value);
7575
});
7676

7777
listenForSettingChanges<float>(
78-
"floating-button-scale",
78+
"floating-btn-scale",
7979
[](float value) {
8080
if (auto fb = OptionMenuButton::get()) fb->setScale(value);
8181
});
8282

8383
listenForSettingChanges<int64_t>(
84-
"floating-button-opacity",
84+
"floating-btn-opacity",
8585
[](int64_t value) {
8686
if (auto fb = OptionMenuButton::get()) fb->setOpacity(value);
8787
});
@@ -126,7 +126,11 @@ class $modify(HIFloatBtnPauseLayer, PauseLayer) {
126126
HORRIBLE_HOOK_FLOATINGBTN;
127127

128128
void customSetup() {
129-
if (auto fb = OptionMenuButton::get()) fb->setVisible(horribleMod->getSettingValue<bool>(setting::FloatingBtn));
129+
auto toggle = horribleMod->getSettingValue<bool>(setting::FloatingBtn);
130+
131+
log::trace("{} floating button", toggle ? "Showing" : "Hiding");
132+
if (auto fb = OptionMenuButton::get()) fb->setVisible(toggle);
133+
130134
PauseLayer::customSetup();
131135
};
132136
};
@@ -150,16 +154,17 @@ class $modify(HIFloatBtnPlayLayer, PlayLayer) {
150154
};
151155

152156
void onQuit() {
153-
toggleButton();
157+
toggleButton(true);
154158
PlayLayer::onQuit();
155159
};
156160

157161
void showEndLayer() {
158-
PlayLayer::showEndLayer();
159162
toggleButton(true);
163+
PlayLayer::showEndLayer();
160164
};
161165

162166
void toggleButton(bool toggle = false) {
167+
log::trace("{} floating button", toggle ? "Showing" : "Hiding");
163168
if (auto fb = OptionMenuButton::get()) fb->setVisible(horribleMod->getSettingValue<bool>(setting::FloatingBtn) && (fb->showInLevel() || toggle));
164169
};
165170
};

src/menu/src/OptionMenuButton.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ using namespace horrible::prelude;
88

99
class OptionMenuButton::Impl final {
1010
public:
11-
bool inLevel = horribleMod->getSettingValue<bool>("floating-button-level");
11+
bool inLevel = horribleMod->getSettingValue<bool>("floating-btn-level");
1212

13-
float scale = horribleMod->getSettingValue<float>("floating-button-scale");
14-
int64_t opacity = horribleMod->getSettingValue<int64_t>("floating-button-opacity");
13+
float scale = horribleMod->getSettingValue<float>("floating-btn-scale");
14+
int64_t opacity = horribleMod->getSettingValue<int64_t>("floating-btn-opacity");
1515

1616
bool isDragging = false;
1717
bool isMoving = false;
@@ -43,7 +43,7 @@ void OptionMenuButton::setupSprite() {
4343
setScale(m_impl->scale); // set initial scale
4444
setOpacity(m_impl->opacity); // set initial opacity
4545

46-
setVisible(horribleMod->getSettingValue<bool>("floating-button")); // set initial visibility
46+
setVisible(horribleMod->getSettingValue<bool>("floating-btn")); // set initial visibility
4747

4848
addChild(m_impl->sprite);
4949
};
@@ -55,7 +55,7 @@ bool OptionMenuButton::init() {
5555
float x = horribleMod->getSavedValue<float>("button-x", 100.f);
5656
float y = horribleMod->getSavedValue<float>("button-y", 125.f);
5757

58-
setID("floating-button"_spr);
58+
setID("floating-btn"_spr);
5959
setPosition({x, y});
6060
setAnchorPoint({0.5, 0.5});
6161
setTouchMode(kCCTouchesOneByOne);

0 commit comments

Comments
 (0)