forked from doublespeakgames/adarkroom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c978f4
commit 6ee6470
Showing
10 changed files
with
6,063 additions
and
6,063 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,78 @@ | ||
/** | ||
* Module that registers the notification box and handles messages | ||
*/ | ||
var Notifications = { | ||
|
||
init: function(options) { | ||
this.options = $.extend( | ||
this.options, | ||
options | ||
); | ||
|
||
// Create the notifications box | ||
elem = $('<div>').attr({ | ||
id: 'notifications', | ||
className: 'notifications' | ||
}); | ||
// Create the transparency gradient | ||
$('<div>').attr('id', 'notifyGradient').appendTo(elem); | ||
|
||
elem.appendTo('div#wrapper'); | ||
}, | ||
|
||
options: {}, // Nothing for now | ||
|
||
elem: null, | ||
|
||
notifyQueue: {}, | ||
|
||
// Allow notification to the player | ||
notify: function(module, text, noQueue) { | ||
if(typeof text == 'undefined') return; | ||
if(text.slice(-1) != ".") text += "."; | ||
if(module != null && Engine.activeModule != module) { | ||
if(!noQueue) { | ||
if(typeof this.notifyQueue[module] == 'undefined') { | ||
this.notifyQueue[module] = []; | ||
} | ||
this.notifyQueue[module].push(text); | ||
} | ||
} else { | ||
Notifications.printMessage(text); | ||
} | ||
Engine.saveGame(); | ||
}, | ||
|
||
clearHidden: function() { | ||
|
||
// To fix some memory usage issues, we clear notifications that have been hidden. | ||
|
||
// We use position().top here, because we know that the parent will be the same, so the position will be the same. | ||
var bottom = $('#notifyGradient').position().top + $('#notifyGradient').outerHeight(true); | ||
|
||
$('.notification').each(function() { | ||
|
||
if($(this).position().top > bottom){ | ||
$(this).remove(); | ||
} | ||
|
||
}); | ||
|
||
}, | ||
|
||
printMessage: function(t) { | ||
var text = $('<div>').addClass('notification').css('opacity', '0').text(t).prependTo('div#notifications'); | ||
text.animate({opacity: 1}, 500, 'linear', function() { | ||
// Do this every time we add a new message, this way we never have a large backlog to iterate through. Keeps things faster. | ||
Notifications.clearHidden(); | ||
}); | ||
}, | ||
|
||
printQueue: function(module) { | ||
if(typeof this.notifyQueue[module] != 'undefined') { | ||
while(this.notifyQueue[module].length > 0) { | ||
Notifications.printMessage(this.notifyQueue[module].shift()); | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Module that registers the notification box and handles messages | ||
*/ | ||
var Notifications = { | ||
|
||
init: function(options) { | ||
this.options = $.extend( | ||
this.options, | ||
options | ||
); | ||
|
||
// Create the notifications box | ||
elem = $('<div>').attr({ | ||
id: 'notifications', | ||
className: 'notifications' | ||
}); | ||
// Create the transparency gradient | ||
$('<div>').attr('id', 'notifyGradient').appendTo(elem); | ||
|
||
elem.appendTo('div#wrapper'); | ||
}, | ||
|
||
options: {}, // Nothing for now | ||
|
||
elem: null, | ||
|
||
notifyQueue: {}, | ||
|
||
// Allow notification to the player | ||
notify: function(module, text, noQueue) { | ||
if(typeof text == 'undefined') return; | ||
if(text.slice(-1) != ".") text += "."; | ||
if(module != null && Engine.activeModule != module) { | ||
if(!noQueue) { | ||
if(typeof this.notifyQueue[module] == 'undefined') { | ||
this.notifyQueue[module] = []; | ||
} | ||
this.notifyQueue[module].push(text); | ||
} | ||
} else { | ||
Notifications.printMessage(text); | ||
} | ||
Engine.saveGame(); | ||
}, | ||
|
||
clearHidden: function() { | ||
|
||
// To fix some memory usage issues, we clear notifications that have been hidden. | ||
|
||
// We use position().top here, because we know that the parent will be the same, so the position will be the same. | ||
var bottom = $('#notifyGradient').position().top + $('#notifyGradient').outerHeight(true); | ||
|
||
$('.notification').each(function() { | ||
|
||
if($(this).position().top > bottom){ | ||
$(this).remove(); | ||
} | ||
|
||
}); | ||
|
||
}, | ||
|
||
printMessage: function(t) { | ||
var text = $('<div>').addClass('notification').css('opacity', '0').text(t).prependTo('div#notifications'); | ||
text.animate({opacity: 1}, 500, 'linear', function() { | ||
// Do this every time we add a new message, this way we never have a large backlog to iterate through. Keeps things faster. | ||
Notifications.clearHidden(); | ||
}); | ||
}, | ||
|
||
printQueue: function(module) { | ||
if(typeof this.notifyQueue[module] != 'undefined') { | ||
while(this.notifyQueue[module].length > 0) { | ||
Notifications.printMessage(this.notifyQueue[module].shift()); | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.