game_bottom_bar.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import 'package:flutter/material.dart';
  2. import 'package:shirne_dialog/shirne_dialog.dart';
  3. import '../models/game_manager.dart';
  4. import '../models/play_mode.dart';
  5. import 'play_step.dart';
  6. class GameBottomBar extends StatefulWidget {
  7. final PlayMode mode;
  8. const GameBottomBar(this.mode, {Key? key}) : super(key: key);
  9. @override
  10. State<GameBottomBar> createState() => GameBottomBarState();
  11. }
  12. class GameBottomBarState extends State<GameBottomBar> {
  13. final GameManager gamer = GameManager.instance;
  14. @override
  15. Widget build(BuildContext context) {
  16. if (widget.mode == PlayMode.modeRobot) {
  17. return robotBottomBar();
  18. }
  19. if (widget.mode == PlayMode.modeRobot) {
  20. return onlineBottomBar();
  21. }
  22. return freeBottomBar();
  23. }
  24. void _showStepList() {
  25. final size = MediaQuery.of(context).size;
  26. MyDialog.popup(
  27. SizedBox(
  28. height: size.height * 0.75,
  29. child: Center(
  30. child: PlayStep(
  31. width: size.width * 0.8,
  32. ),
  33. ),
  34. ),
  35. isScrollControlled: true,
  36. );
  37. }
  38. void _showCode() {}
  39. void _doReply() {}
  40. void _goPrev() {
  41. if (gamer.currentStep < 1) return;
  42. gamer.loadHistory(gamer.currentStep - 1);
  43. setState(() {});
  44. }
  45. void _goNext() {
  46. if (gamer.currentStep + 1 >= gamer.stepCount) return;
  47. gamer.loadHistory(gamer.currentStep + 1);
  48. setState(() {});
  49. }
  50. Widget freeBottomBar() {
  51. return BottomAppBar(
  52. child: Row(
  53. mainAxisAlignment: MainAxisAlignment.spaceAround,
  54. children: [
  55. IconButton(icon: const Icon(Icons.list), onPressed: _showStepList),
  56. IconButton(icon: const Icon(Icons.code), onPressed: _showCode),
  57. IconButton(
  58. icon: const Icon(Icons.navigate_before),
  59. onPressed: _goPrev,
  60. ),
  61. IconButton(icon: const Icon(Icons.navigate_next), onPressed: _goNext)
  62. ],
  63. ),
  64. );
  65. }
  66. Widget onlineBottomBar() {
  67. return BottomAppBar(
  68. child: Row(
  69. mainAxisAlignment: MainAxisAlignment.spaceAround,
  70. children: [
  71. IconButton(icon: const Icon(Icons.list), onPressed: _showStepList),
  72. IconButton(icon: const Icon(Icons.replay), onPressed: _doReply),
  73. IconButton(
  74. icon: const Icon(Icons.navigate_before),
  75. onPressed: _goPrev,
  76. ),
  77. IconButton(icon: const Icon(Icons.navigate_next), onPressed: _goNext)
  78. ],
  79. ),
  80. );
  81. }
  82. Widget robotBottomBar() {
  83. return BottomAppBar(
  84. child: Row(
  85. mainAxisAlignment: MainAxisAlignment.spaceAround,
  86. children: [
  87. IconButton(icon: const Icon(Icons.list), onPressed: _showStepList),
  88. IconButton(icon: const Icon(Icons.replay), onPressed: _doReply),
  89. IconButton(
  90. icon: const Icon(Icons.navigate_before),
  91. onPressed: _goPrev,
  92. ),
  93. IconButton(icon: const Icon(Icons.navigate_next), onPressed: _goNext)
  94. ],
  95. ),
  96. );
  97. }
  98. }