2014-02-11 15:02:27 -05:00
|
|
|
View = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/play/level/gold'
|
2014-05-02 18:12:30 -04:00
|
|
|
teamTemplate = require 'templates/play/level/team_gold'
|
2014-02-11 15:02:27 -05:00
|
|
|
|
|
|
|
module.exports = class GoldView extends View
|
|
|
|
id: "gold-view"
|
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'surface:gold-changed': 'onGoldChanged'
|
|
|
|
'level-set-letterbox': 'onSetLetterbox'
|
|
|
|
|
2014-05-14 19:06:00 -04:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@teamGold = {}
|
|
|
|
@teamGoldEarned = {}
|
|
|
|
|
2014-02-11 15:02:27 -05:00
|
|
|
onGoldChanged: (e) ->
|
|
|
|
@$el.show()
|
2014-05-14 19:06:00 -04:00
|
|
|
return if @teamGold[e.team] is e.gold and @teamGoldEarned[e.team] is e.goldEarned
|
|
|
|
@teamGold[e.team] = e.gold
|
|
|
|
@teamGoldEarned[e.team] = e.goldEarned
|
2014-02-11 15:02:27 -05:00
|
|
|
goldEl = @$el.find('.gold-amount.team-' + e.team)
|
|
|
|
unless goldEl.length
|
2014-05-02 18:12:30 -04:00
|
|
|
teamEl = teamTemplate team: e.team
|
2014-02-11 15:02:27 -05:00
|
|
|
@$el.append(teamEl)
|
2014-05-02 18:12:30 -04:00
|
|
|
goldEl = $('.gold-amount.team-' + e.team, teamEl)
|
2014-04-27 18:33:16 -04:00
|
|
|
text = '' + e.gold
|
|
|
|
if e.goldEarned and e.goldEarned > e.gold
|
|
|
|
text += " (#{e.goldEarned})"
|
|
|
|
goldEl.text text
|
2014-05-14 19:06:00 -04:00
|
|
|
@updateTitle()
|
|
|
|
|
|
|
|
updateTitle: ->
|
|
|
|
@$el.attr 'title', ("Team '#{team}' has #{gold} now of #{@teamGoldEarned[team]} gold earned." for team, gold of @teamGold).join ' '
|
2014-02-11 15:02:27 -05:00
|
|
|
|
|
|
|
onSetLetterbox: (e) ->
|
2014-02-13 12:26:21 -05:00
|
|
|
@$el.toggle not e.on
|