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



×
×
  • Create New...

Important Information

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