simplify access to display width and height and halves

This commit is contained in:
yugecin
2018-07-08 00:30:47 +02:00
parent 27bbc874da
commit d412a2e39e
44 changed files with 339 additions and 399 deletions

View File

@@ -28,8 +28,6 @@ import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.ui.BackButton;
import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -39,9 +37,6 @@ import static yugecin.opsudance.core.InstanceContainer.*;
*/
public class UI {
/** Back button. */
private static BackButton backButton;
/** Time to show volume image, in milliseconds. */
private static final int VOLUME_DISPLAY_TIME = 1500;
@@ -57,20 +52,9 @@ public class UI {
/** The alpha level of the current tooltip (if any). */
private static AnimatedValue tooltipAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR);
// game-related variables
private static DisplayContainer displayContainer;
// This class should not be instantiated.
private UI() {}
/**
* Initializes UI data.
*/
public static void init(DisplayContainer displayContainer) {
UI.displayContainer = displayContainer;
backButton = new BackButton(displayContainer);
}
/**
* Updates all UI components by a delta interval.
* @param delta the delta interval since the last call.
@@ -92,15 +76,9 @@ public class UI {
* Resets the necessary UI components upon entering a state.
*/
public static void enter() {
backButton.resetHover();
resetTooltip();
}
/**
* Returns the 'menu-back' MenuButton.
*/
public static BackButton getBackButton() { return backButton; }
/**
* Draws a tab image and text centered at a location.
* @param x the center x coordinate
@@ -144,13 +122,13 @@ public class UI {
else if (ratio >= 0.9f)
xOffset = img.getWidth() * (1 - ((1 - ratio) * 10f));
img.drawCentered(displayContainer.width - img.getWidth() / 2f + xOffset, displayContainer.height / 2f);
img.drawCentered(width - img.getWidth() / 2f + xOffset, height2);
float barHeight = img.getHeight() * 0.9f;
float volume = OPTION_MASTER_VOLUME.val / 100f;
g.setColor(Color.white);
g.fillRoundRect(
displayContainer.width - (img.getWidth() * 0.368f) + xOffset,
(displayContainer.height / 2f) - (img.getHeight() * 0.47f) + (barHeight * (1 - volume)),
width - (img.getWidth() * 0.368f) + xOffset,
height2 - (img.getHeight() * 0.47f) + (barHeight * (1 - volume)),
img.getWidth() * 0.15f, barHeight * volume, 3
);
}
@@ -209,8 +187,8 @@ public class UI {
return;
// draw loading info
float marginX = displayContainer.width * 0.02f, marginY = displayContainer.height * 0.02f;
float lineY = displayContainer.height - marginY;
float marginX = width * 0.02f, marginY = height * 0.02f;
float lineY = height - marginY;
int lineOffsetY = Fonts.MEDIUM.getLineHeight();
if (OPTION_LOAD_VERBOSE.state) {
// verbose: display percentages and file names
@@ -223,7 +201,7 @@ public class UI {
Fonts.MEDIUM.drawString(marginX, lineY - (lineOffsetY * 2), text, Color.white);
g.setColor(Color.white);
g.fillRoundRect(marginX, lineY - (lineOffsetY / 2f),
(displayContainer.width - (marginX * 2f)) * progress / 100f, lineOffsetY / 4f, 4
(width - (marginX * 2f)) * progress / 100f, lineOffsetY / 4f, 4
);
}
}
@@ -247,7 +225,7 @@ public class UI {
float unitBaseX, float unitBaseY, float unitWidth, float scrollAreaHeight,
Color bgColor, Color scrollbarColor, boolean right
) {
float scrollbarWidth = displayContainer.width * 0.00347f;
float scrollbarWidth = width * 0.00347f;
float scrollbarHeight = scrollAreaHeight * lengthShown / totalLength;
float offsetY = (scrollAreaHeight - scrollbarHeight) * (position / (totalLength - lengthShown));
float scrollbarX = unitBaseX + unitWidth - ((right) ? scrollbarWidth : 0);
@@ -283,7 +261,7 @@ public class UI {
if (tooltipAlpha.getTime() == 0 || tooltip == null)
return;
int margin = displayContainer.width / 100, textMarginX = 2;
int margin = width / 100, textMarginX = 2;
int offset = GameImage.CURSOR_MIDDLE.getImage().getWidth() / 2;
int lineHeight = Fonts.SMALL.getLineHeight();
int textWidth = textMarginX * 2, textHeight = lineHeight;
@@ -303,12 +281,12 @@ public class UI {
// get drawing coordinates
int x = displayContainer.mouseX + offset;
int y = displayContainer.mouseY + offset;
if (x + textWidth > displayContainer.width - margin)
x = displayContainer.width - margin - textWidth;
if (x + textWidth > width - margin)
x = width - margin - textWidth;
else if (x < margin)
x = margin;
if (y + textHeight > displayContainer.height - margin)
y = displayContainer.height - margin - textHeight;
if (y + textHeight > height - margin)
y = height - margin - textHeight;
else if (y < margin)
y = margin;