2014-07-17 20:20:11 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
2014-02-11 15:02:27 -05:00
|
|
|
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
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class LevelGoldView extends CocoView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'gold-view'
|
2014-02-11 15:02:27 -05:00
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'surface:gold-changed': 'onGoldChanged'
|
2014-08-27 15:24:03 -04:00
|
|
|
'level:set-letterbox': 'onSetLetterbox'
|
2014-02-11 15:02:27 -05:00
|
|
|
|
2014-05-14 19:06:00 -04:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@teamGold = {}
|
|
|
|
@teamGoldEarned = {}
|
2014-06-23 13:36:36 -04:00
|
|
|
@shownOnce = false
|
2014-08-27 15:24:03 -04:00
|
|
|
|
2014-02-11 15:02:27 -05:00
|
|
|
onGoldChanged: (e) ->
|
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-06-20 20:19:18 -04:00
|
|
|
@$el[if e.team is 'humans' then 'prepend' else 'append'](teamEl)
|
2014-07-07 19:05:23 -04:00
|
|
|
goldEl = @$el.find('.gold-amount.team-' + e.team)
|
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()
|
2014-06-23 13:36:36 -04:00
|
|
|
@$el.show()
|
|
|
|
@shownOnce = true
|
2014-05-14 19:06:00 -04:00
|
|
|
|
|
|
|
updateTitle: ->
|
2014-07-07 19:56:47 -04:00
|
|
|
strings = []
|
|
|
|
for team, gold of @teamGold
|
|
|
|
if @teamGoldEarned[team]
|
|
|
|
strings.push "Team '#{team}' has #{gold} now of #{@teamGoldEarned[team]} gold earned."
|
|
|
|
else
|
|
|
|
strings.push "Team '#{team}' has #{gold} gold."
|
|
|
|
@$el.attr 'title', strings.join ' '
|
2014-02-11 15:02:27 -05:00
|
|
|
|
|
|
|
onSetLetterbox: (e) ->
|
2014-06-23 13:36:36 -04:00
|
|
|
@$el.toggle not e.on if @shownOnce
|