fix maximum scroll offset not being changed when options are not shown

This commit is contained in:
yugecin 2016-12-11 10:20:22 +01:00
parent 03a2e646ad
commit 81449fb8d5

View File

@ -58,7 +58,7 @@ public class OptionsOverlay {
private int optionHeight; private int optionHeight;
private int scrollOffset; private int scrollOffset;
private final int maxScrollOffset; private int maxScrollOffset;
private int mousePressY; private int mousePressY;
@ -86,7 +86,7 @@ public class OptionsOverlay {
float tabX = width * 0.032f + (tabImage.getWidth() / 3); float tabX = width * 0.032f + (tabImage.getWidth() / 3);
float tabY = Fonts.XLARGE.getLineHeight() + Fonts.DEFAULT.getLineHeight() + height * 0.015f - (tabImage.getHeight() / 2f); float tabY = Fonts.XLARGE.getLineHeight() + Fonts.DEFAULT.getLineHeight() + height * 0.015f - (tabImage.getHeight() / 2f);
int tabOffset = Math.min(tabImage.getWidth(), width / tabs.length); int tabOffset = Math.min(tabImage.getWidth(), width / tabs.length);
int maxScrollOffset = Fonts.MEDIUM.getLineHeight() * 2 * tabs.length; maxScrollOffset = Fonts.MEDIUM.getLineHeight() * 2 * tabs.length;
for (int i = 0; i < tabs.length; i++) { for (int i = 0; i < tabs.length; i++) {
maxScrollOffset += tabs[i].options.length * optionHeight; maxScrollOffset += tabs[i].options.length * optionHeight;
tabs[i].tabIndex = i; tabs[i].tabIndex = i;
@ -97,7 +97,7 @@ public class OptionsOverlay {
tabY += GameImage.MENU_TAB.getImage().getHeight() / 2f; tabY += GameImage.MENU_TAB.getImage().getHeight() / 2f;
} }
} }
this.maxScrollOffset = maxScrollOffset - optionStartY - optionHeight; maxScrollOffset += -optionStartY - optionHeight;
// calculate other positions // calculate other positions
optionStartY = (int) (tabY + tabImage.getHeight() / 2 + 2); // +2 for the separator line optionStartY = (int) (tabY + tabImage.getHeight() / 2 + 2); // +2 for the separator line
@ -147,11 +147,15 @@ public class OptionsOverlay {
g.setClip(0, optionStartY, width, height - optionStartY); g.setClip(0, optionStartY, width, height - optionStartY);
int y = -scrollOffset + optionStartY; int y = -scrollOffset + optionStartY;
selectedTab = 0; selectedTab = 0;
maxScrollOffset = Fonts.MEDIUM.getLineHeight() * 2 * tabs.length;
boolean render = true;
for (int tabIndex = 0; tabIndex < tabs.length; tabIndex++) { for (int tabIndex = 0; tabIndex < tabs.length; tabIndex++) {
OptionTab tab = tabs[tabIndex]; OptionTab tab = tabs[tabIndex];
if (y > 0) { if (y > 0) {
if (render) {
int x = optionStartX + (optionWidth - Fonts.LARGE.getWidth(tab.name)) / 2; int x = optionStartX + (optionWidth - Fonts.LARGE.getWidth(tab.name)) / 2;
Fonts.LARGE.drawString(x, y + Fonts.LARGE.getLineHeight() * 0.6f, tab.name, Color.cyan); Fonts.LARGE.drawString(x, y + Fonts.LARGE.getLineHeight() * 0.6f, tab.name, Color.cyan);
}
} else { } else {
selectedTab++; selectedTab++;
} }
@ -161,16 +165,19 @@ public class OptionsOverlay {
if (!option.showCondition()) { if (!option.showCondition()) {
continue; continue;
} }
if (y > 0) { maxScrollOffset += optionHeight;
if (y > 0 && render) {
renderOption(g, option, y, option == hoverOption); renderOption(g, option, y, option == hoverOption);
} }
y += optionHeight; y += optionHeight;
if (y > height) { if (y > height) {
render = false;
tabIndex = tabs.length; tabIndex = tabs.length;
break;
} }
} }
} }
maxScrollOffset -= optionStartY - optionHeight * 2;
// scrollbar // scrollbar
g.setColor(Color.white); g.setColor(Color.white);
g.fillRoundRect(optionStartX + optionWidth + 15, optionStartY + ((float) scrollOffset / (maxScrollOffset)) * (height - optionStartY - 45), 10, 45, 2); g.fillRoundRect(optionStartX + optionWidth + 15, optionStartY + ((float) scrollOffset / (maxScrollOffset)) * (height - optionStartY - 45), 10, 45, 2);
@ -319,7 +326,7 @@ public class OptionsOverlay {
public void mouseWheelMoved(int delta) { public void mouseWheelMoved(int delta) {
if (!isAdjustingSlider) { if (!isAdjustingSlider) {
scrollOffset = Utils.clamp(scrollOffset - delta, 0, maxScrollOffset - optionStartY); scrollOffset = Utils.clamp(scrollOffset - delta, 0, maxScrollOffset);
} }
} }