Fix up the display a little

Cleanup crew
This commit is contained in:
2025-03-15 23:43:02 +01:00
parent 22ec31c2a7
commit 3c1e949b0d
2 changed files with 190 additions and 195 deletions

View File

@@ -95,7 +95,8 @@ class _ModListPageState extends State<ModListPage> {
bool _isLoading = false; bool _isLoading = false;
String _loadingStatus = ''; String _loadingStatus = '';
int _totalModsFound = 0; int _totalModsFound = 0;
bool _skipFileCount = false; // Skip file counting by default for faster loading bool _skipFileCount =
false; // Skip file counting by default for faster loading
@override @override
void initState() { void initState() {
@@ -119,9 +120,10 @@ class _ModListPageState extends State<ModListPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: _loadedMods.isEmpty && !_isLoading body:
? _buildEmptyState() _loadedMods.isEmpty && !_isLoading
: _buildModList(), ? _buildEmptyState()
: _buildModList(),
); );
} }
@@ -198,7 +200,10 @@ class _ModListPageState extends State<ModListPage> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
final mod = _loadedMods[index]; final mod = _loadedMods[index];
return Card( return Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), margin: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
),
child: ListTile( child: ListTile(
title: Text(mod.name), title: Text(mod.name),
subtitle: Text( subtitle: Text(
@@ -211,12 +216,20 @@ class _ModListPageState extends State<ModListPage> {
if (mod.isBaseGame) if (mod.isBaseGame)
Tooltip( Tooltip(
message: 'Base Game', message: 'Base Game',
child: Icon(Icons.home, color: Colors.blue, size: 16), child: Icon(
Icons.home,
color: Colors.blue,
size: 16,
),
), ),
if (mod.isExpansion) if (mod.isExpansion)
Tooltip( Tooltip(
message: 'Expansion', message: 'Expansion',
child: Icon(Icons.star, color: Colors.yellow, size: 16), child: Icon(
Icons.star,
color: Colors.yellow,
size: 16,
),
), ),
Icon( Icon(
Icons.circle, Icons.circle,
@@ -262,22 +275,25 @@ class _ModListPageState extends State<ModListPage> {
}); });
// Use the simplified loading approach // Use the simplified loading approach
modManager.loadWithConfig(skipFileCount: _skipFileCount).then((_) { modManager
setState(() { .loadWithConfig(skipFileCount: _skipFileCount)
_loadedMods = modManager.mods.values.toList(); .then((_) {
_isLoading = false; setState(() {
_loadingStatus = modManager.loadingStatus; _loadedMods = modManager.mods.values.toList();
_totalModsFound = modManager.totalModsFound; _isLoading = false;
_loadingStatus = modManager.loadingStatus;
_totalModsFound = modManager.totalModsFound;
// Sort mods by name for better display // Sort mods by name for better display
_loadedMods.sort((a, b) => a.name.compareTo(b.name)); _loadedMods.sort((a, b) => a.name.compareTo(b.name));
}); });
}).catchError((error) { })
setState(() { .catchError((error) {
_isLoading = false; setState(() {
_loadingStatus = 'Error loading mods: $error'; _isLoading = false;
}); _loadingStatus = 'Error loading mods: $error';
}); });
});
} }
} }
@@ -342,7 +358,8 @@ class _LoadOrderPageState extends State<LoadOrderPage> {
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
ElevatedButton( ElevatedButton(
onPressed: _isLoading || _sortedMods.isEmpty ? null : _saveModOrder, onPressed:
_isLoading || _sortedMods.isEmpty ? null : _saveModOrder,
child: const Text('Save Load Order'), child: const Text('Save Load Order'),
), ),
], ],
@@ -360,9 +377,10 @@ class _LoadOrderPageState extends State<LoadOrderPage> {
_statusMessage, _statusMessage,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: _hasCycles || _incompatibleMods.isNotEmpty color:
? Colors.orange _hasCycles || _incompatibleMods.isNotEmpty
: Colors.green, ? Colors.orange
: Colors.green,
), ),
), ),
], ],
@@ -375,9 +393,10 @@ class _LoadOrderPageState extends State<LoadOrderPage> {
child: Text( child: Text(
_statusMessage, _statusMessage,
style: TextStyle( style: TextStyle(
color: _hasCycles || _incompatibleMods.isNotEmpty color:
? Colors.orange _hasCycles || _incompatibleMods.isNotEmpty
: Colors.green, ? Colors.orange
: Colors.green,
), ),
), ),
), ),
@@ -399,13 +418,18 @@ class _LoadOrderPageState extends State<LoadOrderPage> {
'Incompatible mods detected:', 'Incompatible mods detected:',
style: TextStyle(color: Colors.orange), style: TextStyle(color: Colors.orange),
), ),
...List.generate(_incompatibleMods.length > 5 ? 5 : _incompatibleMods.length, (index) { ...List.generate(
final pair = _incompatibleMods[index]; _incompatibleMods.length > 5
return Text( ? 5
'- ${modManager.mods[pair[0]]?.name} and ${modManager.mods[pair[1]]?.name}', : _incompatibleMods.length,
style: TextStyle(color: Colors.orange), (index) {
); final pair = _incompatibleMods[index];
}), return Text(
'- ${modManager.mods[pair[0]]?.name} and ${modManager.mods[pair[1]]?.name}',
style: TextStyle(color: Colors.orange),
);
},
),
if (_incompatibleMods.length > 5) if (_incompatibleMods.length > 5)
Text('...and ${_incompatibleMods.length - 5} more'), Text('...and ${_incompatibleMods.length - 5} more'),
], ],
@@ -419,144 +443,113 @@ class _LoadOrderPageState extends State<LoadOrderPage> {
color: Colors.grey.withOpacity(0.1), color: Colors.grey.withOpacity(0.1),
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text('Legend:', style: TextStyle(fontWeight: FontWeight.bold)),
const SizedBox(height: 4),
Row(
children: [
Icon(Icons.home, color: Colors.blue, size: 16),
const SizedBox(width: 4),
Text('Base Game', style: TextStyle(fontSize: 12)),
const SizedBox(width: 12),
Icon(Icons.star, color: Colors.yellow, size: 16),
const SizedBox(width: 4),
Text('Expansion', style: TextStyle(fontSize: 12)),
],
),
const SizedBox(height: 4),
Row(
children: [
Icon(Icons.link, color: Colors.orange, size: 16),
const SizedBox(width: 4),
Text('Hard dependencies', style: TextStyle(fontSize: 12)),
const SizedBox(width: 12),
Icon(Icons.link_off, color: Colors.blue, size: 16),
const SizedBox(width: 4),
Text('Soft dependencies', style: TextStyle(fontSize: 12)),
],
),
const SizedBox(height: 4),
Row(
children: [
Icon(Icons.arrow_forward, color: Colors.green, size: 16),
const SizedBox(width: 4),
Text('Loads before other mods', style: TextStyle(fontSize: 12)),
],
),
const SizedBox(height: 4),
Row(
children: [
Container(width: 12, height: 12, color: Colors.amber),
const SizedBox(width: 4),
Text('Very large mod (>1000 files)', style: TextStyle(fontSize: 12)),
const SizedBox(width: 12),
Container(width: 12, height: 12, color: Colors.yellow.shade600),
const SizedBox(width: 4),
Text('Large mod (>500 files)', style: TextStyle(fontSize: 12)),
],
),
],
),
), ),
Expanded( Expanded(
child: _sortedMods.isEmpty child:
? Center( _sortedMods.isEmpty
child: Text( ? Center(
modManager.modsLoaded child: Text(
? 'Click "Auto-sort Mods" to generate a load order for ${modManager.mods.length} loaded mods.' modManager.modsLoaded
: 'Please go to the Mods tab first to load mods.', ? 'Click "Auto-sort Mods" to generate a load order for ${modManager.mods.length} loaded mods.'
textAlign: TextAlign.center, : 'Please go to the Mods tab first to load mods.',
textAlign: TextAlign.center,
),
)
: ListView.builder(
itemCount: _sortedMods.length,
itemBuilder: (context, index) {
final mod = _sortedMods[index];
return Card(
margin: const EdgeInsets.symmetric(vertical: 4),
child: ListTile(
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('${index + 1}'),
const SizedBox(height: 2),
if (mod.size > 0)
Tooltip(
message: 'This mod contains ${mod.size} files.',
child: Text(
'${mod.size}',
style: TextStyle(
fontSize: 10,
color: Colors.grey,
),
),
),
],
),
title: Text(mod.name),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(mod.id, style: TextStyle(fontSize: 12)),
],
),
isThreeLine:
mod.hardDependencies.isNotEmpty ||
mod.loadAfter.isNotEmpty ||
mod.loadBefore.isNotEmpty,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (mod.isBaseGame)
Tooltip(
message: 'Base Game',
child: Icon(
Icons.home,
color: Colors.blue,
size: 24,
),
),
if (mod.isExpansion)
Tooltip(
message: 'Expansion',
child: Icon(
Icons.star,
color: Colors.yellow,
size: 24,
),
),
if (mod.hardDependencies.isNotEmpty)
Tooltip(
message:
'Hard dependencies:\n${mod.hardDependencies.join('\n')}',
child: Icon(
Icons.link,
color: Colors.orange,
size: 24,
),
),
const SizedBox(width: 4),
if (mod.loadAfter.isNotEmpty)
Tooltip(
message:
'Loads after other mods:\n${mod.loadAfter.join('\n')}',
child: Icon(
Icons.arrow_back,
color: Colors.blue,
size: 24,
),
),
const SizedBox(width: 4),
if (mod.loadBefore.isNotEmpty)
Tooltip(
message:
'Loads before other mods:\n${mod.loadBefore.join('\n')}',
child: Icon(
Icons.arrow_forward,
color: Colors.green,
size: 24,
),
),
],
),
),
);
},
), ),
)
: ListView.builder(
itemCount: _sortedMods.length,
itemBuilder: (context, index) {
final mod = _sortedMods[index];
return Card(
margin: const EdgeInsets.symmetric(vertical: 4),
child: ListTile(
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('${index + 1}'),
const SizedBox(height: 2),
if (mod.size > 0) Text('${mod.size}', style: TextStyle(fontSize: 10, color: Colors.grey)),
],
),
title: Text(mod.name),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(mod.id, style: TextStyle(fontSize: 10)),
if (mod.hardDependencies.isNotEmpty)
Text(
'Hard dependencies: ${mod.hardDependencies.length}',
style: TextStyle(fontSize: 10, color: Colors.orange),
),
if (mod.softDependencies.isNotEmpty)
Text(
'Soft dependencies: ${mod.softDependencies.length}',
style: TextStyle(fontSize: 10, color: Colors.blue),
),
],
),
isThreeLine: mod.hardDependencies.isNotEmpty || mod.softDependencies.isNotEmpty,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (mod.isBaseGame)
Tooltip(
message: 'Base Game',
child: Icon(Icons.home, color: Colors.blue, size: 16),
),
if (mod.isExpansion)
Tooltip(
message: 'Expansion',
child: Icon(Icons.star, color: Colors.yellow, size: 16),
),
if (mod.hardDependencies.isNotEmpty)
Icon(Icons.link, color: Colors.orange, size: 16),
const SizedBox(width: 4),
if (mod.softDependencies.isNotEmpty)
Icon(Icons.link_off, color: Colors.blue, size: 16),
const SizedBox(width: 4),
if (mod.loadBefore.isNotEmpty)
Tooltip(
message: 'Loads before other mods',
child: Icon(Icons.arrow_forward, color: Colors.green, size: 16),
),
const SizedBox(width: 4),
Text(
'${mod.size} files',
style: TextStyle(
fontSize: 12,
fontWeight: mod.size > 1000 ? FontWeight.bold : FontWeight.normal,
color: mod.size > 1000
? Colors.amber
: mod.size > 500
? Colors.yellow.shade600
: Colors.grey,
),
),
],
),
),
);
},
),
), ),
], ],
), ),
@@ -567,7 +560,8 @@ class _LoadOrderPageState extends State<LoadOrderPage> {
void _sortMods() async { void _sortMods() async {
if (modManager.mods.isEmpty) { if (modManager.mods.isEmpty) {
setState(() { setState(() {
_statusMessage = 'No mods have been loaded yet. Please go to the Mods tab and load mods first.'; _statusMessage =
'No mods have been loaded yet. Please go to the Mods tab and load mods first.';
}); });
return; return;
} }
@@ -609,7 +603,8 @@ class _LoadOrderPageState extends State<LoadOrderPage> {
_statusMessage += ' Warning: Dependency cycles were found and fixed.'; _statusMessage += ' Warning: Dependency cycles were found and fixed.';
} }
if (_incompatibleMods.isNotEmpty) { if (_incompatibleMods.isNotEmpty) {
_statusMessage += ' Warning: ${_incompatibleMods.length} incompatible mod pairs found.'; _statusMessage +=
' Warning: ${_incompatibleMods.length} incompatible mod pairs found.';
} }
}); });
} catch (e) { } catch (e) {

View File

@@ -27,7 +27,7 @@ class Mod {
final List<String> versions; // ModMetaData.supportedVersions final List<String> versions; // ModMetaData.supportedVersions
final String description; // ModMetaData.description final String description; // ModMetaData.description
final List<String> hardDependencies; // ModMetaData.modDependencies final List<String> hardDependencies; // ModMetaData.modDependencies
final List<String> softDependencies; // ModMetaData.loadAfter final List<String> loadAfter; // ModMetaData.loadAfter
final List<String> loadBefore; // ModMetaData.loadBefore final List<String> loadBefore; // ModMetaData.loadBefore
final List<String> incompatabilities; // ModMetaData.incompatibleWith final List<String> incompatabilities; // ModMetaData.incompatibleWith
final bool enabled; // ConfigFile.mods.firstWhere((mod) => mod.id == id).enabled final bool enabled; // ConfigFile.mods.firstWhere((mod) => mod.id == id).enabled
@@ -42,7 +42,7 @@ class Mod {
required this.versions, required this.versions,
required this.description, required this.description,
required this.hardDependencies, required this.hardDependencies,
required this.softDependencies, required this.loadAfter,
required this.loadBefore, required this.loadBefore,
required this.incompatabilities, required this.incompatabilities,
required this.enabled, required this.enabled,
@@ -127,9 +127,9 @@ class Mod {
// Silent error for optional element // Silent error for optional element
} }
List<String> softDependencies = []; List<String> loadAfter = [];
try { try {
softDependencies = loadAfter =
metadata metadata
.findElements('loadAfter') .findElements('loadAfter')
.first .first
@@ -188,8 +188,8 @@ class Mod {
bool isExpansion = !isBaseGame && id.startsWith('ludeon.rimworld.'); bool isExpansion = !isBaseGame && id.startsWith('ludeon.rimworld.');
// If this is an expansion, ensure it depends on the base game // If this is an expansion, ensure it depends on the base game
if (isExpansion && !softDependencies.contains('ludeon.rimworld')) { if (isExpansion && !loadAfter.contains('ludeon.rimworld')) {
softDependencies.add('ludeon.rimworld'); loadAfter.add('ludeon.rimworld');
} }
final fileCountTime = final fileCountTime =
@@ -208,7 +208,7 @@ class Mod {
versions: versions, versions: versions,
description: description, description: description,
hardDependencies: hardDependencies, hardDependencies: hardDependencies,
softDependencies: softDependencies, loadAfter: loadAfter,
loadBefore: loadBefore, loadBefore: loadBefore,
incompatabilities: incompatabilities, incompatabilities: incompatabilities,
enabled: false, enabled: false,
@@ -267,7 +267,7 @@ class ModList {
description: isBaseGame ? "RimWorld base game" : description: isBaseGame ? "RimWorld base game" :
isExpansion ? "RimWorld expansion" : "", isExpansion ? "RimWorld expansion" : "",
hardDependencies: [], hardDependencies: [],
softDependencies: isExpansion ? ['ludeon.rimworld'] : [], loadAfter: isExpansion ? ['ludeon.rimworld'] : [],
loadBefore: [], loadBefore: [],
incompatabilities: [], incompatabilities: [],
enabled: true, enabled: true,
@@ -319,7 +319,7 @@ class ModList {
versions: mod.versions, versions: mod.versions,
description: mod.description, description: mod.description,
hardDependencies: mod.hardDependencies, hardDependencies: mod.hardDependencies,
softDependencies: mod.softDependencies, loadAfter: mod.loadAfter,
loadBefore: mod.loadBefore, loadBefore: mod.loadBefore,
incompatabilities: mod.incompatabilities, incompatabilities: mod.incompatabilities,
enabled: activeModIds.contains(mod.id), // Set enabled based on config enabled: activeModIds.contains(mod.id), // Set enabled based on config
@@ -336,7 +336,7 @@ class ModList {
versions: mod.versions, versions: mod.versions,
description: mod.description, description: mod.description,
hardDependencies: mod.hardDependencies, hardDependencies: mod.hardDependencies,
softDependencies: mod.softDependencies, loadAfter: mod.loadAfter,
loadBefore: mod.loadBefore, loadBefore: mod.loadBefore,
incompatabilities: mod.incompatabilities, incompatabilities: mod.incompatabilities,
enabled: activeModIds.contains(mod.id), // Set enabled based on config enabled: activeModIds.contains(mod.id), // Set enabled based on config
@@ -427,7 +427,7 @@ class ModList {
// Add soft dependencies (loadAfter) // Add soft dependencies (loadAfter)
for (final mod in mods.values) { for (final mod in mods.values) {
for (final dependency in mod.softDependencies) { for (final dependency in mod.loadAfter) {
// Only add if the dependency exists in our loaded mods // Only add if the dependency exists in our loaded mods
if (mods.containsKey(dependency)) { if (mods.containsKey(dependency)) {
graph[mod.id]!.add(dependency); graph[mod.id]!.add(dependency);
@@ -738,7 +738,7 @@ class ConfigFile {
description: isBaseGame ? "RimWorld base game" : description: isBaseGame ? "RimWorld base game" :
isExpansion ? "RimWorld expansion" : "", isExpansion ? "RimWorld expansion" : "",
hardDependencies: [], hardDependencies: [],
softDependencies: isExpansion ? ['ludeon.rimworld'] : [], loadAfter: isExpansion ? ['ludeon.rimworld'] : [],
loadBefore: [], loadBefore: [],
incompatabilities: [], incompatabilities: [],
enabled: true, enabled: true,