diff --git a/assets/images/panel-background-outdated.png b/assets/images/panel-background-outdated.png new file mode 100644 index 000000000..76ae147f4 Binary files /dev/null and b/assets/images/panel-background-outdated.png differ diff --git a/src/artwork/panel-background-outdated.graffle b/src/artwork/panel-background-outdated.graffle new file mode 100644 index 000000000..4ec1da428 --- /dev/null +++ b/src/artwork/panel-background-outdated.graffle @@ -0,0 +1,353 @@ + + + + + ActiveLayerIndex + 0 + ApplicationVersion + + com.omnigroup.OmniGraffle.MacAppStore + 139.18 + + AutoAdjust + + BackgroundGraphic + + Bounds + {{0, 0}, {320, 320}} + Class + SolidGraphic + ID + 2 + Style + + shadow + + Draws + NO + + stroke + + Draws + NO + + + + BaseZoom + 0 + CanvasOrigin + {0, 0} + CanvasSize + {320, 320} + ColumnAlign + 1 + ColumnSpacing + 36 + CreationDate + 2016-04-23 05:39:56 +0000 + Creator + Andrew Miner + DisplayScale + 1 pt = 1 px + GraphDocumentVersion + 8 + GraphicsList + + + AllowConnections + NO + AllowLabelDrop + + AllowToConnect + + Class + LineGraphic + ID + 5 + Points + + {160, 480} + {480, 160} + + Style + + stroke + + Cap + 0 + Color + + a + 0.1 + b + 0 + g + 1 + r + 1 + + HeadArrow + 0 + Legacy + + TailArrow + 0 + Width + 120 + + + + + AllowConnections + NO + AllowLabelDrop + + AllowToConnect + + Class + LineGraphic + ID + 4 + Points + + {-160, 160} + {160, -160} + + Style + + stroke + + Cap + 0 + Color + + a + 0.1 + b + 0 + g + 1 + r + 1 + + HeadArrow + 0 + Legacy + + TailArrow + 0 + Width + 120 + + + + + AllowConnections + NO + AllowLabelDrop + + AllowToConnect + + Class + LineGraphic + ID + 3 + Points + + {0, 320} + {320, 0} + + Style + + stroke + + Cap + 0 + Color + + a + 0.1 + b + 0 + g + 1 + r + 1 + + HeadArrow + 0 + Legacy + + TailArrow + 0 + Width + 120 + + + + + GridInfo + + GridSpacing + 10 + MajorGridSpacing + 10 + ShowsGrid + YES + SnapsToGrid + YES + + GuidesLocked + NO + GuidesVisible + YES + HPages + 1 + ImageCounter + 1 + KeepToScale + + Layers + + + Lock + NO + Name + Layer 1 + Print + YES + View + YES + + + LayoutInfo + + Animate + NO + circoMinDist + 18 + circoSeparation + 0.0 + layoutEngine + dot + neatoSeparation + 0.0 + twopiSeparation + 0.0 + + LinksVisible + NO + MagnetsVisible + NO + MasterSheets + + ModificationDate + 2016-04-23 05:58:40 +0000 + Modifier + Andrew Miner + NotesVisible + NO + Orientation + 2 + OriginVisible + NO + PageBreaks + NO + PrintInfo + + NSBottomMargin + + float + 41 + + NSHorizonalPagination + + coded + BAtzdHJlYW10eXBlZIHoA4QBQISEhAhOU051bWJlcgCEhAdOU1ZhbHVlAISECE5TT2JqZWN0AIWEASqEhAFxlwCG + + NSLeftMargin + + float + 18 + + NSPaperSize + + size + {611.99998474121094, 792} + + NSPrintReverseOrientation + + int + 0 + + NSRightMargin + + float + 18 + + NSTopMargin + + float + 18 + + + PrintOnePage + + ReadOnly + NO + RowAlign + 1 + RowSpacing + 36 + SheetTitle + Canvas 1 + SmartAlignmentGuidesActive + YES + SmartDistanceGuidesActive + YES + UniqueID + 1 + UseEntirePage + + VPages + 1 + WindowInfo + + CurrentSheet + 0 + ExpandedCanvases + + + name + Canvas 1 + + + Frame + {{215, 0}, {2134, 1417}} + ListView + + OutlineWidth + 142 + RightSidebar + + ShowRuler + + Sidebar + + SidebarWidth + 120 + VisibleRegion + {{-840, -477}, {1999, 1275}} + Zoom + 1 + ZoomValues + + + Canvas 1 + 1 + 1 + + + + + diff --git a/src/client/models/crafting/crafting_step.coffee b/src/client/models/crafting/crafting_step.coffee index 529f7bffe..2d1a2bd60 100644 --- a/src/client/models/crafting/crafting_step.coffee +++ b/src/client/models/crafting/crafting_step.coffee @@ -27,7 +27,7 @@ module.exports = class CraftingStep addToolsTo: (targetInventory)-> for stack in @_recipe.tools - targetInventory.add stack.itemSlug, stack.quantity + targetInventory.add stack.itemSlug, stack.quantity, insert:true completeInto: (targetInventory)-> for stack in @_recipe.output diff --git a/src/client/models/crafting/craftsman.coffee b/src/client/models/crafting/craftsman.coffee index 613181454..d64b63cba 100644 --- a/src/client/models/crafting/craftsman.coffee +++ b/src/client/models/crafting/craftsman.coffee @@ -22,32 +22,30 @@ module.exports = class Craftsman extends BaseModel @::PLAN_STEP_INCREMENT = 39 @::STAGE = - WAITING: 'waiting' + EMPTY: 'empty' + READY: 'ready' GRAPHING: 'examining recipes' PLANNING: 'computing plans' ANALYZING: 'analyzing plans' COMPLETE: 'complete' INVALID: 'invalid' + OUTDATED: 'outdated' constructor: (modPack)-> if not modPack? then throw new Error 'modPack is required' attributes = - paused: false - stage: @STAGE.WAITING + stage: @STAGE.READY stageCount: 0 super attributes, {} @_modPack = modPack - reset = _.debounce (=> @reset()), 100 - @_have = new Inventory modPack:@_modPack - @_have.on c.event.change, reset + @_have.on c.event.change, => @_resetStage() @_want = new Inventory modPack:@_modPack - @_want.on c.event.change, reset + @_want.on c.event.change, => @_resetStage() - @on c.event.change + ':paused', reset @on c.event.change + ':stage', => logger.info "Craftsman has started #{@stage}..." @on 'scheduleNextWork', => @_scheduleNextWork() @reset() @@ -60,10 +58,7 @@ module.exports = class Craftsman extends BaseModel @_planEvaluator = null @_plans = null - @stage = @STAGE.WAITING - @stageCount = 0 - - @_scheduleNextWork() + @_resetStage() work: -> return if @_want.isEmpty @@ -121,7 +116,7 @@ module.exports = class Craftsman extends BaseModel Object.defineProperties @prototype, complete: - get: -> @stage in [@STAGE.COMPLETE, @STAGE.INVALID] + get: -> @stage in [@STAGE.COMPLETE, @STAGE.INVALID, @STAGE.OUTDATED] have: get: -> @_have @@ -134,8 +129,19 @@ module.exports = class Craftsman extends BaseModel # Private Methods ############################################################################## + _resetStage: -> + @stageCount = 0 + + if @want.isEmpty + if @stage isnt @STAGE.EMPTY + @stage = @STAGE.EMPTY + @reset() + else if not @_plans? + @stage = @STAGE.READY + else + @stage = @STAGE.OUTDATED + _scheduleNextWork: -> - return if @paused return if @want.isEmpty return if @complete diff --git a/src/client/models/game/inventory.coffee b/src/client/models/game/inventory.coffee index 96d4d8368..38a41d09c 100644 --- a/src/client/models/game/inventory.coffee +++ b/src/client/models/game/inventory.coffee @@ -29,10 +29,10 @@ module.exports = class Inventory extends BaseModel # Public Methods ############################################################################### - add: (itemSlug, quantity=1)-> + add: (itemSlug, quantity=1, options={})-> return this unless quantity > 0 - @_add itemSlug, quantity + @_add itemSlug, quantity, options @trigger c.event.add, this, itemSlug, quantity @trigger c.event.change, this return this @@ -209,7 +209,8 @@ module.exports = class Inventory extends BaseModel # Private Methods ############################################################################## - _add: (itemSlug, quantity=1)-> + _add: (itemSlug, quantity=1, options={})-> + options.insert ?= false return unless itemSlug? return unless quantity > 0 @@ -218,7 +219,10 @@ module.exports = class Inventory extends BaseModel stack = new Stack itemSlug:itemSlug, quantity:quantity @listenTo stack, c.event.change, => @trigger c.event.change, this @_stacks[itemSlug] = stack - @_itemSlugs.push itemSlug + if options.insert + @_itemSlugs.unshift itemSlug + else + @_itemSlugs.push itemSlug @_sort() else stack.quantity += quantity diff --git a/src/client/models/site/craft_page.coffee b/src/client/models/site/craft_page.coffee index 106160c40..3085cc24f 100644 --- a/src/client/models/site/craft_page.coffee +++ b/src/client/models/site/craft_page.coffee @@ -40,6 +40,7 @@ module.exports = class CraftPage extends BaseModel inventory.each (stack)=> item = @modPack.findItem stack.itemSlug, enableAsNeeded:true return unless item? and item.isCraftable + @craftsman.want.add stack.itemSlug, stack.quantity inventory.remove stack.itemSlug diff --git a/src/client/site/craft_page/craft_page.jade b/src/client/site/craft_page/craft_page.jade index 9ab7647c6..2891e90a1 100644 --- a/src/client/site/craft_page/craft_page.jade +++ b/src/client/site/craft_page/craft_page.jade @@ -51,8 +51,6 @@ .panel .view__inventory.large.editable - section.view__craftsman_working - section.need h2 Need to Gather .panel @@ -60,4 +58,6 @@ section.steps h2 Steps - .panel \ No newline at end of file + .panel + + section.view__craftsman_working \ No newline at end of file diff --git a/src/client/site/craft_page/craft_page.scss b/src/client/site/craft_page/craft_page.scss index 76e136f9d..c570d8534 100644 --- a/src/client/site/craft_page/craft_page.scss +++ b/src/client/site/craft_page/craft_page.scss @@ -49,4 +49,14 @@ } } } + + &.outdated { + section.need .panel { + background: $color-white url('/images/panel-background-outdated.png') repeat; + } + + section.steps .panel { + background: $color-white url('/images/panel-background-outdated.png') repeat; + } + } } diff --git a/src/client/site/craft_page/craft_page_controller.coffee b/src/client/site/craft_page/craft_page_controller.coffee index 7f08eb495..e7052e436 100644 --- a/src/client/site/craft_page/craft_page_controller.coffee +++ b/src/client/site/craft_page/craft_page_controller.coffee @@ -97,6 +97,7 @@ module.exports = class CraftPageController extends PageController @_workingSectionController = @addChild CraftsmanWorkingController, '.view__craftsman_working', model: @model.craftsman + @_workingSectionController.on c.event.click, -> window.scrollTo 0, 0 @$haveSection = @$('section.have') @$instructionsSection = @$('section.instructions') @@ -117,6 +118,7 @@ module.exports = class CraftPageController extends PageController refresh: -> @_needInventoryController.model = @model.craftsman.plan?.need + @_refreshOutdated() @_refreshSectionVisibility() @_refreshSteps() @_adsenseController.fillAdPositions() @@ -134,7 +136,7 @@ module.exports = class CraftPageController extends PageController controller.model.addToolsTo @model.craftsman.want _completeStep: (controller)-> - controller.model.completeInto @model.craftsman.have + controller.markComplete @model.craftsman.have _isAddingToolsPossible: (controller)-> tools = controller.model.recipe.tools @@ -156,6 +158,12 @@ module.exports = class CraftPageController extends PageController return true + _refreshOutdated: -> + if @model.craftsman.stage is Craftsman::STAGE.OUTDATED + @$el.addClass 'outdated' + else + @$el.removeClass 'outdated' + _refreshSectionVisibility: -> return unless @_rendered @@ -168,11 +176,13 @@ module.exports = class CraftPageController extends PageController if @model.craftsman.want.isEmpty visibleSections.push el for el in [@$instructionsSection, @$wantSection] else if @model.craftsman.stage is Craftsman::STAGE.INVALID - visibleSections.push el for el in [@$wantSection, @$workingSection] + visibleSections.push el for el in [@$wantSection, @$haveSection, @$workingSection] else if not @model.craftsman.complete - visibleSections.push el for el in [@$wantSection, @$workingSection] + visibleSections.push el for el in [@$wantSection, @$haveSection, @$workingSection] else - visibleSections.push el for el in [@$haveSection, @$needSection, @$stepsSection, @$wantSection] + visibleSections.push el for el in [@$haveSection, @$wantSection, @$workingSection] + if @model.craftsman.plan? + visibleSections.push el for el in [@$needSection, @$stepsSection] @hide $el for $el in allSections @show $el for $el in visibleSections diff --git a/src/client/site/craft_page/craftsman_working/craftsman_working.jade b/src/client/site/craft_page/craftsman_working/craftsman_working.jade index 4340f63d6..811282ec2 100644 --- a/src/client/site/craft_page/craftsman_working/craftsman_working.jade +++ b/src/client/site/craft_page/craftsman_working/craftsman_working.jade @@ -5,11 +5,16 @@ //- All rights reserved. //- -.view__item_group.section - .content +.view__craftsman_working + .panel .waiting img(src='/images/wait.gif') .message p .count p + .button: .bezel: p Calculate + + .outdated + .message Crafting plan is out of date! + .button: .bezel: p Recalculate \ No newline at end of file diff --git a/src/client/site/craft_page/craftsman_working/craftsman_working.scss b/src/client/site/craft_page/craftsman_working/craftsman_working.scss index 8ccc10cf3..c456b059a 100644 --- a/src/client/site/craft_page/craftsman_working/craftsman_working.scss +++ b/src/client/site/craft_page/craftsman_working/craftsman_working.scss @@ -6,10 +6,7 @@ All rights reserved. */ .view__craftsman_working { - .content { - background: $color-white; - box-shadow: none; - + .panel { align-items : center; display : flex; flex-direction : column; @@ -34,5 +31,39 @@ All rights reserved. font-size: $font-size-medium; } } + + .button { + margin-top: $size-margin-large; + height: $size-minecraft-block * 2; + width: 50%; + + p { + font-size: $font-size-xxlarge; + transform: translateY(-25%); + } + } + } + + .outdated { + position: fixed; top: 0; left: 0; right: 0; + + + background: fade-out($color-white, 0.15) url('/images/panel-background-outdated.png'); + border-bottom: $size-border-medium solid $color-black; + + display: flex; + flex-direction: column; + align-items: center; + + .message { + margin-top: $size-margin-medium; + font-family: $font-family-header; + font-size: $font-size-xlarge; + } + + .button { + width: $size-minecraft-block * 10; + margin: $size-margin-medium; + } } } diff --git a/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee b/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee index cac9b0fb1..43ebe57b4 100644 --- a/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee +++ b/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee @@ -12,48 +12,94 @@ Craftsman = require '../../../models/crafting/craftsman' module.exports = class CraftsmanWorkingController extends BaseController + @::HIDE_TIMER_DURATION = 2000 + constructor: (options={})-> if not options.model then throw new Error 'options.model is required' options.templateName = 'craft_page/craftsman_working' super options - @model.on c.event.change, => @_refreshStatusText() + @_hideTimer = null + + # Event Methods ################################################################################ + + onButtonClicked: -> + @trigger c.event.click + @model.reset() + @model.work() + return false # BaseController Methods ####################################################################### + onDidModelChange: -> + @refresh() + onDidRender: -> - @$message = @$('.message p') - @$count = @$('.count p') - @$waiting = @$('.waiting') + @$button = @$('.button') + @$count = @$('.count p') + @$message = @$('.message p') + @$outdated = @$('.outdated') + @$waiting = @$('.waiting') + + @_controls = [@$button, @$count, @$message, @$outdated, @$waiting] super refresh: -> - @_refreshStatusText() - super - - # Private Methods ############################################################################## - - _refreshStatusText: -> return unless @$message? and @$count? - @show @$waiting + button = count = message = outdated = waiting = null + switch @model.stage - when Craftsman::STAGE.WAITING - @$message.html 'Preparing crafting calculation...' - @$count.html '' + when Craftsman::STAGE.READY + message = 'Ready to compute crafting plan!' + count = 'Click "Calculate" to continue.' + button = true when Craftsman::STAGE.GRAPHING - @$message.html 'Researching recipes...' - @$count.html "Found #{@model.stageCount} recipes so far..." + message = 'Researching recipes...' + count = "Found #{@model.stageCount} recipes so far..." + watiing = true when Craftsman::STAGE.PLANNING - @$message.html 'Figuring out possible crafting plans...' - @$count.html "Found #{@model.stageCount} possibilities so far..." + message = 'Figuring out possible crafting plans...' + count = "Found #{@model.stageCount} possibilities so far..." + watiing = true when Craftsman::STAGE.ANALYZING - @$message.html 'Looking for the best plan...' - @$count.html "Finished checking #{@model.stageCount} so far..." + message = 'Looking for the best plan...' + count = "Finished checking #{@model.stageCount} so far..." + watiing = true when Craftsman::STAGE.COMPLETE - @$message.html 'All done!' - @$count.html '' + message = 'Crafting plan is complete.' when Craftsman::STAGE.INVALID - @$message.html 'Couldn\'t make a crafting plan' - @$count.html '' - @hide @waiting + message = 'Couldn\'t make a crafting plan!' + count = 'Please report this problem using the Feedback box.' + when Craftsman::STAGE.OUTDATED + message = 'Your crafting plan is out of date!' + count = 'Click "Calculate" to re-compute.' + button = true + outdated = true + + @hide(control) for control in @_controls + + if button? + @show @$button + + if count? + @show @$count + @$count.html count + + if message? + @show @$message + @$message.html message + + if waiting? + @show @$waiting + + if outdated? + @show @$outdated + + super + + # Backbone.View Overrides ###################################################################### + + events: -> + return _.extend super, + 'click .button': 'onButtonClicked' diff --git a/src/client/site/craft_page/step/step.scss b/src/client/site/craft_page/step/step.scss index d5fe5fb2a..8a9687c19 100644 --- a/src/client/site/craft_page/step/step.scss +++ b/src/client/site/craft_page/step/step.scss @@ -53,4 +53,12 @@ } } } + + &.complete { + opacity: 0.25; + + h3 { + text-decoration: line-through; + } + } } \ No newline at end of file diff --git a/src/client/site/craft_page/step/step_controller.coffee b/src/client/site/craft_page/step/step_controller.coffee index 52efa6a05..899265683 100644 --- a/src/client/site/craft_page/step/step_controller.coffee +++ b/src/client/site/craft_page/step/step_controller.coffee @@ -29,6 +29,13 @@ module.exports = class StepController extends BaseController @onComplete = options.onComplete or (controller)-> # do nothing @onAddTools = options.onAddTools or (controller)-> # do nothing + # Public Methods ############################################################################### + + markComplete: (targetInventory)-> + @$el.addClass 'complete' + @$completeButton.addClass 'disabled' + @model.completeInto targetInventory + # Event Methods ################################################################################ onCompleteButtonClicked: (event)-> @@ -63,6 +70,9 @@ module.exports = class StepController extends BaseController onWillChangeModel: (oldModel, newModel)-> if not newModel? then throw new Error 'model cannot be null' + if @rendered + @$el.removeClass 'complete' + @$completeButton.removeClass 'disabled' return super refresh: ->