opsu-dance/src/yugecin/opsudance/ui/OptionsOverlay.java

597 lines
17 KiB
Java
Raw Normal View History

2016-12-11 01:17:30 +01:00
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2016 yugecin
*
* opsu!dance is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opsu!dance is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.ui;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Options;
2016-12-11 01:17:30 +01:00
import itdelatrisu.opsu.Options.GameOption;
2016-12-11 02:08:35 +01:00
import itdelatrisu.opsu.Options.GameOption.OptionType;
2016-12-11 01:17:30 +01:00
import itdelatrisu.opsu.Utils;
2016-12-11 02:18:50 +01:00
import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect;
2016-12-11 01:17:30 +01:00
import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.MenuButton;
import itdelatrisu.opsu.ui.UI;
2016-12-11 02:08:35 +01:00
import org.newdawn.slick.*;
2017-01-19 16:03:53 +01:00
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.core.state.OverlayOpsuState;
2016-12-11 01:17:30 +01:00
2017-01-19 16:03:53 +01:00
public class OptionsOverlay extends OverlayOpsuState {
2016-12-11 01:17:30 +01:00
2017-01-19 16:03:53 +01:00
private final DisplayContainer displayContainer;
2016-12-11 02:08:35 +01:00
2017-01-19 19:23:31 +01:00
private Listener listener;
2017-01-19 16:03:53 +01:00
private Image sliderBallImg;
private Image checkOnImg;
private Image checkOffImg;
2016-12-11 01:17:30 +01:00
private OptionTab[] tabs;
private int selectedTab;
2016-12-11 16:41:56 +01:00
2016-12-11 01:17:30 +01:00
private GameOption hoverOption;
private GameOption selectedOption;
2016-12-11 16:41:56 +01:00
2016-12-11 10:08:22 +01:00
private int sliderOptionStartX;
private int sliderOptionLength;
private boolean isAdjustingSlider;
2016-12-11 16:41:56 +01:00
2016-12-11 02:08:35 +01:00
private boolean isListOptionOpen;
2016-12-11 16:41:56 +01:00
private int listItemHeight;
2016-12-11 11:07:28 +01:00
private int listStartX;
private int listStartY;
private int listWidth;
private int listHeight;
private int listHoverIndex;
2016-12-11 01:17:30 +01:00
private int width;
private int height;
private int optionWidth;
private int optionStartX;
private int optionStartY;
private int optionHeight;
private int scrollOffset;
private int maxScrollOffset;
2016-12-11 01:17:30 +01:00
private int mousePressY;
private boolean keyEntryLeft;
private boolean keyEntryRight;
2016-12-11 16:32:21 +01:00
private int prevMouseX;
private int prevMouseY;
private int sliderSoundDelay;
2017-01-19 19:23:31 +01:00
public OptionsOverlay(DisplayContainer displayContainer, OptionTab[] tabs, int defaultSelectedTabIndex) {
2017-01-19 16:03:53 +01:00
this.displayContainer = displayContainer;
2016-12-11 01:17:30 +01:00
this.tabs = tabs;
selectedTab = defaultSelectedTabIndex;
2016-12-12 18:46:57 +01:00
listHoverIndex = -1;
2017-01-19 16:03:53 +01:00
}
2017-01-19 19:23:31 +01:00
public void setListener(Listener listener) {
this.listener = listener;
}
2017-01-19 16:03:53 +01:00
@Override
public void revalidate() {
super.revalidate();
2016-12-12 18:46:57 +01:00
2016-12-11 02:08:35 +01:00
sliderBallImg = GameImage.CONTROL_SLIDER_BALL.getImage().getScaledCopy(20, 20);
checkOnImg = GameImage.CONTROL_CHECK_ON.getImage().getScaledCopy(20, 20);
checkOffImg = GameImage.CONTROL_CHECK_OFF.getImage().getScaledCopy(20, 20);
2017-01-19 16:03:53 +01:00
width = displayContainer.width;
height = displayContainer.height;
2016-12-11 01:17:30 +01:00
// calculate positions
optionWidth = width / 2;
optionHeight = (int) ((Fonts.MEDIUM.getLineHeight()) * 1.1f);
listItemHeight = (int) (optionHeight * 4f / 5f);
2016-12-11 01:17:30 +01:00
optionStartX = optionWidth / 2;
// initialize tabs
Image tabImage = GameImage.MENU_TAB.getImage();
float tabX = width * 0.032f + (tabImage.getWidth() / 3);
float tabY = Fonts.XLARGE.getLineHeight() + Fonts.DEFAULT.getLineHeight() + height * 0.015f - (tabImage.getHeight() / 2f);
int tabOffset = Math.min(tabImage.getWidth(), width / tabs.length);
maxScrollOffset = Fonts.MEDIUM.getLineHeight() * 2 * tabs.length;
2016-12-11 16:36:29 +01:00
scrollOffset = 0;
2016-12-11 12:47:33 +01:00
for (OptionTab tab : tabs) {
2017-01-19 16:03:53 +01:00
/*
2016-12-11 16:36:29 +01:00
if (defaultSelectedTabIndex-- > 0) {
scrollOffset += Fonts.MEDIUM.getLineHeight() * 2;
scrollOffset += tab.options.length * optionHeight;
}
2017-01-19 16:03:53 +01:00
*/
2016-12-11 12:47:33 +01:00
maxScrollOffset += tab.options.length * optionHeight;
tab.button = new MenuButton(tabImage, tabX, tabY);
2016-12-11 01:17:30 +01:00
tabX += tabOffset;
if (tabX + tabOffset > width) {
tabX = 0;
tabY += GameImage.MENU_TAB.getImage().getHeight() / 2f;
}
}
maxScrollOffset += -optionStartY - optionHeight;
2016-12-11 01:17:30 +01:00
// calculate other positions
optionStartY = (int) (tabY + tabImage.getHeight() / 2 + 2); // +2 for the separator line
}
2017-01-19 16:03:53 +01:00
@Override
public void onRender(Graphics g) {
2016-12-11 01:17:30 +01:00
// bg
g.setColor(Colors.BLACK_ALPHA_75);
g.fillRect(0, 0, width, height);
// title
renderTitle();
// option tabs
2017-01-19 16:03:53 +01:00
renderTabs();
2016-12-11 01:17:30 +01:00
// line separator
g.setColor(Color.white);
g.setLineWidth(2f);
g.drawLine(0, optionStartY - 1, width, optionStartY - 1);
g.resetLineWidth();
// options
renderOptions(g);
2016-12-11 11:07:28 +01:00
if (isListOptionOpen) {
renderOpenList(g);
}
// scrollbar
g.setColor(Color.white);
g.fillRoundRect(optionStartX + optionWidth + 15, optionStartY + ((float) scrollOffset / (maxScrollOffset)) * (height - optionStartY - 45), 10, 45, 2);
g.clearClip();
2016-12-11 01:17:30 +01:00
2016-12-11 02:33:50 +01:00
// UI
2016-12-11 01:17:30 +01:00
UI.getBackButton().draw();
2016-12-11 02:33:50 +01:00
// tooltip
2017-01-19 16:03:53 +01:00
renderTooltip(g);
2016-12-11 12:47:33 +01:00
// key input options
if (keyEntryLeft || keyEntryRight) {
renderKeyEntry(g);
}
}
private void renderKeyEntry(Graphics g) {
g.setColor(Colors.BLACK_ALPHA_75);
g.fillRect(0, 0, width, height);
g.setColor(Color.white);
String prompt = (keyEntryLeft) ? "Please press the new left-click key." : "Please press the new right-click key.";
Fonts.LARGE.drawString((width - Fonts.LARGE.getWidth(prompt)) / 2, (height - Fonts.LARGE.getLineHeight()) / 2, prompt);
2016-12-11 02:33:50 +01:00
}
2017-01-19 16:03:53 +01:00
private void renderTooltip(Graphics g) {
2016-12-11 02:33:50 +01:00
if (hoverOption != null) {
2017-01-19 16:03:53 +01:00
UI.updateTooltip(displayContainer.renderDelta, hoverOption.getDescription(), false);
UI.drawTooltip(g);
2016-12-11 02:33:50 +01:00
}
2016-12-11 01:17:30 +01:00
}
private void renderOptions(Graphics g) {
g.setClip(0, optionStartY, width, height - optionStartY);
2016-12-11 11:07:28 +01:00
listStartX = listStartY = listWidth = listHeight = 0; // render out of the screen
2016-12-11 01:17:30 +01:00
int y = -scrollOffset + optionStartY;
2016-12-11 02:14:43 +01:00
selectedTab = 0;
maxScrollOffset = Fonts.MEDIUM.getLineHeight() * 2 * tabs.length;
boolean render = true;
2016-12-11 01:17:30 +01:00
for (int tabIndex = 0; tabIndex < tabs.length; tabIndex++) {
OptionTab tab = tabs[tabIndex];
if (y > 0) {
if (render) {
int x = optionStartX + (optionWidth - Fonts.LARGE.getWidth(tab.name)) / 2;
Fonts.LARGE.drawString(x, y + Fonts.LARGE.getLineHeight() * 0.6f, tab.name, Color.cyan);
}
2016-12-11 02:14:43 +01:00
} else {
selectedTab++;
2016-12-11 01:17:30 +01:00
}
y += Fonts.MEDIUM.getLineHeight() * 2;
for (int optionIndex = 0; optionIndex < tab.options.length; optionIndex++) {
GameOption option = tab.options[optionIndex];
if (!option.showCondition()) {
continue;
}
maxScrollOffset += optionHeight;
2016-12-11 11:07:28 +01:00
if ((y > 0 && render) || (isListOptionOpen && hoverOption == option)) {
2016-12-11 01:17:30 +01:00
renderOption(g, option, y, option == hoverOption);
}
y += optionHeight;
if (y > height) {
render = false;
2016-12-11 01:17:30 +01:00
tabIndex = tabs.length;
}
}
}
maxScrollOffset -= optionStartY - optionHeight * 2;
2016-12-11 11:07:28 +01:00
}
2016-12-11 11:07:28 +01:00
private void renderOpenList(Graphics g) {
g.setColor(Colors.BLACK_ALPHA_85);
g.fillRect(listStartX, listStartY, listWidth, listHeight);
if (listHoverIndex != -1) {
g.setColor(Colors.ORANGE_BUTTON);
2016-12-11 16:41:56 +01:00
g.fillRect(listStartX, listStartY + listHoverIndex * listItemHeight, listWidth, listItemHeight);
2016-12-11 11:07:28 +01:00
}
g.setLineWidth(1f);
2016-12-11 02:08:35 +01:00
g.setColor(Color.white);
2016-12-11 11:07:28 +01:00
g.drawRect(listStartX, listStartY, listWidth, listHeight);
Object[] listItems = hoverOption.getListItems();
int y = listStartY;
for (Object item : listItems) {
2016-12-11 16:41:56 +01:00
Fonts.MEDIUM.drawString(listStartX + 20, y - Fonts.MEDIUM.getLineHeight() * 0.05f, item.toString());
y += listItemHeight;
2016-12-11 11:07:28 +01:00
}
2016-12-11 01:17:30 +01:00
}
private void renderOption(Graphics g, GameOption option, int y, boolean focus) {
Color col = focus ? Colors.GREEN : Colors.WHITE_FADE;
2016-12-11 02:08:35 +01:00
OptionType type = option.getType();
Object[] listItems = option.getListItems();
if (listItems != null) {
2016-12-11 11:07:28 +01:00
renderListOption(g, option, y, col, listItems);
2016-12-11 02:08:35 +01:00
} else if (type == OptionType.BOOLEAN) {
renderCheckOption(g, option, y, col);
} else if (type == OptionType.NUMERIC) {
renderSliderOption(g, option, y, col);
} else {
renderGenericOption(g, option, y, col);
}
}
2016-12-11 11:07:28 +01:00
private void renderListOption(Graphics g, GameOption option, int y, Color textColor, Object[] listItems) {
2016-12-11 10:40:21 +01:00
int nameLen = Fonts.MEDIUM.getWidth(option.getName());
2016-12-11 02:08:35 +01:00
Fonts.MEDIUM.drawString(optionStartX, y, option.getName(), textColor);
2016-12-11 10:40:21 +01:00
int padding = (int) (optionHeight / 10f);
nameLen += 20;
2016-12-11 11:07:28 +01:00
int itemStart = optionStartX + nameLen;
int itemWidth = optionWidth - nameLen;
Color backColor = Colors.BLACK_ALPHA;
if (hoverOption == option && listHoverIndex == -1) {
backColor = Colors.ORANGE_BUTTON;
}
g.setColor(backColor);
2016-12-11 16:41:56 +01:00
g.fillRect(itemStart, y + padding, itemWidth, listItemHeight);
2016-12-11 10:40:21 +01:00
g.setColor(Color.white);
g.setLineWidth(1f);
2016-12-11 16:41:56 +01:00
g.drawRect(itemStart, y + padding, itemWidth, listItemHeight);
2016-12-11 11:07:28 +01:00
Fonts.MEDIUM.drawString(itemStart + 20, y, option.getValueString(), Color.white);
if (isListOptionOpen && hoverOption == option) {
listStartX = optionStartX + nameLen;
2016-12-11 16:41:56 +01:00
listStartY = y + padding + listItemHeight;
2016-12-11 11:07:28 +01:00
listWidth = itemWidth;
2016-12-11 16:41:56 +01:00
listHeight = listItems.length * listItemHeight;
2016-12-11 11:07:28 +01:00
}
2016-12-11 02:08:35 +01:00
}
private void renderCheckOption(Graphics g, GameOption option, int y, Color textColor) {
if (option.getBooleanValue()) {
checkOnImg.draw(optionStartX, y + optionHeight / 2 - 10, Color.pink);
2016-12-11 02:08:35 +01:00
} else {
checkOffImg.draw(optionStartX, y + optionHeight / 2 - 10, Color.pink);
2016-12-11 02:08:35 +01:00
}
Fonts.MEDIUM.drawString(optionStartX + 30, y, option.getName(), textColor);
}
private void renderSliderOption(Graphics g, GameOption option, int y, Color textColor) {
String value = option.getValueString();
int nameLen = Fonts.MEDIUM.getWidth(option.getName());
int valueLen = Fonts.MEDIUM.getWidth(value);
Fonts.MEDIUM.drawString(optionStartX, y, option.getName(), textColor);
2016-12-11 10:23:32 +01:00
Fonts.MEDIUM.drawString(optionStartX + optionWidth - valueLen, y, value, Colors.BLUE_BACKGROUND);
2016-12-11 02:08:35 +01:00
int sliderLen = optionWidth - nameLen - valueLen - 50;
2016-12-11 10:08:22 +01:00
if (hoverOption == option) {
if (!isAdjustingSlider) {
sliderOptionLength = sliderLen;
sliderOptionStartX = optionStartX + nameLen + 25;
} else {
sliderLen = sliderOptionLength;
}
}
2016-12-11 02:08:35 +01:00
g.setColor(Color.pink);
g.setLineWidth(3f);
g.drawLine(optionStartX + nameLen + 25, y + optionHeight / 2, optionStartX + nameLen + 25 + sliderLen, y + optionHeight / 2);
float sliderValue = (float) (sliderLen + 10) * (option.getIntegerValue() - option.getMinValue()) / (option.getMaxValue() - option.getMinValue());
sliderBallImg.draw(optionStartX + nameLen + 25 + sliderValue - 10, y + optionHeight / 2 - 10, Color.pink);
}
private void renderGenericOption(Graphics g, GameOption option, int y, Color textColor) {
String value = option.getValueString();
int valueLen = Fonts.MEDIUM.getWidth(value);
Fonts.MEDIUM.drawString(optionStartX, y, option.getName(), textColor);
2016-12-11 10:23:32 +01:00
Fonts.MEDIUM.drawString(optionStartX + optionWidth - valueLen, y, value, Colors.BLUE_BACKGROUND);
2016-12-11 01:17:30 +01:00
}
2017-01-19 16:03:53 +01:00
public void renderTabs() {
2016-12-11 01:17:30 +01:00
for (int i = 0; i < tabs.length; i++) {
OptionTab tab = tabs[i];
2017-01-19 16:03:53 +01:00
boolean hovering = tab.button.contains(displayContainer.mouseX, displayContainer.mouseY);
2016-12-11 01:17:30 +01:00
UI.drawTab(tab.button.getX(), tab.button.getY(), tab.name, i == selectedTab, hovering);
}
}
private void renderTitle() {
float marginX = width * 0.015f;
float marginY = height * 0.01f;
Fonts.XLARGE.drawString(marginX, marginY, "Options", Color.white);
marginX += Fonts.XLARGE.getWidth("Options") * 1.2f;
marginY += Fonts.XLARGE.getLineHeight() * 0.9f - Fonts.DEFAULT.getLineHeight();
Fonts.DEFAULT.drawString(marginX, marginY, "Change the way opsu! behaves", Color.white);
}
2017-01-19 16:03:53 +01:00
@Override
public void hide() {
acceptInput = false;
SoundController.playSound(SoundEffect.MENUBACK);
active = false;
}
@Override
public void show() {
acceptInput = true;
active = true;
}
@Override
public void onPreRenderUpdate() {
int mouseX = displayContainer.mouseX;
int mouseY = displayContainer.mouseY;
int delta = displayContainer.renderDelta;
if (sliderSoundDelay > 0) {
sliderSoundDelay -= delta;
}
2016-12-11 16:32:21 +01:00
if (mouseX - prevMouseX == 0 && mouseY - prevMouseY == 0) {
return;
}
prevMouseX = mouseX;
prevMouseY = mouseY;
2016-12-11 01:17:30 +01:00
updateHoverOption(mouseX, mouseY);
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
2016-12-11 10:08:22 +01:00
if (isAdjustingSlider) {
int sliderValue = hoverOption.getIntegerValue();
2017-01-19 16:03:53 +01:00
updateSliderOption();
if (hoverOption.getIntegerValue() - sliderValue != 0 && sliderSoundDelay <= 0) {
sliderSoundDelay = 90;
SoundController.playSound(SoundEffect.MENUHIT);
}
2016-12-11 11:07:28 +01:00
} else if (isListOptionOpen) {
if (listStartX <= mouseX && mouseX < listStartX + listWidth && listStartY <= mouseY && mouseY < listStartY + listHeight) {
2016-12-11 16:41:56 +01:00
listHoverIndex = (mouseY - listStartY) / listItemHeight;
2016-12-11 11:07:28 +01:00
} else {
listHoverIndex = -1;
}
2016-12-11 10:08:22 +01:00
}
2016-12-11 01:17:30 +01:00
}
2017-01-19 16:03:53 +01:00
@Override
public boolean onMousePressed(int button, int x, int y) {
if (keyEntryLeft || keyEntryRight) {
keyEntryLeft = keyEntryRight = false;
2017-01-19 16:03:53 +01:00
return true;
}
2016-12-11 11:07:28 +01:00
if (isListOptionOpen) {
if (y > optionStartY && listStartX <= x && x < listStartX + listWidth && listStartY <= y && y < listStartY + listHeight) {
hoverOption.clickListItem(listHoverIndex);
2017-01-19 19:23:31 +01:00
if (listener != null) {
listener.onSaveOption(hoverOption);
}
SoundController.playSound(SoundEffect.MENUCLICK);
2016-12-11 11:07:28 +01:00
}
isListOptionOpen = false;
listHoverIndex = -1;
updateHoverOption(x, y);
2017-01-19 16:03:53 +01:00
return true;
2016-12-11 11:07:28 +01:00
}
mousePressY = y;
2016-12-12 18:49:26 +01:00
selectedOption = hoverOption;
2016-12-11 01:17:30 +01:00
2016-12-12 18:46:32 +01:00
if (hoverOption != null) {
if (hoverOption.getListItems() != null) {
2016-12-11 11:07:28 +01:00
isListOptionOpen = true;
2016-12-12 18:46:32 +01:00
} else if (hoverOption.getType() == OptionType.NUMERIC) {
2016-12-11 11:07:28 +01:00
isAdjustingSlider = sliderOptionStartX <= x && x < sliderOptionStartX + sliderOptionLength;
2016-12-11 16:32:21 +01:00
if (isAdjustingSlider) {
2017-01-19 16:03:53 +01:00
updateSliderOption();
2016-12-11 16:32:21 +01:00
}
2016-12-11 11:07:28 +01:00
}
2016-12-11 10:08:22 +01:00
}
2016-12-11 01:17:30 +01:00
if (UI.getBackButton().contains(x, y)) {
2017-01-19 16:03:53 +01:00
hide();
2016-12-11 01:17:30 +01:00
}
2017-01-19 16:03:53 +01:00
return true;
}
2017-01-19 16:03:53 +01:00
@Override
public boolean onMouseReleased(int button, int x, int y) {
selectedOption = null;
2017-01-19 19:23:31 +01:00
if (isAdjustingSlider && listener != null) {
listener.onSaveOption(hoverOption);
2016-12-11 16:32:21 +01:00
}
2016-12-11 10:08:22 +01:00
isAdjustingSlider = false;
sliderOptionLength = 0;
// check if clicked, not dragged
if (Math.abs(y - mousePressY) >= 5) {
2017-01-19 16:03:53 +01:00
return true;
}
2016-12-11 02:08:35 +01:00
if (hoverOption != null) {
if (hoverOption.getType() == OptionType.BOOLEAN) {
2017-01-19 16:03:53 +01:00
hoverOption.click();
2017-01-19 19:23:31 +01:00
if (listener != null) {
listener.onSaveOption(hoverOption);
}
SoundController.playSound(SoundEffect.MENUHIT);
2017-01-19 16:03:53 +01:00
return true;
} else if (hoverOption == GameOption.KEY_LEFT) {
keyEntryLeft = true;
} else if (hoverOption == GameOption.KEY_RIGHT) {
keyEntryLeft = true;
}
}
2016-12-11 02:14:43 +01:00
2016-12-11 16:33:32 +01:00
// check if tab was clicked
2016-12-11 02:14:43 +01:00
int tScrollOffset = 0;
2016-12-11 16:33:32 +01:00
for (OptionTab tab : tabs) {
if (tab.button.contains(x, y)) {
scrollOffset = tScrollOffset;
SoundController.playSound(SoundEffect.MENUCLICK);
2017-01-19 16:03:53 +01:00
return true;
2016-12-11 02:14:43 +01:00
}
tScrollOffset += Fonts.MEDIUM.getLineHeight() * 2;
2016-12-11 16:33:32 +01:00
tScrollOffset += tab.options.length * optionHeight;
2016-12-11 02:14:43 +01:00
}
2017-01-19 19:23:31 +01:00
if (UI.getBackButton().contains(x, y) && listener != null) {
listener.onLeaveOptionsMenu();
}
2017-01-19 16:03:53 +01:00
return true;
2016-12-11 01:17:30 +01:00
}
2017-01-19 16:03:53 +01:00
@Override
public boolean onMouseDragged(int oldx, int oldy, int newx, int newy) {
2016-12-11 10:08:22 +01:00
if (!isAdjustingSlider) {
scrollOffset = Utils.clamp(scrollOffset + oldy - newy, 0, maxScrollOffset);
}
2017-01-19 16:03:53 +01:00
return true;
2016-12-11 01:17:30 +01:00
}
2017-01-19 16:03:53 +01:00
@Override
public boolean onMouseWheelMoved(int delta) {
2016-12-11 10:08:22 +01:00
if (!isAdjustingSlider) {
scrollOffset = Utils.clamp(scrollOffset - delta, 0, maxScrollOffset);
2016-12-11 10:08:22 +01:00
}
updateHoverOption(prevMouseX, prevMouseY);
2017-01-19 16:03:53 +01:00
return true;
2016-12-11 01:17:30 +01:00
}
2017-01-19 16:03:53 +01:00
@Override
public boolean onKeyPressed(int key, char c) {
if (keyEntryRight) {
Options.setGameKeyRight(key);
keyEntryRight = false;
return true;
}
if (keyEntryLeft) {
Options.setGameKeyLeft(key);
keyEntryLeft = false;
return true;
}
2017-01-19 19:23:31 +01:00
if (key == Input.KEY_ESCAPE) {
if (isListOptionOpen) {
isListOptionOpen = false;
listHoverIndex = -1;
return true;
2017-01-19 19:23:31 +01:00
}
hide();
if (listener != null) {
listener.onLeaveOptionsMenu();
}
return true;
2016-12-11 01:17:30 +01:00
}
2017-01-19 19:23:31 +01:00
return false;
2016-12-11 01:17:30 +01:00
}
2017-01-19 16:03:53 +01:00
@Override
public boolean onKeyReleased(int key, char c) {
return false;
}
private void updateSliderOption() {
2016-12-12 18:46:32 +01:00
int min = hoverOption.getMinValue();
int max = hoverOption.getMaxValue();
2017-01-19 16:03:53 +01:00
int value = min + Math.round((float) (max - min) * (displayContainer.mouseX - sliderOptionStartX) / (sliderOptionLength));
2016-12-12 18:46:32 +01:00
hoverOption.setValue(Utils.clamp(value, min, max));
2016-12-11 16:32:21 +01:00
}
2016-12-11 01:17:30 +01:00
private void updateHoverOption(int mouseX, int mouseY) {
if (isListOptionOpen || keyEntryLeft || keyEntryRight) {
2016-12-11 11:07:28 +01:00
return;
}
2016-12-11 02:23:02 +01:00
if (selectedOption != null) {
hoverOption = selectedOption;
return;
}
2016-12-11 01:17:30 +01:00
hoverOption = null;
if (mouseY < optionStartY || mouseX < optionStartX || mouseX > optionStartX + optionWidth) {
return;
}
int mouseVirtualY = scrollOffset + mouseY - optionStartY;
for (OptionTab tab : tabs) {
mouseVirtualY -= Fonts.MEDIUM.getLineHeight() * 2;
for (int optionIndex = 0; optionIndex < tab.options.length; optionIndex++) {
GameOption option = tab.options[optionIndex];
if (!option.showCondition()) {
continue;
}
if (mouseVirtualY <= optionHeight) {
if (mouseVirtualY >= 0) {
hoverOption = option;
}
return;
}
mouseVirtualY -= optionHeight;
}
}
}
public static class OptionTab {
public final String name;
public final GameOption[] options;
private MenuButton button;
public OptionTab(String name, GameOption[] options) {
this.name = name;
this.options = options;
}
}
2017-01-19 19:23:31 +01:00
public interface Listener {
2016-12-11 01:17:30 +01:00
2017-01-19 19:23:31 +01:00
void onLeaveOptionsMenu();
2016-12-11 01:17:30 +01:00
void onSaveOption(GameOption option);
}
}