mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 06:42:56 +00:00
Cleanup implementation of buttons in generators module, and do some button cleanup on GuiLogisticalSorter
This commit is contained in:
4 files changed
+120
-97
No files matched your search
@@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.client.gui.button.GuiButtonImageMek;
|
||||
import mekanism.client.gui.element.GuiRedstoneControl;
|
||||
import mekanism.client.gui.element.tab.GuiSecurityTab;
|
||||
import mekanism.client.gui.element.tab.GuiUpgradeTab;
|
||||
@@ -20,6 +21,7 @@ import mekanism.common.content.transporter.TransporterFilter;
|
||||
import mekanism.common.inventory.container.ContainerNull;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMessage;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.tile.TileEntityLogisticalSorter;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
@@ -37,6 +39,10 @@ import org.lwjgl.input.Keyboard;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiLogisticalSorter extends GuiFilterHolder<TileEntityLogisticalSorter, TransporterFilter> {
|
||||
|
||||
private GuiButtonImageMek singleItemButton;
|
||||
private GuiButtonImageMek roundRobinButton;
|
||||
private GuiButtonImageMek autoEjectButton;
|
||||
|
||||
public GuiLogisticalSorter(EntityPlayer player, TileEntityLogisticalSorter tile) {
|
||||
super(tile, new ContainerNull(player, tile));
|
||||
|
||||
@@ -47,18 +53,6 @@ public class GuiLogisticalSorter extends GuiFilterHolder<TileEntityLogisticalSor
|
||||
addGuiElement(new GuiSecurityTab(this, tileEntity, resource));
|
||||
}
|
||||
|
||||
private boolean overAutoEject(int xAxis, int yAxis) {
|
||||
return xAxis >= 12 && xAxis <= 26 && yAxis >= 110 && yAxis <= 124;
|
||||
}
|
||||
|
||||
private boolean overRoundRobin(int xAxis, int yAxis) {
|
||||
return xAxis >= 12 && xAxis <= 26 && yAxis >= 84 && yAxis <= 98;
|
||||
}
|
||||
|
||||
private boolean overSingleItem(int xAxis, int yAxis) {
|
||||
return xAxis >= 12 && xAxis <= 26 && yAxis >= 58 && yAxis <= 72;
|
||||
}
|
||||
|
||||
private boolean overColor(int xAxis, int yAxis) {
|
||||
return xAxis >= 13 && xAxis <= 29 && yAxis >= 137 && yAxis <= 153;
|
||||
}
|
||||
@@ -126,17 +120,6 @@ public class GuiLogisticalSorter extends GuiFilterHolder<TileEntityLogisticalSor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (overAutoEject(xAxis, yAxis)) {
|
||||
//Auto eject button
|
||||
sendDataFromClick(TileNetworkList.withContents(1), SoundEvents.UI_BUTTON_CLICK);
|
||||
} else if (overRoundRobin(xAxis, yAxis)) {
|
||||
//Round robin button
|
||||
sendDataFromClick(TileNetworkList.withContents(2), SoundEvents.UI_BUTTON_CLICK);
|
||||
} else if (overSingleItem(xAxis, yAxis)) {
|
||||
//Single item button
|
||||
sendDataFromClick(TileNetworkList.withContents(5), SoundEvents.UI_BUTTON_CLICK);
|
||||
}
|
||||
}
|
||||
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && mouseBtn == 0) {
|
||||
@@ -167,6 +150,14 @@ public class GuiLogisticalSorter extends GuiFilterHolder<TileEntityLogisticalSor
|
||||
// Add buttons to gui
|
||||
buttonList.clear();
|
||||
buttonList.add(new GuiButton(BUTTON_NEW, guiLeft + filterX, guiTop + 136, filterW, 20, LangUtils.localize("gui.newFilter")));
|
||||
|
||||
singleItemButton = new GuiButtonImageMek(1, guiLeft + 12, guiTop + 58, 14, 14, 204, 14, -14, getGuiLocation());
|
||||
roundRobinButton = new GuiButtonImageMek(2, guiLeft + 12, guiTop + 84, 14, 14, 190, 14, -14, getGuiLocation());
|
||||
autoEjectButton = new GuiButtonImageMek(3, guiLeft + 12, guiTop + 110, 14, 14, 176, 14, -14, getGuiLocation());
|
||||
|
||||
buttonList.add(singleItemButton);
|
||||
buttonList.add(roundRobinButton);
|
||||
buttonList.add(autoEjectButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,6 +165,12 @@ public class GuiLogisticalSorter extends GuiFilterHolder<TileEntityLogisticalSor
|
||||
super.actionPerformed(guibutton);
|
||||
if (guibutton.id == BUTTON_NEW) {
|
||||
sendPacket(SorterGuiPacket.SERVER, 4, 0, null);
|
||||
} else if (guibutton.id == singleItemButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(5)));
|
||||
} else if (guibutton.id == roundRobinButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(2)));
|
||||
} else if (guibutton.id == autoEjectButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(1)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,22 +245,13 @@ public class GuiLogisticalSorter extends GuiFilterHolder<TileEntityLogisticalSor
|
||||
} else {
|
||||
drawHoveringText(LangUtils.localize("gui.none"), xAxis, yAxis);
|
||||
}
|
||||
} else if (overAutoEject(xAxis, yAxis)) {
|
||||
} else if (autoEjectButton.isMouseOver()) {
|
||||
drawHoveringText(MekanismUtils.splitTooltip(LangUtils.localize("mekanism.gui.logisticalSorter.autoEject.tooltip"), ItemStack.EMPTY), xAxis, yAxis);
|
||||
} else if (overRoundRobin(xAxis, yAxis)) {
|
||||
} else if (roundRobinButton.isMouseOver()) {
|
||||
drawHoveringText(MekanismUtils.splitTooltip(LangUtils.localize("mekanism.gui.logisticalSorter.roundRobin.tooltip"), ItemStack.EMPTY), xAxis, yAxis);
|
||||
} else if (overSingleItem(xAxis, yAxis)) {
|
||||
} else if (singleItemButton.isMouseOver()) {
|
||||
drawHoveringText(MekanismUtils.splitTooltip(LangUtils.localize("mekanism.gui.logisticalSorter.singleItem.tooltip"), ItemStack.EMPTY), xAxis, yAxis);
|
||||
}
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
|
||||
super.drawGuiContainerBackgroundLayer(xAxis, yAxis);
|
||||
// Draw gui buttons
|
||||
drawTexturedModalRect(guiLeft + 12, guiTop + 110, 176, 0, overAutoEject(xAxis, yAxis), 14);
|
||||
drawTexturedModalRect(guiLeft + 12, guiTop + 84, 190, 0, overRoundRobin(xAxis, yAxis), 14);
|
||||
drawTexturedModalRect(guiLeft + 12, guiTop + 58, 204, 0, overSingleItem(xAxis, yAxis), 14);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@ package mekanism.generators.client.gui;
|
||||
import java.io.IOException;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.client.gui.GuiMekanismTile;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.client.gui.button.GuiButtonImageMek;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.generators.common.tile.reactor.TileEntityReactorController;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -18,26 +18,24 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class GuiReactorInfo extends GuiMekanismTile<TileEntityReactorController> {
|
||||
|
||||
private GuiButtonImageMek backButton;
|
||||
|
||||
public GuiReactorInfo(TileEntityReactorController tile, Container container) {
|
||||
super(tile, container);
|
||||
}
|
||||
|
||||
private boolean overBackButton(int xAxis, int yAxis) {
|
||||
return xAxis >= 6 && xAxis <= 20 && yAxis >= 6 && yAxis <= 20;
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
backButton = new GuiButtonImageMek(0, guiLeft + 6, guiTop + 6, 14, 14, 176, 14, -14, getGuiLocation());
|
||||
buttonList.add(backButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
|
||||
drawTexturedModalRect(guiLeft + 6, guiTop + 6, 176, 0, overBackButton(xAxis, yAxis), 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
int xAxis = mouseX - guiLeft;
|
||||
int yAxis = mouseY - guiTop;
|
||||
if (button == 0 && overBackButton(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
protected void actionPerformed(GuiButton guibutton) throws IOException {
|
||||
super.actionPerformed(guibutton);
|
||||
if (guibutton.id == backButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 1, 10));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package mekanism.generators.client.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.client.gui.GuiMekanismTile;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.client.gui.button.GuiButtonImageMek;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.inventory.container.ContainerNull;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.generators.client.gui.button.GuiReactorLogicButton;
|
||||
import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter;
|
||||
import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter.ReactorLogic;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -24,16 +26,41 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiReactorLogicAdapter extends GuiMekanismTile<TileEntityReactorLogicAdapter> {
|
||||
|
||||
private List<GuiReactorLogicButton> typeButtons = new ArrayList<>();
|
||||
private GuiButtonImageMek coolingButton;
|
||||
private int buttonID = 0;
|
||||
|
||||
public GuiReactorLogicAdapter(InventoryPlayer inventory, final TileEntityReactorLogicAdapter tile) {
|
||||
super(tile, new ContainerNull(inventory.player, tile));
|
||||
}
|
||||
|
||||
private boolean overCooling(int xAxis, int yAxis) {
|
||||
return xAxis >= 23 && xAxis <= 34 && yAxis >= 19 && yAxis <= 30;
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
coolingButton = new GuiButtonImageMek(buttonID++, guiLeft + 23, guiTop + 19, 11, 11, 176, 11, -11, getGuiLocation());
|
||||
buttonList.add(coolingButton);
|
||||
for (ReactorLogic type : ReactorLogic.values()) {
|
||||
int typeShift = 22 * type.ordinal();
|
||||
GuiReactorLogicButton button = new GuiReactorLogicButton(buttonID++, guiLeft + 24, guiTop + 32 + typeShift, type, tileEntity, getGuiLocation());
|
||||
buttonList.add(button);
|
||||
typeButtons.add(button);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean overType(int xAxis, int yAxis, ReactorLogic type) {
|
||||
return xAxis >= 24 && xAxis <= 152 && yAxis >= 32 + (22 * type.ordinal()) && yAxis <= 32 + 22 + (22 * type.ordinal());
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) throws IOException {
|
||||
super.actionPerformed(guibutton);
|
||||
if (guibutton.id == coolingButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(0)));
|
||||
} else {
|
||||
for (GuiReactorLogicButton button : typeButtons) {
|
||||
if (guibutton.id == button.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(1, button.getType().ordinal())));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,56 +70,23 @@ public class GuiReactorLogicAdapter extends GuiMekanismTile<TileEntityReactorLog
|
||||
renderScaledText(LangUtils.localize("gui.redstoneOutputMode") + ": " + EnumColor.RED + tileEntity.logicType.getLocalizedName(), 23, 123, 0x404040, 130);
|
||||
String text = LangUtils.localize("gui.status") + ": " + EnumColor.RED + LangUtils.localize("gui." + (tileEntity.checkMode() ? "outputting" : "idle"));
|
||||
fontRenderer.drawString(text, (xSize / 2) - (fontRenderer.getStringWidth(text) / 2), 136, 0x404040);
|
||||
for (ReactorLogic type : ReactorLogic.values()) {
|
||||
renderItem(type.getRenderStack(), 27, 35 + (22 * type.ordinal()));
|
||||
fontRenderer.drawString(EnumColor.WHITE + type.getLocalizedName(), 46, 34 + (22 * type.ordinal()), 0x404040);
|
||||
}
|
||||
int xAxis = mouseX - guiLeft;
|
||||
int yAxis = mouseY - guiTop;
|
||||
for (ReactorLogic type : ReactorLogic.values()) {
|
||||
if (overType(xAxis, yAxis, type)) {
|
||||
for (GuiReactorLogicButton button : typeButtons) {
|
||||
ReactorLogic type = button.getType();
|
||||
int typeOffset = 22 * type.ordinal();
|
||||
renderItem(type.getRenderStack(), 27, 35 + typeOffset);
|
||||
fontRenderer.drawString(EnumColor.WHITE + type.getLocalizedName(), 46, 34 + typeOffset, 0x404040);
|
||||
if (button.isMouseOver()) {
|
||||
displayTooltips(MekanismUtils.splitTooltip(type.getDescription(), ItemStack.EMPTY), xAxis, yAxis);
|
||||
}
|
||||
}
|
||||
if (overCooling(xAxis, yAxis)) {
|
||||
if (coolingButton.isMouseOver()) {
|
||||
drawHoveringText(LangUtils.localize("gui.toggleCooling"), xAxis, yAxis);
|
||||
}
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
|
||||
for (ReactorLogic type : ReactorLogic.values()) {
|
||||
MekanismRenderer.color(EnumColor.RED);
|
||||
drawTexturedModalRect(guiLeft + 24, guiTop + 32 + (22 * type.ordinal()), 0, 166 + (type == tileEntity.logicType ? 22 : 0), 128, 22);
|
||||
}
|
||||
MekanismRenderer.resetColor();
|
||||
drawTexturedModalRect(guiLeft + 23, guiTop + 19, 176, 0, overCooling(xAxis, yAxis), 11);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
if (button == 0) {
|
||||
int xAxis = mouseX - guiLeft;
|
||||
int yAxis = mouseY - guiTop;
|
||||
if (overCooling(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(0);
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
return;
|
||||
}
|
||||
for (ReactorLogic type : ReactorLogic.values()) {
|
||||
if (overType(xAxis, yAxis, type) && type != tileEntity.logicType) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(1, type.ordinal());
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation getGuiLocation() {
|
||||
return MekanismUtils.getResource(ResourceType.GUI, "GuiReactorLogicAdapter.png");
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package mekanism.generators.client.gui.button;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter;
|
||||
import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter.ReactorLogic;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiReactorLogicButton extends GuiButton {
|
||||
|
||||
@Nonnull
|
||||
private final TileEntityReactorLogicAdapter tile;
|
||||
private final ResourceLocation resourceLocation;
|
||||
private final ReactorLogic type;
|
||||
|
||||
public GuiReactorLogicButton(int id, int x, int y, ReactorLogic type, @Nonnull TileEntityReactorLogicAdapter tile, ResourceLocation resource) {
|
||||
super(id, x, y, 128, 22, "");
|
||||
this.tile = tile;
|
||||
this.type = type;
|
||||
this.resourceLocation = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (this.visible) {
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
mc.getTextureManager().bindTexture(this.resourceLocation);
|
||||
MekanismRenderer.color(EnumColor.RED);
|
||||
drawTexturedModalRect(this.x, this.y, 0, 166 + (type == tile.logicType ? 22 : 0), this.width, this.height);
|
||||
MekanismRenderer.resetColor();
|
||||
}
|
||||
}
|
||||
|
||||
public ReactorLogic getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user