diff --git a/gradle.properties b/gradle.properties index e52e047..8b93098 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ mod_version=1.4.0-beta maven_group=io.github.darkkronicle archives_base_name=AdvancedChatCore -kommandlib_version=1.0.0-build1 +kommandlib_version=1.0.0-build2 malilib_version = 0.10.0-dev.26 konstruct_version=2.0.2-build1 mxparser_version=4.4.2 diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java b/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java index 24725b4..cf5b8a2 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java @@ -8,6 +8,7 @@ package io.github.darkkronicle.advancedchatcore; import fi.dy.masa.malilib.config.ConfigManager; +import fi.dy.masa.malilib.config.IConfigBase; import fi.dy.masa.malilib.interfaces.IInitializationHandler; import io.github.darkkronicle.advancedchatcore.chat.ChatHistoryProcessor; import io.github.darkkronicle.advancedchatcore.chat.ChatScreenSectionHolder; @@ -40,16 +41,21 @@ public void registerModHandlers() { // Setup chat history MessageDispatcher.getInstance().register(new ChatHistoryProcessor(), -1); - GuiConfigHandler.getInstance() - .addGuiSection( - GuiConfigHandler.createGuiConfigSection( - "advancedchat.config.tab.general", ConfigStorage.General.OPTIONS)); - - GuiConfigHandler.getInstance() - .addGuiSection( - GuiConfigHandler.createGuiConfigSection( - "advancedchat.config.tab.chatscreen", - ConfigStorage.ChatScreen.OPTIONS)); + GuiConfigHandler.getInstance().addTab( + GuiConfigHandler.children( + "advancedchatcore", + "advancedchat.tab.advancedchatcore", + GuiConfigHandler.wrapOptions( + "core_general", + "advancedchatcore.tab.general", + ConfigStorage.General.OPTIONS.stream().map((saveableConfig) -> (IConfigBase) saveableConfig.config).toList() + ), + GuiConfigHandler.wrapOptions( + "chatscreen", + "advancedchatcore.tab.chatscreen", + ConfigStorage.ChatScreen.OPTIONS.stream().map((saveableConfig) -> (IConfigBase) saveableConfig.config).toList() + )) + ); ProfanityUtil.getInstance().loadConfigs(); MessageDispatcher.getInstance().registerPreFilter(text -> { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java index f88e287..14c826f 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java @@ -8,16 +8,19 @@ package io.github.darkkronicle.advancedchatcore.chat; import fi.dy.masa.malilib.gui.GuiBase; +import fi.dy.masa.malilib.gui.button.ButtonBase; import fi.dy.masa.malilib.util.KeyCodes; -import fi.dy.masa.malilib.util.StringUtils; +import io.github.darkkronicle.advancedchatcore.AdvancedChatCore; import io.github.darkkronicle.advancedchatcore.config.ConfigStorage; import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfigHandler; -import io.github.darkkronicle.advancedchatcore.gui.CleanButton; +import io.github.darkkronicle.advancedchatcore.gui.IconButton; import io.github.darkkronicle.advancedchatcore.interfaces.AdvancedChatScreenSection; import io.github.darkkronicle.advancedchatcore.util.Color; import java.util.ArrayList; import java.util.List; import java.util.function.Function; + +import io.github.darkkronicle.advancedchatcore.util.RowList; import lombok.Getter; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.hud.ChatHud; @@ -25,6 +28,7 @@ import net.minecraft.text.MutableText; import net.minecraft.text.Style; import net.minecraft.text.TranslatableText; +import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; public class AdvancedChatScreen extends GuiBase { @@ -41,6 +45,12 @@ public class AdvancedChatScreen extends GuiBase { private static String last = ""; private final List sections = new ArrayList<>(); + @Getter + private final RowList rightSideButtons = new RowList<>(); + + @Getter + private final RowList leftSideButtons = new RowList<>(); + @Override protected void closeGui(boolean showParent) { if (ConfigStorage.ChatScreen.PERSISTENT_TEXT.config.getBooleanValue()) { @@ -95,24 +105,8 @@ protected MutableText getNarrationMessage() { } this.chatField.setChangedListener(this::onChatFieldUpdate); - Color baseColor = getColor(); - int x = client.getWindow().getScaledWidth() - 1; // Add settings button - String settings = StringUtils.translate("advancedchat.gui.button.settings"); - int settingsWidth = StringUtils.getStringWidth(settings) + 5; - x -= settingsWidth + 5; - CleanButton settingsButton = - new CleanButton( - x, - client.getWindow().getScaledHeight() - 27, - settingsWidth, - 11, - baseColor, - settings); - this.addButton( - settingsButton, - (button, mouseButton) -> - GuiBase.openGui(GuiConfigHandler.getInstance().getDefaultScreen())); + rightSideButtons.add("settings", new IconButton(0, 0, 14, 64, new Identifier(AdvancedChatCore.MOD_ID, "textures/gui/settings.png"), (button) -> GuiBase.openGui(GuiConfigHandler.getInstance().getDefaultScreen()))); this.addSelectableChild(this.chatField); @@ -121,6 +115,35 @@ protected MutableText getNarrationMessage() { for (AdvancedChatScreenSection section : sections) { section.initGui(); } + + int originalX = client.getWindow().getScaledWidth() - 1; + int y = client.getWindow().getScaledHeight() - 30; + for (int i = 0; i < rightSideButtons.rowSize(); i++) { + List buttonList = rightSideButtons.get(i); + int maxHeight = 0; + int x = originalX; + for (ButtonBase button : buttonList) { + maxHeight = Math.max(maxHeight, button.getHeight()); + x -= button.getWidth() + 1; + button.setPosition(x, y); + addButton(button, null); + } + y -= maxHeight + 1; + } + originalX = 1; + y = client.getWindow().getScaledHeight() - 30; + for (int i = 0; i < leftSideButtons.rowSize(); i++) { + List buttonList = leftSideButtons.get(i); + int maxHeight = 0; + int x = originalX; + for (ButtonBase button : buttonList) { + maxHeight = Math.max(maxHeight, button.getHeight()); + button.setPosition(x, y); + addButton(button, null); + x += button.getWidth() + 1; + } + y -= maxHeight + 1; + } } public void resize(MinecraftClient client, int width, int height) { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java index 89e41c8..2c8394d 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java @@ -27,9 +27,8 @@ public class ChatHistoryProcessor implements IMessageProcessor { private static boolean sendToHud(Text text) { if (AdvancedChatCore.FORWARD_TO_HUD) { - ((MixinChatHudInvoker) MinecraftClient.getInstance().inGameHud.getChatHud()) - .invokeAddMessage( - text, 0, MinecraftClient.getInstance().inGameHud.getTicks(), false); + ((MixinChatHudInvoker) MinecraftClient.getInstance().inGameHud.getChatHud()).invokeAddMessage( + text, 0, MinecraftClient.getInstance().inGameHud.getTicks(), false); return true; } return false; @@ -59,17 +58,16 @@ public boolean process(FluidText text, @Nullable FluidText unfiltered) { MessageOwner player = SearchUtils.getAuthor( MinecraftClient.getInstance().getNetworkHandler(), unfiltered.getString()); - ChatMessage line = - ChatMessage.builder() - .displayText(text) - .originalText(original) - .owner(player) - .id(0) - .width(width) - .creationTick(MinecraftClient.getInstance().inGameHud.getTicks()) - .time(time) - .backgroundColor(backcolor) - .build(); + ChatMessage line = ChatMessage.builder() + .displayText(text) + .originalText(original) + .owner(player) + .id(0) + .width(width) + .creationTick(MinecraftClient.getInstance().inGameHud.getTicks()) + .time(time) + .backgroundColor(backcolor) + .build(); if (ChatHistory.getInstance().add(line)) { sendToHud(line.getDisplayText()); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java index 0ebf2b8..df94ffc 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java @@ -11,8 +11,12 @@ import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.gui.GuiConfigsBase; import fi.dy.masa.malilib.gui.button.ButtonBase; +import fi.dy.masa.malilib.gui.button.ButtonGeneric; import fi.dy.masa.malilib.gui.button.IButtonActionListener; +import fi.dy.masa.malilib.util.Color4f; import io.github.darkkronicle.advancedchatcore.AdvancedChatCore; +import net.minecraft.client.gui.screen.Screen; + import java.util.List; // Based off of @@ -20,64 +24,157 @@ // Released under GNU LGPL public class GuiConfig extends GuiConfigsBase { - private List tabButtons; - private List configs; + public static TabSupplier TAB = null; + @Deprecated public GuiConfig(List tabButtons, List configs) { + this(); + } + + public GuiConfig() { super(10, 50, AdvancedChatCore.MOD_ID, null, "advancedchat.screen.main"); - this.tabButtons = tabButtons; - this.configs = configs; } @Override public void initGui() { - super.initGui(); - this.clearOptions(); + if (TAB == null) { + // Should be general + for (int i = 0; i < GuiConfigHandler.getInstance().getTabs().size(); i++) { + TabSupplier tab = GuiConfigHandler.getInstance().getTabs().get(i); + if (tab.isSelectable()) { + TAB = tab; + break; + } + } + if (TAB == null) { + // sucks to suck lol + TAB = GuiConfigHandler.getInstance().getTabs().get(0); + } + } + boolean children = TAB.getChildren() != null && TAB.getChildren().size() != 0; + + Screen child = getFullyNestedSupplier(TAB).getScreen(this); + if (child != null) { + GuiBase.openGui(child); + return; + } + clearElements(); int x = 10; int y = 26; - int rows = 1; + int rows = addTabButtons(this, x, y); + y += rows * 22; + if (children) { + y += (addAllChildrenButtons(this, TAB, x, y) * 22); + } + setListPosition(getListX(), y + 10); + if (this.getListWidget() != null) { + this.getListWidget().setSize(this.getBrowserWidth(), this.getBrowserHeight()); + this.getListWidget().initGui(); + } + + } + + @Override + public List getConfigs() { + return ConfigOptionWrapper.createFor(getFullyNestedSupplier(TAB).getOptions()); + } + + public static TabSupplier getFullyNestedSupplier(TabSupplier supplier) { + if (supplier.getChildren() == null || supplier.getChildren().size() == 0) { + return supplier; + } + return getFullyNestedSupplier(supplier.getNestedSelection()); + } - for (GuiConfigHandler.TabButton tab : tabButtons) { - int newY = this.createButton(tab, y); - if (newY != y) { - rows++; - y = newY; + public static int addAllChildrenButtons(GuiBase screen, TabSupplier supplier, int x, int y) { + int rows = 0; + if (supplier.getChildren() != null && supplier.getChildren().size() != 0) { + x += 2; + screen.addLabel(x, y, 10, 22, new Color4f(1, 1, 1, 1).intValue, ">"); + x += 8; + addNestedTabButtons(screen, supplier, x, y); + y += 22; + rows++; + if (supplier.getNestedSelection() != null) { + rows += addAllChildrenButtons(screen, supplier.getNestedSelection(), x, y); } } + return rows; + } + + /** + * Adds the category buttons to the selected screen + * @param screen Screen to apply to + * @return Amount of rows it created + */ + public static int addTabButtons(GuiBase screen, int x, int y) { + int rows = 1; + for (TabSupplier tab : GuiConfigHandler.getInstance().getTabs()) { + int width = screen.getStringWidth(tab.getDisplayName()) + 10; - if (rows > 1) { - int scrollbarPosition = this.getListWidget().getScrollbar().getValue(); - this.setListPosition(this.getListX(), 50 + (rows - 1) * 22); - this.reCreateListWidget(); - this.getListWidget().getScrollbar().setValue(scrollbarPosition); - this.getListWidget().refreshEntries(); + if (x >= screen.width - width - 10) + { + x = 10; + y += 22; + ++rows; + } + + x += createTabButton(screen, x, y, width, tab); } + return rows; } - private int createButton(GuiConfigHandler.TabButton button, int y) { - this.addButton(button.getButton(), new ButtonListenerConfigTabs(button)); - return button.getButton().getY(); + public static int addNestedTabButtons(GuiBase screen, TabSupplier supplier, int x, int y) { + int rows = 1; + for (TabSupplier tab : supplier.getChildren()) { + int width = screen.getStringWidth(tab.getDisplayName()) + 10; + + if (x >= screen.width - width - 10) + { + x = 10; + y += 22; + ++rows; + } + + x += createTabButton(screen, x, y, width, tab, supplier); + } + return rows; } - @Override - public List getConfigs() { - return ConfigOptionWrapper.createFor(configs); + private static int createTabButton(GuiBase screen, int x, int y, int width, TabSupplier tab) { + return createTabButton(screen, x, y, width, tab, null); } - private static class ButtonListenerConfigTabs implements IButtonActionListener { + private static int createTabButton(GuiBase screen, int x, int y, int width, TabSupplier tab, TabSupplier parent) { + ButtonGeneric button = new ButtonGeneric(x, y, width, 20, tab.getDisplayName()); + if (parent == null) { + button.setEnabled(GuiConfig.TAB != tab); + } else { + button.setEnabled(parent.getNestedSelection() != tab); + } + screen.addButton(button, new ButtonListenerTab(tab, parent)); + + return button.getWidth() + 2; + } - private final GuiConfigHandler.TabButton tabButton; + public static class ButtonListenerTab implements IButtonActionListener { + private final TabSupplier tab; + private final TabSupplier parent; - public ButtonListenerConfigTabs(GuiConfigHandler.TabButton tabButton) { - this.tabButton = tabButton; + public ButtonListenerTab(TabSupplier tab, TabSupplier parent) { + this.tab = tab; + this.parent = parent; } @Override public void actionPerformedWithButton(ButtonBase button, int mouseButton) { - GuiConfigHandler.getInstance().activeTab = this.tabButton.getTab().getName(); - GuiBase.openGui( - this.tabButton.getTab().getScreen(GuiConfigHandler.getInstance().getButtons())); + if (parent == null) { + GuiConfig.TAB = this.tab; + } else { + parent.setNestedSelection(this.tab); + } + GuiBase.openGui(new GuiConfig()); } } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java index 003e12d..dfd9614 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java @@ -14,6 +14,9 @@ import io.github.darkkronicle.advancedchatcore.gui.buttons.ConfigTabsButtonListener; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; +import java.util.function.Supplier; + import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Value; @@ -27,12 +30,14 @@ public class GuiConfigHandler { private static final GuiConfigHandler INSTANCE = new GuiConfigHandler(); + @Deprecated public String activeTab = ""; - @Getter private final List tabs = new ArrayList<>(); + @Getter private final List tabs = new ArrayList<>(); private GuiConfigHandler() {} + @Deprecated public boolean isTabActive(GuiConfigHandler.Tab button) { return button.getName().equals(activeTab); } @@ -41,10 +46,39 @@ public static GuiConfigHandler getInstance() { return INSTANCE; } + @Deprecated public void addGuiSection(Tab section) { - tabs.add(section); + if (section instanceof GuiConfigSection gui) { + addTab(new TabSupplier(section.getName(), section.getName()) { + @Override + public List getOptions() { + return gui.getOptions(); + } + }); + return; + } + tabs.add(new TabSupplier(section.getName(), section.getName()) { + @Override + public Screen getScreen(Screen parent) { + return section.getScreen(getButtons()); + } + }); + } + + public void addTab(TabSupplier tab) { + tabs.add(tab); } + public TabSupplier get(String name) { + for (TabSupplier child : tabs) { + if (child.getName().equals(name)) { + return child; + } + } + return null; + } + + @Deprecated public List getButtons() { int x = 10; int y = 26; @@ -52,7 +86,7 @@ public List getButtons() { ArrayList buttons = new ArrayList<>(); MinecraftClient client = MinecraftClient.getInstance(); int windowWidth = client.getWindow().getScaledWidth(); - for (Tab tab : tabs) { + for (TabSupplier tab : tabs) { int width = client.textRenderer.getWidth(tab.getName()) + 10; if (x >= windowWidth - width - 10) { @@ -68,14 +102,14 @@ public List getButtons() { return buttons; } - private ButtonGeneric createButton(int x, int y, int width, Tab tab) { + private ButtonGeneric createButton(int x, int y, int width, TabSupplier tab) { ButtonGeneric button = new ButtonGeneric(x, y, width, 20, tab.getName()); - button.setEnabled(!isTabActive(tab)); + button.setEnabled(!GuiConfig.TAB.equals(tab)); return button; } - public Tab getTab(String name) { - for (Tab b : tabs) { + public TabSupplier getTab(String name) { + for (TabSupplier b : tabs) { if (b.getName().equals(name)) { return b; } @@ -84,23 +118,10 @@ public Tab getTab(String name) { } public Screen getDefaultScreen() { - if (activeTab.isEmpty()) { - activeTab = tabs.get(0).getName(); - } - for (Tab tab : tabs) { - if (tab.getName().equalsIgnoreCase(activeTab)) { - return tab.getScreen(getButtons()); - } - } - return tabs.get(0).getScreen(getButtons()); - } - - public interface Tab { - String getName(); - - Screen getScreen(List buttons); + return new GuiConfig(); } + @Deprecated public static GuiConfigSection createGuiConfigSection( String name, List> configs) { List configBases = new ArrayList<>(); @@ -120,6 +141,81 @@ public String getName() { }; } + @Deprecated + @AllArgsConstructor + @Value + public static class TabButton { + TabSupplier tab; + ButtonGeneric button; + + public ConfigTabsButtonListener createListener() { + return new ConfigTabsButtonListener(this); + } + } + + public static TabSupplier wrapSaveableOptions(String name, String translationKey, Supplier>> supplier) { + Supplier> configSupplier = () -> { + List config = new ArrayList<>(); + List> options = supplier.get(); + for (SaveableConfig s : options) { + config.add(s.config); + } + return config; + }; + return wrapOptions(name, translationKey, configSupplier); + } + + public static TabSupplier wrapSaveableOptions(String name, String translationKey, List> options) { + List config = new ArrayList<>(); + for (SaveableConfig s : options) { + config.add(s.config); + } + return wrapOptions(name, translationKey, config); + } + + public static TabSupplier wrapOptions(String name, String translationKey, List configs) { + return wrapOptions(name, translationKey, () -> configs); + } + + public static TabSupplier wrapOptions(String name, String translationKey, Supplier> options) { + return new TabSupplier(name, translationKey) { + @Override + public List getOptions() { + return options.get(); + } + }; + } + + public static TabSupplier wrapScreen(String name, String translationKey, Function screenSupplier) { + return new TabSupplier(name, translationKey) { + @Override + public Screen getScreen(Screen parent) { + return screenSupplier.apply(parent); + } + }; + } + + public static TabSupplier children(String name, String translationKey, TabSupplier... children) { + TabSupplier tab = new TabSupplier(name, translationKey) { + @Override + public String getName() { + return super.getName(); + } + }; + for (TabSupplier child : children) { + tab.addChild(child); + } + return tab; + } + + @Deprecated + public interface Tab { + String getName(); + + Screen getScreen(List buttons); + } + + @Deprecated public interface GuiConfigSection extends Tab { List getOptions(); @@ -128,19 +224,7 @@ public interface GuiConfigSection extends Tab { @Override default Screen getScreen(List buttons) { GuiConfigHandler.getInstance().activeTab = this.getName(); - return new GuiConfig(buttons, getOptions()); - } - } - - @AllArgsConstructor - @Value - public static class TabButton { - - Tab tab; - ButtonGeneric button; - - public ConfigTabsButtonListener createListener() { - return new ConfigTabsButtonListener(this); + return new GuiConfig(); } } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/TabSupplier.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/TabSupplier.java new file mode 100644 index 0000000..9e2a01f --- /dev/null +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/TabSupplier.java @@ -0,0 +1,73 @@ +package io.github.darkkronicle.advancedchatcore.config.gui; + +import fi.dy.masa.malilib.config.IConfigBase; +import fi.dy.masa.malilib.util.StringUtils; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.gui.screen.Screen; + +import java.util.ArrayList; +import java.util.List; + +public class TabSupplier { + + @Getter + private final String name; + + private final String translationKey; + + @Getter + @Setter + private TabSupplier nestedSelection = null; + + @Getter + private List children = new ArrayList<>(); + + public TabSupplier(String name, String translationKey) { + this.name = name; + this.translationKey = translationKey; + } + + public String getDisplayName() { + return StringUtils.translate(translationKey); + } + + public List getOptions() { + return null; + } + + public Screen getScreen(Screen parent) { + return null; + } + + public boolean isSelectable() { + return true; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof TabSupplier)) { + return false; + } + return (((TabSupplier) obj).getName().equals(getName())); + } + + public void addChild(TabSupplier supplier) { + if (nestedSelection == null) { + if (supplier.isSelectable()) { + nestedSelection = supplier; + } + } + this.children.add(supplier); + } + + public TabSupplier get(String name) { + for (TabSupplier child : children) { + if (name.equals(child.getName())) { + return child; + } + } + return null; + } + +} diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ConfigGuiListBase.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ConfigGuiListBase.java index 69b77eb..134250c 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ConfigGuiListBase.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ConfigGuiListBase.java @@ -9,6 +9,7 @@ import fi.dy.masa.malilib.gui.widgets.WidgetListBase; import fi.dy.masa.malilib.gui.widgets.WidgetListEntryBase; +import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfig; import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfigHandler; import java.util.List; @@ -19,15 +20,16 @@ public abstract class ConfigGuiListBase< WIDGETLIST extends WidgetListBase> extends CoreGuiListBase { - private List tabButtons; - public ConfigGuiListBase(List tabButtons) { this(10, 60, tabButtons); } + public ConfigGuiListBase() { + this(10, 60, null); + } + public ConfigGuiListBase(int listX, int listY, List tabButtons) { super(listX, listY); - this.tabButtons = tabButtons; } @Override @@ -37,17 +39,11 @@ public void initGui() { int x = 10; int y = 26; - int rows = 1; - - for (GuiConfigHandler.TabButton tab : tabButtons) { - int newY = this.createButton(tab, y); - if (newY != y) { - rows++; - y = newY; - } + y += (22 * GuiConfig.addTabButtons(this, 10, y)); + if (GuiConfig.TAB.getChildren() != null && GuiConfig.TAB.getChildren().size() > 0) { + y += (22 * GuiConfig.addAllChildrenButtons(this, GuiConfig.TAB, 10, y)); } - - this.setListPosition(this.getListX(), 68 + (rows - 1) * 22); + this.setListPosition(this.getListX(), y); this.reCreateListWidget(); this.getListWidget().refreshEntries(); @@ -56,11 +52,6 @@ public void initGui() { initGuiConfig(x, y); } - private int createButton(GuiConfigHandler.TabButton button, int y) { - this.addButton(button.getButton(), button.createListener()); - return button.getButton().getY(); - } - /** Method when the GUI is initialized. This one takes an X,Y that is away from the buttons */ public void initGuiConfig(int x, int y) {} } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/IconButton.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/IconButton.java new file mode 100644 index 0000000..a07f00e --- /dev/null +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/IconButton.java @@ -0,0 +1,97 @@ +package io.github.darkkronicle.advancedchatcore.gui; + +import fi.dy.masa.malilib.render.RenderUtils; +import io.github.darkkronicle.advancedchatcore.util.Color; +import io.github.darkkronicle.advancedchatcore.util.Colors; +import lombok.Getter; +import lombok.Setter; +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; + +import java.util.function.Consumer; + +public class IconButton extends CleanButton { + + @Setter + @Getter + private int padding; + + @Setter + @Getter + private Identifier icon; + + @Setter + @Getter + private int iconWidth; + + @Setter + @Getter + private int iconHeight; + + @Setter + @Getter + private Consumer onClick; + + @Getter + @Setter + private String onHover; + + public IconButton(int x, int y, int sideLength, int iconLength, Identifier icon, Consumer mouseClick) { + this(x, y, sideLength, sideLength, iconLength, iconLength, icon, mouseClick); + } + + public IconButton(int x, int y, int width, int height, int iconWidth, int iconHeight, Identifier icon, Consumer mouseClick) { + this(x, y, width, height, 2, iconWidth, iconHeight, icon, mouseClick, null); + } + + public IconButton(int x, int y, int width, int height, int padding, int iconWidth, int iconHeight, Identifier icon, Consumer mouseClick, String onHover) { + super(x, y, width, height, null, null); + this.padding = padding; + this.iconWidth = iconWidth; + this.iconHeight = iconHeight; + this.icon = icon; + this.onClick = mouseClick; + this.onHover = onHover; + } + + @Override + public void render(int mouseX, int mouseY, boolean unused, MatrixStack matrixStack) { + int relMX = mouseX - x; + int relMY = mouseY - y; + hovered = relMX >= 0 && relMX <= width && relMY >= 0 && relMY <= height; + + Color plusBack = Colors.getInstance().getColorOrWhite("background").withAlpha(100); + if (hovered) { + plusBack = Colors.getInstance().getColorOrWhite("hover").withAlpha(plusBack.alpha()); + } + + RenderUtils.drawRect(x, y, width, height, plusBack.color()); + + RenderUtils.color(1, 1, 1, 1); + RenderUtils.bindTexture(icon); + DrawableHelper.drawTexture(matrixStack, x + padding, y + padding, width - (padding * 2), height - (padding * 2), + 0, 0, iconWidth, iconHeight, iconWidth, iconHeight); + + if (hovered && onHover != null) { + DrawableHelper.drawStringWithShadow( + matrixStack, + MinecraftClient.getInstance().textRenderer, + onHover, + mouseX + 4, + mouseY - 16, + Colors.getInstance().getColorOrWhite("white").color()); + } + } + + @Override + protected boolean onMouseClickedImpl(int mouseX, int mouseY, int mouseButton) { + this.mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + onClick.accept(this); + return true; + } + +} diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/buttons/ConfigTabsButtonListener.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/buttons/ConfigTabsButtonListener.java index db23195..39a9f29 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/buttons/ConfigTabsButtonListener.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/buttons/ConfigTabsButtonListener.java @@ -10,10 +10,12 @@ import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.gui.button.ButtonBase; import fi.dy.masa.malilib.gui.button.IButtonActionListener; +import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfig; import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfigHandler; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +@Deprecated @Environment(EnvType.CLIENT) public class ConfigTabsButtonListener implements IButtonActionListener { @@ -25,8 +27,7 @@ public ConfigTabsButtonListener(GuiConfigHandler.TabButton tabButton) { @Override public void actionPerformedWithButton(ButtonBase button, int mouseButton) { - GuiConfigHandler.getInstance().activeTab = this.tabButton.getTab().getName(); - GuiBase.openGui( - this.tabButton.getTab().getScreen(GuiConfigHandler.getInstance().getButtons())); + GuiConfig.TAB = tabButton.getTab(); + GuiBase.openGui(new GuiConfig()); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/RowList.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/RowList.java new file mode 100644 index 0000000..2b6c11d --- /dev/null +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/RowList.java @@ -0,0 +1,61 @@ +package io.github.darkkronicle.advancedchatcore.util; + +import java.util.*; + +public class RowList { + + private final Map> list = new HashMap<>(); + private final List order = new ArrayList<>(); + + public RowList() { + + } + + private List makeNewList() { + return new ArrayList<>(); + } + + public void createSection(String key, int y) { + List newList = makeNewList(); + order.add(y, key); + list.put(key, newList); + } + + public void add(String key, T value) { + add(key, value, -1); + } + + public void add(String key, T value, int index) { + if (!list.containsKey(key)) { + List newList = makeNewList(); + order.add(key); + newList.add(value); + list.put(key, newList); + return; + } + if (index < 0) { + list.get(key).add(value); + } else { + list.get(key).add(index, value); + } + } + + public List get(String key) { + return list.get(key); + } + + public List get(int y) { + String key; + if (y >= order.size()) { + key = order.get(order.size() - 1); + } else { + key = order.get(y); + } + return list.get(key); + } + + public int rowSize() { + return list.size(); + } + +} diff --git a/src/main/resources/assets/advancedchatcore/lang/en_us.json b/src/main/resources/assets/advancedchatcore/lang/en_us.json index 6101cdb..a114920 100644 --- a/src/main/resources/assets/advancedchatcore/lang/en_us.json +++ b/src/main/resources/assets/advancedchatcore/lang/en_us.json @@ -4,9 +4,9 @@ "advancedchat.gui.button.settings": "Settings", "advancedchat.screen.main": "§3Advanced§5Chat§f Config", - "advancedchat.config.tab.general": "§7General", - "advancedchat.config.tab.chatscreen": "§bChat Screen", - + "advancedchatcore.tab.general": "§7General", + "advancedchatcore.tab.chatscreen": "§bChat Screen", + "advancedchat.tab.advancedchatcore": "Core", "advancedchat.config.general.timeformat": "Time Format", "advancedchat.config.general.info.timeformat": "How time is displayed if §6Show Time§r is enabled for both the §9Chat HUD§r and the §aChat Log§r. \nSee the §6SimpleDateFormat§r class for the format ", diff --git a/src/main/resources/assets/advancedchatcore/textures/gui/settings.png b/src/main/resources/assets/advancedchatcore/textures/gui/settings.png new file mode 100644 index 0000000..80bbb28 Binary files /dev/null and b/src/main/resources/assets/advancedchatcore/textures/gui/settings.png differ