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

    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa adalah situs slot deposit pulsa tanpa potongan apapun yang dijamin garansi terpercaya, dimana kamu bisa bermain slot dengan melakukan deposit pulsa dan tanpa dikenakan potongan apapun sehingga dana yang masuk ke dalam akun akan 100% utuh. Proses penarikan dana juga dijamin gampang dan tidak sulit sehingga kamu tidak perlu khawatir akan kemenangan yang akan kamu peroleh dengan sangat mudah jika bermain disini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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