mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -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']
|
evaluateBoard: ['board', 'player']
|
||||||
getPossibleMoves: ['board']
|
getPossibleMoves: ['board']
|
||||||
minimax_alphaBeta: ['board', 'player', 'depth', 'alpha', 'beta']
|
minimax_alphaBeta: ['board', 'player', 'depth', 'alpha', 'beta']
|
||||||
|
distanceTo: ['target']
|
||||||
|
|
||||||
chooseAction: []
|
chooseAction: []
|
||||||
plan: []
|
plan: []
|
||||||
initializeCentroids: []
|
initializeCentroids: []
|
||||||
update: []
|
update: []
|
||||||
|
getNearestEnemy: []
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
.problem-alert
|
.problem-alert
|
||||||
z-index: 10
|
z-index: 10
|
||||||
position: absolute
|
position: absolute
|
||||||
bottom: -135px
|
// Position these at the end of the spell editor, right above the spell toolbar.
|
||||||
|
bottom: -20px
|
||||||
left: 10px
|
left: 10px
|
||||||
right: 10px
|
right: 10px
|
||||||
background: transparent
|
background: transparent
|
||||||
|
|
|
@ -12,9 +12,8 @@
|
||||||
position: absolute
|
position: absolute
|
||||||
left: 10px
|
left: 10px
|
||||||
top: 48px
|
top: 48px
|
||||||
bottom: 121px
|
|
||||||
// Bottom relates to .palette height and padding-top
|
|
||||||
right: 10px
|
right: 10px
|
||||||
|
padding-bottom: 10px
|
||||||
z-index: 1
|
z-index: 1
|
||||||
// Set z-index above palette
|
// Set z-index above palette
|
||||||
display: none
|
display: none
|
||||||
|
@ -62,9 +61,6 @@
|
||||||
line-height: 20px
|
line-height: 20px
|
||||||
overflow: visible
|
overflow: visible
|
||||||
|
|
||||||
&.user-code-problem.spell-cast
|
|
||||||
@include editor-height(60px)
|
|
||||||
|
|
||||||
&.disabled
|
&.disabled
|
||||||
@include opacity(80)
|
@include opacity(80)
|
||||||
.ace_cursor
|
.ace_cursor
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
#spell-palette-view
|
#spell-palette-view
|
||||||
position: absolute
|
position: absolute
|
||||||
bottom: 10px
|
padding-bottom: 10px
|
||||||
left: 10px
|
left: 10px
|
||||||
right: 10px
|
right: 10px
|
||||||
height: 140px
|
//height: 140px
|
||||||
// Height relates to .tab-content height
|
// Height relates to .tab-content height
|
||||||
padding-top: 35px
|
padding-top: 35px
|
||||||
padding-left: 12px
|
padding-left: 12px
|
||||||
|
|
|
@ -48,6 +48,10 @@ module.exports = class SpellPaletteView extends CocoView
|
||||||
$('.nano').nanoScroller()
|
$('.nano').nanoScroller()
|
||||||
@updateCodeLanguage @options.language
|
@updateCodeLanguage @options.language
|
||||||
|
|
||||||
|
afterInsert: ->
|
||||||
|
super()
|
||||||
|
_.delay => @$el?.css('bottom', 0) unless $('#spell-view').is('.shown')
|
||||||
|
|
||||||
updateCodeLanguage: (language) ->
|
updateCodeLanguage: (language) ->
|
||||||
@options.language = language
|
@options.language = language
|
||||||
@$el.find('.code-language-logo').removeClass().addClass 'code-language-logo ' + language
|
@$el.find('.code-language-logo').removeClass().addClass 'code-language-logo ' + language
|
||||||
|
|
|
@ -65,6 +65,7 @@ module.exports = class SpellView extends CocoView
|
||||||
@problems = []
|
@problems = []
|
||||||
@writable = false unless me.team in @spell.permissions.readwrite # TODO: make this do anything
|
@writable = false unless me.team in @spell.permissions.readwrite # TODO: make this do anything
|
||||||
@highlightCurrentLine = _.throttle @highlightCurrentLine, 100
|
@highlightCurrentLine = _.throttle @highlightCurrentLine, 100
|
||||||
|
$(window).on 'resize', @onWindowResize
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
super()
|
super()
|
||||||
|
@ -281,6 +282,8 @@ module.exports = class SpellView extends CocoView
|
||||||
|
|
||||||
setThang: (thang) ->
|
setThang: (thang) ->
|
||||||
@focus()
|
@focus()
|
||||||
|
@lastScreenLineCount = null
|
||||||
|
@updateLines()
|
||||||
return if thang.id is @thang?.id
|
return if thang.id is @thang?.id
|
||||||
@thang = thang
|
@thang = thang
|
||||||
@spellThang = @spell.thangs[@thang.id]
|
@spellThang = @spell.thangs[@thang.id]
|
||||||
|
@ -305,6 +308,31 @@ module.exports = class SpellView extends CocoView
|
||||||
return if @aceDoc.undergoingFirepadOperation # from my Firepad ACE adapter
|
return if @aceDoc.undergoingFirepadOperation # from my Firepad ACE adapter
|
||||||
Backbone.Mediator.publish 'tome:editing-began', {}
|
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) ->
|
onManualCast: (e) ->
|
||||||
cast = @$el.parent().length
|
cast = @$el.parent().length
|
||||||
@recompile cast, e.realTime
|
@recompile cast, e.realTime
|
||||||
|
@ -361,6 +389,7 @@ module.exports = class SpellView extends CocoView
|
||||||
_.debounce @notifyEditingEnded, 1000
|
_.debounce @notifyEditingEnded, 1000
|
||||||
_.throttle @notifyEditingBegan, 250
|
_.throttle @notifyEditingBegan, 250
|
||||||
_.throttle @notifySpellChanged, 300
|
_.throttle @notifySpellChanged, 300
|
||||||
|
_.throttle @updateLines, 500
|
||||||
]
|
]
|
||||||
@onCodeChangeMetaHandler = =>
|
@onCodeChangeMetaHandler = =>
|
||||||
return if @eventsSuppressed
|
return if @eventsSuppressed
|
||||||
|
@ -695,7 +724,15 @@ module.exports = class SpellView extends CocoView
|
||||||
@ace.setValue pretty
|
@ace.setValue pretty
|
||||||
|
|
||||||
onMaximizeToggled: (e) ->
|
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) ->
|
onChangeEditorConfig: (e) ->
|
||||||
aceConfig = me.get('aceConfig') ? {}
|
aceConfig = me.get('aceConfig') ? {}
|
||||||
|
@ -739,4 +776,5 @@ module.exports = class SpellView extends CocoView
|
||||||
@aceSession?.selection.off 'changeCursor', @onCursorActivity
|
@aceSession?.selection.off 'changeCursor', @onCursorActivity
|
||||||
@destroyAceEditor(@ace)
|
@destroyAceEditor(@ace)
|
||||||
@debugView?.destroy()
|
@debugView?.destroy()
|
||||||
|
$(window).off 'resize', @onWindowResize
|
||||||
super()
|
super()
|
||||||
|
|
|
@ -181,6 +181,7 @@ module.exports = class TomeView extends CocoView
|
||||||
@spellTabView = null
|
@spellTabView = null
|
||||||
@removeSubView @spellPaletteView if @spellPaletteView
|
@removeSubView @spellPaletteView if @spellPaletteView
|
||||||
@spellPaletteView = null
|
@spellPaletteView = null
|
||||||
|
@$el.find('#spell-palette-view').hide()
|
||||||
@castButton?.$el.hide()
|
@castButton?.$el.hide()
|
||||||
@thangList?.$el.show()
|
@thangList?.$el.show()
|
||||||
|
|
||||||
|
@ -204,10 +205,10 @@ module.exports = class TomeView extends CocoView
|
||||||
@castButton.attachTo @spellView
|
@castButton.attachTo @spellView
|
||||||
@thangList?.$el.hide()
|
@thangList?.$el.hide()
|
||||||
Backbone.Mediator.publish 'tome:spell-shown', thang: thang, spell: spell
|
Backbone.Mediator.publish 'tome:spell-shown', thang: thang, spell: spell
|
||||||
|
@updateSpellPalette thang, spell
|
||||||
@spellList.setThangAndSpell thang, spell
|
@spellList.setThangAndSpell thang, spell
|
||||||
@spellView?.setThang thang
|
@spellView?.setThang thang
|
||||||
@spellTabView?.setThang thang
|
@spellTabView?.setThang thang
|
||||||
@updateSpellPalette thang, spell
|
|
||||||
|
|
||||||
updateSpellPalette: (thang, spell) ->
|
updateSpellPalette: (thang, spell) ->
|
||||||
return unless thang and @spellPaletteView?.thang isnt thang and thang.programmableProperties or thang.apiProperties
|
return unless thang and @spellPaletteView?.thang isnt thang and thang.programmableProperties or thang.apiProperties
|
||||||
|
|
Loading…
Reference in a new issue