mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
Further cleanup tab element code
This commit is contained in:
9 files changed
+79
-167
No files matched your search
@@ -15,7 +15,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiBoilerTab extends GuiTabElement<TileEntityBoilerCasing, BoilerTab> {
|
||||
public class GuiBoilerTab extends GuiTabElementType<TileEntityBoilerCasing, BoilerTab> {
|
||||
|
||||
public GuiBoilerTab(IGuiWrapper gui, TileEntityBoilerCasing tileEntityBoilerCasing, BoilerTab type, int y, ResourceLocation def) {
|
||||
super(gui, tileEntityBoilerCasing, type, y, def);
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiMatrixTab extends GuiTabElement<TileEntityInductionCasing, MatrixTab> {
|
||||
public class GuiMatrixTab extends GuiTabElementType<TileEntityInductionCasing, MatrixTab> {
|
||||
|
||||
public GuiMatrixTab(IGuiWrapper gui, TileEntityInductionCasing tileEntityInductionCasing, MatrixTab type, int y, ResourceLocation def) {
|
||||
super(gui, tileEntityInductionCasing, type, y, def);
|
||||
|
||||
@@ -2,62 +2,30 @@ package mekanism.client.gui.element.tab;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.GuiTileEntityElement;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiSideConfigurationTab extends GuiTileEntityElement<TileEntity> {
|
||||
public class GuiSideConfigurationTab extends GuiTabElement<TileEntity> {
|
||||
|
||||
public GuiSideConfigurationTab(IGuiWrapper gui, TileEntity tile, ResourceLocation def) {
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiConfigurationTab.png"), gui, def, tile);
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiConfigurationTab.png"), gui, def, tile, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle4i getBounds(int guiWidth, int guiHeight) {
|
||||
return new Rectangle4i(guiWidth - 26, guiHeight + 6, 26, 26);
|
||||
public void displayForegroundTooltip(int xAxis, int yAxis) {
|
||||
displayTooltip(LangUtils.localize("gui.configuration.side"), xAxis, yAxis);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inBounds(int xAxis, int yAxis) {
|
||||
return xAxis >= -21 && xAxis <= -3 && yAxis >= 10 && yAxis <= 28;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
guiObj.drawTexturedRect(guiWidth - 26, guiHeight + 6, 0, 0, 26, 26);
|
||||
guiObj.drawTexturedRect(guiWidth - 21, guiHeight + 10, 26, inBounds(xAxis, yAxis) ? 0 : 18, 18, 18);
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForeground(int xAxis, int yAxis) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
displayTooltip(LangUtils.localize("gui.configuration.side"), xAxis, yAxis);
|
||||
}
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preMouseClicked(int xAxis, int yAxis, int button) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {
|
||||
if (button == 0 && inBounds(xAxis, yAxis)) {
|
||||
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 0, 9));
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
}
|
||||
public void buttonClicked() {
|
||||
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 0, 9));
|
||||
}
|
||||
}
|
||||
@@ -7,17 +7,19 @@ import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class GuiTabElement<TILE extends TileEntity, TAB extends Enum & TabType> extends GuiTileEntityElement<TILE> {
|
||||
public abstract class GuiTabElement<TILE extends TileEntity> extends GuiTileEntityElement<TILE> {
|
||||
|
||||
protected final TAB tabType;
|
||||
protected final int yPos;
|
||||
|
||||
public GuiTabElement(IGuiWrapper gui, TILE tile, TAB type, int y, ResourceLocation def) {
|
||||
super(type.getResource(), gui, def, tile);
|
||||
tabType = type;
|
||||
public GuiTabElement(ResourceLocation resource, IGuiWrapper gui, ResourceLocation def, TILE tile, int y) {
|
||||
super(resource, gui, def, tile);
|
||||
yPos = y;
|
||||
}
|
||||
|
||||
public abstract void displayForegroundTooltip(int xAxis, int yAxis);
|
||||
|
||||
public abstract void buttonClicked();
|
||||
|
||||
@Override
|
||||
public Rectangle4i getBounds(int guiWidth, int guiHeight) {
|
||||
return new Rectangle4i(guiWidth - 26, guiHeight + yPos, 26, 26);
|
||||
@@ -28,25 +30,16 @@ public abstract class GuiTabElement<TILE extends TileEntity, TAB extends Enum &
|
||||
return xAxis >= -21 && xAxis <= -3 && yAxis >= yPos + 4 && yAxis <= yPos + 22;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preMouseClicked(int xAxis, int yAxis, int button) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {
|
||||
if (button == 0 && inBounds(xAxis, yAxis)) {
|
||||
tabType.openGui(tileEntity);
|
||||
buttonClicked();
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForeground(int xAxis, int yAxis) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
displayTooltip(tabType.getDesc(), xAxis, yAxis);
|
||||
}
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
public void preMouseClicked(int xAxis, int yAxis, int button) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,4 +49,13 @@ public abstract class GuiTabElement<TILE extends TileEntity, TAB extends Enum &
|
||||
guiObj.drawTexturedRect(guiWidth - 21, guiHeight + yPos + 4, 26, inBounds(xAxis, yAxis) ? 0 : 18, 18, 18);
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForeground(int xAxis, int yAxis) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
displayForegroundTooltip(xAxis, yAxis);
|
||||
}
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package mekanism.client.gui.element.tab;
|
||||
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class GuiTabElementType<TILE extends TileEntity, TAB extends Enum & TabType> extends GuiTabElement<TILE> {
|
||||
|
||||
protected final TAB tabType;
|
||||
|
||||
public GuiTabElementType(IGuiWrapper gui, TILE tile, TAB type, int y, ResourceLocation def) {
|
||||
super(type.getResource(), gui, def, tile, y);
|
||||
tabType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonClicked() {
|
||||
tabType.openGui(tileEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayForegroundTooltip(int xAxis, int yAxis) {
|
||||
displayTooltip(tabType.getDesc(), xAxis, yAxis);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package mekanism.client.gui.element.tab;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.tab.GuiTransporterConfigTab.TransporterConfigTab;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
@@ -14,38 +13,19 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiTransporterConfigTab extends GuiTabElement<TileEntity, TransporterConfigTab> {
|
||||
public class GuiTransporterConfigTab extends GuiTabElement<TileEntity> {
|
||||
|
||||
public GuiTransporterConfigTab(IGuiWrapper gui, int y, TileEntity tile, ResourceLocation def) {
|
||||
super(gui, tile, TransporterConfigTab.CONFIG, y, def);
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiTransporterConfigTab.png"), gui, def, tile, y);
|
||||
}
|
||||
|
||||
public enum TransporterConfigTab implements TabType {
|
||||
CONFIG("GuiTransporterConfigTab.png", 51, "gui.configuration.transporter");
|
||||
@Override
|
||||
public void buttonClicked() {
|
||||
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 0, 51));
|
||||
}
|
||||
|
||||
private final String path;
|
||||
private final int guiId;
|
||||
private final String desc;
|
||||
|
||||
TransporterConfigTab(String s, int id, String s1) {
|
||||
path = s;
|
||||
guiId = id;
|
||||
desc = s1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getResource() {
|
||||
return MekanismUtils.getResource(ResourceType.GUI_ELEMENT, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openGui(TileEntity tile) {
|
||||
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tile), 0, guiId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return LangUtils.localize(desc);
|
||||
}
|
||||
@Override
|
||||
public void displayForegroundTooltip(int xAxis, int yAxis) {
|
||||
displayTooltip(LangUtils.localize("gui.configuration.transporter"), xAxis, yAxis);
|
||||
}
|
||||
}
|
||||
@@ -2,66 +2,34 @@ package mekanism.client.gui.element.tab;
|
||||
|
||||
import java.util.Arrays;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.GuiTileEntityElement;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.tile.TileEntityDigitalMiner;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiVisualsTab extends GuiTileEntityElement<TileEntityDigitalMiner> {
|
||||
public class GuiVisualsTab extends GuiTabElement<TileEntityDigitalMiner> {
|
||||
|
||||
public GuiVisualsTab(IGuiWrapper gui, TileEntityDigitalMiner tile, ResourceLocation def) {
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiVisualsTab.png"), gui, def, tile);
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiVisualsTab.png"), gui, def, tile, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle4i getBounds(int guiWidth, int guiHeight) {
|
||||
return new Rectangle4i(guiWidth - 26, guiHeight + 6, 26, 26);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inBounds(int xAxis, int yAxis) {
|
||||
return xAxis >= -21 && xAxis <= -3 && yAxis >= 10 && yAxis <= 28;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
guiObj.drawTexturedRect(guiWidth - 26, guiHeight + 6, 0, 0, 26, 26);
|
||||
guiObj.drawTexturedRect(guiWidth - 21, guiHeight + 10, 26, inBounds(xAxis, yAxis) ? 0 : 18, 18, 18);
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForeground(int xAxis, int yAxis) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
if (tileEntity.getRadius() <= 64) {
|
||||
displayTooltip(LangUtils.localize("gui.visuals") + ": " + LangUtils.transOnOff(tileEntity.clientRendering), xAxis, yAxis);
|
||||
} else {
|
||||
displayTooltips(Arrays.asList(LangUtils.localize("gui.visuals") + ": " + LangUtils.transOnOff(tileEntity.clientRendering),
|
||||
TextFormatting.RED.toString() + LangUtils.localize("mekanism.gui.visuals.toobig")), xAxis, yAxis);
|
||||
}
|
||||
public void displayForegroundTooltip(int xAxis, int yAxis) {
|
||||
if (tileEntity.getRadius() <= 64) {
|
||||
displayTooltip(LangUtils.localize("gui.visuals") + ": " + LangUtils.transOnOff(tileEntity.clientRendering), xAxis, yAxis);
|
||||
} else {
|
||||
displayTooltips(Arrays.asList(LangUtils.localize("gui.visuals") + ": " + LangUtils.transOnOff(tileEntity.clientRendering),
|
||||
TextFormatting.RED.toString() + LangUtils.localize("mekanism.gui.visuals.toobig")), xAxis, yAxis);
|
||||
}
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preMouseClicked(int xAxis, int yAxis, int button) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {
|
||||
if (button == 0 && inBounds(xAxis, yAxis)) {
|
||||
tileEntity.clientRendering = !tileEntity.clientRendering;
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
}
|
||||
public void buttonClicked() {
|
||||
tileEntity.clientRendering = !tileEntity.clientRendering;
|
||||
}
|
||||
}
|
||||
@@ -2,62 +2,31 @@ package mekanism.generators.client.gui.element;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.GuiTileEntityElement;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.client.gui.element.tab.GuiTabElement;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
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.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiHeatTab extends GuiTileEntityElement<TileEntityReactorController> {
|
||||
public class GuiHeatTab extends GuiTabElement<TileEntityReactorController> {
|
||||
|
||||
public GuiHeatTab(IGuiWrapper gui, TileEntityReactorController tile, ResourceLocation def) {
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiHeatTab.png"), gui, def, tile);
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiHeatTab.png"), gui, def, tile, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle4i getBounds(int guiWidth, int guiHeight) {
|
||||
return new Rectangle4i(guiWidth - 26, guiHeight + 6, 26, 26);
|
||||
public void displayForegroundTooltip(int xAxis, int yAxis) {
|
||||
displayTooltip(LangUtils.localize("gui.heat"), xAxis, yAxis);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inBounds(int xAxis, int yAxis) {
|
||||
return xAxis >= -21 && xAxis <= -3 && yAxis >= 10 && yAxis <= 28;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
guiObj.drawTexturedRect(guiWidth - 26, guiHeight + 6, 0, 0, 26, 26);
|
||||
guiObj.drawTexturedRect(guiWidth - 21, guiHeight + 10, 26, inBounds(xAxis, yAxis) ? 0 : 18, 18, 18);
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForeground(int xAxis, int yAxis) {
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
displayTooltip(LangUtils.localize("gui.heat"), xAxis, yAxis);
|
||||
}
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preMouseClicked(int xAxis, int yAxis, int button) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {
|
||||
if (button == 0 && inBounds(xAxis, yAxis)) {
|
||||
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 1, 11));
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
}
|
||||
public void buttonClicked() {
|
||||
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 1, 11));
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package mekanism.generators.client.gui.element;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.tab.GuiTabElement;
|
||||
import mekanism.client.gui.element.tab.GuiTabElementType;
|
||||
import mekanism.client.gui.element.tab.TabType;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
|
||||
@@ -17,7 +17,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiTurbineTab extends GuiTabElement<TileEntityTurbineCasing, TurbineTab> {
|
||||
public class GuiTurbineTab extends GuiTabElementType<TileEntityTurbineCasing, TurbineTab> {
|
||||
|
||||
public GuiTurbineTab(IGuiWrapper gui, TileEntityTurbineCasing tileEntityTurbineCasing, TurbineTab type, int y, ResourceLocation def) {
|
||||
super(gui, tileEntityTurbineCasing, type, y, def);
|
||||
|
||||
Reference in new issue
Block a user