Made color and alpha components global among ScriptOverlay classes.

This commit is contained in:
luisc committed 2022-01-30 04:33:00 -06:00
1 parent 534f716991
commit be61bd4e17
11 files changed
+71 -37

No files matched your search

@@ -21,6 +21,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent {
int x, y, width, height;
String fullLabel;
int color;
float alpha;
String[] hoverText;
float scale;
int border = 2;
@@ -77,6 +78,8 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent {
lbl.labelShadowEnabled = component.hasShadow();
lbl.alignment = component.getAlignment();
lbl.alpha = component.getAlpha();
lbl.color = component.getColor();
return lbl;
}
@@ -85,6 +88,8 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent {
ScriptOverlayLabel component = new ScriptOverlayLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color);
component.enableShadow(this.labelShadowEnabled);
component.setAlignment(alignment);
component.setAlpha(alpha);
component.setColor(color);
return component;
}
@@ -98,6 +103,11 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent {
this.drawLabelBackground();
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2
GL11.glTranslatef(this.x,this.y,0.0F);
@@ -20,6 +20,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent {
int y2;
int color;
int thickness;
float alpha;
public CustomOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){
this.id = id;
@@ -42,16 +43,16 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent {
public void onRender(Minecraft mc, float partialTicks) {
double distance = Math.hypot(x1-x2, y1-y2);
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png"));
GL11.glPushMatrix();
GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glColor4f(red,green,blue,1.0F);
GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2
GL11.glTranslatef(this.x1,this.y1,0.0F);
GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F);
GL11.glScaled(thickness, distance,0.0D);
this.drawTexturedModalRect(0,0,0,0, 1, 1);
@@ -61,12 +62,16 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent {
public ICustomOverlayComponent toComponent() {
ScriptOverlayLine line = new ScriptOverlayLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness);
line.setAlignment(alignment);
line.setAlpha(alpha);
line.setColor(color);
return line;
}
public static CustomOverlayLine fromComponent(ScriptOverlayLine component) {
CustomOverlayLine line = new CustomOverlayLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness());
line.alignment = component.getAlignment();
line.alpha = component.getAlpha();
line.color = component.getColor();
return line;
}
@@ -23,6 +23,9 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent
int textureY;
float scale;
int color;
float alpha;
public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0);
}
@@ -52,9 +55,13 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent
mc.getTextureManager().bindTexture(this.texture);
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2
GL11.glColor4f(1.0F,1.0F,1.0F,1.0F);
GL11.glScalef(this.scale, this.scale, this.scale);
this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height));
GL11.glPopMatrix();
@@ -62,8 +69,10 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent
public ICustomOverlayComponent toComponent() {
ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY);
component.setScale(this.scale);
component.setScale(scale);
component.setAlignment(alignment);
component.setAlpha(alpha);
component.setColor(color);
return component;
}
@@ -77,6 +86,8 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent
rect.scale = component.getScale();
rect.alignment = component.getAlignment();
rect.alpha = component.getAlpha();
rect.color = component.getColor();
return rect;
}
@@ -100,7 +100,7 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel {
this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]);
this.setColor(nbt.getInteger("color"));
this.setScale(nbt.getFloat("scale"));
this.enableShadow(this.shadow);
this.enableShadow(nbt.getBoolean("shadow"));
return this;
}
}
@@ -14,4 +14,12 @@ public interface ICustomOverlayComponent {
int getAlignment();
void setAlignment(int alignment);
int getColor();
ICustomOverlayComponent setColor(int color);
float getAlpha();
void setAlpha(float alpha);
}
@@ -11,10 +11,6 @@ public interface IOverlayLabel extends ICustomOverlayComponent {
IOverlayLabel setSize(int var1, int var2);
int getColor();
IOverlayLabel setColor(int var1);
float getScale();
IOverlayLabel setScale(float var1);
@@ -1,17 +1,17 @@
package noppes.npcs.scripted.interfaces;
import noppes.npcs.scripted.overlay.ScriptOverlayLine;
public interface IOverlayLine extends ICustomOverlayComponent {
int getX1();
int getY1();
int getX2();
int getY2();
int getColor();
int getThickness();
void setX1(int x1);
void setY1(int y1);
void setX2(int x2);
void setY2(int y2);
void setColor(int color);
void setThickness(int thickness);
}
@@ -6,12 +6,15 @@ import net.minecraft.nbt.NBTTagString;
import noppes.npcs.scripted.gui.*;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import noppes.npcs.scripted.interfaces.ICustomOverlayComponent;
import noppes.npcs.scripted.interfaces.IOverlayTexturedRect;
public abstract class ScriptOverlayComponent implements ICustomOverlayComponent {
int id;
int posX;
int posY;
int alignment = 0;
int color = 0xFFFFFF;
float alpha = 1.0F;
/* ========ALIGNMENTS========
0 1 2
@@ -54,12 +57,31 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent
this.alignment = alignment;
}
public int getColor() {
return this.color;
}
public ICustomOverlayComponent setColor(int color) {
this.color = color;
return this;
}
public float getAlpha() {
return this.alpha;
}
public void setAlpha(float alpha) {
this.alpha = alpha;
}
public abstract int getType();
public NBTTagCompound toNBT(NBTTagCompound nbt) {
nbt.setInteger("id", this.id);
nbt.setIntArray("pos", new int[]{this.posX, this.posY});
nbt.setInteger("alignment",this.alignment);
nbt.setInteger("color", this.color);
nbt.setFloat("alpha",this.alpha);
nbt.setInteger("type", this.getType());
return nbt;
@@ -69,6 +91,8 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent
this.setID(nbt.getInteger("id"));
this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]);
this.setAlignment(nbt.getInteger("alignment"));
this.setColor(nbt.getInteger("color"));
this.setAlpha(nbt.getInteger("alpha"));
return this;
}
@@ -9,7 +9,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl
String label;
int width;
int height;
int color;
float scale;
boolean shadow;
@@ -56,15 +55,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl
return this;
}
public int getColor() {
return this.color;
}
public IOverlayLabel setColor(int color) {
this.color = color;
return this;
}
public float getScale() {
return this.scale;
}
@@ -91,7 +81,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl
super.toNBT(nbt);
nbt.setString("label", this.label);
nbt.setIntArray("size", new int[]{this.width, this.height});
nbt.setInteger("color", this.color);
nbt.setFloat("scale", this.scale);
nbt.setBoolean("shadow",this.shadow);
return nbt;
@@ -101,9 +90,8 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl
super.fromNBT(nbt);
this.setText(nbt.getString("label"));
this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]);
this.setColor(nbt.getInteger("color"));
this.setScale(nbt.getFloat("scale"));
this.enableShadow(this.shadow);
this.enableShadow(nbt.getBoolean("shadow"));
return this;
}
}
@@ -9,7 +9,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla
int y1;
int x2;
int y2;
int color = 0;
int thickness = 2;
public ScriptOverlayLine(){
@@ -48,7 +47,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla
nbt.setInteger("Y1",y1);
nbt.setInteger("X2",x2);
nbt.setInteger("Y2",y2);
nbt.setInteger("Color",color);
nbt.setInteger("Thickness",thickness);
return nbt;
@@ -60,7 +58,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla
y1 = nbt.getInteger("Y1");
x2 = nbt.getInteger("X2");
y2 = nbt.getInteger("Y2");
color = nbt.getInteger("Color");
thickness = nbt.getInteger("Thickness");
return this;
@@ -78,9 +75,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla
public int getY2(){
return this.y2;
}
public int getColor(){
return this.color;
}
public int getThickness(){
return this.thickness;
}
@@ -97,9 +91,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla
public void setY2(int y2){
this.y2 = y2;
}
public void setColor(int color){
this.color = color;
}
public void setThickness(int thickness){
this.thickness = thickness;
}
@@ -2,6 +2,7 @@ package noppes.npcs.scripted.overlay;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.gui.ScriptGuiComponent;
import noppes.npcs.scripted.interfaces.IOverlayLabel;
import noppes.npcs.scripted.interfaces.IOverlayTexturedRect;
import noppes.npcs.scripted.interfaces.ITexturedRect;