Skip to content

Commit

Permalink
Add figure editing page
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Dec 28, 2024
1 parent b28717e commit cd2ff9d
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 404 deletions.
3 changes: 2 additions & 1 deletion app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ class SetonixApp extends StatelessWidget {
child: child,
),
routes: EditorPage.values
.where((e) => e.location != null)
.map(
(e) => GoRoute(
path: '$kEditorPath${e.location}',
path: e.fullLocation!,
name: e.route,
builder: (context, state) => e.getPage(),
),
Expand Down
79 changes: 79 additions & 0 deletions app/lib/pages/editor/figures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class FiguresEditorPage extends StatelessWidget {
child: BlocBuilder<EditorCubit, SetonixData>(
builder: (context, state) {
final figures = state.getFigureItems();
if (figures.isEmpty) {
return Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(AppLocalizations.of(context).noData),
),
);
}
return Column(
children: figures.map((figure) {
final id = figure.id;
Expand All @@ -37,6 +45,15 @@ class FiguresEditorPage extends StatelessWidget {
cubit.removeFigure(id);
},
),
onTap: () {
showDialog(
context: context,
builder: (context) => BlocProvider.value(
value: cubit,
child: FigureEditorDialog(name: id),
),
);
},
),
);
}).toList(),
Expand Down Expand Up @@ -64,3 +81,65 @@ class FiguresEditorPage extends StatelessWidget {
);
}
}

class FigureEditorDialog extends StatefulWidget {
final String name;

const FigureEditorDialog({super.key, required this.name});

@override
State<FigureEditorDialog> createState() => _FigureEditorDialogState();
}

class _FigureEditorDialogState extends State<FigureEditorDialog> {
late FigureDefinition? _value;

@override
void initState() {
super.initState();
_value = context.read<EditorCubit>().state.getFigure(widget.name);
}

@override
Widget build(BuildContext context) {
final value = _value;
if (value == null) {
return const SizedBox();
}
return ResponsiveAlertDialog(
title: Text(widget.name),
constraints: const BoxConstraints(maxWidth: LeapBreakpoints.compact),
content: ListView(
shrinkWrap: true,
children: [
CheckboxListTile(
value: value.rollable,
title: Text(AppLocalizations.of(context).roll),
onChanged: (bool? value) {
if (value != null) {
setState(() {
_value = _value?.copyWith(rollable: value);
});
}
},
),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context).cancel),
),
ElevatedButton(
onPressed: () {
context.read<EditorCubit>().setFigure(widget.name, value);
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context).save),
),
],
);
}
}
19 changes: 14 additions & 5 deletions app/lib/pages/editor/shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ enum EditorPage {
figures(PhosphorIcons.cube, '/figures'),
decks(PhosphorIcons.stack, '/decks'),
backgrounds(PhosphorIcons.image, '/backgrounds'),
translations(PhosphorIcons.translate, '/translations');
translations(PhosphorIcons.translate, null);

final IconGetter icon;
final String location;
final String? location;

const EditorPage(this.icon, this.location);

String get fullLocation => '$kEditorPath$location';
String get route => this == EditorPage.general ? 'editor' : 'editor-$name';
String? get fullLocation => location == null ? null : '$kEditorPath$location';
String? get route => location == null
? null
: this == EditorPage.general
? 'editor'
: 'editor-$name';

String getLocalizedName(BuildContext context) {
final loc = AppLocalizations.of(context);
Expand Down Expand Up @@ -63,7 +67,11 @@ class EditorNavigatorView extends StatelessWidget {

void _navigate(BuildContext context, EditorPage page) {
final cubit = context.read<EditorCubit>();
context.goNamed(page.route, pathParameters: {'name': cubit.path});
final route = page.route;
if (route == null) {
return;
}
context.goNamed(route, pathParameters: {'name': cubit.path});
}

@override
Expand All @@ -89,6 +97,7 @@ class EditorNavigatorView extends StatelessWidget {
icon: Icon(e.icon(PhosphorIconsStyle.light)),
label: Text(e.getLocalizedName(context)),
selectedIcon: Icon(e.icon(PhosphorIconsStyle.fill)),
enabled: e.location != null,
)),
],
);
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"sharp": "^0.33.5",
"typescript": "^5.7.2"
},
"packageManager": "pnpm@9.14.2",
"packageManager": "pnpm@9.15.2",
"devDependencies": {
"sass": "^1.83.0"
}
Expand Down
Loading

0 comments on commit cd2ff9d

Please sign in to comment.