Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Clipboard to GT #44

Merged
merged 48 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
23bb18a
Start on clipboard GUI
bruberu Jul 13, 2021
ddc506d
Complete everything up to the actual rendering
bruberu Jul 14, 2021
4db918c
Don't forget the buttons
bruberu Jul 14, 2021
c938a8d
Remove TileEntity systems, since they're not really needed
bruberu Jul 15, 2021
d5dbe3a
Wait, this shouldn't be an MTE :thonk:
bruberu Jul 17, 2021
d786313
Merge remote-tracking branch 'origin/master' into clipboard
bruberu Jul 18, 2021
42efbaa
Fiddle around with blockstates
bruberu Jul 20, 2021
a025615
Add proper clipboard-placing behavior
bruberu Jul 23, 2021
a4c383e
Merge remote-tracking branch 'origin/master' into clipboard
bruberu Jul 23, 2021
a3f8a5f
Add a clipboard back
bruberu Jul 23, 2021
36f5101
Begin movement to MTE, by Yefancy's request
bruberu Jul 26, 2021
fa52af7
Remove aged TE code
bruberu Jul 27, 2021
68b3a32
Complete step two of four
bruberu Jul 28, 2021
3d44654
A husk of a renderMetaTileEntityDynamic
bruberu Jul 30, 2021
c6e4062
Fix model rendering
bruberu Jul 31, 2021
f0c245f
Merge remote-tracking branch 'origin/master' into clipboard
bruberu Jul 31, 2021
b2e47a2
Pull in FakeModularGui and FakeModularUIContainer, and start on a few…
bruberu Aug 3, 2021
72d6cd3
Create a Death Ray
bruberu Aug 4, 2021
318724c
Complete check 3/4
bruberu Aug 7, 2021
8ddc5da
Fix references to removed class
bruberu Aug 7, 2021
abfa0be
Tweak clipboard's location
bruberu Aug 7, 2021
6bf8994
Merge remote-tracking branch 'origin/master' into clipboard
bruberu Aug 7, 2021
bfe7e4d
Remove more old code
bruberu Aug 7, 2021
7329d14
Get GUI interactivity online! (4/4) :lets:
bruberu Aug 8, 2021
4969506
Merge remote-tracking branch 'origin/master' into clipboard
bruberu Aug 8, 2021
432d404
Add crafting recipe, and fix some minor issues
bruberu Aug 9, 2021
bd3e711
...Why was that there?
bruberu Aug 9, 2021
3674b33
Fix more various bugs
bruberu Aug 10, 2021
59b044f
Fix more bugs
bruberu Aug 10, 2021
1c437c1
Fix more bugs
bruberu Aug 10, 2021
cff5a3d
Fix non-in-world GUI, and add explainer text to tooltip
bruberu Aug 10, 2021
d56a6d1
Fix certain formatting and extraneous import problems
bruberu Aug 11, 2021
cb51698
Fix certain formatting and extraneous import problems
bruberu Aug 11, 2021
60b409e
Reformat GregFakePlayer
bruberu Aug 11, 2021
b251eb5
Yeet ModelCache.java
bruberu Aug 11, 2021
ac44dc1
Keep removing useless imports
bruberu Aug 11, 2021
88a63c0
Behaviour -> Behavior (as per Tech's request)
bruberu Aug 11, 2021
610f2a1
Implement @Tech22's suggestions
bruberu Aug 11, 2021
ad8de61
Continue transition to behavior
bruberu Aug 11, 2021
5c54da4
Apply all of Kila's suggestions that could be simply implemented
bruberu Aug 12, 2021
8f40c6b
Fix up ClipboardBehavior.java
bruberu Aug 12, 2021
4c19bd1
Fix up MetaTileEntityClipboard.java
bruberu Aug 12, 2021
088e6be
Continue removing unnecessary checks from PlayerInventoryHolder.java
bruberu Aug 12, 2021
dbf7e68
Add Max's textures!
bruberu Aug 12, 2021
44e5666
Squashed commit of the following:
Yefancy Aug 21, 2021
8da065b
compatibility
Yefancy Aug 21, 2021
2b833a8
Merge branch 'master' into clipboard
Yefancy Aug 21, 2021
60b9c8f
Fix remaining issues
bruberu Aug 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public BlockMachine() {
setHardness(6.0f);
setResistance(6.0f);
setTranslationKey("unnamed");
setHarvestLevel("wrench", 1);
Yefancy marked this conversation as resolved.
Show resolved Hide resolved
setDefaultState(getDefaultState().withProperty(OPAQUE, true));
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/cover/ICoverable.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@ static Cuboid6 getCoverPlateBox(EnumFacing side, double plateThickness) {
throw new UnsupportedOperationException();
}
}

public default boolean canRenderMachineGrid() {
return true;
}
}
5 changes: 5 additions & 0 deletions src/main/java/gregtech/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ public class GuiTextures {
public static final TextureArea BORDERED_BACKGROUND = AdoptableTextureArea.fullImage("textures/gui/base/bordered_background.png", 195, 136, 4, 4);
public static final TextureArea BOXED_BACKGROUND = AdoptableTextureArea.fullImage("textures/gui/base/boxed_background.png", 256, 174, 11, 11);

public static final TextureArea BLANK = AdoptableTextureArea.fullImage("textures/gui/base/blank.png", 1, 1, 0, 0);
public static final TextureArea DISPLAY = TextureArea.fullImage("textures/gui/base/display.png");
public static final TextureArea FLUID_SLOT = AdoptableTextureArea.fullImage("textures/gui/base/fluid_slot.png", 18, 18, 1, 1);
public static final TextureArea FLUID_TANK_BACKGROUND = TextureArea.fullImage("textures/gui/base/fluid_tank_background.png");
public static final TextureArea FLUID_TANK_OVERLAY = TextureArea.fullImage("textures/gui/base/fluid_tank_overlay.png");
public static final TextureArea SLOT = AdoptableTextureArea.fullImage("textures/gui/base/slot.png", 18, 18, 1, 1);
public static final TextureArea SLOT_DARKENED = TextureArea.fullImage("textures/gui/base/darkened_slot.png");


//FLUID & ITEM OUTPUT BUTTONS
public static final TextureArea BLOCKS_INPUT = TextureArea.fullImage("textures/gui/widget/button_blocks_input.png");
public static final TextureArea BUTTON = TextureArea.fullImage("textures/gui/widget/button.png");
Expand All @@ -31,8 +33,11 @@ public class GuiTextures {
public static final TextureArea BUTTON_FILTER_NBT = TextureArea.fullImage("textures/gui/widget/button_filter_nbt.png");
public static final TextureArea BUTTON_FLUID_OUTPUT = TextureArea.fullImage("textures/gui/widget/button_fluid_output.png");
public static final TextureArea BUTTON_ITEM_OUTPUT = TextureArea.fullImage("textures/gui/widget/button_item_output.png");
public static final TextureArea BUTTON_LEFT = TextureArea.fullImage("textures/gui/widget/left.png");
bruberu marked this conversation as resolved.
Show resolved Hide resolved
public static final TextureArea BUTTON_OVERCLOCK = TextureArea.fullImage("textures/gui/widget/button_overclock.png");
public static final TextureArea BUTTON_RIGHT = TextureArea.fullImage("textures/gui/widget/right.png");
bruberu marked this conversation as resolved.
Show resolved Hide resolved
public static final TextureArea BUTTON_SWITCH_VIEW = TextureArea.fullImage("textures/gui/widget/button_switch_view.png");
public static final TextureArea CLIPBOARD_CHECKBOX = TextureArea.fullImage("textures/gui/widget/clipboard_checkbox.png");
public static final TextureArea DISTRIBUTION_MODE = TextureArea.fullImage("textures/gui/widget/button_distribution_mode.png");
public static final TextureArea LOCK = TextureArea.fullImage("textures/gui/widget/lock.png");
public static final TextureArea SWITCH = TextureArea.fullImage("textures/gui/widget/switch.png");
Expand Down
123 changes: 123 additions & 0 deletions src/main/java/gregtech/api/gui/impl/FakeModularGui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package gregtech.api.gui.impl;

import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.Widget;
import gregtech.api.util.RenderUtil;
import gregtech.common.gui.impl.FakeModularUIContainerClipboard;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.List;

@SideOnly(Side.CLIENT)
public class FakeModularGui implements IRenderContext {
public final ModularUI modularUI;
public FakeModularUIContainerClipboard container;
protected Minecraft mc;
protected FontRenderer fr;

public FakeModularGui(ModularUI modularUI, FakeModularUIContainerClipboard fakeModularUIContainer){
this.modularUI = modularUI;
this.container = fakeModularUIContainer;
this.modularUI.updateScreenSize(this.modularUI.getWidth(), this.modularUI.getHeight());
this.mc = Minecraft.getMinecraft();
this.fr = mc.fontRenderer;
}

public void updateScreen() {
modularUI.guiWidgets.values().forEach(Widget::updateScreen);
}

public void handleWidgetUpdate(int windowId, int widgetId, PacketBuffer updateData) {
if (windowId == container.windowId) {
Widget widget = modularUI.guiWidgets.get(widgetId);
int updateId = updateData.readVarInt();
if (widget != null) {
widget.readUpdateInfo(updateId, updateData);
}
}
}

public void drawScreen(double x, double y, float partialTicks) {
float halfW = modularUI.getWidth() / 2f;
float halfH = modularUI.getHeight() / 2f;
float scale = 0.5f / Math.max(halfW, halfH);
int mouseX = (int) ((x / scale) + (halfW > halfH? 0: (halfW - halfH)));
int mouseY = (int) ((y / scale) + (halfH > halfW? 0: (halfH - halfW)));

GlStateManager.translate(-scale * halfW, -scale * halfH, 0.01);
GlStateManager.scale(scale, scale, 1);
GlStateManager.depthMask(false);

drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);

for (int i = 0; i < this.container.inventorySlots.size(); ++i) {
RenderUtil.renderSlot(this.container.inventorySlots.get(i), fr);
}


GlStateManager.scale(1, 1, 0);
drawGuiContainerForegroundLayer(mouseX, mouseY);
for (int i = 0; i < this.container.inventorySlots.size(); ++i) {
Slot slot = this.container.inventorySlots.get(i);
if (!slot.getStack().isEmpty() && slot.xPos < mouseX && mouseX < slot.xPos + 18 && slot.yPos < mouseY && mouseY < slot.yPos + 18) {
RenderUtil.renderRect(slot.xPos, slot.yPos, 18, 18, 0, 0X8fffffff);
renderToolTip(slot.getStack(), slot.xPos, slot.yPos);
}
}

GlStateManager.depthMask(true);
GlStateManager.color(1.0f, 1.0f, 1.0f);
GlStateManager.disableLighting();
}

protected void renderToolTip(ItemStack stack, int x, int y) {
FontRenderer font = stack.getItem().getFontRenderer(stack);
GuiUtils.preItemToolTip(stack);
GuiUtils.drawHoveringText(this.getItemToolTip(stack), x, y, modularUI.getScreenWidth(), modularUI.getScreenHeight(), -1, (font == null ? fr : font));
net.minecraftforge.fml.client.config.GuiUtils.postItemToolTip();
}

protected List<String> getItemToolTip(ItemStack itemStack) {
List<String> list = itemStack.getTooltip(mc.player, mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL);
list.set(0, itemStack.getItem().getForgeRarity(itemStack).getColor() + list.get(0));
for (int i = 1; i < list.size(); ++i) {
list.set(i, TextFormatting.GRAY + list.get(i));
}
return list;
}

public void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
modularUI.backgroundPath.draw(0, 0, modularUI.getWidth(), modularUI.getHeight());
for (Widget widget : modularUI.guiWidgets.values()) {
GlStateManager.pushMatrix();
GlStateManager.color(1.0f, 1.0f, 1.0f);
GlStateManager.enableBlend();
widget.drawInBackground(mouseX, mouseY, this);
GlStateManager.popMatrix();
}
}

public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
for (Widget widget : modularUI.guiWidgets.values()) {
GlStateManager.pushMatrix();
GlStateManager.color(1.0f, 1.0f, 1.0f);
widget.drawInForeground(mouseX, mouseY);
GlStateManager.popMatrix();
}
}

public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
return modularUI.guiWidgets.values().stream().anyMatch(widget -> widget.mouseClicked(mouseX, mouseY, mouseButton));
}
}
149 changes: 149 additions & 0 deletions src/main/java/gregtech/api/gui/widgets/ImageCycleButtonWidget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package gregtech.api.gui.widgets;

import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.Widget;
import gregtech.api.gui.resources.SizedTextureArea;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.util.GTUtility;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import gregtech.api.util.function.BooleanConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Arrays;
import java.util.List;
import java.util.function.*;

public class ImageCycleButtonWidget extends Widget {

protected TextureArea buttonTexture;
private int textColor = 0xFFFFFF;
private IntSupplier currentOptionSupplier;
private IntConsumer setOptionExecutor;
private int optionCount;
private final int RIGHT_MOUSE = 1;
protected int currentOption;
protected String tooltipHoverString;
protected long hoverStartTime = -1L;
protected boolean isMouseHovered;

public ImageCycleButtonWidget(int xPosition, int yPosition, int width, int height, TextureArea buttonTexture, int optionCount, IntSupplier currentOptionSupplier, IntConsumer setOptionExecutor) {
super(new Position(xPosition, yPosition), new Size(width, height));
this.buttonTexture = buttonTexture;
this.currentOptionSupplier = currentOptionSupplier;
this.setOptionExecutor = setOptionExecutor;
this.optionCount = optionCount;
}


public ImageCycleButtonWidget(int xPosition, int yPosition, int width, int height, TextureArea buttonTexture, int optionCount, BooleanSupplier supplier, BooleanConsumer updater) {
super(new Position(xPosition, yPosition), new Size(width, height));
this.buttonTexture = buttonTexture;
this.currentOptionSupplier = () -> supplier.getAsBoolean() ? 1 : 0;
this.setOptionExecutor = (value) -> updater.apply(value >= 1);
this.optionCount = optionCount;
}

public ImageCycleButtonWidget setTooltipHoverString(String hoverString) {
this.tooltipHoverString = hoverString;
return this;
}

public ImageCycleButtonWidget setButtonTexture(TextureArea texture) {
this.buttonTexture = texture;
return this;
}

public ImageCycleButtonWidget setTextColor(int textColor) {
this.textColor = textColor;
return this;
}

@Override
@SideOnly(Side.CLIENT)
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
Position pos = getPosition();
Size size = getSize();
if (buttonTexture instanceof SizedTextureArea) {
((SizedTextureArea) buttonTexture).drawHorizontalCutSubArea(pos.x, pos.y, size.width, size.height, (float)currentOption / optionCount, (float)1 / optionCount);
} else {
buttonTexture.drawSubArea(pos.x, pos.y, size.width, size.height, 0.0, (float)currentOption / optionCount, 1.0, (float)1 / optionCount);
}
}

@Override
public void drawInForeground(int mouseX, int mouseY) {
boolean isHovered = isMouseOverElement(mouseX, mouseY);
boolean wasHovered = isMouseHovered;
if (isHovered && !wasHovered) {
this.isMouseHovered = true;
this.hoverStartTime = System.currentTimeMillis();
} else if (!isHovered && wasHovered) {
this.isMouseHovered = false;
this.hoverStartTime = 0L;
} else if (isHovered) {
long timeSinceHover = System.currentTimeMillis() - hoverStartTime;
if (timeSinceHover > 1000L && tooltipHoverString != null) {
List<String> hoverList = Arrays.asList(I18n.format(tooltipHoverString).split("/n"));
drawHoveringText(ItemStack.EMPTY, hoverList, 300, mouseX, mouseY);
}
}
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (currentOptionSupplier.getAsInt() != currentOption) {
this.currentOption = currentOptionSupplier.getAsInt();
writeUpdateInfo(1, buf -> buf.writeVarInt(currentOption));
}
}

@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
super.readUpdateInfo(id, buffer);
if (id == 1) {
this.currentOption = buffer.readVarInt();
}
}

@Override
@SideOnly(Side.CLIENT)
public boolean mouseClicked(int mouseX, int mouseY, int button) {
super.mouseClicked(mouseX, mouseY, button);
if (isMouseOverElement(mouseX, mouseY)) {
//Allow only the RMB to reverse cycle
if(button == RIGHT_MOUSE) {
//Wrap from the first option to the last if needed
this.currentOption = currentOption == 0 ? optionCount - 1 : currentOption - 1;
} else {
this.currentOption = (currentOption + 1) % optionCount;
}
writeClientAction(1, buf -> buf.writeVarInt(currentOption));
playButtonClickSound();
return true;
}
return false;
}


@Override
public void handleClientAction(int id, PacketBuffer buffer) {
super.handleClientAction(id, buffer);
if (id == 1) {
this.currentOption = MathHelper.clamp(buffer.readVarInt(), 0, optionCount);
setOptionExecutor.accept(currentOption);
}
}

}
14 changes: 10 additions & 4 deletions src/main/java/gregtech/api/gui/widgets/SimpleTextWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ public class SimpleTextWidget extends Widget {
protected final int color;
protected final Supplier<String> textSupplier;
protected String lastText = "";
protected boolean isCentered = true;

public SimpleTextWidget(int xPosition, int yPosition, String formatLocale, int color, Supplier<String> textSupplier) {
public SimpleTextWidget(int xPosition, int yPosition, String formatLocale, int color, Supplier<String> textSupplier, boolean isCentered) {
super(new Position(xPosition, yPosition), Size.ZERO);
this.color = color;
this.formatLocale = formatLocale;
this.textSupplier = textSupplier;
this.isCentered = isCentered;
}

public SimpleTextWidget(int xPosition, int yPosition, String formatLocale, int color, Supplier<String> textSupplier) {
this(xPosition, yPosition, formatLocale, color, textSupplier, true);
}

public SimpleTextWidget(int xPosition, int yPosition, String formatLocale, Supplier<String> textSupplier) {
this(xPosition, yPosition, formatLocale, 0x404040, textSupplier);
this(xPosition, yPosition, formatLocale, 0x404040, textSupplier, true);
}

private void updateSize() {
Expand All @@ -51,8 +57,8 @@ public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
String text = formatLocale.isEmpty() ? (I18n.hasKey(lastText) ? I18n.format(lastText) : lastText) : I18n.format(formatLocale, lastText);
Position position = getPosition();
fontRenderer.drawString(text,
position.x - fontRenderer.getStringWidth(text) / 2,
position.y - fontRenderer.FONT_HEIGHT / 2, color);
isCentered ? position.x - fontRenderer.getStringWidth(text) / 2 : position.x,
isCentered ? position.y - fontRenderer.FONT_HEIGHT / 2 : position.y, color);
GlStateManager.color(rColorForOverlay, gColorForOverlay, bColorForOverlay, 1.0F);
}

Expand Down
Loading