MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Scrolling List dans un GUI [1.15.2]

    Planifier Épinglé Verrouillé Déplacé Non résolu Sans suite
    1.15.2
    2 Messages 2 Publieurs 336 Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • En0ri4nE Hors-ligne
      En0ri4n
      dernière édition par

      Hello 🙂 !
      Je viens ici aujourd’hui pour vous demander votre aide sur un problème que je rencontre :
      Comment faire une scrolling list dans un GUI ?
      J’ai déjà ça :

      package fr.eno.pyrionshop.gui;
      
      import java.awt.Color;
      import java.util.List;
      
      import com.mojang.blaze3d.systems.RenderSystem;
      
      import fr.eno.pyrionshop.References;
      import fr.eno.pyrionshop.gui.GuiShopCategory.ShopItemList.ShopListEntry;
      import fr.eno.pyrionshop.gui.button.GuiButtonBack;
      import fr.eno.pyrionshop.utils.InfoShopItem;
      import fr.eno.pyrionshop.utils.ShopCategory;
      import net.minecraft.client.Minecraft;
      import net.minecraft.client.gui.AbstractGui;
      import net.minecraft.client.gui.screen.Screen;
      import net.minecraft.item.Items;
      import net.minecraft.util.ResourceLocation;
      import net.minecraft.util.text.ITextComponent;
      import net.minecraft.util.text.TranslationTextComponent;
      
      public class GuiShopCategory extends Screen
      {
      	private ShopCategory category;
      	private List<InfoShopItem> items;
      	private ShopItemList list;
      	
      	private int selected = -1;
      	private InfoShopItem selectedItem;
      	
      	public GuiShopCategory(ShopCategory category)
      	{
      		super(new TranslationTextComponent("screen.shopCategory.title"));
      		this.category = category;
      		this.items = category.getItems();
      	}
      
      	@Override
      	public void init()
          {
      		list = new ShopItemList(this, items);
      		
      		this.addButton(new GuiButtonBack(0, this.width - 100, this.height - 30, 50, 20, (button) -> minecraft.displayGuiScreen(new GuiShop())));
          }
      	
      	@Override
      	public void render(int mouseX, int mouseY, float partialTicks)
          {
      		this.renderBackground();
      		
      		int sizeX = this.width / 8;
      		int sizeY = 40;
      		this.minecraft.getTextureManager().bindTexture(new ResourceLocation(References.MOD_ID, "textures/gui/shop_background.png"));
      		Screen.blit(sizeX, sizeY, this.width - sizeX * 2, this.height - sizeY * 2, 0, 0, 1920, 1080, 1920, 1080);
      
      		if(list != null)
      			list.render(mouseX, mouseY, partialTicks);
      		
      		this.minecraft.getTextureManager().bindTexture(new ResourceLocation(References.MOD_ID, "textures/gui/shop_flag_" + category.getId() +".png"));
      		RenderSystem.enableAlphaTest();
      		RenderSystem.enableBlend();
      		RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
      		Screen.blit(sizeX, sizeY, this.width - sizeX * 2, this.height - sizeY * 2, 0, 0, 1920, 1080, 1920, 1080);
      		
              super.render(mouseX, mouseY, partialTicks); // Always the end
          }
      	
      	@Override
      	public boolean isPauseScreen()
      	{
              return false;
          }
      	
      	
      	@Override
      	public boolean mouseClicked(double mouseX, double mouseY, int button)
      	{
              if (this.list != null)
                  return this.list.mouseClicked(mouseX, mouseY, button);
              
              return super.mouseClicked(mouseX, mouseY, button);
          }
      
      	public void selectItemIndex(int index)
      	{
      		if (index == this.selected)
                  return;
              this.selected = index;
              this.selectedItem = (index >= 0 && index <= items.size()) ? items.get(selected) : new InfoShopItem(Items.AIR, 0, 0);
      	}
      
      	public boolean itemIndexSelected(int index)
      	{
      		return index == selected;
      	}
      	
      	public GuiShopCategory(ITextComponent title) { super(title); }
      	
      	class ShopItemList extends net.minecraft.client.gui.widget.list.AbstractList<ShopListEntry>
      	{
      		private GuiShopCategory parent;
      		
      		public ShopItemList(GuiShopCategory parent, List<InfoShopItem> items)
      		{
      			super(Minecraft.getInstance(), 10, 10, 10, 10, 40);
      			this.parent = parent;
      		}
      		
      
      		/*
      		public ShopItemList(GuiShopCategory parent, List<InfoShopItem> items)
      		{
      			super(/*, parent.height / 4 + 6, parent.height / 4 * 3 - 5, parent.width / 5, 40, *);
      			this.parent = parent;
      		}*/
      		
      		@Override
      		protected void clickedHeader(int p_clickedHeader_1_, int p_clickedHeader_2_)
      		{
      			super.clickedHeader(p_clickedHeader_1_, p_clickedHeader_2_);
      		}
      		
      		@Override
      		public boolean mouseReleased(double p_mouseReleased_1_, double p_mouseReleased_3_, int p_mouseReleased_5_)
      		{
      			Minecraft.getInstance().displayGuiScreen(new GuiShopItem(this.parent.selectedItem));
      			return super.mouseReleased(p_mouseReleased_1_, p_mouseReleased_3_, p_mouseReleased_5_);
      		}
      				
      		@Override
      		public int getHeight()
      		{
      			return this.height;
      		}
      		
      		@Override
      		public void render(int mouseX, int mouseY, float partialTicks)
      		{
      			int x = this.getLeft();
      			int y = this.getTop();
      			int width = this.getWidth();
      			int height = this.getHeight();
      			AbstractGui.fill(x, y, width, height, Color.WHITE.getRGB());
      			/*
      			if(!isSelected(index))
      				Gui.drawRect(entryRight - listWidth + 1, slotTop - 2, this.right - 7, slotTop - 41, 0xBF8a4305);
      			else
      				Gui.drawRect(entryRight - listWidth + 1, slotTop - 2, this.right - 7, slotTop - 41, 0xFF8a4305);
      				*/
      			/*
      			int scale = 2;
      			RenderSystem.pushMatrix();
      			RenderHelper.enableStandardItemLighting();
      			RenderSystem.scalef(scale, scale, scale);
      			minecraft.getItemRenderer().renderItemIntoGUI(new ItemStack(items.get(index).getItem()), (this.left + 3) / scale, (slotTop + 2) / scale);
      			RenderHelper.disableStandardItemLighting();
      			RenderSystem.popMatrix();
      
      			RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
      			this.parent.drawCenteredString(this.parent.minecraft.fontRenderer, this.parent.items.get(index).getTranslatedName(), entryRight - (right - left) / 2, slotTop + 4, Color.WHITE.getRGB());
      			
      			String purchaseStr = TextFormatting.GREEN + "Achat : " + TextFormatting.GOLD + "100$";
      			String saleStr = TextFormatting.DARK_AQUA + "Vente : " + TextFormatting.GOLD + "100$";
      			this.parent.drawString(this.parent.minecraft.fontRenderer, purchaseStr, entryRight - listWidth / 2 - 10 - this.parent.minecraft.fontRenderer.getStringWidth(purchaseStr), slotTop + this.slotHeight / 4 * 2, Color.WHITE.getRGB());
      			this.parent.drawString(this.parent.minecraft.fontRenderer, saleStr, entryRight - listWidth / 2 + 10, slotTop + this.slotHeight / 4 * 2, Color.WHITE.getRGB());
      		*/}
      		
      		public int getRightSide()
      		{
      			return this.x1 + this.width;
      		}
      		
      		public class ShopListEntry extends net.minecraft.client.gui.widget.list.AbstractList.AbstractListEntry<ShopListEntry>
      		{
      			private InfoShopItem info;
      			private GuiShopCategory parent;
      
      			public ShopListEntry(GuiShopCategory parent, InfoShopItem info)
      			{
      				this.parent = parent;
      				this.info = info;
      			}
      
      			@Override
      			public void render(int intA, int intB, int intC, int intD, int intE, int intF, int intG, boolean bool, float partialTicks)
      			{
      				System.out.println("\nInt A : " + intA + "\n" + 
      						"Int B : " + intB + "\n" + 
      						"Int C : " + intC + "\n" + 
      						"Int D : " + intD + "\n" + 
      						"Int E : " + intE + "\n" + 
      						"Int F : " + intF + "\n" + 
      						"Int G : " + intG + "\n" + 
      						"Boolean : " + bool + "\n" + 
      						"Float : " + partialTicks);
      				/*
      				int scale = 2;
      				RenderSystem.pushMatrix();
      				RenderHelper.enableStandardItemLighting();
      				RenderSystem.scalef(scale, scale, scale);
      				minecraft.getItemRenderer().renderItemIntoGUI(new ItemStack(info.getItem()), (x + 3) / scale, (y + 2) / scale);
      				RenderHelper.disableStandardItemLighting();
      				RenderSystem.popMatrix();
      
      				RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
      				this.parent.drawCenteredString(this.parent.minecraft.fontRenderer, new TranslationTextComponent(this.info.getItem().getTranslationKey()).getFormattedText(), entryRight - (right - left) / 2, slotTop + 4, Color.WHITE.getRGB());
      				
      				String purchaseStr = TextFormatting.GREEN + "Achat : " + TextFormatting.GOLD + "100$";
      				String saleStr = TextFormatting.DARK_AQUA + "Vente : " + TextFormatting.GOLD + "100$";
      				this.parent.drawString(this.parent.minecraft.fontRenderer, purchaseStr, entryRight - listWidth / 2 - 10 - this.parent.minecraft.fontRenderer.getStringWidth(purchaseStr), slotTop + this.slotHeight / 4 * 2, Color.WHITE.getRGB());
      				this.parent.drawString(this.parent.minecraft.fontRenderer, saleStr, entryRight - listWidth / 2 + 10, slotTop + this.slotHeight / 4 * 2, Color.WHITE.getRGB());
      				*/
      			}
      		}
      	}
      }
      

      Mais je n’arrive pas a draw ni a comprendre le système de selection et de list

      Le java c'est comme une boîte de chocolat, on sait jamais sur quoi on va tomber !

      1 réponse Dernière réponse Répondre Citer 0
      • LeBossMax2L Hors-ligne
        LeBossMax2
        dernière édition par LeBossMax2

        Bonjour, je sais pas si tu es toujours sur ton problème, mais voici quelques indications :
        Dans ta fonction init, tu peux ajouter ta liste au children de ton screen, comme ça ça gère le mouseClicked/mouseReleased/… de la liste tout seul.
        Ensuite, pour mettre des éléments dans la liste (par exemple dans son constructeur), tu peux appeler addEntry pour chaque item.
        Pour les paramètres du render du ListEntry, le premier c’est l’indice de l’entre, je pense que le deuxième c’est la position y du rendu et le troisième c’est la coordonnée x (un peu étrange mais bon), ensuite il y a la largeur de la cellule, la hauteur, mouseX, mouseY, isHover et enfin partialTicks.
        Et une dernière indication, c’est plus du Java : quand tu fait une classe à l’intérieur d’une autre, si tu met pas static, tu as accès a une référence à la classe supérieur (et une instance est nécessaire pour construire la classe interne) donc dans ton cas, tu as pas besoin de private GuiShopCategory parent;, tu peux y accéder en faisant GuiShopCategory.this.ceQueTuVeux.

        1 réponse Dernière réponse Répondre Citer 0
        • 1 / 1
        • Premier message
          Dernier message
        Design by Woryk
        ContactMentions Légales

        MINECRAFT FORGE FRANCE © 2024

        Powered by NodeBB