Layed the view framework for a new hero victory modal.

This commit is contained in:
Scott Erickson 2014-09-30 16:14:47 -07:00
parent 19e6b9d095
commit 1dda6bfcfc
4 changed files with 93 additions and 2 deletions

View file

@ -0,0 +1,2 @@
#hero-victory-modal
color: red

View file

@ -0,0 +1,34 @@
extends /templates/modal/modal_base
block modal-header-content
h3
span(data-i18n="play_level.victory_title_prefix")
span= levelName
span(data-i18n="play_level.victory_title_suffix") Complete
block modal-body-content
h4 Achievements Unlocked
for achievement in achievements
.panel
img(src=achievement.getImageURL())
h5= achievement.get('name')
p= achievement.get('description')
if achievement.completed
strong Completed
else
strong Incomplete
p Earned #{achievement.get('worth')} xp.
- var rewards = achievement.get('rewards') || {};
if rewards.gems
p Earned #{achievement.get('rewards').gems} gems.
if rewards.heroes
for hero in rewards.heroes
- var hero = thangTypes[hero];
img(src=hero.getPortraitURL())
if rewards.items
for item in rewards.items
- var item = thangTypes[item];
img(src=item.getPortraitURL())
block modal-footer-content
| footer

View file

@ -32,6 +32,7 @@ GoalsView = require './LevelGoalsView'
LevelFlagsView = require './LevelFlagsView'
GoldView = require './LevelGoldView'
VictoryModal = require './modal/VictoryModal'
HeroVictoryModal = require './modal/HeroVictoryModal'
InfiniteLoopModal = require './modal/InfiniteLoopModal'
GameMenuModal = require 'views/game-menu/GameMenuModal'
@ -196,6 +197,11 @@ module.exports = class PlayLevelView extends RootView
@insertSubviews()
@initVolume()
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
# testing
# modal = new HeroVictoryModal({session: @session, level: @level})
# @openModalView(modal)
@originalSessionState = $.extend(true, {}, @session.get('state'))
@register()
@controlBar.setBus(@bus)
@ -450,8 +456,10 @@ module.exports = class PlayLevelView extends RootView
showVictory: ->
options = {level: @level, supermodel: @supermodel, session: @session}
docs = new VictoryModal(options)
@openModalView(docs)
# ModalClass = if @level.get('type', true) is 'hero' then HeroVictoryModal else VictoryModal
# victoryModal = new ModalClass(options)
victoryModal = new VictoryModal(options)
@openModalView(victoryModal)
if me.get('anonymous')
window.nextLevelURL = @getNextLevelURL() # Signup will go here on completion instead of reloading.

View file

@ -0,0 +1,47 @@
ModalView = require 'views/kinds/ModalView'
template = require 'templates/play/level/modal/hero-victory-modal'
Achievement = require 'models/Achievement'
CocoCollection = require 'collections/CocoCollection'
LocalMongo = require 'lib/LocalMongo'
utils = require 'lib/utils'
ThangType = require 'models/ThangType'
module.exports = class UnnamedView extends ModalView
id: 'hero-victory-modal'
template: template
constructor: (options) ->
super(options)
@session = options.session
@level = options.level
achievements = new CocoCollection([], {
url: "/db/achievement?related=#{@session.get('level').original}"
model: Achievement
})
@thangTypes = {}
@achievements = @supermodel.loadCollection(achievements, 'achievements').model
@listenToOnce @achievements, 'sync', @onAchievementsLoaded
onAchievementsLoaded: ->
thangTypeOriginals = []
for achievement in @achievements.models
rewards = achievement.get('rewards')
console.log 'rewards', rewards
thangTypeOriginals.push rewards.heroes or []
thangTypeOriginals.push rewards.items or []
thangTypeOriginals = _.uniq _.flatten thangTypeOriginals
console.log 'thang type originals?', thangTypeOriginals
for thangTypeOriginal in thangTypeOriginals
thangType = new ThangType()
thangType.url = "/db/thang.type/#{thangTypeOriginal}/version"
thangType.project = ['original', 'rasterIcon']
@thangTypes[thangTypeOriginal] = @supermodel.loadModel(thangType, 'thang').model
getRenderData: ->
c = super()
c.levelName = utils.i18n @level.attributes, 'name'
for achievement in @achievements.models
achievement.completed = LocalMongo.matchesQuery(@session.attributes, achievement.get('query'))
c.achievements = @achievements.models
c.thangTypes = @thangTypes
return c