// gadgets.js
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MY LITTLE PROGRAM - harald.wirth@gmx.at - http://harald.ist.org/ - 2012 - Do not remove this copyleft notice.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// G A D G E T S - speech bubbles, objects in the scene, ...
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// S P E E C H B U B B L E - Handles the speech bubble
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Currently, one instance is used (hardcoded in markup), so only one bubble can be shown at a given moment.
//... it should be possible to display speech bubbles simultaneously
var BaseDialog = function(new_game) {
var game = new_game;
this.next_case = 0;
this.hide_delay = 0; // 0 .. no delay (endless), 1+ .. milliseconds
this.is = function(avatar_id) {
return (avatar_id == game.avatars.current.id);
} // is
this.say = function(text) {
game.speech_bubble.show( text, game.avatars.current );
} // say
this.resume = function(){};
this.dialog_ends = // clone of this.end:
this.end = function() {
game.collision.delete_link();
//...needed? game.speech_bubble.hide();
}
}
var SpeechBubble = function(new_game) {
var self = this;
var game = new_game;
this.DOM_element = game.viewport.DOM_element.getElementsByClassName('speech_bubble')[0];
this.timer;
this.text = ' ';
this.hide_delay = 0;
/**
* show - determines position and unhides bubble
*/
this.show = function(new_text, avatar) {
var img, x;
var scene_position = avatar.position_x + avatar.img.width/2;
// Insert new text to bubble
if (typeof(new_text) != 'undefined') {
img = this.DOM_element.getElementsByTagName('img')[0]; // save the image
this.DOM_element.innerHTML = new_text; // This removes the original image
this.DOM_element.appendChild( img ); // re-add the image
}
// Assign individual color
this.DOM_element.style.color = avatar.colors[0];
//...bubble-addon is an image and has white BG: this.DOM_element.style.backgroundColor = avatar.colors[2];
// calculate position
if (typeof(scene_position) != 'undefined') {
x = scene_position - game.viewport.offset_x;
this.DOM_element.style.left = x + 'px';
}
else {
this.DOM_element.style.left = '50%';
}
// unhide bubble
remove_class( this.DOM_element, 'invisible' );
if (this.hide_delay > 0) {
window.clearTimeout( this.timer );
this.timer = window.setTimeout( this.hide, this.hide_delay );
}
} // show
//
// hide - hides the speech bubble
//
this.hide = function() {
add_class( self.DOM_element, 'invisible' );
} // show
// CONSTRUCTOR //
} // SpeechBubble
//EOF