mirror of
https://github.com/neoforged/NeoForge.git
synced 2026-10-11 22:29:51 +00:00
Refactor AbstractWidget#getFGColor as getLabelTextColor (#3063)
Co-authored-by: sciwhiz12 <[email protected]>
This commit is contained in:
co-authored by
sciwhiz12
parent
7729606851
commit
ab7294afb1
@@ -1,14 +1,15 @@
|
||||
--- a/net/minecraft/client/gui/components/AbstractButton.java
|
||||
+++ b/net/minecraft/client/gui/components/AbstractButton.java
|
||||
@@ -40,7 +_,13 @@
|
||||
@@ -40,7 +_,14 @@
|
||||
protected abstract void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a);
|
||||
|
||||
protected void extractDefaultLabel(ActiveTextCollector output) {
|
||||
- this.extractScrollingStringOverContents(output, this.getMessage(), 2);
|
||||
+ // Neo: Apply forced foreground color if set
|
||||
+ var message = this.getMessage();
|
||||
+ if (getFGColor() != UNSET_FG_COLOR) {
|
||||
+ message = message.copy().withStyle(style -> style.withColor(getFGColor()));
|
||||
+ // Neo: Apply forced label text color if set
|
||||
+ Component message = this.getMessage();
|
||||
+ if (this.labelTextColor != null) {
|
||||
+ int labelTextColor = this.labelTextColor; // Unbox ahead of time so no warning about unboxing in withStyle's lambda
|
||||
+ message = message.copy().withStyle(style -> style.withColor(labelTextColor));
|
||||
+ }
|
||||
+
|
||||
+ this.extractScrollingStringOverContents(output, message, 2);
|
||||
|
||||
@@ -1,22 +1,36 @@
|
||||
--- a/net/minecraft/client/gui/components/AbstractWidget.java
|
||||
+++ b/net/minecraft/client/gui/components/AbstractWidget.java
|
||||
@@ -225,6 +_,19 @@
|
||||
this.focused = focused;
|
||||
}
|
||||
@@ -41,6 +_,8 @@
|
||||
private int tabOrderGroup;
|
||||
private boolean focused;
|
||||
private final WidgetTooltipHolder tooltip = new WidgetTooltipHolder();
|
||||
+ /// Neo: Stores the label text color override. See [#getLabelTextColor()] and [#setLabelTextColor].
|
||||
+ protected @Nullable Integer labelTextColor = null;
|
||||
|
||||
+ public static final int UNSET_FG_COLOR = -1;
|
||||
+ protected int packedFGColor = UNSET_FG_COLOR;
|
||||
+ public int getFGColor() {
|
||||
+ if (packedFGColor != UNSET_FG_COLOR) return packedFGColor;
|
||||
+ return this.active ? -1 : -6250336; // White : Light Grey
|
||||
+ }
|
||||
+ public void setFGColor(int color) {
|
||||
+ this.packedFGColor = color;
|
||||
+ }
|
||||
+ public void clearFGColor() {
|
||||
+ this.packedFGColor = UNSET_FG_COLOR;
|
||||
public AbstractWidget(int x, int y, int width, int height, Component message) {
|
||||
this.x = x;
|
||||
@@ -223,6 +_,24 @@
|
||||
@Override
|
||||
public void setFocused(boolean focused) {
|
||||
this.focused = focused;
|
||||
+ }
|
||||
+
|
||||
+ /// Neo: {@return the widget's label text color} If a custom text color has been set, that color will be used.
|
||||
+ /// If a custom text color has not been set, [net.minecraft.util.CommonColors#WHITE] will be used when active,
|
||||
+ /// and [net.minecraft.util.CommonColors#LIGHT_GRAY] otherwise.
|
||||
+ ///
|
||||
+ /// Subclasses may override this to provide more advanced text color handling.
|
||||
+ public int getLabelTextColor() {
|
||||
+ return this.labelTextColor != null
|
||||
+ ? this.labelTextColor
|
||||
+ : this.active ? net.minecraft.util.CommonColors.WHITE : net.minecraft.util.CommonColors.LIGHT_GRAY;
|
||||
+ }
|
||||
+
|
||||
+ /// Neo: Sets the label text color for this widget based on the given ARGB value, or `null` to reset it to the default colors.
|
||||
+ ///
|
||||
+ /// @param color the new label text color as an ARGB value, or `null` to reset to default
|
||||
+ public void setLabelTextColor(@Nullable Integer color) {
|
||||
+ this.labelTextColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NarratableEntry.NarrationPriority narrationPriority() {
|
||||
if (this.isFocused()) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ExtendedButton extends Button {
|
||||
guiGraphics.blitSprite(RenderPipelines.GUI_TEXTURED, SPRITES.get(this.active, this.isHoveredOrFocused()), this.getX(), this.getY(), this.getWidth(), this.getHeight());
|
||||
|
||||
final FormattedText buttonText = mc.font.ellipsize(this.getMessage(), this.width - 6); // Remove 6 pixels so that the text is always contained within the button's borders
|
||||
guiGraphics.centeredText(mc.font, Language.getInstance().getVisualOrder(buttonText), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, getFGColor());
|
||||
guiGraphics.centeredText(mc.font, Language.getInstance().getVisualOrder(buttonText), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, this.getLabelTextColor());
|
||||
|
||||
if (this.isHovered())
|
||||
guiGraphics.requestCursor(this.isActive() ? CursorTypes.POINTING_HAND : CursorTypes.NOT_ALLOWED);
|
||||
|
||||
@@ -46,10 +46,10 @@ public class UnicodeGlyphButton extends ExtendedButton {
|
||||
guiGraphics.pose().scale(glyphScale, glyphScale);
|
||||
guiGraphics.centeredText(mc.font, Component.literal(glyph),
|
||||
(int) (((this.getX() + (this.width / 2) - (strWidth / 2)) / glyphScale) - (glyphWidth / (2 * glyphScale)) + 2),
|
||||
(int) (((this.getY() + ((this.height - 8) / glyphScale) / 2) - 1) / glyphScale), getFGColor());
|
||||
(int) (((this.getY() + ((this.height - 8) / glyphScale) / 2) - 1) / glyphScale), this.getLabelTextColor());
|
||||
guiGraphics.pose().popMatrix();
|
||||
|
||||
guiGraphics.centeredText(mc.font, buttonText, (int) (this.getX() + (this.width / 2) + (glyphWidth / glyphScale)),
|
||||
this.getY() + (this.height - 8) / 2, getFGColor());
|
||||
this.getY() + (this.height - 8) / 2, this.getLabelTextColor());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user