aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Features.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt45
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt14
8 files changed, 82 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 71cde563c..8926c31c8 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -6,10 +6,7 @@ import at.hannibal2.skyhanni.config.commands.Commands;
import at.hannibal2.skyhanni.data.*;
import at.hannibal2.skyhanni.data.repo.RepoManager;
import at.hannibal2.skyhanni.features.anvil.AnvilCombineHelper;
-import at.hannibal2.skyhanni.features.bazaar.BazaarApi;
-import at.hannibal2.skyhanni.features.bazaar.BazaarBestSellMethod;
-import at.hannibal2.skyhanni.features.bazaar.BazaarCancelledBuyOrderClipboard;
-import at.hannibal2.skyhanni.features.bazaar.BazaarOrderHelper;
+import at.hannibal2.skyhanni.features.bazaar.*;
import at.hannibal2.skyhanni.features.bingo.CompactBingoChat;
import at.hannibal2.skyhanni.features.chat.ChatFilter;
import at.hannibal2.skyhanni.features.chat.PlayerDeathMessages;
@@ -172,6 +169,7 @@ public class SkyHanniMod {
loadModule(new CroesusUnopenedChestTracker());
loadModule(new CompactBingoChat());
loadModule(new BrewingStandOverlay());
+ loadModule(new BazaarUpdateTimer());
Commands.INSTANCE.init();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java
index 39d20d74b..0f3b52c2a 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Features.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java
@@ -106,6 +106,11 @@ public class Features extends Config {
editOverlay(activeConfigCategory, 200, 16, misc.nonGodPotEffectPos);
return;
}
+
+ if (runnableId.equals("bazzarUpdateTimer")) {
+ editOverlay(activeConfigCategory, 200, 16, bazaar.updateTimerPos);
+ return;
+ }
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java b/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java
index 890d21313..2e3ea2195 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java
@@ -27,4 +27,14 @@ public class Bazaar {
@ConfigOption(name = "Cancelled Buy Order Clipboard", desc = "Saves missing items from cancelled buy orders to clipboard for faster re-entry.")
@ConfigEditorBoolean
public boolean cancelledBuyOrderClipboard = true;
+
+ @Expose
+ @ConfigOption(name = "Update Timer", desc = "A countdown timer for upcoming Bazzar data update.")
+ @ConfigEditorBoolean
+ public boolean updateTimer = false;
+
+ @Expose
+ @ConfigOption(name = "Update timer Position", desc = "")
+ @ConfigEditorButton(runnableId = "bazzarUpdateTimer", buttonText = "Edit")
+ public Position updateTimerPos = new Position(10, 10, false, true);
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt
new file mode 100644
index 000000000..4d415d920
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.events
+
+import at.hannibal2.skyhanni.features.bazaar.BazaarData
+
+class BazaarUpdateEvent(val bazaarMap: MutableMap<String, BazaarData>): LorenzEvent() \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
index b43cb1eb3..b4f00f248 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
@@ -1,3 +1,3 @@
package at.hannibal2.skyhanni.features.bazaar
-data class BazaarData(val apiName: String, val itemName: String, val sellPrice: Double, val buyPrice: Double) \ No newline at end of file
+data class BazaarData(val apiName: String, val itemName: String, val sellPrice: Double, val buyPrice: Double, val buyMovingWeek: Int, val sellMovingWeek: Int) \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
index bcf1b3e48..c2f5fb5a7 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.features.bazaar
+import at.hannibal2.skyhanni.events.BazaarUpdateEvent
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
@@ -97,6 +98,8 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa
continue
}
+ val sellMovingWeek = itemData["quick_status"].asJsonObject["sellMovingWeek"].asInt
+ val buyMovingWeek = itemData["quick_status"].asJsonObject["buyMovingWeek"].asInt
//parse bazaar api format into internal name format
if (apiName.startsWith("ENCHANTMENT_")) {
val split = apiName.split("_")
@@ -106,9 +109,10 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa
apiName = text
}
- val data = BazaarData(apiName, itemName, sellPrice, buyPrice)
+ val data = BazaarData(apiName, itemName, sellPrice, buyPrice, buyMovingWeek, sellMovingWeek)
bazaarMap[itemName] = data
}
+ BazaarUpdateEvent(bazaarMap).postAndCatch()
}
private fun getItemName(apiName: String): String? {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt
new file mode 100644
index 000000000..0a99f942a
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt
@@ -0,0 +1,45 @@
+package at.hannibal2.skyhanni.features.bazaar
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.BazaarUpdateEvent
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import net.minecraftforge.client.event.GuiScreenEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.text.DecimalFormat
+
+class BazaarUpdateTimer {
+ private var lastBazaarUpdateTime = 0L
+
+ @SubscribeEvent
+ fun onBazaarUpdate(event: BazaarUpdateEvent) {
+ if (!isEnabled()) return
+ lastBazaarUpdateTime = System.currentTimeMillis()
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) {
+ if (!isEnabled()) return
+ if (!BazaarApi.isBazaarInventory(InventoryUtils.openInventoryName())) return
+
+ val duration = System.currentTimeMillis() - lastBazaarUpdateTime
+ val durationSeconds = duration.toDouble() / 1000
+ val nextUpdateIn = 10 - durationSeconds
+ val format = if (nextUpdateIn < 0) {
+ "Updating"
+ } else {
+ DecimalFormat("0.0").format(nextUpdateIn)
+ }
+
+ val list = mutableListOf<String>()
+ list.add("Next update in:")
+ list.add(format)
+ SkyHanniMod.feature.bazaar.updateTimerPos.renderStrings(list, center = true)
+ }
+
+ private fun isEnabled(): Boolean {
+ return LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.updateTimer
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index ff28c52ab..e3052874f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -424,7 +424,7 @@ object RenderUtils {
return lastValue + (currentValue - lastValue) * multiplier
}
- fun Position.renderString(string: String?, offsetY: Int = 0) {
+ fun Position.renderString(string: String?, offsetY: Int = 0, center: Boolean = true) {
val minecraft = Minecraft.getMinecraft()
if (minecraft.gameSettings.keyBindPlayerList.isKeyDown) return
@@ -437,7 +437,11 @@ object RenderUtils {
val renderer = minecraft.renderManager.fontRenderer ?: return
- val offsetX = (200 - renderer.getStringWidth(display.removeColor())) / 2
+ val offsetX = if (center) {
+ (200 - renderer.getStringWidth(display.removeColor())) / 2
+ } else {
+ 0
+ }
val x = getAbsX(resolution, 200) + offsetX
val y = getAbsY(resolution, 16) + offsetY
@@ -448,13 +452,13 @@ object RenderUtils {
GlStateManager.popMatrix()
}
- fun Position.renderStrings(list: List<String>) {
+ fun Position.renderStrings(list: List<String>, extraSpace: Int = 0, center: Boolean = false) {
if (list.isEmpty()) return
var offsetY = 0
for (s in list) {
- renderString(s, offsetY)
- offsetY += 14
+ renderString(s, offsetY, center = center)
+ offsetY += 10 + extraSpace
}
}