Jump to content

Recommended Posts

Posted

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

Posted

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.

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

    • Dear Brunoe Quick Hack (Team) Thank you so much for your remarkable help in recovering my funds after I was scammed. As a busy surgeon and single mother to three children, the loss was overwhelming.Web-Site: Brunoequickhack.COM Your team's hard work, expertise, and unwavering support gave me hope and helped restore my financial stability. I admire your professionalism and the way you genuinely care about your clients. I highly recommend your services to anyone who has fallen prey to scammers. You are truly life savers. Whats-App: +1705-(7842)-635 With heartfelt thanks, Contact information: BrunoequickhackATgmail.cOM Dear Brunoe Quick Hack (Team) Thank you so much for your remarkable help in recovering my funds after I was scammed. As a busy surgeon and single mother to three children, the loss was overwhelming.Web-Site: Brunoequickhack.COM Your team's hard work, expertise, and unwavering support gave me hope and helped restore my financial stability. I admire your professionalism and the way you genuinely care about your clients. I highly recommend your services to anyone who has fallen prey to scammers. You are truly life savers. Whats-App: +1705-(7842)-635 With heartfelt thanks, Contact information: BrunoequickhackATgmail.cOM
    • ok i tried to disable the last mod's i installed and it is some of then, so now im going to do the classic enable and disable trick to find out which mod cause the crash. thanks for the help  
    • ok  make it work (java not being recognize) by downloading the zip putting it in the java folder and manually setting the path but is still give the same crush report https://pastebin.com/PPmR6jN0
    • Install this one: https://www.azul.com/downloads/?version=java-17-lts&os=windows&architecture=x86-64-bit&package=jdk#zulu After installation, set the java version in your Launcher / Java settings
    • it say it requires java 17 so when i go to install it is say "the installer has encounter an unexpected error installing this package." error code 2503 and 2502. https://pastebin.com/AL6AHMM9
  • Topics

×
×
  • Create New...

Important Information

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