hook up the add new tag page

This commit is contained in:
zontreck 2024-06-07 01:05:22 -07:00
parent 240502972e
commit 2bc99f6bd9
16 changed files with 96 additions and 46 deletions

View file

@ -96,7 +96,7 @@ class EditorState extends State<Editor> {
),
body: TreeView(
nodeBuilder: (context, node) {
return TagExt.render(node.data as Tag);
return TagExt.render(node.data as Tag, context);
},
controller: controller,
),

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:nbteditor/Editor.dart';
import 'package:nbteditor/pages/AddPage.dart';
void main() {
runApp(const MainApp());
@ -12,7 +13,10 @@ class MainApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
routes: {"/": (context) => const Editor()},
routes: {
"/": (context) => const Editor(),
"/add": (context) => AddPage()
},
);
}
}

38
lib/pages/AddPage.dart Normal file
View file

@ -0,0 +1,38 @@
import 'package:flutter/material.dart';
import 'package:libac_dart/nbt/Tag.dart';
import 'package:nbteditor/Constants.dart';
class AddPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => AddState();
}
class AddState extends State<AddPage> {
@override
void didChangeDependencies() {
var args = ModalRoute.of(context)!.settings.arguments as AddElementArgs;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add Tag"),
backgroundColor: Constants.TITLEBAR_COLOR,
),
body: Padding(
padding: EdgeInsets.all(8),
child: SingleChildScrollView(
child: Column(
children: [],
),
),
),
);
}
}
class AddElementArgs {
Tag tag;
AddElementArgs({required this.tag});
}

View file

@ -19,11 +19,11 @@ extension ByteArrayTagExt on ByteArrayTag {
children: entries);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_ByteArray (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value.length} entries", true, false, canBeNamed(this)),
subtitle: TagExt.getElementDescriptor("${value.length} entries", true,
false, canBeNamed(this), this, context),
);
}
}

View file

@ -8,11 +8,11 @@ extension ByteTagExt on ByteTag {
return Node(key: path, label: "TAG_Byte ${getKey()}", data: this);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_Byte (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value}", false, true, canBeNamed(this)),
"${value}", false, true, canBeNamed(this), this, context),
);
}
}

View file

@ -4,14 +4,16 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart';
import 'package:nbteditor/tags/Tag.dart';
extension CompoundTagExt on CompoundTag {
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_Compound (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value.length} tag${value.length > 1 ? "s" : ""}",
true,
false,
canBeNamed(this)));
canBeNamed(this),
this,
context));
}
Node getNode(String path) {

View file

@ -8,11 +8,11 @@ extension DoubleTagExt on DoubleTag {
return Node(key: path, label: "TAG_Double ${getKey()}", data: this);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_Double (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value}", false, true, canBeNamed(this)),
"${value}", false, true, canBeNamed(this), this, context),
);
}
}

View file

@ -9,11 +9,11 @@ extension FloatTagExt on FloatTag {
return Node(key: path, label: "TAG_Float ${getKey()}", data: this);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_Float (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value}", false, true, canBeNamed(this)),
"${value}", false, true, canBeNamed(this), this, context),
);
}
}

View file

@ -20,11 +20,11 @@ extension IntArrayTagExt on IntArrayTag {
children: entries);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_IntArray (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value.length} entries", true, false, canBeNamed(this)),
subtitle: TagExt.getElementDescriptor("${value.length} entries", true,
false, canBeNamed(this), this, context),
);
}
}

View file

@ -9,11 +9,11 @@ extension IntTagExt on IntTag {
return Node(key: path, label: "TAG_Int ${getKey()}", data: this);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_Int (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value}", false, true, canBeNamed(this)),
"${value}", false, true, canBeNamed(this), this, context),
);
}
}

View file

@ -17,13 +17,13 @@ extension ListTagExt on ListTag {
return Node(key: path, label: getKey(), data: this, children: nodes);
}
Widget render() {
Widget render(BuildContext context) {
TagType type = TagType.End;
if (value.length > 0) type = get(0).getTagType();
return ListTile(
title: Text("TAG_List (${getKey()}) (${type})"),
subtitle: TagExt.getElementDescriptor(
"${value.length} entries", true, false, canBeNamed(this)));
subtitle: TagExt.getElementDescriptor("${value.length} entries", true,
false, canBeNamed(this), this, context));
}
}

View file

@ -20,11 +20,11 @@ extension LongArrayTagExt on LongArrayTag {
children: entries);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_LongArray (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value.length} entries", true, false, canBeNamed(this)),
subtitle: TagExt.getElementDescriptor("${value.length} entries", true,
false, canBeNamed(this), this, context),
);
}
}

View file

@ -9,11 +9,11 @@ extension LongTagExt on LongTag {
return Node(key: path, label: "TAG_Long ${getKey()}", data: this);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_Long (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value}", false, true, canBeNamed(this)),
"${value}", false, true, canBeNamed(this), this, context),
);
}
}

View file

@ -9,11 +9,11 @@ extension ShortTagExt on ShortTag {
return Node(key: path, label: "TAG_Short ${getKey()}", data: this);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_Short (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value}", false, true, canBeNamed(this)),
"${value}", false, true, canBeNamed(this), this, context),
);
}
}

View file

@ -9,11 +9,11 @@ extension StringTagExt on StringTag {
return Node(key: path, label: "TAG_String ${getKey()}", data: this);
}
Widget render() {
Widget render(BuildContext context) {
return ListTile(
title: Text("TAG_String (${getKey()})"),
subtitle: TagExt.getElementDescriptor(
"${value}", false, true, canBeNamed(this)),
"${value}", false, true, canBeNamed(this), this, context),
);
}
}

View file

@ -13,6 +13,7 @@ import 'package:libac_dart/nbt/impl/LongArrayTag.dart';
import 'package:libac_dart/nbt/impl/LongTag.dart';
import 'package:libac_dart/nbt/impl/ShortTag.dart';
import 'package:libac_dart/nbt/impl/StringTag.dart';
import 'package:nbteditor/pages/AddPage.dart';
import 'package:nbteditor/tags/ByteArrayTag.dart';
import 'package:nbteditor/tags/ByteTag.dart';
import 'package:nbteditor/tags/CompoundTag.dart';
@ -27,55 +28,55 @@ import 'package:nbteditor/tags/ShortTag.dart';
import 'package:nbteditor/tags/StringTag.dart';
class TagExt {
static Widget render(Tag tag) {
static Widget render(Tag tag, BuildContext context) {
switch (tag.getTagType()) {
case TagType.List:
{
return (tag as ListTag).render();
return (tag as ListTag).render(context);
}
case TagType.Byte:
{
return (tag as ByteTag).render();
return (tag as ByteTag).render(context);
}
case TagType.Int:
{
return (tag as IntTag).render();
return (tag as IntTag).render(context);
}
case TagType.Double:
{
return (tag as DoubleTag).render();
return (tag as DoubleTag).render(context);
}
case TagType.LongArray:
{
return (tag as LongArrayTag).render();
return (tag as LongArrayTag).render(context);
}
case TagType.Long:
{
return (tag as LongTag).render();
return (tag as LongTag).render(context);
}
case TagType.IntArray:
{
return (tag as IntArrayTag).render();
return (tag as IntArrayTag).render(context);
}
case TagType.ByteArray:
{
return (tag as ByteArrayTag).render();
return (tag as ByteArrayTag).render(context);
}
case TagType.String:
{
return (tag as StringTag).render();
return (tag as StringTag).render(context);
}
case TagType.Compound:
{
return (tag as CompoundTag).render();
return (tag as CompoundTag).render(context);
}
case TagType.Short:
{
return (tag as ShortTag).render();
return (tag as ShortTag).render(context);
}
case TagType.Float:
{
return (tag as FloatTag).render();
return (tag as FloatTag).render(context);
}
case TagType.End:
{
@ -141,8 +142,8 @@ class TagExt {
}
}
static Widget getElementDescriptor(
String descript, bool canAddElements, bool editableValue, bool isNamed) {
static Widget getElementDescriptor(String descript, bool canAddElements,
bool editableValue, bool isNamed, Tag tag, BuildContext ctx) {
return Row(
children: [
Text(descript),
@ -150,7 +151,12 @@ class TagExt {
width: 100,
),
if (canAddElements)
ElevatedButton(onPressed: () {}, child: Icon(Icons.add)),
ElevatedButton(
onPressed: () async {
var response = await Navigator.pushNamed(ctx, "/add",
arguments: AddElementArgs(tag: tag));
},
child: Icon(Icons.add)),
if (isNamed)
ElevatedButton(onPressed: () {}, child: Text("R E N A M E")),
if (editableValue)