diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java (renamed from src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/NeedsConfig.java) | 10 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt | 90 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt | 2 |
5 files changed, 56 insertions, 52 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index f98373ea3..e73f63813 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 17 + const val CONFIG_VERSION = 18 fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/NeedsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java index 002b44a16..cbfa9e451 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/NeedsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java @@ -6,18 +6,20 @@ import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; import io.github.moulberry.moulconfig.annotations.ConfigOption; -public class NeedsConfig { +public class ShoppingListConfig { @Expose - @ConfigOption(name = "Items Needed", desc = "Show all items needed for the visitors.") + @ConfigOption(name = "Enable", desc = "Show all items required for the visitors.") @ConfigEditorBoolean @FeatureToggle + // TODO rename "enabled" public boolean display = true; @Expose + // TODO renmae "postion" public Position pos = new Position(180, 170, false, true); @Expose - @ConfigOption(name = "Only when Close", desc = "Only show the needed items when close to the visitors.") + @ConfigOption(name = "Only when Close", desc = "Only show the shopping list when close to the visitors.") @ConfigEditorBoolean public boolean onlyWhenClose = false; @@ -28,7 +30,7 @@ public class NeedsConfig { public boolean inBazaarAlley = true; @Expose - @ConfigOption(name = "Show Price", desc = "Show the coin price in the items needed list.") + @ConfigOption(name = "Show Price", desc = "Show the coin price in the shopping list.") @ConfigEditorBoolean public boolean showPrice = true; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java index 7aca44b89..654dcf511 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java @@ -17,9 +17,9 @@ public class VisitorConfig { public TimerConfig timer = new TimerConfig(); @Expose - @ConfigOption(name = "Visitor Items Needed", desc = "") + @ConfigOption(name = "Visitor Shopping List", desc = "") @Accordion - public NeedsConfig needs = new NeedsConfig(); + public ShoppingListConfig shoppingList = new ShoppingListConfig(); @Expose @ConfigOption(name = "Visitor Inventory", desc = "") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 4bcd4a079..147189257 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -95,7 +95,7 @@ class GardenVisitorFeatures { val pair = ItemUtils.readItemAmount(line) if (pair == null) { ErrorManager.logErrorStateWithData( - "Could not read items required in Visitor Inventory", "ItemUtils.readItemAmount returns null", + "Could not read Shopping List in Visitor Inventory", "ItemUtils.readItemAmount returns null", "line" to line, "offerItem" to offerItem, "lore" to lore, @@ -105,7 +105,7 @@ class GardenVisitorFeatures { } val (itemName, amount) = pair val internalName = NEUInternalName.fromItemName(itemName) - visitor.items[internalName] = amount + visitor.shoppingList[internalName] = amount } readToolTip(visitor, offerItem) @@ -128,36 +128,36 @@ class GardenVisitorFeatures { } private fun drawDisplay() = buildList { - if (!config.needs.display) return@buildList - val (requiredItems, newVisitors) = prepareDrawingData() + if (!config.shoppingList.display) return@buildList + val (shoppingList, newVisitors) = prepareDrawingData() - drawRequiredItems(requiredItems) - drawVisitors(newVisitors, requiredItems) + drawShoppingList(shoppingList) + drawVisitors(newVisitors, shoppingList) } private fun prepareDrawingData(): Pair<MutableMap<NEUInternalName, Int>, MutableList<String>> { - val requiredItems = mutableMapOf<NEUInternalName, Int>() + val globalShoppingList = mutableMapOf<NEUInternalName, Int>() val newVisitors = mutableListOf<String>() for ((visitorName, visitor) in VisitorAPI.getVisitorsMap()) { if (visitor.status == VisitorAPI.VisitorStatus.ACCEPTED || visitor.status == VisitorAPI.VisitorStatus.REFUSED) continue - val items = visitor.items - if (items.isEmpty()) { + val shoppingList = visitor.shoppingList + if (shoppingList.isEmpty()) { newVisitors.add(visitorName) } - for ((internalName, amount) in items) { - val old = requiredItems.getOrDefault(internalName, 0) - requiredItems[internalName] = old + amount + for ((internalName, amount) in shoppingList) { + val old = globalShoppingList.getOrDefault(internalName, 0) + globalShoppingList[internalName] = old + amount } } - return requiredItems to newVisitors + return globalShoppingList to newVisitors } - private fun MutableList<List<Any>>.drawRequiredItems(requiredItems: MutableMap<NEUInternalName, Int>) { - if (requiredItems.isNotEmpty()) { + private fun MutableList<List<Any>>.drawShoppingList(shoppingList: MutableMap<NEUInternalName, Int>) { + if (shoppingList.isNotEmpty()) { var totalPrice = 0.0 - addAsSingletonList("§7Visitor items needed:") - for ((internalName, amount) in requiredItems) { + addAsSingletonList("§7Visitor Shopping List:") + for ((internalName, amount) in shoppingList) { val name = internalName.getItemName() val itemStack = internalName.getItemStack() @@ -173,14 +173,14 @@ class GardenVisitorFeatures { } }) { GardenAPI.inGarden() && !NEUItems.neuHasFocus() }) - if (config.needs.showPrice) { + if (config.shoppingList.showPrice) { val price = internalName.getPrice() * amount totalPrice += price val format = NumberUtil.format(price) list.add(" §7(§6$format§7)") } - if (config.needs.showSackCount) { + if (config.shoppingList.showSackCount) { val sackItemData = SackAPI.fetchSackItem(internalName) val itemStatus = sackItemData.getStatus() val itemAmount = sackItemData.amount @@ -196,17 +196,17 @@ class GardenVisitorFeatures { } if (totalPrice > 0) { val format = NumberUtil.format(totalPrice) - this[0] = listOf("§7Visitor items needed: §7(§6$format§7)") + this[0] = listOf("§7Visitor Shopping List: §7(§6$format§7)") } } } private fun MutableList<List<Any>>.drawVisitors( newVisitors: MutableList<String>, - requiredItems: MutableMap<NEUInternalName, Int> + shoppingList: MutableMap<NEUInternalName, Int> ) { if (newVisitors.isNotEmpty()) { - if (requiredItems.isNotEmpty()) { + if (shoppingList.isNotEmpty()) { addAsSingletonList("") } val amount = newVisitors.size @@ -218,7 +218,7 @@ class GardenVisitorFeatures { val list = mutableListOf<Any>() list.add(" §7- $displayName") - if (config.needs.itemPreview) { + if (config.shoppingList.itemPreview) { val items = GardenVisitorColorNames.visitorItems[visitor.removeColor()] if (items == null) { val text = "Visitor '$visitor' has no items in repo!" @@ -307,14 +307,14 @@ class GardenVisitorFeatures { private fun readToolTip(visitor: VisitorAPI.Visitor, itemStack: ItemStack?) { val stack = itemStack ?: error("Accept offer item not found for visitor ${visitor.visitorName}") var totalPrice = 0.0 - var timeRequired = -1L - var readingItemsNeeded = true + var farmingTimeRequired = -1L + var readingShoppingList = true lastFullPrice = 0.0 val foundRewards = mutableListOf<NEUInternalName>() for (formattedLine in stack.getLore()) { if (formattedLine.contains("Rewards")) { - readingItemsNeeded = false + readingShoppingList = false } val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue @@ -324,7 +324,7 @@ class GardenVisitorFeatures { if (internalName.startsWith("SKYBLOCK_")) continue val price = internalName.getPrice() * amount - if (readingItemsNeeded) { + if (readingShoppingList) { totalPrice += price lastFullPrice += price } else { @@ -348,7 +348,7 @@ class GardenVisitorFeatures { } } - readingItemsNeeded = true + readingShoppingList = true val finalList = stack.getLore().toMutableList() var offset = 0 for ((i, formattedLine) in finalList.toMutableList().withIndex()) { @@ -364,17 +364,17 @@ class GardenVisitorFeatures { copperPattern.matchMatcher(formattedLine) { val copper = group("amount").replace(",", "").toInt() val pricePerCopper = NumberUtil.format((totalPrice / copper).toInt()) - val timePerCopper = TimeUtils.formatDuration((timeRequired / copper) * 1000) + val timePerCopper = TimeUtils.formatDuration((farmingTimeRequired / copper) * 1000) var copperLine = formattedLine if (config.inventory.copperPrice) copperLine += " §7(§6$pricePerCopper §7per)" if (config.inventory.copperTime) { - copperLine += if (timeRequired != -1L) " §7(§b$timePerCopper §7per)" else " §7(§cno speed data!§7)" + copperLine += if (farmingTimeRequired != -1L) " §7(§b$timePerCopper §7per)" else " §7(§cno speed data!§7)" } finalList.set(index, copperLine) } if (formattedLine.contains("Rewards")) { - readingItemsNeeded = false + readingShoppingList = false } val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue @@ -388,7 +388,7 @@ class GardenVisitorFeatures { val format = NumberUtil.format(price) finalList[index] = "$formattedLine §7(§6$format§7)" } - if (!readingItemsNeeded) continue + if (!readingShoppingList) continue val multiplier = NEUItems.getMultiplier(internalName) val rawName = multiplier.first.getItemNameOrNull()?.removeColor() ?: continue @@ -398,8 +398,8 @@ class GardenVisitorFeatures { val formattedAmount = LorenzUtils.formatInteger(cropAmount) val formattedName = "§e$formattedAmount§7x ${cropType.cropName} " val formattedSpeed = cropType.getSpeed()?.let { speed -> - timeRequired = cropAmount / speed - val duration = TimeUtils.formatDuration(timeRequired * 1000) + farmingTimeRequired = cropAmount / speed + val duration = TimeUtils.formatDuration(farmingTimeRequired * 1000) "in §b$duration" } ?: "§cno speed data!" if (config.inventory.exactAmountAndTime) { @@ -413,7 +413,7 @@ class GardenVisitorFeatures { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!GardenAPI.inGarden()) return - if (!config.needs.display && config.highlightStatus == HighlightMode.DISABLED) return + if (!config.shoppingList.display && config.highlightStatus == HighlightMode.DISABLED) return if (!event.isMod(10)) return if (GardenAPI.onBarnPlot && config.highlightStatus != HighlightMode.DISABLED) { @@ -547,9 +547,9 @@ class GardenVisitorFeatures { private fun hasItemsInInventory(visitor: VisitorAPI.Visitor): Boolean { var ready = true - for ((internalName, need) in visitor.items) { + for ((internalName, required) in visitor.shoppingList) { val having = InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName } - if (having < need) { + if (having < required) { ready = false } } @@ -559,14 +559,14 @@ class GardenVisitorFeatures { @SubscribeEvent fun onRenderInSigns(event: DrawScreenEvent.Post) { if (!GardenAPI.inGarden()) return - if (!config.needs.display) return + if (!config.shoppingList.display) return val gui = event.gui if (gui !is GuiEditSign) return - if (config.needs.onlyWhenClose && !GardenAPI.onBarnPlot) return + if (config.shoppingList.onlyWhenClose && !GardenAPI.onBarnPlot) return if (!hideExtraGuis()) { - config.needs.pos.renderStringsAndItems(display, posLabel = "Visitor Items Needed") + config.shoppingList.pos.renderStringsAndItems(display, posLabel = "Visitor Shopping List") } } @@ -574,22 +574,22 @@ class GardenVisitorFeatures { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent) { - if (!config.needs.display) return + if (!config.shoppingList.display) return if (showGui()) { - config.needs.pos.renderStringsAndItems(display, posLabel = "Visitor Items Needed") + config.shoppingList.pos.renderStringsAndItems(display, posLabel = "Visitor Shopping List") } } private fun showGui(): Boolean { - if (config.needs.inBazaarAlley && IslandType.HUB.isInIsland() && LorenzUtils.skyBlockArea == "Bazaar Alley") { + if (config.shoppingList.inBazaarAlley && IslandType.HUB.isInIsland() && LorenzUtils.skyBlockArea == "Bazaar Alley") { return true } if (hideExtraGuis()) return false if (GardenAPI.inGarden()) { if (GardenAPI.onBarnPlot) return true - if (!config.needs.onlyWhenClose) return true + if (!config.shoppingList.onlyWhenClose) return true } return false } @@ -655,6 +655,8 @@ class GardenVisitorFeatures { event.transform(15, "garden.visitors.highlightStatus") { element -> ConfigUtils.migrateIntToEnum(element, HighlightMode::class.java) } + + event.move(18, "garden.visitors.needs", "garden.visitors.shoppingList") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt index a74793fbe..c3c832d78 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt @@ -108,7 +108,7 @@ object VisitorAPI { var nameTagEntityId: Int = -1, var status: VisitorStatus, var inSacks: Boolean = false, - val items: MutableMap<NEUInternalName, Int> = mutableMapOf(), + val shoppingList: MutableMap<NEUInternalName, Int> = mutableMapOf(), var offer: VisitorOffer? = null, ) { var lore: List<String> = emptyList() |