Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ public interface SettingsOptionInstanceAccessor {

@Accessor("caption")
Component polyplus$caption();

@Accessor("value")
void polyplus$setValue(Object value);
}
//?}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import net.minecraft.client.KeyMapping
/*import net.minecraft.client.options.KeyBinding as KeyMapping
import org.lwjgl.opengl.Display
*///?}
//? if >= 26.3 {
import org.lwjgl.sdl.SDLVideo
//?} elif > 1.8.9 {
/*import org.lwjgl.glfw.GLFW
import org.lwjgl.system.MemoryStack
*///?}
//? if >= 1.21.4
import net.minecraft.client.InactivityFpsLimit
import net.minecraft.client.Minecraft
Expand All @@ -26,6 +32,7 @@ import java.nio.file.Path
import kotlin.io.path.exists
import kotlin.io.path.readLines
import kotlin.io.path.writeText
import kotlin.math.roundToInt

object DefaultSettings {
private val logger = LogManager.getLogger("PolyPlus/DefaultSettings")
Expand Down Expand Up @@ -132,6 +139,15 @@ object DefaultSettings {
),
)
//?}
add(
Task(
id = "vanilla-gui-scale",
label = "Minecraft GUI scale",
isPresent = { !PolyPlusConfig.onboardingCompleted && !Mods.guiSlider },
apply = ::applyMonitorGuiScale,
coveredByLegacyFlag = false,
),
)
UNBIND_ALL_NAMESPACES.forEach { namespace ->
add(unbindTask(namespace) { key -> namespace in key.split('.') })
}
Expand Down Expand Up @@ -384,6 +400,59 @@ object DefaultSettings {
*///?}
}

fun applyMonitorGuiScale() {
val options = Minecraft.getInstance().options ?: return
//? if > 1.8.9 {
if (options.guiScale().get() != 0) return
//?} else {
/*if (options.guiScale != 0) return
*///?}
val (width, height) = monitorPixels() ?: return
OnboardingFeatures.applyGuiScale(recommendedGuiScale(width, height))
}

internal fun recommendedGuiScale(width: Int, height: Int): Int =
minOf(width / 640.0, height / 360.0).roundToInt().coerceAtLeast(1)

private fun monitorPixels(): Pair<Int, Int>? {
//? if >= 26.3 {
val display = SDLVideo.SDL_GetDisplayForWindow(Minecraft.getInstance().window.handle())
.takeIf { it != 0 } ?: SDLVideo.SDL_GetPrimaryDisplay()
val mode = SDLVideo.SDL_GetDesktopDisplayMode(display) ?: return null
val density = mode.pixel_density().coerceAtLeast(1f)
return (mode.w() * density).roundToInt() to (mode.h() * density).roundToInt()
//?} elif > 1.8.9 {
/*val monitor = Minecraft.getInstance().window.findBestMonitor() ?: return null
//? if >= 26.2 {
val mode = monitor.currentMode()
val handle = monitor.monitor()
//?} else {
/^val mode = monitor.currentMode
val handle = monitor.monitor
^///?}
val scale = if (ClientPlatform.isMac) MemoryStack.stackPush().use { stack ->
val x = stack.mallocFloat(1)
GLFW.glfwGetMonitorContentScale(handle, x, stack.mallocFloat(1))
x.get(0).coerceAtLeast(1f)
} else 1f
return (mode.width * scale).roundToInt() to (mode.height * scale).roundToInt()
*///?} else {
/*val mode = Display.getDesktopDisplayMode() ?: return null
val density = pylonPixelDensity()
return (mode.width * density).roundToInt() to (mode.height * density).roundToInt()
*///?}
}

//? if <= 1.8.9 {
/*private fun pylonPixelDensity(): Float = runCatching {
val display = Class.forName("pl.tomgirl.pylon.window.DisplaySdl")
val instance = display.getMethod("instance").invoke(null)
if (display.getMethod("isHighPixelDensity").invoke(instance) as Boolean) {
(display.getMethod("getPixelDensity").invoke(instance) as Float).coerceAtLeast(1f)
} else 1f
}.getOrDefault(1f)
*///?}

//? if >= 1.21.4 {
private fun reduceFpsOnlyWhenMinimized() {
val options = Minecraft.getInstance().options ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.polyfrost.polyplus.client.gui.isGlassStyle
import org.polyfrost.polyplus.client.gui.isLightTheme
import org.polyfrost.polyplus.client.gui.isMinecraftStyle
import org.polyfrost.polyplus.compat.Mods
//? if > 1.8.9
import org.polyfrost.polyplus.mixin.client.access.SettingsOptionInstanceAccessor
import java.util.concurrent.ConcurrentHashMap

object OnboardingFeatures {
Expand Down Expand Up @@ -358,7 +360,7 @@ object OnboardingFeatures {
runCatching {
val mc = Minecraft.getInstance()
//? if > 1.8.9 {
mc.options.guiScale().set(value.coerceAtLeast(0))
(mc.options.guiScale() as Any as SettingsOptionInstanceAccessor).`polyplus$setValue`(value.coerceAtLeast(0))
//?} else {
/*mc.options.guiScale = value.coerceAtLeast(0)
*///?}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import org.polyfrost.polyplus.client.features.BlockHighlightDraft
import org.polyfrost.polyplus.client.features.BlockHighlightPresets
import org.polyfrost.polyplus.client.features.BlockHighlightStyle
import org.polyfrost.polyplus.client.features.DefaultModOrder
import org.polyfrost.polyplus.client.features.DefaultSettings
import org.polyfrost.polyplus.client.features.OnboardingFeatures
import org.polyfrost.polyplus.client.features.OnboardingFeatures.ModCard
import org.polyfrost.polyplus.client.gui.preview.BlockHighlightRenderer
Expand Down Expand Up @@ -328,14 +329,13 @@ internal fun OnboardingFlow(
var blurSampleTimedOut by remember { mutableStateOf(false) }
var blurPickedManually by remember { mutableStateOf(false) }
var maxGuiScale by remember { mutableIntStateOf(OnboardingFeatures.maxGuiScale()) }
var chosenGuiScale by remember {
mutableIntStateOf(
//? if > 1.8.9 {
if (Mods.guiSlider) mcGuiScale() else Minecraft.getInstance().options.guiScale().get().coerceIn(0, maxGuiScale),
//?} else {
/*Minecraft.getInstance().options.guiScale.coerceIn(0, maxGuiScale),
*///?}
)
val chosenGuiScale = remember {
if (needsSettings && !Mods.guiSlider) runCatching(DefaultSettings::applyMonitorGuiScale)
//? if > 1.8.9 {
if (Mods.guiSlider) mcGuiScale() else Minecraft.getInstance().options.guiScale().get().coerceAtLeast(0)
//?} else {
/*Minecraft.getInstance().options.guiScale.coerceAtLeast(0)
*///?}
}
val guiScale = if (chosenGuiScale <= 0) 0 else minOf(chosenGuiScale, maxGuiScale)
LaunchedEffect(Unit) {
Expand Down Expand Up @@ -522,7 +522,6 @@ internal fun OnboardingFlow(
LookAndFeelPage(
lightTheme, { lightTheme = it },
uiStyle, { uiStyle = it },
guiScale, maxGuiScale, { chosenGuiScale = it },
)
OnboardingStep.Screens -> ScreensPage(screens) { screens = it }
OnboardingStep.ModOrder -> ModOrderPage(alphabeticalMods) { alphabeticalMods = it }
Expand Down Expand Up @@ -740,15 +739,11 @@ private fun LookAndFeelPage(
onLightTheme: (Boolean) -> Unit,
uiStyle: Int,
onUiStyle: (Int) -> Unit,
guiScale: Int,
maxGuiScale: Int,
onGuiScale: (Int) -> Unit,
) {
Header("Let’s configure the", "Look & Feel")
val colorsHeight = LABEL_HEIGHT + 32f
val styleHeight = LABEL_HEIGHT + 155f
val scaleHeight = if (Mods.guiSlider) 0f else LABEL_HEIGHT + 32f + SECTION_GAP
val total = colorsHeight + SECTION_GAP + styleHeight + scaleHeight
val total = colorsHeight + SECTION_GAP + styleHeight
var y = CONTENT_TOP + ((CONTENT_BOTTOM - CONTENT_TOP) - total) / 2f
SectionHeader("UI Colors", Modifier.offset(232.dp, y.dp).width(198.dp), eyebrow = false)
Row(Modifier.offset(232.dp, (y + LABEL_HEIGHT).dp), horizontalArrangement = Arrangement.spacedBy(18.dp)) {
Expand All @@ -762,33 +757,6 @@ private fun LookAndFeelPage(
StyleCard(option, OnboardingFeatures.uiStyleTheme(option.style, lightTheme), uiStyle == option.style) { onUiStyle(option.style) }
}
}
y += styleHeight + SECTION_GAP
if (!Mods.guiSlider) GuiScaleSection(y, guiScale, maxGuiScale, onGuiScale)
}

@Composable
private fun GuiScaleSection(y: Float, guiScale: Int, maxScale: Int, onGuiScale: (Int) -> Unit) {
SectionHeader("GUI Scale", Modifier.offset(232.dp, y.dp).width(198.dp), eyebrow = false)
val steps = maxScale.coerceAtLeast(1)
fun valueToProgress(v: Int): Float = if (v <= 0) 1f else ((v - 1).toFloat() / steps).coerceIn(0f, 1f)
fun indexToValue(index: Int): Int = if (index >= steps) 0 else index + 1
Row(Modifier.offset(232.dp, (y + LABEL_HEIGHT).dp), verticalAlignment = Alignment.CenterVertically) {
var pending by remember { mutableIntStateOf(guiScale) }
val shown = if (guiScale <= 0) "Auto" else guiScale.toString()
OnboardingSlider(
progress = valueToProgress(guiScale),
width = 332f,
label = "GUI Scale",
valueText = { p -> indexToValue((p * steps).roundToInt()).let { if (it <= 0) "Auto" else it.toString() } },
keyStep = 1f / steps,
onRelease = { OnboardingFeatures.applyGuiScale(pending, persist = false) },
) { p ->
pending = indexToValue((p * steps).roundToInt())
onGuiScale(pending)
}
Spacer(Modifier.width(18.dp))
ValueBadge(shown, 64.dp, 26.dp, Alignment.CenterStart)
}
}

@Composable
Expand Down Expand Up @@ -2557,7 +2525,7 @@ private fun pageSpeech(step: OnboardingStep, page: Int, waiting: Boolean): Strin
OnboardingStep.Accessibility -> ""
OnboardingStep.Terms ->
"Welcome to OneClient. Agree to the Terms of Service and Privacy Policy to use online features. $TERMS_NOTE"
OnboardingStep.LookAndFeel -> "Look and Feel. Choose the UI colors, UI style and GUI scale."
OnboardingStep.LookAndFeel -> "Look and Feel. Choose the UI colors and UI style."
OnboardingStep.Screens ->
"Screens. " + ScreenPart.shown.joinToString(", ") { it.title } + "."
OnboardingStep.ModOrder -> "Mod Sorting. $MOD_ORDER_TEXT"
Expand Down