选择图片
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flame_audio/flame_audio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_first_station/muyu/animate_text.dart';
|
||||
import 'models/image_option.dart';
|
||||
import 'muyu_image.dart';
|
||||
|
||||
import 'count_panel.dart';
|
||||
import 'muyu_app_bar.dart';
|
||||
import 'options/select_image.dart';
|
||||
|
||||
class MuyuPage extends StatefulWidget {
|
||||
const MuyuPage({Key? key}) : super(key: key);
|
||||
@@ -18,9 +21,15 @@ class MuyuPage extends StatefulWidget {
|
||||
class _MuyuPageState extends State<MuyuPage> {
|
||||
int _counter = 0;
|
||||
int _cruValue = 0;
|
||||
int _activeImageIndex = 0;
|
||||
|
||||
final Random _random = Random();
|
||||
|
||||
final List<ImageOption> imageOptions = const [
|
||||
ImageOption('基础版', 'assets/images/muyu.png', 1, 3),
|
||||
ImageOption('尊享版', 'assets/images/muyu2.png', 3, 6),
|
||||
];
|
||||
|
||||
AudioPool? pool;
|
||||
|
||||
@override
|
||||
@@ -56,7 +65,7 @@ class _MuyuPageState extends State<MuyuPage> {
|
||||
alignment: Alignment.topCenter,
|
||||
children: [
|
||||
MuyuAssetsImage(
|
||||
image: 'assets/images/muyu.png',
|
||||
image: activeImage,
|
||||
onTap: _onKnock,
|
||||
),
|
||||
if (_cruValue != 0) AnimateText(text: '功德+$_cruValue')
|
||||
@@ -72,13 +81,41 @@ class _MuyuPageState extends State<MuyuPage> {
|
||||
|
||||
void _onTapSwitchAudio() {}
|
||||
|
||||
void _onTapSwitchImage() {}
|
||||
void _onTapSwitchImage() {
|
||||
showCupertinoModalPopup(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ImageOptionPanel(
|
||||
imageOptions: imageOptions,
|
||||
activeIndex: _activeImageIndex,
|
||||
onSelect: _onSelectImage,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _onKnock() {
|
||||
pool?.start();
|
||||
setState(() {
|
||||
_cruValue = 1 + _random.nextInt(3);
|
||||
_cruValue = knockValue;
|
||||
_counter += _cruValue;
|
||||
});
|
||||
}
|
||||
|
||||
String get activeImage => imageOptions[_activeImageIndex].src;
|
||||
|
||||
int get knockValue {
|
||||
int min = imageOptions[_activeImageIndex].min;
|
||||
int max = imageOptions[_activeImageIndex].max;
|
||||
return min + _random.nextInt(max+1 - min);
|
||||
}
|
||||
|
||||
|
||||
void _onSelectImage(int value) {
|
||||
Navigator.of(context).pop();
|
||||
if(value == _activeImageIndex) return;
|
||||
setState(() {
|
||||
_activeImageIndex = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user