mirror of
https://github.com/HarbourMasters/Shipwright
synced 2026-08-16 21:38:07 -04:00
Merge remote-tracking branch 'origin/develop' into macready-golf-merge
This commit is contained in:
+64
-33
@@ -7,8 +7,11 @@
|
||||
|
||||
#include "UIWidgets.hpp"
|
||||
|
||||
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include <ImGui/imgui_internal.h>
|
||||
#endif
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <libultraship/libultraship.h>
|
||||
|
||||
#include <libultraship/libultra/types.h>
|
||||
@@ -205,7 +208,7 @@ namespace UIWidgets {
|
||||
bool val = (bool)CVarGetInteger(cvarName, defaultValue);
|
||||
if (CustomCheckbox(text, &val, disabled, disabledGraphic)) {
|
||||
CVarSetInteger(cvarName, val);
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
@@ -245,7 +248,7 @@ namespace UIWidgets {
|
||||
CVarSetInteger(cvarName, i);
|
||||
selected = i;
|
||||
changed = true;
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,7 +261,7 @@ namespace UIWidgets {
|
||||
if (disabledValue >= 0 && selected != disabledValue) {
|
||||
CVarSetInteger(cvarName, disabledValue);
|
||||
changed = true;
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,6 +297,7 @@ namespace UIWidgets {
|
||||
bool EnhancementSliderInt(const char* text, const char* id, const char* cvarName, int min, int max, const char* format, int defaultValue, bool PlusMinusButton, bool disabled, const char* disabledTooltipText) {
|
||||
bool changed = false;
|
||||
int val = CVarGetInteger(cvarName, defaultValue);
|
||||
const int oldVal = val;
|
||||
|
||||
if (disabled) {
|
||||
DisableComponent(ImGui::GetStyle().Alpha * 0.5f);
|
||||
@@ -345,9 +349,11 @@ namespace UIWidgets {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
if (changed && (oldVal != val)) {
|
||||
CVarSetInteger(cvarName, val);
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
} else {
|
||||
changed = false;
|
||||
}
|
||||
|
||||
return changed;
|
||||
@@ -356,15 +362,46 @@ namespace UIWidgets {
|
||||
bool EnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage, bool PlusMinusButton, bool disabled, const char* disabledTooltipText) {
|
||||
bool changed = false;
|
||||
float val = CVarGetFloat(cvarName, defaultValue);
|
||||
|
||||
const float oldVal = val;
|
||||
if (disabled) {
|
||||
DisableComponent(ImGui::GetStyle().Alpha * 0.5f);
|
||||
}
|
||||
|
||||
// Calculate how much precision to save based on the given range of the slider, limited to 6 decimal places
|
||||
// Precision is also used when adding/subtracting using the +/- buttons
|
||||
const float sliderWidth = std::min((ImGui::GetContentRegionAvail().x - 2.0f * (PlusMinusButton ? sliderButtonWidth : 0.0f)), maxSliderWidth);
|
||||
const float diff = (max - min) / sliderWidth;
|
||||
int ticks = 0;
|
||||
float increment = 1.0f;
|
||||
if (diff < 1.0f) {
|
||||
ticks++;
|
||||
increment = 0.1f;
|
||||
}
|
||||
if (diff < 0.1f) {
|
||||
ticks++;
|
||||
increment = 0.01f;
|
||||
}
|
||||
if (diff < 0.01f) {
|
||||
ticks++;
|
||||
increment = 0.001f;
|
||||
}
|
||||
if (diff < 0.001f) {
|
||||
ticks++;
|
||||
increment = 0.0001f;
|
||||
}
|
||||
if (diff < 0.0001f) {
|
||||
ticks++;
|
||||
increment = 0.00001f;
|
||||
}
|
||||
if (diff < 0.00001f) {
|
||||
ticks++;
|
||||
increment = 0.000001f;
|
||||
}
|
||||
|
||||
if (!isPercentage) {
|
||||
ImGui::Text(text, val);
|
||||
} else {
|
||||
ImGui::Text(text, static_cast<int>(100 * val));
|
||||
ImGui::Text(text, val * 100.0f);
|
||||
}
|
||||
Spacer(0);
|
||||
|
||||
@@ -372,22 +409,15 @@ namespace UIWidgets {
|
||||
if (PlusMinusButton) {
|
||||
std::string MinusBTNName = " - ##" + std::string(cvarName);
|
||||
if (ImGui::Button(MinusBTNName.c_str())) {
|
||||
if (isPercentage) {
|
||||
val -= 0.01f;
|
||||
} else {
|
||||
val -= 0.1f;
|
||||
}
|
||||
val -= increment;
|
||||
changed = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f);
|
||||
}
|
||||
|
||||
ImGui::PushItemWidth(std::min((ImGui::GetContentRegionAvail().x - (PlusMinusButton ? sliderButtonWidth : 0.0f)), maxSliderWidth));
|
||||
ImGui::PushItemWidth(sliderWidth);
|
||||
if (ImGui::SliderFloat(id, &val, min, max, format, ImGuiSliderFlags_AlwaysClamp)) {
|
||||
if (isPercentage) {
|
||||
val = roundf(val * 100) / 100;
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
@@ -397,11 +427,7 @@ namespace UIWidgets {
|
||||
ImGui::SameLine();
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f);
|
||||
if (ImGui::Button(PlusBTNName.c_str())) {
|
||||
if (isPercentage) {
|
||||
val += 0.01f;
|
||||
} else {
|
||||
val += 0.1f;
|
||||
}
|
||||
val += increment;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@@ -421,9 +447,14 @@ namespace UIWidgets {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
if (changed && !(abs(oldVal - val) < 0.000001f)) {
|
||||
std::stringstream ss;
|
||||
ss << std::setprecision(ticks + 1) << std::setiosflags(std::ios_base::fixed) << val;
|
||||
val = std::stof(ss.str());
|
||||
CVarSetFloat(cvarName, val);
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
} else {
|
||||
changed = false;
|
||||
}
|
||||
|
||||
return changed;
|
||||
@@ -455,14 +486,14 @@ namespace UIWidgets {
|
||||
|
||||
bool EnhancementRadioButton(const char* text, const char* cvarName, int id) {
|
||||
/*Usage :
|
||||
EnhancementRadioButton("My Visible Name","gMyCVarName", MyID);
|
||||
EnhancementRadioButton("My Visible Name",CVAR_GROUP("MyCVarName"), MyID);
|
||||
First arg is the visible name of the Radio button
|
||||
Second is the cvar name where MyID will be saved.
|
||||
Note: the CVar name should be the same to each Buddies.
|
||||
Example :
|
||||
EnhancementRadioButton("English", "gLanguages", LANGUAGE_ENG);
|
||||
EnhancementRadioButton("German", "gLanguages", LANGUAGE_GER);
|
||||
EnhancementRadioButton("French", "gLanguages", LANGUAGE_FRA);
|
||||
EnhancementRadioButton("English", CVAR_SETTING("Languages"), LANGUAGE_ENG);
|
||||
EnhancementRadioButton("German", CVAR_SETTING("Languages"), LANGUAGE_GER);
|
||||
EnhancementRadioButton("French", CVAR_SETTING("Languages"), LANGUAGE_FRA);
|
||||
*/
|
||||
std::string make_invisible = "##" + std::string(text) + std::string(cvarName);
|
||||
|
||||
@@ -470,7 +501,7 @@ namespace UIWidgets {
|
||||
int val = CVarGetInteger(cvarName, 0);
|
||||
if (ImGui::RadioButton(make_invisible.c_str(), id == val)) {
|
||||
CVarSetInteger(cvarName, id);
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
ret = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
@@ -497,7 +528,7 @@ namespace UIWidgets {
|
||||
|
||||
CVarSetColor(cvarName, colorsRGBA);
|
||||
CVarSetInteger(Cvar_RBM.c_str(), 0); //On click disable rainbow mode.
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
changed = true;
|
||||
}
|
||||
Tooltip("Revert colors to the game's original colors (GameCube version)\nOverwrites previously chosen color");
|
||||
@@ -522,7 +553,7 @@ namespace UIWidgets {
|
||||
NewColors.b = fmin(fmax(colors->z * 255, 0), 255);
|
||||
CVarSetColor(cvarName, NewColors);
|
||||
CVarSetInteger(Cvar_RBM.c_str(), 0); // On click disable rainbow mode.
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
changed = true;
|
||||
}
|
||||
Tooltip("Chooses a random color\nOverwrites previously chosen color");
|
||||
@@ -583,7 +614,7 @@ namespace UIWidgets {
|
||||
colors.a = 255.0;
|
||||
|
||||
CVarSetColor(cvarName, colors);
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@@ -599,7 +630,7 @@ namespace UIWidgets {
|
||||
colors.a = ColorRGBA.w * 255.0;
|
||||
|
||||
CVarSetColor(cvarName, colors);
|
||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user