From 2b5755dc1e3a1d9a93005e28421feb457415c0bb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 22 Apr 2023 22:50:49 +0200 Subject: Pupup Warning for Next Jacob's Contest - Opens a popup when the warning time is reached and minecraft is not in focus (default disabled) --- .../features/garden/GardenNextJacobContest.kt | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index 1037d0bb3..7b9e52d14 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -10,11 +10,20 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils import io.github.moulberry.notenoughupdates.util.SkyBlockTime +import kotlinx.coroutines.launch import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent +import org.lwjgl.opengl.Display +import java.awt.event.MouseAdapter +import java.awt.event.MouseEvent import java.time.Instant +import javax.swing.JButton +import javax.swing.JFrame +import javax.swing.JOptionPane +import javax.swing.UIManager class GardenNextJacobContest { private var display = listOf() @@ -215,6 +224,53 @@ class GardenNextJacobContest { LorenzUtils.chat("§e[SkyHanni] Next farming contest: $cropText") TitleUtils.sendTitle("§eFarming Contest!", 5_000) SoundUtils.playBeepSound() + + if (config.nextJacobContestWarnPopup && !Display.isActive()) { + SkyHanniMod.coroutineScope.launch { + openPopupWindow( + "Farming Contest soon!\n" + + "Crops: ${cropText.removeColor()}" + ) + } + } + } + + /** + * Taken and modified from Skytils + */ + private fun openPopupWindow(message: String) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + + val frame = JFrame() + frame.isUndecorated = true + frame.isAlwaysOnTop = true + frame.setLocationRelativeTo(null) + frame.isVisible = true + + val buttons = mutableListOf() + val close = JButton("Ok") + close.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(event: MouseEvent) { + frame.isVisible = false + } + }) + buttons.add(close) + + val allOptions = buttons.toTypedArray() + JOptionPane.showOptionDialog( + frame, + message, + "SkyHanni Jacob Contest Notification", + JOptionPane.DEFAULT_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + allOptions, + allOptions[0] + ) } @SubscribeEvent -- cgit