From fb3db0f3933173c3cccf5212cf30be6cf41fbcd9 Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Thu, 8 Jan 2015 12:34:33 -0800 Subject: [PATCH] Add in next/prev buttons for crafting table --- src/css/templates/crafting_table.scss | 27 + src/design/arrow.graffle | 554 ++++++++++++++++++ src/images/arrow-left-disabled.png | Bin 0 -> 282 bytes src/images/arrow-left-hover.png | Bin 0 -> 302 bytes src/images/arrow-left.png | Bin 0 -> 282 bytes src/images/arrow-right-disabled.png | Bin 0 -> 277 bytes src/images/arrow-right-hover.png | Bin 0 -> 296 bytes src/images/arrow-right.png | Bin 0 -> 280 bytes .../crafting_table_controller.coffee | 28 +- src/scripts/models/crafting_table.coffee | 57 +- src/scripts/models/recipe.coffee | 1 + src/templates/crafting_table.jade | 2 + 12 files changed, 662 insertions(+), 7 deletions(-) create mode 100644 src/design/arrow.graffle create mode 100644 src/images/arrow-left-disabled.png create mode 100644 src/images/arrow-left-hover.png create mode 100644 src/images/arrow-left.png create mode 100644 src/images/arrow-right-disabled.png create mode 100644 src/images/arrow-right-hover.png create mode 100644 src/images/arrow-right.png 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 0000000000000000000000000000000000000000..8ce5770fc2d6bf8e0a616f46c9939b63c4254fbd GIT binary patch literal 282 zcmV+#0p^` zaI;aq&r;=5O4I$BY{N>*l*>7vN}=slPOe}nv%Z(BW0s_?v*%@Lt!XJe%F>p94%!cA z4_auU?SXcJwg+0TOuIk}Ews==t4q5;+XJnWrL~koS6SMff}34uC>5L=#H-XSN-vVS z&5Vt0MvHo9HA8&}wc0E~{jI|T)KGIA>y6q&4K>tI|Lau=)KEix9JQ0CmU>2qA)b0COl`Inn~{dH?_b07*qoM6N<$f-EO_i~s-t literal 0 HcmV?d00001 diff --git a/src/images/arrow-left-hover.png b/src/images/arrow-left-hover.png new file mode 100644 index 0000000000000000000000000000000000000000..f635425a4fc51ef490dbcddeae896a1c7b54b6f6 GIT binary patch literal 302 zcmV+}0nz@6P)Nkl z{Uwdb#xM+LsdD2uo>H;dITvkMNttpn#zQLfc$bqa*!O+6ESC$mlC*i;m1*Y?!cmqs zeY--ta?gVnT4<}MwbIa5PitjlX;YaSw9rBeEwrMv_6^$VX>End(&pKF%F>n!+Ns&D zGn9_;ZDC{X)Min4kyz}X_H&z&qb{vxsJEh)nnkF8b$EapYK~)jqn0~2LJc+4d!v@V zDuEhms5hdPx!e9iJxLXmeq6So)_tBw2qA)b0T%mfn>gUn`v3p{07*qoM6N<$f;Os( A(f|Me literal 0 HcmV?d00001 diff --git a/src/images/arrow-left.png b/src/images/arrow-left.png new file mode 100644 index 0000000000000000000000000000000000000000..8088ee2ed9cfb1e69a41d168124ae650f104bbf4 GIT binary patch literal 282 zcmV+#0p?I-ZFH+@7DQ7G8u&L`TGUaNmr=0V&DW_G?R`0eeSFP}%O6%pKGOd^Gm1zUCp9ETH zp>2WIOGDcNZIq?8awD|RLJKXly0jy-Ezky8T8|aF%hJ9nIQemg((^a$iGBAhwTjX& z$;#Zn_{_*r2dIytR$E1=kJ>yy4K>@b)~F-YP(uy%zaEu94K>u?qYmoSi&R1B%VnFN gf8FbOgb*T_Cp(oyl4x@LB7jc^-bTRaDT$qJ~ASehG=NDvO%wxjP^x;4VA>?gJDMv}O zq`8!GvMVTQj)=N^k(q;Y!7AxiYwc_bM#TBG;8ODHc8b%gq!)E&_VJ7_wWJa1Us1cA zBGgbr{Q>m=b<5P#9;h!+Lk%_5Q2SF~pl+FZbf>=Cl&iINl5VyIC0*CV5pm{{d`TOb z+1t|E++O?tAGEE}4$wl|>~m@lv=g+@LJMsRqYP-Fg?77~_pEtiHOg+T=e=BJzn(`3 bA%C6+{|R3?xs;T800000NkvXXu0mjfbk%!h literal 0 HcmV?d00001 diff --git a/src/images/arrow-right-hover.png b/src/images/arrow-right-hover.png new file mode 100644 index 0000000000000000000000000000000000000000..ace111db5a163ac4c53b384ae1bba937c80a0406 GIT binary patch literal 296 zcmV+@0oVSCP)j)u)d`(K} z7-M|S>tt6@#X<;KtNebA<9M(wIG4QVoOezI`_F<}!!TT}cCnPYEq2k1dYY!aN?B7E z)-%*wQCsaI)KEkHLsSOpW~o)$p1PF2Kn*q2P(y7_Emo+TrPfKerY`GYQ%=_;nzn5V zYRXo6~Fm{e!kCTASej+G=U7$0>VS>yaK>XrZlv*5)b$T4CD?*GBwANxaDhN&t-2q7P{EX&Qz z9{ah=72J#Eezu5cl?$f3&zV`v6m<9QwV;`0M2u3m= + @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