Skip to content

Commit ed8da2d

Browse files
committed
Add option to split Gameplay Timer and fix color when game complete is true.
1 parent 6caaed7 commit ed8da2d

2 files changed

Lines changed: 73 additions & 13 deletions

File tree

soh/soh/Enhancements/TimeDisplay/TimeDisplay.cpp

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ extern PlayState* gPlayState;
1515
uint64_t GetUnixTimestamp();
1616
}
1717

18+
static bool separateGameplay = false;
19+
static float gameplayFontScale = 1.0f;
1820
static float fontScale = 1.0f;
1921
std::string timeDisplayTime = "";
2022
ImTextureID textureDisplay = 0;
@@ -46,6 +48,7 @@ const std::vector<TimeObject> timeDisplayList = {
4648
};
4749

4850
static std::vector<TimeObject> activeTimers;
51+
static TimeObject gameplayTimer = timeDisplayList[DISPLAY_IN_GAME_TIMER];
4952

5053
std::string convertDayTime(uint32_t dayTime) {
5154
uint32_t totalSeconds = 24 * 60 * 60;
@@ -89,6 +92,7 @@ static void TimeDisplayGetTimer(uint32_t timeID) {
8992
case DISPLAY_IN_GAME_TIMER:
9093
textureDisplay = Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName("GAMEPLAY_TIMER");
9194
timeDisplayTime = formatTimeDisplay(GAMEPLAYSTAT_TOTAL_TIME).c_str();
95+
textColor = gSaveContext.ship.stats.gameComplete ? COLOR_LIGHT_GREEN : COLOR_WHITE;
9296
break;
9397
case DISPLAY_TIME_OF_DAY:
9498
if (gSaveContext.dayTime >= DAY_BEGINS && gSaveContext.dayTime < NIGHT_BEGINS) {
@@ -140,6 +144,7 @@ static void TimeDisplayGetTimer(uint32_t timeID) {
140144
timeDisplayTime = std::to_string(FredsQuestWoodOnHand) + "/" + std::to_string(FredsQuestWoodCollected) +
141145
"/" + std::to_string(CVarGetInteger("gHoliday.Fredomato.FredsQuest.WoodNeeded", 300));
142146
textureDisplay = Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName("ITEM_STICK");
147+
break;
143148
default:
144149
break;
145150
}
@@ -152,19 +157,52 @@ void TimeDisplayUpdateDisplayOptions() {
152157
activeTimers.push_back(timer);
153158
}
154159
}
160+
}
155161

156-
// if (pushBack) {
157-
// activeTimers.push_back(timeDisplayList[timeID]);
158-
// } else {
159-
// uint32_t index = 0;
160-
// for (auto& check : activeTimers) {
161-
// if (check.timeID == timeID) {
162-
// activeTimers.erase(activeTimers.begin() + index);
163-
// return;
164-
// }
165-
// index++;
166-
// }
167-
// }
162+
void DrawStandaloneGameplayTimer() {
163+
ImGui::Begin("GameplayTimer", nullptr,
164+
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoFocusOnAppearing |
165+
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
166+
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollbar);
167+
ImGui::SetWindowFontScale(gameplayFontScale);
168+
ImGui::BeginTable("Gameplay Timer", 2, ImGuiTableFlags_NoClip);
169+
ImGui::PushID(DISPLAY_IN_GAME_TIMER);
170+
TimeDisplayGetTimer(DISPLAY_IN_GAME_TIMER);
171+
ImGui::TableNextColumn();
172+
ImGui::Image(textureDisplay, ImVec2(16.0f * gameplayFontScale, 16.0f * gameplayFontScale));
173+
ImGui::TableNextColumn();
174+
if (timeDisplayTime != "-:--") {
175+
char* textToDecode = new char[timeDisplayTime.size() + 1];
176+
textToDecode = std::strcpy(textToDecode, timeDisplayTime.c_str());
177+
size_t textLength = timeDisplayTime.length();
178+
uint16_t textureIndex = 0;
179+
180+
for (size_t i = 0; i < textLength; i++) {
181+
if (textToDecode[i] == ':' || textToDecode[i] == '.') {
182+
textureIndex = 10;
183+
} else {
184+
textureIndex = textToDecode[i] - '0';
185+
}
186+
if (textToDecode[i] == '.') {
187+
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (8.0f * gameplayFontScale));
188+
ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(
189+
digitList[textureIndex].first),
190+
ImVec2(8.0f * gameplayFontScale, 8.0f * gameplayFontScale), ImVec2(0, 0.5f), ImVec2(1, 1),
191+
textColor,
192+
ImVec4(0, 0, 0, 0));
193+
} else {
194+
ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(
195+
digitList[textureIndex].first),
196+
ImVec2(8.0f * gameplayFontScale, 16.0f * gameplayFontScale), ImVec2(0, 0), ImVec2(1, 1),
197+
textColor,
198+
ImVec4(0, 0, 0, 0));
199+
}
200+
ImGui::SameLine(0, 0);
201+
}
202+
}
203+
ImGui::PopID();
204+
ImGui::EndTable();
205+
ImGui::End();
168206
}
169207

170208
void TimeDisplayWindow::Draw() {
@@ -179,6 +217,10 @@ void TimeDisplayWindow::Draw() {
179217
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
180218
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
181219

220+
if (separateGameplay) {
221+
DrawStandaloneGameplayTimer();
222+
}
223+
182224
ImGui::Begin("TimerDisplay", nullptr,
183225
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoFocusOnAppearing |
184226
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
@@ -189,6 +231,10 @@ void TimeDisplayWindow::Draw() {
189231
} else {
190232
ImGui::BeginTable("Timer List", 2, ImGuiTableFlags_NoClip);
191233
for (auto& timers : activeTimers) {
234+
if (separateGameplay && timers.timeID == DISPLAY_IN_GAME_TIMER) {
235+
continue;
236+
}
237+
192238
ImGui::PushID(timers.timeID);
193239
TimeDisplayGetTimer(timers.timeID);
194240
ImGui::TableNextColumn();
@@ -239,6 +285,8 @@ void TimeDisplayWindow::Draw() {
239285
}
240286

241287
void TimeDisplayInitSettings() {
288+
separateGameplay = CVarGetInteger(CVAR_TIME_DISPLAY("SeparateGameplay"), 0);
289+
gameplayFontScale = CVarGetFloat(CVAR_TIME_DISPLAY("GameplayFontScale"), 1.0f);
242290
fontScale = CVarGetFloat(CVAR_TIME_DISPLAY("FontScale"), 1.0f);
243291
if (fontScale < 1.0f) {
244292
fontScale = 1.0f;

soh/soh/SohGui/SohMenuEnhancements.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ void SohMenu::AddMenuEnhancements() {
19081908
.RaceDisable(false)
19091909
.WindowName("Additional Timers")
19101910
.Options(WindowButtonOptions().Tooltip("Enables the separate Additional Timers Window."));
1911-
AddWidget(path, "Font Scale: %.2fx", WIDGET_CVAR_SLIDER_FLOAT)
1911+
AddWidget(path, "Global Scale: %.2fx", WIDGET_CVAR_SLIDER_FLOAT)
19121912
.CVar(CVAR_TIME_DISPLAY("FontScale"))
19131913
.RaceDisable(false)
19141914
.Callback([](WidgetInfo& info) { TimeDisplayInitSettings(); })
@@ -1917,6 +1917,18 @@ void SohMenu::AddMenuEnhancements() {
19171917
.CVar(CVAR_TIME_DISPLAY("ShowWindowBG"))
19181918
.RaceDisable(false)
19191919
.Callback([](WidgetInfo& info) { TimeDisplayInitSettings(); });
1920+
1921+
AddWidget(path, "Gameplay Timer Options", WIDGET_SEPARATOR_TEXT);
1922+
AddWidget(path, "Separate Gameplay Timer", WIDGET_CVAR_CHECKBOX)
1923+
.CVar(CVAR_TIME_DISPLAY("SeparateGameplay"))
1924+
.RaceDisable(false)
1925+
.Callback([](WidgetInfo& info) { TimeDisplayInitSettings(); });
1926+
AddWidget(path, "Scale: %.2fx", WIDGET_CVAR_SLIDER_FLOAT)
1927+
.CVar(CVAR_TIME_DISPLAY("GameplayFontScale"))
1928+
.RaceDisable(false)
1929+
.Callback([](WidgetInfo& info) { TimeDisplayInitSettings(); })
1930+
.Options(FloatSliderOptions().Min(1.0f).Max(5.0f).DefaultValue(1.0f).Format("%.2fx"));
1931+
AddWidget(path, "Display Options", WIDGET_SEPARATOR_TEXT);
19201932
for (auto& timer : timeDisplayList) {
19211933
AddWidget(path, timer.timeLabel, WIDGET_CVAR_CHECKBOX)
19221934
.RaceDisable(false)

0 commit comments

Comments
 (0)