aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev/isxander/yacl3/gui
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/gui')
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java17
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java13
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java10
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java36
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java2
9 files changed, 49 insertions, 45 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
index a34329a..0c3afdd 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
@@ -5,15 +5,24 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Renderable;
+import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import java.awt.*;
public abstract class AbstractWidget implements GuiEventListener, Renderable, NarratableEntry {
+ private static final WidgetSprites SPRITES = new WidgetSprites(
+ new ResourceLocation("widget/button"), // normal
+ new ResourceLocation("widget/button_disabled"), // disabled & !focused
+ new ResourceLocation("widget/button_highlighted"), // !disabled & focused
+ new ResourceLocation("widget/slider_highlighted") // disabled & focused
+ );
+
protected final Minecraft client = Minecraft.getInstance();
protected final Font textRenderer = client.font;
protected final int inactiveColor = 0xFFA0A0A0;
@@ -74,13 +83,7 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na
int width = x2 - x1;
int height = y2 - y1;
- int i = !enabled ? 0 : hovered ? 2 : 1;
- graphics.blit(net.minecraft.client.gui.components.AbstractWidget.WIDGETS_LOCATION, x1, y1, 0, 0, 46 + i * 20, width / 2, height, 256, 256);
- graphics.blit(net.minecraft.client.gui.components.AbstractWidget.WIDGETS_LOCATION, x1 + width / 2, y1, 0, 200 - width / 2f, 46 + i * 20, width / 2, height, 256, 256);
-
- if (hovered && !enabled) {
- drawOutline(graphics, x1, y1, x2, y2, 1, 0xFFD0D0D0);
- }
+ graphics.blitSprite(SPRITES.get(enabled, hovered), x1, y1, width, height);
}
protected void drawOutline(GuiGraphics graphics, int x1, int y1, int x2, int y2, int width, int color) {
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
index e3944ee..a36bd5e 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
@@ -26,23 +26,18 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
this.y = y;
this.x1 = this.x0 + width;
this.doSmoothScrolling = smoothScrolling;
+ setRenderBackground(true);
+ setRenderHeader(false, 0);
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
// default implementation bases scroll step from total height of entries, this is constant
- this.setScrollAmount(this.getScrollAmount() - amount * 20);
+ this.setScrollAmount(this.getScrollAmount() - (vertical + horizontal) * 20);
return true;
}
@Override
- protected void renderBackground(GuiGraphics graphics) {
- // render transparent background if in-game.
- setRenderBackground(true);
- setRenderTopAndBottom(false);
- }
-
- @Override
protected int getScrollbarPosition() {
// default implementation does not respect left/right
return this.x1 - 2;
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java
index 0732c5f..7aa3715 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java
@@ -122,9 +122,9 @@ public class OptionDescriptionWidget extends AbstractWidget {
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
if (isMouseOver(mouseX, mouseY)) {
- targetScrollAmount = Mth.clamp(targetScrollAmount - (int) amount * 10, 0, maxScrollAmount);
+ targetScrollAmount = Mth.clamp(targetScrollAmount - (int) vertical * 10, 0, maxScrollAmount);
lastInteractionTime = currentTimeMS();
return true;
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
index 3197c44..666c3c8 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
@@ -150,11 +150,11 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- super.mouseScrolled(mouseX, mouseY, amount);
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ super.mouseScrolled(mouseX, mouseY, horizontal, vertical);
for (Entry child : children()) {
- if (child.mouseScrolled(mouseX, mouseY, amount))
+ if (child.mouseScrolled(mouseX, mouseY, horizontal, vertical))
break;
}
@@ -305,8 +305,8 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- return widget.mouseScrolled(mouseX, mouseY, amount);
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ return widget.mouseScrolled(mouseX, mouseY, horizontal, vertical);
}
@Override
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java b/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
index b363ada..0bf9c65 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
@@ -43,7 +43,8 @@ public class YACLScreen extends Screen {
public TabNavigationBar tabNavigationBar;
public ScreenRectangle tabArea;
- public Component saveButtonMessage, saveButtonTooltipMessage;
+ public Component saveButtonMessage;
+ public Tooltip saveButtonTooltipMessage;
private int saveButtonMessageTime;
public YACLScreen(YetAnotherConfigLib config, Screen parent) {
@@ -122,18 +123,22 @@ public class YACLScreen extends Screen {
@Override
public void tick() {
- tabManager.tickCurrent();
-
- if (saveButtonMessage != null) {
- if (saveButtonMessageTime > 140) {
- saveButtonMessage = null;
- saveButtonTooltipMessage = null;
- saveButtonMessageTime = 0;
- } else {
- saveButtonMessageTime++;
- //finishedSaveButton.setMessage(saveButtonMessage);
- if (saveButtonTooltipMessage != null) {
- //finishedSaveButton.setTooltip(saveButtonTooltipMessage);
+ if (tabManager.getCurrentTab() instanceof TabExt tabExt) {
+ tabExt.tick();
+ }
+
+ if (tabManager.getCurrentTab() instanceof CategoryTab categoryTab) {
+ if (saveButtonMessage != null) {
+ if (saveButtonMessageTime > 140) {
+ saveButtonMessage = null;
+ saveButtonTooltipMessage = null;
+ saveButtonMessageTime = 0;
+ } else {
+ saveButtonMessageTime++;
+ categoryTab.saveFinishedButton.setMessage(saveButtonMessage);
+ if (saveButtonTooltipMessage != null) {
+ categoryTab.saveFinishedButton.setTooltip(saveButtonTooltipMessage);
+ }
}
}
}
@@ -141,7 +146,7 @@ public class YACLScreen extends Screen {
private void setSaveButtonMessage(Component message, Component tooltip) {
saveButtonMessage = message;
- saveButtonTooltipMessage = tooltip;
+ saveButtonTooltipMessage = Tooltip.create(tooltip);
saveButtonMessageTime = 0;
}
@@ -222,7 +227,7 @@ public class YACLScreen extends Screen {
private final Tooltip tooltip;
private ListHolderWidget<OptionListWidget> optionList;
- private final Button saveFinishedButton;
+ public final Button saveFinishedButton;
private final Button cancelResetButton;
private final Button undoButton;
private final SearchFieldWidget searchField;
@@ -310,7 +315,6 @@ public class YACLScreen extends Screen {
@Override
public void tick() {
updateButtons();
- searchField.tick();
descriptionWidget.tick();
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java b/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java
index 5590dbf..32d7561 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java
@@ -80,11 +80,11 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
if (!isAvailable() || (!isMouseOver(mouseX, mouseY)) || (!Screen.hasShiftDown() && !Screen.hasControlDown()))
return false;
- incrementValue(amount);
+ incrementValue(vertical);
return true;
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
index 5059874..df28d27 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
@@ -67,8 +67,8 @@ public class ListHolderWidget<T extends ElementListWidgetExt<?>> extends Abstrac
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- return this.list.mouseScrolled(mouseX, mouseY, amount);
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ return this.list.mouseScrolled(mouseX, mouseY, horizontal, vertical);
}
@Override
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
index da1965f..66ba6a3 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
@@ -77,8 +77,8 @@ public class ScrollableNavigationBar extends TabNavigationBar {
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- this.setScrollOffset(this.scrollOffset - (int)(amount*10));
+ public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
+ this.setScrollOffset(this.scrollOffset - (int)(vertical*15));
return true;
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
index 3b29594..8ddc5c7 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
@@ -6,4 +6,6 @@ import org.jetbrains.annotations.Nullable;
public interface TabExt extends Tab {
@Nullable Tooltip getTooltip();
+
+ default void tick() {}
}