Skip to content

Commit

Permalink
TapBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Tellevik committed Oct 19, 2020
1 parent 95a4e89 commit 3045b97
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
32 changes: 32 additions & 0 deletions source/Delegate/SelectNumberOfHolesDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,36 @@ class SelectNumberOfHolesDelegate extends Ui.BehaviorDelegate{
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;
}

}
6 changes: 5 additions & 1 deletion source/Gui/SelectNumberOfHoles.mc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ module Gui{
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;
}
Expand Down Expand Up @@ -45,7 +49,7 @@ module Gui{
var pos = [numberPos[0] - 15, numberPos[1] - 10];

setArrowPos(up, down, pos);

mDc.fillPolygon(up);
mDc.fillPolygon(down);

Expand Down
5 changes: 5 additions & 0 deletions source/Model/Course.mc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ class Course{
}

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(keepScore != null && keepScore.size() > i && keepScore[i].isRegistered()){
mHoles[i].setThrows(keepScore[i].getThrows());
mHoles[i].setPar(keepScore[i].getPar());
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion source/View/SelectNumberOfHole.mc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Toybox.WatchUi as Ui;

class SelectNumberOfHolesView extends Ui.View{

hidden var gui;
var gui;
hidden var mController;

hidden const MAX = 36;
Expand Down Expand Up @@ -41,6 +41,9 @@ class SelectNumberOfHolesView extends Ui.View{
function setHole(){
var holes = gui.getNumberOfHoles();
mController.createNewCourse(holes);
if(mController.getGame().getActiveHole().getIndex() >= holes){
mController.getGame().selectHole(holes - 1);
}
}

function addHole(){
Expand Down

0 comments on commit 3045b97

Please sign in to comment.