mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Icons now display, blink when they are about to run off, and turn off after their time out
TokenType Enum now also has a timeout construction field #story[1245]
This commit is contained in:
@@ -40,7 +40,6 @@ public class ClientYacht extends Observable {
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface PowerUpListener {
|
public interface PowerUpListener {
|
||||||
|
|
||||||
void notifyPowerUp(ClientYacht yacht, TokenType tokenType);
|
void notifyPowerUp(ClientYacht yacht, TokenType tokenType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,18 +5,21 @@ package seng302.model.token;
|
|||||||
* Created by wmu16 on 28/08/17.
|
* Created by wmu16 on 28/08/17.
|
||||||
*/
|
*/
|
||||||
public enum TokenType {
|
public enum TokenType {
|
||||||
BOOST(0, "Boost"),
|
|
||||||
HANDLING(1, "Handling"),
|
BOOST(0, "Boost", 10_000),
|
||||||
BUMPER(2, "Bumper"),
|
HANDLING(1, "Handling", 10_000),
|
||||||
WIND_WALKER(3, "Wind Walker"),
|
BUMPER(2, "Bumper", 10_000),
|
||||||
RANDOM(4, "Random");
|
WIND_WALKER(3, "Wind Walker", 10_000),
|
||||||
|
RANDOM(4, "Random", 10_000);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
private String name;
|
private String name;
|
||||||
|
private int timeout;
|
||||||
|
|
||||||
TokenType(int value, String name) {
|
TokenType(int value, String name, int timeout) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
@@ -26,4 +29,8 @@ public enum TokenType {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTimeout() {
|
||||||
|
return timeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ import seng302.visualiser.fxObjects.assets_3D.ModelType;
|
|||||||
public class RaceViewController extends Thread implements ImportantAnnotationDelegate {
|
public class RaceViewController extends Thread implements ImportantAnnotationDelegate {
|
||||||
|
|
||||||
private final int CHAT_LIMIT = 128;
|
private final int CHAT_LIMIT = 128;
|
||||||
|
private static final Double ICON_BLINK_TIMEOUT_RATIO = 0.6;
|
||||||
|
private static final Integer ICON_BLINK_PERIOD = 500;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Pane basePane;
|
private Pane basePane;
|
||||||
@@ -250,24 +252,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
player.addPowerUpListener((yacht, tokenType) -> {
|
player.addPowerUpListener(this::displayPowerUpIcon);
|
||||||
if (yacht == player) {
|
|
||||||
switch (tokenType) {
|
|
||||||
case BOOST:
|
|
||||||
velocityIcon.setVisible(true);
|
|
||||||
break;
|
|
||||||
case HANDLING:
|
|
||||||
handlingIcon.setVisible(true);
|
|
||||||
break;
|
|
||||||
case WIND_WALKER:
|
|
||||||
windWalkerIcon.setVisible(true);
|
|
||||||
break;
|
|
||||||
case BUMPER:
|
|
||||||
bumperIcon.setVisible(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
updateOrder(raceState.getPlayerPositions());
|
updateOrder(raceState.getPlayerPositions());
|
||||||
gameView = new GameView3D();
|
gameView = new GameView3D();
|
||||||
@@ -307,6 +292,61 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the relevant icon, starts blinking it when it is close to turning off and then
|
||||||
|
* switches it off after the tokens time out
|
||||||
|
*
|
||||||
|
* @param yacht The yacht only for which we are displaying the icon
|
||||||
|
* @param tokenType The type of token, indicating what icon needs to be displayed
|
||||||
|
*/
|
||||||
|
private void displayPowerUpIcon(ClientYacht yacht, TokenType tokenType) {
|
||||||
|
if (yacht == player) {
|
||||||
|
final ImageView iconToDisplay;
|
||||||
|
|
||||||
|
switch (tokenType) {
|
||||||
|
case BOOST:
|
||||||
|
iconToDisplay = velocityIcon;
|
||||||
|
break;
|
||||||
|
case HANDLING:
|
||||||
|
iconToDisplay = handlingIcon;
|
||||||
|
break;
|
||||||
|
case WIND_WALKER:
|
||||||
|
iconToDisplay = windWalkerIcon;
|
||||||
|
break;
|
||||||
|
case BUMPER:
|
||||||
|
iconToDisplay = bumperIcon;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
iconToDisplay = velocityIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Turn icon on
|
||||||
|
iconToDisplay.setVisible(true);
|
||||||
|
|
||||||
|
//Start blinking icon towards end
|
||||||
|
Timer blinkingTimer = new Timer();
|
||||||
|
blinkingTimer.schedule(new TimerTask() {
|
||||||
|
Boolean isVisible = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
isVisible = !isVisible;
|
||||||
|
iconToDisplay.setVisible(isVisible);
|
||||||
|
}
|
||||||
|
}, (int) (tokenType.getTimeout() * ICON_BLINK_TIMEOUT_RATIO), ICON_BLINK_PERIOD);
|
||||||
|
|
||||||
|
//Turn icon off after the time out
|
||||||
|
Timer switchOffTimer = new Timer();
|
||||||
|
switchOffTimer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
blinkingTimer.cancel();
|
||||||
|
iconToDisplay.setVisible(false);
|
||||||
|
}
|
||||||
|
}, tokenType.getTimeout());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The important annotations have been changed, update this view
|
* The important annotations have been changed, update this view
|
||||||
|
|||||||
Reference in New Issue
Block a user