Skip to content

Commit

Permalink
Merge pull request #2 from guchengxi1994/feat/position
Browse files Browse the repository at this point in the history
Feat/position
  • Loading branch information
guchengxi1994 authored Jul 3, 2024
2 parents 0a3db63 + bd34511 commit b2c8e64
Show file tree
Hide file tree
Showing 40 changed files with 2,037 additions and 215 deletions.
69 changes: 40 additions & 29 deletions assets/images/tiled/maps/city.tmj

Large diffs are not rendered by default.

831 changes: 780 additions & 51 deletions assets/images/tiled/maps/city.tsj

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions assets/images/tiled/maps/ground.tsj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@
"tilecount":52,
"tiledversion":"1.10.2",
"tileheight":48,
"tiles":[
{
"id":38,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":48,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":48,
"x":0,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}
}],
"tilewidth":48,
"type":"tileset",
"version":"1.10"
Expand Down
27 changes: 27 additions & 0 deletions assets/images/tiled/maps/ground_16.tsj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@
"tilecount":52,
"tiledversion":"1.10.2",
"tileheight":16,
"tiles":[
{
"id":38,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":16,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":16,
"x":0,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}
}],
"tilewidth":16,
"type":"tileset",
"version":"1.10"
Expand Down
2 changes: 1 addition & 1 deletion lib/common/toast_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ToastUtils {
alignment: Alignment.bottomCenter,
builder: (ctx, holder) {
return SizedBox(
width: 200,
width: tip.length > 10 ? 400 : 200,
height: 50,
child: Center(
child: Text(
Expand Down
4 changes: 4 additions & 0 deletions lib/game/components/base_mentor_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:make_a_dream/common/logger_utils.dart';
import 'package:make_a_dream/game/components/quiz_selection_dialog.dart';
import 'package:make_a_dream/game/components/talk_mixin.dart';
import 'package:make_a_dream/game/models/quiz_model.dart';
Expand Down Expand Up @@ -36,6 +37,9 @@ class _BaseMentorState extends ConsumerState<BaseMentorDialog> with TalkMixin {
@override
void initState() {
super.initState();

logger.info("prompt ${widget.prompt}");

if (talked) {
ref.read(baseMentorProvider(widget.mentorName).notifier).plotQuiz();
} else {
Expand Down
151 changes: 151 additions & 0 deletions lib/game/components/gaoshi_dialog.dart
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"))
],
),
)
],
))
],
),
))
],
),
),
);
}
}
13 changes: 8 additions & 5 deletions lib/game/components/quiz_selection_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:flutter/material.dart';
import 'package:make_a_dream/game/models/quiz_model.dart';
import 'package:make_a_dream/game/models/base_quiz_model.dart';
import 'package:make_a_dream/game/models/character_quiz_model.dart';

typedef OnClick = void Function(bool b);

class QuizSelectionDialog extends StatelessWidget {
class QuizSelectionDialog<T extends BaseQuizModel> extends StatelessWidget {
const QuizSelectionDialog(
{super.key, required this.quizModel, required this.onClick});
final QuizModel? quizModel;
final T? quizModel;
final OnClick onClick;

@override
Expand All @@ -23,9 +24,11 @@ class QuizSelectionDialog extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 50,
height: 100,
child: Text(
"问题如下:${quizModel!.question}",
quizModel is CharacterQuizModel
? "问题如下 ${(quizModel! as CharacterQuizModel).quiz} ${quizModel!.question}"
: "问题如下: ${quizModel!.question}",
style: const TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
),
Expand Down
1 change: 1 addition & 0 deletions lib/game/components/splash_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class _SplashWrapperState extends State<SplashWrapper>
SizedBox(
width: 170,
child: AnimatedTextKit(
repeatForever: true,
animatedTexts: [
ColorizeAnimatedText(
'Loading ...',
Expand Down
7 changes: 6 additions & 1 deletion lib/game/decorations/base_mentor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:bonfire/bonfire.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:make_a_dream/game/components/base_mentor_dialog.dart';
import 'package:make_a_dream/game/notifiers/base_mentor_notifier.dart';
import 'package:make_a_dream/game/notifiers/player_notifier.dart';

import 'decoration_mixin.dart';
Expand All @@ -28,6 +29,8 @@ class BaseMentor extends GameDecoration with Sensor<Player>, DecorationMixin {
if (!isTouched) {
isTouched = true;
gameRef.player!.stopMove();
final history =
ref.read(baseMentorProvider(mentorName).notifier).getHistory();
showGeneralDialog(
barrierLabel: "mentor",
barrierDismissible: true,
Expand All @@ -41,7 +44,9 @@ class BaseMentor extends GameDecoration with Sensor<Player>, DecorationMixin {
.read(playerProvider)
.current!
.knowledge
.getKnowledgePrompt(teacherType: mentorName),
.getKnowledgePrompt(
teacherType: mentorName,
his: history.isNotEmpty ? history.join(";") : null),
),
);
});
Expand Down
26 changes: 26 additions & 0 deletions lib/game/decorations/bridge.dart
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);
}
}
34 changes: 34 additions & 0 deletions lib/game/decorations/chair.dart
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);
}
}
7 changes: 5 additions & 2 deletions lib/game/decorations/classroom_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:make_a_dream/game/decorations/decoration_mixin.dart';
import 'package:make_a_dream/game/maps/room_route.dart';
import 'package:make_a_dream/game/notifiers/multiple_map_notifier.dart';
// import 'package:vector_math/vector_math_64.dart' hide Vector2;

class ClassroomEntry extends GameDecoration
with Sensor<Player>, DecorationMixin {
Expand Down Expand Up @@ -35,8 +36,10 @@ class ClassroomEntry extends GameDecoration
isTouched = true;
gameRef.player!.stopMove();
}
updatePosition(ref, Vector2(position.x, position.y + 20));
ref.read(multipleMapProvider.notifier).switchTo(RoomRoute.routeName);
// updatePosition(ref, Vector2(position.x, position.y + 20));
ref
.read(multipleMapProvider.notifier)
.switchTo(RoomRoute.routeName, initial: Vector2(2 * 48, 8 * 48));
super.onContact(component);
}

Expand Down
Loading

0 comments on commit b2c8e64

Please sign in to comment.