
package studio.halbear.hem.gui;

import studio.halbear.hem.HemMod;

import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.world.World;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.ResourceLocation;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.Minecraft;

import java.util.HashMap;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.matrix.MatrixStack;

@OnlyIn(Dist.CLIENT)
public class AirboatGasCelViewGuiWindow extends ContainerScreen<AirboatGasCelViewGui.GuiContainerMod> {
	private World world;
	private int x, y, z;
	private PlayerEntity entity;
	private final static HashMap guistate = AirboatGasCelViewGui.guistate;

	public AirboatGasCelViewGuiWindow(AirboatGasCelViewGui.GuiContainerMod container, PlayerInventory inventory, ITextComponent text) {
		super(container, inventory, text);
		this.world = container.world;
		this.x = container.x;
		this.y = container.y;
		this.z = container.z;
		this.entity = container.entity;
		this.xSize = 428;
		this.ySize = 166;
	}

	private static final ResourceLocation texture = new ResourceLocation("hem:textures/screens/airboat_gas_cel_view.png");

	@Override
	public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(ms);
		super.render(ms, mouseX, mouseY, partialTicks);
		this.renderHoveredTooltip(ms, mouseX, mouseY);
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float partialTicks, int gx, int gy) {
		RenderSystem.color4f(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.blit(ms, k, l, 0, 0, this.xSize, this.ySize, this.xSize, this.ySize);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/airshipheliumui.png"));
		this.blit(ms, this.guiLeft + 2, this.guiTop + 3, 0, 0, 256, 139, 256, 139);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluibottom.png"));
		this.blit(ms, this.guiLeft + 61, this.guiTop + 96, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluiprogress.png"));
		this.blit(ms, this.guiLeft + 61, this.guiTop + 90, 0, 0, 22, 6, 22, 6);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluitop.png"));
		this.blit(ms, this.guiLeft + 61, this.guiTop + 85, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluibottom.png"));
		this.blit(ms, this.guiLeft + 85, this.guiTop + 96, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluitop.png"));
		this.blit(ms, this.guiLeft + 85, this.guiTop + 85, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluiprogress.png"));
		this.blit(ms, this.guiLeft + 85, this.guiTop + 90, 0, 0, 22, 6, 22, 6);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluibottom.png"));
		this.blit(ms, this.guiLeft + 37, this.guiTop + 92, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluitop.png"));
		this.blit(ms, this.guiLeft + 37, this.guiTop + 81, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluiprogress.png"));
		this.blit(ms, this.guiLeft + 37, this.guiTop + 86, 0, 0, 22, 6, 22, 6);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluibottom.png"));
		this.blit(ms, this.guiLeft + 109, this.guiTop + 96, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluibottom.png"));
		this.blit(ms, this.guiLeft + 133, this.guiTop + 96, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluibottom.png"));
		this.blit(ms, this.guiLeft + 157, this.guiTop + 92, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluibottom.png"));
		this.blit(ms, this.guiLeft + 181, this.guiTop + 86, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluiprogress.png"));
		this.blit(ms, this.guiLeft + 109, this.guiTop + 90, 0, 0, 22, 6, 22, 6);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluiprogress.png"));
		this.blit(ms, this.guiLeft + 133, this.guiTop + 90, 0, 0, 22, 6, 22, 6);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluiprogress.png"));
		this.blit(ms, this.guiLeft + 157, this.guiTop + 86, 0, 0, 22, 6, 22, 6);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluiprogress.png"));
		this.blit(ms, this.guiLeft + 181, this.guiTop + 80, 0, 0, 22, 6, 22, 6);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluitop.png"));
		this.blit(ms, this.guiLeft + 109, this.guiTop + 85, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluitop.png"));
		this.blit(ms, this.guiLeft + 133, this.guiTop + 85, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluitop.png"));
		this.blit(ms, this.guiLeft + 157, this.guiTop + 81, 0, 0, 22, 5, 22, 5);

		Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/heliumfilluitop.png"));
		this.blit(ms, this.guiLeft + 181, this.guiTop + 75, 0, 0, 22, 5, 22, 5);

		RenderSystem.disableBlend();
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeScreen();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	public void tick() {
		super.tick();
	}

	@Override
	protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) {
	}

	@Override
	public void onClose() {
		super.onClose();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}

	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
		this.addButton(new Button(this.guiLeft + 260, this.guiTop + 62, 92, 20, new StringTextComponent("Fill Gas Cels"), e -> {
			if (true) {
				HemMod.PACKET_HANDLER.sendToServer(new AirboatGasCelViewGui.ButtonPressedMessage(0, x, y, z));
				AirboatGasCelViewGui.handleButtonAction(entity, 0, x, y, z);
			}
		}));
	}
}
