package com.ea.ironmonkey import androidx.compose.animation.AnimatedVisibility import androidx.compose.material3.AlertDialog import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import nfs.mod.mpcore.GameEventListener import nfs.mod.mpcore.GameEvents // See DEBUG_MENU.md for the full design. Local-only Compose state for now - // Apply doesn't touch any game memory, no real balance getter/setter has // been located yet (see DEBUG_MENU.md ยง3). Exists purely so the debug panel // has something to edit while that RE work is pending. object DebugMoneyState { var amount by mutableStateOf(0L) private set fun apply(newAmount: Long) { amount = newAmount } } // Same GameEventListener-as-Compose-state adapter shape as CarSelectionState // (CarSelectionOverlay.kt) - tracks whether the map has loaded at least once // this session, which is when the debug button should appear. object DebugMenuVisibility : GameEventListener { var mapLoaded by mutableStateOf(false) private set override fun onMapLoaded() { mapLoaded = true } } // Call once, e.g. from GameActivityMain.onCreate, to start receiving // onMapLoaded into DebugMenuVisibility. fun registerDebugMenuListener() { GameEvents.register(DebugMenuVisibility) } @Composable fun DebugMenuButton(visible: Boolean, modifier: Modifier = Modifier) { var dialogOpen by remember { mutableStateOf(false) } AnimatedVisibility(visible = visible, modifier = modifier) { FloatingActionButton(onClick = { dialogOpen = true }) { Text("DBG") } } if (dialogOpen) { DebugMoneyDialog(onDismiss = { dialogOpen = false }) } } @Composable private fun DebugMoneyDialog(onDismiss: () -> Unit) { var text by remember { mutableStateOf(DebugMoneyState.amount.toString()) } AlertDialog( onDismissRequest = onDismiss, title = { Text("Debug: Money") }, text = { OutlinedTextField( value = text, onValueChange = { input -> text = input.filter(Char::isDigit) }, label = { Text("Amount") }, singleLine = true, ) }, confirmButton = { TextButton(onClick = { DebugMoneyState.apply(text.toLongOrNull() ?: DebugMoneyState.amount) onDismiss() }) { Text("Apply") } }, dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } }, ) }