GUI Refactoring and consolidation

This commit is contained in:
Sebastian Hartte
2020-06-14 18:00:02 +02:00
parent 9b19f5b0e2
commit fd7ed5bbf0
53 changed files with 1000 additions and 974 deletions
@@ -19,9 +19,7 @@
package appeng.client.gui.implementations;
import java.io.IOException;
import net.minecraft.client.gui.widget.button.Button;
import appeng.client.gui.widgets.GuiActionButton;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;
@@ -35,20 +33,17 @@ import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiToggleButton;
import appeng.container.implementations.ContainerCellWorkbench;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.util.Platform;
public class GuiCellWorkbench extends GuiUpgradeable<ContainerCellWorkbench>
{
private GuiImgButton clear;
private GuiImgButton partition;
private GuiToggleButton copyMode;
public GuiCellWorkbench(ContainerCellWorkbench container, PlayerInventory playerInventory, ITextComponent title) {
@@ -59,16 +54,11 @@ public class GuiCellWorkbench extends GuiUpgradeable<ContainerCellWorkbench>
@Override
protected void addButtons()
{
this.clear = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE, this::actionPerformed );
this.partition = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH, this::actionPerformed );
this.copyMode = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 48, 11 * 16 + 5, 12 * 16 + 5, GuiText.CopyMode.getLocal(), GuiText.CopyModeDesc
.getLocal(), this::actionPerformed );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed );
this.addButton( this.fuzzyMode );
this.addButton( this.partition );
this.addButton( this.clear );
this.addButton( this.copyMode );
this.fuzzyMode = this.addButton( new GuiSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 68, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::toggleFuzzyMode ) );
this.addButton(new GuiActionButton(this.guiLeft - 18, this.guiTop + 28, ActionItems.WRENCH, act1 -> action("Partition")));
this.addButton(new GuiActionButton(this.guiLeft - 18, this.guiTop + 8, ActionItems.CLOSE, act -> action("Clear")));
this.copyMode = this.addButton( new GuiToggleButton( this.guiLeft - 18, this.guiTop + 48, 11 * 16 + 5, 12 * 16 + 5, GuiText.CopyMode.getLocal(), GuiText.CopyModeDesc
.getLocal(), act -> action("CopyMode") ) );
}
@Override
@@ -166,33 +156,13 @@ public class GuiCellWorkbench extends GuiUpgradeable<ContainerCellWorkbench>
return GuiText.CellWorkbench;
}
@Override
protected void actionPerformed( final Button btn )
{
if( btn == this.copyMode )
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "CopyMode" ) );
}
else if( btn == this.partition )
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Partition" ) );
}
else if( btn == this.clear )
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Clear" ) );
}
else if( btn == this.fuzzyMode )
{
final boolean backwards = minecraft.mouseHelper.isRightDown();
FuzzyMode fz = (FuzzyMode) this.fuzzyMode.getCurrentValue();
fz = Platform.rotateEnum( fz, backwards, Settings.FUZZY_MODE.getPossibleValues() );
NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Fuzzy", fz.name() ) );
}
else
{
super.actionPerformed( btn );
}
private void action(String type) {
NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", type ) );
}
private void toggleFuzzyMode(GuiSettingToggleButton<FuzzyMode> button, boolean backwards) {
FuzzyMode fz = button.getNextValue(backwards);
NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Fuzzy", fz.name() ) );
}
}
@@ -19,6 +19,8 @@
package appeng.client.gui.implementations;
import appeng.api.config.CondenserOutput;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;
@@ -26,20 +28,17 @@ import net.minecraft.entity.player.PlayerInventory;
import appeng.api.config.Settings;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiProgressBar;
import appeng.client.gui.widgets.GuiProgressBar.Direction;
import appeng.container.implementations.ContainerCondenser;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
public class GuiCondenser extends AEBaseGui<ContainerCondenser>
{
private GuiProgressBar pb;
private GuiImgButton mode;
private GuiSettingToggleButton<CondenserOutput> mode;
public GuiCondenser(ContainerCondenser container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
@@ -51,15 +50,10 @@ public class GuiCondenser extends AEBaseGui<ContainerCondenser>
{
super.init();
this.pb = new GuiProgressBar( this.container, "guis/condenser.png", 120 + this.guiLeft, 25 + this.guiTop, 178, 25, 6, 18, Direction.VERTICAL, GuiText.StoredEnergy
.getLocal() );
this.mode = new GuiServerSettingToggleButton<>( 128 + this.guiLeft, 52 + this.guiTop, Settings.CONDENSER_OUTPUT, this.container.getOutput());
this.mode = new GuiImgButton( 128 + this.guiLeft, 52 + this.guiTop, Settings.CONDENSER_OUTPUT, this.container.getOutput(), btn -> {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( Settings.CONDENSER_OUTPUT, backwards ) );
} );
this.addButton( this.pb );
this.addButton(new GuiProgressBar(this.container, "guis/condenser.png", 120 + this.guiLeft, 25 + this.guiTop, 178, 25, 6, 18, Direction.VERTICAL, GuiText.StoredEnergy
.getLocal()));
this.addButton( this.mode );
}
@@ -19,11 +19,12 @@
package appeng.client.gui.implementations;
import appeng.client.gui.widgets.GuiActionButton;
import net.minecraft.entity.player.PlayerInventory;
import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.container.implementations.ContainerCraftingTerm;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.core.localization.GuiText;
@@ -63,7 +64,7 @@ public class GuiCraftingTerm extends GuiMEMonitorable<ContainerCraftingTerm>
public void init()
{
super.init();
GuiImgButton clearBtn = this.addButton( new GuiImgButton( this.guiLeft + 92, this.guiTop + this.ySize - 156, Settings.ACTIONS, ActionItems.STASH, btn -> clear() ));
GuiActionButton clearBtn = this.addButton( new GuiActionButton( this.guiLeft + 92, this.guiTop + this.ySize - 156, ActionItems.STASH, btn -> clear() ));
clearBtn.setHalfSize( true );
}
@@ -22,13 +22,13 @@ package appeng.client.gui.implementations;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.implementations.ContainerFormationPlane;
import appeng.container.implementations.ContainerPriority;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketSwitchGuis;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
@@ -37,7 +37,7 @@ import net.minecraft.util.text.ITextComponent;
public class GuiFormationPlane extends GuiUpgradeable<ContainerFormationPlane>
{
private GuiImgButton placeMode;
private GuiSettingToggleButton<YesNo> placeMode;
public GuiFormationPlane(ContainerFormationPlane container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
@@ -47,8 +47,8 @@ public class GuiFormationPlane extends GuiUpgradeable<ContainerFormationPlane>
@Override
protected void addButtons()
{
this.placeMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.PLACE_BLOCK, YesNo.YES, btn -> selectNextPlaceMode() );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed );
this.placeMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 28, Settings.PLACE_BLOCK, YesNo.YES );
this.fuzzyMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) );
@@ -83,9 +83,4 @@ public class GuiFormationPlane extends GuiUpgradeable<ContainerFormationPlane>
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) );
}
private void selectNextPlaceMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.placeMode.getSetting(), backwards ) );
}
}
@@ -25,11 +25,10 @@ import appeng.api.config.OperationMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.definitions.IDefinitions;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.container.implementations.ContainerIOPort;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
@@ -37,8 +36,8 @@ import net.minecraft.util.text.ITextComponent;
public class GuiIOPort extends GuiUpgradeable<ContainerIOPort>
{
private GuiImgButton fullMode;
private GuiImgButton operationMode;
private GuiSettingToggleButton<FullnessMode> fullMode;
private GuiSettingToggleButton<OperationMode> operationMode;
public GuiIOPort(ContainerIOPort container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
@@ -48,13 +47,13 @@ public class GuiIOPort extends GuiUpgradeable<ContainerIOPort>
@Override
protected void addButtons()
{
this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, this::actionPerformed);
this.fullMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.FULLNESS_MODE, FullnessMode.EMPTY, btn -> selectNextFullMode() );
this.operationMode = new GuiImgButton( this.guiLeft + 80, this.guiTop + 17, Settings.OPERATION_MODE, OperationMode.EMPTY, btn -> selectNextOperationMode() );
this.fullMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 8, Settings.FULLNESS_MODE, FullnessMode.EMPTY );
this.operationMode = new GuiServerSettingToggleButton<>( this.guiLeft + 80, this.guiTop + 17, Settings.OPERATION_MODE, OperationMode.EMPTY );
this.addButton( this.operationMode );
this.addButton( this.redstoneMode );
this.addButton( this.fullMode );
this.redstoneMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
addButton(this.redstoneMode);
}
@Override
@@ -97,14 +96,4 @@ public class GuiIOPort extends GuiUpgradeable<ContainerIOPort>
return "guis/io_port.png";
}
private void selectNextFullMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.fullMode.getSetting(), backwards ) );
}
private void selectNextOperationMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.operationMode.getSetting(), backwards ) );
}
}
@@ -21,7 +21,8 @@ package appeng.client.gui.implementations;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.GuiToggleButton;
import appeng.container.implementations.ContainerInterface;
@@ -37,7 +38,7 @@ import net.minecraft.util.text.ITextComponent;
public class GuiInterface extends GuiUpgradeable<ContainerInterface>
{
private GuiImgButton blockMode;
private GuiSettingToggleButton<YesNo> blockMode;
private GuiToggleButton interfaceMode;
public GuiInterface(ContainerInterface container, PlayerInventory playerInventory, ITextComponent title) {
@@ -50,7 +51,7 @@ public class GuiInterface extends GuiUpgradeable<ContainerInterface>
{
this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) );
this.blockMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.BLOCK, YesNo.NO, btn -> selectNextBlockMode() );
this.blockMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 8, Settings.BLOCK, YesNo.NO );
this.addButton( this.blockMode);
this.interfaceMode = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 26, 84, 85, GuiText.InterfaceTerminal
@@ -90,13 +91,8 @@ public class GuiInterface extends GuiUpgradeable<ContainerInterface>
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) );
}
private void selectNextBlockMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.blockMode.getSetting(), backwards ) );
}
private void selectNextInterfaceMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
final boolean backwards = getMinecraft().mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( Settings.INTERFACE_TERMINAL, backwards ) );
}
@@ -19,8 +19,7 @@
package appeng.client.gui.implementations;
import java.io.IOException;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.util.InputMappings;
import net.minecraft.util.text.ITextComponent;
@@ -33,14 +32,12 @@ import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiNumberBox;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketValueConfig;
@@ -58,8 +55,8 @@ public class GuiLevelEmitter extends GuiUpgradeable<ContainerLevelEmitter>
private Button minus100;
private Button minus1000;
private GuiImgButton levelMode;
private GuiImgButton craftingMode;
private GuiSettingToggleButton<LevelType> levelMode;
private GuiSettingToggleButton<YesNo> craftingMode;
public GuiLevelEmitter(ContainerLevelEmitter container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
@@ -82,10 +79,10 @@ public class GuiLevelEmitter extends GuiUpgradeable<ContainerLevelEmitter>
@Override
protected void addButtons()
{
this.levelMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL, btn -> selectNextLevelMode() );
this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL, this::actionPerformed );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed );
this.craftingMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO, btn -> selectNextCraftingMode() );
this.levelMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 8, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL );
this.redstoneMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL );
this.fuzzyMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.craftingMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO );
final int a = AEConfig.instance().levelByStackAmounts( 0 );
final int b = AEConfig.instance().levelByStackAmounts( 1 );
@@ -104,7 +101,6 @@ public class GuiLevelEmitter extends GuiUpgradeable<ContainerLevelEmitter>
this.addButton( this.levelMode );
this.addButton( this.redstoneMode );
this.addButton( this.fuzzyMode );
this.addButton( this.craftingMode );
}
@@ -165,16 +161,6 @@ public class GuiLevelEmitter extends GuiUpgradeable<ContainerLevelEmitter>
return GuiText.LevelEmitter;
}
private void selectNextCraftingMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.craftingMode.getSetting(), backwards ) );
}
private void selectNextLevelMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.levelMode.getSetting(), backwards ) );
}
private void addQty( final long i )
{
try
@@ -19,11 +19,11 @@
package appeng.client.gui.implementations;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import net.minecraft.entity.player.PlayerInventory;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiProgressBar;
import appeng.client.gui.widgets.GuiProgressBar.Direction;
import appeng.container.implementations.ContainerMAC;
@@ -53,8 +53,8 @@ public class GuiMAC extends GuiUpgradeable<ContainerMAC>
@Override
protected void addButtons()
{
this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, this::actionPerformed );
this.addButton( this.redstoneMode );
this.redstoneMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
addButton(this.redstoneMode);
}
@Override
@@ -24,7 +24,7 @@ import java.util.List;
import appeng.api.config.*;
import appeng.container.implementations.ContainerCraftingStatus;
import appeng.integration.abstraction.JEIFacade;
import net.minecraft.client.gui.widget.button.Button;
import appeng.util.Platform;
import net.minecraft.client.util.InputMappings;
import net.minecraft.inventory.container.Slot;
import net.minecraft.util.text.ITextComponent;
@@ -41,7 +41,7 @@ import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.ActionKey;
import appeng.client.gui.AEBaseMEGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.ISortSource;
@@ -63,7 +63,6 @@ import appeng.helpers.WirelessTerminalGuiObject;
import appeng.parts.reporting.AbstractPartTerminal;
import appeng.tile.misc.TileSecurityStation;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import org.lwjgl.glfw.GLFW;
@@ -89,11 +88,9 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
private int rows = 0;
private int maxRows = Integer.MAX_VALUE;
private int standardSize;
private GuiImgButton ViewBox;
private GuiImgButton SortByBox;
private GuiImgButton SortDirBox;
private GuiImgButton searchBoxSettings;
private GuiImgButton terminalStyleBox;
private GuiSettingToggleButton<ViewItems> viewModeToggle;
private GuiSettingToggleButton<SortOrder> sortByToggle;
private GuiSettingToggleButton<SortDir> sortDirToggle;
private boolean isAutoFocus = false;
private int currentMouseX = 0;
private int currentMouseY = 0;
@@ -165,62 +162,19 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
NetworkHandler.instance().sendToServer( new PacketSwitchGuis(ContainerCraftingStatus.TYPE) );
}
protected void actionPerformed( final Button btn )
{
if( btn instanceof GuiImgButton )
{
final boolean backwards = minecraft.mouseHelper.isRightDown();
final GuiImgButton iBtn = (GuiImgButton) btn;
if( iBtn.getSetting() != Settings.ACTIONS )
{
final Enum cv = iBtn.getCurrentValue();
final Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() );
if( btn == this.terminalStyleBox )
{
AEConfig.instance().getConfigManager().putSetting( iBtn.getSetting(), next );
}
else if( btn == this.searchBoxSettings )
{
AEConfig.instance().getConfigManager().putSetting( iBtn.getSetting(), next );
}
else
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) );
}
iBtn.set( next );
if( next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class )
{
this.reinitalize();
}
}
}
}
private void reinitalize()
{
this.buttons.clear();
this.init();
}
@Override
public void init()
{
minecraft.keyboardListener.enableRepeatEvents( true );
getMinecraft().keyboardListener.enableRepeatEvents( true );
this.maxRows = this.getMaxRows();
this.perRow = AEConfig.instance()
.getConfigManager()
.getSetting(
Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ? 9 : 9 + ( ( this.width - this.standardSize ) / 18 );
TerminalStyle terminalStyle = (TerminalStyle) AEConfig.instance().getConfigManager().getSetting(Settings.TERMINAL_STYLE);
this.perRow = terminalStyle != TerminalStyle.FULL ? 9 : 9 + ( ( this.width - this.standardSize ) / 18 );
final int magicNumber = 114 + 1;
final int extraSpace = this.height - magicNumber - this.reservedSpace;
this.rows = (int) Math.floor( extraSpace / 18 );
this.rows = extraSpace / 18;
if( this.rows > this.maxRows )
{
this.rows = this.maxRows;
@@ -240,7 +194,7 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
}
}
if( AEConfig.instance().getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL )
if( terminalStyle != TerminalStyle.FULL )
{
this.xSize = this.standardSize + ( ( this.perRow - 9 ) * 18 );
}
@@ -263,33 +217,27 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
if( this.customSortOrder )
{
this.SortByBox = this.addButton( new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ), this::actionPerformed ) );
this.sortByToggle = this.addButton( new GuiSettingToggleButton<>( this.guiLeft - 18, offset, Settings.SORT_BY, getSortBy(), Platform::isSortOrderAvailable, this::toggleServerSetting ) );
offset += 20;
}
if( this.viewCell || this instanceof GuiWirelessTerm )
{
this.ViewBox = this.addButton( new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting( Settings.VIEW_MODE ), this::actionPerformed ) );
this.viewModeToggle = this.addButton( new GuiSettingToggleButton<>( this.guiLeft - 18, offset, Settings.VIEW_MODE, getSortDisplay(), this::toggleServerSetting ) );
offset += 20;
}
this.addButton( this.SortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc
.getSetting( Settings.SORT_DIRECTION ), this::actionPerformed ) );
this.addButton( this.sortDirToggle = new GuiSettingToggleButton<>( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, getSortDir(), this::toggleServerSetting ) );
offset += 20;
this.addButton(
this.searchBoxSettings = new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance()
.getConfigManager()
.getSetting(
Settings.SEARCH_MODE ), this::actionPerformed ) );
SearchBoxMode searchMode = (SearchBoxMode) AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_MODE);
this.addButton(new GuiSettingToggleButton<>( this.guiLeft - 18, offset, Settings.SEARCH_MODE, searchMode, Platform::isSearchModeAvailable, this::toggleClientSetting));
offset += 20;
if( !( this instanceof GuiMEPortableCell ) || this instanceof GuiWirelessTerm )
{
this.addButton( this.terminalStyleBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.TERMINAL_STYLE, AEConfig.instance()
.getConfigManager()
.getSetting( Settings.TERMINAL_STYLE ), this::actionPerformed ) );
this.addButton( new GuiSettingToggleButton<>( this.guiLeft - 18, offset, Settings.TERMINAL_STYLE, terminalStyle, this::toggleClientSetting) );
}
this.searchField = new MEGuiTextField( this.font, this.guiLeft + Math.max( 80, this.offsetX ), this.guiTop + 4, 90, 12 );
@@ -306,11 +254,9 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
this.craftingStatusBtn.setHideEdge( 13 );
}
final Enum searchModeSetting = AEConfig.instance().getConfigManager().getSetting( Settings.SEARCH_MODE );
this.isAutoFocus = SearchBoxMode.AUTOSEARCH == searchModeSetting || SearchBoxMode.JEI_AUTOSEARCH == searchModeSetting || SearchBoxMode.AUTOSEARCH_KEEP == searchModeSetting || SearchBoxMode.JEI_AUTOSEARCH_KEEP == searchModeSetting;
final boolean isKeepFilter = SearchBoxMode.AUTOSEARCH_KEEP == searchModeSetting || SearchBoxMode.JEI_AUTOSEARCH_KEEP == searchModeSetting || SearchBoxMode.MANUAL_SEARCH_KEEP == searchModeSetting || SearchBoxMode.JEI_MANUAL_SEARCH_KEEP == searchModeSetting;
final boolean isJEIEnabled = SearchBoxMode.JEI_AUTOSEARCH == searchModeSetting || SearchBoxMode.JEI_MANUAL_SEARCH == searchModeSetting;
this.isAutoFocus = SearchBoxMode.AUTOSEARCH == searchMode || SearchBoxMode.JEI_AUTOSEARCH == searchMode || SearchBoxMode.AUTOSEARCH_KEEP == searchMode || SearchBoxMode.JEI_AUTOSEARCH_KEEP == searchMode;
final boolean isKeepFilter = SearchBoxMode.AUTOSEARCH_KEEP == searchMode || SearchBoxMode.JEI_AUTOSEARCH_KEEP == searchMode || SearchBoxMode.MANUAL_SEARCH_KEEP == searchMode || SearchBoxMode.JEI_MANUAL_SEARCH_KEEP == searchMode;
final boolean isJEIEnabled = SearchBoxMode.JEI_AUTOSEARCH == searchMode || SearchBoxMode.JEI_MANUAL_SEARCH == searchMode;
this.searchField.setFocused2( this.isAutoFocus );
@@ -386,7 +332,7 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
public void removed()
{
super.removed();
minecraft.keyboardListener.enableRepeatEvents( false );
getMinecraft().keyboardListener.enableRepeatEvents( false );
memoryText = this.searchField.getText();
}
@@ -464,13 +410,12 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
return true;
}
final boolean mouseInGui = this.isMouseOver( this.currentMouseX, this.currentMouseY );
if( this.isAutoFocus && !this.searchField.isFocused() && mouseInGui )
if( this.isAutoFocus && !this.searchField.isFocused() && isHovered() )
{
this.searchField.setFocused2( true );
}
if (this.searchField.charTyped(character, p_charTyped_2_)) {
if (this.searchField.isFocused() && this.searchField.charTyped(character, p_charTyped_2_)) {
this.repo.setSearchString( this.searchField.getText() );
this.repo.updateView();
this.setScrollBar();
@@ -486,26 +431,31 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
if( !this.checkHotbarKeys(input) )
if( keyCode != GLFW.GLFW_KEY_ESCAPE && !this.checkHotbarKeys(input) )
{
if( AppEng.proxy.isActionKey( ActionKey.TOGGLE_FOCUS, input ) )
{
this.searchField.setFocused2( !this.searchField.isFocused() );
return true;
}
if( this.searchField.isFocused() && keyCode == GLFW.GLFW_KEY_ENTER )
{
this.searchField.setFocused2( false );
return true;
if (!this.searchField.isFocused() && this.isAutoFocus && isHovered()) {
this.searchField.setFocused2(true);
}
if( this.searchField.keyPressed( keyCode, scanCode, p_keyPressed_3_ ) )
{
this.repo.setSearchString( this.searchField.getText() );
this.repo.updateView();
this.setScrollBar();
// tell forge the key event is handled and should not be sent out
if (this.searchField.isFocused()) {
if (keyCode == GLFW.GLFW_KEY_ENTER) {
this.searchField.setFocused2(false);
return true;
}
if (this.searchField.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
this.repo.setSearchString(this.searchField.getText());
this.repo.updateView();
this.setScrollBar();
}
// We need to swallow key presses if the field is focused because typing 'e' would otherwise close
// the screen
return true;
}
}
@@ -513,6 +463,10 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
}
private boolean isHovered() {
return isPointInRegion(0, 0, this.xSize, this.ySize, currentMouseX, currentMouseY);
}
@Override
public void tick()
{
@@ -539,21 +493,21 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue )
{
if( this.SortByBox != null )
if( this.sortByToggle != null )
{
this.SortByBox.set( this.configSrc.getSetting( Settings.SORT_BY ) );
this.sortByToggle.set( getSortBy() );
}
if( this.SortDirBox != null )
if( this.sortDirToggle != null )
{
this.SortDirBox.set( this.configSrc.getSetting( Settings.SORT_DIRECTION ) );
this.sortDirToggle.set( getSortDir() );
}
if( this.ViewBox != null )
if( this.viewModeToggle != null )
{
this.ViewBox.set( this.configSrc.getSetting( Settings.VIEW_MODE ) );
this.viewModeToggle.set( getSortDisplay() );
}
this.repo.updateView();
@@ -588,4 +542,24 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
{
this.standardSize = standardSize;
}
private <S extends Enum<S>> void toggleClientSetting(GuiSettingToggleButton<S> btn, boolean backwards) {
S next = btn.getNextValue(backwards);
AEConfig.instance().getConfigManager().putSetting( btn.getSetting(), next );
btn.set( next );
this.reinitalize();
}
private <S extends Enum<S>> void toggleServerSetting(GuiSettingToggleButton<S> btn, boolean backwards) {
S next = btn.getNextValue(backwards);
NetworkHandler.instance().sendToServer( new PacketValueConfig( btn.getSetting().name(), next.name() ) );
btn.set( next );
}
private void reinitalize()
{
this.buttons.clear();
this.init();
}
}
@@ -19,19 +19,17 @@
package appeng.client.gui.implementations;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.CommonButtons;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.me.ItemRepo;
import appeng.client.me.SlotME;
import appeng.container.implementations.ContainerNetworkStatus;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.util.Platform;
import com.mojang.blaze3d.systems.RenderSystem;
@@ -49,7 +47,6 @@ public class GuiNetworkStatus extends AEBaseGui<ContainerNetworkStatus> implemen
private final ItemRepo repo;
private final int rows = 4;
private GuiImgButton units;
private int tooltip = -1;
public GuiNetworkStatus(ContainerNetworkStatus container, PlayerInventory playerInventory, ITextComponent title) {
@@ -68,14 +65,7 @@ public class GuiNetworkStatus extends AEBaseGui<ContainerNetworkStatus> implemen
{
super.init();
this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit(), btn -> selectNextUnit() );
this.addButton( this.units );
}
private void selectNextUnit() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
AEConfig.instance().nextPowerUnit( backwards );
this.units.set( AEConfig.instance().selectedPowerUnit() );
this.addButton( CommonButtons.togglePowerUnit( this.guiLeft - 18, this.guiTop + 8 ) );
}
@Override
@@ -20,9 +20,9 @@ package appeng.client.gui.implementations;
import appeng.api.config.ActionItems;
import appeng.api.config.ItemSubstitution;
import appeng.api.config.Settings;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiActionButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.slot.AppEngSlot;
@@ -49,8 +49,8 @@ public class GuiPatternTerm extends GuiMEMonitorable<ContainerPatternTerm>
private GuiTabButton tabCraftButton;
private GuiTabButton tabProcessButton;
private GuiImgButton substitutionsEnabledBtn;
private GuiImgButton substitutionsDisabledBtn;
private GuiActionButton substitutionsEnabledBtn;
private GuiActionButton substitutionsDisabledBtn;
public GuiPatternTerm(ContainerPatternTerm container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
@@ -70,19 +70,19 @@ public class GuiPatternTerm extends GuiMEMonitorable<ContainerPatternTerm>
.getLocal(), this.itemRenderer, btn -> toggleCraftMode(CRAFTMODE_CRFTING) );
this.addButton( this.tabProcessButton );
this.substitutionsEnabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.ENABLED, btn -> toggleSubstitutions(SUBSITUTION_DISABLE) );
this.substitutionsEnabledBtn = new GuiActionButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, ActionItems.ENABLE_SUBSTITUTION, act -> toggleSubstitutions(SUBSITUTION_DISABLE) );
this.substitutionsEnabledBtn.setHalfSize( true );
this.addButton( this.substitutionsEnabledBtn );
this.substitutionsDisabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.DISABLED, btn -> toggleSubstitutions(SUBSITUTION_ENABLE) );
this.substitutionsDisabledBtn = new GuiActionButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, ActionItems.DISABLE_SUBSTITUTION, act -> toggleSubstitutions(SUBSITUTION_ENABLE) );
this.substitutionsDisabledBtn.setHalfSize( true );
this.addButton( this.substitutionsDisabledBtn );
GuiImgButton clearBtn = new GuiImgButton(this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE, btn -> clear());
GuiActionButton clearBtn = new GuiActionButton(this.guiLeft + 74, this.guiTop + this.ySize - 163, ActionItems.CLOSE, act -> clear());
clearBtn.setHalfSize( true );
this.addButton(clearBtn);
GuiImgButton encodeBtn = new GuiImgButton(this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE, btn -> encode());
GuiActionButton encodeBtn = new GuiActionButton(this.guiLeft + 147, this.guiTop + this.ySize - 142, ActionItems.ENCODE, act -> encode());
this.addButton(encodeBtn);
}
@@ -19,11 +19,9 @@
package appeng.client.gui.implementations;
import appeng.api.config.Settings;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.CommonButtons;
import appeng.container.implementations.ContainerSpatialIOPort;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerInventory;
@@ -34,8 +32,6 @@ import net.minecraftforge.fml.client.gui.GuiUtils;
public class GuiSpatialIOPort extends AEBaseGui<ContainerSpatialIOPort>
{
private GuiImgButton units;
public GuiSpatialIOPort(ContainerSpatialIOPort container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
this.ySize = 199;
@@ -45,15 +41,7 @@ public class GuiSpatialIOPort extends AEBaseGui<ContainerSpatialIOPort>
public void init()
{
super.init();
this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit(), btn -> selectNextUnit() );
this.addButton( this.units );
}
private void selectNextUnit() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
AEConfig.instance().nextPowerUnit( backwards );
this.units.set( AEConfig.instance().selectedPowerUnit() );
this.addButton( CommonButtons.togglePowerUnit( this.guiLeft - 18, this.guiTop + 8 ) );
}
@Override
@@ -20,13 +20,14 @@ package appeng.client.gui.implementations;
import appeng.api.config.*;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiActionButton;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.implementations.ContainerPriority;
import appeng.container.implementations.ContainerStorageBus;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import net.minecraft.entity.player.PlayerInventory;
@@ -36,8 +37,8 @@ import net.minecraft.util.text.ITextComponent;
public class GuiStorageBus extends GuiUpgradeable<ContainerStorageBus>
{
private GuiImgButton rwMode;
private GuiImgButton storageFilter;
private GuiSettingToggleButton<AccessRestriction> rwMode;
private GuiSettingToggleButton<StorageFilter> storageFilter;
public GuiStorageBus(ContainerStorageBus container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
@@ -47,11 +48,11 @@ public class GuiStorageBus extends GuiUpgradeable<ContainerStorageBus>
@Override
protected void addButtons()
{
addButton( new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE, btn -> clear() ) );
addButton( new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH, btn -> partition() ) );
this.rwMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE, btn -> toggleReadWriteMode() );
this.storageFilter = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY, btn -> toggleStorageFilterMode() );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed );
addButton( new GuiActionButton( this.guiLeft - 18, this.guiTop + 8, ActionItems.CLOSE, btn -> clear() ) );
addButton( new GuiActionButton( this.guiLeft - 18, this.guiTop + 28, ActionItems.WRENCH, btn -> partition() ) );
this.rwMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE );
this.storageFilter = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY );
this.fuzzyMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) );
@@ -100,14 +101,4 @@ public class GuiStorageBus extends GuiUpgradeable<ContainerStorageBus>
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) );
}
private void toggleReadWriteMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.rwMode.getSetting(), backwards ) );
}
private void toggleStorageFilterMode() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.storageFilter.getSetting(), backwards ) );
}
}
@@ -19,7 +19,7 @@
package appeng.client.gui.implementations;
import net.minecraft.client.gui.widget.button.Button;
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
import net.minecraft.entity.player.PlayerInventory;
import appeng.api.config.FuzzyMode;
@@ -30,11 +30,9 @@ import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.implementations.IUpgradeableHost;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.container.implementations.ContainerUpgradeable;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.parts.automation.PartExportBus;
import appeng.parts.automation.PartImportBus;
import net.minecraft.util.text.ITextComponent;
@@ -47,10 +45,10 @@ public class GuiUpgradeable<T extends ContainerUpgradeable> extends AEBaseGui<T>
protected final ContainerUpgradeable cvb;
protected final IUpgradeableHost bc;
protected GuiImgButton redstoneMode;
protected GuiImgButton fuzzyMode;
protected GuiImgButton craftMode;
protected GuiImgButton schedulingMode;
protected GuiSettingToggleButton<RedstoneMode> redstoneMode;
protected GuiSettingToggleButton<FuzzyMode> fuzzyMode;
protected GuiSettingToggleButton<YesNo> craftMode;
protected GuiSettingToggleButton<SchedulingMode> schedulingMode;
public GuiUpgradeable(T container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
@@ -75,15 +73,14 @@ public class GuiUpgradeable<T extends ContainerUpgradeable> extends AEBaseGui<T>
protected void addButtons()
{
this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, this::actionPerformed );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed );
this.craftMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_ONLY, YesNo.NO, this::actionPerformed );
this.schedulingMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT, this::actionPerformed );
this.addButton( this.craftMode );
this.addButton( this.redstoneMode );
this.addButton( this.fuzzyMode );
this.addButton( this.schedulingMode );
this.redstoneMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
addButton(this.redstoneMode);
this.fuzzyMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 28, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
addButton(this.fuzzyMode);
this.craftMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_ONLY, YesNo.NO );
addButton(this.craftMode);
this.schedulingMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 68, Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT );
addButton(this.schedulingMode);
}
@Override
@@ -165,30 +162,4 @@ public class GuiUpgradeable<T extends ContainerUpgradeable> extends AEBaseGui<T>
return this.bc instanceof PartImportBus ? GuiText.ImportBus : GuiText.ExportBus;
}
// FIXME: replace with individual methods
protected void actionPerformed( final Button btn )
{
// Detect right-clicks
final boolean backwards = minecraft.mouseHelper.isRightDown();
if( btn == this.redstoneMode )
{
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.redstoneMode.getSetting(), backwards ) );
}
if( btn == this.craftMode )
{
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.craftMode.getSetting(), backwards ) );
}
if( btn == this.fuzzyMode )
{
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.fuzzyMode.getSetting(), backwards ) );
}
if( btn == this.schedulingMode )
{
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.schedulingMode.getSetting(), backwards ) );
}
}
}
@@ -21,7 +21,8 @@ package appeng.client.gui.implementations;
import appeng.api.config.Settings;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.CommonButtons;
import appeng.client.gui.widgets.GuiSettingToggleButton;
import appeng.container.implementations.ContainerWireless;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
@@ -34,8 +35,6 @@ import net.minecraftforge.fml.client.gui.GuiUtils;
public class GuiWireless extends AEBaseGui<ContainerWireless>
{
private GuiImgButton units;
public GuiWireless(ContainerWireless container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
this.ySize = 166;
@@ -46,14 +45,7 @@ public class GuiWireless extends AEBaseGui<ContainerWireless>
{
super.init();
this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit(), btn -> toggleUnits() );
this.addButton( this.units );
}
private void toggleUnits() {
final boolean backwards = minecraft.mouseHelper.isRightDown();
AEConfig.instance().nextPowerUnit( backwards );
this.units.set( AEConfig.instance().selectedPowerUnit() );
this.addButton( CommonButtons.togglePowerUnit( this.guiLeft - 18, this.guiTop + 8 ) );
}
@Override
@@ -0,0 +1,23 @@
package appeng.client.gui.widgets;
import appeng.api.config.FuzzyMode;
import appeng.api.config.PowerUnits;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.core.AEConfig;
public final class CommonButtons {
private CommonButtons() {
}
public static GuiSettingToggleButton<PowerUnits> togglePowerUnit(int x, int y) {
return new GuiSettingToggleButton<>( x, y, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit(), CommonButtons::togglePowerUnit );
}
private static void togglePowerUnit(GuiSettingToggleButton<PowerUnits> button, boolean backwards) {
AEConfig.instance().nextPowerUnit( backwards );
button.set( AEConfig.instance().selectedPowerUnit() );
}
}
@@ -0,0 +1,115 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.client.gui.widgets;
import appeng.api.config.*;
import appeng.core.localization.ButtonToolTips;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.regex.Pattern;
public class GuiActionButton extends GuiIconButton implements ITooltip
{
private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL );
private final int iconIndex;
public GuiActionButton(final int x, final int y, final ActionItems action, Consumer<ActionItems> onPress )
{
super( x, y, btn -> onPress.accept(action) );
ButtonToolTips displayName;
ButtonToolTips displayValue;
switch (action) {
case WRENCH:
iconIndex = 66;
displayName = ButtonToolTips.PartitionStorage;
displayValue = ButtonToolTips.PartitionStorageHint;
break;
case CLOSE:
iconIndex = 6;
displayName = ButtonToolTips.Clear;
displayValue = ButtonToolTips.ClearSettings;
break;
case STASH:
iconIndex = 6;
displayName = ButtonToolTips.Stash;
displayValue = ButtonToolTips.StashDesc;
break;
case ENCODE:
iconIndex = 8;
displayName = ButtonToolTips.Encode;
displayValue = ButtonToolTips.EncodeDescription;
break;
case ENABLE_SUBSTITUTION:
iconIndex = 4 + 3 * 16;
displayName = ButtonToolTips.Substitutions;
displayValue = ButtonToolTips.SubstitutionsDescEnabled;
break;
case DISABLE_SUBSTITUTION:
iconIndex = 7 + 3 * 16;
displayName = ButtonToolTips.Substitutions;
displayValue = ButtonToolTips.SubstitutionsDescDisabled;
break;
default:
throw new IllegalArgumentException("Unknown ActionItem: " + action);
}
setMessage(buildMessage(displayName, displayValue));
}
@Override
protected int getIconIndex()
{
return iconIndex;
}
private String buildMessage(ButtonToolTips displayName, ButtonToolTips displayValue)
{
String name = displayName.getTranslationKey().getString();
String value = displayValue.getTranslationKey().getString();
value = PATTERN_NEW_LINE.matcher( value ).replaceAll( "\n" );
final StringBuilder sb = new StringBuilder( value );
int i = sb.lastIndexOf( "\n" );
if( i <= 0 )
{
i = 0;
}
while( i + 30 < sb.length() && ( i = sb.lastIndexOf( " ", i + 30 ) ) != -1 )
{
sb.replace( i, i + 1, "\n" );
}
return name + '\n' + sb;
}
}
@@ -0,0 +1,156 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.client.gui.widgets;
import appeng.api.config.*;
import appeng.core.localization.ButtonToolTips;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public abstract class GuiIconButton extends Button implements ITooltip
{
public static final ResourceLocation TEXTURE_STATES = new ResourceLocation("appliedenergistics2", "textures/guis/states.png");
private boolean halfSize = false;
public GuiIconButton(final int x, final int y, IPressable onPress )
{
super( x, y, 16, 16, "", onPress );
}
public void setVisibility( final boolean vis )
{
this.visible = vis;
this.active = vis;
}
@Override
public void renderButton(final int mouseX, final int mouseY, float partial) {
Minecraft minecraft = Minecraft.getInstance();
if( this.visible )
{
final int iconIndex = this.getIconIndex();
TextureManager textureManager = minecraft.getTextureManager();
textureManager.bindTexture(TEXTURE_STATES);
RenderSystem.disableDepthTest();
RenderSystem.enableBlend(); // FIXME: This should be the _default_ state, but some vanilla widget disables it :|
if( this.halfSize )
{
this.width = 8;
this.height = 8;
RenderSystem.pushMatrix();
RenderSystem.translatef( this.x, this.y, 0.0F );
RenderSystem.scalef( 0.5f, 0.5f, 0.5f );
if( this.active )
{
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
else
{
RenderSystem.color4f( 0.5f, 0.5f, 0.5f, 1.0f );
}
final int uv_y = (int) Math.floor( iconIndex / 16.0f );
final int uv_x = iconIndex - uv_y * 16;
GuiUtils.drawTexturedModalRect( 0, 0, 256 - 16, 256 - 16, 16, 16, 0 );
GuiUtils.drawTexturedModalRect( 0, 0, uv_x * 16, uv_y * 16, 16, 16, 0 );
RenderSystem.popMatrix();
}
else
{
if( this.active )
{
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
else
{
RenderSystem.color4f( 0.5f, 0.5f, 0.5f, 1.0f );
}
final int uv_y = iconIndex / 16;
final int uv_x = iconIndex - uv_y * 16;
GuiUtils.drawTexturedModalRect( this.x, this.y, 256 - 16, 256 - 16, 16, 16, 0 );
GuiUtils.drawTexturedModalRect( this.x, this.y, uv_x * 16, uv_y * 16, 16, 16, 0 );
}
RenderSystem.enableDepthTest();
}
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
protected abstract int getIconIndex();
@Override
public int xPos()
{
return this.x;
}
@Override
public int yPos()
{
return this.y;
}
@Override
public int getWidth()
{
return this.halfSize ? 8 : 16;
}
@Override
public int getHeight()
{
return this.halfSize ? 8 : 16;
}
@Override
public boolean isVisible()
{
return this.visible;
}
public boolean isHalfSize()
{
return this.halfSize;
}
public void setHalfSize( final boolean halfSize )
{
this.halfSize = halfSize;
}
}
@@ -1,407 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.client.gui.widgets;
import appeng.api.config.*;
import appeng.core.localization.ButtonToolTips;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public class GuiImgButton extends Button implements ITooltip
{
private static final Pattern COMPILE = Pattern.compile( "%s" );
private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL );
public static final ResourceLocation TEXTURE_STATES = new ResourceLocation("appliedenergistics2", "textures/guis/states.png");
private static Map<EnumPair, ButtonAppearance> appearances;
private final Enum buttonSetting;
private boolean halfSize = false;
private String fillVar;
private Enum currentValue;
public GuiImgButton( final int x, final int y, final Enum idx, final Enum val, IPressable onPress )
{
super( x, y, 16, 16, "", onPress );
this.buttonSetting = idx;
this.currentValue = val;
if( appearances == null )
{
appearances = new HashMap<>();
this.registerApp( 16 * 7, Settings.CONDENSER_OUTPUT, CondenserOutput.TRASH, ButtonToolTips.CondenserOutput, ButtonToolTips.Trash );
this.registerApp( 16 * 7 + 1, Settings.CONDENSER_OUTPUT, CondenserOutput.MATTER_BALLS, ButtonToolTips.CondenserOutput, ButtonToolTips.MatterBalls );
this.registerApp( 16 * 7 + 2, Settings.CONDENSER_OUTPUT, CondenserOutput.SINGULARITY, ButtonToolTips.CondenserOutput, ButtonToolTips.Singularity );
this.registerApp( 16 * 9 + 1, Settings.ACCESS, AccessRestriction.READ, ButtonToolTips.IOMode, ButtonToolTips.Read );
this.registerApp( 16 * 9, Settings.ACCESS, AccessRestriction.WRITE, ButtonToolTips.IOMode, ButtonToolTips.Write );
this.registerApp( 16 * 9 + 2, Settings.ACCESS, AccessRestriction.READ_WRITE, ButtonToolTips.IOMode, ButtonToolTips.ReadWrite );
this.registerApp( 16 * 10, Settings.POWER_UNITS, PowerUnits.AE, ButtonToolTips.PowerUnits, PowerUnits.AE.textComponent() );
this.registerApp( 16 * 10 + 1, Settings.POWER_UNITS, PowerUnits.EU, ButtonToolTips.PowerUnits, PowerUnits.EU.textComponent() );
this.registerApp( 16 * 10 + 4, Settings.POWER_UNITS, PowerUnits.RF, ButtonToolTips.PowerUnits, PowerUnits.RF.textComponent() );
this.registerApp( 3, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, ButtonToolTips.RedstoneMode, ButtonToolTips.AlwaysActive );
this.registerApp( 0, Settings.REDSTONE_CONTROLLED, RedstoneMode.LOW_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.ActiveWithoutSignal );
this.registerApp( 1, Settings.REDSTONE_CONTROLLED, RedstoneMode.HIGH_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.ActiveWithSignal );
this.registerApp( 2, Settings.REDSTONE_CONTROLLED, RedstoneMode.SIGNAL_PULSE, ButtonToolTips.RedstoneMode, ButtonToolTips.ActiveOnPulse );
this.registerApp( 0, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.EmitLevelsBelow );
this.registerApp( 1, Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.EmitLevelAbove );
this.registerApp( 51, Settings.OPERATION_MODE, OperationMode.FILL, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToStorageCell );
this.registerApp( 50, Settings.OPERATION_MODE, OperationMode.EMPTY, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToNetwork );
this.registerApp( 51, Settings.IO_DIRECTION, RelativeDirection.LEFT, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToStorageCell );
this.registerApp( 50, Settings.IO_DIRECTION, RelativeDirection.RIGHT, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToNetwork );
this.registerApp( 48, Settings.SORT_DIRECTION, SortDir.ASCENDING, ButtonToolTips.SortOrder, ButtonToolTips.ToggleSortDirection );
this.registerApp( 49, Settings.SORT_DIRECTION, SortDir.DESCENDING, ButtonToolTips.SortOrder, ButtonToolTips.ToggleSortDirection );
this.registerApp( 16 * 2 + 3, Settings.SEARCH_MODE, SearchBoxMode.AUTOSEARCH, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_Auto );
this.registerApp( 16 * 2 + 4, Settings.SEARCH_MODE, SearchBoxMode.MANUAL_SEARCH, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_Standard );
this.registerApp( 16 * 2 + 5, Settings.SEARCH_MODE, SearchBoxMode.JEI_AUTOSEARCH, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_JEIAuto );
this.registerApp( 16 * 2 + 6, Settings.SEARCH_MODE, SearchBoxMode.JEI_MANUAL_SEARCH, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_JEIStandard );
this.registerApp( 16 * 2 + 7, Settings.SEARCH_MODE, SearchBoxMode.AUTOSEARCH_KEEP, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_AutoKeep );
this.registerApp( 16 * 2 + 8, Settings.SEARCH_MODE, SearchBoxMode.MANUAL_SEARCH_KEEP, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_StandardKeep );
this.registerApp( 16 * 2 + 9, Settings.SEARCH_MODE, SearchBoxMode.JEI_AUTOSEARCH_KEEP, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_JEIAutoKeep );
this.registerApp( 16 * 2 + 10, Settings.SEARCH_MODE, SearchBoxMode.JEI_MANUAL_SEARCH_KEEP, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_JEIStandardKeep );
this.registerApp( 16 * 5 + 3, Settings.LEVEL_TYPE, LevelType.ENERGY_LEVEL, ButtonToolTips.LevelType, ButtonToolTips.LevelType_Energy );
this.registerApp( 16 * 4 + 3, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL, ButtonToolTips.LevelType, ButtonToolTips.LevelType_Item );
this.registerApp( 16 * 13, Settings.TERMINAL_STYLE, TerminalStyle.TALL, ButtonToolTips.TerminalStyle, ButtonToolTips.TerminalStyle_Tall );
this.registerApp( 16 * 13 + 1, Settings.TERMINAL_STYLE, TerminalStyle.SMALL, ButtonToolTips.TerminalStyle, ButtonToolTips.TerminalStyle_Small );
this.registerApp( 16 * 13 + 2, Settings.TERMINAL_STYLE, TerminalStyle.FULL, ButtonToolTips.TerminalStyle, ButtonToolTips.TerminalStyle_Full );
this.registerApp( 64, Settings.SORT_BY, SortOrder.NAME, ButtonToolTips.SortBy, ButtonToolTips.ItemName );
this.registerApp( 65, Settings.SORT_BY, SortOrder.AMOUNT, ButtonToolTips.SortBy, ButtonToolTips.NumberOfItems );
this.registerApp( 68, Settings.SORT_BY, SortOrder.INVTWEAKS, ButtonToolTips.SortBy, ButtonToolTips.InventoryTweaks );
this.registerApp( 69, Settings.SORT_BY, SortOrder.MOD, ButtonToolTips.SortBy, ButtonToolTips.Mod );
this.registerApp( 66, Settings.ACTIONS, ActionItems.WRENCH, ButtonToolTips.PartitionStorage, ButtonToolTips.PartitionStorageHint );
this.registerApp( 6, Settings.ACTIONS, ActionItems.CLOSE, ButtonToolTips.Clear, ButtonToolTips.ClearSettings );
this.registerApp( 6, Settings.ACTIONS, ActionItems.STASH, ButtonToolTips.Stash, ButtonToolTips.StashDesc );
this.registerApp( 8, Settings.ACTIONS, ActionItems.ENCODE, ButtonToolTips.Encode, ButtonToolTips.EncodeDescription );
this.registerApp( 4 + 3 * 16, Settings.ACTIONS, ItemSubstitution.ENABLED, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDescEnabled );
this.registerApp( 7 + 3 * 16, Settings.ACTIONS, ItemSubstitution.DISABLED, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDescDisabled );
this.registerApp( 16, Settings.VIEW_MODE, ViewItems.STORED, ButtonToolTips.View, ButtonToolTips.StoredItems );
this.registerApp( 18, Settings.VIEW_MODE, ViewItems.ALL, ButtonToolTips.View, ButtonToolTips.StoredCraftable );
this.registerApp( 19, Settings.VIEW_MODE, ViewItems.CRAFTABLE, ButtonToolTips.View, ButtonToolTips.Craftable );
this.registerApp( 16 * 6, Settings.FUZZY_MODE, FuzzyMode.PERCENT_25, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_25 );
this.registerApp( 16 * 6 + 1, Settings.FUZZY_MODE, FuzzyMode.PERCENT_50, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_50 );
this.registerApp( 16 * 6 + 2, Settings.FUZZY_MODE, FuzzyMode.PERCENT_75, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_75 );
this.registerApp( 16 * 6 + 3, Settings.FUZZY_MODE, FuzzyMode.PERCENT_99, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_99 );
this.registerApp( 16 * 6 + 4, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, ButtonToolTips.FuzzyMode, ButtonToolTips.FZIgnoreAll );
this.registerApp( 80, Settings.FULLNESS_MODE, FullnessMode.EMPTY, ButtonToolTips.OperationMode, ButtonToolTips.MoveWhenEmpty );
this.registerApp( 81, Settings.FULLNESS_MODE, FullnessMode.HALF, ButtonToolTips.OperationMode, ButtonToolTips.MoveWhenWorkIsDone );
this.registerApp( 82, Settings.FULLNESS_MODE, FullnessMode.FULL, ButtonToolTips.OperationMode, ButtonToolTips.MoveWhenFull );
this.registerApp( 16 + 5, Settings.BLOCK, YesNo.YES, ButtonToolTips.InterfaceBlockingMode, ButtonToolTips.Blocking );
this.registerApp( 16 + 4, Settings.BLOCK, YesNo.NO, ButtonToolTips.InterfaceBlockingMode, ButtonToolTips.NonBlocking );
this.registerApp( 16 + 3, Settings.CRAFT_ONLY, YesNo.YES, ButtonToolTips.Craft, ButtonToolTips.CraftOnly );
this.registerApp( 16 + 2, Settings.CRAFT_ONLY, YesNo.NO, ButtonToolTips.Craft, ButtonToolTips.CraftEither );
this.registerApp( 16 * 11 + 2, Settings.CRAFT_VIA_REDSTONE, YesNo.YES, ButtonToolTips.EmitterMode, ButtonToolTips.CraftViaRedstone );
this.registerApp( 16 * 11 + 1, Settings.CRAFT_VIA_REDSTONE, YesNo.NO, ButtonToolTips.EmitterMode, ButtonToolTips.EmitWhenCrafting );
this.registerApp( 16 * 3 + 5, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY, ButtonToolTips.ReportInaccessibleItems,
ButtonToolTips.ReportInaccessibleItemsNo );
this.registerApp( 16 * 3 + 6, Settings.STORAGE_FILTER, StorageFilter.NONE, ButtonToolTips.ReportInaccessibleItems,
ButtonToolTips.ReportInaccessibleItemsYes );
this.registerApp( 16 * 14, Settings.PLACE_BLOCK, YesNo.YES, ButtonToolTips.BlockPlacement, ButtonToolTips.BlockPlacementYes );
this.registerApp( 16 * 14 + 1, Settings.PLACE_BLOCK, YesNo.NO, ButtonToolTips.BlockPlacement, ButtonToolTips.BlockPlacementNo );
this.registerApp( 16 * 15, Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT, ButtonToolTips.SchedulingMode, ButtonToolTips.SchedulingModeDefault );
this.registerApp( 16 * 15 + 1, Settings.SCHEDULING_MODE, SchedulingMode.ROUNDROBIN, ButtonToolTips.SchedulingMode,
ButtonToolTips.SchedulingModeRoundRobin );
this.registerApp( 16 * 15 + 2, Settings.SCHEDULING_MODE, SchedulingMode.RANDOM, ButtonToolTips.SchedulingMode,
ButtonToolTips.SchedulingModeRandom );
}
}
private void registerApp( final int iconIndex, final Settings setting, final Enum val, final ButtonToolTips title, final ITextComponent hint )
{
final ButtonAppearance a = new ButtonAppearance();
a.displayName = title.getTranslationKey();
a.displayValue = hint;
a.index = iconIndex;
appearances.put( new EnumPair( setting, val ), a );
}
private void registerApp( final int iconIndex, final Settings setting, final Enum val, final ButtonToolTips title, final ButtonToolTips hint )
{
registerApp(iconIndex, setting, val, title, hint.getTranslationKey());
}
public void setVisibility( final boolean vis )
{
this.visible = vis;
this.active = vis;
}
@Override
public void renderButton(final int mouseX, final int mouseY, float partial) {
Minecraft minecraft = Minecraft.getInstance();
if( this.visible )
{
final int iconIndex = this.getIconIndex();
TextureManager textureManager = minecraft.getTextureManager();
textureManager.bindTexture(TEXTURE_STATES);
RenderSystem.disableDepthTest();
RenderSystem.enableBlend(); // FIXME: This should be the _default_ state, but some vanilla widget disables it :|
if( this.halfSize )
{
this.width = 8;
this.height = 8;
RenderSystem.pushMatrix();
RenderSystem.translatef( this.x, this.y, 0.0F );
RenderSystem.scalef( 0.5f, 0.5f, 0.5f );
if( this.active )
{
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
else
{
RenderSystem.color4f( 0.5f, 0.5f, 0.5f, 1.0f );
}
final int uv_y = (int) Math.floor( iconIndex / 16.0f );
final int uv_x = iconIndex - uv_y * 16;
GuiUtils.drawTexturedModalRect( 0, 0, 256 - 16, 256 - 16, 16, 16, 0 );
GuiUtils.drawTexturedModalRect( 0, 0, uv_x * 16, uv_y * 16, 16, 16, 0 );
RenderSystem.popMatrix();
}
else
{
if( this.active )
{
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
else
{
RenderSystem.color4f( 0.5f, 0.5f, 0.5f, 1.0f );
}
final int uv_y = (int) Math.floor( iconIndex / 16 );
final int uv_x = iconIndex - uv_y * 16;
GuiUtils.drawTexturedModalRect( this.x, this.y, 256 - 16, 256 - 16, 16, 16, 0 );
GuiUtils.drawTexturedModalRect( this.x, this.y, uv_x * 16, uv_y * 16, 16, 16, 0 );
}
RenderSystem.enableDepthTest();
}
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
private int getIconIndex()
{
if( this.buttonSetting != null && this.currentValue != null )
{
final ButtonAppearance app = appearances.get( new EnumPair( this.buttonSetting, this.currentValue ) );
if( app == null )
{
return 256 - 1;
}
return app.index;
}
return 256 - 1;
}
public Settings getSetting()
{
return (Settings) this.buttonSetting;
}
public Enum getCurrentValue()
{
return this.currentValue;
}
@Override
public String getMessage()
{
ITextComponent displayName = null;
ITextComponent displayValue = null;
if( this.buttonSetting != null && this.currentValue != null )
{
final ButtonAppearance buttonAppearance = appearances.get( new EnumPair( this.buttonSetting, this.currentValue ) );
if( buttonAppearance == null )
{
return "No Such Message";
}
displayName = buttonAppearance.displayName;
displayValue = buttonAppearance.displayValue;
}
if( displayName != null )
{
String name = displayName.getString();
String value = displayValue.getString();
if( this.fillVar != null )
{
value = COMPILE.matcher( value ).replaceFirst( this.fillVar );
}
value = PATTERN_NEW_LINE.matcher( value ).replaceAll( "\n" );
final StringBuilder sb = new StringBuilder( value );
int i = sb.lastIndexOf( "\n" );
if( i <= 0 )
{
i = 0;
}
while( i + 30 < sb.length() && ( i = sb.lastIndexOf( " ", i + 30 ) ) != -1 )
{
sb.replace( i, i + 1, "\n" );
}
return name + '\n' + sb;
}
return null;
}
@Override
public int xPos()
{
return this.x;
}
@Override
public int yPos()
{
return this.y;
}
@Override
public int getWidth()
{
return this.halfSize ? 8 : 16;
}
@Override
public int getHeight()
{
return this.halfSize ? 8 : 16;
}
@Override
public boolean isVisible()
{
return this.visible;
}
public void set( final Enum e )
{
if( this.currentValue != e )
{
this.currentValue = e;
}
}
public boolean isHalfSize()
{
return this.halfSize;
}
public void setHalfSize( final boolean halfSize )
{
this.halfSize = halfSize;
}
public String getFillVar()
{
return this.fillVar;
}
public void setFillVar( final String fillVar )
{
this.fillVar = fillVar;
}
private static final class EnumPair
{
final Enum setting;
final Enum value;
EnumPair( final Enum a, final Enum b )
{
this.setting = a;
this.value = b;
}
@Override
public int hashCode()
{
return this.setting.hashCode() ^ this.value.hashCode();
}
@Override
public boolean equals( final Object obj )
{
if( obj == null )
{
return false;
}
if( this.getClass() != obj.getClass() )
{
return false;
}
final EnumPair other = (EnumPair) obj;
return other.setting == this.setting && other.value == this.value;
}
}
private static class ButtonAppearance
{
public int index;
public ITextComponent displayName;
public ITextComponent displayValue;
}
}
@@ -0,0 +1,49 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.client.gui.widgets;
import appeng.api.config.*;
import appeng.core.localization.ButtonToolTips;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
/**
* Convenience button that automatically sends settings changes to the server.
*/
public class GuiServerSettingToggleButton<T extends Enum<T>> extends GuiSettingToggleButton<T>
{
public GuiServerSettingToggleButton(final int x, final int y, final Settings setting, final T val )
{
super( x, y, setting, val, GuiServerSettingToggleButton::sendToServer );
}
private static <T extends Enum<T>> void sendToServer(GuiSettingToggleButton<T> button, boolean backwards) {
NetworkHandler.instance().sendToServer( new PacketConfigButton( button.getSetting(), backwards ) );
}
}
@@ -0,0 +1,324 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.client.gui.widgets;
import appeng.api.config.*;
import appeng.core.localization.ButtonToolTips;
import appeng.util.EnumCycler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
import java.util.regex.Pattern;
public class GuiSettingToggleButton<T extends Enum<T>> extends GuiIconButton
{
private static final Pattern COMPILE = Pattern.compile( "%s" );
private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL );
private static Map<EnumPair, ButtonAppearance> appearances;
private final Settings buttonSetting;
private final IHandler<GuiSettingToggleButton<T>> onPress;
private final EnumSet<T> validValues;
private String fillVar;
private T currentValue;
@FunctionalInterface
public interface IHandler<T extends GuiSettingToggleButton<?>> {
void handle(T button, boolean backwards);
}
public GuiSettingToggleButton(final int x, final int y, final Settings setting, final T val, IHandler<GuiSettingToggleButton<T>> onPress )
{
this(x, y, setting, val, t -> true, onPress);
}
public GuiSettingToggleButton(final int x, final int y, final Settings setting, final T val, Predicate<T> isValidValue, IHandler<GuiSettingToggleButton<T>> onPress )
{
super( x, y, GuiSettingToggleButton::onPress );
this.onPress = onPress;
// Build a list of values (in order) that are valid w.r.t. the given predicate
EnumSet<T> validValues = EnumSet.allOf(val.getDeclaringClass());
validValues.removeIf(isValidValue.negate());
this.validValues = validValues;
this.buttonSetting = setting;
this.currentValue = val;
if( appearances == null )
{
appearances = new HashMap<>();
registerApp( 16 * 7, Settings.CONDENSER_OUTPUT, CondenserOutput.TRASH, ButtonToolTips.CondenserOutput, ButtonToolTips.Trash );
registerApp( 16 * 7 + 1, Settings.CONDENSER_OUTPUT, CondenserOutput.MATTER_BALLS, ButtonToolTips.CondenserOutput, ButtonToolTips.MatterBalls );
registerApp( 16 * 7 + 2, Settings.CONDENSER_OUTPUT, CondenserOutput.SINGULARITY, ButtonToolTips.CondenserOutput, ButtonToolTips.Singularity );
registerApp( 16 * 9 + 1, Settings.ACCESS, AccessRestriction.READ, ButtonToolTips.IOMode, ButtonToolTips.Read );
registerApp( 16 * 9, Settings.ACCESS, AccessRestriction.WRITE, ButtonToolTips.IOMode, ButtonToolTips.Write );
registerApp( 16 * 9 + 2, Settings.ACCESS, AccessRestriction.READ_WRITE, ButtonToolTips.IOMode, ButtonToolTips.ReadWrite );
registerApp( 16 * 10, Settings.POWER_UNITS, PowerUnits.AE, ButtonToolTips.PowerUnits, PowerUnits.AE.textComponent() );
registerApp( 16 * 10 + 1, Settings.POWER_UNITS, PowerUnits.EU, ButtonToolTips.PowerUnits, PowerUnits.EU.textComponent() );
registerApp( 16 * 10 + 4, Settings.POWER_UNITS, PowerUnits.RF, ButtonToolTips.PowerUnits, PowerUnits.RF.textComponent() );
registerApp( 3, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, ButtonToolTips.RedstoneMode, ButtonToolTips.AlwaysActive );
registerApp( 0, Settings.REDSTONE_CONTROLLED, RedstoneMode.LOW_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.ActiveWithoutSignal );
registerApp( 1, Settings.REDSTONE_CONTROLLED, RedstoneMode.HIGH_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.ActiveWithSignal );
registerApp( 2, Settings.REDSTONE_CONTROLLED, RedstoneMode.SIGNAL_PULSE, ButtonToolTips.RedstoneMode, ButtonToolTips.ActiveOnPulse );
registerApp( 0, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.EmitLevelsBelow );
registerApp( 1, Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.EmitLevelAbove );
registerApp( 51, Settings.OPERATION_MODE, OperationMode.FILL, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToStorageCell );
registerApp( 50, Settings.OPERATION_MODE, OperationMode.EMPTY, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToNetwork );
registerApp( 51, Settings.IO_DIRECTION, RelativeDirection.LEFT, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToStorageCell );
registerApp( 50, Settings.IO_DIRECTION, RelativeDirection.RIGHT, ButtonToolTips.TransferDirection, ButtonToolTips.TransferToNetwork );
registerApp( 48, Settings.SORT_DIRECTION, SortDir.ASCENDING, ButtonToolTips.SortOrder, ButtonToolTips.ToggleSortDirection );
registerApp( 49, Settings.SORT_DIRECTION, SortDir.DESCENDING, ButtonToolTips.SortOrder, ButtonToolTips.ToggleSortDirection );
registerApp( 16 * 2 + 3, Settings.SEARCH_MODE, SearchBoxMode.AUTOSEARCH, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_Auto );
registerApp( 16 * 2 + 4, Settings.SEARCH_MODE, SearchBoxMode.MANUAL_SEARCH, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_Standard );
registerApp( 16 * 2 + 5, Settings.SEARCH_MODE, SearchBoxMode.JEI_AUTOSEARCH, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_JEIAuto );
registerApp( 16 * 2 + 6, Settings.SEARCH_MODE, SearchBoxMode.JEI_MANUAL_SEARCH, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_JEIStandard );
registerApp( 16 * 2 + 7, Settings.SEARCH_MODE, SearchBoxMode.AUTOSEARCH_KEEP, ButtonToolTips.SearchMode, ButtonToolTips.SearchMode_AutoKeep );
registerApp( 16 * 2 + 8, Settings.SEARCH_MODE, SearchBoxMode.MANUAL_SEARCH_KEEP, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_StandardKeep );
registerApp( 16 * 2 + 9, Settings.SEARCH_MODE, SearchBoxMode.JEI_AUTOSEARCH_KEEP, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_JEIAutoKeep );
registerApp( 16 * 2 + 10, Settings.SEARCH_MODE, SearchBoxMode.JEI_MANUAL_SEARCH_KEEP, ButtonToolTips.SearchMode,
ButtonToolTips.SearchMode_JEIStandardKeep );
registerApp( 16 * 5 + 3, Settings.LEVEL_TYPE, LevelType.ENERGY_LEVEL, ButtonToolTips.LevelType, ButtonToolTips.LevelType_Energy );
registerApp( 16 * 4 + 3, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL, ButtonToolTips.LevelType, ButtonToolTips.LevelType_Item );
registerApp( 16 * 13, Settings.TERMINAL_STYLE, TerminalStyle.TALL, ButtonToolTips.TerminalStyle, ButtonToolTips.TerminalStyle_Tall );
registerApp( 16 * 13 + 1, Settings.TERMINAL_STYLE, TerminalStyle.SMALL, ButtonToolTips.TerminalStyle, ButtonToolTips.TerminalStyle_Small );
registerApp( 16 * 13 + 2, Settings.TERMINAL_STYLE, TerminalStyle.FULL, ButtonToolTips.TerminalStyle, ButtonToolTips.TerminalStyle_Full );
registerApp( 64, Settings.SORT_BY, SortOrder.NAME, ButtonToolTips.SortBy, ButtonToolTips.ItemName );
registerApp( 65, Settings.SORT_BY, SortOrder.AMOUNT, ButtonToolTips.SortBy, ButtonToolTips.NumberOfItems );
registerApp( 68, Settings.SORT_BY, SortOrder.INVTWEAKS, ButtonToolTips.SortBy, ButtonToolTips.InventoryTweaks );
registerApp( 69, Settings.SORT_BY, SortOrder.MOD, ButtonToolTips.SortBy, ButtonToolTips.Mod );
registerApp( 16, Settings.VIEW_MODE, ViewItems.STORED, ButtonToolTips.View, ButtonToolTips.StoredItems );
registerApp( 18, Settings.VIEW_MODE, ViewItems.ALL, ButtonToolTips.View, ButtonToolTips.StoredCraftable );
registerApp( 19, Settings.VIEW_MODE, ViewItems.CRAFTABLE, ButtonToolTips.View, ButtonToolTips.Craftable );
registerApp( 16 * 6, Settings.FUZZY_MODE, FuzzyMode.PERCENT_25, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_25 );
registerApp( 16 * 6 + 1, Settings.FUZZY_MODE, FuzzyMode.PERCENT_50, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_50 );
registerApp( 16 * 6 + 2, Settings.FUZZY_MODE, FuzzyMode.PERCENT_75, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_75 );
registerApp( 16 * 6 + 3, Settings.FUZZY_MODE, FuzzyMode.PERCENT_99, ButtonToolTips.FuzzyMode, ButtonToolTips.FZPercent_99 );
registerApp( 16 * 6 + 4, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, ButtonToolTips.FuzzyMode, ButtonToolTips.FZIgnoreAll );
registerApp( 80, Settings.FULLNESS_MODE, FullnessMode.EMPTY, ButtonToolTips.OperationMode, ButtonToolTips.MoveWhenEmpty );
registerApp( 81, Settings.FULLNESS_MODE, FullnessMode.HALF, ButtonToolTips.OperationMode, ButtonToolTips.MoveWhenWorkIsDone );
registerApp( 82, Settings.FULLNESS_MODE, FullnessMode.FULL, ButtonToolTips.OperationMode, ButtonToolTips.MoveWhenFull );
registerApp( 16 + 5, Settings.BLOCK, YesNo.YES, ButtonToolTips.InterfaceBlockingMode, ButtonToolTips.Blocking );
registerApp( 16 + 4, Settings.BLOCK, YesNo.NO, ButtonToolTips.InterfaceBlockingMode, ButtonToolTips.NonBlocking );
registerApp( 16 + 3, Settings.CRAFT_ONLY, YesNo.YES, ButtonToolTips.Craft, ButtonToolTips.CraftOnly );
registerApp( 16 + 2, Settings.CRAFT_ONLY, YesNo.NO, ButtonToolTips.Craft, ButtonToolTips.CraftEither );
registerApp( 16 * 11 + 2, Settings.CRAFT_VIA_REDSTONE, YesNo.YES, ButtonToolTips.EmitterMode, ButtonToolTips.CraftViaRedstone );
registerApp( 16 * 11 + 1, Settings.CRAFT_VIA_REDSTONE, YesNo.NO, ButtonToolTips.EmitterMode, ButtonToolTips.EmitWhenCrafting );
registerApp( 16 * 3 + 5, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY, ButtonToolTips.ReportInaccessibleItems,
ButtonToolTips.ReportInaccessibleItemsNo );
registerApp( 16 * 3 + 6, Settings.STORAGE_FILTER, StorageFilter.NONE, ButtonToolTips.ReportInaccessibleItems,
ButtonToolTips.ReportInaccessibleItemsYes );
registerApp( 16 * 14, Settings.PLACE_BLOCK, YesNo.YES, ButtonToolTips.BlockPlacement, ButtonToolTips.BlockPlacementYes );
registerApp( 16 * 14 + 1, Settings.PLACE_BLOCK, YesNo.NO, ButtonToolTips.BlockPlacement, ButtonToolTips.BlockPlacementNo );
registerApp( 16 * 15, Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT, ButtonToolTips.SchedulingMode, ButtonToolTips.SchedulingModeDefault );
registerApp( 16 * 15 + 1, Settings.SCHEDULING_MODE, SchedulingMode.ROUNDROBIN, ButtonToolTips.SchedulingMode,
ButtonToolTips.SchedulingModeRoundRobin );
registerApp( 16 * 15 + 2, Settings.SCHEDULING_MODE, SchedulingMode.RANDOM, ButtonToolTips.SchedulingMode,
ButtonToolTips.SchedulingModeRandom );
}
}
private static void onPress(Button btn) {
if (btn instanceof GuiSettingToggleButton) {
((GuiSettingToggleButton<?>) btn).triggerPress();
}
}
private void triggerPress() {
boolean backwards = Minecraft.getInstance().mouseHelper.isRightDown();
onPress.handle(this, backwards);
}
private static void registerApp( final int iconIndex, final Settings setting, final Enum<?> val, final ButtonToolTips title, final ITextComponent hint )
{
final ButtonAppearance a = new ButtonAppearance();
a.displayName = title.getTranslationKey();
a.displayValue = hint;
a.index = iconIndex;
appearances.put( new EnumPair( setting, val ), a );
}
private static void registerApp( final int iconIndex, final Settings setting, final Enum<?> val, final ButtonToolTips title, final ButtonToolTips hint )
{
registerApp(iconIndex, setting, val, title, hint.getTranslationKey());
}
@Override
protected int getIconIndex()
{
if( this.buttonSetting != null && this.currentValue != null )
{
final ButtonAppearance app = appearances.get( new EnumPair( this.buttonSetting, this.currentValue ) );
if( app == null )
{
return 256 - 1;
}
return app.index;
}
return 256 - 1;
}
public Settings getSetting()
{
return this.buttonSetting;
}
public T getCurrentValue()
{
return this.currentValue;
}
public void set( final T e )
{
if( this.currentValue != e )
{
this.currentValue = e;
}
}
public T getNextValue(boolean backwards) {
return EnumCycler.rotateEnum(currentValue, backwards, validValues);
}
@Override
public String getMessage()
{
ITextComponent displayName = null;
ITextComponent displayValue = null;
if( this.buttonSetting != null && this.currentValue != null )
{
final ButtonAppearance buttonAppearance = appearances.get( new EnumPair( this.buttonSetting, this.currentValue ) );
if( buttonAppearance == null )
{
return "No Such Message";
}
displayName = buttonAppearance.displayName;
displayValue = buttonAppearance.displayValue;
}
if( displayName != null )
{
String name = displayName.getString();
String value = displayValue.getString();
if( this.fillVar != null )
{
value = COMPILE.matcher( value ).replaceFirst( this.fillVar );
}
value = PATTERN_NEW_LINE.matcher( value ).replaceAll( "\n" );
final StringBuilder sb = new StringBuilder( value );
int i = sb.lastIndexOf( "\n" );
if( i <= 0 )
{
i = 0;
}
while( i + 30 < sb.length() && ( i = sb.lastIndexOf( " ", i + 30 ) ) != -1 )
{
sb.replace( i, i + 1, "\n" );
}
return name + '\n' + sb;
}
return null;
}
public String getFillVar()
{
return this.fillVar;
}
public void setFillVar( final String fillVar )
{
this.fillVar = fillVar;
}
private static final class EnumPair
{
final Settings setting;
final Enum<?> value;
EnumPair( final Settings a, final Enum<?> b )
{
this.setting = a;
this.value = b;
}
@Override
public int hashCode()
{
return this.setting.hashCode() ^ this.value.hashCode();
}
@Override
public boolean equals( final Object obj )
{
if( obj == null )
{
return false;
}
if( this.getClass() != obj.getClass() )
{
return false;
}
final EnumPair other = (EnumPair) obj;
return other.setting == this.setting && other.value == this.value;
}
}
private static class ButtonAppearance
{
public int index;
public ITextComponent displayName;
public ITextComponent displayValue;
}
}