Skip to content

Commit

Permalink
Show wtp location when editing wta
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Dec 1, 2024
1 parent 857f744 commit e9f0554
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
15 changes: 15 additions & 0 deletions lib/stateManagement/openFiles/types/WtaWtpData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class WtaWtpTextures with HasUuid, Undoable implements Disposable {
final OpenFileId file;
final String wtaPath;
final String? wtpPath;
final ValueNotifier<List<String>?> wtpDatsPath = ValueNotifier(null);
final bool isWtb;
final int wtaVersion;
final ValueListNotifier<WtaTextureEntry> textures;
Expand All @@ -175,6 +176,19 @@ class WtaWtpTextures with HasUuid, Undoable implements Disposable {

WtaWtpTextures(this.file, this.wtaPath, this.wtpPath, this.isWtb, this.wtaVersion, this.textures, this.useFlagsSimpleMode, this.hasAnySimpleModeFlags) {
textures.addListener(_onPropChange);

if (wtpPath != null) {
List<String> reversePaths = [];
reversePaths.add(wtpPath!);
var remainingPath = dirname(wtpPath!);
while (datExtensions.any((ext) => basename(remainingPath).endsWith(ext))) {
reversePaths.add(remainingPath);
remainingPath = dirname(remainingPath);
if (basename(remainingPath) == datSubExtractDir)
remainingPath = dirname(remainingPath);
}
wtpDatsPath.value = reversePaths.reversed.toList();
}
}

static Future<WtaWtpTextures> fromWtaWtp(OpenFileId file, String wtaPath, String? wtpPath, String extractDir, bool isWtb) async {
Expand Down Expand Up @@ -278,6 +292,7 @@ class WtaWtpTextures with HasUuid, Undoable implements Disposable {
@override
void dispose() {
textures.dispose();
wtpDatsPath.dispose();
}

@override
Expand Down
23 changes: 17 additions & 6 deletions lib/widgets/filesView/types/genericTable/tableEditor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class _RowConfigIndexed {

mixin CustomTableConfig {
late final String name;
Widget? subTitleWidget;
late final List<String> columnNames;
late final List<int> columnFlex;
late final NumberProp rowCount;
Expand Down Expand Up @@ -198,12 +199,22 @@ class _TableEditorState extends ChangeNotifierState<TableEditor> {
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
widget.config.name,
style: Theme.of(context).textTheme.titleLarge,
),
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
widget.config.name,
style: Theme.of(context).textTheme.titleLarge,
),
),
if (widget.config.subTitleWidget != null) ...[
const SizedBox(width: 10),
Expanded(
child: widget.config.subTitleWidget!
),
]
],
),
),
_makeExportDropdown(),
Expand Down
47 changes: 47 additions & 0 deletions lib/widgets/filesView/types/wtaWtpEditor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:path/path.dart';
import '../../../fileTypeUtils/textures/ddsConverter.dart';
import '../../../stateManagement/Property.dart';
import '../../../stateManagement/events/statusInfo.dart';
import '../../../stateManagement/hierarchy/FileHierarchy.dart';
import '../../../stateManagement/listNotifier.dart';
import '../../../stateManagement/openFiles/types/WtaWtpData.dart';
import '../../../utils/utils.dart';
Expand All @@ -34,6 +35,7 @@ class _TexturesTableConfig with CustomTableConfig {
_TexturesTableConfig(this.file, String name, this.texData)
: textures = texData.textures {
this.name = name;
subTitleWidget = _WtpDatPaths(wtpDatsPath: texData.wtpDatsPath);
columnNames = [
"ID", "PNG", "Path", "", "",
if (texData.hasAnySimpleModeFlags)
Expand Down Expand Up @@ -272,3 +274,48 @@ class __TexturePreviewState extends ChangeNotifierState<_TexturePreview> {
);
}
}

class _WtpDatPaths extends ChangeNotifierWidget {
final ValueNotifier<List<String>?> wtpDatsPath;

_WtpDatPaths({required this.wtpDatsPath}) : super(notifier: wtpDatsPath);

@override
State<_WtpDatPaths> createState() => __WtpDatPathsState();
}

class __WtpDatPathsState extends ChangeNotifierState<_WtpDatPaths> {
void _openDat(String path) async {
var file = await openHierarchyManager.openFile(path);
if (file == null)
return;
openHierarchyManager.setSelectedEntry(file);
showToast("Opened ${basename(path)} to sidebar");
}

@override
Widget build(BuildContext context) {
var paths = widget.wtpDatsPath.value;
if (paths == null)
return const SizedBox.shrink();
return Row(
children: [
const Text("WTP inside DTT: "),
for (var path in paths)
if (path != paths.last) ...[
Flexible(
child: TextButton(
onPressed: () => _openDat(path),
child: Text(basename(path), overflow: TextOverflow.ellipsis),
),
),
Text(" > ", style: TextStyle(fontWeight: FontWeight.w900),),
]
else
Flexible(
child: Text(basename(path), overflow: TextOverflow.ellipsis),
),
],
);
}
}

0 comments on commit e9f0554

Please sign in to comment.