/*
 * This file is part of TechReborn, licensed under the MIT License (MIT).
 *
 * Copyright (c) 2018 TechReborn
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package techreborn.client.gui;

import net.minecraft.client.gui.screen.ConfirmChatLinkScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
import net.minecraft.util.SystemUtil;
import reborncore.client.gui.builder.widget.GuiButtonExtended;
import reborncore.common.network.NetworkManager;
import techreborn.config.TechRebornConfig;
import techreborn.items.ItemManual;
import techreborn.packets.ServerboundPackets;

public class GuiManual extends Screen {

	ItemManual manual;
	PlayerEntity player;

	private static final Identifier texture = new Identifier("techreborn", "textures/gui/manual.png");
	int guiWidth = 207;
	int guiHeight = 195;
	private static final String text1 = I18n.translate("techreborn.manual.wiki");
	private static final String text2 = I18n.translate("techreborn.manual.discord");
	private static final String text3 = I18n.translate("techreborn.manual.refund");

	public GuiManual(PlayerEntity player) {
		super(new LiteralText("gui.manual"));
		this.player = player;
	}

	@Override
	public void init() {
		int y = height / 4;
		addButton(new GuiButtonExtended((width / 2 - 30), y + 10, 60, 20, I18n.translate("techreborn.manual.wikibtn"), var1 -> minecraft.openScreen(new ConfirmChatLinkScreen(t -> {
			if(t){
				SystemUtil.getOperatingSystem().open("http://wiki.techreborn.ovh");
				this.minecraft.openScreen(this);
			}
		}, "http://wiki.techreborn.ovh", false))));
		addButton(new GuiButtonExtended((width / 2 - 30), y + 60, 60, 20, I18n.translate("techreborn.manual.discordbtn"), var1 -> minecraft.openScreen(new ConfirmChatLinkScreen(t -> {
			if(t){
				SystemUtil.getOperatingSystem().open("https://discord.gg/teamreborn");
				this.minecraft.openScreen(this);
			}
		}, "https://discord.gg/teamreborn", false))));
		if(TechRebornConfig.allowManualRefund){
			addButton(new GuiButtonExtended((width / 2 - 30), y + 110, 60, 20, I18n.translate("techreborn.manual.refundbtn"), var1 -> {
				NetworkManager.sendToServer(ServerboundPackets.createRefundPacket());
				this.minecraft.openScreen(null);
			}));
		}
	}

	@Override
	public void render(int mouseX, int mouseY, float partialTicks) {
		renderBackground();
		minecraft.getTextureManager().bindTexture(GuiManual.texture);
		int centerX = (width / 2) - guiWidth / 2;
		int centerY = (height / 2) - guiHeight / 2;
		blit(centerX, centerY, 0, 0, guiWidth, guiHeight);
		int y = height / 4;
		font.draw(text1, ((width / 2) - font.getStringWidth(text1) / 2), height / 2 - (guiHeight / 4), 4210752);
		font.draw(text2, ((width / 2) - font.getStringWidth(text2) / 2), height / 2 + 5, 4210752);
		if (TechRebornConfig.allowManualRefund) {
			font.draw(text3, ((width / 2) - font.getStringWidth(text3) / 2), y + 100, 4210752);
		}
		super.render(mouseX, mouseY, partialTicks);
	}
}



@@ -2395,32 +2395,33 @@
 t() %7B%0A%09%09int y = 
+(
 height / 4;%0A%09%09ad
@@ -2409,25 +2409,52 @@
 = (height / 
-4
+2) - guiHeight / 2;%0A%09%09y+= 40
 ;%0A%09%09addButto
@@ -2729,32 +2729,81 @@
 enScreen(this);%0A
+%09%09%09%7D else %7B%0A%09%09%09%09this.minecraft.openScreen(this);%0A
 %09%09%09%7D%0A%09%09%7D, %22http:
@@ -3129,32 +3129,80 @@
 enScreen(this);%0A
+%09%09%09%7Delse %7B%0A%09%09%09%09this.minecraft.openScreen(this);%0A
 %09%09%09%7D%0A%09%09%7D, %22https
@@ -3934,36 +3934,20 @@
 2), 
-height / 2 - (guiHeight / 4)
+centerY + 40
 , 42
@@ -4025,22 +4025,20 @@
 2), 
-height / 2 + 5
+centerY + 90
 , 42
@@ -4157,22 +4157,28 @@
 ) / 2), 
-y
+centerY
  + 1
-0
+4
 0, 42107

Fix manual gui. Closes #1792