Add M9.8d rebindable engineering controls
SDL-free action/HID-key bindings with conflict validation, a staging editor and a versioned all-or-nothing controls file (ADR-0085). The adapter maps keys through the bindings, releases and drains on rebinding, and captures the chosen key ahead of the toolkit and world. The client adds a Controls panel, key hints, startup loading with a bounded rejection notice, and --controls/--show-controls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -138,10 +138,87 @@ void notices() {
|
||||
const auto* more = ImGui::FindWindowByName("##evicted");
|
||||
CHECK(more != nullptr && more->Active && more->Pos.y >= 0);
|
||||
}
|
||||
|
||||
// M9.8d controls panel: fits the viewport, a slot button requests key capture for that
|
||||
// slot without a world click, and the chosen key reaches neither toolkit nor world.
|
||||
void controls_panel() {
|
||||
const std::array<render::Rectangle, 1> boxes{{{0, 0, 32, 32, {40, 40, 40, 255}}}};
|
||||
auto frame = render::Frame::create(boxes);
|
||||
CHECK(frame);
|
||||
auto opened = Application::open({960, 640, false, "software"});
|
||||
CHECK(opened);
|
||||
auto app = std::move(*opened);
|
||||
const auto id = SDL_GetWindowID(window());
|
||||
SDL_Event focus{};
|
||||
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
|
||||
focus.window.windowID = id;
|
||||
CHECK(SDL_PushEvent(&focus) && app->poll_events());
|
||||
UiState ui;
|
||||
EnvironmentLayer environment;
|
||||
OrganismLayer organisms;
|
||||
Selection selection;
|
||||
Launcher launcher;
|
||||
FormBuffers form;
|
||||
render::EnvironmentDisplay display;
|
||||
BindingEditor editor{app->bindings()};
|
||||
PanelView view;
|
||||
view.mode = Mode::fixture;
|
||||
view.launcher = &launcher;
|
||||
view.environment = &environment;
|
||||
view.organisms = &organisms;
|
||||
view.selection = &selection;
|
||||
view.ui = &ui;
|
||||
view.bindings = &app->bindings();
|
||||
view.controls = &editor;
|
||||
PanelActions last;
|
||||
app->set_overlay([&] {
|
||||
const auto a = draw_panels(view, form, display);
|
||||
if (a.capture_key)
|
||||
last.capture_key = a.capture_key;
|
||||
last.apply_controls = last.apply_controls || a.apply_controls;
|
||||
});
|
||||
app->set_ui_capture(true); // As the host does while the panel is open.
|
||||
for (int i = 0; i < 2; ++i)
|
||||
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
|
||||
const auto* w = ImGui::FindWindowByName("Controls");
|
||||
CHECK(w != nullptr && w->Active);
|
||||
const auto& style = ImGui::GetStyle();
|
||||
CHECK(w->ContentSize.x <= w->Size.x - (2 * style.WindowPadding.x) + 0.5F);
|
||||
CHECK(w->Pos.x >= 0 && w->Pos.y >= 0 && w->Pos.x + w->Size.x <= 960 &&
|
||||
w->Pos.y + w->Size.y <= 640);
|
||||
// Probe down the primary column until a slot button answers: the first row is
|
||||
// Move left. Every probe is one batch (move, press, release).
|
||||
const float x =
|
||||
w->Pos.x + w->Size.x - style.WindowPadding.x - 150 - (2 * style.CellPadding.x) - 50;
|
||||
for (float y = w->Pos.y + 20; y < w->Pos.y + w->Size.y && !last.capture_key; y += 4) {
|
||||
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
|
||||
CHECK(app->poll_events() && !app->take_navigation().click);
|
||||
for (int i = 0; i < 3 && !last.capture_key; ++i)
|
||||
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
|
||||
}
|
||||
CHECK(last.capture_key == ControlSlot{Action::move_left, false} && !last.apply_controls);
|
||||
// The host arms capture; the chosen key is consumed before the toolkit.
|
||||
view.capturing = last.capture_key;
|
||||
app->begin_key_capture();
|
||||
SDL_Event key{};
|
||||
key.type = SDL_EVENT_KEY_DOWN;
|
||||
key.key.windowID = id;
|
||||
key.key.scancode = SDL_SCANCODE_J;
|
||||
CHECK(SDL_PushEvent(&key) && app->poll_events());
|
||||
CHECK(app->take_captured_key() == KeyCode{SDL_SCANCODE_J});
|
||||
CHECK(editor.assign(Action::move_left, false, SDL_SCANCODE_J));
|
||||
view.capturing.reset();
|
||||
CHECK(app->present(*frame) == Step::rendered && !ImGui::IsKeyDown(ImGuiKey_J));
|
||||
CHECK(editor.apply() && editor.apply()->action(SDL_SCANCODE_J) == Action::move_left);
|
||||
CHECK(!app->take_navigation().click);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
notices();
|
||||
controls_panel();
|
||||
std::puts("client panel tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user