-
Notifications
You must be signed in to change notification settings - Fork 17
Additional Side Pane
Adding an extra pane to those down the side of your game is very easy. However, creating content for it does require some HTML and CSS.
You can use this pane for anything you want; in this instance we will use it to add a spell book - the user can click on a spell to cast it.
We set it up in settings.setup. If you already have a settings.setup function, you need to add the lines inside the function below to your existing function.
settings.setup = function() {
player.skillsLearnt = ["Double attack", "Fireball"]
createAdditionalPane(1, "Spells", 'spells-known', function() {
let html = ''
for (const name of player.skillsLearnt) {
html += '<p class="item" onclick="runCmd(\'cast ' + name + '\')">' + name + '</p><br/>'
}
return html
})QuestJS expects spells the player can cast to be listed in player.skillsLearnt, and the first line in the function just sets up two so we can test it in action.
The most important line here is the createAdditionalPane function, which creates the new pane. This needs four parameters.
The first parameter is a number, and determines where the pane will appear. A zero would put it right at the top, a one, as in this case, just below the compass, etc. The second is the title the user will see at the top of the pane. The third is the ID of the HTML element. This has to be unique, start with a letter, and composed only of letters, numbers, hyphens and underscores.
The fourth is a function that will return an HTML string to go into the pane. It is a function to allow it to change dynamically through the game - the function will be called after each turn. If the player learns a new spell, it will therefore appear on the list.
In this instance, it will go through each spell in the list and create an entry for it. The HTML will look like this:
<p class="item" onclick="runCmd('cast Fireball')">Fireball</p><br/>This is a p for paragraph element, followed by a line break (<br/>). The p element is given the class "item" so it matches the style of the items inb the inventory. It is also given an "onclick" attribute that contains JavaScript that will run when the element is clicked. This simply calls the runCmd function passing the relevant command.
What if you want to have panes on both sides? You might want to do this if there are likely to be a lot of items and a large status pane, and are worried it will not fit, but be aware that it can look more cluttered.
We will be disabling the responsive feature; this hides the side pane when the screen is narrow. If the panes are so important you need both sides, I assume you do not want them to disappear - and it makes it easier to do. This may impact playability on mobile.
settings.panesCollapseAt = 0
settings.mapAndImageCollapseAt = 0The rest of the code needs to go in the setting.setup and settings.customUI functions. You may already have code in either of these; if so you will need to combine it with the new code. You can only have one of each of these functions in your game.
The bit in settings.customUI creates the second side pane on the right, using existing CSS classes. This example also moves the status pane to the right.
settings.customUI = function() {
// create the side pane
const div = document.createElement('div')
div.id = 'right-pane'
div.className = 'side-panes side-panes-right'
document.body.appendChild(div)
// Move the second pane from the left to the right
const divs = document.body.querySelectorAll('.pane-div')
div.appendChild(divs[1])
}We also need some code is settings.setup. The issue here is timing. The settings.setup is run late in the setting up process, once evertything is in place, so it is here we set the margins, after the elements themselves have been created.
settings.setup = function() {
const main = document.body.querySelector('#main')
main.style.marginRight = '190px'
const inner = document.body.querySelector('#inner')
inner.style.marginLeft = 'auto'
inner.style.marginRight = 'auto'
}So we started by creating a new pane on the left for spells. What if we want that on the right sde instead? We need to modify settings.customUI.
settings.customUI = function() {
const div = document.createElement('div')
div.id = 'right-pane'
div.className = 'side-panes side-panes-right'
let s = '<div id="right-status" class="pane-div">'
s += '<h4 clas="center">'
s += '<table align="center">'
s += '<tr><td><b>Health</b></td></tr>'
s += '<tr><td style="border: thin solid black;background:white;text-align:left;\"><span id="hits-indicator" style="background-color:green;padding-right:100px;"></span></td></tr>'
s += '</table>'
s += '</div>'
div.innerHTML = s
document.body.appendChild(div)
const divs = document.body.querySelectorAll('.pane-div')
//div.appendChild(divs[0])
div.appendChild(divs[1])
}Tutorial
- First steps
- Rooms and Exits
- Items
- Templates
- Items and rooms again
- More items
- Locks
- Commands
- Complex mechanisms
- Uploading
QuestJS Basics
- General
- Settings
- Attributes for items
- Attributes for rooms
- Attributes for exits
- Naming Items and Rooms
- Restrictions, Messages and Reactions
- Creating objects on the fly
- String Functions
- Random Functions
- Array/List Functions
- The
respondfunction - Other Functions
The Text Processor
Commands
- Introduction
- Basic commands (from the tutorial)
- Complex commands
- Example of creating a command (implementing SHOOT GUN AT HENRY)
- More on commands
- Shortcut for commands
- Modifying existing commands
- Custom parser types
- Note on command results
- Meta-Commands
- Neutral language (including alternatives to "you")
- The parser
- Command matching
- Vari-verbs (for verbs that are almost synonyms)
Templates for Items
- Introduction
- Takeable
- Openable
- Container and surface
- Locks and keys
- Wearable
- Furniture
- Button and Switch
- Readable
- Edible
- Vessel (handling liquids)
- Components
- Countable
- Consultable
- Rope
- Construction
- Backscene (walls, etc.)
- Merchandise (including how to create a shop)
- Shiftable (can be pushed from one room to another)
See also:
- Custom templates (and alternatives)
Handing NPCs
- Introduction
- Attributes
- Allowing the player to give commands
- Conversations
- Simple TALK TO
- SAY
- ASK and TELL
- Dynamic conversations with TALK TO
- TALK and DISCUSS
- Following an agenda
- Reactions
- Giving
- Followers
- Visibility
- Changing the player point-of-view
The User Experience (UI)
The main screen
- Basics
- Printing Text Functions
- Special Text Effects
- Output effects (including pausing)
- Hyperlinks
- User Input
The Side Panes
Multi-media (sounds, images, maps, etc.)
- Images
- Sounds
- Youtube Video (Contribution by KV)
- Adding a map
- Node-based maps
- Image-based maps
- Hex maps
- Adding a playing board
- Roulette!... in a grid
Dialogue boxes
- Character Creation
- Other example dialogs [See also "User Input"]
Other Elements
- Toolbar (status bar across the top)
- Custom UI Elements
Role-playing Games
- Introduction
- Getting started
- Items
- Characters (and Monsters!)
- Spawning Monsters and Items)
- Systema Naturae
- Who, When and How NPCs Attack
- Attributes for characters
- Attacking and guarding
- Communicating monsters
- Skills and Spells
- Limiting Magic
- Effects
- The Attack Object
- [Extra utility functions](https://github.com/ThePix/QuestJS/wiki/RPG-Library-%E2%80%90-Extra Functions)
- Randomly Generated Dungeon
- Quests for Quest
- User Interface
Web Basics
- HTML (the basic elements of a web page)
- CSS (how to style web pages)
- SVG (scalable vector graphics)
- Colours
- JavaScript
- Regular Expressions
How-to
Time
- Events (and Turnscripts)
- Date and Time (including custom calendars)
- Timed Events (i.e., real time, not game time)
Items
- Phone a Friend
- Using the USE verb
- Display Verbs
- Change Listeners
- Ensembles (grouping items)
- How to spit
Locations
- Large, open areas
- Region,s with sky, walls, etc.
- Dynamic Room Descriptions
- Transit system (lifts/elevators, buses, trains, simple vehicles)
- Rooms split into multiple locations
- Create rooms on the fly
- Handling weather
Exits
- Alternative Directions (eg, port and starboard)
- Destinations, Not Directions
Meta
- Customise Help
- Provide hints
- Include Achievements
- Add comments to your code
-
End The Game (
io.finish)
Meta: About The Whole Game
- Translate from Quest 5
- Authoring Several Games at Once
- Chaining Several Games Together
- Competition Entry
- Walk-throughs
- Unit testing
- Debugging (trouble-shooting)
Releasing Your Game
Reference
- The Language File
- List of settings
- Scope
- The Output Queue
- Security
- Implementation notes (initialisation order, data structures)
- Files
- Code guidelines
- Save/load
- UNDO
- The editor
- The Cloak of Darkness
- Versions
- Quest 6 or QuestJS
- The other Folders
- Choose your own adventure