diff --git a/core/src/main/java/ml/volder/unikapi/loader/Laby4Loader.java b/core/src/main/java/ml/volder/unikapi/loader/Laby4Loader.java index efdff23..c713c4d 100644 --- a/core/src/main/java/ml/volder/unikapi/loader/Laby4Loader.java +++ b/core/src/main/java/ml/volder/unikapi/loader/Laby4Loader.java @@ -5,8 +5,6 @@ import ml.volder.unikapi.api.ApiReferenceStorageLaby4; import ml.volder.unikapi.event.events.mainmenuopenevent.impl.Laby4MainMenuOpenEvent; import ml.volder.unikapi.logger.Laby4Logger; -import ml.volder.unikapi.widgets.Laby4ModuleManager; -import ml.volder.unikapi.widgets.ModuleSystem; import net.labymod.api.Laby; import net.labymod.api.addon.LabyAddon; import net.labymod.api.client.chat.command.Command; @@ -34,7 +32,6 @@ protected void enable() { UnikAPI.LOGGER = new Laby4Logger("UnikAPI"); UnikAPI.initAPI("labymod4", null, "*"); UnikAPI.registerReferenceStorage(ApiReferenceStorageLaby4.getInstance()); - ModuleSystem.setModuleManager(new Laby4ModuleManager()); Loader.onEnable(); Laby.labyAPI().eventBus().registerListener(this); Laby4MainMenuOpenEvent.checkMainMenu(); diff --git a/core/src/main/java/ml/volder/unikapi/widgets/DefaultModuleManager.java b/core/src/main/java/ml/volder/unikapi/widgets/DefaultModuleManager.java index 5c9835d..be0674b 100644 --- a/core/src/main/java/ml/volder/unikapi/widgets/DefaultModuleManager.java +++ b/core/src/main/java/ml/volder/unikapi/widgets/DefaultModuleManager.java @@ -1,94 +1,38 @@ package ml.volder.unikapi.widgets; - -import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.datasystem.Data; -import ml.volder.unikapi.datasystem.DataManager; -import ml.volder.unikapi.event.EventManager; -import ml.volder.unikapi.guisystem.elements.ControlElement; import ml.volder.unikapi.types.Material; -import ml.volder.unikapi.widgets.editor.GuiEditor; -import ml.volder.unikapi.widgets.elements.ModuleCategoryElement; +import net.labymod.api.Laby; +import net.labymod.api.client.gui.hud.binding.category.HudWidgetCategory; +import net.labymod.api.client.gui.navigation.elements.ScreenNavigationElement; +import net.labymod.api.client.gui.screen.activity.types.TabbedActivity; -import java.io.File; -import java.util.ArrayList; -import java.util.List; import java.util.function.Function; -public class DefaultModuleManager implements ModuleManager{ - - public DefaultModuleManager() { - instance = this; - GuiModuleRenderer guiModuleRenderer = new GuiModuleRenderer(this, DataManager.getOrCreateDataManager(new File(UnikAPI.getCommonDataFolder(), "guiModule" + ".json"))); - EventManager.registerEvents(guiModuleRenderer); - } - - private List guiModuleList = new ArrayList<>(); - private List guiModuleCategories = new ArrayList<>(); - - public List getGuiModuleList() { - return guiModuleList; - } - - private static DefaultModuleManager instance; - - public static GuiModule getModuleByKey(String key) { - for(GuiModule guiModule : instance.guiModuleList) - if(guiModule.getKey().equals(key)) - return guiModule; - return null; - } - - public List getGuiModuleCategories() { - return guiModuleCategories; - } - - public void addModule(GuiModule module, ModuleCategoryElement category) { - module.setCategory(category); - guiModuleList.add(module); - } - - public void addModule(GuiModule module) { - guiModuleList.add(module); - } - - private final DataManager dataManager = DataManager.getOrCreateDataManager(new File(UnikAPI.getCommonDataFolder(), "guiModule" + ".json")); - - @Override - public Object registerCategory(String displayName, Material icon, String description) { - ModuleCategoryElement category = new ModuleCategoryElement(displayName, new ControlElement.IconData(icon)); - getGuiModuleCategories().add(category); - return category; - } - - @Override - public void registerModule(String key, String defaultPrefix, boolean defaultIsEnabled, Object category, Material icon, Function getDisplayValue) { - - - if(!(category instanceof ModuleCategoryElement)) - return; - GuiModule module = new GuiModule(2,2, key, defaultPrefix, defaultIsEnabled, dataManager, (ModuleCategoryElement) category) { - @Override - public String getDisplayValue() { - return getDisplayValue.apply(""); - } - }; - ControlElement.IconData iconData = new ControlElement.IconData(icon); - iconData.setItemDamage(icon.getItemDamage(0)); - module.setIconData(iconData); - getGuiModuleList().add(module); - } - - @Override - public void openEditor() { - PlayerAPI.getAPI().openGuiScreen(new GuiEditor(this, PlayerAPI.getAPI().getCurrentScreen())); - } - - public static DataManager getDataManager() { - if(instance != null && instance.dataManager != null) - return instance.dataManager; - return DataManager.getOrCreateDataManager(new File(UnikAPI.getCommonDataFolder(), "guiModule" + ".json")); - } - +public class DefaultModuleManager implements ModuleManager { + + int categoryId = 0; + @Override + public Object registerCategory(String title, Material material, String description) { + HudWidgetCategory category = new UnikHudWidgetCategory("unikapi-category-" + categoryId, title, description); + Laby.labyAPI().hudWidgetRegistry().categoryRegistry().register(category); + categoryId += 1; + return category; + } + + @Override + public void registerModule(String key, String defaultPrefix, boolean defaultIsEnabled, Object category, Material icon, Function getDisplayValue) { + if(!(category instanceof HudWidgetCategory)) + return; + Laby.labyAPI().hudWidgetRegistry().register(new UnikHudWidget(key, (HudWidgetCategory) category, defaultPrefix, icon,getDisplayValue)); + } + + @Override + public void openEditor() { + ScreenNavigationElement navigationElement = Laby.references().navigationRegistry().getById("labymod") instanceof ScreenNavigationElement ? (ScreenNavigationElement) Laby.references().navigationRegistry().getById("labymod") : null; + if(navigationElement == null || navigationElement.getScreen() == null || !(navigationElement.getScreen() instanceof TabbedActivity)) + return; + TabbedActivity tabbedActivity = (TabbedActivity) navigationElement.getScreen(); + tabbedActivity.switchTab("widgets"); + Laby.labyAPI().minecraft().minecraftWindow().displayScreen(tabbedActivity); + } } diff --git a/core/src/main/java/ml/volder/unikapi/widgets/GuiModule.java b/core/src/main/java/ml/volder/unikapi/widgets/GuiModule.java deleted file mode 100644 index abce676..0000000 --- a/core/src/main/java/ml/volder/unikapi/widgets/GuiModule.java +++ /dev/null @@ -1,517 +0,0 @@ -package ml.volder.unikapi.widgets; - - -import ml.volder.unikapi.api.draw.DrawAPI; -import ml.volder.unikapi.datasystem.Data; -import ml.volder.unikapi.datasystem.DataManager; -import ml.volder.unikapi.guisystem.elements.*; -import ml.volder.unikapi.types.Material; -import ml.volder.unikapi.types.ModColor; -import ml.volder.unikapi.widgets.elements.ModuleCategoryElement; - -import java.awt.*; -import java.util.List; -import java.util.*; - -public class GuiModule { - private RenderRelative renderRelative = RenderRelative.LEFT_TOP; - private int distanceFromXRelative; - private int distanceFromYRelative; - private int moduleHeight; - private String key; - private String prefix; - private ControlElement.IconData iconData; - - private ModuleCategoryElement category; - - private Color valueColor; - private Color keyColor; - private Color bracketColor; - - private boolean bold; - private boolean italic; - private boolean underline; - - private boolean isEnabled; - - private GuiModule attachedModule; - private String attachedModuleKey; - - - private GuiModule parentModule; - private String parentModuleKey; - - private float scaleMultiplier = 2; - - - public GuiModule(int defaultX, int defaultY, String key, String defaultPrefix, boolean defaultIsEnabled, DataManager dataManager, ModuleCategoryElement category) { - this.category = category; - this.moduleHeight = (int) (DrawAPI.getAPI().getFontHeight()*scaleMultiplier); - this.isEnabled = dataManager.getSettings().getData().has("modules." + key + ".isEnabled") - ? dataManager.getSettings().getData().get("modules." + key + ".isEnabled").getAsBoolean() - : defaultIsEnabled; - this.key = key; - this.prefix = dataManager.getSettings().getData().has("modules." + key + ".prefix") - ? dataManager.getSettings().getData().get("modules." + key + ".prefix").getAsString() - : defaultPrefix; - this.distanceFromXRelative = dataManager.getSettings().getData().has("modules." + key + ".distanceFromXRelative") ? dataManager.getSettings().getData().get("modules." + key + ".distanceFromXRelative").getAsInt() : defaultX; - this.distanceFromYRelative = dataManager.getSettings().getData().has("modules." + key + ".distanceFromYRelative") ? dataManager.getSettings().getData().get("modules." + key + ".distanceFromYRelative").getAsInt() : defaultY; - loadConfig(dataManager); - } - - - public void loadConfig(DataManager dataManager) { - - this.scaleMultiplier = dataManager.getSettings().getData().has("modules." + key + ".textSize") - ? dataManager.getSettings().getData().get("modules." + key + ".textSize").getAsFloat() - : 1; - this.moduleHeight = (int) (DrawAPI.getAPI().getFontHeight()*scaleMultiplier); - - this.attachedModuleKey = dataManager.getSettings().getData().has("modules." + key + ".attachedModule") - ? dataManager.getSettings().getData().get("modules." + key + ".attachedModule").getAsString() - : null; - this.attachedModule = getAttachedModule(); - - this.parentModuleKey = dataManager.getSettings().getData().has("modules." + key + ".parentModule") - ? dataManager.getSettings().getData().get("modules." + key + ".parentModule").getAsString() - : null; - this.parentModule = getParrentModule(); - - this.valueColor = dataManager.getSettings().getData().has("modules." + key + ".valueColor") ? new Color(dataManager.getSettings().getData().get("modules." + key + ".valueColor").getAsInt()) : ModColor.WHITE.getColor(); - this.keyColor = dataManager.getSettings().getData().has("modules." + key + ".prefixColor") ? new Color(dataManager.getSettings().getData().get("modules." + key + ".prefixColor").getAsInt()) : ModColor.GREEN.getColor(); - this.bracketColor = dataManager.getSettings().getData().has("modules." + key + ".bracketColor") ? new Color(dataManager.getSettings().getData().get("modules." + key + ".bracketColor").getAsInt()) : ModColor.DARK_GRAY.getColor(); - - this.bold = dataManager.getSettings().getData().has("modules." + key + ".bold") ? dataManager.getSettings().getData().get("modules." + key + ".bold").getAsBoolean() : false; - this.italic = dataManager.getSettings().getData().has("modules." + key + ".italic") ? dataManager.getSettings().getData().get("modules." + key + ".italic").getAsBoolean() : false; - this.underline = dataManager.getSettings().getData().has("modules." + key + ".underline") ? dataManager.getSettings().getData().get("modules." + key + ".underline").getAsBoolean() : false; - } - - public List getSubSettings(DataManager dataManager) { - List subSettings = new ArrayList<>(); - - - StringElement prefixElement = new StringElement("Prefix", "modules." + key + ".prefix", iconData, prefix == null ? key : prefix, dataManager); - prefixElement.addCallback(s -> this.prefix = s); - subSettings.add(prefixElement); - - FloatElement numberElement = new FloatElement("Tekst Størelse", dataManager, "modules." + key + ".textSize", new ControlElement.IconData(Material.PAPER), 1); - numberElement.setMaxValue(1.5F); - numberElement.setMinValue(0.5F); - numberElement.addCallback(integer -> { - scaleMultiplier = integer; - this.moduleHeight = (int) (DrawAPI.getAPI().getFontHeight()*scaleMultiplier); - }); - subSettings.add(numberElement); - - //Color picker and Checkboxes bulk element - ColorPickerCheckBoxBulkElement bulkElement = new ColorPickerCheckBoxBulkElement(""); - bulkElement.setCheckBoxRightBound(true); - - //Color pickers - ColorPicker bracketPicker = new ColorPicker( "Brackets" , bracketColor, () -> ModColor.DARK_GRAY.getColor(), 0 , 0 , 0 , 0); - bracketPicker.setHasDefault( true ); - bracketPicker.setUpdateListener(accepted -> { - dataManager.getSettings().getData().addProperty("modules." + key + ".bracketColor", accepted != null ? accepted.getRGB() : ModColor.DARK_GRAY.getColor().getRGB()); - dataManager.save(); - bracketColor = accepted != null ? accepted : ModColor.DARK_GRAY.getColor(); - }); - bracketPicker.setHasAdvanced(true); - bulkElement.addColorPicker( bracketPicker ); - - ColorPicker valuePicker = new ColorPicker( "Value" , valueColor, () -> ModColor.WHITE.getColor(), 0 , 0 , 0 , 0); - valuePicker.setHasDefault( true ); - valuePicker.setUpdateListener(accepted -> { - dataManager.getSettings().getData().addProperty("modules." + key + ".valueColor", accepted != null ? accepted.getRGB() : ModColor.WHITE.getColor().getRGB()); - dataManager.save(); - valueColor = accepted != null ? accepted : ModColor.WHITE.getColor(); - }); - valuePicker.setHasAdvanced(true); - bulkElement.addColorPicker( valuePicker ); - - ColorPicker prefixPicker = new ColorPicker( "Prefix" , keyColor, () -> ModColor.GREEN.getColor(), 0 , 0 , 0 , 0); - prefixPicker.setHasDefault( true ); - prefixPicker.setUpdateListener(accepted -> { - dataManager.getSettings().getData().addProperty("modules." + key + ".prefixColor", accepted != null ? accepted.getRGB() : ModColor.GREEN.getColor().getRGB()); - dataManager.save(); - keyColor = accepted != null ? accepted : ModColor.GREEN.getColor(); - }); - prefixPicker.setHasAdvanced(true); - bulkElement.addColorPicker( prefixPicker ); - - //Checkboxes - CheckBox boldCheckBox = new CheckBox( "Bold", bold == true ? CheckBox.EnumCheckBoxValue.ENABLED : CheckBox.EnumCheckBoxValue.DISABLED, () -> CheckBox.EnumCheckBoxValue.DISABLED, 0 , 0 , 0 , 0); - boldCheckBox.setHasDefault( true ); - boldCheckBox.setUpdateListener(accepted -> { - bold = accepted == CheckBox.EnumCheckBoxValue.ENABLED; - dataManager.getSettings().getData().addProperty("modules." + key + ".bold", bold); - dataManager.save(); - }); - bulkElement.addCheckbox( boldCheckBox ); - - CheckBox italicCheckBox = new CheckBox( "Italic", italic == true ? CheckBox.EnumCheckBoxValue.ENABLED : CheckBox.EnumCheckBoxValue.DISABLED, () -> CheckBox.EnumCheckBoxValue.DISABLED, 0 , 0 , 0 , 0); - italicCheckBox.setHasDefault( true ); - italicCheckBox.setUpdateListener(accepted -> { - italic = accepted == CheckBox.EnumCheckBoxValue.ENABLED; - dataManager.getSettings().getData().addProperty("modules." + key + ".italic", italic); - dataManager.save(); - }); - bulkElement.addCheckbox( italicCheckBox ); - - CheckBox underlineCheckBox = new CheckBox( "Underline", underline == true ? CheckBox.EnumCheckBoxValue.ENABLED : CheckBox.EnumCheckBoxValue.DISABLED, () -> CheckBox.EnumCheckBoxValue.DISABLED, 0 , 0 , 0 , 0); - underlineCheckBox.setHasDefault( true ); - underlineCheckBox.setUpdateListener(accepted -> { - underline = accepted == CheckBox.EnumCheckBoxValue.ENABLED; - dataManager.getSettings().getData().addProperty("modules." + key + ".underline", underline); - dataManager.save(); - }); - bulkElement.addCheckbox( underlineCheckBox ); - - subSettings.add( bulkElement ); - - return subSettings; - } - - public void drawModule() { - draw(getDrawX(), getDrawY()); - } - - public double getDrawX() { - return this.getDrawX(DrawAPI.getAPI().getScaledWidth()); - } - - public double getDrawX(int scaledWidth) { - return getRelativePointX(scaledWidth) == 0 - ? getRelativePointX(scaledWidth) + convertScaledRatio(getDistanceFromXRelative(), DrawAPI.getAPI().getScaledWidth(), scaledWidth) - : getRelativePointX(scaledWidth) - convertScaledRatio(getDistanceFromXRelative(), DrawAPI.getAPI().getScaledWidth(), scaledWidth); - } - - public double getDrawY() { - return this.getDrawY(DrawAPI.getAPI().getScaledHeight()); - } - - public double getDrawY(int scaledHeight) { - return getRelativePointY(scaledHeight) == 0 - ? getRelativePointY(scaledHeight) + convertScaledRatio(getDistanceFromYRelative(), DrawAPI.getAPI().getScaledHeight(), scaledHeight) - : getRelativePointY(scaledHeight) - convertScaledRatio(getDistanceFromYRelative(), DrawAPI.getAPI().getScaledHeight(), scaledHeight); - } - - public RenderRelative getRenderRelative() { - return renderRelative; - } - - public int getDistanceFromXRelative() { - return distanceFromXRelative; - } - - public int getDistanceFromYRelative() { - return distanceFromYRelative; - } - - private int getRelativePointX(int scaledWidth) { - switch (renderRelative) { - case LEFT_TOP: - case LEFT_BOTTOM: - return 0; - case RIGHT_TOP: - case RIGHT_BOTTOM: - return scaledWidth; - default: - return 0; - } - } - - private int getRelativePointY(int scaledHeight) { - switch (renderRelative) { - case LEFT_TOP: - case RIGHT_TOP: - return 0; - case LEFT_BOTTOM: - case RIGHT_BOTTOM: - return scaledHeight; - default: - return 0; - } - } - - public List getText() { - List textList = new ArrayList<>(); - textList.add(new Text("[", bracketColor.getRGB(), bold, italic, underline)); - textList.add(new Text(prefix == null ? key : prefix, keyColor.getRGB(), bold, italic, underline)); - textList.add(new Text("] ", bracketColor.getRGB(), bold, italic, underline)); - textList.add(new Text(getDisplayValue(), valueColor.getRGB(), bold, italic, underline)); - return textList; - } - - public int getWidth() { - String text = ""; - for(Text t : getText()) { - text += t.getText(); - } - return (int) (DrawAPI.getAPI().getStringWidth(text)*scaleMultiplier); - } - - public int getModuleHeight() { - return moduleHeight; - } - - public void draw(double screenX, double screenY) { - if(isEnabled != true) - return; - Iterator textIterator = getText().iterator(); - while(textIterator.hasNext()) { - Text text = textIterator.next(); - int stringWidth = (int) (DrawAPI.getAPI().getStringWidth(text.getText()) * scaleMultiplier); - DrawAPI.getAPI().renderString(text.getText(), (float) screenX, (float) screenY, true, false, scaleMultiplier, text.getColor()); - screenX += stringWidth; - } - } - - public void savePosition(DataManager dataManager) { - savePosition(dataManager, true); - } - - public void savePosition(DataManager dataManager, boolean saveAttached) { - dataManager.getSettings().getData().addProperty("modules." + key + ".distanceFromXRelative", distanceFromXRelative); - dataManager.getSettings().getData().addProperty("modules." + key + ".distanceFromYRelative", distanceFromYRelative); - if(getAttachedModule() == null) - dataManager.getSettings().getData().remove("modules." + key + ".attachedModule"); - else - dataManager.getSettings().getData().addProperty("modules." + key + ".attachedModule", getAttachedModule().key); - if(getParrentModule() == null) - dataManager.getSettings().getData().remove("modules." + key + ".parentModule"); - else - dataManager.getSettings().getData().addProperty("modules." + key + ".parentModule", getParrentModule().key); - dataManager.save(); - if(saveAttached && getAttachedModule() != null) - getAttachedModule().savePosition(dataManager, true); - } - - public void setDistanceFromXRelative(int distance) { - this.distanceFromXRelative = distance; - } - - public void setDistanceFromYRelative(int distance) { - this.distanceFromYRelative = distance; - } - - public void updatePosition(int distanceFromXRelative, int distanceFromYRelative, RenderRelative renderRelative, boolean moveAttachedModules) { - setDistanceFromXRelative(distanceFromXRelative); - setDistanceFromYRelative(distanceFromYRelative); - this.renderRelative = renderRelative; - if(moveAttachedModules && hasAttachedModule()) - getAttachedModule().updatePosition(distanceFromXRelative, distanceFromYRelative + moduleHeight + 1, renderRelative, true); - } - - public void updatePosition(int x, int y, int scaledWidth, int scaledHeight) { - updatePosition(x, y, scaledWidth, scaledHeight, true); - } - - public void updatePosition(int x, int y, int scaledWidth, int scaledHeight, boolean moveAttachedModules) { - renderRelative = scaledWidth / 2 <= x ? RenderRelative.RIGHT_TOP : RenderRelative.LEFT_TOP; - setDistanceFromXRelative(getDistanceFromRelative( - x, - scaledWidth, - DrawAPI.getAPI().getScaledWidth(), - true - ) - ); - setDistanceFromYRelative(getDistanceFromRelative( - y, - scaledHeight, - DrawAPI.getAPI().getScaledHeight(), - false - ) - ); - if(moveAttachedModules && hasAttachedModule()) - getAttachedModule().updatePosition(getDistanceFromXRelative(), getDistanceFromYRelative() + moduleHeight + 1, renderRelative, true); - } - - private int getDistanceFromRelative(int point, int scale, int actualScale, boolean isHorizontal) { - point = convertScaledRatio(point, scale, actualScale); - boolean isRelativeToZero; - if(isHorizontal) - isRelativeToZero = renderRelative == RenderRelative.LEFT_TOP || renderRelative == RenderRelative.LEFT_BOTTOM; - else - isRelativeToZero = renderRelative == RenderRelative.LEFT_TOP || renderRelative == RenderRelative.RIGHT_TOP; - return isRelativeToZero ? point : actualScale - point; - } - - private int convertScaledRatio(int point, int currentScale, int targetScale) { - double ratio = (double) targetScale / currentScale; - return (int) (point * ratio); - } - - public String getDisplayValue(){ - return "Dette modul er ikke aktivt!"; - } - - public boolean isEnabled() { - return isEnabled; - } - - public void setEnabled(boolean enabled) { - isEnabled = enabled; - if(isEnabled) - return; - if(parentModule != null && getAttachedModule() != null) { - getParrentModule().attachedModule = getAttachedModule(); - getParrentModule().attachedModuleKey = getAttachedModule().key; - getAttachedModule().parentModule = getParrentModule(); - getAttachedModule().parentModuleKey = getParrentModule().key; - this.parentModule = null; - this.parentModuleKey = null; - this.attachedModule = null; - this.attachedModuleKey = null; - }else if (getParrentModule() != null) { - getParrentModule().attachedModule = null; - getParrentModule().attachedModuleKey = null; - this.parentModule = null; - this.parentModuleKey = null; - }else if (getAttachedModule() != null) { - getAttachedModule().parentModule = null; - getAttachedModule().parentModuleKey = null; - this.attachedModule = null; - this.attachedModuleKey = null; - } - savePosition(DefaultModuleManager.getDataManager()); - } - - public Color getValueColor() { - return valueColor; - } - - public void setValueColor(Color valueColor) { - this.valueColor = valueColor; - } - - public Color getKeyColor() { - return keyColor; - } - - public void setKeyColor(Color keyColor) { - this.keyColor = keyColor; - } - - public Color getBracketColor() { - return bracketColor; - } - - public void setBracketColor(Color bracketColor) { - this.bracketColor = bracketColor; - } - - public String getKey() { - return key; - } - public String getPrefix() { - return prefix == null ? key : prefix; - } - - public ControlElement.IconData getIconData() { - return iconData == null ? new ControlElement.IconData(Material.PAPER) : iconData; - } - - public void setIconData(ControlElement.IconData iconData) { - this.iconData = iconData; - } - - public ModuleCategoryElement getCategory() { - return category; - } - - public void setCategory(ModuleCategoryElement categorySettingsElement) { - this.category = categorySettingsElement; - } - - public void attachModule(GuiModule module) { - if(module == this) - return; - if(module.isAttachedToModule()) - module.deattachFromParent(); - if(getAttachedModule() != null) { - module.attachModule(getAttachedModule()); - } - attachedModule = module; - attachedModuleKey = module.key; - getAttachedModule().parentModule = this; - getAttachedModule().parentModuleKey = this.key; - updatePosition(getDistanceFromXRelative(), getDistanceFromYRelative(), renderRelative, true); - } - - public void deattachModule() { - if(getAttachedModule() == null) - return; - getAttachedModule().parentModule = null; - getAttachedModule().parentModuleKey = null; - attachedModule = null; - attachedModuleKey = null; - } - - public void deattachFromParent() { - if(getParrentModule() != null) - getParrentModule().deattachModule(); - } - - public boolean hasAttachedModule() { - return getAttachedModule() != null; - } - - public boolean isAttachedToModule() { - return getParrentModule() != null; - } - - public Collection getSubModules() { - Collection subModules = new HashSet<>(); - subModules.add(this); - if(hasAttachedModule()) - subModules.addAll(getAttachedModule().getSubModules()); - return subModules; - } - - public GuiModule getNextModule() { - return getAttachedModule(); - } - - public boolean hasNextModule() { - return getAttachedModule() != null; - } - - public GuiModule getTopMostModule() { - if(getParrentModule() != null) - return getParrentModule().getTopMostModule(); - return this; - } - - public GuiModule getBottomMostModule() { - if(getAttachedModule() != null) - return getAttachedModule().getBottomMostModule(); - return this; - } - - public int getDistancetoBottomMostModule(boolean includeThis) { - int distance = 0; - if(includeThis) - distance += moduleHeight + 1; - if(attachedModule != null) - distance += getAttachedModule().getDistancetoBottomMostModule(true); - return distance; - } - - public GuiModule getAttachedModule() { - if(attachedModule == null) { - if (attachedModuleKey == null) - return null; - attachedModule = DefaultModuleManager.getModuleByKey(attachedModuleKey); - } - return attachedModule; - } - - public GuiModule getParrentModule() { - if(parentModule == null) { - if (parentModuleKey == null) - return null; - parentModule = DefaultModuleManager.getModuleByKey(parentModuleKey); - } - return parentModule; - } -} diff --git a/core/src/main/java/ml/volder/unikapi/widgets/GuiModuleRenderer.java b/core/src/main/java/ml/volder/unikapi/widgets/GuiModuleRenderer.java deleted file mode 100644 index b910b0e..0000000 --- a/core/src/main/java/ml/volder/unikapi/widgets/GuiModuleRenderer.java +++ /dev/null @@ -1,22 +0,0 @@ -package ml.volder.unikapi.widgets; - - -import ml.volder.unikapi.datasystem.Data; -import ml.volder.unikapi.datasystem.DataManager; -import ml.volder.unikapi.event.Listener; - -public class GuiModuleRenderer implements Listener { - - private DefaultModuleManager moduleManager; - - public GuiModuleRenderer(DefaultModuleManager moduleManager, DataManager dataManager) { - this.moduleManager = moduleManager; - } - - public void drawScreenEvent(/*DrawScreenEvent event*/) { - if(!ModuleSystem.shouldRenderModules()) - return; - // Not used anymore - drawn through the labymod widget system - //TODO remove old module system - } -} diff --git a/core/src/main/java/ml/volder/unikapi/widgets/Laby4ModuleManager.java b/core/src/main/java/ml/volder/unikapi/widgets/Laby4ModuleManager.java deleted file mode 100644 index 32fa9dd..0000000 --- a/core/src/main/java/ml/volder/unikapi/widgets/Laby4ModuleManager.java +++ /dev/null @@ -1,38 +0,0 @@ -package ml.volder.unikapi.widgets; - -import ml.volder.unikapi.types.Material; -import net.labymod.api.Laby; -import net.labymod.api.client.gui.hud.binding.category.HudWidgetCategory; -import net.labymod.api.client.gui.navigation.elements.ScreenNavigationElement; -import net.labymod.api.client.gui.screen.activity.types.TabbedActivity; - -import java.util.function.Function; - -public class Laby4ModuleManager implements ModuleManager{ - - int categoryId = 0; - @Override - public Object registerCategory(String title, Material material, String description) { - HudWidgetCategory category = new UnikHudWidgetCategory("unikapi-category-" + categoryId, title, description); - Laby.labyAPI().hudWidgetRegistry().categoryRegistry().register(category); - categoryId += 1; - return category; - } - - @Override - public void registerModule(String key, String defaultPrefix, boolean defaultIsEnabled, Object category, Material icon, Function getDisplayValue) { - if(!(category instanceof HudWidgetCategory)) - return; - Laby.labyAPI().hudWidgetRegistry().register(new UnikHudWidget(key, (HudWidgetCategory) category, defaultPrefix, icon,getDisplayValue)); - } - - @Override - public void openEditor() { - ScreenNavigationElement navigationElement = Laby.references().navigationRegistry().getById("labymod") instanceof ScreenNavigationElement ? (ScreenNavigationElement) Laby.references().navigationRegistry().getById("labymod") : null; - if(navigationElement == null || navigationElement.getScreen() == null || !(navigationElement.getScreen() instanceof TabbedActivity)) - return; - TabbedActivity tabbedActivity = (TabbedActivity) navigationElement.getScreen(); - tabbedActivity.switchTab("widgets"); - Laby.labyAPI().minecraft().minecraftWindow().displayScreen(tabbedActivity); - } -} diff --git a/core/src/main/java/ml/volder/unikapi/widgets/ModuleSystem.java b/core/src/main/java/ml/volder/unikapi/widgets/ModuleSystem.java index dc67e8e..15c530c 100644 --- a/core/src/main/java/ml/volder/unikapi/widgets/ModuleSystem.java +++ b/core/src/main/java/ml/volder/unikapi/widgets/ModuleSystem.java @@ -34,6 +34,15 @@ public static Object registerCategory(String displayName) { return registerCategory(displayName, Material.PAPER, ""); } + /*** + * Register a module through the labymod api + * @param key the key of the module + * @param defaultPrefix the default prefix of the module + * @param defaultIsEnabled the default state of the module + * @param category the category of the module + * @param icon the icon of the module + * @param getDisplayValue the function that returns the display value of the module + */ public static void registerModule(String key, String defaultPrefix, boolean defaultIsEnabled, Object category, Material icon, Function getDisplayValue) { getModuleManager().registerModule(key, defaultPrefix, defaultIsEnabled, category, icon, getDisplayValue); } diff --git a/core/src/main/java/ml/volder/unikapi/widgets/RenderRelative.java b/core/src/main/java/ml/volder/unikapi/widgets/RenderRelative.java deleted file mode 100644 index 7b8964e..0000000 --- a/core/src/main/java/ml/volder/unikapi/widgets/RenderRelative.java +++ /dev/null @@ -1,8 +0,0 @@ -package ml.volder.unikapi.widgets; - -public enum RenderRelative { - LEFT_TOP, - LEFT_BOTTOM, - RIGHT_TOP, - RIGHT_BOTTOM -} diff --git a/core/src/main/java/ml/volder/unikapi/widgets/Text.java b/core/src/main/java/ml/volder/unikapi/widgets/Text.java deleted file mode 100644 index 2aaaf67..0000000 --- a/core/src/main/java/ml/volder/unikapi/widgets/Text.java +++ /dev/null @@ -1,66 +0,0 @@ -package ml.volder.unikapi.widgets; - -import ml.volder.unikapi.types.ModColor; - -public class Text { - private String text; - private int color; - - public Text(String text, int color) { - this.text = text; - this.color = color; - } - - public Text(String text, int color, boolean bold, boolean italic, boolean underline) { - if (bold) { - text = ModColor.cl('l') + text; - } - - if (italic) { - text = ModColor.cl('o') + text; - } - - if (underline) { - text = ModColor.cl('n') + text; - } - - this.text = text; - this.color = color; - } - - public static Text getText(String text) { - return new Text(text, 16777215); - } - - public static Text getText(String text, int color) { - return new Text(text, color); - } - - public static Text getText(String text, int r, int g, int b) { - return getText(text, ModColor.toRGB(r, g, b, 255)); - } - - public static Text getText(String text, int r, int g, int b, int a) { - return getText(text, ModColor.toRGB(r, g, b, a)); - } - - public boolean isDefaultColor() { - return this.color == 16777215; - } - - public String getText() { - return this.text; - } - - public int getColor() { - return this.color; - } - - public void setText(String text) { - this.text = text; - } - - public void setColor(int color) { - this.color = color; - } -} diff --git a/core/src/main/java/ml/volder/unikapi/widgets/editor/GuiEditor.java b/core/src/main/java/ml/volder/unikapi/widgets/editor/GuiEditor.java deleted file mode 100644 index f3def56..0000000 --- a/core/src/main/java/ml/volder/unikapi/widgets/editor/GuiEditor.java +++ /dev/null @@ -1,376 +0,0 @@ -package ml.volder.unikapi.widgets.editor; - - -import ml.volder.unikapi.api.draw.DrawAPI; -import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.guisystem.ModTextures; -import ml.volder.unikapi.guisystem.elements.BooleanElement; -import ml.volder.unikapi.guisystem.elements.ControlElement; -import ml.volder.unikapi.guisystem.elements.Scrollbar; -import ml.volder.unikapi.guisystem.elements.SettingsElement; -import ml.volder.unikapi.keysystem.Key; -import ml.volder.unikapi.keysystem.MouseButton; -import ml.volder.unikapi.types.ModColor; -import ml.volder.unikapi.widgets.DefaultModuleManager; -import ml.volder.unikapi.widgets.GuiModule; -import ml.volder.unikapi.widgets.RenderRelative; -import ml.volder.unikapi.widgets.elements.ModuleCategoryElement; -import ml.volder.unikapi.wrappers.guibutton.WrappedGuiButton; -import ml.volder.unikapi.wrappers.guiscreen.WrappedGuiScreen; - -import java.awt.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class GuiEditor extends WrappedGuiScreen { - - private static final int MODULE_ATTACH_DISTANCE = 30; - - private ArrayList path = new ArrayList(); - - private List moduleCategoryElementList = new ArrayList<>(); - private DefaultModuleManager moduleManager; - private GuiModule hoveredGuiModule; - private GuiModule draggedGuiModule; - private GuiModule attachGuiModule; - private double dragOffsetX; - private double dragOffsetY; - private WrappedGuiButton buttonBack; - private WrappedGuiScreen lastScreen; - private Scrollbar scrollbar; - - private int editorScaledWidth; - private int editorScaledHeight; - - public GuiEditor(DefaultModuleManager moduleManager, WrappedGuiScreen lastScreen) { - this.moduleManager = moduleManager; - this.lastScreen = lastScreen; - this.scrollbar = new Scrollbar(22); - editorScaledHeight = getHeight() / 6 * 5; - editorScaledWidth = getWidth() / 6 * 5; - for(ModuleCategoryElement category : moduleManager.getGuiModuleCategories()) { - category.getSubSettings().getElements().clear(); - moduleCategoryElementList.add(category); - } - - for (GuiModule guiModule : moduleManager.getGuiModuleList()) { - - String key = "modules." + guiModule.getKey() + ".isEnabled"; - - BooleanElement booleanElement = new BooleanElement(guiModule.getPrefix(), moduleManager.getDataManager(),key, guiModule.getIconData(), (moduleManager.getDataManager().getSettings().getData().has(key) && moduleManager.getDataManager().getSettings().getData().get(key).getAsBoolean())); - booleanElement.addCallback(guiModule::setEnabled); - for (SettingsElement elements : guiModule.getSubSettings(moduleManager.getDataManager())) { - booleanElement.getSubSettings().add(elements); - } - - booleanElement.setAdvancedButtonCallback(aBoolean -> { - this.path.add(booleanElement); - }); - - guiModule.getCategory().getSubSettings().add(booleanElement); - } - this.buttonBack = new WrappedGuiButton(1, 5, (getHeight() / 24) + 10, 22, 20, "<"); - } - - @Override - public void updateScreen() { - - } - - @Override - public void initGui() { - double editorWidth = getWidth() / 6; - double editorHeight = getHeight() / 6 * 5; - double editorStart = getHeight() / 6 * 0.5; - double editorEnd = editorStart + editorHeight; - this.scrollbar.setPosition(editorWidth - 3, editorStart + 2, editorWidth - 1, editorEnd - 2); - this.scrollbar.setSpeed(22); - this.scrollbar.update(this.moduleCategoryElementList.size()); - this.scrollbar.init(); - } - - @Override - public void actionPerformed(WrappedGuiButton button) { - if(button.getId() == 1) { - if(!path.isEmpty()){ - path.remove(path.size()-1); - this.scrollbar.setScrollY(0); - }else { - if(lastScreen != null){ - PlayerAPI.getAPI().openGuiScreen(lastScreen); - }else{ - PlayerAPI.getAPI().openGuiScreen(null); - } - } - } - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - editorScaledHeight = getHeight() / 6 * 5; - editorScaledWidth = getWidth() / 6 * 5; - //Draw Background - DrawAPI drawAPI = DrawAPI.getAPI(); - drawAPI.drawOverlayBackground(0, this.getHeight()); - drawAPI.drawDimmedBackground(0); - drawMinecraftBackground(); - //Draw Modules - drawModules(mouseX, mouseY); - //Draw Editor - this.scrollbar.draw(mouseX, mouseY); - - double editorWidth = getWidth() / 6; - double startY = ((getHeight() / 6) * 0.5) + 2 + this.scrollbar.getScrollY(); - double elementX = editorWidth * 0.02; - double elementWidth = editorWidth - elementX * 2; - double totalEntryHeight = 0.0D; - if(path.isEmpty()){ - for (ModuleCategoryElement moduleCategoryElement : moduleCategoryElementList) { - moduleCategoryElement.draw((int)elementX, (int)startY, (int)(elementX + elementWidth), (int)startY + moduleCategoryElement.getEntryHeight(), mouseX, mouseY); - startY += moduleCategoryElement.getEntryHeight() + 2; - totalEntryHeight += moduleCategoryElement.getEntryHeight() + 2; - } - this.scrollbar.setEntryHeight(totalEntryHeight / (double)this.moduleCategoryElementList.size()); - this.scrollbar.update(this.moduleCategoryElementList.size()); - } else { - if(path.get(path.size()-1).hasSubSettings()) { - for (SettingsElement settingsElement : path.get(path.size()-1).getSubSettings().getElements()) { - settingsElement.draw((int)elementX, (int)startY, (int)(elementX + elementWidth), (int)startY + settingsElement.getEntryHeight(), mouseX, mouseY); - startY += settingsElement.getEntryHeight() + 2; - totalEntryHeight += settingsElement.getEntryHeight() + 2; - } - } - this.scrollbar.setEntryHeight(totalEntryHeight / (double)this.path.get(path.size()-1).getSubSettings().getElements().size()); - this.scrollbar.update(this.path.get(path.size()-1).getSubSettings().getElements().size()); - } - - drawAPI.drawOverlayBackground(0, (int) ((getHeight() / 6) * 0.5)); - drawAPI.drawOverlayBackground(getHeight() - (int) ((getHeight() / 6) * 0.5) - 5, getHeight()); - drawAPI.drawGradientShadowBottom(getHeight()-((getHeight() / 6) * 0.5) - 5, 0, getWidth()); - drawAPI.drawGradientShadowTop(((getHeight() / 6) * 0.5), 0, getWidth()); - - this.buttonBack.drawButton(mouseX, mouseY); - } - - private void drawMinecraftBackground() { - DrawAPI drawAPI = DrawAPI.getAPI(); - double backgroundWidth = (getWidth() / 6) * 5; - double backgroundHeight = (getHeight() / 6) * 5; - drawAPI.bindTexture(ModTextures.MINECRAFT_BACKGROUND); - drawAPI.drawTexture((getWidth() / 6),(getHeight() / 6) * 0.5,256,256,backgroundWidth,backgroundHeight); - } - - private void drawModules(int mouseX, int mouseY) { - hoveredGuiModule = null; - - moduleManager.getGuiModuleList().forEach(guiModule -> { - if(guiModule.isEnabled()) { - if(isMouseOverModule(mouseX,mouseY,guiModule)) { - hoveredGuiModule = guiModule; - } - } - }); - - moduleManager.getGuiModuleList().forEach(this::drawGuiModule); - } - - private void drawGuiModule(GuiModule guiModule) { - if(guiModule.isAttachedToModule()) - return; - double drawX = guiModule.getDrawX(editorScaledWidth) + getWidth() / 6; - double drawY = guiModule.getDrawY(editorScaledHeight) + getHeight() / 6 * 0.5; - Collection subModules = guiModule.getSubModules(); - if(guiModule.getRenderRelative() == RenderRelative.RIGHT_TOP || guiModule.getRenderRelative() == RenderRelative.LEFT_TOP) { - for (GuiModule module : subModules) { - if(drawX + module.getWidth() - getWidth() / 6 > editorScaledWidth) - drawX = DrawAPI.getAPI().getScaledWidth() - module.getWidth(); - } - } - GuiModule module = guiModule; - while (module != null) { - DrawAPI drawAPI = DrawAPI.getAPI(); - if(hoveredGuiModule != null && draggedGuiModule == null && hoveredGuiModule == module) { - drawAPI.drawRect(drawX, drawY,drawX+module.getWidth(),drawY+module.getModuleHeight(), ModColor.toRGB(128,128, 128, 100)); - } else if (draggedGuiModule == module) { - drawAPI.drawRect(drawX, drawY,drawX+module.getWidth(),drawY+module.getModuleHeight(), ModColor.toRGB(128,128, 128, 150)); - } - if (attachGuiModule != null && attachGuiModule == module) { - double endX = drawX + attachGuiModule.getWidth(); - drawAPI.drawRectangle((int) drawX, (int) drawY + module.getModuleHeight(), (int) endX, (int) drawY + module.getModuleHeight() + 1, new Color(255, 218, 0,255).getRGB()); - } - module.draw(drawX, drawY); - drawY += module.getModuleHeight() + 1; - module = module.getNextModule(); - } - } - - private boolean isMouseOverModule(int mouseX, int mouseY, GuiModule guiModule) { - DrawAPI drawAPI = DrawAPI.getAPI(); - GuiModule topMostModule = guiModule.getTopMostModule(); - double drawX = topMostModule.getDrawX(editorScaledWidth) + getWidth() / 6; - double drawY = topMostModule.getDrawY(editorScaledHeight) + getHeight() / 6 * 0.5; - GuiModule module = topMostModule; - while (module != null) { - if(module != guiModule) - drawY += module.getModuleHeight() + 1; - else - break; - module = module.getNextModule(); - } - - Collection subModules = guiModule.getSubModules(); - if(guiModule.getRenderRelative() == RenderRelative.RIGHT_TOP || guiModule.getRenderRelative() == RenderRelative.LEFT_TOP) { - for (GuiModule m : subModules) { - if(drawX + m.getWidth() - getWidth() / 6 > editorScaledWidth) - drawX = DrawAPI.getAPI().getScaledWidth() - m.getWidth(); - } - } - - double width = guiModule.getWidth(); - double height = drawAPI.getFontHeight(); - return (mouseX > drawX && mouseX < drawX + width) && (mouseY > drawY && mouseY < drawY + height); - } - - @Override - public void mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) { - this.scrollbar.mouseAction(mouseX, mouseY, Scrollbar.EnumMouseAction.CLICKED); - if(mouseY >= getHeight() / 12 && mouseY <= getHeight() / 6 * 5.5){ - if(this.path.isEmpty()) { - for (ModuleCategoryElement moduleCategoryElement : moduleCategoryElementList) { - if (moduleCategoryElement.isMouseOver()) { - this.path.add(moduleCategoryElement); - } - } - } - if(!this.path.isEmpty()) { - if(path.get(path.size()-1).hasSubSettings()) { - for (SettingsElement settingsElement : path.get(path.size()-1).getSubSettings().getElements()) { - if(settingsElement instanceof ControlElement && ((ControlElement)settingsElement).getButtonAdvanced().isMouseOver() && ((ControlElement)settingsElement).getButtonAdvanced().isEnabled()) { - ((ControlElement) settingsElement).getAdvancedButtonCallback().accept(true); - } - settingsElement.unfocus(mouseX, mouseY, mouseButton); - settingsElement.mouseClicked(mouseX, mouseY, mouseButton); - } - } - } - } - - - if(this.buttonBack.isMouseOver()) { - actionPerformed(buttonBack); - } - - draggedGuiModule = hoveredGuiModule; - if(draggedGuiModule == null) - return; - dragOffsetX = (mouseX - getWidth() / 6) - draggedGuiModule.getDrawX(getWidth() / 6 * 5); - dragOffsetY = (mouseY - getHeight() / 6 * 0.5) - draggedGuiModule.getDrawY(getHeight() / 6 * 5); - } - - @Override - public void mouseClickMove(int mouseX, int mouseY, MouseButton clickedMouseButton, long timeSinceLastClick) { - this.scrollbar.mouseAction(mouseX, mouseY, Scrollbar.EnumMouseAction.DRAGGING); - if(!this.path.isEmpty()) { - if(path.get(path.size()-1).hasSubSettings()) { - for (SettingsElement settingsElement : path.get(path.size()-1).getSubSettings().getElements()) { - settingsElement.mouseClickMove(mouseX, mouseY, clickedMouseButton); - } - } - } - if(draggedGuiModule == null || !draggedGuiModule.isEnabled()) - return; - if(mouseX > getWidth() / 6 && (mouseY > getHeight() / 6 * 0.5 && mouseY < getHeight() - getHeight() / 6 * 0.5)){ - double scaledWidth = getWidth() / 6 * 5; - double scaledHeight = getHeight() / 6 * 5; - double xPos = mouseX - getWidth() / 6 - dragOffsetX; - double yPos = mouseY - getHeight() / 6 * 0.5 - dragOffsetY; - - - - Collection guiModules = draggedGuiModule.getSubModules(); - - for (GuiModule module : guiModules) { - // Check out of screen x - if(xPos + module.getWidth() > scaledWidth && xPos - module.getWidth() < xPos) - xPos = scaledWidth - (module.getWidth() * (scaledWidth / DrawAPI.getAPI().getScaledWidth())); - xPos = xPos < 0 ? 0 : xPos; - - // Check out of screen y - if(yPos + module.getDistancetoBottomMostModule(false) > scaledHeight) { - yPos = scaledHeight - module.getDistancetoBottomMostModule(false); - } - yPos = yPos < 0 ? 0 : yPos; - } - - - - - if(draggedGuiModule.isAttachedToModule()) - draggedGuiModule.deattachFromParent(); - draggedGuiModule.updatePosition((int) xPos, (int) yPos, (int) scaledWidth, (int) scaledHeight); - - //Check if module should attach - attachGuiModule = null; - for(GuiModule module : moduleManager.getGuiModuleList()) { - if(module == draggedGuiModule) - continue; - if (!module.isEnabled()) - continue; - if(draggedGuiModule.getTopMostModule().getSubModules().contains(module)) - continue; - double drawX = module.getDrawX(editorScaledWidth) + getWidth() / 6; - double drawY = module.getDrawY(editorScaledHeight) + getHeight() / 12; - if(!(mouseX > drawX && mouseX < drawX + module.getWidth())) - continue; - if(attachGuiModule != null && attachGuiModule.getDrawY(editorScaledHeight) + getHeight() / 12 + module.getModuleHeight() - 1 > drawY) - continue; - if(mouseY > drawY && Math.abs(mouseY - drawY) < MODULE_ATTACH_DISTANCE) { - attachGuiModule = module; - } - } - - } - } - - @Override - public void mouseReleased(int mouseX, int mouseY, MouseButton mouseButton) { - this.scrollbar.mouseAction(mouseX, mouseY, Scrollbar.EnumMouseAction.RELEASED); - if(!this.path.isEmpty()) { - if(path.get(path.size()-1).hasSubSettings()) { - for (SettingsElement settingsElement : path.get(path.size()-1).getSubSettings().getElements()) { - settingsElement.mouseRelease(mouseX, mouseY, mouseButton); - } - } - } - if(attachGuiModule != null) - attachGuiModule.attachModule(draggedGuiModule); - attachGuiModule = null; - if(draggedGuiModule != null) - draggedGuiModule.getTopMostModule().savePosition(moduleManager.getDataManager()); - draggedGuiModule = null; - dragOffsetX = 0; - dragOffsetY = 0; - } - - @Override - public void handleMouseInput() { - this.scrollbar.mouseInput(); - } - - @Override - public void keyTyped(char typedChar, Key key) { - if(!this.path.isEmpty()) { - if(path.get(path.size()-1).hasSubSettings()) { - for (SettingsElement settingsElement : path.get(path.size()-1).getSubSettings().getElements()) { - settingsElement.keyTyped(typedChar, key); - } - } - } - } - - @Override - public void onGuiClosed() { - - } -} diff --git a/core/src/main/java/ml/volder/unikapi/widgets/elements/ModuleCategoryElement.java b/core/src/main/java/ml/volder/unikapi/widgets/elements/ModuleCategoryElement.java deleted file mode 100644 index 262dfe7..0000000 --- a/core/src/main/java/ml/volder/unikapi/widgets/elements/ModuleCategoryElement.java +++ /dev/null @@ -1,76 +0,0 @@ -package ml.volder.unikapi.widgets.elements; - - -import ml.volder.unikapi.api.draw.DrawAPI; -import ml.volder.unikapi.guisystem.elements.BooleanElement; -import ml.volder.unikapi.guisystem.elements.ControlElement; -import ml.volder.unikapi.guisystem.elements.SettingsElement; -import ml.volder.unikapi.keysystem.Key; -import ml.volder.unikapi.keysystem.MouseButton; -import ml.volder.unikapi.types.ModColor; - -public class ModuleCategoryElement extends SettingsElement { - - private ControlElement.IconData iconData; - - public ModuleCategoryElement(String displayName, ControlElement.IconData iconData) { - super(displayName, (String)null); - this.iconData = iconData; - } - - public void draw(int x, int y, int maxX, int maxY, int mouseX, int mouseY) { - super.draw(x, y, maxX, maxY, mouseX, mouseY); - int absoluteY = y + 7; - DrawAPI drawAPI = DrawAPI.getAPI(); - drawAPI.drawRectangle(x, y, maxX, maxY, ModColor.toRGB(200, 200, 200, this.mouseOver ? 50 : 30)); - int imageSize = maxY - y; - if (this.iconData.hasTextureIcon()) { - drawAPI.bindTexture(this.iconData.getTextureIcon()); - drawAPI.drawTexture((double) (x + 2), (double) (y + 2), 256.0D, 256.0D, 18.0D, 18.0D); - } else if (this.iconData.hasMaterialIcon()) { - drawAPI.drawItem(this.iconData.getMaterialIcon(), this.iconData.getItemDamage(), x + 3, y + 3, null); - } - drawAPI.drawString(this.getDisplayName(), (double)(x + imageSize + 5), (double)absoluteY); - drawAPI.drawRightString(getSubSettings().getElements().stream().filter(element -> { - if(element instanceof BooleanElement) { - return ((BooleanElement) element).getCurrentValue(); - } - return false; - }).count() + ModColor.cl("7") + "/" + ModColor.cl("f") + getSubSettings().getElements().size(), (double)(maxX - 5), (double)absoluteY); - } - - @Override - public void drawDescription(int var1, int var2, int var3) { - - } - - @Override - public void mouseClicked(int var1, int var2, MouseButton mouseButton) { - - } - - @Override - public void mouseRelease(int var1, int var2, MouseButton mouseButton) { - - } - - @Override - public void mouseClickMove(int var1, int var2, MouseButton mouseButton) { - - } - - @Override - public void keyTyped(char var1, Key key) { - - } - - @Override - public void unfocus(int var1, int var2, MouseButton mouseButton) { - - } - - @Override - public int getEntryHeight() { - return 22; - } -}