/* * This file is part of OneConfig. * OneConfig - Next Generation Config Library for Minecraft: Java Edition * Copyright (C) 2021, 2022 Polyfrost. * * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * OneConfig is licensed under the terms of version 3 of the GNU Lesser * General Public License as published by the Free Software Foundation, AND * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, * either version 1.0 of the Additional Terms, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License. If not, see . You should * have also received a copy of the Additional Terms Applicable * to OneConfig, as published by Polyfrost. If not, see * */ package cc.polyfrost.oneconfig.utils.gui; import cc.polyfrost.oneconfig.gui.GuiPause; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.libs.universal.UScreen; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.utils.InputHandler; import org.jetbrains.annotations.NotNull; /** *

OneUIScreen

* OneUIScreen is a GUI that can be used to render things on the client's screen. * It contains many handy methods for rendering, including {@link #draw(long, float, InputHandler)} for drawing using OneConfig's {@link RenderManager}. *

It also contains methods for mouse input. (see {@link InputHandler} for more utils). *

* Use GuiUtils to display a screen; and GuiUtils.closeScreen to close it. */ public abstract class OneUIScreen extends UScreen implements GuiPause { private final boolean useMinecraftScale; private final InputHandler inputHandler = new InputHandler(); /** * Create a new OneUIScreen. * * @param useMinecraftScale wether to use Minecraft scale * @param restoreGuiOnClose use this to declare weather or not to open the Gui that was open before it when this screen is closed. */ public OneUIScreen(boolean useMinecraftScale, boolean restoreGuiOnClose) { super(restoreGuiOnClose); this.useMinecraftScale = useMinecraftScale; } /** * Create a new OneUIScreen. * * @param useMinecraftScale wether to use Minecraft scale */ public OneUIScreen(boolean useMinecraftScale) { this(useMinecraftScale, false); } /** * Create a new OneUIScreen. */ public OneUIScreen() { this(false, false); } @Override public final void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); if (useMinecraftScale) inputHandler.scale(UResolution.getScaleFactor(), UResolution.getScaleFactor()); RenderManager.setupAndDraw(useMinecraftScale, vg -> draw(vg, partialTicks, inputHandler)); } /** * Use this method to draw things on the screen. It is called every render tick, and has a handy vg (NanoVG context) that can be used with the {@link RenderManager} to draw things. *

* For example: {@link RenderManager#drawRoundedRect(long, float, float, float, float, int, float)} * * @param vg The NanoVG context you can use to render things with * @param partialTicks The time between ticks (You can use this as a deltaTime equivalent) * @param inputHandler The input handler */ public abstract void draw(long vg, float partialTicks, InputHandler inputHandler); /** * @return If this gui has background blur */ public boolean hasBackgroundBlur() { return false; } @Override public boolean doesGuiPauseGame() { return false; } }