-
Notifications
You must be signed in to change notification settings - Fork 0
Dialog
nhmkdev edited this page Jan 6, 2014
·
19 revisions
The dialog system is used to display text and response options through a standard interface.
A dialog is the following:
- List of states (each with - Text (optional) & List of options (optional))
- Selector (icon or character (pending))
- Windows (optional)
var Dialogs = ig.global.data.dialogs;
var Dialog = ig.support.dialog;
Notes:
- The dialogsSampleSettingsBase is an optional separate object for easy reuse across dialog objects. All fields indicated in the dialogsSampleSettingsBase object are applicable to the 's' object of a dialog.
- If the next state cannot be determined (due to data error or just not specifying) the dialog will close.
- The data for a dialog can be thought of as a conversation with the capability of a branching conversation based on requirements to reach given states.
var dialogsSampleSettingsBase =
{
f:'04b03.font', // font ('media/' is prepended and '.png' is appended automatically)
w:200, // width of the dialog space (for text wrap purposes) (default: 0)
h:0, // height does nothing for now... probably need to scroll (default: 0)
x:30, // x location (default: 0)
y:0, // y location (default: 0)
osx:5, // selector x offset (default: 0)
osy:6, // selector y offset (default: 0)
r:null // requirements to show this dialog (default: null)
win:[] // array of windows drawn in order specified by array (default: null)
winex:[] // additional array of windows (used for overrides that need an additional window instead of an override - drawn after the win array in order) (default: null)
c:null //class - used for key translation for localization + menu item actions (default: null) ('ig.global.' is prepended when associating to the class object)
}
Dialogs.sample =
{
s: // settings object
{
base:dialogsSampleSettingsBase , // base settings for this dialog (see base functionality (TODO link))
x:52, // base x override
winex: [] // extension to the windows [] (so the base and each dialog can have their own)
},
sa: // array of dialog state objects
[
{
n:'A', // state name (default:'')
t: 'Hi!', // text to display when this state is active
ns:'B', // next state (if there are no options that specify a next state) (default:'')
r:null, // requirements to enter this state (TODO: link to requirements) (default: null)
a:null, // action when exiting the state (TODO: link to actions) (default: null)
do: //default option index (default: 0)
o: // array of options to display when the state is active (default: null)
[
{
t:"Hello", // text
ns:'B' // next state name (if null or non-existent - exits the dialog)
a:null // action when option is selected (default: null) (default: null)
ca:'' // class action (only applicable if the dialog is configured with a class) (TODO: reference class docs)
cav:{} // class action variables (only applicable if the dialog is configured with a class) (TODO: reference class docs)
r:null // requires object (used to show/hide options) (default: null)
},
{ // Note: this option is trimmed down to just the essentials (and will exit on selection)
t:"Goodbye"
}
],
win:[] // windows for the given state (default: null)
},
{
n:'B',
t: 'Well good talking to you.',
}
]
}
TODO: reference the source code where this above is used.
In your main game mode's update() (before calling parent) add the following:
if(Dialog.update())
{
// updating the dialog (all other game updates are halted)
return;
}
Any time you need to pop open a dialog simply initialize the data by calling Dialog.initData:
var Dialog = ig.support.dialog;
// entity that popped the dialog (may be null) -- this is to allow the dialog to call .kill() on the entity if the data is setup to do so
// dialogObject - the dialog definition (ie. Dialogs.sample from above)
Dialog.initData(entity, dialogObject);