-
Notifications
You must be signed in to change notification settings - Fork 18
Buttons, buttons, buttons
This is an alternative way of laying out the side pane. Whether it is better is a matter of person preference; it has the advantage that every option is immediately visible, but it does take up more space on the screen.
This is what is looks like.
There are broadly two things that need to be modified; the inventories and the compass. In both cases this is split between settings.js and code.js, depending on when things need to be done.
We need three things. The first is the normal array that sets up the inventories. There are two differences here. The first is that each entry has a "noContent" string that is displayed when that inventory is empty.
The second difference is the fourth inventory, which you will probably want to omit (just delete the whole line) but illustrates how you can add additional lists.
// For items
settings.inventoryPane = [
{name:'You are holding...', alt:'itemsHeld', test:settings.isHeldNotWorn, getLoc:function() { return game.player.name; }, noContent:'Nothing' },
{name:'You are wearing...', alt:'itemsWorn', test:settings.isWorn, getLoc:function() { return game.player.name; }, noContent:'Nothing' },
{name:'You can see...', alt:'itemsHere', test:settings.isHere, getLoc:function() { return game.player.loc; }, noContent:'Nothing' },
{name:'You are on the phone to...', alt:'onPhoneTo', test:function(item) { return item.name === player.onPhoneTo }, noContent:'No one' }
]
The second part is for the compass. We need to turn off he standard compass, and add our own (also discussed here).
// For directions
settings.compassPane = false
settings.setup = function() {
createPaneBox(0, "Go to", '', 'directions')
settings.updateCustomUI()
}
The bulk of the work is done in settings.updateCustomUI
which is a special function Quest will call each turn, and it is here that the new compass and inventories are populated.
settings.updateCustomUI = function() {
// For items
for (const el of document.querySelectorAll('.item-action')) {
el.style.display = 'block'
}
// For directions
const el = document.querySelector('#directions')
if (!el) return // not there yet
const exitList = currentLocation.getExits({excludeLocked:true})
let s = '<p class="item-class"><span class="item-name">You can go:</span>'
for (let ex of exitList) {
s += ' <span class="item-action-button" onclick="io.clickExit(\'' + ex.dir + '\')">'
s += ex.dir
s += '</span>'
}
s += '</p>'
el.innerHTML = s
el.previousSibling.innerHTML = currentLocation.headingAlias
}
If you prefer to list the destinations, rather than the directions, you can change the line s += ex.dir
to s += ex.name
, but I would advise doing so only if the command line is disabled, because typing the destination will not work.
Lastly, we just need to replace the default function in io
that creates the HTML for each item.
io.getItemHtml = function(item, loc, isSubItem, highlight) {
const verbList = item.getVerbs(loc)
if (verbList === undefined) { errormsg("No verbs for " + item.name); console.log(item); }
let s = '<p id="' + item.name + '-item" class="item-class"><span class="item-name">' + item.getListAlias(loc) + ':</span>'
for (let verb of verbList) {
if (typeof verb === 'string') verb = {name:verb, action:verb}
s += ' <span class="item-action-button" onclick="io.clickItemAction(\'' + item.name + '\', \'' + verb.action + '\')">';
s += verb.name;
s += '</span>';
}
s += '</p>'
return s
}
You also need some CSS styling. If you do not already have a CSS file in your game, create a new file, "style.css" in the game folder, and add this line to settings.js.
settings.styleFile = 'style'
If you do have a CSS file, just add this to it.
.side-panes {
width: 300px;
}
.item-class {
padding: 3px;
margin-top: 1em ;
margin-bottom: 1em ;
line-height: 2em;
}
.item-name {
font-style: italic;
padding-right: 5px;
}
.item-nothing {
font-style: italic;
padding: 3px;
line-height: 2em;
}
.item-action-button {
cursor: pointer;
color:white;
background-color:black;
border-radius: 3px;
padding: 3px;
}
You should play around with this to get it to your like, but this is a good starting point.
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
respond
function - 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