// Path: src/main/java/uk/kihira/tails/client/gui/GuiBaseScreen.java
// @OnlyIn(Dist.CLIENT)
// public abstract class GuiBaseScreen extends Screen
// {
//     private int prevMouseX;
//     private int prevMouseY;
//     private float mouseIdleTicks;
// 
//     protected GuiBaseScreen(ITextComponent titleIn)
//     {
//         super(titleIn);
//     }
// 
//     @Override
//     public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks)
//     {
//         super.render(matrixStack, mouseX, mouseY, partialTicks);
// 
//         // Tooltips
//         for (Widget btn : buttons)
//         {
//             if (btn instanceof ITooltip && btn.isMouseOver(mouseX, mouseY))
//             {
//                 if (prevMouseX == mouseX && prevMouseY == mouseY) mouseIdleTicks += partialTicks;
//                 else if (mouseIdleTicks > 0f) mouseIdleTicks = 0f;
//                 // todo drawHoveringText(((ITooltip) btn).getTooltip(mouseX, mouseY, mouseIdleTicks), mouseX, mouseY);
//                 prevMouseX = mouseX;
//                 prevMouseY = mouseY;
//                 break;
//             }
//         }
//     }
// 
//     public static class GuiButtonToggle extends Button
//     {
//         public GuiButtonToggle(int x, int y, int width, int height, ITextComponent text, int maxTextWidth, String... tooltips)
//         {
//             super(x, y, width, height, text, (a) -> {}, (button, matrixStack, mouseX, mouseY) ->
//             {
//                 if (!button.active)
//                 {
//                     // todo Screen.renderTooltip(matrixStack, Minecraft.getInstance().fontRenderer.trimStringToWidth(new StringTextComponent(tooltips), Math.max(this.width / 2 - 43, 170)), mouseX, mouseY);
//                 }
//             });
//         }
// 
//         @Override
//         public boolean mouseClicked(double mouseX, double mouseY, int button)
//         {
//             if (this.visible && GuiBaseScreen.isMouseOver(mouseX, mouseY, x, y, width, height))
//             {
//                 this.active = !this.active;
//                 return true;
//             }
//             return false;
//         }
// 
//         // TODO
// /*        @Override
//         public void drawButtonForegroundLayer(int x, int y)
//         {
//             ArrayList<String> list = new ArrayList<>(this.tooltip);
//             list.add((!this.enabled ? TextFormatting.GREEN + TextFormatting.ITALIC.toString() + "Enabled" : TextFormatting.RED + TextFormatting.ITALIC.toString() + "Disabled"));
//             drawHoveringText(list, x, y);
//         }*/
//     }
// 
//     public static boolean isMouseOver(double mouseX, double mouseY, double x, double y, double width, double height)
//     {
//         return mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
//     }
// }
// 
// Path: src/main/java/uk/kihira/tails/client/gui/IControl.java
// public interface IControl<V> {
// 
//     void setValue(V newValue);
// 
//     V getValue();
// }
// 
// Path: src/main/java/uk/kihira/tails/client/gui/IControlCallback.java
// public interface IControlCallback<T extends IControl<V>, V> {
// 
//     boolean onValueChange(T slider, V oldValue, V newValue);
// }
// 
// Path: src/main/java/uk/kihira/tails/client/gui/ITooltip.java
// @Nonnull
// public interface ITooltip {
//     List<String> getTooltip(int mouseX, int mouseY, float mouseIdleTime);
// }


import com.google.common.base.Strings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import uk.kihira.tails.client.gui.GuiBaseScreen;
import uk.kihira.tails.client.gui.IControl;
import uk.kihira.tails.client.gui.IControlCallback;
import uk.kihira.tails.client.gui.ITooltip;
import javax.annotation.Nullable;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package uk.kihira.tails.client.gui.controls;



// todo tooltips only work for guibuttons
@OnlyIn(Dist.CLIENT)
public class NumberInput extends Widget implements IControl<Float>, ITooltip
{
    private static final char[] VALID_CHARS = new char[]{'-', '.', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
    private static final float SHIFT_MOD = 10f;
    private static final float CTRL_MOD = 0.1f;

    private final int xPos;
    private final int yPos;

    private final float min;
    private final float max;
    private final float increment;

    private final int btnWidth = 10;
    private final int btnXPos;
    private final int btnHeight;

    private final DecimalFormat df = new DecimalFormat("###.##");
    private final TextFieldWidget numInput;
    private float num = 0f;
// Path: src/main/java/uk/kihira/tails/client/gui/GuiBaseScreen.java
// @OnlyIn(Dist.CLIENT)
// public abstract class GuiBaseScreen extends Screen
// {
//     private int prevMouseX;
//     private int prevMouseY;
//     private float mouseIdleTicks;
// 
//     protected GuiBaseScreen(ITextComponent titleIn)
//     {
//         super(titleIn);
//     }
// 
//     @Override
//     public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks)
//     {
//         super.render(matrixStack, mouseX, mouseY, partialTicks);
// 
//         // Tooltips
//         for (Widget btn : buttons)
//         {
//             if (btn instanceof ITooltip && btn.isMouseOver(mouseX, mouseY))
//             {
//                 if (prevMouseX == mouseX && prevMouseY == mouseY) mouseIdleTicks += partialTicks;
//                 else if (mouseIdleTicks > 0f) mouseIdleTicks = 0f;
//                 // todo drawHoveringText(((ITooltip) btn).getTooltip(mouseX, mouseY, mouseIdleTicks), mouseX, mouseY);
//                 prevMouseX = mouseX;
//                 prevMouseY = mouseY;
//                 break;
//             }
//         }
//     }
// 
//     public static class GuiButtonToggle extends Button
//     {
//         public GuiButtonToggle(int x, int y, int width, int height, ITextComponent text, int maxTextWidth, String... tooltips)
//         {
//             super(x, y, width, height, text, (a) -> {}, (button, matrixStack, mouseX, mouseY) ->
//             {
//                 if (!button.active)
//                 {
//                     // todo Screen.renderTooltip(matrixStack, Minecraft.getInstance().fontRenderer.trimStringToWidth(new StringTextComponent(tooltips), Math.max(this.width / 2 - 43, 170)), mouseX, mouseY);
//                 }
//             });
//         }
// 
//         @Override
//         public boolean mouseClicked(double mouseX, double mouseY, int button)
//         {
//             if (this.visible && GuiBaseScreen.isMouseOver(mouseX, mouseY, x, y, width, height))
//             {
//                 this.active = !this.active;
//                 return true;
//             }
//             return false;
//         }
// 
//         // TODO
// /*        @Override
//         public void drawButtonForegroundLayer(int x, int y)
//         {
//             ArrayList<String> list = new ArrayList<>(this.tooltip);
//             list.add((!this.enabled ? TextFormatting.GREEN + TextFormatting.ITALIC.toString() + "Enabled" : TextFormatting.RED + TextFormatting.ITALIC.toString() + "Disabled"));
//             drawHoveringText(list, x, y);
//         }*/
//     }
// 
//     public static boolean isMouseOver(double mouseX, double mouseY, double x, double y, double width, double height)
//     {
//         return mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
//     }
// }
// 
// Path: src/main/java/uk/kihira/tails/client/gui/IControl.java
// public interface IControl<V> {
// 
//     void setValue(V newValue);
// 
//     V getValue();
// }
// 
// Path: src/main/java/uk/kihira/tails/client/gui/IControlCallback.java
// public interface IControlCallback<T extends IControl<V>, V> {
// 
//     boolean onValueChange(T slider, V oldValue, V newValue);
// }
// 
// Path: src/main/java/uk/kihira/tails/client/gui/ITooltip.java
// @Nonnull
// public interface ITooltip {
//     List<String> getTooltip(int mouseX, int mouseY, float mouseIdleTime);
// }


// Path: src/main/java/uk/kihira/tails/client/gui/controls/NumberInput.java
import com.google.common.base.Strings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import uk.kihira.tails.client.gui.GuiBaseScreen;
import uk.kihira.tails.client.gui.IControl;
import uk.kihira.tails.client.gui.IControlCallback;
import uk.kihira.tails.client.gui.ITooltip;
import javax.annotation.Nullable;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

package uk.kihira.tails.client.gui.controls;



// todo tooltips only work for guibuttons
@OnlyIn(Dist.CLIENT)
public class NumberInput extends Widget implements IControl<Float>, ITooltip
{
    private static final char[] VALID_CHARS = new char[]{'-', '.', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
    private static final float SHIFT_MOD = 10f;
    private static final float CTRL_MOD = 0.1f;

    private final int xPos;
    private final int yPos;

    private final float min;
    private final float max;
    private final float increment;

    private final int btnWidth = 10;
    private final int btnXPos;
    private final int btnHeight;

    private final DecimalFormat df = new DecimalFormat("###.##");
    private final TextFieldWidget numInput;
    private float num = 0f;
    private IControlCallback<IControl<Float>, Float> callback;