mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Added a screen for when playback ends.
This commit is contained in:
parent
a53498224c
commit
02d1dc2445
5 changed files with 76 additions and 4 deletions
40
app/lib/surface/PlaybackOverScreen.coffee
Normal file
40
app/lib/surface/PlaybackOverScreen.coffee
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
CocoClass = require 'lib/CocoClass'
|
||||||
|
|
||||||
|
module.exports = class PlaybackoverScreen extends CocoClass
|
||||||
|
constructor: (options) ->
|
||||||
|
super()
|
||||||
|
options ?= {}
|
||||||
|
@camera = options.camera
|
||||||
|
@layer = options.layer
|
||||||
|
console.error @toString(), "needs a camera." unless @camera
|
||||||
|
console.error @toString(), "needs a layer." unless @layer
|
||||||
|
@build()
|
||||||
|
|
||||||
|
toString: -> "<PlaybackoverScreen>"
|
||||||
|
|
||||||
|
build: ->
|
||||||
|
@dimLayer = new createjs.Container()
|
||||||
|
@dimLayer.mouseEnabled = @dimLayer.mouseChildren = false
|
||||||
|
@dimLayer.layerIndex = -12
|
||||||
|
@dimLayer.addChild @dimScreen = new createjs.Shape()
|
||||||
|
@dimScreen.graphics.beginFill("rgba(0,0,0,0.4)").rect 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
||||||
|
@dimLayer.cache 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
||||||
|
@dimLayer.alpha = 0
|
||||||
|
@layer.addChild @dimLayer
|
||||||
|
|
||||||
|
show: ->
|
||||||
|
console.log 'show playback over screen', @showing
|
||||||
|
return if @showing
|
||||||
|
@showing = true
|
||||||
|
|
||||||
|
@dimLayer.alpha = 0
|
||||||
|
createjs.Tween.removeTweens @dimLayer
|
||||||
|
createjs.Tween.get(@dimLayer).to({alpha:1}, 500)
|
||||||
|
|
||||||
|
hide: ->
|
||||||
|
console.log 'hide playback over screen', @showing
|
||||||
|
return unless @showing
|
||||||
|
@showing = false
|
||||||
|
|
||||||
|
createjs.Tween.removeTweens @dimLayer
|
||||||
|
createjs.Tween.get(@dimLayer).to({alpha:0}, 500)
|
|
@ -212,11 +212,16 @@ module.exports = class SpriteBoss extends CocoClass
|
||||||
|
|
||||||
onNewWorld: (e) ->
|
onNewWorld: (e) ->
|
||||||
@world = @options.world = e.world
|
@world = @options.world = e.world
|
||||||
|
@play()
|
||||||
|
|
||||||
|
onCastSpells: -> @stop()
|
||||||
|
|
||||||
|
play: ->
|
||||||
sprite.imageObject.play() for thangID, sprite of @sprites
|
sprite.imageObject.play() for thangID, sprite of @sprites
|
||||||
@selectionMark?.play()
|
@selectionMark?.play()
|
||||||
@targetMark?.play()
|
@targetMark?.play()
|
||||||
|
|
||||||
onCastSpells: ->
|
stop: ->
|
||||||
sprite.imageObject.stop() for thangID, sprite of @sprites
|
sprite.imageObject.stop() for thangID, sprite of @sprites
|
||||||
@selectionMark?.stop()
|
@selectionMark?.stop()
|
||||||
@targetMark?.stop()
|
@targetMark?.stop()
|
||||||
|
|
|
@ -9,6 +9,7 @@ Layer = require './Layer'
|
||||||
Letterbox = require './Letterbox'
|
Letterbox = require './Letterbox'
|
||||||
Dimmer = require './Dimmer'
|
Dimmer = require './Dimmer'
|
||||||
CastingScreen = require './CastingScreen'
|
CastingScreen = require './CastingScreen'
|
||||||
|
PlaybackOverScreen = require './PlaybackOverScreen'
|
||||||
DebugDisplay = require './DebugDisplay'
|
DebugDisplay = require './DebugDisplay'
|
||||||
CoordinateDisplay = require './CoordinateDisplay'
|
CoordinateDisplay = require './CoordinateDisplay'
|
||||||
SpriteBoss = require './SpriteBoss'
|
SpriteBoss = require './SpriteBoss'
|
||||||
|
@ -90,6 +91,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@chooser?.destroy()
|
@chooser?.destroy()
|
||||||
@dimmer?.destroy()
|
@dimmer?.destroy()
|
||||||
@castingScreen?.destroy()
|
@castingScreen?.destroy()
|
||||||
|
@playbackOverScreen?.destroy()
|
||||||
@stage.clear()
|
@stage.clear()
|
||||||
@musicPlayer?.destroy()
|
@musicPlayer?.destroy()
|
||||||
@stage.removeAllChildren()
|
@stage.removeAllChildren()
|
||||||
|
@ -179,7 +181,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
container.addChild shape
|
container.addChild shape
|
||||||
|
|
||||||
setProgress: (progress, scrubDuration=500) ->
|
setProgress: (progress, scrubDuration=500) ->
|
||||||
progress = Math.max(Math.min(progress, 0.99), 0.0)
|
progress = Math.max(Math.min(progress, 1), 0.0)
|
||||||
|
|
||||||
@scrubbing = true
|
@scrubbing = true
|
||||||
onTweenEnd = =>
|
onTweenEnd = =>
|
||||||
|
@ -193,7 +195,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
createjs.Tween.removeTweens(@)
|
createjs.Tween.removeTweens(@)
|
||||||
@currentFrame = @scrubbingTo
|
@currentFrame = @scrubbingTo
|
||||||
|
|
||||||
@scrubbingTo = Math.floor(progress * @world.totalFrames)
|
@scrubbingTo = Math.min(Math.floor(progress * @world.totalFrames), @world.totalFrames)
|
||||||
@scrubbingPlaybackSpeed = Math.sqrt(Math.abs(@scrubbingTo - @currentFrame) * @world.dt / (scrubDuration or 0.5))
|
@scrubbingPlaybackSpeed = Math.sqrt(Math.abs(@scrubbingTo - @currentFrame) * @world.dt / (scrubDuration or 0.5))
|
||||||
if scrubDuration
|
if scrubDuration
|
||||||
t = createjs.Tween
|
t = createjs.Tween
|
||||||
|
@ -298,6 +300,18 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
frame: @currentFrame
|
frame: @currentFrame
|
||||||
world: @world
|
world: @world
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if @lastFrame < @world.totalFrames and @currentFrame >= @world.totalFrames
|
||||||
|
@spriteBoss.stop()
|
||||||
|
@playbackOverScreen.show()
|
||||||
|
@ended = true
|
||||||
|
Backbone.Mediator.publish 'surface:playback-ended'
|
||||||
|
else if @currentFrame < @world.totalFrames and @ended
|
||||||
|
@spriteBoss.play()
|
||||||
|
@playbackOverScreen.hide()
|
||||||
|
@ended = false
|
||||||
|
Backbone.Mediator.publish 'surface:playback-restarted'
|
||||||
|
|
||||||
@lastFrame = @currentFrame
|
@lastFrame = @currentFrame
|
||||||
|
|
||||||
onCastSpells: (event) ->
|
onCastSpells: (event) ->
|
||||||
|
@ -353,6 +367,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@screenLayer.addChild new Letterbox canvasWidth: canvasWidth, canvasHeight: canvasHeight
|
@screenLayer.addChild new Letterbox canvasWidth: canvasWidth, canvasHeight: canvasHeight
|
||||||
@spriteBoss = new SpriteBoss camera: @camera, surfaceLayer: @surfaceLayer, surfaceTextLayer: @surfaceTextLayer, world: @world, thangTypes: @options.thangTypes, choosing: @options.choosing, navigateToSelection: @options.navigateToSelection, showInvisible: @options.showInvisible
|
@spriteBoss = new SpriteBoss camera: @camera, surfaceLayer: @surfaceLayer, surfaceTextLayer: @surfaceTextLayer, world: @world, thangTypes: @options.thangTypes, choosing: @options.choosing, navigateToSelection: @options.navigateToSelection, showInvisible: @options.showInvisible
|
||||||
@castingScreen ?= new CastingScreen camera: @camera, layer: @screenLayer
|
@castingScreen ?= new CastingScreen camera: @camera, layer: @screenLayer
|
||||||
|
@playbackOverScreen ?= new PlaybackOverScreen camera: @camera, layer: @screenLayer
|
||||||
@stage.enableMouseOver(10)
|
@stage.enableMouseOver(10)
|
||||||
@stage.addEventListener 'stagemousemove', @onMouseMove
|
@stage.addEventListener 'stagemousemove', @onMouseMove
|
||||||
@stage.addEventListener 'stagemousedown', @onMouseDown
|
@stage.addEventListener 'stagemousedown', @onMouseDown
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
left: 10px
|
left: 10px
|
||||||
top: 42px
|
top: 42px
|
||||||
background-color: rgba(200,200,200,0.8)
|
background-color: rgba(200,200,200,0.8)
|
||||||
|
|
||||||
|
&.brighter
|
||||||
|
background-color: rgba(200,200,200,1.0)
|
||||||
|
|
||||||
border: black
|
border: black
|
||||||
padding: 5px 7px 5px 5px
|
padding: 5px 7px 5px 5px
|
||||||
box-sizing: border-box
|
box-sizing: border-box
|
||||||
|
|
|
@ -14,6 +14,8 @@ module.exports = class GoalsView extends View
|
||||||
subscriptions:
|
subscriptions:
|
||||||
'goal-manager:new-goal-states': 'onNewGoalStates'
|
'goal-manager:new-goal-states': 'onNewGoalStates'
|
||||||
'level-set-letterbox': 'onSetLetterbox'
|
'level-set-letterbox': 'onSetLetterbox'
|
||||||
|
'surface:playback-restarted': 'onSurfacePlaybackRestarted'
|
||||||
|
'surface:playback-ended': 'onSurfacePlaybackEnded'
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click': 'toggleCollapse'
|
'click': 'toggleCollapse'
|
||||||
|
@ -48,6 +50,12 @@ module.exports = class GoalsView extends View
|
||||||
goals.push goal
|
goals.push goal
|
||||||
@$el.removeClass('secret') if goals.length > 0
|
@$el.removeClass('secret') if goals.length > 0
|
||||||
|
|
||||||
|
onSurfacePlaybackRestarted: ->
|
||||||
|
@$el.removeClass 'brighter'
|
||||||
|
|
||||||
|
onSurfacePlaybackEnded: ->
|
||||||
|
@$el.addClass 'brighter'
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
super()
|
super()
|
||||||
@$el.addClass('secret').addClass('expanded')
|
@$el.addClass('secret').addClass('expanded')
|
||||||
|
|
Loading…
Reference in a new issue