diff --git a/resources/Menus/MainMenu.xml b/resources/Menus/MainMenu.xml index 942732f..7c694c8 100644 --- a/resources/Menus/MainMenu.xml +++ b/resources/Menus/MainMenu.xml @@ -1,6 +1,7 @@ + \ No newline at end of file diff --git a/resources/strings/strings.xml b/resources/strings/strings.xml index 920109a..27cb8de 100644 --- a/resources/strings/strings.xml +++ b/resources/strings/strings.xml @@ -7,4 +7,8 @@ Edit Par New game Scorecard + Number of holes + + + Number of holes diff --git a/source/Delegate/MainMenuDelegate.mc b/source/Delegate/MainMenuDelegate.mc index 1a8a675..551868b 100644 --- a/source/Delegate/MainMenuDelegate.mc +++ b/source/Delegate/MainMenuDelegate.mc @@ -19,8 +19,11 @@ class MainMenuDelegate extends Ui.MenuInputDelegate{ }else if(item == :scorecard){ var view = new ScoreCardView(mController); Ui.switchToView(view, new ScoreCardDelegate(view, mController), Ui.SLIDE_UP); + }else if(item == :numberOfHoles){ + var picker = new SelectNumberOfHolesView(mController); + Ui.pushView(picker, new SelectNumberOfHolesDelegate(picker, mController), Ui.SLIDE_UP); } - + if(item == :changePar){ mController.editPar = true; } diff --git a/source/Delegate/ScoreCardDelegate.mc b/source/Delegate/ScoreCardDelegate.mc index 1218a32..53c2e9f 100644 --- a/source/Delegate/ScoreCardDelegate.mc +++ b/source/Delegate/ScoreCardDelegate.mc @@ -16,10 +16,10 @@ class ScoreCardDelegate extends Ui.BehaviorDelegate{ switch(key){ case Ui.KEY_UP: - relatedView.shiftScoreCard(); + relatedView.previousPage(); break; case Ui.KEY_DOWN: - relatedView.shiftScoreCard(); + relatedView.nextPage(); break; } relatedView.requestUpdate(); @@ -27,7 +27,7 @@ class ScoreCardDelegate extends Ui.BehaviorDelegate{ } function onTap(clickEvent) { - relatedView.shiftScoreCard(); + relatedView.nextPage(); relatedView.requestUpdate(); return false; } diff --git a/source/Delegate/SelectNumberOfHolesDelegate.mc b/source/Delegate/SelectNumberOfHolesDelegate.mc new file mode 100644 index 0000000..3bda678 --- /dev/null +++ b/source/Delegate/SelectNumberOfHolesDelegate.mc @@ -0,0 +1,70 @@ +using Toybox.WatchUi as Ui; + +class SelectNumberOfHolesDelegate extends Ui.BehaviorDelegate{ + + hidden var mController; + hidden var relatedView; + + function initialize(view, controller) { + BehaviorDelegate.initialize(); + relatedView = view; + mController = controller; + } + + function onCancel() { + WatchUi.popView(WatchUi.SLIDE_IMMEDIATE); + } + + function onKey(keyEvent) { + var key = keyEvent.getKey(); + + switch(key){ + case Ui.KEY_UP: + relatedView.addHole(); + break; + case Ui.KEY_DOWN: + relatedView.removeHole(); + break; + case Ui.KEY_ENTER: + relatedView.setHole(); + Ui.popView(Ui.SLIDE_IMMEDIATE); + return false; + break; + } + relatedView.requestUpdate(); + return false; + } + + function onTap(keyEvent){ + + if(tapUp(keyEvent)){ + relatedView.addHole(); + } + if(tapDown(keyEvent)){ + relatedView.removeHole(); + } + relatedView.requestUpdate(); + + return false; + } + + hidden function tapDown(keyEvent) { + var coordinates = keyEvent.getCoordinates(); + var gui = relatedView.gui; + var tapDown = gui.tapBoxDown; + + return coordinates[0] > tapDown[0] && coordinates[0] < tapDown[0] + gui.TAP_BOX_WIDTH + && coordinates[1] > tapDown[1] && coordinates[1] < tapDown[1] + gui.TAP_BOX_HEIGHT; + + } + + hidden function tapUp(keyEvent) { + var coordinates = keyEvent.getCoordinates(); + var gui = relatedView.gui; + var tapUp = gui.tapBoxUp; + + return coordinates[0] > tapUp[0] && coordinates[0] < tapUp[0] + gui.TAP_BOX_WIDTH + && coordinates[1] > tapUp[1] && coordinates[1] < tapUp[1] + gui.TAP_BOX_HEIGHT; + } + +} \ No newline at end of file diff --git a/source/Gui/Gui.mc b/source/Gui/Gui.mc index eb95a85..5b211d1 100644 --- a/source/Gui/Gui.mc +++ b/source/Gui/Gui.mc @@ -15,8 +15,15 @@ module Gui { /** TEXT JUSTIFYCATION **/ const CENTER_TEXT = Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER; - - + + + /** Arrows **/ + const UP_ARROW = [[0,20], [30,20], [15,0]]; + const DOWN_ARROW = [[0,0], [30,0], [15,20]]; + + + const TAP_BOX_HEIGHT = 50; + const TAP_BOX_WIDTH = 50; /** COLORS **/ const BLACK = Gfx.COLOR_BLACK; diff --git a/source/Gui/MainGui.mc b/source/Gui/MainGui.mc index c6613a7..ea5f49c 100644 --- a/source/Gui/MainGui.mc +++ b/source/Gui/MainGui.mc @@ -9,11 +9,8 @@ module Gui{ class MainGui extends CommonGui{ - const UP_ARROW = [[0,20], [30,20], [15,0]]; - const DOWN_ARROW = [[0,0], [30,0], [15,20]]; + - const TAP_BOX_HEIGHT = 50; - const TAP_BOX_WIDTH = 50; var tapBoxUp; var tapBoxDown; @@ -119,8 +116,8 @@ module Gui{ editParValue(MEDIUM_FONT); }else if(version == Vivoactive){ editParValue(SMALL_FONT); - }else if(version == Forerunner645){ - editParValue(TINY_FONT|| version == Big); + }else if(version == Forerunner645 || version == Big){ + editParValue(TINY_FONT); } }else{ diff --git a/source/Gui/ScoreCardGui.mc b/source/Gui/ScoreCardGui.mc index e1cffe8..38c4f86 100644 --- a/source/Gui/ScoreCardGui.mc +++ b/source/Gui/ScoreCardGui.mc @@ -44,17 +44,39 @@ module Gui{ } - function update(front) { + function update(page) { setColor(); drawTable(); - if(front){ - drawScoreFront9(); - }else{ - drawScoreBack9(); - } + drawScore(page); } + + hidden function drawScore(page){ + var startHole = 9*page - 8; + var lastHole = 9*page; + var holes = mController.getGame().getCourse().getHoles(); + if(holes.size() < lastHole){ + lastHole = holes.size(); + } + var title = "Hole " + startHole + "-" + lastHole; + titleText(title); + + var x = left + (columnWidth/2); + + + + for(var i = startHole; i <= lastHole; i++){ + drawTopLine(i, x); + x += columnWidth; + } + x = left + (columnWidth/2); + for(var i = startHole-1; i < lastHole; i++){ + color(holes[i], x); + drawBottomLine(throws(holes[i]), x); + x += columnWidth; + } + } hidden function drawTable() { diff --git a/source/Gui/SelectNumberOfHoles.mc b/source/Gui/SelectNumberOfHoles.mc new file mode 100644 index 0000000..40f90bf --- /dev/null +++ b/source/Gui/SelectNumberOfHoles.mc @@ -0,0 +1,84 @@ + +module Gui{ + class SelectNumberOfHoles extends CommonGui{ + + var tapBoxUp; + var tapBoxDown; + + hidden var numberPos; + hidden var arrowPos; + hidden var numberOfHoles; + + function initialize(dc, controller){ + CommonGui.initialize(dc, controller); + numberPos = [ width/2, height/2 ]; + + tapBoxUp = [numberPos[0] - 25, numberPos[1] - 75]; + tapBoxDown = [numberPos[0] - 25, numberPos[1] + 25]; + + numberOfHoles = controller.getGame().getCourse().getNumberOfHoles(); + } + + + function setNumberOfHoles(n){ + numberOfHoles = n; + } + + function getNumberOfHoles(){ + return numberOfHoles; + } + + function update(){ + setColor(); + updateNumber(); + } + + hidden function updateNumber(){ + drawArrows(); + drawNumber(); + } + + hidden function drawNumber(){ + drawText(numberOfHoles,numberPos, LARGE_FONT, CENTER_TEXT); + } + + hidden function drawArrows() { + var up = [UP_ARROW[0], UP_ARROW[1], UP_ARROW[2]]; + var down = [DOWN_ARROW[0], DOWN_ARROW[1], DOWN_ARROW[2]]; + + var pos = [numberPos[0] - 15, numberPos[1] - 10]; + + setArrowPos(up, down, pos); + + mDc.fillPolygon(up); + mDc.fillPolygon(down); + + resetArrowPos(up, down, pos); + } + + hidden function setArrowPos(up, down, pos) { + for(var i = 0; i < up.size(); i++){ + up[i][0] += pos[0]; + up[i][1] += pos[1] - 50; + } + + for(var i = 0; i < down.size(); i++){ + down[i][0] += pos[0]; + down[i][1] += pos[1] + 50; + } + } + + hidden function resetArrowPos(up, down, pos) { + for(var i = 0; i < up.size(); i++){ + up[i][0] -= pos[0]; + up[i][1] -= pos[1] - 50; + } + + for(var i = 0; i < down.size(); i++){ + down[i][0] -= pos[0]; + down[i][1] -= pos[1] + 50; + } + } + + } +} \ No newline at end of file diff --git a/source/Model/Controller.mc b/source/Model/Controller.mc index c41c853..c01c315 100644 --- a/source/Model/Controller.mc +++ b/source/Model/Controller.mc @@ -31,7 +31,11 @@ class Controller{ } } - + + function addHole(){ + + } + function parValue() { return mGame.getActiveHole().getPar().toString(); } @@ -140,4 +144,8 @@ class Controller{ } mGame.selectHole(0); } + + function createNewCourse(numberOfHoles){ + mGame.newCourse(numberOfHoles); + } } \ No newline at end of file diff --git a/source/Model/Course.mc b/source/Model/Course.mc index 1b5decf..086febe 100644 --- a/source/Model/Course.mc +++ b/source/Model/Course.mc @@ -2,18 +2,24 @@ class Course{ hidden var mHoles; + hidden var numberOfHoles; function initialize(state, par){ if(state == null){ - createNewCourse(par); + setUpCourse(par); }else{ lastCourse(state, par); } } - + + function getNumberOfHoles(){ + return numberOfHoles; + } + function lastCourse(state, par) { mHoles = new [state.size()]; + numberOfHoles = mHoles.size(); for(var i = 0; i < mHoles.size(); i++){ var hole = new Hole(i); if(state[i] != 0){ @@ -29,12 +35,35 @@ class Course{ } } - function createNewCourse(par) { - mHoles = new [18]; + hidden function setUpCourse(par) { + if(par == null){ + mHoles = new [18]; + numberOfHoles = mHoles.size(); + for(var i = 0; i < mHoles.size(); i++){ + mHoles[i] = new Hole(i); + } + }else{ + numberOfHoles = par.size(); + mHoles = new [numberOfHoles]; + + for(var i = 0; i < numberOfHoles; i++){ + mHoles[i] = new Hole(i); + mHoles[i].setPar(par[i]); + } + } + + + } + + function createCourse(holes){ + var keepScore = mHoles; + numberOfHoles = holes; + mHoles = new [numberOfHoles]; for(var i = 0; i < mHoles.size(); i++){ mHoles[i] = new Hole(i); - if(par != null){ - mHoles[i].setPar(par[i]); + if(keepScore != null && keepScore.size() > i && keepScore[i].isRegistered()){ + mHoles[i].setThrows(keepScore[i].getThrows()); + mHoles[i].setPar(keepScore[i].getPar()); } } } diff --git a/source/Model/Game.mc b/source/Model/Game.mc index 53f33d6..afb3025 100644 --- a/source/Model/Game.mc +++ b/source/Model/Game.mc @@ -6,7 +6,11 @@ class Game{ mCourse = course; activeHole = firstNotRegisterdHole(); } - + + function newCourse(numbOfHoles){ + mCourse.createCourse(numbOfHoles); + } + function firstNotRegisterdHole() { var holes = mCourse.getHoles(); for(var i = 0; i < holes.size(); i++){ diff --git a/source/View/ScoreCard.mc b/source/View/ScoreCard.mc index 852cb1b..d4d34c2 100644 --- a/source/View/ScoreCard.mc +++ b/source/View/ScoreCard.mc @@ -6,16 +6,28 @@ class ScoreCardView extends Ui.View{ hidden var gui; hidden var mController; hidden var front = true; + hidden var page = 1; + hidden var numberOfPages; function initialize(controller) { View.initialize(); mController = controller; + + numberOfPages = getNumberOfPages(); } function onLayout(dc) { gui = new Gui.ScoreCardGui(dc, mController); } - + + hidden function getNumberOfPages(){ + var numberOfHoles = mController.getGame().getCourse().getNumberOfHoles(); + var pages = numberOfHoles / 9; + if(numberOfHoles % 9 > 0){ + pages++; + } + return pages; + } // Called when this View is brought to the foreground. Restore // the state of this View and prepare it to be shown. This includes @@ -27,10 +39,26 @@ class ScoreCardView extends Ui.View{ function onUpdate(dc) { // Call the parent onUpdate function to redraw the layout View.onUpdate(dc); - gui.update(front); + gui.update(page); return true; } - + + function nextPage(){ + if(page == numberOfPages){ + page = 1; + }else{ + page++; + } + } + + function previousPage(){ + if(page == 1){ + page = numberOfPages; + }else{ + page--; + } + } + function shiftScoreCard() { if(front){ front = false; diff --git a/source/View/SelectNumberOfHole.mc b/source/View/SelectNumberOfHole.mc new file mode 100644 index 0000000..08ab520 --- /dev/null +++ b/source/View/SelectNumberOfHole.mc @@ -0,0 +1,66 @@ +using Toybox.WatchUi as Ui; + +class SelectNumberOfHolesView extends Ui.View{ + + var gui; + hidden var mController; + + hidden const MAX = 36; + hidden const MIN = 1; + + function initialize(controller) { + View.initialize(); + mController = controller; + } + + // Load your resources here + function onLayout(dc) { + gui = new Gui.SelectNumberOfHoles(dc, mController); + + } + + // Called when this View is brought to the foreground. Restore + // the state of this View and prepare it to be shown. This includes + // loading resources into memory. + function onShow() { + } + + // Update the view + function onUpdate(dc) { + // Call the parent onUpdate function to redraw the layout + View.onUpdate(dc); + gui.update(); + } + + // Called when this View is removed from the screen. Save the + // state of this View here. This includes freeing resources from + // memory. + function onHide() { + } + + function setHole(){ + var holes = gui.getNumberOfHoles(); + mController.createNewCourse(holes); + if(mController.getGame().getActiveHole().getIndex() >= holes){ + mController.getGame().selectHole(holes - 1); + } + } + + function addHole(){ + var holes = gui.getNumberOfHoles(); + if(holes < MAX){ + holes++; + } + gui.setNumberOfHoles(holes); + + } + + function removeHole(){ + var holes = gui.getNumberOfHoles(); + if(holes > MIN){ + holes--; + } + gui.setNumberOfHoles(holes); + + } +} \ No newline at end of file