2014-01-03 13:32:13 -05:00
|
|
|
View = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/play/level/control_bar'
|
|
|
|
|
|
|
|
DocsModal = require './modal/docs_modal'
|
|
|
|
MultiplayerModal = require './modal/multiplayer_modal'
|
|
|
|
ReloadModal = require './modal/reload_modal'
|
|
|
|
|
|
|
|
module.exports = class ControlBarView extends View
|
|
|
|
id: "control-bar-view"
|
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'bus:player-states-changed': 'onPlayerStatesChanged'
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click #multiplayer-button': ->
|
|
|
|
window.tracker?.trackEvent 'Clicked Multiplayer', level: @worldName, label: @worldName
|
|
|
|
@showMultiplayerModal()
|
|
|
|
|
|
|
|
'click #docs-button': ->
|
|
|
|
window.tracker?.trackEvent 'Clicked Docs', level: @worldName, label: @worldName
|
|
|
|
@showGuideModal()
|
|
|
|
|
|
|
|
'click #restart-button': ->
|
|
|
|
window.tracker?.trackEvent 'Clicked Restart', level: @worldName, label: @worldName
|
|
|
|
@showRestartModal()
|
|
|
|
|
|
|
|
'click': -> Backbone.Mediator.publish 'focus-editor'
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
@worldName = options.worldName
|
|
|
|
@session = options.session
|
|
|
|
@level = options.level
|
2014-02-06 20:31:08 -05:00
|
|
|
@playableTeams = options.playableTeams
|
2014-01-03 13:32:13 -05:00
|
|
|
super options
|
|
|
|
|
|
|
|
setBus: (@bus) ->
|
|
|
|
|
|
|
|
onPlayerStatesChanged: (e) ->
|
2014-02-12 15:41:41 -05:00
|
|
|
# TODO: this doesn't fire any more. Replacement?
|
2014-01-03 13:32:13 -05:00
|
|
|
return unless @bus is e.bus
|
|
|
|
numPlayers = _.keys(e.players).length
|
|
|
|
return if numPlayers is @numPlayers
|
|
|
|
@numPlayers = numPlayers
|
|
|
|
text = 'Multiplayer'
|
|
|
|
text += " (#{numPlayers})" if numPlayers > 1
|
|
|
|
$('#multiplayer-button', @$el).text(text)
|
|
|
|
|
2014-02-11 17:24:06 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
super context
|
|
|
|
context.worldName = @worldName
|
|
|
|
context.multiplayerEnabled = @session.get('multiplayer')
|
|
|
|
context
|
|
|
|
|
|
|
|
showGuideModal: ->
|
|
|
|
options = {docs: @level.get('documentation'), supermodel: @supermodel}
|
|
|
|
@openModalView(new DocsModal(options))
|
|
|
|
|
|
|
|
showMultiplayerModal: ->
|
2014-02-13 13:16:27 -05:00
|
|
|
@openModalView(new MultiplayerModal(session: @session, playableTeams: @playableTeams, level: @level))
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
showRestartModal: ->
|
|
|
|
@openModalView(new ReloadModal())
|