页面UI替换1远程遥控和各项弹窗和作业主页面和子页面+路径规划的主页面重构等

This commit is contained in:
2026-10-28 14:38:24 +08:00
parent 8a41113c92
commit eb8dec2868
64 changed files with 25316 additions and 1174 deletions

View File

@@ -10,6 +10,55 @@ class JoystickValue {
JoystickValue(this.x, this.y);
}
/// 摇杆可视化皮肤(可选)。传 null 时保持原有青色科技风绘制,行为完全不变。
///
/// 新增该皮肤是为了支持「深色玻璃圆盘 + 白色摇杆球 + 方向文字」的样式,
/// 只影响绘制,不参与手势与取值逻辑。
class JoystickSkin {
const JoystickSkin({
required this.baseColor,
required this.baseEdgeColor,
required this.ringColor,
required this.arrowColor,
required this.knobColor,
required this.knobShadowColor,
required this.labelColor,
this.upLabel,
this.downLabel,
this.leftLabel,
this.rightLabel,
this.labelSize = 13,
});
/// 圆盘径向渐变:内圈 / 外圈色
final Color baseColor;
final Color baseEdgeColor;
/// 圆盘描边与内圈参考环颜色
final Color ringColor;
/// 方向箭头颜色
final Color arrowColor;
/// 摇杆球颜色(径向渐变外圈,内圈自动提亮)
final Color knobColor;
/// 摇杆球投影颜色
final Color knobShadowColor;
/// 方向文字颜色
final Color labelColor;
/// 上 / 下 / 左 / 右方向文字(为空则该方向只画箭头)
final String? upLabel;
final String? downLabel;
final String? leftLabel;
final String? rightLabel;
/// 方向文字字号(已由调用方按屏幕缩放)
final double labelSize;
}
class CCJoystick extends StatefulWidget {
final AxisHint axisHint;
final Function(JoystickValue) onValueChanged;
@@ -17,6 +66,9 @@ class CCJoystick extends StatefulWidget {
final Future<void> Function()? onPanEnd; // 🔥 修复:改为异步回调
final double radius;
/// 可选皮肤:为空时用默认青色科技风(老页面观感不变)。
final JoystickSkin? skin;
const CCJoystick({
super.key,
required this.axisHint,
@@ -24,6 +76,7 @@ class CCJoystick extends StatefulWidget {
this.onPress,
this.onPanEnd, // 🔥 新增
this.radius = 80,
this.skin,
});
@override
@@ -122,6 +175,7 @@ class _CustomJoystickState extends State<CCJoystick>
radius: widget.radius,
axisHint: widget.axisHint,
floatValue: _floatController.value * 10 - 5, // -5f 到 5f
skin: widget.skin,
),
);
},
@@ -147,16 +201,27 @@ class JoystickPainter extends CustomPainter {
final AxisHint axisHint;
final double floatValue;
/// 可选皮肤:非空时改走深色玻璃风绘制分支。
final JoystickSkin? skin;
JoystickPainter({
required this.offset,
required this.radius,
required this.axisHint,
required this.floatValue,
this.skin,
});
@override
void paint(Canvas canvas, Size size) {
final center = Offset(size.width / 2, size.height / 2);
// 传入皮肤的页面走深色玻璃风:底盘 + 参考环 + 蓝色方向箭头 + 文字 + 白球
if (skin != null) {
_paintSkin(canvas, center, size);
return;
}
final paint = Paint();
// 1. 绘制底盘 (对应 Color(0x6600BFFF))
@@ -212,6 +277,165 @@ class JoystickPainter extends CustomPainter {
canvas.drawCircle(center + offset, 35, paint);
}
/// 深色玻璃皮肤绘制:圆盘 → 参考环 → 方向箭头与文字 → 摇杆球。
/// 只做视觉,手势与取值由 State 负责,与默认分支互不影响。
void _paintSkin(Canvas canvas, Offset center, Size size) {
final s = skin!;
final disk = radius + 8;
// 1. 底盘:径向渐变深灰玻璃 + 半透明白描边
canvas.drawCircle(
center,
disk,
Paint()
..shader = RadialGradient(
colors: [s.baseColor, s.baseEdgeColor],
).createShader(Rect.fromCircle(center: center, radius: disk)),
);
canvas.drawCircle(
center,
disk,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1.5
..color = s.ringColor,
);
// 2. 参考环:给出中心区(摇杆球的行程范围)
canvas.drawCircle(
center,
radius * 0.6,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1
..color = s.ringColor.withValues(alpha: 0.55),
);
canvas.drawCircle(
center,
radius * 0.9,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1
..color = s.ringColor.withValues(alpha: 0.35),
);
// 3. 方向箭头 + 文字(文字靠盘边,箭头贴内,和球留出呼吸)
final isFB = axisHint == AxisHint.forwardBackward;
_skinArm(
canvas,
anchor: center + Offset(0, -radius * 0.5),
textAnchor: center + Offset(0, -radius * 0.78),
text: isFB ? s.upLabel : s.leftLabel,
direction: isFB ? _ArmDir.up : _ArmDir.left,
s: s,
);
_skinArm(
canvas,
anchor: center + Offset(0, radius * 0.5),
textAnchor: center + Offset(0, radius * 0.78),
text: isFB ? s.downLabel : s.rightLabel,
direction: isFB ? _ArmDir.down : _ArmDir.right,
s: s,
);
if (isFB) {
_skinArm(
canvas,
anchor: center + Offset(-radius * 0.5, 0),
textAnchor: center + Offset(-radius * 0.72, 0),
text: s.leftLabel,
direction: _ArmDir.left,
s: s,
);
_skinArm(
canvas,
anchor: center + Offset(radius * 0.5, 0),
textAnchor: center + Offset(radius * 0.72, 0),
text: s.rightLabel,
direction: _ArmDir.right,
s: s,
);
}
// 4. 摇杆球:白色径向渐变 + 柔和投影
final knobCenter = center + offset;
final knobR = radius * 0.42;
canvas.drawCircle(
knobCenter + Offset(0, knobR * 0.16),
knobR,
Paint()
..color = s.knobShadowColor
..maskFilter = MaskFilter.blur(BlurStyle.normal, knobR * 0.35),
);
canvas.drawCircle(
knobCenter,
knobR,
Paint()
..shader = RadialGradient(
center: const Alignment(-0.35, -0.45),
colors: [Colors.white, s.knobColor],
stops: const [0.15, 1],
).createShader(Rect.fromCircle(center: knobCenter, radius: knobR)),
);
}
/// 皮肤版本的单个方向:蓝色小箭头(杆 + 三角头)+ 方向文字
void _skinArm(
Canvas canvas, {
required Offset anchor,
required Offset textAnchor,
required String? text,
required _ArmDir direction,
required JoystickSkin s,
}) {
final len = radius * 0.16;
final head = radius * 0.09;
final paint = Paint()
..color = s.arrowColor
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = radius * 0.035;
canvas.save();
canvas.translate(anchor.dx, anchor.dy);
// 统一按「朝上」绘制,再按方向旋转,避免四份重复坐标
canvas.rotate(switch (direction) {
_ArmDir.up => 0,
_ArmDir.right => 1.5708,
_ArmDir.down => 3.1416,
_ArmDir.left => -1.5708,
});
// 杆
canvas.drawLine(Offset(0, len * 0.5), Offset(0, -len * 0.5), paint);
// 三角头
canvas.drawPath(
Path()
..moveTo(0, -len * 0.95)
..lineTo(-head, -len * 0.35)
..lineTo(head, -len * 0.35)
..close(),
Paint()..color = s.arrowColor,
);
canvas.restore();
if (text == null || text.isEmpty) return;
final tp = TextPainter(
text: TextSpan(
text: text,
style: TextStyle(
color: s.labelColor,
fontSize: s.labelSize,
fontWeight: FontWeight.w600,
height: 1.1,
),
),
textDirection: TextDirection.ltr,
)..layout();
tp.paint(
canvas,
textAnchor - Offset(tp.width / 2, tp.height / 2),
);
}
void _drawArrow(
Canvas canvas,
Offset pos,
@@ -242,3 +466,6 @@ class JoystickPainter extends CustomPainter {
@override
bool shouldRepaint(covariant JoystickPainter oldDelegate) => true;
}
/// 皮肤方向枚举(仅供 [_skinArm] 的旋转映射使用)
enum _ArmDir { up, down, left, right }