2014-07-17 20:20:11 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
2014-03-14 20:06:08 -04:00
|
|
|
template = require 'templates/play/level/level_loading'
|
2014-09-21 23:49:45 -04:00
|
|
|
utils = require 'lib/utils'
|
2014-03-14 20:06:08 -04:00
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
module.exports = class LevelLoadingView extends CocoView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'level-loading-view'
|
2014-03-14 20:06:08 -04:00
|
|
|
template: template
|
|
|
|
|
2014-09-21 17:35:59 -04:00
|
|
|
events:
|
2014-09-21 23:19:27 -04:00
|
|
|
'mousedown .start-level-button': 'startUnveiling' # Split into two for animation smoothness.
|
2014-09-21 17:35:59 -04:00
|
|
|
'click .start-level-button': 'onClickStartLevel'
|
|
|
|
|
2014-09-21 18:52:49 -04:00
|
|
|
subscriptions:
|
2014-09-21 23:19:27 -04:00
|
|
|
'level:loaded': 'onLevelLoaded' # If Level loads after level loading view.
|
2014-09-21 17:35:59 -04:00
|
|
|
|
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-09-21 23:19:27 -04:00
|
|
|
@onLevelLoaded level: @options.level if @options.level?.get('goals') # If Level was already loaded.
|
2014-03-14 20:06:08 -04:00
|
|
|
|
2014-09-21 18:52:49 -04:00
|
|
|
onLevelLoaded: (e) ->
|
|
|
|
@level = e.level
|
2014-09-22 01:10:52 -04:00
|
|
|
goalContainer = @$el.find('.level-loading-goals')
|
|
|
|
goalList = goalContainer.find('ul')
|
|
|
|
goalCount = 0
|
2014-09-21 23:19:27 -04:00
|
|
|
for goalID, goal of @level.get('goals') when (not goal.team or goal.team is e.team) and not goal.hiddenGoal
|
2014-09-21 23:49:45 -04:00
|
|
|
name = utils.i18n goal, 'name'
|
|
|
|
goalList.append $('<li class="list-group-item header-font">' + name + '</li>')
|
2014-09-22 01:10:52 -04:00
|
|
|
++goalCount
|
|
|
|
if goalCount
|
|
|
|
goalContainer.removeClass('secret')
|
|
|
|
if goalCount is 1
|
|
|
|
goalContainer.find('.panel-heading').text $.i18n.t 'play_level.goal' # Not plural
|
2014-09-21 18:52:49 -04:00
|
|
|
|
2014-03-14 20:06:08 -04:00
|
|
|
showReady: ->
|
2014-05-20 00:53:14 -04:00
|
|
|
return if @shownReady
|
|
|
|
@shownReady = true
|
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
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'level_loaded', volume: 0.75 # old: loading_ready
|
2014-09-21 23:19:27 -04:00
|
|
|
if @options.autoUnveil
|
|
|
|
@startUnveiling()
|
|
|
|
@unveil()
|
|
|
|
else
|
|
|
|
@$el.find('.start-level-button').removeClass 'secret'
|
2014-03-14 20:06:08 -04:00
|
|
|
|
2014-09-21 18:52:49 -04:00
|
|
|
startUnveiling: (e) ->
|
|
|
|
Backbone.Mediator.publish 'level:loading-view-unveiling', {}
|
2014-09-23 14:39:56 -04:00
|
|
|
_.delay @onClickStartLevel, 1000 # If they never mouse-up for the click (or a modal shows up and interrupts the click), do it anyway.
|
2014-09-21 18:52:49 -04:00
|
|
|
|
2014-09-23 14:39:56 -04:00
|
|
|
onClickStartLevel: (e) =>
|
|
|
|
return if @destroyed
|
2014-09-21 17:35:59 -04:00
|
|
|
@unveil()
|
2014-03-14 20:06:08 -04:00
|
|
|
|
2014-09-21 17:35:59 -04:00
|
|
|
unveil: ->
|
2014-09-23 14:39:56 -04:00
|
|
|
return if @$el.hasClass 'unveiled'
|
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-09-11 11:38:30 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'loading-view-unveil', volume: 0.5
|
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: @
|