aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/gui/buttons/LocationButton.java
blob: a8937fda08b90127c44823202f5f1e25c7edd9f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package me.Danker.gui.buttons;

import me.Danker.handlers.TextRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.gui.GuiButton;

public class LocationButton extends GuiButton {

	private int x;
	private int y;
	private double scale;
	private String text;
	private String text2;
	private Integer text2Offset;
	
	public LocationButton(int buttonId, int x, int y, double width, double height, double scale, String text, String text2, Integer text2Offset) {
		super(buttonId, x, y, text);
		this.x = x;
		this.y = y;
		this.width = (int) width;
		this.height = (int) height;
		this.scale = scale;
		this.text = text;
		this.text2 = text2;
		this.text2Offset = text2Offset;
	}
	
	@Override
	public void drawButton(Minecraft mc, int mouseX, int mouseY) {
		String[] splitText;
		if (text2 == null) {
			splitText = text.split("\n");
		} else {
			splitText = text2.split("\n");
		}

		int longestText = -1;
		for (String s : splitText) {
			int stringLength = mc.fontRendererObj.getStringWidth(s);
			if (stringLength > longestText) {
				longestText = stringLength;
			}
		}
		
		if (text2 == null) {
			drawRect(x - 2, y - 2, (int) (x + longestText * scale + 3), (int) (y + (splitText.length * 9 + 3) * scale), 0x40D3D3D3);
		} else {
			drawRect(x - 2, y - 2, (int) (x + (longestText + text2Offset) * scale + 3), (int) (y + (splitText.length * 9 + 3) * scale), 0x40D3D3D3);
			new TextRenderer(mc, text2, (int) (x + (text2Offset * scale)), y, scale);
		}
		new TextRenderer(mc, text, x, y, scale);
	}
	
	@Override
	public void playPressSound(SoundHandler soundHandler) {
		
	}
	
}