-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
389 additions
and
12 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/main/java/xyz/violaflower/legacy_tweaks/client/gui/element/LegacyTabButton.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,109 @@ | ||
package xyz.violaflower.legacy_tweaks.client.gui.element; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.*; | ||
import net.minecraft.client.gui.narration.NarratedElementType; | ||
import net.minecraft.client.gui.narration.NarrationElementOutput; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
/// @see StateSwitchingButton | ||
public class LegacyTabButton extends StateSwitchingButton { | ||
public final Function<LegacyTabButton, Renderable> icon; | ||
private final Consumer<LegacyTabButton> onPress; | ||
protected int selectedTabIndex; | ||
public LegacyWidgetSprites widgets; | ||
public final Component text; | ||
public int tabIndex; | ||
|
||
public LegacyTabButton(int x, int y, int width, int height, boolean isStateTriggered, int selectedTabIndex, int tabIndex, Component text, LegacyWidgetSprites sprites, Function<LegacyTabButton, Renderable> icon, Consumer<LegacyTabButton> onPress) { | ||
super(x, y, width, height, isStateTriggered); | ||
this.icon = icon; | ||
this.onPress = onPress; | ||
this.selectedTabIndex = selectedTabIndex; | ||
this.text = text; | ||
this.isStateTriggered = isStateTriggered; | ||
this.tabIndex = tabIndex; | ||
this.initTextureValues(sprites); | ||
} | ||
|
||
public void initTextureValues(LegacyWidgetSprites widgets) { | ||
this.widgets = widgets; | ||
} | ||
|
||
@Override | ||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { | ||
if (this.widgets != null) { | ||
int i = this.getY(); | ||
if (this.isStateTriggered) { | ||
i -= 2; | ||
} | ||
RenderSystem.disableDepthTest(); | ||
guiGraphics.blitSprite(this.widgets.get(this.isStateTriggered, this.selectedTabIndex), this.getX(), i, this.width, this.height); | ||
RenderSystem.enableDepthTest(); | ||
} | ||
} | ||
|
||
public void setStateTriggered(boolean triggered) { | ||
this.isStateTriggered = triggered; | ||
} | ||
|
||
public boolean isStateTriggered() { | ||
return this.isStateTriggered; | ||
} | ||
|
||
public static Function<LegacyTabButton,Renderable> createIconItem(Item item){ | ||
return b-> (guiGraphics, i, j, f) -> b.renderItem(guiGraphics, item.getDefaultInstance()); | ||
} | ||
|
||
public static Function<LegacyTabButton,Renderable> createIconItem(ItemStack itemStack){ | ||
return b-> (guiGraphics, i, j, f) -> b.renderItem(guiGraphics, itemStack); | ||
} | ||
|
||
public static Function<LegacyTabButton,Renderable> createIconSprite(ResourceLocation icon){ | ||
return b-> (guiGraphics, i, j, f) -> b.renderIcon(guiGraphics, icon); | ||
} | ||
|
||
public static Function<LegacyTabButton,Renderable> createTextIcon(int color) { | ||
return b -> (graphics, i, j, f) -> b.renderString(graphics, Minecraft.getInstance().font, color); | ||
} | ||
|
||
private void renderItem(GuiGraphics guiGraphics, ItemStack itemStack) { | ||
int i = this.isStateTriggered ? -2 : 0; | ||
guiGraphics.renderFakeItem(itemStack, this.getX() + this.width/2 - 12, this.getY() + this.height/2 - 12 + i); | ||
} | ||
|
||
private void renderIcon(GuiGraphics guiGraphics, ResourceLocation icon){ | ||
int i = this.isStateTriggered ? -2 : 0; | ||
guiGraphics.blitSprite(icon, getX() + this.width/2 - 12, getY() + this.height/2 - 12 + i, 24, 24); | ||
} | ||
|
||
protected void renderString(GuiGraphics guiGraphics, Font font, int color) { | ||
guiGraphics.drawString(font, this.text, getX() + (this.width - font.width(this.text))/2, getY() + (this.height - 7)/2, color, false); | ||
} | ||
|
||
@Override | ||
public void onClick(double mouseX, double mouseY) { | ||
isStateTriggered = !isStateTriggered; | ||
onPress.accept(this); | ||
} | ||
|
||
@Override | ||
protected boolean clicked(double d, double e) { | ||
return isMouseOver(d,e); | ||
} | ||
|
||
@Override | ||
public void updateWidgetNarration(NarrationElementOutput narrationElementOutput) { | ||
narrationElementOutput.add(NarratedElementType.TITLE, Component.translatable(this.text.getString())); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/xyz/violaflower/legacy_tweaks/client/gui/element/LegacyWidgetSprites.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,30 @@ | ||
package xyz.violaflower.legacy_tweaks.client.gui.element; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public record LegacyWidgetSprites(ResourceLocation enabledLeft, ResourceLocation enabledCenter, ResourceLocation enabledRight, ResourceLocation focusedLeft, ResourceLocation focusedCenter, ResourceLocation focusedRight) { | ||
|
||
public LegacyWidgetSprites(ResourceLocation enabled, ResourceLocation focused) { | ||
this(enabled, enabled, enabled, focused, focused, focused); | ||
} | ||
|
||
public LegacyWidgetSprites(ResourceLocation enabledLeft, ResourceLocation enabledCenter, ResourceLocation enabledRight, ResourceLocation focusedLeft, ResourceLocation focusedCenter, ResourceLocation focusedRight) { | ||
this.enabledLeft = enabledLeft; | ||
this.enabledCenter = enabledCenter; | ||
this.enabledRight = enabledRight; | ||
this.focusedLeft = focusedLeft; | ||
this.focusedCenter = focusedCenter; | ||
this.focusedRight = focusedRight; | ||
} | ||
|
||
public ResourceLocation get(boolean focused, int type) { | ||
if (type == 0) { | ||
return focused ? this.focusedLeft : this.enabledLeft; | ||
} else if (type == 1) { | ||
return focused ? this.focusedCenter : this.enabledCenter; | ||
} else if (type == 2) { | ||
return focused ? this.focusedRight : this.enabledRight; | ||
} | ||
return this.enabledCenter; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/xyz/violaflower/legacy_tweaks/client/gui/element/RecipeBookTabListing.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,44 @@ | ||
package xyz.violaflower.legacy_tweaks.client.gui.element; | ||
|
||
import net.minecraft.client.RecipeBookCategories; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.Renderable; | ||
import net.minecraft.client.gui.components.events.GuiEventListener; | ||
import net.minecraft.client.gui.narration.NarratableEntry; | ||
import net.minecraft.client.gui.narration.NarrationElementOutput; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
public class RecipeBookTabListing implements Renderable, GuiEventListener, NarratableEntry { | ||
public RecipeBookTabListing(RecipeBookCategories category) { | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { | ||
|
||
} | ||
|
||
@Override | ||
public void setFocused(boolean focused) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isFocused() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public NarrationPriority narrationPriority() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void updateNarration(NarrationElementOutput narrationElementOutput) { | ||
|
||
} | ||
} |
Oops, something went wrong.