Skip to content

Commit

Permalink
oneconfig beta 1
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDiamondPro committed Feb 1, 2023
1 parent 9bcc8d1 commit 1c2ce59
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 76 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_name = SkyGuide
mod_id = skyguide
mod_version = 1.2.1
mod_version = 1.2.1+oneconfig-beta1

essential.defaults.loom=0

Expand Down
74 changes: 44 additions & 30 deletions src/main/kotlin/dev/dediamondpro/skyguide/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import cc.polyfrost.oneconfig.config.core.OneKeyBind
import cc.polyfrost.oneconfig.config.data.Mod
import cc.polyfrost.oneconfig.config.data.ModType
import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator
import cc.polyfrost.oneconfig.config.migration.VigilanceName
import cc.polyfrost.oneconfig.libs.universal.UKeyboard
import dev.dediamondpro.skyguide.gui.MapGui
import dev.dediamondpro.skyguide.handlers.AssetHandler
Expand All @@ -37,26 +38,29 @@ object Config : Config(
var textureQuality = 1

@Switch(
name = "Keep In Memory",
description = "Keep all assets in memory.",
name = "Download Assets at launch",
description = "Download all assets at launch.",
category = "General"
)
@VigilanceName( name = "Download at Launch", category = "General", subcategory = "")
@NonProfileSpecific
var keepAssetsLoaded = true
var downloadAtLaunch = false

@Switch(
name = "Download at launch",
description = "Download all assets at launch.",
name = "Keep Assets In Memory",
description = "Keep all assets in memory.",
category = "General"
)
@VigilanceName( name = "Keep In Memory", category = "General", subcategory = "")
@NonProfileSpecific
var downloadAtLaunch = false
var keepAssetsLoaded = true

@Switch(
name = "Lazy Loading",
name = "Lazy Asset Loading",
description = "Load assets as they are needed.",
category = "General"
)
@VigilanceName( name = "Lazy Loading", category = "General", subcategory = "")
@NonProfileSpecific
var lazyLoading = true

Expand All @@ -65,48 +69,53 @@ object Config : Config(
@KeyBind(
name = "Map Keybind",
description = "The keybind to open the map.",
category = "Map"
category = "Map",
size = 2
)
var mapKeyBind = OneKeyBind(UKeyboard.KEY_M)

@Slider(
name = "Default Scale",
description = "The default scale of the map.",
@Switch(
name = "Show NPCs",
description = "Show npcs on the map.",
category = "Map",
min = 0.25f, max = 5f
size = 2
)
var defaultScale = 2f
var showNpcs = true

@Slider(
name = "Player Pointer Size",
description = "The size of the player pointer.",
category = "Map",
min = 7f, max = 49f
)
var mapPointerSize = 14f

@Switch(
name = "Show MVP Warps",
description = "Show MVP warps on the map.",
category = "Map",
size = 2
)
var showMVPWarps = true

@Switch(
name = "Show NPCs",
description = "Show npcs on the map.",
category = "Map",
)
var showNpcs = true

@cc.polyfrost.oneconfig.config.annotations.Color(
allowAlpha = false,
name = "Pin Color",
description = "The color of the destination pin.",
category = "Map"
category = "Map",
size = 2
)
var pinColor = OneColor(Color.RED)

@Slider(
name = "Default Scale",
description = "The default scale of the map.",
category = "Map",
min = 0.25f, max = 5f
)
var defaultScale = 2f

@Slider(
name = "Player Pointer Size",
description = "The size of the player pointer.",
category = "Map",
min = 7f, max = 49f
)
var mapPointerSize = 14f

// Mini-Map

@HUD(
Expand All @@ -121,21 +130,26 @@ object Config : Config(
name = "Show Skytils Waypoints",
description = "Show Skytils waypoints on the map.",
category = "Integration",
subcategory = "Skytils"
subcategory = "Skytils",
size = 2
)
var skytilsWaypoints = true

@Switch(
name = "Show Disabled Skytils Waypoints",
description = "Whether to show disabled Skytils waypoints on the map.",
category = "Integration",
subcategory = "Skytils"
subcategory = "Skytils",
size = 2
)
var disabledSkytilsWaypoints = false

// Hidden

@NonProfileSpecific
var downloadAssets = true

@NonProfileSpecific
var firstLaunchVersion = 0

init {
Expand Down
27 changes: 12 additions & 15 deletions src/main/kotlin/dev/dediamondpro/skyguide/handlers/AssetHandler.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package dev.dediamondpro.skyguide.handlers

import cc.polyfrost.oneconfig.libs.universal.UChat
import cc.polyfrost.oneconfig.libs.universal.UGraphics
import cc.polyfrost.oneconfig.libs.universal.UMinecraft
import cc.polyfrost.oneconfig.libs.universal.utils.ReleasedDynamicTexture
import cc.polyfrost.oneconfig.renderer.asset.Icon
import cc.polyfrost.oneconfig.utils.Multithreading
import cc.polyfrost.oneconfig.utils.Notifications
import dev.dediamondpro.skyguide.SkyGuide
import dev.dediamondpro.skyguide.config.Config
import dev.dediamondpro.skyguide.map.SkyblockMap
import dev.dediamondpro.skyguide.utils.*
import net.minecraft.util.EnumChatFormatting
import dev.dediamondpro.skyguide.utils.IOUtils
import dev.dediamondpro.skyguide.utils.NetworkUtils
import dev.dediamondpro.skyguide.utils.WebAsset
import dev.dediamondpro.skyguide.utils.toFile
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent
Expand All @@ -18,6 +21,7 @@ import java.io.IOException
import java.net.URL
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.util.concurrent.Callable
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap
import javax.imageio.ImageIO
Expand All @@ -37,18 +41,11 @@ class AssetHandler {
currentFile = 0
currentPercent = 0f
if (UMinecraft.getWorld() == null) return
postMessage()
}

private fun postMessage() {
val percent = (currentFile.toFloat() + currentPercent) / totalFiles.toFloat()
if (percent == 1f) {
UChat.chat("${EnumChatFormatting.DARK_AQUA}${SkyGuide.NAME} > ${EnumChatFormatting.YELLOW}Finished downloading assets!")
downloadedAssets = true
} else {
UChat.chat("${EnumChatFormatting.DARK_AQUA}${SkyGuide.NAME} > ${EnumChatFormatting.YELLOW}Downloading assets... ${(percent * 100).toInt()}% ($currentFile/$totalFiles)")
TickDelay(20, AssetHandler::postMessage)
}
Notifications.INSTANCE.send(
"Downloading Assets",
"SkyGuide by DeDiamondPro",
Icon("/assets/skyguide/downloading.svg"),
Callable { (currentFile.toFloat() + currentPercent) / totalFiles.toFloat() })
}

fun loadAsset(fileName: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package dev.dediamondpro.skyguide.handlers

import cc.polyfrost.oneconfig.libs.universal.UChat
import cc.polyfrost.oneconfig.utils.Notifications
import dev.dediamondpro.skyguide.config.Config
import dev.dediamondpro.skyguide.utils.SBInfo
import net.minecraft.util.EnumChatFormatting
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent

class FirstLaunchHandler {
@SubscribeEvent
fun clientTickEvent(e: ClientTickEvent) {
if (Config.firstLaunchVersion != 1 && SBInfo.inSkyblock) {
UChat.chat(
"${EnumChatFormatting.YELLOW}Thank you for installing SkyGuide!" +
"\n${EnumChatFormatting.YELLOW}SkyGuide provides a neat mini-map" +
"\n${EnumChatFormatting.YELLOW}and a full map you can open by pressing m!\n" +
"${EnumChatFormatting.YELLOW}To configure SkyGuide please do /skyguide!"
Notifications.INSTANCE.send(
"Thank you for installing SkyGuide!",
"Press '${Config.mapKeyBind.display}' to open the map!\nDo '/skyguide' to configure skyguide!",
10000f,
Runnable { Config.openGui() }
)
Config.firstLaunchVersion = 1
Config.save()
Expand Down
40 changes: 21 additions & 19 deletions src/main/kotlin/dev/dediamondpro/skyguide/hud/MiniMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import cc.polyfrost.oneconfig.hud.Hud
import cc.polyfrost.oneconfig.libs.universal.UGraphics
import cc.polyfrost.oneconfig.libs.universal.UMatrixStack
import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.polyfrost.oneconfig.libs.universal.UScreen
import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer
import dev.dediamondpro.skyguide.gui.MapGui
import dev.dediamondpro.skyguide.map.Island
import dev.dediamondpro.skyguide.map.SkyblockMap
import dev.dediamondpro.skyguide.map.Textures
Expand All @@ -20,29 +22,20 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.opengl.GL11
import kotlin.math.pow

class MiniMap : Hud(true, 0f, 0f, 0.7f) {
class MiniMap : Hud(true, 0f, 1815f, 0.7f) {
@Switch(
name = "Rotate With Player",
description = "Rotate the map with the player.",
category = "Mini-Map"
)
var rotateWithPlayer = true

@Slider(
name = "Zoom Factor",
description = "The zoom factor of the map.",
min = 0.25f, max = 5f,
category = "Mini-Map"
)
var mapZoom = 1.5f

@Slider(
name = "Underground Zoom Multiplier",
description = "The zoom multiplier of the map when underground.",
min = 0.25f, max = 5f,
@Switch(
name = "Show PIOs",
description = "Whether to show points of interests (npcs, portals, ...) on the mini-map.",
category = "Mini-Map"
)
var undergroundMapZoom = 2f
var showPIOs = true

@Switch(
name = "Background",
Expand All @@ -58,12 +51,21 @@ class MiniMap : Hud(true, 0f, 0f, 0.7f) {
)
var backgroundColor = OneColor(0, 0, 0)

@Switch(
name = "Show PIOs",
description = "Whether to show points of interests (npcs, portals, ...) on the mini-map.",
@Slider(
name = "Zoom Factor",
description = "The zoom factor of the map.",
min = 0.25f, max = 5f,
category = "Mini-Map"
)
var showPIOs = true
var mapZoom = 1.5f

@Slider(
name = "Underground Zoom Multiplier",
description = "The zoom multiplier of the map when underground.",
min = 0.25f, max = 5f,
category = "Mini-Map"
)
var undergroundMapZoom = 2f

@Slider(
name = "Player Pointer Size",
Expand Down Expand Up @@ -220,6 +222,6 @@ class MiniMap : Hud(true, 0f, 0f, 0.7f) {
}

override fun shouldShow(): Boolean {
return super.shouldShow() && SBInfo.inSkyblock && SkyblockMap.currentIslandAvailable()
return super.shouldShow() && SBInfo.inSkyblock && SkyblockMap.currentIslandAvailable() && UScreen.currentScreen !is MapGui
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dediamondpro.skyguide.map.navigation

import dev.dediamondpro.skyguide.config.Config
import dev.dediamondpro.skyguide.utils.RenderUtils
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumChatFormatting
Expand All @@ -13,7 +14,7 @@ class DestinationAction(private val destination: Destination) : NavigationAction
destination.x.toDouble(),
destination.y?.toDouble() ?: 0.0,
destination.z.toDouble()
), Color.RED.rgb, partialTicks
), Config.pinColor.rgb, partialTicks
)
if (destination.y != null) RenderUtils.renderWayPoint(
mutableListOf("${EnumChatFormatting.BLUE}${destination.name.replaceFirstChar { it.uppercase() }}"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dediamondpro.skyguide.map.navigation

import dev.dediamondpro.skyguide.config.Config
import dev.dediamondpro.skyguide.map.poi.Npc
import dev.dediamondpro.skyguide.utils.RenderUtils
import net.minecraft.util.BlockPos
Expand All @@ -11,7 +12,7 @@ class NpcAction(private val npc: Npc, private val destination: Destination) : Na
override fun drawAction(partialTicks: Float) {
RenderUtils.renderBeaconBeam(
BlockPos(npc.x.toDouble(), npc.y.toDouble(), npc.z.toDouble()),
Color.RED.rgb,
Config.pinColor.rgb,
partialTicks
)
RenderUtils.renderWayPoint(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dediamondpro.skyguide.map.navigation

import dev.dediamondpro.skyguide.config.Config
import dev.dediamondpro.skyguide.map.SkyblockMap
import dev.dediamondpro.skyguide.map.poi.Portal
import dev.dediamondpro.skyguide.utils.RenderUtils
Expand All @@ -12,7 +13,7 @@ class PortalAction(private val portal: Portal, private val destination: Destinat
override fun drawAction(partialTicks: Float) {
RenderUtils.renderBeaconBeam(
BlockPos(portal.x.toDouble(), portal.y.toDouble(), portal.z.toDouble()),
Color.RED.rgb,
Config.pinColor.rgb,
partialTicks
)
RenderUtils.renderWayPoint(
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/dev/dediamondpro/skyguide/map/poi/Npc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Npc(
}

override fun drawIcon(x: Float, y: Float) {
UGraphics.enableDepth()
UGraphics.GL.pushMatrix()
UGraphics.GL.translate(x - 16, y - 16, 0f)
UGraphics.GL.scale(2.0, 2.0, 1.0)
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/dev/dediamondpro/skyguide/utils/GuiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class GuiUtils {
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onHudRenderEvent(event: RenderGameOverlayEvent.Post) {
if (event.type != RenderGameOverlayEvent.ElementType.ALL) return
prevHudDeltaTime = hudDeltaTime
hudDeltaTime = 0L
}

companion object {
private var prevHudDeltaTime: Long = 0L
private var hudDeltaTime: Long = 0L
private var guiDeltaTime: Long = 0L
private var time = -1L
Expand All @@ -74,7 +76,7 @@ class GuiUtils {
private set

fun getHudDeltaTime(): Long {
return hudDeltaTime
return if (hudDeltaTime == 0L) prevHudDeltaTime else hudDeltaTime
}

fun getGuiDeltaTime(): Long {
Expand Down
Loading

0 comments on commit 1c2ce59

Please sign in to comment.