From 12f1bfdd7e18f2067ca532292754d451dc39f4bf Mon Sep 17 00:00:00 2001 From: brandon3055 Date: Sat, 24 Feb 2024 07:56:48 +1100 Subject: [PATCH] Made elements more easily extendable. --- .../lib/gui/modular/elements/GuiButton.java | 16 +++--- .../gui/modular/elements/GuiColourPicker.java | 8 +-- .../gui/modular/elements/GuiContextMenu.java | 16 +++--- .../lib/gui/modular/elements/GuiDVD.java | 14 +++--- .../lib/gui/modular/elements/GuiDialog.java | 6 +-- .../gui/modular/elements/GuiEnergyBar.java | 10 ++-- .../modular/elements/GuiEntityRenderer.java | 22 ++++---- .../modular/elements/GuiEventProvider.java | 16 +++--- .../gui/modular/elements/GuiFluidTank.java | 14 +++--- .../gui/modular/elements/GuiItemStack.java | 6 +-- .../lib/gui/modular/elements/GuiList.java | 28 +++++------ .../gui/modular/elements/GuiManipulable.java | 32 ++++++------ .../gui/modular/elements/GuiProgressIcon.java | 8 +-- .../gui/modular/elements/GuiRectangle.java | 12 ++--- .../gui/modular/elements/GuiScrolling.java | 14 +++--- .../lib/gui/modular/elements/GuiSlider.java | 28 +++++------ .../lib/gui/modular/elements/GuiSlots.java | 24 ++++----- .../lib/gui/modular/elements/GuiText.java | 18 +++---- .../gui/modular/elements/GuiTextField.java | 50 +++++++++---------- .../lib/gui/modular/elements/GuiTextList.java | 14 +++--- .../lib/gui/modular/elements/GuiTexture.java | 6 +-- 21 files changed, 181 insertions(+), 181 deletions(-) diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java index b8df4d2b..305a7f42 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java @@ -27,14 +27,14 @@ public class GuiButton extends GuiElement { public static final int RIGHT_CLICK = 1; public static final int MIDDLE_CLICK = 2; - private final Map onClick = new HashMap<>(); - private final Map onPress = new HashMap<>(); - private boolean pressed = false; - private Holder pressSound = SoundEvents.UI_BUTTON_CLICK; - private Holder releaseSound = null; - private Supplier disabled = () -> false; - private Supplier toggleState; - private GuiText label = null; + protected final Map onClick = new HashMap<>(); + protected final Map onPress = new HashMap<>(); + protected boolean pressed = false; + protected Holder pressSound = SoundEvents.UI_BUTTON_CLICK; + protected Holder releaseSound = null; + protected Supplier disabled = () -> false; + protected Supplier toggleState; + protected GuiText label = null; /** * In its default state this is a blank, invisible element that can fire callbacks when pressed. diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java index c576a7e8..52b32645 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java @@ -18,9 +18,9 @@ */ public class GuiColourPicker extends GuiManipulable { - private ColourState colourState = ColourState.create(); - private GuiButton okButton; - private GuiButton cancelButton; + protected ColourState colourState = ColourState.create(); + protected GuiButton okButton; + protected GuiButton cancelButton; public GuiColourPicker(@NotNull GuiParent parent) { super(parent); @@ -121,7 +121,7 @@ public static SliderBG makeSlider(GuiElement background, int colour, SliderSt return slideBG; } - private static boolean validHex(String value) { + protected static boolean validHex(String value) { try { Integer.parseUnsignedInt(value, 16); return true; diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java index 704c701b..5d73d766 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java @@ -21,13 +21,13 @@ */ public class GuiContextMenu extends GuiElement { - private BiFunction, GuiButton> buttonBuilder = (menu, label) -> GuiButton.flatColourButton(menu, label, hover -> hover ? 0xFF475b6a : 0xFF151515).constrain(HEIGHT, literal(12)); - private final Map, Runnable> options = new LinkedHashMap<>(); - private final Map, Supplier>> tooltips = new HashMap<>(); - private final List buttons = new ArrayList<>(); - private boolean closeOnItemClicked = true; - private boolean closeOnOutsideClick = true; - private boolean actionOnClick = false; + protected BiFunction, GuiButton> buttonBuilder = (menu, label) -> GuiButton.flatColourButton(menu, label, hover -> hover ? 0xFF475b6a : 0xFF151515).constrain(HEIGHT, literal(12)); + protected final Map, Runnable> options = new LinkedHashMap<>(); + protected final Map, Supplier>> tooltips = new HashMap<>(); + protected final List buttons = new ArrayList<>(); + protected boolean closeOnItemClicked = true; + protected boolean closeOnOutsideClick = true; + protected boolean actionOnClick = false; public GuiContextMenu(ModularGui gui) { super(gui.getRoot()); @@ -90,7 +90,7 @@ public GuiContextMenu addOption(Supplier label, Runnable action, Comp return addOption(label, () -> List.of(tooltip), action); } - private void rebuildButtons() { + protected void rebuildButtons() { buttons.forEach(this::removeChild); buttons.clear(); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java index a3195c62..0ddd272e 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java @@ -19,14 +19,14 @@ * Created by brandon3055 on 10/09/2023 */ public class GuiDVD extends GuiElement implements ContentElement> { - private static final Random randy = new Random(); + protected static final Random randy = new Random(); - private final GuiElement movingElement; - private double xOffset = 0; - private double yOffset = 0; - private Vector2d velocity = null; - private int bounce = 0; - private Consumer onBounce = bounce -> { + protected final GuiElement movingElement; + protected double xOffset = 0; + protected double yOffset = 0; + protected Vector2d velocity = null; + protected int bounce = 0; + protected Consumer onBounce = bounce -> { }; public GuiDVD(@NotNull GuiParent parent) { diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiDialog.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiDialog.java index 064e1f9f..ed0ad5a4 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiDialog.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiDialog.java @@ -24,8 +24,8 @@ */ public class GuiDialog extends GuiElement { - private boolean blockKeyInput = true; - private boolean blockMouseInput = true; + protected boolean blockKeyInput = true; + protected boolean blockMouseInput = true; protected GuiDialog(@NotNull GuiParent parent) { super(parent); @@ -216,7 +216,7 @@ public static GuiDialog optionsDialog(@NotNull GuiParent parent, @Nullable Co return dialog; } - private static GuiButton defaultButton(GuiDialog dialog, Option option) { + protected static GuiButton defaultButton(GuiDialog dialog, Option option) { GuiButton button = new GuiButton(dialog); GuiRectangle background = new GuiRectangle(button) diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiEnergyBar.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiEnergyBar.java index f91ce143..1359f37d 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiEnergyBar.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiEnergyBar.java @@ -29,11 +29,11 @@ public class GuiEnergyBar extends GuiElement implements Background public static final Material EMPTY = CCGuiTextures.getUncached("widgets/energy_empty"); public static final Material FULL = CCGuiTextures.getUncached("widgets/energy_full"); - private Supplier energy = () -> 0L; - private Supplier capacity = () -> 0L; - private Material emptyTexture = EMPTY; - private Material fullTexture = FULL; - private BiFunction> toolTipFormatter; + protected Supplier energy = () -> 0L; + protected Supplier capacity = () -> 0L; + protected Material emptyTexture = EMPTY; + protected Material fullTexture = FULL; + protected BiFunction> toolTipFormatter; public GuiEnergyBar(@NotNull GuiParent parent) { super(parent); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiEntityRenderer.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiEntityRenderer.java index f3e3b0db..836c78c7 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiEntityRenderer.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiEntityRenderer.java @@ -38,17 +38,17 @@ */ public class GuiEntityRenderer extends GuiElement implements BackgroundRender { public static final Logger LOGGER = LogManager.getLogger(); - private static final Map entityCache = new HashMap<>(); - private static final List invalidEntities = new ArrayList<>(); - - private Supplier rotationSpeed = () -> 1F; - private Supplier lockedRotation = () -> 0F; - private Entity entity; - private ResourceLocation entityName; - private boolean invalidEntity = false; - private Supplier rotationLocked = () -> false; - private Supplier trackMouse = () -> false; - private Supplier drawName = () -> false; + protected static final Map entityCache = new HashMap<>(); + protected static final List invalidEntities = new ArrayList<>(); + + protected Supplier rotationSpeed = () -> 1F; + protected Supplier lockedRotation = () -> 0F; + protected Entity entity; + protected ResourceLocation entityName; + protected boolean invalidEntity = false; + protected Supplier rotationLocked = () -> false; + protected Supplier trackMouse = () -> false; + protected Supplier drawName = () -> false; public boolean force2dSize = false; public GuiEntityRenderer(@NotNull GuiParent parent) { diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiEventProvider.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiEventProvider.java index 393ba6c3..20bd9123 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiEventProvider.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiEventProvider.java @@ -13,14 +13,14 @@ */ public class GuiEventProvider extends GuiElement { - private boolean ignoreConsumed = false; - private final List> clickListeners = new ArrayList<>(); - private final List> releaseListeners = new ArrayList<>(); - private final List> movedListeners = new ArrayList<>(); - private final List> scrollListeners = new ArrayList<>(); - private final List> keyPressListeners = new ArrayList<>(); - private final List> keyReleaseListeners = new ArrayList<>(); - private final List> charTypedListeners = new ArrayList<>(); + protected boolean ignoreConsumed = false; + protected final List> clickListeners = new ArrayList<>(); + protected final List> releaseListeners = new ArrayList<>(); + protected final List> movedListeners = new ArrayList<>(); + protected final List> scrollListeners = new ArrayList<>(); + protected final List> keyPressListeners = new ArrayList<>(); + protected final List> keyReleaseListeners = new ArrayList<>(); + protected final List> charTypedListeners = new ArrayList<>(); public GuiEventProvider(@NotNull GuiParent parent) { super(parent); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiFluidTank.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiFluidTank.java index 12ce2600..838ebe6e 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiFluidTank.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiFluidTank.java @@ -39,13 +39,13 @@ public class GuiFluidTank extends GuiElement implements Background //TODO make a better texture, This feels a little too.. cluttered. public static final Material DEFAULT_WINDOW = CCGuiTextures.getUncached("widgets/tank_window"); - private int gaugeColour = 0xFF909090; - private boolean drawGauge = true; - private Material window = null; - private Supplier capacity = () -> 10000L; - private Supplier fluidStack = () -> FluidStack.EMPTY; + protected int gaugeColour = 0xFF909090; + protected boolean drawGauge = true; + protected Material window = null; + protected Supplier capacity = () -> 10000L; + protected Supplier fluidStack = () -> FluidStack.EMPTY; - private BiFunction> toolTipFormatter; + protected BiFunction> toolTipFormatter; public GuiFluidTank(@NotNull GuiParent parent) { super(parent); @@ -166,7 +166,7 @@ public void renderBackground(GuiRender render, double mouseX, double mouseY, flo } } - private double computeGaugeSpacing() { + protected double computeGaugeSpacing() { double ySize = ySize(); double capacity = getCapacity(); if (ySize / (capacity / 100D) > 3) return ySize / (capacity / 100D); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java index 099d2c8a..d3959a17 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java @@ -20,9 +20,9 @@ * Created by brandon3055 on 03/09/2023 */ public class GuiItemStack extends GuiElement implements BackgroundRender { - private Supplier stack; - private Supplier decorate = () -> true; - private Supplier toolTip = () -> true; + protected Supplier stack; + protected Supplier decorate = () -> true; + protected Supplier toolTip = () -> true; public GuiItemStack(@NotNull GuiParent parent) { this(parent, () -> ItemStack.EMPTY); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiList.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiList.java index fe26fb75..393561e2 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiList.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiList.java @@ -35,19 +35,19 @@ public class GuiList extends GuiElement> { * This is made available primarily for debugging purposes where it can be useful to see what's going on behind the scenes. */ public boolean enableScissor = true; - private double yScrollPos = 0; - private double lastWidth = 0; - private double contentHeight = 0; - private double itemSpacing = 1; - private boolean rebuild = true; - private GuiSlider hiddenBar = null; - - private final List listContent = new ArrayList<>(); - private final Map> elementMap = new HashMap<>(); - private final LinkedList> visible = new LinkedList<>(); - private Predicate filter = e -> true; - - private BiFunction, E, ? extends GuiElement> displayBuilder = (parent, e) -> { + protected double yScrollPos = 0; + protected double lastWidth = 0; + protected double contentHeight = 0; + protected double itemSpacing = 1; + protected boolean rebuild = true; + protected GuiSlider hiddenBar = null; + + protected final List listContent = new ArrayList<>(); + protected final Map> elementMap = new HashMap<>(); + protected final LinkedList> visible = new LinkedList<>(); + protected Predicate filter = e -> true; + + protected BiFunction, E, ? extends GuiElement> displayBuilder = (parent, e) -> { GuiText text = new GuiText(parent, () -> Component.literal(String.valueOf(e))).setWrap(true); text.constrain(GeoParam.HEIGHT, Constraint.dynamic(() -> (double) font().wordWrapHeight(text.getText(), (int) text.xSize()))); return text; @@ -190,7 +190,7 @@ public void scrollTo(E scrollTo) { } } - private void updateVisible() { + protected void updateVisible() { visible.forEach(this::removeChild); visible.clear(); contentHeight = 0; diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java index d95835e4..0c7e29da 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java @@ -33,17 +33,17 @@ * Created by brandon3055 on 13/11/2023 */ public class GuiManipulable extends GuiElement implements ContentElement> { - private final GuiElement contentElement; - - private int dragXOffset = 0; - private int dragYOffset = 0; - private boolean isDragging = false; - private boolean dragPos = false; - private boolean dragTop = false; - private boolean dragLeft = false; - private boolean dragBottom = false; - private boolean dragRight = false; - private boolean enableCursors = false; + protected final GuiElement contentElement; + + protected int dragXOffset = 0; + protected int dragYOffset = 0; + protected boolean isDragging = false; + protected boolean dragPos = false; + protected boolean dragTop = false; + protected boolean dragLeft = false; + protected boolean dragBottom = false; + protected boolean dragRight = false; + protected boolean enableCursors = false; //Made available for external position restraints public int xMin = 0; @@ -76,11 +76,11 @@ public class GuiManipulable extends GuiElement implements Conten } }; - private GuiElement moveHandle; - private GuiElement leftHandle; - private GuiElement rightHandle; - private GuiElement topHandle; - private GuiElement bottomHandle; + protected GuiElement moveHandle; + protected GuiElement leftHandle; + protected GuiElement rightHandle; + protected GuiElement topHandle; + protected GuiElement bottomHandle; public GuiManipulable(@NotNull GuiParent parent) { super(parent); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiProgressIcon.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiProgressIcon.java index 3e56ce61..a820c56e 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiProgressIcon.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiProgressIcon.java @@ -25,10 +25,10 @@ */ public class GuiProgressIcon extends GuiElement implements BackgroundRender { - private Material background = null; - private Material animated; - private Supplier progress = () -> 0D; - private Direction direction = Direction.RIGHT; + protected Material background = null; + protected Material animated; + protected Supplier progress = () -> 0D; + protected Direction direction = Direction.RIGHT; public GuiProgressIcon(@NotNull GuiParent parent, Material animated) { super(parent); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiRectangle.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiRectangle.java index 0d034702..897655d6 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiRectangle.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiRectangle.java @@ -15,14 +15,14 @@ * Created by brandon3055 on 28/08/2023 */ public class GuiRectangle extends GuiElement implements BackgroundRender { - private Supplier fill = null; - private Supplier border = null; + protected Supplier fill = null; + protected Supplier border = null; - private Supplier borderWidth = () -> 1D; + protected Supplier borderWidth = () -> 1D; - private Supplier shadeTopLeft; - private Supplier shadeBottomRight; - private Supplier shadeCorners; + protected Supplier shadeTopLeft; + protected Supplier shadeBottomRight; + protected Supplier shadeCorners; /** * @param parent parent {@link GuiParent}. diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiScrolling.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiScrolling.java index c0c5f9e0..ce4e966d 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiScrolling.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiScrolling.java @@ -39,12 +39,12 @@ public class GuiScrolling extends GuiElement implements ContentEle * This is made available primarily for debugging purposes where it can be useful to see what's going on behind the scenes. */ public boolean enableScissor = true; - private GuiElement contentElement; - private double xScrollPos = 0; - private double yScrollPos = 0; - private double contentWidth = 0; - private double contentHeight = 0; - private boolean setup = false; + protected GuiElement contentElement; + protected double xScrollPos = 0; + protected double yScrollPos = 0; + protected double contentWidth = 0; + protected double contentHeight = 0; + protected boolean setup = false; /** * @param parent parent {@link GuiParent}. @@ -161,7 +161,7 @@ protected boolean renderChild(GuiElement child, GuiRender render, double mous return ret; } - private class ContentElement extends GuiElement { + protected class ContentElement extends GuiElement { /** * @param parent parent {@link GuiParent}. */ diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiSlider.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiSlider.java index 2157ccf8..639c15e9 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiSlider.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiSlider.java @@ -19,24 +19,24 @@ * Created by brandon3055 on 02/09/2023 */ public class GuiSlider extends GuiElement { - private final Axis axis; - private SliderState state = SliderState.create(0.1); - private GuiElement slider; - private double outOfBoundsDist = 50; - private GuiElement scrollableElement; - - private int dragButton = GuiButton.LEFT_CLICK; - private int scrollDragButton = GuiButton.MIDDLE_CLICK; - private boolean middleClickScroll = false; + protected final Axis axis; + protected SliderState state = SliderState.create(0.1); + protected GuiElement slider; + protected double outOfBoundsDist = 50; + protected GuiElement scrollableElement; + + protected int dragButton = GuiButton.LEFT_CLICK; + protected int scrollDragButton = GuiButton.MIDDLE_CLICK; + protected boolean middleClickScroll = false; /** * This should theoretically never be needed, But just in case... */ public boolean invertDragScroll = false; - private boolean dragging = false; - private double slideStartPos = 0; - private Position clickPos = Position.create(0, 0); - private boolean scrollableDragging = false; + protected boolean dragging = false; + protected double slideStartPos = 0; + protected Position clickPos = Position.create(0, 0); + protected boolean scrollableDragging = false; /** * Creates a basic gui slider that moves along the specified axis. @@ -230,7 +230,7 @@ public void mouseMoved(double mouseX, double mouseY) { super.mouseMoved(mouseX, mouseY); } - private void handleDrag(double mouseX, double mouseY) { + protected void handleDrag(double mouseX, double mouseY) { Position mousePos = Position.create(mouseX, mouseY); Rectangle rect = dragging || scrollableElement == null ? getRectangle() : scrollableElement.getRectangle(); diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java index b798be25..c07e038a 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java @@ -32,17 +32,17 @@ public class GuiSlots extends GuiElement implements BackgroundRender { public static final Material[] ARMOR_SLOTS = new Material[]{Material.fromAtlas(BLOCK_ATLAS, "item/empty_armor_slot_helmet"), Material.fromAtlas(BLOCK_ATLAS, "item/empty_armor_slot_chestplate"), Material.fromAtlas(BLOCK_ATLAS, "item/empty_armor_slot_leggings"), Material.fromAtlas(BLOCK_ATLAS, "item/empty_armor_slot_boots")}; public static final Material OFF_HAND_SLOT = Material.fromAtlas(BLOCK_ATLAS, "item/empty_armor_slot_shield"); - private final int firstSlot; - private final int slotCount; - private final int columns; - private final SlotGroup slots; - private final ContainerScreenAccess screenAccess; - - private Material slotTexture = CCGuiTextures.getUncached("widgets/slot"); - private Function slotIcons = slot -> null; - private Function highlightColour = slot -> 0x80ffffff; - private int xSlotSpacing = 0; - private int ySlotSpacing = 0; + protected final int firstSlot; + protected final int slotCount; + protected final int columns; + protected final SlotGroup slots; + protected final ContainerScreenAccess screenAccess; + + protected Material slotTexture = CCGuiTextures.getUncached("widgets/slot"); + protected Function slotIcons = slot -> null; + protected Function highlightColour = slot -> 0x80ffffff; + protected int xSlotSpacing = 0; + protected int ySlotSpacing = 0; /** * @param slots The slot group containing the slots that this element will manage. @@ -243,7 +243,7 @@ public double getBackgroundDepth() { return 33; } - private void updateSlots(GuiElement root) { + protected void updateSlots(GuiElement root) { int columns = Math.min(this.columns, slots.size()); int rows = Math.max(1, slots.size() / columns); double width = (columns * 18) + (columns - 1) * xSlotSpacing; diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiText.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiText.java index f553d660..cc19eaa7 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiText.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiText.java @@ -27,15 +27,15 @@ * Created by brandon3055 on 31/08/2023 */ public class GuiText extends GuiElement implements ForegroundRender { - private Supplier text; - private Supplier shadow = () -> true; - private Supplier textColour = () -> 0xFFFFFFFF; - private Supplier rotation = null; - private Position rotatePoint = Position.create(() -> xSize() / 2, () -> ySize() / 2); - private boolean trim = false; - private boolean wrap = false; - private boolean scroll = true; - private Align alignment = Align.CENTER; + protected Supplier text; + protected Supplier shadow = () -> true; + protected Supplier textColour = () -> 0xFFFFFFFF; + protected Supplier rotation = null; + protected Position rotatePoint = Position.create(() -> xSize() / 2, () -> ySize() / 2); + protected boolean trim = false; + protected boolean wrap = false; + protected boolean scroll = true; + protected Align alignment = Align.CENTER; //TODO, Arbitrary rotation is fun, But may want to switch to Axis, with option for "reverse" /** diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiTextField.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiTextField.java index c9c0a62f..ee84879c 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiTextField.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiTextField.java @@ -36,36 +36,36 @@ * Created by brandon3055 on 03/09/2023 */ public class GuiTextField extends GuiElement implements BackgroundRender { - private static final RenderType HIGHLIGHT_TYPE = RenderType.create("text_field_highlight", DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS, 256, RenderType.CompositeState.builder() + protected static final RenderType HIGHLIGHT_TYPE = RenderType.create("text_field_highlight", DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS, 256, RenderType.CompositeState.builder() .setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorShader)) .setColorLogicState(RenderStateShard.OR_REVERSE_COLOR_LOGIC) .createCompositeState(false)); - private int tick; - private int cursorPos; - private int maxLength = 32; - private int displayPos; - private int highlightPos; - private boolean focused; - private boolean shiftPressed; + protected int tick; + protected int cursorPos; + protected int maxLength = 32; + protected int displayPos; + protected int highlightPos; + protected boolean focused; + protected boolean shiftPressed; - private Supplier isEditable = () -> true; - private Supplier isFocusable = () -> true; - private Supplier canLoseFocus = () -> true; + protected Supplier isEditable = () -> true; + protected Supplier isFocusable = () -> true; + protected Supplier canLoseFocus = () -> true; - private Runnable onEditComplete = null; - private Runnable onEnterPressed = null; + protected Runnable onEditComplete = null; + protected Runnable onEnterPressed = null; - private TextState textState = TextState.simpleState(""); - private Supplier shadow = () -> true; - private Supplier textColor = () -> 0xe0e0e0; + protected TextState textState = TextState.simpleState(""); + protected Supplier shadow = () -> true; + protected Supplier textColor = () -> 0xe0e0e0; - private Supplier suggestion = null; - private Supplier suggestionColour = () -> 0x7f7f80; - private Supplier suggestionShadow = () -> true; + protected Supplier suggestion = null; + protected Supplier suggestionColour = () -> 0x7f7f80; + protected Supplier suggestionShadow = () -> true; - private Predicate filter = Objects::nonNull; - private BiFunction formatter = (string, pos) -> FormattedCharSequence.forward(string, Style.EMPTY); + protected Predicate filter = Objects::nonNull; + protected BiFunction formatter = (string, pos) -> FormattedCharSequence.forward(string, Style.EMPTY); public GuiTextField(@NotNull GuiParent parent) { super(parent); @@ -261,7 +261,7 @@ public GuiTextField setMaxLength(int newWidth) { return this; } - private int getMaxLength() { + protected int getMaxLength() { return maxLength; } @@ -315,7 +315,7 @@ public void insertText(String text) { } } - private void deleteText(int i) { + protected void deleteText(int i) { if (Screen.hasControlDown()) { deleteWords(i); } else { @@ -357,7 +357,7 @@ public int getWordPosition(int i) { return getWordPosition(i, getCursorPosition()); } - private int getWordPosition(int i, int i1) { + protected int getWordPosition(int i, int i1) { return getWordPosition(i, i1, true); } @@ -389,7 +389,7 @@ public void moveCursor(int pos) { moveCursorTo(getCursorPos(pos)); } - private int getCursorPos(int i) { + protected int getCursorPos(int i) { return Util.offsetByCodepoints(getValue(), cursorPos, i); } diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiTextList.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiTextList.java index 865b935c..c7c5c253 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiTextList.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiTextList.java @@ -20,13 +20,13 @@ * Created by brandon3055 on 10/10/2023 */ public class GuiTextList extends GuiElement implements ForegroundRender { - private Supplier> text; - private Supplier shadow = () -> true; - private Supplier textColour = () -> 0xFFFFFFFF; - private boolean scroll = true; - private Align horizontalAlign = Align.CENTER; - private Align verticalAlign = Align.TOP; - private int lineSpacing = 0; + protected Supplier> text; + protected Supplier shadow = () -> true; + protected Supplier textColour = () -> 0xFFFFFFFF; + protected boolean scroll = true; + protected Align horizontalAlign = Align.CENTER; + protected Align verticalAlign = Align.TOP; + protected int lineSpacing = 0; /** * @param parent parent {@link GuiParent}. diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiTexture.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiTexture.java index da5c0577..b9ef8439 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiTexture.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiTexture.java @@ -14,9 +14,9 @@ * Created by brandon3055 on 28/08/2023 */ public class GuiTexture extends GuiElement implements BackgroundRender { - private Supplier getMaterial; - private Supplier colour = () -> 0xFFFFFFFF; - private Borders dynamicBorders = null; + protected Supplier getMaterial; + protected Supplier colour = () -> 0xFFFFFFFF; + protected Borders dynamicBorders = null; /** * @param parent parent {@link GuiParent}.