Skip to content

Commit

Permalink
Move gui components to common
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Sep 21, 2024
1 parent d92c3a2 commit 37098c3
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import org.cyclops.cyclopscore.helper.RenderHelpers;
import org.cyclops.cyclopscore.helper.IModHelpers;

import javax.annotation.Nullable;
import java.awt.*;
Expand Down Expand Up @@ -65,7 +65,7 @@ public WidgetScrollBar(int x, int y, int height, Component narrationMessage,
@Override
public boolean isMouseOver(double x, double y) {
if (scollRegion != null) {
if (RenderHelpers.isPointInRegion(scollRegion, new Point((int) x, (int) y))) {
if (IModHelpers.get().getRenderHelpers().isPointInRegion(scollRegion, new Point((int) x, (int) y))) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cyclops.cyclopscore.client.gui.component.button;

import lombok.Getter;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
Expand All @@ -9,22 +8,22 @@

/**
* A button with an arrow in a certain direction.
* @author rubensworks
*
* @author rubensworks
*/
public class ButtonArrow extends ButtonExtended {

@Getter
private final ButtonArrow.Direction direction;
private final Image[] directionImages;

/**
* Make a new instance.
* @param x X
* @param y Y
*
* @param x X
* @param y Y
* @param narrationMessage The string to print.
* @param pressCallback A callback for when this button was pressed.
* @param direction The direction of the arrow to draw.
* @param pressCallback A callback for when this button was pressed.
* @param direction The direction of the arrow to draw.
*/
public ButtonArrow(int x, int y, Component narrationMessage, Button.OnPress pressCallback, ButtonArrow.Direction direction) {
super(x, y, direction.width, direction.height, narrationMessage, pressCallback, true);
Expand All @@ -33,13 +32,13 @@ public ButtonArrow(int x, int y, Component narrationMessage, Button.OnPress pres
}

protected static Image[] getDirectionImage(ButtonArrow.Direction direction) {
if(direction == Direction.NORTH) {
if (direction == Direction.NORTH) {
return Images.BUTTON_ARROW_UP;
} else if(direction == Direction.EAST) {
} else if (direction == Direction.EAST) {
return Images.BUTTON_ARROW_RIGHT;
} else if(direction == Direction.SOUTH) {
} else if (direction == Direction.SOUTH) {
return Images.BUTTON_ARROW_DOWN;
} else if(direction == Direction.WEST) {
} else if (direction == Direction.WEST) {
return Images.BUTTON_ARROW_LEFT;
}
return null;
Expand All @@ -55,6 +54,10 @@ protected void drawButtonInner(GuiGraphics guiGraphics, int mouseX, int mouseY)

}

public Direction getDirection() {
return this.direction;
}

public enum Direction {

NORTH(15, 10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.cyclops.cyclopscore.client.gui.component.button.ButtonArrow;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;

/**
* A number field which by default only accepts positive numbers.
Expand Down Expand Up @@ -115,7 +115,7 @@ public float validateNumber(float number) {
}

protected int getDiffAmount() {
return MinecraftHelpers.isShifted() ? 10 : 1;
return Screen.hasShiftDown() ? 10 : 1;
}

protected void increase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import lombok.Data;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.resources.ResourceLocation;
import org.cyclops.cyclopscore.helper.RenderHelpers;
import org.cyclops.cyclopscore.helper.IModHelpers;
import org.joml.Matrix4f;

/**
* A wrapper that contains a reference to a {@link net.minecraft.resources.ResourceLocation} and its sheet position.
* @author rubensworks
*/
@Data
public class Image implements IImage {

private final ResourceLocation resourceLocation;
Expand All @@ -29,15 +27,35 @@ public Image(ResourceLocation resourceLocation, int sheetX, int sheetY, int shee
this.sheetHeight = sheetHeight;
}

public ResourceLocation getResourceLocation() {
return resourceLocation;
}

public int getSheetX() {
return sheetX;
}

public int getSheetY() {
return sheetY;
}

public int getSheetWidth() {
return sheetWidth;
}

public int getSheetHeight() {
return sheetHeight;
}

@Override
public void draw(GuiGraphics gui, int x, int y) {
gui.blit(resourceLocation, x, y, sheetX, sheetY, sheetWidth, sheetHeight);
}

@Override
public void drawWithColor(GuiGraphics gui, int x, int y, float r, float g, float b, float a) {
RenderHelpers.bindTexture(resourceLocation);
RenderHelpers.blitColored(gui, x, y, 0, sheetX, sheetY, sheetWidth, sheetHeight, r, g, b, a);
IModHelpers.get().getRenderHelpers().bindTexture(resourceLocation);
IModHelpers.get().getRenderHelpers().blitColored(gui, x, y, 0, sheetX, sheetY, sheetWidth, sheetHeight, r, g, b, a);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package org.cyclops.cyclopscore.client.gui.image;

import net.minecraft.resources.ResourceLocation;
import org.cyclops.cyclopscore.CyclopsCore;
import org.cyclops.cyclopscore.init.ModBase;
import org.cyclops.cyclopscore.helper.CyclopsCoreInstance;

/**
* Default images provided by this mod.
* @author rubensworks
*/
public class Images {

public static final ResourceLocation ICONS = ResourceLocation.fromNamespaceAndPath(CyclopsCore._instance.getModId(),
CyclopsCore._instance.getReferenceValue(ModBase.REFKEY_TEXTURE_PATH_GUI) + "icons.png");
public static final ResourceLocation ICONS = ResourceLocation.fromNamespaceAndPath(CyclopsCoreInstance.MOD.getModId(),
"textures/gui/icons.png");

public static final ResourceLocation BUTTONS = ResourceLocation.fromNamespaceAndPath(CyclopsCore._instance.getModId(),
CyclopsCore._instance.getReferenceValue(ModBase.REFKEY_TEXTURE_PATH_GUI) + "buttons.png");
public static final ResourceLocation BUTTONS = ResourceLocation.fromNamespaceAndPath(CyclopsCoreInstance.MOD.getModId(),
"textures/gui/buttons.png");

public static final ResourceLocation WIDGETS = ResourceLocation.fromNamespaceAndPath(CyclopsCore._instance.getModId(),
CyclopsCore._instance.getReferenceValue(ModBase.REFKEY_TEXTURE_PATH_GUI) + "widgets.png");
public static final ResourceLocation WIDGETS = ResourceLocation.fromNamespaceAndPath(CyclopsCoreInstance.MOD.getModId(),
"textures/gui/widgets.png");

public static final Image ARROW_DOWN = new Image(ICONS, 18, 0, 18, 18);
public static final Image ARROW_UP = new Image(ICONS, 36, 0, 18, 18);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public net.minecraft.client.KeyMapping ALL
# Widgets
public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen isHovering(Lnet/minecraft/world/inventory/Slot;DD)Z
public net.minecraft.client.gui.components.EditBox getEnableBackgroundDrawing()Z
protected net.minecraft.client.gui.components.AbstractButton SPRITES
protected net.minecraft.client.gui.components.AbstractButton f_290895_ # SPRITES

# Menus
public net.minecraft.world.inventory.Slot onSwapCraft(I)V
Expand Down
3 changes: 3 additions & 0 deletions loader-common/src/main/resources/cyclopscore.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ accessible method net/minecraft/client/renderer/blockentity/BlockEntityRenderers
# Screens
accessible class net/minecraft/client/gui/screens/MenuScreens$ScreenConstructor

# Widgets
accessible field net/minecraft/client/gui/components/AbstractButton SPRITES Lnet/minecraft/client/gui/components/WidgetSprites;

# Slot
accessible field net/minecraft/world/inventory/Slot x I
mutable field net/minecraft/world/inventory/Slot x I
Expand Down

0 comments on commit 37098c3

Please sign in to comment.