-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from guchengxi1994/feat/position
Feat/position
- Loading branch information
Showing
40 changed files
with
2,037 additions
and
215 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// ignore_for_file: avoid_init_to_null | ||
|
||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:make_a_dream/game/components/avatar_widget.dart'; | ||
import 'package:make_a_dream/game/components/quiz_selection_dialog.dart'; | ||
import 'package:make_a_dream/game/models/character_quiz_model.dart'; | ||
import 'package:make_a_dream/game/notifiers/base_mentor_notifier.dart'; | ||
import 'package:make_a_dream/global/ai_client.dart'; | ||
import 'package:make_a_dream/isar/database.dart'; | ||
import 'package:markdown_widget/markdown_widget.dart'; | ||
|
||
class GaoshiDialog extends ConsumerStatefulWidget { | ||
const GaoshiDialog({super.key, required this.npcName, this.prompt = ""}); | ||
final String npcName; | ||
final String prompt; | ||
|
||
@override | ||
ConsumerState<GaoshiDialog> createState() => _GaoshiDialogState(); | ||
} | ||
|
||
class _GaoshiDialogState extends ConsumerState<GaoshiDialog> { | ||
bool isExpanded = false; | ||
final AiClient aiClient = AiClient(); | ||
final IsarDatabase isarDatabase = IsarDatabase(); | ||
final ScrollController controller = ScrollController(); | ||
|
||
bool correct = false; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
ref | ||
.read(baseMentorProvider(widget.npcName).notifier) | ||
.plot(humanMessage: widget.prompt); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final state = ref.watch(baseMentorProvider(widget.npcName)); | ||
CharacterQuizModel? quizModel = null; | ||
try { | ||
quizModel = CharacterQuizModel.fromJson(jsonDecode( | ||
state.dialog.replaceAll("```json", "").replaceAll("```", ""))); | ||
} catch (_) {} | ||
|
||
return Material( | ||
color: Colors.transparent, | ||
child: Container( | ||
decoration: const BoxDecoration(color: Colors.transparent), | ||
padding: const EdgeInsets.all(10), | ||
child: Stack( | ||
children: [ | ||
const SizedBox.expand(), | ||
Positioned( | ||
bottom: 0, | ||
child: Container( | ||
padding: const EdgeInsets.all(10), | ||
width: MediaQuery.of(context).size.width - 20, | ||
height: isExpanded | ||
? MediaQuery.of(context).size.height * 0.8 | ||
: 200, | ||
decoration: BoxDecoration( | ||
color: Colors.white.withOpacity(0.7), | ||
border: Border.all(width: 3), | ||
borderRadius: BorderRadius.circular(20)), | ||
child: Row( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
SizedBox( | ||
width: 200, | ||
height: 200, | ||
child: NpcAvatarWidget( | ||
avatar: aiClient.getAvatarByName(state.npc.name), | ||
name: state.npc.name, | ||
), | ||
), | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Expanded( | ||
child: SingleChildScrollView( | ||
controller: ref | ||
.read( | ||
baseMentorProvider(widget.npcName).notifier) | ||
.controller, | ||
child: quizModel != null | ||
? QuizSelectionDialog( | ||
quizModel: quizModel, | ||
onClick: (b) { | ||
correct = b; | ||
if (b) { | ||
ref | ||
.read(baseMentorProvider( | ||
widget.npcName) | ||
.notifier) | ||
.simplePlot(quizModel!.reason); | ||
} else { | ||
ref | ||
.read(baseMentorProvider( | ||
widget.npcName) | ||
.notifier) | ||
.simplePlot( | ||
"回答错误.\n${quizModel!.reason}"); | ||
} | ||
}) | ||
: MarkdownBlock( | ||
data: state.dialog, | ||
selectable: false, | ||
config: MarkdownConfig.defaultConfig, | ||
), | ||
)), | ||
if (state.conversationDone && state.dialog != "") | ||
SizedBox( | ||
height: 40, | ||
child: Row( | ||
children: [ | ||
const Expanded(child: SizedBox()), | ||
TextButton( | ||
autofocus: true, | ||
onPressed: () { | ||
setState(() { | ||
isExpanded = !isExpanded; | ||
}); | ||
}, | ||
child: isExpanded | ||
? const Icon(Icons.expand_more) | ||
: const Icon(Icons.expand_less)), | ||
TextButton( | ||
autofocus: true, | ||
onPressed: () { | ||
Navigator.of(context).pop(correct); | ||
}, | ||
child: const Text("Got it")) | ||
], | ||
), | ||
) | ||
], | ||
)) | ||
], | ||
), | ||
)) | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:bonfire/bonfire.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:make_a_dream/game/decorations/decoration_mixin.dart'; | ||
|
||
class Bridge extends GameDecoration with Sensor<Player>, DecorationMixin { | ||
Bridge({required super.position, required super.size, required this.ref}); | ||
|
||
bool isTouched = false; | ||
final WidgetRef ref; | ||
|
||
@override | ||
void onContact(Player component) { | ||
if (!isTouched) { | ||
isTouched = true; | ||
gameRef.player!.stopMove(); | ||
} | ||
updatePosition(ref, position); | ||
super.onContact(component); | ||
} | ||
|
||
@override | ||
void onContactExit(Player component) { | ||
isTouched = false; | ||
super.onContactExit(component); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:bonfire/bonfire.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:make_a_dream/common/toast_utils.dart'; | ||
import 'package:make_a_dream/game/notifiers/player_notifier.dart'; | ||
|
||
class Chair extends GameDecoration with Sensor<Player> { | ||
Chair({required super.position, required super.size, required this.ref}); | ||
|
||
bool isTouched = false; | ||
final WidgetRef ref; | ||
|
||
@override | ||
void onContact(Player component) { | ||
super.onContact(component); | ||
if (gameRef.player != null && !isTouched) { | ||
gameRef.player!.stopMove(); | ||
isTouched = true; | ||
if (ref.read(playerProvider).current!.knowledge.total > 650) { | ||
ToastUtils.decorationTip(null, tip: "是时候了!"); | ||
} else { | ||
ToastUtils.decorationTip(null, tip: "时机尚未成熟,我的朋友..."); | ||
// [23 * 16 = 368,58 * 928] | ||
gameRef.player!.translate(Vector2(368 - position.x, 928 - position.y)); | ||
gameRef.player!.moveDown(); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void onContactExit(Player component) { | ||
isTouched = false; | ||
super.onContactExit(component); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.