forked from HarbourMasters/Ghostship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckTracker.cpp
More file actions
259 lines (228 loc) · 11.7 KB
/
Copy pathCheckTracker.cpp
File metadata and controls
259 lines (228 loc) · 11.7 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include "CheckTracker.h"
#include "port/Rando/Logic/Logic.h"
#include "port/ShipUtils.h"
#include "port/ui/UIWidgets.hpp"
#include <cstring>
extern "C" {
#include "include/assets/textures/segment2.h"
}
namespace GhostshipGui {
extern std::shared_ptr<Rando::CheckTracker::CheckTrackerWindow> mRandoCheckTrackerWindow;
}
#define DEFAULT_COLLECTED_COLOR Color_RGBA8(100, 255, 100, 255)
#define DEFAULT_SKIPPED_COLOR Color_RGBA8(255, 100, 255, 255)
#define DEFAULT_ITEM_COLOR Color_RGBA8(79, 0, 221, 255)
#define CVAR_NAME_SHOW_CHECK_TRACKER "gWindows.CheckTracker"
#define CVAR_NAME_CHECK_TRACKER_OPACITY "gRando.CheckTracker.Opacity"
#define CVAR_NAME_CHECK_TRACKER_SCALE "gRando.CheckTracker.Scale"
#define CVAR_NAME_SHOW_CURRENT_LEVEL "gRando.CheckTracker.ShowCurrentLevel"
#define CVAR_NAME_COLLECTED_COLOR "gRando.CheckTracker.CollectedColor"
#define CVAR_NAME_SKIPPED_COLOR "gRando.CheckTracker.SkippedColor"
#define CVAR_NAME_ITEM_COLOR "gRando.CheckTracker.ItemColor"
#define CVAR_SHOW_CHECK_TRACKER CVarGetInteger(CVAR_NAME_SHOW_CHECK_TRACKER, 0)
#define CVAR_CHECK_TRACKER_OPACITY CVarGetFloat(CVAR_NAME_CHECK_TRACKER_OPACITY, 0.5f)
#define CVAR_CHECK_TRACKER_SCALE CVarGetFloat(CVAR_NAME_CHECK_TRACKER_SCALE, 1.0f)
#define CVAR_SHOW_CURRENT_LEVEL CVarGetInteger(CVAR_NAME_SHOW_CURRENT_LEVEL, 0)
#define CVAR_COLLECTED_COLOR CVarGetColor(CVAR_NAME_COLLECTED_COLOR ".Value", DEFAULT_COLLECTED_COLOR)
#define CVAR_SKIPPED_COLOR CVarGetColor(CVAR_NAME_SKIPPED_COLOR ".Value", DEFAULT_SKIPPED_COLOR)
#define CVAR_ITEM_COLOR CVarGetColor(CVAR_NAME_ITEM_COLOR ".Value", DEFAULT_ITEM_COLOR)
std::vector<std::tuple<const char*, Color_RGBA8, const char*>> defaultCheckColorList = {
{ CVAR_NAME_COLLECTED_COLOR, DEFAULT_COLLECTED_COLOR, "Check Obtained" },
{ CVAR_NAME_SKIPPED_COLOR, DEFAULT_SKIPPED_COLOR, "Check Skipped" },
{ CVAR_NAME_ITEM_COLOR, DEFAULT_ITEM_COLOR, "Obtained Item" },
};
bool checkTrackerPopoutState = false;
ImVec4 checkTrackerBG = ImVec4{ 0, 0, 0, 0.5f };
float checkTrackerScale = 1.0f;
bool expandState = true;
void DrawCheckTrackerList() {
if (Rando::Logic::shuffledPool.empty()) {
return;
}
for (auto& [id, name] : levelIdList) {
if (CVAR_SHOW_CURRENT_LEVEL && id != gCurrLevelNum) {
continue;
}
ImGui::PushID(id);
ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0, 0, 0, 0.5f));
ImGui::SetNextItemOpen(expandState, ImGuiCond_Always);
if (ImGui::CollapsingHeader(name.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Indent(20.0f);
if (ImGui::BeginTable("CheckList", 2)) {
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed, (16.0f * checkTrackerScale));
ImGui::TableSetupColumn("Check");
ImGui::TableNextColumn();
for (auto& entry : Rando::Logic::shuffledPool) {
RandoSaveCheck& randoSaveCheck = RANDO_SAVE_CHECKS(selectedFileNum)[entry.randoCheckId];
if (Rando::StaticData::Checks[entry.randoCheckId].levelId != id) {
continue;
}
ImVec4 checkTextColor = randoSaveCheck.obtained
? VecFromRGBA8(CVAR_COLLECTED_COLOR)
: UIWidgets::ColorValues.at(UIWidgets::Colors::White);
ImVec4 itemTextColor = randoSaveCheck.obtained
? VecFromRGBA8(CVAR_ITEM_COLOR)
: UIWidgets::ColorValues.at(UIWidgets::Colors::Indigo);
if (randoSaveCheck.skipped) {
checkTextColor = itemTextColor = VecFromRGBA8(CVAR_SKIPPED_COLOR);
}
const char* texture = randoSaveCheck.randoItemId == RI_STAR ? texture_hud_char_star
: randoSaveCheck.randoItemId == RI_COIN_RED ? "Red Coin Icon"
: "Blue Coin Icon";
ImTextureID textureId =
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(texture);
ImGui::BeginGroup();
ImGui::Image(textureId, ImVec2(16.0f * checkTrackerScale, 16.0f * checkTrackerScale));
ImGui::TableNextColumn();
ImGui::TextColored(checkTextColor, Rando::StaticData::Checks[entry.randoCheckId].name);
if (randoSaveCheck.obtained) {
ImGui::SameLine();
RandoItemId randoItemId = Rando::StaticData::GetShuffledRandoItem(entry.randoCheckId);
ImGui::TextColored(itemTextColor, "(%s)", Rando::StaticData::Items[randoItemId].name);
} else if (randoSaveCheck.skipped) {
ImGui::SameLine();
ImGui::TextColored(itemTextColor, "(%s)", "Skipped");
}
ImGui::Dummy(ImVec2(ImGui::GetContentRegionAvail().x, 0));
ImGui::EndGroup();
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, ImGui::IsItemHovered()
? IM_COL32(255, 255, 0, 128)
: IM_COL32(255, 255, 255, 0));
if (ImGui::IsItemClicked()) {
randoSaveCheck.skipped = !randoSaveCheck.skipped;
}
ImGui::TableNextColumn();
}
ImGui::EndTable();
}
ImGui::Unindent(20.0f);
}
ImGui::PopStyleColor(2);
ImGui::PopID();
}
}
namespace Rando {
namespace CheckTracker {
void CheckTrackerWindow::Draw() {
if (!CVAR_SHOW_CHECK_TRACKER) {
return;
}
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, checkTrackerBG);
ImGui::PushStyleColor(ImGuiCol_TitleBg, checkTrackerBG);
ImGui::PushStyleColor(ImGuiCol_WindowBg, checkTrackerBG);
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
ImGui::SetNextWindowSize(ImVec2(485.0f, 500.0f), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Check Tracker", nullptr, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoFocusOnAppearing)) {
checkTrackerBG.w = ImGui::IsWindowDocked() ? 1.0f : CVAR_CHECK_TRACKER_OPACITY;
ImGui::SetWindowFontScale(checkTrackerScale);
if (Rando::Logic::shuffledPool.empty()) {
ImGui::TextColored(UIWidgets::ColorValues.at(UIWidgets::Colors::Orange), "No Rando Save Loaded");
ImGui::End();
ImGui::PopStyleColor(4);
ImGui::PopStyleVar(1);
return;
}
if (ImGui::BeginChild("Checks")) {
DrawCheckTrackerList();
ImGui::EndChild();
}
ImGui::End();
}
ImGui::PopStyleColor(4);
ImGui::PopStyleVar(1);
}
void SettingsWindow::DrawElement() {
if (CVarGetInteger("gWindows.CheckTracker", 0)) {
checkTrackerPopoutState = true;
UIWidgets::WindowButton("Return Check Tracker", "gWindows.CheckTracker", GhostshipGui::mRandoCheckTrackerWindow,
{ .size = UIWidgets::Sizes::Inline, .color = UIWidgets::Colors::Red });
} else {
checkTrackerPopoutState = false;
UIWidgets::WindowButton("Popout Check Tracker", "gWindows.CheckTracker", GhostshipGui::mRandoCheckTrackerWindow,
{ .size = UIWidgets::Sizes::Inline, .color = UIWidgets::Colors::Green });
}
if (ImGui::BeginTable("Settings Table", 2)) {
ImGui::TableSetupColumn("col1", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("col2", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextColumn();
ImGui::SeparatorText("Check Tracker");
if (!checkTrackerPopoutState) {
if (ImGui::BeginChild("Checks", ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
DrawCheckTrackerList();
ImGui::EndChild();
}
} else {
ImGui::TextColored(UIWidgets::ColorValues.at(WIDGET_COLOR), "Tracker popped out");
}
ImGui::TableNextColumn();
ImGui::SeparatorText("Check Settings");
UIWidgets::CVarCheckbox("Only Show Current Level", CVAR_NAME_SHOW_CURRENT_LEVEL);
if (UIWidgets::Button(
"Expand All",
UIWidgets::ButtonOptions{}.Color(WIDGET_COLOR).Size(ImVec2(ImGui::GetContentRegionAvail().x / 2, 0)))) {
expandState = true;
}
ImGui::SameLine();
if (UIWidgets::Button("Collapse All", UIWidgets::ButtonOptions{}.Color(WIDGET_COLOR))) {
expandState = false;
}
ImGui::SeparatorText("Window Settings");
// UIWidgets::CVarCheckbox("Show Search", CVAR_NAME_SHOW_SEARCH,
// UIWidgets::CheckboxOptions().DefaultValue(true)); UIWidgets::CVarCheckbox("Show Check Type Filters",
// CVAR_NAME_SHOW_CHECK_TYPE_FILTER);
if (UIWidgets::CVarSliderFloat("", CVAR_NAME_CHECK_TRACKER_OPACITY,
{
.format = "Opacity: %.1f",
.step = 0.10f,
.min = 0.0f,
.max = 1.0f,
.defaultValue = 0.5f,
.labelPosition = UIWidgets::LabelPositions::None,
.color = WIDGET_COLOR,
})) {
checkTrackerBG.w = CVAR_CHECK_TRACKER_OPACITY;
}
if (UIWidgets::CVarSliderFloat(" ", CVAR_NAME_CHECK_TRACKER_SCALE,
{
.format = "Scale: %.1f",
.step = 0.10f,
.min = 0.7f,
.max = 2.5f,
.defaultValue = 1.0f,
.labelPosition = UIWidgets::LabelPositions::None,
.color = WIDGET_COLOR,
})) {
checkTrackerScale = CVAR_CHECK_TRACKER_SCALE;
}
int16_t checkColorIndex = 0;
for (auto& [cvar, color, label] : defaultCheckColorList) {
std::string cvarText = cvar;
cvarText += ".Value";
std::string colorText = label;
colorText += " Color";
std::string widgetLabel = "##";
widgetLabel += std::to_string(checkColorIndex);
ImGui::PushID(checkColorIndex);
UIWidgets::CVarColorPicker(widgetLabel.c_str(), cvar, color, true);
ImGui::SameLine();
if (UIWidgets::Button(ICON_FA_REFRESH, { .size = ImVec2(32.0f, 32.0f), .color = WIDGET_COLOR })) {
CVarSetColor(cvarText.c_str(), color);
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
}
ImGui::SameLine();
ImGui::Text(colorText.c_str());
ImGui::PopID();
checkColorIndex++;
}
ImGui::EndTable();
}
}
void Init() {
checkTrackerPopoutState = CVarGetInteger("gWindows.CheckTracker", 0);
checkTrackerBG = { 0, 0, 0, CVAR_CHECK_TRACKER_OPACITY };
checkTrackerScale = CVAR_CHECK_TRACKER_SCALE;
}
} // namespace CheckTracker
} // namespace Rando