Skip to content

Commit 4dfa87f

Browse files
committed
Added toggle in the options to show battery percentage.
1 parent f1f6c50 commit 4dfa87f

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/ClockUpdater.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,20 @@ void ClockMod::ClockUpdater::Update() {
4545
// Sets position
4646
// text->get_transform()->set_position(UnityEngine::Vector3(0, 1, 2.6));
4747
// Get current Battery Level
48-
float batterylvl = GlobalNamespace::OVRPlugin::OVRP_1_1_0::ovrp_GetSystemBatteryLevel();
49-
batterylvl = batterylvl * 100;
50-
std::string tandb = timestr;
51-
tandb += " ";
52-
std::string batterylevel = std::to_string(batterylvl);
53-
batterylevel.erase(batterylevel.find_last_not_of('0') + 1, std::string::npos);
54-
batterylevel.erase(batterylevel.find_last_not_of('.') + 1, std::string::npos);
55-
tandb += batterylevel;
56-
tandb += "%";
48+
if (getConfig().config["BattToggle"].GetBool() == true) {
49+
float batterylvl = GlobalNamespace::OVRPlugin::OVRP_1_1_0::ovrp_GetSystemBatteryLevel();
50+
batterylvl = batterylvl * 100;
51+
std::string tandb = timestr;
52+
tandb += " - ";
53+
std::string batterylevel = std::to_string(batterylvl);
54+
batterylevel.erase(batterylevel.find_last_not_of('0') + 1, std::string::npos);
55+
batterylevel.erase(batterylevel.find_last_not_of('.') + 1, std::string::npos);
56+
tandb += batterylevel;
57+
tandb += "%";
5758

58-
text->set_text(il2cpp_utils::createcsstr(tandb));
59+
text->set_text(il2cpp_utils::createcsstr(tandb));
60+
}
61+
else {
62+
text->set_text(il2cpp_utils::createcsstr(timestr));
63+
}
5964
}

src/ClockViewContoller.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ void SecToggle(ClockMod::ClockViewController* parent, bool newValue) {
2626
void SetFontSize(ClockMod::ClockViewController* parent, float newValue) {
2727
getConfig().config["FontSize"].SetFloat(newValue);
2828
}
29+
void BattToggle(ClockMod::ClockViewController* parent, bool newValue) {
30+
getConfig().config["BattToggle"].SetBool(newValue);
31+
}
2932

3033
void ClockMod::ClockViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) {
3134
if (firstActivation) {
@@ -55,6 +58,12 @@ void ClockMod::ClockViewController::DidActivate(bool firstActivation, bool added
5558
classof(UnityEngine::Events::UnityAction_1<float>*), this, SetFontSize); // Decimal places Value Steps Min Value Max Value
5659
QuestUI::IncrementSetting* FontIncrementObject = QuestUI::BeatSaberUI::CreateIncrementSetting(container->get_transform(), "Font Size", 1, 0.1, getConfig().config["FontSize"].GetFloat(), 1.0f, 8.0f, onFontSizeChange);
5760
QuestUI::BeatSaberUI::AddHoverHint(FontIncrementObject->get_gameObject(), "Changes the Font Size of the Clock (Default: 4)");
61+
// Show Seconds
62+
auto onBattSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
63+
classof(UnityEngine::Events::UnityAction_1<bool>*), this, BattToggle
64+
);
65+
UnityEngine::UI::Toggle* BattToggleObject = QuestUI::BeatSaberUI::CreateToggle(container->get_transform(), "Show Battery Percentage", getConfig().config["BattToggle"].GetBool(), onBattSettingChange);
66+
QuestUI::BeatSaberUI::AddHoverHint(BattToggleObject->get_gameObject(), "Displays Battery percentage next to clock.");
5867
}
5968
}
6069
// Write config

src/main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ extern "C" void setup(ModInfo & info) {
164164
getConfig().config.AddMember("FontSize", rapidjson::Value(0).SetFloat(4), allocator);
165165
getConfig().Write();
166166
}
167+
if (!getConfig().config.HasMember("BattToggle")) {
168+
getConfig().config.AddMember("BattToggle", rapidjson::Value(0).SetBool(false), allocator);
169+
getConfig().Write();
170+
}
167171
}
168172

169173
// Called later on in the game loading - a good time to install function hooks

0 commit comments

Comments
 (0)