Merge pull request #211 from yugecin/slider-improvements
Slider improvements (fade in ticks, fade out reversearrow, animations)
This commit is contained in:
@@ -180,6 +180,7 @@ public class Slider implements GameObject {
|
||||
@Override
|
||||
public void draw(Graphics g, int trackPosition) {
|
||||
int timeDiff = hitObject.getTime() - trackPosition;
|
||||
final int repeats = hitObject.getRepeatCount();
|
||||
final int approachTime = game.getApproachTime();
|
||||
final int fadeInTime = game.getFadeInTime();
|
||||
float scale = timeDiff / (float) approachTime;
|
||||
@@ -205,21 +206,44 @@ public class Slider implements GameObject {
|
||||
float curveInterval = Options.isSliderSnaking() ? alpha : 1f;
|
||||
curve.draw(color,curveInterval);
|
||||
|
||||
// end circle
|
||||
Vec2f endCircPos = curve.pointAt(curveInterval);
|
||||
hitCircle.drawCentered(endCircPos.x, endCircPos.y, color);
|
||||
hitCircleOverlay.drawCentered(endCircPos.x, endCircPos.y, Colors.WHITE_FADE);
|
||||
// end circle, only draw if ball still has to go there
|
||||
if (curveInterval == 1f && currentRepeats < repeats - (repeats % 2 == 0 ? 1 : 0)) {
|
||||
Color circleColor = new Color(color);
|
||||
Color overlayColor = new Color(Colors.WHITE_FADE);
|
||||
if (currentRepeats == 0) {
|
||||
if (Options.isSliderSnaking()) {
|
||||
// fade in end circle using decorationsAlpha when snaking sliders are enabled
|
||||
circleColor.a = overlayColor.a = sliderAlpha * decorationsAlpha;
|
||||
}
|
||||
} else {
|
||||
// fade in end circle after repeats
|
||||
circleColor.a = overlayColor.a = sliderAlpha * getCircleAlphaAfterRepeat(trackPosition, true);
|
||||
}
|
||||
Vec2f endCircPos = curve.pointAt(curveInterval);
|
||||
hitCircle.drawCentered(endCircPos.x, endCircPos.y, circleColor);
|
||||
hitCircleOverlay.drawCentered(endCircPos.x, endCircPos.y, overlayColor);
|
||||
}
|
||||
|
||||
// start circle
|
||||
hitCircle.drawCentered(x, y, color);
|
||||
if (!overlayAboveNumber)
|
||||
hitCircleOverlay.drawCentered(x, y, Colors.WHITE_FADE);
|
||||
// set first circle colors to fade in after repeats
|
||||
Color firstCircleColor = new Color(color);
|
||||
Color startCircleOverlayColor = new Color(Colors.WHITE_FADE);
|
||||
if (sliderClickedInitial) {
|
||||
// fade in first circle after repeats
|
||||
firstCircleColor.a = startCircleOverlayColor.a = sliderAlpha * getCircleAlphaAfterRepeat(trackPosition, false);
|
||||
}
|
||||
|
||||
// start circle, only draw if ball still has to go there
|
||||
if (!sliderClickedInitial || currentRepeats < repeats - (repeats % 2 == 1 ? 1 : 0)) {
|
||||
hitCircle.drawCentered(x, y, firstCircleColor);
|
||||
if (!overlayAboveNumber || sliderClickedInitial)
|
||||
hitCircleOverlay.drawCentered(x, y, startCircleOverlayColor);
|
||||
}
|
||||
|
||||
color.a = alpha;
|
||||
|
||||
// ticks
|
||||
if (ticksT != null) {
|
||||
drawSliderTicks(g, trackPosition, sliderAlpha, decorationsAlpha);
|
||||
drawSliderTicks(trackPosition, sliderAlpha, decorationsAlpha);
|
||||
Colors.WHITE_FADE.a = oldWhiteFadeAlpha;
|
||||
}
|
||||
|
||||
@@ -231,44 +255,42 @@ public class Slider implements GameObject {
|
||||
alpha = Math.min(alpha, hiddenAlpha);
|
||||
}
|
||||
}
|
||||
if (sliderClickedInitial)
|
||||
; // don't draw current combo number if already clicked
|
||||
else
|
||||
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
|
||||
hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), alpha);
|
||||
|
||||
if (overlayAboveNumber) {
|
||||
oldWhiteFadeAlpha = Colors.WHITE_FADE.a;
|
||||
Colors.WHITE_FADE.a = sliderAlpha;
|
||||
hitCircleOverlay.drawCentered(x, y, Colors.WHITE_FADE);
|
||||
Colors.WHITE_FADE.a = oldWhiteFadeAlpha;
|
||||
// draw combonumber and overlay if not initially clicked
|
||||
if (!sliderClickedInitial) {
|
||||
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
|
||||
hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), alpha);
|
||||
|
||||
if (overlayAboveNumber) {
|
||||
startCircleOverlayColor.a = sliderAlpha;
|
||||
hitCircleOverlay.drawCentered(x, y, startCircleOverlayColor);
|
||||
}
|
||||
}
|
||||
|
||||
// repeats
|
||||
if (curveInterval == 1.0f) {
|
||||
for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1; tcurRepeat++) {
|
||||
if (hitObject.getRepeatCount() - 1 > tcurRepeat) {
|
||||
Image arrow = GameImage.REVERSEARROW.getImage();
|
||||
// bouncing animation
|
||||
//arrow = arrow.getScaledCopy((float) (1 + 0.2d * ((trackPosition + sliderTime * tcurRepeat) % 292) / 292));
|
||||
float colorLuminance = 0.299f*color.r + 0.587f*color.g + 0.114f*color.b;
|
||||
Color arrowColor = colorLuminance < 0.8f ? Color.white : Color.black;
|
||||
if (tcurRepeat != currentRepeats) {
|
||||
if (sliderTime == 0)
|
||||
continue;
|
||||
float t = Math.max(getT(trackPosition, true), 0);
|
||||
arrow.setAlpha((float) (t - Math.floor(t)));
|
||||
} else
|
||||
arrow.setAlpha(Options.isSliderSnaking() ? decorationsAlpha : 1f);
|
||||
if (tcurRepeat % 2 == 0) {
|
||||
// last circle
|
||||
arrow.setRotation(curve.getEndAngle());
|
||||
arrow.drawCentered(endPos.x, endPos.y, arrowColor);
|
||||
} else {
|
||||
// first circle
|
||||
arrow.setRotation(curve.getStartAngle());
|
||||
arrow.drawCentered(x, y, arrowColor);
|
||||
for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1 && tcurRepeat < repeats - 1; tcurRepeat++) {
|
||||
Image arrow = GameImage.REVERSEARROW.getImage();
|
||||
// bouncing animation
|
||||
//arrow = arrow.getScaledCopy((float) (1 + 0.2d * ((trackPosition + sliderTime * tcurRepeat) % 292) / 292));
|
||||
float colorLuminance = 0.299f*color.r + 0.587f*color.g + 0.114f*color.b;
|
||||
Color arrowColor = colorLuminance < 0.8f ? Color.white : Color.black;
|
||||
if (tcurRepeat == 0) {
|
||||
arrow.setAlpha(Options.isSliderSnaking() ? decorationsAlpha : 1f);
|
||||
} else {
|
||||
if (!sliderClickedInitial) {
|
||||
continue;
|
||||
}
|
||||
arrow.setAlpha(getCircleAlphaAfterRepeat(trackPosition, tcurRepeat % 2 == 0));
|
||||
}
|
||||
if (tcurRepeat % 2 == 0) {
|
||||
// last circle
|
||||
arrow.setRotation(curve.getEndAngle());
|
||||
arrow.drawCentered(endPos.x, endPos.y, arrowColor);
|
||||
} else {
|
||||
// first circle
|
||||
arrow.setRotation(curve.getStartAngle());
|
||||
arrow.drawCentered(x, y, arrowColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,12 +341,11 @@ public class Slider implements GameObject {
|
||||
|
||||
/**
|
||||
* Draws slider ticks.
|
||||
* @param g the graphics context
|
||||
* @param trackPosition the track position
|
||||
* @param curveAlpha the curve alpha level
|
||||
* @param decorationsAlpha the decorations alpha level
|
||||
*/
|
||||
private void drawSliderTicks(Graphics g, int trackPosition, float curveAlpha, float decorationsAlpha) {
|
||||
private void drawSliderTicks(int trackPosition, float curveAlpha, float decorationsAlpha) {
|
||||
float tickScale = 0.5f + 0.5f * AnimationEquation.OUT_BACK.calc(decorationsAlpha);
|
||||
Image tick = GameImage.SLIDER_TICK.getImage().getScaledCopy(tickScale);
|
||||
|
||||
@@ -344,14 +365,44 @@ public class Slider implements GameObject {
|
||||
min = 0;
|
||||
}
|
||||
|
||||
// calculate the tick alpha level
|
||||
float sliderTickAlpha;
|
||||
if (currentRepeats == 0) {
|
||||
sliderTickAlpha = decorationsAlpha;
|
||||
} else {
|
||||
float t = getT(trackPosition, false);
|
||||
if (currentRepeats % 2 == 1) {
|
||||
t = 1f - t;
|
||||
}
|
||||
sliderTickAlpha = Utils.clamp(t * ticksT.length * 2, 0f, 1f);
|
||||
}
|
||||
|
||||
// draw ticks
|
||||
Colors.WHITE_FADE.a = Math.min(curveAlpha, sliderTickAlpha);
|
||||
for (int i = min; i < max; i++) {
|
||||
Vec2f c = curve.pointAt(ticksT[i]);
|
||||
Colors.WHITE_FADE.a = Math.min(curveAlpha, decorationsAlpha);
|
||||
tick.drawCentered(c.x, c.y, Colors.WHITE_FADE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the alpha level used to fade in circles & reversearrows after repeat
|
||||
* @param trackPosition current trackposition, in ms
|
||||
* @param endCircle request alpha for end circle (true) or start circle (false)?
|
||||
* @return alpha level as float in interval [0, 1]
|
||||
*/
|
||||
private float getCircleAlphaAfterRepeat(int trackPosition, boolean endCircle) {
|
||||
int ticksN = ticksT == null ? 0 : ticksT.length;
|
||||
float t = getT(trackPosition, false);
|
||||
if (endCircle) {
|
||||
t = 1f - t;
|
||||
}
|
||||
if (currentRepeats % 2 == (endCircle ? 0 : 1)) {
|
||||
t = 1f;
|
||||
}
|
||||
return Utils.clamp(t * (ticksN + 1), 0f, 1f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the slider hit result.
|
||||
* @return the hit result (GameData.HIT_* constants)
|
||||
@@ -430,7 +481,7 @@ public class Slider implements GameObject {
|
||||
}
|
||||
data.hitResult(hitObject.getTime() + (int) sliderTimeTotal, result,
|
||||
cx, cy, color, comboEnd, hitObject, type, sliderHeldToEnd,
|
||||
currentRepeats + 1, curve, sliderHeldToEnd);
|
||||
currentRepeats + 1, null, sliderHeldToEnd);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -449,8 +500,11 @@ public class Slider implements GameObject {
|
||||
if (timeDiff < hitResultOffset[GameData.HIT_50]) {
|
||||
result = GameData.HIT_SLIDER30;
|
||||
ticksHit++;
|
||||
} else if (timeDiff < hitResultOffset[GameData.HIT_MISS])
|
||||
data.sendAnimationResult(trackPosition, this.x, this.y, color, true);
|
||||
} else if (timeDiff < hitResultOffset[GameData.HIT_MISS]) {
|
||||
result = GameData.HIT_MISS;
|
||||
data.sendAnimationResult(trackPosition, this.x, this.y, color, false);
|
||||
}
|
||||
//else not a hit
|
||||
|
||||
if (result > -1) {
|
||||
@@ -478,8 +532,11 @@ public class Slider implements GameObject {
|
||||
if (isAutoMod) { // "auto" mod: catch any missed notes due to lag
|
||||
ticksHit++;
|
||||
data.sliderTickResult(time, GameData.HIT_SLIDER30, x, y, hitObject, currentRepeats);
|
||||
} else
|
||||
data.sendAnimationResult(time, x, y, color, true);
|
||||
} else {
|
||||
data.sliderTickResult(time, GameData.HIT_MISS, x, y, hitObject, currentRepeats);
|
||||
data.sendAnimationResult(trackPosition, x, y, color, false);
|
||||
}
|
||||
}
|
||||
|
||||
// "auto" mod: send a perfect hit result
|
||||
@@ -488,6 +545,7 @@ public class Slider implements GameObject {
|
||||
ticksHit++;
|
||||
sliderClickedInitial = true;
|
||||
data.sliderTickResult(time, GameData.HIT_SLIDER30, x, y, hitObject, currentRepeats);
|
||||
data.sendAnimationResult(time, x, y, color, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,6 +577,9 @@ public class Slider implements GameObject {
|
||||
|
||||
// calculate and send slider result
|
||||
hitResult();
|
||||
|
||||
// send 'curve fade out' hit result
|
||||
data.sendSliderCurveResult(getEndTime(), color, curve);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -565,13 +626,26 @@ public class Slider implements GameObject {
|
||||
// held during new repeat
|
||||
if (isNewRepeat) {
|
||||
ticksHit++;
|
||||
|
||||
HitObjectType type;
|
||||
float posX, posY;
|
||||
if (currentRepeats % 2 > 0) { // last circle
|
||||
int lastIndex = hitObject.getSliderX().length;
|
||||
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER30,
|
||||
curve.getX(lastIndex), curve.getY(lastIndex), hitObject, currentRepeats);
|
||||
} else // first circle
|
||||
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER30,
|
||||
c.x, c.y, hitObject, currentRepeats);
|
||||
type = HitObjectType.SLIDER_LAST;
|
||||
Vec2f endPos = curve.pointAt(1f);
|
||||
posX = endPos.x;
|
||||
posY = endPos.y;
|
||||
} else { // first circle
|
||||
type = HitObjectType.SLIDER_FIRST;
|
||||
posX = this.x;
|
||||
posY = this.y;
|
||||
}
|
||||
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER30,
|
||||
posX, posY, hitObject, currentRepeats);
|
||||
|
||||
// send hit result, to fade out reversearrow
|
||||
float colorLuminance = 0.299f*color.r + 0.587f*color.g + 0.114f*color.b;
|
||||
Color arrowColor = colorLuminance < 0.8f ? Color.white : Color.black;
|
||||
data.sendRepeatSliderResult(trackPosition, posX, posY, arrowColor, curve, type);
|
||||
}
|
||||
|
||||
// held during new tick
|
||||
|
||||
Reference in New Issue
Block a user