summaryrefslogtreecommitdiff
path: root/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/ui/ArcadeControls.kt
blob: f5b4839c30583abb137941433e7607808101ce1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package coffee.liz.abstractionengine.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun ArcadeControls(
    onDirectionPressed: (Direction) -> Unit,
    onActionA: () -> Unit,
    onActionB: () -> Unit,
    modifier: Modifier = Modifier,
    gameContent: @Composable BoxScope.() -> Unit = {
        // Default placeholder content
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(16.dp)
        ) {
            Text(
                text = "GAME AREA",
                fontSize = 18.sp,
                fontWeight = FontWeight.Bold,
                fontFamily = FontFamily.Monospace,
                color = MaterialTheme.colorScheme.onPrimary
            )
        }
    }
) {
    var lastDirection by remember { mutableStateOf<Direction?>(null) }
    var lastAction by remember { mutableStateOf<String?>(null) }

    Box(modifier = modifier.fillMaxSize()) {
        // PCB background layer
        PCBBackground()

        // Transparent casing overlay
        Box(
            modifier = Modifier
                .fillMaxSize()
                .background(Color(0x33000000))
        )

        // Content
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(16.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(16.dp)
        ) {
        // Game area (square)
        Box(
            modifier = Modifier
                .fillMaxWidth(0.95f)
                .aspectRatio(1f)
                .background(
                    color = GameBoyColors.ScreenGreen.copy(alpha = 0.85f),
                    shape = RoundedCornerShape(8.dp)
                )
                .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(8.dp))
                .padding(8.dp),
            contentAlignment = Alignment.Center,
            content = gameContent
        )

        // Control panel
        Box(
            modifier = Modifier
                .fillMaxWidth(0.95f)
                .background(
                    color = MaterialTheme.colorScheme.surface.copy(alpha = 0.7f),
                    shape = RoundedCornerShape(16.dp)
                )
                .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(16.dp))
                .padding(horizontal = 16.dp, vertical = 16.dp),
            contentAlignment = Alignment.Center
        ) {
            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceEvenly,
                verticalAlignment = Alignment.CenterVertically
            ) {
                // D-Pad on the left
                DPad(
                    onDirectionPressed = { direction ->
                        lastDirection = direction
                        lastAction = null
                        onDirectionPressed(direction)
                    }
                )

                // Action buttons on the right
                Row(
                    horizontalArrangement = Arrangement.spacedBy(12.dp)
                ) {
                    ArcadeButton(
                        label = "B",
                        color = ArcadeButtonColor.YELLOW,
                        onClick = {
                            lastAction = "B"
                            lastDirection = null
                            onActionB()
                        }
                    )
                    ArcadeButton(
                        label = "A",
                        color = ArcadeButtonColor.RED,
                        onClick = {
                            lastAction = "A"
                            lastDirection = null
                            onActionA()
                        }
                    )
                }
            }
        }
        }
    }
}