Skip to content

Commit 732d0ca

Browse files
committed
Clock can now be "Rainbowified thanks to code from RedBrumbler.
1 parent 75fd9cf commit 732d0ca

File tree

5 files changed

+126
-60
lines changed

5 files changed

+126
-60
lines changed

include/ClockModConfig.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DECLARE_CONFIG(ModConfig,
77
DECLARE_VALUE(TwelveToggle, bool, "24/12 Toggle", false);
88
DECLARE_VALUE(SecToggle, bool, "Show Seconds", false);
99
DECLARE_VALUE(BattToggle, bool, "Show Battery Percentage", false);
10+
DECLARE_VALUE(RainbowClock, bool, "Rainbowify it", false);
1011
DECLARE_VALUE(FontSize, double, "Font Size", 3.5);
1112

1213
DECLARE_VALUE(ClockXOffset, double, "Clock X Offset", 0);
@@ -23,6 +24,7 @@ DECLARE_CONFIG(ModConfig,
2324
INIT_VALUE(TwelveToggle);
2425
INIT_VALUE(SecToggle);
2526
INIT_VALUE(BattToggle);
27+
INIT_VALUE(RainbowClock);
2628
INIT_VALUE(FontSize);
2729
INIT_VALUE(ClockXOffset);
2830
INIT_VALUE(ClockYOffset);

include/RainbowClock.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Rainbow Clock thanks to Redbrumbler
2+
#pragma once
3+
#include <string>
4+
#include <vector>
5+
#include "UnityEngine/Color.hpp"
6+
7+
class RainbowClock
8+
{
9+
public:
10+
static bool shouldRainbow(std::string name);
11+
12+
static bool shouldRainbow(UnityEngine::Color color);
13+
14+
static std::string rainbowify(std::string);
15+
16+
static std::string toLower(std::string in);
17+
private:
18+
static inline int rainbowIndex = rand() % 12;
19+
static inline const std::vector<std::string> colors = {
20+
"#ff6060",
21+
"#ffa060",
22+
"#ffff60",
23+
"#a0ff60",
24+
"#60ff60",
25+
"#60ffa0",
26+
"#60ffff",
27+
"#60a0ff",
28+
"#6060ff",
29+
"#a060ff",
30+
"#ff60ff",
31+
"#ff60a0"
32+
};
33+
};

src/ClockUpdater.cpp

+88-59
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "TMPro/TextMeshProUGUI.hpp"
1010
#include <ctime>
1111
#include "GlobalNamespace/OVRPlugin_OVRP_1_1_0.hpp"
12+
#include "RainbowClock.hpp" // Needed to make the Clock Rainbowy (is that actually a word?)
1213
using namespace UnityEngine;
1314
using namespace TMPro;
1415

@@ -24,66 +25,94 @@ std::string getBatteryString(int level)
2425
else return string_format("<color=#ff8800>%s</color>", percent.c_str());
2526
}
2627

27-
// Updates the Clock.
28+
// RainbowClock, makes the Clock beautiful, yeah really it does.
29+
std::string RainbowClock::rainbowify(std::string input)
30+
{
31+
std::string result = "";
2832

29-
void ClockMod::ClockUpdater::Update() {
30-
time_t rawtime;
31-
char timestr[20];
32-
struct tm* timeinfo;
33-
time(&rawtime);
34-
timeinfo = localtime(&rawtime);
35-
36-
// TODO: Change the clock code to:
37-
// std::string getTimeString(timeInfo);
38-
// std::string result = getTimeString();
39-
//
40-
// if (batterytoggle)
41-
// {
42-
// result += " - ";
43-
// result += getBatteryString(batterylvl);
44-
// }
45-
//
46-
// text->set_text(il2cpp_utils::createcsstr(result));
47-
48-
// Checks config Settings for 12/24 Hour time and if Show Seconds is toggled on or off.
49-
50-
if (!getModConfig().TwelveToggle.GetValue()) {
51-
if (getModConfig().SecToggle.GetValue()) { //Check if seconds should be shown
52-
strftime(timestr, 20, "%H:%M:%S", timeinfo);
53-
}
54-
else {
55-
strftime(timestr, 20, "%H:%M", timeinfo);
56-
}
57-
}
58-
else { // If set to show 24 Hour Format
59-
if (getModConfig().SecToggle.GetValue()) { //Check if seconds should be shown
60-
strftime(timestr, 20, "%l:%M:%S %p", timeinfo);
61-
}
62-
else {
63-
strftime(timestr, 20, "%l:%M %p", timeinfo);
64-
};
33+
for (auto c : input)
34+
{
35+
result += string_format("<color=%s>%c</color>", colors[rainbowIndex].c_str(), c);
36+
rainbowIndex++;
37+
rainbowIndex %= colors.size();
6538
}
6639

67-
auto text = get_gameObject()->GetComponent<TextMeshProUGUI*>();
68-
69-
// Get current Battery Level
70-
if (getModConfig().BattToggle.GetValue()) {
71-
float batterylvl = GlobalNamespace::OVRPlugin::OVRP_1_1_0::ovrp_GetSystemBatteryLevel();
72-
batterylvl = batterylvl * 100;
73-
auto batterylevel = getBatteryString((int)batterylvl);
74-
std::string tandb = timestr;
75-
tandb += " - ";
76-
tandb += batterylevel;
77-
78-
text->set_text(il2cpp_utils::createcsstr(tandb));
79-
}
80-
else {
81-
text->set_text(il2cpp_utils::createcsstr(timestr));
82-
}
83-
84-
text->set_color(getModConfig().ClockColor.GetValue());
85-
text->set_fontSize(getModConfig().FontSize.GetValue());
86-
// text->get_transform()->set_position(UnityEngine::Vector3(0 + getModConfig().ClockXOffset.GetValue(), 0.5 + getModConfig().ClockYOffset.GetValue(), 3.85 + getModConfig().ClockZOffset.GetValue()));
87-
if (Config.InMPLobby == false) {
88-
get_transform()->GetParent()->set_position(UnityEngine::Vector3(getModConfig().ClockX.GetValue() + getModConfig().ClockXOffset.GetValue(), getModConfig().ClockY.GetValue() + getModConfig().ClockYOffset.GetValue(), getModConfig().ClockZ.GetValue() + getModConfig().ClockZOffset.GetValue())); }
40+
return result;
41+
}
42+
43+
// Updates the Clock.
44+
int wait = 0; // Sometimes you just need to take a deep breath and slow the fuck down, I'm looking at you ClockUpdater, also probably the dumbest way to slow it down.
45+
46+
void ClockMod::ClockUpdater::Update() {
47+
time_t rawtime;
48+
char timechar[20];
49+
struct tm* timeinfo;
50+
time(&rawtime);
51+
timeinfo = localtime(&rawtime);
52+
53+
if (wait == 10) {
54+
wait = 0;
55+
56+
// std::string timestr; // Added this because I have to declare it
57+
58+
// TODO: Change the clock code to:
59+
// std::string getTimeString(timeInfo);
60+
// std::string result = getTimeString();
61+
//
62+
// if (batterytoggle)
63+
// {
64+
// result += " - ";
65+
// result += getBatteryString(batterylvl);
66+
// }
67+
//
68+
// text->set_text(il2cpp_utils::createcsstr(result));
69+
70+
// Checks config Settings for 12/24 Hour time and if Show Seconds is toggled on or off.
71+
72+
if (!getModConfig().TwelveToggle.GetValue()) {
73+
if (getModConfig().SecToggle.GetValue()) { //Check if seconds should be shown
74+
strftime(timechar, 20, "%H:%M:%S", timeinfo);
75+
}
76+
else {
77+
strftime(timechar, 20, "%H:%M", timeinfo);
78+
}
79+
}
80+
else { // If set to show 24 Hour Format
81+
if (getModConfig().SecToggle.GetValue()) { //Check if seconds should be shown
82+
strftime(timechar, 20, "%l:%M:%S %p", timeinfo);
83+
}
84+
else {
85+
strftime(timechar, 20, "%l:%M %p", timeinfo);
86+
};
87+
}
88+
std::string timestr = timechar;
89+
if (getModConfig().RainbowClock.GetValue()) {
90+
timestr = RainbowClock::rainbowify((std::string)timestr);
91+
};
92+
auto text = get_gameObject()->GetComponent<TextMeshProUGUI*>();
93+
94+
// Get current Battery Level
95+
if (getModConfig().BattToggle.GetValue()) {
96+
float batterylvl = GlobalNamespace::OVRPlugin::OVRP_1_1_0::ovrp_GetSystemBatteryLevel();
97+
batterylvl = batterylvl * 100;
98+
auto batterylevel = getBatteryString((int)batterylvl);
99+
100+
std::string tandb = timestr;
101+
tandb += " - ";
102+
tandb += batterylevel;
103+
104+
text->set_text(il2cpp_utils::createcsstr(tandb));
105+
}
106+
else {
107+
text->set_text(il2cpp_utils::createcsstr(timestr));
108+
}
109+
if (getModConfig().RainbowClock.GetValue() == false) {
110+
text->set_color(getModConfig().ClockColor.GetValue());
111+
};
112+
text->set_fontSize(getModConfig().FontSize.GetValue());
113+
// text->get_transform()->set_position(UnityEngine::Vector3(0 + getModConfig().ClockXOffset.GetValue(), 0.5 + getModConfig().ClockYOffset.GetValue(), 3.85 + getModConfig().ClockZOffset.GetValue()));
114+
if (Config.InMPLobby == false) {
115+
get_transform()->GetParent()->set_position(UnityEngine::Vector3(getModConfig().ClockX.GetValue() + getModConfig().ClockXOffset.GetValue(), getModConfig().ClockY.GetValue() + getModConfig().ClockYOffset.GetValue(), getModConfig().ClockZ.GetValue() + getModConfig().ClockZOffset.GetValue()));
116+
}
117+
} else { wait = wait + 1; }
89118
}

src/ClockViewContoller.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void ClockMod::ClockViewController::DidActivate(bool firstActivation, bool added
3737

3838
BeatSaberUI::AddHoverHint(AddConfigValueToggle(parent, getModConfig().BattToggle)->get_gameObject(), "Displays Battery percentage next to the clock.");
3939

40+
BeatSaberUI::AddHoverHint(AddConfigValueToggle(parent, getModConfig().RainbowClock)->get_gameObject(), "Makes the Clock beautiful.");
41+
4042
BeatSaberUI::AddHoverHint(AddConfigValueIncrementFloat(parent, getModConfig().FontSize, 1, 0.1f, 1.0f, 5.0f)->get_gameObject(), "Changes the Font Size of the Clock (Default: 3.5)");
4143

4244
BeatSaberUI::AddHoverHint(AddConfigValueIncrementFloat(parent, getModConfig().ClockXOffset, 1, 0.1f, -10.0f, 10.0f)->get_gameObject(), "Offsets the X (Left/Right) Position of the Clock");

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ float ClockZ = getModConfig().ClockZ.GetValue();
6767
UnityEngine::Canvas* canvas;
6868
UnityEngine::UI::VerticalLayoutGroup* layout;
6969

70-
// Clock Offset
70+
// Clock Offset (moved to ClockUpdater)
7171
//void Update() {
7272
// layout->get_transform()->set_position(UnityEngine::Vector3(ClockX + getModConfig().ClockXOffset.GetValue(), ClockY + getModConfig().ClockYOffset.GetValue(), ClockZ + getModConfig().ClockZOffset.GetValue()));
7373
//}

0 commit comments

Comments
 (0)