Skip to content

Commit

Permalink
uhhh this didn't work either
Browse files Browse the repository at this point in the history
  • Loading branch information
Permdog99 committed Jan 19, 2025
1 parent 8b8ef5f commit 8d9c71f
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@
/// @see StateSwitchingButton
public class LegacyTabButton extends StateSwitchingButton {
public final Function<LegacyTabButton, Renderable> icon;
private final Consumer<LegacyTabButton> onPress;
public 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) {
public LegacyTabButton(int x, int y, int width, int height, boolean isStateTriggered, int selectedTabIndex, 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);
}

Expand Down Expand Up @@ -97,6 +95,11 @@ public void onClick(double mouseX, double mouseY) {
onPress.accept(this);
}

public void onPress() {
isStateTriggered = !isStateTriggered;
onPress.accept(this);
}

@Override
protected boolean clicked(double d, double e) {
return isMouseOver(d,e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,104 @@
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 org.jetbrains.annotations.Nullable;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;

public class LegacyTabListing implements Renderable, GuiEventListener, NarratableEntry {
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;

public class LegacyTabListing implements Renderable, GuiEventListener, NarratableEntry {
public final List<LegacyTabButton> tabs;
public int selectedIndex = 0;
public boolean isFocused = false;
public LegacyWidgetSprites genericTabWidgets = new LegacyWidgetSprites(Sprites.CRAFTING_TAB_LEFT_SIDE, Sprites.CRAFTING_TAB_CENTER, Sprites.CRAFTING_TAB_RIGHT_SIDE, Sprites.CRAFTING_TAB_SELECTED_SIDE, Sprites.CRAFTING_TAB_SELECTED, Sprites.CRAFTING_TAB_SELECTED_SIDE);

public LegacyTabListing() {
this.tabs = new ArrayList<>();
}

public void addTab(LegacyTabButton tab) {
this.tabs.add(tab);
}

public void addTab(int x, int y, int width, int height, boolean isStateTriggered, Component text, LegacyWidgetSprites sprites, Function<LegacyTabButton, Renderable> icon, Consumer<LegacyTabButton> onPress) {
addTab(new LegacyTabButton(x, y, width, height, isStateTriggered, selectedIndex, text, sprites, icon, p -> {
if (selectedIndex != this.tabs.indexOf(p)) {
selectedIndex = this.tabs.indexOf(p);
onPress.accept(p);
}
}));
}

public LegacyTabListing createTab(int x, int y, int width, int height, boolean isStateTriggered, Component text, LegacyWidgetSprites sprites, Function<LegacyTabButton, Renderable> icon, Consumer<LegacyTabButton> onPress) {
this.addTab(x, y, width, height, isStateTriggered, text, sprites, icon, onPress);
return this;
}

public LegacyTabListing createTabWithPredeterminedTabWidget(int x, int y, int width, int height, boolean isStateTriggered, Component text, Function<LegacyTabButton, Renderable> icon, Consumer<LegacyTabButton> onPress) {
this.addTab(x, y, width, height, isStateTriggered, text, this.genericTabWidgets, icon, onPress);
return this;
}

public LegacyTabListing createMultipleTabs(int tabAmount, int x, int y, int width, int height, Component text, @Nullable LegacyWidgetSprites sprites, List<Function<LegacyTabButton, Renderable>> icons, Consumer<LegacyTabButton> onPress) {
for (int i = 0; i <= tabAmount; i++) {
LegacyWidgetSprites widgets = sprites != null ? sprites : this.genericTabWidgets;
this.addTab(x, y, width, height, false, text, widgets, icons.get(i), onPress);
}
return this;
}

public void init(int x, int y, int width, boolean isVertical) {
int xPos = 0;

BiConsumer<LegacyTabButton, Integer> finalTabManager = (tabList, i)->{};
BiConsumer<LegacyTabButton, Integer> tabManager = (tabList, i) -> {
tabList.setWidth(width / this.tabs.size());
tabList.setX(x + i);
tabList.setY(y);
finalTabManager.accept(tabList, i);
};

for (LegacyTabButton tabList : this.tabs) {
tabManager.accept(tabList, xPos);
xPos += isVertical ? tabList.getHeight() : tabList.getWidth();
}
}

public void setSelectedTab(int index){
if (!this.tabs.isEmpty()) {
selectedIndex = -1;
this.tabs.get(index).onPress();
}
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {

for (int index = 0; index < this.tabs.size(); index++) {
LegacyTabButton tab = this.tabs.get(index);
tab.setStateTriggered(this.selectedIndex == index);
tab.render(guiGraphics, mouseX, mouseY, partialTick);
}
}

@Override
public void setFocused(boolean focused) {

focused = this.isFocused;
}

@Override
public boolean isFocused() {
return false;
return isFocused;
}

@Override
public boolean mouseClicked(double a, double b, int c) {
return !this.tabs.stream().filter(tabs-> tabs.mouseClicked(a, b, c)).toList().isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.violaflower.legacy_tweaks.client.gui.element.LegacyTabButton;
import xyz.violaflower.legacy_tweaks.client.gui.element.LegacyTabListing;
import xyz.violaflower.legacy_tweaks.client.gui.element.LegacyWidgetSprites;
import xyz.violaflower.legacy_tweaks.client.gui.extention.SlotExtension;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyAutoCraftingScreen;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyInventoryScreen;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand All @@ -49,7 +51,7 @@ public class LegacyRecipeBookCraftingScreen extends LegacyAutoCraftingScreen<Inv
private static float staticLeftPos;
private static float staticTopPos;
public ClientRecipeBook book;
public final List<LegacyTabButton> tabs = new ArrayList<>();
public LegacyTabListing tabs = new LegacyTabListing();
public LegacyTabButton selectedTab;
protected RecipeBookMenu<?, ?> menu;
private final RecipeBookPage recipeBookPage = new RecipeBookPage();
Expand All @@ -65,7 +67,6 @@ public LegacyRecipeBookCraftingScreen(Player player, Screen parent) {
this.parent = parent;
staticLeftPos = this.leftPos - (useSmallCrafting() ? 36.5f : 0f);
staticTopPos = this.topPos;

}

protected void init(Minecraft minecraft, RecipeBookMenu<?, ?> menu) {
Expand All @@ -76,34 +77,34 @@ protected void init(Minecraft minecraft, RecipeBookMenu<?, ?> menu) {
}

public void initBook() {
this.tabs.clear();
this.tabs.tabs.clear();
createTabs();
this.recipeBookPage.init(this.minecraft, (int) this.leftPos, (int) this.topPos);
// this.recipeBookPage.addListener(this);
this.selectedTab.setStateTriggered(true);
setVisible();
this.updateCollections(false);
this.createTabs1();
this.createTabs();
this.updateTabs();
}

private void createTabs() {
List<RecipeBookCategories> categoryIndex = RecipeBookCategories.getCategories(RecipeBookType.CRAFTING);
this.tabs.createMultipleTabs(7, (int) this.leftPos, (int) this.topPos, 20, 20, Component.empty(), sprites, createIcons(categoryIndex.size()), tabs -> updateTabs());
}

private List<Function<LegacyTabButton, Renderable>> createIcons(int categoryIndex) {
List<Function<LegacyTabButton, Renderable>> icons = new ArrayList<>(List.of());
for(RecipeBookCategories recipeBookCategories : RecipeBookCategories.getCategories(RecipeBookType.CRAFTING)) {
List<RecipeBookCategories> categoryIndex = RecipeBookCategories.getCategories(RecipeBookType.CRAFTING);
for (int i = 0; i == categoryIndex.size(); i++) {
Function<LegacyTabButton, Renderable> icon = LegacyTabButton.createIconItem(recipeBookCategories.getIconItems().get(i));
int xPos = (int) (this.leftPos - 20) + (i * 20);
this.tabs.add(new LegacyTabButton(xPos, (int) this.topPos - 20, 101, 66, false, i == 0 ? 0 : i == categoryIndex.getLast().hashCode() ? 2 : 1, categoryIndex.indexOf(i), this.title, this.sprites, icon, b -> changeTab()));
for (int i = 0; i <= categoryIndex; i++) {
icons.add(LegacyTabButton.createIconItem(recipeBookCategories.getIconItems().get(i)));
}
}
}

private void createTabs1() {
this.tabs.add(new LegacyTabButton((int) this.leftPos, (int) this.topPos - 20, 101, 66, false, 1, 0, this.title, this.sprites, LegacyTabButton.createIconItem(ItemStack.EMPTY), b -> changeTab()));
return icons;
}

private RecipeBookCategories getCategory() {
return RecipeBookCategories.getCategories(RecipeBookType.CRAFTING).get(this.tabs.get(this.selectedTab.tabIndex).tabIndex);
return RecipeBookCategories.getCategories(RecipeBookType.CRAFTING).get(this.tabs.selectedIndex);
}

protected void setVisible() {
Expand Down Expand Up @@ -202,7 +203,7 @@ protected void sendUpdateSettings() {
@Override
protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
super.renderBg(guiGraphics, partialTick, mouseX, mouseY);
for(LegacyTabButton recipeBookTabButton : this.tabs) {
for(LegacyTabButton recipeBookTabButton : this.tabs.tabs) {
recipeBookTabButton.render(guiGraphics, mouseX, mouseY, partialTick);
}
}
Expand Down

0 comments on commit 8d9c71f

Please sign in to comment.