2014-08-08 14:36:41 -04:00
|
|
|
ModalView = require 'views/kinds/ModalView'
|
|
|
|
template = require 'templates/game-menu/game-menu-modal'
|
|
|
|
submenuViews = [
|
|
|
|
require 'views/game-menu/InventoryView'
|
|
|
|
require 'views/game-menu/ChooseHeroView'
|
|
|
|
require 'views/game-menu/SaveLoadView'
|
|
|
|
require 'views/game-menu/OptionsView'
|
|
|
|
require 'views/game-menu/GuideView'
|
|
|
|
require 'views/game-menu/MultiplayerView'
|
|
|
|
]
|
|
|
|
|
|
|
|
module.exports = class GameMenuModal extends ModalView
|
|
|
|
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-09-11 11:38:30 -04:00
|
|
|
|
2014-08-12 12:13:23 -04:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@options.showDevBits = me.isAdmin() or /https?:\/\/localhost/.test(window.location.href)
|
2014-10-18 17:51:43 -04:00
|
|
|
@options.showInventory = @options.level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop']
|
2014-10-31 19:33:43 -04:00
|
|
|
@options.showTab = options.showTab
|
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-08-12 12:13:23 -04:00
|
|
|
context.showDevBits = @options.showDevBits
|
2014-09-02 00:10:45 -04:00
|
|
|
context.showInventory = @options.showInventory
|
2014-10-31 19:33:43 -04:00
|
|
|
context.showTab = @options.showTab
|
2014-10-28 19:30:40 -04:00
|
|
|
docs = @options.level.get('documentation') ? {}
|
|
|
|
context.showsGuide = docs.specificArticles?.length or docs.generalArticles?.length
|
2014-08-08 14:36:41 -04:00
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@insertSubView new submenuView @options for submenuView in submenuViews
|
2014-10-31 19:33:43 -04:00
|
|
|
if @options.showTab
|
|
|
|
firstView = switch @options.showTab
|
|
|
|
when 'multiplayer' then @subviews.multiplayer_view
|
|
|
|
unless firstView?
|
|
|
|
firstView = (if @options.showInventory then @subviews.inventory_view else @subviews.choose_hero_view)
|
2014-09-21 02:06:28 -04:00
|
|
|
firstView.$el.addClass 'active'
|
|
|
|
firstView.onShown?()
|
2014-09-05 15:39:30 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-open', volume: 1
|
2014-08-10 18:56:34 -04:00
|
|
|
|
2014-09-21 02:06:28 -04:00
|
|
|
onTabShown: (e) ->
|
2014-09-11 11:38:30 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-tab-switch', volume: 1
|
2014-09-21 02:06:28 -04:00
|
|
|
@subviews.inventory_view.selectedHero = @subviews.choose_hero_view.selectedHero
|
|
|
|
@subviews[e.target.hash.substring(1).replace(/-/g, '_')].onShown?()
|
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-09-20 19:04:13 -04:00
|
|
|
patchingMe = @updateConfig()
|
|
|
|
me.patch() unless patchingMe # Might need to patch for options menu, too
|
2014-09-11 11:38:30 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-close', volume: 1
|
2014-10-23 23:03:19 -04:00
|
|
|
Backbone.Mediator.publish 'music-player:exit-menu', {}
|
2014-09-20 18:18:21 -04:00
|
|
|
|
2014-09-20 19:04:13 -04:00
|
|
|
updateConfig: ->
|
2014-09-23 01:26:09 -04:00
|
|
|
sessionHeroConfig = @options.startingSessionHeroConfig
|
2014-09-20 18:18:21 -04:00
|
|
|
lastHeroConfig = me.get('heroConfig') ? {}
|
2014-09-22 23:15:51 -04:00
|
|
|
thangType = @subviews.choose_hero_view.selectedHero?.get 'original'
|
2014-09-20 18:18:21 -04:00
|
|
|
inventory = @subviews.inventory_view.getCurrentEquipmentConfig()
|
|
|
|
patchSession = patchMe = false
|
2014-09-22 23:15:51 -04:00
|
|
|
props = {}
|
2014-09-23 11:58:23 -04:00
|
|
|
if thangType or not sessionHeroConfig.thangType
|
|
|
|
props.thangType = thangType ? '529ffbf1cf1818f2be000001' # Default to Tharin if it somehow doesn't get set.
|
|
|
|
if _.size(inventory) or not sessionHeroConfig.inventory
|
|
|
|
props.inventory = inventory
|
2014-09-20 18:18:21 -04:00
|
|
|
for key, val of props when val
|
|
|
|
patchSession ||= not _.isEqual val, sessionHeroConfig[key]
|
|
|
|
patchMe ||= not _.isEqual val, lastHeroConfig[key]
|
|
|
|
sessionHeroConfig[key] = val
|
|
|
|
lastHeroConfig[key] = val
|
2014-09-20 19:04:13 -04:00
|
|
|
if (codeLanguage = @subviews.choose_hero_view.codeLanguage) and @subviews.choose_hero_view.codeLanguageChanged
|
|
|
|
patchSession ||= codeLanguage isnt @options.session.get('codeLanguage')
|
|
|
|
patchMe ||= codeLanguage isnt me.get('aceConfig')?.language
|
|
|
|
@options.session.set 'codeLanguage', codeLanguage
|
|
|
|
aceConfig = me.get('aceConfig', true) ? {}
|
|
|
|
aceConfig.language = codeLanguage
|
|
|
|
me.set 'aceConfig', aceConfig
|
2014-09-22 23:15:51 -04:00
|
|
|
console.log 'update config from game menu modal; props:', props, 'patch session?', patchSession, 'patch me?', patchMe
|
2014-09-20 18:18:21 -04:00
|
|
|
if patchSession
|
|
|
|
@options.session.set 'heroConfig', sessionHeroConfig
|
2014-09-21 23:19:27 -04:00
|
|
|
success = ->
|
2014-09-20 18:18:21 -04:00
|
|
|
_.defer -> Backbone.Mediator.publish 'level:hero-config-changed', {}
|
2014-09-21 23:19:27 -04:00
|
|
|
error = (model, res) ->
|
|
|
|
console.error 'error patching session', model, res, res.responseJSON, res.status, res.statusText
|
|
|
|
@options.session.patch success: success, error: error
|
2014-09-20 18:18:21 -04:00
|
|
|
if patchMe
|
|
|
|
me.set 'heroConfig', lastHeroConfig
|
|
|
|
me.patch()
|
|
|
|
patchMe
|