Jump to content

[1.12]Button Translation


ArmamentHaki

Recommended Posts

Well I managed to create fixed-scale Objects but the Problem which I have now is the Translation...
It still is related to the GuiScale and I don't want to rescale it for each GuiScale as Long as their is another solution.
Here are my classes now:

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
{
	//the cards I want to display in the box
	private ArrayList<Card> displayedCards = new ArrayList<Card>();
	//the players cards which out of which the the displayedCards resolves
	private ArrayList<Card> playerCards = new ArrayList<Card>();
	
	//the background, fixed to the screen width and height
	private static final ResourceLocation debase = new ResourceLocation("duelmonsters", "textures/textures/gui/guidebase.png");
	private Button button1;
	
	public GuiDeckEditor(EntityPlayer player)
	{
		if(!player.world.isRemote)
		{
			playerCards = player.getCapability(DuelDataProvider.DUELDAT_CAP, null).getPlayerCards();
		}
		//just some cards to add to the screen for testing purposes
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());
		displayedCards.add(new CardSpeedWarrior());


	}
	
	@Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
	{
		GlStateManager.pushMatrix();
		float x = (float)width/512;
		float y = (float)height/288;
		GlStateManager.scale(x, y, 1.0);
		mc.renderEngine.bindTexture(debase);
		this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 512, 288, 512, 288);
		GlStateManager.popMatrix();
		//draws buttons
		for(GuiButton button : this.buttonList)
		{
			if(button instanceof Button)
			{
				((Button) button).drawScreen(mc);
			}
		}
	}
    
	@Override
    public void initGui()
    {
		//column and line of the current card
		int line = 0;
		int column = 0;
		//button-id
		int id = 0;
		for(Card itCard : displayedCards) 
		{
			//resource
			ResourceLocation resource = itCard.getResource();
			//calculates button width/height (texture & size)
			float x = (float)width/256;
			x = x/20;
			float y = x*256;
			float z = x*373;
			int j = (int)y;
			int k = (int)z;
			//button object created
			GuiButton button = new Button(id, x, 0, 0, j, k,  "", resource);
			//calculates button position
			if(button instanceof Button)
			{
				//this is the problem, I tried out so many things like casting to floats etc but it wont work...
				//responsible for calculating translations of the textures
				float a = (float)width;
				float b = (float)height;
				float trX = a;
				float trY = b;
				trX = (float)trX/6;
				trY = (float)trY/5;
				trX = (float)trX + (float)((a/(float)16)*(float)column);
				trY = (float)trY + (float)((a/(float)16)*(float)line);
				((Button) button).setX((int)trX);
				((Button) button).setY((int)trY);
				((Button) button).setTrX(trX);
				((Button) button).setTrY(trY);
				
	            //responsible for having 6 objects in each line and then starting a new column
	            column++;
	            if(column == 5)
				{
					line++;
					column = 0;
				}

			}
			this.buttonList.add(button);
			
			id++;
		}
		
    }
}

 

The 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;
	private float trX;
	private float trY;
	
	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;
	}
	
	//draws the button, gets called in the gui screen class
	public void drawScreen(Minecraft mc)
    {
        if (this.visible)
        { 
        	GlStateManager.pushMatrix();
            mc.renderEngine.bindTexture(this.resource);
            /*translates the texture, this is the problem*/
            GlStateManager.translate(this.trX, this.trY, 1.0);
            //scaling works properly
            GlStateManager.scale(this.scaleFactor, this.scaleFactor, 1.0);
            //reference for me to know what trX and trY are
            Log.getLogger().info(trX);
            Log.getLogger().info(trY);
            this.drawModalRectWithCustomSizedTexture(this.xPosition, this.yPosition, 0, 0, 256, 373, 256, 373);
            GlStateManager.popMatrix();
        }
    }
	
	//getter setter
	public int getId()
	{
		return this.id;
	}
	
	public float getTrX() {
		return trX;
	}
	public void setTrX(float trX) {
		this.trX = trX;
	}
	public float getTrY() {
		return trY;
	}
	public void setTrY(float trY2) {
		this.trY = trY2;
	}
	public int getX()
	{
		return this.xPosition;
	}
	public void setX(int pX)
	{
		this.xPosition = pX;
	}
	public int getY()
	{
		return this.yPosition;
	}
	public void setY(int pY)
	{
		this.yPosition = pY;
	}
	
	
}

 

And These are 2 Screenshots of what doesn't work:

1. Image: GuiScale "Small"

2. Image: GuiScale "Auto"

 

 

2017-07-01_13.40.22.png

2017-07-01_13.40.31.png

Link to comment
Share on other sites

bump. I considered using mc.displayHeight/Width. I tried to log the guiscale related to the screenpixels:
For Small Scale, I got the same amount.

For Normal and the rest I got half of the original amount, which can't be true, so I am still on it...

Edited by ArmamentHaki
Link to comment
Share on other sites

  • 2 years later...

1.12 is no longer supported on this forum.

Please update to a modern version of Minecraft to receive support.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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