mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-26 09:12:56 +00:00
Refactor GuiLabel
This commit is contained in:
1 parent
1673bd5109
commit
fa95cf0f1b
1 file changed
+59
-61
@@ -1,11 +1,11 @@
|
|||||||
package com.falsepattern.lib.compat;
|
package com.falsepattern.lib.compat;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import lombok.*;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.client.gui.Gui;
|
import net.minecraft.client.gui.Gui;
|
||||||
@@ -15,81 +15,79 @@ import org.lwjgl.opengl.GL11;
|
|||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiLabel extends Gui {
|
public class GuiLabel extends Gui {
|
||||||
|
private final List<String> lines = new ArrayList<>();
|
||||||
|
private final FontRenderer fontRenderer;
|
||||||
|
private final int textColor;
|
||||||
|
|
||||||
|
private boolean centered = false;
|
||||||
protected int width;
|
protected int width;
|
||||||
protected int height;
|
protected int height;
|
||||||
|
public int id;
|
||||||
public int x;
|
public int x;
|
||||||
public int y;
|
public int y;
|
||||||
private final List<String> labels;
|
|
||||||
public int id;
|
|
||||||
private boolean centered;
|
|
||||||
public boolean visible = true;
|
public boolean visible = true;
|
||||||
private final boolean labelBgEnabled;
|
|
||||||
private final int textColor;
|
|
||||||
private final int backColor;
|
|
||||||
private final int ulColor;
|
|
||||||
private final int brColor;
|
|
||||||
private final FontRenderer fontRenderer;
|
|
||||||
private final int border;
|
|
||||||
|
|
||||||
public GuiLabel(FontRenderer fontRendererObj, int p_i45540_2_, int p_i45540_3_, int p_i45540_4_, int p_i45540_5_, int p_i45540_6_, int p_i45540_7_) {
|
/**
|
||||||
this.fontRenderer = fontRendererObj;
|
* Instantiates a new Gui label.
|
||||||
this.id = p_i45540_2_;
|
*
|
||||||
this.x = p_i45540_3_;
|
* @param fontRenderer the minecraft font renderer
|
||||||
this.y = p_i45540_4_;
|
* @param id the id
|
||||||
this.width = p_i45540_5_;
|
* @param x the x
|
||||||
this.height = p_i45540_6_;
|
* @param y the y
|
||||||
this.labels = Lists.newArrayList();
|
* @param width the width
|
||||||
this.centered = false;
|
* @param height the height
|
||||||
this.labelBgEnabled = false;
|
* @param textColour the text colour
|
||||||
this.textColor = p_i45540_7_;
|
*/
|
||||||
this.backColor = -1;
|
public GuiLabel(@NonNull FontRenderer fontRenderer, int id, int x, int y, int width, int height, int textColour) {
|
||||||
this.ulColor = -1;
|
this.fontRenderer = fontRenderer;
|
||||||
this.brColor = -1;
|
this.id = id;
|
||||||
this.border = 0;
|
this.x = x;
|
||||||
}
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
public void addLine(String p_175202_1_) {
|
this.height = height;
|
||||||
this.labels.add(I18n.format(p_175202_1_));
|
this.textColor = textColour;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Label to be centered
|
* Add a line of text to the GuiLabel.
|
||||||
|
*
|
||||||
|
* @param text string to add.
|
||||||
|
*/
|
||||||
|
public void addLine(@NonNull String text) {
|
||||||
|
lines.add(I18n.format(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the label text to render centred with respect to the x and y.
|
||||||
|
*
|
||||||
|
* @return the GuiLabel.
|
||||||
*/
|
*/
|
||||||
public GuiLabel setCentered() {
|
public GuiLabel setCentered() {
|
||||||
this.centered = true;
|
centered = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawLabel(Minecraft mc, int mouseX, int mouseY) {
|
|
||||||
if (this.visible) {
|
|
||||||
GL11.glEnable(GL11.GL_BLEND);
|
|
||||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
|
||||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
this.drawLabelBackground(mc, mouseX, mouseY);
|
|
||||||
int i = this.y + this.height / 2 + this.border / 2;
|
|
||||||
int j = i - this.labels.size() * 10 / 2;
|
|
||||||
|
|
||||||
for (int k = 0; k < this.labels.size(); ++k) {
|
/**
|
||||||
if (this.centered) {
|
* Draw label.
|
||||||
this.drawCenteredString(this.fontRenderer, this.labels.get(k), this.x + this.width / 2, j + k * 10, this.textColor);
|
*
|
||||||
} else {
|
* @param minecraft the minecraft
|
||||||
this.drawString(this.fontRenderer, this.labels.get(k), this.x, j + k * 10, this.textColor);
|
* @param mouseX the mouse x
|
||||||
}
|
* @param mouseY the mouse y
|
||||||
|
*/
|
||||||
|
public void drawLabel(@NonNull Minecraft minecraft, int mouseX, int mouseY) {
|
||||||
|
if (!visible)
|
||||||
|
return;
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
|
||||||
|
|
||||||
|
val topLeftY = y + height / 2 - lines.size() * 10 / 2;
|
||||||
|
for (var i = 0; i < lines.size(); ++i) {
|
||||||
|
if (centered) {
|
||||||
|
drawCenteredString(fontRenderer, lines.get(i), x + width / 2, topLeftY + i * 10, textColor);
|
||||||
|
} else {
|
||||||
|
drawString(fontRenderer, lines.get(i), x, topLeftY + i * 10, textColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void drawLabelBackground(Minecraft mcIn, int mouseX, int mouseY) {
|
|
||||||
if (this.labelBgEnabled) {
|
|
||||||
int i = this.width + this.border * 2;
|
|
||||||
int j = this.height + this.border * 2;
|
|
||||||
int k = this.x - this.border;
|
|
||||||
int l = this.y - this.border;
|
|
||||||
drawRect(k, l, k + i, l + j, this.backColor);
|
|
||||||
this.drawHorizontalLine(k, k + i, l, this.ulColor);
|
|
||||||
this.drawHorizontalLine(k, k + i, l + j, this.brColor);
|
|
||||||
this.drawVerticalLine(k, l, l + j, this.ulColor);
|
|
||||||
this.drawVerticalLine(k + i, l, l + j, this.brColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user