Fixed Annotations and bound windarrow

- Wind arrow for the bermuda race is bound between 215 and 235 degrees
- annotations will not correctly highlight what they are showing
#story[877] story[882]
main
Fan-Wu Yang 9 years ago
parent e9f3467d97
commit b9b03305b0

@ -12,6 +12,7 @@ import seng302.Networking.Messages.Enums.BoatStatusEnum;
import seng302.Networking.Messages.Enums.RaceStatusEnum; import seng302.Networking.Messages.Enums.RaceStatusEnum;
import seng302.Networking.Messages.Enums.RaceTypeEnum; import seng302.Networking.Messages.Enums.RaceTypeEnum;
import seng302.Networking.Messages.RaceStatus; import seng302.Networking.Messages.RaceStatus;
import seng302.Networking.Utils.AC35UnitConverter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -102,8 +103,11 @@ public class Race implements Runnable {
*/ */
private double windSpeed; private double windSpeed;
private int windDir; private double windDirDegrees;
private double windDir;
private int changeWind = 4; private int changeWind = 4;
private static final int windUpperBound = 235;
private static final int windLowerBound = 215;
@ -261,7 +265,7 @@ public class Race implements Runnable {
//TODO REFACTOR for consistency, could send parameters to mockOutput instead of the whole racestatus. This will also fix the sequence number issue. //TODO REFACTOR for consistency, could send parameters to mockOutput instead of the whole racestatus. This will also fix the sequence number issue.
//Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class. //Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class.
int windDirectionInt = BoatLocation.convertHeadingDoubleToInt(this.windDirection.degrees()); int windDirectionInt = AC35UnitConverter.encodeHeading(this.windDirection.degrees());
int windSpeedInt = (int) (windSpeed * Constants.KnotsToMMPerSecond); int windSpeedInt = (int) (windSpeed * Constants.KnotsToMMPerSecond);
//Create race status object, and send it. //Create race status object, and send it.
@ -863,31 +867,31 @@ public class Race implements Runnable {
} }
protected void initialiseWindDir(){ protected void initialiseWindDir(){
windDir = new Random().nextInt(65535+1); windDirDegrees = 225;
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir)); windDir = AC35UnitConverter.convertHeading(windDirDegrees);
/*windDir = new Random().nextInt(65535+1);
windDir = BoatLocation.convertHeadingIntToDouble(255);*/
this.windDirection = new Bearing((int)windDir);
} }
protected void changeWindDir(){ protected void changeWindDir(){
int r = new Random().nextInt(changeWind)+1; int r = new Random().nextInt(changeWind)+1;
if(r==1){ if(r==1){
windDir+=100; windDirDegrees = (0.5 + windDirDegrees) % 360;
} else if (r==2){ } else if (r==2){
windDir-=100; windDirDegrees = ((windDirDegrees - 0.5) + 360) % 360;///keep the degrees positive when below 0
} }
if (windDir > 65535){ if (windDirDegrees > windUpperBound){
windDir -= 65535; windDirDegrees = windUpperBound;
} }
if (windDir < 0){ if (windDirDegrees < windLowerBound){
windDir += 65535; windDirDegrees = windLowerBound;
} }
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir));
}
protected void setWindDir(int wind){ windDir = AC35UnitConverter.convertHeading(windDirDegrees);
if (wind>=0 && wind<=65535){
windDir = wind; System.out.println(windDirDegrees + " + " + windDir);
this.windDirection = new Bearing(BoatLocation.convertHeadingIntToDouble(windDir)); this.windDirection = new Bearing(windDirDegrees);
}
} }
protected void setChangeWind(int changeVal){ protected void setChangeWind(int changeVal){
@ -897,6 +901,6 @@ public class Race implements Runnable {
} }
protected int getWind(){ protected int getWind(){
return windDir; return (int)windDir;
} }
} }

@ -1,6 +1,7 @@
package seng302.Networking.Messages; package seng302.Networking.Messages;
import seng302.Networking.Messages.Enums.MessageType; import seng302.Networking.Messages.Enums.MessageType;
import seng302.Networking.Utils.AC35UnitConverter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -18,7 +19,6 @@ public class RaceStatus extends AC35Data {
private int windSpeed; private int windSpeed;
private int raceType; private int raceType;
private List<BoatStatus> boatStatuses; private List<BoatStatus> boatStatuses;
private static final double windDirectionScalar = 360.0 / 32768.0; // 0x8000 / 360
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, List<BoatStatus> boatStatuses){ public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, List<BoatStatus> boatStatuses){
super(MessageType.RACESTATUS); super(MessageType.RACESTATUS);
@ -29,7 +29,7 @@ public class RaceStatus extends AC35Data {
this.windDirection = windDirection; this.windDirection = windDirection;
this.windSpeed = windSpeed; this.windSpeed = windSpeed;
this.raceType = raceType; this.raceType = raceType;
this.boatStatuses = boatStatuses;//note this is a copy so any alterations to the parent will affect this. this.boatStatuses = boatStatuses;//note this is not a copy so any alterations to the parent will affect this.
} }
@ -125,6 +125,6 @@ public class RaceStatus extends AC35Data {
} }
public double getScaledWindDirection() { public double getScaledWindDirection() {
return (double) windDirection * windDirectionScalar; return (double) AC35UnitConverter.convertHeading(windDirection);
} }
} }

@ -19,6 +19,23 @@ public class AC35UnitConverter {
return (double) value * 360.0/65536.0;//2^15 return (double) value * 360.0/65536.0;//2^15
} }
public static double convertHeading(int value){
return (double) value * 360.0/65536.0;//2^15
}
public static double convertHeading(double value){
return value * 360.0/65536.0;//2^15
}
public static int encodeHeading(int value){
return (int) (value / 360.0 * 65536.0);//2^15
}
public static int encodeHeading(double value){
return (int) (value / 360.0 * 65536.0);//2^15
}
public static double convertTrueWindAngle(long value){ public static double convertTrueWindAngle(long value){
return (double) value * 180.0/32768.0;//-2^15 to 2^15 return (double) value * 180.0/32768.0;//-2^15 to 2^15
} }

@ -31,6 +31,8 @@ public class RaceController extends Controller {
private Map<String, Boolean> annoShownBeforeHide; private Map<String, Boolean> annoShownBeforeHide;
private int buttonChecked;//button currently checked allows the checkboxes to know whether or not to put it's state in history (if not hidden then store) private int buttonChecked;//button currently checked allows the checkboxes to know whether or not to put it's state in history (if not hidden then store)
private int prevBtnChecked;//button to keep track of previous pressed button incase we want to check a checkbox straight from hidden we do not wish for all previous to come on. private int prevBtnChecked;//button to keep track of previous pressed button incase we want to check a checkbox straight from hidden we do not wish for all previous to come on.
private boolean radioBtnChecked;
private boolean selectShow = false; //button to make it so that show doesn't run the listener
private static String nameCheckAnno = "name"; private static String nameCheckAnno = "name";
private static String abbrevCheckAnno = "abbrev"; private static String abbrevCheckAnno = "abbrev";
@ -350,7 +352,22 @@ public class RaceController extends Controller {
} }
private void storeCurrentAnnotationState(){ private void storeCurrentAnnotationState(String dictionaryAnnotationKey, boolean selected){
if (buttonChecked != hideBtn) {
//if we are checking the box straight out of hide instead of using the radio buttons
annoShownBeforeHide.put(dictionaryAnnotationKey, selected);
System.out.println();
if (prevBtnChecked == hideBtn && buttonChecked == noBtn){
storeCurrentAnnotationDictionary();
}
if (buttonChecked == noBtn) {
selectShow = false;
annotationGroup.selectToggle(showAnnoRBTN);
}
}
}
private void storeCurrentAnnotationDictionary(){
annoShownBeforeHide.put(nameCheckAnno, showName.isSelected()); annoShownBeforeHide.put(nameCheckAnno, showName.isSelected());
annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected()); annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected());
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected()); annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
@ -381,92 +398,46 @@ public class RaceController extends Controller {
showName.selectedProperty().addListener((ov, old_val, new_val) -> { showName.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoName(); raceMap.toggleAnnoName();
radioBtnChecked = false;
storeCurrentAnnotationState(nameCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
//if we are checking the box straight out of hide instead of using the radio buttons
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(nameCheckAnno, showName.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
//listener for show abbreviation for annotation //listener for show abbreviation for annotation
showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> { showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoAbbrev(); raceMap.toggleAnnoAbbrev();
radioBtnChecked = false;
storeCurrentAnnotationState(abbrevCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
//listener for show boat path for annotation //listener for show boat path for annotation
showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> { showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleBoatPath(); raceMap.toggleBoatPath();
radioBtnChecked = false;
storeCurrentAnnotationState(pathCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
//listener to show speed for annotation //listener to show speed for annotation
showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> { showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoSpeed(); raceMap.toggleAnnoSpeed();
radioBtnChecked = false;
storeCurrentAnnotationState(speedCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(speedCheckAnno, showSpeed.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
}); });
showTime.selectedProperty().addListener((ov, old_val, new_val) -> { showTime.selectedProperty().addListener((ov, old_val, new_val) -> {
if (old_val != new_val) { if (old_val != new_val) {
raceMap.toggleAnnoTime(); raceMap.toggleAnnoTime();
radioBtnChecked = false;
storeCurrentAnnotationState(timeCheckAnno, new_val);
raceMap.update();
} }
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(timeCheckAnno, showTime.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
prevBtnChecked = noBtn;
raceMap.update();
}); });
//listener to save currently selected annotation //listener to save currently selected annotation
saveAnno.setOnAction(event -> { saveAnno.setOnAction(event -> {
@ -477,47 +448,81 @@ public class RaceController extends Controller {
presetAnno.add(showBoatPath.isSelected()); presetAnno.add(showBoatPath.isSelected());
presetAnno.add(showTime.isSelected()); presetAnno.add(showTime.isSelected());
}); });
//listener for hiding hideAnnoRBTN.setOnAction((e)->{
hideAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ System.out.println("called hide");
buttonChecked = hideBtn; buttonChecked = hideBtn;
//raceMap.hideAnnotations(); selectShow = false;
showName.setSelected(false); showName.setSelected(false);
showAbbrev.setSelected(false); showAbbrev.setSelected(false);
showBoatPath.setSelected(false); showBoatPath.setSelected(false);
showSpeed.setSelected(false); showSpeed.setSelected(false);
showTime.setSelected(false); showTime.setSelected(false);
annotationGroup.selectToggle(hideAnnoRBTN);
raceMap.update(); raceMap.update();
buttonChecked = noBtn; buttonChecked = noBtn;
prevBtnChecked = hideBtn; prevBtnChecked = hideBtn;
selectShow = true;
}); });
//listener for showing all annotations //listener for hiding
showAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ /*hideAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
buttonChecked = showBtn; buttonChecked = hideBtn;
showName.setSelected(annoShownBeforeHide.get(nameCheckAnno)); showName.setSelected(false);
showAbbrev.setSelected(annoShownBeforeHide.get(abbrevCheckAnno)); showAbbrev.setSelected(false);
showBoatPath.setSelected(annoShownBeforeHide.get(pathCheckAnno)); showBoatPath.setSelected(false);
showSpeed.setSelected(annoShownBeforeHide.get(speedCheckAnno)); showSpeed.setSelected(false);
showTime.setSelected(annoShownBeforeHide.get(timeCheckAnno)); showTime.setSelected(false);
raceMap.update(); raceMap.update();
buttonChecked = noBtn; buttonChecked = noBtn;
prevBtnChecked = showBtn; prevBtnChecked = hideBtn;
}); });*/
//listener for showing all annotations
showAnnoRBTN.setOnAction((e)->{
if (selectShow) {
System.out.println("called show");
buttonChecked = showBtn;
showName.setSelected(annoShownBeforeHide.get(nameCheckAnno));
showAbbrev.setSelected(annoShownBeforeHide.get(abbrevCheckAnno));
showBoatPath.setSelected(annoShownBeforeHide.get(pathCheckAnno));
showSpeed.setSelected(annoShownBeforeHide.get(speedCheckAnno));
showTime.setSelected(annoShownBeforeHide.get(timeCheckAnno));
raceMap.update();
buttonChecked = noBtn;
prevBtnChecked = showBtn;
}
selectShow = true;
});/*.addListener((ov, old_val, new_val) ->{
if (selectShow) {
buttonChecked = showBtn;
showName.setSelected(annoShownBeforeHide.get(nameCheckAnno));
showAbbrev.setSelected(annoShownBeforeHide.get(abbrevCheckAnno));
showBoatPath.setSelected(annoShownBeforeHide.get(pathCheckAnno));
showSpeed.setSelected(annoShownBeforeHide.get(speedCheckAnno));
showTime.setSelected(annoShownBeforeHide.get(timeCheckAnno));
raceMap.update();
buttonChecked = noBtn;
prevBtnChecked = showBtn;
}
selectShow = true;
});*/
//listener for showing all important //listener for showing all important
partialAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ partialAnnoRBTN.setOnAction((e)->{
System.out.println("called Partial");
selectShow = false;
buttonChecked = partialBtn; buttonChecked = partialBtn;
showName.setSelected(false); showName.setSelected(false);
showAbbrev.setSelected(true); showAbbrev.setSelected(true);
showSpeed.setSelected(true); showSpeed.setSelected(true);
showBoatPath.setSelected(false); showBoatPath.setSelected(false);
showTime.setSelected(false); showTime.setSelected(false);
annotationGroup.selectToggle(partialAnnoRBTN);
raceMap.update(); raceMap.update();
buttonChecked = noBtn; buttonChecked = noBtn;
prevBtnChecked = partialBtn; prevBtnChecked = partialBtn;
selectShow = true;
}); });
//listener for showing all important //listener for showing all important
importantAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{ importantAnnoRBTN.setOnAction((e) ->{
System.out.println("called Important");
selectShow = false;
buttonChecked = importantBtn; buttonChecked = importantBtn;
if (presetAnno.size() > 0) { if (presetAnno.size() > 0) {
showName.setSelected(presetAnno.get(0)); showName.setSelected(presetAnno.get(0));
@ -525,11 +530,12 @@ public class RaceController extends Controller {
showSpeed.setSelected(presetAnno.get(2)); showSpeed.setSelected(presetAnno.get(2));
showBoatPath.setSelected(presetAnno.get(3)); showBoatPath.setSelected(presetAnno.get(3));
showTime.setSelected(presetAnno.get(4)); showTime.setSelected(presetAnno.get(4));
annotationGroup.selectToggle(importantAnnoRBTN); storeCurrentAnnotationDictionary();
raceMap.update(); raceMap.update();
} }
buttonChecked = noBtn; buttonChecked = noBtn;
prevBtnChecked = importantBtn; prevBtnChecked = importantBtn;
selectShow = true;
}); });
annotationGroup.selectToggle(showAnnoRBTN); annotationGroup.selectToggle(showAnnoRBTN);
} }

Loading…
Cancel
Save