3.3.19 • Published 10 months ago

contro-ui v3.3.19

Weekly downloads
30
License
GNU GPLv3
Repository
github
Last release
10 months ago

contro-ui

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
      //- ...

API

Experimental UI library!

start(Object options)

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)

async change(String state, String subState, Object options)

Switch to another state: menu or cui context.

boolean options.keepBackground
keep showing the previous ui, by default it's hidden.

async onChange(String state, String subState)

Override this function to do something when cui changes to a different state.

async afterChange(String state, String subState)

Override this function to do something after cui changes to a different state.

async doAction(String act)

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

async onAction(String act)

Override this function to do something after a keyboard key or controller button press.

async doHeldAction(String act, Number timeHeld)

Do the specified held action.

async onHeldAction(String act, Number timeHeld)

Override this function to do something after a keyboard key or controller button is held.

makeCursor(jQuery \$cursor, String state)

Make \$cursor the current cursor, state is the current ui by default.

beforeMove(jQuery \$cursor, String state)

Override this function to do something before the cursor changes.

afterMove(jQuery \$cursor, String state)

Override this function to do something after the cursor changes.

bind(String|Array keys, String act)

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-_");

click(jQuery \$elem, String act)

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.

addView(String state, Object options)

Add a menu or other cui context. Will add click listeners for any .cui elems within the view.

editView(String state, Object options)

Replace view options with the options object given.

async alert(String msg, String title, String stateAfterAlert)

msg can be text or html, if stateAfterAlert is provided cui will change to that state after the user presses the "okay" button.

async error(String msg, var code, String stateAfterError)

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");
});

async resize(Boolean adjust, String state)

Adjust ui components (or not) on resize.

async onResize(Boolean adjust)

Override this method to adjust ui components on resize.

passthrough(Object contro)

Override this function to access the contro object directly, which has the parsed controller button, stick, and trigger info.

3.3.19

10 months ago

3.3.18

1 year ago

3.3.17

2 years ago

3.3.13

2 years ago

3.3.14

2 years ago

3.3.15

2 years ago

3.3.16

2 years ago

3.3.10

3 years ago

3.3.11

3 years ago

3.3.8

3 years ago

3.3.7

3 years ago

3.3.5

3 years ago

3.3.4

3 years ago

3.3.3

3 years ago

3.3.2

3 years ago

3.2.1

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.41

4 years ago

2.0.40

4 years ago

2.0.39

4 years ago

2.0.38

4 years ago

2.0.37

4 years ago

2.0.36

4 years ago

2.0.35

4 years ago

2.0.34

4 years ago

2.0.33

4 years ago

2.0.32

4 years ago

2.0.31

4 years ago

2.0.29

4 years ago

2.0.30

4 years ago

2.0.28

4 years ago

2.0.27

4 years ago

2.0.26

4 years ago

2.0.25

4 years ago

2.0.24

5 years ago

2.0.23

5 years ago

2.0.22

5 years ago

2.0.21

5 years ago

2.0.20

5 years ago

2.0.19

5 years ago

2.0.18

5 years ago

2.0.17

5 years ago

2.0.16

5 years ago

2.0.15

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.9

5 years ago

2.0.10

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.8

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago