added game status
This commit is contained in:
200
lib/widgets/game_state_view.dart
Normal file
200
lib/widgets/game_state_view.dart
Normal file
@ -0,0 +1,200 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/services/DatabaseService.dart';
|
||||
import 'package:rogapp/utils/database_helper.dart';
|
||||
import 'package:rogapp/widgets/GameState/CheckinState.dart';
|
||||
import 'package:rogapp/widgets/GameState/ConnectionStatus.dart';
|
||||
import 'package:rogapp/widgets/GameState/DashboardWidget.dart';
|
||||
import 'package:rogapp/widgets/GameState/game_on_off.dart';
|
||||
|
||||
class GameStateManager {
|
||||
static final GameStateManager _instance = GameStateManager._internal();
|
||||
|
||||
factory GameStateManager() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
GameStateManager._internal();
|
||||
|
||||
List<String> _logs = [];
|
||||
List<VoidCallback> _listeners = [];
|
||||
|
||||
List<String> get logs => _logs;
|
||||
|
||||
void addLog(String log) {
|
||||
_logs.add(log);
|
||||
_notifyListeners(); // Notify all listeners
|
||||
}
|
||||
|
||||
void clearLogs() {
|
||||
_logs.clear();
|
||||
_notifyListeners(); // Notify all listeners
|
||||
}
|
||||
|
||||
void addListener(VoidCallback listener) {
|
||||
_listeners.add(listener);
|
||||
}
|
||||
|
||||
void removeListener(VoidCallback listener) {
|
||||
_listeners.remove(listener);
|
||||
}
|
||||
|
||||
void _notifyListeners() {
|
||||
for (var listener in _listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GameStateWidget extends StatefulWidget {
|
||||
const GameStateWidget({super.key});
|
||||
|
||||
@override
|
||||
State<GameStateWidget> createState() => _GameStateWidgetState();
|
||||
}
|
||||
|
||||
class _GameStateWidgetState extends State<GameStateWidget> {
|
||||
final GameStateManager gameStateManager = GameStateManager();
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
final DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
gameStateManager.addListener(_updateLogs);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
gameStateManager.removeListener(_updateLogs);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _updateLogs() {
|
||||
Future.delayed(Duration.zero, () {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void toggleExpanded() {
|
||||
setState(() {
|
||||
isExpanded = !isExpanded;
|
||||
});
|
||||
}
|
||||
|
||||
void clearLogs() {
|
||||
gameStateManager.clearLogs();
|
||||
}
|
||||
|
||||
bool isExpanded = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final DatabaseService dbService = DatabaseService();
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
decoration: BoxDecoration(color: Colors.black12),
|
||||
child: GestureDetector(
|
||||
onTap: toggleExpanded,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
color: isExpanded ? Colors.black54 : Colors.black12,
|
||||
height: isExpanded ? 160.0 : 48.0, // Adjust sizes as needed
|
||||
child: Column(
|
||||
children: [
|
||||
// Top bar with clear button
|
||||
if (isExpanded)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
||||
color: Colors.blueGrey, // Adjust color as needed
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text('ゲームステータス', style: TextStyle(color: Colors.white)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.clear, color: Colors.white),
|
||||
onPressed: toggleExpanded,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Log messages
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceEvenly,
|
||||
children: [
|
||||
Obx(() => Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: GameStatusIndicator(
|
||||
gameStarted: destinationController.isInRog.value,
|
||||
minimized: !isExpanded,
|
||||
),
|
||||
)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: StreamBuilder<List<Destination>>(
|
||||
stream: dbService.destinationUpdatesStream,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState ==
|
||||
ConnectionState.waiting) {
|
||||
return const CircularProgressIndicator();
|
||||
} else if (snapshot.hasError) {
|
||||
return LocationVisitedWidget(
|
||||
count: 0,
|
||||
minimized: !isExpanded,
|
||||
);
|
||||
} else if (snapshot.hasData) {
|
||||
return LocationVisitedWidget(
|
||||
count: snapshot.data!.length,
|
||||
minimized: !isExpanded,
|
||||
);
|
||||
} else {
|
||||
return LocationVisitedWidget(
|
||||
count: 0,
|
||||
minimized: !isExpanded,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
// child: LocationVisitedWidget(
|
||||
// count:
|
||||
// minimized: !isExpanded,
|
||||
// ),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: ConnectionStatusIndicator(
|
||||
connectionStatus: ConnectionStatus.wifi,
|
||||
minimized: !isExpanded),
|
||||
) // Expanded view
|
||||
],
|
||||
),
|
||||
// child: Obx(
|
||||
// () => DashboardWidget(
|
||||
// gameStarted: destinationController.isInRog.value,
|
||||
// locationsVisited: 3,
|
||||
// isMinimized: false,
|
||||
// ),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user