Skip to content

Commit

Permalink
add show in char select and sheet color alpha settings, adjust dark c…
Browse files Browse the repository at this point in the history
…olor selection algorithm, fix conditional color retriver, update default settings
  • Loading branch information
pv42 committed Jan 23, 2022
1 parent 90190db commit 351f3de
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
24 changes: 16 additions & 8 deletions TheTruth/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ Settings::Settings() {
Logger::e(e.what());
}
} else {
Logger::i("no settings file found, using default settings for [Cute]");
showBgColorInRolesTable = true;
showBgColorInOwnRoles = true;
Logger::i("no settings file found, using default settings");
ownWindowShowTitle = true;
lockOwnRoleWindow = false;
showHeaderInOwnRoles = false;
Expand All @@ -36,14 +34,16 @@ Settings::Settings() {
showAllRolesMode = ALL_AERODROME;
showCurrentWing = true;
showOwnRolesMode = OWN_ALWAYS;
sheetId = "19AEHyOVnXCzTlVmmKROu7AHLn9NYN7JzjLCNm7KE9Tc";
ownName = "Pv";
namesRange = "'The Truth'!A5:A14";
wingRolesRanges = vector<string>{ "", "", "'The Truth'!G22:I31", "'The Truth'!B22:E31", "'The Truth'!B5:E14", "'The Truth'!G5:I14", "'The Truth'!K5:M14"};
wingHeaderRanges = vector<string>{ "", "", "'The Truth'!G21:I21", "'The Truth'!B21:E21" ,"'The Truth'!B4:E4", "'The Truth'!G4:I4", "'The Truth'!K4:M4" };
windowToggleKey.keyCode = 82; // r
windowToggleKey.requireArcMod1 = true;
windowToggleKey.requireArcMod2 = true;
// color
sheetColorAlpha = 0.8;
showBgColorInRolesTable = true;
showBgColorInOwnRoles = true;
useSheetsConditionalColors = true;
// sheet setup
ownName = "Pv";
}
}

Expand All @@ -61,6 +61,9 @@ void Settings::loadFromJson(json j) {
if (j.contains("useSheetsConditionalColors") && j["useSheetsConditionalColors"].is_boolean()) {
useSheetsConditionalColors = j["useSheetsConditionalColors"];
}
if (j.contains("sheetColorAlpha") && j["sheetColorAlpha"].is_number_float()) {
sheetColorAlpha = j["sheetColorAlpha"];
}
if (j.contains("sheetId") && j["sheetId"].is_string()) {
sheetId = j["sheetId"];
}
Expand Down Expand Up @@ -91,6 +94,9 @@ void Settings::loadFromJson(json j) {
if (j.contains("showCurrentWing") && j["showCurrentWing"].is_boolean()) {
lockOwnRoleWindow = j["showCurrentWing"];
}
if (j.contains("showInCharSelectAndLoading") && j["showInCharSelectAndLoading"].is_boolean()) {
showInCharSelectAndLoading = j["showInCharSelectAndLoading"];
}
if (j.contains("showHeaderInOwnRoles") && j["showHeaderInOwnRoles"].is_boolean()) {
showHeaderInOwnRoles = j["showHeaderInOwnRoles"];
}
Expand Down Expand Up @@ -190,6 +196,7 @@ json Settings::toJson() const {
j["showBgColorInRolesTable"] = showBgColorInRolesTable;
j["showBgColorInOwnRoles"] = showBgColorInOwnRoles;
j["useSheetsConditionalColors"] = useSheetsConditionalColors;
j["sheetColorAlpha"] = sheetColorAlpha;
j["sheetId"] = sheetId;
j["ownName"] = ownName;
j["namesRange"] = namesRange;
Expand All @@ -199,6 +206,7 @@ json Settings::toJson() const {
j["weekday"] = weekday;
j["showCurrentWing"] = showCurrentWing;
j["showAllRolesMode"] = showAllRolesMode;
j["showInCharSelectAndLoading"] = showInCharSelectAndLoading;
j["flipRowsAndCols"] = flipRowsAndCols;
j["windowToggleKey"] = windowToggleKey.keyCode;
j["windowToggleKeyMod1"] = windowToggleKey.requireArcMod1;
Expand Down
2 changes: 2 additions & 0 deletions TheTruth/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Settings {
bool showBgColorInRolesTable;
bool showBgColorInOwnRoles;
bool useSheetsConditionalColors;
float sheetColorAlpha;
bool ownWindowShowTitle;
bool lockOwnRoleWindow;
bool showHeaderInOwnRoles;
Expand All @@ -52,6 +53,7 @@ class Settings {
Key windowToggleKey;
ShowOwnRolesMode showOwnRolesMode;
ShowAllRolesMode showAllRolesMode;
bool showInCharSelectAndLoading;
vector<pair<string, ImColor>> customColors;
void save() const;
private:
Expand Down
14 changes: 12 additions & 2 deletions TheTruth/SheetsAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ json getSheetFromRangeAndJson(const shared_ptr<json> whole_json, const string& r
if (whole_json == NULL) throw(std::exception("json handle is null"));
if (!whole_json->contains("sheets") || !(*whole_json)["sheets"].is_array() || (*whole_json)["sheets"].size() == 0)
throw(std::exception("json does not contain a sheets"));
Logger::d(range.c_str());
int colon_index = -1;
for(int i = 1; i < range.size(); i++) { // empty named sheets are not allowed
if (range.at(i) == '\'') {
for(int i = 0; i < range.size(); i++) { // empty named sheets are not allowed
if (range.at(i) == '!') {
colon_index = i;
break;
}
Expand Down Expand Up @@ -271,10 +272,19 @@ void SheetsAPI::downloadSheetMetaData() {
transform(mapKey.begin(), mapKey.end(), mapKey.begin(), ::tolower);
Logger::d(string_format("set color for %s to %.2f %.2f %.2f", mapKey.c_str(), color.x, color.y, color.z));
colors_cache[mapKey] = color;
} else {
Logger::d("conditional boolean rule conddition does not contain userEnteredValue");
}
}
} else {
Logger::d(string_format("condtional rule is of unexpected fromat"));
}
}
if (sheet_json["conditionalFormats"].size() == 0) {
Logger::d("conditionalFormats lenght is 0 found");
}
} else {
Logger::d("no conditionalFormats found");
}
} catch (std::exception e) {
Logger::e("failed to download meta data");
Expand Down
16 changes: 10 additions & 6 deletions TheTruth/TheTruth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ void TheTruth::UIOptions() {
ImGui::Combo("weekday", &settings.weekday, weekdays, 7);
}
ImGui::Checkbox("fixate own roles position", &settings.lockOwnRoleWindow);
ImGui::Checkbox("show during loading screens", &settings.showInCharSelectAndLoading);
ImGui::Checkbox("show title bar in own roles", &settings.ownWindowShowTitle);
ImGui::Checkbox("show bosses in own roles", &settings.showHeaderInOwnRoles);
ImGui::Separator();
Expand All @@ -284,7 +285,8 @@ void TheTruth::UIOptions() {
ImGui::Text("Colors");
ImGui::Checkbox("colors in own roles", &settings.showBgColorInOwnRoles);
ImGui::Checkbox("colors in all roles", &settings.showBgColorInRolesTable);
ImGui::Checkbox("use conditional formation colors", &settings.useSheetsConditionalColors);
ImGui::Checkbox("use sheet conditional formation colors", &settings.useSheetsConditionalColors);
ImGui::SliderFloat("conditional formating alpha", &settings.sheetColorAlpha, 0, 1);
if (ImGui::Button("custom colors###tt_cst_color_btn")) {
showCustomColorSetup = true;
}
Expand Down Expand Up @@ -324,19 +326,19 @@ int getWingByMap(int mapId) {
}
}

float getColorLightness(const ImVec4& color) {
bool useInvertedTextColor(const ImVec4& color) {
float max = color.x;
float min = color.x;
if (color.y > max) max = color.y;
if (color.y < min) min = color.y;
if (color.z > max) max = color.z;
if (color.z < min) min = color.z;
return (max + min) / 2.0f;
return color.x * 0.299 + color.y * 0.587 + (color.z * 0.114) > 150./255.;
}

ImVec4 getTextColor(const ImVec4& bgColor) {
ImVec4 textCol = ImVec4(ImGui::GetStyleColorVec4(ImGuiCol_Text));
if (getColorLightness(bgColor) >= 0.5f) { // determin if black or white text depending on the bg color
if (useInvertedTextColor(bgColor)) { // determin if black or white text depending on the bg color
textCol.x = 1.0f - textCol.x;
textCol.y = 1.0f - textCol.y;
textCol.z = 1.0f - textCol.z;
Expand All @@ -348,6 +350,9 @@ map<string, ImVec4> getColorMap(const shared_ptr<SheetsAPI> api, const Settings&
map<string, ImVec4> colorMap;
if (settings.useSheetsConditionalColors) {
colorMap = api->getColors();
for (auto iter = colorMap.begin(); iter != colorMap.end(); iter++) {
iter->second.w = settings.sheetColorAlpha;
}
}
for (pair<string, ImColor> cc : settings.customColors) {
string key = cc.first;
Expand Down Expand Up @@ -717,8 +722,7 @@ bool shouldShowBigUI(int map, ShowAllRolesMode mode) {

void TheTruth::ImGui(uint32_t not_charsel_or_loading) {
int mapId = mumbleApi.getMapId();
if (not_charsel_or_loading) {

if (not_charsel_or_loading || settings.showInCharSelectAndLoading) {
int currentWing = getWingByMap(mapId);
if (currentWing > 0) {
if (sheetsAPI->hasWing(currentWing)) {
Expand Down

0 comments on commit 351f3de

Please sign in to comment.