mirror of
https://github.com/zontreck/NBTEditor
synced 2024-11-21 13:48:56 -07:00
Create value editor prompt
This commit is contained in:
parent
d5577bb39a
commit
10e9189e31
17 changed files with 143 additions and 42 deletions
|
@ -45,6 +45,10 @@ class EditorState extends State<Editor> {
|
|||
}
|
||||
}
|
||||
|
||||
void didChangeState() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
controller =
|
||||
|
@ -119,7 +123,7 @@ class EditorState extends State<Editor> {
|
|||
),
|
||||
body: TreeView(
|
||||
nodeBuilder: (context, node) {
|
||||
return TagExt.render(node.data as Tag, context);
|
||||
return TagExt.render(node.data as Tag, context, didChangeState);
|
||||
},
|
||||
controller: controller,
|
||||
),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:nbteditor/Editor.dart';
|
||||
import 'package:nbteditor/pages/AddPage.dart';
|
||||
import 'package:nbteditor/pages/EditValue.dart';
|
||||
import 'package:nbteditor/pages/SNBTEditor.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -17,7 +18,7 @@ class MainApp extends StatelessWidget {
|
|||
routes: {
|
||||
"/": (context) => const Editor(),
|
||||
"/add": (context) => const AddPage(),
|
||||
"/snbt": (context) => const SnbtEdit()
|
||||
"/snbt": (context) => const SnbtEdit(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
77
lib/pages/EditValue.dart
Normal file
77
lib/pages/EditValue.dart
Normal file
|
@ -0,0 +1,77 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:libac_dart/nbt/Tag.dart';
|
||||
import 'package:libac_dart/nbt/impl/StringTag.dart';
|
||||
|
||||
class EditValuePrompt extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return EditValueState();
|
||||
}
|
||||
}
|
||||
|
||||
class EditValueState extends State<EditValuePrompt> {
|
||||
TagType TagValueType = TagType.String;
|
||||
Tag MainTag = StringTag.valueOf("str");
|
||||
|
||||
TextEditingController TEC = TextEditingController();
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
var args = ModalRoute.of(context)!.settings.arguments!;
|
||||
|
||||
if (args is Tag) {
|
||||
Tag tag = args as Tag;
|
||||
setState(() {
|
||||
TagValueType = tag.getTagType();
|
||||
MainTag = tag;
|
||||
|
||||
TEC.text = "${MainTag.getValue()}";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: Icon(Icons.edit_document),
|
||||
title: Text("Edit Value - ${MainTag.getKey()}"),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
dynamic val = TEC.text;
|
||||
switch (MainTag.getTagType()) {
|
||||
case TagType.Byte:
|
||||
case TagType.Int:
|
||||
case TagType.Long:
|
||||
case TagType.Short:
|
||||
{
|
||||
val = int.parse(val);
|
||||
break;
|
||||
}
|
||||
case TagType.Double:
|
||||
case TagType.Float:
|
||||
{
|
||||
val = double.parse(val);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
Navigator.pop(context, val);
|
||||
},
|
||||
child: Text("Submit")),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text("Cancel"))
|
||||
],
|
||||
content: TextField(
|
||||
controller: TEC,
|
||||
decoration: InputDecoration(border: OutlineInputBorder()),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -19,13 +19,13 @@ extension ByteArrayTagExt on ByteArrayTag {
|
|||
children: entries);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_ByteArray (${getKey()})"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/ByteArray.png")),
|
||||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||
trailing: TagExt.getElementButtons(
|
||||
true, canBeNamed(this), false, this, context),
|
||||
true, canBeNamed(this), false, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ extension ByteTagExt on ByteTag {
|
|||
return Node(key: path, label: "TAG_Byte ${getKey()}", data: this);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_Byte (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor(
|
||||
|
@ -16,7 +16,7 @@ extension ByteTagExt on ByteTag {
|
|||
),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/Byte.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
false, canBeNamed(this), true, this, context),
|
||||
false, canBeNamed(this), true, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
|||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
||||
extension CompoundTagExt on CompoundTag {
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_Compound (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor(
|
||||
|
@ -12,7 +12,7 @@ extension CompoundTagExt on CompoundTag {
|
|||
),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/Compound.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
true, canBeNamed(this), false, this, context),
|
||||
true, canBeNamed(this), false, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,13 @@ extension DoubleTagExt on DoubleTag {
|
|||
return Node(key: path, label: "TAG_Double ${getKey()}", data: this);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_Double (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor("$value"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/Double.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
false, canBeNamed(this), true, this, context),
|
||||
false, canBeNamed(this), true, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ extension FloatTagExt on FloatTag {
|
|||
return Node(key: path, label: "TAG_Float ${getKey()}", data: this);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_Float (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor("$value"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/Float.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
false, canBeNamed(this), true, this, context),
|
||||
false, canBeNamed(this), true, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ extension IntArrayTagExt on IntArrayTag {
|
|||
children: entries);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_IntArray (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/IntegerArray.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
true, canBeNamed(this), false, this, context),
|
||||
true, canBeNamed(this), false, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ extension IntTagExt on IntTag {
|
|||
return Node(key: path, label: "TAG_Int ${getKey()}", data: this);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_Int (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor("$value"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/Integer.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
false, canBeNamed(this), true, this, context),
|
||||
false, canBeNamed(this), true, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ extension ListTagExt on ListTag {
|
|||
return Node(key: path, label: getKey(), data: this, children: nodes);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
TagType type = TagType.End;
|
||||
if (value.isNotEmpty) type = get(0).getTagType();
|
||||
|
||||
|
@ -26,7 +26,7 @@ extension ListTagExt on ListTag {
|
|||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/List.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
true, canBeNamed(this), false, this, context),
|
||||
true, canBeNamed(this), false, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ extension LongArrayTagExt on LongArrayTag {
|
|||
children: entries);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_LongArray (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/LongArray.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
true, canBeNamed(this), false, this, context),
|
||||
true, canBeNamed(this), false, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ extension LongTagExt on LongTag {
|
|||
return Node(key: path, label: "TAG_Long ${getKey()}", data: this);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_Long (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor("$value"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/Long.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
false, canBeNamed(this), true, this, context),
|
||||
false, canBeNamed(this), true, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ extension ShortTagExt on ShortTag {
|
|||
return Node(key: path, label: "TAG_Short ${getKey()}", data: this);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_Short (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor("$value"),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/Short.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
false, canBeNamed(this), true, this, context),
|
||||
false, canBeNamed(this), true, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ extension StringTagExt on StringTag {
|
|||
return Node(key: path, label: "TAG_String ${getKey()}", data: this);
|
||||
}
|
||||
|
||||
Widget render(BuildContext context) {
|
||||
Widget render(BuildContext context, Function didChangeState) {
|
||||
return ListTile(
|
||||
title: Text("TAG_String (${getKey()})"),
|
||||
subtitle: TagExt.getElementDescriptor(value),
|
||||
leading: const Image(image: AssetImage("Icons/PNG/String.png")),
|
||||
trailing: TagExt.getElementButtons(
|
||||
false, canBeNamed(this), true, this, context),
|
||||
false, canBeNamed(this), true, this, context, didChangeState),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_treeview/flutter_treeview.dart';
|
||||
import 'package:libac_dart/nbt/Tag.dart';
|
||||
|
@ -15,6 +16,7 @@ import 'package:libac_dart/nbt/impl/ShortTag.dart';
|
|||
import 'package:libac_dart/nbt/impl/StringTag.dart';
|
||||
import 'package:nbteditor/Editor.dart';
|
||||
import 'package:nbteditor/pages/AddPage.dart';
|
||||
import 'package:nbteditor/pages/EditValue.dart';
|
||||
import 'package:nbteditor/pages/RenamePrompt.dart';
|
||||
import 'package:nbteditor/tags/ByteArrayTag.dart';
|
||||
import 'package:nbteditor/tags/ByteTag.dart';
|
||||
|
@ -30,55 +32,55 @@ import 'package:nbteditor/tags/ShortTag.dart';
|
|||
import 'package:nbteditor/tags/StringTag.dart';
|
||||
|
||||
class TagExt {
|
||||
static Widget render(Tag tag, BuildContext context) {
|
||||
static Widget render(Tag tag, BuildContext context, Function didChangeState) {
|
||||
switch (tag.getTagType()) {
|
||||
case TagType.List:
|
||||
{
|
||||
return (tag as ListTag).render(context);
|
||||
return (tag as ListTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.Byte:
|
||||
{
|
||||
return (tag as ByteTag).render(context);
|
||||
return (tag as ByteTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.Int:
|
||||
{
|
||||
return (tag as IntTag).render(context);
|
||||
return (tag as IntTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.Double:
|
||||
{
|
||||
return (tag as DoubleTag).render(context);
|
||||
return (tag as DoubleTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.LongArray:
|
||||
{
|
||||
return (tag as LongArrayTag).render(context);
|
||||
return (tag as LongArrayTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.Long:
|
||||
{
|
||||
return (tag as LongTag).render(context);
|
||||
return (tag as LongTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.IntArray:
|
||||
{
|
||||
return (tag as IntArrayTag).render(context);
|
||||
return (tag as IntArrayTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.ByteArray:
|
||||
{
|
||||
return (tag as ByteArrayTag).render(context);
|
||||
return (tag as ByteArrayTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.String:
|
||||
{
|
||||
return (tag as StringTag).render(context);
|
||||
return (tag as StringTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.Compound:
|
||||
{
|
||||
return (tag as CompoundTag).render(context);
|
||||
return (tag as CompoundTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.Short:
|
||||
{
|
||||
return (tag as ShortTag).render(context);
|
||||
return (tag as ShortTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.Float:
|
||||
{
|
||||
return (tag as FloatTag).render(context);
|
||||
return (tag as FloatTag).render(context, didChangeState);
|
||||
}
|
||||
case TagType.End:
|
||||
{
|
||||
|
@ -145,7 +147,7 @@ class TagExt {
|
|||
}
|
||||
|
||||
static Widget getElementButtons(bool canAddElements, bool isNamed,
|
||||
bool editableValue, Tag tag, BuildContext ctx) {
|
||||
bool editableValue, Tag tag, BuildContext ctx, Function didChangeState) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
@ -210,7 +212,24 @@ class TagExt {
|
|||
},
|
||||
icon: Icon(Icons.drive_file_rename_outline)),
|
||||
if (editableValue)
|
||||
IconButton(onPressed: () {}, icon: Icon(Icons.edit_document))
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
var response = await showAdaptiveDialog(
|
||||
context: ctx,
|
||||
builder: (B) {
|
||||
return EditValuePrompt();
|
||||
},
|
||||
routeSettings: RouteSettings(arguments: tag));
|
||||
|
||||
if (response == null) {
|
||||
return;
|
||||
} else {
|
||||
tag.setValue(response);
|
||||
|
||||
didChangeState.call();
|
||||
}
|
||||
},
|
||||
icon: Icon(Icons.edit_document))
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ dependencies:
|
|||
flutter_treeview: ^1.0.7+1
|
||||
libac_dart:
|
||||
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
|
||||
version: 1.2.072024+2043
|
||||
version: 1.2.072124+0507
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue