Skip to content

Commit

Permalink
more options & 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDiamondPro committed Aug 2, 2023
1 parent 7f52f82 commit ce7ef6b
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 75 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.3.0

essential.defaults.loom=0

Expand Down
51 changes: 43 additions & 8 deletions src/main/kotlin/dev/dediamondpro/skyguide/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ object Config : Vigilant(configFile, SkyGuide.NAME) {
)
var mapPointerSize = 14f

@Property(
type = PropertyType.SWITCH,
name = "Show Warps",
description = "Show warps on the map.",
category = "Map",
)
var showWarps = true

@Property(
type = PropertyType.SWITCH,
name = "Show MVP Warps",
Expand All @@ -88,6 +96,15 @@ object Config : Vigilant(configFile, SkyGuide.NAME) {
)
var showNpcs = true

@Property(
type = PropertyType.DECIMAL_SLIDER,
name = "POI Scale",
description = "The scale of POIs on the map.",
category = "Map",
minF = 0.25f, maxF = 4f
)
var POIScale = 1f

@Property(
type = PropertyType.COLOR,
allowAlpha = false,
Expand Down Expand Up @@ -167,14 +184,6 @@ object Config : Vigilant(configFile, SkyGuide.NAME) {
)
var backgroundColor = Color(0, 0, 0)

@Property(
type = PropertyType.SWITCH,
name = "Show PIOs",
description = "Whether to show points of interests (npcs, portals, ...) on the mini-map.",
category = "Mini-Map"
)
var showPIOs = true

@Property(
type = PropertyType.DECIMAL_SLIDER,
name = "Player Pointer Size",
Expand All @@ -184,6 +193,31 @@ object Config : Vigilant(configFile, SkyGuide.NAME) {
)
var miniMapPointerSize = 12f

@Property(
type = PropertyType.SWITCH,
name = "Show Warps",
description = "Show warps on the mini-map.",
category = "Mini-Map",
)
var showWarpsMiniMap = true

@Property(
type = PropertyType.SWITCH,
name = "Show NPCs",
description = "Show npcs on the mini-map.",
category = "Mini-Map",
)
var showNpcsMiniMap = true

@Property(
type = PropertyType.DECIMAL_SLIDER,
name = "POI Scale",
description = "The scale of POIs on the mini-map.",
category = "Mini-Map",
minF = 0.25f, maxF = 4f
)
var POIScaleMiniMap = 1f

@Property(
type = PropertyType.SWITCH,
name = "Show in GUIs",
Expand Down Expand Up @@ -273,5 +307,6 @@ object Config : Vigilant(configFile, SkyGuide.NAME) {
}
}
addDependency("lazyLoading", "keepAssetsLoaded")
addDependency("showMVPWarps", "showWarps")
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/dediamondpro/skyguide/hud/MiniMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MiniMap {
)
UGraphics.color4f(1f, 1f, 1f, 1f)
UGraphics.GL.popMatrix()
if (Config.showPIOs) island.drawPioMiniMap(
island.drawPioMiniMap(
x + 75 * scale - UPlayer.getOffsetX(event.partialTicks) * totalScale,
y + 75 * scale - UPlayer.getOffsetY(event.partialTicks) * totalScale,
x + 75.0 * scale,
Expand Down
31 changes: 14 additions & 17 deletions src/main/kotlin/dev/dediamondpro/skyguide/map/Island.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import dev.dediamondpro.skyguide.utils.ItemUtils
import gg.essential.universal.UGraphics
import kotlinx.serialization.Transient
import net.minecraft.item.ItemStack
import kotlin.math.cos
import kotlin.math.pow
import kotlin.math.sin
import kotlin.math.sqrt
import kotlin.math.*

/**
* @param images The images of the map
Expand Down Expand Up @@ -88,28 +85,29 @@ data class Island(
lastPoi = poi
continue
}
if (!poi.shouldDraw(locations, scale)) continue
poi.draw(x, y, xOffset, yOffset, scale)
if (!poi.shouldDraw(locations, scale, Config.POIScale)) continue
poi.draw(x, y, xOffset, yOffset, scale, Config.POIScale)
locations.add(poi.x to poi.z)
}
// draw destination last since it always has to be on top
UGraphics.disableDepth()
lastPoi?.draw(x, y, xOffset, yOffset, scale)
lastPoi?.draw(x, y, xOffset, yOffset, scale, Config.POIScale)
UGraphics.enableDepth()
}

fun drawPioMiniMap(x: Float, y: Float, originX: Double, originY: Double, scale: Float, rotation: Double) {
val locations = mutableListOf<Pair<Float, Float>>()
var lastPoi: PointOfInterest? = null
for (poi in getPointsOfInterest()) {
for (poi in getPointsOfInterest(true)) {
if (poi is DestinationPoi) {
lastPoi = poi
continue
}
if (!poi.shouldDraw(locations, scale)) continue
if (!poi.shouldDraw(locations, scale, Config.POIScaleMiniMap)) continue
poi.drawRaw(
(cos(rotation) * (x + poi.x * scale - originX) + sin(rotation) * (y + poi.z * scale - originY) + originX).toFloat(),
(-sin(rotation) * (x + poi.x * scale - originX) + cos(rotation) * (y + poi.z * scale - originY) + originY).toFloat(),
Config.POIScaleMiniMap
)
locations.add(poi.x to poi.z)
}
Expand All @@ -118,6 +116,7 @@ data class Island(
lastPoi?.drawRaw(
(cos(rotation) * (x + lastPoi.x * scale - originX) + sin(rotation) * (y + lastPoi.z * scale - originY) + originX).toFloat(),
(-sin(rotation) * (x + lastPoi.x * scale - originX) + cos(rotation) * (y + lastPoi.z * scale - originY) + originY).toFloat(),
Config.POIScaleMiniMap
)
UGraphics.enableDepth()
}
Expand All @@ -134,11 +133,9 @@ data class Island(
val yScaled = mouseY / scale - y
for (poi in getPointsOfInterest()) {
if ((!locations.contains(poi.x to poi.z) && poi !is DestinationPoi) || !poi.shouldDrawTooltip(
xScaled,
yScaled,
xOffset,
yOffset,
scale
xScaled, yScaled,
xOffset, yOffset,
scale, Config.POIScale
)
) continue
poi.drawTooltip(mouseX, mouseY)
Expand All @@ -159,12 +156,12 @@ data class Island(
return images.first()
}

private fun getPointsOfInterest(): List<PointOfInterest> {
private fun getPointsOfInterest(miniMap: Boolean = false): List<PointOfInterest> {
val list = mutableListOf<PointOfInterest>()
list.addAll(portals)
if (Config.showWarps && !miniMap || Config.showWarpsMiniMap && miniMap) list.addAll(portals)
INEUCompat.instance?.getCurrentlyTrackedWaypoint()?.let { if (it.island == this) list.add(it) }
if (SkytilsCompat.waypoints.containsKey(this)) list.addAll(SkytilsCompat.waypoints[this]!!)
list.addAll(npcs)
if (Config.showNpcs && !miniMap || Config.showNpcsMiniMap && miniMap) list.addAll(npcs)
val dest = NavigationHandler.destinationPio
if (dest.destination != null && dest.destination!!.island == this) list.add(
0, NavigationHandler.destinationPio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import dev.dediamondpro.skyguide.utils.RenderUtils
import gg.essential.universal.UChat
import gg.essential.universal.UGraphics
import net.minecraft.util.EnumChatFormatting
import kotlin.math.pow
import kotlin.math.sqrt

class DestinationPoi(var destination: Destination?) : PointOfInterest() {
override val x: Float
Expand All @@ -23,7 +21,7 @@ class DestinationPoi(var destination: Destination?) : PointOfInterest() {
return destination != null
}

override fun drawIcon(x: Float, y: Float) {
override fun drawIcon(x: Float, y: Float, scale: Float) {
UGraphics.color4f(
Config.pinColor.red / 255f,
Config.pinColor.green / 255f,
Expand All @@ -32,10 +30,10 @@ class DestinationPoi(var destination: Destination?) : PointOfInterest() {
)
RenderUtils.drawImage(
"/assets/skyguide/pin.png",
x - 8f,
y - 8f,
16f,
16f
x - 8f * scale,
y - 8f * scale,
16f * scale,
16f * scale
)
UGraphics.color4f(1f, 1f, 1f, 1f)
}
Expand All @@ -61,5 +59,5 @@ class DestinationPoi(var destination: Destination?) : PointOfInterest() {
NavigationHandler.clearNavigation()
}

override fun drawBackground(x: Float, y: Float) {}
override fun drawBackground(x: Float, y: Float, scale: Float) {}
}
12 changes: 6 additions & 6 deletions src/main/kotlin/dev/dediamondpro/skyguide/map/poi/NEUWaypoint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ data class NEUWaypoint(
return Config.neuWaypoints
}

override fun drawIcon(x: Float, y: Float) {
override fun drawIcon(x: Float, y: Float, scale: Float) {
UGraphics.color4f(1f, 0f, 0f, 1f)
RenderUtils.drawImage(
"/assets/skyguide/pin.png",
x - 8f,
y - 8f,
16f,
16f
x - 8f * scale,
y - 8f * scale,
16f * scale,
16f * scale
)
}

Expand All @@ -48,5 +48,5 @@ data class NEUWaypoint(
neuCompat.untrackWaypoint()
}

override fun drawBackground(x: Float, y: Float) {}
override fun drawBackground(x: Float, y: Float, scale: Float) {}
}
10 changes: 4 additions & 6 deletions src/main/kotlin/dev/dediamondpro/skyguide/map/poi/Npc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ class Npc(
@Transient
override val skull = ItemUtils.createSkull(owner, texture)

override fun shouldDraw(): Boolean {
return Config.showNpcs
}
override fun shouldDraw(): Boolean = true

override fun drawIcon(x: Float, y: Float) {
override fun drawIcon(x: Float, y: Float, scale: Float) {
UGraphics.GL.pushMatrix()
UGraphics.GL.translate(x - 16, y - 16, 0f)
UGraphics.GL.scale(2.0, 2.0, 1.0)
UGraphics.GL.translate(x - 16 * scale, y - 16 * scale, 0f)
UGraphics.GL.scale(2.0 * scale, 2.0 * scale, 1.0)
ItemUtils.drawItemStack(skull, 0, 0)
UGraphics.GL.popMatrix()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,51 @@ abstract class PointOfInterest {

protected abstract fun shouldDraw(): Boolean

fun shouldDraw(locations: MutableList<Pair<Float, Float>>, scale: Float): Boolean {
fun shouldDraw(locations: MutableList<Pair<Float, Float>>, scale: Float, poiScale: Float): Boolean {
for (location in locations) {
val dist = sqrt(
(location.first * scale - x * scale).toDouble()
.pow(2.0) + (location.second * scale - z * scale).toDouble().pow(2.0)
)
if (dist < 32) return false
if (dist < 32 * poiScale) return false
}
return shouldDraw()
}

fun draw(xMove: Float, yMove: Float, xOffset: Float, yOffset: Float, scale: Float) {
drawBackground((x + xOffset + xMove) * scale, (z + yOffset + yMove) * scale)
drawIcon((x + xOffset + xMove) * scale, (z + yOffset + yMove) * scale)
fun draw(xMove: Float, yMove: Float, xOffset: Float, yOffset: Float, scale: Float, poiScale: Float) {
drawBackground((x + xOffset + xMove) * scale, (z + yOffset + yMove) * scale, poiScale)
drawIcon((x + xOffset + xMove) * scale, (z + yOffset + yMove) * scale, poiScale)
}

fun drawRaw(x: Float, y: Float) {
drawBackground(x, y)
drawIcon(x, y)
fun drawRaw(x: Float, y: Float, poiScale: Float) {
drawBackground(x, y, poiScale)
drawIcon(x, y, poiScale)
}

protected open fun drawBackground(x: Float, y: Float) {
protected open fun drawBackground(x: Float, y: Float, scale: Float) {
UGraphics.color4f(1f, 1f, 1f, 1f)
RenderUtils.drawImage(
"/assets/skyguide/map_location.png",
x - 16f,
y - 16,
32f,
32f
x - 16f * scale,
y - 16 * scale,
32f * scale,
32f * scale
)
}

protected abstract fun drawIcon(x: Float, y: Float)
protected abstract fun drawIcon(x: Float, y: Float, scale: Float)

fun shouldDrawTooltip(
mouseXScaled: Float,
mouseYScaled: Float,
xOffset: Float,
yOffset: Float,
scale: Float
scale: Float,
poiScale: Float
): Boolean {
return shouldDraw()
&& mouseXScaled >= (x + xOffset - 16f / scale) && mouseXScaled <= (x + xOffset + 16f / scale)
&& mouseYScaled >= (z + yOffset - 16f / scale) && mouseYScaled <= (z + yOffset + 16f / scale)
&& mouseXScaled >= (x + xOffset - (16f * poiScale) / scale) && mouseXScaled <= (x + xOffset + (16f * poiScale) / scale)
&& mouseYScaled >= (z + yOffset - (16f * poiScale) / scale) && mouseYScaled <= (z + yOffset + (16f * poiScale) / scale)
}

fun drawTooltip(mouseX: Int, mouseY: Int) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/dev/dediamondpro/skyguide/map/poi/Portal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ data class Portal(
return command != null && (!mvp || Config.showMVPWarps)
}

override fun drawIcon(x: Float, y: Float) {
override fun drawIcon(x: Float, y: Float, scale: Float) {
RenderUtils.drawImage(
"/assets/skyguide/portal.png",
x - 6f,
y - 9f,
12f,
18f
x - 6f * scale,
y - 9f * scale,
12f * scale,
18f * scale
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SkytilsWaypoint(
return Config.skytilsWaypoints && (enabled || Config.disabledSkytilsWaypoints)
}

override fun drawIcon(x: Float, y: Float) {
override fun drawIcon(x: Float, y: Float, scale: Float) {
UGraphics.color4f(
color.red / 255f,
color.green / 255f,
Expand All @@ -34,10 +34,10 @@ class SkytilsWaypoint(
)
RenderUtils.drawImage(
"/assets/skyguide/pin.png",
x - 8f,
y - 8f,
16f,
16f
x - 8f * scale,
y - 8f * scale,
16f * scale,
16f * scale
)
UGraphics.color4f(1f, 1f, 1f, 1f)
}
Expand All @@ -64,5 +64,5 @@ class SkytilsWaypoint(
NavigationHandler.navigateTo(Destination(island!!, x, y, z, name))
}

override fun drawBackground(x: Float, y: Float) {}
override fun drawBackground(x: Float, y: Float, scale: Float) {}
}

0 comments on commit ce7ef6b

Please sign in to comment.