simplify access to display width and height and halves
This commit is contained in:
@@ -44,6 +44,7 @@ import yugecin.opsudance.core.errorhandling.ErrorDumpable;
|
||||
import yugecin.opsudance.core.state.OpsuState;
|
||||
import yugecin.opsudance.events.ResolutionChangedListener;
|
||||
import yugecin.opsudance.events.SkinChangedListener;
|
||||
import yugecin.opsudance.ui.BackButton;
|
||||
import yugecin.opsudance.utils.GLHelper;
|
||||
|
||||
import java.io.StringWriter;
|
||||
@@ -68,9 +69,6 @@ public class DisplayContainer implements ErrorDumpable, SkinChangedListener {
|
||||
|
||||
private Graphics graphics;
|
||||
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public int mouseX;
|
||||
public int mouseY;
|
||||
|
||||
@@ -149,12 +147,13 @@ public class DisplayContainer implements ErrorDumpable, SkinChangedListener {
|
||||
}
|
||||
}
|
||||
|
||||
backButton = new BackButton();
|
||||
|
||||
// TODO clean this up
|
||||
GameMod.init(width, height);
|
||||
PlaybackSpeed.init(width, height);
|
||||
HitObject.init(width, height);
|
||||
DownloadNode.init(width, height);
|
||||
UI.init(this);
|
||||
}
|
||||
|
||||
public void setUPS(int ups) {
|
||||
@@ -262,7 +261,7 @@ public class DisplayContainer implements ErrorDumpable, SkinChangedListener {
|
||||
}
|
||||
|
||||
public void setup() throws Exception {
|
||||
width = height = -1;
|
||||
width = height = width2 = height2 = -1;
|
||||
Display.setTitle("opsu!dance");
|
||||
setupResolutionOptionlist(nativeDisplayMode.getWidth(), nativeDisplayMode.getHeight());
|
||||
updateDisplayMode(OPTION_SCREEN_RESOLUTION.getValueString());
|
||||
@@ -372,29 +371,34 @@ public class DisplayContainer implements ErrorDumpable, SkinChangedListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDisplayMode(int width, int height, boolean fullscreen) throws Exception {
|
||||
if (this.width == width && this.height == height) {
|
||||
public void setDisplayMode(int w, int h, boolean fullscreen) throws Exception {
|
||||
if (width == w && height == h) {
|
||||
Display.setFullscreen(fullscreen);
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayMode displayMode = null;
|
||||
if (fullscreen) {
|
||||
displayMode = GLHelper.findFullscreenDisplayMode(nativeDisplayMode.getBitsPerPixel(), nativeDisplayMode.getFrequency(), width, height);
|
||||
final int bpp = this.nativeDisplayMode.getBitsPerPixel();
|
||||
final int freq = this.nativeDisplayMode.getFrequency();
|
||||
displayMode = GLHelper.findFullscreenDisplayMode(bpp, freq, w, h);
|
||||
}
|
||||
|
||||
if (displayMode == null) {
|
||||
displayMode = new DisplayMode(width, height);
|
||||
displayMode = new DisplayMode(w, h);
|
||||
if (fullscreen) {
|
||||
fullscreen = false;
|
||||
String msg = String.format("Fullscreen mode is not supported for %sx%s", width, height);
|
||||
String msg = "Fullscreen mode is not supported for %sx%s";
|
||||
msg = String.format(msg, w, h);
|
||||
Log.warn(msg);
|
||||
bubNotifs.send(BUB_ORANGE, msg);
|
||||
}
|
||||
}
|
||||
|
||||
this.width = displayMode.getWidth();
|
||||
this.height = displayMode.getHeight();
|
||||
width = displayMode.getWidth();
|
||||
height = displayMode.getHeight();
|
||||
width2 = width / 2;
|
||||
height2 = height / 2;
|
||||
|
||||
Display.setDisplayMode(displayMode);
|
||||
Display.setFullscreen(fullscreen);
|
||||
@@ -509,6 +513,7 @@ public class DisplayContainer implements ErrorDumpable, SkinChangedListener {
|
||||
this.state = state;
|
||||
this.state.enter();
|
||||
input.addListener(this.state);
|
||||
backButton.resetHover();
|
||||
if (this.rendering) {
|
||||
// state might be changed in preRenderUpdate,
|
||||
// in that case the new state will be rendered without having
|
||||
|
||||
@@ -34,6 +34,7 @@ import yugecin.opsudance.options.Configuration;
|
||||
import yugecin.opsudance.options.OptionsService;
|
||||
import yugecin.opsudance.render.GameObjectRenderer;
|
||||
import yugecin.opsudance.skinning.SkinService;
|
||||
import yugecin.opsudance.ui.BackButton;
|
||||
import yugecin.opsudance.utils.ManifestWrapper;
|
||||
|
||||
import java.io.File;
|
||||
@@ -55,6 +56,7 @@ public class InstanceContainer {
|
||||
public static BeatmapParser beatmapParser;
|
||||
public static Updater updater;
|
||||
|
||||
public static BackButton backButton;
|
||||
public static DisplayContainer displayContainer;
|
||||
public static Input input;
|
||||
|
||||
@@ -72,6 +74,8 @@ public class InstanceContainer {
|
||||
public static Game gameState;
|
||||
public static GameRanking gameRankingState;
|
||||
public static GamePauseMenu pauseState;
|
||||
|
||||
public static int width, width2, height, height2;
|
||||
|
||||
public static void kickstart() {
|
||||
updater = new Updater();
|
||||
|
||||
@@ -26,7 +26,7 @@ import yugecin.opsudance.events.ResolutionChangedListener;
|
||||
import java.util.Formatter;
|
||||
import java.util.List;
|
||||
|
||||
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
|
||||
import static yugecin.opsudance.core.InstanceContainer.*;
|
||||
|
||||
public class BarNotificationState implements ResolutionChangedListener {
|
||||
|
||||
@@ -60,10 +60,10 @@ public class BarNotificationState implements ResolutionChangedListener {
|
||||
timeShown += displayContainer.renderDelta;
|
||||
processAnimations();
|
||||
g.setColor(bgcol);
|
||||
g.fillRect(0, displayContainer.height / 2 - barHalfHeight, displayContainer.width, barHalfHeight * 2);
|
||||
g.fillRect(0, height2 - barHalfHeight, width, barHalfHeight * 2);
|
||||
int y = textY;
|
||||
for (String line : lines) {
|
||||
Fonts.LARGE.drawString((displayContainer.width - Fonts.LARGE.getWidth(line)) / 2, y, line, textCol);
|
||||
Fonts.LARGE.drawString((width - Fonts.LARGE.getWidth(line)) / 2, y, line, textCol);
|
||||
y += Fonts.LARGE.getLineHeight();
|
||||
}
|
||||
}
|
||||
@@ -88,9 +88,9 @@ public class BarNotificationState implements ResolutionChangedListener {
|
||||
}
|
||||
|
||||
private void calculatePosition() {
|
||||
this.lines = Fonts.wrap(Fonts.LARGE, message, (int) (displayContainer.width * 0.96f), true);
|
||||
this.lines = Fonts.wrap(Fonts.LARGE, message, (int) (width * 0.96f), true);
|
||||
int textHeight = (int) (Fonts.LARGE.getLineHeight() * (lines.size() + 0.5f));
|
||||
textY = (displayContainer.height - textHeight) / 2 + (int) (Fonts.LARGE.getLineHeight() / 5f);
|
||||
textY = (height - textHeight) / 2 + (int) (Fonts.LARGE.getLineHeight() / 5f);
|
||||
barHalfTargetHeight = textHeight / 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,10 +72,10 @@ public class BubNotifState implements MouseListener, ResolutionChangedListener {
|
||||
|
||||
private void calculatePositions() {
|
||||
// if width is 0, attempting to wrap it will result in infinite loop
|
||||
Notification.width = Math.max(50, (int) (displayContainer.width * 0.1703125f));
|
||||
Notification.baseLine = (int) (displayContainer.height * 0.9645f);
|
||||
Notification.paddingY = (int) (displayContainer.height * 0.0144f);
|
||||
Notification.finalX = displayContainer.width - Notification.width - (int) (displayContainer.width * 0.01);
|
||||
Notification.width = Math.max(50, (int) (width * 0.1703125f));
|
||||
Notification.baseLine = (int) (height * 0.9645f);
|
||||
Notification.paddingY = (int) (height * 0.0144f);
|
||||
Notification.finalX = width - Notification.width - (int) (width * 0.01);
|
||||
Notification.fontPaddingX = (int) (Notification.width * 0.02f);
|
||||
Notification.fontPaddingY = (int) (Fonts.SMALLBOLD.getLineHeight() / 4f);
|
||||
Notification.lineHeight = Fonts.SMALLBOLD.getLineHeight();
|
||||
|
||||
@@ -24,7 +24,7 @@ import yugecin.opsudance.events.ResolutionChangedListener;
|
||||
import yugecin.opsudance.utils.FPSMeter;
|
||||
|
||||
import static yugecin.opsudance.options.Options.*;
|
||||
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
|
||||
import static yugecin.opsudance.core.InstanceContainer.*;
|
||||
|
||||
public class FpsRenderState implements ResolutionChangedListener {
|
||||
|
||||
@@ -90,8 +90,8 @@ public class FpsRenderState implements ResolutionChangedListener {
|
||||
@Override
|
||||
public void onResolutionChanged(int w, int h) {
|
||||
singleHeight = Fonts.SMALL.getLineHeight();
|
||||
x = displayContainer.width - 3;
|
||||
y = displayContainer.height - 3 - singleHeight - 10;
|
||||
x = width - 3;
|
||||
y = height - 3 - singleHeight - 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user