mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-12 16:51:35 -05:00
49 lines
1.3 KiB
CoffeeScript
49 lines
1.3 KiB
CoffeeScript
|
CocoClass = require 'lib/CocoClass'
|
||
|
|
||
|
module.exports = class CastingScreen extends CocoClass
|
||
|
subscriptions:
|
||
|
'tome:cast-spells': 'onCastingBegins'
|
||
|
'god:new-world-created': 'onCastingEnds'
|
||
|
|
||
|
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()
|
||
|
|
||
|
onCastingBegins: ->
|
||
|
@show()
|
||
|
|
||
|
onCastingEnds: ->
|
||
|
@hide()
|
||
|
|
||
|
toString: -> "<CastingScreen>"
|
||
|
|
||
|
build: ->
|
||
|
@dimLayer = new createjs.Container()
|
||
|
@dimLayer.mouseEnabled = @dimLayer.mouseChildren = false
|
||
|
@dimLayer.layerIndex = -11
|
||
|
@dimLayer.addChild @dimScreen = new createjs.Shape()
|
||
|
@dimScreen.graphics.beginFill("rgba(0,0,0,0.5)").rect 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
||
|
@dimLayer.cache 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
||
|
@dimLayer.alpha = 0
|
||
|
@layer.addChild @dimLayer
|
||
|
|
||
|
show: ->
|
||
|
return if @on
|
||
|
@on = true
|
||
|
|
||
|
@dimLayer.alpha = 0
|
||
|
createjs.Tween.removeTweens @dimLayer
|
||
|
createjs.Tween.get(@dimLayer).to({alpha:1}, 500)
|
||
|
|
||
|
hide: ->
|
||
|
return unless @on
|
||
|
@on = false
|
||
|
|
||
|
createjs.Tween.removeTweens @dimLayer
|
||
|
createjs.Tween.get(@dimLayer).to({alpha:0}, 500)
|