Added tasks to campaign editor; fixed/added campaign editor level click/double-click handling; improved campaign editor level Treema status view formatting.

This commit is contained in:
Nick Winter 2014-12-29 12:46:14 -08:00
parent 370dff606d
commit 1440584633
7 changed files with 84 additions and 19 deletions

View file

@ -107,8 +107,11 @@ _.extend CampaignSchema.properties, {
level: { type: 'string', links: [{rel: 'db', href: '/db/level/{($)}/version'}], format: 'latest-version-original-reference' }
type: { enum: ['heroes', 'items', 'levels'] }
}}
campaign: c.shortString title: 'Campaign', description: 'Which campaign this level is part of (like "desert").', format: 'hidden' # Automatically set by campaign editor.
tasks: c.array {title: 'Tasks', description: 'Tasks to be completed for this level.'}, c.task
#- normal properties
position: c.point2d()
}

View file

@ -10,6 +10,10 @@
.treema-root
max-height: 100%
overflow: scroll
.completion
position: absolute
right: 0
#right-column
position: absolute
@ -17,12 +21,3 @@
bottom: 0
right: 0
width: 75%
#campaign-level-view
position: absolute
top: 0
left: 0
right: 0
bottom: 0
background-color: white
z-index: 3

View file

@ -0,0 +1,13 @@
#campaign-level-view
background-color: white
position: absolute
top: 0
left: 0
right: 0
z-index: 3
.tasks
padding: 15px
.button.close
font-size: 63px

View file

@ -1,4 +1,17 @@
.jumbotron
.button.close(type="button", aria-hidden="true") ×
h1= level.get('name')
h1
span.spr= level.get('name')
a(href="/editor/level/#{level.get('slug')}", target="_blank") (edit)
p= level.get('description')
h2 TODO: actually put useful stuff in here
if level.get('tasks')
.tasks
h3 Tasks (read only)
ul.list-unstyled
for task in level.get('tasks')
li
input(type='checkbox', checked=task.complete)
span.spl= task.name

View file

@ -164,6 +164,7 @@ module.exports = class CampaignEditorView extends RootView
@listenTo @campaignView, 'level-moved', @onCampaignLevelMoved
@listenTo @campaignView, 'adjacent-campaign-moved', @onAdjacentCampaignMoved
@listenTo @campaignView, 'level-clicked', @onCampaignLevelClicked
@listenTo @campaignView, 'level-double-clicked', @onCampaignLevelDoubleClicked
@insertSubView @campaignView
onTreemaChanged: (e, nodes) =>
@ -188,8 +189,7 @@ module.exports = class CampaignEditorView extends RootView
path = node.getPath()
return unless _.string.startsWith path, '/levels/'
original = path.split('/')[2]
level = @supermodel.getModelByOriginal Level, original
@insertSubView new CampaignLevelView({}, level)
@openCampaignLevelView @supermodel.getModelByOriginal Level, original
onCampaignLevelMoved: (e) ->
path = "levels/#{e.levelOriginal}/position"
@ -204,6 +204,14 @@ module.exports = class CampaignEditorView extends RootView
levelTreema.select()
# levelTreema.open()
onCampaignLevelDoubleClicked: (levelOriginal) ->
@openCampaignLevelView @supermodel.getModelByOriginal Level, levelOriginal
openCampaignLevelView: (level) ->
@insertSubView campaignLevelView = new CampaignLevelView({}, level)
@listenToOnce campaignLevelView, 'hidden', => @$el.find('#campaign-view').show()
@$el.find('#campaign-view').hide()
updateRewardsForLevel: (level, rewards) ->
achievements = @supermodel.getModels(Achievement)
achievements = (a for a in achievements when a.get('related') is level.get('original'))
@ -250,7 +258,27 @@ class LevelsNode extends TreemaObjectNode
class LevelNode extends TreemaObjectNode
valueClass: 'treema-level'
buildValueForDisplay: (valEl, data) ->
@buildValueForDisplaySimply valEl, data.name
name = data.name
if data.requiresSubscription
name = "[P] " + name
status = ''
el = 'strong'
if data.adminOnly
status += " (disabled)"
el = 'span'
else if data.adventurer
status += " (adventurer)"
completion = ''
if data.tasks
completion = "#{(t for t in data.tasks when t.complete).length} / #{data.tasks.length}"
valEl.append $("<#{el}></#{el}>").addClass('treema-shortened').text name
if status
valEl.append $('<em class="spl"></em>').text status
if completion
valEl.append $('<span class="completion"></span>').text completion
populateData: ->
return if @data.name?

View file

@ -1,19 +1,24 @@
CocoView = require 'views/core/CocoView'
Level = require 'models/Level'
module.exports = class CampaignLevelView extends CocoView
id: 'campaign-level-view'
template: require 'templates/editor/campaign/campaign-level-view'
events:
'click .close': 'onClickClose'
constructor: (options, @level) ->
super(options)
@fullLevel = new Level _id: @level.id
@fullLevel.fetch()
@listenToOnce @fullLevel, 'sync', => @render?()
getRenderData: ->
c = super()
c.level = @level
c.level = if @fullLevel.loaded then @fullLevel else @level
c
onClickClose: ->
@$el.addClass('hidden')
@$el.addClass('hidden')
@trigger 'hidden'

View file

@ -34,6 +34,7 @@ module.exports = class CampaignView extends RootView
events:
'click .map-background': 'onClickMap'
'click .level a': 'onClickLevel'
'dblclick .level a': 'onDoubleClickLevel'
'click .level-info-container .start-level': 'onClickStartLevel'
'mouseenter .level a': 'onMouseEnterLevel'
'mouseleave .level a': 'onMouseLeaveLevel'
@ -236,8 +237,9 @@ module.exports = class CampaignView extends RootView
@$levelInfo?.hide()
levelElement = $(e.target).parents('.level')
levelSlug = levelElement.data('level-slug')
levelOriginal = levelElement.data('level-original')
if @editorMode
return @trigger 'level-clicked', levelSlug
return @trigger 'level-clicked', levelOriginal
level = _.find _.values(@campaign.get('levels')), slug: levelSlug
if application.isIPadApp
@$levelInfo = @$el.find(".level-info-container[data-level-slug=#{levelSlug}]").show()
@ -256,6 +258,12 @@ module.exports = class CampaignView extends RootView
@startLevel levelElement
window.tracker?.trackEvent 'Clicked Level', category: 'World Map', levelID: levelSlug, ['Google Analytics']
onDoubleClickLevel: (e) ->
return unless @editorMode
levelElement = $(e.target).parents('.level')
levelOriginal = levelElement.data('level-original')
@trigger 'level-double-clicked', levelOriginal
onClickStartLevel: (e) ->
levelElement = $(e.target).parents('.level-info-container')
@startLevel levelElement