diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/ConfigFieldContainer.java b/src/configlib/java/fr/alexdoru/configlib/lib/ConfigFieldContainer.java index 2ce2a246..ce1a15bf 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/ConfigFieldContainer.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/ConfigFieldContainer.java @@ -158,9 +158,9 @@ private void loadConfigValueToField() throws IllegalAccessException { break; } case ENUM_COLOR: { - EnumChatFormatting value = (EnumChatFormatting) this.getEnumValue(this.getProp().getString()); + EnumChatFormatting value = this.getEnumValue(this.getProp().getString()); if (value == null || !value.isColor()) { - value = (EnumChatFormatting) this.getEnumValue(this.getProp().getDefault()); + value = this.getEnumValue(this.getProp().getDefault()); } field.set(null, value); break; @@ -280,7 +280,8 @@ public ConfigUIElement getConfigButton(ConfigGuiScreen configGuiScreen, Renderer } } case ENUM_COLOR: { - return new ColorEnumGuiButton(configGuiScreen, field, event, annotation); + final EnumChatFormatting defaultColor = getEnumValue(this.getProp().getDefault()); + return new ColorEnumGuiButton(configGuiScreen, field, event, annotation, defaultColor); } case ENUM: { return new EnumGuiButton(field, event, annotation); @@ -294,13 +295,13 @@ public ConfigProperty getAnnotation() { } @Nullable - private Enum getEnumValue(@NotNull String valueName) { + private > T getEnumValue(@NotNull String valueName) { if (!Enum.class.isAssignableFrom(field.getType())) { throw new IllegalArgumentException(); } try { - //noinspection rawtypes,unchecked - return Enum.valueOf((Class) field.getType(), valueName); + //noinspection unchecked + return Enum.valueOf((Class) field.getType(), valueName); } catch (IllegalArgumentException ignored) {} return null; } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/ConfigGuiScreen.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/ConfigGuiScreen.java index bdbef5d5..40808df1 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/ConfigGuiScreen.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/ConfigGuiScreen.java @@ -24,8 +24,7 @@ public class ConfigGuiScreen extends GuiScreen { - public static final int PADDING = 6; - public static final int ELEMENT_GAP = 4; + private static final int PADDING = 6; private static final ResourceLocation BLUR = new ResourceLocation("configlib", "blur.json"); @@ -40,7 +39,7 @@ public class ConfigGuiScreen extends GuiScreen { private GuiTextField searchField; private String selectedCategory = ""; private SliderGuiButton lastInteractedSlider; - private OverlayConfigGuiButton lastInteractedOverlay; + private OverlayConfigGuiButton currentlyOpenOverlay; private final Scrollbar configScrollbar = new Scrollbar(); private final Scrollbar categoryScrollbar = new Scrollbar(); @@ -130,8 +129,8 @@ public void initGui() { CATEGORY_BOX.LEFT = GUI_INSIDE.LEFT; CATEGORY_BOX.TOP = GUI_INSIDE.TOP + fontRendererObj.FONT_HEIGHT + 1 + PADDING; CATEGORY_BOX.RIGHT = GUI_INSIDE.LEFT + GUI_WIDTH / 5; - final int categoryContentHeight = getCategoryContentHeight(); - final int categoryMaxY = CATEGORY_BOX.TOP + categoryContentHeight + 2 * PADDING; + final int categoryContentHeight = getContentHeight(this.categoryElements); + final int categoryMaxY = CATEGORY_BOX.TOP + categoryContentHeight; CATEGORY_BOX.BOTTOM = Math.min(categoryMaxY, GUI_INSIDE.BOTTOM); CONFIG_BOX.LEFT = CATEGORY_BOX.RIGHT + PADDING; @@ -166,10 +165,10 @@ public void initGui() { SEARCH_BOX.BOTTOM = GUI_INSIDE.TOP + mc.fontRendererObj.FONT_HEIGHT; this.categoryScrollbar.init(lastCategoryScroll, categoryContentHeight, CATEGORY_BOX.getHeight()); - this.configScrollbar.init(lastConfigScroll, this.getConfigContentHeight(), CONFIG_BOX.getHeight()); + this.configScrollbar.init(lastConfigScroll, getContentHeight(this.renderedConfigElements), CONFIG_BOX.getHeight()); this.lastInteractedSlider = null; - this.lastInteractedOverlay = null; + closeOpenOverlay(); this.mc.entityRenderer.loadShader(BLUR); super.initGui(); @@ -178,8 +177,8 @@ public void initGui() { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { - final int categoryContentHeight = this.getCategoryContentHeight(); - final int configContentHeight = this.getConfigContentHeight(); + final int categoryContentHeight = getContentHeight(this.categoryElements); + final int configContentHeight = getContentHeight(this.renderedConfigElements); this.categoryScrollbar.updateScrollPos(categoryContentHeight, CATEGORY_BOX.getHeight()); this.configScrollbar.updateScrollPos(configContentHeight, CONFIG_BOX.getHeight()); @@ -221,9 +220,18 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { CONFIG_BOX.applyScissors(mc, res, 1); + final boolean canMouseBeVisuallyOverElements = CONFIG_BOX.isMouseInBox(mouseX, mouseY) && (currentlyOpenOverlay == null || !currentlyOpenOverlay.isMouseOverOverlay(mouseX, mouseY)); + + final List hoveringTextLines = new ArrayList<>(); final int configDrawX = CONFIG_BOX.LEFT + PADDING; forEachVisible(this.renderedConfigElements, CONFIG_BOX, this.configScrollbar.getScroll(), (element, drawY) -> { - element.draw(colorPalette, configDrawX, drawY, mouseX, mouseY); + element.draw(colorPalette, configDrawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElements); + if (canMouseBeVisuallyOverElements && hoveringTextLines.isEmpty()) { + final List hoveringTextLinesIn = element.getHoveringTextLines(); + if (hoveringTextLinesIn != null && !hoveringTextLinesIn.isEmpty()) { + hoveringTextLines.addAll(hoveringTextLinesIn); + } + } return false; }); @@ -232,63 +240,94 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { GL11.glDisable(GL11.GL_SCISSOR_TEST); super.drawScreen(mouseX, mouseY, partialTicks); + + if (currentlyOpenOverlay != null) { + currentlyOpenOverlay.drawOverlay(colorPalette, mouseX, mouseY); + if (hoveringTextLines.isEmpty()) { + final List hoveringTextLinesIn = currentlyOpenOverlay.getOverlayHoveringTextLines(); + if (hoveringTextLinesIn != null && !hoveringTextLinesIn.isEmpty()) { + hoveringTextLines.addAll(hoveringTextLinesIn); + } + } + } + + if (!hoveringTextLines.isEmpty()) { + drawHoveringText(hoveringTextLines, mouseX, mouseY); + } } @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { final MouseButton button = MouseButton.from(mouseButton); - if (lastInteractedOverlay != null) { + OverlayConfigGuiButton overlayToClose = null; + if (currentlyOpenOverlay != null) { try { - lastInteractedOverlay.mouseClicked(mouseX, mouseY, button); + if (currentlyOpenOverlay.mouseClickedOnOverlay(mouseX, mouseY, button)) { + if (!currentlyOpenOverlay.isOverlayOpen()) this.currentlyOpenOverlay = null; + return; + } } catch (IllegalAccessException e) { throw new RuntimeException("Caught exception running mouse click events!", e); } - if (!lastInteractedOverlay.isOverlayOpen()) { - lastInteractedOverlay = null; + if (currentlyOpenOverlay.isOverlayOpen()) { + overlayToClose = currentlyOpenOverlay; } - return; + this.currentlyOpenOverlay = null; } - if (CATEGORY_BOX.isMouseInBox(mouseX, mouseY)) { - final boolean consumedClick = forEachVisible(this.categoryElements, CATEGORY_BOX, this.categoryScrollbar.getScroll(), (element, drawY) -> - element.mouseClicked(mouseX, mouseY, button) - ); - if (consumedClick) return; - if (this.categoryScrollbar.mouseClicked(mouseX, mouseY, button)) { - return; - } - } else if (CONFIG_BOX.isMouseInBox(mouseX, mouseY)) { - final boolean consumedClick = forEachVisible(this.renderedConfigElements, CONFIG_BOX, this.configScrollbar.getScroll(), (element, drawY) -> { - try { - if (element.mouseClicked(mouseX, mouseY, button)) { - if (element instanceof SliderGuiButton) { - lastInteractedSlider = ((SliderGuiButton) element); - } else if (element instanceof OverlayConfigGuiButton) { - final OverlayConfigGuiButton overlay = (OverlayConfigGuiButton) element; - if (overlay.isOverlayOpen()) { - lastInteractedOverlay = overlay; + // keep this label, it will come in handy in the feature if you need to have more "cleanup code" + // for example, if in the feature you choose to use my "Searchbar" + click_scan: { + if (CATEGORY_BOX.isMouseInBox(mouseX, mouseY)) { + final boolean consumedClick = forEachVisible(this.categoryElements, CATEGORY_BOX, this.categoryScrollbar.getScroll(), (element, drawY) -> + element.mouseClicked(mouseX, mouseY, button) + ); + if (consumedClick || categoryScrollbar.mouseClicked(mouseX, mouseY, button)) { + break click_scan; + } + } else if (CONFIG_BOX.isMouseInBox(mouseX, mouseY)) { + final boolean consumedClick = forEachVisible(this.renderedConfigElements, CONFIG_BOX, this.configScrollbar.getScroll(), (element, drawY) -> { + try { + if (element.mouseClicked(mouseX, mouseY, button)) { + if (element instanceof SliderGuiButton) { + lastInteractedSlider = ((SliderGuiButton) element); + } else if (element instanceof OverlayConfigGuiButton) { + final OverlayConfigGuiButton overlay = (OverlayConfigGuiButton) element; + if (overlay.isOverlayOpen()) { + currentlyOpenOverlay = overlay; + } } + return true; } - return true; + } catch (IllegalAccessException e) { + throw new RuntimeException("Caught exception running mouse click events!", e); } - } catch (IllegalAccessException e) { - throw new RuntimeException("Caught exception running mouse click events!", e); + return false; + }); + if (consumedClick || configScrollbar.mouseClicked(mouseX, mouseY, button)) { + break click_scan; } - return false; - }); - if (consumedClick) return; - if (this.configScrollbar.mouseClicked(mouseX, mouseY, button)) { - return; + } else if (button.isLeft() && SEARCH_BOX.isMouseInBox(mouseX, mouseY)) { + searchField.setFocused(true); + break click_scan; } - } else if (button.isLeft() && SEARCH_BOX.isMouseInBox(mouseX, mouseY)) { - searchField.setFocused(true); - return; + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + if (overlayToClose != null && overlayToClose != currentlyOpenOverlay) { + overlayToClose.closeOverlay(); } - super.mouseClicked(mouseX, mouseY, mouseButton); } @Override protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { final MouseButton button = MouseButton.from(mouseButton); + if (currentlyOpenOverlay != null) { + final boolean handledByOverlay = currentlyOpenOverlay.mouseReleasedOnOverlay(mouseX, mouseY, button); + if (!currentlyOpenOverlay.isOverlayOpen()) this.currentlyOpenOverlay = null; + if (handledByOverlay) { + return; + } + } for (final ConfigUIElement element : this.renderedConfigElements) { if (element.mouseReleased(mouseX, mouseY, button)) { return; @@ -301,8 +340,10 @@ protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { - if (lastInteractedOverlay != null) { - return; + if (currentlyOpenOverlay != null) { + final boolean handledByOverlay = currentlyOpenOverlay.overlayKeyTyped(typedChar, keyCode); + if (!currentlyOpenOverlay.isOverlayOpen()) this.currentlyOpenOverlay = null; + if (handledByOverlay) return; } if (lastInteractedSlider != null && (keyCode == Keyboard.KEY_LEFT || keyCode == Keyboard.KEY_RIGHT)) { lastInteractedSlider.updateSliderFromIncrement(keyCode == Keyboard.KEY_LEFT ? -1 : 1); @@ -310,7 +351,7 @@ protected void keyTyped(char typedChar, int keyCode) throws IOException { return; } if (searchField != null) { - if (keyCode == 1 && searchField.isFocused()) { + if (keyCode == Keyboard.KEY_ESCAPE && searchField.isFocused()) { searchField.setText(""); updateSearch(""); searchField.setFocused(false); @@ -335,8 +376,10 @@ protected void keyTyped(char typedChar, int keyCode) throws IOException { @Override public void handleMouseInput() throws IOException { super.handleMouseInput(); - if (lastInteractedOverlay != null) { - return; + if (currentlyOpenOverlay != null) { + final boolean handledByOverlay = currentlyOpenOverlay.handleOverlayMouseInput(); + if (!currentlyOpenOverlay.isOverlayOpen()) this.currentlyOpenOverlay = null; + if (handledByOverlay) return; } final int wheel = Mouse.getEventDWheel(); if (wheel != 0) { @@ -347,6 +390,7 @@ public void handleMouseInput() throws IOException { if (CATEGORY_BOX.isMouseInBox(mouseX, mouseY)) { this.categoryScrollbar.scheduleScroll(direction, amount); } else if (CONFIG_BOX.isMouseInBox(mouseX, mouseY)) { + closeOpenOverlay(); // won't be noticed for 'ColorEnumGuiButton's Overlay' but is a must for 'Selector' and probably for future 'Color Edit' this.configScrollbar.scheduleScroll(direction, amount); } } @@ -364,24 +408,6 @@ public boolean doesGuiPauseGame() { return false; } - private int getCategoryContentHeight() { - int height = 0; - for (final CategoryGuiButton category : this.categoryElements) { - height += category.getHeight() + ELEMENT_GAP; - } - if (!this.categoryElements.isEmpty()) height -= ELEMENT_GAP; - return height; - } - - private int getConfigContentHeight() { - int height = 0; - for (final ConfigUIElement element : this.renderedConfigElements) { - height += element.getHeight() + ELEMENT_GAP; - } - if (!this.renderedConfigElements.isEmpty()) height -= ELEMENT_GAP; - return height; - } - public void setFocusedCategory(String categoryName) { if (categoryName == null) return; this.selectedCategory = categoryName; @@ -391,7 +417,7 @@ public void setFocusedCategory(String categoryName) { } this.configScrollbar.resetScroll(); this.lastInteractedSlider = null; - this.lastInteractedOverlay = null; + closeOpenOverlay(); this.renderedConfigElements.clear(); for (final ConfigUIElement element : this.configElements) { if (categoryName.equals(element.getCategory())) { @@ -408,7 +434,7 @@ private void updateSearch(String search) { search = search.toLowerCase(); this.configScrollbar.resetScroll(); this.lastInteractedSlider = null; - this.lastInteractedOverlay = null; + closeOpenOverlay(); this.renderedConfigElements.clear(); String lastKey = null; final int elementWidth = CONFIG_BOX.getWidth() - 2 * PADDING; @@ -438,14 +464,27 @@ private void updateSearch(String search) { } } + private static int getContentHeight(List elements) { + if (elements.isEmpty()) return 0; + int height = PADDING * 2 - (elements.get(0).getTopMargin() + elements.get(elements.size()-1).getBottomMargin()); + for (final T element : elements) { + height += element.getTopMargin() + element.getHeight() + element.getBottomMargin(); + } + return height; + } + private static boolean forEachVisible(List elements, Box box, int scroll, ElementVisitor visitor) { int drawY = box.TOP + PADDING - scroll; + if (!elements.isEmpty()) { + drawY -= elements.get(0).getTopMargin(); + } for (final T element : elements) { + drawY += element.getTopMargin(); final int elementHeight = element.getHeight(); if (drawY + elementHeight >= box.TOP && drawY <= box.BOTTOM) { if (visitor.visit(element, drawY)) return true; } - drawY += elementHeight + ELEMENT_GAP; + drawY += elementHeight + element.getBottomMargin(); } return false; } @@ -465,4 +504,10 @@ public Box getConfigBoxSize() { return CONFIG_BOX; } + private void closeOpenOverlay() { + if (this.currentlyOpenOverlay != null) { + this.currentlyOpenOverlay.closeOverlay(); + this.currentlyOpenOverlay = null; + } + } } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/Scrollbar.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/Scrollbar.java index e37bc7db..a09484b9 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/Scrollbar.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/Scrollbar.java @@ -35,26 +35,28 @@ public void updateScrollPos(int contentHeight, int boxHeight) { } public void drawScrollbar(ColorPalette colorPalette, Box box, int mouseY, int contentHeight) { - final int categoryBoxHeight = box.getHeight() - 2; - final boolean renderCategoryScrollbar = contentHeight > categoryBoxHeight; - if (renderCategoryScrollbar) { - final int scrollBarSize = categoryBoxHeight * categoryBoxHeight / contentHeight; - final int minScrollBarY = box.TOP + 1 + 1; - final int maxScrollBarY = box.BOTTOM - 1 - scrollBarSize - 1; - if (dragging) { - final int relativeMouseY = mouseY - minScrollBarY - grabbedAtY; - if (maxScrollBarY != minScrollBarY) { - final int newScroll = relativeMouseY * (contentHeight - box.getHeight()) / (maxScrollBarY - minScrollBarY); - this.scroll(this.scroll - newScroll, contentHeight, box.getHeight()); - } + final int REAL_BOX_HEIGHT = box.getHeight(); + if (contentHeight <= REAL_BOX_HEIGHT) return; + final int VERTICAL_MARGIN = 2; + final int AVAILABLE_BOX_HEIGHT = REAL_BOX_HEIGHT - VERTICAL_MARGIN * 2; + final int thumbHeight = AVAILABLE_BOX_HEIGHT * REAL_BOX_HEIGHT / contentHeight; + final int minY = box.TOP + VERTICAL_MARGIN; + final int maxY = box.BOTTOM - thumbHeight - VERTICAL_MARGIN; + final int scrollRange = contentHeight - REAL_BOX_HEIGHT; + final int trackRange = maxY - minY; + if (dragging) { + final int relativeMouseY = mouseY - minY - grabbedAtY; + if (trackRange != 0) { + final int newScroll = relativeMouseY * scrollRange / trackRange; + this.scroll(this.scroll - newScroll, contentHeight, REAL_BOX_HEIGHT); } - this.thumb.LEFT = box.RIGHT - 5; - this.thumb.TOP = ((maxScrollBarY - minScrollBarY) * this.scroll) / (contentHeight - categoryBoxHeight) + minScrollBarY; - this.thumb.RIGHT = this.thumb.LEFT + 3; - this.thumb.BOTTOM = this.thumb.TOP + scrollBarSize; - GuiUtil.drawVerticalLine(box.RIGHT - 4, box.TOP + 4, box.BOTTOM - 4, colorPalette.SCROLLBAR_TRACK); - GuiUtil.drawRect(this.thumb, colorPalette.SCROLLBAR_THUMB); } + this.thumb.LEFT = box.RIGHT - 5; + this.thumb.TOP = minY + (int) ((float)this.scroll / scrollRange * trackRange); + this.thumb.RIGHT = this.thumb.LEFT + 3; + this.thumb.BOTTOM = this.thumb.TOP + thumbHeight; + GuiUtil.drawVerticalLine(box.RIGHT - 4, box.TOP + 4, box.BOTTOM - 4, colorPalette.SCROLLBAR_TRACK); + GuiUtil.drawRect(this.thumb, colorPalette.SCROLLBAR_THUMB); } public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) { @@ -74,8 +76,8 @@ public void mouseReleased(MouseButton mouseButton) { private void scroll(int amount, int contentHeight, int boxHeight) { this.scroll = this.scroll - amount; - if (this.scroll > contentHeight + 2 * ConfigGuiScreen.PADDING - boxHeight) { - this.scroll = contentHeight + 2 * ConfigGuiScreen.PADDING - boxHeight; + if (this.scroll > contentHeight - boxHeight) { + this.scroll = contentHeight - boxHeight; this.amountToScroll = 0; } if (this.scroll <= 0) { diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/BooleanGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/BooleanGuiButton.java index a73efeb9..50e27c8a 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/BooleanGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/BooleanGuiButton.java @@ -3,7 +3,6 @@ import fr.alexdoru.configlib.api.ColorPalette; import fr.alexdoru.configlib.api.ConfigProperty; import fr.alexdoru.configlib.lib.gui.MouseButton; -import net.minecraft.util.EnumChatFormatting; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -16,22 +15,24 @@ public class BooleanGuiButton extends ConfigGuiButton { public BooleanGuiButton(Field field, Method event, ConfigProperty annotation) throws IllegalAccessException { super(field, event, annotation); this.toggled = (boolean) this.field.get(null); - this.button = new ClickGuiButton(0, 0, 0, mc.fontRendererObj.getStringWidth(" Disabled "), 20, getButtonText()); + this.button = getMainButton(getBooleanText(toggled)); + this.rightSideContentWidth = button.width + BUTTON_RIGHT_MARGIN; + this.rightSideContentHeight = button.height; } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { - super.draw(colorPalette, drawX, drawY, mouseX, mouseY); - button.xPosition = drawX + boxWidth - button.width - 20; - button.yPosition = drawY + (this.hasComment() ? 8 + mc.fontRendererObj.FONT_HEIGHT / 2 : (getHeight() - button.height) / 2); - button.drawButton(colorPalette, mc, mouseX, mouseY); + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { + super.draw(colorPalette, drawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElement); + button.xPosition = contentLeft; + button.yPosition = drawY + getCenterYOffset(button.height); + button.drawButton(colorPalette, mc, mouseX, mouseY, canMouseBeVisuallyOverElement); } @Override public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) throws IllegalAccessException { if (mouseButton.isLeft() && button.mousePressed(mc, mouseX, mouseY)) { flipBooleanConfig(); - button.displayString = getButtonText(); + button.displayString = getBooleanText(toggled); button.playPressSound(mc.getSoundHandler()); return true; } @@ -43,9 +44,4 @@ private void flipBooleanConfig() throws IllegalAccessException { toggled = (boolean) this.field.get(null); invokeConfigEvent(); } - - private String getButtonText() { - return toggled ? EnumChatFormatting.GREEN + "Enabled" : EnumChatFormatting.RED + "Disabled"; - } - } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryGuiButton.java index c3ed76c8..b2734179 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryGuiButton.java @@ -41,8 +41,7 @@ public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) { } private boolean isMouseHovering(int mouseX, int mouseY) { - final int extraY = ConfigGuiScreen.ELEMENT_GAP / 2; - return mouseX >= posX && mouseY >= posY - extraY && mouseX < posX + getWidth() && mouseY < posY + extraY + getHeight(); + return mouseX >= posX && mouseY >= posY - getTopMargin() && mouseX < posX + getWidth() && mouseY < posY + getHeight() + getBottomMargin(); } public int getWidth() { diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryHeader.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryHeader.java index d5db2620..63ce6e78 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryHeader.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/CategoryHeader.java @@ -11,6 +11,8 @@ public class CategoryHeader implements ConfigUIElement { + private static final int COMMENT_TOP_MARGIN = 4; + private final Minecraft mc = Minecraft.getMinecraft(); private final String name; private final String displayname; @@ -44,7 +46,7 @@ public void setBoxWidth(int boxWidth) { } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { final int textX = drawX + (boxWidth - mc.fontRendererObj.getStringWidth(displayname) * 2) / 2; GlStateManager.translate(textX, drawY, 0); GlStateManager.scale(2, 2, 2); @@ -52,7 +54,7 @@ public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, in GlStateManager.scale(0.5, 0.5, 0.5); GlStateManager.translate(-textX, -drawY, 0); if (hasComment) { - int commentY = drawY + mc.fontRendererObj.FONT_HEIGHT * 2 + 8; + int commentY = drawY + mc.fontRendererObj.FONT_HEIGHT * 2 + COMMENT_TOP_MARGIN; for (final String line : commentToRender) { final int lineX = drawX + (boxWidth - mc.fontRendererObj.getStringWidth(line)) / 2; mc.fontRendererObj.drawStringWithShadow(line, lineX, commentY, colorPalette.CATEGORY_HEADER_COMMENT_TEXT); @@ -69,9 +71,9 @@ public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) { @Override public int getHeight() { if (hasComment) { - return mc.fontRendererObj.FONT_HEIGHT * 2 + 8 + mc.fontRendererObj.FONT_HEIGHT * commentToRender.size() + 8; + return mc.fontRendererObj.FONT_HEIGHT * 2 + COMMENT_TOP_MARGIN + mc.fontRendererObj.FONT_HEIGHT * commentToRender.size(); } - return mc.fontRendererObj.FONT_HEIGHT * 2 + 8; + return mc.fontRendererObj.FONT_HEIGHT * 2; } @Override @@ -89,4 +91,8 @@ public boolean matchSearch(String search) { return false; } + @Override + public int getBottomMargin() { + return 8; + } } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ClickGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ClickGuiButton.java index 39c44a41..6e5ef3e6 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ClickGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ClickGuiButton.java @@ -35,7 +35,11 @@ public void setTexture(ResourceLocation texture) { } public void drawButton(ColorPalette colorPalette, Minecraft mc, int mouseX, int mouseY) { - this.hovered = this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + drawButton(colorPalette, mc, mouseX, mouseY, true); + } + + public void drawButton(ColorPalette colorPalette, Minecraft mc, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { + this.hovered = canMouseBeVisuallyOverElement && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; if (this.visible) { this.mouseDragged(mc, mouseX, mouseY); GuiUtil.drawBoxWithOutline( diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorEnumGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorEnumGuiButton.java index 07f3099f..635da8dc 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorEnumGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorEnumGuiButton.java @@ -8,8 +8,10 @@ import fr.alexdoru.configlib.lib.gui.MouseButton; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; import java.awt.Color; import java.lang.reflect.Field; @@ -26,9 +28,17 @@ public class ColorEnumGuiButton extends OverlayConfigGuiButton { private final ClickGuiButton button; private final List colorButtons = new ArrayList<>(); private final Box panelBox = new Box(); + private final int defaultColorIndex; + private int lastSavedColorIndex; private int color; + private int selectedColorIndex; - public ColorEnumGuiButton(ConfigGuiScreen parentScreen, Field field, Method event, ConfigProperty annotation) throws IllegalAccessException { + // don't make this 'final', they should only be constructed when needed and set to null after (much cheaper) + private ClickGuiButton doneButton; + private ClickGuiButton resetButton; + private ClickGuiButton undoButton; + + public ColorEnumGuiButton(ConfigGuiScreen parentScreen, Field field, Method event, ConfigProperty annotation, EnumChatFormatting defaultColor) throws IllegalAccessException { super(field, event, annotation); this.parentScreen = parentScreen; int maxWidth = 0; @@ -38,90 +48,176 @@ public ColorEnumGuiButton(ConfigGuiScreen parentScreen, Field field, Method even this.colorButtons.add(new ColorSquareButton(c)); } } + this.defaultColorIndex = defaultColor.getColorIndex(); this.button = new ClickGuiButton(0, 0, 0, maxWidth, 20, ""); this.setValue((EnumChatFormatting) this.field.get(null)); + this.lastSavedColorIndex = this.selectedColorIndex; + this.rightSideContentWidth = button.width + BUTTON_RIGHT_MARGIN + 1 + button.height; // button.height == color_box_size + this.rightSideContentHeight = button.height; } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { - super.draw(colorPalette, drawX, drawY, mouseX, mouseY); - button.xPosition = drawX + boxWidth - button.width - 20; - button.yPosition = drawY + (this.hasComment() ? 8 + mc.fontRendererObj.FONT_HEIGHT / 2 : (getHeight() - button.height) / 2); - button.drawButton(colorPalette, mc, mouseX, mouseY); - final int left = button.xPosition - 20 - 1; - final int top = button.yPosition; - GuiUtil.drawBoxWithOutline(left, top, left + 20, top + 20, 255 << 24 | color, colorPalette.COLOR_BUTTON_INDICATOR_BORDER); - if (isOverlayOpen) { - GlStateManager.translate(0, 0, 200); - - final Box configBox = this.parentScreen.getConfigBoxSize(); - final int panelWidth = 8 * SQUARE + 9 * GAP; - final int panelHeight = GAP + SQUARE + GAP + SQUARE + GAP + mc.fontRendererObj.FONT_HEIGHT + GAP; - panelBox.LEFT = configBox.LEFT + (configBox.getWidth() - panelWidth) / 2; - panelBox.TOP = configBox.TOP + (configBox.getHeight() - panelHeight) / 2; - panelBox.RIGHT = panelBox.LEFT + panelWidth; - panelBox.BOTTOM = panelBox.TOP + panelHeight; - GuiUtil.drawBoxWithOutline(panelBox.LEFT, panelBox.TOP, panelBox.RIGHT, panelBox.BOTTOM, colorPalette.SETTING_BACKGROUND, colorPalette.SETTING_BACKGROUND_BORDER); - - EnumChatFormatting hovered = null; - final int startX = panelBox.LEFT + GAP; - final int startY = panelBox.TOP + GAP + mc.fontRendererObj.FONT_HEIGHT + GAP; - final List buttons = this.colorButtons; - for (int i = 0; i < buttons.size(); i++) { - final ColorSquareButton colorButton = buttons.get(i); - final int row = i / 8; - final int col = i % 8; - colorButton.xPosition = startX + col * (SQUARE + GAP); - colorButton.yPosition = startY + row * (SQUARE + GAP); - colorButton.drawButton(mc, mouseX, mouseY); - if (colorButton.isMouseOver()) hovered = colorButton.color; - } + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { + super.draw(colorPalette, drawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElement); + final int top = drawY + getCenterYOffset(button.height); + final int colorBoxSize = button.height; + GuiUtil.drawBoxWithOutline(contentLeft, top, contentLeft + colorBoxSize, top + colorBoxSize, 255 << 24 | color, colorPalette.COLOR_BUTTON_INDICATOR_BORDER); + button.xPosition = contentLeft + 1 + colorBoxSize; + button.yPosition = top; + button.drawButton(colorPalette, mc, mouseX, mouseY, canMouseBeVisuallyOverElement); + } - if (hovered != null) { - final String titleText = hovered + hovered.name(); - final int titleX = panelBox.LEFT + panelWidth / 2; - final int titleY = panelBox.TOP + GAP; - GuiUtil.drawCenteredString(titleText, titleX, titleY, 0xFFFFFFFF); + @Override + public void drawOverlay(ColorPalette colorPalette, int mouseX, int mouseY) { + final Box configBox = this.parentScreen.getConfigBoxSize(); + final int panelWidth = 8 * SQUARE + 9 * GAP; + final int panelHeight = GAP + mc.fontRendererObj.FONT_HEIGHT + GAP + SQUARE + GAP + SQUARE + 6 + doneButton.height + GAP; + panelBox.LEFT = configBox.LEFT + (configBox.getWidth() - panelWidth) / 2; + panelBox.TOP = configBox.TOP + (configBox.getHeight() - panelHeight) / 2; + panelBox.RIGHT = panelBox.LEFT + panelWidth; + panelBox.BOTTOM = panelBox.TOP + panelHeight; + GuiUtil.drawBoxWithOutline(panelBox.LEFT, panelBox.TOP, panelBox.RIGHT, panelBox.BOTTOM, colorPalette.SETTING_BACKGROUND, colorPalette.SETTING_BACKGROUND_BORDER); + + EnumChatFormatting hovered = null; + final int startX = panelBox.LEFT + GAP; + final int startY = panelBox.TOP + GAP + mc.fontRendererObj.FONT_HEIGHT + GAP; + final List buttons = this.colorButtons; + for (int i = 0; i < buttons.size(); i++) { + final ColorSquareButton colorButton = buttons.get(i); + final int row = i / 8; + final int col = i % 8; + colorButton.xPosition = startX + col * (SQUARE + GAP); + colorButton.yPosition = startY + row * (SQUARE + GAP); + colorButton.drawButton(mc, mouseX, mouseY); + if (this.selectedColorIndex == i) { + GuiUtil.drawOutline(colorButton.xPosition-1, colorButton.yPosition-1, colorButton.xPosition + colorButton.width + 1, colorButton.yPosition + colorButton.height + 1, 0xFF3C6EFF); } + if (colorButton.isMouseOver()) hovered = colorButton.color; + } - GlStateManager.translate(0, 0, -200); + if (hovered != null) { + final String titleText = hovered + hovered.name(); + final int titleX = panelBox.LEFT + panelWidth / 2; + final int titleY = panelBox.TOP + GAP; + GuiUtil.drawCenteredString(titleText, titleX, titleY, 0xFFFFFFFF); } + + final int buttonsTop = panelBox.BOTTOM - GAP - doneButton.height; + final int totalButtonsWidth = resetButton.width + GAP + doneButton.width + GAP + undoButton.width; + resetButton.xPosition = panelBox.LEFT + (panelWidth - totalButtonsWidth) / 2; + resetButton.yPosition = buttonsTop; + resetButton.drawButton(colorPalette, mc, mouseX, mouseY); + + doneButton.xPosition = resetButton.xPosition + resetButton.width + GAP; + doneButton.yPosition = buttonsTop; + doneButton.drawButton(colorPalette, mc, mouseX, mouseY); + + undoButton.xPosition = doneButton.xPosition + doneButton.width + GAP; + undoButton.yPosition = buttonsTop; + undoButton.drawButton(colorPalette, mc, mouseX, mouseY); + } + + @Override + public List getOverlayHoveringTextLines() { + if (resetButton.isMouseOver() && resetButton.hasHoveringText()) { + return resetButton.getHoveringTextLines(); + } + else if (undoButton.isMouseOver() && undoButton.hasHoveringText()) { + return undoButton.getHoveringTextLines(); + } + return null; + } + + @Override + public boolean isMouseOverOverlay(int mouseX, int mouseY) { + return panelBox.isMouseInBox(mouseX, mouseY); } @Override public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) throws IllegalAccessException { - if (!mouseButton.isLeft()) return false; - if (isOverlayOpen) { - if (panelBox.isMouseInBox(mouseX, mouseY)) { + if (mouseButton.isLeft() && button.mousePressed(mc, mouseX, mouseY)) { + button.playPressSound(mc.getSoundHandler()); + // only do work if the overlay is closed. + // if its open only play sound + if (!isOverlayOpen()) { + this.doneButton = new ClickGuiButton(-1, 0, 0, getMainButtonWidth(), 14, "Done"); + final int ICON_BUTTON_SIZE = doneButton.height; + this.resetButton = new ClickGuiButton(-1, 0, 0, ICON_BUTTON_SIZE, ICON_BUTTON_SIZE, ""); + this.resetButton.setTexture(new ResourceLocation("configlib", "reload.png")); + this.resetButton.setHoveringText("Reset to Default Position"); + this.undoButton = new ClickGuiButton(-1, 0, 0, ICON_BUTTON_SIZE, ICON_BUTTON_SIZE, ""); + this.undoButton.setTexture(new ResourceLocation("configlib", "undo.png")); + this.undoButton.setHoveringText("Undo Changes"); + isOverlayOpen = true; + } + return true; + } + return false; + } + + @Override + public boolean mouseClickedOnOverlay(int mouseX, int mouseY, MouseButton button) throws IllegalAccessException { + if (isMouseOverOverlay(mouseX, mouseY)) { + if (button.isLeft()) { for (final ColorSquareButton colorButton : this.colorButtons) { - if (colorButton.isMouseOver()) { - button.playPressSound(mc.getSoundHandler()); - this.setNewValue(colorButton.color); + if (colorButton.mousePressed(mc, mouseX, mouseY)) { + handleButtonClick(colorButton); return true; } } - } else { - isOverlayOpen = false; + if (doneButton.mousePressed(mc, mouseX, mouseY)) { + closeOverlay(); + } + else if (resetButton.mousePressed(mc, mouseX, mouseY)) { + handleButtonClick(colorButtons.get(defaultColorIndex)); + } + else if (undoButton.mousePressed(mc, mouseX, mouseY)) { + handleButtonClick(colorButtons.get(lastSavedColorIndex)); + } } return true; } - if (button.mousePressed(mc, mouseX, mouseY)) { - button.playPressSound(mc.getSoundHandler()); - isOverlayOpen = true; - return true; + return false; + } + + @Override + public boolean handleOverlayMouseInput() { + if (Mouse.getEventDWheel() != 0) { + final int mouseX = Mouse.getEventX() * parentScreen.width / mc.displayWidth; + final int mouseY = parentScreen.height - Mouse.getEventY() * parentScreen.height / mc.displayHeight - 1; + return parentScreen.getConfigBoxSize().isMouseInBox(mouseX, mouseY); // don't allow 'config box scroll' } return false; } + @Override + public boolean overlayKeyTyped(char typedChar, int keyCode) { + if (keyCode == Keyboard.KEY_ESCAPE) { + closeOverlay(); + } + return true; + } + private void setValue(EnumChatFormatting v) { this.color = mc.fontRendererObj.getColorCode(v.toString().charAt(1)); this.button.displayString = v + v.name(); + this.selectedColorIndex = v.getColorIndex(); } - private void setNewValue(EnumChatFormatting v) throws IllegalAccessException { - this.setValue(v); - this.field.set(null, v); - this.invokeConfigEvent(); + private void handleButtonClick(ColorSquareButton button) throws IllegalAccessException { + button.playPressSound(mc.getSoundHandler()); + this.field.set(null, button.color); + this.setValue(button.color); + invokeConfigEvent(); + } + + @Override + public void closeOverlay() { + super.closeOverlay(); + this.lastSavedColorIndex = this.selectedColorIndex; + this.doneButton = null; + this.resetButton = null; + this.undoButton = null; } private static class ColorSquareButton extends GuiButton { @@ -146,5 +242,4 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) { } } - } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorGuiButton.java index 20bc1eae..180fb73b 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ColorGuiButton.java @@ -21,18 +21,20 @@ public ColorGuiButton(ConfigGuiScreen configGuiScreen, Field field, ConfigProper this.parentScreen = configGuiScreen; this.color = (int) this.field.get(null); this.defaultColor = defaultColor; - this.button = new ClickGuiButton(0, 0, 0, mc.fontRendererObj.getStringWidth(" Disabled "), 20, "Change"); + this.button = getMainButton("Change"); + this.rightSideContentWidth = button.width + BUTTON_RIGHT_MARGIN + 1 + button.height; // button.height == color_box_size + this.rightSideContentHeight = button.height; } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { - super.draw(colorPalette, drawX, drawY, mouseX, mouseY); - button.xPosition = drawX + boxWidth - button.width - 20; - button.yPosition = drawY + (this.hasComment() ? 8 + mc.fontRendererObj.FONT_HEIGHT / 2 : (getHeight() - button.height) / 2); - button.drawButton(colorPalette, mc, mouseX, mouseY); - final int left = button.xPosition - 20 - 1; - final int top = button.yPosition; - GuiUtil.drawBoxWithOutline(left, top, left + 20, top + 20, 255 << 24 | color, colorPalette.COLOR_BUTTON_INDICATOR_BORDER); + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { + super.draw(colorPalette, drawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElement); + final int top = drawY + getCenterYOffset(button.height); + final int colorBoxSize = button.height; + GuiUtil.drawBoxWithOutline(contentLeft, top, contentLeft + colorBoxSize, top + colorBoxSize, 255 << 24 | color, colorPalette.COLOR_BUTTON_INDICATOR_BORDER); + button.xPosition = contentLeft + colorBoxSize + 1; + button.yPosition = top; + button.drawButton(colorPalette, mc, mouseX, mouseY, canMouseBeVisuallyOverElement); } @Override @@ -44,5 +46,4 @@ public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) thr } return false; } - } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigGuiButton.java index f28505da..15f9a411 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigGuiButton.java @@ -5,6 +5,7 @@ import fr.alexdoru.configlib.lib.gui.GuiUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import java.lang.reflect.Field; @@ -15,6 +16,10 @@ public abstract class ConfigGuiButton implements ConfigUIElement { + protected static final int DEFAULT_PADDING = 8; + protected static final int BUTTON_RIGHT_MARGIN = 20; + private static final int COMMENT_TOP_MARGIN = 4; + protected final Minecraft mc = Minecraft.getMinecraft(); protected final Field field; private final Method event; @@ -22,6 +27,14 @@ public abstract class ConfigGuiButton implements ConfigUIElement { private final List commentToRender = new ArrayList<>(); protected int boxWidth; protected int posX, posY; + protected int boxHeight; + protected int contentLeft; + + /** The distance between the left-most position of the content (button) and the right side of the rect */ + protected int rightSideContentWidth; + + /** The height of the right-side content (button[s], slider, etc...) */ + protected int rightSideContentHeight; protected ConfigGuiButton(Field field, Method event, ConfigProperty annotation) { this.field = field; @@ -29,26 +42,34 @@ protected ConfigGuiButton(Field field, Method event, ConfigProperty annotation) this.annotation = annotation; } + /** + * {@link #rightSideContentWidth} must be correctly set before this method is called + */ @Override public void setBoxWidth(int boxWidth) { this.boxWidth = boxWidth; if (this.hasComment()) { - final int wrapWidth = boxWidth - mc.fontRendererObj.getStringWidth(" Disabled ") - 20 - 20; + final int wrapWidth = boxWidth - getLeftPadding() - rightSideContentWidth - 16; // 20 this.commentToRender.clear(); this.commentToRender.addAll(resizeCommentLines(annotation.comment(), wrapWidth, mc)); } } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { this.posX = drawX; this.posY = drawY; - GuiUtil.drawBoxWithOutline(drawX, drawY, drawX + boxWidth, drawY + getHeight(), colorPalette.SETTING_BACKGROUND, colorPalette.SETTING_BACKGROUND_BORDER); - mc.fontRendererObj.drawStringWithShadow(annotation.name(), drawX + 8, drawY + 8, colorPalette.SETTING_NAME_TEXT); + this.boxHeight = getHeight(); + final int right = drawX + boxWidth; + this.contentLeft = right - rightSideContentWidth; + GuiUtil.drawBoxWithOutline(drawX, drawY, right, drawY + boxHeight, colorPalette.SETTING_BACKGROUND, colorPalette.SETTING_BACKGROUND_BORDER); + final int textX = drawX + getLeftPadding(); + final int textY = drawY + (this.hasComment() ? DEFAULT_PADDING : getCenterYOffset(mc.fontRendererObj.FONT_HEIGHT)); + mc.fontRendererObj.drawStringWithShadow(annotation.name(), textX, textY, colorPalette.SETTING_NAME_TEXT); if (this.hasComment()) { - int commentY = drawY + 8 + mc.fontRendererObj.FONT_HEIGHT + 8; + int commentY = textY + mc.fontRendererObj.FONT_HEIGHT + COMMENT_TOP_MARGIN; for (final String line : commentToRender) { - mc.fontRendererObj.drawStringWithShadow(line, drawX + 8, commentY, colorPalette.SETTING_COMMENT_TEXT); + mc.fontRendererObj.drawStringWithShadow(line, textX, commentY, colorPalette.SETTING_COMMENT_TEXT); commentY += mc.fontRendererObj.FONT_HEIGHT; } } @@ -56,10 +77,11 @@ public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, in @Override public int getHeight() { + int textHeight = mc.fontRendererObj.FONT_HEIGHT; if (this.hasComment()) { - return 8 + mc.fontRendererObj.FONT_HEIGHT + 8 + mc.fontRendererObj.FONT_HEIGHT * commentToRender.size() + 8 - 1; + textHeight += COMMENT_TOP_MARGIN + mc.fontRendererObj.FONT_HEIGHT * commentToRender.size(); } - return 8 + mc.fontRendererObj.FONT_HEIGHT + 8 - 1; + return DEFAULT_PADDING + Math.max(textHeight, rightSideContentHeight) + DEFAULT_PADDING - 1; } @Override @@ -97,4 +119,22 @@ protected void playPressSound() { this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); } + // doesn't seem useful, but it's a must for future 'CustomElements' + protected int getLeftPadding() { return DEFAULT_PADDING; } + + protected final ClickGuiButton getMainButton(String text) { + return new ClickGuiButton(-1, 0, 0, getMainButtonWidth(), 20, text); + } + + protected final int getMainButtonWidth() { + return mc.fontRendererObj.getStringWidth("Disabled") + 9; + } + + protected static String getBooleanText(boolean value) { + return value ? EnumChatFormatting.GREEN + "Enabled" : EnumChatFormatting.RED + "Disabled"; + } + + protected final int getCenterYOffset(int height) { + return (this.boxHeight - height) / 2; + } } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigUIElement.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigUIElement.java index 2f56a751..77fabd73 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigUIElement.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/ConfigUIElement.java @@ -12,7 +12,7 @@ public interface ConfigUIElement extends SizedElement { void setBoxWidth(int boxWidth); - void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY); + void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement); boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) throws IllegalAccessException; @@ -41,4 +41,5 @@ default List resizeCommentLines(String comment, int wrapWidth, Minecraft } } + default List getHoveringTextLines() { return null; } } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/EnumGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/EnumGuiButton.java index 5dd15d73..eafc7286 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/EnumGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/EnumGuiButton.java @@ -24,18 +24,20 @@ public EnumGuiButton(Field field, Method event, ConfigProperty annotation) throw } int width = 0; for (final Enum e : values) { - width = Math.max(width, mc.fontRendererObj.getStringWidth(" " + e.name())); + width = Math.max(width, mc.fontRendererObj.getStringWidth(e.name()) + 9); } this.button = new ClickGuiButton(0, 0, 0, width, 20, ""); this.setValue((Enum) this.field.get(null)); + this.rightSideContentWidth = button.width + BUTTON_RIGHT_MARGIN; + this.rightSideContentHeight = button.height; } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { - super.draw(colorPalette, drawX, drawY, mouseX, mouseY); - button.xPosition = drawX + boxWidth - button.width - 20; - button.yPosition = drawY + (this.hasComment() ? 8 + mc.fontRendererObj.FONT_HEIGHT / 2 : (getHeight() - button.height) / 2); - button.drawButton(colorPalette, mc, mouseX, mouseY); + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { + super.draw(colorPalette, drawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElement); + button.xPosition = contentLeft; + button.yPosition = drawY + getCenterYOffset(button.height); + button.drawButton(colorPalette, mc, mouseX, mouseY, canMouseBeVisuallyOverElement); } @Override diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/OverlayConfigGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/OverlayConfigGuiButton.java index 4be3af14..2dc4d960 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/OverlayConfigGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/OverlayConfigGuiButton.java @@ -1,9 +1,12 @@ package fr.alexdoru.configlib.lib.gui.elements; +import fr.alexdoru.configlib.api.ColorPalette; import fr.alexdoru.configlib.api.ConfigProperty; +import fr.alexdoru.configlib.lib.gui.MouseButton; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.List; public abstract class OverlayConfigGuiButton extends ConfigGuiButton { @@ -13,8 +16,29 @@ protected OverlayConfigGuiButton(Field field, Method event, ConfigProperty annot super(field, event, annotation); } + public abstract boolean isMouseOverOverlay(int mouseX, int mouseY); + + public abstract void drawOverlay(ColorPalette colorPalette, int mouseX, int mouseY); + + public List getOverlayHoveringTextLines() { return null; } + + /** @return {@code true} if the overlay handles the mouse click */ + public abstract boolean mouseClickedOnOverlay(int mouseX, int mouseY, MouseButton button) throws IllegalAccessException; + + /** @return {@code true} if the overlay handles the mouse release */ + public boolean mouseReleasedOnOverlay(int mouseX, int mouseY, MouseButton button) { return false; } + + /** @return {@code true} if the overlay handles the mouse input */ + public boolean handleOverlayMouseInput() { return false; } + + /** @return {@code true} if the overlay handles the key typed */ + public boolean overlayKeyTyped(char typedChar, int keyCode) { return false; } + public boolean isOverlayOpen() { return isOverlayOpen; } + public void closeOverlay() { + this.isOverlayOpen = false; + } } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/RendererGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/RendererGuiButton.java index 672af83c..5534200c 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/RendererGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/RendererGuiButton.java @@ -7,11 +7,11 @@ import fr.alexdoru.configlib.lib.gui.ConfigGuiScreen; import fr.alexdoru.configlib.lib.gui.MouseButton; import fr.alexdoru.configlib.lib.gui.RendererEditGuiScreen; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.List; public class RendererGuiButton extends ConfigGuiButton { @@ -33,34 +33,33 @@ public RendererGuiButton( this.rendererManager = rendererManager; this.rendererPosition = ((RendererPosition) field.get(null)); this.toggled = this.rendererPosition.isEnabled(); - this.buttonEnabled = new ClickGuiButton(0, 0, 0, mc.fontRendererObj.getStringWidth(" Disabled "), 20, getButtonText()); - this.buttonMoveHud = new ClickGuiButton(0, 0, 0, 20, 20, ""); + this.buttonEnabled = getMainButton(getBooleanText(toggled)); + final int moveHudBtnSize = buttonEnabled.height; + this.buttonMoveHud = new ClickGuiButton(0, 0, 0, moveHudBtnSize, moveHudBtnSize, ""); this.buttonMoveHud.setTexture(new ResourceLocation("configlib", "move.png")); + this.buttonMoveHud.setHoveringText("Move HUD"); + this.rightSideContentWidth = buttonEnabled.width + BUTTON_RIGHT_MARGIN + 1 + buttonMoveHud.width; + this.rightSideContentHeight = buttonEnabled.height; } @Override - public void setBoxWidth(int boxWidth) { - super.setBoxWidth(boxWidth - 20 - 1); - this.boxWidth = boxWidth; - } + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { + super.draw(colorPalette, drawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElement); - @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { - super.draw(colorPalette, drawX, drawY, mouseX, mouseY); - buttonEnabled.xPosition = drawX + boxWidth - buttonEnabled.width - 20; - buttonEnabled.yPosition = drawY + 8; - buttonEnabled.drawButton(colorPalette, mc, mouseX, mouseY); + final int top = drawY + getCenterYOffset(buttonEnabled.height); - buttonMoveHud.xPosition = buttonEnabled.xPosition - buttonMoveHud.width - 1; - buttonMoveHud.yPosition = buttonEnabled.yPosition; - buttonMoveHud.drawButton(colorPalette, mc, mouseX, mouseY); + buttonMoveHud.xPosition = contentLeft; + buttonMoveHud.yPosition = top; + buttonMoveHud.drawButton(colorPalette, mc, mouseX, mouseY, canMouseBeVisuallyOverElement); - if (buttonMoveHud.isMouseOver()) { - final String text = "Move HUD"; - final int textX = buttonMoveHud.xPosition - 4 - mc.fontRendererObj.getStringWidth(text); - final int textY = buttonMoveHud.yPosition + (buttonMoveHud.height - 8) / 2; - mc.fontRendererObj.drawStringWithShadow(text, textX, textY, colorPalette.HUD_BUTTON_HINT_TEXT); - } + buttonEnabled.xPosition = buttonMoveHud.xPosition + buttonMoveHud.width + 1; + buttonEnabled.yPosition = top; + buttonEnabled.drawButton(colorPalette, mc, mouseX, mouseY, canMouseBeVisuallyOverElement); + } + + @Override + public List getHoveringTextLines() { + return (buttonMoveHud.isMouseOver() && buttonMoveHud.hasHoveringText()) ? buttonMoveHud.getHoveringTextLines() : null; } @Override @@ -68,7 +67,7 @@ public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) { if (mouseButton.isLeft()) { if (buttonEnabled.mousePressed(mc, mouseX, mouseY)) { flipBooleanConfig(); - buttonEnabled.displayString = getButtonText(); + buttonEnabled.displayString = getBooleanText(toggled); buttonEnabled.playPressSound(mc.getSoundHandler()); return true; } else if (buttonMoveHud.mousePressed(mc, mouseX, mouseY)) { @@ -85,9 +84,4 @@ private void flipBooleanConfig() { toggled = rendererPosition.isEnabled(); invokeConfigEvent(); } - - private String getButtonText() { - return toggled ? EnumChatFormatting.GREEN + "Enabled" : EnumChatFormatting.RED + "Disabled"; - } - -} +} \ No newline at end of file diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SizedElement.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SizedElement.java index 66666de8..7c045479 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SizedElement.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SizedElement.java @@ -4,4 +4,7 @@ public interface SizedElement { int getHeight(); + default int getTopMargin() { return 2; } + + default int getBottomMargin() { return 2; } } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SliderGuiButton.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SliderGuiButton.java index 5d9e8cc5..18631552 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SliderGuiButton.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SliderGuiButton.java @@ -3,6 +3,7 @@ import fr.alexdoru.configlib.api.ColorPalette; import fr.alexdoru.configlib.api.ConfigProperty; import fr.alexdoru.configlib.lib.gui.GuiUtil; +import net.minecraft.client.gui.Gui; import fr.alexdoru.configlib.lib.gui.MouseButton; import net.minecraft.util.MathHelper; @@ -20,7 +21,7 @@ public class SliderGuiButton extends ConfigGuiButton { private int plusButtonX, plusButtonY; private int sliderIncrement; private final boolean isIntValue; - private boolean isPourcentage; + private boolean isPercentage; private final int minValue, maxValue; private int sliderValueI; private double sliderValueD; @@ -39,7 +40,7 @@ public SliderGuiButton(Field field, Method event, ConfigProperty annotation) thr isIntValue = false; sliderValueD = (double) field.get(null); if (minValue == 0 && maxValue == 1) { - isPourcentage = true; + isPercentage = true; sliderValueI = (int) ((double) field.get(null) * 100d); sliderIncrement = MathHelper.clamp_int((SLIDER_WIDTH - 1) * (sliderValueI) / 100, 0, SLIDER_WIDTH - 1); } else { @@ -49,38 +50,39 @@ public SliderGuiButton(Field field, Method event, ConfigProperty annotation) thr } else { throw new IllegalArgumentException("Field of type " + field.getType() + " not supported by SliderGuiButton."); } + this.rightSideContentWidth = (PLUS_BUTTON_SIZE + SLIDER_BUTTON_SIZE / 2) * 2 + 1 + SLIDER_WIDTH + 6; + this.rightSideContentHeight = SLIDER_BUTTON_SIZE + mc.fontRendererObj.FONT_HEIGHT + 6; } @Override - public void setBoxWidth(int boxWidth) { - super.setBoxWidth(boxWidth - 60); - this.boxWidth = boxWidth; - } - - @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { - super.draw(colorPalette, drawX, drawY, mouseX, mouseY); + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { + super.draw(colorPalette, drawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElement); if (dragging) { updateSliderFromPosition(mouseX - sliderBarX); } final int SLIDER_HEIGHT = 6; - sliderBarX = drawX + boxWidth - SLIDER_WIDTH - 20; - final int sliderBarY = drawY + 8 + mc.fontRendererObj.FONT_HEIGHT; - sliderButtonX = sliderBarX + sliderIncrement - SLIDER_BUTTON_SIZE / 2; + final int HALF_SLIDER_BUTTON_SIZE = SLIDER_BUTTON_SIZE / 2; + sliderBarX = contentLeft + PLUS_BUTTON_SIZE + HALF_SLIDER_BUTTON_SIZE + 1; + final int sliderBarY = drawY + getCenterYOffset(SLIDER_HEIGHT); + sliderButtonX = sliderBarX + sliderIncrement - HALF_SLIDER_BUTTON_SIZE; sliderButtonY = sliderBarY + (SLIDER_HEIGHT - SLIDER_BUTTON_SIZE) / 2; - minusButtonX = sliderBarX - SLIDER_BUTTON_SIZE / 2 - PLUS_BUTTON_SIZE - 1; + minusButtonX = contentLeft; minusButtonY = sliderBarY + (SLIDER_HEIGHT - PLUS_BUTTON_SIZE) / 2; - plusButtonX = sliderBarX + SLIDER_WIDTH + SLIDER_BUTTON_SIZE / 2; - plusButtonY = sliderBarY + (SLIDER_HEIGHT - PLUS_BUTTON_SIZE) / 2; + plusButtonX = sliderBarX + SLIDER_WIDTH + HALF_SLIDER_BUTTON_SIZE; + plusButtonY = minusButtonY; GuiUtil.drawBoxWithOutline(sliderBarX, sliderBarY, sliderBarX + SLIDER_WIDTH, sliderBarY + SLIDER_HEIGHT, colorPalette.SLIDER_BUTTON_TRACK, colorPalette.SLIDER_BUTTON_TRACK_BORDER); - final boolean silderHovered = isMouseOnButton(mouseX, mouseY, sliderButtonX, sliderButtonY, SLIDER_BUTTON_SIZE, SLIDER_BUTTON_SIZE); + final boolean silderHovered = canMouseBeVisuallyOverElement && isMouseOnButton(mouseX, mouseY, sliderButtonX, sliderButtonY, SLIDER_BUTTON_SIZE, SLIDER_BUTTON_SIZE); final int sliderColor = silderHovered ? GuiUtil.brightenColor(colorPalette.SLIDER_BUTTON_THUMB, 0.12f) : colorPalette.SLIDER_BUTTON_THUMB; + if (sliderButtonX > (sliderBarX + 1)) { + final int top = sliderBarY + 1; + Gui.drawRect(sliderBarX + 1, top, sliderButtonX, top + SLIDER_HEIGHT - 2, sliderColor); + } GuiUtil.drawBoxWithOutline(sliderButtonX, sliderButtonY, sliderButtonX + SLIDER_BUTTON_SIZE, sliderButtonY + SLIDER_BUTTON_SIZE, sliderColor, colorPalette.SLIDER_BUTTON_THUMB_BORDER); - final boolean isMinusHovered = isMouseOnButton(mouseX, mouseY, minusButtonX, minusButtonY, PLUS_BUTTON_SIZE, PLUS_BUTTON_SIZE); + final boolean isMinusHovered = canMouseBeVisuallyOverElement && isMouseOnButton(mouseX, mouseY, minusButtonX, minusButtonY, PLUS_BUTTON_SIZE, PLUS_BUTTON_SIZE); final int minusColor = isMinusHovered ? GuiUtil.brightenColor(colorPalette.SLIDER_BUTTON_PLUS_BACKGROUND, 0.12f) : colorPalette.SLIDER_BUTTON_PLUS_BACKGROUND; GuiUtil.drawBoxWithOutline(minusButtonX, minusButtonY, minusButtonX + PLUS_BUTTON_SIZE, minusButtonY + PLUS_BUTTON_SIZE, minusColor, colorPalette.SLIDER_BUTTON_PLUS_BACKGROUND_BORDER); mc.fontRendererObj.drawStringWithShadow("-", minusButtonX + 2, minusButtonY + 1, colorPalette.SLIDER_BUTTON_PLUS_TEXT); - final boolean isPlusHovered = isMouseOnButton(mouseX, mouseY, plusButtonX, plusButtonY, PLUS_BUTTON_SIZE, PLUS_BUTTON_SIZE); + final boolean isPlusHovered = canMouseBeVisuallyOverElement && isMouseOnButton(mouseX, mouseY, plusButtonX, plusButtonY, PLUS_BUTTON_SIZE, PLUS_BUTTON_SIZE); final int plusColor = isPlusHovered ? GuiUtil.brightenColor(colorPalette.SLIDER_BUTTON_PLUS_BACKGROUND, 0.12f) : colorPalette.SLIDER_BUTTON_PLUS_BACKGROUND; GuiUtil.drawBoxWithOutline(plusButtonX, plusButtonY, plusButtonX + PLUS_BUTTON_SIZE, plusButtonY + PLUS_BUTTON_SIZE, plusColor, colorPalette.SLIDER_BUTTON_PLUS_BACKGROUND_BORDER); mc.fontRendererObj.drawStringWithShadow("+", plusButtonX + 2, plusButtonY + 1, colorPalette.SLIDER_BUTTON_PLUS_TEXT); @@ -88,22 +90,17 @@ public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, in if (isIntValue) { valueText = String.valueOf(sliderValueI); } else { - if (isPourcentage) { + if (isPercentage) { valueText = MathHelper.floor_double(sliderValueI) + "%"; } else { valueText = String.format("%.2f", sliderValueD); } } final int valueX = sliderButtonX + (SLIDER_BUTTON_SIZE - mc.fontRendererObj.getStringWidth(valueText)) / 2; - final int valueY = sliderBarY - mc.fontRendererObj.FONT_HEIGHT - 4; + final int valueY = sliderButtonY - mc.fontRendererObj.FONT_HEIGHT - 1; mc.fontRendererObj.drawStringWithShadow(valueText, valueX, valueY, colorPalette.SLIDER_BUTTON_VALUE_TEXT); } - @Override - public int getHeight() { - return Math.max(super.getHeight(), 8 + mc.fontRendererObj.FONT_HEIGHT + SLIDER_BUTTON_SIZE + 8); - } - @Override public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) throws IllegalAccessException { if (mouseButton.isLeft()) { @@ -144,7 +141,7 @@ private void updateSliderFromPosition(int sliderIncrementIn) { if (prevValue != sliderValueI) { invokeConfigEvent(); } - } else if (isPourcentage) { + } else if (isPercentage) { final int prevValue = sliderValueI; sliderValueI = MathHelper.clamp_int(sliderIncrement * 100 / (SLIDER_WIDTH - 1), 0, 100); field.setDouble(null, MathHelper.clamp_double(sliderValueI / 100d, 0, 1)); @@ -171,7 +168,7 @@ public void updateSliderFromIncrement(int valueIncrement) { sliderValueI = MathHelper.clamp_int(sliderValueI + valueIncrement, minValue, maxValue); sliderIncrement = MathHelper.clamp_int((SLIDER_WIDTH - 1) * (sliderValueI - minValue) / (maxValue - minValue), 0, SLIDER_WIDTH - 1); field.setInt(null, sliderValueI); - } else if (isPourcentage) { + } else if (isPercentage) { sliderValueI = MathHelper.clamp_int(sliderValueI + valueIncrement, 0, 100); sliderIncrement = MathHelper.clamp_int((SLIDER_WIDTH - 1) * sliderValueI / (100), 0, SLIDER_WIDTH - 1); field.setDouble(null, MathHelper.clamp_double(sliderValueI / 100d, 0, 1)); @@ -185,5 +182,4 @@ public void updateSliderFromIncrement(int valueIncrement) { } invokeConfigEvent(); } - } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SubCategoryHeader.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SubCategoryHeader.java index 785ba467..e249cb7c 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SubCategoryHeader.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/SubCategoryHeader.java @@ -22,7 +22,7 @@ public void setBoxWidth(int boxWidth) { } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { final int textX = drawX + (boxWidth - mc.fontRendererObj.getStringWidth(subCategoryName)) / 2; mc.fontRendererObj.drawStringWithShadow(subCategoryName, textX, drawY, 0xFFFFFFFF); } @@ -52,5 +52,4 @@ public boolean matchSearch(String search) { return categoryName.toLowerCase().contains(search) || subCategoryName.toLowerCase().contains(search); } - } diff --git a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/TextLabel.java b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/TextLabel.java index 446004d8..4e30ad2a 100644 --- a/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/TextLabel.java +++ b/src/configlib/java/fr/alexdoru/configlib/lib/gui/elements/TextLabel.java @@ -20,7 +20,7 @@ public void setBoxWidth(int boxWidth) { } @Override - public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) { + public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) { final int textX = drawX + (boxWidth - mc.fontRendererObj.getStringWidth(this.text)) / 2; mc.fontRendererObj.drawStringWithShadow(this.text, textX, drawY, colorPalette.LABEL_TEXT); } @@ -49,5 +49,4 @@ public String getSubCategory() { public boolean matchSearch(String search) { return false; } - }