Fixed-width taskbar meters
This commit is contained in:
1 parent
4e3abaa381
commit
9983365f74
1 file changed
+14
-8
+14
-8
@@ -26,8 +26,6 @@ constexpr float INDICATOR_SPEED = 2;
|
|||||||
constexpr float ITEM_SIZE = 96;
|
constexpr float ITEM_SIZE = 96;
|
||||||
constexpr float ROUNDING = 10;
|
constexpr float ROUNDING = 10;
|
||||||
constexpr float BAR_EASE = 6;
|
constexpr float BAR_EASE = 6;
|
||||||
constexpr float BAR_SHAKE = 2;
|
|
||||||
constexpr float BAR_SHAKE_SPEED = 40;
|
|
||||||
constexpr float FLOATER_SHADOW = 3;
|
constexpr float FLOATER_SHADOW = 3;
|
||||||
constexpr float OVERSTUFFED_PULSE = 0.35f;
|
constexpr float OVERSTUFFED_PULSE = 0.35f;
|
||||||
constexpr float OVERSTUFFED_SPEED = 6;
|
constexpr float OVERSTUFFED_SPEED = 6;
|
||||||
@@ -492,11 +490,23 @@ void Ui::taskbar_draw(Play& play, ImVec2 screen)
|
|||||||
float fills[] = {body.stage_progress_get(), stats.calories / std::max(1.0f, body.capacity_max_get()), digestion};
|
float fills[] = {body.stage_progress_get(), stats.calories / std::max(1.0f, body.capacity_max_get()), digestion};
|
||||||
float overstuffed = std::clamp((stats.calories - stats.capacity) / (body.capacity_max_get() - stats.capacity), 0.0f, 1.0f);
|
float overstuffed = std::clamp((stats.calories - stats.capacity) / (body.capacity_max_get() - stats.capacity), 0.0f, 1.0f);
|
||||||
|
|
||||||
|
auto widest_get = [](std::string text) {
|
||||||
|
for (char& character : text)
|
||||||
|
if (character >= '0' && character <= '9')
|
||||||
|
character = '8';
|
||||||
|
return ImGui::CalcTextSize(text.c_str()).x;
|
||||||
|
};
|
||||||
|
Traits& traits = data.traits;
|
||||||
|
std::string heaviest = weight_format(traits.weightMax, *measurement);
|
||||||
|
float fullest = traits.capacityMax * traits.overstuffedMultiplier;
|
||||||
|
float texts[] = {widest_get(heaviest + " / " + heaviest),
|
||||||
|
widest_get(text_format("%.0f / %.0f kcal", fullest, fullest)),
|
||||||
|
std::max(widest_get("Digesting..."), widest_get("100%"))};
|
||||||
float widths[std::size(labels)];
|
float widths[std::size(labels)];
|
||||||
float used = 0;
|
float used = 0;
|
||||||
for (int i = 0; i < (int)std::size(labels); i++)
|
for (int i = 0; i < (int)std::size(labels); i++)
|
||||||
{
|
{
|
||||||
widths[i] = std::max(BAR_WIDTH_MIN, ImGui::CalcTextSize(bars[i].c_str()).x + style.FramePadding.x * 4);
|
widths[i] = std::max(BAR_WIDTH_MIN, texts[i] + style.FramePadding.x * 4);
|
||||||
used += ImGui::CalcTextSize(labels[i]).x + style.ItemSpacing.x + widths[i];
|
used += ImGui::CalcTextSize(labels[i]).x + style.ItemSpacing.x + widths[i];
|
||||||
}
|
}
|
||||||
int count = BUTTONS_FIXED + (int)data.interactTypes.size() + play.isCheats;
|
int count = BUTTONS_FIXED + (int)data.interactTypes.size() + play.isCheats;
|
||||||
@@ -569,13 +579,9 @@ void Ui::taskbar_draw(Play& play, ImVec2 screen)
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
float time = (float)ImGui::GetTime();
|
float time = (float)ImGui::GetTime();
|
||||||
barFills[i] += (fills[i] - barFills[i]) * std::min(1.0f, BAR_EASE * ImGui::GetIO().DeltaTime);
|
barFills[i] += (fills[i] - barFills[i]) * std::min(1.0f, BAR_EASE * ImGui::GetIO().DeltaTime);
|
||||||
if (i == 1 && overstuffed > 0)
|
|
||||||
{
|
|
||||||
float red = 1 - overstuffed * (1 - OVERSTUFFED_PULSE * (1 + std::sin(time * OVERSTUFFED_SPEED)) / 2);
|
float red = 1 - overstuffed * (1 - OVERSTUFFED_PULSE * (1 + std::sin(time * OVERSTUFFED_SPEED)) / 2);
|
||||||
|
if (i == 1 && overstuffed > 0)
|
||||||
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(1, red, red, 1));
|
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(1, red, red, 1));
|
||||||
ImVec2 cursor = ImGui::GetCursorScreenPos();
|
|
||||||
ImGui::SetCursorScreenPos({cursor.x + std::sin(time * BAR_SHAKE_SPEED) * BAR_SHAKE * overstuffed, cursor.y});
|
|
||||||
}
|
|
||||||
ImGui::ProgressBar(barFills[i], {widths[i], 0}, bars[i].c_str());
|
ImGui::ProgressBar(barFills[i], {widths[i], 0}, bars[i].c_str());
|
||||||
if (i == 1 && overstuffed > 0)
|
if (i == 1 && overstuffed > 0)
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
|||||||
Reference in new issue
Block a user