From 9470ad19563e637b46bf0707b93fde96fba43b77 Mon Sep 17 00:00:00 2001 From: ArthurHeitmann Date: Fri, 7 Oct 2022 20:28:44 +0200 Subject: [PATCH] added command editor --- .../customXmlProps/commandEditor.dart | 96 +++++++++++++++++++ .../customXmlProps/conditionEditor.dart | 8 +- .../simpleProps/XmlPropEditorFactory.dart | 10 ++ 3 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 lib/widgets/propEditors/customXmlProps/commandEditor.dart diff --git a/lib/widgets/propEditors/customXmlProps/commandEditor.dart b/lib/widgets/propEditors/customXmlProps/commandEditor.dart new file mode 100644 index 00000000..c75ffd78 --- /dev/null +++ b/lib/widgets/propEditors/customXmlProps/commandEditor.dart @@ -0,0 +1,96 @@ + + +import 'package:flutter/material.dart'; +import 'package:nier_scripts_editor/widgets/propEditors/customXmlProps/puidReferenceEditor.dart'; + +import '../../../customTheme.dart'; +import '../../../stateManagement/ChangeNotifierWidget.dart'; +import '../../../stateManagement/xmlProps/xmlProp.dart'; +import '../simpleProps/XmlPropEditorFactory.dart'; +import '../simpleProps/propEditorFactory.dart'; + +class CommandEditor extends ChangeNotifierWidget { + final XmlProp prop; + final bool showDetails; + + CommandEditor({super.key, required this.prop, required this.showDetails}) : super(notifier: prop); + + @override + State createState() => CommandEditorState(); +} + +class CommandEditorState extends ChangeNotifierState { + @override + Widget build(BuildContext context) { + var command = widget.prop.get("command") ?? widget.prop.get("hit"); + var isHitCommand = command?.tagName == "hit"; + var hitoutCommand = widget.prop.get("hitout"); + var args = widget.prop.get("args"); + + return Padding( + padding: const EdgeInsets.all(4.0), + child: Row( + children: [ + Text( + "!", + style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold), + ), + SizedBox(width: 10), + Expanded( + child: Container( + decoration: BoxDecoration( + color: getTheme(context).formElementBgColor, + borderRadius: BorderRadius.circular(5), + ), + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + PuidReferenceEditor(prop: widget.prop.get("puid")!, showDetails: widget.showDetails), + if (command != null) + ...makeCommandEditor(command, isHitCommand ? "hit" : null) + else + Text("No command"), + if (hitoutCommand != null) + ...makeCommandEditor(hitoutCommand, "hitout"), + if (args != null) + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: makeXmlPropEditor(args, widget.showDetails), + ), + ], + ), + ), + ) + ] + ), + ); + } + + List makeCommandEditor(XmlProp commParent, String? commLabel) { + var label = commParent.get("command")?.get("label")?.value ?? commParent.get("label")?.value; + var value = commParent.get("command")?.get("value") ?? commParent.get("value"); + var args = commParent.get("args"); + + return [ + Divider(color: getTheme(context).textColor!.withOpacity(0.5), thickness: 2,), + if (commLabel != null) + Center( + child: Text(commLabel, style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),) + ), + if (label != null) + makePropEditor(label), + if (value != null) + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: makeXmlPropEditor(value, widget.showDetails), + ), + if (args != null) + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: makeXmlPropEditor(args, widget.showDetails), + ), + ]; + } +} diff --git a/lib/widgets/propEditors/customXmlProps/conditionEditor.dart b/lib/widgets/propEditors/customXmlProps/conditionEditor.dart index a0f6e975..35cdde88 100644 --- a/lib/widgets/propEditors/customXmlProps/conditionEditor.dart +++ b/lib/widgets/propEditors/customXmlProps/conditionEditor.dart @@ -34,7 +34,7 @@ class _ConditionEditorState extends ChangeNotifierState { "?", style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold), ), - SizedBox(width: 12), + SizedBox(width: 10), Expanded( child: Container( decoration: BoxDecoration( @@ -47,11 +47,9 @@ class _ConditionEditorState extends ChangeNotifierState { crossAxisAlignment: CrossAxisAlignment.start, children: [ PuidReferenceEditor(prop: widget.prop.get("puid")!, showDetails: widget.showDetails), - Divider(color: getTheme(context).textColor!.withOpacity(0.75), thickness: 2,), + Divider(color: getTheme(context).textColor!.withOpacity(0.5), thickness: 2,), if (label != null) - makePropEditor(label) - else - Text("No label"), + makePropEditor(label), if (value != null) Padding( padding: const EdgeInsets.only(left: 8.0), diff --git a/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart b/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart index a621a3d4..91a620d3 100644 --- a/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart +++ b/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart @@ -6,6 +6,7 @@ import '../../../stateManagement/Property.dart'; import '../../../stateManagement/xmlProps/xmlProp.dart'; import '../../../utils.dart'; import '../customXmlProps/areaEditor.dart'; +import '../customXmlProps/commandEditor.dart'; import '../customXmlProps/conditionEditor.dart'; import '../customXmlProps/entityEditor.dart'; import '../customXmlProps/layoutsEditor.dart'; @@ -78,6 +79,15 @@ List makeXmlMultiPropEditor(XmlProp parent, boo if (i + 1 < parent.length && _puidRefIdTags.contains(parent[i + 1].tagName)) i++; } + // command + else if (child.tagName == "puid" && i + 1 < parent.length && (parent[i + 1].tagName == "command" || parent[i + 1].tagName == "hit")) { + widgets.add(CommandEditor(prop: parent, showDetails: showDetails)); + i++; + if (i + 1 < parent.length && parent[i + 1].tagName == "hitout") + i++; + if (i + 1 < parent.length && parent[i + 1].tagName == "args") + i++; + } // fallback else { widgets.add(makeXmlPropEditor(child, showDetails));