Reformatted all the code using the default intelji formatting options.
This commit is contained in:
parent
2f63a24070
commit
e0ab0af822
363 changed files with 20524 additions and 23016 deletions
|
@ -12,8 +12,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
* @author skyboy
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundBase implements ISound
|
||||
{
|
||||
public class SoundBase implements ISound {
|
||||
|
||||
protected AttenuationType attenuation;
|
||||
protected final ResourceLocation sound;
|
||||
|
@ -25,86 +24,72 @@ public class SoundBase implements ISound
|
|||
protected boolean repeat;
|
||||
protected int repeatDelay;
|
||||
|
||||
public SoundBase(String sound)
|
||||
{
|
||||
public SoundBase(String sound) {
|
||||
|
||||
this(sound, 0);
|
||||
}
|
||||
|
||||
public SoundBase(String sound, float volume)
|
||||
{
|
||||
public SoundBase(String sound, float volume) {
|
||||
|
||||
this(sound, volume, 0);
|
||||
}
|
||||
|
||||
public SoundBase(String sound, float volume, float pitch)
|
||||
{
|
||||
public SoundBase(String sound, float volume, float pitch) {
|
||||
|
||||
this(sound, volume, pitch, false, 0);
|
||||
}
|
||||
|
||||
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay)
|
||||
{
|
||||
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay) {
|
||||
|
||||
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
|
||||
}
|
||||
|
||||
public SoundBase(String sound, float volume, float pitch, double x, double y, double z)
|
||||
{
|
||||
public SoundBase(String sound, float volume, float pitch, double x, double y, double z) {
|
||||
|
||||
this(sound, volume, pitch, false, 0, x, y, z);
|
||||
}
|
||||
|
||||
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
|
||||
{
|
||||
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
|
||||
|
||||
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
|
||||
}
|
||||
|
||||
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
|
||||
{
|
||||
public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation) {
|
||||
|
||||
this(new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
|
||||
}
|
||||
|
||||
public SoundBase(ResourceLocation sound)
|
||||
{
|
||||
public SoundBase(ResourceLocation sound) {
|
||||
|
||||
this(sound, 0);
|
||||
}
|
||||
|
||||
public SoundBase(ResourceLocation sound, float volume)
|
||||
{
|
||||
public SoundBase(ResourceLocation sound, float volume) {
|
||||
|
||||
this(sound, volume, 0);
|
||||
}
|
||||
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch)
|
||||
{
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch) {
|
||||
|
||||
this(sound, volume, pitch, false, 0);
|
||||
}
|
||||
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay)
|
||||
{
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay) {
|
||||
|
||||
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
|
||||
}
|
||||
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, double x, double y, double z)
|
||||
{
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, double x, double y, double z) {
|
||||
|
||||
this(sound, volume, pitch, false, 0, x, y, z);
|
||||
}
|
||||
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
|
||||
{
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
|
||||
|
||||
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
|
||||
}
|
||||
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
|
||||
{
|
||||
public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation) {
|
||||
|
||||
this.attenuation = attenuation;
|
||||
this.sound = sound;
|
||||
|
@ -117,8 +102,7 @@ public class SoundBase implements ISound
|
|||
this.repeatDelay = repeatDelay;
|
||||
}
|
||||
|
||||
public SoundBase(SoundBase other)
|
||||
{
|
||||
public SoundBase(SoundBase other) {
|
||||
|
||||
this.attenuation = other.attenuation;
|
||||
this.sound = other.sound;
|
||||
|
@ -132,64 +116,55 @@ public class SoundBase implements ISound
|
|||
}
|
||||
|
||||
@Override
|
||||
public AttenuationType getAttenuationType()
|
||||
{
|
||||
public AttenuationType getAttenuationType() {
|
||||
|
||||
return attenuation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getPositionedSoundLocation()
|
||||
{
|
||||
public ResourceLocation getPositionedSoundLocation() {
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume()
|
||||
{
|
||||
public float getVolume() {
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPitch()
|
||||
{
|
||||
public float getPitch() {
|
||||
|
||||
return pitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getXPosF()
|
||||
{
|
||||
public float getXPosF() {
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYPosF()
|
||||
{
|
||||
public float getYPosF() {
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZPosF()
|
||||
{
|
||||
public float getZPosF() {
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRepeat()
|
||||
{
|
||||
public boolean canRepeat() {
|
||||
|
||||
return repeat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRepeatDelay()
|
||||
{
|
||||
public int getRepeatDelay() {
|
||||
|
||||
return repeatDelay;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,8 +2,7 @@ package techreborn.cofhLib.gui;
|
|||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
public class GuiBook extends GuiScreen
|
||||
{
|
||||
public class GuiBook extends GuiScreen {
|
||||
|
||||
protected int mouseX = 0;
|
||||
protected int mouseY = 0;
|
||||
|
|
|
@ -1,125 +1,105 @@
|
|||
package techreborn.cofhLib.gui;
|
||||
|
||||
public class GuiColor extends Number
|
||||
{
|
||||
public class GuiColor extends Number {
|
||||
|
||||
private static final long serialVersionUID = 7024827242888861187L;
|
||||
private final int _color;
|
||||
|
||||
public GuiColor(int argb)
|
||||
{
|
||||
public GuiColor(int argb) {
|
||||
|
||||
_color = argb;
|
||||
}
|
||||
|
||||
public GuiColor(int rgba, Void dummy)
|
||||
{
|
||||
public GuiColor(int rgba, Void dummy) {
|
||||
|
||||
this(rgba >>> 24, rgba >> 16, rgba >> 8, rgba);
|
||||
}
|
||||
|
||||
public GuiColor(byte alpha, int argb)
|
||||
{
|
||||
public GuiColor(byte alpha, int argb) {
|
||||
|
||||
this(argb >> 16, argb >> 8, argb, alpha);
|
||||
}
|
||||
|
||||
public GuiColor(int rgba, byte alpha)
|
||||
{
|
||||
public GuiColor(int rgba, byte alpha) {
|
||||
|
||||
this(rgba >>> 24, rgba >> 16, rgba >> 8, alpha);
|
||||
}
|
||||
|
||||
public GuiColor(int r, int g, int b)
|
||||
{
|
||||
public GuiColor(int r, int g, int b) {
|
||||
|
||||
this(r, g, b, 255);
|
||||
}
|
||||
|
||||
public GuiColor(int r, int g, int b, int a)
|
||||
{
|
||||
public GuiColor(int r, int g, int b, int a) {
|
||||
|
||||
_color = (b & 0xFF) | (g & 0xFF) << 8 | (r & 0xFF) << 16 | (a & 0xFF) << 24;
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
public int getColor() {
|
||||
|
||||
return _color;
|
||||
}
|
||||
|
||||
public int getIntR()
|
||||
{
|
||||
public int getIntR() {
|
||||
|
||||
return (_color >> 16) & 0xFF;
|
||||
}
|
||||
|
||||
public int getIntG()
|
||||
{
|
||||
public int getIntG() {
|
||||
|
||||
return (_color >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
public int getIntB()
|
||||
{
|
||||
public int getIntB() {
|
||||
|
||||
return (_color >> 0) & 0xFF;
|
||||
}
|
||||
|
||||
public int getIntA()
|
||||
{
|
||||
public int getIntA() {
|
||||
|
||||
return (_color >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
public float getFloatR()
|
||||
{
|
||||
public float getFloatR() {
|
||||
|
||||
return getIntR() / 255f;
|
||||
}
|
||||
|
||||
public float getFloatG()
|
||||
{
|
||||
public float getFloatG() {
|
||||
|
||||
return getIntG() / 255f;
|
||||
}
|
||||
|
||||
public float getFloatB()
|
||||
{
|
||||
public float getFloatB() {
|
||||
|
||||
return getIntB() / 255f;
|
||||
}
|
||||
|
||||
public float getFloatA()
|
||||
{
|
||||
public float getFloatA() {
|
||||
|
||||
return getIntA() / 255f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intValue()
|
||||
{
|
||||
public int intValue() {
|
||||
|
||||
return getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long longValue()
|
||||
{
|
||||
public long longValue() {
|
||||
|
||||
return getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue()
|
||||
{
|
||||
public float floatValue() {
|
||||
|
||||
return getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double doubleValue()
|
||||
{
|
||||
public double doubleValue() {
|
||||
|
||||
return getColor();
|
||||
}
|
||||
|
|
|
@ -2,11 +2,10 @@ package techreborn.cofhLib.gui;
|
|||
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
public class GuiProps
|
||||
{
|
||||
public class GuiProps {
|
||||
|
||||
|
||||
public static final String RESOURCE_PREFIX = ModInfo.MOD_ID + ":";
|
||||
public static final String RESOURCE_PREFIX = ModInfo.MOD_ID + ":";
|
||||
|
||||
/* GUI */
|
||||
public static final String PATH_GFX = RESOURCE_PREFIX + "textures/";
|
||||
|
|
|
@ -7,32 +7,27 @@ import techreborn.cofhLib.gui.element.TabBase;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public class TabTracker
|
||||
{
|
||||
public class TabTracker {
|
||||
|
||||
private static Class<? extends TabBase> openedLeftTab;
|
||||
private static Class<? extends TabBase> openedRightTab;
|
||||
|
||||
public static Class<? extends TabBase> getOpenedLeftTab()
|
||||
{
|
||||
public static Class<? extends TabBase> getOpenedLeftTab() {
|
||||
|
||||
return openedLeftTab;
|
||||
}
|
||||
|
||||
public static Class<? extends TabBase> getOpenedRightTab()
|
||||
{
|
||||
public static Class<? extends TabBase> getOpenedRightTab() {
|
||||
|
||||
return openedRightTab;
|
||||
}
|
||||
|
||||
public static void setOpenedLeftTab(Class<? extends TabBase> tabClass)
|
||||
{
|
||||
public static void setOpenedLeftTab(Class<? extends TabBase> tabClass) {
|
||||
|
||||
openedLeftTab = tabClass;
|
||||
}
|
||||
|
||||
public static void setOpenedRightTab(Class<? extends TabBase> tabClass)
|
||||
{
|
||||
public static void setOpenedRightTab(Class<? extends TabBase> tabClass) {
|
||||
|
||||
openedRightTab = tabClass;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,7 @@ import java.util.List;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public abstract class ElementBase
|
||||
{
|
||||
public abstract class ElementBase {
|
||||
|
||||
public GuiBase gui;
|
||||
protected ResourceLocation texture;
|
||||
|
@ -33,16 +32,14 @@ public abstract class ElementBase
|
|||
private boolean visible = true;
|
||||
private boolean enabled = true;
|
||||
|
||||
public ElementBase(GuiBase gui, int posX, int posY)
|
||||
{
|
||||
public ElementBase(GuiBase gui, int posX, int posY) {
|
||||
|
||||
this.gui = gui;
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
}
|
||||
|
||||
public ElementBase(GuiBase gui, int posX, int posY, int width, int height)
|
||||
{
|
||||
public ElementBase(GuiBase gui, int posX, int posY, int width, int height) {
|
||||
|
||||
this.gui = gui;
|
||||
this.posX = posX;
|
||||
|
@ -51,31 +48,27 @@ public abstract class ElementBase
|
|||
this.sizeY = height;
|
||||
}
|
||||
|
||||
public ElementBase setName(String name)
|
||||
{
|
||||
public ElementBase setName(String name) {
|
||||
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setPosition(int posX, int posY)
|
||||
{
|
||||
public ElementBase setPosition(int posX, int posY) {
|
||||
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setSize(int sizeX, int sizeY)
|
||||
{
|
||||
public ElementBase setSize(int sizeX, int sizeY) {
|
||||
|
||||
this.sizeX = sizeX;
|
||||
this.sizeY = sizeY;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setTexture(String texture, int texW, int texH)
|
||||
{
|
||||
public ElementBase setTexture(String texture, int texW, int texH) {
|
||||
|
||||
this.texture = new ResourceLocation(texture);
|
||||
this.texW = texW;
|
||||
|
@ -83,8 +76,7 @@ public abstract class ElementBase
|
|||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setTexture(ResourceLocation texture, int texW, int texH)
|
||||
{
|
||||
public ElementBase setTexture(ResourceLocation texture, int texW, int texH) {
|
||||
|
||||
this.texture = texture;
|
||||
this.texW = texW;
|
||||
|
@ -92,40 +84,34 @@ public abstract class ElementBase
|
|||
return this;
|
||||
}
|
||||
|
||||
public final ElementBase setVisible(boolean visible)
|
||||
{
|
||||
public final ElementBase setVisible(boolean visible) {
|
||||
|
||||
this.visible = visible;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isVisible()
|
||||
{
|
||||
public boolean isVisible() {
|
||||
|
||||
return visible;
|
||||
}
|
||||
|
||||
public final ElementBase setEnabled(boolean enabled)
|
||||
{
|
||||
public final ElementBase setEnabled(boolean enabled) {
|
||||
|
||||
this.enabled = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
public boolean isEnabled() {
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void update(int mouseX, int mouseY)
|
||||
{
|
||||
public void update(int mouseX, int mouseY) {
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -133,19 +119,16 @@ public abstract class ElementBase
|
|||
|
||||
public abstract void drawForeground(int mouseX, int mouseY);
|
||||
|
||||
public void addTooltip(List<String> list)
|
||||
{
|
||||
public void addTooltip(List<String> list) {
|
||||
|
||||
}
|
||||
|
||||
public void drawModalRect(int x, int y, int width, int height, int color)
|
||||
{
|
||||
public void drawModalRect(int x, int y, int width, int height, int color) {
|
||||
|
||||
gui.drawSizedModalRect(x, y, width, height, color);
|
||||
}
|
||||
|
||||
public void drawStencil(int xStart, int yStart, int xEnd, int yEnd, int flag)
|
||||
{
|
||||
public void drawStencil(int xStart, int yStart, int xEnd, int yEnd, int flag) {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glStencilFunc(GL11.GL_ALWAYS, flag, flag);
|
||||
GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
|
||||
|
@ -165,61 +148,51 @@ public abstract class ElementBase
|
|||
GL11.glDepthMask(true);
|
||||
}
|
||||
|
||||
public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height)
|
||||
{
|
||||
public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height) {
|
||||
|
||||
gui.drawSizedTexturedModalRect(x, y, u, v, width, height, texW, texH);
|
||||
}
|
||||
|
||||
public void drawCenteredString(FontRenderer fontRenderer, String text, int x, int y, int color)
|
||||
{
|
||||
public void drawCenteredString(FontRenderer fontRenderer, String text, int x, int y, int color) {
|
||||
|
||||
fontRenderer.drawStringWithShadow(text, x - fontRenderer.getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton)
|
||||
{
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onMouseReleased(int mouseX, int mouseY)
|
||||
{
|
||||
public void onMouseReleased(int mouseX, int mouseY) {
|
||||
|
||||
}
|
||||
|
||||
public boolean onMouseWheel(int mouseX, int mouseY, int movement)
|
||||
{
|
||||
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onKeyTyped(char characterTyped, int keyPressed)
|
||||
{
|
||||
public boolean onKeyTyped(char characterTyped, int keyPressed) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean intersectsWith(int mouseX, int mouseY)
|
||||
{
|
||||
public boolean intersectsWith(int mouseX, int mouseY) {
|
||||
|
||||
return mouseX >= this.posX && mouseX <= this.posX + this.sizeX && mouseY >= this.posY && mouseY <= this.posY + this.sizeY;
|
||||
}
|
||||
|
||||
public final String getName()
|
||||
{
|
||||
public final String getName() {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public final GuiBase getContainerScreen()
|
||||
{
|
||||
public final GuiBase getContainerScreen() {
|
||||
|
||||
return gui;
|
||||
}
|
||||
|
||||
public final FontRenderer getFontRenderer()
|
||||
{
|
||||
public final FontRenderer getFontRenderer() {
|
||||
|
||||
return gui.getFontRenderer();
|
||||
}
|
||||
|
@ -227,8 +200,7 @@ public abstract class ElementBase
|
|||
/**
|
||||
* This method is relative to the GUI's y coordinate
|
||||
*/
|
||||
public final int getPosY()
|
||||
{
|
||||
public final int getPosY() {
|
||||
|
||||
return posY;
|
||||
}
|
||||
|
@ -236,20 +208,17 @@ public abstract class ElementBase
|
|||
/**
|
||||
* This method is relative to the GUI's x coordinate
|
||||
*/
|
||||
public final int getPosX()
|
||||
{
|
||||
public final int getPosX() {
|
||||
|
||||
return posX;
|
||||
}
|
||||
|
||||
public final int getHeight()
|
||||
{
|
||||
public final int getHeight() {
|
||||
|
||||
return sizeY;
|
||||
}
|
||||
|
||||
public final int getWidth()
|
||||
{
|
||||
public final int getWidth() {
|
||||
|
||||
return sizeX;
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ import techreborn.cofhLib.util.helpers.StringHelper;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class ElementButton extends ElementBase
|
||||
{
|
||||
public class ElementButton extends ElementBase {
|
||||
|
||||
int sheetX;
|
||||
int sheetY;
|
||||
|
@ -59,131 +58,105 @@ public class ElementButton extends ElementBase
|
|||
this.disabledY = disabledY;
|
||||
}
|
||||
|
||||
public ElementButton clearToolTip()
|
||||
{
|
||||
public ElementButton clearToolTip() {
|
||||
|
||||
this.tooltip = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementButton setToolTip(String tooltip)
|
||||
{
|
||||
public ElementButton setToolTip(String tooltip) {
|
||||
|
||||
this.tooltip = tooltip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementButton setToolTipLocalized(boolean localized)
|
||||
{
|
||||
public ElementButton setToolTipLocalized(boolean localized) {
|
||||
|
||||
this.tooltipLocalized = localized;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks)
|
||||
{
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
|
||||
RenderHelper.bindTexture(texture);
|
||||
if (isEnabled())
|
||||
{
|
||||
if (intersectsWith(mouseX, mouseY))
|
||||
{
|
||||
if (isEnabled()) {
|
||||
if (intersectsWith(mouseX, mouseY)) {
|
||||
|
||||
drawTexturedModalRect(posX, posY, hoverX, hoverY, sizeX, sizeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
drawTexturedModalRect(posX, posY, sheetX, sheetY, sizeX, sizeY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
drawTexturedModalRect(posX, posY, disabledX, disabledY, sizeX, sizeY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTooltip(List<String> list)
|
||||
{
|
||||
public void addTooltip(List<String> list) {
|
||||
|
||||
if (tooltip != null)
|
||||
{
|
||||
if (tooltipLocalized)
|
||||
{
|
||||
if (tooltip != null) {
|
||||
if (tooltipLocalized) {
|
||||
list.add(tooltip);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
list.add(StringHelper.localize(tooltip));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMousePressed(int x, int y, int mouseButton)
|
||||
{
|
||||
public boolean onMousePressed(int x, int y, int mouseButton) {
|
||||
|
||||
if (isEnabled())
|
||||
{
|
||||
if (isEnabled()) {
|
||||
gui.handleElementButtonClick(getName(), mouseButton);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSheetX(int pos)
|
||||
{
|
||||
public void setSheetX(int pos) {
|
||||
|
||||
sheetX = pos;
|
||||
}
|
||||
|
||||
public void setSheetY(int pos)
|
||||
{
|
||||
public void setSheetY(int pos) {
|
||||
|
||||
sheetY = pos;
|
||||
}
|
||||
|
||||
public void setHoverX(int pos)
|
||||
{
|
||||
public void setHoverX(int pos) {
|
||||
|
||||
hoverX = pos;
|
||||
}
|
||||
|
||||
public void setHoverY(int pos)
|
||||
{
|
||||
public void setHoverY(int pos) {
|
||||
|
||||
hoverY = pos;
|
||||
}
|
||||
|
||||
public ElementButton setDisabledX(int pos)
|
||||
{
|
||||
public ElementButton setDisabledX(int pos) {
|
||||
|
||||
disabledX = pos;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementButton setDisabledY(int pos)
|
||||
{
|
||||
public ElementButton setDisabledY(int pos) {
|
||||
|
||||
disabledY = pos;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setActive()
|
||||
{
|
||||
public void setActive() {
|
||||
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
public void setDisabled()
|
||||
{
|
||||
public void setDisabled() {
|
||||
|
||||
setEnabled(false);
|
||||
}
|
||||
|
|
|
@ -4,38 +4,29 @@ import net.minecraft.util.ResourceLocation;
|
|||
import org.lwjgl.opengl.GL11;
|
||||
import techreborn.cofhLib.gui.GuiProps;
|
||||
|
||||
public abstract class ElementButtonManaged extends ElementBase
|
||||
{
|
||||
public abstract class ElementButtonManaged extends ElementBase {
|
||||
|
||||
public static final ResourceLocation HOVER = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Button_Hover.png");
|
||||
public static final ResourceLocation ENABLED = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Button_Enabled.png");
|
||||
public static final ResourceLocation DISABLED = new ResourceLocation(GuiProps.PATH_ELEMENTS + "Button_Disabled.png");
|
||||
private String _text;
|
||||
|
||||
public ElementButtonManaged(techreborn.cofhLib.gui.GuiBase containerScreen, int posX, int posY, int sizeX, int sizeY, String text)
|
||||
{
|
||||
public ElementButtonManaged(techreborn.cofhLib.gui.GuiBase containerScreen, int posX, int posY, int sizeX, int sizeY, String text) {
|
||||
super(containerScreen, posX, posY, sizeX, sizeY);
|
||||
_text = text;
|
||||
}
|
||||
|
||||
public void setText(String text)
|
||||
{
|
||||
public void setText(String text) {
|
||||
_text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks)
|
||||
{
|
||||
if (!isEnabled())
|
||||
{
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
if (!isEnabled()) {
|
||||
gui.bindTexture(DISABLED);
|
||||
}
|
||||
else if (intersectsWith(mouseX, mouseY))
|
||||
{
|
||||
} else if (intersectsWith(mouseX, mouseY)) {
|
||||
gui.bindTexture(HOVER);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
gui.bindTexture(ENABLED);
|
||||
}
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
@ -46,42 +37,29 @@ public abstract class ElementButtonManaged extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
String text = getFontRenderer().trimStringToWidth(_text, sizeX - 4);
|
||||
drawCenteredString(getFontRenderer(), text, posX + sizeX / 2, posY + (sizeY - 8) / 2, getTextColor(mouseX, mouseY));
|
||||
}
|
||||
|
||||
protected int getTextColor(int mouseX, int mouseY)
|
||||
{
|
||||
if (!isEnabled())
|
||||
{
|
||||
protected int getTextColor(int mouseX, int mouseY) {
|
||||
if (!isEnabled()) {
|
||||
return -6250336;
|
||||
}
|
||||
else if (intersectsWith(mouseX, mouseY))
|
||||
{
|
||||
} else if (intersectsWith(mouseX, mouseY)) {
|
||||
return 16777120;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 14737632;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton)
|
||||
{
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
|
||||
techreborn.cofhLib.gui.GuiBase.playSound("random.click", 1.0F, 1.0F);
|
||||
if (mouseButton == 0)
|
||||
{
|
||||
if (mouseButton == 0) {
|
||||
onClick();
|
||||
}
|
||||
else if (mouseButton == 1)
|
||||
{
|
||||
} else if (mouseButton == 1) {
|
||||
onRightClick();
|
||||
}
|
||||
else if (mouseButton == 2)
|
||||
{
|
||||
} else if (mouseButton == 2) {
|
||||
onMiddleClick();
|
||||
}
|
||||
return true;
|
||||
|
@ -89,13 +67,11 @@ public abstract class ElementButtonManaged extends ElementBase
|
|||
|
||||
public abstract void onClick();
|
||||
|
||||
public void onRightClick()
|
||||
{
|
||||
public void onRightClick() {
|
||||
|
||||
}
|
||||
|
||||
public void onMiddleClick()
|
||||
{
|
||||
public void onMiddleClick() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,39 +3,32 @@ package techreborn.cofhLib.gui.element;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ElementButtonOption extends ElementButtonManaged
|
||||
{
|
||||
public abstract class ElementButtonOption extends ElementButtonManaged {
|
||||
|
||||
private final Map<Integer, String> _values = new HashMap<Integer, String>();
|
||||
private int _currentValue = 0;
|
||||
private int _maxValue;
|
||||
|
||||
public ElementButtonOption(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height)
|
||||
{
|
||||
public ElementButtonOption(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height) {
|
||||
|
||||
super(containerScreen, x, y, width, height, "");
|
||||
}
|
||||
|
||||
public void setValue(int value, String label)
|
||||
{
|
||||
public void setValue(int value, String label) {
|
||||
|
||||
_values.put(value, label);
|
||||
if (value > _maxValue)
|
||||
{
|
||||
if (value > _maxValue) {
|
||||
_maxValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick()
|
||||
{
|
||||
public void onClick() {
|
||||
|
||||
int nextValue = _currentValue;
|
||||
do
|
||||
{
|
||||
do {
|
||||
nextValue++;
|
||||
if (nextValue > _maxValue)
|
||||
{
|
||||
if (nextValue > _maxValue) {
|
||||
nextValue = 0;
|
||||
}
|
||||
} while (_values.get(nextValue) == null);
|
||||
|
@ -43,38 +36,32 @@ public abstract class ElementButtonOption extends ElementButtonManaged
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRightClick()
|
||||
{
|
||||
public void onRightClick() {
|
||||
|
||||
int nextValue = _currentValue;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
nextValue--;
|
||||
if (nextValue < 0)
|
||||
{
|
||||
if (nextValue < 0) {
|
||||
nextValue = _maxValue;
|
||||
}
|
||||
} while (_values.get(nextValue) == null);
|
||||
setSelectedIndex(nextValue);
|
||||
}
|
||||
|
||||
public int getSelectedIndex()
|
||||
{
|
||||
public int getSelectedIndex() {
|
||||
|
||||
return _currentValue;
|
||||
}
|
||||
|
||||
public void setSelectedIndex(int index)
|
||||
{
|
||||
public void setSelectedIndex(int index) {
|
||||
|
||||
_currentValue = index;
|
||||
setText(_values.get(_currentValue));
|
||||
onValueChanged(_currentValue, _values.get(_currentValue));
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
public String getValue() {
|
||||
|
||||
return _values.get(_currentValue);
|
||||
}
|
||||
|
|
|
@ -2,52 +2,44 @@ package techreborn.cofhLib.gui.element;
|
|||
|
||||
import techreborn.cofhLib.render.RenderHelper;
|
||||
|
||||
public class ElementDualScaled extends ElementBase
|
||||
{
|
||||
public class ElementDualScaled extends ElementBase {
|
||||
|
||||
public int quantity;
|
||||
public int mode;
|
||||
public boolean background = true;
|
||||
|
||||
public ElementDualScaled(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY)
|
||||
{
|
||||
public ElementDualScaled(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY) {
|
||||
|
||||
super(gui, posX, posY);
|
||||
}
|
||||
|
||||
public ElementDualScaled setBackground(boolean background)
|
||||
{
|
||||
public ElementDualScaled setBackground(boolean background) {
|
||||
|
||||
this.background = background;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementDualScaled setMode(int mode)
|
||||
{
|
||||
public ElementDualScaled setMode(int mode) {
|
||||
|
||||
this.mode = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementDualScaled setQuantity(int quantity)
|
||||
{
|
||||
public ElementDualScaled setQuantity(int quantity) {
|
||||
|
||||
this.quantity = quantity;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks)
|
||||
{
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
|
||||
RenderHelper.bindTexture(texture);
|
||||
|
||||
if (background)
|
||||
{
|
||||
if (background) {
|
||||
drawTexturedModalRect(posX, posY, 0, 0, sizeX, sizeY);
|
||||
}
|
||||
switch (mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case 0:
|
||||
// vertical bottom -> top
|
||||
drawTexturedModalRect(posX, posY + sizeY - quantity, sizeX, sizeY - quantity, sizeX, quantity);
|
||||
|
@ -63,8 +55,7 @@ public class ElementDualScaled extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,334 +9,332 @@ import java.util.Collection;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glTranslated;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class ElementListBox extends ElementBase {
|
||||
|
||||
public int borderColor = new GuiColor(120, 120, 120, 255).getColor();
|
||||
public int backgroundColor = new GuiColor(0, 0, 0, 255).getColor();
|
||||
public int selectedLineColor = new GuiColor(0, 0, 0, 255).getColor();
|
||||
public int textColor = new GuiColor(150, 150, 150, 255).getColor();
|
||||
public int selectedTextColor = new GuiColor(255, 255, 255, 255).getColor();
|
||||
public int borderColor = new GuiColor(120, 120, 120, 255).getColor();
|
||||
public int backgroundColor = new GuiColor(0, 0, 0, 255).getColor();
|
||||
public int selectedLineColor = new GuiColor(0, 0, 0, 255).getColor();
|
||||
public int textColor = new GuiColor(150, 150, 150, 255).getColor();
|
||||
public int selectedTextColor = new GuiColor(255, 255, 255, 255).getColor();
|
||||
|
||||
private final int _marginTop = 2;
|
||||
private final int _marginLeft = 2;
|
||||
private final int _marginRight = 2;
|
||||
private final int _marginBottom = 2;
|
||||
private final int _marginTop = 2;
|
||||
private final int _marginLeft = 2;
|
||||
private final int _marginRight = 2;
|
||||
private final int _marginBottom = 2;
|
||||
|
||||
public List<IListBoxElement> _elements = new LinkedList<IListBoxElement>();
|
||||
public List<IListBoxElement> _elements = new LinkedList<IListBoxElement>();
|
||||
|
||||
private int _firstIndexDisplayed;
|
||||
private int _selectedIndex;
|
||||
private int scrollHoriz;
|
||||
private int _firstIndexDisplayed;
|
||||
private int _selectedIndex;
|
||||
private int scrollHoriz;
|
||||
|
||||
public ElementListBox(GuiBase containerScreen, int x, int y, int width, int height) {
|
||||
public ElementListBox(GuiBase containerScreen, int x, int y, int width, int height) {
|
||||
|
||||
super(containerScreen, x, y, width, height);
|
||||
}
|
||||
super(containerScreen, x, y, width, height);
|
||||
}
|
||||
|
||||
public void add(IListBoxElement element) {
|
||||
public void add(IListBoxElement element) {
|
||||
|
||||
_elements.add(element);
|
||||
}
|
||||
_elements.add(element);
|
||||
}
|
||||
|
||||
public void add(Collection<? extends IListBoxElement> elements) {
|
||||
public void add(Collection<? extends IListBoxElement> elements) {
|
||||
|
||||
_elements.addAll(elements);
|
||||
}
|
||||
_elements.addAll(elements);
|
||||
}
|
||||
|
||||
public void remove(IListBoxElement element) {
|
||||
public void remove(IListBoxElement element) {
|
||||
|
||||
_elements.remove(element);
|
||||
}
|
||||
_elements.remove(element);
|
||||
}
|
||||
|
||||
public void removeAt(int index) {
|
||||
public void removeAt(int index) {
|
||||
|
||||
_elements.remove(index);
|
||||
}
|
||||
_elements.remove(index);
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
public void removeAll() {
|
||||
|
||||
_elements.clear();
|
||||
}
|
||||
_elements.clear();
|
||||
}
|
||||
|
||||
public int getInternalWidth() {
|
||||
public int getInternalWidth() {
|
||||
|
||||
int width = 0;
|
||||
for (int i = 0; i < _elements.size(); i++) {
|
||||
width = Math.max(_elements.get(i).getWidth(), width);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
int width = 0;
|
||||
for (int i = 0; i < _elements.size(); i++) {
|
||||
width = Math.max(_elements.get(i).getWidth(), width);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getInternalHeight() {
|
||||
public int getInternalHeight() {
|
||||
|
||||
int height = 0;
|
||||
for (int i = 0; i < _elements.size(); i++) {
|
||||
height += _elements.get(i).getHeight();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
int height = 0;
|
||||
for (int i = 0; i < _elements.size(); i++) {
|
||||
height += _elements.get(i).getHeight();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getContentWidth() {
|
||||
public int getContentWidth() {
|
||||
|
||||
return sizeX - _marginLeft - _marginRight;
|
||||
}
|
||||
return sizeX - _marginLeft - _marginRight;
|
||||
}
|
||||
|
||||
public int getContentHeight() {
|
||||
public int getContentHeight() {
|
||||
|
||||
return sizeY - _marginTop - _marginBottom;
|
||||
}
|
||||
return sizeY - _marginTop - _marginBottom;
|
||||
}
|
||||
|
||||
public int getContentTop() {
|
||||
public int getContentTop() {
|
||||
|
||||
return posY + _marginTop;
|
||||
}
|
||||
return posY + _marginTop;
|
||||
}
|
||||
|
||||
public int getContentLeft() {
|
||||
public int getContentLeft() {
|
||||
|
||||
return posX + _marginLeft;
|
||||
}
|
||||
return posX + _marginLeft;
|
||||
}
|
||||
|
||||
public final int getContentBottom() {
|
||||
public final int getContentBottom() {
|
||||
|
||||
return getContentTop() + getContentHeight();
|
||||
}
|
||||
return getContentTop() + getContentHeight();
|
||||
}
|
||||
|
||||
public final int getContentRight() {
|
||||
public final int getContentRight() {
|
||||
|
||||
return getContentLeft() + getContentWidth();
|
||||
}
|
||||
return getContentLeft() + getContentWidth();
|
||||
}
|
||||
|
||||
public ElementListBox setTextColor(Number textColor, Number selectedTextColor) {
|
||||
public ElementListBox setTextColor(Number textColor, Number selectedTextColor) {
|
||||
|
||||
if (textColor != null) {
|
||||
this.textColor = textColor.intValue();
|
||||
}
|
||||
if (selectedTextColor != null) {
|
||||
this.selectedTextColor = selectedTextColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
if (textColor != null) {
|
||||
this.textColor = textColor.intValue();
|
||||
}
|
||||
if (selectedTextColor != null) {
|
||||
this.selectedTextColor = selectedTextColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementListBox setSelectionColor(Number selectedLineColor) {
|
||||
public ElementListBox setSelectionColor(Number selectedLineColor) {
|
||||
|
||||
if (selectedLineColor != null) {
|
||||
this.selectedLineColor = selectedLineColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementListBox setBackgroundColor(Number backgroundColor, Number borderColor) {
|
||||
|
||||
if (backgroundColor != null) {
|
||||
this.backgroundColor = backgroundColor.intValue();
|
||||
}
|
||||
if (borderColor != null) {
|
||||
this.borderColor = borderColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
|
||||
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
|
||||
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
int heightDrawn = 0;
|
||||
int nextElement = _firstIndexDisplayed;
|
||||
|
||||
glPushMatrix();
|
||||
//glDisable(GL_LIGHTING);
|
||||
|
||||
//glEnable(GL_STENCIL_TEST);
|
||||
//glClear(GL_STENCIL_BUFFER_BIT);
|
||||
//drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1);
|
||||
|
||||
glTranslated(-scrollHoriz, 0, 0);
|
||||
|
||||
int e = _elements.size();
|
||||
while (nextElement < e && heightDrawn <= getContentHeight()) {
|
||||
if (nextElement == _selectedIndex) {
|
||||
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor);
|
||||
} else {
|
||||
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, backgroundColor, textColor);
|
||||
}
|
||||
heightDrawn += _elements.get(nextElement).getHeight();
|
||||
nextElement++;
|
||||
}
|
||||
//glDisable(GL_STENCIL_TEST);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
int heightChecked = 0;
|
||||
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
|
||||
if (heightChecked > getContentHeight()) {
|
||||
break;
|
||||
}
|
||||
int elementHeight = _elements.get(i).getHeight();
|
||||
if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY) {
|
||||
setSelectedIndex(i);
|
||||
onElementClicked(_elements.get(i));
|
||||
break;
|
||||
}
|
||||
heightChecked += elementHeight;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
|
||||
|
||||
if (StringHelper.isControlKeyDown()) {
|
||||
if (movement > 0) {
|
||||
scrollLeft();
|
||||
} else if (movement < 0) {
|
||||
scrollRight();
|
||||
}
|
||||
} else {
|
||||
if (movement > 0) {
|
||||
scrollUp();
|
||||
} else if (movement < 0) {
|
||||
scrollDown();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void scrollDown() {
|
||||
|
||||
int heightDisplayed = 0;
|
||||
int elementsDisplayed = 0;
|
||||
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
|
||||
if (heightDisplayed + _elements.get(i).getHeight() > sizeY) {
|
||||
break;
|
||||
}
|
||||
heightDisplayed += _elements.get(i).getHeight();
|
||||
elementsDisplayed++;
|
||||
}
|
||||
if (_firstIndexDisplayed + elementsDisplayed < _elements.size()) {
|
||||
_firstIndexDisplayed++;
|
||||
}
|
||||
onScrollV(_firstIndexDisplayed);
|
||||
}
|
||||
|
||||
public void scrollUp() {
|
||||
|
||||
if (_firstIndexDisplayed > 0) {
|
||||
_firstIndexDisplayed--;
|
||||
}
|
||||
onScrollV(_firstIndexDisplayed);
|
||||
}
|
||||
|
||||
public void scrollLeft() {
|
||||
|
||||
scrollHoriz = Math.max(scrollHoriz - 15, 0);
|
||||
onScrollH(scrollHoriz);
|
||||
}
|
||||
|
||||
public void scrollRight() {
|
||||
|
||||
scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH());
|
||||
onScrollH(scrollHoriz);
|
||||
}
|
||||
|
||||
public int getLastScrollPosition() {
|
||||
|
||||
int position = _elements.size() - 1;
|
||||
int heightUsed = _elements.get(position).getHeight();
|
||||
|
||||
while (position > 0 && heightUsed < sizeY) {
|
||||
position--;
|
||||
heightUsed += _elements.get(position).getHeight();
|
||||
}
|
||||
return position + 1;
|
||||
}
|
||||
|
||||
public int getLastScrollPositionH() {
|
||||
|
||||
return Math.max(getInternalWidth() - getContentWidth(), 0);
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
|
||||
return _selectedIndex;
|
||||
}
|
||||
if (selectedLineColor != null) {
|
||||
this.selectedLineColor = selectedLineColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementListBox setBackgroundColor(Number backgroundColor, Number borderColor) {
|
||||
|
||||
if (backgroundColor != null) {
|
||||
this.backgroundColor = backgroundColor.intValue();
|
||||
}
|
||||
if (borderColor != null) {
|
||||
this.borderColor = borderColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
|
||||
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
|
||||
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
int heightDrawn = 0;
|
||||
int nextElement = _firstIndexDisplayed;
|
||||
|
||||
glPushMatrix();
|
||||
//glDisable(GL_LIGHTING);
|
||||
|
||||
//glEnable(GL_STENCIL_TEST);
|
||||
//glClear(GL_STENCIL_BUFFER_BIT);
|
||||
//drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1);
|
||||
|
||||
glTranslated(-scrollHoriz, 0, 0);
|
||||
|
||||
int e = _elements.size();
|
||||
while (nextElement < e && heightDrawn <= getContentHeight()) {
|
||||
if (nextElement == _selectedIndex) {
|
||||
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor);
|
||||
} else {
|
||||
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, backgroundColor, textColor);
|
||||
}
|
||||
heightDrawn += _elements.get(nextElement).getHeight();
|
||||
nextElement++;
|
||||
}
|
||||
//glDisable(GL_STENCIL_TEST);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
int heightChecked = 0;
|
||||
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
|
||||
if (heightChecked > getContentHeight()) {
|
||||
break;
|
||||
}
|
||||
int elementHeight = _elements.get(i).getHeight();
|
||||
if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY) {
|
||||
setSelectedIndex(i);
|
||||
onElementClicked(_elements.get(i));
|
||||
break;
|
||||
}
|
||||
heightChecked += elementHeight;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
|
||||
|
||||
if (StringHelper.isControlKeyDown()) {
|
||||
if (movement > 0) {
|
||||
scrollLeft();
|
||||
} else if (movement < 0) {
|
||||
scrollRight();
|
||||
}
|
||||
} else {
|
||||
if (movement > 0) {
|
||||
scrollUp();
|
||||
} else if (movement < 0) {
|
||||
scrollDown();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void scrollDown() {
|
||||
|
||||
int heightDisplayed = 0;
|
||||
int elementsDisplayed = 0;
|
||||
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
|
||||
if (heightDisplayed + _elements.get(i).getHeight() > sizeY) {
|
||||
break;
|
||||
}
|
||||
heightDisplayed += _elements.get(i).getHeight();
|
||||
elementsDisplayed++;
|
||||
}
|
||||
if (_firstIndexDisplayed + elementsDisplayed < _elements.size()) {
|
||||
_firstIndexDisplayed++;
|
||||
}
|
||||
onScrollV(_firstIndexDisplayed);
|
||||
}
|
||||
|
||||
public void scrollUp() {
|
||||
|
||||
if (_firstIndexDisplayed > 0) {
|
||||
_firstIndexDisplayed--;
|
||||
}
|
||||
onScrollV(_firstIndexDisplayed);
|
||||
}
|
||||
|
||||
public void scrollLeft() {
|
||||
|
||||
scrollHoriz = Math.max(scrollHoriz - 15, 0);
|
||||
onScrollH(scrollHoriz);
|
||||
}
|
||||
|
||||
public void scrollRight() {
|
||||
|
||||
scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH());
|
||||
onScrollH(scrollHoriz);
|
||||
}
|
||||
|
||||
public int getLastScrollPosition() {
|
||||
|
||||
int position = _elements.size() - 1;
|
||||
int heightUsed = _elements.get(position).getHeight();
|
||||
|
||||
while (position > 0 && heightUsed < sizeY) {
|
||||
position--;
|
||||
heightUsed += _elements.get(position).getHeight();
|
||||
}
|
||||
return position + 1;
|
||||
}
|
||||
|
||||
public int getLastScrollPositionH() {
|
||||
|
||||
return Math.max(getInternalWidth() - getContentWidth(), 0);
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
|
||||
return _selectedIndex;
|
||||
}
|
||||
|
||||
public int getIndexOf(Object value) {
|
||||
public int getIndexOf(Object value) {
|
||||
|
||||
for (int i = 0; i < _elements.size(); i++) {
|
||||
if (_elements.get(i).getValue().equals(value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < _elements.size(); i++) {
|
||||
if (_elements.get(i).getValue().equals(value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public IListBoxElement getSelectedElement() {
|
||||
public IListBoxElement getSelectedElement() {
|
||||
|
||||
if (_selectedIndex == -1 || _selectedIndex == _elements.size()) {
|
||||
return null;
|
||||
}
|
||||
return _elements.get(_selectedIndex);
|
||||
}
|
||||
if (_selectedIndex == -1 || _selectedIndex == _elements.size()) {
|
||||
return null;
|
||||
}
|
||||
return _elements.get(_selectedIndex);
|
||||
}
|
||||
|
||||
public void setSelectedIndex(int index) {
|
||||
public void setSelectedIndex(int index) {
|
||||
|
||||
if (index >= -1 && index != _selectedIndex && index < _elements.size()) {
|
||||
_selectedIndex = index;
|
||||
onSelectionChanged(_selectedIndex, getSelectedElement());
|
||||
}
|
||||
}
|
||||
if (index >= -1 && index != _selectedIndex && index < _elements.size()) {
|
||||
_selectedIndex = index;
|
||||
onSelectionChanged(_selectedIndex, getSelectedElement());
|
||||
}
|
||||
}
|
||||
|
||||
public IListBoxElement getElement(int index) {
|
||||
public IListBoxElement getElement(int index) {
|
||||
|
||||
return _elements.get(index);
|
||||
}
|
||||
return _elements.get(index);
|
||||
}
|
||||
|
||||
public int getElementCount() {
|
||||
public int getElementCount() {
|
||||
|
||||
return _elements.size();
|
||||
}
|
||||
return _elements.size();
|
||||
}
|
||||
|
||||
public void scrollToV(int index) {
|
||||
public void scrollToV(int index) {
|
||||
|
||||
if (index >= 0 && index < _elements.size()) {
|
||||
_firstIndexDisplayed = index;
|
||||
}
|
||||
}
|
||||
if (index >= 0 && index < _elements.size()) {
|
||||
_firstIndexDisplayed = index;
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToH(int index) {
|
||||
public void scrollToH(int index) {
|
||||
|
||||
if (index >= 0 && index <= getLastScrollPositionH()) {
|
||||
scrollHoriz = index;
|
||||
}
|
||||
}
|
||||
if (index >= 0 && index <= getLastScrollPositionH()) {
|
||||
scrollHoriz = index;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onElementClicked(IListBoxElement element) {
|
||||
protected void onElementClicked(IListBoxElement element) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void onScrollV(int newStartIndex) {
|
||||
protected void onScrollV(int newStartIndex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void onScrollH(int newStartIndex) {
|
||||
protected void onScrollH(int newStartIndex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSelectionChanged(int newIndex, IListBoxElement newElement) {
|
||||
protected void onSelectionChanged(int newIndex, IListBoxElement newElement) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,20 +7,17 @@ import techreborn.cofhLib.render.RenderHelper;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public class ElementSimple extends ElementBase
|
||||
{
|
||||
public class ElementSimple extends ElementBase {
|
||||
|
||||
int texU = 0;
|
||||
int texV = 0;
|
||||
|
||||
public ElementSimple(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY)
|
||||
{
|
||||
public ElementSimple(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY) {
|
||||
|
||||
super(gui, posX, posY);
|
||||
}
|
||||
|
||||
public ElementSimple setTextureOffsets(int u, int v)
|
||||
{
|
||||
public ElementSimple setTextureOffsets(int u, int v) {
|
||||
|
||||
texU = u;
|
||||
texV = v;
|
||||
|
@ -28,16 +25,14 @@ public class ElementSimple extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks)
|
||||
{
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
|
||||
RenderHelper.bindTexture(texture);
|
||||
drawTexturedModalRect(posX, posY, texU, texV, sizeX, sizeY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ import org.lwjgl.opengl.GL11;
|
|||
import techreborn.cofhLib.gui.GuiBase;
|
||||
import techreborn.cofhLib.gui.GuiColor;
|
||||
|
||||
public abstract class ElementSlider extends ElementBase
|
||||
{
|
||||
public abstract class ElementSlider extends ElementBase {
|
||||
protected int _value;
|
||||
protected int _valueMin;
|
||||
protected int _valueMax;
|
||||
|
@ -23,103 +22,84 @@ public abstract class ElementSlider extends ElementBase
|
|||
protected ResourceLocation hoverTexture = Textures.Gui.Elements.BUTTON_HOVER;
|
||||
protected ResourceLocation disabledTexture = Textures.Gui.Elements.BUTTON_DISABLED;
|
||||
|
||||
protected ElementSlider(GuiBase containerScreen, int x, int y, int width, int height, int maxValue)
|
||||
{
|
||||
protected ElementSlider(GuiBase containerScreen, int x, int y, int width, int height, int maxValue) {
|
||||
this(containerScreen, x, y, width, height, maxValue, 0);
|
||||
}
|
||||
|
||||
protected ElementSlider(GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue)
|
||||
{
|
||||
protected ElementSlider(GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue) {
|
||||
super(containerScreen, x, y, width, height);
|
||||
_valueMax = maxValue;
|
||||
_valueMin = minValue;
|
||||
}
|
||||
|
||||
protected ElementSlider(GuiBase containerScreen, String elementName, int x, int y, int width, int height, int maxValue, int minValue)
|
||||
{
|
||||
protected ElementSlider(GuiBase containerScreen, String elementName, int x, int y, int width, int height, int maxValue, int minValue) {
|
||||
super(containerScreen, x, y, width, height);
|
||||
this.name = elementName;
|
||||
_valueMax = maxValue;
|
||||
_valueMin = minValue;
|
||||
}
|
||||
|
||||
public ElementSlider setColor(int backgroundColor, int borderColor)
|
||||
{
|
||||
public ElementSlider setColor(int backgroundColor, int borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
this.backgroundColor = backgroundColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementSlider setSliderSize(int width, int height)
|
||||
{
|
||||
public ElementSlider setSliderSize(int width, int height) {
|
||||
_sliderWidth = width;
|
||||
_sliderHeight = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
public int getValue() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
public int getValueMin()
|
||||
{
|
||||
public int getValueMin() {
|
||||
return this._valueMin;
|
||||
}
|
||||
|
||||
public int getValueMax()
|
||||
{
|
||||
public int getValueMax() {
|
||||
return this._valueMax;
|
||||
}
|
||||
|
||||
public ElementSlider setValue(int value)
|
||||
{
|
||||
public ElementSlider setValue(int value) {
|
||||
value = Math.max(_valueMin, Math.min(_valueMax, value));
|
||||
if (value != _value)
|
||||
{
|
||||
if (value != _value) {
|
||||
_value = value;
|
||||
onValueChanged(_value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementSlider setMinValue(int minValue)
|
||||
{
|
||||
public ElementSlider setMinValue(int minValue) {
|
||||
_valueMin = minValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementSlider setMaxValue(int maxValue)
|
||||
{
|
||||
public ElementSlider setMaxValue(int maxValue) {
|
||||
_valueMax = maxValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks)
|
||||
{
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
|
||||
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
protected void drawSlider(int mouseX, int mouseY, int sliderX, int sliderY)
|
||||
{
|
||||
protected void drawSlider(int mouseX, int mouseY, int sliderX, int sliderY) {
|
||||
int sliderMidX = _sliderWidth / 2;
|
||||
int sliderMidY = _sliderHeight / 2;
|
||||
int sliderEndX = _sliderWidth - sliderMidX;
|
||||
int sliderEndY = _sliderHeight - sliderMidY;
|
||||
|
||||
if (!isEnabled())
|
||||
{
|
||||
if (!isEnabled()) {
|
||||
gui.bindTexture(disabledTexture);
|
||||
}
|
||||
else if (isHovering(mouseX, mouseY))
|
||||
{
|
||||
} else if (isHovering(mouseX, mouseY)) {
|
||||
gui.bindTexture(hoverTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
gui.bindTexture(enabledTexture);
|
||||
}
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
@ -130,8 +110,7 @@ public abstract class ElementSlider extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
int sliderX = posX + getSliderX();
|
||||
int sliderY = posY + getSliderY();
|
||||
|
||||
|
@ -139,44 +118,36 @@ public abstract class ElementSlider extends ElementBase
|
|||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
protected boolean isHovering(int x, int y)
|
||||
{
|
||||
protected boolean isHovering(int x, int y) {
|
||||
return intersectsWith(x, y);
|
||||
}
|
||||
|
||||
public int getSliderX()
|
||||
{
|
||||
public int getSliderX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getSliderY()
|
||||
{
|
||||
public int getSliderY() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton)
|
||||
{
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
|
||||
_isDragging = mouseButton == 0;
|
||||
update(mouseX, mouseY);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseReleased(int mouseX, int mouseY)
|
||||
{
|
||||
if (_isDragging)
|
||||
{
|
||||
public void onMouseReleased(int mouseX, int mouseY) {
|
||||
if (_isDragging) {
|
||||
onStopDragging();
|
||||
}
|
||||
_isDragging = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int mouseX, int mouseY)
|
||||
{
|
||||
if (_isDragging)
|
||||
{
|
||||
public void update(int mouseX, int mouseY) {
|
||||
if (_isDragging) {
|
||||
dragSlider(mouseX - posX, mouseY - posY);
|
||||
}
|
||||
}
|
||||
|
@ -184,41 +155,32 @@ public abstract class ElementSlider extends ElementBase
|
|||
protected abstract void dragSlider(int x, int y);
|
||||
|
||||
@Override
|
||||
public boolean onMouseWheel(int mouseX, int mouseY, int movement)
|
||||
{
|
||||
if (movement > 0)
|
||||
{
|
||||
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
|
||||
if (movement > 0) {
|
||||
setValue(_value - 1);
|
||||
}
|
||||
else if (movement < 0)
|
||||
{
|
||||
} else if (movement < 0) {
|
||||
setValue(_value + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onValueChanged(int value)
|
||||
{
|
||||
public void onValueChanged(int value) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void onStopDragging()
|
||||
{
|
||||
public void onStopDragging() {
|
||||
return;
|
||||
}
|
||||
|
||||
public void setEnabledTexture(ResourceLocation enabledTexture)
|
||||
{
|
||||
public void setEnabledTexture(ResourceLocation enabledTexture) {
|
||||
this.enabledTexture = enabledTexture;
|
||||
}
|
||||
|
||||
public void setDisabledTexture(ResourceLocation disabledTexture)
|
||||
{
|
||||
public void setDisabledTexture(ResourceLocation disabledTexture) {
|
||||
this.disabledTexture = disabledTexture;
|
||||
}
|
||||
|
||||
public void setHoverTexture(ResourceLocation hoverTexture)
|
||||
{
|
||||
public void setHoverTexture(ResourceLocation hoverTexture) {
|
||||
this.hoverTexture = hoverTexture;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,15 +9,10 @@ import techreborn.cofhLib.gui.GuiBase;
|
|||
import techreborn.cofhLib.gui.GuiColor;
|
||||
import techreborn.cofhLib.util.helpers.MathHelper;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_STENCIL_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_STENCIL_TEST;
|
||||
import static org.lwjgl.opengl.GL11.glClear;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
|
||||
public class ElementTextField extends ElementBase
|
||||
{
|
||||
public class ElementTextField extends ElementBase {
|
||||
public int borderColor = new GuiColor(55, 55, 55).getColor();
|
||||
public int backgroundColor = new GuiColor(139, 139, 139).getColor();
|
||||
public int disabledColor = new GuiColor(198, 198, 198).getColor();
|
||||
|
@ -45,70 +40,58 @@ public class ElementTextField extends ElementBase
|
|||
|
||||
protected boolean enableStencil = false;
|
||||
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, int width, int height)
|
||||
{
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, int width, int height) {
|
||||
this(gui, posX, posY, width, height, (short) 32);
|
||||
}
|
||||
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, int width, int height, short limit)
|
||||
{
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, int width, int height, short limit) {
|
||||
super(gui, posX, posY, width, height);
|
||||
setPadding(1, 1, 1, 1);
|
||||
setMaxLength(limit);
|
||||
}
|
||||
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, String name, int width, int height)
|
||||
{
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, String name, int width, int height) {
|
||||
this(gui, posX, posY, name, width, height, (short) 32);
|
||||
}
|
||||
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, String name, int width, int height, short limit)
|
||||
{
|
||||
public ElementTextField(GuiBase gui, int posX, int posY, String name, int width, int height, short limit) {
|
||||
super(gui, posX, posY, width, height);
|
||||
setName(name);
|
||||
setPadding(1, 1, 1, 1);
|
||||
setMaxLength(limit);
|
||||
}
|
||||
|
||||
public ElementTextField setTextColor(Number textColor, Number selectedTextColor)
|
||||
{
|
||||
if (textColor != null)
|
||||
{
|
||||
public ElementTextField setTextColor(Number textColor, Number selectedTextColor) {
|
||||
if (textColor != null) {
|
||||
this.textColor = textColor.intValue();
|
||||
}
|
||||
if (selectedTextColor != null)
|
||||
{
|
||||
if (selectedTextColor != null) {
|
||||
this.selectedTextColor = selectedTextColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setPaddingLeft(int paddingLeft)
|
||||
{
|
||||
public ElementTextField setPaddingLeft(int paddingLeft) {
|
||||
this.paddingLeft = paddingLeft;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setPaddingRight(int paddingRight)
|
||||
{
|
||||
public ElementTextField setPaddingRight(int paddingRight) {
|
||||
this.paddingRight = paddingRight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setPaddingTop(int paddingTop)
|
||||
{
|
||||
public ElementTextField setPaddingTop(int paddingTop) {
|
||||
this.paddingTop = paddingTop;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setPaddingBottom(int paddingBottom)
|
||||
{
|
||||
public ElementTextField setPaddingBottom(int paddingBottom) {
|
||||
this.paddingBottom = paddingBottom;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setPadding(int paddingTop, int paddingRight, int paddingBottom, int paddingLeft)
|
||||
{
|
||||
public ElementTextField setPadding(int paddingTop, int paddingRight, int paddingBottom, int paddingLeft) {
|
||||
this.paddingTop = paddingTop;
|
||||
this.paddingRight = paddingRight;
|
||||
this.paddingBottom = paddingBottom;
|
||||
|
@ -116,133 +99,107 @@ public class ElementTextField extends ElementBase
|
|||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setSelectionColor(Number selectedLineColor, Number defaultCaretColor)
|
||||
{
|
||||
if (selectedLineColor != null)
|
||||
{
|
||||
public ElementTextField setSelectionColor(Number selectedLineColor, Number defaultCaretColor) {
|
||||
if (selectedLineColor != null) {
|
||||
this.selectedLineColor = selectedLineColor.intValue();
|
||||
}
|
||||
if (defaultCaretColor != null)
|
||||
{
|
||||
if (defaultCaretColor != null) {
|
||||
this.defaultCaretColor = defaultCaretColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setBackgroundColor(Number backgroundColor, Number disabledColor, Number borderColor)
|
||||
{
|
||||
if (backgroundColor != null)
|
||||
{
|
||||
public ElementTextField setBackgroundColor(Number backgroundColor, Number disabledColor, Number borderColor) {
|
||||
if (backgroundColor != null) {
|
||||
this.backgroundColor = backgroundColor.intValue();
|
||||
}
|
||||
if (disabledColor != null)
|
||||
{
|
||||
if (disabledColor != null) {
|
||||
this.disabledColor = disabledColor.intValue();
|
||||
}
|
||||
if (borderColor != null)
|
||||
{
|
||||
if (borderColor != null) {
|
||||
this.borderColor = borderColor.intValue();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setFocusable(boolean focusable)
|
||||
{
|
||||
public ElementTextField setFocusable(boolean focusable) {
|
||||
canFocusChange = focusable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setFocused(boolean focused)
|
||||
{
|
||||
if (canFocusChange)
|
||||
{
|
||||
public ElementTextField setFocused(boolean focused) {
|
||||
if (canFocusChange) {
|
||||
isFocused = focused;
|
||||
caretCounter = 0;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setText(String text)
|
||||
{
|
||||
public ElementTextField setText(String text) {
|
||||
selectionStart = 0;
|
||||
selectionEnd = textLength;
|
||||
writeText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementTextField setMaxLength(short limit)
|
||||
{
|
||||
public ElementTextField setMaxLength(short limit) {
|
||||
char[] oldText = text;
|
||||
text = new char[limit];
|
||||
textLength = Math.min(limit, textLength);
|
||||
if (oldText != null)
|
||||
{
|
||||
if (oldText != null) {
|
||||
System.arraycopy(oldText, 0, text, 0, textLength);
|
||||
}
|
||||
findRenderStart();
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMaxStringLength()
|
||||
{
|
||||
public int getMaxStringLength() {
|
||||
return text.length;
|
||||
}
|
||||
|
||||
public boolean isFocused()
|
||||
{
|
||||
public boolean isFocused() {
|
||||
return isEnabled() && isFocused;
|
||||
}
|
||||
|
||||
public boolean isFocusable()
|
||||
{
|
||||
public boolean isFocusable() {
|
||||
return canFocusChange;
|
||||
}
|
||||
|
||||
public int getContentWidth()
|
||||
{
|
||||
public int getContentWidth() {
|
||||
FontRenderer font = getFontRenderer();
|
||||
int width = 0;
|
||||
for (int i = 0; i < textLength; ++i)
|
||||
{
|
||||
for (int i = 0; i < textLength; ++i) {
|
||||
width += font.getCharWidth(text[i]);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getPaddingLeft()
|
||||
{
|
||||
public int getPaddingLeft() {
|
||||
return paddingLeft;
|
||||
}
|
||||
|
||||
public int getPaddingRight()
|
||||
{
|
||||
public int getPaddingRight() {
|
||||
return paddingRight;
|
||||
}
|
||||
|
||||
public int getPaddingTop()
|
||||
{
|
||||
public int getPaddingTop() {
|
||||
return paddingTop;
|
||||
}
|
||||
|
||||
public int getPaddingBottom()
|
||||
{
|
||||
public int getPaddingBottom() {
|
||||
return paddingBottom;
|
||||
}
|
||||
|
||||
public int getVisibleWidth()
|
||||
{
|
||||
public int getVisibleWidth() {
|
||||
FontRenderer font = getFontRenderer();
|
||||
int width = 0, endX = sizeX - 1;
|
||||
for (int i = renderStart; i < textLength; ++i)
|
||||
{
|
||||
for (int i = renderStart; i < textLength; ++i) {
|
||||
int charW = font.getCharWidth(text[i]);
|
||||
if (!enableStencil && (width + charW) > endX)
|
||||
{
|
||||
if (!enableStencil && (width + charW) > endX) {
|
||||
break;
|
||||
}
|
||||
width += charW;
|
||||
if (width >= endX)
|
||||
{
|
||||
if (width >= endX) {
|
||||
width = Math.min(width, endX);
|
||||
break;
|
||||
}
|
||||
|
@ -250,28 +207,22 @@ public class ElementTextField extends ElementBase
|
|||
return width;
|
||||
}
|
||||
|
||||
public String getText()
|
||||
{
|
||||
public String getText() {
|
||||
return new String(text, 0, textLength);
|
||||
}
|
||||
|
||||
public String getSelectedText()
|
||||
{
|
||||
public String getSelectedText() {
|
||||
|
||||
if (selectionStart != selectionEnd)
|
||||
{
|
||||
if (selectionStart != selectionEnd) {
|
||||
return new String(text, selectionStart, selectionEnd);
|
||||
}
|
||||
return getText();
|
||||
}
|
||||
|
||||
public void writeText(String text)
|
||||
{
|
||||
public void writeText(String text) {
|
||||
int i = 0;
|
||||
for (int e = text.length(); i < e; ++i)
|
||||
{
|
||||
if (!insertCharacter(text.charAt(i)))
|
||||
{
|
||||
for (int e = text.length(); i < e; ++i) {
|
||||
if (!insertCharacter(text.charAt(i))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -280,70 +231,55 @@ public class ElementTextField extends ElementBase
|
|||
onCharacterEntered(i > 0);
|
||||
}
|
||||
|
||||
public boolean isAllowedCharacter(char charTyped)
|
||||
{
|
||||
public boolean isAllowedCharacter(char charTyped) {
|
||||
return ChatAllowedCharacters.isAllowedCharacter(charTyped);
|
||||
}
|
||||
|
||||
protected boolean onEnter()
|
||||
{
|
||||
protected boolean onEnter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void onFocusLost()
|
||||
{
|
||||
protected void onFocusLost() {
|
||||
|
||||
}
|
||||
|
||||
protected void onCharacterEntered(boolean success)
|
||||
{
|
||||
protected void onCharacterEntered(boolean success) {
|
||||
|
||||
}
|
||||
|
||||
protected boolean insertCharacter(char charTyped)
|
||||
{
|
||||
protected boolean insertCharacter(char charTyped) {
|
||||
|
||||
if (isAllowedCharacter(charTyped))
|
||||
{
|
||||
if (isAllowedCharacter(charTyped)) {
|
||||
|
||||
if (selectionStart != selectionEnd)
|
||||
{
|
||||
if (caret == selectionStart)
|
||||
{
|
||||
if (selectionStart != selectionEnd) {
|
||||
if (caret == selectionStart) {
|
||||
++caret;
|
||||
}
|
||||
text[selectionStart++] = charTyped;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((caretInsert && caret == text.length) || textLength == text.length)
|
||||
{
|
||||
if ((caretInsert && caret == text.length) || textLength == text.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!caretInsert)
|
||||
{
|
||||
if (caret < textLength)
|
||||
{
|
||||
if (!caretInsert) {
|
||||
if (caret < textLength) {
|
||||
System.arraycopy(text, caret, text, caret + 1, textLength - caret);
|
||||
}
|
||||
++textLength;
|
||||
}
|
||||
text[caret++] = charTyped;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void findRenderStart()
|
||||
{
|
||||
protected void findRenderStart() {
|
||||
|
||||
caret = MathHelper.clampI(caret, 0, textLength);
|
||||
if (caret < renderStart)
|
||||
{
|
||||
if (caret < renderStart) {
|
||||
renderStart = caret;
|
||||
return;
|
||||
}
|
||||
|
@ -351,27 +287,21 @@ public class ElementTextField extends ElementBase
|
|||
FontRenderer font = getFontRenderer();
|
||||
int endX = sizeX - 2;
|
||||
|
||||
for (int i = renderStart, width = 0; i < caret; ++i)
|
||||
{
|
||||
for (int i = renderStart, width = 0; i < caret; ++i) {
|
||||
width += font.getCharWidth(text[i]);
|
||||
while (width >= endX)
|
||||
{
|
||||
while (width >= endX) {
|
||||
width -= font.getCharWidth(text[renderStart++]);
|
||||
if (renderStart >= textLength)
|
||||
{
|
||||
if (renderStart >= textLength) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearSelection()
|
||||
{
|
||||
protected void clearSelection() {
|
||||
|
||||
if (selectionStart != selectionEnd)
|
||||
{
|
||||
if (selectionEnd < textLength)
|
||||
{
|
||||
if (selectionStart != selectionEnd) {
|
||||
if (selectionEnd < textLength) {
|
||||
System.arraycopy(text, selectionEnd, text, selectionStart, textLength - selectionEnd);
|
||||
}
|
||||
textLength -= selectionEnd - selectionStart;
|
||||
|
@ -381,49 +311,39 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
}
|
||||
|
||||
protected final int seekNextCaretLocation(int pos)
|
||||
{
|
||||
protected final int seekNextCaretLocation(int pos) {
|
||||
|
||||
return seekNextCaretLocation(pos, true);
|
||||
}
|
||||
|
||||
protected int seekNextCaretLocation(int pos, boolean forward)
|
||||
{
|
||||
protected int seekNextCaretLocation(int pos, boolean forward) {
|
||||
|
||||
int dir = forward ? 1 : -1;
|
||||
int e = forward ? textLength : 0;
|
||||
if (pos == textLength)
|
||||
{
|
||||
if (pos == textLength) {
|
||||
--pos;
|
||||
}
|
||||
char prevChar = text[pos];
|
||||
while (pos != e && Character.isSpaceChar(prevChar))
|
||||
{
|
||||
while (pos != e && Character.isSpaceChar(prevChar)) {
|
||||
prevChar = text[pos += dir];
|
||||
}
|
||||
|
||||
if (smartCaret)
|
||||
{
|
||||
for (int i = pos; i != e; i += dir)
|
||||
{
|
||||
if (smartCaret) {
|
||||
for (int i = pos; i != e; i += dir) {
|
||||
char curChar = text[i];
|
||||
boolean caze = Character.isUpperCase(curChar) != Character.isUpperCase(prevChar);
|
||||
if (caze || Character.isSpaceChar(curChar) != Character.isSpaceChar(prevChar) ||
|
||||
Character.isLetterOrDigit(curChar) != Character.isLetterOrDigit(prevChar))
|
||||
{
|
||||
if ((pos + dir) != i || !Character.isLetterOrDigit(curChar))
|
||||
{
|
||||
Character.isLetterOrDigit(curChar) != Character.isLetterOrDigit(prevChar)) {
|
||||
if ((pos + dir) != i || !Character.isLetterOrDigit(curChar)) {
|
||||
return i + (smartCaretCase && caze && Character.isUpperCase(prevChar) ? -dir : 0);
|
||||
}
|
||||
}
|
||||
prevChar = curChar;
|
||||
}
|
||||
}
|
||||
for (int i = pos; i != e; i += dir)
|
||||
{
|
||||
for (int i = pos; i != e; i += dir) {
|
||||
char curChar = text[i];
|
||||
if (Character.isSpaceChar(curChar) != Character.isSpaceChar(prevChar))
|
||||
{
|
||||
if (Character.isSpaceChar(curChar) != Character.isSpaceChar(prevChar)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -431,29 +351,24 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyTyped(char charTyped, int keyTyped)
|
||||
{
|
||||
if (!isFocused())
|
||||
{
|
||||
public boolean onKeyTyped(char charTyped, int keyTyped) {
|
||||
if (!isFocused()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (charTyped)
|
||||
{
|
||||
switch (charTyped) {
|
||||
case 1: // ^A
|
||||
selectionEnd = caret = textLength;
|
||||
selectionStart = 0;
|
||||
findRenderStart();
|
||||
return true;
|
||||
case 3: // ^C
|
||||
if (selectionStart != selectionEnd)
|
||||
{
|
||||
if (selectionStart != selectionEnd) {
|
||||
GuiScreen.setClipboardString(getSelectedText());
|
||||
}
|
||||
return true;
|
||||
case 24: // ^X
|
||||
if (selectionStart != selectionEnd)
|
||||
{
|
||||
if (selectionStart != selectionEnd) {
|
||||
GuiScreen.setClipboardString(getSelectedText());
|
||||
clearSelection();
|
||||
}
|
||||
|
@ -464,8 +379,7 @@ public class ElementTextField extends ElementBase
|
|||
|
||||
return true;
|
||||
default:
|
||||
switch (keyTyped)
|
||||
{
|
||||
switch (keyTyped) {
|
||||
case Keyboard.KEY_ESCAPE:
|
||||
setFocused(false);
|
||||
return !isFocused();
|
||||
|
@ -473,12 +387,9 @@ public class ElementTextField extends ElementBase
|
|||
case Keyboard.KEY_NUMPADENTER:
|
||||
return onEnter();
|
||||
case Keyboard.KEY_INSERT:
|
||||
if (GuiScreen.isShiftKeyDown())
|
||||
{
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
writeText(GuiScreen.getClipboardString());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
caretInsert = !caretInsert;
|
||||
}
|
||||
|
||||
|
@ -488,29 +399,21 @@ public class ElementTextField extends ElementBase
|
|||
|
||||
return true;
|
||||
case Keyboard.KEY_DELETE: // delete
|
||||
if (!GuiScreen.isShiftKeyDown())
|
||||
{
|
||||
if (selectionStart != selectionEnd)
|
||||
{
|
||||
if (!GuiScreen.isShiftKeyDown()) {
|
||||
if (selectionStart != selectionEnd) {
|
||||
clearSelection();
|
||||
}
|
||||
else if (GuiScreen.isCtrlKeyDown())
|
||||
{
|
||||
} else if (GuiScreen.isCtrlKeyDown()) {
|
||||
int size = seekNextCaretLocation(caret, true) - caret;
|
||||
selectionStart = caret;
|
||||
selectionEnd = caret + size;
|
||||
clearSelection();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (caret < textLength && textLength > 0)
|
||||
{
|
||||
} else {
|
||||
if (caret < textLength && textLength > 0) {
|
||||
--textLength;
|
||||
System.arraycopy(text, caret + 1, text, caret, textLength - caret);
|
||||
}
|
||||
}
|
||||
if (caret <= renderStart)
|
||||
{
|
||||
if (caret <= renderStart) {
|
||||
renderStart = MathHelper.clampI(caret - 3, 0, textLength);
|
||||
}
|
||||
findRenderStart();
|
||||
|
@ -519,60 +422,45 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
// continue.. (shift+delete = backspace)
|
||||
case Keyboard.KEY_BACK: // backspace
|
||||
if (selectionStart != selectionEnd)
|
||||
{
|
||||
if (selectionStart != selectionEnd) {
|
||||
clearSelection();
|
||||
}
|
||||
else if (GuiScreen.isCtrlKeyDown())
|
||||
{
|
||||
} else if (GuiScreen.isCtrlKeyDown()) {
|
||||
int size = seekNextCaretLocation(caret, false) - caret;
|
||||
selectionStart = caret + size;
|
||||
selectionEnd = caret;
|
||||
clearSelection();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (caret > 0 && textLength > 0)
|
||||
{
|
||||
} else {
|
||||
if (caret > 0 && textLength > 0) {
|
||||
--caret;
|
||||
System.arraycopy(text, caret + 1, text, caret, textLength - caret);
|
||||
--textLength;
|
||||
}
|
||||
}
|
||||
if (caret <= renderStart)
|
||||
{
|
||||
if (caret <= renderStart) {
|
||||
renderStart = MathHelper.clampI(caret - 3, 0, textLength);
|
||||
}
|
||||
findRenderStart();
|
||||
onCharacterEntered(true);
|
||||
return true;
|
||||
case Keyboard.KEY_HOME: // home
|
||||
if (GuiScreen.isShiftKeyDown())
|
||||
{
|
||||
if (caret > selectionEnd)
|
||||
{
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
if (caret > selectionEnd) {
|
||||
selectionEnd = selectionStart;
|
||||
}
|
||||
selectionStart = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
selectionStart = selectionEnd = 0;
|
||||
}
|
||||
renderStart = caret = 0;
|
||||
|
||||
return true;
|
||||
case Keyboard.KEY_END: // end
|
||||
if (GuiScreen.isShiftKeyDown())
|
||||
{
|
||||
if (caret < selectionStart)
|
||||
{
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
if (caret < selectionStart) {
|
||||
selectionStart = selectionEnd;
|
||||
}
|
||||
selectionEnd = textLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
selectionStart = selectionEnd = textLength;
|
||||
}
|
||||
caret = textLength;
|
||||
|
@ -582,13 +470,11 @@ public class ElementTextField extends ElementBase
|
|||
case Keyboard.KEY_LEFT: // left arrow
|
||||
case Keyboard.KEY_RIGHT: // right arrow
|
||||
int size = keyTyped == 203 ? -1 : 1;
|
||||
if (GuiScreen.isCtrlKeyDown())
|
||||
{
|
||||
if (GuiScreen.isCtrlKeyDown()) {
|
||||
size = seekNextCaretLocation(caret, keyTyped == 205) - caret;
|
||||
}
|
||||
|
||||
if (selectionStart == selectionEnd || !GuiScreen.isShiftKeyDown())
|
||||
{
|
||||
if (selectionStart == selectionEnd || !GuiScreen.isShiftKeyDown()) {
|
||||
selectionStart = selectionEnd = caret;
|
||||
}
|
||||
|
||||
|
@ -599,14 +485,10 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
findRenderStart();
|
||||
|
||||
if (GuiScreen.isShiftKeyDown())
|
||||
{
|
||||
if (caret == selectionStart + size)
|
||||
{
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
if (caret == selectionStart + size) {
|
||||
selectionStart = caret;
|
||||
}
|
||||
else if (caret == selectionEnd + size)
|
||||
{
|
||||
} else if (caret == selectionEnd + size) {
|
||||
selectionEnd = caret;
|
||||
}
|
||||
// this logic is 'broken' in that the selection doesn't wrap
|
||||
|
@ -614,8 +496,7 @@ public class ElementTextField extends ElementBase
|
|||
// the rest of the word the caret is on i.e., a|bc|def -> a|bcdef|
|
||||
// i don't know that it matters (home+end exhibit the former)
|
||||
|
||||
if (selectionStart > selectionEnd)
|
||||
{
|
||||
if (selectionStart > selectionEnd) {
|
||||
int t = selectionStart;
|
||||
selectionStart = selectionEnd;
|
||||
selectionEnd = t;
|
||||
|
@ -624,16 +505,13 @@ public class ElementTextField extends ElementBase
|
|||
|
||||
return true;
|
||||
default:
|
||||
if (isAllowedCharacter(charTyped))
|
||||
{
|
||||
if (isAllowedCharacter(charTyped)) {
|
||||
boolean typed = insertCharacter(charTyped);
|
||||
clearSelection();
|
||||
findRenderStart();
|
||||
onCharacterEntered(typed);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -641,25 +519,20 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton)
|
||||
{
|
||||
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
selecting = mouseButton == 0;
|
||||
l:
|
||||
if (selecting)
|
||||
{
|
||||
if (textLength == 0)
|
||||
{
|
||||
if (selecting) {
|
||||
if (textLength == 0) {
|
||||
selectionStart = selectionEnd = caret = 0;
|
||||
break l;
|
||||
}
|
||||
FontRenderer font = getFontRenderer();
|
||||
int pos = mouseX - posX - 1;
|
||||
for (int i = renderStart, width = 0; ; )
|
||||
{
|
||||
for (int i = renderStart, width = 0; ; ) {
|
||||
int charW = font.getCharWidth(text[i]);
|
||||
if ((width += charW) > pos || ++i >= textLength)
|
||||
{
|
||||
if ((width += charW) > pos || ++i >= textLength) {
|
||||
selectionStart = selectionEnd = caret = i;
|
||||
break;
|
||||
}
|
||||
|
@ -671,8 +544,7 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void update(int mouseX, int mouseY)
|
||||
{
|
||||
public void update(int mouseX, int mouseY) {
|
||||
|
||||
++caretCounter;
|
||||
//if (selecting) {
|
||||
|
@ -684,15 +556,12 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onMouseReleased(int mouseX, int mouseY)
|
||||
{
|
||||
public void onMouseReleased(int mouseX, int mouseY) {
|
||||
|
||||
if (!selecting)
|
||||
{
|
||||
if (!selecting) {
|
||||
boolean focus = isFocused();
|
||||
setFocused(false);
|
||||
if (focus && !isFocused())
|
||||
{
|
||||
if (focus && !isFocused()) {
|
||||
onFocusLost();
|
||||
}
|
||||
}
|
||||
|
@ -700,19 +569,16 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks)
|
||||
{
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
|
||||
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
|
||||
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, isEnabled() ? backgroundColor : disabledColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
if (enableStencil)
|
||||
{
|
||||
if (enableStencil) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
drawStencil(posX + 1, posY + 1, posX + sizeX - 1, posY + sizeY - 1, 1);
|
||||
|
@ -721,45 +587,36 @@ public class ElementTextField extends ElementBase
|
|||
FontRenderer font = getFontRenderer();
|
||||
char[] text = this.text;
|
||||
int startX = posX + paddingLeft, endX = sizeX - paddingRight, startY = posY + paddingTop, endY = startY + font.FONT_HEIGHT + paddingBottom;
|
||||
for (int i = renderStart, width = 0; i <= textLength; ++i)
|
||||
{
|
||||
for (int i = renderStart, width = 0; i <= textLength; ++i) {
|
||||
boolean end = i == textLength;
|
||||
int charW = 2;
|
||||
if (!end)
|
||||
{
|
||||
if (!end) {
|
||||
charW = font.getCharWidth(text[i]);
|
||||
if (!enableStencil && (width + charW) > endX)
|
||||
{
|
||||
if (!enableStencil && (width + charW) > endX) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean drawCaret = i == caret && (caretCounter &= 31) < 16 && isFocused();
|
||||
if (drawCaret)
|
||||
{
|
||||
if (drawCaret) {
|
||||
int caretEnd = width + 2;
|
||||
if (caretInsert)
|
||||
{
|
||||
if (caretInsert) {
|
||||
caretEnd = width + charW;
|
||||
}
|
||||
drawModalRect(startX + width, startY - 1, startX + caretEnd, endY, (0xFF000000 & defaultCaretColor) | (~defaultCaretColor & 0xFFFFFF));
|
||||
}
|
||||
|
||||
if (!end)
|
||||
{
|
||||
if (!end) {
|
||||
boolean selected = i >= selectionStart & i < selectionEnd;
|
||||
if (selected)
|
||||
{
|
||||
if (selected) {
|
||||
drawModalRect(startX + width, startY, startX + width + charW, endY, selectedLineColor);
|
||||
}
|
||||
font.drawStringWithShadow(String.valueOf(text[i]), startX + width, startY, selected ? selectedTextColor : textColor);
|
||||
}
|
||||
|
||||
if (drawCaret)
|
||||
{
|
||||
if (drawCaret) {
|
||||
int caretEnd = width + 2;
|
||||
if (caretInsert)
|
||||
{
|
||||
if (caretInsert) {
|
||||
caretEnd = width + charW;
|
||||
}
|
||||
|
||||
|
@ -770,14 +627,12 @@ public class ElementTextField extends ElementBase
|
|||
}
|
||||
|
||||
width += charW;
|
||||
if (width > endX)
|
||||
{
|
||||
if (width > endX) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (enableStencil)
|
||||
{
|
||||
if (enableStencil) {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,20 +5,17 @@ import techreborn.cofhLib.util.CharacterSingleton;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ElementTextFieldFiltered extends ElementTextField
|
||||
{
|
||||
public class ElementTextFieldFiltered extends ElementTextField {
|
||||
protected boolean includeVanilla = true;
|
||||
protected CharacterSingleton seq = new CharacterSingleton();
|
||||
protected Matcher filter;
|
||||
|
||||
public ElementTextFieldFiltered(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height)
|
||||
{
|
||||
public ElementTextFieldFiltered(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height) {
|
||||
|
||||
super(gui, posX, posY, width, height);
|
||||
}
|
||||
|
||||
public ElementTextFieldFiltered(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height, short limit)
|
||||
{
|
||||
public ElementTextFieldFiltered(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height, short limit) {
|
||||
|
||||
super(gui, posX, posY, width, height, limit);
|
||||
}
|
||||
|
@ -28,8 +25,7 @@ public class ElementTextFieldFiltered extends ElementTextField
|
|||
* @param includeVanilla Include vanilla disallowed characters
|
||||
* @return this
|
||||
*/
|
||||
public ElementTextFieldFiltered setFilter(Pattern pattern, boolean includeVanilla)
|
||||
{
|
||||
public ElementTextFieldFiltered setFilter(Pattern pattern, boolean includeVanilla) {
|
||||
|
||||
filter = pattern.matcher(seq);
|
||||
this.includeVanilla = includeVanilla;
|
||||
|
@ -37,8 +33,7 @@ public class ElementTextFieldFiltered extends ElementTextField
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedCharacter(char charTyped)
|
||||
{
|
||||
public boolean isAllowedCharacter(char charTyped) {
|
||||
|
||||
seq.character = charTyped;
|
||||
return (!includeVanilla || super.isAllowedCharacter(charTyped)) && (filter == null || filter.reset().matches());
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
package techreborn.cofhLib.gui.element;
|
||||
|
||||
public class ElementTextFieldLimited extends ElementTextField
|
||||
{
|
||||
public class ElementTextFieldLimited extends ElementTextField {
|
||||
|
||||
protected boolean includeVanilla = true;
|
||||
protected String filter;
|
||||
|
||||
public ElementTextFieldLimited(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height)
|
||||
{
|
||||
public ElementTextFieldLimited(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height) {
|
||||
|
||||
super(gui, posX, posY, width, height);
|
||||
}
|
||||
|
||||
public ElementTextFieldLimited(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height, short limit)
|
||||
{
|
||||
public ElementTextFieldLimited(techreborn.cofhLib.gui.GuiBase gui, int posX, int posY, int width, int height, short limit) {
|
||||
|
||||
super(gui, posX, posY, width, height, limit);
|
||||
}
|
||||
|
@ -23,8 +20,7 @@ public class ElementTextFieldLimited extends ElementTextField
|
|||
* @param includeVanilla Include vanilla disallowed characters
|
||||
* @return this
|
||||
*/
|
||||
public ElementTextFieldLimited setFilter(String pattern, boolean includeVanilla)
|
||||
{
|
||||
public ElementTextFieldLimited setFilter(String pattern, boolean includeVanilla) {
|
||||
|
||||
filter = pattern;
|
||||
this.includeVanilla = includeVanilla;
|
||||
|
@ -32,8 +28,7 @@ public class ElementTextFieldLimited extends ElementTextField
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedCharacter(char charTyped)
|
||||
{
|
||||
public boolean isAllowedCharacter(char charTyped) {
|
||||
|
||||
return (!includeVanilla || super.isAllowedCharacter(charTyped)) && (filter == null || filter.indexOf(charTyped) >= 0);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ import techreborn.cofhLib.render.RenderHelper;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public abstract class TabBase extends ElementBase
|
||||
{
|
||||
public abstract class TabBase extends ElementBase {
|
||||
|
||||
public static int tabExpandSpeed = 8;
|
||||
|
||||
|
@ -43,31 +42,25 @@ public abstract class TabBase extends ElementBase
|
|||
public static final ResourceLocation DEFAULT_TEXTURE_LEFT = new ResourceLocation(techreborn.cofhLib.gui.GuiProps.PATH_ELEMENTS + "Tab_Left.png");
|
||||
public static final ResourceLocation DEFAULT_TEXTURE_RIGHT = new ResourceLocation(techreborn.cofhLib.gui.GuiProps.PATH_ELEMENTS + "Tab_Right.png");
|
||||
|
||||
public TabBase(techreborn.cofhLib.gui.GuiBase gui)
|
||||
{
|
||||
public TabBase(techreborn.cofhLib.gui.GuiBase gui) {
|
||||
|
||||
super(gui, 0, 0);
|
||||
texture = DEFAULT_TEXTURE_RIGHT;
|
||||
}
|
||||
|
||||
public TabBase(techreborn.cofhLib.gui.GuiBase gui, int side)
|
||||
{
|
||||
public TabBase(techreborn.cofhLib.gui.GuiBase gui, int side) {
|
||||
|
||||
super(gui, 0, 0);
|
||||
this.side = side;
|
||||
|
||||
if (side == LEFT)
|
||||
{
|
||||
if (side == LEFT) {
|
||||
texture = DEFAULT_TEXTURE_LEFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
texture = DEFAULT_TEXTURE_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
public TabBase setOffsets(int x, int y)
|
||||
{
|
||||
public TabBase setOffsets(int x, int y) {
|
||||
|
||||
offsetX = x;
|
||||
offsetY = y;
|
||||
|
@ -75,76 +68,57 @@ public abstract class TabBase extends ElementBase
|
|||
return this;
|
||||
}
|
||||
|
||||
public void draw(int x, int y)
|
||||
{
|
||||
public void draw(int x, int y) {
|
||||
|
||||
posX = x + offsetX;
|
||||
posY = y + offsetY;
|
||||
draw();
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
public void draw() {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks)
|
||||
{
|
||||
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
public void update() {
|
||||
|
||||
if (open && currentWidth < maxWidth)
|
||||
{
|
||||
if (open && currentWidth < maxWidth) {
|
||||
currentWidth += tabExpandSpeed;
|
||||
}
|
||||
else if (!open && currentWidth > minWidth)
|
||||
{
|
||||
} else if (!open && currentWidth > minWidth) {
|
||||
currentWidth -= tabExpandSpeed;
|
||||
}
|
||||
if (currentWidth > maxWidth)
|
||||
{
|
||||
if (currentWidth > maxWidth) {
|
||||
currentWidth = maxWidth;
|
||||
}
|
||||
else if (currentWidth < minWidth)
|
||||
{
|
||||
} else if (currentWidth < minWidth) {
|
||||
currentWidth = minWidth;
|
||||
}
|
||||
if (open && currentHeight < maxHeight)
|
||||
{
|
||||
if (open && currentHeight < maxHeight) {
|
||||
currentHeight += tabExpandSpeed;
|
||||
}
|
||||
else if (!open && currentHeight > minHeight)
|
||||
{
|
||||
} else if (!open && currentHeight > minHeight) {
|
||||
currentHeight -= tabExpandSpeed;
|
||||
}
|
||||
if (currentHeight > maxHeight)
|
||||
{
|
||||
if (currentHeight > maxHeight) {
|
||||
currentHeight = maxHeight;
|
||||
}
|
||||
else if (currentHeight < minHeight)
|
||||
{
|
||||
} else if (currentHeight < minHeight) {
|
||||
currentHeight = minHeight;
|
||||
}
|
||||
if (!fullyOpen && open && currentWidth == maxWidth && currentHeight == maxHeight)
|
||||
{
|
||||
if (!fullyOpen && open && currentWidth == maxWidth && currentHeight == maxHeight) {
|
||||
setFullyOpen();
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawBackground()
|
||||
{
|
||||
protected void drawBackground() {
|
||||
|
||||
float colorR = (backgroundColor >> 16 & 255) / 255.0F;
|
||||
float colorG = (backgroundColor >> 8 & 255) / 255.0F;
|
||||
|
@ -164,8 +138,7 @@ public abstract class TabBase extends ElementBase
|
|||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
|
||||
}
|
||||
|
||||
protected void drawTabIcon(String iconName)
|
||||
{
|
||||
protected void drawTabIcon(String iconName) {
|
||||
|
||||
gui.drawIcon(iconName, posXOffset(), posY + 3, 1);
|
||||
}
|
||||
|
@ -173,11 +146,9 @@ public abstract class TabBase extends ElementBase
|
|||
/**
|
||||
* Shortcut to correct for the proper X position.
|
||||
*/
|
||||
protected int posX()
|
||||
{
|
||||
protected int posX() {
|
||||
|
||||
if (side == LEFT)
|
||||
{
|
||||
if (side == LEFT) {
|
||||
return posX - currentWidth;
|
||||
}
|
||||
return posX;
|
||||
|
@ -186,53 +157,43 @@ public abstract class TabBase extends ElementBase
|
|||
/**
|
||||
* Corrects for shadowing differences in tabs to ensure that they always look nice - used in font rendering, typically.
|
||||
*/
|
||||
protected int posXOffset()
|
||||
{
|
||||
protected int posXOffset() {
|
||||
|
||||
return posX() + sideOffset();
|
||||
}
|
||||
|
||||
protected int sideOffset()
|
||||
{
|
||||
protected int sideOffset() {
|
||||
|
||||
return (side == LEFT ? 4 : 2);
|
||||
}
|
||||
|
||||
public boolean intersectsWith(int mouseX, int mouseY, int shiftX, int shiftY)
|
||||
{
|
||||
public boolean intersectsWith(int mouseX, int mouseY, int shiftX, int shiftY) {
|
||||
|
||||
shiftX += offsetX;
|
||||
shiftY += offsetY;
|
||||
|
||||
if (side == LEFT)
|
||||
{
|
||||
if (mouseX <= shiftX && mouseX >= shiftX - currentWidth && mouseY >= shiftY && mouseY <= shiftY + currentHeight)
|
||||
{
|
||||
if (side == LEFT) {
|
||||
if (mouseX <= shiftX && mouseX >= shiftX - currentWidth && mouseY >= shiftY && mouseY <= shiftY + currentHeight) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (mouseX >= shiftX && mouseX <= shiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + currentHeight)
|
||||
{
|
||||
} else if (mouseX >= shiftX && mouseX <= shiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + currentHeight) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFullyOpened()
|
||||
{
|
||||
public boolean isFullyOpened() {
|
||||
|
||||
return fullyOpen;
|
||||
}
|
||||
|
||||
public void setCurrentShift(int x, int y)
|
||||
{
|
||||
public void setCurrentShift(int x, int y) {
|
||||
|
||||
currentShiftX = x + offsetX;
|
||||
currentShiftY = y + offsetY;
|
||||
}
|
||||
|
||||
public void setFullyOpen()
|
||||
{
|
||||
public void setFullyOpen() {
|
||||
|
||||
open = true;
|
||||
currentWidth = maxWidth;
|
||||
|
@ -240,45 +201,31 @@ public abstract class TabBase extends ElementBase
|
|||
fullyOpen = true;
|
||||
}
|
||||
|
||||
public void toggleOpen()
|
||||
{
|
||||
public void toggleOpen() {
|
||||
|
||||
if (open)
|
||||
{
|
||||
if (open) {
|
||||
open = false;
|
||||
if (side == LEFT)
|
||||
{
|
||||
if (side == LEFT) {
|
||||
techreborn.cofhLib.gui.TabTracker.setOpenedLeftTab(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
techreborn.cofhLib.gui.TabTracker.setOpenedRightTab(null);
|
||||
}
|
||||
fullyOpen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
open = true;
|
||||
if (side == LEFT)
|
||||
{
|
||||
if (side == LEFT) {
|
||||
techreborn.cofhLib.gui.TabTracker.setOpenedLeftTab(this.getClass());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
techreborn.cofhLib.gui.TabTracker.setOpenedRightTab(this.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public techreborn.cofhLib.util.Rectangle4i getBounds()
|
||||
{
|
||||
public techreborn.cofhLib.util.Rectangle4i getBounds() {
|
||||
|
||||
if (isVisible())
|
||||
{
|
||||
if (isVisible()) {
|
||||
return new techreborn.cofhLib.util.Rectangle4i(posX() + gui.getGuiLeft(), posY + gui.getGuiTop(), currentWidth, currentHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return new techreborn.cofhLib.util.Rectangle4i(posX() + gui.getGuiLeft(), posY + gui.getGuiTop(), 0, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ package techreborn.cofhLib.gui.element.listbox;
|
|||
|
||||
import techreborn.cofhLib.gui.element.ElementListBox;
|
||||
|
||||
public interface IListBoxElement
|
||||
{
|
||||
public interface IListBoxElement {
|
||||
|
||||
public int getHeight();
|
||||
|
||||
|
|
|
@ -3,41 +3,35 @@ package techreborn.cofhLib.gui.element.listbox;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import techreborn.cofhLib.gui.element.ElementListBox;
|
||||
|
||||
public class ListBoxElementText implements IListBoxElement
|
||||
{
|
||||
public class ListBoxElementText implements IListBoxElement {
|
||||
|
||||
private final String _text;
|
||||
|
||||
public ListBoxElementText(String text)
|
||||
{
|
||||
public ListBoxElementText(String text) {
|
||||
|
||||
_text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
public Object getValue() {
|
||||
|
||||
return _text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
public int getHeight() {
|
||||
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth()
|
||||
{
|
||||
public int getWidth() {
|
||||
|
||||
return Minecraft.getMinecraft().fontRenderer.getStringWidth(_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(ElementListBox listBox, int x, int y, int backColor, int textColor)
|
||||
{
|
||||
public void draw(ElementListBox listBox, int x, int y, int backColor, int textColor) {
|
||||
|
||||
Minecraft.getMinecraft().fontRenderer.drawString(_text, x, y, textColor);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
package techreborn.cofhLib.gui.element.listbox;
|
||||
|
||||
public class SliderHorizontal extends techreborn.cofhLib.gui.element.ElementSlider
|
||||
{
|
||||
public class SliderHorizontal extends techreborn.cofhLib.gui.element.ElementSlider {
|
||||
|
||||
public SliderHorizontal(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue)
|
||||
{
|
||||
public SliderHorizontal(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue) {
|
||||
|
||||
this(containerScreen, x, y, width, height, maxValue, 0);
|
||||
}
|
||||
|
||||
public SliderHorizontal(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue)
|
||||
{
|
||||
public SliderHorizontal(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue) {
|
||||
|
||||
super(containerScreen, x, y, width, height, maxValue, minValue);
|
||||
int dist = maxValue - minValue;
|
||||
|
@ -18,8 +15,7 @@ public class SliderHorizontal extends techreborn.cofhLib.gui.element.ElementSlid
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSliderX()
|
||||
{
|
||||
public int getSliderX() {
|
||||
|
||||
int dist = _valueMax - _valueMin;
|
||||
int maxPos = sizeX - _sliderWidth;
|
||||
|
@ -27,8 +23,7 @@ public class SliderHorizontal extends techreborn.cofhLib.gui.element.ElementSlid
|
|||
}
|
||||
|
||||
@Override
|
||||
public void dragSlider(int v, int y)
|
||||
{
|
||||
public void dragSlider(int v, int y) {
|
||||
|
||||
v += Math.round(_sliderWidth * (v / (float) sizeX) + (_sliderWidth * 0.25f));
|
||||
setValue(_valueMin + ((_valueMax - _valueMin) * v / sizeX));
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
package techreborn.cofhLib.gui.element.listbox;
|
||||
|
||||
public class SliderVertical extends techreborn.cofhLib.gui.element.ElementSlider
|
||||
{
|
||||
public class SliderVertical extends techreborn.cofhLib.gui.element.ElementSlider {
|
||||
|
||||
public SliderVertical(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue)
|
||||
{
|
||||
public SliderVertical(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue) {
|
||||
|
||||
this(containerScreen, x, y, width, height, maxValue, 0);
|
||||
}
|
||||
|
||||
public SliderVertical(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue)
|
||||
{
|
||||
public SliderVertical(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue) {
|
||||
|
||||
super(containerScreen, x, y, width, height, maxValue, minValue);
|
||||
int dist = maxValue - minValue;
|
||||
|
@ -18,8 +15,7 @@ public class SliderVertical extends techreborn.cofhLib.gui.element.ElementSlider
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSliderY()
|
||||
{
|
||||
public int getSliderY() {
|
||||
|
||||
int dist = _valueMax - _valueMin;
|
||||
int maxPos = sizeY - _sliderHeight;
|
||||
|
@ -27,8 +23,7 @@ public class SliderVertical extends techreborn.cofhLib.gui.element.ElementSlider
|
|||
}
|
||||
|
||||
@Override
|
||||
public void dragSlider(int x, int v)
|
||||
{
|
||||
public void dragSlider(int x, int v) {
|
||||
|
||||
v += Math.round(_sliderHeight * (v / (float) sizeY) + (_sliderHeight * 0.25f));
|
||||
setValue(_valueMin + ((_valueMax - _valueMin) * v / sizeY));
|
||||
|
|
|
@ -7,8 +7,7 @@ import net.minecraft.item.ItemStack;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public interface ISlotValidator
|
||||
{
|
||||
public interface ISlotValidator {
|
||||
|
||||
/**
|
||||
* Essentially a passthrough so an arbitrary criterion can be checked against.
|
||||
|
|
|
@ -8,21 +8,18 @@ import net.minecraft.item.ItemStack;
|
|||
/**
|
||||
* Slot that will only accept ItemStacks whose items are a subclass of the given class.
|
||||
*/
|
||||
public class SlotAcceptAssignable extends Slot
|
||||
{
|
||||
public class SlotAcceptAssignable extends Slot {
|
||||
|
||||
protected Class<? extends Item> clazz;
|
||||
|
||||
public SlotAcceptAssignable(IInventory inventory, int index, int x, int y, Class<? extends Item> c)
|
||||
{
|
||||
public SlotAcceptAssignable(IInventory inventory, int index, int x, int y, Class<? extends Item> c) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
clazz = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return stack != null && clazz.isInstance(stack.getItem());
|
||||
}
|
||||
|
|
|
@ -9,29 +9,23 @@ import net.minecraft.item.ItemStack;
|
|||
* <p/>
|
||||
* If an ISidedInventory, canInsertItem (from side 6 (UNKNOWN)) must also return true.
|
||||
*/
|
||||
public class SlotAcceptInsertable extends SlotAcceptValid
|
||||
{
|
||||
public class SlotAcceptInsertable extends SlotAcceptValid {
|
||||
|
||||
protected ISidedInventory sidedInv;
|
||||
|
||||
public SlotAcceptInsertable(IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotAcceptInsertable(IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
|
||||
if (inventory instanceof ISidedInventory)
|
||||
{
|
||||
if (inventory instanceof ISidedInventory) {
|
||||
sidedInv = (ISidedInventory) inventory;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sidedInv = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
boolean valid = super.isItemValid(stack);
|
||||
|
||||
|
|
|
@ -7,18 +7,15 @@ import net.minecraft.item.ItemStack;
|
|||
/**
|
||||
* Slot that will only accept ItemStacks when the IInventory returns true from isItemValidForSlot.
|
||||
*/
|
||||
public class SlotAcceptValid extends Slot
|
||||
{
|
||||
public class SlotAcceptValid extends Slot {
|
||||
|
||||
public SlotAcceptValid(IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotAcceptValid(IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return stack != null && this.inventory.isItemValidForSlot(this.slotNumber, stack);
|
||||
}
|
||||
|
|
|
@ -10,25 +10,21 @@ import net.minecraft.item.ItemStack;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public class SlotCraftingLocked extends SlotCrafting
|
||||
{
|
||||
public class SlotCraftingLocked extends SlotCrafting {
|
||||
|
||||
public SlotCraftingLocked(EntityPlayer player, IInventory craftMatrix, IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotCraftingLocked(EntityPlayer player, IInventory craftMatrix, IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(player, craftMatrix, inventory, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player)
|
||||
{
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -10,38 +10,32 @@ import net.minecraft.item.ItemStack;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public class SlotFalseCopy extends Slot
|
||||
{
|
||||
public class SlotFalseCopy extends Slot {
|
||||
|
||||
public int slotIndex = 0;
|
||||
|
||||
public SlotFalseCopy(IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotFalseCopy(IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
slotIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player)
|
||||
{
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack)
|
||||
{
|
||||
public void putStack(ItemStack stack) {
|
||||
|
||||
if (stack != null)
|
||||
{
|
||||
if (stack != null) {
|
||||
stack.stackSize = 1;
|
||||
}
|
||||
this.inventory.setInventorySlotContents(this.slotIndex, stack);
|
||||
|
|
|
@ -12,51 +12,44 @@ import net.minecraft.item.ItemStack;
|
|||
* <p/>
|
||||
* Used primarily for containers that have a larger internal inventory than external (e.g., DeepStorageUnit)
|
||||
*/
|
||||
public class SlotInvisible extends Slot
|
||||
{
|
||||
public class SlotInvisible extends Slot {
|
||||
|
||||
protected final int slotIndex;
|
||||
|
||||
public SlotInvisible(IInventory inventory, int index, int x, int y, int slot)
|
||||
{
|
||||
public SlotInvisible(IInventory inventory, int index, int x, int y, int slot) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
slotIndex = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack)
|
||||
{
|
||||
public void putStack(ItemStack stack) {
|
||||
|
||||
this.inventory.setInventorySlotContents(slotIndex, stack);
|
||||
this.onSlotChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack()
|
||||
{
|
||||
public ItemStack getStack() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int par1)
|
||||
{
|
||||
public ItemStack decrStackSize(int par1) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer p)
|
||||
{
|
||||
public boolean canTakeStack(EntityPlayer p) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean func_111238_b()
|
||||
{
|
||||
public boolean func_111238_b() {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8,18 +8,15 @@ import net.minecraft.item.ItemStack;
|
|||
/**
|
||||
* Slot that will only accept Potions.
|
||||
*/
|
||||
public class SlotPotion extends Slot
|
||||
{
|
||||
public class SlotPotion extends Slot {
|
||||
|
||||
public SlotPotion(IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotPotion(IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return stack != null && stack.getItem().equals(Items.potionitem);
|
||||
}
|
||||
|
|
|
@ -7,18 +7,15 @@ import net.minecraft.item.ItemStack;
|
|||
/**
|
||||
* Slot that will only accept Potion Ingredients.
|
||||
*/
|
||||
public class SlotPotionIngredient extends Slot
|
||||
{
|
||||
public class SlotPotionIngredient extends Slot {
|
||||
|
||||
public SlotPotionIngredient(IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotPotionIngredient(IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return stack != null && stack.getItem().isPotionIngredient(stack);
|
||||
}
|
||||
|
|
|
@ -7,18 +7,15 @@ import net.minecraft.item.ItemStack;
|
|||
/**
|
||||
* Slot which players can only remove items from.
|
||||
*/
|
||||
public class SlotRemoveOnly extends Slot
|
||||
{
|
||||
public class SlotRemoveOnly extends Slot {
|
||||
|
||||
public SlotRemoveOnly(IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotRemoveOnly(IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -9,21 +9,18 @@ import net.minecraft.item.ItemStack;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public class SlotValidated extends Slot
|
||||
{
|
||||
public class SlotValidated extends Slot {
|
||||
|
||||
ISlotValidator validator;
|
||||
|
||||
public SlotValidated(ISlotValidator validator, IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotValidated(ISlotValidator validator, IInventory inventory, int index, int x, int y) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return validator.isItemValid(stack);
|
||||
}
|
||||
|
|
|
@ -10,55 +10,47 @@ import net.minecraft.item.ItemStack;
|
|||
/**
|
||||
* A slot that can only be used to display an item, not edited. Can optionally not highlight when moused over.
|
||||
*/
|
||||
public class SlotViewOnly extends Slot
|
||||
{
|
||||
public class SlotViewOnly extends Slot {
|
||||
|
||||
protected boolean showHighlight;
|
||||
|
||||
public SlotViewOnly(IInventory inventory, int index, int x, int y)
|
||||
{
|
||||
public SlotViewOnly(IInventory inventory, int index, int x, int y) {
|
||||
|
||||
this(inventory, index, x, y, false);
|
||||
}
|
||||
|
||||
public SlotViewOnly(IInventory inventory, int index, int x, int y, boolean highlight)
|
||||
{
|
||||
public SlotViewOnly(IInventory inventory, int index, int x, int y, boolean highlight) {
|
||||
|
||||
super(inventory, index, x, y);
|
||||
showHighlight = highlight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack)
|
||||
{
|
||||
public void putStack(ItemStack stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i)
|
||||
{
|
||||
public ItemStack decrStackSize(int i) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player)
|
||||
{
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean func_111238_b()
|
||||
{
|
||||
public boolean func_111238_b() {
|
||||
|
||||
return showHighlight;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ import org.lwjgl.opengl.GL11;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public final class RenderHelper
|
||||
{
|
||||
public final class RenderHelper {
|
||||
|
||||
public static final double RENDER_OFFSET = 1.0D / 1024.0D;
|
||||
public static final ResourceLocation MC_BLOCK_SHEET = new ResourceLocation("textures/atlas/blocks.png");
|
||||
|
@ -30,55 +29,46 @@ public final class RenderHelper
|
|||
public static final ResourceLocation MC_FONT_ALTERNATE = new ResourceLocation("textures/font/ascii_sga.png");
|
||||
public static final ResourceLocation MC_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||
|
||||
private RenderHelper()
|
||||
{
|
||||
private RenderHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static final TextureManager engine()
|
||||
{
|
||||
public static final TextureManager engine() {
|
||||
|
||||
return Minecraft.getMinecraft().renderEngine;
|
||||
}
|
||||
|
||||
public static final Tessellator tessellator()
|
||||
{
|
||||
public static final Tessellator tessellator() {
|
||||
|
||||
return Tessellator.instance;
|
||||
}
|
||||
|
||||
public static void setColor3ub(int color)
|
||||
{
|
||||
public static void setColor3ub(int color) {
|
||||
|
||||
GL11.glColor3ub((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));
|
||||
}
|
||||
|
||||
public static void setColor4ub(int color)
|
||||
{
|
||||
public static void setColor4ub(int color) {
|
||||
|
||||
GL11.glColor4ub((byte) (color >> 24 & 0xFF), (byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));
|
||||
}
|
||||
|
||||
public static void resetColor()
|
||||
{
|
||||
public static void resetColor() {
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
}
|
||||
|
||||
public static void renderItemAsBlock(RenderBlocks renderer, ItemStack item, double translateX, double translateY, double translateZ)
|
||||
{
|
||||
public static void renderItemAsBlock(RenderBlocks renderer, ItemStack item, double translateX, double translateY, double translateZ) {
|
||||
|
||||
renderTextureAsBlock(renderer, item.getIconIndex(), translateX, translateY, translateZ);
|
||||
}
|
||||
|
||||
public static void renderTextureAsBlock(RenderBlocks renderer, IIcon texture, double translateX, double translateY, double translateZ)
|
||||
{
|
||||
public static void renderTextureAsBlock(RenderBlocks renderer, IIcon texture, double translateX, double translateY, double translateZ) {
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
Block block = Blocks.stone;
|
||||
|
||||
if (texture == null)
|
||||
{
|
||||
if (texture == null) {
|
||||
return;
|
||||
}
|
||||
renderer.setRenderBoundsFromBlock(block);
|
||||
|
@ -106,14 +96,12 @@ public final class RenderHelper
|
|||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void renderItemIn2D(IIcon icon)
|
||||
{
|
||||
public static void renderItemIn2D(IIcon icon) {
|
||||
|
||||
ItemRenderer.renderItemIn2D(Tessellator.instance, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
|
||||
}
|
||||
|
||||
public static void renderIcon(IIcon icon, double z)
|
||||
{
|
||||
public static void renderIcon(IIcon icon, double z) {
|
||||
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
Tessellator.instance.addVertexWithUV(0, 16, z, icon.getMinU(), icon.getMaxV());
|
||||
|
@ -123,8 +111,7 @@ public final class RenderHelper
|
|||
Tessellator.instance.draw();
|
||||
}
|
||||
|
||||
public static void renderIcon(double x, double y, double z, IIcon icon, int width, int height)
|
||||
{
|
||||
public static void renderIcon(double x, double y, double z, IIcon icon, int width, int height) {
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
|
@ -135,64 +122,53 @@ public final class RenderHelper
|
|||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static final IIcon getFluidTexture(Fluid fluid)
|
||||
{
|
||||
public static final IIcon getFluidTexture(Fluid fluid) {
|
||||
|
||||
if (fluid == null)
|
||||
{
|
||||
if (fluid == null) {
|
||||
return FluidRegistry.LAVA.getIcon();
|
||||
}
|
||||
return fluid.getIcon();
|
||||
}
|
||||
|
||||
public static final IIcon getFluidTexture(FluidStack fluid)
|
||||
{
|
||||
public static final IIcon getFluidTexture(FluidStack fluid) {
|
||||
|
||||
if (fluid == null || fluid.getFluid() == null || fluid.getFluid().getIcon(fluid) == null)
|
||||
{
|
||||
if (fluid == null || fluid.getFluid() == null || fluid.getFluid().getIcon(fluid) == null) {
|
||||
return FluidRegistry.LAVA.getIcon();
|
||||
}
|
||||
return fluid.getFluid().getIcon(fluid);
|
||||
}
|
||||
|
||||
public static final void bindItemTexture(ItemStack stack)
|
||||
{
|
||||
public static final void bindItemTexture(ItemStack stack) {
|
||||
|
||||
engine().bindTexture(stack.getItemSpriteNumber() == 0 ? MC_BLOCK_SHEET : MC_ITEM_SHEET);
|
||||
}
|
||||
|
||||
public static final void bindTexture(ResourceLocation texture)
|
||||
{
|
||||
public static final void bindTexture(ResourceLocation texture) {
|
||||
|
||||
engine().bindTexture(texture);
|
||||
}
|
||||
|
||||
public static final void setBlockTextureSheet()
|
||||
{
|
||||
public static final void setBlockTextureSheet() {
|
||||
|
||||
bindTexture(MC_BLOCK_SHEET);
|
||||
}
|
||||
|
||||
public static final void setItemTextureSheet()
|
||||
{
|
||||
public static final void setItemTextureSheet() {
|
||||
|
||||
bindTexture(MC_ITEM_SHEET);
|
||||
}
|
||||
|
||||
public static final void setDefaultFontTextureSheet()
|
||||
{
|
||||
public static final void setDefaultFontTextureSheet() {
|
||||
|
||||
bindTexture(MC_FONT_DEFAULT);
|
||||
}
|
||||
|
||||
public static final void setSGAFontTextureSheet()
|
||||
{
|
||||
public static final void setSGAFontTextureSheet() {
|
||||
|
||||
bindTexture(MC_FONT_ALTERNATE);
|
||||
}
|
||||
|
||||
public static final void enableGUIStandardItemLighting()
|
||||
{
|
||||
public static final void enableGUIStandardItemLighting() {
|
||||
|
||||
net.minecraft.client.renderer.RenderHelper.enableGUIStandardItemLighting();
|
||||
}
|
||||
|
|
|
@ -1,30 +1,25 @@
|
|||
package techreborn.cofhLib.util;
|
||||
|
||||
public class CharacterSingleton implements CharSequence
|
||||
{
|
||||
public class CharacterSingleton implements CharSequence {
|
||||
|
||||
public char character;
|
||||
|
||||
@Override
|
||||
public int length()
|
||||
{
|
||||
public int length() {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char charAt(int index)
|
||||
{
|
||||
public char charAt(int index) {
|
||||
|
||||
return character;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence subSequence(int start, int end)
|
||||
{
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
|
||||
if (start == end)
|
||||
{
|
||||
if (start == end) {
|
||||
return "";
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -5,21 +5,18 @@ package techreborn.cofhLib.util;
|
|||
*
|
||||
* @author Chicken Bones
|
||||
*/
|
||||
public class Rectangle4i
|
||||
{
|
||||
public class Rectangle4i {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int w;
|
||||
public int h;
|
||||
|
||||
public Rectangle4i()
|
||||
{
|
||||
public Rectangle4i() {
|
||||
|
||||
}
|
||||
|
||||
public Rectangle4i(int x, int y, int w, int h)
|
||||
{
|
||||
public Rectangle4i(int x, int y, int w, int h) {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -27,32 +24,27 @@ public class Rectangle4i
|
|||
this.h = h;
|
||||
}
|
||||
|
||||
public int x1()
|
||||
{
|
||||
public int x1() {
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public int y1()
|
||||
{
|
||||
public int y1() {
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
public int x2()
|
||||
{
|
||||
public int x2() {
|
||||
|
||||
return x + w - 1;
|
||||
}
|
||||
|
||||
public int y2()
|
||||
{
|
||||
public int y2() {
|
||||
|
||||
return y + h - 1;
|
||||
}
|
||||
|
||||
public void set(int x, int y, int w, int h)
|
||||
{
|
||||
public void set(int x, int y, int w, int h) {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -60,81 +52,64 @@ public class Rectangle4i
|
|||
this.h = h;
|
||||
}
|
||||
|
||||
public Rectangle4i offset(int dx, int dy)
|
||||
{
|
||||
public Rectangle4i offset(int dx, int dy) {
|
||||
|
||||
x += dx;
|
||||
y += dy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Rectangle4i include(int px, int py)
|
||||
{
|
||||
public Rectangle4i include(int px, int py) {
|
||||
|
||||
if (px < x)
|
||||
{
|
||||
if (px < x) {
|
||||
expand(px - x, 0);
|
||||
}
|
||||
if (px >= x + w)
|
||||
{
|
||||
if (px >= x + w) {
|
||||
expand(px - x - w + 1, 0);
|
||||
}
|
||||
if (py < y)
|
||||
{
|
||||
if (py < y) {
|
||||
expand(0, py - y);
|
||||
}
|
||||
if (py >= y + h)
|
||||
{
|
||||
if (py >= y + h) {
|
||||
expand(0, py - y - h + 1);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Rectangle4i include(Rectangle4i r)
|
||||
{
|
||||
public Rectangle4i include(Rectangle4i r) {
|
||||
|
||||
include(r.x, r.y);
|
||||
return include(r.x2(), r.y2());
|
||||
}
|
||||
|
||||
public Rectangle4i expand(int px, int py)
|
||||
{
|
||||
public Rectangle4i expand(int px, int py) {
|
||||
|
||||
if (px > 0)
|
||||
{
|
||||
if (px > 0) {
|
||||
w += px;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
x += px;
|
||||
w -= px;
|
||||
}
|
||||
if (py > 0)
|
||||
{
|
||||
if (py > 0) {
|
||||
h += py;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
y += py;
|
||||
h -= py;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean contains(int px, int py)
|
||||
{
|
||||
public boolean contains(int px, int py) {
|
||||
|
||||
return x <= px && px < x + w && y <= py && py < y + h;
|
||||
}
|
||||
|
||||
public boolean intersects(Rectangle4i r)
|
||||
{
|
||||
public boolean intersects(Rectangle4i r) {
|
||||
|
||||
return r.x + r.w > x && r.x < x + w && r.y + r.h > y && r.y < y + h;
|
||||
}
|
||||
|
||||
public int area()
|
||||
{
|
||||
public int area() {
|
||||
|
||||
return w * h;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,9 @@ import java.util.Random;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public final class MathHelper
|
||||
{
|
||||
public final class MathHelper {
|
||||
|
||||
private MathHelper()
|
||||
{
|
||||
private MathHelper() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,10 +17,8 @@ public final class MathHelper
|
|||
public static final double PHI = 1.618034;
|
||||
public static final double[] SIN_TABLE = new double[65536];
|
||||
|
||||
static
|
||||
{
|
||||
for (int i = 0; i < 65536; i++)
|
||||
{
|
||||
static {
|
||||
for (int i = 0; i < 65536; i++) {
|
||||
SIN_TABLE[i] = Math.sin(i / 65536D * 2 * Math.PI);
|
||||
}
|
||||
SIN_TABLE[0] = 0;
|
||||
|
@ -31,113 +27,93 @@ public final class MathHelper
|
|||
SIN_TABLE[49152] = 1;
|
||||
}
|
||||
|
||||
public static double sin(double d)
|
||||
{
|
||||
public static double sin(double d) {
|
||||
|
||||
return SIN_TABLE[(int) ((float) d * 10430.378F) & 65535];
|
||||
}
|
||||
|
||||
public static double cos(double d)
|
||||
{
|
||||
public static double cos(double d) {
|
||||
|
||||
return SIN_TABLE[(int) ((float) d * 10430.378F + 16384.0F) & 65535];
|
||||
}
|
||||
|
||||
public static int clampI(int a, int min, int max)
|
||||
{
|
||||
public static int clampI(int a, int min, int max) {
|
||||
|
||||
return a < min ? min : (a > max ? max : a);
|
||||
}
|
||||
|
||||
public static float clampF(float a, float min, float max)
|
||||
{
|
||||
public static float clampF(float a, float min, float max) {
|
||||
|
||||
return a < min ? min : (a > max ? max : a);
|
||||
}
|
||||
|
||||
public static float approachLinear(float a, float b, float max)
|
||||
{
|
||||
public static float approachLinear(float a, float b, float max) {
|
||||
|
||||
return a > b ? a - b < max ? b : a - max : b - a < max ? b : a + max;
|
||||
}
|
||||
|
||||
public static double approachLinear(double a, double b, double max)
|
||||
{
|
||||
public static double approachLinear(double a, double b, double max) {
|
||||
|
||||
return a > b ? a - b < max ? b : a - max : b - a < max ? b : a + max;
|
||||
}
|
||||
|
||||
public static float interpolate(float a, float b, float d)
|
||||
{
|
||||
public static float interpolate(float a, float b, float d) {
|
||||
|
||||
return a + (b - a) * d;
|
||||
}
|
||||
|
||||
public static double interpolate(double a, double b, double d)
|
||||
{
|
||||
public static double interpolate(double a, double b, double d) {
|
||||
|
||||
return a + (b - a) * d;
|
||||
}
|
||||
|
||||
public static double approachExp(double a, double b, double ratio)
|
||||
{
|
||||
public static double approachExp(double a, double b, double ratio) {
|
||||
|
||||
return a + (b - a) * ratio;
|
||||
}
|
||||
|
||||
public static double approachExp(double a, double b, double ratio, double cap)
|
||||
{
|
||||
public static double approachExp(double a, double b, double ratio, double cap) {
|
||||
|
||||
double d = (b - a) * ratio;
|
||||
|
||||
if (Math.abs(d) > cap)
|
||||
{
|
||||
if (Math.abs(d) > cap) {
|
||||
d = Math.signum(d) * cap;
|
||||
}
|
||||
return a + d;
|
||||
}
|
||||
|
||||
public static double retreatExp(double a, double b, double c, double ratio, double kick)
|
||||
{
|
||||
public static double retreatExp(double a, double b, double c, double ratio, double kick) {
|
||||
|
||||
double d = (Math.abs(c - a) + kick) * ratio;
|
||||
|
||||
if (d > Math.abs(b - a))
|
||||
{
|
||||
if (d > Math.abs(b - a)) {
|
||||
return b;
|
||||
}
|
||||
return a + Math.signum(b - a) * d;
|
||||
}
|
||||
|
||||
public static double clip(double value, double min, double max)
|
||||
{
|
||||
public static double clip(double value, double min, double max) {
|
||||
|
||||
if (value > max)
|
||||
{
|
||||
if (value > max) {
|
||||
value = max;
|
||||
}
|
||||
else if (value < min)
|
||||
{
|
||||
} else if (value < min) {
|
||||
value = min;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean between(double a, double x, double b)
|
||||
{
|
||||
public static boolean between(double a, double x, double b) {
|
||||
|
||||
return a <= x && x <= b;
|
||||
}
|
||||
|
||||
public static int approachExpI(int a, int b, double ratio)
|
||||
{
|
||||
public static int approachExpI(int a, int b, double ratio) {
|
||||
|
||||
int r = (int) Math.round(approachExp(a, b, ratio));
|
||||
return r == a ? b : r;
|
||||
}
|
||||
|
||||
public static int retreatExpI(int a, int b, int c, double ratio, int kick)
|
||||
{
|
||||
public static int retreatExpI(int a, int b, int c, double ratio, int kick) {
|
||||
|
||||
int r = (int) Math.round(retreatExp(a, b, c, ratio, kick));
|
||||
return r == a ? b : r;
|
||||
|
@ -146,8 +122,7 @@ public final class MathHelper
|
|||
/**
|
||||
* Unchecked implementation to round a number. Parameter should be known to be valid in advance.
|
||||
*/
|
||||
public static int round(double d)
|
||||
{
|
||||
public static int round(double d) {
|
||||
|
||||
return (int) (d + 0.5D);
|
||||
}
|
||||
|
@ -155,8 +130,7 @@ public final class MathHelper
|
|||
/**
|
||||
* Unchecked implementation to round a number up. Parameter should be known to be valid in advance.
|
||||
*/
|
||||
public static int ceil(double d)
|
||||
{
|
||||
public static int ceil(double d) {
|
||||
|
||||
return (int) (d + 0.9999D);
|
||||
}
|
||||
|
@ -164,8 +138,7 @@ public final class MathHelper
|
|||
/**
|
||||
* Unchecked implementation to round a number down. Parameter should be known to be valid in advance.
|
||||
*/
|
||||
public static int floor(double d)
|
||||
{
|
||||
public static int floor(double d) {
|
||||
|
||||
int i = (int) d;
|
||||
return d < i ? i - 1 : i;
|
||||
|
@ -174,20 +147,17 @@ public final class MathHelper
|
|||
/**
|
||||
* Unchecked implementation to determine the smaller of two Floats. Parameters should be known to be valid in advance.
|
||||
*/
|
||||
public static float minF(float a, float b)
|
||||
{
|
||||
public static float minF(float a, float b) {
|
||||
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
public static float minF(int a, float b)
|
||||
{
|
||||
public static float minF(int a, float b) {
|
||||
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
public static float minF(float a, int b)
|
||||
{
|
||||
public static float minF(float a, int b) {
|
||||
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
@ -195,47 +165,39 @@ public final class MathHelper
|
|||
/**
|
||||
* Unchecked implementation to determine the larger of two Floats. Parameters should be known to be valid in advance.
|
||||
*/
|
||||
public static float maxF(float a, float b)
|
||||
{
|
||||
public static float maxF(float a, float b) {
|
||||
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static float maxF(int a, float b)
|
||||
{
|
||||
public static float maxF(int a, float b) {
|
||||
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static float maxF(float a, int b)
|
||||
{
|
||||
public static float maxF(float a, int b) {
|
||||
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static double maxAbs(double a, double b)
|
||||
{
|
||||
public static double maxAbs(double a, double b) {
|
||||
|
||||
if (a < 0.0D)
|
||||
{
|
||||
if (a < 0.0D) {
|
||||
a = -a;
|
||||
}
|
||||
if (b < 0.0D)
|
||||
{
|
||||
if (b < 0.0D) {
|
||||
b = -b;
|
||||
}
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static int setBit(int mask, int bit, boolean value)
|
||||
{
|
||||
public static int setBit(int mask, int bit, boolean value) {
|
||||
|
||||
mask |= (value ? 1 : 0) << bit;
|
||||
return mask;
|
||||
}
|
||||
|
||||
public static boolean isBitSet(int mask, int bit)
|
||||
{
|
||||
public static boolean isBitSet(int mask, int bit) {
|
||||
|
||||
return (mask & 1 << bit) != 0;
|
||||
}
|
||||
|
|
|
@ -15,75 +15,60 @@ import java.util.List;
|
|||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public final class StringHelper
|
||||
{
|
||||
public final class StringHelper {
|
||||
|
||||
private StringHelper()
|
||||
{
|
||||
private StringHelper() {
|
||||
|
||||
}
|
||||
|
||||
/* KEY HELPERS */
|
||||
public static boolean isAltKeyDown()
|
||||
{
|
||||
public static boolean isAltKeyDown() {
|
||||
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
|
||||
}
|
||||
|
||||
public static boolean isControlKeyDown()
|
||||
{
|
||||
public static boolean isControlKeyDown() {
|
||||
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
|
||||
}
|
||||
|
||||
public static boolean isShiftKeyDown()
|
||||
{
|
||||
public static boolean isShiftKeyDown() {
|
||||
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
|
||||
/* FORMAT HELPERS */
|
||||
public static int getSplitStringHeight(FontRenderer fontRenderer, String input, int width)
|
||||
{
|
||||
public static int getSplitStringHeight(FontRenderer fontRenderer, String input, int width) {
|
||||
|
||||
@SuppressWarnings("rawtypes") List stringRows = fontRenderer.listFormattedStringToWidth(input, width);
|
||||
return stringRows.size() * fontRenderer.FONT_HEIGHT;
|
||||
}
|
||||
|
||||
public static String camelCase(String input)
|
||||
{
|
||||
public static String camelCase(String input) {
|
||||
|
||||
return input.substring(0, 1).toLowerCase() + input.substring(1);
|
||||
}
|
||||
|
||||
public static String titleCase(String input)
|
||||
{
|
||||
public static String titleCase(String input) {
|
||||
|
||||
return input.substring(0, 1).toUpperCase() + input.substring(1);
|
||||
}
|
||||
|
||||
public static String localize(String key)
|
||||
{
|
||||
public static String localize(String key) {
|
||||
|
||||
return StatCollector.translateToLocal(key);
|
||||
}
|
||||
|
||||
public static String getFluidName(FluidStack stack)
|
||||
{
|
||||
public static String getFluidName(FluidStack stack) {
|
||||
|
||||
Fluid fluid = stack.getFluid();
|
||||
|
||||
String name = "" + END;
|
||||
if (fluid.getRarity() == EnumRarity.uncommon)
|
||||
{
|
||||
if (fluid.getRarity() == EnumRarity.uncommon) {
|
||||
name += YELLOW;
|
||||
}
|
||||
else if (fluid.getRarity() == EnumRarity.rare)
|
||||
{
|
||||
} else if (fluid.getRarity() == EnumRarity.rare) {
|
||||
name += BRIGHT_BLUE;
|
||||
}
|
||||
else if (fluid.getRarity() == EnumRarity.epic)
|
||||
{
|
||||
} else if (fluid.getRarity() == EnumRarity.epic) {
|
||||
name += PINK;
|
||||
}
|
||||
name += fluid.getLocalizedName(stack) + END;
|
||||
|
@ -91,30 +76,22 @@ public final class StringHelper
|
|||
return name;
|
||||
}
|
||||
|
||||
public static String getFluidName(FluidStack stack, String defaultName)
|
||||
{
|
||||
public static String getFluidName(FluidStack stack, String defaultName) {
|
||||
|
||||
if (stack == null)
|
||||
{
|
||||
if (stack == null) {
|
||||
return defaultName;
|
||||
}
|
||||
return getFluidName(stack);
|
||||
}
|
||||
|
||||
public static String getItemName(ItemStack stack)
|
||||
{
|
||||
public static String getItemName(ItemStack stack) {
|
||||
|
||||
String name = "" + END;
|
||||
if (stack.getRarity() == EnumRarity.uncommon)
|
||||
{
|
||||
if (stack.getRarity() == EnumRarity.uncommon) {
|
||||
name += YELLOW;
|
||||
}
|
||||
else if (stack.getRarity() == EnumRarity.rare)
|
||||
{
|
||||
} else if (stack.getRarity() == EnumRarity.rare) {
|
||||
name += BRIGHT_BLUE;
|
||||
}
|
||||
else if (stack.getRarity() == EnumRarity.epic)
|
||||
{
|
||||
} else if (stack.getRarity() == EnumRarity.epic) {
|
||||
name += PINK;
|
||||
}
|
||||
name += stack.getDisplayName() + END;
|
||||
|
@ -122,64 +99,49 @@ public final class StringHelper
|
|||
return name;
|
||||
}
|
||||
|
||||
public static String getScaledNumber(long number)
|
||||
{
|
||||
public static String getScaledNumber(long number) {
|
||||
|
||||
if (number >= 1000000000)
|
||||
{
|
||||
if (number >= 1000000000) {
|
||||
return number / 1000000000 + "." + (number % 1000000000 / 10000000) + "G";
|
||||
}
|
||||
else if (number >= 1000000)
|
||||
{
|
||||
} else if (number >= 1000000) {
|
||||
return number / 1000000 + "." + (number % 1000000 / 10000) + "M";
|
||||
}
|
||||
else if (number >= 1000)
|
||||
{
|
||||
} else if (number >= 1000) {
|
||||
return number / 1000 + "." + (number % 1000 / 10) + "k";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return String.valueOf(number);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getScaledNumber(long number, int minDigits)
|
||||
{
|
||||
public static String getScaledNumber(long number, int minDigits) {
|
||||
|
||||
return getScaledNumber(number);
|
||||
}
|
||||
|
||||
/* ITEM TEXT HELPERS */
|
||||
public static String getActivationText(String key)
|
||||
{
|
||||
public static String getActivationText(String key) {
|
||||
|
||||
return BRIGHT_BLUE + localize(key) + END;
|
||||
}
|
||||
|
||||
public static String getDeactivationText(String key)
|
||||
{
|
||||
public static String getDeactivationText(String key) {
|
||||
|
||||
return YELLOW + localize(key) + END;
|
||||
}
|
||||
|
||||
public static String getInfoText(String key)
|
||||
{
|
||||
public static String getInfoText(String key) {
|
||||
|
||||
return BRIGHT_GREEN + localize(key) + END;
|
||||
}
|
||||
|
||||
public static String getFlavorText(String key)
|
||||
{
|
||||
public static String getFlavorText(String key) {
|
||||
|
||||
return LIGHT_GRAY + ITALIC + localize(key) + END;
|
||||
}
|
||||
|
||||
public static String getRarity(int level)
|
||||
{
|
||||
public static String getRarity(int level) {
|
||||
|
||||
switch (level)
|
||||
{
|
||||
switch (level) {
|
||||
case 2:
|
||||
return StringHelper.YELLOW;
|
||||
case 3:
|
||||
|
@ -189,45 +151,38 @@ public final class StringHelper
|
|||
}
|
||||
}
|
||||
|
||||
public static String shiftForDetails()
|
||||
{
|
||||
public static String shiftForDetails() {
|
||||
|
||||
return LIGHT_GRAY + localize("info.cofh.hold") + " " + YELLOW + ITALIC + localize("info.cofh.shift") + " " + END + LIGHT_GRAY + localize("info.cofh.forDetails") + END;
|
||||
}
|
||||
|
||||
/* TUTORIAL TAB HELPERS */
|
||||
public static String tutorialTabAugment()
|
||||
{
|
||||
public static String tutorialTabAugment() {
|
||||
|
||||
return localize("info.cofh.tutorial.tabAugment");
|
||||
}
|
||||
|
||||
public static String tutorialTabConfiguration()
|
||||
{
|
||||
public static String tutorialTabConfiguration() {
|
||||
|
||||
return localize("info.cofh.tutorial.tabConfiguration.0");
|
||||
}
|
||||
|
||||
public static String tutorialTabOperation()
|
||||
{
|
||||
public static String tutorialTabOperation() {
|
||||
|
||||
return localize("info.cofh.tutorial.tabConfiguration.1");
|
||||
}
|
||||
|
||||
public static String tutorialTabRedstone()
|
||||
{
|
||||
public static String tutorialTabRedstone() {
|
||||
|
||||
return localize("info.cofh.tutorial.tabRedstone");
|
||||
}
|
||||
|
||||
public static String tutorialTabSecurity()
|
||||
{
|
||||
public static String tutorialTabSecurity() {
|
||||
|
||||
return localize("info.cofh.tutorial.tabSecurity");
|
||||
}
|
||||
|
||||
public static String tutorialTabFluxRequired()
|
||||
{
|
||||
public static String tutorialTabFluxRequired() {
|
||||
|
||||
return localize("info.cofh.tutorial.fluxRequired");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue