aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java32
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java14
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java12
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java18
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java109
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java10
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java13
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java7
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java20
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java71
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java36
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java45
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java8
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java43
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java19
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java3
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java134
20 files changed, 493 insertions, 111 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
index 87dfd34..403b5c0 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
@@ -103,15 +103,15 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
if (blockInventory!=null) {
if (slot.inventory==blockInventory) {
//Try to transfer the item from the block into the player's inventory
- if (!this.insertItem(toTransfer, this.playerInventory, true)) {
+ if (!this.insertItem(toTransfer, this.playerInventory, true, player)) {
return ItemStack.EMPTY;
}
- } else if (!this.insertItem(toTransfer, this.blockInventory, false)) { //Try to transfer the item from the player to the block
+ } else if (!this.insertItem(toTransfer, this.blockInventory, false, player)) { //Try to transfer the item from the player to the block
return ItemStack.EMPTY;
}
} else {
//There's no block, just swap between the player's storage and their hotbar
- if (!swapHotbar(toTransfer, slotNumber, this.playerInventory)) {
+ if (!swapHotbar(toTransfer, slotNumber, this.playerInventory, player)) {
return ItemStack.EMPTY;
}
}
@@ -130,9 +130,9 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
}
/** WILL MODIFY toInsert! Returns true if anything was inserted. */
- private boolean insertIntoExisting(ItemStack toInsert, Slot slot) {
+ private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) {
ItemStack curSlotStack = slot.getStack();
- if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack)) {
+ if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canTakeItems(player)) {
int combinedAmount = curSlotStack.getCount() + toInsert.getCount();
if (combinedAmount <= toInsert.getMaxCount()) {
toInsert.setCount(0);
@@ -166,7 +166,7 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
return false;
}
- private boolean insertItem(ItemStack toInsert, Inventory inventory, boolean walkBackwards) {
+ private boolean insertItem(ItemStack toInsert, Inventory inventory, boolean walkBackwards, PlayerEntity player) {
//Make a unified list of slots *only from this inventory*
ArrayList<Slot> inventorySlots = new ArrayList<>();
for(Slot slot : slots) {
@@ -179,13 +179,13 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
if (walkBackwards) {
for(int i=inventorySlots.size()-1; i>=0; i--) {
Slot curSlot = inventorySlots.get(i);
- if (insertIntoExisting(toInsert, curSlot)) inserted = true;
+ if (insertIntoExisting(toInsert, curSlot, player)) inserted = true;
if (toInsert.isEmpty()) break;
}
} else {
for(int i=0; i<inventorySlots.size(); i++) {
Slot curSlot = inventorySlots.get(i);
- if (insertIntoExisting(toInsert, curSlot)) inserted = true;
+ if (insertIntoExisting(toInsert, curSlot, player)) inserted = true;
if (toInsert.isEmpty()) break;
}
@@ -212,7 +212,7 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
return inserted;
}
- private boolean swapHotbar(ItemStack toInsert, int slotNumber, Inventory inventory) {
+ private boolean swapHotbar(ItemStack toInsert, int slotNumber, Inventory inventory, PlayerEntity player) {
//Feel out the slots to see what's storage versus hotbar
ArrayList<Slot> storageSlots = new ArrayList<>();
ArrayList<Slot> hotbarSlots = new ArrayList<>();
@@ -236,7 +236,7 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
//swap from hotbar to storage
for(int i=0; i<storageSlots.size(); i++) {
Slot curSlot = storageSlots.get(i);
- if (insertIntoExisting(toInsert, curSlot)) inserted = true;
+ if (insertIntoExisting(toInsert, curSlot, player)) inserted = true;
if (toInsert.isEmpty()) break;
}
if (!toInsert.isEmpty()) {
@@ -250,7 +250,7 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
//swap from storage to hotbar
for(int i=0; i<hotbarSlots.size(); i++) {
Slot curSlot = hotbarSlots.get(i);
- if (insertIntoExisting(toInsert, curSlot)) inserted = true;
+ if (insertIntoExisting(toInsert, curSlot, player)) inserted = true;
if (toInsert.isEmpty()) break;
}
if (!toInsert.isEmpty()) {
@@ -333,13 +333,19 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
Block b = state.getBlock();
if (b instanceof InventoryProvider) {
- return ((InventoryProvider)b).getInventory(state, world, pos);
+ Inventory inventory = ((InventoryProvider)b).getInventory(state, world, pos);
+ if (inventory != null) {
+ return inventory;
+ }
}
BlockEntity be = world.getBlockEntity(pos);
if (be!=null) {
if (be instanceof InventoryProvider) {
- return ((InventoryProvider)be).getInventory(state, world, pos);
+ Inventory inventory = ((InventoryProvider)be).getInventory(state, world, pos);
+ if (inventory != null) {
+ return inventory;
+ }
} else if (be instanceof Inventory) {
return (Inventory)be;
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java b/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java
index da54dda..84eee0f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java
@@ -13,32 +13,32 @@ public class EmptyInventory implements Inventory {
public void clear() {}
@Override
- public int getInvSize() {
+ public int size() {
return 0;
}
@Override
- public boolean isInvEmpty() {
+ public boolean isEmpty() {
return true;
}
@Override
- public ItemStack getInvStack(int slot) {
+ public ItemStack getStack(int slot) {
return ItemStack.EMPTY;
}
@Override
- public ItemStack takeInvStack(int slot, int count) {
+ public ItemStack removeStack(int slot, int count) {
return ItemStack.EMPTY;
}
@Override
- public ItemStack removeInvStack(int slot) {
+ public ItemStack removeStack(int slot) {
return ItemStack.EMPTY;
}
@Override
- public void setInvStack(int slot, ItemStack stack) {
+ public void setStack(int slot, ItemStack stack) {
}
@Override
@@ -46,7 +46,7 @@ public class EmptyInventory implements Inventory {
}
@Override
- public boolean canPlayerUseInv(PlayerEntity player) {
+ public boolean canPlayerUse(PlayerEntity player) {
return true;
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
index e6b30af..cce4cfe 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
@@ -17,12 +17,12 @@ public class ValidatedSlot extends Slot {
@Override
public boolean canInsert(ItemStack stack) {
- return modifiable && inventory.isValidInvStack(slotNumber, stack);
+ return modifiable && inventory.isValid(slotNumber, stack);
}
@Override
public boolean canTakeItems(PlayerEntity player) {
- return modifiable && inventory.canPlayerUseInv(player);
+ return modifiable && inventory.canPlayerUse(player);
}
@Override
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index 1a8c326..05f3b68 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -5,6 +5,7 @@ import io.github.cottonmc.cotton.gui.widget.WPanel;
import io.github.cottonmc.cotton.gui.widget.WWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@@ -55,7 +56,7 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
public void paint(int mouseX, int mouseY) {
- super.renderBackground();
+ super.renderBackground(ScreenDrawing.matrices);
if (description!=null) {
WPanel root = description.getRootPanel();
@@ -65,16 +66,17 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
if (getTitle() != null) {
- textRenderer.draw(getTitle().asFormattedString(), left, top, description.getTitleColor());
+ textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), left, top, description.getTitleColor());
}
}
@SuppressWarnings("deprecation")
@Override
- public void render(int mouseX, int mouseY, float partialTicks) {
+ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
+ ScreenDrawing.matrices = matrices;
paint(mouseX, mouseY);
- super.render(mouseX, mouseY, partialTicks);
+ super.render(matrices, mouseX, mouseY, partialTicks);
if (description!=null) {
WPanel root = description.getRootPanel();
@@ -222,6 +224,6 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
@Override
public void renderTextHover(Text text, int x, int y) {
- renderTextHoverEffect(text, x, y);
+ renderTextHoverEffect(ScreenDrawing.matrices, text, x, y);
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java
index 6294ac6..0e6fa4f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java
@@ -6,6 +6,7 @@ import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.Window;
+import net.minecraft.client.util.math.MatrixStack;
import java.util.*;
@@ -104,7 +105,8 @@ public enum CottonHud implements HudRenderCallback {
}
@Override
- public void onHudRender(float tickDelta) {
+ public void onHudRender(MatrixStack matrices, float tickDelta) {
+ ScreenDrawing.matrices = matrices;
Window window = MinecraftClient.getInstance().getWindow();
int hudWidth = window.getScaledWidth();
int hudHeight = window.getScaledHeight();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index a9597dc..c64ffa2 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -2,6 +2,7 @@ package io.github.cottonmc.cotton.gui.client;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.DiffuseLighting;
+import net.minecraft.client.util.math.MatrixStack;
import org.lwjgl.glfw.GLFW;
import io.github.cottonmc.cotton.gui.CottonInventoryController;
@@ -182,12 +183,12 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
WWidget child = root.hit(containerX, containerY);
child.onMouseMove(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY());
}
-
+
@Override
- protected void drawBackground(float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way.
+ protected void drawBackground(MatrixStack matrices, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way.
public void paint(int mouseX, int mouseY) {
- super.renderBackground();
+ super.renderBackground(ScreenDrawing.matrices);
if (description!=null) {
WPanel root = description.getRootPanel();
@@ -197,16 +198,17 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
}
if (getTitle() != null) {
- textRenderer.draw(getTitle().asFormattedString(), x, y, description.getTitleColor());
+ textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), x, y, description.getTitleColor());
}
}
@SuppressWarnings("deprecation")
@Override
- public void render(int mouseX, int mouseY, float partialTicks) {
+ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
+ ScreenDrawing.matrices = matrices;
paint(mouseX, mouseY);
- super.render(mouseX, mouseY, partialTicks);
+ super.render(matrices, mouseX, mouseY, partialTicks);
DiffuseLighting.disable(); //Needed because super.render leaves dirty state
if (description!=null) {
@@ -219,7 +221,7 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
}
}
- drawMouseoverTooltip(mouseX, mouseY); //Draws the itemstack tooltips
+ drawMouseoverTooltip(matrices, mouseX, mouseY); //Draws the itemstack tooltips
}
@Override
@@ -235,6 +237,6 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
@Override
public void renderTextHover(Text text, int x, int y) {
- renderTextHoverEffect(text, x, y);
+ renderTextHoverEffect(ScreenDrawing.matrices, text, x, y);
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
index 0cfac29..199909f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
@@ -1,5 +1,7 @@
package io.github.cottonmc.cotton.gui.client;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.text.Text;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.platform.GlStateManager;
@@ -17,9 +19,23 @@ import net.minecraft.util.Identifier;
* {@code ScreenDrawing} contains utility methods for drawing contents on a screen.
*/
public class ScreenDrawing {
+ // Internal MatrixStack for rendering strings.
+ // TODO (2.0): Remove
+ static MatrixStack matrices;
+
private ScreenDrawing() {}
/**
+ * Gets the currently bound matrix stack.
+ *
+ * @return the matrix stack
+ * @since 1.9.0
+ */
+ public static MatrixStack getMatrices() {
+ return matrices;
+ }
+
+ /**
* Draws a textured rectangle.
*
* @param x the x coordinate of the box on-screen
@@ -295,19 +311,51 @@ public class ScreenDrawing {
public static void drawString(String s, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.draw(s, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color);
}
break;
case CENTER: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.draw(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.draw(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
+ }
+ break;
+ }
+ }
+
+ /**
+ * Draws a text component with a custom alignment.
+ *
+ * @param text the text
+ * @param align the alignment of the string
+ * @param x the X position
+ * @param y the Y position
+ * @param width the width of the string, used for aligning
+ * @param color the text color
+ * @since 1.9.0
+ */
+ public static void drawString(Text text, Alignment align, int x, int y, int width, int color) {
+ switch(align) {
+ case LEFT: {
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ }
+ break;
+ case CENTER: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = (width/2) - (wid/2);
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ }
+ break;
+ case RIGHT: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = width - wid;
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
}
break;
}
@@ -326,19 +374,50 @@ public class ScreenDrawing {
public static void drawStringWithShadow(String s, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x, y, color);
}
break;
case CENTER: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
+ }
+ break;
+ }
+ }
+
+ /**
+ * Draws a shadowed text component.
+ *
+ * @param text the text component
+ * @param align the alignment of the string
+ * @param x the X position
+ * @param y the Y position
+ * @param width the width of the string, used for aligning
+ * @param color the text color
+ */
+ public static void drawStringWithShadow(Text text, Alignment align, int x, int y, int width, int color) {
+ switch(align) {
+ case LEFT: {
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ }
+ break;
+ case CENTER: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = (width/2) - (wid/2);
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ }
+ break;
+ case RIGHT: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = width - wid;
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
}
break;
}
@@ -353,7 +432,19 @@ public class ScreenDrawing {
* @param color the text color
*/
public static void drawString(String s, int x, int y, int color) {
- MinecraftClient.getInstance().textRenderer.draw(s, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color);
+ }
+
+ /**
+ * Draws a left-aligned text component.
+ *
+ * @param text the text component
+ * @param x the X position
+ * @param y the Y position
+ * @param color the text color
+ */
+ public static void drawString(Text text, int x, int y, int color) {
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
}
/**
@@ -361,8 +452,8 @@ public class ScreenDrawing {
*/
@Deprecated
public static void drawCenteredWithShadow(String s, int x, int y, int color) {
- TextRenderer render = MinecraftClient.getInstance().getFontManager().getTextRenderer(MinecraftClient.DEFAULT_TEXT_RENDERER_ID);
- render.drawWithShadow(s, (float)(x - render.getStringWidth(s) / 2), (float)y, color);
+ TextRenderer render = MinecraftClient.getInstance().textRenderer;
+ render.drawWithShadow(matrices, s, (float)(x - render.getStringWidth(s) / 2), (float)y, color);
}
public static int colorAtOpacity(int opaque, float opacity) {
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
index a086b3a..b5e1344 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
@@ -1,5 +1,7 @@
package io.github.cottonmc.cotton.gui.widget;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.glfw.GLFW;
@@ -103,6 +105,7 @@ public abstract class WAbstractSlider extends WWidget {
return true;
}
+ @Environment(EnvType.CLIENT)
@Override
public WWidget onMouseDown(int x, int y, int button) {
// Check if cursor is inside or <=2px away from track
@@ -112,6 +115,7 @@ public abstract class WAbstractSlider extends WWidget {
return super.onMouseDown(x, y, button);
}
+ @Environment(EnvType.CLIENT)
@Override
public void onMouseDrag(int x, int y, int button) {
if (isFocused()) {
@@ -120,6 +124,7 @@ public abstract class WAbstractSlider extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
moveSlider(x, y);
@@ -134,6 +139,7 @@ public abstract class WAbstractSlider extends WWidget {
if (value != previousValue) onValueChanged(value);
}
+ @Environment(EnvType.CLIENT)
@Override
public WWidget onMouseUp(int x, int y, int button) {
dragging = false;
@@ -141,6 +147,7 @@ public abstract class WAbstractSlider extends WWidget {
return super.onMouseUp(x, y, button);
}
+ @Environment(EnvType.CLIENT)
@Override
public void onMouseScroll(int x, int y, double amount) {
int previous = value;
@@ -152,6 +159,7 @@ public abstract class WAbstractSlider extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void tick() {
if (draggingFinishedFromScrollingTimer > 0) {
@@ -242,6 +250,7 @@ public abstract class WAbstractSlider extends WWidget {
if (valueChangeListener != null) valueChangeListener.accept(value);
}
+ @Environment(EnvType.CLIENT)
@Override
public void onKeyPressed(int ch, int key, int modifiers) {
boolean valueChanged = false;
@@ -269,6 +278,7 @@ public abstract class WAbstractSlider extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void onKeyReleased(int ch, int key, int modifiers) {
if (pendingDraggingFinishedFromKeyboard && (isDecreasingKey(ch) || isIncreasingKey(ch))) {
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
index 519d1a3..168e540 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
@@ -7,6 +7,7 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.screen.PropertyDelegate;
+import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
@@ -160,23 +161,23 @@ public class WBar extends WWidget {
}
@Override
- public void addInformation(List<String> information) {
+ public void addTooltip(List<Text> information) {
if (tooltipLabel!=null) {
int value = (field>=0) ? properties.get(field) : 0;
int valMax = (max>=0) ? properties.get(max) : maxValue;
- String formatted = tooltipLabel;
+ Text formatted;
try {
- formatted = new TranslatableText(tooltipLabel, Integer.valueOf(value), Integer.valueOf(valMax)).asFormattedString();
+ formatted = new TranslatableText(tooltipLabel, Integer.valueOf(value), Integer.valueOf(valMax));
} catch (Throwable t) {
- formatted = t.getLocalizedMessage();
+ formatted = new LiteralText(t.getLocalizedMessage());
} //Fallback to raw tooltipLabel
information.add(formatted);
}
if (tooltipTextComponent!=null) {
try {
- information.add(tooltipTextComponent.asFormattedString());
+ information.add(tooltipTextComponent);
} catch (Throwable t) {
- information.add(t.getLocalizedMessage());
+ information.add(new LiteralText(t.getLocalizedMessage()));
}
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
index fbf664d..b3fc425 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -2,6 +2,8 @@ package io.github.cottonmc.cotton.gui.widget;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.Alignment;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.sound.PositionedSoundInstance;
@@ -58,7 +60,7 @@ public class WButton extends WWidget {
color = 0xFFFFA0;
}*/
- ScreenDrawing.drawStringWithShadow(label.asFormattedString(), alignment, x, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
+ ScreenDrawing.drawStringWithShadow(label, alignment, x, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
}
}
@@ -66,7 +68,8 @@ public class WButton extends WWidget {
public void setSize(int x, int y) {
super.setSize(x, 20);
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
super.onClick(x, y, button);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java
index be516c7..d3d91b0 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java
@@ -41,6 +41,7 @@ public class WItem extends WWidget {
return true;
}
+ @Environment(EnvType.CLIENT)
@Override
public void tick() {
if (ticks++ >= duration) {
@@ -55,7 +56,6 @@ public class WItem extends WWidget {
RenderSystem.pushMatrix();
RenderSystem.enableDepthTest();
RenderSystem.translatef(x, y, 0);
- RenderSystem.scalef(1.2f, 1.2f, 1.0f);
MinecraftClient mc = MinecraftClient.getInstance();
ItemRenderer renderer = mc.getItemRenderer();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
index d925c17..1ab42b1 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
@@ -23,7 +23,14 @@ public class WLabel extends WWidget {
protected int color;
protected int darkmodeColor;
+ /**
+ * The default text color for light mode labels.
+ */
public static final int DEFAULT_TEXT_COLOR = 0x404040;
+
+ /**
+ * The default text color for {@linkplain io.github.cottonmc.cotton.gui.client.LibGuiConfig#darkMode dark mode} labels.
+ */
public static final int DEFAULT_DARKMODE_TEXT_COLOR = 0xbcbcbc;
/**
@@ -69,8 +76,7 @@ public class WLabel extends WWidget {
@Override
public void paintBackground(int x, int y, int mouseX, int mouseY) {
- String translated = text.asFormattedString();
- ScreenDrawing.drawString(translated, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color);
+ ScreenDrawing.drawString(text, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color);
Text hoveredText = getTextAt(mouseX, mouseY);
if (hoveredText != null) {
@@ -81,6 +87,7 @@ public class WLabel extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
Text hoveredText = getTextAt(x, y);
@@ -96,14 +103,7 @@ public class WLabel extends WWidget {
@Nullable
private Text getTextAt(int x, int y) {
if (isWithinBounds(x, y)) {
- int i = 0;
- for (Text component : text) {
- TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
- i += renderer.getStringWidth(component.asFormattedString());
- if (i > x) {
- return component;
- }
- }
+ return MinecraftClient.getInstance().textRenderer.method_27527().method_27489(text, x);
}
return null;
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
index 4541427..d9ab1b0 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
@@ -25,19 +25,47 @@ public class WLabeledSlider extends WAbstractSlider {
@Nullable private LabelUpdater labelUpdater = null;
private Alignment labelAlignment = Alignment.CENTER;
+ /**
+ * Constructs a horizontal slider with no default label.
+ *
+ * @param min the minimum value
+ * @param max the maximum value
+ */
public WLabeledSlider(int min, int max) {
this(min, max, Axis.HORIZONTAL);
}
+ /**
+ * Constructs a slider with no default label.
+ *
+ * @param min the minimum value
+ * @param max the maximum value
+ * @param axis the slider axis
+ */
public WLabeledSlider(int min, int max, Axis axis) {
super(min, max, axis);
}
+ /**
+ * Constructs a slider.
+ *
+ * @param min the minimum value
+ * @param max the maximum value
+ * @param axis the slider axis
+ * @param label the slider label (can be null)
+ */
public WLabeledSlider(int min, int max, Axis axis, @Nullable Text label) {
this(min, max, axis);
this.label = label;
}
+ /**
+ * Constructs a horizontal slider.
+ *
+ * @param min the minimum value
+ * @param max the maximum value
+ * @param label the slider label (can be null)
+ */
public WLabeledSlider(int min, int max, @Nullable Text label) {
this(min, max);
this.label = lab