2014-07-17 20:20:11 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/play/level/hud'
|
|
|
|
prop_template = require 'templates/play/level/hud_prop'
|
|
|
|
action_template = require 'templates/play/level/hud_action'
|
2014-07-23 10:02:45 -04:00
|
|
|
DialogueAnimator = require './DialogueAnimator'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class LevelHUDView extends CocoView
|
2014-01-03 13:32:13 -05:00
|
|
|
id: 'thang-hud'
|
|
|
|
template: template
|
|
|
|
dialogueMode: false
|
2014-10-02 21:08:04 -04:00
|
|
|
showingActions: false
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'surface:frame-changed': 'onFrameChanged'
|
2014-08-27 15:24:03 -04:00
|
|
|
'level:disable-controls': 'onDisableControls'
|
|
|
|
'level:enable-controls': 'onEnableControls'
|
2014-01-03 13:32:13 -05:00
|
|
|
'surface:sprite-selected': 'onSpriteSelected'
|
|
|
|
'sprite:speech-updated': 'onSpriteDialogue'
|
2014-08-27 15:24:03 -04:00
|
|
|
'level:sprite-clear-dialogue': 'onSpriteClearDialogue'
|
2014-01-03 13:32:13 -05:00
|
|
|
'level:shift-space-pressed': 'onShiftSpacePressed'
|
2014-01-08 22:24:51 -05:00
|
|
|
'level:escape-pressed': 'onEscapePressed'
|
2014-08-27 15:24:03 -04:00
|
|
|
'sprite:dialogue-sound-completed': 'onDialogueSoundCompleted'
|
|
|
|
'sprite:thang-began-talking': 'onThangBeganTalking'
|
|
|
|
'sprite:thang-finished-talking': 'onThangFinishedTalking'
|
2014-01-15 16:04:48 -05:00
|
|
|
'god:new-world-created': 'onNewWorld'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
2014-02-16 18:30:00 -05:00
|
|
|
'click': 'onClick'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
afterRender: ->
|
2014-01-09 14:04:22 -05:00
|
|
|
super()
|
|
|
|
@$el.addClass 'no-selection'
|
2014-10-31 00:34:49 -04:00
|
|
|
if @options.level.get('slug') in ['dungeons-of-kithgard', 'gems-in-the-deep', 'forgetful-gemsmith', 'shadow-guard', 'kounter-kithwise', 'crawlways-of-kithgard', 'true-names', 'favorable-odds', 'the-raised-sword', 'the-first-kithmaze', 'descending-further', 'the-second-kithmaze', 'new-sight', 'known-enemy', 'master-of-names', 'lowly-kithmen', 'closing-the-distance', 'tactical-strike', 'the-final-kithmaze', 'the-gauntlet']
|
2014-10-30 19:59:32 -04:00
|
|
|
@hidesHUD = true
|
|
|
|
@$el.addClass 'hide-hud-properties'
|
2014-01-09 14:04:22 -05:00
|
|
|
|
2014-02-16 18:30:00 -05:00
|
|
|
onClick: (e) ->
|
2014-08-27 21:43:17 -04:00
|
|
|
Backbone.Mediator.publish 'tome:focus-editor', {} unless $(e.target).parents('.thang-props').length
|
2014-02-16 18:30:00 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
onFrameChanged: (e) ->
|
|
|
|
@timeProgress = e.progress
|
|
|
|
@update()
|
|
|
|
|
|
|
|
onDisableControls: (e) ->
|
|
|
|
return if e.controls and not ('hud' in e.controls)
|
|
|
|
@disabled = true
|
|
|
|
|
|
|
|
onEnableControls: (e) ->
|
|
|
|
return if e.controls and not ('hud' in e.controls)
|
|
|
|
@disabled = false
|
|
|
|
|
|
|
|
onSpriteSelected: (e) ->
|
|
|
|
# TODO: this allows the surface and HUD selection to get out of sync if we select another unit while in dialogue mode
|
|
|
|
return if @disabled or @dialogueMode
|
|
|
|
@switchToThangElements()
|
2014-01-09 14:04:22 -05:00
|
|
|
@setThang e.thang, e.sprite?.thangType
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onSpriteDialogue: (e) ->
|
|
|
|
return unless e.message
|
|
|
|
spriteID = e.sprite.thang.id
|
2014-01-09 14:04:22 -05:00
|
|
|
@setSpeaker e.sprite
|
|
|
|
@stage?.startTalking()
|
2014-01-03 13:32:13 -05:00
|
|
|
@setMessage(e.message, e.mood, e.responses)
|
|
|
|
window.tracker?.trackEvent 'Heard Sprite', {speaker: spriteID, message: e.message, label: e.message}, ['Google Analytics']
|
|
|
|
|
|
|
|
onDialogueSoundCompleted: ->
|
2014-01-09 14:04:22 -05:00
|
|
|
@stage?.stopTalking()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onSpriteClearDialogue: ->
|
|
|
|
@clearSpeaker()
|
|
|
|
|
2014-01-15 16:04:48 -05:00
|
|
|
onNewWorld: (e) ->
|
2014-02-25 15:39:22 -05:00
|
|
|
hadThang = @thang
|
2014-01-15 16:04:48 -05:00
|
|
|
@thang = e.world.thangMap[@thang.id] if @thang
|
2014-02-25 15:39:22 -05:00
|
|
|
if hadThang and not @thang
|
2014-02-05 18:54:34 -05:00
|
|
|
@setThang null, null
|
2014-08-22 17:59:32 -04:00
|
|
|
else if @thang
|
|
|
|
@createActions() # Make sure it updates its actions.
|
2014-01-15 16:04:48 -05:00
|
|
|
|
2014-01-09 14:04:22 -05:00
|
|
|
setThang: (thang, thangType) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
unless @speaker
|
|
|
|
if not thang? and not @thang? then return
|
|
|
|
if thang? and @thang? and thang.id is @thang.id then return
|
2014-01-09 21:30:18 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
@thang = thang
|
2014-01-09 14:04:22 -05:00
|
|
|
@thangType = thangType
|
2014-01-03 13:32:13 -05:00
|
|
|
@$el.toggleClass 'no-selection', not @thang?
|
|
|
|
clearTimeout @hintNextSelectionTimeout
|
|
|
|
@$el.find('.no-selection-message').hide()
|
|
|
|
if not @thang
|
2014-10-18 17:51:43 -04:00
|
|
|
unless @options.level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop']
|
2014-10-15 01:38:22 -04:00
|
|
|
@hintNextSelectionTimeout = _.delay((=> @$el.find('.no-selection-message').slideDown('slow')), 10000)
|
2014-01-03 13:32:13 -05:00
|
|
|
return
|
2014-01-15 18:16:31 -05:00
|
|
|
@createAvatar thangType, @thang
|
2014-01-03 13:32:13 -05:00
|
|
|
@createProperties()
|
|
|
|
@createActions()
|
|
|
|
@update()
|
|
|
|
@speaker = null
|
|
|
|
|
2014-01-09 14:04:22 -05:00
|
|
|
setSpeaker: (speakerSprite) ->
|
|
|
|
return if speakerSprite is @speakerSprite
|
|
|
|
@speakerSprite = speakerSprite
|
|
|
|
@speaker = @speakerSprite.thang.id
|
2014-02-19 16:43:44 -05:00
|
|
|
@createAvatar @speakerSprite.thangType, @speakerSprite.thang, @speakerSprite.options.colorConfig
|
2014-01-03 13:32:13 -05:00
|
|
|
@$el.removeClass 'no-selection'
|
|
|
|
@switchToDialogueElements()
|
|
|
|
|
|
|
|
clearSpeaker: ->
|
|
|
|
if not @thang
|
|
|
|
@$el.addClass 'no-selection'
|
2014-01-09 21:30:18 -05:00
|
|
|
@setThang @thang, @thangType
|
2014-01-03 13:32:13 -05:00
|
|
|
@switchToThangElements()
|
|
|
|
@speaker = null
|
2014-01-09 14:04:22 -05:00
|
|
|
@speakerSprite = null
|
2014-01-03 13:32:13 -05:00
|
|
|
@bubble = null
|
|
|
|
@update()
|
|
|
|
|
2014-02-19 16:43:44 -05:00
|
|
|
createAvatar: (thangType, thang, colorConfig) ->
|
2014-05-13 13:26:33 -04:00
|
|
|
unless thangType.isFullyLoaded()
|
|
|
|
args = arguments
|
|
|
|
unless @listeningToCreateAvatar
|
|
|
|
@listenToOnce thangType, 'sync', -> @createAvatar(args...)
|
|
|
|
@listeningToCreateAvatar = true
|
|
|
|
return
|
|
|
|
@listeningToCreateAvatar = false
|
2014-09-28 17:00:48 -04:00
|
|
|
options = thang.getLankOptions() or {}
|
2014-01-15 18:16:31 -05:00
|
|
|
options.async = false
|
2014-02-20 18:13:15 -05:00
|
|
|
options.colorConfig = colorConfig if colorConfig
|
2014-01-09 14:04:22 -05:00
|
|
|
wrapper = @$el.find '.thang-canvas-wrapper'
|
|
|
|
team = @thang?.team or @speakerSprite?.thang?.team
|
2014-01-30 15:03:33 -05:00
|
|
|
wrapper.removeClass (i, css) -> (css.match(/\bteam-\S+/g) or []).join ' '
|
|
|
|
wrapper.addClass "team-#{team}"
|
2014-05-02 20:03:30 -04:00
|
|
|
if thangType.get('raster')
|
|
|
|
wrapper.empty().append($('<img />').attr('src', '/file/'+thangType.get('raster')))
|
|
|
|
else
|
2014-06-19 11:06:34 -04:00
|
|
|
return unless stage = thangType.getPortraitStage options
|
2014-05-02 20:03:30 -04:00
|
|
|
newCanvas = $(stage.canvas).addClass('thang-canvas')
|
|
|
|
wrapper.empty().append(newCanvas)
|
|
|
|
stage.update()
|
|
|
|
@stage?.stopTalking()
|
|
|
|
@stage = stage
|
2014-01-09 14:04:22 -05:00
|
|
|
|
|
|
|
onThangBeganTalking: (e) ->
|
|
|
|
return unless @stage and @thang is e.thang
|
|
|
|
@stage?.startTalking()
|
|
|
|
|
|
|
|
onThangFinishedTalking: (e) ->
|
|
|
|
return unless @stage and @thang is e.thang
|
|
|
|
@stage?.stopTalking()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
createProperties: ->
|
|
|
|
props = @$el.find('.thang-props')
|
2014-06-30 22:16:26 -04:00
|
|
|
props.find(':not(.thang-name)').remove()
|
2014-09-22 17:05:13 -04:00
|
|
|
if @thang.id is 'Hero Placeholder'
|
|
|
|
name = {knight: 'Tharin', captain: 'Anya'}[@thang.type] ? 'Hero'
|
|
|
|
else
|
|
|
|
name = if @thang.type then "#{@thang.id} - #{@thang.type}" else @thang.id
|
|
|
|
props.find('.thang-name').text name
|
2014-03-10 12:37:05 -04:00
|
|
|
propNames = _.without @thang.hudProperties ? [], 'action'
|
2014-03-03 19:45:03 -05:00
|
|
|
nColumns = Math.ceil propNames.length / 5
|
|
|
|
columns = ($('<div class="thang-props-column"></div>').appendTo(props) for i in [0 ... nColumns])
|
|
|
|
for prop, i in propNames
|
2014-03-01 14:06:44 -05:00
|
|
|
continue if prop is 'action'
|
2014-01-03 13:32:13 -05:00
|
|
|
pel = @createPropElement prop
|
|
|
|
continue unless pel?
|
|
|
|
if pel.find('.bar').is('*') and props.find('.bar').is('*')
|
|
|
|
props.find('.bar-prop').last().after pel # Keep bars together
|
|
|
|
else
|
2014-03-03 19:45:03 -05:00
|
|
|
columns[i % nColumns].append pel
|
2014-03-01 14:06:44 -05:00
|
|
|
null
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
createActions: ->
|
|
|
|
actions = @$el.find('.thang-actions tbody').empty()
|
2014-03-28 18:23:12 -04:00
|
|
|
showActions = @thang.world and not @thang.notOfThisWorld and not _.isEmpty(@thang.actions) and 'action' in (@thang.hudProperties ? [])
|
2014-03-08 18:43:56 -05:00
|
|
|
@$el.find('.thang-actions').toggleClass 'secret', not showActions
|
2014-10-02 21:08:04 -04:00
|
|
|
@showingActions = showActions
|
2014-02-28 14:38:41 -05:00
|
|
|
return unless showActions
|
2014-01-03 13:32:13 -05:00
|
|
|
@buildActionTimespans()
|
|
|
|
for actionName, action of @thang.actions
|
|
|
|
actions.append @createActionElement(actionName)
|
|
|
|
@lastActionTimespans[actionName] = {}
|
|
|
|
|
|
|
|
setMessage: (message, mood, responses) ->
|
|
|
|
message = marked message
|
2014-05-02 18:51:07 -04:00
|
|
|
# Fix old HTML icons like <i class='icon-play'></i> in the Markdown
|
|
|
|
message = message.replace /<i class='(.+?)'><\/i>/, "<i class='$1'></i>"
|
2014-01-03 13:32:13 -05:00
|
|
|
clearInterval(@messageInterval) if @messageInterval
|
|
|
|
@bubble = $('.dialogue-bubble', @$el)
|
|
|
|
@bubble.removeClass(@lastMood) if @lastMood
|
|
|
|
@lastMood = mood
|
|
|
|
@bubble.text('')
|
2014-02-13 12:26:21 -05:00
|
|
|
group = $('<div class="enter secret"></div>')
|
2014-01-03 13:32:13 -05:00
|
|
|
@bubble.append(group)
|
|
|
|
if responses
|
|
|
|
@lastResponses = responses
|
|
|
|
for response in responses
|
|
|
|
button = $('<button class="btn btn-small banner"></button>').text(response.text)
|
|
|
|
button.addClass response.buttonClass if response.buttonClass
|
|
|
|
group.append(button)
|
|
|
|
response.button = $('button:last', group)
|
|
|
|
else
|
2014-11-01 18:57:42 -04:00
|
|
|
if @options.level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop']
|
|
|
|
s = $.i18n.t('play_level.hud_continue_short', defaultValue: 'Continue')
|
|
|
|
else
|
|
|
|
s = $.i18n.t('play_level.hud_continue', defaultValue: 'Continue (shift+space)') # Get rid of eventually
|
2014-06-30 22:16:26 -04:00
|
|
|
sk = $.i18n.t('play_level.skip_tutorial', defaultValue: 'skip: esc')
|
2014-03-05 13:06:18 -05:00
|
|
|
if not @escapePressed
|
|
|
|
group.append('<span class="hud-hint">' + sk + '</span>')
|
2014-01-03 13:32:13 -05:00
|
|
|
group.append($('<button class="btn btn-small banner with-dot">' + s + ' <div class="dot"></div></button>'))
|
|
|
|
@lastResponses = null
|
2014-09-23 01:26:09 -04:00
|
|
|
if @speaker is 'Hero Placeholder'
|
2014-09-23 02:01:19 -04:00
|
|
|
# Doesn't work if it fires from a script; we don't really know who we are then.
|
2014-09-23 01:26:09 -04:00
|
|
|
name = {knight: 'Tharin', captain: 'Anya'}[@speakerSprite?.thang?.id] ? 'Hero'
|
|
|
|
else
|
|
|
|
name = @speaker
|
|
|
|
@bubble.append($("<h3>#{name}</h3>"))
|
2014-01-03 13:32:13 -05:00
|
|
|
@animator = new DialogueAnimator(message, @bubble)
|
2014-08-26 15:39:30 -04:00
|
|
|
@messageInterval = setInterval(@addMoreMessage, 1000 / 30) # 30 FPS
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
addMoreMessage: =>
|
|
|
|
if @animator.done()
|
|
|
|
clearInterval(@messageInterval)
|
|
|
|
@messageInterval = null
|
2014-06-30 22:16:26 -04:00
|
|
|
$('.enter', @bubble).removeClass('secret').css('opacity', 0.0).delay(500).animate({opacity: 1.0}, 500, @animateEnterButton)
|
2014-01-03 13:32:13 -05:00
|
|
|
if @lastResponses
|
|
|
|
buttons = $('.enter button')
|
|
|
|
for response, i in @lastResponses
|
2014-08-28 12:52:51 -04:00
|
|
|
channel = response.channel.replace 'level-set-playing', 'level:set-playing' # Easier than migrating all those victory buttons.
|
|
|
|
f = (r) => => setTimeout((-> Backbone.Mediator.publish(channel, r.event or {})), 10)
|
2014-01-03 13:32:13 -05:00
|
|
|
$(buttons[i]).click(f(response))
|
|
|
|
else
|
2014-08-27 21:43:17 -04:00
|
|
|
$('.enter', @bubble).click(-> Backbone.Mediator.publish('script:end-current-script', {}))
|
2014-01-03 13:32:13 -05:00
|
|
|
return
|
|
|
|
@animator.tick()
|
|
|
|
|
|
|
|
onShiftSpacePressed: (e) ->
|
2014-01-08 17:23:36 -05:00
|
|
|
@shiftSpacePressed = (@shiftSpacePressed || 0) + 1
|
2014-08-27 15:24:03 -04:00
|
|
|
# We don't need to handle script:end-current-script--that's done--but if we do have
|
2014-01-03 13:32:13 -05:00
|
|
|
# custom buttons, then we need to trigger the one that should fire (the last one).
|
|
|
|
# If we decide that always having the last one fire is bad, we should make it smarter.
|
|
|
|
return unless @lastResponses?.length
|
|
|
|
r = @lastResponses[@lastResponses.length - 1]
|
2014-08-28 12:52:51 -04:00
|
|
|
channel = r.channel.replace 'level-set-playing', 'level:set-playing'
|
|
|
|
_.delay (-> Backbone.Mediator.publish(channel, r.event or {})), 10
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-01-08 22:24:51 -05:00
|
|
|
onEscapePressed: (e) ->
|
|
|
|
@escapePressed = true
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
animateEnterButton: =>
|
|
|
|
return unless @bubble
|
|
|
|
button = $('.enter', @bubble)
|
|
|
|
dot = $('.dot', button)
|
2014-06-30 22:16:26 -04:00
|
|
|
dot.animate({opacity: 0.2}, 300).animate({opacity: 1.9}, 600, @animateEnterButton)
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
switchToDialogueElements: ->
|
|
|
|
@dialogueMode = true
|
2014-02-13 12:26:21 -05:00
|
|
|
$('.thang-elem', @$el).addClass('secret')
|
|
|
|
@$el.find('.thang-canvas-wrapper').removeClass('secret')
|
2014-01-03 13:32:13 -05:00
|
|
|
$('.dialogue-area', @$el)
|
2014-02-13 12:26:21 -05:00
|
|
|
.removeClass('secret')
|
2014-06-30 22:16:26 -04:00
|
|
|
.animate({opacity: 1.0}, 200)
|
2014-01-03 13:32:13 -05:00
|
|
|
$('.dialogue-bubble', @$el)
|
|
|
|
.css('opacity', 0.0)
|
|
|
|
.delay(200)
|
2014-06-30 22:16:26 -04:00
|
|
|
.animate({opacity: 1.0}, 200)
|
2014-01-03 13:32:13 -05:00
|
|
|
clearTimeout @hintNextSelectionTimeout
|
|
|
|
|
|
|
|
switchToThangElements: ->
|
|
|
|
@dialogueMode = false
|
2014-02-13 12:26:21 -05:00
|
|
|
$('.thang-elem', @$el).removeClass('secret')
|
|
|
|
$('.dialogue-area', @$el).addClass('secret')
|
2014-10-02 21:08:04 -04:00
|
|
|
$('.thang-actions', @$el).toggleClass 'secret', not @showingActions
|
2014-10-30 19:59:32 -04:00
|
|
|
@$el.find('.thang-canvas-wrapper').addClass('secret') if @hidesHUD
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
update: ->
|
|
|
|
return unless @thang and not @speaker
|
2014-03-13 18:35:28 -04:00
|
|
|
@$el.find('.thang-props-column').toggleClass 'nonexistent', not @thang.exists
|
|
|
|
if @thang.exists
|
|
|
|
@updatePropElement(prop, @thang[prop]) for prop in @thang.hudProperties ? []
|
2014-01-03 13:32:13 -05:00
|
|
|
# Update action timeline
|
|
|
|
@updateActions()
|
|
|
|
|
|
|
|
createPropElement: (prop) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
if prop in ['maxHealth']
|
2014-01-03 13:32:13 -05:00
|
|
|
return null # included in the bar
|
|
|
|
context =
|
|
|
|
prop: prop
|
2014-09-04 18:14:27 -04:00
|
|
|
hasIcon: prop in ['health', 'pos', 'target', 'collectedThangIDs', 'gold', 'bountyGold', 'visualRange', 'attackDamage', 'attackRange', 'maxSpeed', 'attackNearbyEnemyRange']
|
2014-06-30 22:16:26 -04:00
|
|
|
hasBar: prop in ['health']
|
2014-01-03 13:32:13 -05:00
|
|
|
$(prop_template(context))
|
|
|
|
|
|
|
|
updatePropElement: (prop, val) ->
|
|
|
|
pel = @$el.find '.thang-props *[name=' + prop + ']'
|
2014-06-30 22:16:26 -04:00
|
|
|
if prop in ['maxHealth']
|
2014-03-01 14:06:44 -05:00
|
|
|
return # Don't show maxes--they're built into bar labels.
|
2014-06-30 22:16:26 -04:00
|
|
|
if prop in ['health']
|
|
|
|
max = @thang['max' + prop.charAt(0).toUpperCase() + prop.slice(1)]
|
|
|
|
regen = @thang[prop + 'ReplenishRate']
|
2014-01-03 13:32:13 -05:00
|
|
|
percent = Math.round 100 * val / max
|
2014-06-30 22:16:26 -04:00
|
|
|
pel.find('.bar').css 'width', percent + '%'
|
|
|
|
labelText = prop + ': ' + @formatValue(prop, val) + ' / ' + @formatValue(prop, max)
|
2014-01-03 13:32:13 -05:00
|
|
|
if regen
|
2014-06-30 22:16:26 -04:00
|
|
|
labelText += ' (+' + @formatValue(prop, regen) + '/s)'
|
2014-03-03 19:45:03 -05:00
|
|
|
pel.find('.bar-prop-value').text(Math.round(max)) if max
|
2014-01-03 13:32:13 -05:00
|
|
|
else
|
|
|
|
s = @formatValue(prop, val)
|
2014-03-01 14:06:44 -05:00
|
|
|
labelText = "#{prop}: #{s}"
|
|
|
|
if prop is 'attackDamage'
|
|
|
|
cooldown = @thang.actions.attack.cooldown
|
|
|
|
dps = @thang.attackDamage / cooldown
|
|
|
|
labelText += " / #{cooldown.toFixed(2)}s (DPS: #{dps.toFixed(2)})"
|
2014-01-03 13:32:13 -05:00
|
|
|
pel.find('.prop-value').text s
|
2014-03-01 14:06:44 -05:00
|
|
|
pel.attr 'title', labelText
|
2014-01-03 13:32:13 -05:00
|
|
|
pel
|
|
|
|
|
|
|
|
formatValue: (prop, val) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
if prop is 'target' and not val
|
|
|
|
val = @thang['targetPos']
|
2014-01-03 13:32:13 -05:00
|
|
|
val = null if val?.isZero()
|
2014-06-30 22:16:26 -04:00
|
|
|
if prop is 'rotation'
|
|
|
|
return (val * 180 / Math.PI).toFixed(0) + '˚'
|
2014-03-01 14:06:44 -05:00
|
|
|
if prop.search(/Range$/) isnt -1
|
|
|
|
return val + 'm'
|
2014-01-03 13:32:13 -05:00
|
|
|
if typeof val is 'number'
|
2014-02-26 21:09:09 -05:00
|
|
|
if Math.round(val) == val or prop is 'gold' then return val.toFixed(0) # int
|
2014-01-03 13:32:13 -05:00
|
|
|
if -10 < val < 10 then return val.toFixed(2)
|
|
|
|
if -100 < val < 100 then return val.toFixed(1)
|
|
|
|
return val.toFixed(0)
|
2014-06-30 22:16:26 -04:00
|
|
|
if val and typeof val is 'object'
|
2014-01-03 13:32:13 -05:00
|
|
|
if val.id
|
|
|
|
return val.id
|
|
|
|
else if val.x and val.y
|
2014-01-29 11:38:37 -05:00
|
|
|
return "x: #{val.x.toFixed(0)} y: #{val.y.toFixed(0)}"
|
|
|
|
#return "x: #{val.x.toFixed(0)} y: #{val.y.toFixed(0)}, z: #{val.z.toFixed(0)}" # Debugging: include z
|
2014-01-03 13:32:13 -05:00
|
|
|
else if not val?
|
2014-06-30 22:16:26 -04:00
|
|
|
return 'No ' + prop
|
2014-01-03 13:32:13 -05:00
|
|
|
return val
|
|
|
|
|
|
|
|
updateActions: ->
|
2014-10-02 21:08:04 -04:00
|
|
|
return unless @thang.world and @showingActions and not _.isEmpty @thang.actions
|
2014-01-03 13:32:13 -05:00
|
|
|
@buildActionTimespans() unless @timespans
|
|
|
|
for actionName, action of @thang.actions
|
2014-02-05 18:54:34 -05:00
|
|
|
@updateActionElement(actionName, @timespans[actionName], @thang.action is actionName)
|
2014-01-03 13:32:13 -05:00
|
|
|
tableContainer = @$el.find('.table-container')
|
|
|
|
arrow = tableContainer.find('.progress-arrow')
|
2014-04-28 19:31:51 -04:00
|
|
|
@timelineWidth ||= tableContainer.find('tr:not(.secret) .action-timeline').width()
|
|
|
|
@actionArrowWidth ||= arrow.width()
|
|
|
|
right = (1 - (@timeProgress ? 0)) * @timelineWidth
|
|
|
|
arrow.css 'right', right - @actionArrowWidth / 2
|
2014-01-03 13:32:13 -05:00
|
|
|
tableContainer.find('.progress-line').css 'right', right
|
|
|
|
|
|
|
|
buildActionTimespans: ->
|
|
|
|
@lastActionTimespans = {}
|
|
|
|
@timespans = {}
|
|
|
|
dt = @thang.world.dt
|
|
|
|
actionHistory = @thang.world.actionsForThang @thang.id, true
|
2014-03-10 12:37:05 -04:00
|
|
|
[lastFrame, lastAction] = [0, null]
|
2014-01-03 13:32:13 -05:00
|
|
|
for hist in actionHistory.concat {frame: @thang.world.totalFrames, name: 'END'}
|
|
|
|
[newFrame, newAction] = [hist.frame, hist.name]
|
|
|
|
continue if newAction is lastAction
|
2014-03-10 12:37:05 -04:00
|
|
|
if newFrame > lastFrame and lastAction
|
2014-02-06 19:05:41 -05:00
|
|
|
# TODO: don't push it if it didn't exist until then
|
2014-01-03 13:32:13 -05:00
|
|
|
(@timespans[lastAction] ?= []).push [lastFrame * dt, newFrame * dt]
|
|
|
|
[lastFrame, lastAction] = [newFrame, newAction]
|
|
|
|
|
|
|
|
createActionElement: (action) ->
|
|
|
|
$(action_template(action: action))
|
|
|
|
|
|
|
|
updateActionElement: (action, timespans, current) ->
|
|
|
|
ael = @$el.find '.thang-actions *[name=' + action + ']'
|
|
|
|
ael.toggleClass 'current-action', current
|
|
|
|
|
|
|
|
timespans ?= []
|
|
|
|
lastTimespans = @lastActionTimespans[action] ? []
|
|
|
|
if @lastActionTimespans and timespans.length is lastTimespans.length
|
|
|
|
changed = false
|
|
|
|
for timespan, i in timespans
|
|
|
|
if timespan[0] isnt lastTimespans[i][0] or timespan[1] isnt lastTimespans[i][1]
|
|
|
|
changed = true
|
|
|
|
break
|
|
|
|
return unless changed
|
2014-02-13 12:26:21 -05:00
|
|
|
ael.toggleClass 'secret', not timespans.length
|
2014-01-03 13:32:13 -05:00
|
|
|
@lastActionTimespans[action] = timespans
|
|
|
|
timeline = ael.find('.action-timeline .timeline-wrapper').empty()
|
|
|
|
lifespan = @thang.world.totalFrames / @thang.world.frameRate
|
|
|
|
scale = timeline.width() / lifespan
|
|
|
|
for [start, end] in timespans
|
|
|
|
bar = $('<div></div>').css left: start * scale, right: (lifespan - end) * scale
|
|
|
|
timeline.append bar
|
|
|
|
|
|
|
|
ael
|
2014-01-09 14:04:22 -05:00
|
|
|
|
|
|
|
destroy: ->
|
2014-01-09 14:05:51 -05:00
|
|
|
@stage?.stopTalking()
|
2014-02-11 17:58:45 -05:00
|
|
|
clearInterval(@messageInterval) if @messageInterval
|
2014-02-25 17:46:48 -05:00
|
|
|
clearTimeout @hintNextSelectionTimeout if @hintNextSelectionTimeout
|
2014-02-14 13:57:47 -05:00
|
|
|
super()
|