This commit is contained in:
kejaro committed 2026-10-05 20:55:29 +01:00
1 parent f7bcbc53ef
commit 65b26786a0
39 files changed
+4710 -3044

No files matched your search

-2
View File
@@ -1,2 +0,0 @@
import Toybox.Lang;
import Toybox.WatchUi;
+19 -20
View File
@@ -6,28 +6,28 @@ class mainDelegate extends WatchUi.BehaviorDelegate {
function initialize() {
BehaviorDelegate.initialize();
// gMenuTeams = new WatchUi.Menu2({:title => "Select Team"});
// gMenuTeams.addItem(new WatchUi.MenuItem(HOME.toString(), null, HOME, null));
// gMenuTeams.addItem(new WatchUi.MenuItem(AWAY.toString(), null, AWAY, null));
gMenuTeams = new WatchUi.Menu2({:title => "Select Team"});
gMenuTeams.addItem(new WatchUi.MenuItem(HOME.toString(), null, HOME, null));
gMenuTeams.addItem(new WatchUi.MenuItem(AWAY.toString(), null, AWAY, null));
// gMenuActions = new WatchUi.Menu2({:title => "Select Action"});
// gMenuActions.addItem(new WatchUi.MenuItem("Record Goal", "FG, PC, or PS", GOAL, null));
// gMenuActions.addItem(new WatchUi.MenuItem("Record Card", "Green, Yellow, Red", CARD, null));
// gMenuActions.addItem(new WatchUi.MenuItem("Quit", "TODO:", QUIT, null));
gMenuActions = new WatchUi.Menu2({:title => "Select Action"});
gMenuActions.addItem(new WatchUi.MenuItem("Record Goal", "FG, PC, or PS", GOAL, null));
gMenuActions.addItem(new WatchUi.MenuItem("Record Card", "Green, Yellow, Red", CARD, null));
gMenuActions.addItem(new WatchUi.MenuItem("Quit", "TODO:", QUIT, null));
// gMenuGoals = new WatchUi.Menu2({:title => "Select Goal"});
// gMenuGoals.addItem(new WatchUi.MenuItem("Field Goal", null, FG, null));
// gMenuGoals.addItem(new WatchUi.MenuItem("Penaly Corner", null, PC, null));
// gMenuGoals.addItem(new WatchUi.MenuItem("Penalty Stroke", null, PS, null));
gMenuGoals = new WatchUi.Menu2({:title => "Select Goal"});
gMenuGoals.addItem(new WatchUi.MenuItem("Field Goal", null, FG, null));
gMenuGoals.addItem(new WatchUi.MenuItem("Penaly Corner", null, PC, null));
gMenuGoals.addItem(new WatchUi.MenuItem("Penalty Stroke", null, PS, null));
// gMenuCards = new WatchUi.Menu2({:title => "Select Card"});
// gMenuCards.addItem(new WatchUi.MenuItem("Green Card", null, GREEN, {:icon => $.gIconGreen}));
// gMenuCards.addItem(new WatchUi.MenuItem("Yellow Card", null, YELLOW, {:icon => $.gIconYellow}));
// gMenuCards.addItem(new WatchUi.MenuItem("Red Card", null, RED, {:icon => $.gIconRed}));
gMenuCards = new WatchUi.Menu2({:title => "Select Card"});
gMenuCards.addItem(new WatchUi.MenuItem("Green Card", null, GREEN, {:icon => $.gIconGreen}));
gMenuCards.addItem(new WatchUi.MenuItem("Yellow Card", null, YELLOW, {:icon => $.gIconYellow}));
gMenuCards.addItem(new WatchUi.MenuItem("Red Card", null, RED, {:icon => $.gIconRed}));
// gMenuApp = new WatchUi.Menu2({:title => "Select Action"});
// gMenuApp.addItem(new WatchUi.MenuItem("New Game", null, 0, null));
// gMenuApp.addItem(new WatchUi.MenuItem("Exit", null, 1, null));
gMenuApp = new WatchUi.Menu2({:title => "Select Action"});
gMenuApp.addItem(new WatchUi.MenuItem("New Game", null, 0, null));
gMenuApp.addItem(new WatchUi.MenuItem("Exit", null, 1, null));
}
@@ -48,12 +48,11 @@ class mainDelegate extends WatchUi.BehaviorDelegate {
return true;
case WatchUi.KEY_ESC:
System.exit();
switch($.gMatch.state){
case POSTGAME:
default:
// WatchUi.pushView($.gMenuActions, new menuActionsDelegate(), WatchUi.SLIDE_UP);
WatchUi.pushView($.gMenuActions, new menuActionsDelegate(), WatchUi.SLIDE_UP);
return true;
}
+48 -15
View File
@@ -2,6 +2,8 @@ import Toybox.Lang;
import Toybox.WatchUi;
import Toybox.Graphics;
import Toybox.Time;
import Toybox.Math;
import Toybox.System;
public enum enCard{
RED,
@@ -41,25 +43,51 @@ public var gMenuApp as WatchUi.Menu2?;
public var gScore as String = "0-0";
public var gMatch as Match?;
public var gIconGreen = WatchUi.loadResource(Rez.Drawables.greenCard);
public var gIconYellow = WatchUi.loadResource(Rez.Drawables.yellowCard);
public var gIconRed = WatchUi.loadResource(Rez.Drawables.redCard);
public var gX as Number?;
public var gR as Float?;
public var gH as Number?;
public var gW as Number?;
public var gY as Number?;
public const gH as Float = Toybox.System.getDeviceSettings().screenHeight.toFloat();
public const gW as Float = Toybox.System.getDeviceSettings().screenWidth.toFloat();
public const gX as Float = gW / 2.0;
public const gY as Float = gH / 2.0;
public const gR as Float = gW / 2.0;
public var gTitleArc as Float = 25.0;
public var gPeriodWidth as Float = 6.0;
public var gPeriodArc as Float?;// = gTitleArc;
public var gFilledArc as Float?;
public var gStartAngle as Float?;
public var gEndAngle as Float?;
public var gFontTimer = WatchUi.loadResource($.Rez.Fonts.SevenSegment);
public var gFontCards = WatchUi.loadResource($.Rez.Fonts.font40);
public var gFontClock = WatchUi.loadResource($.Rez.Fonts.led_small);
public var gFontScore = WatchUi.loadResource($.Rez.Fonts.font40);
public var gFontCardsX = Graphics.getFontHeight($.gFontCards)/2;
public var gFontTimer = WatchUi.loadResource($.Rez.Fonts.SevenSegment);
public var gFontButtons = WatchUi.loadResource($.Rez.Fonts.fontButtons);
public var gFontClock = WatchUi.loadResource($.Rez.Fonts.led_small);
public var gFontScore = WatchUi.loadResource($.Rez.Fonts.fontCards);
public var gFontCards = WatchUi.loadResource($.Rez.Fonts.fontCards);
public const gFontCardsX = Graphics.getFontHeight($.gFontButtons)/2;
public const gFontCardsW = Graphics.getFontHeight($.gFontButtons);
public const gFontCardsR = Math.sqrt(2 * gFontCardsW * gFontCardsW) / 2.0;
public var gTitleArc1 as Float = 25.0;
public var gPeriodWidth as Float = 6.0;
public const gBUTTON_GPS as Array<Float> = [
$.gX + Math.sin( 60.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth),
$.gY - Math.cos( 60.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth)];
public const gBUTTON_SET as Array<Float> = [
$.gX + Math.sin(120.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth),
$.gY - Math.cos(120.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth)];
public const gBUTTON_DOWN as Array<Float> = [
$.gX + Math.sin(240.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth),
$.gY - Math.cos(240.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth)];
public const gBUTTON_UP as Array<Float> = [
$.gX + Math.sin(270.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth),
$.gY - Math.cos(270.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth)];
public const gBUTTON_CTL as Array<Float> = [
$.gX + Math.sin(300.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth),
$.gY - Math.cos(300.0 * Math.PI / 180.0) * ($.gX - gFontCardsR - gPeriodWidth)];
public var gInfo as Time.Gregorian.Info?;
public var gTime as String?;
@@ -70,6 +98,11 @@ public var g1H as String = "\u0080".toString();
public var g3Q as String = "\u0081".toString();
public var gCards as Array<String> = ["\u0084", "\u0083", "\u0082"];
public var gPlay as String = "\u0085".toString();
public var gPause as String = "\u0086".toString();
public var gPlus as String = "\u0087".toString();
public var gPlay as String = "\u0030".toString();
public var gPause as String = "\u0031".toString();
public var gPlus as String = "\u0032".toString();
public function closeApp(){
// WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
System.exit();
}
+83 -51
View File
@@ -12,6 +12,8 @@ class mainView extends WatchUi.View {
private var _rr as Float?;
private var _tm as String = "00:00";
private var _aa as String = "oops";
private var _i as Integer?;
private var _j as Integer?;
function initialize() {
View.initialize();
@@ -20,6 +22,7 @@ class mainView extends WatchUi.View {
$.gMatch.recordCard(HOME,GREEN,22,1);
$.gMatch.recordCard(AWAY,YELLOW,10,2);
$.gMatch.recordCard(AWAY,RED,10,0);
// gTitleArc1 = 25.0;
}
function timerTick() as Void{
@@ -31,12 +34,12 @@ class mainView extends WatchUi.View {
}
function onLayout(dc as Dc) as Void {
$.gW = dc.getWidth();
$.gH = dc.getHeight();
$.gX = $.gW / 2;
$.gY = $.gH / 2;
_rr = $.gX - ($.gPeriodWidth / 2);
$.gPeriodArc = (360.0 - $.gTitleArc - ($.gMatch.breakCount * $.gTitleArc)) / $.gMatch.playCount;
// $.gW = dc.getWidth().toFloat();
// $.gH = dc.getHeight().toFloat();
// $.gX = $.gW / 2;
// $.gY = $.gH / 2;
_rr = $.gX - (gPeriodWidth / 2);
$.gPeriodArc = (360.0 - gTitleArc1 - ($.gMatch.breakCount * gTitleArc1)) / $.gMatch.playCount;
}
function onUpdate(dc as Dc) as Void {
@@ -78,31 +81,32 @@ class mainView extends WatchUi.View {
}
private function drawMatchProgress(dc as Dc){
dc.setPenWidth($.gPeriodWidth);
$.gStartAngle = 90.0 - ($.gTitleArc / 2);
for (var i = 0; i < $.gMatch.periods.size(); i++) {
if ($.gMatch.periods[i].type == PLAY){
dc.setColor($.gColours[timerBg], Graphics.COLOR_TRANSPARENT);
$.gEndAngle = $.gStartAngle - $.gPeriodArc;
dc.drawArc($.gX,
$.gY,
_rr,
Graphics.ARC_CLOCKWISE,
$.gStartAngle,
$.gEndAngle);
$.gFilledArc = ($.gMatch.periods[i].elapsed.toFloat() / $.gMatch.periods[i].duration.toFloat()) * $.gPeriodArc;
if ($.gFilledArc > 0.0) {
dc.setColor($.gColours[timer], Graphics.COLOR_TRANSPARENT);
dc.drawArc($.gX,
$.gY,
_rr,
Graphics.ARC_CLOCKWISE,
$.gStartAngle,
$.gStartAngle - $.gFilledArc);
}
$.gStartAngle = $.gEndAngle - $.gTitleArc;
dc.setPenWidth(gPeriodWidth);
$.gStartAngle = 90.0 - (gTitleArc1 / 2);
$.gEndAngle = gStartAngle - $.gPeriodArc;
for (_i = 0; _i < 4; _i++) {
dc.setColor($.gColours[timerBg], Graphics.COLOR_TRANSPARENT);
dc.drawArc( $.gX,
$.gY,
_rr,
Graphics.ARC_CLOCKWISE,
$.gStartAngle,
$.gEndAngle);
dc.setColor($.gColours[timer], Graphics.COLOR_TRANSPARENT);
$.gFilledArc = ($.gMatch.periods[_i].elapsed.toFloat() / $.gMatch.periods[_i].duration.toFloat()) * $.gPeriodArc;
if ($.gFilledArc > 1) {
dc.drawArc( $.gX,
$.gY,
_rr,
Graphics.ARC_CLOCKWISE,
$.gStartAngle,
$.gStartAngle -$.gFilledArc);
}
$.gStartAngle = $.gEndAngle - gTitleArc1;
$.gEndAngle = $.gStartAngle - $.gPeriodArc;
}
}
@@ -110,7 +114,6 @@ class mainView extends WatchUi.View {
_mm = $.gMatch.period.remaining/60;
_ss = $.gMatch.period.remaining%60;
_tm = Lang.format("$1$:$2$", [_mm.format("%02d"), _ss.format("%02d")]);
dc.setColor($.gColours[timerBg], Graphics.COLOR_TRANSPARENT);
dc.drawText($.gX,
$.gY,
@@ -124,12 +127,6 @@ class mainView extends WatchUi.View {
$.gFontTimer,
_tm,
Graphics.TEXT_JUSTIFY_VCENTER | Graphics.TEXT_JUSTIFY_CENTER);
var c = 5 + Graphics.getFontHeight($.gFontTimer) / 2;
var w = 5 + dc.getTextWidthInPixels(_tm, $.gFontTimer) / 2;
dc.setPenWidth(1);
dc.drawLine($.gY - w, $.gY - c, $.gY + w, $.gY - c);
dc.drawLine($.gY - w, $.gY + c, $.gY + w, $.gY + c);
}
private function drawMatchScore(dc as Dc){
@@ -162,42 +159,77 @@ class mainView extends WatchUi.View {
}
private function drawButtons(dc as Dc){
// dc.setPenWidth(2);
// dc.drawCircle($.gX, $.gY, ($.gW / 2) - gFontCardsR - gPeriodWidth);
// dc.drawText($.gBUTTON_UP[0],
// $.gBUTTON_UP[1],
// $.gFontButtons,
// $.gPlus,
// Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
// dc.drawText($.gBUTTON_GPS[0],
// $.gBUTTON_GPS[1],
// $.gFontButtons,
// $.gPlus,
// Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
// dc.drawText($.gBUTTON_SET[0],
// $.gBUTTON_SET[1],
// $.gFontButtons,
// $.gPlus,
// Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
// dc.drawText($.gBUTTON_DOWN[0],
// $.gBUTTON_DOWN[1],
// $.gFontButtons,
// $.gPlus,
// Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
// dc.drawText($.gBUTTON_CTL[0],
// $.gBUTTON_CTL[1],
// $.gFontButtons,
// $.gPlus,
// Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
if($.gMatch.period.play){
dc.drawText(340,
$.gY + gFontCardsX - 100,
$.gFontCards,
dc.drawText($.gBUTTON_GPS[0],
$.gBUTTON_GPS[1],
$.gFontButtons,
$.gPlay,
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
}
else{
dc.drawText(340,
$.gY + gFontCardsX - 100,
$.gFontCards,
dc.drawText($.gBUTTON_GPS[0],
$.gBUTTON_GPS[1],
$.gFontButtons,
$.gPause,
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
}
dc.drawText(340,
$.gY - gFontCardsX + 100,
$.gFontCards,
dc.drawText($.gBUTTON_SET[0],
$.gBUTTON_SET[1],
$.gFontButtons,
$.gPlus,
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
}
private function drawActiveCards(dc as Dc){
for (var i = 0; i < $.gMatch.cards.size(); i++){
if ($.gMatch.cards[i].isActive){
var w = $.gMatch.cards[i].remaining;
_j = 0;
for (_i = 0; _i < $.gMatch.cards.size(); _i++){
if ($.gMatch.cards[_i].isActive){
var w = $.gMatch.cards[_i].remaining;
_mm = w/60;
_ss = w%60;
$.gTextCard = Lang.format( "$1$ $2$($3$)$4$:$5$", [$.gCards[$.gMatch.cards[i].card.toNumber()] ,"H", $.gMatch.cards[i].player.format("%02d"), _mm.format("%02d"), _ss.format("%02d")]);
$.gTextCard = Lang.format( "$1$ $2$($3$)$4$:$5$", [$.gCards[$.gMatch.cards[_i].card.toNumber()] ,"H", $.gMatch.cards[_i].player.format("%02d"), _mm.format("%02d"), _ss.format("%02d")]);
dc.drawText($.gX,
$.gY + (i * 35) + 55,
$.gY + (_j * 35) + 55,
$.gFontCards,
$.gTextCard,
Graphics.TEXT_JUSTIFY_CENTER);
_j++;
}
}
}
+2 -2
View File
@@ -42,8 +42,8 @@ public class Card {
public function update() as Void{
remaining = end - $.gMatch.elapsed;
if(remaining == 0){
//WatchUi.pushView(new menuConfirmationDelegate(Lang.format("Card: $1$ Over",[player.format("%02d")]), false), new ConfirmationDelegate(method(:dummy)), WatchUi.SLIDE_LEFT);
System.println(Lang.format("Card: $1$ Over",[player.format("%02d")]));
WatchUi.pushView(new menuConfirmationDelegate(Lang.format("Card: $1$ Over",[player.format("%02d")]), false), new ConfirmationDelegate(method(:dummy)), WatchUi.SLIDE_LEFT);
// System.println(Lang.format("Card: $1$ Over",[player.format("%02d")]));
isActive = false;
}
}
+14 -1
View File
@@ -33,7 +33,7 @@ class Match {
_datetime = Time.now().value();
state = PREGAME;
periods.add(new Period("1st Quarter", PLAY, 100));
periods.add(new Period("1st Quarter", PLAY, 35 * 60));
periods.add(new Period("1/4 Break" , BREAK, 2));
periods.add(new Period("2nd Quarter", PLAY, 100));
periods.add(new Period("1/2 Break" , BREAK, 2));
@@ -76,4 +76,17 @@ class Match {
cards.add(new Card(team, type, player , duration, me.elapsed));
}
function recordGoal(team as enTeam, type as enGoal, player as Number){
goals.add(new Goal(team, type, player, me.elapsed));
switch (team) {
case HOME:
homeScore++;
break;
case AWAY:
awayScore++;
break;
}
}
}
+29
View File
@@ -0,0 +1,29 @@
import Toybox.WatchUi;
import Toybox.Lang;
class menuActionsDelegate extends WatchUi.Menu2InputDelegate {
private var _action as enAction?;
function initialize() {
Menu2InputDelegate.initialize();
}
function onSelect(item as WatchUi.MenuItem) as Void {
_action = item.getId() as enAction;
switch (_action){
case QUIT:
closeApp();
break;
default:
WatchUi.popView(WatchUi.SLIDE_DOWN);
WatchUi.pushView($.gMenuTeams, new menuTeamsDelegate(_action), WatchUi.SLIDE_UP);
}
}
function onCancel() as Boolean {
WatchUi.popView(WatchUi.SLIDE_DOWN);
return true;
}
}
+24
View File
@@ -0,0 +1,24 @@
import Toybox.WatchUi;
import Toybox.Lang;
class menuAppDelegate extends WatchUi.Menu2InputDelegate {
function initialize() {
Menu2InputDelegate.initialize();
}
function onSelect(item as WatchUi.MenuItem) as Void {
switch(item.getId() as Number){
case 0:
break;
case 1:
WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
}
}
function onCancel() as Boolean {
WatchUi.popView(WatchUi.SLIDE_DOWN);
return true;
}
}
+34
View File
@@ -0,0 +1,34 @@
import Toybox.WatchUi;
import Toybox.Lang;
class menuCardsDelegate extends WatchUi.Menu2InputDelegate {
private var _player as Number?;
private var _team as enTeam?;
private var _card as enCard?;
private var _mins as Number?;
function initialize(team as enTeam, player as Number) {
_player = player;
_team = team;
Menu2InputDelegate.initialize();
}
function onSelect(item as WatchUi.MenuItem) as Void {
_card = item.getId() as enCard;
switch(_card){
case GREEN:
_mins = 2;
break;
case YELLOW:
_mins = 5;
break;
case RED:
_mins = 0;
break;
default:
break;
}
$.gMatch.recordCard(_team, _card, _player, _mins);
WatchUi.popView(WatchUi.SLIDE_DOWN);
}
}
+83
View File
@@ -0,0 +1,83 @@
import Toybox.WatchUi;
import Toybox.Graphics;
import Toybox.Lang;
class menuConfirmationDelegate extends WatchUi.View {
private var _message as String;
private var _showCancel as Boolean;
function initialize(message as String, showCancel as Boolean) {
View.initialize();
_message = message;
_showCancel = showCancel;
}
function onUpdate(dc as Dc) as Void {
dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);
dc.clear();
dc.setPenWidth(4);
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.drawText(
$.gX,
$.gY,
$.gFontScore,
_message,
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER
);
dc.setColor(Graphics.COLOR_DK_GREEN, Graphics.COLOR_TRANSPARENT);
dc.drawArc($.gX, $.gY, $.gR, Graphics.ARC_CLOCKWISE, 40, 20);
dc.setColor(Graphics.COLOR_DK_GREEN, Graphics.COLOR_TRANSPARENT);
dc.drawText(
$.gX,
$.gH * 0.25,
$.gFontScore,
"Confirm",
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER
);
if (_showCancel){
// Bottom Right: Back Button (Cancel Action)
dc.setColor(Graphics.COLOR_DK_RED , Graphics.COLOR_TRANSPARENT);
dc.drawArc($.gX, $.gY, $.gR, Graphics.ARC_CLOCKWISE, -20, -40);
dc.setColor(Graphics.COLOR_DK_RED, Graphics.COLOR_TRANSPARENT);
dc.drawText(
$.gX,
$.gH * 0.75,
$.gFontScore,
"Cancel",
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER
);
}
}
}
class ConfirmationDelegate extends WatchUi.InputDelegate {
private var _callback as Method;
function initialize(callback as Method) {
InputDelegate.initialize();
_callback = callback;
}
function onKey(keyEvent as KeyEvent) as Boolean {
var key = keyEvent.getKey();
if (key == WatchUi.KEY_ENTER) {
_callback.invoke(true); // Invoke original action
WatchUi.popView(WatchUi.SLIDE_RIGHT);
return true;
}
if (key == WatchUi.KEY_ESC) {
_callback.invoke(false); // Cancelled
WatchUi.popView(WatchUi.SLIDE_RIGHT);
return true;
}
return false;
}
}
+22
View File
@@ -0,0 +1,22 @@
import Toybox.WatchUi;
import Toybox.Lang;
class menuGoalsDelegate extends WatchUi.Menu2InputDelegate {
private var _player as Number?;
private var _team as enTeam?;
private var _goal as enGoal?;
function initialize(team as enTeam, player as Number) {
_player = player;
_team = team;
Menu2InputDelegate.initialize();
}
function onSelect(item as WatchUi.MenuItem) as Void {
_goal = item.getId() as enGoal;
$.gMatch.recordGoal(_team, _goal, _player);
WatchUi.popView(WatchUi.SLIDE_DOWN);
}
}
+140
View File
@@ -0,0 +1,140 @@
import Toybox.WatchUi;
import Toybox.Lang;
import Toybox.Graphics;
class menuPlayerDelegate extends WatchUi.PickerDelegate {
private var _action as enAction?;
private var _team as enTeam?;
private var _player as Number?;
function initialize(action as enAction, team as enTeam) {
_team = team;
_action =action;
PickerDelegate.initialize();
}
function onAccept(values) as Boolean {
var tens = values[0] as Number;
var units = values[1] as Number;
_player = (tens * 10) + units;
System.println(Lang.format("Action: $1$ - Team: $2$ - Player: $3$", [_action, _team, _player]));
WatchUi.popView(WatchUi.SLIDE_DOWN);
switch (_action){
case GOAL:
WatchUi.pushView($.gMenuGoals, new menuGoalsDelegate(_team, _player), WatchUi.SLIDE_UP);
break;
case CARD:
WatchUi.pushView($.gMenuCards, new menuCardsDelegate(_team, _player), WatchUi.SLIDE_UP);
break;
}
return true;
}
function onCancel() as Boolean {
WatchUi.popView(WatchUi.SLIDE_DOWN);
return true;
}
}
class playerPicker extends WatchUi.Picker {
function initialize() {
var title = new WatchUi.Text({
:text => "Player",
:color => Graphics.COLOR_ORANGE,
:font => Graphics.FONT_TINY,
:locX =>WatchUi.LAYOUT_HALIGN_CENTER,
:locY =>WatchUi.LAYOUT_VALIGN_TOP
// :justification => Graphics.TEXT_JUSTIFY_CENTER,
// :locY => 30 // Shifted down slightly to comfortably clear round screen curvature
});
var pattern = [
new NumberFactory(0, 9, 1,{:format=>"%d"}), // Index 0: Tens
new NumberFactory(0, 9, 1,{:format=>"%d"}) // Index 1: Units
];
Picker.initialize({
:title => title,
:pattern => pattern,
:defaults => [0, 0]
});
}
}
class NumberFactory extends WatchUi.PickerFactory {
private var _start as Number;
private var _stop as Number;
private var _increment as Number;
private var _formatString as String;
private var _font as FontDefinition;
//! Constructor
//! @param start Number to start with
//! @param stop Number to end with
//! @param increment How far apart the numbers should be
//! @param options Dictionary of options
//! @option options :font The font to use
//! @option options :format The number format to display
public function initialize(start as Number, stop as Number, increment as Number, options as {
:font as FontDefinition,
:format as String
}) {
PickerFactory.initialize();
_start = start;
_stop = stop;
_increment = increment;
var format = options.get(:format);
if (format != null) {
_formatString = format;
} else {
_formatString = "%d";
}
var font = options.get(:font);
if (font != null) {
_font = font;
} else {
_font = Graphics.FONT_NUMBER_HOT;
}
}
//! Get the index of a number item
//! @param value The number to get the index of
//! @return The index of the number
public function getIndex(value as Number) as Number {
return (value / _increment) - _start;
}
//! Generate a Drawable instance for an item
//! @param index The item index
//! @param selected true if the current item is selected, false otherwise
//! @return Drawable for the item
public function getDrawable(index as Number, selected as Boolean) as Drawable? {
var value = getValue(index);
var text = "No item";
if (value instanceof Number) {
text = value.format(_formatString);
}
return new WatchUi.Text({:text=>text, :color=>Graphics.COLOR_WHITE, :font=>_font,
:locX=>WatchUi.LAYOUT_HALIGN_CENTER, :locY=>WatchUi.LAYOUT_VALIGN_CENTER});
}
//! Get the value of the item at the given index
//! @param index Index of the item to get the value of
//! @return Value of the item
public function getValue(index as Number) as Object? {
return _start + (index * _increment);
}
//! Get the number of picker items
//! @return Number of items
public function getSize() as Number {
return (_stop - _start) / _increment + 1;
}
}
+23
View File
@@ -0,0 +1,23 @@
import Toybox.WatchUi;
import Toybox.Lang;
class menuTeamsDelegate extends WatchUi.Menu2InputDelegate {
private var _action as enAction;
private var _team as enTeam?;
function initialize(action as enAction) {
Menu2InputDelegate.initialize();
_action = action;
}
function onSelect(item as WatchUi.MenuItem) as Void {
_team = item.getId() as enTeam;
WatchUi.popView(WatchUi.SLIDE_DOWN);
WatchUi.pushView(new playerPicker(), new menuPlayerDelegate(_action, _team), WatchUi.SLIDE_UP);
}
function onCancel() as Boolean {
WatchUi.popView(WatchUi.SLIDE_DOWN);
return true;
}
}
+8 -8
View File
@@ -11,44 +11,44 @@ class MyInputDelegate extends WatchUi.InputDelegate {
function onDrag(dragEvent as WatchUi.DragEvent) as Lang.Boolean {
$.kjr = "on-Drag";
System.println(dragEvent.getType());
// System.println(dragEvent.getType());
WatchUi.requestUpdate();
return true;
}
function onFlick(flickEvent as WatchUi.FlickEvent) as Lang.Boolean {
$.kjr = "onFlick";
System.println(flickEvent.getDirection());
// System.println(flickEvent.getDirection());
WatchUi.requestUpdate();
return true;
}
function onHold(clickEvent as WatchUi.ClickEvent) as Lang.Boolean {
$.kjr = "onHold";
System.println(clickEvent.getType());
// System.println(clickEvent.getType());
WatchUi.requestUpdate();
return true;
}
function onKey(keyEvent as WatchUi.KeyEvent) as Lang.Boolean {
$.kjr = "onKey";
System.println(keyEvent.getKey());
// System.println(keyEvent.getKey());
WatchUi.requestUpdate();
return true;
}
function onKeyPressed(keyEvent as WatchUi.KeyEvent) as Lang.Boolean {
$.kjr = "onKeyPressed";
System.println(keyEvent.getKey());
// System.println(keyEvent.getKey());
WatchUi.requestUpdate();
return true;
}
function onKeyReleased(keyEvent as WatchUi.KeyEvent) as Lang.Boolean {
$.kjr = "onKeyReleased";
System.println(keyEvent.getKey());
// System.println(keyEvent.getKey());
WatchUi.requestUpdate();
return true;
}
function onRelease(clickEvent as WatchUi.ClickEvent) as Lang.Boolean {
$.kjr = "onRelease";
System.println(clickEvent.getType());
// System.println(clickEvent.getType());
WatchUi.requestUpdate();
return true;
}
@@ -65,7 +65,7 @@ class MyInputDelegate extends WatchUi.InputDelegate {
}
function onTap(clickEvent as WatchUi.ClickEvent) as Lang.Boolean {
$.kjr = "onTap";
System.println(clickEvent.getType());
// System.println(clickEvent.getType());
WatchUi.requestUpdate();
return true;
}