2014-11-28 20:49:41 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
2016-02-25 18:24:16 -05:00
|
|
|
CreateAccountModal = require 'views/core/CreateAccountModal'
|
2014-11-29 15:46:04 -05:00
|
|
|
template = require 'templates/play/menu/game-menu-modal'
|
2014-08-08 14:36:41 -04:00
|
|
|
submenuViews = [
|
2014-11-29 15:46:04 -05:00
|
|
|
require 'views/play/menu/SaveLoadView'
|
|
|
|
require 'views/play/menu/OptionsView'
|
|
|
|
require 'views/play/menu/GuideView'
|
2014-08-08 14:36:41 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
module.exports = class GameMenuModal extends ModalView
|
2014-11-07 11:54:22 -05:00
|
|
|
className: 'modal fade play-modal'
|
2014-08-08 14:36:41 -04:00
|
|
|
template: template
|
|
|
|
id: 'game-menu-modal'
|
2014-08-31 18:08:52 -04:00
|
|
|
instant: true
|
2014-08-08 14:36:41 -04:00
|
|
|
|
2014-09-11 11:38:30 -04:00
|
|
|
events:
|
|
|
|
'change input.select': 'onSelectionChanged'
|
2014-10-28 19:30:40 -04:00
|
|
|
'shown.bs.tab #game-menu-nav a': 'onTabShown'
|
2014-11-07 11:54:22 -05:00
|
|
|
'click #change-hero-tab': -> @trigger 'change-hero'
|
2014-11-18 16:57:20 -05:00
|
|
|
'click #close-modal': 'hide'
|
2014-12-08 16:13:30 -05:00
|
|
|
'click .auth-tab': 'onClickSignupButton'
|
2014-09-11 11:38:30 -04:00
|
|
|
|
2014-08-12 12:13:23 -04:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2015-10-27 16:21:39 -04:00
|
|
|
@level = @options.level
|
2014-09-21 16:26:56 -04:00
|
|
|
@options.levelID = @options.level.get('slug')
|
2014-09-23 01:26:09 -04:00
|
|
|
@options.startingSessionHeroConfig = $.extend {}, true, (@options.session.get('heroConfig') ? {})
|
2014-10-31 21:05:29 -04:00
|
|
|
Backbone.Mediator.publish 'music-player:enter-menu', terrain: @options.level.get('terrain', true) ? 'Dungeon'
|
2014-08-12 12:13:23 -04:00
|
|
|
|
2014-08-08 14:36:41 -04:00
|
|
|
getRenderData: (context={}) ->
|
|
|
|
context = super(context)
|
2014-10-28 19:30:40 -04:00
|
|
|
docs = @options.level.get('documentation') ? {}
|
2016-07-14 13:26:09 -04:00
|
|
|
submenus = ['guide', 'options', 'save-load']
|
2016-03-04 14:44:36 -05:00
|
|
|
submenus = _.without submenus, 'options' if window.serverConfig.picoCTF
|
2016-07-21 14:11:11 -04:00
|
|
|
unless window.serverConfig.picoCTF
|
|
|
|
if @level.isType('course', 'course-ladder') or not @options.level.get('helpVideos')?.length > 0
|
|
|
|
submenus = _.without submenus, 'guide'
|
2014-11-07 11:54:22 -05:00
|
|
|
submenus = _.without submenus, 'save-load' unless me.isAdmin() or /https?:\/\/localhost/.test(window.location.href)
|
2015-03-05 11:58:11 -05:00
|
|
|
@includedSubmenus = submenus
|
2014-11-07 11:54:22 -05:00
|
|
|
context.showTab = @options.showTab ? submenus[0]
|
|
|
|
context.submenus = submenus
|
|
|
|
context.iconMap =
|
|
|
|
'options': 'cog'
|
|
|
|
'guide': 'list'
|
|
|
|
'save-load': 'floppy-disk'
|
2014-08-08 14:36:41 -04:00
|
|
|
context
|
|
|
|
|
2015-10-27 16:21:39 -04:00
|
|
|
showsChooseHero: ->
|
2016-07-14 11:58:43 -04:00
|
|
|
return false if @level?.isType('course', 'course-ladder')
|
2016-01-26 16:20:23 -05:00
|
|
|
return false if @options.levelID in ['zero-sum', 'ace-of-coders', 'elemental-wars']
|
2015-10-27 16:21:39 -04:00
|
|
|
return true
|
|
|
|
|
2014-08-08 14:36:41 -04:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@insertSubView new submenuView @options for submenuView in submenuViews
|
2015-03-05 11:58:11 -05:00
|
|
|
firstView = switch @options.showTab
|
|
|
|
when 'guide' then @subviews.guide_view
|
|
|
|
else
|
|
|
|
if 'guide' in @includedSubmenus then @subviews.guide_view else @subviews.options_view
|
2014-09-21 02:06:28 -04:00
|
|
|
firstView.$el.addClass 'active'
|
|
|
|
firstView.onShown?()
|
2014-11-26 09:58:23 -05:00
|
|
|
@playSound 'game-menu-open'
|
2014-11-09 22:39:09 -05:00
|
|
|
@$el.find('.nano:visible').nanoScroller()
|
2014-08-10 18:56:34 -04:00
|
|
|
|
2014-09-21 02:06:28 -04:00
|
|
|
onTabShown: (e) ->
|
2014-11-26 09:58:23 -05:00
|
|
|
@playSound 'game-menu-tab-switch'
|
2014-12-18 01:26:23 -05:00
|
|
|
shownSubviewKey = e.target.hash.substring(1).replace(/-/g, '_')
|
|
|
|
@subviews[shownSubviewKey].onShown?()
|
|
|
|
subview.onHidden?() for subviewKey, subview of @subviews when subviewKey isnt shownSubviewKey
|
2014-09-11 11:38:30 -04:00
|
|
|
|
2014-08-10 18:56:34 -04:00
|
|
|
onHidden: ->
|
2014-09-17 21:56:08 -04:00
|
|
|
super()
|
2014-08-10 18:56:34 -04:00
|
|
|
subview.onHidden?() for subviewKey, subview of @subviews
|
2014-11-26 09:58:23 -05:00
|
|
|
@playSound 'game-menu-close'
|
2014-10-23 23:03:19 -04:00
|
|
|
Backbone.Mediator.publish 'music-player:exit-menu', {}
|
2015-03-05 11:58:11 -05:00
|
|
|
|
2014-12-08 16:13:30 -05:00
|
|
|
onClickSignupButton: (e) ->
|
|
|
|
window.tracker?.trackEvent 'Started Signup', category: 'Play Level', label: 'Game Menu', level: @options.levelID
|
|
|
|
# TODO: Default already seems to be prevented. Need to be explicit?
|
|
|
|
e.preventDefault()
|
2016-02-25 18:24:16 -05:00
|
|
|
@openModalView new CreateAccountModal()
|