#include "panels.hpp" #include "evo/client/labels.hpp" #include #include #include #include namespace evo::client_app { namespace { using client::LaunchPhase; ImVec4 color(render::Color c) { return {static_cast(c.red) / 255.0F, static_cast(c.green) / 255.0F, static_cast(c.blue) / 255.0F, static_cast(c.alpha) / 255.0F}; } void copy(std::array& out, const std::string& in) { out.fill('\0'); std::memcpy(out.data(), in.data(), std::min(in.size(), out.size() - 1)); } std::string text(const std::array& in) { return {in.begin(), std::find(in.begin(), in.end(), '\0')}; } void row(const char* label, const std::string& value, const std::string& unit = {}) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TextUnformatted(label); ImGui::TableNextColumn(); ImGui::TextUnformatted(value.c_str()); ImGui::TableNextColumn(); ImGui::TextUnformatted(unit.c_str()); } void swatch(const char* id, render::Color c, const char* label) { ImGui::ColorButton(id, color(c), ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoAlpha, {14, 14}); ImGui::SameLine(); ImGui::TextUnformatted(label); } constexpr ImVec4 amber{0.94F, 0.67F, 0.16F, 1.0F}, red{0.95F, 0.35F, 0.35F, 1.0F}, green{0.35F, 0.80F, 0.60F, 1.0F}; ImVec4 freshness_color(client::Freshness f) { return f == client::Freshness::current ? green : f == client::Freshness::stale ? amber : red; } const char* outcome_name(client::OutcomeState s) { switch (s) { case client::OutcomeState::sent: return "sent (no reply yet)"; case client::OutcomeState::admitted: return "admitted (not yet durable)"; case client::OutcomeState::rejected: return "rejected"; case client::OutcomeState::durable: return "durable, no effect"; case client::OutcomeState::not_committed: return "not committed"; case client::OutcomeState::unknown: return "UNKNOWN (connection lost)"; } return "?"; } void disabled_wrapped(const char* text) { ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); ImGui::TextWrapped("%s", text); ImGui::PopStyleColor(); } std::string key_label(client::KeyCode key) { return key == client::no_key ? std::string{"-"} : std::string{client::key_name(key)}; } std::string controls_hint(const client::Bindings& b) { using client::Action; const auto k = [&](Action action) { return key_label(b.slot(action).primary); }; return "Click selects, wheel zooms. Move " + k(Action::move_up) + " " + k(Action::move_left) + " " + k(Action::move_down) + " " + k(Action::move_right) + "; pan " + k(Action::pan_up) + " " + k(Action::pan_left) + " " + k(Action::pan_down) + " " + k(Action::pan_right) + "; UI capture " + k(Action::toggle_capture) + "."; } // Fixed wording only (never echoes paths or file bytes); wraps inside the launcher. void error_text(client::LaunchError error) { ImGui::PushStyleColor(ImGuiCol_Text, red); ImGui::TextWrapped("%s", std::string{client::launch_error_text(error)}.c_str()); ImGui::PopStyleColor(); } constexpr std::array layer_names{ "Water", "Dissolved nitrogen", "Dissolved phosphorus", "Organic carbon", "Organic nitrogen", "Organic phosphorus", "Organic other", "Organic energy", "Incident energy", "Heat", "Moisture (saturation)"}; void launcher(const PanelView& v, FormBuffers& form, PanelActions& a) { const auto phase = v.launcher->phase(); const auto& io = ImGui::GetIO(); ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, io.DisplaySize.y * 0.5F}, ImGuiCond_Always, {0.5F, 0.5F}); ImGui::SetNextWindowSize({520, 0}, ImGuiCond_Always); ImGui::Begin("Aeternalis Evolution - engineering client", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); ImGui::TextWrapped("Choose a data source. Nothing here is a game or a player account."); if (ImGui::SmallButton("Controls...")) a.open_controls = true; ImGui::Separator(); if (ImGui::Button("Local fixture", {160, 0})) a.fixture = true; ImGui::SameLine(); ImGui::TextWrapped("In-memory stand-in: environment changes and static organisms. Not a " "server, not an ecosystem, not authoritative."); ImGui::Separator(); ImGui::TextUnformatted("Connect to a dev region"); ImGui::BeginDisabled(!v.remote_available || phase == LaunchPhase::connecting); ImGui::InputText("Endpoint (host:port)", form.endpoint.data(), form.endpoint.size()); ImGui::InputText("Server name", form.server_name.data(), form.server_name.size()); ImGui::InputText("Dev CA file", form.authority.data(), form.authority.size()); ImGui::InputText("Grant bundle file", form.grants.data(), form.grants.size()); const bool start = phase == LaunchPhase::choosing && ImGui::Button("Connect", {160, 0}); ImGui::EndDisabled(); if (start) a.connect = true; if (!v.remote_available) ImGui::TextColored(amber, "Remote mode needs a build with EVO_BUILD_NETWORK."); if (v.form_error) error_text(*v.form_error); if (phase == LaunchPhase::connecting) { ImGui::TextColored(amber, "Connecting (TLS handshake and grant check)..."); if (ImGui::Button("Cancel", {120, 0})) a.cancel = true; } if (phase == LaunchPhase::failed) { error_text(v.launcher->error()); if (ImGui::Button("Retry", {120, 0})) a.retry = true; ImGui::SameLine(); if (ImGui::Button("Cancel", {120, 0})) a.cancel = true; } ImGui::TextDisabled("Files are read when you connect; nothing is saved."); ImGui::End(); } void banner(const PanelView& v, PanelActions& a) { const auto& io = ImGui::GetIO(); ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, 4}, ImGuiCond_Always, {0.5F, 0}); ImGui::Begin("##mode", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings); if (v.mode == Mode::fixture) { ImGui::TextColored(amber, "LOCAL FIXTURE - in-memory stand-in, not authoritative"); ImGui::SameLine(); if (ImGui::SmallButton("Launcher")) a.back = true; ImGui::SameLine(); if (ImGui::SmallButton("Controls")) a.open_controls = true; } else { ImGui::TextColored(v.remote && v.remote->phase == "connected" ? green : amber, "DEV REGION - %s", v.remote ? v.remote->phase.c_str() : "?"); ImGui::SameLine(); if (ImGui::SmallButton("Disconnect")) a.ask_disconnect = true; ImGui::SameLine(); if (ImGui::SmallButton("Controls")) a.open_controls = true; } ImGui::End(); } void legend(const PanelView& v, render::EnvironmentDisplay& display) { ImGui::SetNextWindowPos({8, 40}, ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize({300, 0}, ImGuiCond_FirstUseEver); ImGui::Begin("Legend"); int current = display.mode == render::EnvironmentDisplay::Mode::moisture ? static_cast(world::field_count) : static_cast(display.field); if (ImGui::Combo("Layer", ¤t, layer_names.data(), static_cast(layer_names.size()))) { display = current == static_cast(world::field_count) ? render::EnvironmentDisplay{render::EnvironmentDisplay::Mode::moisture} : render::EnvironmentDisplay{render::EnvironmentDisplay::Mode::field, static_cast(current)}; } if (display.mode == render::EnvironmentDisplay::Mode::moisture) ImGui::TextWrapped("Water saturation, linear from 0 %% (low) to 100 %% (high)."); else ImGui::TextWrapped("%s", client::density_scale(display.field).c_str()); swatch("##low", render::ramp(0), "Present: low"); ImGui::SameLine(); swatch("##mid", render::ramp(0.5), "mid"); ImGui::SameLine(); swatch("##high", render::ramp(1), "high"); swatch("##zero", render::palette::present_zero, "Present zero (black)"); swatch("##missing", render::palette::missing_a, "Missing: checkerboard"); swatch("##notreq", render::palette::not_requested, "Not requested: hollow outline"); swatch("##undef", render::palette::undefined, "Undefined moisture (no capacity)"); swatch("##stale", render::palette::stale_outline, "Stale: dimmed, amber outlines"); ImGui::Separator(); const auto env = v.environment ? v.environment->freshness() : client::Freshness::none; const auto org = v.organisms ? v.organisms->freshness() : client::Freshness::none; ImGui::TextColored(freshness_color(env), "Environment: %s", std::string{client::freshness_name(env)}.c_str()); ImGui::TextColored(freshness_color(org), "Organisms: %s", std::string{client::freshness_name(org)}.c_str()); if (v.mode == Mode::remote && v.organisms && v.organisms->current() && v.organisms->current()->cells().empty()) ImGui::TextWrapped("No individual organisms: this region reports pooled inventories only."); if (v.mode == Mode::fixture) ImGui::TextWrapped("Fixture organisms are static presentation data built from genomes."); if (v.visible_organisms >= 0) ImGui::Text("Organisms drawn: %d", v.visible_organisms); if (v.bindings != nullptr) disabled_wrapped(controls_hint(*v.bindings).c_str()); ImGui::End(); } void inspector(const PanelView& v) { const auto& io = ImGui::GetIO(); ImGui::SetNextWindowPos({io.DisplaySize.x - 8, 40}, ImGuiCond_FirstUseEver, {1, 0}); ImGui::SetNextWindowSize({420, 0}, ImGuiCond_FirstUseEver); ImGui::Begin("Inspector"); const auto* env = v.environment ? v.environment->current() : nullptr; const auto* orgs = v.organisms ? v.organisms->current() : nullptr; const auto* organism = v.selection->organism(orgs); const auto* cell = v.selection->cell(env); if (organism == nullptr && cell == nullptr) { ImGui::TextWrapped("Click an organism or habitat cell to inspect it."); ImGui::End(); return; } const auto freshness = organism ? v.organisms->freshness() : v.environment->freshness(); if (freshness == client::Freshness::stale) ImGui::TextColored(amber, "STALE: values are from an older revision."); if (ImGui::BeginTable("rows", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) { for (const auto& r : organism ? client::organism_rows(*organism) : client::cell_rows(*cell)) row(r.label.c_str(), r.value, r.unit); ImGui::EndTable(); } if (cell != nullptr && ImGui::BeginTable("fields", 2, ImGuiTableFlags_RowBg)) { // Values wrap inside the column so missing/not-requested explanations stay readable. ImGui::TableSetupColumn("field", ImGuiTableColumnFlags_WidthFixed, 150); ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch); for (std::size_t k = 0; k < world::field_count; ++k) { const auto field = static_cast(k); const auto value = client::describe_field(*cell, field); ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TextUnformatted(std::string{client::field_name(field)}.c_str()); ImGui::TableNextColumn(); const bool tinted = value.kind == client::ValueKind::missing || value.kind == client::ValueKind::not_requested; if (tinted) ImGui::PushStyleColor(ImGuiCol_Text, value.kind == client::ValueKind::missing ? red : ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); ImGui::TextWrapped("%s", value.text.c_str()); if (tinted) ImGui::PopStyleColor(); } const auto moisture = client::describe_moisture(*cell); ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TextUnformatted("Moisture"); ImGui::TableNextColumn(); ImGui::TextWrapped("%s", moisture.text.c_str()); ImGui::EndTable(); } ImGui::End(); } // Rebinding: each slot button arms key capture for that slot; the panel holds UI // capture, so no key or click reaches the world while it is open (ADR-0085). void controls(const PanelView& v, PanelActions& a) { if (v.controls == nullptr) return; const auto& io = ImGui::GetIO(); ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, io.DisplaySize.y * 0.5F}, ImGuiCond_Always, {0.5F, 0.5F}); ImGui::SetNextWindowSize({std::min(460.0F, io.DisplaySize.x - 16), 0}, ImGuiCond_Always); ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings); disabled_wrapped("Keys are named by their US-layout position. Mouse click (select) and " "wheel (zoom) are fixed. Escape cancels a key capture."); if (ImGui::BeginTable("bindings", 3, ImGuiTableFlags_RowBg)) { ImGui::TableSetupColumn("Action", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("Primary", ImGuiTableColumnFlags_WidthFixed, 120); ImGui::TableSetupColumn("Secondary", ImGuiTableColumnFlags_WidthFixed, 150); ImGui::TableHeadersRow(); for (std::size_t k = 0; k < client::action_count; ++k) { const auto action = static_cast(k); const auto& slot = v.controls->draft()[k]; ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TextUnformatted(std::string{client::action_name(action)}.c_str()); for (const bool secondary : {false, true}) { ImGui::TableNextColumn(); const ControlSlot here{action, secondary}; const auto key = secondary ? slot.secondary : slot.primary; const std::string label = (v.capturing == here ? std::string{"Press a key"} : key_label(key)) + "##" + std::to_string(k) + (secondary ? "s" : "p"); ImGui::BeginDisabled(v.capturing.has_value()); if (ImGui::Button(label.c_str(), {100, 0})) a.capture_key = here; if (secondary && key != client::no_key) { ImGui::SameLine(); if (ImGui::SmallButton(("x##clear" + std::to_string(k)).c_str())) a.clear_secondary = action; } ImGui::EndDisabled(); } } ImGui::EndTable(); } if (v.capturing) { ImGui::TextColored(amber, "Press a key for %s (Escape cancels).", std::string{client::action_name(v.capturing->action)}.c_str()); if (ImGui::Button("Cancel capture", {140, 0})) a.cancel_capture = true; } if (v.controls_problem) { ImGui::PushStyleColor(ImGuiCol_Text, red); ImGui::TextWrapped("%s", client::describe(*v.controls_problem).c_str()); ImGui::PopStyleColor(); } ImGui::BeginDisabled(v.capturing.has_value()); if (ImGui::Button("Apply", {100, 0})) a.apply_controls = true; ImGui::SameLine(); if (ImGui::Button("Reset defaults", {130, 0})) a.reset_controls = true; ImGui::SameLine(); if (ImGui::Button("Cancel", {100, 0})) a.close_controls = true; ImGui::EndDisabled(); ImGui::End(); } void session(const PanelView& v) { if (!v.remote) return; const auto& io = ImGui::GetIO(); ImGui::SetNextWindowPos({8, io.DisplaySize.y - 8}, ImGuiCond_FirstUseEver, {0, 1}); ImGui::SetNextWindowSize({360, 0}, ImGuiCond_FirstUseEver); ImGui::Begin("Session"); const auto& s = *v.remote; if (ImGui::BeginTable("status", 3, ImGuiTableFlags_SizingFixedFit)) { row("Connection", s.phase); row("Session / epoch", std::to_string(s.session) + " / " + std::to_string(s.epoch)); row("Server tick", std::to_string(s.server_tick)); row("Durable watermark", std::to_string(s.commit_watermark)); row("Grants left", std::to_string(s.grants_left)); ImGui::EndTable(); } disabled_wrapped("Intentions (newest first; this is the record, toasts expire):"); if (v.outcomes && ImGui::BeginTable("outcomes", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) { const auto& entries = v.outcomes->entries(); int shown = 0; for (auto it = entries.rbegin(); it != entries.rend() && shown < 10; ++it, ++shown) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Text("#%llu", static_cast(it->sequence)); ImGui::TableNextColumn(); ImGui::TextUnformatted(outcome_name(it->state)); ImGui::TableNextColumn(); if (it->state == client::OutcomeState::durable) ImGui::Text("tick %llu, commit %llu", static_cast(it->tick), static_cast(it->commit_sequence)); else if (it->state == client::OutcomeState::rejected) ImGui::Text("status %u", static_cast(it->detail)); } ImGui::EndTable(); } ImGui::End(); } // Newest at the bottom right. Each notice wraps its text beside a reserved close // column, so the button is always visible; the stack stops at 60 % of the viewport // height and counts what it could not show (those still expire or can be dismissed // once space frees). Notices are not the outcome record (Session panel is). void notices(const PanelView& v, PanelActions& a) { const auto& io = ImGui::GetIO(); const float width = std::min(notice_width, io.DisplaySize.x - 16); const float top = io.DisplaySize.y * 0.4F; float y = io.DisplaySize.y - 8; const auto list = v.ui->notices(); std::size_t hidden = 0; for (auto it = list.rbegin(); it != list.rend(); ++it) { const auto& n = *it; if (y < top || width < 120) { ++hidden; continue; } ImGui::SetNextWindowPos({io.DisplaySize.x - 8, y}, ImGuiCond_Always, {1, 1}); ImGui::SetNextWindowSize({width, 0}, ImGuiCond_Always); const std::string id = notice_window_prefix + std::to_string(n.id); ImGui::Begin(id.c_str(), nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing); if (ImGui::BeginTable("notice", 2)) { ImGui::TableSetupColumn("text", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("close", ImGuiTableColumnFlags_WidthFixed, notice_close_width); ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::PushStyleColor(ImGuiCol_Text, n.level == client::NoticeLevel::error ? red : n.level == client::NoticeLevel::warning ? amber : green); ImGui::TextWrapped("%s", n.text.c_str()); ImGui::PopStyleColor(); ImGui::TableNextColumn(); if (ImGui::Button(("x" + id).c_str(), {notice_close_width, 0})) a.dismiss_notice = n.id; ImGui::EndTable(); } y -= ImGui::GetWindowHeight() + 4; ImGui::End(); } if (v.ui->evicted_notices() > 0 || hidden > 0) { ImGui::SetNextWindowPos({io.DisplaySize.x - 8, y}, ImGuiCond_Always, {1, 1}); ImGui::Begin("##evicted", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing); if (hidden > 0) ImGui::TextDisabled("%zu more notices (dismiss to show)", hidden); if (v.ui->evicted_notices() > 0) ImGui::TextDisabled("%llu older notices discarded", static_cast(v.ui->evicted_notices())); ImGui::End(); } } void dialog(const PanelView& v, PanelActions& a) { const auto& d = v.ui->dialog(); if (!d) return; const std::string id = d->title + "##dialog" + std::to_string(d->id); ImGui::OpenPopup(id.c_str()); if (ImGui::BeginPopupModal(id.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::TextWrapped("%s", d->body.c_str()); if (ImGui::Button("Confirm", {120, 0})) a.confirm_dialog = d->id; ImGui::SameLine(); if (ImGui::Button("Cancel", {120, 0})) a.cancel_dialog = d->id; ImGui::EndPopup(); } } } // namespace void FormBuffers::load(const client::ConnectForm& f) { copy(endpoint, f.endpoint); copy(server_name, f.server_name); copy(authority, f.authority_path); copy(grants, f.grants_path); } client::ConnectForm FormBuffers::form() const { return {text(endpoint), text(server_name), text(authority), text(grants)}; } PanelActions draw_panels(const PanelView& view, FormBuffers& form, render::EnvironmentDisplay& display) { PanelActions actions; if (view.mode == Mode::launcher) { launcher(view, form, actions); } else { banner(view, actions); legend(view, display); inspector(view); session(view); } controls(view, actions); notices(view, actions); dialog(view, actions); return actions; } } // namespace evo::client_app