mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 00:35:06 +00:00
Added Custom GUI Lines, with configurable thickness & color. Draws a line between one point defined by (x1,y1), and another defined by (x2,y2)
This commit is contained in:
1 parent
fcaafe4b26
commit
8b24dad211
7 files changed
+212
-10
No files matched your search
@@ -429,6 +429,11 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD
|
||||
this.components.put(scroll.getID(), scroll);
|
||||
this.addDataHolder(scroll);
|
||||
this.addClickListener(scroll);
|
||||
break;
|
||||
case 6:
|
||||
CustomGuiLine line = CustomGuiLine.fromComponent((ScriptGuiLine) component);
|
||||
this.components.put(line.getID(),line);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package noppes.npcs.client.gui.custom.components;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.custom.GuiCustom;
|
||||
import noppes.npcs.client.gui.custom.interfaces.IGuiComponent;
|
||||
import noppes.npcs.scripted.gui.ScriptGuiLine;
|
||||
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class CustomGuiLine extends Gui implements IGuiComponent {
|
||||
int id;
|
||||
GuiCustom parent;
|
||||
int x1;
|
||||
int y1;
|
||||
int x2;
|
||||
int y2;
|
||||
int color;
|
||||
int thickness;
|
||||
|
||||
public CustomGuiLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){
|
||||
this.id = id;
|
||||
this.x1 = GuiCustom.guiLeft + x1;
|
||||
this.y1 = GuiCustom.guiTop + y1;
|
||||
this.x2 = GuiCustom.guiLeft + x2;
|
||||
this.y2 = GuiCustom.guiTop + y2;
|
||||
this.color = color;
|
||||
this.thickness = thickness;
|
||||
}
|
||||
|
||||
public void setParent(GuiCustom parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
|
||||
double distance = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
|
||||
|
||||
float particleRed = (color >> 16 & 255) / 255f;
|
||||
float particleGreen = (color >> 8 & 255) / 255f;
|
||||
float particleBlue = (color & 255) / 255f;
|
||||
|
||||
mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png"));
|
||||
GL11.glPushMatrix();
|
||||
GL11.glColor4f(particleRed,particleGreen,particleBlue,1.0F);
|
||||
GL11.glTranslatef(this.x1,this.y1,0.0F);
|
||||
GL11.glRotatef((float) (Math.sin((x1-x2)/distance)*180/Math.PI),0.0F,0.0F,1.0F);
|
||||
this.drawTexturedModalRect((int) -Math.ceil((double)thickness/2),0,0,0, thickness, (int) distance);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public ICustomGuiComponent toComponent() {
|
||||
return new ScriptGuiLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness);
|
||||
}
|
||||
|
||||
public static CustomGuiLine fromComponent(ScriptGuiLine component) {
|
||||
return new CustomGuiLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness());
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
import noppes.npcs.scripted.interfaces.*;
|
||||
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
|
||||
import noppes.npcs.scripted.interfaces.IPlayer;
|
||||
import noppes.npcs.scripted.interfaces.IButton;
|
||||
import noppes.npcs.scripted.interfaces.ICustomGui;
|
||||
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
|
||||
import noppes.npcs.scripted.interfaces.IItemSlot;
|
||||
import noppes.npcs.scripted.interfaces.ILabel;
|
||||
import noppes.npcs.scripted.interfaces.IScroll;
|
||||
import noppes.npcs.scripted.interfaces.ITextField;
|
||||
import noppes.npcs.scripted.interfaces.ITexturedRect;
|
||||
import noppes.npcs.scripted.interfaces.IItemStack;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.controllers.CustomGuiController;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
@@ -170,6 +161,18 @@ public class ScriptGui implements ICustomGui {
|
||||
return (IScroll)this.components.get(this.components.size() - 1);
|
||||
}
|
||||
|
||||
public ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) {
|
||||
ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2, color, thickness);
|
||||
this.components.add(line);
|
||||
return (ILine) this.components.get(this.components.size() - 1);
|
||||
}
|
||||
|
||||
public ILine addLine(int id, int x1, int y1, int x2, int y2) {
|
||||
ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2);
|
||||
this.components.add(line);
|
||||
return (ILine) this.components.get(this.components.size() - 1);
|
||||
}
|
||||
|
||||
public void showPlayerInventory(int x, int y) {
|
||||
this.showPlayerInv = true;
|
||||
this.playerInvX = x;
|
||||
|
||||
@@ -112,6 +112,8 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent {
|
||||
return (new ScriptGuiScroll()).fromNBT(nbt);
|
||||
case 5:
|
||||
return (new ScriptGuiItemSlot()).fromNBT(nbt);
|
||||
case 6:
|
||||
return (new ScriptGuiLine()).fromNBT(nbt);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package noppes.npcs.scripted.gui;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.scripted.interfaces.ILine;
|
||||
|
||||
public class ScriptGuiLine extends ScriptGuiComponent implements ILine {
|
||||
int x1;
|
||||
int y1;
|
||||
int x2;
|
||||
int y2;
|
||||
int color = 0;
|
||||
int thickness = 2;
|
||||
|
||||
public ScriptGuiLine(){
|
||||
}
|
||||
|
||||
public ScriptGuiLine(int id, int x1, int y1, int x2, int y2){
|
||||
this.setPos(x1, y1);
|
||||
this.setID(id);
|
||||
this.hoverText = new String[]{""};
|
||||
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
}
|
||||
|
||||
public ScriptGuiLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){
|
||||
this.setPos(x1, y1);
|
||||
this.setID(id);
|
||||
this.hoverText = new String[]{""};
|
||||
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
this.color = color;
|
||||
this.thickness = thickness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
public NBTTagCompound toNBT(NBTTagCompound nbt) {
|
||||
super.toNBT(nbt);
|
||||
nbt.setInteger("X1",x1);
|
||||
nbt.setInteger("Y1",y1);
|
||||
nbt.setInteger("X2",x2);
|
||||
nbt.setInteger("Y2",y2);
|
||||
nbt.setInteger("Color",color);
|
||||
nbt.setInteger("Thickness",thickness);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public ScriptGuiComponent fromNBT(NBTTagCompound nbt) {
|
||||
super.fromNBT(nbt);
|
||||
x1 = nbt.getInteger("X1");
|
||||
y1 = nbt.getInteger("Y1");
|
||||
x2 = nbt.getInteger("X2");
|
||||
y2 = nbt.getInteger("Y2");
|
||||
color = nbt.getInteger("Color");
|
||||
thickness = nbt.getInteger("Thickness");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getX1(){
|
||||
return this.x1;
|
||||
}
|
||||
public int getY1(){
|
||||
return this.y1;
|
||||
}
|
||||
public int getX2(){
|
||||
return this.x2;
|
||||
}
|
||||
public int getY2(){
|
||||
return this.y2;
|
||||
}
|
||||
public int getColor(){
|
||||
return this.color;
|
||||
}
|
||||
public int getThickness(){
|
||||
return this.thickness;
|
||||
}
|
||||
|
||||
public void setX1(int x1){
|
||||
this.x1 = x1;
|
||||
}
|
||||
public void setY1(int y1){
|
||||
this.y1 = y1;
|
||||
}
|
||||
public void setX2(int x2){
|
||||
this.x2 = x2;
|
||||
}
|
||||
public void setY2(int y2){
|
||||
this.y2 = y2;
|
||||
}
|
||||
public void setColor(int color){
|
||||
this.color = color;
|
||||
}
|
||||
public void setThickness(int thickness){
|
||||
this.thickness = thickness;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,10 @@ public interface ICustomGui {
|
||||
|
||||
IScroll addScroll(int var1, int var2, int var3, int var4, int var5, String[] var6);
|
||||
|
||||
ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness);
|
||||
|
||||
ILine addLine(int id, int x1, int y1, int x2, int y2);
|
||||
|
||||
IItemSlot addItemSlot(int var1, int var2);
|
||||
|
||||
IItemSlot addItemSlot(int var1, int var2, IItemStack var3);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package noppes.npcs.scripted.interfaces;
|
||||
|
||||
public interface ILine extends ICustomGuiComponent {
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user