Skip to content

Commit

Permalink
Added Redstone toggle See #1 for further info.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTroble committed Jan 4, 2019
1 parent 844ce36 commit 575333b
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 317 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -26,3 +26,4 @@ run
/README.txt
/forge-1.12.2-14.23.5.2770-changelog.txt
/CREDITS.txt
/gradle.properties
24 changes: 23 additions & 1 deletion src/main/java/info/u_team/draw_bridge/gui/GuiDrawBridge.java
@@ -1,14 +1,21 @@
package info.u_team.draw_bridge.gui;

import java.io.IOException;

import com.google.common.collect.Lists;

import info.u_team.draw_bridge.DrawBridgeConstants;
import info.u_team.draw_bridge.container.ContainerDrawBridge;
import info.u_team.draw_bridge.tileentity.TileEntityDrawBridge;
import info.u_team.u_team_core.gui.UGuiContainer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiButtonToggle;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.config.GuiSlider;
import net.minecraftforge.fml.relauncher.*;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiDrawBridge extends UGuiContainer {
Expand All @@ -18,6 +25,7 @@ public class GuiDrawBridge extends UGuiContainer {
private final TileEntityDrawBridge drawbridge;

private GuiSlider speedSlider;
private GuiButtonToggle toggle;

private int fixValueTry;

Expand All @@ -31,13 +39,26 @@ public GuiDrawBridge(TileEntityDrawBridge tileentity, EntityPlayer entityplayer)
public void initGui() {
super.initGui();
fixValueTry = 0;
toggle = new GuiButtonToggle(1, guiLeft + 100, guiTop + 60, 20, 20, drawbridge.needsRedstone());
toggle.initTextureValues(xSize, 0, 20, 20, BACKGROUND);
buttonList.add(toggle);
speedSlider = new GuiSlider(0, guiLeft + 7, guiTop + 60, 90, 20, I18n.format(DrawBridgeConstants.MODID + ":container.drawbridge.speed"), I18n.format(DrawBridgeConstants.MODID + ":container.drawbridge.ticks"), 0, 100, drawbridge.getSpeed(), false, true, (slider) -> {
drawbridge.setSpeed(slider.getValueInt());
drawbridge.syncClientToServer(drawbridge.getPos());
});
buttonList.add(speedSlider);
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
super.actionPerformed(button);
if(button.id == 1) {
toggle.setStateTriggered(!toggle.isStateTriggered());
drawbridge.setNeedsRedstone(toggle.isStateTriggered());
drawbridge.syncClientToServer(drawbridge.getPos());
}
}

@Override
public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
fontRenderer.drawString(I18n.format(DrawBridgeConstants.MODID + ":container.drawbridge"), 8, 6, 4210752);
Expand All @@ -49,6 +70,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
renderHoveredToolTip(mouseX, mouseY);
if(toggle.isMouseOver())this.drawHoveringText(Lists.newArrayList("Needs Redstone to activate?"), mouseX, mouseY, fontRenderer);
if (fixValueTry < 10 && speedSlider.getValueInt() == 0) {
speedSlider.setValue(drawbridge.getSpeed());
if (speedSlider.getValueInt() > 0) {
Expand Down

0 comments on commit 575333b

Please sign in to comment.