Added support for individual slot configuration
* start work on slot config * More slot work * More gui work for slot config * Remove old sided code * More slot work * More slot memes * Stuff seems to be working :) * Start work on auto input / output * Slot IO check boxes now work * Fix buttons at different screen resolutions * Improve close button * Gui polish * Fix multiblock hologram rendering * More fixes + changes * Cleanup + output fix
This commit is contained in:
parent
a59647a0b7
commit
cbcb465c97
61 changed files with 1396 additions and 641 deletions
|
@ -26,15 +26,19 @@ package techreborn.client.gui;
|
|||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import reborncore.api.tile.IUpgradeable;
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
import techreborn.client.container.builder.BuiltContainer;
|
||||
import techreborn.client.gui.slot.GuiSlotConfiguration;
|
||||
import techreborn.client.gui.widget.GuiButtonPowerBar;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Prospector
|
||||
*/
|
||||
|
@ -45,6 +49,7 @@ public class GuiBase extends GuiContainer {
|
|||
public TRBuilder builder = new TRBuilder();
|
||||
public TileEntity tile;
|
||||
public BuiltContainer container;
|
||||
public static boolean showSlotConfig = false;
|
||||
|
||||
public GuiBase(EntityPlayer player, TileEntity tile, BuiltContainer container) {
|
||||
super(container);
|
||||
|
@ -106,6 +111,7 @@ public class GuiBase extends GuiContainer {
|
|||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
GuiSlotConfiguration.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,6 +127,8 @@ public class GuiBase extends GuiContainer {
|
|||
builder.drawUpgrades(this, upgradeable, guiLeft, guiTop);
|
||||
}
|
||||
}
|
||||
builder.drawSlotTab(this, guiLeft, guiTop, mouseX, mouseY);
|
||||
|
||||
}
|
||||
|
||||
public boolean drawPlayerSlots() {
|
||||
|
@ -135,6 +143,9 @@ public class GuiBase extends GuiContainer {
|
|||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
drawTitle();
|
||||
if(showSlotConfig){
|
||||
GuiSlotConfiguration.draw(this, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -179,6 +190,54 @@ public class GuiBase extends GuiContainer {
|
|||
buttonList.add(new GuiButtonPowerBar(id, x + factorX, y + factorY, this, layer));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
if(showSlotConfig){
|
||||
if(GuiSlotConfiguration.mouseClicked(mouseX, mouseY, mouseButton, this)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if(showSlotConfig){
|
||||
GuiSlotConfiguration.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick, this);
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
if(isPointInRegion(-26, 84, 30, 30, mouseX, mouseY)){
|
||||
showSlotConfig = !showSlotConfig;
|
||||
if(!showSlotConfig){
|
||||
GuiSlotConfiguration.reset();
|
||||
}
|
||||
}
|
||||
if(showSlotConfig){
|
||||
if(GuiSlotConfiguration.mouseReleased(mouseX, mouseY, state, this)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
showSlotConfig = false;
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
public boolean isPointInRect(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY) {
|
||||
return super.isPointInRegion(rectX, rectY, rectWidth, rectHeight, pointX, pointY);
|
||||
}
|
||||
|
||||
public TileLegacyMachineBase getMachine(){
|
||||
return (TileLegacyMachineBase) tile;
|
||||
}
|
||||
|
||||
//TODO
|
||||
public enum SlotRender {
|
||||
STANDARD, OUTPUT, NONE, SPRITE;
|
||||
|
|
|
@ -108,7 +108,7 @@ public class GuiBlastFurnace extends GuiBase {
|
|||
@Override
|
||||
public void actionPerformed(final GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.id == 212) {
|
||||
if (button.id == 212 && !GuiBase.showSlotConfig) {
|
||||
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
|
||||
{
|
||||
// This code here makes a basic multiblock and then sets to the selected one.
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
package techreborn.client.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
@ -41,6 +39,8 @@ import techreborn.init.ModBlocks;
|
|||
import techreborn.proxies.ClientProxy;
|
||||
import techreborn.tiles.multiblock.TileDistillationTower;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiDistillationTower extends GuiBase {
|
||||
|
||||
public TileDistillationTower tile;
|
||||
|
@ -105,7 +105,7 @@ public class GuiDistillationTower extends GuiBase {
|
|||
@Override
|
||||
public void actionPerformed(final GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.id == 212) {
|
||||
if (button.id == 212 && !GuiBase.showSlotConfig) {
|
||||
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
|
||||
{
|
||||
// This code here makes a basic multiblock and then sets to the selected one.
|
||||
|
|
|
@ -107,7 +107,7 @@ public class GuiImplosionCompressor extends GuiBase {
|
|||
@Override
|
||||
public void actionPerformed(final GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.id == 212) {
|
||||
if (button.id == 212 && !GuiBase.showSlotConfig) {
|
||||
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
|
||||
{
|
||||
// This code here makes a basic multiblock and then sets to the selected one.
|
||||
|
|
|
@ -111,7 +111,7 @@ public class GuiIndustrialGrinder extends GuiBase {
|
|||
@Override
|
||||
public void actionPerformed(final GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.id == 212) {
|
||||
if (button.id == 212 && !GuiBase.showSlotConfig) {
|
||||
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
|
||||
{
|
||||
// This code here makes a basic multiblock and then sets to the selected one.
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
package techreborn.client.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -41,6 +39,8 @@ import techreborn.init.ModBlocks;
|
|||
import techreborn.proxies.ClientProxy;
|
||||
import techreborn.tiles.multiblock.TileIndustrialSawmill;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiIndustrialSawmill extends GuiBase {
|
||||
|
||||
TileIndustrialSawmill tile;
|
||||
|
@ -110,7 +110,7 @@ public class GuiIndustrialSawmill extends GuiBase {
|
|||
@Override
|
||||
public void actionPerformed(final GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.id == 212) {
|
||||
if (button.id == 212 && !GuiBase.showSlotConfig) {
|
||||
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
|
||||
{
|
||||
// This code here makes a basic multiblock and then sets to the selected one.
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
package techreborn.client.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -39,6 +37,8 @@ import techreborn.init.ModBlocks;
|
|||
import techreborn.proxies.ClientProxy;
|
||||
import techreborn.tiles.multiblock.TileVacuumFreezer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiVacuumFreezer extends GuiBase {
|
||||
|
||||
TileVacuumFreezer tile;
|
||||
|
@ -102,7 +102,7 @@ public class GuiVacuumFreezer extends GuiBase {
|
|||
@Override
|
||||
public void actionPerformed(final GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.id == 212) {
|
||||
if (button.id == 212 && !GuiBase.showSlotConfig) {
|
||||
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
|
||||
{
|
||||
// This code here makes a basic multiblock and then sets to the selected one.
|
||||
|
|
|
@ -27,23 +27,30 @@ package techreborn.client.gui;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import reborncore.api.tile.IUpgradeable;
|
||||
import reborncore.client.guibuilder.GuiBuilder;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import techreborn.init.ModItems;
|
||||
import techreborn.lib.ModInfo;
|
||||
import techreborn.proxies.ClientProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.item.ItemStack.EMPTY;
|
||||
|
||||
/**
|
||||
* Created by Prospector
|
||||
*/
|
||||
|
@ -86,6 +93,9 @@ public class TRBuilder extends GuiBuilder {
|
|||
}
|
||||
|
||||
public void drawProgressBar(GuiBase gui, int progress, int maxProgress, int x, int y, int mouseX, int mouseY, ProgressDirection direction, GuiBase.Layer layer) {
|
||||
if(GuiBase.showSlotConfig){
|
||||
return;
|
||||
}
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
|
@ -189,6 +199,9 @@ public class TRBuilder extends GuiBuilder {
|
|||
}
|
||||
|
||||
public void drawJEIButton(GuiBase gui, int x, int y, GuiBase.Layer layer) {
|
||||
if(GuiBase.showSlotConfig){
|
||||
return;
|
||||
}
|
||||
if (Loader.isModLoaded("jei")) {
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
|
@ -200,6 +213,9 @@ public class TRBuilder extends GuiBuilder {
|
|||
}
|
||||
|
||||
public void drawHologramButton(GuiBase gui, int x, int y, int mouseX, int mouseY, GuiBase.Layer layer) {
|
||||
if(GuiBase.showSlotConfig){
|
||||
return;
|
||||
}
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
|
@ -299,6 +315,9 @@ public class TRBuilder extends GuiBuilder {
|
|||
}
|
||||
|
||||
public void drawMultiblockMissingBar(GuiBase gui, GuiBase.Layer layer) {
|
||||
if(GuiBase.showSlotConfig){
|
||||
return;
|
||||
}
|
||||
int x = 0;
|
||||
int y = 4;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
|
@ -364,6 +383,32 @@ public class TRBuilder extends GuiBuilder {
|
|||
gui.drawTexturedModalRect(posX - 27, posY + 4, 126, 151, 30, 87);
|
||||
}
|
||||
|
||||
public void drawSlotTab(GuiScreen gui, int posX, int posY, int mouseX, int mouseY){
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(GUI_SHEET);
|
||||
gui.drawTexturedModalRect(posX - 26, posY + 84, 157, 148, 30, 30);
|
||||
renderItemStack(new ItemStack(ModItems.WRENCH), posX - 19, posY + 92);
|
||||
if (isInRect(posX - 19, posY + 92, 12, 12, mouseX, mouseY)) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("Configure slots");
|
||||
net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(list, mouseX, mouseY, gui.width, gui.height, -1, gui.mc.fontRenderer);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderItemStack(ItemStack stack, int x, int y) {
|
||||
if (stack != EMPTY) {
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
|
||||
itemRenderer.renderItemAndEffectIntoGUI(stack, x, y);
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawScrapSlot(GuiScreen gui, int posX, int posY) {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(GUI_SHEET);
|
||||
gui.drawTexturedModalRect(posX, posY, 150, 0, 18, 18);
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
package techreborn.client.gui.slot;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import reborncore.client.gui.GuiUtil;
|
||||
import techreborn.client.container.builder.BuiltContainer;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
import techreborn.client.gui.slot.elements.ConfigSlotElement;
|
||||
import techreborn.client.gui.slot.elements.ElementBase;
|
||||
import techreborn.client.gui.slot.elements.SlotType;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GuiSlotConfiguration {
|
||||
|
||||
static HashMap<Integer, ConfigSlotElement> slotElementMap = new HashMap<>();
|
||||
|
||||
public static int slectedSlot = 0;
|
||||
|
||||
public static void reset() {
|
||||
slectedSlot = -1;
|
||||
}
|
||||
|
||||
public static void init(GuiBase guiBase) {
|
||||
reset();
|
||||
slotElementMap.clear();
|
||||
|
||||
BuiltContainer container = guiBase.container;
|
||||
for (Slot slot : container.inventorySlots) {
|
||||
if (guiBase.tile != slot.inventory) {
|
||||
continue;
|
||||
}
|
||||
ConfigSlotElement slotElement = new ConfigSlotElement(guiBase.getMachine(), slot.getSlotIndex(), SlotType.NORMAL, slot.xPos - guiBase.guiLeft + 50, slot.yPos - guiBase.guiTop - 25, guiBase);
|
||||
slotElementMap.put(slot.getSlotIndex(), slotElement);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void draw(GuiBase guiBase, int mouseX, int mouseY) {
|
||||
BuiltContainer container = guiBase.container;
|
||||
for (Slot slot : container.inventorySlots) {
|
||||
if (guiBase.tile != slot.inventory) {
|
||||
continue;
|
||||
}
|
||||
GlStateManager.color(255, 0, 0);
|
||||
Color color = new Color(255, 0, 0, 128);
|
||||
GuiUtil.drawGradientRect(slot.xPos - 1, slot.yPos - 1, 18, 18, color.getRGB(), color.getRGB());
|
||||
GlStateManager.color(255, 255, 255);
|
||||
}
|
||||
|
||||
if (slectedSlot != -1) {
|
||||
slotElementMap.get(slectedSlot).draw(guiBase);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ConfigSlotElement> getVisibleElements() {
|
||||
if(slectedSlot == -1){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return slotElementMap.values().stream()
|
||||
.filter(configSlotElement -> configSlotElement.getId() == slectedSlot)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
//Allows closing of the widget with the escape key
|
||||
@SubscribeEvent
|
||||
public static void keyboardEvent(GuiScreenEvent.KeyboardInputEvent event){
|
||||
if(!getVisibleElements().isEmpty() && Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
||||
slectedSlot = -1;
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean mouseClicked(int mouseX, int mouseY, int mouseButton, GuiBase guiBase) throws IOException {
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
||||
for (ElementBase element : configSlotElement.elements) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isPressing = true;
|
||||
boolean action = element.onStartPress(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isPressing = false;
|
||||
}
|
||||
}
|
||||
if (action)
|
||||
break;
|
||||
} else {
|
||||
element.isPressing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BuiltContainer container = guiBase.container;
|
||||
|
||||
if(getVisibleElements().isEmpty()) {
|
||||
for (Slot slot : container.inventorySlots) {
|
||||
if (guiBase.tile != slot.inventory) {
|
||||
continue;
|
||||
}
|
||||
if (guiBase.isPointInRect(slot.xPos, slot.yPos, 18, 18, mouseX, mouseY)) {
|
||||
slectedSlot = slot.getSlotIndex();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return !getVisibleElements().isEmpty();
|
||||
}
|
||||
|
||||
public static void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick, GuiBase guiBase) {
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
||||
for (ElementBase element : configSlotElement.elements) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isDragging = true;
|
||||
boolean action = element.onDrag(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isDragging = false;
|
||||
}
|
||||
}
|
||||
if (action)
|
||||
break;
|
||||
} else {
|
||||
element.isDragging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean mouseReleased(int mouseX, int mouseY, int mouseButton, GuiBase guiBase) {
|
||||
boolean clicked = false;
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
||||
if (configSlotElement.isInRect(guiBase, configSlotElement.x, configSlotElement.y, configSlotElement.getWidth(guiBase.getMachine()), configSlotElement.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
clicked = true;
|
||||
}
|
||||
for (ElementBase element : Lists.reverse(configSlotElement.elements)) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isReleasing = true;
|
||||
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isReleasing = false;
|
||||
}
|
||||
}
|
||||
if (action)
|
||||
clicked = true;
|
||||
break;
|
||||
} else {
|
||||
element.isReleasing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return clicked;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
public class ButtonElement extends ElementBase {
|
||||
private Sprite.Button buttonSprite;
|
||||
|
||||
public ButtonElement(int x, int y, Sprite.Button buttonSprite) {
|
||||
super(x, y, buttonSprite.getNormal());
|
||||
this.buttonSprite = buttonSprite;
|
||||
this.addUpdateAction((gui, element) -> {
|
||||
if (isHovering) {
|
||||
element.container.setSprite(0, buttonSprite.getHovered());
|
||||
} else {
|
||||
element.container.setSprite(0, buttonSprite.getNormal());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
|
||||
public class CheckBoxElement extends ElementBase {
|
||||
public String label, type;
|
||||
public int labelColor, slotID;
|
||||
TileLegacyMachineBase machineBase;
|
||||
|
||||
private Sprite.CheckBox checkBoxSprite;
|
||||
|
||||
public CheckBoxElement(String label, int labelColor, int x, int y, String type, int slotID, Sprite.CheckBox checkBoxSprite, TileLegacyMachineBase machineBase) {
|
||||
super(x, y, checkBoxSprite.getNormal());
|
||||
this.checkBoxSprite = checkBoxSprite;
|
||||
this.type = type;
|
||||
this.slotID = slotID;
|
||||
this.machineBase = machineBase;
|
||||
this.label = label;
|
||||
this.labelColor = labelColor;
|
||||
if (isTicked()) {
|
||||
container.setSprite(0, checkBoxSprite.getTicked());
|
||||
} else {
|
||||
container.setSprite(0, checkBoxSprite.getNormal());
|
||||
}
|
||||
this.addPressAction((element, gui, provider, mouseX, mouseY) -> {
|
||||
if (isTicked()) {
|
||||
element.container.setSprite(0, checkBoxSprite.getTicked());
|
||||
} else {
|
||||
element.container.setSprite(0, checkBoxSprite.getNormal());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui) {
|
||||
// super.draw(gui);
|
||||
ISprite sprite = checkBoxSprite.getNormal();
|
||||
if(isTicked()){
|
||||
sprite = checkBoxSprite.getTicked();
|
||||
}
|
||||
drawSprite(gui, sprite, x, y );
|
||||
drawString(gui, label, x + checkBoxSprite.getNormal().width + 5, ((y + getHeight(gui.getMachine()) / 2) - (gui.mc.fontRenderer.FONT_HEIGHT / 2)), labelColor);
|
||||
}
|
||||
|
||||
public boolean isTicked() {
|
||||
if(type.equalsIgnoreCase("output")){
|
||||
return machineBase.slotConfiguration.getSlotDetails(slotID).autoOutput();
|
||||
}
|
||||
return machineBase.slotConfiguration.getSlotDetails(slotID).autoInput();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.common.tile.SlotConfiguration;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
import techreborn.client.gui.slot.GuiSlotConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigSlotElement extends ElementBase {
|
||||
SlotType type;
|
||||
IInventory inventory;
|
||||
int id;
|
||||
public List<ElementBase> elements = new ArrayList<>();
|
||||
|
||||
|
||||
public ConfigSlotElement(IInventory slotInventory, int slotId, SlotType type, int x, int y, GuiBase gui) {
|
||||
super(x, y, type.getButtonSprite());
|
||||
this.type = type;
|
||||
this.inventory = slotInventory;
|
||||
this.id = slotId;
|
||||
|
||||
SlotConfigPopupElement popupElement;
|
||||
|
||||
elements.add(popupElement = new SlotConfigPopupElement(this.id, x - 22, y - 22, this));
|
||||
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON).addReleaseAction((element, gui1, provider, mouseX, mouseY) -> {
|
||||
GuiSlotConfiguration.slectedSlot = -1;
|
||||
return true;
|
||||
}));
|
||||
|
||||
SlotConfiguration.SlotConfigHolder slotConfigHolder = gui.getMachine().slotConfiguration.getSlotDetails(id);
|
||||
|
||||
elements.add(new CheckBoxElement("Auto Input", 0xFFFFFFFF, x - 26, y + 42, "input", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine()).addPressAction((element, gui12, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "input", gui12);
|
||||
return true;
|
||||
}));
|
||||
elements.add(new CheckBoxElement("Auto Output", 0xFFFFFFFF, x - 26, y + 57,"output", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "output", gui13);
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui) {
|
||||
super.draw(gui);
|
||||
ItemStack stack = inventory.getStackInSlot(id);
|
||||
int xPos = x + 1 + gui.guiLeft;
|
||||
int yPos = y + 1 + gui.guiTop;
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
|
||||
renderItem.renderItemAndEffectIntoGUI(gui.mc.player, stack, xPos, yPos);
|
||||
renderItem.renderItemOverlayIntoGUI(gui.mc.fontRenderer, stack, xPos, yPos, null);
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.popMatrix();
|
||||
if (isHovering) {
|
||||
drawSprite(gui, type.getButtonHoverOverlay(), x, y);
|
||||
}
|
||||
elements.forEach(elementBase -> elementBase.draw(gui));
|
||||
}
|
||||
|
||||
public SlotType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,363 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import reborncore.client.guibuilder.GuiBuilder;
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ElementBase {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public boolean isHovering = false;
|
||||
public boolean isDragging = false;
|
||||
public boolean isPressing = false;
|
||||
public boolean isReleasing = false;
|
||||
public boolean startPressLast = false;
|
||||
public boolean isHoveringLast = false;
|
||||
public boolean isDraggingLast = false;
|
||||
public boolean isPressingLast = false;
|
||||
public boolean isReleasingLast = false;
|
||||
public List<ElementBase.Action> hoverActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> dragActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> startPressActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> pressActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> releaseActions = new ArrayList<>();
|
||||
public SpriteContainer container;
|
||||
public List<UpdateAction> updateActions = new ArrayList<>();
|
||||
public List<UpdateAction> buttonUpdate = new ArrayList<>();
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public static final ResourceLocation MECH_ELEMENTS = new ResourceLocation(ModInfo.MOD_ID, "textures/gui/elements.png");
|
||||
|
||||
public ElementBase(int x, int y, SpriteContainer container) {
|
||||
this.container = container;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, ISprite... sprites) {
|
||||
this.container = new SpriteContainer();
|
||||
for (ISprite sprite : sprites) {
|
||||
container.addSprite(sprite);
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, int width, int height) {
|
||||
this.container = new SpriteContainer();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, int width, int height, SpriteContainer container) {
|
||||
this.container = container;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, int width, int height, ISprite... sprites) {
|
||||
this.container = new SpriteContainer();
|
||||
for (ISprite sprite : sprites) {
|
||||
container.addSprite(sprite);
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public SpriteContainer getSpriteContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
public void adjustDimensions(TileLegacyMachineBase provider) {
|
||||
if (container.offsetSprites != null) {
|
||||
for (OffsetSprite offsetSprite : container.offsetSprites) {
|
||||
if (offsetSprite.getSprite().getSprite(provider).width + offsetSprite.getOffsetX(provider) > this.width) {
|
||||
this.width = offsetSprite.getSprite().getSprite(provider).width + offsetSprite.getOffsetX(provider);
|
||||
}
|
||||
if (offsetSprite.getSprite().getSprite(provider).height + offsetSprite.getOffsetY(provider) > this.height) {
|
||||
this.height = offsetSprite.getSprite().getSprite(provider).height + offsetSprite.getOffsetY(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(GuiBase gui) {
|
||||
for (OffsetSprite sprite : getSpriteContainer().offsetSprites) {
|
||||
drawSprite(gui, sprite.getSprite(), x + sprite.getOffsetX(gui.getMachine()), y + sprite.getOffsetY(gui.getMachine()));
|
||||
}
|
||||
}
|
||||
|
||||
public void renderUpdate(GuiBase gui) {
|
||||
isHoveringLast = isHovering;
|
||||
isPressingLast = isPressing;
|
||||
isDraggingLast = isDragging;
|
||||
isReleasingLast = isReleasing;
|
||||
}
|
||||
|
||||
public void update(GuiBase gui) {
|
||||
for (UpdateAction action : updateActions) {
|
||||
action.update(gui, this);
|
||||
}
|
||||
}
|
||||
|
||||
public ElementBase addUpdateAction(UpdateAction action) {
|
||||
updateActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public ElementBase setX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public ElementBase setY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getWidth(TileLegacyMachineBase provider) {
|
||||
adjustDimensions(provider);
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight(TileLegacyMachineBase provider) {
|
||||
adjustDimensions(provider);
|
||||
return height;
|
||||
}
|
||||
|
||||
public ElementBase addHoverAction(ElementBase.Action action) {
|
||||
this.hoverActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addDragAction(ElementBase.Action action) {
|
||||
this.dragActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addStartPressAction(ElementBase.Action action) {
|
||||
this.startPressActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addPressAction(ElementBase.Action action) {
|
||||
this.pressActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addReleaseAction(ElementBase.Action action) {
|
||||
this.releaseActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean onHover(TileLegacyMachineBase provider, GuiBase gui, int mouseX, int mouseY) {
|
||||
for (ElementBase.Action action : hoverActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
return !hoverActions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean onDrag(TileLegacyMachineBase provider, GuiBase gui, int mouseX, int mouseY) {
|
||||
for (ElementBase.Action action : dragActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
return !dragActions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean onStartPress(TileLegacyMachineBase provider, GuiBase gui, int mouseX, int mouseY) {
|
||||
for (ElementBase.Action action : startPressActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
return !startPressActions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean onRelease(TileLegacyMachineBase provider, GuiBase gui, int mouseX, int mouseY) {
|
||||
for (ElementBase.Action action : releaseActions) {
|
||||
if(action.execute(this, gui, provider, mouseX, mouseY)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (isPressing) {
|
||||
for (ElementBase.Action action : pressActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
return !releaseActions.isEmpty() || !pressActions.isEmpty();
|
||||
}
|
||||
|
||||
public interface Action {
|
||||
boolean execute(ElementBase element, GuiBase gui, TileLegacyMachineBase provider, int mouseX, int mouseY);
|
||||
}
|
||||
|
||||
public interface UpdateAction {
|
||||
void update(GuiBase gui, ElementBase element);
|
||||
}
|
||||
|
||||
public void drawRect(GuiBase gui, int x, int y, int width, int height, int colour) {
|
||||
drawGradientRect(gui, x, y, width, height, colour, colour);
|
||||
}
|
||||
|
||||
/*
|
||||
Taken from Gui
|
||||
*/
|
||||
public void drawGradientRect(GuiBase gui, int x, int y, int width, int height, int startColor, int endColor) {
|
||||
x = adjustX(gui, x);
|
||||
y = adjustY(gui, y);
|
||||
|
||||
int left = x;
|
||||
int top = y;
|
||||
int right = x + width;
|
||||
int bottom = y + height;
|
||||
float f = (float) (startColor >> 24 & 255) / 255.0F;
|
||||
float f1 = (float) (startColor >> 16 & 255) / 255.0F;
|
||||
float f2 = (float) (startColor >> 8 & 255) / 255.0F;
|
||||
float f3 = (float) (startColor & 255) / 255.0F;
|
||||
float f4 = (float) (endColor >> 24 & 255) / 255.0F;
|
||||
float f5 = (float) (endColor >> 16 & 255) / 255.0F;
|
||||
float f6 = (float) (endColor >> 8 & 255) / 255.0F;
|
||||
float f7 = (float) (endColor & 255) / 255.0F;
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
GlStateManager.shadeModel(7425);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder vertexbuffer = tessellator.getBuffer();
|
||||
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||
vertexbuffer.pos((double) right, (double) top, (double) 0).color(f1, f2, f3, f).endVertex();
|
||||
vertexbuffer.pos((double) left, (double) top, (double) 0).color(f1, f2, f3, f).endVertex();
|
||||
vertexbuffer.pos((double) left, (double) bottom, (double) 0).color(f5, f6, f7, f4).endVertex();
|
||||
vertexbuffer.pos((double) right, (double) bottom, (double) 0).color(f5, f6, f7, f4).endVertex();
|
||||
tessellator.draw();
|
||||
GlStateManager.shadeModel(7424);
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
public int adjustX(GuiBase gui, int x) {
|
||||
return gui.guiLeft + x;
|
||||
}
|
||||
|
||||
public int adjustY(GuiBase gui, int y) {
|
||||
return gui.guiTop + y;
|
||||
}
|
||||
|
||||
public boolean isInRect(GuiBase gui, int x, int y, int xSize, int ySize, int mouseX, int mouseY) {
|
||||
return gui.isPointInRect(x + gui.guiLeft, y + gui.guiTop, xSize, ySize, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void drawString(GuiBase gui, String string, int x, int y, int color) {
|
||||
x = adjustX(gui, x);
|
||||
y = adjustY(gui, y);
|
||||
gui.mc.fontRenderer.drawString(string, x, y, color);
|
||||
}
|
||||
|
||||
public void drawString(GuiBase gui, String string, int x, int y) {
|
||||
drawString(gui, string, x, y, 16777215);
|
||||
}
|
||||
|
||||
public void setTextureSheet(ResourceLocation textureLocation) {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(textureLocation);
|
||||
}
|
||||
|
||||
public void drawCenteredString(GuiBase gui, String string, int y, int colour) {
|
||||
drawString(gui, string, (gui.getXSize() / 2 - gui.mc.fontRenderer.getStringWidth(string) / 2), y, colour);
|
||||
}
|
||||
|
||||
public void drawCenteredString(GuiBase gui, String string, int x, int y, int colour) {
|
||||
drawString(gui, string, (x - gui.mc.fontRenderer.getStringWidth(string) / 2), y, colour);
|
||||
}
|
||||
|
||||
public int getStringWidth(String string) {
|
||||
return Minecraft.getMinecraft().fontRenderer.getStringWidth(string);
|
||||
}
|
||||
|
||||
public void drawSprite(GuiBase gui, ISprite iSprite, int x, int y) {
|
||||
Sprite sprite = iSprite.getSprite(gui.getMachine());
|
||||
if (sprite != null) {
|
||||
if (sprite.hasTextureInfo()) {
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
setTextureSheet(sprite.textureLocation);
|
||||
gui.drawTexturedModalRect(x + gui.guiLeft, y + gui.guiTop, sprite.x, sprite.y, sprite.width, sprite.height);
|
||||
}
|
||||
if (sprite.hasStack()) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
|
||||
itemRenderer.renderItemAndEffectIntoGUI(sprite.itemStack, x + gui.guiLeft, y + gui.guiTop);
|
||||
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getScaledBurnTime(int scale, int burnTime, int totalBurnTime) {
|
||||
return (int) (((float) burnTime / (float) totalBurnTime) * scale);
|
||||
}
|
||||
|
||||
public TextFormatting getPercentageColour(int percentage) {
|
||||
if (percentage <= 10) {
|
||||
return TextFormatting.RED;
|
||||
} else if (percentage >= 75) {
|
||||
return TextFormatting.GREEN;
|
||||
} else {
|
||||
return TextFormatting.YELLOW;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPercentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
|
||||
public void drawDefaultBackground(GuiScreen gui, int x, int y, int width, int height) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(GuiBuilder.defaultTextureSheet);
|
||||
gui.drawTexturedModalRect(x, y, 0, 0, width / 2, height / 2);
|
||||
gui.drawTexturedModalRect(x + width / 2, y, 150 - width / 2, 0, width / 2, height / 2);
|
||||
gui.drawTexturedModalRect(x, y + height / 2, 0, 150 - height / 2, width / 2, height / 2);
|
||||
gui.drawTexturedModalRect(x + width / 2, y + height / 2, 150 - width / 2, 150 - height / 2, width / 2, height / 2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
|
||||
public interface ISprite {
|
||||
Sprite getSprite(TileLegacyMachineBase provider);
|
||||
}
|
21
src/main/java/techreborn/client/gui/slot/elements/LICENSE
Normal file
21
src/main/java/techreborn/client/gui/slot/elements/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 Prospector
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,45 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
|
||||
public class OffsetSprite {
|
||||
public ISprite sprite;
|
||||
public int offsetX = 0;
|
||||
public int offsetY = 0;
|
||||
|
||||
public OffsetSprite(ISprite sprite, int offsetX, int offsetY) {
|
||||
this.sprite = sprite;
|
||||
this.offsetX = offsetX;
|
||||
this.offsetY = offsetY;
|
||||
}
|
||||
|
||||
public OffsetSprite(ISprite sprite) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public OffsetSprite(Sprite sprite, TileLegacyMachineBase provider) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public ISprite getSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public int getOffsetX(TileLegacyMachineBase provider) {
|
||||
return offsetX + sprite.getSprite(provider).offsetX;
|
||||
}
|
||||
|
||||
public OffsetSprite setOffsetX(int offsetX) {
|
||||
this.offsetX = offsetX;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getOffsetY(TileLegacyMachineBase provider) {
|
||||
return offsetY + sprite.getSprite(provider).offsetY;
|
||||
}
|
||||
|
||||
public OffsetSprite setOffsetY(int offsetY) {
|
||||
this.offsetY = offsetY;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
All code in this class was taken with permssion from https://github.com/ProfessorProspector/Mechanical-Construct
|
||||
|
||||
A large ammount of modifications have taken place to allow it to work with techreborn.
|
|
@ -0,0 +1,194 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.client.gui.GuiUtil;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import reborncore.common.network.packet.PacketIOSave;
|
||||
import reborncore.common.network.packet.PacketSlotSave;
|
||||
import reborncore.common.tile.SlotConfiguration;
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
import reborncore.common.util.MachineFacing;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class SlotConfigPopupElement extends ElementBase {
|
||||
int id;
|
||||
|
||||
ConfigSlotElement slotElement;
|
||||
|
||||
|
||||
public SlotConfigPopupElement(int slotId, int x, int y, ConfigSlotElement slotElement) {
|
||||
super(x, y, Sprite.SLOT_CONFIG_POPUP);
|
||||
this.id = slotId;
|
||||
this.slotElement = slotElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui) {
|
||||
drawDefaultBackground(gui, adjustX(gui, getX() -8), adjustY(gui, getY() - 7), 84, 105);
|
||||
super.draw(gui);
|
||||
|
||||
TileLegacyMachineBase machine = ((TileLegacyMachineBase) gui.tile);
|
||||
IBlockAccess blockAccess = machine.getWorld();
|
||||
BlockPos pos = machine.getPos();
|
||||
IBlockState state = blockAccess.getBlockState(pos);
|
||||
IBlockState actualState = Blocks.DIRT.getDefaultState().getActualState(blockAccess, pos);
|
||||
BlockRendererDispatcher dispatcher = FMLClientHandler.instance().getClient().getBlockRendererDispatcher();
|
||||
IBakedModel model = dispatcher.getBlockModelShapes().getModelForState(state.withProperty(BlockMachineBase.FACING, EnumFacing.NORTH));
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
drawState(gui, blockAccess, model, actualState, pos, dispatcher, 4, 23); //left
|
||||
drawState(gui, blockAccess, model, actualState, pos, dispatcher, 23, -12, -90F, 1F, 0F, 0F); //top
|
||||
drawState(gui, blockAccess, model, actualState, pos, dispatcher, 23, 23, -90F, 0F, 1F, 0F); //centre
|
||||
drawState(gui, blockAccess, model, actualState, pos, dispatcher, 23, 42, 90F, 1F, 0F, 0F); //bottom
|
||||
drawState(gui, blockAccess, model, actualState, pos, dispatcher, 26, 23, 180F, 0F, 1F, 0F); //right
|
||||
drawState(gui, blockAccess, model, actualState, pos, dispatcher, 26, 42, 90F, 0F, 1F, 0F); //back
|
||||
|
||||
|
||||
drawSlotSateColor(gui.getMachine(), MachineFacing.UP.getFacing(machine), id, 22, -1, gui);
|
||||
drawSlotSateColor(gui.getMachine(), MachineFacing.FRONT.getFacing(machine), id, 22, 18, gui);
|
||||
drawSlotSateColor(gui.getMachine(), MachineFacing.DOWN.getFacing(machine), id, 22, 37, gui);
|
||||
drawSlotSateColor(gui.getMachine(), MachineFacing.RIGHT.getFacing(machine), id, 41, 18, gui);
|
||||
drawSlotSateColor(gui.getMachine(), MachineFacing.BACK.getFacing(machine), id, 41, 37, gui);
|
||||
drawSlotSateColor(gui.getMachine(), MachineFacing.LEFT.getFacing(machine), id, 3, 18, gui);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onRelease(TileLegacyMachineBase provider, GuiBase gui, int mouseX, int mouseY) {
|
||||
if(isInBox(23 , 4, 16, 16, mouseX, mouseY, gui)){
|
||||
cyleSlotConfig(MachineFacing.UP.getFacing(provider), gui);
|
||||
} else if(isInBox(23 , 23, 16, 16, mouseX, mouseY, gui)){
|
||||
cyleSlotConfig(MachineFacing.FRONT.getFacing(provider), gui);
|
||||
} else if(isInBox(42 , 23, 16, 16, mouseX, mouseY, gui)){
|
||||
cyleSlotConfig(MachineFacing.RIGHT.getFacing(provider), gui);
|
||||
} else if(isInBox(4 , 23, 16, 16, mouseX, mouseY, gui)){
|
||||
cyleSlotConfig(MachineFacing.LEFT.getFacing(provider), gui);
|
||||
} else if(isInBox(23 , 42, 16, 16, mouseX, mouseY, gui)){
|
||||
cyleSlotConfig(MachineFacing.DOWN.getFacing(provider), gui);
|
||||
} else if(isInBox(42 , 42, 16, 16, mouseX, mouseY, gui)){
|
||||
cyleSlotConfig(MachineFacing.BACK.getFacing(provider), gui);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void cyleSlotConfig(EnumFacing side, GuiBase guiBase){
|
||||
SlotConfiguration.SlotConfig currentSlot = guiBase.getMachine().slotConfiguration.getSlotDetails(id).getSideDetail(side);
|
||||
|
||||
SlotConfiguration.SlotIO slotIO = new SlotConfiguration.SlotIO(currentSlot.getSlotIO().getIoConfig().getNext());
|
||||
SlotConfiguration.SlotConfig newConfig = new SlotConfiguration.SlotConfig(side, slotIO, id);
|
||||
PacketSlotSave packetSlotSave = new PacketSlotSave(guiBase.tile.getPos(), newConfig);
|
||||
NetworkManager.sendToServer(packetSlotSave);
|
||||
}
|
||||
|
||||
public void updateCheckBox(CheckBoxElement checkBoxElement, String type, GuiBase guiBase){
|
||||
SlotConfiguration.SlotConfigHolder configHolder = guiBase.getMachine().slotConfiguration.getSlotDetails(id);
|
||||
boolean input = configHolder.autoInput();
|
||||
boolean output = configHolder.autoOutput();
|
||||
if(type.equalsIgnoreCase("input")){
|
||||
input = !configHolder.autoInput();
|
||||
}
|
||||
if(type.equalsIgnoreCase("output")){
|
||||
output = !configHolder.autoOutput();
|
||||
}
|
||||
|
||||
PacketIOSave packetSlotSave = new PacketIOSave(guiBase.tile.getPos(), id, input, output);
|
||||
NetworkManager.sendToServer(packetSlotSave);
|
||||
}
|
||||
|
||||
private void drawSlotSateColor(TileLegacyMachineBase machineBase, EnumFacing side, int slotID, int inx, int iny, GuiBase gui){
|
||||
iny += 4;
|
||||
int sx = inx + getX() + gui.guiLeft;
|
||||
int sy = iny + getY() + gui.guiTop;
|
||||
SlotConfiguration.SlotConfigHolder slotConfigHolder = machineBase.slotConfiguration.getSlotDetails(slotID);
|
||||
if(slotConfigHolder == null){
|
||||
RebornCore.logHelper.debug("Humm, this isnt suppoed to happen");
|
||||
return;
|
||||
}
|
||||
SlotConfiguration.SlotConfig slotConfig = slotConfigHolder.getSideDetail(side);
|
||||
Color color;
|
||||
switch (slotConfig.getSlotIO().getIoConfig()){
|
||||
case NONE:
|
||||
color = new Color(0, 0, 0, 0);
|
||||
break;
|
||||
case INPUT:
|
||||
color = new Color(0, 0, 255, 128);
|
||||
break;
|
||||
case OUTPUT:
|
||||
color = new Color(255, 69, 0, 128);
|
||||
break;
|
||||
default:
|
||||
color = new Color(0, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
GlStateManager.color(255, 255, 255);
|
||||
GuiUtil.drawGradientRect(sx, sy, 18, 18, color.getRGB(), color.getRGB());
|
||||
GlStateManager.color(255, 255, 255);
|
||||
|
||||
}
|
||||
|
||||
private boolean isInBox(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY, GuiBase guiBase){
|
||||
rectX += getX();
|
||||
rectY += getY();
|
||||
if(true){
|
||||
return isInRect(guiBase, rectX, rectY, rectWidth, rectHeight, pointX, pointY);
|
||||
}
|
||||
return (pointX - guiBase.getGuiLeft()) >= rectX - 1 && (pointX - guiBase.getGuiLeft()) < rectX + rectWidth + 1 && (pointY - guiBase.getGuiTop()) >= rectY - 1 && (pointY - guiBase.getGuiTop()) < rectY + rectHeight + 1;
|
||||
}
|
||||
|
||||
public void drawState(GuiBase gui,
|
||||
IBlockAccess blockAccess,
|
||||
IBakedModel model,
|
||||
IBlockState actualState,
|
||||
BlockPos pos,
|
||||
BlockRendererDispatcher dispatcher,
|
||||
int x,
|
||||
int y,
|
||||
float rotAngle,
|
||||
float rotX,
|
||||
float rotY,
|
||||
float rotZ) {
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.translate(8 + gui.guiLeft + this.x + x, 8 + gui.guiTop + this.y + y, 512);
|
||||
GlStateManager.scale(16F, 16F, 16F);
|
||||
GlStateManager.translate(0.5F, 0.5F, 0.5F);
|
||||
GlStateManager.scale(-1, -1, -1);
|
||||
if (rotAngle != 0) {
|
||||
GlStateManager.rotate(rotAngle, rotX, rotY, rotZ);
|
||||
}
|
||||
dispatcher.getBlockModelRenderer().renderModelBrightness(model, actualState, 1F, false);
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
/* GlStateManager.pushMatrix();
|
||||
GlStateManager.enableDepth();
|
||||
// GlStateManager.translate(8 + gui.xFactor + this.x + x, 8 + gui.yFactor + this.y + y, 1000);
|
||||
GlStateManager.translate(gui.xFactor + this.x + x, gui.yFactor + this.y + y, 512);
|
||||
if (rotAngle != 0) {
|
||||
GlStateManager.rotate(rotAngle, rotX, rotY, rotZ);
|
||||
}
|
||||
GlStateManager.scale(16F, 16F, 16F);
|
||||
GlStateManager.translate(-0.5F, -0.5F, -0.5F);
|
||||
GlStateManager.scale(-1, -1, -1);
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.popMatrix();*/
|
||||
}
|
||||
|
||||
public void drawState(GuiBase gui, IBlockAccess blockAccess, IBakedModel model, IBlockState actualState, BlockPos pos, BlockRendererDispatcher dispatcher, int x, int y) {
|
||||
drawState(gui, blockAccess, model, actualState, pos, dispatcher, x, y, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class SlotElement extends ElementBase {
|
||||
protected ItemStackHandler slotInventory;
|
||||
protected SlotType type;
|
||||
int slotId, slotX, slotY;
|
||||
|
||||
public SlotElement(ItemStackHandler slotInventory, int slotId, int slotX, int slotY, SlotType type, int x, int y) {
|
||||
super(x, y, type.getSprite());
|
||||
this.type = type;
|
||||
this.slotInventory = slotInventory;
|
||||
this.slotId = slotId;
|
||||
this.slotX = slotX;
|
||||
this.slotY = slotY;
|
||||
}
|
||||
|
||||
public SlotType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public ItemStackHandler getSlotInventory() {
|
||||
return slotInventory;
|
||||
}
|
||||
|
||||
public int getSlotId() {
|
||||
return slotId;
|
||||
}
|
||||
|
||||
public int getSlotX() {
|
||||
return slotX;
|
||||
}
|
||||
|
||||
public int getSlotY() {
|
||||
return slotY;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
public enum SlotType {
|
||||
NORMAL(1, 1, Sprite.SLOT_NORMAL, Sprite.BUTTON_SLOT_NORMAL, Sprite.BUTTON_HOVER_OVERLAY_SLOT_NORMAL);
|
||||
|
||||
int slotOffsetX;
|
||||
int slotOffsetY;
|
||||
Sprite sprite;
|
||||
Sprite buttonSprite;
|
||||
Sprite buttonHoverOverlay;
|
||||
|
||||
SlotType(int slotOffsetX, int slotOffsetY, Sprite sprite, Sprite buttonSprite, Sprite buttonHoverOverlay) {
|
||||
this.slotOffsetX = slotOffsetX;
|
||||
this.slotOffsetY = slotOffsetY;
|
||||
this.sprite = sprite;
|
||||
this.buttonSprite = buttonSprite;
|
||||
this.buttonHoverOverlay = buttonHoverOverlay;
|
||||
}
|
||||
|
||||
SlotType(int slotOffset, Sprite sprite) {
|
||||
this.slotOffsetX = slotOffset;
|
||||
this.slotOffsetY = slotOffset;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public int getSlotOffsetX() {
|
||||
return slotOffsetX;
|
||||
}
|
||||
|
||||
public int getSlotOffsetY() {
|
||||
return slotOffsetY;
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public Sprite getButtonSprite() {
|
||||
return buttonSprite;
|
||||
}
|
||||
|
||||
public Sprite getButtonHoverOverlay() {
|
||||
return buttonHoverOverlay;
|
||||
}
|
||||
}
|
145
src/main/java/techreborn/client/gui/slot/elements/Sprite.java
Normal file
145
src/main/java/techreborn/client/gui/slot/elements/Sprite.java
Normal file
|
@ -0,0 +1,145 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
|
||||
public class Sprite implements ISprite {
|
||||
public static final Sprite EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 0, 0);
|
||||
public static final Sprite SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 18, 18);
|
||||
public static final Sprite CHARGE_SLOT_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 18, 0, 18, 18);
|
||||
public static final Sprite DISCHARGE_SLOT_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 36, 0, 18, 18);
|
||||
public static final Sprite ENERGY_BAR = new Sprite(ElementBase.MECH_ELEMENTS, 0, 18, 12, 40);
|
||||
public static final Sprite ENERGY_BAR_BACKGROUND = new Sprite(ElementBase.MECH_ELEMENTS, 12, 18, 14, 42);
|
||||
public static final Sprite TOP_ENERGY_BAR = new Sprite(ElementBase.MECH_ELEMENTS, 0, 215, 167, 2);
|
||||
public static final Sprite TOP_ENERGY_BAR_BACKGROUND = new Sprite(ElementBase.MECH_ELEMENTS, 0, 217, 169, 3);
|
||||
public static final Sprite LEFT_TAB = new Sprite(ElementBase.MECH_ELEMENTS, 0, 86, 23, 26);
|
||||
public static final Sprite LEFT_TAB_SELECTED = new Sprite(ElementBase.MECH_ELEMENTS, 0, 60, 29, 26);
|
||||
public static final Sprite CONFIGURE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 18, 16, 16);
|
||||
public static final Sprite REDSTONE_DISABLED_ICON = new Sprite(new ItemStack(Items.GUNPOWDER));
|
||||
public static final Sprite REDSTONE_LOW_ICON = new Sprite(new ItemStack(Items.REDSTONE));
|
||||
public static final Sprite REDSTONE_HIGH_ICON = new Sprite(new ItemStack(Blocks.REDSTONE_TORCH));
|
||||
public static final Sprite UPGRADE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 34, 16, 16);
|
||||
public static final Sprite ENERGY_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 46, 19, 9, 13);
|
||||
public static final Sprite ENERGY_ICON_EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 62, 19, 9, 13);
|
||||
public static final Sprite JEI_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 42, 34, 16, 16);
|
||||
public static final Sprite BUTTON_SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 54, 0, 18, 18);
|
||||
public static final Sprite FAKE_SLOT = new Sprite(ElementBase.MECH_ELEMENTS, 72, 0, 18, 18);
|
||||
public static final Sprite BUTTON_HOVER_OVERLAY_SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 90, 0, 18, 18);
|
||||
public static final Sprite SLOT_CONFIG_POPUP = new Sprite(ElementBase.MECH_ELEMENTS, 29, 60, 62, 62);
|
||||
public static final Sprite.Button EXIT_BUTTON = new Sprite.Button(new Sprite(ElementBase.MECH_ELEMENTS, 26, 122, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 39, 122, 13, 13));
|
||||
public static final Sprite.CheckBox DARK_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 18, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 18, 16, 13));
|
||||
public static final Sprite.CheckBox LIGHT_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 31, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 31, 16, 13));
|
||||
|
||||
public final ResourceLocation textureLocation;
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int width;
|
||||
public final int height;
|
||||
public int offsetX = 0;
|
||||
public int offsetY = 0;
|
||||
public ItemStack itemStack;
|
||||
|
||||
public Sprite(ResourceLocation textureLocation, int x, int y, int width, int height) {
|
||||
this.textureLocation = textureLocation;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.itemStack = null;
|
||||
}
|
||||
|
||||
public Sprite(ItemStack stack) {
|
||||
this.textureLocation = null;
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
this.width = -1;
|
||||
this.height = -1;
|
||||
this.itemStack = stack;
|
||||
}
|
||||
|
||||
public boolean hasStack() {
|
||||
return itemStack != null;
|
||||
}
|
||||
|
||||
public boolean hasTextureInfo() {
|
||||
return x >= 0 && y >= 0 && width >= 0 && height >= 0;
|
||||
}
|
||||
|
||||
public Sprite setOffsetX(int offsetX) {
|
||||
this.offsetX = offsetX;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Sprite setOffsetY(int offsetY) {
|
||||
this.offsetY = offsetY;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite(TileLegacyMachineBase provider) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Button {
|
||||
private Sprite normal;
|
||||
private Sprite hovered;
|
||||
|
||||
public Button(Sprite normal, Sprite hovered) {
|
||||
this.normal = normal;
|
||||
this.hovered = hovered;
|
||||
}
|
||||
|
||||
public Sprite getNormal() {
|
||||
return normal;
|
||||
}
|
||||
|
||||
public Sprite getHovered() {
|
||||
return hovered;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ToggleButton {
|
||||
private Sprite normal;
|
||||
private Sprite hovered;
|
||||
private Sprite pressed;
|
||||
|
||||
public ToggleButton(Sprite normal, Sprite hovered, Sprite pressed) {
|
||||
this.normal = normal;
|
||||
this.hovered = hovered;
|
||||
this.pressed = pressed;
|
||||
}
|
||||
|
||||
public Sprite getNormal() {
|
||||
return normal;
|
||||
}
|
||||
|
||||
public Sprite getHovered() {
|
||||
return hovered;
|
||||
}
|
||||
|
||||
public Sprite getPressed() {
|
||||
return pressed;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CheckBox {
|
||||
private Sprite normal;
|
||||
private Sprite ticked;
|
||||
|
||||
public CheckBox(Sprite normal, Sprite ticked) {
|
||||
this.normal = normal;
|
||||
this.ticked = ticked;
|
||||
}
|
||||
|
||||
public Sprite getNormal() {
|
||||
return normal;
|
||||
}
|
||||
|
||||
public Sprite getTicked() {
|
||||
return ticked;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package techreborn.client.gui.slot.elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpriteContainer {
|
||||
public List<OffsetSprite> offsetSprites = new ArrayList<>();
|
||||
|
||||
public SpriteContainer setSprite(int index, OffsetSprite sprite) {
|
||||
offsetSprites.set(index, sprite);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer setSprite(int index, ISprite sprite, int offsetX, int offsetY) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.set(index, new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX + offsetX).setOffsetY(((Sprite) sprite).offsetY + offsetY));
|
||||
} else {
|
||||
offsetSprites.set(index, new OffsetSprite(sprite, offsetX, offsetY));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer setSprite(int index, ISprite sprite) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.set(index, new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX).setOffsetY(((Sprite) sprite).offsetY));
|
||||
} else {
|
||||
offsetSprites.add(index, new OffsetSprite(sprite));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer addSprite(OffsetSprite sprite) {
|
||||
offsetSprites.add(sprite);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer addSprite(ISprite sprite, int offsetX, int offsetY) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.add(new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX + offsetX).setOffsetY(((Sprite) sprite).offsetY + offsetY));
|
||||
} else {
|
||||
offsetSprites.add(new OffsetSprite(sprite, offsetX, offsetY));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer addSprite(ISprite sprite) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.add(new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX).setOffsetY(((Sprite) sprite).offsetY));
|
||||
} else {
|
||||
offsetSprites.add(new OffsetSprite(sprite));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue