Changed GuiRenderSettings to have "Advanced" settings
Added GuiColorPicker and implemented it for Greenscreen color choosing
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiColorPicker extends GuiButton {
|
||||
|
||||
private final int PICKER_SIZE = 100;
|
||||
|
||||
private boolean pickerVisible = false;
|
||||
private int pickedColor = Color.BLACK.getRGB();
|
||||
|
||||
public int pickerX, pickerY;
|
||||
|
||||
public GuiColorPicker(int buttonId, int x, int y, String text, int pickerX, int pickerY) {
|
||||
super(buttonId, x, y, text);
|
||||
this.pickerX = pickerX;
|
||||
this.pickerY = pickerY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if(this.visible) {
|
||||
FontRenderer fontrenderer = mc.fontRendererObj;
|
||||
mc.getTextureManager().bindTexture(buttonTextures);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
||||
int k = this.getHoverState(this.hovered);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlStateManager.blendFunc(770, 771);
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
|
||||
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
int l = 14737632;
|
||||
|
||||
if (packedFGColour != 0) {
|
||||
l = packedFGColour;
|
||||
}
|
||||
else if (!this.enabled) {
|
||||
l = 10526880;
|
||||
}
|
||||
else if (this.hovered) {
|
||||
l = 16777120;
|
||||
}
|
||||
|
||||
int strWidth = fontrenderer.getStringWidth(this.displayString);
|
||||
|
||||
this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2 - 10, this.yPosition + (this.height - 8) / 2, l);
|
||||
this.drawGradientRect(this.xPosition + (width+strWidth)/2, this.yPosition + 5, this.xPosition + (width+strWidth)/2 + 10,
|
||||
this.yPosition + 5 + 10, pickedColor, pickedColor);
|
||||
|
||||
if(pickerVisible && this.enabled) {
|
||||
for(int x=0; x < PICKER_SIZE; x++) {
|
||||
for(int y=0; y < PICKER_SIZE; y++) {
|
||||
int color = getColorAtPosition(x, y);
|
||||
this.drawGradientRect(pickerX+x, pickerY+y, pickerX+x+1, pickerY+y+1, color, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
||||
if(pickerVisible && this.enabled) {
|
||||
if(MouseUtils.isMouseWithinBounds(pickerX, pickerY, PICKER_SIZE, PICKER_SIZE)) {
|
||||
Point mousePoint = MouseUtils.getMousePos();
|
||||
setPickerColor(getColorAtPosition(mousePoint.getX() - pickerX, mousePoint.getY() - pickerY));
|
||||
}
|
||||
}
|
||||
return super.mousePressed(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
|
||||
if(Mouse.isButtonDown(0)) mousePressed(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void pickerToggled() {
|
||||
pickerVisible = !pickerVisible;
|
||||
}
|
||||
|
||||
private int getColorAtPosition(int x, int y) {
|
||||
if(x < 0 || x > PICKER_SIZE || y < 0 || y > PICKER_SIZE) return 0;
|
||||
|
||||
boolean grey = x >= (PICKER_SIZE-5);
|
||||
|
||||
float h = grey ? 0 : (float)x / (PICKER_SIZE - 5);
|
||||
float s = grey ? 0 : y <= (PICKER_SIZE/2) ? (float)y / (PICKER_SIZE/2) : 1;
|
||||
float v = grey ? 1 - ((float)y / PICKER_SIZE) : y > (PICKER_SIZE/2) ? 1 - ((float)(y-(PICKER_SIZE/2)) / (PICKER_SIZE/2f)) : 1;
|
||||
|
||||
return Color.HSBtoRGB(h, s, v);
|
||||
}
|
||||
|
||||
public void setPickerColor(int color) {
|
||||
this.pickedColor = color;
|
||||
}
|
||||
|
||||
public int getPickedColor() {
|
||||
return pickedColor & 0xffffff;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiDropdown<T> extends GuiTextField {
|
||||
@@ -22,6 +26,7 @@ public class GuiDropdown<T> extends GuiTextField {
|
||||
|
||||
private int upperIndex = 0;
|
||||
private List<T> elements = new ArrayList<T>();
|
||||
private HashMap<Integer, String> hoverTexts = new HashMap<Integer, String>();
|
||||
|
||||
public GuiDropdown(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int visibleDropout) {
|
||||
@@ -49,6 +54,10 @@ public class GuiDropdown<T> extends GuiTextField {
|
||||
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 4, yPosition + (height / 4) + i + 2, -6250336);
|
||||
}
|
||||
|
||||
boolean drawHover = false;
|
||||
Point hoverPos = null;
|
||||
String hoverText = null;
|
||||
|
||||
if(open && elements.size() > 0) {
|
||||
//draw the dropout part when opened
|
||||
|
||||
@@ -78,6 +87,16 @@ public class GuiDropdown<T> extends GuiTextField {
|
||||
String toWrite = mc.fontRendererObj.trimStringToWidth(obj.toString(), width - 8);
|
||||
drawString(mc.fontRendererObj, toWrite, xPosition + 4, yPosition + height + y + 4, Color.WHITE.getRGB());
|
||||
|
||||
if(MouseUtils.isMouseWithinBounds(xPosition, yPosition + height + y, width, dropoutElementHeight)) {
|
||||
String hover = hoverTexts.get(i);
|
||||
if(hover != null) {
|
||||
Point mousePos = MouseUtils.getMousePos();
|
||||
drawHover = true;
|
||||
hoverPos = mousePos;
|
||||
hoverText = hover;
|
||||
}
|
||||
}
|
||||
|
||||
y += dropoutElementHeight;
|
||||
i++;
|
||||
if(y >= requiredHeight) {
|
||||
@@ -106,6 +125,10 @@ public class GuiDropdown<T> extends GuiTextField {
|
||||
|
||||
drawRect(xPosition + width - 3, yPosition + height + barY, xPosition + width, yPosition + height + 2 + barY + barHeight, -6250336);
|
||||
}
|
||||
|
||||
if(drawHover) {
|
||||
ReplayMod.tooltipRenderer.drawTooltip(hoverPos.getX(), hoverPos.getY(), hoverText, null, Color.WHITE.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +185,10 @@ public class GuiDropdown<T> extends GuiTextField {
|
||||
}
|
||||
}
|
||||
|
||||
public void setHoverText(int index, String text) {
|
||||
hoverTexts.put(index, text);
|
||||
}
|
||||
|
||||
public T getElement(int index) {
|
||||
return elements.get(index);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
public class GuiToggleButton extends GuiButton {
|
||||
|
||||
private String baseText;
|
||||
private String[] values;
|
||||
private int value;
|
||||
|
||||
public GuiToggleButton(int buttonId, int x, int y, String buttonText, String[] values) {
|
||||
super(buttonId, x, y, buttonText);
|
||||
this.values = values;
|
||||
this.baseText = buttonText;
|
||||
this.value = 0;
|
||||
if(values.length <= 1) {
|
||||
throw new RuntimeException("At least two elements need to be added to a GuiToggleButton");
|
||||
}
|
||||
|
||||
this.displayString = baseText+values[value];
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
value++;
|
||||
if(value >= values.length) value = 0;
|
||||
this.displayString = baseText+values[value];
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user