make comboboxes work
This commit is contained in:
parent
30b07f75d8
commit
3c8b769248
|
@ -27,6 +27,7 @@ public class Colors {
|
||||||
public static final Color
|
public static final Color
|
||||||
BLACK_ALPHA = new Color(0, 0, 0, 0.5f),
|
BLACK_ALPHA = new Color(0, 0, 0, 0.5f),
|
||||||
BLACK_ALPHA_75 = new Color(0, 0, 0, 0.75f),
|
BLACK_ALPHA_75 = new Color(0, 0, 0, 0.75f),
|
||||||
|
BLACK_ALPHA_85 = new Color(0, 0, 0, 0.85f),
|
||||||
WHITE_ALPHA = new Color(255, 255, 255, 0.5f),
|
WHITE_ALPHA = new Color(255, 255, 255, 0.5f),
|
||||||
BLUE_DIVIDER = new Color(49, 94, 237),
|
BLUE_DIVIDER = new Color(49, 94, 237),
|
||||||
BLUE_BACKGROUND = new Color(74, 130, 255),
|
BLUE_BACKGROUND = new Color(74, 130, 255),
|
||||||
|
|
|
@ -48,6 +48,11 @@ public class OptionsOverlay {
|
||||||
private int sliderOptionLength;
|
private int sliderOptionLength;
|
||||||
private boolean isAdjustingSlider;
|
private boolean isAdjustingSlider;
|
||||||
private boolean isListOptionOpen;
|
private boolean isListOptionOpen;
|
||||||
|
private int listStartX;
|
||||||
|
private int listStartY;
|
||||||
|
private int listWidth;
|
||||||
|
private int listHeight;
|
||||||
|
private int listHoverIndex;
|
||||||
|
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
|
@ -122,6 +127,14 @@ public class OptionsOverlay {
|
||||||
|
|
||||||
// options
|
// options
|
||||||
renderOptions(g);
|
renderOptions(g);
|
||||||
|
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();
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
UI.getBackButton().draw();
|
UI.getBackButton().draw();
|
||||||
|
@ -145,6 +158,7 @@ public class OptionsOverlay {
|
||||||
|
|
||||||
private void renderOptions(Graphics g) {
|
private void renderOptions(Graphics g) {
|
||||||
g.setClip(0, optionStartY, width, height - optionStartY);
|
g.setClip(0, optionStartY, width, height - optionStartY);
|
||||||
|
listStartX = listStartY = listWidth = listHeight = 0; // render out of the screen
|
||||||
int y = -scrollOffset + optionStartY;
|
int y = -scrollOffset + optionStartY;
|
||||||
selectedTab = 0;
|
selectedTab = 0;
|
||||||
maxScrollOffset = Fonts.MEDIUM.getLineHeight() * 2 * tabs.length;
|
maxScrollOffset = Fonts.MEDIUM.getLineHeight() * 2 * tabs.length;
|
||||||
|
@ -166,7 +180,7 @@ public class OptionsOverlay {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
maxScrollOffset += optionHeight;
|
maxScrollOffset += optionHeight;
|
||||||
if (y > 0 && render) {
|
if ((y > 0 && render) || (isListOptionOpen && hoverOption == option)) {
|
||||||
renderOption(g, option, y, option == hoverOption);
|
renderOption(g, option, y, option == hoverOption);
|
||||||
}
|
}
|
||||||
y += optionHeight;
|
y += optionHeight;
|
||||||
|
@ -177,11 +191,25 @@ public class OptionsOverlay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maxScrollOffset -= optionStartY - optionHeight * 2;
|
maxScrollOffset -= optionStartY - optionHeight * 2;
|
||||||
|
}
|
||||||
|
|
||||||
// scrollbar
|
private void renderOpenList(Graphics g) {
|
||||||
|
// list
|
||||||
|
g.setColor(Colors.BLACK_ALPHA_85);
|
||||||
|
g.fillRect(listStartX, listStartY, listWidth, listHeight);
|
||||||
|
if (listHoverIndex != -1) {
|
||||||
|
g.setColor(Colors.ORANGE_BUTTON);
|
||||||
|
g.fillRect(listStartX, listStartY + listHoverIndex * optionHeight, listWidth, optionHeight);
|
||||||
|
}
|
||||||
|
g.setLineWidth(1f);
|
||||||
g.setColor(Color.white);
|
g.setColor(Color.white);
|
||||||
g.fillRoundRect(optionStartX + optionWidth + 15, optionStartY + ((float) scrollOffset / (maxScrollOffset)) * (height - optionStartY - 45), 10, 45, 2);
|
g.drawRect(listStartX, listStartY, listWidth, listHeight);
|
||||||
g.clearClip();
|
Object[] listItems = hoverOption.getListItems();
|
||||||
|
int y = listStartY;
|
||||||
|
for (Object item : listItems) {
|
||||||
|
Fonts.MEDIUM.drawString(listStartX + 20, y, item.toString());
|
||||||
|
y += optionHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderOption(Graphics g, GameOption option, int y, boolean focus) {
|
private void renderOption(Graphics g, GameOption option, int y, boolean focus) {
|
||||||
|
@ -189,7 +217,7 @@ public class OptionsOverlay {
|
||||||
OptionType type = option.getType();
|
OptionType type = option.getType();
|
||||||
Object[] listItems = option.getListItems();
|
Object[] listItems = option.getListItems();
|
||||||
if (listItems != null) {
|
if (listItems != null) {
|
||||||
renderListOption(g, option, y, col);
|
renderListOption(g, option, y, col, listItems);
|
||||||
} else if (type == OptionType.BOOLEAN) {
|
} else if (type == OptionType.BOOLEAN) {
|
||||||
renderCheckOption(g, option, y, col);
|
renderCheckOption(g, option, y, col);
|
||||||
} else if (type == OptionType.NUMERIC) {
|
} else if (type == OptionType.NUMERIC) {
|
||||||
|
@ -199,18 +227,30 @@ public class OptionsOverlay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderListOption(Graphics g, GameOption option, int y, Color textColor) {
|
private void renderListOption(Graphics g, GameOption option, int y, Color textColor, Object[] listItems) {
|
||||||
int nameLen = Fonts.MEDIUM.getWidth(option.getName());
|
int nameLen = Fonts.MEDIUM.getWidth(option.getName());
|
||||||
Fonts.MEDIUM.drawString(optionStartX, y, option.getName(), textColor);
|
Fonts.MEDIUM.drawString(optionStartX, y, option.getName(), textColor);
|
||||||
int size = (int) (optionHeight * 4f / 5f);
|
int size = (int) (optionHeight * 4f / 5f);
|
||||||
int padding = (int) (optionHeight / 10f);
|
int padding = (int) (optionHeight / 10f);
|
||||||
nameLen += 20;
|
nameLen += 20;
|
||||||
g.setColor(hoverOption == option ? Colors.ORANGE_BUTTON : Colors.BLACK_ALPHA);
|
int itemStart = optionStartX + nameLen;
|
||||||
g.fillRect(optionStartX + nameLen, y + padding, optionWidth - nameLen, size);
|
int itemWidth = optionWidth - nameLen;
|
||||||
|
Color backColor = Colors.BLACK_ALPHA;
|
||||||
|
if (hoverOption == option && listHoverIndex == -1) {
|
||||||
|
backColor = Colors.ORANGE_BUTTON;
|
||||||
|
}
|
||||||
|
g.setColor(backColor);
|
||||||
|
g.fillRect(itemStart, y + padding, itemWidth, size);
|
||||||
g.setColor(Color.white);
|
g.setColor(Color.white);
|
||||||
g.setLineWidth(1f);
|
g.setLineWidth(1f);
|
||||||
g.drawRect(optionStartX + nameLen, y + padding, optionWidth - nameLen, size);
|
g.drawRect(itemStart, y + padding, itemWidth, size);
|
||||||
Fonts.MEDIUM.drawString(optionStartX + nameLen + 20, y, option.getValueString(), Color.white);
|
Fonts.MEDIUM.drawString(itemStart + 20, y, option.getValueString(), Color.white);
|
||||||
|
if (isListOptionOpen && hoverOption == option) {
|
||||||
|
listStartX = optionStartX + nameLen;
|
||||||
|
listStartY = y + padding + size;
|
||||||
|
listWidth = itemWidth;
|
||||||
|
listHeight = listItems.length * optionHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderCheckOption(Graphics g, GameOption option, int y, Color textColor) {
|
private void renderCheckOption(Graphics g, GameOption option, int y, Color textColor) {
|
||||||
|
@ -279,16 +319,35 @@ public class OptionsOverlay {
|
||||||
int value = min + (int) ((float) (max - min) * (mouseX - sliderOptionStartX) / (sliderOptionLength));
|
int value = min + (int) ((float) (max - min) * (mouseX - sliderOptionStartX) / (sliderOptionLength));
|
||||||
selectedOption.setValue(Utils.clamp(value, min, max));
|
selectedOption.setValue(Utils.clamp(value, min, max));
|
||||||
selectedOption.drag(container, 0);
|
selectedOption.drag(container, 0);
|
||||||
|
} else if (isListOptionOpen) {
|
||||||
|
if (listStartX <= mouseX && mouseX < listStartX + listWidth && listStartY <= mouseY && mouseY < listStartY + listHeight) {
|
||||||
|
listHoverIndex = (mouseY - listStartY) / optionHeight;
|
||||||
|
} else {
|
||||||
|
listHoverIndex = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mousePressed(int button, int x, int y) {
|
public void mousePressed(int button, int x, int y) {
|
||||||
|
if (isListOptionOpen) {
|
||||||
|
if (y > optionStartY && listStartX <= x && x < listStartX + listWidth && listStartY <= y && y < listStartY + listHeight) {
|
||||||
|
hoverOption.clickListItem(listHoverIndex);
|
||||||
|
}
|
||||||
|
isListOptionOpen = false;
|
||||||
|
listHoverIndex = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mousePressY = y;
|
mousePressY = y;
|
||||||
selectedOption = hoverOption;
|
selectedOption = hoverOption;
|
||||||
|
|
||||||
if (selectedOption != null && selectedOption.getType() == OptionType.NUMERIC) {
|
if (selectedOption != null) {
|
||||||
|
if (selectedOption.getListItems() != null) {
|
||||||
|
isListOptionOpen = true;
|
||||||
|
} else if (selectedOption.getType() == OptionType.NUMERIC) {
|
||||||
isAdjustingSlider = sliderOptionStartX <= x && x < sliderOptionStartX + sliderOptionLength;
|
isAdjustingSlider = sliderOptionStartX <= x && x < sliderOptionStartX + sliderOptionLength;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (UI.getBackButton().contains(x, y)) {
|
if (UI.getBackButton().contains(x, y)) {
|
||||||
parent.onLeave();
|
parent.onLeave();
|
||||||
|
@ -348,6 +407,9 @@ public class OptionsOverlay {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateHoverOption(int mouseX, int mouseY) {
|
private void updateHoverOption(int mouseX, int mouseY) {
|
||||||
|
if (isListOptionOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (selectedOption != null) {
|
if (selectedOption != null) {
|
||||||
hoverOption = selectedOption;
|
hoverOption = selectedOption;
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user