Skip to content

Commit 34d9aeb

Browse files
committed
Fix bugs
Fixes #36 Fixes #37
1 parent f7d2b97 commit 34d9aeb

7 files changed

Lines changed: 155 additions & 56 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.polyfrost.polyplus.mixin.client;
2+
3+
import org.polyfrost.oneconfig.api.config.v1.Tree;
4+
import org.polyfrost.oneconfig.internal.ui.compose.impls.OneConfigUIScreen;
5+
import org.polyfrost.polyplus.client.gui.PolyPlusOneConfigIntegration;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Unique;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
12+
13+
@Mixin(value = OneConfigUIScreen.class, remap = false)
14+
public class Mixin_OneConfigUIScreenRoute {
15+
@Unique
16+
private Object polyplus$openingRoute;
17+
18+
@Inject(method = "<init>(Ljava/lang/String;Ljava/lang/String;Lorg/polyfrost/oneconfig/api/config/v1/Tree;)V", at = @At("RETURN"), remap = false)
19+
private void polyplus$captureOpeningRoute(String initialTreeId, String initialCategory, Tree initialTree, CallbackInfo ci) {
20+
polyplus$openingRoute = PolyPlusOneConfigIntegration.consumePendingOpeningRoute();
21+
}
22+
23+
@Inject(method = "resolveOpeningBehaviorRoute", at = @At("HEAD"), cancellable = true, remap = false)
24+
private void polyplus$forceOpeningRoute(CallbackInfoReturnable<Object> cir) {
25+
if (polyplus$openingRoute != null) {
26+
cir.setReturnValue(polyplus$openingRoute);
27+
}
28+
}
29+
}

src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusConfig.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ object PolyPlusConfig : Config("${PolyPlusConstants.ID}.json", PolyPlusConstants
2929
@JvmStatic @Include
3030
var onboardingFeaturesApplied = false
3131

32+
@JvmStatic @Include
33+
var onboardingSprintApplied = false
34+
3235
@JvmStatic @Include
3336
var onboardingPolyBlurApplied = false
3437

src/main/kotlin/org/polyfrost/polyplus/client/features/OnboardingFeatures.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,26 @@ import org.polyfrost.polyplus.client.PolyPlusConfig
1717
object OnboardingFeatures {
1818
private val logger = LogManager.getLogger("PolyPlus/Onboarding")
1919

20+
val polySprintAvailable: Boolean by lazy { classExists(POLYSPRINT_CONFIG) }
21+
val polyBlurAvailable: Boolean by lazy { classExists(POLYBLUR_CONFIG) }
22+
val evergreenAvailable: Boolean by lazy { classExists(EVERGREEN_FPS) }
23+
24+
val modsPageAvailable: Boolean
25+
get() = polySprintAvailable || polyBlurAvailable || evergreenAvailable
26+
2027
fun initialize() {
21-
val polyBlurAvailable = classExists(POLYBLUR_CONFIG)
22-
val evergreenAvailable = classExists(EVERGREEN_FPS)
2328
eventHandler { _: TickEvent.End ->
2429
if (!PolyPlusConfig.onboardingCompleted) return@eventHandler
2530
var changed = false
2631
if (!PolyPlusConfig.onboardingFeaturesApplied) {
2732
applyCoreSettings()
2833
changed = true
2934
}
35+
if (polySprintAvailable && !PolyPlusConfig.onboardingSprintApplied) {
36+
applyToggleSprint(PolyPlusConfig.onboardingToggleSprint)
37+
PolyPlusConfig.onboardingSprintApplied = true
38+
changed = true
39+
}
3040
if (polyBlurAvailable && !PolyPlusConfig.onboardingPolyBlurApplied) {
3141
if (applyPolyBlur(PolyPlusConfig.onboardingMotionBlur)) {
3242
PolyPlusConfig.onboardingPolyBlurApplied = true
@@ -45,6 +55,10 @@ object OnboardingFeatures {
4555

4656
fun applySavedSettings() {
4757
applyCoreSettings()
58+
if (polySprintAvailable) {
59+
applyToggleSprint(PolyPlusConfig.onboardingToggleSprint)
60+
PolyPlusConfig.onboardingSprintApplied = true
61+
}
4862
if (applyPolyBlur(PolyPlusConfig.onboardingMotionBlur)) {
4963
PolyPlusConfig.onboardingPolyBlurApplied = true
5064
}
@@ -56,7 +70,6 @@ object OnboardingFeatures {
5670

5771
private fun applyCoreSettings() {
5872
applyTheme(PolyPlusConfig.onboardingLightTheme, PolyPlusConfig.onboardingUiStyle)
59-
applyToggleSprint(PolyPlusConfig.onboardingToggleSprint)
6073
PolyPlusConfig.onboardingFeaturesApplied = true
6174
}
6275

@@ -157,6 +170,7 @@ object OnboardingFeatures {
157170
val className: String,
158171
)
159172

173+
private const val POLYSPRINT_CONFIG = "org.polyfrost.polysprint.client.PolySprintConfig"
160174
private const val POLYBLUR_CONFIG = "org.polyfrost.polyblur.client.PolyBlurConfig"
161175
private const val EVERGREEN_FPS = "org.polyfrost.evergreenhud.client.hud.FpsHud"
162176
private const val EVERGREEN_CPS = "org.polyfrost.evergreenhud.client.hud.CpsHud"

src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusCosmeticsScreen.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import org.polyfrost.oneconfig.internal.ui.components.Icon
7474
import org.polyfrost.oneconfig.internal.ui.compose.impls.OneConfigUIScreen
7575
import org.polyfrost.oneconfig.internal.ui.navigation.NavigationGroup
7676
import org.polyfrost.oneconfig.internal.ui.navigation.NavigationRoute
77-
import org.polyfrost.oneconfig.internal.ui.shell.LocalNavController
77+
import org.polyfrost.oneconfig.internal.ui.navigation.graph.ModsGraph
7878
import org.polyfrost.oneconfig.internal.ui.themes.Accent
7979
import org.polyfrost.oneconfig.internal.ui.themes.LocalTheme
8080
import org.polyfrost.polyplus.client.PolyPlusClient
@@ -132,29 +132,30 @@ object PolyPlusOneConfigIntegration {
132132
builder.polyPlusCosmeticsGraph()
133133
}
134134

135+
@Volatile
136+
private var pendingOpeningRoute: Any? = null
137+
138+
@JvmStatic
139+
fun consumePendingOpeningRoute(): Any? {
140+
val route = pendingOpeningRoute
141+
pendingOpeningRoute = null
142+
return route
143+
}
144+
145+
@JvmStatic
146+
fun openCosmetics() = openOneConfig(PolyPlusCosmeticsRoute)
147+
135148
@JvmStatic
136-
fun openCosmetics() {
149+
fun openMods() = openOneConfig(ModsGraph)
150+
151+
private fun openOneConfig(route: Any) {
152+
pendingOpeningRoute = route
137153
val mc = net.minecraft.client.Minecraft.getInstance()
138154
//? if >= 26.2 {
139155
/*mc.gui.setScreen(OneConfigUIScreen())
140156
*///?} else {
141157
mc.setScreen(OneConfigUIScreen())
142158
//?}
143-
Thread({
144-
var attempts = 0
145-
while (attempts++ < 600) {
146-
val ready = LocalNavController.isReady &&
147-
runCatching { LocalNavController.current.graph; true }.getOrDefault(false)
148-
if (ready) {
149-
mc.execute { runCatching { LocalNavController.wrapper.navigate(PolyPlusCosmeticsRoute) } }
150-
return@Thread
151-
}
152-
Thread.sleep(16L)
153-
}
154-
}, "polyplus-open-cosmetics").apply {
155-
isDaemon = true
156-
start()
157-
}
158159
}
159160
}
160161

src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusMainMenuScreen.kt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ import androidx.compose.ui.unit.dp
7575
import androidx.compose.ui.unit.sp
7676
import androidx.compose.ui.window.Popup
7777
import androidx.compose.ui.window.PopupProperties
78+
import kotlinx.coroutines.CoroutineScope
7879
import kotlinx.coroutines.Dispatchers
7980
import kotlinx.coroutines.async
8081
import kotlinx.coroutines.delay
82+
import kotlinx.coroutines.launch
8183
import org.jetbrains.skia.Image as SkiaImage
8284
import org.polyfrost.oneconfig.internal.ui.components.Icon
8385
import org.polyfrost.oneconfig.internal.ui.components.LocalUiOversample
@@ -93,7 +95,6 @@ import org.polyfrost.polyplus.client.gui.preview.PlayerPreview
9395
import org.polyfrost.polyplus.client.gui.preview.PlayerPreviewSource
9496
import org.polyfrost.polyplus.client.utils.ClientPlatform
9597
import java.util.Collections
96-
import java.util.IdentityHashMap
9798
import java.util.concurrent.ConcurrentHashMap
9899

99100
class PolyPlusMainMenuScreen : ComposeScreen(RenderMode.CONTINUOUS) {
@@ -171,7 +172,7 @@ class PolyPlusMainMenuScreen : ComposeScreen(RenderMode.CONTINUOUS) {
171172
var pingTick by remember { mutableStateOf(0) }
172173
LaunchedEffect(servers) {
173174
if (servers.isEmpty()) return@LaunchedEffect
174-
MainMenuServerPings.start(servers)
175+
MainMenuServerPings.start(this, servers)
175176
while (true) {
176177
MainMenuServerPings.tick()
177178
pingTick++
@@ -208,13 +209,7 @@ class PolyPlusMainMenuScreen : ComposeScreen(RenderMode.CONTINUOUS) {
208209
/*mc.setScreen(net.minecraft.client.gui.screens.options.OptionsScreen(this, mc.options))
209210
*///?}
210211
},
211-
mods = {
212-
//? if >= 26.2 {
213-
/*mc.gui.setScreen(org.polyfrost.oneconfig.internal.ui.compose.impls.OneConfigUIScreen())
214-
*///?} else {
215-
mc.setScreen(org.polyfrost.oneconfig.internal.ui.compose.impls.OneConfigUIScreen())
216-
//?}
217-
},
212+
mods = { PolyPlusOneConfigIntegration.openMods() },
218213
fullscreen = { mc.window.toggleFullScreen() },
219214
quit = { mc.stop() },
220215
connect = { server -> connectTo(mc, server) },
@@ -234,18 +229,22 @@ class PolyPlusMainMenuScreen : ComposeScreen(RenderMode.CONTINUOUS) {
234229

235230
private object MainMenuServerPings {
236231
private val pinger = net.minecraft.client.multiplayer.ServerStatusPinger()
237-
private val started = Collections.newSetFromMap(IdentityHashMap<net.minecraft.client.multiplayer.ServerData, Boolean>())
232+
private val started = Collections.newSetFromMap(ConcurrentHashMap<net.minecraft.client.multiplayer.ServerData, Boolean>())
238233

239-
@Synchronized
240-
fun start(servers: List<net.minecraft.client.multiplayer.ServerData>) {
234+
fun start(scope: CoroutineScope, servers: List<net.minecraft.client.multiplayer.ServerData>) {
241235
servers.forEach { data ->
242236
if (started.add(data)) {
243-
//? if >= 1.21.11 {
244-
val elg = net.minecraft.server.network.EventLoopGroupHolder.remote(false)
245-
runCatching { pinger.pingServer(data, Runnable {}, Runnable {}, elg) }
246-
//?} else {
247-
/*runCatching { pinger.pingServer(data, Runnable {}, Runnable {}) }
248-
*///?}
237+
scope.launch(Dispatchers.IO) {
238+
val ok = runCatching {
239+
//? if >= 1.21.11 {
240+
val elg = net.minecraft.server.network.EventLoopGroupHolder.remote(false)
241+
pinger.pingServer(data, Runnable {}, Runnable {}, elg)
242+
//?} else {
243+
/*pinger.pingServer(data, Runnable {}, Runnable {})
244+
*///?}
245+
}.isSuccess
246+
if (!ok) started.remove(data)
247+
}
249248
}
250249
}
251250
}

src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusOnboardingScreen.kt

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ class PolyPlusOnboardingScreen : ComposeScreen(RenderMode.CONTINUOUS) {
104104

105105
@Composable
106106
override fun compose() {
107+
val pages = remember {
108+
buildList {
109+
add(OnboardingPage.LOOK_AND_FEEL)
110+
if (OnboardingFeatures.modsPageAvailable) add(OnboardingPage.MODS)
111+
add(OnboardingPage.COSMETICS)
112+
add(OnboardingPage.DONE)
113+
}
114+
}
107115
var page by remember { mutableIntStateOf(0) }
108116
var lightTheme by remember { mutableStateOf(PolyPlusConfig.onboardingLightTheme) }
109117
var uiStyle by remember { mutableIntStateOf(PolyPlusConfig.onboardingUiStyle) }
@@ -173,30 +181,32 @@ class PolyPlusOnboardingScreen : ComposeScreen(RenderMode.CONTINUOUS) {
173181
.background(PanelBackground)
174182
.border(1.3.dp, PanelBorder, PANEL_SHAPE),
175183
) {
176-
when (page) {
177-
0 -> LookAndFeelPage(lightTheme, { lightTheme = it }, uiStyle, { uiStyle = it }, hudStyle, { hudStyle = it })
178-
1 -> ModsPage(
184+
when (pages[page]) {
185+
OnboardingPage.LOOK_AND_FEEL ->
186+
LookAndFeelPage(lightTheme, { lightTheme = it }, uiStyle, { uiStyle = it }, hudStyle, { hudStyle = it })
187+
OnboardingPage.MODS -> ModsPage(
179188
toggleSprint,
180189
{ toggleSprint = it },
181190
hudSelections,
182191
{ hudSelections = it },
183192
motionBlur,
184193
{ motionBlur = it },
185194
)
186-
2 -> CosmeticsPage(
195+
OnboardingPage.COSMETICS -> CosmeticsPage(
187196
onClaim = { PolyPlusClient.refreshCosmetics() },
188197
onStore = {
189198
finish()
190199
PolyPlusOneConfigIntegration.openCosmetics()
191200
},
192201
)
193-
else -> DonePage()
202+
OnboardingPage.DONE -> DonePage()
194203
}
195204
BottomNavigation(
196205
page,
206+
pages.size,
197207
onSkip = finish,
198208
onBack = { page-- },
199-
onNext = { if (page == PAGE_COUNT - 1) finish() else page++ },
209+
onNext = { if (page == pages.size - 1) finish() else page++ },
200210
)
201211
}
202212
}
@@ -243,13 +253,40 @@ private fun ModsPage(
243253
onMotionBlur: (Int) -> Unit,
244254
) {
245255
Header("Continuing with", "Mods")
246-
SectionLabel("Toggle Sprint", 140f)
247-
Row(Modifier.offset(232.dp, 172.dp), horizontalArrangement = Arrangement.spacedBy(18.dp)) {
256+
val sprint = OnboardingFeatures.polySprintAvailable
257+
val huds = OnboardingFeatures.evergreenAvailable
258+
val blur = OnboardingFeatures.polyBlurAvailable
259+
val heights = buildList {
260+
if (sprint) add(SPRINT_SECTION_HEIGHT)
261+
if (huds) add(HUD_SECTION_HEIGHT)
262+
if (blur) add(BLUR_SECTION_HEIGHT)
263+
}
264+
val total = heights.sum() + SECTION_GAP * (heights.size - 1).coerceAtLeast(0)
265+
var y = CONTENT_TOP + ((CONTENT_BOTTOM - CONTENT_TOP) - total) / 2f
266+
if (sprint) {
267+
SprintSection(y, toggleSprint, onToggleSprint)
268+
y += SPRINT_SECTION_HEIGHT + SECTION_GAP
269+
}
270+
if (huds) {
271+
HudSection(y, hud, onHudChange)
272+
y += HUD_SECTION_HEIGHT + SECTION_GAP
273+
}
274+
if (blur) MotionBlurSection(y, motionBlur, onMotionBlur)
275+
}
276+
277+
@Composable
278+
private fun SprintSection(y: Float, toggleSprint: Boolean, onToggleSprint: (Boolean) -> Unit) {
279+
SectionLabel("Toggle Sprint", y)
280+
Row(Modifier.offset(232.dp, (y + LABEL_HEIGHT).dp), horizontalArrangement = Arrangement.spacedBy(18.dp)) {
248281
ChoiceButton("Enabled", ONBOARDING_ASSETS + "zap.svg", toggleSprint, 198f) { onToggleSprint(true) }
249282
ChoiceButton("Disabled", ONBOARDING_ASSETS + "flash-off.svg", !toggleSprint, 198f) { onToggleSprint(false) }
250283
}
251-
SectionLabel("HUD Mods", 228f)
252-
Column(Modifier.offset(232.dp, 260.dp), verticalArrangement = Arrangement.spacedBy(18.dp)) {
284+
}
285+
286+
@Composable
287+
private fun HudSection(y: Float, hud: HudSelections, onHudChange: (HudSelections) -> Unit) {
288+
SectionLabel("HUD Mods", y)
289+
Column(Modifier.offset(232.dp, (y + LABEL_HEIGHT).dp), verticalArrangement = Arrangement.spacedBy(18.dp)) {
253290
Row(horizontalArrangement = Arrangement.spacedBy(18.dp)) {
254291
ChoiceButton("FPS", ONBOARDING_ASSETS + "play-square.svg", hud.fps, 126f) { onHudChange(hud.copy(fps = !hud.fps)) }
255292
ChoiceButton("CPS", ONBOARDING_ASSETS + "mouse.svg", hud.cps, 126f) { onHudChange(hud.copy(cps = !hud.cps)) }
@@ -261,8 +298,12 @@ private fun ModsPage(
261298
ChoiceButton("Direction", ONBOARDING_ASSETS + "compass.svg", hud.direction, 126f) { onHudChange(hud.copy(direction = !hud.direction)) }
262299
}
263300
}
264-
SectionLabel("Motion Blur", 367f)
265-
Row(Modifier.offset(232.dp, 399.dp), verticalAlignment = Alignment.CenterVertically) {
301+
}
302+
303+
@Composable
304+
private fun MotionBlurSection(y: Float, motionBlur: Int, onMotionBlur: (Int) -> Unit) {
305+
SectionLabel("Motion Blur", y)
306+
Row(Modifier.offset(232.dp, (y + LABEL_HEIGHT).dp), verticalAlignment = Alignment.CenterVertically) {
266307
val thumbSize = 13.dp
267308
var trackWidthPx by remember { mutableStateOf(0f) }
268309
val progress by animateFloatAsState(
@@ -321,7 +362,7 @@ private fun ModsPage(
321362
contentAlignment = Alignment.CenterStart,
322363
) { OnboardingText(motionBlur.toString(), 12, Modifier.padding(start = 8.dp)) }
323364
}
324-
MotionBlurPreview(motionBlur, Modifier.offset(233.5.dp, 442.dp).size(413.dp, 115.dp))
365+
MotionBlurPreview(motionBlur, Modifier.offset(233.5.dp, (y + BLUR_PREVIEW_OFFSET).dp).size(413.dp, BLUR_PREVIEW_HEIGHT.dp))
325366
}
326367

327368
@Composable
@@ -471,15 +512,15 @@ private fun Checkerboard(modifier: Modifier) {
471512
}
472513

473514
@Composable
474-
private fun BottomNavigation(page: Int, onSkip: () -> Unit, onBack: () -> Unit, onNext: () -> Unit) {
515+
private fun BottomNavigation(page: Int, pageCount: Int, onSkip: () -> Unit, onBack: () -> Unit, onNext: () -> Unit) {
475516
if (page == 0) {
476517
ChoiceButton("Skip", MAIN_MENU_ASSETS + "x-close.svg", false, 100f, Modifier.offset(26.dp, 604.dp), onSkip)
477518
} else {
478519
ChoiceButton("Back", "assets/polyplus/ico/left-arrow.svg", false, 100f, Modifier.offset(26.dp, 604.dp), onBack)
479520
}
480-
ChoiceButton(if (page == PAGE_COUNT - 1) "Finish" else "Next", MAIN_MENU_ASSETS + "chevron-right.svg", true, 100f, Modifier.offset(754.dp, 604.dp), onNext)
481-
Row(Modifier.offset(((PANEL_WIDTH - (PAGE_COUNT * 17f - 5f)) / 2f).dp, 614.dp), horizontalArrangement = Arrangement.spacedBy(5.dp), verticalAlignment = Alignment.CenterVertically) {
482-
repeat(PAGE_COUNT) { index ->
521+
ChoiceButton(if (page == pageCount - 1) "Finish" else "Next", MAIN_MENU_ASSETS + "chevron-right.svg", true, 100f, Modifier.offset(754.dp, 604.dp), onNext)
522+
Row(Modifier.offset(((PANEL_WIDTH - (pageCount * 17f - 5f)) / 2f).dp, 614.dp), horizontalArrangement = Arrangement.spacedBy(5.dp), verticalAlignment = Alignment.CenterVertically) {
523+
repeat(pageCount) { index ->
483524
Box(
484525
Modifier.size(if (index == page) 12.dp else 10.dp)
485526
.clip(RoundedCornerShape(8.dp))
@@ -552,6 +593,8 @@ private fun loadOnboardingImage(path: String): SkiaImage? = runCatching {
552593
SkiaImage.makeFromEncoded(bytes)
553594
}.getOrNull()
554595

596+
private enum class OnboardingPage { LOOK_AND_FEEL, MODS, COSMETICS, DONE }
597+
555598
private data class HudSelections(
556599
val fps: Boolean,
557600
val cps: Boolean,
@@ -567,8 +610,17 @@ private const val PANEL_X = 520f
567610
private const val PANEL_Y = 210f
568611
private const val PANEL_WIDTH = 880f
569612
private const val PANEL_HEIGHT = 660f
570-
private const val PAGE_COUNT = 4
571613
private const val MOTION_BLUR_MAX = 10
614+
615+
private const val CONTENT_TOP = 140f
616+
private const val CONTENT_BOTTOM = 557f
617+
private const val SECTION_GAP = 24f
618+
private const val LABEL_HEIGHT = 32f
619+
private const val SPRINT_SECTION_HEIGHT = LABEL_HEIGHT + 32f
620+
private const val HUD_SECTION_HEIGHT = LABEL_HEIGHT + 82f
621+
private const val BLUR_PREVIEW_OFFSET = 75f
622+
private const val BLUR_PREVIEW_HEIGHT = 115f
623+
private const val BLUR_SECTION_HEIGHT = BLUR_PREVIEW_OFFSET + BLUR_PREVIEW_HEIGHT
572624
private const val ONBOARDING_ASSETS = "assets/polyplus/onboarding/"
573625
private const val MAIN_MENU_ASSETS = "assets/polyplus/mainmenu/"
574626
private val PANEL_SHAPE = RoundedCornerShape(10.345.dp)

0 commit comments

Comments
 (0)