codecombat/app/views/play/level/ControlBarView.coffee

160 lines
6.3 KiB
CoffeeScript
Raw Normal View History

CocoView = require 'views/core/CocoView'
Game dev levels (#3810) * Tweak API doc behavior and styling * Instead of moving to the left during active dialogues, just move to the top * Allow pointer events * Adjust close button * Re-enable pinning API docs for game-dev and web-dev levels * Make sidebar in PlayGameDevLevelView stretch, better layout columns * Set up content of PlayGameDevLevelView sidebar to scroll * Add rest of PlayGameDevLevelView sidebar content, rework what loading looks like * Finish PlayGameDevLevelView * Add share area below * Cover the brown background, paint it gray * Tweak PlayGameDevLevelView * Have progress bar show everything * Fix Surface resize handling * Fix PlayGameDevLevelView resizing incorrectly when playing * Add GameDevVictoryModal to PlayGameDevLevelView * Don't show missing-doctype annotation in Ace * Hook up GameDevVictoryModal copy button * Fix onChangeAnnotation runtime error * Fix onLevelLoaded runtime error * Have CourseVictoryModal link to /courses when course is done * Trim, update CourseDetailsView * Remove last vestiges of teacherMode * Remove giant navigation buttons at top * Quick switch to flat style * Add analytics for game-dev * Update Analytics events for gamedev * Prefix event names with context * Send to Mixpanel * Include more properties * Mostly set up indefinite play and autocast for game-dev levels * Set up cast buttons and shortcut for game-dev * Add rudimentary instructions when students play game-dev levels * Couple tweaks * fix a bit of code that expects frames to always stick around * have PlayGameDevLevelView render a couple frames on load * API Docs use 'game' instead of 'hero' * Move tags to head without combining * Add HTML comment-start string Fixes missing entry point arrows * Fix some whitespace
2016-07-28 16:39:58 -04:00
template = require 'templates/play/level/control-bar-view'
{me} = require 'core/auth'
2014-01-03 13:32:13 -05:00
Campaign = require 'models/Campaign'
Classroom = require 'models/Classroom'
Course = require 'models/Course'
CourseInstance = require 'models/CourseInstance'
GameMenuModal = require 'views/play/menu/GameMenuModal'
LevelSetupManager = require 'lib/LevelSetupManager'
2014-01-03 13:32:13 -05:00
2014-07-17 20:20:11 -04:00
module.exports = class ControlBarView extends CocoView
2014-06-30 22:16:26 -04:00
id: 'control-bar-view'
2014-01-03 13:32:13 -05:00
template: template
subscriptions:
'level:disable-controls': 'onDisableControls'
'level:enable-controls': 'onEnableControls'
'ipad:memory-warning': 'onIPadMemoryWarning'
2014-01-03 13:32:13 -05:00
events:
'click #next-game-button': -> Backbone.Mediator.publish 'level:next-game-pressed', {}
'click #game-menu-button': 'showGameMenuModal'
'click': -> Backbone.Mediator.publish 'tome:focus-editor', {}
2014-11-20 14:11:27 -05:00
'click .levels-link-area': 'onClickHome'
'click .home a': 'onClickHome'
'click #control-bar-sign-up-button': 'onClickSignupButton'
2014-01-03 13:32:13 -05:00
constructor: (options) ->
@supermodel = options.supermodel
@courseID = options.courseID
@courseInstanceID = options.courseInstanceID
2015-09-24 20:12:18 -04:00
2014-01-03 13:32:13 -05:00
@worldName = options.worldName
@session = options.session
@level = options.level
@levelSlug = @level.get('slug')
@levelID = @levelSlug or @level.id
2014-03-12 20:51:09 -04:00
@spectateGame = options.spectateGame ? false
@observing = options.session.get('creator') isnt me.id
@levelNumber = ''
if @level.isType('course', 'game-dev', 'web-dev') and @level.get('campaignIndex')?
@levelNumber = @level.get('campaignIndex') + 1
if @courseInstanceID
@courseInstance = new CourseInstance(_id: @courseInstanceID)
jqxhr = @courseInstance.fetch()
@supermodel.trackRequest(jqxhr)
new Promise(jqxhr.then).then(=>
@classroom = new Classroom(_id: @courseInstance.get('classroomID'))
@supermodel.trackRequest @classroom.fetch()
)
else if @courseID
@course = new Course(_id: @courseID)
jqxhr = @course.fetch()
@supermodel.trackRequest(jqxhr)
new Promise(jqxhr.then).then(=>
@campaign = new Campaign(_id: @course.get('campaignID'))
@supermodel.trackRequest(@campaign.fetch())
)
2014-01-03 13:32:13 -05:00
super options
if @level.get 'replayable'
@listenTo @session, 'change-difficulty', @onSessionDifficultyChanged
2014-01-03 13:32:13 -05:00
onLoaded: ->
if @classroom
@levelNumber = @classroom.getLevelNumber(@level.get('original'), @levelNumber)
else if @campaign
@levelNumber = @campaign.getLevelNumber(@level.get('original'), @levelNumber)
super()
2014-01-03 13:32:13 -05:00
setBus: (@bus) ->
getRenderData: (c={}) ->
super c
c.worldName = @worldName
c.ladderGame = @level.isType('ladder', 'hero-ladder', 'course-ladder')
if @level.get 'replayable'
c.levelDifficulty = @session.get('state')?.difficulty ? 0
if @observing
c.levelDifficulty = Math.max 0, c.levelDifficulty - 1 # Show the difficulty they won, not the next one.
c.difficultyTitle = "#{$.i18n.t 'play.level_difficulty'}#{c.levelDifficulty}"
@lastDifficulty = c.levelDifficulty
2014-03-12 20:51:09 -04:00
c.spectateGame = @spectateGame
c.observing = @observing
@homeViewArgs = [{supermodel: if @hasReceivedMemoryWarning then null else @supermodel}]
if me.isSessionless()
2016-04-08 15:59:10 -04:00
@homeLink = "/teachers/courses"
@homeViewClass = "views/courses/TeacherCoursesView"
else if @level.isType('ladder', 'ladder-tutorial', 'hero-ladder', 'course-ladder')
levelID = @level.get('slug')?.replace(/\-tutorial$/, '') or @level.id
@homeLink = "/play/ladder/#{levelID}"
@homeViewClass = 'views/ladder/LadderView'
@homeViewArgs.push levelID
if leagueID = @getQueryVariable('league') or @getQueryVariable('course-instance')
leagueType = if @level.isType('course-ladder') then 'course' else 'clan'
@homeViewArgs.push leagueType
@homeViewArgs.push leagueID
@homeLink += "/#{leagueType}/#{leagueID}"
else if @level.isType('course') or @courseID
2015-09-24 20:12:18 -04:00
@homeLink = '/courses'
@homeViewClass = 'views/courses/CoursesView'
if @courseID
@homeLink += "/#{@courseID}"
@homeViewArgs.push @courseID
@homeViewClass = 'views/courses/CourseDetailsView'
if @courseInstanceID
@homeLink += "/#{@courseInstanceID}"
2015-09-24 20:12:18 -04:00
@homeViewArgs.push @courseInstanceID
else if @level.isType('hero', 'hero-coop', 'game-dev', 'web-dev') or window.serverConfig.picoCTF
@homeLink = '/play'
@homeViewClass = 'views/play/CampaignView'
campaign = @level.get 'campaign'
@homeLink += '/' + campaign
@homeViewArgs.push campaign
2014-05-05 18:33:08 -04:00
else
@homeLink = '/'
@homeViewClass = 'views/HomeView'
c.editorLink = "/editor/level/#{@level.get('slug') or @level.id}"
c.homeLink = @homeLink
c
2014-01-03 13:32:13 -05:00
showGameMenuModal: (e, tab=null) ->
2015-08-13 08:58:37 -04:00
gameMenuModal = new GameMenuModal level: @level, session: @session, supermodel: @supermodel, showTab: tab
@openModalView gameMenuModal
@listenToOnce gameMenuModal, 'change-hero', ->
@setupManager?.destroy()
@setupManager = new LevelSetupManager({supermodel: @supermodel, level: @level, levelID: @levelID, parent: @, session: @session, courseID: @courseID, courseInstanceID: @courseInstanceID})
@setupManager.open()
onClickHome: (e) ->
if @level.isType('course')
category = if me.isTeacher() then 'Teachers' else 'Students'
window.tracker?.trackEvent 'Play Level Back To Levels', category: category, levelSlug: @levelSlug, ['Mixpanel']
e.preventDefault()
e.stopImmediatePropagation()
Backbone.Mediator.publish 'router:navigate', route: @homeLink, viewClass: @homeViewClass, viewArgs: @homeViewArgs
onClickSignupButton: (e) ->
window.tracker?.trackEvent 'Started Signup', category: 'Play Level', label: 'Control Bar', level: @levelID
onDisableControls: (e) -> @toggleControls e, false
onEnableControls: (e) -> @toggleControls e, true
toggleControls: (e, enabled) ->
return if e.controls and not ('level' in e.controls)
return if enabled is @controlsEnabled
@controlsEnabled = enabled
@$el.toggleClass 'controls-disabled', not enabled
onIPadMemoryWarning: (e) ->
@hasReceivedMemoryWarning = true
onSessionDifficultyChanged: ->
return if @session.get('state')?.difficulty is @lastDifficulty
@render()
destroy: ->
@setupManager?.destroy()
super()