208 lines
7.2 KiB
Mason
208 lines
7.2 KiB
Mason
import Toybox.Graphics;
|
|
import Toybox.WatchUi;
|
|
import Toybox.Lang;
|
|
import Toybox.Timer;
|
|
import Toybox.Time;
|
|
|
|
class mainView extends WatchUi.View {
|
|
private var _timer as Timer.Timer = new Timer.Timer();
|
|
private var _tick as Number = 0;
|
|
private var _mm as Number?; // = 0;
|
|
private var _ss as Number?; // = 0;
|
|
private var _rr as Float?;
|
|
private var _tm as String = "00:00";
|
|
private var _aa as String = "oops";
|
|
|
|
function initialize() {
|
|
View.initialize();
|
|
_timer.start(method(:timerTick), 100, true);
|
|
$.gMatch = new Match();
|
|
$.gMatch.recordCard(HOME,GREEN,22,1);
|
|
$.gMatch.recordCard(AWAY,YELLOW,10,2);
|
|
$.gMatch.recordCard(AWAY,RED,10,0);
|
|
}
|
|
|
|
function timerTick() as Void{
|
|
_tick++;
|
|
$.gMatch.period.update();
|
|
if (_tick % 10 == 0){
|
|
WatchUi.requestUpdate();
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
function onUpdate(dc as Dc) as Void {
|
|
var _colourBG = $.gColours[background] ;
|
|
var _colourText = $.gColours[timer];
|
|
|
|
dc.setColor(_colourText, _colourBG);
|
|
dc.clear();
|
|
// drawTest(dc);
|
|
drawPeriodName(dc);
|
|
drawMatchProgress(dc);
|
|
drawPeriodTimer(dc);
|
|
drawMatchScore(dc);
|
|
drawCurrentTime(dc);
|
|
drawButtons(dc);
|
|
drawActiveCards(dc);
|
|
}
|
|
|
|
private function drawPeriodName(dc as Dc){
|
|
var FontClock = $.gFontScore;
|
|
switch($.gMatch.state){
|
|
case PREGAME:
|
|
_aa = "Pre-Game";
|
|
break;
|
|
case INGAME:
|
|
_aa = $.gMatch.period.name;
|
|
break;
|
|
case POSTGAME:
|
|
_aa = "Game-Over";
|
|
break;
|
|
}
|
|
|
|
dc.setColor($.gColours[timer], Graphics.COLOR_TRANSPARENT);
|
|
dc.drawText($.gX,
|
|
$.gY - 145,
|
|
FontClock,
|
|
_aa,
|
|
Graphics.TEXT_JUSTIFY_VCENTER | Graphics.TEXT_JUSTIFY_CENTER);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function drawPeriodTimer(dc as Dc){
|
|
_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,
|
|
$.gFontTimer,
|
|
"88:88",
|
|
Graphics.TEXT_JUSTIFY_VCENTER | Graphics.TEXT_JUSTIFY_CENTER);
|
|
|
|
dc.setColor($.gColours[timer], Graphics.COLOR_TRANSPARENT);
|
|
dc.drawText($.gX,
|
|
$.gY,
|
|
$.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){
|
|
$.gScore = Lang.format("$1$-$2$", [$.gMatch.homeScore, $.gMatch.awayScore]);
|
|
|
|
// dc.setColor($.gColours[timerBg], Graphics.COLOR_TRANSPARENT);
|
|
// dc.drawText($.gX,
|
|
// $.gY - 90,
|
|
// $.gFontScore,
|
|
// "###",
|
|
// Graphics.TEXT_JUSTIFY_VCENTER | Graphics.TEXT_JUSTIFY_CENTER);
|
|
|
|
dc.setColor($.gColours[timer], Graphics.COLOR_TRANSPARENT);
|
|
dc.drawText($.gX,
|
|
$.gY - 90,
|
|
$.gFontScore,
|
|
$.gScore,
|
|
Graphics.TEXT_JUSTIFY_VCENTER | Graphics.TEXT_JUSTIFY_CENTER);
|
|
}
|
|
|
|
private function drawCurrentTime(dc as Dc){
|
|
$.gInfo = Time.Gregorian.info(Time.now(), Time.FORMAT_LONG);
|
|
$.gTime = Lang.format("$1$:$2$", [$.gInfo.hour.format("%02d"), $.gInfo.min.format("%02d")]);
|
|
dc.setColor($.gColours[timer], Graphics.COLOR_TRANSPARENT);
|
|
dc.drawText($.gX,
|
|
0,
|
|
$.gFontClock,
|
|
$.gTime,
|
|
Graphics.TEXT_JUSTIFY_CENTER);
|
|
}
|
|
|
|
private function drawButtons(dc as Dc){
|
|
if($.gMatch.period.play){
|
|
dc.drawText(340,
|
|
$.gY + gFontCardsX - 100,
|
|
$.gFontCards,
|
|
$.gPlay,
|
|
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
|
|
}
|
|
else{
|
|
dc.drawText(340,
|
|
$.gY + gFontCardsX - 100,
|
|
$.gFontCards,
|
|
$.gPause,
|
|
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
|
|
}
|
|
|
|
dc.drawText(340,
|
|
$.gY - gFontCardsX + 100,
|
|
$.gFontCards,
|
|
$.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;
|
|
_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")]);
|
|
|
|
dc.drawText($.gX,
|
|
$.gY + (i * 35) + 55,
|
|
$.gFontCards,
|
|
$.gTextCard,
|
|
Graphics.TEXT_JUSTIFY_CENTER);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|