-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorBlindColorChanger.cc
More file actions
695 lines (606 loc) · 28 KB
/
Copy pathColorBlindColorChanger.cc
File metadata and controls
695 lines (606 loc) · 28 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
#include "ColorBlindColorChanger.h"
#include "Windows.h" // IWYU pragma: keep
#include "shellapi.h"
#include "imgui.h"
#include "imgui_helper.h"
#include "imgui_internal.h"
#include "bakkesmod/../utils/parser.h"
#include "bakkesmod/wrappers/gameobject/MapListWrapper.h"
#include "bm_helper.h"
#include "CVarManager.h"
#include "HookedEvents.h"
#include "Logger.h"
#include "PersistentManagedCVarStorage.h"
namespace {
namespace log = LOGGER;
}; // namespace
BAKKESMOD_PLUGIN(ColorBlindColorChanger, "ColorBlindColorChanger", "1.0.1", /*UNUSED*/ NULL);
/**
* \brief do the following when your plugin is loaded
*/
void ColorBlindColorChanger::onLoad() {
// initialize things
HookedEvents::gameWrapper = gameWrapper;
// set up logging necessities
log::set_cvarmanager(cvarManager);
log::set_loglevel(log::LOGLEVEL::OFF);
// set a prefix to attach in front of all cvars to avoid name clashes
CVarManager::instance().set_cvar_prefix("cbcc_"); // INCLUDE PLUGIN CVAR PREFIX HERE!!!
CVarManager::instance().set_cvarmanager(cvarManager);
// MAKE SECOND PARAMETER A SHORT FORM NAME OF THE PLUGIN + "_cvars"
cvar_storage = std::make_unique<PersistentManagedCVarStorage>(this, "colorblindcolorchanger_cvars", true, true);
MapListWrapper mlw = gameWrapper->GetMapListWrapper();
if (mlw) {
ArrayWrapper<MapDataWrapper> awmdw = mlw.GetSortedMaps();
for (const auto & map : awmdw) {
if (!map) { continue; }
game_maps_name_filename.emplace_back(std::make_pair(map.GetLocalizedName(), map.GetName()));
}
}
init_cvars();
init_hooked_events();
cb_enabled = gameWrapper->GetbColorBlind();
log::log_debug("GETBCOLORBLIND/cb_enabled: {}", cb_enabled);
}
/**
* \brief group together the initialization of cvars
*/
void ColorBlindColorChanger::init_cvars() {
// REGISTER THE CVARS DECLARED IN THE HEADER
CVarManager::instance().register_cvars();
#define X(name, ...) cvar_storage->AddCVar(CVarManager::instance().get_cvar_prefix() + #name);
LIST_OF_PLUGIN_CVARS
#undef X
CVarWrapper bcvar = CVarManager::instance().getCVM()->registerCvar(
CVarManager::instance().get_cvar_prefix() + "global" + "_blue",
to_string_color(default_blue_rgba),
"Blue/Your RGBA value for global",
false);
CVarWrapper ocvar = CVarManager::instance().getCVM()->registerCvar(
CVarManager::instance().get_cvar_prefix() + "global" + "_orange",
to_string_color(default_orange_rgba),
"Orange/Opponent RGBA value for global",
false);
cvar_storage->AddCVar(CVarManager::instance().get_cvar_prefix() + "global" + "_blue");
cvar_storage->AddCVar(CVarManager::instance().get_cvar_prefix() + "global" + "_orange");
// add a cvar for every map
for (const auto & map_name : game_maps_name_filename) {
CVarWrapper bcvar = CVarManager::instance().getCVM()->registerCvar(
CVarManager::instance().get_cvar_prefix() + map_name.second + "_blue",
to_string_color(default_blue_rgba),
"Blue/Your RGBA value for " + map_name.first,
false);
CVarWrapper ocvar = CVarManager::instance().getCVM()->registerCvar(
CVarManager::instance().get_cvar_prefix() + map_name.second + "_orange",
to_string_color(default_orange_rgba),
"Orange/Opponent RGBA value for " + map_name.first,
false);
cvar_storage->AddCVar(CVarManager::instance().get_cvar_prefix() + map_name.second + "_blue");
cvar_storage->AddCVar(CVarManager::instance().get_cvar_prefix() + map_name.second + "_orange");
}
CVarManager::instance().get_cvar_enabled().addOnValueChanged([this](std::string oldValue, CVarWrapper newValue) {
if (plugin_enabled == newValue.getBoolValue() == true) { return; }
plugin_enabled = newValue.getBoolValue();
plugin_enabled ? enable_plugin() : disable_plugin();
});
CVarManager::instance().get_cvar_global().addOnValueChanged(
[this](std::string oldValue, CVarWrapper newValue) { globally_set = newValue.getBoolValue(); });
CVarManager::instance().get_cvar_colorize_option().addOnValueChanged(
[this](std::string oldValue, CVarWrapper newValue) { colorize_option = newValue.getBoolValue(); });
}
/**
* \brief group together the initialization of hooked events
*/
void ColorBlindColorChanger::init_hooked_events() {
HookedEvents::AddHookedEventWithCaller<ActorWrapper>(
"Function TAGame.GFxData_Settings_TA.SetColorBlind",
[this](ActorWrapper unused, void * params, std::string event_name) {
log::log_info("CALLING {}...", event_name);
struct parms {
unsigned char unused[0x8]; // HAS THINGS BUT I DONT WANT THEM
bool b;
} * b = reinterpret_cast<parms *>(params);
cb_enabled = b->b;
});
HookedEvents::AddHookedEvent("Function Engine.GameInfo.PreExit", [this](std::string event_name) {
log::log_info("CALLING {}...", event_name);
// ASSURED CLEANUP
onUnload();
});
}
void ColorBlindColorChanger::hook_colorblind_color_change_events() {
HookedEvents::AddHookedEvent(
// this one is called when teams are created, so you can use it in spectator mode
"Function TAGame.GFxHUD_TA.OnAllTeamsCreated",
[this](auto... fargs) {
if (colorize_option == 1) {
// this is because it seems only valid if blue/orange is set
return;
}
log::log_info("CALLING {} ...", fargs...);
set_colorblind_colors();
},
true);
HookedEvents::AddHookedEvent(
// this function called when you join a team
"Function Engine.Player.HandleTeamChanged",
[this](auto... fargs) {
if (colorize_option == 0) {
// this is because it seems only valid if your/oppo is set
return;
}
log::log_info("CALLING {} ...", fargs...);
set_colorblind_colors();
},
true);
}
void ColorBlindColorChanger::unhook_colorblind_color_change_events() {
HookedEvents::RemoveHook("Function TAGame.GFxHUD_TA.OnAllTeamsCreated");
HookedEvents::RemoveHook("Function Engine.Player.HandleTeamChanged");
}
void ColorBlindColorChanger::set_colorblind_colors() {
gameWrapper->SetTimeout(
[this](GameWrapper * gw) {
ServerWrapper sw = gameWrapper->GetCurrentGameState();
if (!sw) {
log::log_error("NO SERVER");
return;
}
std::string map_name_or_global = globally_set ? "global" : gameWrapper->GetCurrentMap();
log::log_debug("map_name_or_global_string = {}", map_name_or_global);
CVarWrapper bcvar = CVarManager::instance().getCVM()->getCvar(
CVarManager::instance().get_cvar_prefix() + map_name_or_global + "_blue");
CVarWrapper ocvar = CVarManager::instance().getCVM()->getCvar(
CVarManager::instance().get_cvar_prefix() + map_name_or_global + "_orange");
ArrayWrapper<TeamWrapper> awtw = sw.GetTeams();
if (awtw.IsNull()) {
log::log_error("NO ARRAYWRAPPER<TEAMWRAPPER>");
return;
}
int blue_team_idx = BLUE_TEAM_IDX;
int orange_team_idx = ORANGE_TEAM_IDX;
if (colorize_option == 0) { // blue x orange
} else { // your team x oppo
// getting your team number
PlayerControllerWrapper pcw = gameWrapper->GetPlayerController();
if (!pcw) {
log::log_error("NO PCW");
return;
}
log::log_debug("PlayerController's TEAM NUMBER: {}", pcw.GetTeamNum2());
blue_team_idx = pcw.GetTeamNum2(); // MIGHT BE UCHAR_MAX IF YOU'RE NOT ON A TEAM!
if (blue_team_idx == UCHAR_MAX) {
log::log_error("NOT ON A TEAM! (NO YOU/OPPONENT DISTINCTION APPLICABLE)");
return;
}
orange_team_idx = 1 - blue_team_idx; // there are assumedly only 2 teams.
}
TeamWrapper bteam = awtw.Count() > abs(blue_team_idx) ? awtw.Get(blue_team_idx) : NULL;
if (bteam) {
bteam.SetColorBlindFontColor(bcvar.getColorValue());
bteam.UpdateColors();
} else {
log::log_error("NO BLUE TEAM");
}
// Modes like Knockout don't have an "orange team", so this is for protection against that.
TeamWrapper oteam = awtw.Count() > abs(orange_team_idx) ? awtw.Get(orange_team_idx) : NULL;
if (oteam) {
oteam.SetColorBlindFontColor(ocvar.getColorValue());
oteam.UpdateColors();
} else {
log::log_error("NO ORANGE TEAM");
}
},
0.25f);
}
void ColorBlindColorChanger::unset_colorblind_colors() {
gameWrapper->SetTimeout(
[this](GameWrapper * gw) {
ServerWrapper sw = gameWrapper->GetCurrentGameState();
if (!sw) {
log::log_error("NO SERVER");
return;
}
ArrayWrapper<TeamWrapper> awtw = sw.GetTeams();
if (awtw.IsNull()) {
log::log_error("NO ARRAYWRAPPER<TEAMWRAPPER>");
return;
}
TeamWrapper bteam = awtw.Count() > 0 ? awtw.Get(BLUE_TEAM_IDX) : NULL;
if (bteam) {
bteam.SetColorBlindFontColor(default_blue_rgba);
bteam.UpdateColors();
} else {
log::log_error("NO BLUE TEAM");
}
// Modes like Knockout don't have an "orange team", so this is for protection against that.
TeamWrapper oteam = awtw.Count() > 1 ? awtw.Get(ORANGE_TEAM_IDX) : NULL;
if (oteam) {
oteam.SetColorBlindFontColor(default_orange_rgba);
oteam.UpdateColors();
} else {
log::log_error("NO ORANGE TEAM");
}
},
0.25f);
}
void ColorBlindColorChanger::enable_plugin() {
plugin_enabled = true;
hook_colorblind_color_change_events();
set_colorblind_colors();
}
void ColorBlindColorChanger::disable_plugin() {
plugin_enabled = false;
unhook_colorblind_color_change_events();
unset_colorblind_colors();
}
/**
* \brief This is for helping with IMGUI stuff
*
* copied from: https://github.com/ocornut/imgui/discussions/3862
*
* \param width total width of items
* \param alignment where on the line to align
*/
static inline void AlignForWidth(float width, float alignment = 0.5f) {
float avail = ImGui::GetContentRegionAvail().x;
float off = (avail - width) * alignment;
if (off > 0.0f) { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + off); }
}
/**
* \brief https://mastodon.gamedev.place/@dougbinks/99009293355650878
*
* \param col_ The color the underline should be.
*/
static inline void AddUnderline(ImColor col_) {
ImVec2 min = ImGui::GetItemRectMin();
ImVec2 max = ImGui::GetItemRectMax();
min.y = max.y;
ImGui::GetWindowDrawList()->AddLine(min, max, col_, 1.0f);
}
/**
* \brief taken from https://gist.github.com/dougbinks/ef0962ef6ebe2cadae76c4e9f0586c69
* "hyperlink urls"
*
* \param name_ The shown text.
* \param URL_ The url accessed after clicking the shown text.
* \param SameLineBefore_ Should use on the same line before?
* \param SameLineAfter_ Should use on the same line after?
*/
static inline void TextURL(const char * name_, const char * URL_, uint8_t SameLineBefore_, uint8_t SameLineAfter_) {
if (1 == SameLineBefore_) { ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); }
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 165, 255, 255));
ImGui::Text("%s", name_);
ImGui::PopStyleColor();
if (ImGui::IsItemHovered()) {
if (ImGui::IsMouseClicked(0)) {
// What if the URL length is greater than int but less than size_t?
// well then the program should crash, but this is fine.
const int nchar = std::clamp(
static_cast<int>(std::strlen(URL_)),
0,
(std::numeric_limits<int>::max)() - 1);
wchar_t * URL = new wchar_t[nchar + 1];
wmemset(URL, 0, nchar + 1);
MultiByteToWideChar(CP_UTF8, 0, URL_, nchar, URL, nchar);
ShellExecuteW(NULL, L"open", URL, NULL, NULL, SW_SHOWNORMAL);
delete[] URL;
}
AddUnderline(ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]);
ImGui::SetTooltip(" Open in browser\n%s", URL_);
} else {
AddUnderline(ImGui::GetStyle().Colors[ImGuiCol_Button]);
}
if (1 == SameLineAfter_) { ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); }
}
/**
* \brief This call usually includes ImGui code that is shown and rendered (repeatedly,
* on every frame rendered) when your plugin is selected in the plugin
* manager. AFAIK, if your plugin doesn't have an associated *.set file for its
* settings, this will be used instead.
*
*/
void ColorBlindColorChanger::RenderSettings() {
if (!cb_enabled) {
std::string disclaimer {
"This plugin does not work with the color blind setting disabled "
"(found in Settings -> Interface -> Color blind mode)."};
float dwidth = ImGui::CalcTextSize(disclaimer.c_str()).x;
AlignForWidth(dwidth);
ImGui::TextWrapped(disclaimer.c_str());
return;
}
if (ImGui::Checkbox("Enable plugin", &plugin_enabled)) {
CVarManager::instance().get_cvar_enabled().setValue(plugin_enabled);
}
ImGui::SameLine();
std::string s {"Debug level? (leave OFF to spare your console)"};
float item_size = ImGui::CalcTextSize(s.c_str()).x + 75.0f;
AlignForWidth(item_size, 1.0f);
ImGui::TextUnformatted(s.c_str());
ImGui::SameLine();
ImGui::SetNextItemWidth(75.0f);
if (ImGui::BeginCombo("##debug_level", debug_level, ImGuiComboFlags_NoArrowButton)) {
for (int n = 0; n < IM_ARRAYSIZE(debug_levels); n++) {
bool is_selected = (debug_level == debug_levels[n]);
if (ImGui::Selectable(debug_levels[n], is_selected)) {
debug_level = debug_levels[n];
log::set_loglevel(static_cast<log::LOGLEVEL>(n));
}
if (is_selected) { ImGui::SetItemDefaultFocus(); }
}
ImGui::EndCombo();
}
ImGui::Separator();
with_Disabled(!plugin_enabled);
if (ImGui::Checkbox("Set color globally? ", &globally_set)) {
CVarManager::instance().get_cvar_global().setValue(globally_set);
}
ImGui::SameLine(ImGui::GetCursorPosX(), 100.0f);
ImGui::SetNextItemWidth(200.0f);
if (ImGui::Combo("##colorize_option", &colorize_option, color_set_choice, IM_ARRAYSIZE(color_set_choice))) {
CVarManager::instance().get_cvar_colorize_option().setValue(colorize_option);
set_colorblind_colors();
}
ImGui::SameLine(740.0f, 0.0f);
ImGui::SetNextItemWidth(150.0f);
if (ImGui::Button("Update Colors")) {
gameWrapper->Execute([this](GameWrapper * gw) { set_colorblind_colors(); });
}
ImGui::NewLine();
static float cpos_bottom_blue = 0.0f;
static float cpos_bottom_orange = 0.0f;
ImGui::Columns(3, "##settings", false);
ImGui::SetColumnWidth(0, 400.0f);
ImGui::SetColumnWidth(1, 340.0f);
static size_t selected_map_idx = 0;
maybe_Disabled(globally_set) {
ImGui::TextUnformatted("Asterisk (*) by map name means a non-default color is set.");
ImGui::BeginGroup();
bool window_visible = ImGui::BeginChild(
ImGui::GetID(reinterpret_cast<void *>(static_cast<intptr_t>(0))),
ImVec2(ImGui::GetContentRegionAvailWidth(), (std::max)(cpos_bottom_orange - 50.0f, 300.0f)),
true,
NULL);
if (window_visible) {
for (size_t i = 0; i < game_maps_name_filename.size(); ++i) {
std::string_view map_name = game_maps_name_filename[i].first;
std::string_view map_filename = game_maps_name_filename[i].second;
bool is_set = (CVarManager::instance()
.getCVM()
->getCvar(
CVarManager::instance().get_cvar_prefix() + map_filename.data()
+ "_blue")
.getColorValue()
!= default_blue_rgba)
|| (CVarManager::instance()
.getCVM()
->getCvar(
CVarManager::instance().get_cvar_prefix() + map_filename.data()
+ "_orange")
.getColorValue()
!= default_orange_rgba);
char buf[128] = {0};
snprintf(
buf,
sizeof(buf),
"%s%s",
is_set ? "(*) " : "",
game_maps_name_filename[i].first.c_str());
if (ImGui::Selectable(
buf,
selected_map_idx == i,
globally_set ? ImGuiSelectableFlags_Disabled : ImGuiSelectableFlags_None)) {
selected_map_idx = i;
}
}
}
ImGui::EndChild();
ImGui::EndGroup();
}
ImGui::NextColumn();
if (globally_set) {
ImGui::TextUnformatted("Setting the color for all maps:");
} else {
ImGui::Text("Setting the color for %s:", game_maps_name_filename[selected_map_idx].first.c_str());
}
std::string map_name_or_global = globally_set ? "global" : game_maps_name_filename[selected_map_idx].second;
CVarWrapper bcvar = CVarManager::instance().getCVM()->getCvar(
CVarManager::instance().get_cvar_prefix() + map_name_or_global + "_blue");
CVarWrapper ocvar = CVarManager::instance().getCVM()->getCvar(
CVarManager::instance().get_cvar_prefix() + map_name_or_global + "_orange");
ImGuiColorEditFlags color_select_flags = ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_DisplayRGB
| ImGuiColorEditFlags_Float;
const char * blue_txt = colorize_option == 0 ? "Blue" : "Your";
ImGui::Text("%s team: ", blue_txt);
const LinearColor & blue_color = bcvar ? bcvar.getColorValue() : LinearColor {};
float blue_rgba[4] = {blue_color.R, blue_color.G, blue_color.B, blue_color.A};
if (ImGui::ColorPicker4("##blue_color", blue_rgba, color_select_flags)) {
bcvar.setValue(LinearColor {blue_rgba[0], blue_rgba[1], blue_rgba[2], blue_rgba[3]});
}
cpos_bottom_blue = ImGui::GetCursorPosY();
ImGui::NewLine();
const char * orange_txt = colorize_option == 0 ? "Orange" : "Opponent";
ImGui::Text("%s team: ", orange_txt);
const LinearColor & orange_color = ocvar ? ocvar.getColorValue() : LinearColor {};
float orange_rgba[4] = {orange_color.R, orange_color.G, orange_color.B, orange_color.A};
if (ImGui::ColorPicker4("##orange_color", orange_rgba, color_select_flags)) {
ocvar.setValue(LinearColor {orange_rgba[0], orange_rgba[1], orange_rgba[2], orange_rgba[3]});
}
cpos_bottom_orange = ImGui::GetCursorPosY();
ImGui::NextColumn();
float indent_factor = 40.0f;
ImGui::Indent(indent_factor);
ImGui::SetNextItemWidth(100.0f);
if (ImGui::Button("Load Map")) {
constexpr static const char * load_map_str
= "start {}?Game=TAGame.GameInfo_Soccar_TA?Lan?GameTags=BotsIntro,UnlimitedTime,PlayerCount8";
if (globally_set) {
gameWrapper->Execute([this](GameWrapper * gw) {
// needs to be called before the execute, otherwise...?
const std::string rmap = gw->GetRandomMap();
gw->ExecuteUnrealCommand(std::format(load_map_str, rmap));
});
} else {
gameWrapper->Execute([this](GameWrapper * gw) {
log::log_debug(
"game_maps_name_filename[selected_map_idx].second: {}",
game_maps_name_filename[selected_map_idx].second);
gw->ExecuteUnrealCommand(
std::format(load_map_str, game_maps_name_filename[selected_map_idx].second));
});
}
}
ImGui::Unindent(indent_factor);
ImGui::SetCursorPosY(cpos_bottom_blue / 2.0f - 30.0f);
ImGui::Indent(indent_factor);
ImGui::SetNextItemWidth(25.0f);
if (ImGui::Button("Set Default##def_blue")) { bcvar.setValue(default_blue_rgba); }
ImGui::NewLine();
ImGui::TextUnformatted("Copied color:");
ImVec4 blue_temp_color = {temp_blue_copy.R, temp_blue_copy.G, temp_blue_copy.B, temp_blue_copy.A};
ImGui::ColorButton("##copied_blue_color", blue_temp_color, color_select_flags, ImVec2(80, 50));
ImGui::Unindent(indent_factor);
ImGui::SetNextItemWidth(25.0f);
if (ImGui::Button("Copy Color##blue")) {
temp_blue_copy.R = blue_rgba[0];
temp_blue_copy.G = blue_rgba[1];
temp_blue_copy.B = blue_rgba[2];
temp_blue_copy.A = blue_rgba[3];
}
ImGui::SameLine(0.0f, 20.0f);
ImGui::SetNextItemWidth(25.0f);
if (ImGui::Button("Paste Color##blue")) {
blue_rgba[0] = temp_blue_copy.R;
blue_rgba[1] = temp_blue_copy.G;
blue_rgba[2] = temp_blue_copy.B;
blue_rgba[3] = temp_blue_copy.A;
bcvar.setValue(LinearColor {blue_rgba[0], blue_rgba[1], blue_rgba[2], blue_rgba[3]});
}
ImGui::SetCursorPosY(cpos_bottom_orange - (cpos_bottom_blue / 2.0f) - 30.0f);
ImGui::Indent(indent_factor);
ImGui::SetNextItemWidth(25.0f);
if (ImGui::Button("Set Default##def_orange")) { ocvar.setValue(default_orange_rgba); }
ImGui::NewLine();
ImGui::TextUnformatted("Copied color:");
ImVec4 orange_temp_color = {temp_orange_copy.R, temp_orange_copy.G, temp_orange_copy.B, temp_orange_copy.A};
ImGui::ColorButton("##copied_orange_color", orange_temp_color, color_select_flags, ImVec2(80, 50));
ImGui::Unindent(indent_factor);
ImGui::SetNextItemWidth(25.0f);
if (ImGui::Button("Copy Color##orange")) {
temp_orange_copy.R = orange_rgba[0];
temp_orange_copy.G = orange_rgba[1];
temp_orange_copy.B = orange_rgba[2];
temp_orange_copy.A = orange_rgba[3];
}
ImGui::SameLine(0.0f, 20.0f);
ImGui::SetNextItemWidth(25.0f);
if (ImGui::Button("Paste Color##orange")) {
orange_rgba[0] = temp_orange_copy.R;
orange_rgba[1] = temp_orange_copy.G;
orange_rgba[2] = temp_orange_copy.B;
orange_rgba[3] = temp_orange_copy.A;
ocvar.setValue(LinearColor {orange_rgba[0], orange_rgba[1], orange_rgba[2], orange_rgba[3]});
}
ImGui::EndColumns();
ImGui::NewLine();
if (ImGui::CollapsingHeader("INFORMATION")) {
// SOME TEXT EXPLAINING SOME QUESTIONS
static const float INDENT_OFFSET = 40.0f;
// Question 1
ImGui::Indent(INDENT_OFFSET);
ImGui::TextUnformatted("WHAT IF I CRASH OR HAVE A PROBLEM?");
AddUnderline(col_white);
ImGui::TextUnformatted("WHAT IF I HAVE A SUGGESTION?");
AddUnderline(col_white);
ImGui::TextUnformatted("WHAT IF I NEED TO INFORM YOU OF A CORRECTION?");
AddUnderline(col_white);
ImGui::Unindent(INDENT_OFFSET);
ImGui::TextUnformatted("Raise an issue on the github page: ");
TextURL("HERE", "https://github.com/mgavin/ColorBlindColorChanger/issues", true, true);
ImGui::TextUnformatted(" Thanks!");
}
}
/**
* \brief "SetImGuiContext happens when the plugin's ImGui is initialized."
* https://wiki.bakkesplugins.com/imgui/custom_fonts/
*
* also:
* "Don't call this yourself, BM will call this function with a pointer
* to the current ImGui context" -- pluginsettingswindow.h
* ...
*
* \param ctx AFAIK The pointer to the ImGui context
*/
void ColorBlindColorChanger::SetImGuiContext(uintptr_t ctx) {
ImGui::SetCurrentContext(reinterpret_cast<ImGuiContext *>(ctx));
}
/**
* \brief Get the name of the plugin for the plugins tab in bakkesmod
*
*
* \return The name of the plugin for the plugins tab in BakkesMod.
*/
std::string ColorBlindColorChanger::GetPluginName() {
return "Color Blind Color Changer";
}
/*
* for when you've inherited from BakkesMod::Plugin::PluginWindow.
* this lets you do "togglemenu (GetMenuName())" in BakkesMod's console...
* ie
* if the following GetMenuName() returns "xyz", then you can refer to your
* plugin's window in game through "togglemenu xyz"
*/
/**
* \brief do the following on togglemenu open
*/
// void ColorBlindColorChanger::OnOpen() {};
/**
* \brief do the following on menu close
*/
// void ColorBlindColorChanger::OnClose() {};
/**
* \brief (ImGui) Code called while rendering your menu window
*/
// void ColorBlindColorChanger::Render() {};
/**
* \brief Returns the name of the menu to refer to it by
*
* \return The name used refered to by togglemenu
*/
// std::string ColorBlindColorChanger::GetMenuName() {
// return "ColorBlindColorChanger";
// };
/**
* \brief Returns a std::string to show as the title
*
* \return The title of the menu
*/
// std::string ColorBlindColorChanger::GetMenuTitle() {
// return "ColorBlindColorChanger";
// };
/**
* \brief Is it the active overlay(window)?
*
* \return True/False for being the active overlay
*/
// bool ColorBlindColorChanger::IsActiveOverlay() {
// return true;
// };
/**
* \brief Should this block input from the rest of the program?
* (aka RocketLeague and BakkesMod windows)
*
* \return True/False for if bakkesmod should block input
*/
// bool ColorBlindColorChanger::ShouldBlockInput() {
// return false;
// };
/**
* \brief Do the following when your plugin is unloaded
*
* destroy things here, don't throw
* don't rely on this to assuredly run when RL is closed
*/
void ColorBlindColorChanger::onUnload() {
}