Skip to content

Commit

Permalink
Cosmetics hotfixes (#640)
Browse files Browse the repository at this point in the history
* Initial branch creation

* Revert Main Game so it do not conflict later

* should fix window build, made namespace for Cosmetics

* forgot to edit one title

* Ability to add hidden window (usefull for Rainbow)
Fix building issues

* Line break, unused bool remove
  • Loading branch information
Baoulettes authored Jul 12, 2022
1 parent c25089b commit 37bf9b3
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 74 deletions.
86 changes: 17 additions & 69 deletions libultraship/libultraship/ImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,13 @@ namespace SohImGui {
bool p_open = false;
bool needs_save = false;

const char* RainbowColorCvarList[] = {
//This is the list of possible CVars that has rainbow effect.
"gTunic_Kokiri_", "gTunic_Goron_", "gTunic_Zora_",
"gFireArrowCol", "gIceArrowCol", "gTunic_Zora_",
"gFireArrowColEnv", "gIceArrowColEnv", "gLightArrowColEnv",
"gCCHeartsPrim", "gDDCCHeartsPrim", "gLightArrowCol",
"gCCABtnPrim", "gCCBBtnPrim", "gCCCBtnPrim", "gCCStartBtnPrim",
"gCCCUBtnPrim", "gCCCLBtnPrim", "gCCCRBtnPrim", "gCCCDBtnPrim", "gCCDpadPrim",
"gCCMagicBorderNormPrim", "gCCMagicBorderPrim", "gCCMagicPrim", "gCCMagicUsePrim",
"gCCMinimapPrim", "gCCMinimapDGNPrim", "gCCMinimapCPPrim", "gCCMinimapLEPrim",
"gCCRupeePrim", "gCCKeysPrim", "gDog1Col", "gDog2Col", "gCCVSOAPrim",
"gKeese1_Ef_Prim","gKeese2_Ef_Prim","gKeese1_Ef_Env","gKeese2_Ef_Env",
"gDF_Col", "gDF_Env",
"gNL_Diamond_Col", "gNL_Diamond_Env", "gNL_Orb_Col", "gNL_Orb_Env",
"gTrailCol", "gCharged1Col", "gCharged1ColEnv", "gCharged2Col", "gCharged2ColEnv",
"gCCFileChoosePrim", "gCCFileChooseTextPrim", "gCCEquipmentsPrim", "gCCItemsPrim",
"gCCMapsPrim", "gCCQuestsPrim", "gCCSavePrim", "gCCGameoverPrim",
};

const char* filters[3] = {
"Three-Point",
"Linear",
"None"
};

std::map<std::string, std::vector<std::string>> hiddenwindowCategories;
std::map<std::string, std::vector<std::string>> windowCategories;
std::map<std::string, CustomWindow> customWindows;

Expand Down Expand Up @@ -248,50 +230,6 @@ namespace SohImGui {
stbi_image_free(img_data);
}

void LoadRainbowColor() {
u8 arrayLength = sizeof(RainbowColorCvarList) / sizeof(*RainbowColorCvarList);
for (u8 s = 0; s < arrayLength; s++) {
std::string cvarName = RainbowColorCvarList[s];
std::string Cvar_Red = cvarName;
Cvar_Red += "R";
std::string Cvar_Green = cvarName;
Cvar_Green += "G";
std::string Cvar_Blue = cvarName;
Cvar_Blue += "B";
std::string Cvar_RBM = cvarName;
Cvar_RBM += "RBM";
std::string RBM_HUE = cvarName;
RBM_HUE += "Hue";
f32 Canon = 10.f * s;
ImVec4 NewColor;
const f32 deltaTime = 1.0f / ImGui::GetIO().Framerate;
f32 hue = CVar_GetFloat(RBM_HUE.c_str(), 0.0f);
f32 newHue = hue + CVar_GetS32("gColorRainbowSpeed", 1) * 36.0f * deltaTime;
if (newHue >= 360)
newHue = 0;
CVar_SetFloat(RBM_HUE.c_str(), newHue);
f32 current_hue = CVar_GetFloat(RBM_HUE.c_str(), 0);
u8 i = current_hue / 60 + 1;
u8 a = (-current_hue / 60.0f + i) * 255;
u8 b = (current_hue / 60.0f + (1 - i)) * 255;

switch (i) {
case 1: NewColor.x = 255; NewColor.y = b; NewColor.z = 0; break;
case 2: NewColor.x = a; NewColor.y = 255; NewColor.z = 0; break;
case 3: NewColor.x = 0; NewColor.y = 255; NewColor.z = b; break;
case 4: NewColor.x = 0; NewColor.y = a; NewColor.z = 255; break;
case 5: NewColor.x = b; NewColor.y = 0; NewColor.z = 255; break;
case 6: NewColor.x = 255; NewColor.y = 0; NewColor.z = a; break;
}

if (CVar_GetS32(Cvar_RBM.c_str(), 0) != 0) {
CVar_SetS32(Cvar_Red.c_str(), ClampFloatToInt(NewColor.x, 0, 255));
CVar_SetS32(Cvar_Green.c_str(), ClampFloatToInt(NewColor.y, 0, 255));
CVar_SetS32(Cvar_Blue.c_str(), ClampFloatToInt(NewColor.z, 0, 255));
}
}
}

void LoadPickersColors(ImVec4& ColorArray, const char* cvarname, const ImVec4& default_colors, bool has_alpha) {
std::string Cvar_Red = cvarname;
Cvar_Red += "R";
Expand Down Expand Up @@ -1276,14 +1214,22 @@ namespace SohImGui {
}
ImGui::EndMenu();
}

}

ImGui::EndMenuBar();
}

ImGui::End();

for (const auto& category : hiddenwindowCategories) {
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
ImGui::SetNextWindowSize(ImVec2 (0,0));
ImGui::SetNextWindowPos(ImVec2 (-100,-100));
ImGui::Begin(category.first.c_str(), nullptr, ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNavFocus);
ImGui::End();
ImGui::PopStyleColor();
}

if (CVar_GetS32("gStatsEnabled", 0)) {
const float framerate = ImGui::GetIO().Framerate;
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
Expand Down Expand Up @@ -1422,8 +1368,6 @@ namespace SohImGui {
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
//Placed here so it does the rainbow effects even if menu is not on.
LoadRainbowColor();
}

void CancelFrame() {
Expand All @@ -1437,18 +1381,22 @@ namespace SohImGui {
console->Commands[cmd] = std::move(entry);
}

void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc) {
void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc, bool isEnabled, bool isHidden) {
if (customWindows.contains(name)) {
SPDLOG_ERROR("SohImGui::AddWindow: Attempting to add duplicate window name %s", name.c_str());
return;
}

customWindows[name] = {
.enabled = false,
.enabled = isEnabled,
.drawFunc = drawFunc
};

windowCategories[category].emplace_back(name);
if (isHidden) {
hiddenwindowCategories[category].emplace_back(name);
} else {
windowCategories[category].emplace_back(name);
}
}

ImTextureID GetTextureByName(const std::string& name) {
Expand Down
3 changes: 2 additions & 1 deletion libultraship/libultraship/ImGuiImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ namespace SohImGui {
void CancelFrame(void);
void ShowCursor(bool hide, Dialogues w);
void BindCmd(const std::string& cmd, CommandEntry entry);
void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc);
void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc, bool isEnabled=false, bool isHidden=false);
void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint = ImVec4(1, 1, 1, 1));
void LoadPickersColors(ImVec4& ColorArray, const char* cvarname, const ImVec4& default_colors, bool has_alpha=false);
int ClampFloatToInt(float value, int min, int max);
void RandomizeColor(const char* cvarName, ImVec4* colors);
void RainbowColor(const char* cvarName, ImVec4* colors);
void ResetColor(const char* cvarName, ImVec4* colors, ImVec4 defaultcolors, bool has_alpha);
Expand Down
73 changes: 69 additions & 4 deletions soh/soh/Enhancements/cosmetics/CosmeticsEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,67 @@ ImVec4 menu_map_colors;
ImVec4 menu_quest_colors;
ImVec4 menu_save_colors;
ImVec4 menu_gameover_colors;*/
const char* RainbowColorCvarList[] = {
//This is the list of possible CVars that has rainbow effect.
"gTunic_Kokiri_", "gTunic_Goron_", "gTunic_Zora_",
"gFireArrowCol", "gIceArrowCol", "gTunic_Zora_",
"gFireArrowColEnv", "gIceArrowColEnv", "gLightArrowColEnv",
"gCCHeartsPrim", "gDDCCHeartsPrim", "gLightArrowCol", "gCCDDHeartsPrim",
"gCCABtnPrim", "gCCBBtnPrim", "gCCCBtnPrim", "gCCStartBtnPrim",
"gCCCUBtnPrim", "gCCCLBtnPrim", "gCCCRBtnPrim", "gCCCDBtnPrim", "gCCDpadPrim",
"gCCMagicBorderNormPrim", "gCCMagicBorderPrim", "gCCMagicPrim", "gCCMagicUsePrim",
"gCCMinimapPrim", "gCCMinimapDGNPrim", "gCCMinimapCPPrim", "gCCMinimapLEPrim",
"gCCRupeePrim", "gCCKeysPrim", "gDog1Col", "gDog2Col", "gCCVSOAPrim",
"gKeese1_Ef_Prim","gKeese2_Ef_Prim","gKeese1_Ef_Env","gKeese2_Ef_Env",
"gDF_Col", "gDF_Env",
"gNL_Diamond_Col", "gNL_Diamond_Env", "gNL_Orb_Col", "gNL_Orb_Env",
"gTrailCol", "gCharged1Col", "gCharged1ColEnv", "gCharged2Col", "gCharged2ColEnv",
"gCCFileChoosePrim", "gCCFileChooseTextPrim", "gCCEquipmentsPrim", "gCCItemsPrim",
"gCCMapsPrim", "gCCQuestsPrim", "gCCSavePrim", "gCCGameoverPrim",
};
void LoadRainbowColor(bool& open) {
u8 arrayLength = sizeof(RainbowColorCvarList) / sizeof(*RainbowColorCvarList);
for (u8 s = 0; s < arrayLength; s++) {
std::string cvarName = RainbowColorCvarList[s];
std::string Cvar_Red = cvarName;
Cvar_Red += "R";
std::string Cvar_Green = cvarName;
Cvar_Green += "G";
std::string Cvar_Blue = cvarName;
Cvar_Blue += "B";
std::string Cvar_RBM = cvarName;
Cvar_RBM += "RBM";
std::string RBM_HUE = cvarName;
RBM_HUE += "Hue";
f32 Canon = 10.f * s;
ImVec4 NewColor;
const f32 deltaTime = 1.0f / ImGui::GetIO().Framerate;
f32 hue = CVar_GetFloat(RBM_HUE.c_str(), 0.0f);
f32 newHue = hue + CVar_GetS32("gColorRainbowSpeed", 1) * 36.0f * deltaTime;
if (newHue >= 360)
newHue = 0;
CVar_SetFloat(RBM_HUE.c_str(), newHue);
f32 current_hue = CVar_GetFloat(RBM_HUE.c_str(), 0);
u8 i = current_hue / 60 + 1;
u8 a = (-current_hue / 60.0f + i) * 255;
u8 b = (current_hue / 60.0f + (1 - i)) * 255;

switch (i) {
case 1: NewColor.x = 255; NewColor.y = b; NewColor.z = 0; break;
case 2: NewColor.x = a; NewColor.y = 255; NewColor.z = 0; break;
case 3: NewColor.x = 0; NewColor.y = 255; NewColor.z = b; break;
case 4: NewColor.x = 0; NewColor.y = a; NewColor.z = 255; break;
case 5: NewColor.x = b; NewColor.y = 0; NewColor.z = 255; break;
case 6: NewColor.x = 255; NewColor.y = 0; NewColor.z = a; break;
}

if (CVar_GetS32(Cvar_RBM.c_str(), 0) != 0) {
CVar_SetS32(Cvar_Red.c_str(), SohImGui::ClampFloatToInt(NewColor.x, 0, 255));
CVar_SetS32(Cvar_Green.c_str(), SohImGui::ClampFloatToInt(NewColor.y, 0, 255));
CVar_SetS32(Cvar_Blue.c_str(), SohImGui::ClampFloatToInt(NewColor.z, 0, 255));
}
}
}
void Table_InitHeader(bool has_header = true) {
if (has_header) {
ImGui::TableHeadersRow();
Expand Down Expand Up @@ -258,11 +319,11 @@ void Draw_ItemsSkills(){
SohImGui::EnhancementColor("Level 2 color", "gCharged2ColEnv", charged2_colenv, ImVec4(255,100,0,255));
ImGui::EndTable();
}
SohImGui::EnhancementCheckbox("Custom sword trails color", "gUseTrailsCol");
SohImGui::EnhancementCheckbox("Custom trails color", "gUseTrailsCol");
if (CVar_GetS32("gUseTrailsCol",0) && ImGui::BeginTable("tabletrails", 1, ImGuiTableFlags_BordersH | ImGuiTableFlags_BordersV)) {
ImGui::TableSetupColumn("Custom Swords trails", ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_NoSort, TablesCellsWidth);
ImGui::TableSetupColumn("Custom Trails", ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_NoSort, TablesCellsWidth);
Table_InitHeader();
Draw_HelpIcon("Affects Slash trails color");
Draw_HelpIcon("Affects Swords slash, boomerang and Bombchu trails color");
SohImGui::EnhancementColor("Trails color", "gTrailCol", trailscol, ImVec4(255,255,255,255));
SohImGui::EnhancementSliderInt("Trails duration: %dx", "##TrailsMul", "gTrailDurantion", 1, 5, "");
SohImGui::Tooltip("The longer the trails the weirder it become");
Expand Down Expand Up @@ -1044,6 +1105,10 @@ void DrawCosmeticsEditor(bool& open) {
ImGui::End();
}
void InitCosmeticsEditor() {
//This allow to hide a window without disturbing the player nor adding things in menu
//LoadRainbowColor() will this way run in background once it's window is activated
//ImGui::SetNextItemWidth(0.0f);
SohImGui::AddWindow("Cosmetics", "Rainbowfunction", LoadRainbowColor, true, true);
//Draw the bar in the menu.
SohImGui::AddWindow("Cosmetics", "Cosmetics Editor", DrawCosmeticsEditor);
}
}
1 change: 1 addition & 0 deletions soh/soh/Enhancements/cosmetics/CosmeticsEditor.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once

void InitCosmeticsEditor();//Init the menu itself
void LoadRainbowColor();

0 comments on commit 37bf9b3

Please sign in to comment.