1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#include "DisplayOverlay.h"
#include <spdlog/fmt/fmt.h>
#include <libultraship/bridge/consolevariablebridge.h>
#include <ship/Context.h>
#include <ship/window/Window.h>
extern "C" {
#include "variables.h"
uint64_t GetUnixTimestamp();
}
#include "ShipUtils.h"
#include "interface/parameter_static/parameter_static.h"
#include "2s2h/Enhancements/Enhancements.h"
float windowScale = 1.0f;
ImVec4 windowBG = ImVec4(0, 0, 0, 0.5f);
static constexpr ImVec4 tintColor = {};
void DrawInGameTimer(uint32_t timer, ImVec4 color = ImVec4(1, 1, 1, 1)) {
float windowScale = MAX(CVarGetFloat("gDisplayOverlay.Scale", 1.0f), 1.0f);
std::string timerStr = Ship_FormatTimeDisplay(timer);
uint16_t textureIndex = 0;
for (const auto c : timerStr) {
if (c == ':' || c == '.') {
textureIndex = 10;
} else {
textureIndex = c - '0';
}
if (c == '.') {
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (8.0f * windowScale));
ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(digitList[textureIndex]),
ImVec2(8.0f * windowScale, 8.0f * windowScale), ImVec2(0, 0.5f), ImVec2(1, 1), color,
tintColor);
} else {
ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(digitList[textureIndex]),
ImVec2(8.0f * windowScale, 16.0f * windowScale), ImVec2(0, 0), ImVec2(1, 1), color, tintColor);
}
ImGui::SameLine(0, 0);
}
}
void DisplayOverlayWindow::Draw() {
if (!IsVisible() || !gPlayState) {
return;
}
int displayOverlay = CVarGetInteger(CVAR_DISPLAY_OVERLAY_MODE, 0);
if (displayOverlay == TIMER_DISPLAY_NONE) {
return;
}
float windowScale = MAX(CVarGetFloat("gDisplayOverlay.Scale", 1.0f), 1.0f);
ImVec4 windowBG = !CVarGetInteger("gDisplayOverlay.Background", 0) ? ImVec4(0, 0, 0, 0.5f) : ImVec4(0, 0, 0, 0);
ImGui::PushStyleColor(ImGuiCol_WindowBg, windowBG);
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
ImGui::Begin("Overlay", nullptr,
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollbar);
ImGui::SetWindowFontScale(windowScale);
ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(gTimerClockIconTex),
ImVec2(16.0f * windowScale, 16.0f * windowScale));
ImGui::SameLine(0, 10.0f);
uint64_t timeToDisplay = 0;
if (gSaveContext.save.shipSaveInfo.fileCompletedAt == 0) { // Player has not beaten the game
switch (displayOverlay) {
case TIMER_DISPLAY_RTA:
timeToDisplay = (GetUnixTimestamp() - gSaveContext.save.shipSaveInfo.fileCreatedAt);
break;
case TIMER_DISPLAY_IGT:
timeToDisplay = ((GetUnixTimestamp() - gSaveContext.shipSaveContext.lastTimeLog) +
gSaveContext.save.shipSaveInfo.filePlaytime);
break;
default:
break;
}
DrawInGameTimer(timeToDisplay / 100);
} else { // Player has beaten the game
switch (displayOverlay) {
case TIMER_DISPLAY_RTA:
timeToDisplay =
(gSaveContext.save.shipSaveInfo.fileCompletedAt - gSaveContext.save.shipSaveInfo.fileCreatedAt);
break;
case TIMER_DISPLAY_IGT:
timeToDisplay = gSaveContext.save.shipSaveInfo.filePlaytime;
break;
default:
break;
}
DrawInGameTimer(timeToDisplay / 100, ImVec4(0, 1, 0, 1));
}
ImGui::End();
ImGui::PopStyleVar(1);
ImGui::PopStyleColor(2);
}
void DisplayOverlayWindow::InitElement() {
}
|