mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 19:34:09 +00:00
Push Working Compile
This commit is contained in:
1 parent
20a46e6007
commit
070e032907
3 files changed
+969
No files matched your search
@@ -0,0 +1,255 @@
|
||||
package noppes.npcs.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageEffects;
|
||||
import noppes.npcs.client.gui.script.GuiScriptEffect;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.client.renderer.ImageData;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldListener {
|
||||
private final GuiNPCManageEffects parent;
|
||||
public CustomEffect effect;
|
||||
private final String originalName;
|
||||
|
||||
private List<GuiMenuTopButton> topButtons = new ArrayList<>();
|
||||
|
||||
public SubGuiEffectGeneral(GuiNPCManageEffects parent, CustomEffect effect) {
|
||||
this.effect = effect;
|
||||
this.parent = parent;
|
||||
this.originalName = effect.name;
|
||||
this.closeOnEsc = true;
|
||||
|
||||
setBackground("menubg.png");
|
||||
xSize = 360;
|
||||
ySize = 216;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X");
|
||||
|
||||
GuiMenuTopButton general = new GuiMenuTopButton(-1, guiLeft + 4, guiTop - 10, "display.general");
|
||||
GuiMenuTopButton scripts = new GuiMenuTopButton(-2, general.xPosition + general.getWidth(), guiTop - 10, "script.scripts");
|
||||
|
||||
close.active = false;
|
||||
general.active = true;
|
||||
scripts.active = false;
|
||||
|
||||
addTopButton(close);
|
||||
addTopButton(general);
|
||||
addTopButton(scripts);
|
||||
|
||||
guiTop += 7;
|
||||
int y = guiTop + 7;
|
||||
int x = guiLeft + 4 + 4;
|
||||
addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, x + 36, y, 280, 20, effect.name));
|
||||
getTextField(1).setMaxStringLength(40);
|
||||
addLabel(new GuiNpcLabel(1, "gui.name", x, y + 5));
|
||||
|
||||
addLabel(new GuiNpcLabel(-1, "ID", x + 320, y + 1));
|
||||
addLabel(new GuiNpcLabel(-2, effect.id + "", x + 320, y + 11));
|
||||
|
||||
y += 23;
|
||||
|
||||
addTextField(new GuiNpcTextField(2, this, x + 70, y, 246, 20, effect.menuName.replaceAll("§", "&")));
|
||||
getTextField(2).setMaxStringLength(40);
|
||||
addLabel(new GuiNpcLabel(2, "general.menuName", x, y + 5));
|
||||
|
||||
y += 23;
|
||||
|
||||
addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(3, this, x + 70, y, 83, 20, ""+effect.everyXTick),
|
||||
10,
|
||||
1200,
|
||||
effect.everyXTick
|
||||
));
|
||||
getTextField(3).setMaxStringLength(6);
|
||||
getTextField(3).integersOnly = true;
|
||||
addLabel(new GuiNpcLabel(3, "effect.editor.runsEveryX", x, y + 5));
|
||||
|
||||
int oldX = x;
|
||||
int xEnd = guiLeft+xSize-10;
|
||||
x = getTextField(3).xPosition + getTextField(3).width;
|
||||
addButton(new GuiNpcButtonYesNo(10, (x+xEnd - 83) / 2, y + 23, 83, 20, effect.lossOnDeath));
|
||||
GuiNpcLabel label = new GuiNpcLabel(10, "effect.editor.lossOnDeath", x, y + 5);
|
||||
label.x = (x+xEnd - fontRendererObj.getStringWidth(label.label))/2;
|
||||
addLabel(label);
|
||||
x = oldX;
|
||||
y += 23;
|
||||
|
||||
addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(4, this, x + 70, y, 83, 20, ""+effect.length),
|
||||
-100,
|
||||
86400,
|
||||
effect.length
|
||||
));
|
||||
|
||||
addLabel(new GuiNpcLabel(4, "effect.editor.defaultLength", x, y + 5));
|
||||
|
||||
x = oldX - 4;
|
||||
y += 23;
|
||||
GuiScrollWindow scrollWindow = new GuiScrollWindow(this, x + 5, y, xSize - 20, ySize - 10 - (y - guiTop), 0) {
|
||||
@Override
|
||||
public void drawComponents(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawComponents(mouseX, mouseY, partialTicks);
|
||||
|
||||
int iconRenderSize = 96;
|
||||
|
||||
int x = 10, y = (clipHeight - 96) / 2;
|
||||
|
||||
TextureManager textureManager = mc.getTextureManager();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
ImageData data = ClientCacheHandler.getImageData(effect.icon);
|
||||
if (data.imageLoaded()) {
|
||||
data.bindTexture();
|
||||
int iconX = effect.iconX;
|
||||
int iconY = effect.iconY;
|
||||
int iconWidth = effect.getWidth();
|
||||
int iconHeight = effect.getHeight();
|
||||
int width = data.getTotalWidth();
|
||||
int height = data.getTotalWidth();
|
||||
|
||||
|
||||
func_152125_a(x, y, iconX, iconY, iconWidth, iconHeight, iconRenderSize, iconRenderSize, width, height);
|
||||
|
||||
} else {
|
||||
textureManager.bindTexture(new ResourceLocation("customnpcs", "textures/marks/question.png"));
|
||||
func_152125_a(x, y, 0, 0, 1, 1, iconRenderSize, iconRenderSize, 1, 1);
|
||||
}
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
// TODO: FIX TEXTURE
|
||||
// textureManager.bindTexture(new ResourceLocation(CustomNpcPlusDBC.ID + ":textures/gui/icons.png"));
|
||||
func_152125_a(x, y, 0, 240, 16, 16, iconRenderSize, iconRenderSize, 256, 256);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
}
|
||||
};
|
||||
addScrollableGui(0, scrollWindow);
|
||||
|
||||
y = (scrollWindow.clipHeight - 96) / 2 + 5;
|
||||
x = 116;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(5, "display.texture", x, y, 0xFFFFFF));
|
||||
y += 12;
|
||||
scrollWindow.addTextField(new GuiNpcTextField(5, this, x, y, scrollWindow.clipWidth-x-10, 20, effect.icon));
|
||||
scrollWindow.getTextField(5).setMaxStringLength(100);
|
||||
|
||||
y += 25;
|
||||
|
||||
scrollWindow.addLabel(new GuiNpcLabel(6, "effect.editor.xPos", x, y + 6, 0xFFFFFF));
|
||||
scrollWindow.addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(6, this, x + 43, y, 60, 20, ""+effect.iconX),
|
||||
0,
|
||||
10240,
|
||||
effect.iconX
|
||||
));
|
||||
scrollWindow.addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(7, this, scrollWindow.clipWidth - 60 - 10, y, 60, 20, ""+effect.iconY),
|
||||
0,
|
||||
10240,
|
||||
effect.iconY
|
||||
));
|
||||
scrollWindow.addLabel(new GuiNpcLabel(7, "effect.editor.yPos", scrollWindow.getTextField(7).xPosition - 43, y + 6, 0xFFFFFF));
|
||||
y += 23;
|
||||
|
||||
scrollWindow.addLabel(new GuiNpcLabel(8, "effect.editor.width", x, y + 6, 0xFFFFFF));
|
||||
scrollWindow.addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(8, this, x + 43, y, 60, 20, ""+effect.width),
|
||||
0,
|
||||
10240,
|
||||
effect.width
|
||||
));
|
||||
scrollWindow.addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(9, this, scrollWindow.clipWidth - 60 - 10, y, 60, 20, ""+effect.height),
|
||||
0,
|
||||
10240,
|
||||
effect.height
|
||||
));
|
||||
scrollWindow.addLabel(new GuiNpcLabel(9, "effect.editor.height", scrollWindow.getTextField(9).xPosition - 43, y + 6, 0xFFFFFF));
|
||||
|
||||
}
|
||||
|
||||
private GuiNpcTextField setIntegerOnly(GuiNpcTextField field, int min, int max, int def) {
|
||||
field.integersOnly = true;
|
||||
field.setMinMaxDefault(min, max, def);
|
||||
field.setMaxStringLength(6);
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == -5) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (id == -2) {
|
||||
// TODO: FIX PACKET
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCSaveEffect(effect.writeToNBT(false), originalName));
|
||||
GuiScriptEffect scriptGUI = new GuiScriptEffect(parent, effect);
|
||||
scriptGUI.setWorldAndResolution(mc, width, height);
|
||||
scriptGUI.initGui();
|
||||
mc.currentScreen = scriptGUI;
|
||||
}
|
||||
if (id == 10) {
|
||||
GuiNpcButtonYesNo button = (GuiNpcButtonYesNo) guibutton;
|
||||
effect.lossOnDeath = button.getBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField guiNpcTextField) {
|
||||
int id = guiNpcTextField.id;
|
||||
|
||||
switch (id) {
|
||||
case 1:
|
||||
effect.setName(guiNpcTextField.getText());
|
||||
break;
|
||||
case 2:
|
||||
effect.setMenuName(guiNpcTextField.getText());
|
||||
break;
|
||||
case 3:
|
||||
effect.setEveryXTick(guiNpcTextField.getInteger());
|
||||
guiNpcTextField.setText(effect.everyXTick+"");
|
||||
break;
|
||||
case 4:
|
||||
int length = guiNpcTextField.getInteger();
|
||||
if (length < 0)
|
||||
length = -100;
|
||||
guiNpcTextField.setText(length+"");
|
||||
effect.length = length;
|
||||
break;
|
||||
case 5:
|
||||
effect.icon = guiNpcTextField.getText();
|
||||
break;
|
||||
case 6:
|
||||
effect.iconX = guiNpcTextField.getInteger();
|
||||
break;
|
||||
case 7:
|
||||
effect.iconY = guiNpcTextField.getInteger();
|
||||
break;
|
||||
case 8:
|
||||
effect.width = guiNpcTextField.getInteger();
|
||||
break;
|
||||
case 9:
|
||||
effect.height = guiNpcTextField.getInteger();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
// TODO: FIX Packet
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCSaveEffect(effect.writeToNBT(false), originalName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.SubGuiEffectGeneral;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.client.renderer.ImageData;
|
||||
import noppes.npcs.controllers.StatusEffectController;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GuiNPCManageEffects extends GuiNPCInterface2 implements ICustomScrollListener, IScrollData, IGuiData, ISubGuiListener, GuiYesNoCallback {
|
||||
public GuiCustomScroll scrollEffects;
|
||||
public HashMap<String, Integer> data = new HashMap<>();
|
||||
public CustomEffect effect = new CustomEffect();
|
||||
public String selected = null;
|
||||
public String search = "";
|
||||
public String originalName = "";
|
||||
boolean setNormalSound = true;
|
||||
|
||||
public GuiNPCManageEffects(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
|
||||
// TODO: Fix Packet
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCRequestEffect(-1));
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
addButton(new GuiNpcButton(0, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
|
||||
|
||||
addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 32, 45, 20, "gui.remove"));
|
||||
getButton(1).enabled = effect != null && effect.id != -1;
|
||||
|
||||
addButton(new GuiNpcButton(2, guiLeft + 368, guiTop + 56, 45, 20, "gui.clone"));
|
||||
getButton(2).enabled = effect != null && effect.id != -1;
|
||||
|
||||
addButton(new GuiNpcButton(3, guiLeft + 368, guiTop + 80, 45, 20, "gui.edit"));
|
||||
getButton(3).enabled = effect != null && effect.id != -1;
|
||||
|
||||
if (scrollEffects == null) {
|
||||
scrollEffects = new GuiCustomScroll(this, 0, 0);
|
||||
scrollEffects.setSize(143, 185);
|
||||
}
|
||||
scrollEffects.guiLeft = guiLeft + 220;
|
||||
scrollEffects.guiTop = guiTop + 4;
|
||||
addScroll(scrollEffects);
|
||||
scrollEffects.setList(getSearchList());
|
||||
|
||||
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 4 + 3 + 185, 143, 20, search));
|
||||
if (effect != null && effect.id != -1) {
|
||||
addLabel(new GuiNpcLabel(10, "ID", guiLeft + 368, guiTop + 4 + 3 + 185));
|
||||
addLabel(new GuiNpcLabel(11, effect.id + "", guiLeft + 368, guiTop + 4 + 3 + 195));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
GuiNpcButton button = (GuiNpcButton) guibutton;
|
||||
if (button.id == 0) {
|
||||
save();
|
||||
String name = "New";
|
||||
while (data.containsKey(name))
|
||||
name += "_";
|
||||
CustomEffect effect = new CustomEffect(-1, name);
|
||||
|
||||
// TODO: Fix Packet
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCSaveEffect(effect.writeToNBT(false), ""));
|
||||
} else if (button.id == 1) {
|
||||
if (data.containsKey(scrollEffects.getSelected())) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, scrollEffects.getSelected(), StatCollector.translateToLocal("gui.delete"), 1);
|
||||
displayGuiScreen(guiyesno);
|
||||
}
|
||||
} else if (button.id == 2) {
|
||||
CustomEffect effect = this.effect.cloneEffect();
|
||||
while (data.containsKey(effect.name))
|
||||
effect.name += "_";
|
||||
// TODO: Fix Packet
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCSaveEffect(effect.writeToNBT(false), ""));
|
||||
}
|
||||
|
||||
if (effect == null)
|
||||
return;
|
||||
|
||||
if (button.id == 3) {
|
||||
if (data.containsKey(scrollEffects.getSelected()) && effect != null && effect.id >= 0) {
|
||||
setSubGui(new SubGuiEffectGeneral(this, effect));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
this.effect = new CustomEffect();
|
||||
effect.readFromNBT(compound);
|
||||
setSelected(effect.name);
|
||||
|
||||
if (effect.id != -1) {
|
||||
StatusEffectController.getInstance().customEffects.replace(effect.id, effect);
|
||||
}
|
||||
|
||||
|
||||
|
||||
initGui();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int i, int j, float f) {
|
||||
super.drawScreen(i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground() {
|
||||
super.drawBackground();
|
||||
renderScreen();
|
||||
}
|
||||
|
||||
private void renderScreen() {
|
||||
drawGradientRect(guiLeft + 5, guiTop + 4, guiLeft + 218, guiTop + 24, 0xC0101010, 0xC0101010);
|
||||
drawHorizontalLine(guiLeft + 5, guiLeft + 218, guiTop + 25, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor);
|
||||
drawGradientRect(guiLeft + 5, guiTop + 27, guiLeft + 218, guiTop + ySize + 9, 0xA0101010, 0xA0101010);
|
||||
|
||||
|
||||
if (effect == null)
|
||||
return;
|
||||
if (effect.id == -1)
|
||||
return;
|
||||
|
||||
String drawString = effect.getMenuName();
|
||||
int textWidth = getStringWidthWithoutColor(drawString);
|
||||
int centerX = guiLeft + 5 + ((218 - 10 - textWidth) / 2); // Adjusted centerX calculation
|
||||
fontRendererObj.drawString(drawString, centerX, guiTop + 10, CustomNpcResourceListener.DefaultTextColor, true);
|
||||
int y = guiTop + 33;
|
||||
int x = guiLeft + 12;
|
||||
|
||||
int iconRenderSize = 48;
|
||||
|
||||
TextureManager textureManager = mc.getTextureManager();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
ImageData data = ClientCacheHandler.getImageData(effect.icon);
|
||||
if (data.imageLoaded()) {
|
||||
data.bindTexture();
|
||||
int iconX = effect.iconX;
|
||||
int iconY = effect.iconY;
|
||||
int iconWidth = effect.getWidth();
|
||||
int iconHeight = effect.getHeight();
|
||||
int width = data.getTotalWidth();
|
||||
int height = data.getTotalWidth();
|
||||
|
||||
|
||||
func_152125_a(x, y, iconX, iconY, iconWidth, iconHeight, iconRenderSize, iconRenderSize, width, height);
|
||||
|
||||
} else {
|
||||
textureManager.bindTexture(new ResourceLocation("customnpcs", "textures/marks/question.png"));
|
||||
func_152125_a(x, y, 0, 0, 1, 1, iconRenderSize, iconRenderSize, 1, 1);
|
||||
}
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
// TODO: Fix ICONS
|
||||
// textureManager.bindTexture(new ResourceLocation(CustomNpcPlusDBC.ID + ":textures/gui/icons.png"));
|
||||
func_152125_a(x, y, 0, 240, 16, 16, iconRenderSize, iconRenderSize, 256, 256);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
x += iconRenderSize + 3;
|
||||
y += 2;
|
||||
|
||||
String translated = StatCollector.translateToLocal("gui.name") + ": " + effect.name;
|
||||
fontRendererObj.drawString(translated, x, y, 0xFFFFFF, false);
|
||||
int transLength = getStringWidthWithoutColor(translated);
|
||||
fontRendererObj.drawString(" (ID: "+ effect.id+ ")", x + transLength, y, 0xB5B5B5, false);
|
||||
y += 12;
|
||||
fontRendererObj.drawString(StatCollector.translateToLocal("general.menuName") + ": " + effect.menuName, x, y, 0xFFFFFF, false);
|
||||
y += 12;
|
||||
fontRendererObj.drawString(StatCollector.translateToLocal("effect.runsEveryX") + ": " + effect.everyXTick + "t", x, y, 0xB5B5B5, false);
|
||||
y += 12;
|
||||
fontRendererObj.drawString(StatCollector.translateToLocal("effect.defaultLength") + ": " + effect.length + "s", x, y, 0xB5B5B5, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
|
||||
if (getTextField(55) != null) {
|
||||
if (getTextField(55).isFocused()) {
|
||||
if (search.equals(getTextField(55).getText()))
|
||||
return;
|
||||
search = getTextField(55).getText().toLowerCase();
|
||||
scrollEffects.resetScroll();
|
||||
scrollEffects.setList(getSearchList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getSearchList() {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<String>(this.data.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (String name : this.data.keySet()) {
|
||||
if (name.toLowerCase().contains(search))
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data) {
|
||||
String name = scrollEffects.getSelected();
|
||||
this.data = data;
|
||||
scrollEffects.setList(getSearchList());
|
||||
|
||||
if (name != null)
|
||||
scrollEffects.setSelected(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
this.selected = selected;
|
||||
scrollEffects.setSelected(selected);
|
||||
originalName = scrollEffects.getSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll.id == 0) {
|
||||
save();
|
||||
effect = null;
|
||||
selected = scrollEffects.getSelected();
|
||||
originalName = scrollEffects.getSelected();
|
||||
if (selected != null && !selected.isEmpty()) {
|
||||
// TODO: Fix Packet
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCGetEffect(data.get(selected)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
// ICustomScrollListener.super.customScrollDoubleClicked(selection, scroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (this.selected != null && this.data.containsKey(this.selected) && this.effect != null) {
|
||||
|
||||
// TODO: Fix Packet
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCSaveEffect(effect.writeToNBT(false), originalName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean result, int id) {
|
||||
NoppesUtil.openGUI(player, this);
|
||||
if (!result)
|
||||
return;
|
||||
if (id == 1) {
|
||||
if (data.containsKey(scrollEffects.getSelected())) {
|
||||
|
||||
// TODO: Fix Packet
|
||||
// DBCPacketHandler.Instance.sendToServer(new DBCRemoveEffect(data.get(scrollEffects.getSelected())));
|
||||
scrollEffects.clear();
|
||||
effect = new CustomEffect();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getStringWidthWithoutColor(String text) {
|
||||
int width = 0;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
|
||||
if (c == '§') {
|
||||
if (i < text.length() - 1) {
|
||||
i += 1;
|
||||
}
|
||||
} else {
|
||||
// If not a color code, calculate the width
|
||||
width += fontRendererObj.getCharWidth(c);
|
||||
}
|
||||
}
|
||||
return width;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,404 @@
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiConfirmOpenLink;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageEffects;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import noppes.npcs.controllers.data.EffectScriptHandler;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener, ITextfieldListener {
|
||||
|
||||
private int activeTab = 0;
|
||||
public Map<String, List<String>> languages = new HashMap();
|
||||
private final int scriptLimit = 1;
|
||||
public List<String> hookList = new ArrayList();
|
||||
public String previousHookClicked = "";
|
||||
|
||||
public final GuiNPCManageEffects parent;
|
||||
public final CustomEffect effect;
|
||||
private final EffectScriptHandler scriptHandler;
|
||||
|
||||
|
||||
public GuiScriptEffect(GuiNPCManageEffects parent, CustomEffect effect) {
|
||||
this.drawDefaultBackground = true;
|
||||
this.closeOnEsc = true;
|
||||
this.xSize = 420;
|
||||
this.setBackground("menubg.png");
|
||||
|
||||
this.parent = parent;
|
||||
this.effect = effect;
|
||||
this.scriptHandler = new EffectScriptHandler();
|
||||
|
||||
for (EffectScriptHandler.ScriptType type : EffectScriptHandler.ScriptType.values()) {
|
||||
this.hookList.add(type.function);
|
||||
}
|
||||
|
||||
// TODO: FIX PACKET
|
||||
// DBCPacketClient.sendClient(new DBCRequestEffectScript(effect.id));
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
this.ySize = (int)((double)this.xSize * 0.56);
|
||||
if ((double)this.ySize > (double)this.height * 0.95) {
|
||||
this.ySize = (int)((double)this.height * 0.95);
|
||||
this.xSize = (int)((double)this.ySize / 0.56);
|
||||
}
|
||||
|
||||
this.bgScale = (float)this.xSize / 400.0F;
|
||||
super.initGui();
|
||||
this.guiTop += 10;
|
||||
int yoffset = (int)((double)this.ySize * 0.02);
|
||||
GuiMenuTopButton top;
|
||||
this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings"));
|
||||
int topXoffset = 0;
|
||||
int topYoffset = 0;
|
||||
|
||||
|
||||
if (this.scriptHandler.container != null) {
|
||||
this.addTopButton(top = new GuiMenuTopButton(1, top.xPosition + top.width + topXoffset, top.yPosition + topYoffset, "Script"));
|
||||
|
||||
} else {
|
||||
this.addTopButton(new GuiMenuTopButton(this.scriptLimit, top.xPosition + top.width, top.yPosition, "+"));
|
||||
}
|
||||
|
||||
top = this.getTopButton(this.activeTab);
|
||||
if (top == null) {
|
||||
this.activeTab = 0;
|
||||
top = this.getTopButton(0);
|
||||
}
|
||||
|
||||
top.active = true;
|
||||
if (this.activeTab == 1) {
|
||||
GuiCustomScroll hooks = new GuiCustomScroll(this, 1);
|
||||
hooks.allowUserInput = false;
|
||||
hooks.setSize(108, 198);
|
||||
hooks.guiLeft = this.guiLeft - 110;
|
||||
hooks.guiTop = this.guiTop + 14;
|
||||
|
||||
hooks.setUnsortedList(this.hookList);
|
||||
this.addScroll(hooks);
|
||||
GuiNpcLabel hookLabel = new GuiNpcLabel(0, "script.hooks", hooks.guiLeft, this.guiTop + 5);
|
||||
hookLabel.color = 11184810;
|
||||
this.addLabel(hookLabel);
|
||||
ScriptContainer container = this.scriptHandler.container;
|
||||
GuiScriptTextArea ta = new GuiScriptTextArea(this, 2, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96) - yoffset * 2, container == null ? "" : container.script);
|
||||
ta.enableCodeHighlighting();
|
||||
ta.setListener(this);
|
||||
this.addTextField(ta);
|
||||
int left1 = this.guiLeft + this.xSize - 104;
|
||||
this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear"));
|
||||
this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste"));
|
||||
this.addButton(new GuiNpcButton(100, left1, this.guiTop + 21 + yoffset, 60, 20, "gui.copy"));
|
||||
this.addButton(new GuiNpcButton(105, left1 + 61, this.guiTop + 21 + yoffset, 60, 20, "gui.remove"));
|
||||
|
||||
this.addButton(new GuiNpcButton(107, left1, this.guiTop + 66 + yoffset, 80, 20, "script.loadscript"));
|
||||
// TODO Uncomment if script lists ever get added
|
||||
this.getButton(107).enabled = false;
|
||||
|
||||
GuiCustomScroll scroll = (new GuiCustomScroll(this, 0)).setUnselectable();
|
||||
scroll.setSize(100, (int)((double)this.ySize * 0.54) - yoffset * 2);
|
||||
scroll.guiLeft = left1;
|
||||
scroll.guiTop = this.guiTop + 88 + yoffset;
|
||||
if (container != null) {
|
||||
scroll.setList(container.scripts);
|
||||
}
|
||||
|
||||
this.addScroll(scroll);
|
||||
} else {
|
||||
GuiNpcTextArea var8 = new GuiNpcTextArea(2, this, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText());
|
||||
var8.enabled = false;
|
||||
this.addTextField(var8);
|
||||
int var9 = this.guiLeft + this.xSize - 150;
|
||||
this.addButton(new GuiNpcButton(100, var9, this.guiTop + 125, 60, 20, "gui.copy"));
|
||||
this.addButton(new GuiNpcButton(102, var9, this.guiTop + 146, 60, 20, "gui.clear"));
|
||||
this.addLabel(new GuiNpcLabel(1, "script.language", var9, this.guiTop + 15));
|
||||
this.addButton(new GuiNpcButton(103, var9 + 60, this.guiTop + 10, 80, 20, this.languages.keySet().toArray(new String[this.languages.keySet().size()]), this.getScriptIndex()));
|
||||
this.getButton(103).enabled = !this.languages.isEmpty();
|
||||
this.addLabel(new GuiNpcLabel(2, "gui.enabled", var9, this.guiTop + 36));
|
||||
this.addButton(new GuiNpcButton(104, var9 + 60, this.guiTop + 31, 50, 20, new String[]{"gui.no", "gui.yes"}, this.scriptHandler.getEnabled() ? 1 : 0));
|
||||
if (this.player.worldObj.isRemote) {
|
||||
this.addButton(new GuiNpcButton(106, var9, this.guiTop + 55, 150, 20, "script.openfolder"));
|
||||
}
|
||||
|
||||
this.addButton(new GuiNpcButton(109, var9, this.guiTop + 78, 80, 20, "gui.website"));
|
||||
this.addButton(new GuiNpcButton(112, var9 + 81, this.guiTop + 78, 80, 20, "gui.forum"));
|
||||
this.addButton(new GuiNpcButton(110, var9, this.guiTop + 99, 80, 20, "script.apidoc"));
|
||||
this.addButton(new GuiNpcButton(111, var9 + 81, this.guiTop + 99, 80, 20, "script.apisrc"));
|
||||
}
|
||||
|
||||
this.xSize = 420;
|
||||
this.ySize = 256;
|
||||
}
|
||||
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
String hook = scroll.getSelected();
|
||||
if (this.previousHookClicked.equals(hook)) {
|
||||
String addString = "";
|
||||
if (!this.getTextField(2).getText().isEmpty()) {
|
||||
addString = addString + "\n";
|
||||
}
|
||||
|
||||
addString = addString + "function " + hook + "(event) {\n \n}\n";
|
||||
this.getTextField(2).setText(this.getTextField(2).getText() + addString);
|
||||
this.previousHookClicked = "";
|
||||
} else {
|
||||
this.previousHookClicked = hook;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
}
|
||||
|
||||
private String getConsoleText() {
|
||||
Map<Long, String> map = this.scriptHandler.getConsoleText();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Iterator var3 = map.entrySet().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
Map.Entry<Long, String> entry = (Map.Entry)var3.next();
|
||||
builder.insert(0, new Date((Long)entry.getKey()) + (String)entry.getValue() + "\n");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private int getScriptIndex() {
|
||||
int i = 0;
|
||||
|
||||
for(Iterator var2 = this.languages.keySet().iterator(); var2.hasNext(); ++i) {
|
||||
String language = (String)var2.next();
|
||||
if (language.equalsIgnoreCase(this.scriptHandler.getLanguage())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void confirmClicked(boolean flag, int i) {
|
||||
if (flag) {
|
||||
if (i == 0) {
|
||||
this.openLink("https://www.curseforge.com/minecraft/mc-mods/customnpc-plus");
|
||||
}
|
||||
|
||||
if (i == 1) {
|
||||
this.openLink("https://kamkeel.github.io/CustomNPC-Plus/");
|
||||
}
|
||||
|
||||
if (i == 2) {
|
||||
this.openLink("https://kamkeel.github.io/CustomNPC-Plus/");
|
||||
}
|
||||
|
||||
if (i == 3) {
|
||||
this.openLink("http://www.minecraftforge.net/forum/index.php/board,122.0.html");
|
||||
}
|
||||
|
||||
if (i == 10) {
|
||||
this.scriptHandler.container = null;
|
||||
this.activeTab = 0;
|
||||
}
|
||||
|
||||
if (i == 101) {
|
||||
this.getTextField(2).setText(NoppesStringUtils.getClipboardContents());
|
||||
this.setScript();
|
||||
}
|
||||
|
||||
if (i == 102) {
|
||||
if (this.activeTab == 1) {
|
||||
ScriptContainer container = this.scriptHandler.container;
|
||||
container.script = "";
|
||||
} else {
|
||||
this.scriptHandler.clearConsole();
|
||||
}
|
||||
|
||||
this.initGui();
|
||||
}
|
||||
}
|
||||
|
||||
this.displayGuiScreen(this);
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
this.setScript();
|
||||
this.activeTab = 0;
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
if (guibutton.id == this.scriptLimit) {
|
||||
if (scriptHandler.container == null)
|
||||
this.scriptHandler.container = new ScriptContainer(this.scriptHandler);
|
||||
else
|
||||
this.setScript();
|
||||
this.activeTab = 1;
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
if (guibutton.id == 109) {
|
||||
this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://kamkeel.github.io/CustomNPC-Plus/", 0, true));
|
||||
}
|
||||
|
||||
if (guibutton.id == 110) {
|
||||
this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://github.com/KAMKEEL/CustomNPC-Plus-API", 1, true));
|
||||
}
|
||||
|
||||
if (guibutton.id == 111) {
|
||||
this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://github.com/Noppes/CustomNPCsAPI", 2, true));
|
||||
}
|
||||
|
||||
if (guibutton.id == 112) {
|
||||
this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.minecraftforge.net/forum/index.php/board,122.0.html", 3, true));
|
||||
}
|
||||
|
||||
if (guibutton.id == 100) {
|
||||
NoppesStringUtils.setClipboardContents(this.getTextField(2).getText());
|
||||
}
|
||||
|
||||
if (guibutton.id == 101) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, StatCollector.translateToLocal("gui.paste"), StatCollector.translateToLocal("gui.sure"), 101);
|
||||
this.displayGuiScreen(guiyesno);
|
||||
}
|
||||
|
||||
GuiYesNo container1;
|
||||
if (guibutton.id == 102) {
|
||||
container1 = new GuiYesNo(this, StatCollector.translateToLocal("gui.clear"), StatCollector.translateToLocal("gui.sure"), 102);
|
||||
this.displayGuiScreen(container1);
|
||||
}
|
||||
|
||||
if (guibutton.id == 103) {
|
||||
this.scriptHandler.setLanguage(guibutton.displayString);
|
||||
}
|
||||
|
||||
if (guibutton.id == 104) {
|
||||
this.scriptHandler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1);
|
||||
}
|
||||
|
||||
if (guibutton.id == 105) {
|
||||
container1 = new GuiYesNo(this, "", ((GuiNpcButton)guibutton).displayString, 10);
|
||||
this.displayGuiScreen(container1);
|
||||
}
|
||||
|
||||
if (guibutton.id == 106) {
|
||||
NoppesUtil.openFolder(ScriptController.Instance.dir);
|
||||
}
|
||||
|
||||
if (guibutton.id == 107) {
|
||||
ScriptContainer container = this.scriptHandler.container;
|
||||
if (container == null) {
|
||||
container = new ScriptContainer(this.scriptHandler);
|
||||
this.scriptHandler.container = container;
|
||||
}
|
||||
|
||||
// this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.script.getLanguage()), container));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setScript() {
|
||||
if (this.activeTab == 1) {
|
||||
ScriptContainer container = this.scriptHandler.container;
|
||||
if (container == null) {
|
||||
container = new ScriptContainer(this.scriptHandler);
|
||||
this.scriptHandler.container = container;
|
||||
}
|
||||
|
||||
String text = this.getTextField(2).getText();
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = text.replace("\r", "\n");
|
||||
container.script = text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if (!compound.hasKey("Tab")) {
|
||||
this.scriptHandler.setLanguage(compound.getString("ScriptLanguage"));
|
||||
this.scriptHandler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
this.copiedSetGuiData(compound);
|
||||
} else {
|
||||
int tab = compound.getInteger("Tab");
|
||||
ScriptContainer container = new ScriptContainer(this.scriptHandler);
|
||||
container.readFromNBT(compound.getCompoundTag("Script"));
|
||||
this.scriptHandler.container = container;
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void copiedSetGuiData(NBTTagCompound compound) {
|
||||
NBTTagList data = compound.getTagList("Languages", 10);
|
||||
HashMap languages = new HashMap();
|
||||
|
||||
for(int i = 0; i < data.tagCount(); ++i) {
|
||||
NBTTagCompound comp = data.getCompoundTagAt(i);
|
||||
ArrayList scripts = new ArrayList();
|
||||
NBTTagList list = comp.getTagList("Scripts", 8);
|
||||
|
||||
for(int j = 0; j < list.tagCount(); ++j) {
|
||||
scripts.add(list.getStringTagAt(j));
|
||||
}
|
||||
|
||||
languages.put(comp.getString("Language"), scripts);
|
||||
}
|
||||
|
||||
this.languages = languages;
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.setScript();
|
||||
|
||||
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
// TODO: FIX PACKET
|
||||
// DBCSaveEffectScript.Save(effect.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
||||
|
||||
// TODO: FIX PACKET
|
||||
// DBCSaveEffectScript.Save(effect.id, -1, containers.size(), scriptData);
|
||||
}
|
||||
|
||||
public void textUpdate(String text) {
|
||||
ScriptContainer container = this.scriptHandler.container;
|
||||
if (container != null) {
|
||||
container.script = text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveText(String text) {
|
||||
ScriptContainer container = this.scriptHandler.container;
|
||||
if (container != null) {
|
||||
container.script = text;
|
||||
}
|
||||
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.save();
|
||||
parent.setWorldAndResolution(mc, width, height);
|
||||
parent.initGui();
|
||||
mc.currentScreen = parent;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user