Skip to content

Commit

Permalink
Made elements more easily extendable.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Feb 23, 2024
1 parent 2fbbb12 commit 78c9671
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public class GuiButton extends GuiElement<GuiButton> {
public static final int RIGHT_CLICK = 1;
public static final int MIDDLE_CLICK = 2;

private final Map<Integer, Runnable> onClick = new HashMap<>();
private final Map<Integer, Runnable> onPress = new HashMap<>();
private boolean pressed = false;
private Holder<SoundEvent> pressSound = SoundEvents.UI_BUTTON_CLICK;
private Holder<SoundEvent> releaseSound = null;
private Supplier<Boolean> disabled = () -> false;
private Supplier<Boolean> toggleState;
private GuiText label = null;
protected final Map<Integer, Runnable> onClick = new HashMap<>();
protected final Map<Integer, Runnable> onPress = new HashMap<>();
protected boolean pressed = false;
protected Holder<SoundEvent> pressSound = SoundEvents.UI_BUTTON_CLICK;
protected Holder<SoundEvent> releaseSound = null;
protected Supplier<Boolean> disabled = () -> false;
protected Supplier<Boolean> toggleState;
protected GuiText label = null;

/**
* In its default state this is a blank, invisible element that can fire callbacks when pressed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
*/
public class GuiContextMenu extends GuiElement<GuiContextMenu> {

private BiFunction<GuiContextMenu, Supplier<Component>, GuiButton> buttonBuilder = (menu, label) -> GuiButton.flatColourButton(menu, label, hover -> hover ? 0xFF475b6a : 0xFF151515).constrain(HEIGHT, literal(12));
private final Map<Supplier<Component>, Runnable> options = new LinkedHashMap<>();
private final Map<Supplier<Component>, Supplier<List<Component>>> tooltips = new HashMap<>();
private final List<GuiButton> buttons = new ArrayList<>();
private boolean closeOnItemClicked = true;
private boolean closeOnOutsideClick = true;
private boolean actionOnClick = false;
protected BiFunction<GuiContextMenu, Supplier<Component>, GuiButton> buttonBuilder = (menu, label) -> GuiButton.flatColourButton(menu, label, hover -> hover ? 0xFF475b6a : 0xFF151515).constrain(HEIGHT, literal(12));
protected final Map<Supplier<Component>, Runnable> options = new LinkedHashMap<>();
protected final Map<Supplier<Component>, Supplier<List<Component>>> tooltips = new HashMap<>();
protected final List<GuiButton> buttons = new ArrayList<>();
protected boolean closeOnItemClicked = true;
protected boolean closeOnOutsideClick = true;
protected boolean actionOnClick = false;

public GuiContextMenu(ModularGui gui) {
super(gui.getRoot());
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
* Created by brandon3055 on 10/09/2023
*/
public class GuiDVD extends GuiElement<GuiDVD> implements ContentElement<GuiElement<?>> {
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<Integer> onBounce = bounce -> {
protected final GuiElement<?> movingElement;
protected double xOffset = 0;
protected double yOffset = 0;
protected Vector2d velocity = null;
protected int bounce = 0;
protected Consumer<Integer> onBounce = bounce -> {
};

public GuiDVD(@NotNull GuiParent<?> parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
public class GuiDialog extends GuiElement<GuiDialog> {

private boolean blockKeyInput = true;
private boolean blockMouseInput = true;
protected boolean blockKeyInput = true;
protected boolean blockMouseInput = true;

protected GuiDialog(@NotNull GuiParent<?> parent) {
super(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class GuiEnergyBar extends GuiElement<GuiEnergyBar> implements Background
public static final Material EMPTY = CCGuiTextures.getUncached("widgets/energy_empty");
public static final Material FULL = CCGuiTextures.getUncached("widgets/energy_full");

private Supplier<Long> energy = () -> 0L;
private Supplier<Long> capacity = () -> 0L;
private Material emptyTexture = EMPTY;
private Material fullTexture = FULL;
private BiFunction<Long, Long, List<Component>> toolTipFormatter;
protected Supplier<Long> energy = () -> 0L;
protected Supplier<Long> capacity = () -> 0L;
protected Material emptyTexture = EMPTY;
protected Material fullTexture = FULL;
protected BiFunction<Long, Long, List<Component>> toolTipFormatter;

public GuiEnergyBar(@NotNull GuiParent<?> parent) {
super(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@
*/
public class GuiEntityRenderer extends GuiElement<GuiEntityRenderer> implements BackgroundRender {
public static final Logger LOGGER = LogManager.getLogger();
private static final Map<ResourceLocation, Entity> entityCache = new HashMap<>();
private static final List<ResourceLocation> invalidEntities = new ArrayList<>();

private Supplier<Float> rotationSpeed = () -> 1F;
private Supplier<Float> lockedRotation = () -> 0F;
private Entity entity;
private ResourceLocation entityName;
private boolean invalidEntity = false;
private Supplier<Boolean> rotationLocked = () -> false;
private Supplier<Boolean> trackMouse = () -> false;
private Supplier<Boolean> drawName = () -> false;
protected static final Map<ResourceLocation, Entity> entityCache = new HashMap<>();
protected static final List<ResourceLocation> invalidEntities = new ArrayList<>();

protected Supplier<Float> rotationSpeed = () -> 1F;
protected Supplier<Float> lockedRotation = () -> 0F;
protected Entity entity;
protected ResourceLocation entityName;
protected boolean invalidEntity = false;
protected Supplier<Boolean> rotationLocked = () -> false;
protected Supplier<Boolean> trackMouse = () -> false;
protected Supplier<Boolean> drawName = () -> false;
public boolean force2dSize = false;

public GuiEntityRenderer(@NotNull GuiParent<?> parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*/
public class GuiEventProvider extends GuiElement<GuiEventProvider> {

private boolean ignoreConsumed = false;
private final List<TriConsumer<Double, Double, Integer>> clickListeners = new ArrayList<>();
private final List<TriConsumer<Double, Double, Integer>> releaseListeners = new ArrayList<>();
private final List<BiConsumer<Double, Double>> movedListeners = new ArrayList<>();
private final List<TriConsumer<Double, Double, Double>> scrollListeners = new ArrayList<>();
private final List<TriConsumer<Integer, Integer, Integer>> keyPressListeners = new ArrayList<>();
private final List<TriConsumer<Integer, Integer, Integer>> keyReleaseListeners = new ArrayList<>();
private final List<BiConsumer<Character, Integer>> charTypedListeners = new ArrayList<>();
protected boolean ignoreConsumed = false;
protected final List<TriConsumer<Double, Double, Integer>> clickListeners = new ArrayList<>();
protected final List<TriConsumer<Double, Double, Integer>> releaseListeners = new ArrayList<>();
protected final List<BiConsumer<Double, Double>> movedListeners = new ArrayList<>();
protected final List<TriConsumer<Double, Double, Double>> scrollListeners = new ArrayList<>();
protected final List<TriConsumer<Integer, Integer, Integer>> keyPressListeners = new ArrayList<>();
protected final List<TriConsumer<Integer, Integer, Integer>> keyReleaseListeners = new ArrayList<>();
protected final List<BiConsumer<Character, Integer>> charTypedListeners = new ArrayList<>();

public GuiEventProvider(@NotNull GuiParent<?> parent) {
super(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public class GuiFluidTank extends GuiElement<GuiFluidTank> 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<Long> capacity = () -> 10000L;
private Supplier<FluidStack> fluidStack = () -> FluidStack.EMPTY;
protected int gaugeColour = 0xFF909090;
protected boolean drawGauge = true;
protected Material window = null;
protected Supplier<Long> capacity = () -> 10000L;
protected Supplier<FluidStack> fluidStack = () -> FluidStack.EMPTY;

private BiFunction<FluidStack, Long, List<Component>> toolTipFormatter;
protected BiFunction<FluidStack, Long, List<Component>> toolTipFormatter;

public GuiFluidTank(@NotNull GuiParent<?> parent) {
super(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
* Created by brandon3055 on 03/09/2023
*/
public class GuiItemStack extends GuiElement<GuiItemStack> implements BackgroundRender {
private Supplier<ItemStack> stack;
private Supplier<Boolean> decorate = () -> true;
private Supplier<Boolean> toolTip = () -> true;
protected Supplier<ItemStack> stack;
protected Supplier<Boolean> decorate = () -> true;
protected Supplier<Boolean> toolTip = () -> true;

public GuiItemStack(@NotNull GuiParent<?> parent) {
this(parent, () -> ItemStack.EMPTY);
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/codechicken/lib/gui/modular/elements/GuiList.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public class GuiList<E> extends GuiElement<GuiList<E>> {
* 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<E> listContent = new ArrayList<>();
private final Map<E, GuiElement<?>> elementMap = new HashMap<>();
private final LinkedList<GuiElement<?>> visible = new LinkedList<>();
private Predicate<E> filter = e -> true;

private BiFunction<GuiList<E>, 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<E> listContent = new ArrayList<>();
protected final Map<E, GuiElement<?>> elementMap = new HashMap<>();
protected final LinkedList<GuiElement<?>> visible = new LinkedList<>();
protected Predicate<E> filter = e -> true;

protected BiFunction<GuiList<E>, 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
* Created by brandon3055 on 13/11/2023
*/
public class GuiManipulable extends GuiElement<GuiManipulable> implements ContentElement<GuiElement<?>> {
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;
Expand Down Expand Up @@ -76,11 +76,11 @@ public class GuiManipulable extends GuiElement<GuiManipulable> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
*/
public class GuiProgressIcon extends GuiElement<GuiProgressIcon> implements BackgroundRender {

private Material background = null;
private Material animated;
private Supplier<Double> progress = () -> 0D;
private Direction direction = Direction.RIGHT;
protected Material background = null;
protected Material animated;
protected Supplier<Double> progress = () -> 0D;
protected Direction direction = Direction.RIGHT;

public GuiProgressIcon(@NotNull GuiParent<?> parent, Material animated) {
super(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* Created by brandon3055 on 28/08/2023
*/
public class GuiRectangle extends GuiElement<GuiRectangle> implements BackgroundRender {
private Supplier<Integer> fill = null;
private Supplier<Integer> border = null;
protected Supplier<Integer> fill = null;
protected Supplier<Integer> border = null;

private Supplier<Double> borderWidth = () -> 1D;
protected Supplier<Double> borderWidth = () -> 1D;

private Supplier<Integer> shadeTopLeft;
private Supplier<Integer> shadeBottomRight;
private Supplier<Integer> shadeCorners;
protected Supplier<Integer> shadeTopLeft;
protected Supplier<Integer> shadeBottomRight;
protected Supplier<Integer> shadeCorners;

/**
* @param parent parent {@link GuiParent}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class GuiScrolling extends GuiElement<GuiScrolling> 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}.
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/codechicken/lib/gui/modular/elements/GuiSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
* Created by brandon3055 on 02/09/2023
*/
public class GuiSlider extends GuiElement<GuiSlider> {
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.
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public class GuiSlots extends GuiElement<GuiSlots> 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<Integer, Material> slotIcons = slot -> null;
private Function<Integer, Integer> 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<Integer, Material> slotIcons = slot -> null;
protected Function<Integer, Integer> highlightColour = slot -> 0x80ffffff;
protected int xSlotSpacing = 0;
protected int ySlotSpacing = 0;

/**
* @param slots The slot group containing the slots that this element will manage.
Expand Down
Loading

0 comments on commit 78c9671

Please sign in to comment.