2014-03-14 20:06:08 -04:00
|
|
|
View = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/play/level/level_loading'
|
|
|
|
|
2014-03-16 20:07:10 -04:00
|
|
|
|
2014-03-14 20:06:08 -04:00
|
|
|
module.exports = class LevelLoadingView extends View
|
|
|
|
id: "level-loading-view"
|
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'level-loader:progress-changed': 'onLevelLoaderProgressChanged'
|
2014-04-09 12:04:59 -04:00
|
|
|
|
2014-04-17 19:23:35 -04:00
|
|
|
onLoaded: ->
|
2014-03-17 01:01:21 -04:00
|
|
|
afterRender: ->
|
2014-03-17 03:12:11 -04:00
|
|
|
@$el.find('.tip.rare').remove() if _.random(1, 10) < 9
|
|
|
|
tips = @$el.find('.tip').addClass('to-remove')
|
2014-03-17 01:01:21 -04:00
|
|
|
tip = _.sample(tips)
|
2014-03-17 03:12:11 -04:00
|
|
|
$(tip).removeClass('to-remove')
|
|
|
|
@$el.find('.to-remove').remove()
|
2014-03-14 20:06:08 -04:00
|
|
|
|
|
|
|
onLevelLoaderProgressChanged: (e) ->
|
2014-04-15 18:01:54 -04:00
|
|
|
return if @destroyed
|
2014-03-14 20:06:08 -04:00
|
|
|
@progress = e.progress
|
2014-03-17 03:05:45 -04:00
|
|
|
@progress = 0.01 if @progress < 0.01
|
2014-03-14 20:06:08 -04:00
|
|
|
@updateProgressBar()
|
|
|
|
|
|
|
|
updateProgressBar: ->
|
2014-04-17 19:23:35 -04:00
|
|
|
@$el.find('.progress-bar').css('width', (100 * @progress) + '%')
|
2014-03-14 20:06:08 -04:00
|
|
|
|
|
|
|
showReady: ->
|
2014-03-17 08:52:19 -04:00
|
|
|
ready = $.i18n.t('play_level.loading_ready', defaultValue: 'Ready!')
|
|
|
|
@$el.find('#tip-wrapper .tip').addClass('ready').text ready
|
|
|
|
Backbone.Mediator.publish 'play-sound', trigger: 'loading_ready', volume: 0.75
|
2014-03-14 20:06:08 -04:00
|
|
|
|
|
|
|
unveil: ->
|
2014-03-14 22:44:19 -04:00
|
|
|
_.delay @reallyUnveil, 1000
|
2014-03-14 20:06:08 -04:00
|
|
|
|
|
|
|
reallyUnveil: =>
|
2014-04-10 16:59:08 -04:00
|
|
|
return if @destroyed or @progress < 1
|
2014-04-09 12:04:59 -04:00
|
|
|
@$el.addClass 'unveiled'
|
2014-03-14 20:06:08 -04:00
|
|
|
loadingDetails = @$el.find('.loading-details')
|
|
|
|
duration = parseFloat loadingDetails.css 'transition-duration'
|
|
|
|
loadingDetails.css 'top', -loadingDetails.outerHeight(true)
|
2014-03-14 22:44:19 -04:00
|
|
|
@$el.find('.left-wing').css left: '-100%', backgroundPosition: 'right -400px top 0'
|
|
|
|
@$el.find('.right-wing').css right: '-100%', backgroundPosition: 'left -400px top 0'
|
2014-03-14 20:06:08 -04:00
|
|
|
_.delay @onUnveilEnded, duration * 1000
|
|
|
|
|
|
|
|
onUnveilEnded: =>
|
|
|
|
return if @destroyed
|
2014-04-13 23:31:23 -04:00
|
|
|
Backbone.Mediator.publish 'level:loading-view-unveiled', view: @
|