forked from IrisShaders/Iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # gradle.properties
- Loading branch information
Showing
9 changed files
with
241 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package net.coderbot.iris.gui; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawableHelper; | ||
import net.minecraft.client.sound.PositionedSoundInstance; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.Identifier; | ||
|
||
/** | ||
* Class serving as abstraction and | ||
* centralization for common GUI | ||
* rendering/other code calls. | ||
* | ||
* Helps allow for easier portability | ||
* to Minecraft 1.17 by abstracting | ||
* some code that will be changed. | ||
*/ | ||
public final class GuiUtil { | ||
private static final Identifier IRIS_WIDGETS_TEX = new Identifier("iris", "textures/gui/widgets.png"); | ||
|
||
private GuiUtil() {} | ||
|
||
private static MinecraftClient client() { | ||
return MinecraftClient.getInstance(); | ||
} | ||
|
||
/** | ||
* Binds Iris's widgets texture to be | ||
* used for succeeding draw calls. | ||
*/ | ||
public static void bindIrisWidgetsTexture() { | ||
client().getTextureManager().bindTexture(IRIS_WIDGETS_TEX); | ||
} | ||
|
||
/** | ||
* Draws a button. Button textures must be mapped with the | ||
* same coordinates as those on the vanilla widgets texture. | ||
* | ||
* @param x X position of the left of the button | ||
* @param y Y position of the top of the button | ||
* @param width Width of the button, maximum 398 | ||
* @param height Height of the button, maximum 20 | ||
* @param hovered Whether the button is being hovered over with the mouse | ||
* @param disabled Whether the button should use the "disabled" texture | ||
*/ | ||
public static void drawButton(MatrixStack matrices, int x, int y, int width, int height, boolean hovered, boolean disabled) { | ||
// Create variables for half of the width and height. | ||
// Will not be exact when width and height are odd, but | ||
// that case is handled within the draw calls. | ||
int halfWidth = width / 2; | ||
int halfHeight = height / 2; | ||
|
||
// V offset for which button texture to use | ||
int vOffset = disabled ? 46 : hovered ? 86 : 66; | ||
|
||
// Sets RenderSystem to use solid white as the tint color for blend mode, and enables blend mode | ||
RenderSystem.blendColor(1.0f, 1.0f, 1.0f, 1.0f); | ||
RenderSystem.enableBlend(); | ||
|
||
// Sets RenderSystem to be able to use textures when drawing | ||
RenderSystem.enableTexture(); | ||
|
||
// Top left section | ||
DrawableHelper.drawTexture(matrices, x, y, 0, vOffset, halfWidth, halfHeight, 256, 256); | ||
// Top right section | ||
DrawableHelper.drawTexture(matrices, x + halfWidth, y, 200 - (width - halfWidth), vOffset, width - halfWidth, halfHeight, 256, 256); | ||
// Bottom left section | ||
DrawableHelper.drawTexture(matrices, x, y + halfHeight, 0, vOffset + (20 - (height - halfHeight)), halfWidth, height - halfHeight, 256, 256); | ||
// Bottom right section | ||
DrawableHelper.drawTexture(matrices, x + halfWidth, y + halfHeight, 200 - (width - halfWidth), vOffset + (20 - (height - halfHeight)), width - halfWidth, height - halfHeight, 256, 256); | ||
} | ||
|
||
/** | ||
* Plays the {@code UI_BUTTON_CLICK} sound event as a | ||
* master sound effect. | ||
* | ||
* Used in non-{@code ButtonWidget} UI elements upon click | ||
* or other action. | ||
*/ | ||
public static void playButtonClickSound() { | ||
client().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.