Résolu GuiTextField
-
Bonjour,
J’aurai juste une question je voulais savoir comment sauvegarder un TextField pour un autre gui voila se que je veut faire
http://prntscr.com/d4nw5i
http://prntscr.com/d4o2d8package fr.darkvince.ultrav2.guijoueur; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.client.FMLClientHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiOptions; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiShareToLan; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.achievement.GuiAchievements; import net.minecraft.client.gui.achievement.GuiStats; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.storage.ISaveFormat; import net.minecraft.world.storage.WorldInfo; public class GuiJoueur extends GuiScreen { private Minecraft minecraft; private EntityPlayer player; public static final ResourceLocation texture = new ResourceLocation("ultrav2:textures/gui/Joueur.png"); private int xSize; private int ySize; private GuiTextField pseudo; public GuiJoueur(Minecraft minecraft, EntityPlayer entityplayer) { xSize = 176; ySize = 166; mc = minecraft; player = entityplayer; } @Override public boolean doesGuiPauseGame() { return false; } public void initGui() { int i = (width - xSize) / 2; int j = (height - ySize) / 2; this.buttonList.add(new GuiButton(0, this.width / 2 - 20, this.height / 4 + 46, 98, 20, "F HOME")); this.buttonList.add(new GuiButton(1, this.width / 2 - 20, this.height / 4 + 20, 98, 20, "SPAWN")); this.buttonList.add(new GuiButton(2, this.width / 2 - 20, this.height / 4 + -5, 98, 20, "BOUTIQUE")); String s = Minecraft.getMinecraft().thePlayer.getDisplayName(); this.pseudo = new GuiTextField(this.fontRendererObj, this.width / 4 + 65, 135, 90, 20); this.pseudo.setText(s); this.pseudo.setMaxStringLength(15); this.pseudo.setFocused(true); this.buttonList.add(new GuiButton(3, this.width / 2 - 49, this.height / 4 + 100, 105, 20, "CHANGER DE JOUEUR")); } protected void keyTyped(char par1, int par2) { super.keyTyped(par1, par2); this.pseudo.textboxKeyTyped(par1, par2); } public void actionPerformed(GuiButton par1GuiButton) { switch (par1GuiButton.id) { case 0: this.mc.thePlayer.sendChatMessage("/f home"); break; case 1: this.mc.thePlayer.sendChatMessage("/spawn"); break; case 2: this.mc.thePlayer.sendChatMessage("/warp shop"); break; case 3: Minecraft.getMinecraft().displayGuiScreen(new GuiJoueurAutre(minecraft, player)); break; } } public void drawScreen(int i, int j, float f) { int k = (width - xSize) / 2; int l = (height - ySize) / 2; GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glColor3f(1.0F, 1.0F, 1.0F); drawBackgroundImage(); drawForeGroundLayer(); super.drawScreen(i, j, f); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); this.pseudo.drawTextBox(); } public void drawBackgroundImage() { int displayX = (width - xSize) / 2; int displayY = (height - ySize) / 2; this.mc.getTextureManager().bindTexture(texture); drawTexturedModalRect(displayX, displayY , 0, 0, xSize, ySize); } public void drawForeGroundLayer() { } protected void mouseClicked(int i, int j, int k) { super.mouseClicked(i, j, k); this.pseudo.mouseClicked(i, j, k); } public void updateScreen() { super.updateScreen(); if (!mc.thePlayer.isEntityAlive() || mc.thePlayer.isDead) { mc.thePlayer.closeScreen(); } } }
package fr.darkvince.ultrav2.guijoueur; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; public class GuiJoueurAutre extends GuiScreen { private Minecraft minecraft; private EntityPlayer player; public static final ResourceLocation texture = new ResourceLocation("ultrav2:textures/gui/Joueur.png"); private int xSize; private int ySize; private GuiTextField pseudo; public GuiJoueurAutre(Minecraft minecraft, EntityPlayer entityplayer) { xSize = 176; ySize = 166; mc = minecraft; player = entityplayer; } @Override public boolean doesGuiPauseGame() { return false; } public void initGui() { int i = (width - xSize) / 2; int j = (height - ySize) / 2; this.buttonList.add(new GuiButton(0, this.width / 2 - 20, this.height / 4 + 46, 98, 20, "F INVITE")); this.buttonList.add(new GuiButton(1, this.width / 2 - 20, this.height / 4 + 20, 98, 20, "TRADE")); this.buttonList.add(new GuiButton(2, this.width / 2 - 20, this.height / 4 + -5, 98, 20, "TP")); this.buttonList.add(new GuiButton(3, this.width / 2 - 49, this.height / 4 + 100, 105, 20, "RETOUR")); String s = Minecraft.getMinecraft().thePlayer.getDisplayName(); } public void actionPerformed(GuiButton par1GuiButton) { String s = Minecraft.getMinecraft().thePlayer.getDisplayName(); switch (par1GuiButton.id) { case 0: this.mc.thePlayer.sendChatMessage("/f invite" + s); break; case 1: this.mc.thePlayer.sendChatMessage("/echange" + s); break; case 2: this.mc.thePlayer.sendChatMessage("/tpahere" + s); break; case 3: Minecraft.getMinecraft().displayGuiScreen(new GuiJoueur(minecraft, player)); break; } } public void drawScreen(int i, int j, float f) { int k = (width - xSize) / 2; int l = (height - ySize) / 2; GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glColor3f(1.0F, 1.0F, 1.0F); drawBackgroundImage(); drawForeGroundLayer(); super.drawScreen(i, j, f); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); } public void drawBackgroundImage() { int displayX = (width - xSize) / 2; int displayY = (height - ySize) / 2; this.mc.getTextureManager().bindTexture(texture); drawTexturedModalRect(displayX, displayY , 0, 0, xSize, ySize); } public void drawForeGroundLayer() { } protected void mouseClicked(int i, int j, int k) { super.mouseClicked(i, j, k); } public void updateScreen() { super.updateScreen(); if (!mc.thePlayer.isEntityAlive() || mc.thePlayer.isDead) { mc.thePlayer.closeScreen(); } } }
Voilà comment je pourrai prendre le pseudo entre dans GuiJoueur pour le mettre dans GuiJoueurAutre
Merci d’avance
-
Tu peux simplement le passer dans le constructeur.
-
@‘robin4002’:
Tu peux simplement le passer dans le constructeur.
Comment sa passer mon ma textbox ?
-
@‘darkvince37’:
@‘robin4002’:
Tu peux simplement le passer dans le constructeur.
Comment sa passer mon ma textbox ?
Je crois qu’il veut dire que tu peux passer ton textbox dans le constructeur de ta classe (GuiScreen).
-
Et comment je doit me débrouiller faut que je passe par quoi ?
Envoyé de mon SM-G928F en utilisant Tapatalk
-
private String pseudo; public GuiJoueurAutre(Minecraft minecraft, EntityPlayer entityplayer, String pseudo) { xSize = 176; ySize = 166; mc = minecraft; this.player = entityplayer; this.pseudo = pseudo; }
Et dans GuiJoueur, remplaces :
Minecraft.getMinecraft().displayGuiScreen(new GuiJoueurAutre(minecraft, player));
par :
Minecraft.getMinecraft().displayGuiScreen(new GuiJoueurAutre(minecraft, player, pseudo.getText()));Il y a quoi de compliqué à faire ça ?
-
Pas grand chose mais je savais pas du tous comment mis prendre merci bcp