put common hitcircle render code in separate class
This commit is contained in:
@@ -20,7 +20,6 @@ package itdelatrisu.opsu.objects;
|
||||
|
||||
import itdelatrisu.opsu.GameData;
|
||||
import itdelatrisu.opsu.GameData.HitObjectType;
|
||||
import itdelatrisu.opsu.GameImage;
|
||||
import itdelatrisu.opsu.GameMod;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
@@ -30,16 +29,18 @@ import itdelatrisu.opsu.states.Game;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import yugecin.opsudance.Dancer;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.render.GameObjectRenderer;
|
||||
|
||||
/**
|
||||
* Data type representing a circle object.
|
||||
*/
|
||||
public class Circle extends GameObject {
|
||||
/** The diameter of hit circles. */
|
||||
public static float diameter;
|
||||
|
||||
@Inject
|
||||
private GameObjectRenderer gameObjectRenderer;
|
||||
|
||||
/** The associated HitObject. */
|
||||
private HitObject hitObject;
|
||||
@@ -62,18 +63,6 @@ public class Circle extends GameObject {
|
||||
|
||||
private int comboColorIndex;
|
||||
|
||||
/**
|
||||
* Initializes the Circle data type with map modifiers, images, and dimensions.
|
||||
* @param circleDiameter the circle diameter
|
||||
*/
|
||||
public static void init(float circleDiameter) {
|
||||
diameter = circleDiameter * HitObject.getXMultiplier(); // convert from Osupixels (640x480)
|
||||
int diameterInt = (int) diameter;
|
||||
GameImage.HITCIRCLE.setImage(GameImage.HITCIRCLE.getImage().getScaledCopy(diameterInt, diameterInt));
|
||||
GameImage.HITCIRCLE_OVERLAY.setImage(GameImage.HITCIRCLE_OVERLAY.getImage().getScaledCopy(diameterInt, diameterInt));
|
||||
GameImage.APPROACHCIRCLE.setImage(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(diameterInt, diameterInt));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param hitObject the associated HitObject
|
||||
@@ -129,16 +118,10 @@ public class Circle extends GameObject {
|
||||
float oldAlpha = Colors.WHITE_FADE.a;
|
||||
Colors.WHITE_FADE.a = color.a = alpha;
|
||||
|
||||
if (timeDiff >= 0 && !GameMod.HIDDEN.isActive() && Options.isDrawApproach())
|
||||
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
|
||||
GameImage.HITCIRCLE.getImage().drawCentered(x, y, color);
|
||||
boolean overlayAboveNumber = Options.getSkin().isHitCircleOverlayAboveNumber();
|
||||
if (!overlayAboveNumber)
|
||||
GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Colors.WHITE_FADE);
|
||||
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
|
||||
GameImage.HITCIRCLE.getImage().getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), alpha);
|
||||
if (overlayAboveNumber)
|
||||
GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Colors.WHITE_FADE);
|
||||
if (timeDiff >= 0) {
|
||||
gameObjectRenderer.renderApproachCircle(x, y, color, approachScale);
|
||||
}
|
||||
gameObjectRenderer.renderHitCircle(x, y, color, hitObject.getComboNumber(), alpha);
|
||||
|
||||
Colors.WHITE_FADE.a = oldAlpha;
|
||||
|
||||
@@ -172,7 +155,7 @@ public class Circle extends GameObject {
|
||||
@Override
|
||||
public boolean mousePressed(int x, int y, int trackPosition) {
|
||||
double distance = Math.hypot(this.x - x, this.y - y);
|
||||
if (distance < diameter / 2) {
|
||||
if (distance < gameObjectRenderer.getCircleDiameter() / 2) {
|
||||
int timeDiff = trackPosition - hitObject.getTime();
|
||||
int result = hitResult(timeDiff);
|
||||
|
||||
|
||||
@@ -37,11 +37,20 @@ import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import yugecin.opsudance.Dancer;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.render.GameObjectRenderer;
|
||||
|
||||
/**
|
||||
* Data type representing a slider object.
|
||||
*/
|
||||
public class Slider extends GameObject {
|
||||
|
||||
@Inject
|
||||
private DisplayContainer displayContainer;
|
||||
|
||||
@Inject
|
||||
private GameObjectRenderer gameObjectRenderer;
|
||||
|
||||
/** Slider ball frames. */
|
||||
private static Image[] sliderBallImages;
|
||||
|
||||
@@ -54,9 +63,6 @@ public class Slider extends GameObject {
|
||||
/** Follow circle radius. */
|
||||
private static float followRadius;
|
||||
|
||||
/** The diameter of hit circles. */
|
||||
private static float diameter;
|
||||
|
||||
/** The associated HitObject. */
|
||||
private HitObject hitObject;
|
||||
|
||||
@@ -116,9 +122,6 @@ public class Slider extends GameObject {
|
||||
private static final int FOLLOW_EXPAND_TIME = 150;
|
||||
private static final int FOLLOW_SHRINK_TIME = 100;
|
||||
|
||||
/** Container dimensions. */
|
||||
private static int containerWidth, containerHeight;
|
||||
|
||||
private int repeats;
|
||||
|
||||
private static Color curveColor = new Color(0, 0, 0, 20);
|
||||
@@ -134,14 +137,9 @@ public class Slider extends GameObject {
|
||||
* @param circleDiameter the circle diameter
|
||||
* @param beatmap the associated beatmap
|
||||
*/
|
||||
public static void init(DisplayContainer displayContainer, float circleDiameter, Beatmap beatmap) {
|
||||
containerWidth = displayContainer.width;
|
||||
containerHeight = displayContainer.height;
|
||||
|
||||
diameter = circleDiameter * HitObject.getXMultiplier(); // convert from Osupixels (640x480)
|
||||
int diameterInt = (int) diameter;
|
||||
|
||||
followRadius = diameter / 2 * 3f;
|
||||
public static void init(float circleDiameter, Beatmap beatmap) {
|
||||
followRadius = circleDiameter / 2 * 3f;
|
||||
int diameterInt = (int) circleDiameter;
|
||||
|
||||
// slider ball
|
||||
if (GameImage.SLIDER_BALL.hasBeatmapSkinImages() ||
|
||||
@@ -219,8 +217,6 @@ public class Slider extends GameObject {
|
||||
boolean overlayAboveNumber = Options.getSkin().isHitCircleOverlayAboveNumber();
|
||||
float oldAlpha = Colors.WHITE_FADE.a;
|
||||
Colors.WHITE_FADE.a = color.a = alpha;
|
||||
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
||||
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
||||
Vec2f endPos = curve.pointAt(1);
|
||||
|
||||
float oldWhiteFadeAlpha = Colors.WHITE_FADE.a;
|
||||
@@ -249,8 +245,8 @@ public class Slider extends GameObject {
|
||||
circleColor.a = overlayColor.a = sliderAlpha * getCircleAlphaAfterRepeat(trackPosition, true);
|
||||
}
|
||||
Vec2f endCircPos = curve.pointAt(1f);
|
||||
hitCircle.drawCentered(endCircPos.x, endCircPos.y, circleColor);
|
||||
hitCircleOverlay.drawCentered(endCircPos.x, endCircPos.y, overlayColor);
|
||||
gameObjectRenderer.renderHitCircleOnly(endCircPos.x, endCircPos.y, circleColor);
|
||||
gameObjectRenderer.renderHitCircleOverlayOnly(endCircPos.x, endCircPos.y, overlayColor);
|
||||
}
|
||||
|
||||
g.pushTransform();
|
||||
@@ -268,9 +264,10 @@ public class Slider extends GameObject {
|
||||
|
||||
// start circle, only draw if ball still has to go there
|
||||
if (!sliderClickedInitial || (Options.isDrawSliderEndCircles() && currentRepeats < repeatCount - (repeatCount % 2 == 1 ? 1 : 0))) {
|
||||
hitCircle.drawCentered(x, y, firstCircleColor);
|
||||
if (!overlayAboveNumber || sliderClickedInitial)
|
||||
hitCircleOverlay.drawCentered(x, y, startCircleOverlayColor);
|
||||
gameObjectRenderer.renderHitCircleOnly(x, y, firstCircleColor);
|
||||
if (!overlayAboveNumber || sliderClickedInitial) {
|
||||
gameObjectRenderer.renderHitCircleOverlayOnly(x, y, startCircleOverlayColor);
|
||||
}
|
||||
}
|
||||
|
||||
g.popTransform();
|
||||
@@ -297,12 +294,11 @@ public class Slider extends GameObject {
|
||||
|
||||
// draw combo number and overlay if not initially clicked
|
||||
if (!sliderClickedInitial) {
|
||||
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
|
||||
hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), alpha);
|
||||
gameObjectRenderer.renderComboNumberOnly(x, y, hitObject.getComboNumber(), alpha);
|
||||
|
||||
if (overlayAboveNumber) {
|
||||
startCircleOverlayColor.a = sliderAlpha;
|
||||
hitCircleOverlay.drawCentered(x, y, startCircleOverlayColor);
|
||||
gameObjectRenderer.renderHitCircleOverlayOnly(x, y, startCircleOverlayColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +336,7 @@ public class Slider extends GameObject {
|
||||
g.rotate(x, y, -180f);
|
||||
}
|
||||
if (!GameMod.HIDDEN.isActive() && Options.isDrawApproach()) {
|
||||
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
|
||||
gameObjectRenderer.renderApproachCircle(x, y, color, approachScale);
|
||||
}
|
||||
g.popTransform();
|
||||
} else {
|
||||
@@ -394,7 +390,7 @@ public class Slider extends GameObject {
|
||||
float oldAlphaBlack = Colors.BLACK_ALPHA.a;
|
||||
Colors.BLACK_ALPHA.a = 0.75f;
|
||||
g.setColor(Colors.BLACK_ALPHA);
|
||||
g.fillRect(0, 0, containerWidth, containerHeight);
|
||||
g.fillRect(0, 0, displayContainer.width, displayContainer.height);
|
||||
Colors.BLACK_ALPHA.a = oldAlphaBlack;
|
||||
}
|
||||
}
|
||||
@@ -606,7 +602,7 @@ public class Slider extends GameObject {
|
||||
return false;
|
||||
|
||||
double distance = Math.hypot(this.x - x, this.y - y);
|
||||
if (distance < diameter / 2) {
|
||||
if (distance < gameObjectRenderer.getCircleDiameter() / 2) {
|
||||
int timeDiff = Math.abs(trackPosition - hitObject.getTime());
|
||||
int[] hitResultOffset = game.getHitResultOffsets();
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import itdelatrisu.opsu.GameImage;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.beatmap.HitObject;
|
||||
import itdelatrisu.opsu.objects.Circle;
|
||||
import itdelatrisu.opsu.objects.curves.Vec2f;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -37,6 +36,7 @@ import org.lwjgl.opengl.GL20;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.util.Log;
|
||||
import yugecin.opsudance.render.GameObjectRenderer;
|
||||
|
||||
/**
|
||||
* Hold the temporary render state that needs to be restored again after the new
|
||||
@@ -303,7 +303,7 @@ public class CurveRenderState {
|
||||
double diff_x = x - last_x;
|
||||
double diff_y = y - last_y;
|
||||
float dist = Utils.distance(x, y, last_x, last_y);
|
||||
if (dist < Circle.diameter / 8) {
|
||||
if (dist < GameObjectRenderer.instance.getCircleDiameter() / 8) {
|
||||
x = (float) (x - diff_x / 2);
|
||||
y = (float) (y - diff_y / 2);
|
||||
} else {
|
||||
|
||||
@@ -73,6 +73,7 @@ import yugecin.opsudance.core.state.transitions.FadeOutTransitionState;
|
||||
import yugecin.opsudance.events.BarNotificationEvent;
|
||||
import yugecin.opsudance.events.BubbleNotificationEvent;
|
||||
import yugecin.opsudance.objects.curves.FakeCombinedCurve;
|
||||
import yugecin.opsudance.render.GameObjectRenderer;
|
||||
import yugecin.opsudance.sbv2.MoveStoryboard;
|
||||
import yugecin.opsudance.ui.OptionsOverlay;
|
||||
import yugecin.opsudance.ui.StoryboardOverlay;
|
||||
@@ -86,6 +87,9 @@ public class Game extends ComplexOpsuState {
|
||||
@Inject
|
||||
private InstanceContainer instanceContainer;
|
||||
|
||||
@Inject
|
||||
private GameObjectRenderer gameObjectRenderer;
|
||||
|
||||
public static boolean isInGame; // TODO delete this when #79 is fixed
|
||||
/** Game restart states. */
|
||||
public enum Restart {
|
||||
@@ -362,6 +366,7 @@ public class Game extends ComplexOpsuState {
|
||||
|
||||
// create the associated GameData object
|
||||
data = new GameData(displayContainer.width, displayContainer.height);
|
||||
gameObjectRenderer.setGameData(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1560,12 +1565,13 @@ public class Game extends ComplexOpsuState {
|
||||
}
|
||||
|
||||
try {
|
||||
if (hitObject.isCircle())
|
||||
gameObjects[i] = new Circle(hitObject, this, data, hitObject.getComboIndex(), comboEnd);
|
||||
else if (hitObject.isSlider())
|
||||
gameObjects[i] = new Slider(hitObject, this, data, hitObject.getComboIndex(), comboEnd);
|
||||
else if (hitObject.isSpinner())
|
||||
if (hitObject.isCircle()) {
|
||||
gameObjects[i] = instanceContainer.injectFields(new Circle(hitObject, this, data, hitObject.getComboIndex(), comboEnd));
|
||||
} else if (hitObject.isSlider()) {
|
||||
gameObjects[i] = instanceContainer.injectFields(new Slider(hitObject, this, data, hitObject.getComboIndex(), comboEnd));
|
||||
} else if (hitObject.isSpinner()) {
|
||||
gameObjects[i] = new Spinner(hitObject, this, data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String message = String.format("Failed to create %s at index %d:\n%s", hitObject.getTypeName(), i, hitObject.toString());
|
||||
Log.error(message, e);
|
||||
@@ -2036,8 +2042,8 @@ public class Game extends ComplexOpsuState {
|
||||
HitObject.setStackOffset(diameter * STACK_OFFSET_MODIFIER);
|
||||
|
||||
// initialize objects
|
||||
Circle.init(diameter);
|
||||
Slider.init(displayContainer, diameter, beatmap);
|
||||
gameObjectRenderer.initForGame(data, diameter);
|
||||
Slider.init(gameObjectRenderer.getCircleDiameter(), beatmap);
|
||||
Spinner.init(displayContainer, overallDifficulty);
|
||||
Curve.init(displayContainer.width, displayContainer.height, diameter, (Options.isBeatmapSkinIgnored()) ?
|
||||
Options.getSkin().getSliderBorderColor() : beatmap.getSliderBorderColor());
|
||||
|
||||
Reference in New Issue
Block a user