Skip to content

Commit

Permalink
Is Alive implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoCunha committed Feb 9, 2020
1 parent eb54e5c commit c60d042
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 100 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ mslrb2015/fonts.txt
mslrb2015/fonts.txt
*.txt
mslrb2015/C
mslrb2015/RefBox
RefereeClient/RefClientSession
*.autosave
2 changes: 1 addition & 1 deletion mslrb2015/Button.pde
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void buttonEvent(char group, int pos) {
StateMachine.Update(clickedButton, btnOn);

if(soundMaxTime != null && clickedButton.isStart()) {
SetPieceDelay.startTimer(Config.setPieceMaxTime_ms);
setPieceDelay.startTimer(Config.setPieceMaxTime_ms);
println ("Millis: " + Config.setPieceMaxTime_ms);
}

Expand Down
3 changes: 2 additions & 1 deletion mslrb2015/Config.pde
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ static class Config
public static String defaultRightTeamLongName = "Right";
public static String defaultRightTeam = "TeamRight";

// Sounds
// Sounds & others
public static String sounds_maxTime = "";
public static int blinkTime_ms = 500;

public static void Load(PApplet parent, String filename)
{
Expand Down
46 changes: 31 additions & 15 deletions mslrb2015/Popup.pde
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static class Popup
public static void close()
{
for (int n = 0; n < popUpButtons; n++)
bPopup[n].disable();
bPopup[n].disable();
enabled = false;
mainApplet.redraw();

Expand Down Expand Up @@ -114,24 +114,27 @@ static class Popup
mainApplet.fill(63, 72, 204);
mainApplet.stroke(220, 220, 220);
mainApplet.rect(mainApplet.width/2, mainApplet.height/2, popUpWidth, popUpHeight, 12);

int mwx = mainApplet.width/2;
int mwxOffset = popUpWidth / 3;
int hw = 0;
if (bw1 > 0) hw = bw1 / 2;
else if (bw2 > 0) hw = bw2 / 2;
else hw = bw3 / 2;

if (type == PopupTypeEnum.POPUP_SUBS) {
mainApplet.fill(Config.defaultLeftBackgroundColor);
mainApplet.rect(mainApplet.width/2 - popUpWidth/3, mainApplet.height/2, popUpWidth/3, popUpHeight, 12);
mainApplet.fill(Config.defaultRightBackgroundColor);
mainApplet.rect(mainApplet.width/2 + popUpWidth/3, mainApplet.height/2, popUpWidth/3, popUpHeight, 12);
mainApplet.fill(200);
mainApplet.rect(mainApplet.width/4, mainApplet.height/2 - 100, 140, 24);
mainApplet.rect(mainApplet.width/4*3, mainApplet.height/2 - 100, 140, 24);
mainApplet.rect(mwx - mwxOffset, mainApplet.height/2 - 40, 140, 24);
mainApplet.rect(mwx + mwxOffset, mainApplet.height/2 - 40, 140, 24);
}

int hw = 0;
if (bw1 > 0) hw = bw1 / 2;
else if (bw2 > 0) hw = bw2 / 2;
else hw = bw3 / 2;

int delta = (popUpWidth - bw1 - bw2 - bw3) / (numOfButtons + 1);
int leftOffset = (mainApplet.width / 2 - popUpWidth / 2) + delta + hw;

if (bPopup[b1].isEnabled()) {
if (type == PopupTypeEnum.POPUP_HELP) {
bPopup[b1].setxy(leftOffset, mainApplet.height/2+78);
Expand All @@ -140,7 +143,10 @@ static class Popup
bPopup[b1].setxy(leftOffset, mainApplet.height/2 + 85);
}
else if (type == PopupTypeEnum.POPUP_SUBS) {
bPopup[b1].setxy(leftOffset + delta/2 - 20, mainApplet.height/2 + 240);
bPopup[b1].setxy(mwx + 3 - mwxOffset / 4, mainApplet.height / 2 + popUpHeight / 3);
}
else if (type == PopupTypeEnum.POPUP_ALIVE) {
bPopup[b1].setxy(mwx - mwxOffset / 2, mainApplet.height / 2 + popUpHeight * 3 / 10 + 3);
}
else {
bPopup[b1].setxy(leftOffset, mainApplet.height/2+40);
Expand All @@ -149,7 +155,10 @@ static class Popup
}
if (bPopup[b2].isEnabled()) {
if (type == PopupTypeEnum.POPUP_SUBS) {
bPopup[b2].setxy(leftOffset - delta/2 + 20, mainApplet.height/2 + 240);
bPopup[b2].setxy(mwx - 3 + mwxOffset / 4, mainApplet.height / 2 + popUpHeight / 3);
}
else if (type == PopupTypeEnum.POPUP_ALIVE) {
bPopup[b2].setxy(mwx + mwxOffset / 2, mainApplet.height / 2 + popUpHeight * 3 / 10 + 3);
}
else {
bPopup[b2].setxy(leftOffset, mainApplet.height/2+40);
Expand Down Expand Up @@ -185,20 +194,27 @@ static class Popup
mainApplet.text( message, mainApplet.width/2, mainApplet.height/2 - 90);
}
else if (type == PopupTypeEnum.POPUP_SUBS) {
mainApplet.text( message, mainApplet.width/2, mainApplet.height/2 - 150);

mainApplet.text( message, mainApplet.width/2, mainApplet.height/2 - 130);
mainApplet.textSize(1.2*fontSize);
mainApplet.text( "Team A", popUpWidth/4, mainApplet.height/2 - 220);
mainApplet.text( "Team B", mainApplet.width - popUpWidth/4, mainApplet.height/2 - 220);
mainApplet.text( teamA.shortName, mwx - mwxOffset, mainApplet.height/2 - 90);
mainApplet.text( teamB.shortName, mwx + mwxOffset, mainApplet.height/2 - 90);
mainApplet.fill(0);
mainApplet.textSize(0.8*fontSize);
mainApplet.text( "Robot number", mainApplet.width/4, mainApplet.height/2 - 100);
mainApplet.text( "Robot number", mainApplet.width/4*3, mainApplet.height/2 - 100);
mainApplet.text( "Robot number", mwx - mwxOffset, mainApplet.height/2 - 40);
mainApplet.text( "Robot number", mwx + mwxOffset, mainApplet.height/2 - 40);
mainApplet.fill(220);
if (!StateMachine.validInput) {
mainApplet.fill(#E03030); // Red card color
mainApplet.text("Invalid robot number! Please enter values between 0 and 99", mainApplet.width/2, mainApplet.height/2 + 150, 220, 1200);
}
}
else if (type == PopupTypeEnum.POPUP_ALIVE) {
mainApplet.text( cTeam.longName, mwx, mainApplet.height/2 - 40);
mainApplet.text( "Robot number:", mwx - 68, mainApplet.height/2 + 8);
mainApplet.textSize(1.2*fontSize);
mainApplet.text( message, mainApplet.width/2, mainApplet.height/2 - 78);
}
else {
mainApplet.text( message, mainApplet.width/2, mainApplet.height/2 - 50);
}
Expand Down
56 changes: 34 additions & 22 deletions mslrb2015/StateMachine.pde
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ static class StateMachine

case POPUP_ALIVE:
{
if (Popup.getResponse().equals("OK") && tBoxIsAlive.value.length() > 0) {
int rid = int(tBoxIsAlive.value);
if (rid > 0) send_event_v2(""+COMM_ISALIVE, Description.get(COMM_ISALIVE), cTeam, rid);
}
Popup.close();
tBoxIsAlive.hide();
tBoxIsAlive.value = "";
buttonFromEnum(ButtonsEnum.BTN_START).disable();
setpiece = false;
break;
Expand Down Expand Up @@ -82,8 +88,8 @@ static class StateMachine
gsPrev = saveGS;
mainWatch.resetStopWatch();
playTimeWatch.resetStopWatch();
SetPieceDelay.resetStopWatch();
SetPieceDelay.stopTimer();
setPieceDelay.resetStopWatch();
setPieceDelay.stopTimer();
switch(gsCurrent)
{
case GS_HALFTIME:
Expand Down Expand Up @@ -176,8 +182,8 @@ static class StateMachine
if (validInput) {
for (int t = 0; t < tBox.length; t++)
{
if (tBox[t].value != "0") {
if (t < 3) {
if (tBox[t].value.length() > 0) {
if (t % 2 == 0) {
if(!teamA.newSubstitution) teamA.newSubstitution = true;
teamA.substitute(int(tBox[t].value));
}
Expand All @@ -186,11 +192,11 @@ static class StateMachine
teamB.substitute(int(tBox[t].value));
}
}
tBox[t].value = "0";
tBox[t].value = "";
tBox[t].hide();
}
if (teamA.newSubstitution || teamB.newSubstitution) {
SetPieceDelay.startTimer(Config.substitutionMaxTime_ms);
setPieceDelay.startTimer(Config.substitutionMaxTime_ms);
println ("Substitution timer (s): " + Config.substitutionMaxTime_ms/1000);
}
Popup.close();
Expand All @@ -199,7 +205,7 @@ static class StateMachine
else if (Popup.getResponse().equals("Cancel")) {
for (int t = 0; t < tBox.length; t++)
{
tBox[t].value = "0";
tBox[t].value = "";
tBox[t].hide();
}
validInput = true;
Expand Down Expand Up @@ -257,7 +263,13 @@ static class StateMachine
}
else if(btnCurrent.isAlive())
{
Popup.show(PopupTypeEnum.POPUP_ALIVE, MSG_ISALIVE, 0, 8, 0, 24, 380, 200);
if(btnCurrent.isLeft())
cTeam = teamA;
else
cTeam = teamB;
Popup.show(PopupTypeEnum.POPUP_ALIVE, MSG_ISALIVE, 8, 10, 0, 24, 380, 230);
tBoxIsAlive.show();
tBoxIsAlive.clicked();
// done = true;
// return;
}
Expand Down Expand Up @@ -306,18 +318,18 @@ static class StateMachine
}
else if(btnCurrent.isStop())
{
SetPieceDelay.resetStopWatch();
SetPieceDelay.stopTimer();
setPieceDelay.resetStopWatch();
setPieceDelay.stopTimer();
forceKickoff = false;
}
else if(btnCurrent.isSubs())
{
Popup.show(PopupTypeEnum.POPUP_SUBS, MSG_SUBS, 9, 10, 0, 24, 840, 600);
Popup.show(PopupTypeEnum.POPUP_SUBS, MSG_SUBS, 9, 10, 0, 24, 680, 320);
for (int t = 0; t < tBox.length; t++)
{
tBox[t].show();
}

tBox[0].clicked();
}
else if(btnCurrent.isConfig())
{
Expand Down Expand Up @@ -347,8 +359,8 @@ static class StateMachine
{
mainWatch.resetStopWatch();
playTimeWatch.resetStopWatch();
SetPieceDelay.resetStopWatch();
SetPieceDelay.stopTimer();
setPieceDelay.resetStopWatch();
setPieceDelay.stopTimer();
nextGS = SwitchRunningStopped();
switch(nextGS)
{
Expand Down Expand Up @@ -393,8 +405,8 @@ static class StateMachine
else if(btnCurrent.isStop())
{
ResetSetpiece();
SetPieceDelay.resetStopWatch();
SetPieceDelay.stopTimer();
setPieceDelay.resetStopWatch();
setPieceDelay.stopTimer();
}
else if(btnCurrent.isEndPart()){
nextGS = SwitchGamePart();
Expand Down Expand Up @@ -422,8 +434,8 @@ static class StateMachine
SetSetpiece(btnCurrent.isLeft(), btnCurrent);
else if(btnCurrent.isStop()) {
ResetSetpiece();
SetPieceDelay.resetStopWatch();
SetPieceDelay.stopTimer();
setPieceDelay.resetStopWatch();
setPieceDelay.stopTimer();
}
else if(btnCurrent.isEndPart())
nextGS = SwitchGamePart();
Expand All @@ -435,8 +447,8 @@ static class StateMachine
if(setpiece)
ResetSetpiece(); //<>// //<>//
if(btnCurrent.isStop()){
SetPieceDelay.resetStopWatch();
SetPieceDelay.stopTimer();
setPieceDelay.resetStopWatch();
setPieceDelay.stopTimer();
nextGS = SwitchRunningStopped();
}
break;
Expand Down Expand Up @@ -576,8 +588,8 @@ static class StateMachine
teamB.resetname();
mainWatch.resetStopWatch();
playTimeWatch.resetStopWatch();
SetPieceDelay.resetStopWatch();
SetPieceDelay.stopTimer();
setPieceDelay.resetStopWatch();
setPieceDelay.stopTimer();
} catch(Exception e) {}
}

Expand Down
48 changes: 39 additions & 9 deletions mslrb2015/SystemEvents.pde
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,55 @@ void mouseMoved() {
void keyPressed() {

// TODO: only accept numbers for textbox value
for (int i=0; i<tBox.length; i++) {
for (int i = 0; i < tBox.length; i++) {
if (tBox[i].clickedLast && tBox[i].visible) {
if (key == BACKSPACE && tBox[i].value.length() > 1) {
tBox[i].value = tBox[i].value.substring(0, tBox[i].value.length() - 1);
if (key == BACKSPACE) {
if (tBox[i].value.length() > 1){
tBox[i].value = tBox[i].value.substring(0, tBox[i].value.length() - 1);
}
else {
tBox[i].value = "";
}
}
else if (key == BACKSPACE && tBox[i].value.length() == 1) {
tBox[i].value = "0";
if (key == TAB){
tBox[i].unclicked();
if (++i >= tBox.length) i = 0;
tBox[i].clicked();
break;
}
else {
else if (key >= '0' && key <= '9') {
tBox[i].value += key;
}
String number = tBox[i].value;
}
}
if (tBoxIsAlive.visible) {
if (key == BACKSPACE) {
if (tBoxIsAlive.value.length() > 1){
tBoxIsAlive.value = tBoxIsAlive.value.substring(0, tBoxIsAlive.value.length() - 1);
}
else {
tBoxIsAlive.value = "";
}
}
else if (key >= '0' && key <= '9') {
tBoxIsAlive.value += key;
}
}


if (key == ESC){
key = 0; //disable quit on ESC
// Close popup
if(Popup.isEnabled())
Popup.close();
if(Popup.isEnabled()) {
for (int t = 0; t < tBox.length; t++)
{
tBox[t].value = "";
tBox[t].hide();
}
tBoxIsAlive.hide();
Popup.close();
}

}
if (key == 32){
key = 0;
Expand Down
30 changes: 7 additions & 23 deletions mslrb2015/Team.pde
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,21 @@ class Team {

//*******************************************************************
void substitute(int robotID) {
if (robotID > 0){
send_event_v2(""+COMM_SUBSTITUTION, "substituting", this, robotID);
println("substituting robot " + robotID + " (on field) for robot (outside field)");
}
/* @mbc Robot IDs are virtual [0 to 4] and corresponds to each of the circles in the interface
for (int i = 0; i < r.length; i++) {
if (this.r[i].state.equals("play") || this.r[i].state.equals("yellow")) { // only robots that are in play can substitute
send_event_v2(""+COMM_SUBSTITUTION, "substituting", this, robotID);
this.substitute_timer_start(i);
println("substituting robot " + i + " (on field) for robot " + robotID + " (outside field)");
break;
}
}
} */
}

//*******************************************************************
public int numberOfPlayingRobots()
{
Expand Down Expand Up @@ -326,27 +331,6 @@ class Team {
for (int i=0; i<5; i++)
r[i].updateUI(colorTeam,isLeft);

//@mbc
/* float tx;
float ty;
stroke(colorTeam);
stroke(96);
strokeWeight(3);
color rcolor=230;
//fill(rcolor);
fill(194);
if (isLeft) {
tx=offsetLeft.x - 165 + 28;
ty=offsetLeft.y + 218;
}
else {
tx=offsetRight.x + 106 + 28;
ty=offsetLeft.y + 218;
}
ellipse(tx, ty, 42, 42);
imageMode(CENTER);
image(skullImageOff, tx, ty, 26, 26);
*/
textAlign(LEFT, BOTTOM);
textFont(debugFont);
fill(#ffff00);
Expand Down
Loading

0 comments on commit c60d042

Please sign in to comment.