From 5c77eea304fed4a10e0e10e1fa1a041b42624a05 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Tue, 25 Nov 2014 10:15:10 -0800 Subject: [PATCH 1/2] You can now buy heroes. --- app/schemas/subscriptions/misc.coffee | 4 ++ .../play/modal/play-heroes-modal.jade | 2 +- app/views/play/modal/PlayHeroesModal.coffee | 65 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/schemas/subscriptions/misc.coffee b/app/schemas/subscriptions/misc.coffee index f85a036d7..b3affb40d 100644 --- a/app/schemas/subscriptions/misc.coffee +++ b/app/schemas/subscriptions/misc.coffee @@ -64,3 +64,7 @@ module.exports = 'store:item-purchased': c.object {required: ['item', 'itemSlug']}, item: {type: 'object'} itemSlug: {type: 'string'} + + 'store:hero-purchased': c.object {required: ['hero', 'heroSlug']}, + hero: {type: 'object'} + heroSlug: {type: 'string'} diff --git a/app/templates/play/modal/play-heroes-modal.jade b/app/templates/play/modal/play-heroes-modal.jade index 0ebacf09e..8c76a8b9f 100644 --- a/app/templates/play/modal/play-heroes-modal.jade +++ b/app/templates/play/modal/play-heroes-modal.jade @@ -28,7 +28,7 @@ .hero-stat-row .stat-label(data-i18n='choose_hero.status') - .stat-value(data-i18n=hero.purchasable ? 'play.purchasable' : (hero.locked ? 'play.locked' : 'play.available')) + .stat-value.hero-status-value(data-i18n=hero.purchasable ? 'play.purchasable' : (hero.locked ? 'play.locked' : 'play.available')) .hero-stat-row .stat-label(data-i18n='choose_hero.weapons') diff --git a/app/views/play/modal/PlayHeroesModal.coffee b/app/views/play/modal/PlayHeroesModal.coffee index 6400a9406..5feade956 100644 --- a/app/views/play/modal/PlayHeroesModal.coffee +++ b/app/views/play/modal/PlayHeroesModal.coffee @@ -1,10 +1,13 @@ ModalView = require 'views/kinds/ModalView' template = require 'templates/play/modal/play-heroes-modal' +buyGemsPromptTemplate = require 'templates/play/modal/buy-gems-prompt' CocoCollection = require 'collections/CocoCollection' ThangType = require 'models/ThangType' SpriteBuilder = require 'lib/sprites/SpriteBuilder' AudioPlayer = require 'lib/AudioPlayer' utils = require 'lib/utils' +BuyGemsModal = require 'views/play/modal/BuyGemsModal' +Purchase = require 'models/Purchase' module.exports = class PlayHeroesModal extends ModalView className: 'modal fade play-modal' @@ -16,6 +19,9 @@ module.exports = class PlayHeroesModal extends ModalView 'change #option-code-language': 'onCodeLanguageChanged' 'click #close-modal': 'hide' 'click #confirm-button': 'saveAndHide' + 'click .unlock-button': 'onUnlockButtonClicked' + 'click .buy-gems-prompt-button': 'onBuyGemsPromptButtonClicked' + 'click': 'onClickedSomewhere' shortcuts: 'left': -> @$el.find('#hero-carousel').carousel('prev') if @heroes.models.length and not @$el.hasClass 'secret' @@ -211,6 +217,65 @@ module.exports = class PlayHeroesModal extends ModalView @codeLanguage = @$el.find('#option-code-language').val() @codeLanguageChanged = true + + #- Purchasing the hero + + onUnlockButtonClicked: (e) -> + e.stopPropagation() + button = $(e.target).closest('button') + affordable = @visibleHero.get('gems') <= me.gems() + if not affordable + @askToBuyGems button + else if button.hasClass('confirm') + + purchase = Purchase.makeFor(@visibleHero) + purchase.save() + + #- set local changes to mimic what should happen on the server... + purchased = me.get('purchased') ? {} + purchased.heroes ?= [] + purchased.heroes.push(@visibleHero.get('original')) + me.set('purchased', purchased) + me.set('spent', (me.get('spent') ? 0) + @visibleHero.get('gems')) + + #- ...then rerender visible hero + heroEntry = @$el.find(".hero-item[data-hero-id='#{@visibleHero.get('original')}']") + heroEntry.find('.hero-status-value').attr('data-i18n', 'play.available').i18n() + heroEntry.removeClass 'locked purchasable' + @rerenderFooter() + + Backbone.Mediator.publish 'store:hero-purchased', hero: @visibleHero, heroSlug: @visibleHero.get('slug') + else + button.addClass('confirm').text($.i18n.t('play.confirm')) + @$el.one 'click', (e) -> + button.removeClass('confirm').text($.i18n.t('play.unlock')) if e.target isnt button[0] + + askToBuyGems: (unlockButton) -> + if me.getGemPromptGroup() is 'no-prompt' + return @openModalView new BuyGemsModal() + @$el.find('.unlock-button').popover 'destroy' + popoverTemplate = buyGemsPromptTemplate {} + unlockButton.popover( + animation: true + trigger: 'manual' + placement: 'left' + content: ' ' # template has it + container: @$el + template: popoverTemplate + ).popover 'show' + popover = unlockButton.data('bs.popover') + popover?.$tip?.i18n() + + onBuyGemsPromptButtonClicked: (e) -> + @openModalView new BuyGemsModal() + + onClickedSomewhere: (e) -> + return if @destroyed + @$el.find('.unlock-button').popover 'destroy' + + + #- Exiting + saveAndHide: -> hero = @selectedHero.get('original') From bbc9b615eafb4e46cd179f77db3a7f8e66cf3199 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Tue, 25 Nov 2014 10:28:31 -0800 Subject: [PATCH 2/2] ItemDetailsView showing item descriptions now. --- app/styles/play/modal/item-details-view.sass | 5 ++++- app/templates/play/modal/item-details-view.jade | 3 +++ app/templates/play/modal/play-heroes-modal.jade | 2 -- app/views/play/modal/ItemDetailsView.coffee | 1 + app/views/play/modal/PlayItemsModal.coffee | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/styles/play/modal/item-details-view.sass b/app/styles/play/modal/item-details-view.sass index b7f9f8e10..6f3c661d4 100644 --- a/app/styles/play/modal/item-details-view.sass +++ b/app/styles/play/modal/item-details-view.sass @@ -65,9 +65,12 @@ position: absolute left: 150px color: rgb(42,38,28) + + .item-description + margin: 15px 15px 0 25px #skills - margin: 25px + margin: 15px 15px 0 25px h3 color: rgb(41,35,25) diff --git a/app/templates/play/modal/item-details-view.jade b/app/templates/play/modal/item-details-view.jade index ad2609aa1..7039e01e7 100644 --- a/app/templates/play/modal/item-details-view.jade +++ b/app/templates/play/modal/item-details-view.jade @@ -18,6 +18,9 @@ div.stat= stat.display img.hr(src="/images/pages/play/modal/hr.png", class=stat.isLast ? "" : "faded", draggable="false") + if item.description + .item-description= item.description + if props.length #skills h3.big-font(data-i18n="play.skills_granted") diff --git a/app/templates/play/modal/play-heroes-modal.jade b/app/templates/play/modal/play-heroes-modal.jade index 8c76a8b9f..4ea0a4b74 100644 --- a/app/templates/play/modal/play-heroes-modal.jade +++ b/app/templates/play/modal/play-heroes-modal.jade @@ -62,7 +62,6 @@ span.gem.gem-20 else if visibleHero.locked - //#locked-hero-explanation= lockedExplanation #locked-hero-explanation h2 span= visibleHero.name @@ -74,7 +73,6 @@ .form .form-group.select-group span.help-block(data-i18n="choose_hero.programming_language_description") Which programming language do you want to use? - //label.control-label(for="option-code-language", data-i18n="choose_hero.programming_language") Programming Language select#option-code-language(name="code-language") for option in codeLanguages option(value=option.id, selected=codeLanguage === option.id)= option.name diff --git a/app/views/play/modal/ItemDetailsView.coffee b/app/views/play/modal/ItemDetailsView.coffee index 6baed33e9..3e9faf7c5 100644 --- a/app/views/play/modal/ItemDetailsView.coffee +++ b/app/views/play/modal/ItemDetailsView.coffee @@ -19,6 +19,7 @@ module.exports = class ItemDetailsView extends CocoView if @item @spellDocs = {} @item.name = utils.i18n @item.attributes, 'name' + @item.description = utils.i18n @item.attributes, 'description' @item.affordable = me.gems() >= @item.get('gems') @item.owned = me.ownsItem @item.get('original') @item.comingSoon = not @item.getFrontFacingStats().props.length and not _.size @item.getFrontFacingStats().stats # Temp: while there are placeholder items diff --git a/app/views/play/modal/PlayItemsModal.coffee b/app/views/play/modal/PlayItemsModal.coffee index 74b17fcdf..e401bef46 100644 --- a/app/views/play/modal/PlayItemsModal.coffee +++ b/app/views/play/modal/PlayItemsModal.coffee @@ -67,6 +67,7 @@ module.exports = class PlayItemsModal extends ModalView 'rasterIcon' 'gems' 'tier' + 'description' 'i18n' 'heroClass' ]