Although CosPlay does not define an opinionated UI framework, several sprites and supporting classes are often used for constructing UI elements on the screen. These include:
Class | Description |
---|---|
CPLayoutSprite | This sprite allows to dynamically layout other sprites based on text layout specification. Layout specification defines how one sprite should be positioned in relation to some other sprite. |
CPDynamicSprite | Common super-class for all sprites that support dynamic positioning. This class is used by CPLayoutSprite sprite and is the base class for all built-in sprites that support dynamic positioning. |
CPLabelSprite | Simple dynamic sprite that can be used for textual labels. |
CPSpacerSprite | Simple dynamic sprite that has no rendering content and provides only its dimension. This sprite is often used in dynamic layout to provide dynamic spacing between UI elements. |
CPTitlePanelSprite | A dynamic sprite that provides rendering of the single-character border with optional title. Often used by dialogs, popup windows and other UI elements that require a visual border. |
CPListBoxSprite | A dynamic sprite that provides combobox-like single-element UI selector. |
CPTextInputSprite | A dynamic sprite that provides standard text input field UI element. |
CPSystemFont | A system 1-character height font that should be used for UI elements. |
CPSingletonSprite | A convenient sprite that allows to execute a given function only once per given lifecycle scope, i.e. the scope of the scene object, the scene itself or the entire game. |
The most effective way to see how these and other sprites can be used to create UI elements is to run and review the following examples that are pre-packaged with CosPlay:
Example | |
---|---|
# Will launch using terminal emulator. $ sbt "project cosplay; runMain org.cosplay.examples.fonts.CPFontsExample" # Will launch in the same terminal console. $ mvn -f modules/cosplay exec:java -P ex:fonts | |
# Will launch using terminal emulator. $ sbt "project cosplay; runMain org.cosplay.examples.textinput.CPTextInputExample" # Will launch in the same terminal console. $ mvn -f modules/cosplay exec:java -P ex:textinput | |
# Will launch using terminal emulator. $ sbt "project cosplay; runMain org.cosplay.examples.layout.CPLayoutExample" # Will launch in the same terminal console. $ mvn -f modules/cosplay exec:java -P ex:layout | |
# Will launch using terminal emulator. $ sbt "project cosplay; runMain org.cosplay.examples.dialog.CPDialogExample" # Will launch in the same terminal console. $ mvn -f modules/cosplay exec:java -P ex:dialog | |
# Will launch using terminal emulator. $ sbt "project cosplay; runMain org.cosplay.examples.listbox.CPListBoxExample" # Will launch in the same terminal console. $ mvn -f modules/cosplay exec:java -P ex:listbox |
SBT & Maven
CosPlay comes with support for both SBT and Maven builds. Running examples and built-in games via SBT will automatically use terminal emulator since both SBT and CosPlay use JLine library and SBT therefor uses Java process fork to launch the examples and games. If you want to run directly in the terminal console using pure text-mode - use Maven method instead.