Ajouter un bouton à un GUI
-
http://minecraftforgefrance.fr/showthread.php?tid=2447&pid=28442#pid28442
-> tes variables textfield et textefield sont null lors du premier drawScreen (qui est visiblement appelé avant initGui. Ajoutes un null check. -
Ton bouton n’est pas extends GuiButton… C’est tout simplement marqué dans le crash report.
Regarde le tutoriel sur les Extended Entity Properties, y’a un exemple de banque.
-
Merci et j’ai changé par un GuiButton mais regardes il y a une erreur au 2ème public GuiAC(…)
Implicit super constructor GuiButton() is undefined. Must explicity invoke another constructorpackage fr.altiscraft.altiscraft.common; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class GuiAC extends GuiButton { protected static final ResourceLocation buttonTextures = new ResourceLocation(ModAltisCraft.MODID, "textures/gui/widgets.png"); /** Button width in pixels */ public int width; /** Button height in pixels */ public int height; /** The x position of this control. */ public int xPosition; /** The y position of this control. */ public int yPosition; /** The string displayed on this control. */ public String displayString; public int id; /** True if this control is enabled, false to disable. */ public boolean enabled; /** Hides the button completely if false. */ public boolean visible; protected boolean field_146123_n; public int packedFGColour; public GuiAC(int p_i1020_1_, int p_i1020_2_, int p_i1020_3_, String p_i1020_4_) { this(p_i1020_1_, p_i1020_2_, p_i1020_3_, 200, 20, p_i1020_4_); } public GuiAC(int p_i1021_1_, int p_i1021_2_, int p_i1021_3_, int p_i1021_4_, int p_i1021_5_, String p_i1021_6_) { this.width = 200; this.height = 20; this.enabled = true; this.visible = true; this.id = p_i1021_1_; this.xPosition = p_i1021_2_; this.yPosition = p_i1021_3_; this.width = p_i1021_4_; this.height = p_i1021_5_; this.displayString = p_i1021_6_; } /** * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over * this button and 2 if it IS hovering over this button. */ public int getHoverState(boolean p_146114_1_) { byte b0 = 1; if (!this.enabled) { b0 = 0; } else if (p_146114_1_) { b0 = 2; } return b0; } /** * Draws this button to the screen. */ public void drawButton(Minecraft p_146112_1_, int p_146112_2_, int p_146112_3_) { if (this.visible) { FontRenderer fontrenderer = p_146112_1_.fontRenderer; p_146112_1_.getTextureManager().bindTexture(buttonTextures); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.field_146123_n = p_146112_2_ >= this.xPosition && p_146112_3_ >= this.yPosition && p_146112_2_ < this.xPosition + this.width && p_146112_3_ < this.yPosition + this.height; int k = this.getHoverState(this.field_146123_n); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 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(p_146112_1_, p_146112_2_, p_146112_3_); int l = 14737632; if (packedFGColour != 0) { l = packedFGColour; } else if (!this.enabled) { l = 10526880; } else if (this.field_146123_n) { l = 16777120; } this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); } } /** * Fired when the mouse button is dragged. Equivalent of * MouseListener.mouseDragged(MouseEvent e). */ protected void mouseDragged(Minecraft p_146119_1_, int p_146119_2_, int p_146119_3_) { } /** * Fired when the mouse button is released. Equivalent of * MouseListener.mouseReleased(MouseEvent e). */ public void mouseReleased(int p_146118_1_, int p_146118_2_) { } /** * Returns true if the mouse has been pressed on this control. Equivalent of * MouseListener.mousePressed(MouseEvent e). */ public boolean mousePressed(Minecraft p_146116_1_, int p_146116_2_, int p_146116_3_) { return this.enabled && this.visible && p_146116_2_ >= this.xPosition && p_146116_3_ >= this.yPosition && p_146116_2_ < this.xPosition + this.width && p_146116_3_ < this.yPosition + this.height; } public boolean func_146115_a() { return this.field_146123_n; } public void func_146111_b(int p_146111_1_, int p_146111_2_) { } public void func_146113_a(SoundHandler p_146113_1_) { p_146113_1_.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); } public int getButtonWidth() { return this.width; } public int func_154310_c() { return this.height; } }EDIT : Et Robin Quelle utilité de régler les textfileds il marche très bien :S
-
Si je ne me trompe pas puisque tu as extend GuiButton, tu n’es pas obligé de copier tou mes seulement ce que tu veux changer. Je crois
-
Mode comme ça ? :')
package fr.altiscraft.altiscraft.common; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class GuiAC extends GuiButton { public GuiAC(int p_i1020_1_, int p_i1020_2_, int p_i1020_3_, String p_i1020_4_) { super(p_i1020_1_, p_i1020_2_, p_i1020_3_, p_i1020_4_); } protected static final ResourceLocation buttonTextures = new ResourceLocation(ModAltisCraft.MODID, "textures/gui/widgets.png"); } -
Essaie comme ça:
package fr.altiscraft.altiscraft.common; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class GuiAC extends GuiButton { protected static final ResourceLocation buttonTextures = new ResourceLocation(ModAltisCraft.MODID, "textures/gui/widgets.png"); public GuiAC(int p_i1020_1_, int p_i1020_2_, int p_i1020_3_, String p_i1020_4_) { super(p_i1020_1_, p_i1020_2_, p_i1020_3_, p_i1020_4_); } @Override public GuiAC(int id, int xPosition, int yPosition, int width, int height, String displayString) { this.width = 200; this.height = 20; this.enabled = true; this.visible = true; this.id = id; this.xPosition = xPosition; this.yPosition = yPosition; this.width = width; this.height = height; this.displayString = displayString; } public void drawButton(Minecraft mc, int x, int y) { if (this.visible) { FontRenderer fontrenderer = mc.fontRenderer; mc.getTextureManager().bindTexture(buttonTextures); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height; int k = this.getHoverState(this.field_146123_n); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 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, x, y); int l = 14737632; if (packedFGColour != 0) { l = packedFGColour; } else if (!this.enabled) { l = 10526880; } else if (this.field_146123_n) { l = 16777120; } this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); } } } -
Non, il faut ré-écrire la fonction où la texture est dessinée.
-
Donc je suis bon SCAREX avec le dernier code que j’ai envoyé ?

-
Le “non” était pour ton message, pas pour DiabolicaTrix. Regarde ce qu’a fait DiabolicaTrix.
-
Ah ok :') j’ai pris son code mais :
The annotation @Override is disallowed for this location
et toujours cette même erreur : Implicit super constructor GuiButton() is undefined. Must explicity invoke another constructor
-
Elle est où l’erreur?
-
En effet il ne devrait pas avoir de @Override sur le constructeur.
-
Je voulais le mettre sur drawButton mais je me suis trompé, quoique je ne sais pas si il le faut vraiment
-
Toujours cette erreur : [size=x-smallImplicit super constructor GuiButton() is undefined. Must explicity invoke another constructor ligne 25 sur public GuiAC(…) :]
package fr.altiscraft.altiscraft.common; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class GuiAC extends GuiButton { protected static final ResourceLocation buttonTextures = new ResourceLocation(ModAltisCraft.MODID, "textures/gui/widgets.png"); public GuiAC(int p_i1020_1_, int p_i1020_2_, int p_i1020_3_, String p_i1020_4_) { super(p_i1020_1_, p_i1020_2_, p_i1020_3_, p_i1020_4_); } public GuiAC(int id, int xPosition, int yPosition, int width, int height, String displayString) { this.width = 200; this.height = 20; this.enabled = true; this.visible = true; this.id = id; this.xPosition = xPosition; this.yPosition = yPosition; this.width = width; this.height = height; this.displayString = displayString; } public void drawButton(Minecraft mc, int x, int y) { if (this.visible) { FontRenderer fontrenderer = mc.fontRenderer; mc.getTextureManager().bindTexture(buttonTextures); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height; int k = this.getHoverState(this.field_146123_n); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 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, x, y); int l = 14737632; if (packedFGColour != 0) { l = packedFGColour; } else if (!this.enabled) { l = 10526880; } else if (this.field_146123_n) { l = 16777120; } this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); } } } -
Essaie ça:
package fr.altiscraft.altiscraft.common; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class GuiAC extends GuiButton { protected static final ResourceLocation buttonTextures = new ResourceLocation(ModAltisCraft.MODID, "textures/gui/widgets.png"); public GuiAC(int id, int xPosition, int yPosition, String nomdubouton) { super(id, xPosition, yPosition, longueurdubouton, largeurdubouton, nomdubouton); } public void drawButton(Minecraft mc, int x, int y) { if (this.visible) { FontRenderer fontrenderer = mc.fontRenderer; mc.getTextureManager().bindTexture(buttonTextures); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height; int k = this.getHoverState(this.field_146123_n); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 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, x, y); int l = 14737632; if (packedFGColour != 0) { l = packedFGColour; } else if (!this.enabled) { l = 10526880; } else if (this.field_146123_n) { l = 16777120; } this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); } } }Donc quand tu appelle ça donne: buttonList.add(new GuiAC(0, guiX + 8, guiY + 12 + 5, label));
Il faut que tu retire la grandeur du bouton et que tu l’ajoute à la main dans ta classe GuiAC u il est écrit: longueurdubouton, largeurdubouton
-
C’est bon merci énormément mais sinon j’ai une autre question ^^ comment changer la couleur du message qu’on a mis lorsqu’on passe la souris dessus comme “RETIRER” ?
-
Que evux-tu dire: “comme “RETIRER”?”?
-
tu parle du changement de texture l’ors du mouseOver? dans ce cas la utilise la fonction isMouseOver et tu rebind la texture
-
public int getHoverState(boolean p_146114_1_) { byte b0 = 1; if (!this.enabled) { b0 = 0; } else if (p_146114_1_) { b0 = 2; } return b0; }Essaye de bidouiller avec ça, la fonction retourne 1 si le bouton est désactivé, 2 si le bouton est activé et deux si la souris la “survole”
-
Il faut regarder la position de la souris, regarde dans la classe GuiButton