Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.