Skip to content

Commit

Permalink
added command editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Oct 7, 2022
1 parent bafa001 commit 9470ad1
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 5 deletions.
96 changes: 96 additions & 0 deletions lib/widgets/propEditors/customXmlProps/commandEditor.dart
Original file line number Diff line number Diff line change
@@ -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<CommandEditor> createState() => CommandEditorState();
}

class CommandEditorState extends ChangeNotifierState<CommandEditor> {
@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<Widget> 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),
),
];
}
}
8 changes: 3 additions & 5 deletions lib/widgets/propEditors/customXmlProps/conditionEditor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _ConditionEditorState extends ChangeNotifierState<ConditionEditor> {
"?",
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
),
SizedBox(width: 12),
SizedBox(width: 10),
Expanded(
child: Container(
decoration: BoxDecoration(
Expand All @@ -47,11 +47,9 @@ class _ConditionEditorState extends ChangeNotifierState<ConditionEditor> {
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),
Expand Down
10 changes: 10 additions & 0 deletions lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -78,6 +79,15 @@ List<Widget> makeXmlMultiPropEditor<T extends PropTextField>(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<T>(child, showDetails));
Expand Down

0 comments on commit 9470ad1

Please sign in to comment.