Jump to content

[1.12]Custom Button Textures


ArmamentHaki

Recommended Posts

I made a custom button, which sizes its texture to 1/15 of the Screen.
After that, I tried to also do this with the width and height of the button so that they are equally big.

But the Problem is that the texture gets cut off if I do that.

I will Show you my Gui and Button class:

package armamenthaki.duelmonsters.gui;

import armamenthaki.duelmonsters.util.Log;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;

public class Button extends GuiButton
{
	private ResourceLocation resource;
	private float scaleFactor;
	
	public Button(int id, float sF, int xPos, int yPos, int width, int height, String str, ResourceLocation pResource)
	{
		super(id, xPos, yPos, width, height, str);
		this.resource = pResource;
		this.scaleFactor = sF;
		this.visible = true;
		this.width = width;
		this.height = height;
	}
	
	public void drawScreen(Minecraft mc)
    {
        if (this.visible)
        { 
        	GlStateManager.pushMatrix();
            mc.renderEngine.bindTexture(this.resource);
            GlStateManager.scale(this.scaleFactor, this.scaleFactor, 1.0);
            this.drawModalRectWithCustomSizedTexture(this.xPosition, this.yPosition, 0, 0, this.width, this.height, 256, 373);
            GlStateManager.popMatrix();
        }
    }
	
	public int getId()
	{
		return this.id;
	}
	
}
package armamenthaki.duelmonsters.gui;

import java.util.ArrayList;

import armamenthaki.duelmonsters.duel.Card;
import armamenthaki.duelmonsters.duel.cards.CardSpeedWarrior;
import armamenthaki.duelmonsters.individual.capabilities.DuelDataProvider;
import armamenthaki.duelmonsters.util.Log;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

public class GuiDeckEditor extends GuiScreen
{
	private ArrayList<Card> displayedCards = new ArrayList<Card>();
	private ArrayList<Card> playerCards = new ArrayList<Card>();
	
	
	private static final ResourceLocation cmbase = new ResourceLocation("duelmonsters", "textures/textures/gui/guicmbase.png");
	private Button button1;
	
	public GuiDeckEditor(EntityPlayer player)
	{
		if(!player.world.isRemote)
		{
			playerCards = player.getCapability(DuelDataProvider.DUELDAT_CAP, null).getPlayerCards();
		}
		displayedCards.add(new CardSpeedWarrior());
	}
	
	@Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
	{
		for(GuiButton button : this.buttonList)
		{
			if(button instanceof Button)
			{
				((Button) button).drawScreen(mc);
			}
		}
	}
    
	@Override
    public void initGui()
    {
		int id = 0;
		for(Card itCard : displayedCards) 
		{
			float x = (float)width/256;
			x = x/15;
			ResourceLocation resource = itCard.getResource();
			float y = x*256;
			float z = x*373;
			int j = (int)y;
			int k = (int)z;
			Log.getLogger().info(j);
			Log.getLogger().info(k);
			Log.getLogger().info(x);
			Log.getLogger().info(y);
			Log.getLogger().info(z);
			GuiButton button = new Button(id, x, 0, 0, j, k,  "", resource);
			this.buttonList.add(button);
			id++;
		}
		
    }
}

 

Everything works fine, I get no Errors but if I then go ingame, I get this:

(Upper left of the Picture, it should actually show all of the card)

2017-06-30_18.36.50.png

Link to comment
Share on other sites

Actually just figured out that I was drawing the Rect related to the buttons' texture, so I changed the
Parameters of the drawRectMethod from this.width and this.height to the original texture size,

and it works.

Sorry for posting, but I was trying it some time already.

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.



×
×
  • Create New...

Important Information

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