Enable option to turn on mouselook

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-17 20:45:29 +01:00
parent 55cf73f7f5
commit c424e10475
5 changed files with 199 additions and 70 deletions

View File

@@ -35,6 +35,7 @@ class _DifficultyScreenState extends State<DifficultyScreen> {
difficulty: difficulty,
startingEpisode: widget.wolf3d.activeEpisode,
audio: widget.wolf3d.audio,
input: widget.wolf3d.input,
),
),
);

View File

@@ -3,7 +3,6 @@ import 'package:flutter/services.dart';
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
import 'package:wolf_3d_dart/wolf_3d_engine.dart';
import 'package:wolf_3d_flutter/wolf_3d_input_flutter.dart';
import 'package:wolf_3d_dart/wolf_3d_input.dart';
import 'package:wolf_3d_renderer/wolf_3d_ascii_renderer.dart';
import 'package:wolf_3d_renderer/wolf_3d_flutter_renderer.dart';
@@ -12,12 +11,14 @@ class GameScreen extends StatefulWidget {
final Difficulty difficulty;
final int startingEpisode;
final EngineAudio audio;
final Wolf3dFlutterInput input;
const GameScreen({
required this.data,
required this.difficulty,
required this.startingEpisode,
required this.audio,
required this.input,
super.key,
});
@@ -27,19 +28,17 @@ class GameScreen extends StatefulWidget {
class _GameScreenState extends State<GameScreen> {
late final WolfEngine _engine;
late final Wolf3dInput _input;
bool _useAsciiMode = false;
@override
void initState() {
super.initState();
_input = Wolf3dFlutterInput();
_engine = WolfEngine(
data: widget.data,
difficulty: widget.difficulty,
startingEpisode: widget.startingEpisode,
audio: widget.audio,
input: _input,
input: widget.input,
onGameWon: () => Navigator.of(context).pop(),
);
_engine.init();
@@ -48,65 +47,71 @@ class _GameScreenState extends State<GameScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
_useAsciiMode
? WolfAsciiRenderer(engine: _engine)
: WolfFlutterRenderer(engine: _engine),
body: Listener(
onPointerDown: widget.input.onPointerDown,
onPointerUp: widget.input.onPointerUp,
onPointerMove: widget.input.onPointerMove,
onPointerHover: widget.input.onPointerMove,
child: Stack(
children: [
_useAsciiMode
? WolfAsciiRenderer(engine: _engine)
: WolfFlutterRenderer(engine: _engine),
if (!_engine.isInitialized)
Container(
color: Colors.black,
child: const Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(color: Colors.teal),
SizedBox(height: 20),
Text(
"GET PSYCHED!",
style: TextStyle(
color: Colors.teal,
fontFamily: 'monospace',
if (!_engine.isInitialized)
Container(
color: Colors.black,
child: const Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(color: Colors.teal),
SizedBox(height: 20),
Text(
"GET PSYCHED!",
style: TextStyle(
color: Colors.teal,
fontFamily: 'monospace',
),
),
),
],
],
),
),
),
// TAB listener
Focus(
autofocus: true,
onKeyEvent: (node, event) {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.tab) {
setState(() => _useAsciiMode = !_useAsciiMode);
return KeyEventResult.handled;
}
return KeyEventResult.ignored;
},
child: const SizedBox.shrink(),
),
// TAB listener
Focus(
autofocus: true,
onKeyEvent: (node, event) {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.tab) {
setState(() => _useAsciiMode = !_useAsciiMode);
return KeyEventResult.handled;
}
return KeyEventResult.ignored;
},
child: const SizedBox.shrink(),
),
// Loading Overlay
if (!_engine.isInitialized)
Container(
color: Colors.black,
child: const Center(
child: CircularProgressIndicator(color: Colors.teal),
),
),
// Loading Overlay
if (!_engine.isInitialized)
Container(
color: Colors.black,
child: const Center(
child: CircularProgressIndicator(color: Colors.teal),
Positioned(
top: 16,
right: 16,
child: Text(
'TAB: Swap Renderer',
style: TextStyle(color: Colors.white.withValues(alpha: 0.5)),
),
),
Positioned(
top: 16,
right: 16,
child: Text(
'TAB: Swap Renderer',
style: TextStyle(color: Colors.white.withValues(alpha: 0.5)),
),
),
],
],
),
),
);
}