mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 20:22:12 +00:00
Merge pull request #1864 from MatthiasMann/clear_sideconfig
allow shift click on side config button to reset all sides to default
This commit is contained in:
commit
0c77fd1319
13 files changed
+160
-76
No files matched your search
@@ -6,8 +6,8 @@ import crazypants.gui.IGuiScreen;
|
||||
public class ToggleButtonEIO extends IconButtonEIO {
|
||||
|
||||
private boolean selected;
|
||||
private IconEIO unselectedIcon;
|
||||
private IconEIO selectedIcon;
|
||||
private final IconEIO unselectedIcon;
|
||||
private final IconEIO selectedIcon;
|
||||
|
||||
private String[] selectedTooltip;
|
||||
private String[] unselectedTooltip;
|
||||
@@ -52,12 +52,15 @@ public class ToggleButtonEIO extends IconButtonEIO {
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if(result) {
|
||||
setSelected(!selected);
|
||||
if(super.mousePressed(par1Minecraft, par2, par3)) {
|
||||
return toggleSelected();
|
||||
}
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean toggleSelected() {
|
||||
setSelected(!selected);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setSelectedToolTip(String... tt) {
|
||||
|
||||
@@ -44,10 +44,10 @@ import crazypants.util.Lang;
|
||||
|
||||
public class TooltipAddera {
|
||||
|
||||
public static TooltipAddera instance = new TooltipAddera();
|
||||
public static final TooltipAddera instance = new TooltipAddera();
|
||||
|
||||
//TODO: Need to decouple this stuff with a callback
|
||||
private BallTipProvider btp = new BallTipProvider();
|
||||
private final BallTipProvider btp = new BallTipProvider();
|
||||
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.register(instance);
|
||||
@@ -96,11 +96,11 @@ public class TooltipAddera {
|
||||
IGrindingMultiplier gb = CrusherRecipeManager.getInstance().getGrindballFromStack(evt.itemStack);
|
||||
if(gb != null) {
|
||||
btp.ball = gb;
|
||||
TooltipAddera.instance.addInformation(btp, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
addInformation(btp, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
}
|
||||
|
||||
if(Config.addRegisterdNameTooltip) {
|
||||
UniqueIdentifier uid = null;
|
||||
UniqueIdentifier uid;
|
||||
Block block = Block.getBlockFromItem(evt.itemStack.getItem());
|
||||
if(block != null && block != Blocks.air) {
|
||||
uid = GameRegistry.findUniqueIdentifierFor(block);
|
||||
@@ -259,19 +259,18 @@ public class TooltipAddera {
|
||||
}
|
||||
|
||||
public static void addDetailedTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName, ".tooltip.detailed.line");
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.detailed.line"));
|
||||
}
|
||||
|
||||
public static void addBasicTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName, ".tooltip.basic.line");
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.basic.line"));
|
||||
}
|
||||
|
||||
public static void addCommonTooltipFromResources(List list, String unlocalizedName) {
|
||||
addTooltipFromResources(list, unlocalizedName, ".tooltip.common.line");
|
||||
addTooltipFromResources(list, unlocalizedName.concat(".tooltip.common.line"));
|
||||
}
|
||||
|
||||
public static void addTooltipFromResources(List list, String unlocalizedName, String tooltipTag) {
|
||||
String keyBase = unlocalizedName + tooltipTag;
|
||||
public static void addTooltipFromResources(List list, String keyBase) {
|
||||
boolean done = false;
|
||||
int line = 1;
|
||||
while (!done) {
|
||||
|
||||
@@ -108,6 +108,16 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllIoModes() {
|
||||
if(faceModes != null) {
|
||||
faceModes = null;
|
||||
forceClientUpdate = true;
|
||||
notifyNeighbours = true;
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IoMode getIoMode(ForgeDirection face) {
|
||||
if(faceModes == null) {
|
||||
|
||||
@@ -13,6 +13,8 @@ public interface IIoConfigurable {
|
||||
|
||||
public IoMode getIoMode(ForgeDirection face) ;
|
||||
|
||||
public void clearAllIoModes();
|
||||
|
||||
BlockCoord getLocation();
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class PacketIoMode implements IMessage, IMessageHandler<PacketIoMode, IMessage> {
|
||||
|
||||
@@ -19,10 +20,20 @@ public class PacketIoMode implements IMessage, IMessageHandler<PacketIoMode, IMe
|
||||
public PacketIoMode() {
|
||||
}
|
||||
|
||||
public PacketIoMode(IIoConfigurable cont) {
|
||||
BlockCoord location = cont.getLocation();
|
||||
this.x = location.x;
|
||||
this.y = location.y;
|
||||
this.z = location.z;
|
||||
this.mode = IoMode.NONE;
|
||||
this.face = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
public PacketIoMode(IIoConfigurable cont, ForgeDirection face) {
|
||||
this.x = cont.getLocation().x;
|
||||
this.y = cont.getLocation().y;
|
||||
this.z = cont.getLocation().z;
|
||||
BlockCoord location = cont.getLocation();
|
||||
this.x = location.x;
|
||||
this.y = location.y;
|
||||
this.z = location.z;
|
||||
this.face = face;
|
||||
mode = cont.getIoMode(face);
|
||||
}
|
||||
@@ -52,7 +63,11 @@ public class PacketIoMode implements IMessage, IMessageHandler<PacketIoMode, IMe
|
||||
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te instanceof IIoConfigurable) {
|
||||
IIoConfigurable me = (IIoConfigurable) te;
|
||||
me.setIoMode(message.face, message.mode);
|
||||
if(message.face == ForgeDirection.UNKNOWN) {
|
||||
me.clearAllIoModes();
|
||||
} else {
|
||||
me.setIoMode(message.face, message.mode);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,14 @@ public class TileBuffer extends AbstractPowerConsumerEntity implements IPaintabl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllIoModes() {
|
||||
super.clearAllIoModes();
|
||||
if(dist != null) {
|
||||
dist.neighboursChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack var2, int side) {
|
||||
return hasInventory() && getIoMode(ForgeDirection.VALID_DIRECTIONS[side]).canRecieveInput() && isMachineItemValidForSlot(slot, var2);
|
||||
|
||||
@@ -15,8 +15,6 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
@@ -25,6 +23,7 @@ import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.NetworkState;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateRequest;
|
||||
import crazypants.enderio.machine.gui.GuiButtonIoConfig;
|
||||
import crazypants.enderio.machine.gui.GuiOverlayIoConfig;
|
||||
import crazypants.enderio.machine.gui.GuiPoweredMachineBase;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
@@ -69,8 +68,8 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
private GuiTextField maxInputTF;
|
||||
private GuiTextField maxOutputTF;
|
||||
|
||||
private GuiOverlayIoConfig configOverlay;
|
||||
private IconButtonEIO configB;
|
||||
private final GuiOverlayIoConfig configOverlay;
|
||||
private final GuiButtonIoConfig configB;
|
||||
|
||||
private CapBankClientNetwork network;
|
||||
|
||||
@@ -144,10 +143,6 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
});
|
||||
outputRsButton.setTooltipKey("enderio.gui.capBank.outputRs");
|
||||
|
||||
y += 20;
|
||||
configB = new IconButtonEIO(this, CONFIG_ID, x, y, IconEIO.IO_CONFIG_UP);
|
||||
configB.setToolTip(Lang.localize("gui.machine.ioMode.overlay.tooltip"));
|
||||
|
||||
List<BlockCoord> coords = new ArrayList<BlockCoord>();
|
||||
if(network != null && network.getMembers().size() < 200) {
|
||||
for (TileCapBank cb : network.getMembers()) {
|
||||
@@ -160,13 +155,6 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
|
||||
|
||||
configOverlay = new GuiOverlayIoConfig(coords) {
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
super.setVisible(visible);
|
||||
configB.setIcon(visible ? IconEIO.IO_CONFIG_DOWN : IconEIO.IO_CONFIG_UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLabelForMode(IoMode mode) {
|
||||
if(mode == IoMode.PUSH) {
|
||||
@@ -176,19 +164,11 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
}
|
||||
return super.getLabelForMode(mode);
|
||||
}
|
||||
|
||||
};
|
||||
addOverlay(configOverlay);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
if(b.id == CONFIG_ID) {
|
||||
boolean vis = !configOverlay.isVisible();
|
||||
configOverlay.setVisible(vis);
|
||||
}
|
||||
y += 20;
|
||||
configB = new GuiButtonIoConfig(this, CONFIG_ID, x, y, te, configOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,16 +177,13 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
|
||||
configB.onGuiInit();
|
||||
|
||||
int x = guiLeft + xSize - rightMargin - GuiPoweredMachineBase.BUTTON_SIZE;
|
||||
int y = guiTop + inputY;
|
||||
|
||||
FontRenderer fontRenderer = getFontRenderer();
|
||||
|
||||
inputRsButton.onGuiInit();
|
||||
outputRsButton.onGuiInit();
|
||||
|
||||
x = guiLeft + inputX;
|
||||
y = guiTop + inputY;
|
||||
int x = guiLeft + inputX;
|
||||
int y = guiTop + inputY;
|
||||
maxInputTF = new GuiTextField(fontRenderer, x, y, 68, 16);
|
||||
maxInputTF.setCanLoseFocus(true);
|
||||
maxInputTF.setMaxStringLength(10);
|
||||
|
||||
@@ -300,6 +300,23 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerHandler,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllIoModes() {
|
||||
if(network != null) {
|
||||
for(TileCapBank cb : network.getMembers()) {
|
||||
cb.doClearAllIoModes();
|
||||
}
|
||||
} else {
|
||||
doClearAllIoModes();
|
||||
}
|
||||
}
|
||||
|
||||
private void doClearAllIoModes() {
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
setDefaultIoMode(dir);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IoMode getIoMode(ForgeDirection face) {
|
||||
if(faceModes == null) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package crazypants.enderio.machine.gui;
|
||||
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.IIoConfigurable;
|
||||
import crazypants.enderio.machine.PacketIoMode;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.IGuiScreen;
|
||||
import crazypants.util.Lang;
|
||||
import java.util.ArrayList;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class GuiButtonIoConfig extends ToggleButtonEIO {
|
||||
|
||||
private final IIoConfigurable config;
|
||||
private final GuiOverlayIoConfig configOverlay;
|
||||
|
||||
@SuppressWarnings("LeakingThisInConstructor")
|
||||
public GuiButtonIoConfig(IGuiScreen gui, int id, int x, int y, IIoConfigurable config, GuiOverlayIoConfig configOverlay) {
|
||||
super(gui, id, x, y, IconEIO.IO_CONFIG_UP, IconEIO.IO_CONFIG_DOWN);
|
||||
this.config = config;
|
||||
this.configOverlay = configOverlay;
|
||||
this.configOverlay.setConfigB(this);
|
||||
|
||||
String configTooltip = Lang.localize("gui.machine.ioMode.overlay.tooltip");
|
||||
setUnselectedToolTip(configTooltip);
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
list.add(configTooltip);
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.machine.ioMode.overlay.tooltip.visible.line");
|
||||
if(list.size() > 1) {
|
||||
setSelectedToolTip(list.toArray(new String[list.size()]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean toggleSelected() {
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
|
||||
if(!configOverlay.isVisible()) {
|
||||
return false;
|
||||
}
|
||||
config.clearAllIoModes();
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketIoMode(config));
|
||||
} else {
|
||||
boolean vis = !configOverlay.isVisible();
|
||||
configOverlay.setVisible(vis);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.IoConfigRenderer.SelectedFace;
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
@@ -42,7 +41,7 @@ public abstract class GuiMachineBase<T extends AbstractMachineEntity> extends Gu
|
||||
|
||||
private final GuiOverlayIoConfig configOverlay;
|
||||
|
||||
protected ToggleButtonEIO configB;
|
||||
protected final GuiButtonIoConfig configB;
|
||||
|
||||
protected IconButtonEIO recipeButton;
|
||||
|
||||
@@ -59,37 +58,18 @@ public abstract class GuiMachineBase<T extends AbstractMachineEntity> extends Gu
|
||||
int y = 5;
|
||||
redstoneButton = new RedstoneModeButton(this, -1, x, y, tileEntity, new BlockCoord(tileEntity));
|
||||
|
||||
y += 19;
|
||||
configB = new ToggleButtonEIO(this, CONFIG_ID, x, y, IconEIO.IO_CONFIG_UP, IconEIO.IO_CONFIG_DOWN);
|
||||
configB.setToolTip(Lang.localize("gui.machine.ioMode.overlay.tooltip"));
|
||||
|
||||
configOverlay = new GuiOverlayIoConfig(machine) {
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
super.setVisible(visible);
|
||||
configB.setSelected(visible);
|
||||
}
|
||||
|
||||
};
|
||||
configOverlay = new GuiOverlayIoConfig(machine);
|
||||
addOverlay(configOverlay);
|
||||
|
||||
|
||||
y += 19;
|
||||
configB = new GuiButtonIoConfig(this, CONFIG_ID, x, y, machine, configOverlay);
|
||||
|
||||
y += 19;
|
||||
|
||||
recipeButton = new IconButtonEIO(this, RECIPE_ID, x, y, IconEIO.RECIPE);
|
||||
recipeButton.visible = false;
|
||||
recipeButton.setIconMargin(3, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
if(b.id == CONFIG_ID) {
|
||||
boolean vis = !configOverlay.isVisible();
|
||||
configOverlay.setVisible(vis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.client.gui.ScaledResolution;
|
||||
import crazypants.enderio.gui.IGuiOverlay;
|
||||
import crazypants.enderio.gui.IoConfigRenderer;
|
||||
import crazypants.enderio.gui.IoConfigRenderer.SelectedFace;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.machine.IIoConfigurable;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.gui.IGuiScreen;
|
||||
@@ -21,6 +22,7 @@ import crazypants.util.BlockCoord;
|
||||
public class GuiOverlayIoConfig implements IGuiOverlay {
|
||||
|
||||
private boolean visible = false;
|
||||
private ToggleButtonEIO configB;
|
||||
|
||||
private IGuiScreen screen;
|
||||
|
||||
@@ -39,6 +41,10 @@ public class GuiOverlayIoConfig implements IGuiOverlay {
|
||||
coords.addAll(bc);
|
||||
}
|
||||
|
||||
public void setConfigB(ToggleButtonEIO configB) {
|
||||
this.configB = configB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IGuiScreen screen) {
|
||||
this.screen = screen;
|
||||
@@ -98,7 +104,9 @@ public class GuiOverlayIoConfig implements IGuiOverlay {
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
|
||||
if(configB != null) {
|
||||
configB.setSelected(visible);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -143,6 +143,18 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerHa
|
||||
setIoMode(faceHit, mode, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllIoModes() {
|
||||
if(faceModes != null) {
|
||||
faceModes = null;
|
||||
receptorsDirty = true;
|
||||
getController().masterReceptorsDirty = true;
|
||||
notifyNeighbours = true;
|
||||
render = true;
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void setIoMode(ForgeDirection faceHit, IoMode mode, boolean updateReceptors) {
|
||||
if(mode == IoMode.NONE && faceModes == null) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user