From 54de8482f1405defa81a1f0a28ed8da42df9b783 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Thu, 16 Oct 2014 12:08:21 -0700 Subject: [PATCH] Spell palette now hugs the spell editor, which itself shrinks as needed. --- app/lib/aether_utils.coffee | 2 + app/styles/play/level/tome/problem_alert.sass | 3 +- app/styles/play/level/tome/spell.sass | 6 +-- app/styles/play/level/tome/spell_palette.sass | 4 +- .../play/level/tome/SpellPaletteView.coffee | 4 ++ app/views/play/level/tome/SpellView.coffee | 40 ++++++++++++++++++- app/views/play/level/tome/TomeView.coffee | 3 +- 7 files changed, 52 insertions(+), 10 deletions(-) diff --git a/app/lib/aether_utils.coffee b/app/lib/aether_utils.coffee index ebc200ae2..8468bf29a 100644 --- a/app/lib/aether_utils.coffee +++ b/app/lib/aether_utils.coffee @@ -44,8 +44,10 @@ functionParameters = evaluateBoard: ['board', 'player'] getPossibleMoves: ['board'] minimax_alphaBeta: ['board', 'player', 'depth', 'alpha', 'beta'] + distanceTo: ['target'] chooseAction: [] plan: [] initializeCentroids: [] update: [] + getNearestEnemy: [] diff --git a/app/styles/play/level/tome/problem_alert.sass b/app/styles/play/level/tome/problem_alert.sass index 2fef34314..8b0a623ea 100644 --- a/app/styles/play/level/tome/problem_alert.sass +++ b/app/styles/play/level/tome/problem_alert.sass @@ -4,7 +4,8 @@ .problem-alert z-index: 10 position: absolute - bottom: -135px + // Position these at the end of the spell editor, right above the spell toolbar. + bottom: -20px left: 10px right: 10px background: transparent diff --git a/app/styles/play/level/tome/spell.sass b/app/styles/play/level/tome/spell.sass index adeeb581f..0d07f8c36 100644 --- a/app/styles/play/level/tome/spell.sass +++ b/app/styles/play/level/tome/spell.sass @@ -12,9 +12,8 @@ position: absolute left: 10px top: 48px - bottom: 121px - // Bottom relates to .palette height and padding-top right: 10px + padding-bottom: 10px z-index: 1 // Set z-index above palette display: none @@ -62,9 +61,6 @@ line-height: 20px overflow: visible - &.user-code-problem.spell-cast - @include editor-height(60px) - &.disabled @include opacity(80) .ace_cursor diff --git a/app/styles/play/level/tome/spell_palette.sass b/app/styles/play/level/tome/spell_palette.sass index 274ae31e0..4103c0311 100644 --- a/app/styles/play/level/tome/spell_palette.sass +++ b/app/styles/play/level/tome/spell_palette.sass @@ -3,10 +3,10 @@ #spell-palette-view position: absolute - bottom: 10px + padding-bottom: 10px left: 10px right: 10px - height: 140px + //height: 140px // Height relates to .tab-content height padding-top: 35px padding-left: 12px diff --git a/app/views/play/level/tome/SpellPaletteView.coffee b/app/views/play/level/tome/SpellPaletteView.coffee index 4eaf69514..fff49811f 100644 --- a/app/views/play/level/tome/SpellPaletteView.coffee +++ b/app/views/play/level/tome/SpellPaletteView.coffee @@ -48,6 +48,10 @@ module.exports = class SpellPaletteView extends CocoView $('.nano').nanoScroller() @updateCodeLanguage @options.language + afterInsert: -> + super() + _.delay => @$el?.css('bottom', 0) unless $('#spell-view').is('.shown') + updateCodeLanguage: (language) -> @options.language = language @$el.find('.code-language-logo').removeClass().addClass 'code-language-logo ' + language diff --git a/app/views/play/level/tome/SpellView.coffee b/app/views/play/level/tome/SpellView.coffee index 69699f249..d74204322 100644 --- a/app/views/play/level/tome/SpellView.coffee +++ b/app/views/play/level/tome/SpellView.coffee @@ -65,6 +65,7 @@ module.exports = class SpellView extends CocoView @problems = [] @writable = false unless me.team in @spell.permissions.readwrite # TODO: make this do anything @highlightCurrentLine = _.throttle @highlightCurrentLine, 100 + $(window).on 'resize', @onWindowResize afterRender: -> super() @@ -281,6 +282,8 @@ module.exports = class SpellView extends CocoView setThang: (thang) -> @focus() + @lastScreenLineCount = null + @updateLines() return if thang.id is @thang?.id @thang = thang @spellThang = @spell.thangs[@thang.id] @@ -305,6 +308,31 @@ module.exports = class SpellView extends CocoView return if @aceDoc.undergoingFirepadOperation # from my Firepad ACE adapter Backbone.Mediator.publish 'tome:editing-began', {} + updateLines: => + # Make sure there are always blank lines for the player to type on, and that the editor resizes to the height of the lines. + lineCount = @aceDoc.getLength() + lastLine = @aceDoc.$lines[lineCount - 1] + if lastLine isnt '' + cursorPosition = @ace.getCursorPosition() + wasAtEnd = cursorPosition.row is lineCount - 1 and cursorPosition.column is lastLine.length + @aceDoc.insertNewLine row: lineCount, column: 0 #lastLine.length + @ace.navigateLeft(1) if wasAtEnd + ++lineCount + screenLineCount = @aceSession.getScreenLength() + if screenLineCount isnt @lastScreenLineCount + @lastScreenLineCount = screenLineCount + lineHeight = @ace.renderer.lineHeight or 20 + tomeHeight = $('#tome-view').innerHeight() + spellListTabEntryHeight = $('#spell-list-tab-entry-view').outerHeight() + spellToolbarHeight = $('.spell-toolbar-view').outerHeight() + spellPaletteHeight = $('#spell-palette-view').outerHeight() + maxHeight = tomeHeight - spellListTabEntryHeight - spellToolbarHeight - spellPaletteHeight + linesAtMaxHeight = Math.floor(maxHeight / lineHeight) + lines = Math.max 8, Math.min(screenLineCount + 4, linesAtMaxHeight) + # 2 lines buffer is nice, but 4 leaves room to put problem alerts. + @ace.setOptions minLines: lines, maxLines: lines + $('#spell-palette-view').css('top', 38 + 45 + lineHeight * lines) # Move spell palette up, slightly underlapping us. + onManualCast: (e) -> cast = @$el.parent().length @recompile cast, e.realTime @@ -361,6 +389,7 @@ module.exports = class SpellView extends CocoView _.debounce @notifyEditingEnded, 1000 _.throttle @notifyEditingBegan, 250 _.throttle @notifySpellChanged, 300 + _.throttle @updateLines, 500 ] @onCodeChangeMetaHandler = => return if @eventsSuppressed @@ -695,7 +724,15 @@ module.exports = class SpellView extends CocoView @ace.setValue pretty onMaximizeToggled: (e) -> - _.delay (=> @ace?.resize true), 500 # Wait $level-resize-transition-time. + _.delay (=> @resize()), 500 + 100 # Wait $level-resize-transition-time, plus a bit. + + onWindowResize: (e) => + _.delay (=> @resize?()), 500 + 100 # Wait $level-resize-transition-time, plus a bit. + + resize: -> + @ace?.resize true + @lastScreenLineCount = null + @updateLines() onChangeEditorConfig: (e) -> aceConfig = me.get('aceConfig') ? {} @@ -739,4 +776,5 @@ module.exports = class SpellView extends CocoView @aceSession?.selection.off 'changeCursor', @onCursorActivity @destroyAceEditor(@ace) @debugView?.destroy() + $(window).off 'resize', @onWindowResize super() diff --git a/app/views/play/level/tome/TomeView.coffee b/app/views/play/level/tome/TomeView.coffee index de1f10008..9d6e961fa 100644 --- a/app/views/play/level/tome/TomeView.coffee +++ b/app/views/play/level/tome/TomeView.coffee @@ -181,6 +181,7 @@ module.exports = class TomeView extends CocoView @spellTabView = null @removeSubView @spellPaletteView if @spellPaletteView @spellPaletteView = null + @$el.find('#spell-palette-view').hide() @castButton?.$el.hide() @thangList?.$el.show() @@ -204,10 +205,10 @@ module.exports = class TomeView extends CocoView @castButton.attachTo @spellView @thangList?.$el.hide() Backbone.Mediator.publish 'tome:spell-shown', thang: thang, spell: spell + @updateSpellPalette thang, spell @spellList.setThangAndSpell thang, spell @spellView?.setThang thang @spellTabView?.setThang thang - @updateSpellPalette thang, spell updateSpellPalette: (thang, spell) -> return unless thang and @spellPaletteView?.thang isnt thang and thang.programmableProperties or thang.apiProperties