Clean up troubleshooter

This commit is contained in:
2025-03-18 22:17:28 +01:00
parent a4ee202971
commit 71ad392fb6

View File

@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:rimworld_modman/mod.dart';
import 'package:rimworld_modman/mod_list.dart';
import 'package:rimworld_modman/mod_list_troubleshooter.dart';
@@ -17,7 +16,8 @@ class ModTroubleshooterWidget extends StatefulWidget {
const ModTroubleshooterWidget({super.key});
@override
State<ModTroubleshooterWidget> createState() => _ModTroubleshooterWidgetState();
State<ModTroubleshooterWidget> createState() =>
_ModTroubleshooterWidgetState();
}
class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
@@ -81,7 +81,9 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
_nextBackwardMove = _troubleshooter.binaryBackwardMove();
} else {
_nextForwardMove = _troubleshooter.linearForwardMove(stepSize: _stepSize);
_nextBackwardMove = _troubleshooter.linearBackwardMove(stepSize: _stepSize);
_nextBackwardMove = _troubleshooter.linearBackwardMove(
stepSize: _stepSize,
);
}
}
@@ -94,7 +96,7 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
}
// Load all required dependencies for the selected mods
final loadOrder = result.loadRequired();
final loadOrder = result.loadRequiredBaseGame();
// Use the mods from the load order result
setState(() {
@@ -112,7 +114,7 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
}
// Load all required dependencies for the selected mods
final loadOrder = result.loadRequired();
final loadOrder = result.loadRequiredBaseGame();
// Use the mods from the load order result
setState(() {
@@ -121,13 +123,6 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
});
}
void _toggleSearchMode() {
setState(() {
_isBinaryMode = !_isBinaryMode;
_updateNextMoves();
});
}
void _markAsGood(String modId) {
setState(() {
_checkedMods.add(modId);
@@ -179,7 +174,9 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
// Save the configuration (we don't have direct access to save method, so show a message)
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('${_selectedMods.length} mods prepared for testing. Please use Save button in the Mods tab to save config.'),
content: Text(
'${_selectedMods.length} mods prepared for testing. Please use Save button in the Mods tab to save config.',
),
backgroundColor: Colors.orange,
duration: const Duration(seconds: 4),
),
@@ -252,12 +249,7 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
}
return Column(
children: [
_buildControlPanel(),
Expanded(
child: _buildModList(),
),
],
children: [_buildControlPanel(), Expanded(child: _buildModList())],
);
}
@@ -266,7 +258,10 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.build, size: AppThemeExtension.of(context).iconSizeLarge * 2),
Icon(
Icons.build,
size: AppThemeExtension.of(context).iconSizeLarge * 2,
),
const SizedBox(height: 16),
Text(
'Troubleshooting',
@@ -299,56 +294,6 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
);
}
Widget _buildInstructionsPanel() {
return Card(
margin: AppThemeExtension.of(context).paddingRegular,
child: Padding(
padding: AppThemeExtension.of(context).paddingRegular,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Mod Troubleshooter',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 8),
Text(
'This tool helps you find problematic mods by testing different combinations. '
'Follow these steps:',
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 8),
Text(
'1. Start RimWorld with the highlighted mods active',
style: Theme.of(context).textTheme.bodyMedium,
),
Text(
'2. If the game works correctly, mark those mods as "Good"',
style: Theme.of(context).textTheme.bodyMedium,
),
Text(
'3. If the problem occurs, use "Forward" or "Backward" to narrow down the problem',
style: Theme.of(context).textTheme.bodyMedium,
),
Text(
'4. Mods marked as "Problem" are more likely to be causing issues',
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 8),
if (_selectedMods.isNotEmpty)
Text(
'Currently testing ${_selectedMods.length} mods',
style: TextStyle(
fontWeight: FontWeight.bold,
color: AppThemeExtension.of(context).enabledModColor,
),
),
],
),
),
);
}
Widget _buildControlPanel() {
return Card(
margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
@@ -379,10 +324,7 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
Row(
children: [
// Binary/Linear mode toggle
Text(
'Mode:',
style: Theme.of(context).textTheme.bodyMedium,
),
Text('Mode:', style: Theme.of(context).textTheme.bodyMedium),
const SizedBox(width: 8),
ToggleButtons(
isSelected: [!_isBinaryMode, _isBinaryMode],
@@ -407,10 +349,7 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
// Step size input field (only for linear mode)
if (!_isBinaryMode) ...[
const SizedBox(width: 16),
Text(
'Step:',
style: Theme.of(context).textTheme.bodyMedium,
),
Text('Step:', style: Theme.of(context).textTheme.bodyMedium),
const SizedBox(width: 4),
SizedBox(
width: 60,
@@ -442,19 +381,33 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
// Buttons to mark selected mods
if (_selectedMods.isNotEmpty) ...[
OutlinedButton.icon(
icon: Icon(Icons.error, color: Colors.red.shade300, size: 16),
icon: Icon(
Icons.error,
color: Colors.red.shade300,
size: 16,
),
label: const Text('Problem'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 0,
),
),
onPressed: _markSelectedAsProblem,
),
const SizedBox(width: 4),
OutlinedButton.icon(
icon: Icon(Icons.check_circle, color: Colors.green.shade300, size: 16),
icon: Icon(
Icons.check_circle,
color: Colors.green.shade300,
size: 16,
),
label: const Text('Good'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 0,
),
),
onPressed: _markSelectedAsGood,
),
@@ -466,7 +419,10 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
icon: const Icon(Icons.refresh, size: 16),
label: const Text('Reset'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 0,
),
),
onPressed: _resetTroubleshooter,
),
@@ -478,7 +434,10 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
icon: const Icon(Icons.save, size: 16),
label: const Text('Save'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 0,
),
),
onPressed: _saveTroubleshootingConfig,
),
@@ -539,11 +498,15 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
bool isInNextForward = false;
bool isInNextBackward = false;
if (_nextForwardMove != null && index >= _nextForwardMove!.startIndex && index < _nextForwardMove!.endIndex) {
if (_nextForwardMove != null &&
index >= _nextForwardMove!.startIndex &&
index < _nextForwardMove!.endIndex) {
isInNextForward = true;
}
if (_nextBackwardMove != null && index >= _nextBackwardMove!.startIndex && index < _nextBackwardMove!.endIndex) {
if (_nextBackwardMove != null &&
index >= _nextBackwardMove!.startIndex &&
index < _nextBackwardMove!.endIndex) {
isInNextBackward = true;
}
@@ -592,51 +555,75 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
children: [
if (isSelected)
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 0,
),
margin: const EdgeInsets.only(right: 4),
decoration: BoxDecoration(
color: Colors.blue.shade800.withOpacity(0.2),
color: const Color(
0x28303F9F,
), // Blue with alpha 40
borderRadius: BorderRadius.circular(4),
),
child: Text(
'TESTING',
style: TextStyle(
color: Colors.blue.shade200,
fontSize: AppThemeExtension.of(context).textSizeSmall,
fontSize:
AppThemeExtension.of(
context,
).textSizeSmall,
fontWeight: FontWeight.bold,
),
),
),
if (isChecked)
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 0,
),
margin: const EdgeInsets.only(right: 4),
decoration: BoxDecoration(
color: Colors.green.shade800.withOpacity(0.2),
color: const Color(
0x1E2E7D32,
), // Green with alpha 30
borderRadius: BorderRadius.circular(4),
),
child: Text(
'GOOD',
style: TextStyle(
color: Colors.green.shade200,
fontSize: AppThemeExtension.of(context).textSizeSmall,
fontSize:
AppThemeExtension.of(
context,
).textSizeSmall,
fontWeight: FontWeight.bold,
),
),
),
if (isProblem)
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 0,
),
margin: const EdgeInsets.only(right: 4),
decoration: BoxDecoration(
color: Colors.red.shade800.withOpacity(0.2),
color: const Color(
0x1EC62828,
), // Red with alpha 30
borderRadius: BorderRadius.circular(4),
),
child: Text(
'PROBLEM',
style: TextStyle(
color: Colors.red.shade200,
fontSize: AppThemeExtension.of(context).textSizeSmall,
fontSize:
AppThemeExtension.of(
context,
).textSizeSmall,
fontWeight: FontWeight.bold,
),
),
@@ -645,7 +632,10 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
child: Text(
mod.name,
style: TextStyle(
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
fontWeight:
isSelected
? FontWeight.bold
: FontWeight.normal,
),
),
),
@@ -666,8 +656,10 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
message: 'Base Game',
child: Icon(
Icons.home,
color: AppThemeExtension.of(context).baseGameColor,
size: AppThemeExtension.of(context).iconSizeSmall,
color:
AppThemeExtension.of(context).baseGameColor,
size:
AppThemeExtension.of(context).iconSizeSmall,
),
),
if (mod.isExpansion)
@@ -675,17 +667,23 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
message: 'Expansion',
child: Icon(
Icons.star,
color: AppThemeExtension.of(context).expansionColor,
size: AppThemeExtension.of(context).iconSizeSmall,
color:
AppThemeExtension.of(
context,
).expansionColor,
size:
AppThemeExtension.of(context).iconSizeSmall,
),
),
if (mod.dependencies.isNotEmpty)
Tooltip(
message: 'Dependencies:\n${mod.dependencies.join('\n')}',
message:
'Dependencies:\n${mod.dependencies.join('\n')}',
child: Icon(
Icons.link,
color: AppThemeExtension.of(context).linkColor,
size: AppThemeExtension.of(context).iconSizeSmall,
size:
AppThemeExtension.of(context).iconSizeSmall,
),
),
@@ -712,27 +710,39 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
// Show navigation indicators
if (isInNextForward)
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.2),
color: const Color(
0x0A2196F3,
), // Blue with alpha 10
borderRadius: BorderRadius.circular(4),
),
child: Tooltip(
message: 'Click to move Forward (test this mod)',
message:
'Click to move Forward (test this mod)',
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.arrow_forward,
color: Colors.blue.shade300,
size: AppThemeExtension.of(context).iconSizeSmall,
size:
AppThemeExtension.of(
context,
).iconSizeSmall,
),
const SizedBox(width: 2),
Text(
'Forward',
style: TextStyle(
color: Colors.blue.shade300,
fontSize: AppThemeExtension.of(context).textSizeSmall,
fontSize:
AppThemeExtension.of(
context,
).textSizeSmall,
),
),
],
@@ -742,27 +752,39 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
if (isInNextBackward)
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
decoration: BoxDecoration(
color: Colors.purple.withOpacity(0.2),
color: const Color(
0x0A9C27B0,
), // Purple with alpha 10
borderRadius: BorderRadius.circular(4),
),
child: Tooltip(
message: 'Click to move Backward (test this mod)',
message:
'Click to move Backward (test this mod)',
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.arrow_back,
color: Colors.purple.shade300,
size: AppThemeExtension.of(context).iconSizeSmall,
size:
AppThemeExtension.of(
context,
).iconSizeSmall,
),
const SizedBox(width: 2),
Text(
'Back',
style: TextStyle(
color: Colors.purple.shade300,
fontSize: AppThemeExtension.of(context).textSizeSmall,
fontSize:
AppThemeExtension.of(
context,
).textSizeSmall,
),
),
],
@@ -791,20 +813,17 @@ class _ModTroubleshooterWidgetState extends State<ModTroubleshooterWidget> {
}) {
// Priority: 1. Selected, 2. Navigation areas, 3. Status
if (isSelected) {
return Colors.blue.shade800.withOpacity(0.3);
return const Color(0x80303F9F);
} else if (isInNextForward && isInNextBackward) {
// Both forward and backward - more obvious purple
return Colors.deepPurple.withOpacity(0.3);
return const Color(0x50673AB7);
} else if (isInNextForward) {
// Forward navigation - more obvious blue
return Colors.blue.withOpacity(0.25);
return const Color(0x402196F3);
} else if (isInNextBackward) {
// Backward navigation - more obvious purple
return Colors.purple.withOpacity(0.25);
return const Color(0x409C27B0);
} else if (isChecked) {
return Colors.green.shade800.withOpacity(0.2);
return const Color(0x802E7D32);
} else if (isProblem) {
return Colors.red.shade800.withOpacity(0.2);
return const Color(0x80C62828);
}
return Colors.transparent;