Add reproduction safety trial and resizable cellular panels
This commit is contained in:
+45
-14
@@ -1170,10 +1170,21 @@ ImVec2 hud_position(ImVec2 position, ImVec2 size) {
|
||||
return {std::clamp(position.x, margin, std::max(margin, display.x - size.x - margin)),
|
||||
std::clamp(position.y, margin, std::max(margin, display.y - size.y - margin))};
|
||||
}
|
||||
void place_hud_panel(HudPanelPlacement& placement, ImVec2 fallback, ImVec2 size) {
|
||||
void place_hud_panel(HudPanelPlacement& placement, ImVec2 fallback, ImVec2 size, bool minimized) {
|
||||
const auto display = ImGui::GetIO().DisplaySize;
|
||||
ImGui::GetIO().ConfigWindowsResizeFromEdges = true;
|
||||
const ImVec2 minimum{std::min(size.x, px(260)), minimized ? size.y : px(120)};
|
||||
if (placement.size) {
|
||||
size.x = px(placement.size->first);
|
||||
if (!minimized)
|
||||
size.y = px(placement.size->second);
|
||||
}
|
||||
size.x = std::min(size.x, std::max(1.0F, display.x - 2 * px(8)));
|
||||
size.y = std::min(size.y, std::max(1.0F, display.y - 2 * px(8)));
|
||||
const ImVec2 maximum{std::max(1.0F, display.x - 2 * px(8)),
|
||||
minimized ? size.y : std::max(1.0F, display.y - 2 * px(8))};
|
||||
ImGui::SetNextWindowSizeConstraints(
|
||||
{std::min(minimum.x, maximum.x), std::min(minimum.y, maximum.y)}, maximum);
|
||||
auto position = fallback;
|
||||
if (placement.anchor)
|
||||
position = {placement.anchor->first * display.x, placement.anchor->second * display.y};
|
||||
@@ -1182,6 +1193,7 @@ void place_hud_panel(HudPanelPlacement& placement, ImVec2 fallback, ImVec2 size)
|
||||
placement.anchor = {position.x / display.x, position.y / display.y};
|
||||
ImGui::SetNextWindowPos(position, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(size, ImGuiCond_Always);
|
||||
placement.requested_size = {size.x, size.y};
|
||||
}
|
||||
float collapsed_height(bool energy = false) {
|
||||
return 2 * ImGui::GetStyle().WindowPadding.y + ImGui::GetFrameHeight() +
|
||||
@@ -1197,6 +1209,16 @@ void end_hud_body() {
|
||||
}
|
||||
// The heading stays outside the scrollable body. Only this handle moves a panel.
|
||||
void panel_heading(const char* title, bool& minimized, HudPanelPlacement& placement) {
|
||||
// Begin applies native edge/corner resizing after the requested layout. Retain only
|
||||
// deliberate edits, so untouched cards still follow the viewport's default layout.
|
||||
const auto size = ImGui::GetWindowSize();
|
||||
const auto resized_position = ImGui::GetWindowPos();
|
||||
if (!minimized && (std::abs(size.x - placement.requested_size.first) > 0.5F ||
|
||||
std::abs(size.y - placement.requested_size.second) > 0.5F)) {
|
||||
placement.size = {size.x / px(1), size.y / px(1)};
|
||||
const auto display = ImGui::GetIO().DisplaySize;
|
||||
placement.anchor = {resized_position.x / display.x, resized_position.y / display.y};
|
||||
}
|
||||
ImGui::PushID(title);
|
||||
const float right = ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x;
|
||||
ImGui::AlignTextToFramePadding();
|
||||
@@ -1221,9 +1243,12 @@ void panel_heading(const char* title, bool& minimized, HudPanelPlacement& placem
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll);
|
||||
ImGui::SetTooltip("Drag to place %s. Double-click to reset its position.", title);
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||
ImGui::SetTooltip("Drag to place %s; drag an edge to resize. Double-click to reset.",
|
||||
title);
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
||||
placement.anchor.reset();
|
||||
placement.size.reset();
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SetCursorPosX(right - ImGui::CalcTextSize(" + ").x -
|
||||
@@ -1286,9 +1311,10 @@ void hud_vitals(const PanelView& v, FormBuffers& form, bool compact) {
|
||||
place_hud_panel(form.vitals_placement,
|
||||
compact ? ImVec2{px(12), px(64)}
|
||||
: ImVec2{clearance, io.DisplaySize.y - px(16) - height},
|
||||
{width, height});
|
||||
{width, height}, form.vitals_minimized);
|
||||
ImGui::Begin("Vitals", nullptr,
|
||||
hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||
(hud_flags & ~ImGuiWindowFlags_NoResize) | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoScrollbar);
|
||||
panel_heading("Your cell", form.vitals_minimized, form.vitals_placement);
|
||||
if (form.vitals_minimized) {
|
||||
if (d)
|
||||
@@ -1323,7 +1349,9 @@ void hud_vitals(const PanelView& v, FormBuffers& form, bool compact) {
|
||||
ImGui::SetTooltip("Last second: +%s collected, -%s into growth.%s",
|
||||
energy_text(flows.collected[0]).c_str(),
|
||||
energy_text(flows.into_growth[0]).c_str(),
|
||||
d->growth_limit == 1 ? "\nEnergy is holding your growth back." : "");
|
||||
d->growth_limit == 1
|
||||
? "\nEnergy availability or the survival buffer is limiting growth."
|
||||
: "");
|
||||
}
|
||||
if (const auto& change = play->energy_change(); change && change->falling)
|
||||
disabled_wrapped("Energy is falling: feeding may not cover upkeep and movement.");
|
||||
@@ -1520,13 +1548,14 @@ void hud_notes(const PanelView& v, FormBuffers& form, PanelActions& a, bool comp
|
||||
return;
|
||||
const auto& io = ImGui::GetIO();
|
||||
const float clearance = eyepiece_clearance();
|
||||
place_hud_panel(
|
||||
form.notes_placement, {clearance, px(64)},
|
||||
{px(260), form.notes_minimized
|
||||
? collapsed_height()
|
||||
: std::min(px(260), std::max(px(120), io.DisplaySize.y * 0.41F))});
|
||||
place_hud_panel(form.notes_placement, {clearance, px(64)},
|
||||
{px(260), form.notes_minimized
|
||||
? collapsed_height()
|
||||
: std::min(px(260), std::max(px(120), io.DisplaySize.y * 0.41F))},
|
||||
form.notes_minimized);
|
||||
ImGui::Begin("Field notes", nullptr,
|
||||
hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||
(hud_flags & ~ImGuiWindowFlags_NoResize) | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoScrollbar);
|
||||
panel_heading("Field notes", form.notes_minimized, form.notes_placement);
|
||||
if (form.notes_minimized) {
|
||||
ImGui::End();
|
||||
@@ -1974,9 +2003,11 @@ void hud_map(const PanelView& v, FormBuffers& form, bool compact) {
|
||||
{io.DisplaySize.x - (compact ? px(12) : eyepiece_clearance()) - width, px(126)},
|
||||
{width, form.map_minimized ? collapsed_height()
|
||||
: std::min(px(compact ? 192.0F : 300.0F),
|
||||
io.DisplaySize.y - px(200))});
|
||||
io.DisplaySize.y - px(200))},
|
||||
form.map_minimized);
|
||||
ImGui::Begin("Nearby", nullptr,
|
||||
hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||
(hud_flags & ~ImGuiWindowFlags_NoResize) | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoScrollbar);
|
||||
panel_heading("Nearby", form.map_minimized, form.map_placement);
|
||||
if (form.map_minimized) {
|
||||
ImGui::End();
|
||||
|
||||
@@ -84,7 +84,10 @@ inline constexpr const char* notice_window_prefix = "##notice";
|
||||
// HUD positions are client-session preferences in normalized viewport coordinates.
|
||||
struct HudPanelPlacement {
|
||||
std::optional<std::pair<float, float>> anchor;
|
||||
// Expanded size in unscaled UI units; collapse never overwrites it.
|
||||
std::optional<std::pair<float, float>> size;
|
||||
std::pair<float, float> drag_origin{};
|
||||
std::pair<float, float> requested_size{};
|
||||
};
|
||||
// Connect form fields and presentation preferences; never persisted.
|
||||
struct FormBuffers {
|
||||
|
||||
Reference in New Issue
Block a user