Toolkit-independent launcher, selection, label and outcome-log models with bounded inputs and fixed error text; Dear ImGui overlay in the native adapter with toolkit-first event routing and capture; engineering panels for fixture vs dev region, legend, inspector, session outcomes, notices and dialog. Additive SessionClient::unreachable_attempts() bounds unreachable connects. Docs, CI targets and validation evidence updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
359 lines
16 KiB
C++
359 lines
16 KiB
C++
#include "panels.hpp"
|
|
#include "evo/client/labels.hpp"
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
#include <imgui.h>
|
|
#include <string>
|
|
|
|
namespace evo::client_app {
|
|
namespace {
|
|
using client::LaunchPhase;
|
|
ImVec4 color(render::Color c) {
|
|
return {static_cast<float>(c.red) / 255.0F, static_cast<float>(c.green) / 255.0F,
|
|
static_cast<float>(c.blue) / 255.0F, static_cast<float>(c.alpha) / 255.0F};
|
|
}
|
|
void copy(std::array<char, client::max_field_bytes>& 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<char, client::max_field_bytes>& 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();
|
|
}
|
|
// 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<const char*, world::field_count + 1> 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.");
|
|
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;
|
|
} 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::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<int>(world::field_count)
|
|
: static_cast<int>(display.field);
|
|
if (ImGui::Combo("Layer", ¤t, layer_names.data(), static_cast<int>(layer_names.size()))) {
|
|
display = current == static_cast<int>(world::field_count)
|
|
? render::EnvironmentDisplay{render::EnvironmentDisplay::Mode::moisture}
|
|
: render::EnvironmentDisplay{render::EnvironmentDisplay::Mode::field,
|
|
static_cast<world::Field>(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);
|
|
disabled_wrapped("Click to select. Arrows pan, wheel zooms, WASD moves.");
|
|
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<world::Field>(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();
|
|
}
|
|
|
|
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<unsigned long long>(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<unsigned long long>(it->tick),
|
|
static_cast<unsigned long long>(it->commit_sequence));
|
|
else if (it->state == client::OutcomeState::rejected)
|
|
ImGui::Text("status %u", static_cast<unsigned>(it->detail));
|
|
}
|
|
ImGui::EndTable();
|
|
}
|
|
ImGui::End();
|
|
}
|
|
|
|
void notices(const PanelView& v, PanelActions& a) {
|
|
const auto& io = ImGui::GetIO();
|
|
float y = io.DisplaySize.y - 8;
|
|
for (const auto& n : v.ui->notices()) {
|
|
ImGui::SetNextWindowPos({io.DisplaySize.x - 8, y}, ImGuiCond_Always, {1, 1});
|
|
ImGui::SetNextWindowSize({320, 0}, ImGuiCond_Always);
|
|
const std::string id = "##notice" + std::to_string(n.id);
|
|
ImGui::Begin(id.c_str(), nullptr,
|
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
|
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing);
|
|
ImGui::TextColored(n.level == client::NoticeLevel::error ? red
|
|
: n.level == client::NoticeLevel::warning ? amber
|
|
: green,
|
|
"%s", n.text.c_str());
|
|
ImGui::SameLine();
|
|
if (ImGui::SmallButton(("x" + id).c_str()))
|
|
a.dismiss_notice = n.id;
|
|
y -= ImGui::GetWindowHeight() + 4;
|
|
ImGui::End();
|
|
}
|
|
if (v.ui->evicted_notices() > 0) {
|
|
ImGui::SetNextWindowPos({io.DisplaySize.x - 8, y}, ImGuiCond_Always, {1, 1});
|
|
ImGui::Begin("##evicted", nullptr,
|
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize);
|
|
ImGui::TextDisabled("%llu older notices discarded",
|
|
static_cast<unsigned long long>(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);
|
|
}
|
|
notices(view, actions);
|
|
dialog(view, actions);
|
|
return actions;
|
|
}
|
|
} // namespace evo::client_app
|