2014-01-03 13:32:13 -05:00
|
|
|
View = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/play/level/goals'
|
|
|
|
{me} = require 'lib/auth'
|
2014-03-13 12:02:19 -04:00
|
|
|
utils = require 'lib/utils'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
stateIconMap =
|
|
|
|
incomplete: 'icon-minus'
|
|
|
|
success: 'icon-ok'
|
|
|
|
failure: 'icon-remove'
|
|
|
|
|
|
|
|
module.exports = class GoalsView extends View
|
|
|
|
id: "goals-view"
|
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'goal-manager:new-goal-states': 'onNewGoalStates'
|
|
|
|
'level-set-letterbox': 'onSetLetterbox'
|
2014-02-25 20:14:39 -05:00
|
|
|
'surface:playback-restarted': 'onSurfacePlaybackRestarted'
|
|
|
|
'surface:playback-ended': 'onSurfacePlaybackEnded'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
2014-05-19 19:34:39 -04:00
|
|
|
'mouseenter': ->
|
|
|
|
@mouseEntered = true
|
|
|
|
@updatePlacement()
|
|
|
|
|
|
|
|
'mouseleave': ->
|
|
|
|
@mouseEntered = false
|
|
|
|
@updatePlacement()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-11 15:02:27 -05:00
|
|
|
toggleCollapse: (e) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
@$el.toggleClass('expanded').toggleClass('collapsed')
|
|
|
|
|
|
|
|
onNewGoalStates: (e) ->
|
2014-05-19 19:34:39 -04:00
|
|
|
@$el.find('.goal-status').addClass 'secret'
|
|
|
|
classToShow = null
|
|
|
|
classToShow = 'success' if e.overallStatus is 'success'
|
|
|
|
classToShow = 'failure' if e.overallStatus is 'failure'
|
|
|
|
classToShow ?= 'timed-out' if e.timedOut
|
|
|
|
classToShow ?= 'incomplete'
|
|
|
|
@$el.find('.goal-status.'+classToShow).removeClass 'secret'
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
list = $('#primary-goals-list', @$el)
|
|
|
|
list.empty()
|
|
|
|
goals = []
|
|
|
|
for goal in e.goals
|
|
|
|
state = e.goalStates[goal.id]
|
|
|
|
continue if goal.hiddenGoal and state.status isnt 'failure'
|
2014-02-10 15:49:38 -05:00
|
|
|
continue if goal.team and me.team isnt goal.team
|
2014-03-13 12:02:19 -04:00
|
|
|
text = utils.i18n goal, 'name'
|
2014-01-03 13:32:13 -05:00
|
|
|
if state.killed
|
|
|
|
dead = _.filter(_.values(state.killed)).length
|
|
|
|
targeted = _.values(state.killed).length
|
|
|
|
if targeted > 1
|
|
|
|
# Does this make sense?
|
|
|
|
if goal.isPositive
|
|
|
|
completed = dead
|
|
|
|
else
|
|
|
|
completed = targeted - dead
|
|
|
|
text = text + " (#{completed}/#{targeted})"
|
|
|
|
# This should really get refactored, along with GoalManager, so that goals have a standard
|
|
|
|
# representation of how many are done, how many are needed, what that means, etc.
|
|
|
|
li = $('<li></li>').addClass("status-#{state.status}").text(text)
|
|
|
|
li.prepend($('<i></i>').addClass(stateIconMap[state.status]))
|
|
|
|
list.append(li)
|
|
|
|
goals.push goal
|
2014-02-15 20:36:27 -05:00
|
|
|
@$el.removeClass('secret') if goals.length > 0
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-25 20:14:39 -05:00
|
|
|
onSurfacePlaybackRestarted: ->
|
2014-05-19 19:34:39 -04:00
|
|
|
@playbackEnded = false
|
2014-02-25 20:14:39 -05:00
|
|
|
@$el.removeClass 'brighter'
|
2014-05-19 19:34:39 -04:00
|
|
|
@updatePlacement()
|
2014-02-25 20:14:39 -05:00
|
|
|
|
|
|
|
onSurfacePlaybackEnded: ->
|
2014-05-19 19:34:39 -04:00
|
|
|
@playbackEnded = true
|
2014-02-25 20:14:39 -05:00
|
|
|
@$el.addClass 'brighter'
|
2014-05-19 19:34:39 -04:00
|
|
|
@updatePlacement()
|
2014-02-25 20:14:39 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
render: ->
|
|
|
|
super()
|
2014-02-15 20:36:27 -05:00
|
|
|
@$el.addClass('secret').addClass('expanded')
|
2014-05-19 14:31:18 -04:00
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
2014-05-19 19:34:39 -04:00
|
|
|
@updatePlacement()
|
2014-05-19 14:31:18 -04:00
|
|
|
|
2014-05-19 19:34:39 -04:00
|
|
|
updatePlacement: ->
|
|
|
|
if @playbackEnded or @mouseEntered
|
|
|
|
# expand
|
|
|
|
@$el.css('top', -10)
|
|
|
|
else
|
|
|
|
# collapse
|
|
|
|
@$el.css('top', 26 - @$el.outerHeight())
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onSetLetterbox: (e) ->
|
2014-02-13 12:26:21 -05:00
|
|
|
@$el.toggle not e.on
|
2014-05-19 19:34:39 -04:00
|
|
|
@updatePlacement()
|