Barre de défilement
-
Bonjour, je voudrais créer une barre de défilement comme celle du menu des options graphiques, la mince. Donc, j’ai fouillé un peu dans les codes et j’ai trouvé quelques classe: GuiListExtended et GuiOptionsRowList. Le seul problème est que le constructeur de GuiOptionsRowList prend un Enum d’options en paramètre. J’ai donc essayé en recréant la classe et en changeant ce que j’avais besoin, mais sans succès car le code est adapté pour un Enum, mais moi ce serait préférablement une ArrayList.
Mes codes:
GuiInv (la classe où je veux mettre la scroll bar):
package fr.altiscraft.altiscraft.common; import java.util.ArrayList; import org.lwjgl.opengl.GL11; import diabolicatrix.project.EEPRestrained; import diabolicatrix.project.GuiGangMenu; import diabolicatrix.project.InventoryManager; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiOptions; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ResourceLocation; public class GuiInv extends GuiScreen { int guiWidth = 350; int guiHeight = 200; public static ArrayList <string>list = new ArrayList<string>(); private EntityPlayer player = Minecraft.getMinecraft().thePlayer; private GuiTextField text; @Override public void drawScreen(int x, int y, float ticks) { EEPRestrained prop = EEPRestrained.get(player); int guix = (width - guiWidth) / 2; int guiy = (height - guiHeight) / 2; GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/Fondinv.png")); drawTexturedModalRect(guix, guiy, 0, 0, guiWidth - 3, 15); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/BackGround.png")); drawTexturedModalRect(guix, guiy + 16, 0, 0, guiWidth - 3, 150); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/FondClair.png")); drawTexturedModalRect(guix + 220, guiy + 35, 0, 0, 125, 100); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/FondBAC.png")); drawTexturedModalRect(guix + 5, guiy + 20, 0, 0, 90, 15); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/FondBAC.png")); drawTexturedModalRect(guix + 102, guiy + 20, 0, 0, 110, 15); mc.renderEngine.bindTexture(new ResourceLocation(ModAltisCraft.MODID, "textures/gui/FondBAC.png")); drawTexturedModalRect(guix + 220, guiy + 20, 0, 0, 125, 15); fontRendererObj.drawString("Menu du joueur", guix + 5, guiy + 5, 0xFFFFFF); fontRendererObj.drawString("" + prop.getMoney() + "$", guix + 15, guiy + 45, 0xFFFFFF); fontRendererObj.drawString("" + prop.getCash() + "$", guix + 15, guiy + 55, 0xFFFFFF); fontRendererObj.drawString(I18n.format("stat.money", new Object[0]), guix + 7, guiy + 25, 0xFFFFFF); fontRendererObj.drawString("Licenses", guix + 105, guiy + 25, 0xFFFFFF); InventoryManager.getItems(Minecraft.getMinecraft().thePlayer.inventory); int pos = 0; for (int i = 0; i < list.size(); i++) { fontRendererObj.drawString(list.get(i), guix + 223, guiy + 38 + pos, 0xFFFFFF); pos += 10; } fontRendererObj.drawString("Objets Actuels", guix + 222, guiy + 25, 0xFFFFFF); fontRendererObj.drawString("Poids: 0 / 64", guix + 282, guiy + 5, 0xFFFFFF); super.drawScreen(x, y, ticks); } public void initGui() { int guiX = (this.width - guiWidth) / 2; int guiY = (this.height - guiHeight) / 2; this.text = new GuiTextField(this.fontRendererObj, this.width / 2 - 68, this.height / 2 - 46, 140, 20); text.setText("Montant"); buttonList.clear(); buttonList.add(new GuiAC4(0, guiX, guiY + 167, "FERMER")); buttonList.add(new GuiAC4(1, guiX, guiY + 188, "SYNC DATA")); buttonList.add(new GuiAC4(2, guiX + 69, guiY + 167, "PARAMETRES")); buttonList.add(new GuiAC4(3, guiX + 69, guiY + 188, "STAFF")); buttonList.add(new GuiAC4(4, guiX + 139, guiY + 167, "MON GANG")); buttonList.add(new GuiAC4(5, guiX + 139, guiY + 188, "STATISTIQUES")); buttonList.add(new GuiAC4(6, guiX + 209, guiY + 167, "PORTE-CLES")); buttonList.add(new GuiAC4(7, guiX + 209, guiY + 188, "BOURSE")); buttonList.add(new GuiAC4(8, guiX + 279, guiY + 167, "TELEPHONE")); buttonList.add(new GuiAC4(9, guiX + 279, guiY + 188, "INFORMATIONS")); super.initGui(); } protected void keyTyped(char par1, int par2) { super.keyTyped(par1, par2); this.text.textboxKeyTyped(par1, par2); } protected void mouseClicked(int x, int y, int btn) { super.mouseClicked(x, y, btn); this.text.mouseClicked(x, y, btn); } public void updateScreen() { super.updateScreen(); this.text.updateCursorCounter(); } @Override protected void actionPerformed(GuiButton btn) { if (btn.id == 0) { Minecraft.getMinecraft().displayGuiScreen(null); } if (btn.id == 1) { Minecraft.getMinecraft().thePlayer .addChatMessage(new ChatComponentText((I18n.format("sync.data") + I18n.format("sync.data2")))); Minecraft.getMinecraft().theWorld.setBlock(0, 59, 0, Blocks.redstone_block); } if (btn.id == 2) { this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings)); } if (btn.id == 3) { Minecraft.getMinecraft().displayGuiScreen(new GuiStaff()); } if (btn.id == 4) { Minecraft.getMinecraft().displayGuiScreen(new GuiGangMenu()); } if (btn.id == 5) { Minecraft.getMinecraft().displayGuiScreen(new GuiStats()); } if (btn.id == 6) { Minecraft.getMinecraft().displayGuiScreen(new GuiKey()); } if (btn.id == 7) { Minecraft.getMinecraft().displayGuiScreen(new GuiBourse()); } if (btn.id == 8) { Minecraft.getMinecraft().displayGuiScreen(new GuiTel()); } if (btn.id == 9) { Minecraft.getMinecraft().displayGuiScreen(new GuiInformations()); } } @Override public boolean doesGuiPauseGame() { return false; } }
Screenshots:
::::::
Mes test (sur un autre gui):
package diabolicatrix.project; import java.util.ArrayList; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.client.renderer.InventoryEffectRenderer; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryBasic; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; public class GuiTest extends GuiScreen { private boolean needsScrollBars; private float currentScroll = 0; private boolean isScrolling; private boolean wasClicking; private boolean mouseClicked; private ArrayList invList; private boolean hasScrollBar = true; private int xSize = 194; private int ySize = 135; public GuiTest() { this.allowUserInput = true; } public void initGui() { super.initGui(); Keyboard.enableRepeatEvents(true); } public void onGuiClosed() { super.onGuiClosed(); Keyboard.enableRepeatEvents(false); } public void drawScreen(int par1, int par2, float par3) { /* boolean flag = Mouse.isButtonDown(0); int guiLeft = (this.width - this.xSize) / 2; int guiTop = (this.height - this.ySize) / 2; int k = guiLeft; int l = guiTop; int i1 = k + 175; int j1 = l + 18; int k1 = i1 + 12; int l1 = j1 + 90; if (!this.wasClicking && flag && par1 >= i1 && par2 >= j1 && par1 < k1 && par2 < l1) { this.isScrolling = this.needsScrollBars; } if (!flag) { this.isScrolling = false; } this.wasClicking = flag; if (this.isScrolling) { this.currentScroll = ((float)(par2 - j1) - 7.5F) / ((float)(l1 - j1) - 15.0F); if (this.currentScroll < 0.0F) { this.currentScroll = 0.0F; } if (this.currentScroll > 1.0F) { this.currentScroll = 1.0F; } System.out.println("Scrolling!"); } this.drawGuiContainerBackgroundLayer(par3, par1, par2); */ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/creative_inventory/tab_items.png")); int guiX = (this.width - this.ySize) / 2; int guiY = (this.height - this.ySize) / 2; this.drawTexturedModalRect(guiX, guiY, 0, 0, this.xSize, this.ySize); int max = this.xSize + 175; int min = this.xSize + 18; int width = min + 90; if (this.needsScrollBars) { this.drawTexturedModalRect(max, min + (int)((float)(width - min - 17) * this.currentScroll), 0,198, 12, 15); } else { this.drawTexturedModalRect(max, min, 12, 198, 12, 15); } super.drawScreen(par1, par2, par3); } public void handleMouseInput() { super.handleMouseInput(); int i = Mouse.getEventDWheel(); int m = Mouse.getEventButton(); if (i != 0 && this.needsScrollBars()) { int j = 54 / 9 - 5 + 1; if (i > 0) i = 1; if (i < 0) i = -1; this.currentScroll = (float)((double)this.currentScroll - (double)i / (double)j); if (this.currentScroll < 0.0F) { this.currentScroll = 0.0F; } if (this.currentScroll > 1.0F) { this.currentScroll = 1.0F; } System.out.println("Scrolling 2!"); } } @Override protected void mouseClicked(int x, int y, int z) { System.out.println("x: " + x + " y: " + y + " z: " + z); super.mouseClicked(x, y, z); } private boolean needsScrollBars() { /*if (((ContainerInfinityChest)this.inventorySlots).hasMoreThan1PageOfItemsInList()) this.needsScrollBars = true; else this.needsScrollBars = false; */ return true; } private boolean updateInv() { return true; } protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { } public boolean displayScrollBar() { return this.hasScrollBar; } public boolean doesGuiPauseGame() { return false; } } ```</string></string>
-
-
GuiScrollingList c’est une classe de Mc?
-
Regardes les importations : import net.minecraftforge.fml.client.GuiScrollingList;
-
Ah effectivement, je n’avais pas pensé à regarde là, merci. Je vais essayer.
EDIT: Donc mon code ressemble à ça:
Mon GuiTest:
package diabolicatrix.project; import java.util.ArrayList; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import fr.altiscraft.altiscraft.common.GuiInv; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.client.renderer.InventoryEffectRenderer; import net.minecraft.client.resources.I18n; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryBasic; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; public class GuiTest extends GuiScreen { private boolean needsScrollBars; private float currentScroll = 0; private boolean isScrolling; private boolean wasClicking; private boolean mouseClicked; private ArrayList invList; private boolean hasScrollBar = true; private GuiScrollingTest scroll; private int xSize = 194; private int ySize = 135; public GuiTest() { this.allowUserInput = true; } public void initGui() { this.scroll = new GuiScrollingTest(40, this, 130, 90); this.scroll.registerScrollButtons(GuiInv.list, 12, 13); super.initGui(); } public void drawScreen(int x, int y, float ticks) { this.drawDefaultBackground(); this.scroll.drawScreen(x, y, ticks); super.drawScreen(x, y, ticks); } public boolean doesGuiPauseGame() { return false; } }
Mon GuiScroll:
package diabolicatrix.project; import cpw.mods.fml.client.GuiScrollingList; import fr.altiscraft.altiscraft.common.GuiInv; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; public class GuiScrollingTest extends GuiScrollingList { private GuiTest parent; public GuiScrollingTest(int width, GuiTest parent, int left, int top) { super(parent.mc, width, parent.height, top, parent.height - 84, left, 20); this.parent = parent; } @Override protected int getSize() { return GuiInv.list.size(); } @Override protected void elementClicked(int index, boolean doubleClick) { } @Override protected boolean isSelected(int index) { return false; } @Override protected void drawBackground() { } @Override protected void drawSlot(int var1, int var2, int var3, int var4, Tessellator var5) { } }
Et ça donne ça:
:::
:::
Mon problème vient surement du drawSlot, mais je ne comprend pas l’utilité de celui-ci. Avec son nom j’imaginais que c’était pour dessiner la list, mais Scarex dessinait un string.