/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 Zoe Lee (Kihira)
 *
 * See LICENSE for full License
 */

package kihira.foxlib.client.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.client.config.GuiButtonExt;

import java.util.ArrayList;
import java.util.List;

public abstract class GuiBaseScreen extends GuiScreen {
    private int prevMouseX;
    private int prevMouseY;
    private float mouseIdleTicks;

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        super.drawScreen(mouseX, mouseY, partialTicks);

        // Tooltips
        for (GuiButton btn : buttonList) {
            if (btn instanceof ITooltip && btn.isMouseOver()) {
                if (prevMouseX == mouseX && prevMouseY == mouseY) mouseIdleTicks += partialTicks;
                else if (mouseIdleTicks > 0f) mouseIdleTicks = 0f;
                drawHoveringText(((ITooltip) btn).getTooltip(mouseX, mouseY, mouseIdleTicks), mouseX, mouseY);
                prevMouseX = mouseX;
                prevMouseY = mouseY;
                break;
            }
        }
    }

    public class GuiButtonTooltip extends GuiButtonExt implements ITooltip {
        private final int maxTextWidth;
        protected final ArrayList<String> tooltip = new ArrayList<String>();

        @SuppressWarnings("unchecked")
        public GuiButtonTooltip(int id, int x, int y, int width, int height, String text, int maxTextWidth, String... tooltips) {
            super(id, x, y, width, height, text);
            this.maxTextWidth = maxTextWidth;
            if (tooltips != null && tooltips.length > 0) {
                for (String s : tooltips) {
                    tooltip.addAll(fontRendererObj.listFormattedStringToWidth(s, this.maxTextWidth));
                }
            }
        }

        @Override
        public List<String> getTooltip(int mouseX, int mouseY, float mouseIdleTime) {
            return this.tooltip;
        }
    }

    public static boolean isMouseOver(int mouseX, int mouseY, int xPos, int yPos, int width, int height) {
        return mouseX >= xPos && mouseY >= yPos && mouseX < xPos + width && mouseY < yPos + height;
    }

    public class GuiButtonToggle extends GuiButtonTooltip {

        public GuiButtonToggle(int id, int x, int y, int width, int height, String text, int maxTextWidth, String... tooltips) {
            super(id, x, y, width, height, text, maxTextWidth, tooltips);
        }

        @Override
        public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) {
            if (this.visible && GuiBaseScreen.isMouseOver(mouseX, mouseY, xPosition, yPosition, width, height)) {
                this.enabled = !this.enabled;
                return true;
            }
            return false;
        }

        @Override
        public void drawButtonForegroundLayer(int x, int y) {
            ArrayList<String> list = new ArrayList<>();
            list.addAll(this.tooltip);
            list.add((!this.enabled ? TextFormatting.GREEN + TextFormatting.ITALIC.toString() + "Enabled" : TextFormatting.RED + TextFormatting.ITALIC.toString() + "Disabled"));
            drawHoveringText(list, x, y);
        }
    }
}

@@ -1426,22 +1426,16 @@
 rayList%3C
-String
 %3E();%0A%0A  
@@ -2103,222 +2103,8 @@
  %7D%0A%0A
-    public static boolean isMouseOver(int mouseX, int mouseY, int xPos, int yPos, int width, int height) %7B%0A        return mouseX %3E= xPos && mouseY %3E= yPos && mouseX %3C xPos + width && mouseY %3C yPos + height;%0A    %7D%0A%0A
     
@@ -3125,11 +3125,207 @@
  %7D%0A    %7D
+%0A%0A    public static boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height) %7B%0A        return mouseX %3E= x && mouseY %3E= y && mouseX %3C x + width && mouseY %3C y + height;%0A    %7D
 %0A%7D%0A

Fix merge