Skip to content

Commit dc73b98

Browse files
committed
Add variations and background editor
1 parent cc76864 commit dc73b98

File tree

6 files changed

+299
-136
lines changed

6 files changed

+299
-136
lines changed

app/lib/pages/editor/backgrounds.dart

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
44
import 'package:material_leap/material_leap.dart';
55
import 'package:phosphor_flutter/phosphor_flutter.dart';
66
import 'package:setonix/bloc/editor.dart';
7+
import 'package:setonix/pages/editor/textures.dart';
78
import 'package:setonix_api/setonix_api.dart';
89

910
class BackgroundsEditorPage extends StatelessWidget {
@@ -31,6 +32,15 @@ class BackgroundsEditorPage extends StatelessWidget {
3132
},
3233
child: ListTile(
3334
title: Text(id),
35+
onTap: () {
36+
showDialog(
37+
context: context,
38+
builder: (context) => BlocProvider.value(
39+
value: cubit,
40+
child: BackgroundEditorDialog(name: id),
41+
),
42+
);
43+
},
3444
trailing: IconButton(
3545
icon: const Icon(PhosphorIconsLight.trash),
3646
onPressed: () {
@@ -63,3 +73,82 @@ class BackgroundsEditorPage extends StatelessWidget {
6373
);
6474
}
6575
}
76+
77+
class BackgroundEditorDialog extends StatefulWidget {
78+
final String name;
79+
80+
const BackgroundEditorDialog({
81+
super.key,
82+
required this.name,
83+
});
84+
85+
@override
86+
State<BackgroundEditorDialog> createState() => _BackgroundEditorDialogState();
87+
}
88+
89+
class _BackgroundEditorDialogState extends State<BackgroundEditorDialog> {
90+
BackgroundDefinition? _value;
91+
late PackTranslation _translation;
92+
93+
@override
94+
void initState() {
95+
super.initState();
96+
final editorState = context.read<EditorCubit>().state;
97+
_value = editorState.getBackground(widget.name);
98+
_translation = editorState.getTranslationOrDefault();
99+
}
100+
101+
@override
102+
Widget build(BuildContext context) {
103+
final value = _value;
104+
if (value == null) {
105+
return const SizedBox();
106+
}
107+
return ResponsiveAlertDialog(
108+
title: Text(widget.name),
109+
constraints: const BoxConstraints(
110+
maxWidth: LeapBreakpoints.compact, maxHeight: 600),
111+
content: ListView(
112+
shrinkWrap: true,
113+
children: [
114+
TextFormField(
115+
decoration: InputDecoration(
116+
labelText: AppLocalizations.of(context).name,
117+
filled: true,
118+
icon: const Icon(PhosphorIconsLight.textT),
119+
),
120+
initialValue: _translation.backgrounds[widget.name]?.name,
121+
onChanged: (value) {
122+
final translation = BackgroundTranslation(name: value);
123+
_translation = _translation.copyWith.backgrounds
124+
.put(widget.name, translation);
125+
},
126+
),
127+
const SizedBox(height: 8),
128+
VisualEditingView(
129+
value: value,
130+
onChanged: (value) {
131+
setState(() {
132+
_value = value;
133+
});
134+
}),
135+
],
136+
),
137+
actions: [
138+
TextButton(
139+
onPressed: () {
140+
Navigator.of(context).pop();
141+
},
142+
child: Text(AppLocalizations.of(context).cancel),
143+
),
144+
ElevatedButton(
145+
onPressed: () {
146+
context.read<EditorCubit>().setBackground(widget.name, value);
147+
Navigator.of(context).pop();
148+
},
149+
child: Text(AppLocalizations.of(context).save),
150+
),
151+
],
152+
);
153+
}
154+
}

app/lib/pages/editor/figures.dart

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class FigureEditorDialog extends StatefulWidget {
9393
}
9494

9595
class _FigureEditorDialogState extends State<FigureEditorDialog> {
96-
late FigureDefinition? _value;
96+
FigureDefinition? _value;
9797
late PackTranslation _translation;
9898

9999
@override
@@ -188,6 +188,27 @@ class _FigureEditorDialogState extends State<FigureEditorDialog> {
188188
final variation = variations[index];
189189
return ListTile(
190190
title: Text(variation.key),
191+
onTap: () async {
192+
final bloc = context.read<EditorCubit>();
193+
final result =
194+
await showDialog<VariationDefinition>(
195+
context: context,
196+
builder: (context) => BlocProvider.value(
197+
value: bloc,
198+
child: _FigureVariationEditorDialog(
199+
name: variation.key,
200+
value: variation.value,
201+
),
202+
),
203+
);
204+
if (result == null) return;
205+
setState(() {
206+
_value = value.copyWith.variations.put(
207+
variation.key,
208+
result,
209+
);
210+
});
211+
},
191212
trailing: IconButton(
192213
icon: const Icon(PhosphorIconsLight.trash),
193214
onPressed: () {
@@ -255,3 +276,56 @@ class _FigureEditorDialogState extends State<FigureEditorDialog> {
255276
);
256277
}
257278
}
279+
280+
class _FigureVariationEditorDialog extends StatefulWidget {
281+
final String name;
282+
final VariationDefinition value;
283+
284+
const _FigureVariationEditorDialog({
285+
super.key,
286+
required this.name,
287+
required this.value,
288+
});
289+
290+
@override
291+
State<_FigureVariationEditorDialog> createState() =>
292+
__FigureVariationEditorDialogState();
293+
}
294+
295+
class __FigureVariationEditorDialogState
296+
extends State<_FigureVariationEditorDialog> {
297+
late VariationDefinition _value;
298+
299+
@override
300+
void initState() {
301+
super.initState();
302+
_value = widget.value;
303+
}
304+
305+
@override
306+
Widget build(BuildContext context) {
307+
return ResponsiveAlertDialog(
308+
title: Text(widget.name),
309+
content: VisualEditingView(
310+
value: _value,
311+
onChanged: (v) => setState(() {
312+
_value = v;
313+
}),
314+
),
315+
actions: [
316+
TextButton(
317+
onPressed: () {
318+
Navigator.of(context).pop();
319+
},
320+
child: Text(AppLocalizations.of(context).cancel),
321+
),
322+
ElevatedButton(
323+
onPressed: () {
324+
Navigator.of(context).pop(_value);
325+
},
326+
child: Text(AppLocalizations.of(context).save),
327+
),
328+
],
329+
);
330+
}
331+
}

app/macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88
import device_info_plus
99
import dynamic_color
1010
import file_selector_macos
11-
import flutter_secure_storage_macos
11+
import flutter_secure_storage_darwin
1212
import package_info_plus
1313
import path_provider_foundation
1414
import screen_retriever_macos
@@ -21,7 +21,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
2121
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
2222
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
2323
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
24-
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
24+
FlutterSecureStorageDarwinPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageDarwinPlugin"))
2525
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
2626
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
2727
ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin"))

app/pubspec.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -458,26 +458,26 @@ packages:
458458
dependency: "direct main"
459459
description:
460460
name: flutter_secure_storage
461-
sha256: "127f5ab0b6402baa7a3322bddb419a22874f7b5b1e12c9946e329c7f846d8e4e"
461+
sha256: f7eceb0bc6f4fd0441e29d43cab9ac2a1c5ffd7ea7b64075136b718c46954874
462462
url: "https://pub.dev"
463463
source: hosted
464-
version: "10.0.0-beta.3"
465-
flutter_secure_storage_linux:
464+
version: "10.0.0-beta.4"
465+
flutter_secure_storage_darwin:
466466
dependency: transitive
467467
description:
468-
name: flutter_secure_storage_linux
469-
sha256: b777e220fbf21c149574aa31f9e4ed56dcf025c4ef196664fe90954c265105dc
468+
name: flutter_secure_storage_darwin
469+
sha256: f226f2a572bed96bc6542198ebaec227150786e34311d455a7e2d3d06d951845
470470
url: "https://pub.dev"
471471
source: hosted
472-
version: "2.0.0"
473-
flutter_secure_storage_macos:
472+
version: "0.1.0"
473+
flutter_secure_storage_linux:
474474
dependency: transitive
475475
description:
476-
name: flutter_secure_storage_macos
477-
sha256: "75894eb6b402ac7f7f5ee5487d651b87855a338e26eb6993f4b2fce33013a615"
476+
name: flutter_secure_storage_linux
477+
sha256: b777e220fbf21c149574aa31f9e4ed56dcf025c4ef196664fe90954c265105dc
478478
url: "https://pub.dev"
479479
source: hosted
480-
version: "4.0.0"
480+
version: "2.0.0"
481481
flutter_secure_storage_platform_interface:
482482
dependency: transitive
483483
description:
@@ -1051,10 +1051,10 @@ packages:
10511051
dependency: transitive
10521052
description:
10531053
name: shared_preferences_android
1054-
sha256: "02a7d8a9ef346c9af715811b01fbd8e27845ad2c41148eefd31321471b41863d"
1054+
sha256: bf808be89fe9dc467475e982c1db6c2faf3d2acf54d526cd5ec37d86c99dbd84
10551055
url: "https://pub.dev"
10561056
source: hosted
1057-
version: "2.4.0"
1057+
version: "2.4.1"
10581058
shared_preferences_foundation:
10591059
dependency: transitive
10601060
description:
@@ -1297,10 +1297,10 @@ packages:
12971297
dependency: transitive
12981298
description:
12991299
name: url_launcher_windows
1300-
sha256: "44cf3aabcedde30f2dba119a9dea3b0f2672fbe6fa96e85536251d678216b3c4"
1300+
sha256: "3284b6d2ac454cf34f114e1d3319866fdd1e19cdc329999057e44ffe936cfa77"
13011301
url: "https://pub.dev"
13021302
source: hosted
1303-
version: "3.1.3"
1303+
version: "3.1.4"
13041304
uuid:
13051305
dependency: transitive
13061306
description:

docs/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
},
1212
"dependencies": {
1313
"@astrojs/check": "^0.9.4",
14-
"@astrojs/react": "^4.1.2",
14+
"@astrojs/react": "^4.1.3",
1515
"@astrojs/starlight": "^0.30.5",
1616
"@phosphor-icons/react": "^2.1.7",
17-
"@types/react": "^19.0.3",
17+
"@types/react": "^19.0.4",
1818
"@types/react-dom": "^19.0.2",
19-
"astro": "^5.1.3",
19+
"astro": "^5.1.5",
2020
"react": "^19.0.0",
2121
"react-dom": "^19.0.0",
2222
"remark-gemoji": "^8.0.0",
2323
"remark-heading-id": "^1.0.1",
2424
"sharp": "^0.33.5",
25-
"typescript": "^5.7.2"
25+
"typescript": "^5.7.3"
2626
},
2727
"packageManager": "[email protected]",
2828
"devDependencies": {

0 commit comments

Comments
 (0)