From 5c0763f0a9fd00eaed7dafef565519cb560a211d Mon Sep 17 00:00:00 2001 From: Matthew <119624750+casualWaist@users.noreply.github.com> Date: Fri, 14 Jun 2024 21:14:37 -0400 Subject: [PATCH] Finished Bot Animations and other fixes --- assets/pangea/bot_faces/pangea_bot.riv | Bin 10794 -> 10789 bytes .../controllers/igc_controller.dart | 9 ---- .../choreographer/widgets/it_bar_buttons.dart | 2 +- .../widgets/it_feedback_card.dart | 2 +- lib/pangea/controllers/user_controller.dart | 2 +- lib/pangea/utils/instructions.dart | 2 +- lib/pangea/widgets/common/bot_face_svg.dart | 32 +++++++++----- .../conversation_bot_settings.dart | 2 +- .../widgets/igc/pangea_text_controller.dart | 6 --- lib/pangea/widgets/igc/span_card.dart | 40 ++++++++++++------ lib/pangea/widgets/new_group/vocab_list.dart | 6 +-- 11 files changed, 57 insertions(+), 46 deletions(-) diff --git a/assets/pangea/bot_faces/pangea_bot.riv b/assets/pangea/bot_faces/pangea_bot.riv index b6956e547eeb1962304f8ad5aeec12c435307b3e..177b9b28fe53aa22a9bb986fbdd7a3e62dd71a09 100644 GIT binary patch delta 178 zcmZ1#vNUAFEwRma#B^9UbIE*T+svdK%)B{V&5^mD%QdegwJ5kGu_TqjvWt=3C$TcM zNWqZ7j=^y{Bg;I-34RQ2vl$scJhpj^7x=-vxj=yidyp7AiWq|fNQ`kF;|q4UItQ>A l(>%r<;&8DB2L{`zKr?KoiZL<*H32!y4E7+31w^ni0051&D{KG& delta 186 zcmZ1)vMOZ5Eip#x%{Rq#S(&UEH?zrnV*}BDl!BQ-w7;4ob3M0fUP)?^LU2i9Nh*V7 z7bCk*VkMAo$l$ getIGCTextData({required bool tokensOnly}) async { try { if (choreographer.currentText.isEmpty) return clear(); @@ -215,12 +212,6 @@ class IgcController { ), onITStart: () { if (choreographer.itEnabled && igcTextData != null) { - if (turnOnAutoPlay) { - choreographer.pangeaController.pStoreService.save( - ToolSetting.itAutoPlay.toString(), - true, - ); - } choreographer.onITStart(igcTextData!.matches[firstMatchIndex]); } }, diff --git a/lib/pangea/choreographer/widgets/it_bar_buttons.dart b/lib/pangea/choreographer/widgets/it_bar_buttons.dart index 815020d17..786c17c07 100644 --- a/lib/pangea/choreographer/widgets/it_bar_buttons.dart +++ b/lib/pangea/choreographer/widgets/it_bar_buttons.dart @@ -45,7 +45,7 @@ class ITBotButton extends StatelessWidget { ); return IconButton( - icon: const BotFace(width: 40.0, expression: BotExpression.right), + icon: const BotFace(width: 40.0, expression: BotExpression.idle), onPressed: () => choreographer.pangeaController.instructions.show( context, InstructionsEnum.itInstructions, diff --git a/lib/pangea/choreographer/widgets/it_feedback_card.dart b/lib/pangea/choreographer/widgets/it_feedback_card.dart index 072d24e1a..5424310a8 100644 --- a/lib/pangea/choreographer/widgets/it_feedback_card.dart +++ b/lib/pangea/choreographer/widgets/it_feedback_card.dart @@ -129,7 +129,7 @@ class ITFeedbackCardView extends StatelessWidget { children: [ CardHeader( text: controller.widget.req.chosenContinuance, - botExpression: BotExpression.down, + botExpression: BotExpression.nonGold, ), Text( controller.widget.choiceFeedback, diff --git a/lib/pangea/controllers/user_controller.dart b/lib/pangea/controllers/user_controller.dart index c6a1b3409..0e336fdf6 100644 --- a/lib/pangea/controllers/user_controller.dart +++ b/lib/pangea/controllers/user_controller.dart @@ -142,7 +142,7 @@ class UserController extends BaseController { await updateMatrixProfile( dateOfBirth: dob, - autoPlayMessages: autoPlay ?? false, + autoPlayMessages: autoPlay, activatedFreeTrial: trial, interactiveTranslator: interactiveTranslator, itAutoPlay: itAutoPlay, diff --git a/lib/pangea/utils/instructions.dart b/lib/pangea/utils/instructions.dart index f1fa8b59f..7d3711ae6 100644 --- a/lib/pangea/utils/instructions.dart +++ b/lib/pangea/utils/instructions.dart @@ -73,7 +73,7 @@ class InstructionsController { children: [ CardHeader( text: key.title(context), - botExpression: BotExpression.surprised, + botExpression: BotExpression.idle, onClose: () => {_instructionsClosed[key] = true}, ), const SizedBox(height: 10.0), diff --git a/lib/pangea/widgets/common/bot_face_svg.dart b/lib/pangea/widgets/common/bot_face_svg.dart index b856596dd..f387b4bc3 100644 --- a/lib/pangea/widgets/common/bot_face_svg.dart +++ b/lib/pangea/widgets/common/bot_face_svg.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:rive/rive.dart'; -enum BotExpression { surprised, right, addled, left, down, shocked } +enum BotExpression { gold, nonGold, addled, idle, surprised } class BotFace extends StatefulWidget { final double width; @@ -21,7 +21,7 @@ class BotFace extends StatefulWidget { class BotFaceState extends State { Artboard? _artboard; - SMINumber? _input; + StateMachineController? _controller; @override void initState() { @@ -31,11 +31,11 @@ class BotFaceState extends State { double mapExpressionToInput(BotExpression expression) { switch (expression) { - case BotExpression.surprised: + case BotExpression.gold: return 1.0; - case BotExpression.right: + case BotExpression.nonGold: return 2.0; - case BotExpression.shocked: + case BotExpression.surprised: return 3.0; case BotExpression.addled: return 4.0; @@ -48,14 +48,13 @@ class BotFaceState extends State { final riveFile = await RiveFile.asset('assets/pangea/bot_faces/pangea_bot.riv'); final artboard = riveFile.mainArtboard; - final controller = StateMachineController + _controller = StateMachineController .fromArtboard(artboard, 'BotIconStateMachine'); - if (controller != null) { - artboard.addController(controller); - _input = controller.findInput("Enter State") as SMINumber?; - controller.setInputValue( - 890, // this should be the id of the input + if (_controller != null) { + artboard.addController(_controller!); + _controller!.setInputValue( + _controller!.stateMachine.inputs[0].id, mapExpressionToInput(widget.expression), ); } @@ -79,6 +78,17 @@ class BotFaceState extends State { : Container(), ); } + + @override + void didUpdateWidget(BotFace oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.expression != widget.expression) { + _controller!.setInputValue( + _controller!.stateMachine.inputs[0].id, + mapExpressionToInput(widget.expression), + ); + } + } } // extension ParseToString on BotExpressions { diff --git a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart index d10fd6980..7e242b706 100644 --- a/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart +++ b/lib/pangea/widgets/conversation_bot/conversation_bot_settings.dart @@ -142,7 +142,7 @@ class ConversationBotSettingsState extends State { Theme.of(context).textTheme.bodyLarge!.color, child: const BotFace( width: 30.0, - expression: BotExpression.right, + expression: BotExpression.idle, ), ), activeColor: AppConfig.activeToggleColor, diff --git a/lib/pangea/widgets/igc/pangea_text_controller.dart b/lib/pangea/widgets/igc/pangea_text_controller.dart index c476ccca0..adecb4f00 100644 --- a/lib/pangea/widgets/igc/pangea_text_controller.dart +++ b/lib/pangea/widgets/igc/pangea_text_controller.dart @@ -85,12 +85,6 @@ class PangeaTextController extends TextEditingController { cursorOffset: selection.baseOffset, ), onITStart: () { - if (choreographer.igc.turnOnAutoPlay) { - choreographer.pangeaController.pStoreService.save( - 'ToolSetting.itAutoPlay', - true, - ); - } choreographer.onITStart( choreographer.igc.igcTextData!.matches[matchIndex], ); diff --git a/lib/pangea/widgets/igc/span_card.dart b/lib/pangea/widgets/igc/span_card.dart index 9b9fbb4ec..3d6df9928 100644 --- a/lib/pangea/widgets/igc/span_card.dart +++ b/lib/pangea/widgets/igc/span_card.dart @@ -15,6 +15,7 @@ import '../../../widgets/matrix.dart'; import '../../choreographer/widgets/choice_array.dart'; import '../../controllers/pangea_controller.dart'; import '../../enum/span_choice_type.dart'; +import '../../models/class_model.dart'; import '../../models/span_card_model.dart'; import '../common/bot_face_svg.dart'; import 'card_header.dart'; @@ -49,6 +50,8 @@ class SpanCardState extends State { bool fetchingData = false; int? selectedChoiceIndex; + BotExpression currentExpression = BotExpression.nonGold; + //on initState, get SpanDetails @override void initState() { @@ -121,7 +124,23 @@ class WordMatchContent extends StatelessWidget { .choices?[index] .selected = true; - controller.setState(() => ()); + controller.setState( + () => ( + controller.currentExpression = + controller + .widget + .scm + .choreographer + .igc + .igcTextData + !.matches[controller.widget.scm.matchIndex] + .match + .choices![index] + .isBestCorrection + ? BotExpression.gold + : BotExpression.nonGold + ), + ); // if (controller.widget.scm.pangeaMatch.match.choices![index].type == // SpanChoiceType.distractor) { // await controller.getSpanDetails(); @@ -166,7 +185,7 @@ class WordMatchContent extends StatelessWidget { CardHeader( text: controller.error?.toString() ?? matchCopy.title, botExpression: controller.error == null - ? BotExpression.right + ? controller.currentExpression : BotExpression.addled, ), Expanded( @@ -284,10 +303,7 @@ class WordMatchContent extends StatelessWidget { ), if (controller.widget.scm.pangeaMatch!.isITStart) DontShowSwitchListTile( - value: controller.widget.scm.choreographer.igc.turnOnAutoPlay, - onChanged: ((value) { - controller.widget.scm.choreographer.igc.turnOnAutoPlay = value; - }), + controller: pangeaController, ), ], ); @@ -429,13 +445,11 @@ class StartITButton extends StatelessWidget { } class DontShowSwitchListTile extends StatefulWidget { - final bool value; - final ValueChanged onChanged; + final PangeaController controller; const DontShowSwitchListTile({ super.key, - required this.value, - required this.onChanged, + required this.controller, }); @override @@ -448,7 +462,6 @@ class DontShowSwitchListTileState extends State { @override void initState() { super.initState(); - switchValue = widget.value; } @override @@ -458,7 +471,10 @@ class DontShowSwitchListTileState extends State { title: Text(L10n.of(context)!.interactiveTranslatorAutoPlaySliderHeader), value: switchValue, onChanged: (value) => { - widget.onChanged(value), + widget.controller.pStoreService.save( + ToolSetting.itAutoPlay.toString(), + value, + ), setState(() => switchValue = value), }, ); diff --git a/lib/pangea/widgets/new_group/vocab_list.dart b/lib/pangea/widgets/new_group/vocab_list.dart index e6c2675e4..240e99a85 100644 --- a/lib/pangea/widgets/new_group/vocab_list.dart +++ b/lib/pangea/widgets/new_group/vocab_list.dart @@ -271,7 +271,7 @@ class GenerateVocabButtonState extends State { ElevatedButton.icon( icon: const BotFace( width: 50.0, - expression: BotExpression.right, + expression: BotExpression.idle, ), label: Text(L10n.of(context)!.generateVocabulary), onPressed: () async { @@ -464,9 +464,9 @@ class PromptsFieldState extends State { // button to call API ElevatedButton.icon( - icon: const BotFace( + icon: BotFace( width: 50.0, - expression: BotExpression.right, + expression: BotExpression.idle, ), label: Text(L10n.of(context)!.generatePrompts), onPressed: () async {