Added RC's button templates
Feel free to use/rewrite/delete as you see fit.
This commit is contained in:
parent
1eb2bd12a7
commit
2a46bf1954
8 changed files with 313 additions and 0 deletions
BIN
buildcraft_resources/gfx/buildcraft/gui/buttons.png
Normal file
BIN
buildcraft_resources/gfx/buildcraft/gui/buttons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
32
common/buildcraft/core/gui/buttons/GuiBetterButton.java
Normal file
32
common/buildcraft/core/gui/buttons/GuiBetterButton.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package buildcraft.core.gui.buttons;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiBetterButton extends GuiButton {
|
||||
|
||||
public static final String BUTTON_TEXTURES = "/gfx/buildcraft/gui/buttons.png";
|
||||
|
||||
public GuiBetterButton(int id, int x, int y, String label) {
|
||||
this(id, x, y, 200, 20, label);
|
||||
}
|
||||
|
||||
public GuiBetterButton(int id, int x, int y, int width, int height, String label) {
|
||||
super(id, x, y, width, height, label);
|
||||
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
45
common/buildcraft/core/gui/buttons/GuiButtonSmall.java
Normal file
45
common/buildcraft/core/gui/buttons/GuiButtonSmall.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package buildcraft.core.gui.buttons;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiButtonSmall extends GuiBetterButton {
|
||||
|
||||
public GuiButtonSmall(int i, int x, int y, String s) {
|
||||
this(i, x, y, 200, s);
|
||||
}
|
||||
|
||||
public GuiButtonSmall(int i, int x, int y, int w, String s) {
|
||||
super(i, x, y, w, 15, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft minecraft, int i, int j) {
|
||||
if (!drawButton) {
|
||||
return;
|
||||
}
|
||||
FontRenderer fontrenderer = minecraft.fontRenderer;
|
||||
minecraft.renderEngine.bindTexture(BUTTON_TEXTURES);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
boolean flag = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height;
|
||||
int k = getHoverState(flag);
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 168 + k * 15, width / 2, height);
|
||||
drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 168 + k * 15, width / 2, height);
|
||||
mouseDragged(minecraft, i, j);
|
||||
if (!enabled) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else if (flag) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
58
common/buildcraft/core/gui/buttons/GuiMultiButton.java
Normal file
58
common/buildcraft/core/gui/buttons/GuiMultiButton.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package buildcraft.core.gui.buttons;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiMultiButton extends GuiBetterButton {
|
||||
|
||||
private final MultiButtonController control;
|
||||
|
||||
public GuiMultiButton(int id, int x, int y, int width, MultiButtonController control) {
|
||||
super(id, x, y, width, 20, "");
|
||||
this.control = control.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft minecraft, int i, int j) {
|
||||
if (!drawButton) {
|
||||
return;
|
||||
}
|
||||
FontRenderer fontrenderer = minecraft.fontRenderer;
|
||||
minecraft.renderEngine.bindTexture(BUTTON_TEXTURES);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
boolean flag = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height;
|
||||
int hoverState = getHoverState(flag);
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 88 + hoverState * 20, width / 2, height);
|
||||
drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 88 + hoverState * 20, width / 2, height);
|
||||
mouseDragged(minecraft, i, j);
|
||||
displayString = control.getButtonState().getLabel();
|
||||
if (!enabled) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else if (flag) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean pressed = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if (pressed) {
|
||||
control.incrementState();
|
||||
}
|
||||
return pressed;
|
||||
}
|
||||
|
||||
public MultiButtonController getController() {
|
||||
return control;
|
||||
}
|
||||
}
|
69
common/buildcraft/core/gui/buttons/GuiToggleButton.java
Normal file
69
common/buildcraft/core/gui/buttons/GuiToggleButton.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package buildcraft.core.gui.buttons;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
public class GuiToggleButton extends GuiBetterButton {
|
||||
|
||||
public boolean active;
|
||||
|
||||
public GuiToggleButton(int id, int x, int y, String label, boolean active) {
|
||||
this(id, x, y, 200, 20, label, active);
|
||||
}
|
||||
|
||||
public GuiToggleButton(int id, int x, int y, int width, String s, boolean active) {
|
||||
super(id, x, y, width, 20, s);
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public GuiToggleButton(int id, int x, int y, int width, int height, String s, boolean active) {
|
||||
super(id, x, y, width, height, s);
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
active = !active;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHoverState(boolean flag) {
|
||||
int state = 1;
|
||||
if (!enabled) {
|
||||
state = 0;
|
||||
} else if (flag) {
|
||||
state = 2;
|
||||
} else if (!active) {
|
||||
state = 3;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft minecraft, int i, int j) {
|
||||
if (!drawButton) {
|
||||
return;
|
||||
}
|
||||
FontRenderer fontrenderer = minecraft.fontRenderer;
|
||||
minecraft.renderEngine.bindTexture(BUTTON_TEXTURES);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
boolean flag = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height;
|
||||
int k = getHoverState(flag);
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 88 + k * 20, width / 2, height);
|
||||
drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 88 + k * 20, width / 2, height);
|
||||
mouseDragged(minecraft, i, j);
|
||||
if (!enabled) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else if (flag) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffffa0);
|
||||
} else if (!active) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0x777777);
|
||||
} else {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
48
common/buildcraft/core/gui/buttons/GuiToggleButtonSmall.java
Normal file
48
common/buildcraft/core/gui/buttons/GuiToggleButtonSmall.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
package buildcraft.core.gui.buttons;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiToggleButtonSmall extends GuiToggleButton {
|
||||
|
||||
public GuiToggleButtonSmall(int i, int j, int k, String s, boolean active) {
|
||||
this(i, j, k, 200, s, active);
|
||||
}
|
||||
|
||||
public GuiToggleButtonSmall(int i, int x, int y, int w, String s, boolean active) {
|
||||
super(i, x, y, w, 15, s, active);
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft minecraft, int i, int j) {
|
||||
if (!drawButton) {
|
||||
return;
|
||||
}
|
||||
FontRenderer fontrenderer = minecraft.fontRenderer;
|
||||
minecraft.renderEngine.bindTexture(BUTTON_TEXTURES);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
boolean flag = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height;
|
||||
int k = getHoverState(flag);
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 168 + k * 15, width / 2, height);
|
||||
drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 168 + k * 15, width / 2, height);
|
||||
mouseDragged(minecraft, i, j);
|
||||
if (!enabled) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else if (flag) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffffa0);
|
||||
} else if (!active) {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0x777777);
|
||||
} else {
|
||||
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
12
common/buildcraft/core/gui/buttons/IMultiButtonState.java
Normal file
12
common/buildcraft/core/gui/buttons/IMultiButtonState.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package buildcraft.core.gui.buttons;
|
||||
|
||||
/**
|
||||
* This could possibly be expanded to include the graphic that should be
|
||||
* rendered.
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
public interface IMultiButtonState {
|
||||
|
||||
public String getLabel();
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package buildcraft.core.gui.buttons;
|
||||
|
||||
/**
|
||||
* T should be an Enum of button states
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
public class MultiButtonController<T extends IMultiButtonState> {
|
||||
|
||||
private int currentState;
|
||||
private final T[] validStates;
|
||||
|
||||
private MultiButtonController(int startState, T... validStates) {
|
||||
this.currentState = startState;
|
||||
this.validStates = validStates;
|
||||
}
|
||||
|
||||
public static <T extends IMultiButtonState> MultiButtonController getController(int startState, T... validStates) {
|
||||
return new MultiButtonController<T>(startState, validStates);
|
||||
}
|
||||
|
||||
public MultiButtonController copy() {
|
||||
return new MultiButtonController(currentState, validStates.clone());
|
||||
}
|
||||
|
||||
public T[] getValidStates() {
|
||||
return validStates;
|
||||
}
|
||||
|
||||
public int incrementState() {
|
||||
int newState = currentState + 1;
|
||||
if (newState >= validStates.length) {
|
||||
newState = 0;
|
||||
}
|
||||
currentState = newState;
|
||||
return currentState;
|
||||
}
|
||||
|
||||
public void setCurrentState(int state) {
|
||||
currentState = state;
|
||||
}
|
||||
|
||||
public int getCurrentState() {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
public T getButtonState() {
|
||||
return validStates[currentState];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue