1
1
package cc.warlock.warlock3.app.ui.settings
2
2
3
- import androidx.compose.foundation.background
4
- import androidx.compose.foundation.gestures.Orientation
5
- import androidx.compose.foundation.gestures.scrollable
3
+ import androidx.compose.foundation.*
6
4
import androidx.compose.foundation.layout.*
7
- import androidx.compose.foundation.rememberScrollState
8
- import androidx.compose.foundation.shape.RoundedCornerShape
9
5
import androidx.compose.material.*
10
6
import androidx.compose.material.icons.Icons
11
7
import androidx.compose.material.icons.filled.Add
12
8
import androidx.compose.material.icons.filled.Delete
13
9
import androidx.compose.material.icons.filled.Edit
14
10
import androidx.compose.material.icons.filled.Palette
15
11
import androidx.compose.runtime.*
12
+ import androidx.compose.ui.Alignment
16
13
import androidx.compose.ui.Modifier
17
- import androidx.compose.ui.draw.clip
18
14
import androidx.compose.ui.graphics.Color
19
- import androidx.compose.ui.text.TextStyle
20
15
import androidx.compose.ui.unit.dp
21
16
import androidx.compose.ui.window.Dialog
22
17
import androidx.compose.ui.window.rememberDialogState
@@ -25,14 +20,11 @@ import cc.warlock.warlock3.app.components.ColorPickerDialog
25
20
import cc.warlock.warlock3.app.util.toColor
26
21
import cc.warlock.warlock3.core.client.GameCharacter
27
22
import cc.warlock.warlock3.core.prefs.HighlightRepository
28
- import cc.warlock.warlock3.core.prefs.PresetRepository
29
- import cc.warlock.warlock3.core.prefs.defaultStyles
30
23
import cc.warlock.warlock3.core.prefs.models.Highlight
31
24
import cc.warlock.warlock3.core.text.*
32
25
import cc.warlock.warlock3.core.util.toWarlockColor
33
26
import kotlinx.coroutines.DelicateCoroutinesApi
34
27
import kotlinx.coroutines.GlobalScope
35
- import kotlinx.coroutines.flow.map
36
28
import kotlinx.coroutines.launch
37
29
import kotlinx.coroutines.runBlocking
38
30
import java.util.*
@@ -43,7 +35,6 @@ fun HighlightsView(
43
35
currentCharacter : GameCharacter ? ,
44
36
allCharacters : List <GameCharacter >,
45
37
highlightRepository : HighlightRepository ,
46
- presetRepository : PresetRepository ,
47
38
) {
48
39
var selectedCharacter by remember(currentCharacter) { mutableStateOf(currentCharacter) }
49
40
val currentCharacterId = selectedCharacter?.id
@@ -54,17 +45,7 @@ fun HighlightsView(
54
45
}
55
46
.collectAsState(emptyList())
56
47
var editingHighlight by remember { mutableStateOf<Highlight ?>(null ) }
57
- var defaultStyle by remember { mutableStateOf(defaultStyles[" default" ]) }
58
- val defaultTextColor = defaultStyle?.textColor?.specifiedOrNull()?.toColor() ? : Color .Unspecified
59
- val defaultBackgroundColor = defaultStyle?.backgroundColor?.toColor() ? : Color .Unspecified
60
- LaunchedEffect (currentCharacterId) {
61
- if (currentCharacterId != null ) {
62
- presetRepository.observePresetsForCharacter(currentCharacterId).map { it[" default" ] }
63
- .collect {
64
- defaultStyle = it
65
- }
66
- }
67
- }
48
+
68
49
Column (Modifier .fillMaxSize()) {
69
50
SettingsCharacterSelector (
70
51
selectedCharacter = selectedCharacter,
@@ -76,14 +57,12 @@ fun HighlightsView(
76
57
Text (text = " Highlights" , style = MaterialTheme .typography.h5)
77
58
Spacer (Modifier .height(8 .dp))
78
59
Column (
79
- Modifier .fillMaxWidth().weight(1f ).background(defaultBackgroundColor).clip( MaterialTheme .shapes.medium)
60
+ Modifier .fillMaxWidth().weight(1f )
80
61
) {
81
62
highlights.forEach { highlight ->
82
- val color = highlight.styles[0 ]?.textColor?.specifiedOrNull()?.toColor() ? : defaultTextColor
83
- val background = highlight.styles[0 ]?.backgroundColor?.toColor() ? : defaultBackgroundColor
84
63
ListItem (
85
64
text = {
86
- Text (text = highlight.pattern, style = TextStyle (color = color, background = background) )
65
+ Text (text = highlight.pattern)
87
66
},
88
67
trailing = {
89
68
Row {
@@ -93,7 +72,6 @@ fun HighlightsView(
93
72
Icon (
94
73
imageVector = Icons .Default .Edit ,
95
74
contentDescription = " Edit" ,
96
- tint = defaultTextColor
97
75
)
98
76
}
99
77
Spacer (Modifier .width(8 .dp))
@@ -105,7 +83,6 @@ fun HighlightsView(
105
83
Icon (
106
84
imageVector = Icons .Default .Delete ,
107
85
contentDescription = " Delete" ,
108
- tint = defaultTextColor
109
86
)
110
87
}
111
88
}
@@ -136,9 +113,8 @@ fun HighlightsView(
136
113
highlight = highlight,
137
114
saveHighlight = { newHighlight ->
138
115
runBlocking {
139
- val characterId = currentCharacter?.id
140
- if (characterId != null ) {
141
- highlightRepository.save(characterId, newHighlight)
116
+ if (currentCharacterId != null ) {
117
+ highlightRepository.save(currentCharacterId, newHighlight)
142
118
} else {
143
119
highlightRepository.saveGlobal(newHighlight)
144
120
}
@@ -163,18 +139,30 @@ fun EditHighlightDialog(
163
139
var ignoreCase by remember { mutableStateOf(highlight.ignoreCase) }
164
140
165
141
Dialog (
166
- state = rememberDialogState(width = 600 .dp, height = 300 .dp),
142
+ state = rememberDialogState(width = 640 .dp, height = 480 .dp),
167
143
onCloseRequest = onClose,
168
144
title = " Edit Highlight"
169
145
) {
170
146
Column (
171
- modifier = Modifier
172
- .scrollable(
173
- state = rememberScrollState(),
174
- orientation = Orientation .Horizontal
175
- )
176
- .padding(24 .dp)
147
+ modifier = Modifier .padding(24 .dp)
177
148
) {
149
+ Row {
150
+ Row (Modifier .clickable { isRegex = false }) {
151
+ RadioButton (
152
+ selected = ! isRegex,
153
+ onClick = { isRegex = false },
154
+ )
155
+ Text (text = " Text highlight" , modifier = Modifier .align(Alignment .CenterVertically ))
156
+ }
157
+ Spacer (Modifier .width(16 .dp))
158
+ Row (Modifier .clickable { isRegex = true }) {
159
+ RadioButton (
160
+ selected = isRegex,
161
+ onClick = { isRegex = true }
162
+ )
163
+ Text (text = " Regex highlight" , modifier = Modifier .align(Alignment .CenterVertically ))
164
+ }
165
+ }
178
166
TextField (value = pattern, label = { Text (" Pattern" ) }, onValueChange = { pattern = it })
179
167
// Add | to match empty string, then match and see how many groups there are
180
168
val groupCount = if (isRegex) try {
@@ -187,43 +175,62 @@ fun EditHighlightDialog(
187
175
styles.add(StyleDefinition ())
188
176
}
189
177
}
190
- Column {
191
- for (i in 0 until groupCount) {
192
- val style = styles[i]
193
- Row {
194
- var textColorValue by remember { mutableStateOf(style.textColor.toHexString() ? : " " ) }
195
- ColorTextField (
196
- label = " Text color" ,
197
- value = textColorValue,
198
- onValueChanged = {
199
- textColorValue = it
200
- it.toWarlockColor()?.let { color ->
201
- styles[i] = style.copy(textColor = color)
202
- }
178
+ Box (modifier = Modifier .fillMaxWidth().weight(1f )) {
179
+ val showScrollbar = groupCount > 1
180
+ val scrollState = rememberScrollState()
181
+ Column (
182
+ modifier = if (showScrollbar) Modifier .verticalScroll(scrollState).padding(end = LocalScrollbarStyle .current.thickness) else Modifier
183
+ ) {
184
+ for (i in 0 until groupCount) {
185
+ val style = styles[i]
186
+ Row {
187
+ if (isRegex) {
188
+ Text (" $i :" , Modifier .align(Alignment .CenterVertically ))
189
+ Spacer (Modifier .width(8 .dp))
203
190
}
204
- )
205
-
206
- Spacer (Modifier .width(16 .dp))
207
- var backgroundColorValue by remember {
208
- mutableStateOf(style.backgroundColor.toHexString() ? : " " )
209
- }
210
- ColorTextField (
211
- label = " Background color" ,
212
- value = backgroundColorValue,
213
- onValueChanged = {
214
- backgroundColorValue = it
215
- it.toWarlockColor()?.let { color ->
216
- styles[i] = style.copy(backgroundColor = color)
191
+ var textColorValue by remember { mutableStateOf(style.textColor.toHexString() ? : " " ) }
192
+ ColorTextField (
193
+ label = " Text color" ,
194
+ value = textColorValue,
195
+ onValueChanged = {
196
+ textColorValue = it
197
+ styles[i] = style.copy(textColor = it.toWarlockColor() ? : WarlockColor .Unspecified )
217
198
}
199
+ )
200
+
201
+ Spacer (Modifier .width(16 .dp))
202
+ var backgroundColorValue by remember {
203
+ mutableStateOf(style.backgroundColor.toHexString() ? : " " )
218
204
}
219
- )
205
+ ColorTextField (
206
+ label = " Background color" ,
207
+ value = backgroundColorValue,
208
+ onValueChanged = {
209
+ backgroundColorValue = it
210
+ styles[i] =
211
+ style.copy(backgroundColor = it.toWarlockColor() ? : WarlockColor .Unspecified )
212
+ }
213
+ )
214
+ }
220
215
}
221
216
}
217
+ if (showScrollbar) {
218
+ VerticalScrollbar (
219
+ adapter = rememberScrollbarAdapter(scrollState),
220
+ modifier = Modifier .align(Alignment .CenterEnd ).fillMaxHeight()
221
+ )
222
+ }
223
+ }
224
+ if (! isRegex) {
222
225
Row {
223
226
Checkbox (checked = matchPartialWord, onCheckedChange = { matchPartialWord = it })
224
- Text (" Match partial words" )
227
+ Text (text = " Match partial words" , modifier = Modifier .align( Alignment . CenterVertically ) )
225
228
}
226
229
}
230
+ Row {
231
+ Checkbox (checked = ignoreCase, onCheckedChange = { ignoreCase = it })
232
+ Text (text = " Ignore case" , modifier = Modifier .align(Alignment .CenterVertically ))
233
+ }
227
234
Row (
228
235
modifier = Modifier .fillMaxWidth(),
229
236
horizontalArrangement = Arrangement .End
@@ -275,7 +282,7 @@ fun ColorTextField(
275
282
value = value,
276
283
onValueChange = {
277
284
onValueChanged(it)
278
- invalidColor = it.toWarlockColor() == null
285
+ invalidColor = it.toWarlockColor() == null && it.isNotEmpty()
279
286
},
280
287
trailingIcon = {
281
288
IconButton (
@@ -294,8 +301,7 @@ fun ColorTextField(
294
301
isError = invalidColor
295
302
)
296
303
editColor?.let { (colorText, setColor) ->
297
- val color = colorText.toWarlockColor() ? : WarlockColor .Unspecified
298
- val initialColor = if (color.isUnspecified()) Color .Black else color.toColor()
304
+ val initialColor = colorText.toWarlockColor()?.specifiedOrNull()?.toColor() ? : Color .Black
299
305
ColorPickerDialog (
300
306
initialColor = initialColor,
301
307
onCloseRequest = { editColor = null },
0 commit comments