diff --git a/src/css/templates/crafting_table.scss b/src/css/templates/crafting_table.scss index e21127d85..56a5c76c6 100644 --- a/src/css/templates/crafting_table.scss +++ b/src/css/templates/crafting_table.scss @@ -9,13 +9,40 @@ All rights reserved. min-height: 14em; width: 100%; + .panel { position: absolute; top: 5em; right: 2em; bottom: 0; left: 2em; background: $color-table-background; + .prev { + background: url('/images/arrow-left-disabled.png'); + position: absolute; top: 50%; left: 1em; height: 8em; width: 4em; + @include transform(translateY(-50%)); + + &.enabled { + background: url('/images/arrow-left.png'); + cursor: pointer; + + &:hover { background: url('/images/arrow-left-hover.png'); } + } + } + .view__crafting_grid { position: absolute; top: 50%; left: 33%; @include transform(translate(-50%, -50%)); } + + .next { + background: url('/images/arrow-right-disabled.png'); + position: absolute; top: 50%; right: 1em; height: 8em; width: 4em; + @include transform(translateY(-50%)); + + &.enabled { + background: url('/images/arrow-right.png'); + cursor: pointer; + + &:hover { background: url('/images/arrow-right-hover.png'); } + } + } } } diff --git a/src/design/arrow.graffle b/src/design/arrow.graffle new file mode 100644 index 000000000..3e835e79c --- /dev/null +++ b/src/design/arrow.graffle @@ -0,0 +1,554 @@ + + + + + ApplicationVersion + + com.omnigroup.OmniGraffle.MacAppStore + 139.18 + + CreationDate + 2015-01-08 19:09:04 +0000 + Creator + Andrew Miner + GraphDocumentVersion + 8 + GuidesLocked + NO + GuidesVisible + YES + ImageCounter + 1 + LinksVisible + NO + MagnetsVisible + NO + MasterSheets + + ModificationDate + 2015-01-08 19:15:47 +0000 + Modifier + Andrew Miner + NotesVisible + NO + 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 + + + ReadOnly + NO + Sheets + + + ActiveLayerIndex + 0 + AutoAdjust + + BackgroundGraphic + + Bounds + {{0, 0}, {40, 80}} + Class + SolidGraphic + ID + 2 + Style + + shadow + + Draws + NO + + stroke + + Draws + NO + + + + BaseZoom + 0 + CanvasOrigin + {0, 0} + CanvasSize + {40, 80} + ColumnAlign + 1 + ColumnSpacing + 36 + DisplayScale + 1 pt = 1 px + GraphicsList + + + AllowConnections + NO + AllowLabelDrop + + AllowToConnect + + Class + LineGraphic + ID + 3 + Points + + {30, 10} + {10, 40} + {30, 70} + + Style + + stroke + + Color + + b + 0.755581 + g + 0.755568 + r + 0.755591 + + HeadArrow + 0 + Legacy + + TailArrow + 0 + Width + 4 + + + + + GridInfo + + GridSpacing + 10 + MajorGridSpacing + 10 + ShowsGrid + YES + SnapsToGrid + YES + + HPages + 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 + + Orientation + 2 + PrintOnePage + + RowAlign + 1 + RowSpacing + 36 + SheetTitle + normal + UniqueID + 1 + VPages + 1 + + + ActiveLayerIndex + 0 + AutoAdjust + + BackgroundGraphic + + Bounds + {{0, 0}, {40, 80}} + Class + SolidGraphic + ID + 2 + Style + + shadow + + Draws + NO + + stroke + + Draws + NO + + + + BaseZoom + 0 + CanvasOrigin + {0, 0} + CanvasSize + {40, 80} + ColumnAlign + 1 + ColumnSpacing + 36 + DisplayScale + 1 pt = 1 px + GraphicsList + + + AllowConnections + NO + AllowLabelDrop + + AllowToConnect + + Class + LineGraphic + ID + 3 + Points + + {30, 10} + {10, 40} + {30, 70} + + Style + + stroke + + Color + + b + 0.424669 + g + 0.424661 + r + 0.424674 + + HeadArrow + 0 + Legacy + + TailArrow + 0 + Width + 4 + + + + + GridInfo + + GridSpacing + 10 + MajorGridSpacing + 10 + ShowsGrid + YES + SnapsToGrid + YES + + HPages + 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 + + Orientation + 2 + PrintOnePage + + RowAlign + 1 + RowSpacing + 36 + SheetTitle + hover + UniqueID + 2 + VPages + 1 + + + ActiveLayerIndex + 0 + AutoAdjust + + BackgroundGraphic + + Bounds + {{0, 0}, {40, 80}} + Class + SolidGraphic + ID + 2 + Style + + shadow + + Draws + NO + + stroke + + Draws + NO + + + + BaseZoom + 0 + CanvasOrigin + {0, 0} + CanvasSize + {40, 80} + ColumnAlign + 1 + ColumnSpacing + 36 + DisplayScale + 1 pt = 1 px + GraphicsList + + + AllowConnections + NO + AllowLabelDrop + + AllowToConnect + + Class + LineGraphic + ID + 3 + Points + + {30, 10} + {10, 40} + {30, 70} + + Style + + stroke + + Color + + b + 0.937305 + g + 0.937289 + r + 0.937317 + + HeadArrow + 0 + Legacy + + TailArrow + 0 + Width + 4 + + + + + GridInfo + + GridSpacing + 10 + MajorGridSpacing + 10 + ShowsGrid + YES + SnapsToGrid + YES + + HPages + 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 + + Orientation + 2 + PrintOnePage + + RowAlign + 1 + RowSpacing + 36 + SheetTitle + disabled + UniqueID + 3 + VPages + 1 + + + SmartAlignmentGuidesActive + YES + SmartDistanceGuidesActive + YES + UseEntirePage + + WindowInfo + + CurrentSheet + 2 + ExpandedCanvases + + Frame + {{306, -0}, {974, 777}} + ListView + + OutlineWidth + 142 + RightSidebar + + ShowRuler + + Sidebar + + SidebarWidth + 120 + VisibleRegion + {{-53, -15}, {146.67832705845066, 111.0139900859549}} + Zoom + 5.7199997901916504 + ZoomValues + + + normal + 5.7199997901916504 + 5.630000114440918 + + + hover + 5.7199997901916504 + 1 + + + disabled + 5.7199997901916504 + 1 + + + + + diff --git a/src/images/arrow-left-disabled.png b/src/images/arrow-left-disabled.png new file mode 100644 index 000000000..8ce5770fc Binary files /dev/null and b/src/images/arrow-left-disabled.png differ diff --git a/src/images/arrow-left-hover.png b/src/images/arrow-left-hover.png new file mode 100644 index 000000000..f635425a4 Binary files /dev/null and b/src/images/arrow-left-hover.png differ diff --git a/src/images/arrow-left.png b/src/images/arrow-left.png new file mode 100644 index 000000000..8088ee2ed Binary files /dev/null and b/src/images/arrow-left.png differ diff --git a/src/images/arrow-right-disabled.png b/src/images/arrow-right-disabled.png new file mode 100644 index 000000000..764784a41 Binary files /dev/null and b/src/images/arrow-right-disabled.png differ diff --git a/src/images/arrow-right-hover.png b/src/images/arrow-right-hover.png new file mode 100644 index 000000000..ace111db5 Binary files /dev/null and b/src/images/arrow-right-hover.png differ diff --git a/src/images/arrow-right.png b/src/images/arrow-right.png new file mode 100644 index 000000000..c0ba334a6 Binary files /dev/null and b/src/images/arrow-right.png differ diff --git a/src/scripts/controllers/crafting_table_controller.coffee b/src/scripts/controllers/crafting_table_controller.coffee index a13e6252d..3bc6d80de 100644 --- a/src/scripts/controllers/crafting_table_controller.coffee +++ b/src/scripts/controllers/crafting_table_controller.coffee @@ -17,11 +17,35 @@ module.exports = class CraftingTableController extends BaseController options.templateName = 'crafting_table' super options + # Event Methods ################################################################################ + + onNextClicked: -> + @model.step += 1 + + onPrevClicked: -> + @model.step -= 1 + # BaseController Overrides ##################################################################### onDidRender: -> @gridController = @addChild CraftingGridController, '.view__crafting_grid', model:@model.grid - @$nextButton = @$('button[name="next"]') - @$prevButton = @$('button[name="prev"]') + @$next = @$('.next') + @$prev = @$('.prev') super + + refresh: -> + @$prev.removeClass 'enabled' + @$next.removeClass 'enabled' + + if @model.hasSteps + if @model.hasPrevStep then @$prev.addClass 'enabled' + if @model.hasNextStep then @$next.addClass 'enabled' + + super + + # Backbone.View Overrides ###################################################################### + + events: + 'click .next': 'onNextClicked' + 'click .prev': 'onPrevClicked' diff --git a/src/scripts/models/crafting_table.coffee b/src/scripts/models/crafting_table.coffee index 513f5746f..efa1ea8cd 100644 --- a/src/scripts/models/crafting_table.coffee +++ b/src/scripts/models/crafting_table.coffee @@ -15,23 +15,70 @@ module.exports = class CraftingTable extends BaseModel constructor: (attributes={}, options={})-> if not attributes.plan? then throw new Error "attributes.plan is required" attributes.grid ?= new CraftingGrid modPack:attributes.plan.modPack - attributes.step ?= 0 super attributes, options @plan.on 'change', => @reset() + @_step = 0 + @_steps = [] + + Object.defineProperties this, { + hasNextStep: { get:@hasNextStep } + hasPrevStep: { get:@hasPrevStep } + hasSteps: { get:@hasSteps } + step: { get:@getStep, set:@setStep } + } # Public Methods ############################################################################### reset: -> - logger.trace "CraftingTable.reset()" - + @_compactSteps() @step = 0 - @grid.recipe = @plan.steps[0] + + return this + + # Property Methods ############################################################################# + + hasNextStep: -> + return @_step + 1 < @_steps.length + + hasPrevStep: -> + return @_step > 0 + + getStep: -> + return @_step + + setStep: (newStep)-> + newStep = Math.max 0, Math.min @_steps.length, newStep + + @_step = newStep + @grid.recipe = @_steps[@_step]?.recipe @trigger 'change', this return this + hasSteps: -> + return @_steps.length > 0 + # Object Overrides ############################################################################# toString: -> - return "#{@constructor.name} (#{@cid}) { plan:#{@plan}, step:#{@step} }" + return "#{@constructor.name} (#{@cid}) { plan:#{@plan}, step:#{@_step} }" + + # Private Methods ############################################################################## + + _compactSteps: -> + @_steps = [] + currentStep = null + + for recipe in @plan.steps + if currentStep? + if currentStep.recipe.name is recipe.name + currentStep.multiplier += 1 + else + currentStep = null + + if not currentStep + currentStep = multiplier:1, recipe:recipe + @_steps.push currentStep + + return @_steps diff --git a/src/scripts/models/recipe.coffee b/src/scripts/models/recipe.coffee index 5c3858471..7fde69733 100644 --- a/src/scripts/models/recipe.coffee +++ b/src/scripts/models/recipe.coffee @@ -27,6 +27,7 @@ module.exports = class Recipe extends BaseModel getItemSlugAt: (index)-> patternDigit = @pattern[index] return null unless patternDigit? + return null unless patternDigit.match /[0-9]/ stack = @input[parseInt(patternDigit)] return null unless stack? diff --git a/src/templates/crafting_table.jade b/src/templates/crafting_table.jade index 3a95b69ae..9109beb24 100644 --- a/src/templates/crafting_table.jade +++ b/src/templates/crafting_table.jade @@ -11,4 +11,6 @@ p Crafting Table .panel + .prev table.view__crafting_grid + .next