2014-11-28 20:49:41 -05:00
|
|
|
CocoClass = require 'core/CocoClass'
|
2014-02-25 20:14:39 -05:00
|
|
|
|
2014-03-13 18:35:28 -04:00
|
|
|
module.exports = class PlaybackOverScreen extends CocoClass
|
2014-10-08 12:46:56 -04:00
|
|
|
subscriptions:
|
|
|
|
'goal-manager:new-goal-states': 'onNewGoalStates'
|
|
|
|
|
2014-02-25 20:14:39 -05:00
|
|
|
constructor: (options) ->
|
|
|
|
super()
|
|
|
|
options ?= {}
|
|
|
|
@camera = options.camera
|
|
|
|
@layer = options.layer
|
2015-09-03 16:32:20 -04:00
|
|
|
@playerNames = options.playerNames
|
2014-06-30 22:16:26 -04:00
|
|
|
console.error @toString(), 'needs a camera.' unless @camera
|
|
|
|
console.error @toString(), 'needs a layer.' unless @layer
|
2014-02-25 20:14:39 -05:00
|
|
|
@build()
|
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
toString: -> '<PlaybackOverScreen>'
|
2014-02-25 20:14:39 -05:00
|
|
|
|
|
|
|
build: ->
|
|
|
|
@dimLayer = new createjs.Container()
|
|
|
|
@dimLayer.mouseEnabled = @dimLayer.mouseChildren = false
|
|
|
|
@dimLayer.addChild @dimScreen = new createjs.Shape()
|
|
|
|
@dimLayer.alpha = 0
|
|
|
|
@layer.addChild @dimLayer
|
|
|
|
|
2015-09-03 16:32:20 -04:00
|
|
|
makeVictoryText: ->
|
|
|
|
s = ''
|
|
|
|
size = Math.ceil @camera.canvasHeight / 6
|
|
|
|
text = new createjs.Text s, "#{size}px Open Sans Condensed", '#F7B42C'
|
|
|
|
text.shadow = new createjs.Shadow '#000', Math.ceil(@camera.canvasHeight / 300), Math.ceil(@camera.canvasHeight / 300), Math.ceil(@camera.canvasHeight / 120)
|
|
|
|
text.textAlign = 'center'
|
|
|
|
text.textBaseline = 'middle'
|
|
|
|
text.x = 0.5 * @camera.canvasWidth
|
|
|
|
text.y = 0.8 * @camera.canvasHeight
|
|
|
|
@dimLayer.addChild text
|
|
|
|
@text = text
|
|
|
|
|
2014-02-25 20:14:39 -05:00
|
|
|
show: ->
|
|
|
|
return if @showing
|
|
|
|
@showing = true
|
2014-10-08 13:46:10 -04:00
|
|
|
@updateColor 'rgba(212, 212, 212, 0.4)' unless @color # If we haven't caught the goal state for the first run, just do something neutral.
|
2014-02-25 20:14:39 -05:00
|
|
|
@dimLayer.alpha = 0
|
|
|
|
createjs.Tween.removeTweens @dimLayer
|
2014-06-30 22:16:26 -04:00
|
|
|
createjs.Tween.get(@dimLayer).to({alpha: 1}, 500)
|
2014-02-25 20:14:39 -05:00
|
|
|
|
|
|
|
hide: ->
|
|
|
|
return unless @showing
|
|
|
|
@showing = false
|
|
|
|
createjs.Tween.removeTweens @dimLayer
|
2014-06-30 22:16:26 -04:00
|
|
|
createjs.Tween.get(@dimLayer).to({alpha: 0}, 500)
|
2014-10-08 12:46:56 -04:00
|
|
|
|
|
|
|
onNewGoalStates: (e) ->
|
|
|
|
success = e.overallStatus is 'success'
|
|
|
|
failure = e.overallStatus is 'failure'
|
|
|
|
timedOut = e.timedOut
|
|
|
|
incomplete = not success and not failure and not timedOut
|
|
|
|
color = if failure then 'rgba(255, 128, 128, 0.4)' else 'rgba(255, 255, 255, 0.4)'
|
|
|
|
@updateColor color
|
2015-09-03 18:04:57 -04:00
|
|
|
@updateText e
|
2014-10-08 12:46:56 -04:00
|
|
|
|
|
|
|
updateColor: (color) ->
|
|
|
|
return if color is @color
|
|
|
|
@dimScreen.graphics.clear().beginFill(color).rect 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
|
|
|
if @color
|
|
|
|
@dimLayer.updateCache()
|
|
|
|
else
|
2015-09-03 16:32:20 -04:00
|
|
|
@dimLayer.cache 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
2014-10-08 12:46:56 -04:00
|
|
|
@color = color
|
2015-09-03 16:32:20 -04:00
|
|
|
|
2015-09-03 18:04:57 -04:00
|
|
|
updateText: (goalEvent) ->
|
2015-09-03 16:32:20 -04:00
|
|
|
return unless _.size @playerNames # Only on multiplayer levels
|
2015-09-03 18:04:57 -04:00
|
|
|
teamOverallStatuses = {}
|
|
|
|
|
|
|
|
goals = if goalEvent.goalStates then _.values goalEvent.goalStates else []
|
|
|
|
goals = (g for g in goals when not g.optional)
|
|
|
|
for team in ['humans', 'ogres']
|
|
|
|
teamGoals = (g for g in goals when g.team in [undefined, team])
|
|
|
|
statuses = (goal.status for goal in teamGoals)
|
|
|
|
overallStatus = 'success' if statuses.length > 0 and _.every(statuses, (s) -> s is 'success')
|
|
|
|
overallStatus = 'failure' if statuses.length > 0 and 'failure' in statuses
|
|
|
|
teamOverallStatuses[team] = overallStatus
|
|
|
|
|
2015-09-03 16:32:20 -04:00
|
|
|
@makeVictoryText() unless @text
|
2015-09-03 18:04:57 -04:00
|
|
|
if teamOverallStatuses.humans is 'success'
|
2015-09-03 16:32:20 -04:00
|
|
|
@text.color = '#E62B1E'
|
2015-09-03 18:04:57 -04:00
|
|
|
@text.text = ((@playerNames.humans ? $.i18n.t('ladder.red_ai')) + ' ' + $.i18n.t('ladder.wins')).toLocaleUpperCase()
|
|
|
|
else if teamOverallStatuses.ogres is 'success'
|
2015-09-03 16:32:20 -04:00
|
|
|
@text.color = '#0597FF'
|
2015-09-03 18:04:57 -04:00
|
|
|
@text.text = ((@playerNames.ogres ? $.i18n.t('ladder.blue_ai')) + ' ' + $.i18n.t('ladder.wins')).toLocaleUpperCase()
|
2015-09-03 16:32:20 -04:00
|
|
|
else
|
|
|
|
@text.color = '#F7B42C'
|
2015-09-03 18:04:57 -04:00
|
|
|
if goalEvent.timedOut
|
2015-09-03 16:32:20 -04:00
|
|
|
@text.text = 'TIMED OUT'
|
|
|
|
else
|
|
|
|
@text.text = 'INCOMPLETE'
|
|
|
|
@dimLayer.updateCache()
|