-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.20' into 1.20
- Loading branch information
Showing
36 changed files
with
666 additions
and
280 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ColorEditbox.java
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,75 @@ | ||
package com.teammoeg.frostedheart.base.client.gui.widget; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.teammoeg.frostedheart.util.client.FHColorHelper; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.EditBox; | ||
import net.minecraft.network.chat.Component; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ColorEditbox extends EditBox { | ||
private static final String PREFIX = "0x"; | ||
private static final String PREFIX_WITH_ALPHA = "0xFF"; | ||
protected final Font font; | ||
protected final boolean withAlpha; | ||
|
||
public ColorEditbox(Font font, int x, int y, int width, int height, Component message) { | ||
this(font, x, y, width, height, message, true, 0); | ||
} | ||
|
||
public ColorEditbox(Font font, int x, int y, int width, int height, Component message, boolean withAlpha, int colorValue) { | ||
super(font, x, y, width, height, message); | ||
this.font = font; | ||
this.withAlpha = withAlpha; | ||
setValue(colorValue); | ||
setMaxLength(withAlpha ? 6 : 8); | ||
setResponder(s -> { | ||
try { | ||
setTextColor(FHColorHelper.WHITE); | ||
Integer.parseUnsignedInt(s, 16); | ||
} catch (NumberFormatException e) { | ||
setTextColor(FHColorHelper.RED); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTick) { | ||
super.renderWidget(graphics, mouseX, mouseY, partialTick); | ||
graphics.drawString(font, getPrefix(), getX()-2-font.width(getPrefix()), getY()+(getHeight()/2)-4, 0xFFFFFFFF); | ||
|
||
PoseStack pose = graphics.pose(); | ||
pose.pushPose(); | ||
pose.translate(1, 1, 0); | ||
graphics.fill(getX()+getWidth()+2, getY(), getX()+getWidth()+getHeight()+2, getY()+getHeight(), FHColorHelper.makeDark(getColorValue(), 0.25F)); | ||
pose.translate(-1, -1, 0); | ||
graphics.fill(getX()+getWidth()+2, getY(), getX()+getWidth()+getHeight()+2, getY()+getHeight(), getColorValue()); | ||
pose.popPose(); | ||
} | ||
|
||
public int getColorValue() { | ||
try { | ||
return withAlpha ? FHColorHelper.setAlpha(Integer.parseUnsignedInt(getValue(), 16), 1F) : Integer.parseUnsignedInt(getValue(), 16); | ||
} catch (NumberFormatException e) { | ||
return FHColorHelper.RED; | ||
} | ||
} | ||
|
||
public void setValue(int value) { | ||
if (withAlpha) { | ||
setValue(FHColorHelper.toHexString(value).substring(2).toUpperCase()); | ||
} else { | ||
setValue(FHColorHelper.toHexString(value).toUpperCase()); | ||
} | ||
} | ||
|
||
private String getPrefix() { | ||
return withAlpha ? PREFIX_WITH_ALPHA : PREFIX; | ||
} | ||
|
||
@Override | ||
public @NotNull String getValue() { | ||
return (withAlpha ? "FF" : "") + super.getValue(); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/IconCheckbox.java
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,47 @@ | ||
package com.teammoeg.frostedheart.base.client.gui.widget; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.teammoeg.frostedheart.util.client.FHColorHelper; | ||
import com.teammoeg.frostedheart.util.client.FHGuiHelper; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.Checkbox; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.util.Mth; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class IconCheckbox extends Checkbox { | ||
private static final IconButton.Icon SELECTED_ICON = IconButton.Icon.CHECK; | ||
private int scale; | ||
|
||
public IconCheckbox(int pX, int pY, Component pMessage, boolean pSelected) { | ||
this(pX, pY, 1, pMessage, pSelected); | ||
} | ||
|
||
public IconCheckbox(int pX, int pY, int scale, Component pMessage, boolean pSelected) { | ||
super(pX, pY, SELECTED_ICON.size.width, SELECTED_ICON.size.height, pMessage, pSelected, false); | ||
this.scale = Mth.clamp(scale, 1, Integer.MAX_VALUE); | ||
width *= scale; | ||
height *= scale; | ||
} | ||
|
||
public void setScale(int scale) { | ||
int w = this.width / this.scale; | ||
int h = this.height / this.scale; | ||
this.scale = scale; | ||
this.width = w * scale; | ||
this.height = h * scale; | ||
} | ||
|
||
@Override | ||
public void renderWidget(@NotNull GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { | ||
IconButton.Icon icon = selected() ? SELECTED_ICON : IconButton.Icon.CROSS; | ||
RenderSystem.enableDepthTest(); | ||
pGuiGraphics.setColor(1.0F, 1.0F, 1.0F, this.alpha); | ||
RenderSystem.enableBlend(); | ||
FHGuiHelper.bindTexture(IconButton.ICON_LOCATION); | ||
FHGuiHelper.blitColored(pGuiGraphics.pose(), getX(), getY(), getWidth(), getHeight(), icon.x*scale, icon.y*scale, getWidth(), getHeight(), IconButton.TEXTURE_WIDTH*scale, IconButton.TEXTURE_HEIGHT*scale, FHColorHelper.CYAN, alpha); | ||
pGuiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.