-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/main/java/com/dyonovan/modernalchemy/gui/buttons/MultiStateButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.dyonovan.modernalchemy.gui.buttons; | ||
|
||
import com.dyonovan.modernalchemy.lib.Constants; | ||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.lwjgl.opengl.GL11; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class MultiStateButton extends GuiButton { | ||
|
||
int states; | ||
int currentState = 0; | ||
String resource; | ||
|
||
/** | ||
* Makes a button with provided states | ||
* @param index The button index | ||
* @param x xPos | ||
* @param y yPos | ||
* @param width button width | ||
* @param height button height | ||
* @param statesNum how many states | ||
* @param string Resource location (don't worry about mod id, just "textures/gui/...") | ||
*/ | ||
public MultiStateButton(int index, int x, int y, int width, int height, int statesNum, String string) { | ||
super(index, x, y, ""); | ||
this.width = width; | ||
this.height = height; | ||
states = statesNum; | ||
resource = string; | ||
} | ||
|
||
/** | ||
* Increments the icon 1 state | ||
*/ | ||
public void cycleIcon() { | ||
currentState++; | ||
if(currentState >= states) | ||
currentState = 0; | ||
} | ||
|
||
/** | ||
* Set the state of the button | ||
* @param i What state (should probably be less than the max) | ||
*/ | ||
public void setCurrentState(int i) { | ||
currentState = i; | ||
} | ||
|
||
/** | ||
* Get what state the button is in | ||
* @return the int representation of the current state | ||
*/ | ||
public int getState() { | ||
return currentState; | ||
} | ||
|
||
public void drawButton(Minecraft par1Minecraft, int par2, int par3) | ||
{ | ||
super.drawButton(par1Minecraft, par2, par3); | ||
if (this.visible) | ||
{ | ||
par1Minecraft.getTextureManager().bindTexture(new ResourceLocation(Constants.MODID, resource)); | ||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | ||
boolean flag = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height; | ||
|
||
int u = currentState * width; | ||
int v = 0; | ||
if (flag) | ||
{ | ||
v += this.height; | ||
|
||
} | ||
this.drawTexturedModalRect(this.xPosition, this.yPosition, u, v, this.width, this.height); | ||
} | ||
} | ||
} |
Binary file added
BIN
+517 Bytes
src/main/resources/assets/modernalchemy/textures/gui/buttons/testButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.