This UI library is used by Nostlan to create a UI that can be interacted with via game controllers and/or mouse and keyboard. It requires jQuery and Mousetrap. Optionally you can install gca-js
as a peer dependency for Gamecube controller support.
global.cui = require("contro-ui");
cui.start();
doctype html
html
head
title Your App's Title
meta(charset='utf-8')
link(rel='stylesheet' type='text/css' href=node_modules + '/bootstrap/dist/css/bootstrap.min.css')
link(rel='stylesheet' type='text/css' href=node_modules + '/contro-ui/dist/css/contro-ui.css')
body
#nameOfMenu.menu.row-y
//- full width button
.cui.col(name='actionName0') button 0 label text
.row.row-x
//- three buttons in horizontal row
.cui.col(name='actionName1') button 1 label text
.cui.col(name='actionName2') button 2 label text
.cui.col(name='actionName3') button 3 label text
#otherMenu.menu.row-y
//- ...
Experimental UI library!
Required to initialize contro-ui, adds event listener for gamepad connections, adds click and hover event listeners to all .cui
elements.
boolean options.v
enable verbose logging
boolean options.haptic
enable haptic feedback (controller vibrations)
boolean options.gca
enable Gamecube Controller Adapter support (requires npm package gca-js)
Switch to another state: menu or cui context.
boolean options.keepBackground
keep showing the previous ui, by default it's hidden.
Override this function to do something when cui changes to a different state.
Override this function to do something after cui changes to a different state.
Do the specified action.
String act
the action, can be a controller or keyboard action
'a', 'b', 'x', 'y', 'l', 'r' controller face button actions
'up', 'down', 'left', 'right' dpad/leftStick directional movement actions
'back' change state back to the previous ui state
'doubleBack' go back two ui states
'quit' quit the app
Override this function to do something after a keyboard key or controller button press.
Do the specified held action.
Override this function to do something after a keyboard key or controller button is held.
Make $cursor the current cursor, state is the current ui by default.
Override this function to do something before the cursor changes.
Override this function to do something after the cursor changes.
Bind keyboard key(s) to a controller button or cui action.
For modifier keys you can use shift
, ctrl
, alt
, or meta
.
You can substitute option
for alt
and command
for meta
.
Other special keys are backspace
, tab
, enter
, return
, capslock
, esc
, escape
, space
, pageup
, pagedown
, end
, home
, left
, up
, right
, down
, ins
, del
, and plus
.
Any other key you should be able to reference by name like a
, /
, $
, *
, or =
.
For more info look at the Mousetrap documentation.
// example of binding keyboard keys
for (let char of "abcdefghijklmnopqrstuvwxyz1234567890") {
cui.bind(char, "char-" + char);
}
cui.bind("space", "char-_");
Bind mouse clicking on a jQuery DOM element to a controller button or cui action. Don't use on .cui elements! Use the "name" property to set the click action for .cui elements.
Add a menu or other cui context. Will add click listeners for any .cui elems within the view.
Replace view options with the options object given.
msg can be text or html, if stateAfterAlert is provided cui will change to that state after the user presses the "okay" button.
Error code can be a Number or String, calls the alert function internally.
// example that displays unexpected errors to users
// before quitting the app
const process = require("process");
process.on("uncaughtException", ror => {
console.error(ror);
cui.err(`<textarea rows=8>${ror.stack}</textarea>`, "App crashed!", "quit");
});
Adjust ui components (or not) on resize.
Override this method to adjust ui components on resize.
Override this function to access the contro object directly, which has the parsed controller button, stick, and trigger info.