Skip to content

Commit 0550187

Browse files
committed
Partially finished implementing mod delete dialog.
1 parent 6c4092f commit 0550187

File tree

2 files changed

+129
-58
lines changed

2 files changed

+129
-58
lines changed

lib/thirdparty/faded_scrollable/faded_scrollable.dart

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ class FadedScrollable extends StatefulWidget {
133133

134134
class _FadedScrollableState extends State<FadedScrollable> {
135135
double scrollRatio = 0;
136+
bool _isScrollable = false;
136137

137138
_GradientConfig _getGradientConfig() {
138139
final double upperStop = widget.maxTopScreenRatioFade;
139140
final double lowerStop = 1 - widget.maxBottomScreenRatioFade;
140141

141-
final bool shouldFadeTop = scrollRatio > widget.scrollRatioStart;
142-
final bool shouldFadeBottom = scrollRatio < widget.scrollRatioEnd;
142+
final bool shouldFadeTop =
143+
_isScrollable && scrollRatio > widget.scrollRatioStart;
144+
final bool shouldFadeBottom =
145+
_isScrollable && scrollRatio < widget.scrollRatioEnd;
146+
143147
final List<double> stops = [];
144148
final List<Color> colors = [];
145149

@@ -182,28 +186,38 @@ class _FadedScrollableState extends State<FadedScrollable> {
182186

183187
return NotificationListener<ScrollNotification>(
184188
onNotification: (notification) {
185-
if (notification is ScrollUpdateNotification) {
189+
if (notification is ScrollUpdateNotification ||
190+
notification is ScrollMetricsNotification) {
191+
final metrics = notification.metrics;
192+
final maxExtent = metrics.maxScrollExtent;
193+
194+
final bool isScrollableNow = maxExtent > 0;
195+
final double ratio = isScrollableNow
196+
? (metrics.pixels / maxExtent).clamp(0.0, 1.0)
197+
: 1.0;
198+
186199
setState(() {
187-
scrollRatio =
188-
notification.metrics.pixels /
189-
notification.metrics.maxScrollExtent;
200+
_isScrollable = isScrollableNow;
201+
scrollRatio = ratio;
190202
});
191203
}
192204

193205
return true;
194206
},
195-
child: ShaderMask(
196-
shaderCallback: (Rect rect) {
197-
return LinearGradient(
198-
begin: Alignment.topCenter,
199-
end: Alignment.bottomCenter,
200-
colors: gradientConfig.colors,
201-
stops: gradientConfig.stops,
202-
).createShader(rect);
203-
},
204-
blendMode: BlendMode.dstOut,
205-
child: widget.child,
206-
),
207+
child: gradientConfig.colors.isEmpty
208+
? widget.child
209+
: ShaderMask(
210+
shaderCallback: (Rect rect) {
211+
return LinearGradient(
212+
begin: Alignment.topCenter,
213+
end: Alignment.bottomCenter,
214+
colors: gradientConfig.colors,
215+
stops: gradientConfig.stops,
216+
).createShader(rect);
217+
},
218+
blendMode: BlendMode.dstOut,
219+
child: widget.child,
220+
),
207221
);
208222
}
209223
}

lib/utils/dialogs.dart

Lines changed: 97 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:open_filex/open_filex.dart';
88
import 'package:path/path.dart' as p;
99
import 'package:trios/about/about_page.dart';
1010
import 'package:trios/models/mod_variant.dart';
11+
import 'package:trios/thirdparty/dartx/iterable.dart';
1112
import 'package:trios/thirdparty/faded_scrollable/faded_scrollable.dart';
1213
import 'package:trios/trios/app_state.dart';
1314
import 'package:trios/trios/constants.dart';
@@ -139,6 +140,7 @@ Future<void> showDeleteModFoldersConfirmationDialog(
139140
bool allowDeletingEnabledMods =
140141
allowDeletingEnabledModsDefaultState ?? false;
141142
List<ModVariant> filteredVariantsToDelete = variantsToDelete;
143+
List<ModVariant> enabledVariantsThatWillNotBeDeleted = [];
142144

143145
final shouldDelete = await showDialog<bool>(
144146
context: context,
@@ -148,14 +150,26 @@ Future<void> showDeleteModFoldersConfirmationDialog(
148150
return StatefulBuilder(
149151
builder: (context, setState) {
150152
final allMods = ref.read(AppState.mods);
151-
filteredVariantsToDelete = variantsToDelete
152-
.where(
153-
(variant) => allowDeletingEnabledMods
154-
? true
155-
: !variant.isEnabled(allMods),
156-
)
153+
154+
final isOnlyEnabledMods = variantsToDelete.all(
155+
(variant) => variant.isEnabled(allMods),
156+
);
157+
158+
enabledVariantsThatWillNotBeDeleted =
159+
(isOnlyEnabledMods || allowDeletingEnabledMods)
160+
? []
161+
: variantsToDelete
162+
.where((variant) => !variant.isEnabled(allMods))
163+
.toList();
164+
165+
filteredVariantsToDelete =
166+
variantsToDelete - enabledVariantsThatWillNotBeDeleted;
167+
168+
final enabledVariants = variantsToDelete
169+
.where((variant) => variant.isEnabled(allMods))
157170
.toList();
158-
final s = filteredVariantsToDelete.length > 1 ? "s" : "";
171+
172+
final s = filteredVariantsToDelete.length == 1 ? "s" : "";
159173

160174
return AlertDialog(
161175
title: Text('Delete Mod$s'),
@@ -166,7 +180,9 @@ Future<void> showDeleteModFoldersConfirmationDialog(
166180
crossAxisAlignment: CrossAxisAlignment.start,
167181
spacing: 8,
168182
children: [
169-
const Text('Are you sure you want to delete:'),
183+
if (filteredVariantsToDelete.isNotEmpty ||
184+
isOnlyEnabledMods)
185+
const Text('Are you sure you want to delete:'),
170186
Flexible(
171187
child: FadedScrollable(
172188
child: Scrollbar(
@@ -182,47 +198,61 @@ Future<void> showDeleteModFoldersConfirmationDialog(
182198
children: [
183199
for (final variant
184200
in filteredVariantsToDelete)
185-
Column(
186-
mainAxisSize: MainAxisSize.min,
187-
crossAxisAlignment:
188-
CrossAxisAlignment.start,
189-
children: [
190-
Text(
191-
"• ${variant.modInfo.nameOrId} v${variant.modInfo.version}",
192-
style: theme.textTheme.labelLarge,
193-
),
194-
Text(
195-
" ${variant.modFolder.path}",
196-
style: theme.textTheme.labelMedium
197-
?.copyWith(
198-
color: theme
199-
.textTheme
200-
.bodyMedium
201-
?.color
202-
?.withAlpha(200),
203-
),
201+
_buildVariantToDeleteRow(variant, theme),
202+
if (enabledVariantsThatWillNotBeDeleted
203+
.isNotEmpty)
204+
Padding(
205+
padding: const .only(top: 16),
206+
child: Text.rich(
207+
TextSpan(
208+
style: theme.textTheme.bodyLarge
209+
?.copyWith(fontSize: 20),
210+
children: [
211+
TextSpan(
212+
text:
213+
"The following mods will ",
214+
),
215+
TextSpan(
216+
text: "not",
217+
style: theme
218+
.textTheme
219+
.bodyMedium
220+
?.copyWith(
221+
fontSize: 20,
222+
fontWeight: .bold,
223+
),
224+
),
225+
TextSpan(
226+
text:
227+
" be deleted because they are enabled:",
228+
),
229+
],
204230
),
205-
],
231+
),
206232
),
233+
for (final variant
234+
in enabledVariantsThatWillNotBeDeleted)
235+
_buildVariantToDeleteRow(variant, theme),
207236
],
208237
),
209238
),
210239
),
211240
),
212241
),
213242
),
214-
CheckboxWithLabel(
215-
label: "Allow deleting of currently-enabled mods",
216-
value: allowDeletingEnabledMods,
217-
onChanged: (newValue) {
218-
setState(() {
219-
allowDeletingEnabledMods =
220-
newValue ??
221-
allowDeletingEnabledModsDefaultState ??
222-
false;
223-
});
224-
},
225-
),
243+
if (!isOnlyEnabledMods && enabledVariants.isNotEmpty)
244+
CheckboxWithLabel(
245+
label: "Allow deleting of currently-enabled mods",
246+
value: allowDeletingEnabledMods,
247+
onChanged: (newValue) {
248+
setState(() {
249+
allowDeletingEnabledMods =
250+
newValue ??
251+
allowDeletingEnabledModsDefaultState ??
252+
false;
253+
});
254+
},
255+
),
226256
Text(
227257
"This will delete the mod folder$s on disk. This action cannot be undone.",
228258
style: theme.textTheme.bodyMedium?.copyWith(
@@ -267,3 +297,30 @@ Future<void> showDeleteModFoldersConfirmationDialog(
267297
},
268298
);
269299
}
300+
301+
Row _buildVariantToDeleteRow(ModVariant variant, ThemeData theme) {
302+
return Row(
303+
children: [
304+
Checkbox(value: true, onChanged: (newValue) {}),
305+
Padding(
306+
padding: const .only(left: 4),
307+
child: Column(
308+
mainAxisSize: MainAxisSize.min,
309+
crossAxisAlignment: CrossAxisAlignment.start,
310+
children: [
311+
Text(
312+
"${variant.modInfo.nameOrId} v${variant.modInfo.version}",
313+
style: theme.textTheme.labelLarge,
314+
),
315+
Text(
316+
variant.modFolder.path,
317+
style: theme.textTheme.labelMedium?.copyWith(
318+
color: theme.textTheme.bodyMedium?.color?.withAlpha(200),
319+
),
320+
),
321+
],
322+
),
323+
),
324+
],
325+
);
326+
}

0 commit comments

Comments
 (0)