RPGUI Documentation
repository·master·Indexed 21 days ago
https://github.com/ronenness/rpguiA lightweight, CSS-driven framework for building old-school RPG-style user interfaces for web games. RPGUI allows developers to create game GUIs using standard HTML and predefined CSS classes for containers, sliders, progress bars, and 8-bit style aesthetics without external dependencies. Version 1.0.3 includes helper functions for dynamic element creation and value manipulation via the RPGUI object.
What's inside RPGUI
- RPGUI is a lightweight framework designed for creating old-school RPG-style graphical user interfaces (GUIs) for web-based games. Instead of writing complex JavaScript logic for UI rendering, you use standard HTML elements and apply specific RPGUI CSS classes. The framework handles the styling, layout, and specialized RPG aesthetics automatically.
Key features of RPGUI
masterRPGUI provides a comprehensive CSS-driven system for game interfaces, including:
- Containers: Various frame types for grouping UI elements.
- Interactivity: Dragging functionality, styled buttons, checkboxes, radio buttons, and sliders/progress bars.
- Selection Widgets: Sophisticated dropdowns (based on
<select>) and listboxes. - Aesthetics: 8-bit style customized cursors and a collection of built-in RPG icons.
- Zero Dependencies: Works out of the box with no external library requirements.
Initialize RPGUI with rpgui-content
masterAll RPGUI-related elements must be contained within a
divthat has therpgui-contentclass. This class sets the global RPGUI rules, including font styles and cursor behaviors. Elements outside this container will not receive RPGUI styling.<div class="rpgui-content"> <!-- All RPGUI elements must go here --> </div><div class="rpgui-content"> <!-- rpgui goes here --> </div>Use RPGUI dropdowns and lists
masterBoth dropdowns and lists are created using
<select>elements with<option>tags.- Dropdowns: Add the
rpgui-dropdownclass to the<select>tag. - Lists: Add the
rpgui-listclass to the<select>tag (use thesizeattribute to define the number of visible rows).
Important: Once the page is loaded and the RPGUI elements are generated, you cannot add new
<option>elements to them dynamically via standard DOM manipulation.<!-- Dropdown --> <select class="rpgui-dropdown"> <option value="option1">option1</option> </select> <!-- List --> <select class="rpgui-list" size="5"> <option value="option1">option1</option> </select>- Dropdowns: Add the
How to theme RPGUI
masterThe easiest way to customize the look of RPGUI is to replace the existing images in the
dist/img/folder. The filenames are descriptive and correspond to the UI elements they represent.Note that RPGUI is not designed as a highly flexible library for deep structural changes; to modify the CSS rules or JavaScript logic, you must edit the source files directly.
Configure RPGUI for Angular
masterIf you are using Angular, you must include the RPGUI CSS in your
angular.jsonassets and styles arrays to ensure the styles are loaded correctly."assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.css", "dist/rpgui.css" ], "scripts": []Use RPGUI buttons, checkboxes, and radio buttons
masterButtons
Create a styled button by placing a
<p>tag inside a<button>and adding therpgui-buttonclass. Use thegoldenclass for a fancier version.<button class="rpgui-button" type="button"><p>Click me!</p></button>Checkboxes and Radio Buttons
Both require an
<input>tag and a following<label>tag to function correctly. The RPGUI implementation hides the actual input and styles the label based on the input state.- Checkbox:
<input class="rpgui-checkbox" type="checkbox"><label>Label text</label> - Radio:
<input class="rpgui-radio" type="radio" value="val"><label>Label text</label>
You can use the
goldenclass on either for a fancier style.<button class="rpgui-button"><p>Click me!</p></button> <input class="rpgui-checkbox" type="checkbox"><label>Checkbox label</label> <input class="rpgui-radio" type="radio" value="v"><label>Radio label</label>- Checkbox:
Build RPGUI from source
masterTo build the distribution files, you must first install the npm dependencies and then run the gulp build task.
On Unix-like systems (macOS/Linux):
- Install dependencies:
npm install - Build:
gulp dist
On Windows:
- Install dependencies:
npm install - Build:
node_modules\.bin\gulp dist
npm install gulp dist- Install dependencies:
Create containers and frames
masterA
rpgui-containeracts as a window or form to hold GUI elements. You should place all your elements inside these containers. RPGUI provides several built-in frame styles:framed: Default grey frame with orange borders.framed-golden: Golden frame with a brown background.framed-golden-2: Brighter golden frame with smoother borders.framed-grey: A grey frame, ideal for nesting as an internal container within a largerframedcontainer.
To make a container movable like a window, add the
rpgui-draggableclass. Note that dragging must be initiated by grabbing the container div itself, not the elements inside it.<div class="rpgui-content"> <!-- default frame --> <div class="rpgui-container framed"></div> <!-- golden frame --> <div class="rpgui-container framed-golden"></div> <!-- draggable container --> <div class="rpgui-container rpgui-draggable"></div> </div>Install and include RPGUI in your project
masterTo use RPGUI, you must include the CSS and JavaScript files from the
dist/directory in your HTML<head>.Important: You must also ensure the
imgdirectory from thedist/folder is included in your project structure, as the framework relies on these image resources for its styling and icons.<link href="dist/rpgui.css" rel="stylesheet" type="text/css" > <script src="dist/rpgui.js"></script>Use RPGUI sliders and progress bars
masterRPGUI Sliders
Create a styled range input by using an
<input type="range">with therpgui-sliderclass. You can also use thegoldenclass for a fancier style.<input class="rpgui-slider" type="range" min="0" max="10" value="8"> <input class="rpgui-slider golden" type="range" min="0" max="10" value="8">RPGUI Progress Bars
Progress bars (useful for health/mana bars) are created using a
divwith therpgui-progressclass. They default to purple, but you can usered,green, orblueclasses.Note: Progress bars use a value range from
0.0to1.0. UseRPGUI.set_value()to update them.<div id="red-bar" class="rpgui-progress red"></div> <script> // Set the bar to 50% full RPGUI.set_value(document.getElementById("red-bar"), 0.5); </script><input class="rpgui-slider" type="range" min="0" max="10" value="8"> <div class="rpgui-progress red"></div>Use RPGUI helper functions
masterWhile most RPGUI elements are styled via CSS classes on standard HTML elements, the
RPGUIobject provides helper functions for dynamic creation and reliable value manipulation.RPGUI.create(element, type): Dynamically transforms a base HTML element into an RPGUI element after the page has loaded.RPGUI.set_value(element, value): The most reliable way to set an element's value. It handles different input types (e.g.,.checkedfor checkboxes vs.valuefor text) and manually triggers theonchangeevent.RPGUI.get_value(element): Retrieves the current value of an RPGUI element.
// Create a dropdown from a <select> tag var select = document.getElementById("some_id"); RPGUI.create(select, "dropdown"); // Set a value reliably (triggers onchange) RPGUI.set_value(select, "option1"); // Get a value var val = RPGUI.get_value(select);