diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java index 05f70105900c..990e555d2706 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java @@ -3,6 +3,7 @@ import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.HasLegacyId; import at.hannibal2.skyhanni.config.features.inventory.chocolatefactory.ChocolateFactoryConfig; +import at.hannibal2.skyhanni.config.features.inventory.customwardrobe.CustomWardrobeConfig; import at.hannibal2.skyhanni.config.features.inventory.helper.HelperConfig; import at.hannibal2.skyhanni.config.features.itemability.ItemAbilityConfig; import at.hannibal2.skyhanni.config.features.misc.EstimatedItemValueConfig; @@ -49,6 +50,10 @@ public class InventoryConfig { @Category(name = "Item Abilities", desc = "Stuff about item abilities.") public ItemAbilityConfig itemAbilities = new ItemAbilityConfig(); + @Expose + @Category(name = "Custom Wardrobe", desc = "New Wardrobe Look.") + public CustomWardrobeConfig customWardrobe = new CustomWardrobeConfig(); + @Expose @Category(name = "Chocolate Factory", desc = "Features to help you master the Chocolate Factory idle game.") public ChocolateFactoryConfig chocolateFactory = new ChocolateFactoryConfig(); @@ -93,23 +98,19 @@ public class InventoryConfig { @Accordion public GetFromSackConfig gfs = new GetFromSackConfig(); + @Expose @ConfigOption(name = "Pocket Sack-In-A-Sack", desc = "") @Accordion - @Expose public PocketSackInASackConfig pocketSackInASack = new PocketSackInASackConfig(); @Expose - @ConfigOption( - name = "Item Number", - desc = "Showing the item number as a stack size for these items." - ) + @ConfigOption(name = "Item Number", desc = "Showing the item number as a stack size for these items.") @ConfigEditorDraggableList public List itemNumberAsStackSize = new ArrayList<>(Arrays.asList( NEW_YEAR_CAKE, RANCHERS_BOOTS_SPEED, LARVA_HOOK, - VACUUM_GARDEN - )); + VACUUM_GARDEN)); public enum ItemNumberEntry implements HasLegacyId { MASTER_STAR_TIER("§bMaster Star Tier", 0), @@ -168,11 +169,8 @@ public String toString() { public boolean vacuumBagCap = true; @Expose - @ConfigOption( - name = "Quick Craft Confirmation", - desc = "Require Ctrl+Click to craft items that aren't often quick crafted " + - "(e.g. armor, weapons, accessories). Sack items can be crafted normally." - ) + @ConfigOption(name = "Quick Craft Confirmation", desc = "Require Ctrl+Click to craft items that aren't often quick crafted " + + "(e.g. armor, weapons, accessories). Sack items can be crafted normally.") @ConfigEditorBoolean @FeatureToggle public boolean quickCraftingConfirmation = false; @@ -190,23 +188,20 @@ public String toString() { public boolean anvilCombineHelper = false; @Expose - @ConfigOption(name = "Item Stars", - desc = "Show a compact star count in the item name for all items.") + @ConfigOption(name = "Item Stars", desc = "Show a compact star count in the item name for all items.") @ConfigEditorBoolean @FeatureToggle public boolean itemStars = false; @Expose - @ConfigOption(name = "Missing Tasks", - desc = "Highlight missing tasks in the SkyBlock Level Guide inventory.") + @ConfigOption(name = "Missing Tasks", desc = "Highlight missing tasks in the SkyBlock Level Guide inventory.") // TODO move( , "inventory.highlightMissingSkyBlockLevelGuide", "inventory.skyblockGuideConfig.highlightMissingSkyBlockLevelGuide") @ConfigEditorBoolean @FeatureToggle public boolean highlightMissingSkyBlockLevelGuide = true; @Expose - @ConfigOption(name = "Power Stone Guide", - desc = "Highlight missing power stones, show their total bazaar price, and allows to open the bazaar when clicking on the items in the Power Stone Guide.") + @ConfigOption(name = "Power Stone Guide", desc = "Highlight missing power stones, show their total bazaar price, and allows to open the bazaar when clicking on the items in the Power Stone Guide.") // TODO move( , "inventory.powerStoneGuide", "inventory.skyblockGuideConfig.powerStoneGuide") @ConfigEditorBoolean @FeatureToggle diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/ColorConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/ColorConfig.java new file mode 100644 index 000000000000..20f9282542b3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/ColorConfig.java @@ -0,0 +1,44 @@ +package at.hannibal2.skyhanni.config.features.inventory.customwardrobe; + +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorColour; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class ColorConfig { + + @Expose + @ConfigOption(name = "Background", desc = "Color of the GUI background.") + @ConfigEditorColour + public String backgroundColor = "0:127:0:0:0"; + + @Expose + @ConfigOption(name = "Equipped", desc = "Color of the currently equipped wardrobe slot.") + @ConfigEditorColour + public String equippedColor = "0:127:85:255:85"; + + @Expose + @ConfigOption(name = "Favorite", desc = "Color of the wardrobe slots that have been added as favorites.") + @ConfigEditorColour + public String favoriteColor = "0:127:255:85:85"; + + @Expose + @ConfigOption(name = "Same Page", desc = "Color of wardrobe slots in the same page.") + @ConfigEditorColour + public String samePageColor = "0:127:94:108:255"; + + @Expose + @ConfigOption(name = "Other Page", desc = "Color of wardrobe slots in another page.") + @ConfigEditorColour + public String otherPageColor = "0:127:0:0:0"; + + @Expose + @ConfigOption(name = "Top Outline", desc = "Color of the top of the outline when hovered.") + @ConfigEditorColour + public String topBorderColor = "0:255:255:200:0"; + + @Expose + @ConfigOption(name = "Bottom Outline", desc = "Color of the bottom of the outline when hovered.") + @ConfigEditorColour + public String bottomBorderColor = "0:255:255:0:0"; + +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/CustomWardrobeConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/CustomWardrobeConfig.java new file mode 100644 index 000000000000..a4ea69badb20 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/CustomWardrobeConfig.java @@ -0,0 +1,54 @@ +package at.hannibal2.skyhanni.config.features.inventory.customwardrobe; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.Accordion; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class CustomWardrobeConfig { + + @Expose + @ConfigOption(name = "Enable", desc = "Enables the Custom Wardrobe GUI.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Follow mouse", desc = "Players follow the movement of the mouse.") + @ConfigEditorBoolean + public boolean eyesFollowMouse = true; + + @Expose + @ConfigOption(name = "Hide Empty Slots", desc = "Hides wardrobe slots with no armor.") + @ConfigEditorBoolean + public boolean hideEmptySlots = false; + + @Expose + @ConfigOption(name = "Hide Locked Slots", desc = "Hides locked wardrobe slots.") + @ConfigEditorBoolean + public boolean hideLockedSlots = false; + + @Expose + public boolean onlyFavorites = false; + + @Expose + @ConfigOption(name = "Estimated Value", desc = "Show a §2$ §7sign you can hover to see the wardrobe slot value.") + @ConfigEditorBoolean + public boolean estimatedValue = true; + + @Expose + @ConfigOption(name = "Loading text", desc = "Shows a \"§cLoading...\" §7text when the wardrobe page hasn't fully loaded in yet.") + @ConfigEditorBoolean + public boolean loadingText = true; + + @Expose + @ConfigOption(name = "Colors", desc = "Change the color settings.") + @Accordion + public ColorConfig color = new ColorConfig(); + + @Expose + @ConfigOption(name = "Spacing", desc = "") + @Accordion + public SpacingConfig spacing = new SpacingConfig(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/SpacingConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/SpacingConfig.java new file mode 100644 index 000000000000..363a9a6a70bf --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/customwardrobe/SpacingConfig.java @@ -0,0 +1,145 @@ +package at.hannibal2.skyhanni.config.features.inventory.customwardrobe; + +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import io.github.notenoughupdates.moulconfig.observer.Property; + +public class SpacingConfig { + + @Expose + @ConfigOption(name = "Global Scale", desc = "Controls the scale of the entirety of the wardrobe.") + @ConfigEditorSlider( + minValue = 30, + maxValue = 200, + minStep = 1 + ) + public Property globalScale = Property.of(100); + + @Expose + @ConfigOption(name = "Outline Thickness", desc = "How thick the outline of the hovered slot is.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 15, + minStep = 1 + ) + public Property outlineThickness = Property.of(5); + + @Expose + @ConfigOption(name = "Outline Blur", desc = "Amount of blur of the outline.") + @ConfigEditorSlider( + minValue = 0f, + maxValue = 1f, + minStep = 0.1f + ) + public Property outlineBlur = Property.of(0.5f); + + @Expose + @ConfigOption(name = "Slot Width", desc = "Width of the wardrobe slots.") + @ConfigEditorSlider( + minValue = 30, + maxValue = 100, + minStep = 1 + ) + public Property slotWidth = Property.of(75); + + @Expose + @ConfigOption(name = "Slot Height", desc = "Height of the wardrobe slots.") + @ConfigEditorSlider( + minValue = 60, + maxValue = 200, + minStep = 1 + ) + public Property slotHeight = Property.of(140); + + @Expose + @ConfigOption(name = "Player Scale", desc = "Scale of the players.") + @ConfigEditorSlider( + minValue = 0, + maxValue = 100, + minStep = 1 + ) + public Property playerScale = Property.of(75); + + @Expose + @ConfigOption(name = "Slots per Row", desc = "Max amount of wardrobe slots per row.") + @ConfigEditorSlider( + minValue = 5, + maxValue = 18, + minStep = 1 + ) + public Property maxPlayersPerRow = Property.of(9); + + @Expose + @ConfigOption(name = "Slots Horizontal Spacing", desc = "How much space horizontally between wardrobe slots.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 20, + minStep = 1 + ) + public Property horizontalSpacing = Property.of(3); + + @Expose + @ConfigOption(name = "Slots Vertical Spacing", desc = "How much space vertically between wardrobe slots.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 20, + minStep = 1 + ) + public Property verticalSpacing = Property.of(3); + + @Expose + @ConfigOption(name = "Slots & Buttons Spacing", desc = "How much vertical space there is between wardrobe slots and the buttons.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 40, + minStep = 1 + ) + public Property buttonSlotsVerticalSpacing = Property.of(10); + + @Expose + @ConfigOption(name = "Button Horizontal Spacing", desc = "How much space horizontally between buttons.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 40, + minStep = 1 + ) + public Property buttonHorizontalSpacing = Property.of(10); + + @Expose + @ConfigOption(name = "Button Vertical Spacing", desc = "How much space vertically between buttons.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 40, + minStep = 1 + ) + public Property buttonVerticalSpacing = Property.of(10); + + @Expose + @ConfigOption(name = "Button Width", desc = "Width of the buttons.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 60, + minStep = 1 + ) + public Property buttonWidth = Property.of(50); + + @Expose + @ConfigOption(name = "Button Height", desc = "Height of the buttons.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 60, + minStep = 1 + ) + public Property buttonHeight = Property.of(20); + + @Expose + @ConfigOption(name = "Background Padding", desc = "Space between the edges of the background and the slots.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 20, + minStep = 1 + ) + public Property backgroundPadding = Property.of(10); + +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index bc25da446e3e..0fce526a5e47 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -28,6 +28,7 @@ import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker; import at.hannibal2.skyhanni.features.garden.pests.VinylType; import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI; import at.hannibal2.skyhanni.features.mining.fossilexcavator.ExcavatorProfitTracker; import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker; import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker; @@ -609,13 +610,26 @@ public static class DianaStorage { public DianaProfitTracker.Data dianaProfitTracker = new DianaProfitTracker.Data(); @Expose - // TODO renmae + // TODO rename public MythologicalCreatureTracker.Data mythologicalMobTracker = new MythologicalCreatureTracker.Data(); } @Expose public Map skillData = new HashMap<>(); + @Expose + public WardrobeStorage wardrobe = new WardrobeStorage(); + + public static class WardrobeStorage { + @Expose + public Map wardrobeData = new HashMap<>(); + + @Expose + @Nullable + public Integer currentWardrobeSlot = null; + } + + @Expose public UpgradeReminder.CommunityShopUpgrade communityShopProfileUpgrade = null; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt new file mode 100644 index 000000000000..03004a7f7e83 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt @@ -0,0 +1,578 @@ +package at.hannibal2.skyhanni.features.inventory.wardrobe + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.core.config.Position +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.MAX_PAGES +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.MAX_SLOT_PER_PAGE +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.createWardrobePriceLore +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.currentPage +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.currentWardrobeSlot +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.inCustomWardrobe +import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.inWardrobe +import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ColorUtils.addAlpha +import at.hannibal2.skyhanni.utils.ColorUtils.darker +import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor +import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColorInt +import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha +import at.hannibal2.skyhanni.utils.ConditionalUtils +import at.hannibal2.skyhanni.utils.ConditionalUtils.transformIf +import at.hannibal2.skyhanni.utils.ConfigUtils.jumpToEditor +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.EntityUtils.getFakePlayer +import at.hannibal2.skyhanni.utils.InventoryUtils.clickSlot +import at.hannibal2.skyhanni.utils.InventoryUtils.getWindowId +import at.hannibal2.skyhanni.utils.ItemUtils.removeEnchants +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment +import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color +import kotlin.math.min +import kotlin.time.Duration.Companion.milliseconds + +@SkyHanniModule +object CustomWardrobe { + + private val config get() = SkyHanniMod.feature.inventory.customWardrobe + + private var displayRenderable: Renderable? = null + private var inventoryButton: Renderable? = null + private var editMode = false + private var waitingForInventoryUpdate = false + + private var activeScale: Int = 100 + private var currentMaxSize: Pair? = null + private var lastScreenSize: Pair? = null + private var guiName = "Custom Wardrobe" + + @SubscribeEvent + fun onGuiRender(event: GuiContainerEvent.BeforeDraw) { + if (!isEnabled() || editMode) return + val gui = event.gui + val renderable = displayRenderable ?: run { + update() + displayRenderable ?: return + } + + val screenSize = gui.width to gui.height + + if (screenSize != lastScreenSize) { + lastScreenSize = screenSize + val didUpdate = updateScreenSize(screenSize) + if (didUpdate) return + } + + val (width, height) = renderable.width to renderable.height + val pos = Position((gui.width - width) / 2, (gui.height - height) / 2) + if (waitingForInventoryUpdate && config.loadingText) { + val loadingRenderable = Renderable.string( + "§cLoading...", + scale = activeScale / 100.0 + ) + val loadingPos = + Position(pos.rawX + (width - loadingRenderable.width) / 2, pos.rawY - loadingRenderable.height) + loadingPos.renderRenderable(loadingRenderable, posLabel = guiName, addToGuiManager = false) + } + + GlStateManager.translate(0f, 0f, 100f) + pos.renderRenderable(renderable, posLabel = guiName, addToGuiManager = false) + GlStateManager.translate(0f, 0f, -100f) + event.cancel() + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!isEnabled()) return + if (!editMode) return + val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return + val renderable = inventoryButton ?: addReEnableButton().also { inventoryButton = it } + val accessorGui = gui as AccessorGuiContainer + val posX = accessorGui.guiLeft + (1.05 * accessorGui.width).toInt() + val posY = accessorGui.guiTop + (accessorGui.height - renderable.height) / 2 + Position(posX, posY).renderRenderable(renderable, posLabel = guiName, addToGuiManager = false) + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + waitingForInventoryUpdate = false + DelayedRun.runDelayed(500.milliseconds) { + if (!inWardrobe()) { + reset() + } + } + } + + @SubscribeEvent + fun onConfigUpdate(event: ConfigLoadEvent) { + with(config.spacing) { + ConditionalUtils.onToggle( + globalScale, outlineThickness, outlineBlur, + slotWidth, slotHeight, playerScale, + maxPlayersPerRow, horizontalSpacing, verticalSpacing, + buttonSlotsVerticalSpacing, buttonHorizontalSpacing, buttonVerticalSpacing, + buttonWidth, buttonHeight, backgroundPadding, + ) { + currentMaxSize = null + lastScreenSize = null + } + } + } + + @SubscribeEvent + fun onInventoryUpdate(event: InventoryUpdatedEvent) { + if (!isEnabled() || editMode) return + update() + } + + private fun update() { + displayRenderable = createRenderables() + } + + private fun updateScreenSize(gui: Pair): Boolean { + val renderable = currentMaxSize ?: run { + activeScale = config.spacing.globalScale.get() + update() + return true + } + val previousActiveScale = activeScale + val unscaledRenderableWidth = 100 * (renderable.first / activeScale.toDouble()) + val unscaledRenderableHeight = 100 * (renderable.second / activeScale.toDouble()) + val autoScaleWidth = 100 * ((gui.first * 0.9) / unscaledRenderableWidth) + val autoScaleHeight = 10_000 * ((gui.second * 0.9) / unscaledRenderableHeight) + val maxScale = min(autoScaleWidth, autoScaleHeight).toInt() + + activeScale = config.spacing.globalScale.get().coerceAtMost(maxScale) + return if (activeScale != previousActiveScale) { + update() + true + } else false + } + + private fun createRenderables(): Renderable { + var list = WardrobeAPI.wardrobeSlots + var wardrobeWarning: String? = null + + if (list.isEmpty()) wardrobeWarning = "§cYour wardrobe is empty :(" + + if (config.hideLockedSlots) { + list = list.filter { !it.locked } + if (list.isEmpty()) wardrobeWarning = "§cAll your slots are locked? Somehow" + } + + if (config.hideEmptySlots) { + list = list.filter { !it.isEmpty() } + if (list.isEmpty()) wardrobeWarning = "§cAll slots are empty :(" + } + if (config.onlyFavorites) { + list = list.filter { it.favorite || it.isCurrentSlot() } + if (list.isEmpty()) wardrobeWarning = "§cDidn't set any favorites" + } + + val maxPlayersPerRow = config.spacing.maxPlayersPerRow.get() + val maxPlayersRows = ((MAX_SLOT_PER_PAGE * MAX_PAGES - 1) / maxPlayersPerRow) + 1 + val containerWidth = (config.spacing.slotWidth.get() * (activeScale / 100.0)).toInt() + val containerHeight = (config.spacing.slotHeight.get() * (activeScale / 100.0)).toInt() + val playerWidth = (containerWidth * (config.spacing.playerScale.get() / 100.0)) + val horizontalSpacing = (config.spacing.horizontalSpacing.get() * (activeScale / 100.0)).toInt() + val verticalSpacing = (config.spacing.verticalSpacing.get() * (activeScale / 100.0)).toInt() + val backgroundPadding = (config.spacing.backgroundPadding.get() * (activeScale / 100.0)).toInt() + val buttonVerticalSpacing = (config.spacing.buttonVerticalSpacing.get() * (activeScale / 100.0)).toInt() + + var maxRenderableWidth = maxPlayersPerRow * containerWidth + (maxPlayersPerRow - 1) * horizontalSpacing + var maxRenderableHeight = maxPlayersRows * containerHeight + (maxPlayersRows - 1) * verticalSpacing + + val button = addButtons() + + if (button.width > maxRenderableWidth) maxRenderableWidth = button.width + maxRenderableHeight += button.height + buttonVerticalSpacing + + maxRenderableWidth += 2 * backgroundPadding + maxRenderableHeight += 2 * backgroundPadding + currentMaxSize = maxRenderableWidth to maxRenderableHeight + + wardrobeWarning?.let { text -> + val warningRenderable = Renderable.string( + text, + 3.0 * (activeScale / 100.0), + horizontalAlign = HorizontalAlignment.CENTER + ) + val withButtons = Renderable.verticalContainer( + listOf(warningRenderable, button), + buttonVerticalSpacing, + horizontalAlign = HorizontalAlignment.CENTER + ) + return addGuiBackground(withButtons, backgroundPadding) + } + + val chunkedList = list.chunked(maxPlayersPerRow) + + val rowsRenderables = chunkedList.map { row -> + val slotsRenderables = row.map { slot -> + var scale = playerWidth + val armorTooltipRenderable = { + val loreList = mutableListOf() + val height = containerHeight - 3 + + // This is needed to keep the background size the same as the player renderable size + val hoverableSizes = MutableList(4) { height / 4 }.apply { + for (k in 0 until height % 4) this[k]++ + } + + for (armorIndex in 0 until 4) { + val stack = slot.armor[armorIndex]?.copy() + if (stack == null) { + loreList.add(Renderable.placeholder(containerWidth, hoverableSizes[armorIndex])) + } else { + loreList.add( + Renderable.hoverable( + Renderable.hoverTips( + Renderable.placeholder(containerWidth, hoverableSizes[armorIndex]), + stack.getTooltip(Minecraft.getMinecraft().thePlayer, false) + ), + Renderable.placeholder(containerWidth, hoverableSizes[armorIndex]), + bypassChecks = true + ) + ) + } + } + Renderable.verticalContainer(loreList, spacing = 1) + } + + val playerBackground = createHoverableRenderable( + armorTooltipRenderable.invoke(), + topLayerRenderable = addSlotHoverableButtons(slot), + hoveredColor = slot.getSlotColor(), + borderOutlineThickness = config.spacing.outlineThickness.get(), + borderOutlineBlur = config.spacing.outlineBlur.get(), + onClick = { slot.clickSlot() } + ) + + val fakePlayer = getFakePlayer() + + fakePlayer.inventory.armorInventory = + slot.armor.map { it?.copy()?.removeEnchants() }.reversed().toTypedArray() + + val playerColor = if (!slot.isInCurrentPage()) { + scale *= 0.9 + Color.GRAY.withAlpha(100) + } else null + + val playerRenderable = Renderable.fakePlayer( + fakePlayer, + followMouse = config.eyesFollowMouse, + width = containerWidth, + height = containerHeight, + entityScale = scale.toInt(), + padding = 0, + color = playerColor, + ) + + Renderable.doubleLayered(playerBackground, playerRenderable, false) + } + Renderable.horizontalContainer(slotsRenderables, horizontalSpacing) + } + + val allSlotsRenderable = Renderable.verticalContainer( + rowsRenderables, + verticalSpacing, + horizontalAlign = HorizontalAlignment.CENTER + ) + + val withButtons = Renderable.verticalContainer( + listOf(allSlotsRenderable, button), + buttonVerticalSpacing, + horizontalAlign = HorizontalAlignment.CENTER + ) + + return addGuiBackground(withButtons, backgroundPadding) + } + + private fun addGuiBackground(renderable: Renderable, borderPadding: Int) = + Renderable.drawInsideRoundedRect( + Renderable.doubleLayered( + renderable, + Renderable.clickable( + Renderable.string( + "§7SkyHanni", + horizontalAlign = HorizontalAlignment.RIGHT, + verticalAlign = VerticalAlignment.BOTTOM, + scale = 1.0 * (activeScale / 100.0) + ).let { Renderable.hoverable(hovered = Renderable.underlined(it), unhovered = it) }, + onClick = { + config::enabled.jumpToEditor() + reset() + currentPage = null + } + ), + blockBottomHover = false + ), + config.color.backgroundColor.toChromaColor(), + padding = borderPadding + ) + + private fun reset() { + inCustomWardrobe = false + editMode = false + displayRenderable = null + inventoryButton = null + } + + private fun addButtons(): Renderable { + val (horizontalSpacing, verticalSpacing) = with(config.spacing) { + buttonHorizontalSpacing.get() * (activeScale / 100.0) to buttonVerticalSpacing.get() * (activeScale / 100.0) + } + + val backButton = createLabeledButton( + "§aBack", + onClick = { + clickSlot(48, getWindowId() ?: -1) + reset() + currentPage = null + } + ) + val exitButton = createLabeledButton( + "§cClose", + onClick = { + clickSlot(49, getWindowId() ?: -1) + reset() + currentPage = null + } + ) + + val greenColor = Color(85, 255, 85, 200) + val redColor = Color(255, 85, 85, 200) + + val onlyFavoriteButton = createLabeledButton( + "§eFavorite", + hoveredColor = if (config.onlyFavorites) greenColor else redColor, + onClick = { + config.onlyFavorites = !config.onlyFavorites + update() + } + ) + + val editButton = createLabeledButton( + "§bEdit", + onClick = { + DelayedRun.runNextTick { + reset() + editMode = true + } + } + ) + + val row = Renderable.horizontalContainer( + listOf(backButton, exitButton, onlyFavoriteButton), + horizontalSpacing.toInt(), + horizontalAlign = HorizontalAlignment.CENTER, + ) + + val total = Renderable.verticalContainer( + listOf(row, editButton), + verticalSpacing.toInt(), + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER + ) + + return total + } + + private fun addReEnableButton(): Renderable { + val color = Color(116, 150, 255, 200) + return createLabeledButton( + "§bEdit", + hoveredColor = color, + unhoveredColor = color.darker(0.8), + onClick = { + inCustomWardrobe = false + editMode = false + update() + } + ) + } + + private fun addSlotHoverableButtons(wardrobeSlot: WardrobeAPI.WardrobeSlot): Renderable { + val list = mutableListOf() + val textScale = 1.5 * (activeScale / 100.0) + list.add( + Renderable.clickable( + Renderable.hoverable( + Renderable.string( + (if (wardrobeSlot.favorite) "§c" else "§7") + "❤", + scale = textScale, + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER + ), + Renderable.string( + (if (wardrobeSlot.favorite) "§4" else "§8") + "❤", + scale = textScale, + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER + ) + ), + onClick = { + wardrobeSlot.favorite = !wardrobeSlot.favorite + update() + } + ) + ) + + if (config.estimatedValue && !wardrobeSlot.isEmpty()) { + val lore = createWardrobePriceLore(wardrobeSlot) + list.add( + Renderable.hoverTips( + Renderable.string( + "§2$", + scale = textScale, + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER + ), lore + ) + ) + } + + return Renderable.verticalContainer(list, 1, HorizontalAlignment.RIGHT) + } + + private fun createLabeledButton( + text: String, + hoveredColor: Color = Color(130, 130, 130, 200), + unhoveredColor: Color = hoveredColor.darker(0.57), + onClick: () -> Unit + ): Renderable { + val buttonWidth = (config.spacing.buttonWidth.get() * (activeScale / 100.0)).toInt() + val buttonHeight = (config.spacing.buttonHeight.get() * (activeScale / 100.0)).toInt() + val textScale = (activeScale / 100.0) + + val renderable = Renderable.hoverable( + Renderable.drawInsideRoundedRectWithOutline( + Renderable.doubleLayered( + Renderable.clickable( + Renderable.placeholder(buttonWidth, buttonHeight), + onClick + ), + Renderable.string( + text, + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER, + scale = textScale + ), + false, + ), + hoveredColor, + padding = 0, + topOutlineColor = config.color.topBorderColor.toChromaColorInt(), + bottomOutlineColor = config.color.bottomBorderColor.toChromaColorInt(), + borderOutlineThickness = 2, + horizontalAlign = HorizontalAlignment.CENTER + ), + Renderable.drawInsideRoundedRect( + Renderable.doubleLayered( + Renderable.placeholder(buttonWidth, buttonHeight), + Renderable.string( + text, + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER, + scale = textScale + ), + ), + unhoveredColor.darker(0.57), + padding = 0, + horizontalAlign = HorizontalAlignment.CENTER + ) + ) + + return renderable + } + + private fun createHoverableRenderable( + hoveredRenderable: Renderable, + unhoveredRenderable: Renderable = Renderable.placeholder(hoveredRenderable.width, hoveredRenderable.height), + topLayerRenderable: Renderable = Renderable.placeholder(0, 0), + padding: Int = 0, + horizontalAlignment: HorizontalAlignment = HorizontalAlignment.CENTER, + verticalAlignment: VerticalAlignment = VerticalAlignment.CENTER, + hoveredColor: Color, + unHoveredColor: Color = hoveredColor, + borderOutlineThickness: Int, + borderOutlineBlur: Float = 0.5f, + onClick: () -> Unit, + onHover: () -> Unit = {}, + ): Renderable = + Renderable.hoverable( + Renderable.drawInsideRoundedRectWithOutline( + Renderable.doubleLayered( + Renderable.clickable( + hoveredRenderable, + onClick + ), topLayerRenderable + ), + hoveredColor, + padding = padding, + topOutlineColor = config.color.topBorderColor.toChromaColorInt(), + bottomOutlineColor = config.color.bottomBorderColor.toChromaColorInt(), + borderOutlineThickness = borderOutlineThickness, + blur = borderOutlineBlur, + horizontalAlign = horizontalAlignment, + verticalAlign = verticalAlignment + ), + Renderable.drawInsideRoundedRect( + unhoveredRenderable, + unHoveredColor, + padding = padding, + horizontalAlign = horizontalAlignment, + verticalAlign = verticalAlignment + ), + onHover = { onHover() } + ) + + private fun WardrobeAPI.WardrobeSlot.clickSlot() { + val previousPageSlot = 45 + val nextPageSlot = 53 + val wardrobePage = currentPage ?: return + val windowId = getWindowId() ?: -1 + if (isInCurrentPage()) { + if (isEmpty() || locked || waitingForInventoryUpdate) return + currentWardrobeSlot = if (isCurrentSlot()) null + else id + clickSlot(inventorySlot, windowId) + } else { + if (page < wardrobePage) { + currentPage = wardrobePage - 1 + waitingForInventoryUpdate = true + clickSlot(previousPageSlot, windowId) + } else if (page > wardrobePage) { + currentPage = wardrobePage + 1 + waitingForInventoryUpdate = true + clickSlot(nextPageSlot, windowId) + } + } + update() + } + + private fun WardrobeAPI.WardrobeSlot.getSlotColor() = + with(config.color) { + when { + isCurrentSlot() -> equippedColor + favorite -> favoriteColor + else -> null + }?.toChromaColor()?.transformIf({ isInCurrentPage() }) { darker() } + ?: (if (!isInCurrentPage()) samePageColor else otherPageColor).toChromaColor() + .transformIf({ locked || isEmpty() }) { darker() }.addAlpha(100) + + } + + fun isEnabled() = LorenzUtils.inSkyBlock && inWardrobe() && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/EstimatedWardrobePrice.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/EstimatedWardrobePrice.kt new file mode 100644 index 000000000000..7c2610c83ce4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/EstimatedWardrobePrice.kt @@ -0,0 +1,39 @@ +package at.hannibal2.skyhanni.features.inventory.wardrobe + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class EstimatedWardrobePrice { + + private val config get() = SkyHanniMod.feature.inventory.estimatedItemValues + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.armor) return + if (!WardrobeAPI.inWardrobe()) return + if (WardrobeAPI.inCustomWardrobe) return + + val slot = WardrobeAPI.wardrobeSlots.firstOrNull { + event.slot.slotNumber == it.inventorySlot && it.isInCurrentPage() + } ?: return + + + val lore = WardrobeAPI.createWardrobePriceLore(slot) + if (lore.isEmpty()) return + + val tooltip = event.toolTip + var index = 3 + + tooltip.add(index++, "") + tooltip.addAll(index, lore) + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(3, "misc.estimatedIemValueArmor", "misc.estimatedItemValues.armor") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/WardrobeAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/WardrobeAPI.kt new file mode 100644 index 000000000000..070e343a4ff4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/WardrobeAPI.kt @@ -0,0 +1,253 @@ +package at.hannibal2.skyhanni.features.inventory.wardrobe + +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.DebugDataCollectEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValueCalculator +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import com.google.gson.annotations.Expose +import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.item.EnumDyeColor +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.milliseconds + +@SkyHanniModule +object WardrobeAPI { + + val storage get() = ProfileStorageData.profileSpecific?.wardrobe + + private val repoGroup = RepoPattern.group("inventory.wardrobe") + private val inventoryPattern by repoGroup.pattern( + "inventory.name", + "Wardrobe \\((?\\d+)/\\d+\\)" + ) + + /** + * REGEX-TEST: §7Slot 4: §aEquipped + */ + private val equippedSlotPattern by repoGroup.pattern( + "equippedslot", + "§7Slot \\d+: §aEquipped" + ) + + private const val FIRST_SLOT = 36 + private const val FIRST_HELMET_SLOT = 0 + private const val FIRST_CHESTPLATE_SLOT = 9 + private const val FIRST_LEGGINGS_SLOT = 18 + private const val FIRST_BOOTS_SLOT = 27 + const val MAX_SLOT_PER_PAGE = 9 + const val MAX_PAGES = 2 + + var wardrobeSlots = listOf() + var inCustomWardrobe = false + + class WardrobeSlot( + val id: Int, + val page: Int, + val inventorySlot: Int, + val helmetSlot: Int, + val chestplateSlot: Int, + val leggingsSlot: Int, + val bootsSlot: Int, + ) { + private fun getData() = storage?.wardrobeData?.getOrPut(id) { + WardrobeData( + id, + (1..4).associateWith { null }.toMutableMap(), + locked = true, + favorite = false, + ) + } + + var helmet: ItemStack? + get() = getData()?.armor?.get(1) + set(value) { + getData()?.armor?.set(1, value) + } + + var chestplate: ItemStack? + get() = getData()?.armor?.get(2) + set(value) { + getData()?.armor?.set(2, value) + } + + var leggings: ItemStack? + get() = getData()?.armor?.get(3) + set(value) { + getData()?.armor?.set(3, value) + } + + var boots: ItemStack? + get() = getData()?.armor?.get(4) + set(value) { + getData()?.armor?.set(4, value) + } + + var locked: Boolean + get() = getData()?.locked ?: true + set(value) { + getData()?.locked = value + } + + var favorite: Boolean + get() = getData()?.favorite ?: false + set(value) { + getData()?.favorite = value + } + + val armor get() = (1..4).associateWith { getData()?.armor?.get(it) }.toSortedMap().values.toList() + + fun isEmpty(): Boolean = armor.all { it == null } + + fun isCurrentSlot() = getData()?.id == currentWardrobeSlot + + fun isInCurrentPage() = (currentPage == null && page == 1) || (page == currentPage) + } + + + var currentWardrobeSlot: Int? + get() = storage?.currentWardrobeSlot + set(value) { + storage?.currentWardrobeSlot = value + } + + var currentPage: Int? = null + + init { + val list = mutableListOf() + var id = 0 + + for (page in 1..MAX_PAGES) { + for (slot in 0 until MAX_SLOT_PER_PAGE) { + val inventorySlot = FIRST_SLOT + slot + val helmetSlot = FIRST_HELMET_SLOT + slot + val chestplateSlot = FIRST_CHESTPLATE_SLOT + slot + val leggingsSlot = FIRST_LEGGINGS_SLOT + slot + val bootsSlot = FIRST_BOOTS_SLOT + slot + list.add(WardrobeSlot(++id, page, inventorySlot, helmetSlot, chestplateSlot, leggingsSlot, bootsSlot)) + } + } + wardrobeSlots = list + } + + private fun getWardrobeItem(itemStack: ItemStack?) = + if (itemStack?.item == ItemStack(Blocks.stained_glass_pane).item || itemStack == null) null else itemStack + + private fun getWardrobeSlotFromId(id: Int?) = wardrobeSlots.find { it.id == id } + + fun inWardrobe() = inventoryPattern.matches(InventoryUtils.openInventoryName()) + + fun createWardrobePriceLore(slot: WardrobeSlot) = buildList { + if (slot.isEmpty()) return@buildList + add("§aEstimated Armor Value:") + var totalPrice = 0.0 + slot.armor.forEach { + if (it != null) { + val price = EstimatedItemValueCalculator.getTotalPrice(it) + add(" §7- ${it.name}: §6${NumberUtil.format(price)}") + totalPrice += price + } + } + if (totalPrice != 0.0) add(" §aTotal Value: §6§l${NumberUtil.format(totalPrice)} coins") + } + + @SubscribeEvent + fun onInventoryUpdate(event: InventoryUpdatedEvent) { + if (!LorenzUtils.inSkyBlock) return + + inventoryPattern.matchMatcher(event.inventoryName) { + currentPage = group("currentPage").formatInt() + } ?: return + if (currentPage == null) return + + val itemsList = event.inventoryItems + + val allGrayDye = wardrobeSlots.all { + itemsList[it.inventorySlot]?.itemDamage == EnumDyeColor.GRAY.dyeDamage || !it.isInCurrentPage() + } + + if (allGrayDye) { + val allSlotsEmpty = wardrobeSlots.all { + (getWardrobeItem(itemsList[it.helmetSlot]) == null && getWardrobeItem(itemsList[it.chestplateSlot]) == null && + getWardrobeItem(itemsList[it.leggingsSlot]) == null && getWardrobeItem(itemsList[it.bootsSlot]) == null) || + !it.isInCurrentPage() + } + if (allSlotsEmpty) { + wardrobeSlots.filter { it.isInCurrentPage() }.forEach { + it.helmet = null + it.chestplate = null + it.leggings = null + it.boots = null + } + } else return + } + + var foundCurrentSlot = false + + for (slot in wardrobeSlots.filter { it.isInCurrentPage() }) { + slot.helmet = getWardrobeItem(itemsList[slot.helmetSlot]) + slot.chestplate = getWardrobeItem(itemsList[slot.chestplateSlot]) + slot.leggings = getWardrobeItem(itemsList[slot.leggingsSlot]) + slot.boots = getWardrobeItem(itemsList[slot.bootsSlot]) + if (equippedSlotPattern.matches(itemsList[slot.inventorySlot]?.name)) { + currentWardrobeSlot = slot.id + foundCurrentSlot = true + } + slot.locked = (itemsList[slot.inventorySlot] == ItemStack(Items.dye, EnumDyeColor.RED.dyeDamage)) + if (slot.locked) wardrobeSlots.forEach { if (it.id > slot.id) it.locked = true } + } + if (!foundCurrentSlot && getWardrobeSlotFromId(currentWardrobeSlot)?.page == currentPage) { + currentWardrobeSlot = null + } + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + DelayedRun.runDelayed(500.milliseconds) { + if (!inWardrobe()) currentPage = null + } + } + + @SubscribeEvent + fun onDebugCollect(event: DebugDataCollectEvent) { + event.title("Wardrobe") + event.addIrrelevant { + wardrobeSlots.forEach { slot -> + val slotInfo = buildString { + append("Slot ${slot.id}") + if (slot.favorite) append(" - Favorite: true") + } + if (slot.locked) { + add("$slotInfo is locked") + } else if (slot.isEmpty()) { + add("$slotInfo is empty") + } else { + add(slotInfo) + slot.helmet?.let { add(" Helmet: ${it.name}") } + slot.chestplate?.let { add(" Chestplate: ${it.name}") } + slot.leggings?.let { add(" Leggings: ${it.name}") } + slot.boots?.let { add(" Boots: ${it.name}") } + } + } + } + } + + class WardrobeData( + @Expose val id: Int, + @Expose var armor: MutableMap, + @Expose var locked: Boolean, + @Expose var favorite: Boolean, + ) +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt deleted file mode 100644 index 5e536ad015fe..000000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt +++ /dev/null @@ -1,74 +0,0 @@ -package at.hannibal2.skyhanni.features.misc.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent -import at.hannibal2.skyhanni.events.LorenzToolTipEvent -import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil -import net.minecraft.item.ItemStack -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -@SkyHanniModule -object EstimatedWardrobePrice { - - private val config get() = SkyHanniMod.feature.inventory.estimatedItemValues - var data = mutableMapOf>() - - @SubscribeEvent - fun onTooltip(event: LorenzToolTipEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.armor) return - if (!InventoryUtils.openInventoryName().contains("Wardrobe")) return - - val slot = event.slot.slotNumber - val id = slot % 9 - // Only showing in the armor select line - if (slot - id != 36) return - val items = data[id] ?: return - - var index = 3 - val toolTip = event.toolTip - if (toolTip.size < 4) return - toolTip.add(index++, "") - toolTip.add(index++, "§aEstimated Armor Value:") - - var totalPrice = 0.0 - for (item in items) { - - val price = EstimatedItemValueCalculator.getTotalPrice(item) - totalPrice += price - - toolTip.add(index++, " §7- ${item.name}: §6${NumberUtil.format(price)}") - } - toolTip.add(index, " §aTotal Value: §6§l${NumberUtil.format(totalPrice)} coins") - } - - @SubscribeEvent - fun onInventoryOpen(event: InventoryFullyOpenedEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.armor) return - if (!event.inventoryName.startsWith("Wardrobe")) return - - val map = mutableMapOf>() - - for ((slot, item) in event.inventoryItems) { - item.getInternalNameOrNull() ?: continue - val price = EstimatedItemValueCalculator.getTotalPrice(item) - if (price == 0.0) continue - val id = slot % 9 - val list = map.getOrPut(id) { mutableListOf() } - list.add(item) - } - data = map - } - - @SubscribeEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(3, "misc.estimatedIemValueArmor", "misc.estimatedItemValues.armor") - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt index 2572b969f2fd..041457d25735 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiContainerEvent.CloseWindowEvent import at.hannibal2.skyhanni.events.GuiContainerEvent.SlotClickEvent import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests +import at.hannibal2.skyhanni.utils.DelayedRun import io.github.moulberry.notenoughupdates.NEUApi import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.inventory.Slot @@ -40,7 +41,9 @@ class GuiContainerHook(guiAny: Any) { GuiData.preDrawEventCancelled = true ci.cancel() } else { - GuiData.preDrawEventCancelled = false + DelayedRun.runNextTick { + GuiData.preDrawEventCancelled = false + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java index 5d9d6146dfd3..8a4485694af4 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java @@ -20,4 +20,10 @@ public interface AccessorGuiContainer { @Invoker("drawGuiContainerBackgroundLayer") void invokeDrawGuiContainerBackgroundLayer_skyhanni(float f, int i, int mouseY); + + @Accessor("xSize") + int getWidth(); + + @Accessor("ySize") + int getHeight(); } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt index 00eb2e04642b..430310709c42 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt @@ -14,13 +14,16 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.block.state.IBlockState import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityOtherPlayerMP +import net.minecraft.client.resources.DefaultPlayerSkin import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraft.entity.monster.EntityEnderman import net.minecraft.entity.player.EntityPlayer +import net.minecraft.entity.player.EnumPlayerModelParts import net.minecraft.item.ItemStack import net.minecraft.potion.Potion +import net.minecraft.scoreboard.ScorePlayerTeam import net.minecraft.util.AxisAlignedBB import net.minecraftforge.client.event.RenderLivingEvent import net.minecraftforge.fml.common.eventhandler.Event @@ -190,6 +193,27 @@ object EntityUtils { fun EntityLivingBase.isRunicAndCorrupt() = baseMaxHealth == health.toInt().derpy() * 3 * 4 fun Entity.cleanName() = this.name.removeColor() + + /** + * @return a fake player with the same skin as the real player + */ + fun getFakePlayer(): EntityOtherPlayerMP { + val mc = Minecraft.getMinecraft() + return object : EntityOtherPlayerMP( + mc.theWorld, + mc.thePlayer.gameProfile + ) { + override fun getLocationSkin() = + mc.thePlayer.locationSkin ?: DefaultPlayerSkin.getDefaultSkin(mc.thePlayer.uniqueID) + + override fun getTeam() = object : ScorePlayerTeam(null, null) { + override fun getNameTagVisibility() = EnumVisible.NEVER + } + + override fun isWearing(part: EnumPlayerModelParts?) = + mc.thePlayer.isWearing(part) && part != EnumPlayerModelParts.CAPE + } + } } private fun Event.cancel() { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt index e3f06b83b241..a0e8cd5d54f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -36,6 +36,8 @@ object InventoryUtils { fun ContainerChest.getInventoryName() = this.lowerChestInventory.displayName.unformattedText.trim() + fun getWindowId() = (Minecraft.getMinecraft().currentScreen as? GuiChest)?.inventorySlots?.windowId + fun getItemsInOwnInventory() = getItemsInOwnInventoryWithNull()?.filterNotNull() ?: emptyList() @@ -112,4 +114,10 @@ object InventoryUtils { } fun NEUInternalName.getAmountInInventory(): Int = countItemsInLowerInventory { it.getInternalNameOrNull() == this } + + fun clickSlot(slot: Int, windowId: Int) { + if (windowId == -1) return + val mc = Minecraft.getMinecraft() + mc.playerController.windowClick(windowId, slot, 0, 0, mc.thePlayer) + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index d093dcfaf1ab..6af19e382e11 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -123,6 +123,13 @@ object ItemUtils { // Checks for hypixel enchantments in the attributes fun ItemStack.hasEnchantments() = getEnchantments()?.isNotEmpty() ?: false + fun ItemStack.removeEnchants(): ItemStack = apply { + val tag = tagCompound ?: NBTTagCompound() + tag.removeTag("ench") + tag.removeTag("StoredEnchantments") + tagCompound = tag + } + fun ItemStack.getSkullTexture(): String? { if (item != Items.skull) return null if (tagCompound == null) return null diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 40e8ddab95db..1506882cd40d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -559,6 +559,7 @@ object RenderUtils { renderables: List, extraSpace: Int = 0, posLabel: String, + addToGuiManager: Boolean = true, ) { if (renderables.isEmpty()) return var longestY = 0 @@ -575,7 +576,21 @@ object RenderUtils { GlStateManager.popMatrix() } - GuiEditManager.add(this, posLabel, longestX, longestY) + if (addToGuiManager) GuiEditManager.add(this, posLabel, longestX, longestY) + } + + fun Position.renderRenderable( + renderable: Renderable, + posLabel: String, + addToGuiManager: Boolean = true, + ) { + GlStateManager.pushMatrix() + val (x, y) = transform() + Renderable.withMousePosition(x, y) { + renderable.render(0, 0) + } + GlStateManager.popMatrix() + if (addToGuiManager) GuiEditManager.add(this, posLabel, renderable.width, 0) } /** diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index 0d830e5c1788..cf6a3f181e70 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -8,8 +8,10 @@ import at.hannibal2.skyhanni.data.ToolTipData import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager import at.hannibal2.skyhanni.features.chroma.ChromaType import at.hannibal2.skyhanni.features.misc.DarkenShader +import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper import at.hannibal2.skyhanni.utils.CollectionUtils.contains import at.hannibal2.skyhanni.utils.ColorUtils +import at.hannibal2.skyhanni.utils.ColorUtils.addAlpha import at.hannibal2.skyhanni.utils.ColorUtils.darker import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked import at.hannibal2.skyhanni.utils.LorenzColor @@ -31,7 +33,9 @@ import net.minecraft.client.Minecraft import net.minecraft.client.gui.Gui import net.minecraft.client.gui.GuiIngameMenu import net.minecraft.client.gui.inventory.GuiEditSign +import net.minecraft.client.gui.inventory.GuiInventory.drawEntityOnScreen import net.minecraft.client.renderer.GlStateManager +import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.util.ResourceLocation import java.awt.Color @@ -292,10 +296,10 @@ interface Renderable { bypassChecks: Boolean = false, condition: () -> Boolean = { true }, highlightsOnHoverSlots: List = emptyList(), + onHover: () -> Unit = {}, ) = object : Renderable { - override val width: Int - get() = max(hovered.width, unhovered.width) - override val height = 10 + override val width = max(hovered.width, unhovered.width) + override val height = max(hovered.height, unhovered.height) override val horizontalAlign get() = if (isHovered) hovered.horizontalAlign else unhovered.horizontalAlign override val verticalAlign get() = if (isHovered) hovered.verticalAlign else unhovered.verticalAlign @@ -304,6 +308,7 @@ interface Renderable { override fun render(posX: Int, posY: Int) { val pair = Pair(posX, posY) isHovered = if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) { + onHover() hovered.render(posX, posY) HighlightOnHoverSlot.currentSlots[pair] = highlightsOnHoverSlots true @@ -315,6 +320,29 @@ interface Renderable { } } + /** Bottom Layer must be bigger then the top layer */ + fun doubleLayered( + bottomLayer: Renderable, + topLayer: Renderable, + blockBottomHover: Boolean = true, + ) = object : Renderable { + override val width = bottomLayer.width + override val height = bottomLayer.height + override val horizontalAlign = bottomLayer.horizontalAlign + override val verticalAlign = bottomLayer.verticalAlign + + override fun render(posX: Int, posY: Int) { + val (x, y) = topLayer.renderXYAligned(posX, posY, width, height) + val (posX, posY) = if (topLayer.isHovered(posX + x, posY + y) && blockBottomHover) { + bottomLayer.width + 1 to bottomLayer.height + 1 + } else { + posX to posY + } + bottomLayer.render(posX, posY) + } + + } + fun itemStackWithTip( item: ItemStack, scale: Double = NEUItems.itemFontSize, @@ -562,7 +590,7 @@ interface Renderable { } // TODO use this to render current boosted crop in next jacob contest crops - fun Renderable.renderBounds(color: Color = LorenzColor.GREEN.toColor()) = object : Renderable { + fun Renderable.renderBounds(color: Color = LorenzColor.GREEN.toColor().addAlpha(100)) = object : Renderable { override val width = this@renderBounds.width override val height = this@renderBounds.height override val horizontalAlign = this@renderBounds.horizontalAlign @@ -846,5 +874,85 @@ interface Renderable { GlStateManager.translate(-padding.toFloat(), -padding.toFloat(), 0f) } } + + fun drawInsideRoundedRectWithOutline( + input: Renderable, + color: Color, + padding: Int = 2, + radius: Int = 10, + smoothness: Int = 2, + topOutlineColor: Int, + bottomOutlineColor: Int, + borderOutlineThickness: Int, + blur: Float = 0.7f, + horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT, + verticalAlign: VerticalAlignment = VerticalAlignment.TOP, + ) = object : Renderable { + override val width = input.width + padding * 2 + override val height = input.height + padding * 2 + override val horizontalAlign = horizontalAlign + override val verticalAlign = verticalAlign + + override fun render(posX: Int, posY: Int) { + RenderUtils.drawRoundRect(0, 0, width, height, color.rgb, radius, smoothness) + RenderUtils.drawRoundRectOutline( + 0, + 0, + width, + height, + topOutlineColor, + bottomOutlineColor, + borderOutlineThickness, + radius, + blur + ) + + GlStateManager.translate(padding.toFloat(), padding.toFloat(), 0f) + input.render(posX + padding, posY + padding) + GlStateManager.translate(-padding.toFloat(), -padding.toFloat(), 0f) + } + } + + fun fakePlayer( + player: EntityPlayer, + followMouse: Boolean = false, + eyesX: Float = 0f, + eyesY: Float = 0f, + width: Int = 50, + height: Int = 100, + entityScale: Int = 30, + padding: Int = 5, + color: Int? = null, + colorCondition: () -> Boolean = { true }, + ) = object : Renderable { + override val width = width + 2 * padding + override val height = height + 2 * padding + override val horizontalAlign = HorizontalAlignment.LEFT + override val verticalAlign = VerticalAlignment.TOP + val playerWidth = entityScale + val playerHeight = entityScale * 2 + val playerX = width / 2 + padding + val playerY = height / 2 + playerHeight / 2 + padding + + override fun render(posX: Int, posY: Int) { + GlStateManager.color(1f, 1f, 1f, 1f) + if (color != null) RenderLivingEntityHelper.setEntityColor(player, color, colorCondition) + val mouse = currentRenderPassMousePosition ?: return + val mouseXRelativeToPlayer = + if (followMouse) (posX + playerX - mouse.first).toFloat() else eyesX + val mouseYRelativeToPlayer = + if (followMouse) (posY + playerY - mouse.second - 1.62 * entityScale).toFloat() else eyesY + GlStateManager.translate(0f, 0f, 100f) + drawEntityOnScreen( + playerX, + playerY, + entityScale, + mouseXRelativeToPlayer, + mouseYRelativeToPlayer, + player + ) + GlStateManager.translate(0f, 0f, -100f) + } + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt index cf81fc9ff8bd..d1a8aae02b1d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt @@ -48,25 +48,28 @@ internal object RenderableUtils { else -> 0 } - fun Renderable.renderXYAligned(posX: Int, posY: Int, xSpace: Int, ySpace: Int) { + fun Renderable.renderXYAligned(posX: Int, posY: Int, xSpace: Int, ySpace: Int): Pair { val xOffset = calculateAlignmentXOffset(this, xSpace) val yOffset = calculateAlignmentYOffset(this, ySpace) GlStateManager.translate(xOffset.toFloat(), yOffset.toFloat(), 0f) this.render(posX + xOffset, posY + yOffset) GlStateManager.translate(-xOffset.toFloat(), -yOffset.toFloat(), 0f) + return xOffset to yOffset } - fun Renderable.renderXAligned(posX: Int, posY: Int, xSpace: Int) { + fun Renderable.renderXAligned(posX: Int, posY: Int, xSpace: Int): Int { val xOffset = calculateAlignmentXOffset(this, xSpace) GlStateManager.translate(xOffset.toFloat(), 0f, 0f) this.render(posX + xOffset, posY) GlStateManager.translate(-xOffset.toFloat(), 0f, 0f) + return xOffset } - fun Renderable.renderYAligned(posX: Int, posY: Int, ySpace: Int) { + fun Renderable.renderYAligned(posX: Int, posY: Int, ySpace: Int): Int { val yOffset = calculateAlignmentYOffset(this, ySpace) GlStateManager.translate(0f, yOffset.toFloat(), 0f) this.render(posX, posY + yOffset) GlStateManager.translate(0f, -yOffset.toFloat(), 0f) + return yOffset } }