Jump to content

[1.11 - Solved] Dark Buttons in a GuiScrollingList


Franckyi

Recommended Posts

Yep, sure :

 

 

 

My GuiUpdaterScreen class (superclass of most of my GuiScreens, doesn't change much) :

package com.franckyi.itemeditor.api.gui;

import java.io.IOException;

import com.franckyi.itemeditor.ItemEditorMod;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;

public abstract class GuiUpdaterScreen extends GuiScreen {

protected GuiButton cancelButton, doneButton;
protected int previousScreen;

public GuiUpdaterScreen(int previousScreen) {
	this.previousScreen = previousScreen;
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
	if (button == doneButton)
		updateServer();
	if (button == cancelButton || button == doneButton)
		switchGui(previousScreen);
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
	this.drawDefaultBackground();
	super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
public final boolean doesGuiPauseGame() {
	return ItemEditorMod.config.pauseGame;
}

public abstract void initGui();

protected abstract void updateServer();

protected void switchGui(int screen) {
	mc.player.openGui(ItemEditorMod.instance, screen, mc.world, (int) mc.player.posX, (int) mc.player.posY,
			(int) mc.player.posZ);
}

}

 

GuiEditLore, the screen, parent of my list :

package com.franckyi.itemeditor.client.gui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.franckyi.itemeditor.api.gui.GuiUpdaterScreen;
import com.franckyi.itemeditor.client.gui.child.GuiLoreList;
import com.franckyi.itemeditor.client.gui.child.GuiLoreList.LoreListEntry;
import com.franckyi.itemeditor.network.EditLoreMessage;
import com.franckyi.itemeditor.network.ModPacketHandler;

import net.minecraft.client.gui.GuiButton;

public class GuiEditLore extends GuiUpdaterScreen {

public GuiEditLore(int previousScreen) {
	super(previousScreen);
}

private GuiLoreList loreList;
private List<String> loreMessage = new ArrayList<String>();

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
	super.drawScreen(mouseX, mouseY, partialTicks);
	drawString(fontRendererObj, "Edit Item Lore", this.width / 2 - 35, this.height / 2 - 90, 0x5555ff);
	loreList.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
public void initGui() {
	loreList = new GuiLoreList(mc, width/2, height/2, height/4, 3*height/4, width/4, 25, width, height, this);
	for(LoreListEntry entry : loreList.getLoreList())
		buttonList.add(entry.getFormatButton());
	buttonList.add(doneButton = new GuiButton(1, width/2 - 100, 3*height/4 + 20, 90, 20, "§2Done"));
	buttonList.add(cancelButton = new GuiButton(2, width/2 + 10, 3*height/4 + 20, 90, 20, "§4Cancel"));
	loreList.getLoreList().get(0).getTextField().setFocused(true);
}

@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
	for (LoreListEntry entry : loreList.getLoreList())
		entry.getTextField().textboxKeyTyped(typedChar, keyCode);
	super.keyTyped(typedChar, keyCode);
}

@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
	for (LoreListEntry entry : loreList.getLoreList())
		entry.getTextField().mouseClicked(mouseX, mouseY, mouseButton);
	super.mouseClicked(mouseX, mouseY, mouseButton);
}

@Override
public void updateScreen() {
	for (LoreListEntry entry : loreList.getLoreList())
		entry.getTextField().updateCursorCounter();
	super.updateScreen();
}

@Override
protected void updateServer() {
	for (LoreListEntry entry : loreList.getLoreList())
		loreMessage.add(entry.getTextField().getText());
	ModPacketHandler.INSTANCE.sendToServer(new EditLoreMessage(loreMessage));
}

}

 

GuiLoreList, my GuiScrollingList :

package com.franckyi.itemeditor.client.gui.child;

import java.util.ArrayList;
import java.util.List;

import com.franckyi.itemeditor.ItemEditorMod;
import com.franckyi.itemeditor.api.gui.GuiFormatButton;
import com.franckyi.itemeditor.helper.ModHelper;

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.client.renderer.Tessellator;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.fml.client.GuiScrollingList;

public class GuiLoreList extends GuiScrollingList {

private GuiScreen parent;
private List<LoreListEntry> loreList = new ArrayList<LoreListEntry>();

public GuiLoreList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight,
		int screenWidth, int screenHeight, GuiScreen parent) {
	super(client, width, height, top, bottom, left, entryHeight, screenWidth, screenHeight);
	this.parent = parent;
	NBTTagList lores = ModHelper.clientStack.getOrCreateSubCompound("display").getTagList("Lore", NBT.TAG_STRING);
	for(int i = 0; i < ItemEditorMod.config.loreLineNumber; i++){
		if(lores.hasNoTags() || i >= lores.tagCount())
			loreList.add(new LoreListEntry(i));
		else
			loreList.add(new LoreListEntry(i, lores.getStringTagAt(i)));
	}
}

@Override
protected int getSize() {
	return loreList.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 slotIdx, int entryRight, int slotTop, int slotBuffer, Tessellator tess) {
	LoreListEntry entry = loreList.get(slotIdx);
	parent.drawString(parent.mc.fontRendererObj, "Line " + (entry.index + 1), left + 10, slotTop + 7, 0xffffff);
	entry.textField.xPosition = left + 50;
	entry.textField.yPosition = slotTop;
	entry.textField.width = listWidth - 100;
	entry.textField.drawTextBox();
	entry.formatButton.xPosition = entryRight - 30;
	entry.formatButton.yPosition = slotTop;
	entry.formatButton.visible = (entry.formatButton.yPosition > this.top && entry.formatButton.yPosition + 20 < this.bottom);
	entry.formatButton.enabled = entry.formatButton.visible;
}

public List<LoreListEntry> getLoreList(){
	return loreList;
}

public class LoreListEntry {

	private int index;
	private GuiTextField textField;
	private GuiFormatButton formatButton;

	public LoreListEntry(int index){
		this.index = index;
		this.textField = new GuiTextField((index+1)*10, parent.mc.fontRendererObj, 0, 0, 0, 20);
		this.formatButton = new GuiFormatButton((index+1)*20, 0, 0, textField);
	}

	public LoreListEntry(int index, String text) {
		this(index);
		this.textField.setText(text);
	}

	public GuiTextField getTextField() {
		return textField;
	}

	public GuiButton getFormatButton() {
		return formatButton;
	}

}

}

 

 

Link to comment
Share on other sites

If I recall correctly, I don't think you would need to this.drawDefaultBackground(); in the drawScreen method if your GUI does directly extend from GuiScreen (because it already draws it, so you would have a darker background, because you summed the dark ones). Maybe that's why your buttons appear darker ?

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Okay, I just had to increase the zLevel of the button.

 

Now, (totally out of the subject, but I don't want to open another thread...)

I want to add a texture on the button. In my button class (extends GuiButton), I've done that :

        @Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
	super.drawButton(mc, mouseX, mouseY);
	mc.getTextureManager().bindTexture(new ResourceLocation(ModReference.MODID, "textures/gui/formatbuttonicon.png"));
	this.drawTexturedModalRect(this.xPosition + 2, this.yPosition + 2, 0, 0, 16, 16);	
}

But the texture doesn't appear. It's a 16*16 texture located in

assets/modid/textures/gui/formatbuttonicon.png

folder.

 

Link to comment
Share on other sites

Gui#drawTexturedModalRect

assumes you are using a 256x256 image. Use

Gui#drawModalRectWithCustomSizedTexture

with the last 2 parameters as the image size.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Ok so, I'm using

Gui#drawModalRectWithCustomSizedTexture(xPosInGui, yPosInGui, xPosInImg, yPosInImg, xSizeInGui, ySizeInGui, xSizeInImg, ySizeInImg)

.

The texture works. But I want it to cover the button, and not to be behind it. How can I do that ?

 

EDIT : Found how to do that. I created a custom

drawModalRectWithCustomSizedTexture

method from the original one, and added a zLevel parameter. And that works.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have done this now but have got the error:   'food(net.minecraft.world.food.FoodProperties)' in 'net.minecraft.world.item.Item.Properties' cannot be applied to                '(net.minecraftforge.registries.RegistryObject<net.minecraft.world.item.Item>)' public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register( "lemon_juice", () -> new Item( new HoneyBottleItem.Properties().stacksTo(1).food( (new FoodProperties.Builder()) .nutrition(3) .saturationMod(0.25F) .effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 1500), 0.01f ) .build() ) )); The code above is from the ModFoods class, the one below from the ModItems class. public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register("lemon_juice", () -> new Item(new Item.Properties().food(ModFoods.LEMON_JUICE)));   I shall keep going between them to try and figure out the cause. I am sorry if this is too much for you to help with, though I thank you greatly for your patience and all the effort you have put in to help me.
    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
    • Hi, I'm trying to use datagen to create json files in my own mod. This is my ModRecipeProvider class. public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { public ModRecipeProvider(PackOutput pOutput) { super(pOutput); } @Override protected void buildRecipes(Consumer<FinishedRecipe> pWriter) { ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', ModItems.COMPRESSED_DIAMOND.get()) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get(),9) .requires(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .unlockedBy(getHasName(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()), has(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get())) .save(pWriter); ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', Blocks.DIAMOND_BLOCK) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); } } When I try to run the runData client, it shows an error:  Caused by: java.lang.IllegalStateException: Duplicate recipe compressed:compressed_diamond I know that it's caused by the fact that there are two recipes for the ModItems.COMPRESSED_DIAMOND. But I need both of these recipes, because I need a way to craft ModItems.COMPRESSED_DIAMOND_BLOCK and restore 9 diamond blocks from ModItems.COMPRESSED_DIAMOND. Is there a way to solve this?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.