mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Spell palette now hugs the spell editor, which itself shrinks as needed.
This commit is contained in:
parent
fbaced90c3
commit
54de8482f1
7 changed files with 52 additions and 10 deletions
|
@ -44,8 +44,10 @@ functionParameters =
|
|||
evaluateBoard: ['board', 'player']
|
||||
getPossibleMoves: ['board']
|
||||
minimax_alphaBeta: ['board', 'player', 'depth', 'alpha', 'beta']
|
||||
distanceTo: ['target']
|
||||
|
||||
chooseAction: []
|
||||
plan: []
|
||||
initializeCentroids: []
|
||||
update: []
|
||||
getNearestEnemy: []
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue