2014-07-23 10:02:45 -04:00
|
|
|
SpellListEntryView = require './SpellListEntryView'
|
|
|
|
ThangAvatarView = require 'views/play/level/ThangAvatarView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/play/level/tome/spell_list_tab_entry'
|
2014-02-13 19:09:32 -05:00
|
|
|
LevelComponent = require 'models/LevelComponent'
|
2014-07-23 10:02:45 -04:00
|
|
|
DocFormatter = require './DocFormatter'
|
2014-07-23 08:38:12 -04:00
|
|
|
filters = require 'lib/image_filter'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
module.exports = class SpellListTabEntryView extends SpellListEntryView
|
|
|
|
template: template
|
|
|
|
id: 'spell-list-tab-entry-view'
|
|
|
|
|
|
|
|
subscriptions:
|
2014-08-27 15:24:03 -04:00
|
|
|
'level:disable-controls': 'onDisableControls'
|
|
|
|
'level:enable-controls': 'onEnableControls'
|
2014-06-30 22:16:26 -04:00
|
|
|
'tome:spell-loaded': 'onSpellLoaded'
|
|
|
|
'tome:spell-changed': 'onSpellChanged'
|
2014-01-15 16:04:48 -05:00
|
|
|
'god:new-world-created': 'onNewWorld'
|
2014-06-26 01:56:39 -04:00
|
|
|
'tome:spell-changed-language': 'onSpellChangedLanguage'
|
2014-08-27 21:43:17 -04:00
|
|
|
'tome:toggle-maximize': 'onToggleMaximize'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
|
|
|
'click .spell-list-button': 'onDropdownClick'
|
|
|
|
'click .reload-code': 'onCodeReload'
|
2014-02-22 20:18:58 -05:00
|
|
|
'click .beautify-code': 'onBeautifyClick'
|
2014-08-27 21:43:17 -04:00
|
|
|
'click .fullscreen-code': 'onToggleMaximize'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
context = super context
|
2014-08-27 20:26:56 -04:00
|
|
|
ctrl = if @isMac() then 'Cmd' else 'Ctrl'
|
|
|
|
shift = $.i18n.t 'keyboard_shortcuts.shift'
|
|
|
|
context.beautifyShortcutVerbose = "#{ctrl}+#{shift}+B: #{$.i18n.t 'keyboard_shortcuts.beautify'}"
|
|
|
|
context.maximizeShortcutVerbose = "#{ctrl}+#{shift}+M: #{$.i18n.t 'keyboard_shortcuts.maximize_editor'}"
|
2014-01-03 13:32:13 -05:00
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@$el.addClass 'spell-tab'
|
2014-07-23 09:50:47 -04:00
|
|
|
@attachTransitionEventListener()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-01-15 16:04:48 -05:00
|
|
|
onNewWorld: (e) ->
|
|
|
|
@thang = e.world.thangMap[@thang.id] if @thang
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
setThang: (thang) ->
|
|
|
|
return if thang.id is @thang?.id
|
|
|
|
@thang = thang
|
|
|
|
@spellThang = @spell.thangs[@thang.id]
|
|
|
|
@buildAvatar()
|
|
|
|
@buildDocs() unless @docsBuilt
|
|
|
|
|
|
|
|
buildAvatar: ->
|
2014-01-09 17:04:46 -05:00
|
|
|
avatar = new ThangAvatarView thang: @thang, includeName: false, supermodel: @supermodel
|
2014-01-03 13:32:13 -05:00
|
|
|
if @avatar
|
|
|
|
@avatar.$el.replaceWith avatar.$el
|
|
|
|
@avatar.destroy()
|
|
|
|
else
|
|
|
|
@$el.find('.thang-avatar-placeholder').replaceWith avatar.$el
|
|
|
|
@avatar = avatar
|
|
|
|
@avatar.render()
|
|
|
|
|
|
|
|
buildDocs: ->
|
|
|
|
@docsBuilt = true
|
2014-02-13 19:09:32 -05:00
|
|
|
lcs = @supermodel.getModels LevelComponent
|
|
|
|
found = false
|
|
|
|
for lc in lcs when not found
|
|
|
|
for doc in lc.get('propertyDocumentation') ? []
|
|
|
|
if doc.name is @spell.name
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
return unless found
|
2014-07-15 22:25:53 -04:00
|
|
|
docFormatter = new DocFormatter doc: doc, thang: @thang, language: @options.language, selectedMethod: true
|
2014-02-14 19:08:01 -05:00
|
|
|
@$el.find('code').popover(
|
2014-02-13 19:09:32 -05:00
|
|
|
animation: true
|
|
|
|
html: true
|
2014-02-20 13:39:16 -05:00
|
|
|
placement: 'bottom'
|
2014-02-13 19:09:32 -05:00
|
|
|
trigger: 'hover'
|
2014-06-26 01:56:39 -04:00
|
|
|
content: docFormatter.formatPopover()
|
2014-02-13 19:09:32 -05:00
|
|
|
container: @$el.parent()
|
2014-09-11 11:38:30 -04:00
|
|
|
).on 'show.bs.popover', =>
|
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: "spell-tab-entry-open", volume: 0.75
|
2014-02-13 19:09:32 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
onMouseEnterAvatar: (e) -> # Don't call super
|
|
|
|
onMouseLeaveAvatar: (e) -> # Don't call super
|
|
|
|
onClick: (e) -> # Don't call super
|
2014-07-23 08:38:12 -04:00
|
|
|
onDisableControls: (e) -> @toggleControls e, false
|
|
|
|
onEnableControls: (e) -> @toggleControls e, true
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onDropdownClick: (e) ->
|
2014-02-24 14:21:51 -05:00
|
|
|
return unless @controlsEnabled
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'tome:toggle-spell-list', {}
|
2014-09-05 15:39:30 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'spell-list-open', volume: 1
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-08-27 20:26:56 -04:00
|
|
|
onCodeReload: (e) ->
|
2014-02-24 14:21:51 -05:00
|
|
|
return unless @controlsEnabled
|
2014-06-30 22:16:26 -04:00
|
|
|
Backbone.Mediator.publish 'tome:reload-code', spell: @spell
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-08-27 20:26:56 -04:00
|
|
|
onBeautifyClick: (e) ->
|
2014-02-24 14:21:51 -05:00
|
|
|
return unless @controlsEnabled
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'tome:spell-beautify', spell: @spell
|
2014-02-22 20:18:58 -05:00
|
|
|
|
2014-08-27 21:43:17 -04:00
|
|
|
onToggleMaximize: (e) ->
|
2014-08-14 16:29:57 -04:00
|
|
|
$codearea = $('html')
|
|
|
|
$('#code-area').css 'z-index', 20 unless $codearea.hasClass 'fullscreen-editor'
|
|
|
|
$('html').toggleClass 'fullscreen-editor'
|
2014-07-23 08:38:12 -04:00
|
|
|
$('.fullscreen-code').toggleClass 'maximized'
|
2014-08-27 21:43:17 -04:00
|
|
|
Backbone.Mediator.publish 'tome:maximize-toggled', {}
|
2014-07-09 16:41:42 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
updateReloadButton: ->
|
|
|
|
changed = @spell.hasChanged null, @spell.getSource()
|
|
|
|
@$el.find('.reload-code').css('display', if changed then 'inline-block' else 'none')
|
|
|
|
|
|
|
|
onSpellLoaded: (e) ->
|
|
|
|
return unless e.spell is @spell
|
|
|
|
@updateReloadButton()
|
|
|
|
|
|
|
|
onSpellChanged: (e) ->
|
|
|
|
return unless e.spell is @spell
|
|
|
|
@updateReloadButton()
|
|
|
|
|
2014-06-26 01:56:39 -04:00
|
|
|
onSpellChangedLanguage: (e) ->
|
|
|
|
return unless e.spell is @spell
|
|
|
|
@options.language = e.language
|
|
|
|
@$el.find('code').popover 'destroy'
|
|
|
|
@render()
|
|
|
|
@docsBuilt = false
|
|
|
|
@buildDocs() if @thang
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
toggleControls: (e, enabled) ->
|
|
|
|
# Don't call super; do it differently
|
|
|
|
return if e.controls and not ('editor' in e.controls)
|
|
|
|
return if enabled is @controlsEnabled
|
|
|
|
@controlsEnabled = enabled
|
|
|
|
@$el.toggleClass 'read-only', not enabled
|
2014-07-23 08:38:12 -04:00
|
|
|
@toggleBackground()
|
|
|
|
|
|
|
|
toggleBackground: =>
|
|
|
|
# TODO: make the palette background an actual background and do the CSS trick
|
|
|
|
# used in spell_list_entry.sass for disabling
|
|
|
|
background = @$el.find('img.spell-tab-image-hidden')[0]
|
|
|
|
if background.naturalWidth is 0 # not loaded yet
|
|
|
|
return _.delay @toggleBackground, 100
|
|
|
|
filters.revertImage background, '.spell-list-entry-view.spell-tab' if @controlsEnabled
|
|
|
|
filters.darkenImage background, '.spell-list-entry-view.spell-tab', 0.8 unless @controlsEnabled
|
2014-02-11 15:02:49 -05:00
|
|
|
|
2014-07-23 09:50:47 -04:00
|
|
|
attachTransitionEventListener: =>
|
|
|
|
transitionListener = ''
|
|
|
|
testEl = document.createElement 'fakeelement'
|
2014-08-27 15:24:03 -04:00
|
|
|
transitions =
|
2014-07-23 09:50:47 -04:00
|
|
|
'transition':'transitionend'
|
|
|
|
'OTransition':'oTransitionEnd'
|
|
|
|
'MozTransition':'transitionend'
|
|
|
|
'WebkitTransition':'webkitTransitionEnd'
|
|
|
|
for transition, transitionEvent of transitions
|
|
|
|
unless testEl.style[transition] is undefined
|
|
|
|
transitionListener = transitionEvent
|
|
|
|
break
|
|
|
|
$codearea = $('#code-area')
|
|
|
|
$codearea.on transitionListener, =>
|
2014-08-14 16:29:57 -04:00
|
|
|
$codearea.css 'z-index', 1 unless $('html').hasClass 'fullscreen-editor'
|
2014-07-23 09:50:47 -04:00
|
|
|
|
|
|
|
|
2014-02-11 15:02:49 -05:00
|
|
|
destroy: ->
|
|
|
|
@avatar?.destroy()
|
2014-02-16 18:30:00 -05:00
|
|
|
@$el.find('code').popover 'destroy'
|
2014-02-12 21:54:45 -05:00
|
|
|
super()
|