Skip to content

Commit 9f9f763

Browse files
committed
Fix unable find link-button between ether width slider and add auto label name generation
1 parent e0d3572 commit 9f9f763

5 files changed

Lines changed: 32 additions & 14 deletions

File tree

lib/page/panel/builder/page_panel_builder_controller.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:VirtualFlightThrottle/utility/utility_dart.dart';
99
import 'package:VirtualFlightThrottle/utility/utility_system.dart';
1010
import 'package:flutter/material.dart';
1111
import 'package:flutter/services.dart';
12-
import 'package:fluttertoast/fluttertoast.dart';
1312

1413
enum SelectableTileState {
1514
USED,
@@ -54,13 +53,14 @@ class PagePanelBuilderController with ChangeNotifier {
5453
if (!this.checkComponentSize(width, height)) {
5554
SystemUtility.showToast(message: "The selected area is smaller than the minimum size required by component.");
5655
return;
57-
}
58-
else if (!this.checkComponentPosition(x, y, width, height)) return;
56+
} else if (!this.checkComponentPosition(x, y, width, height)) return;
5957
this.firstPoint = null;
6058
this.insertComponent(getDefaultComponentSetting(this.selectedComponent,
6159
name: PanelUtility.findNewName(this.panelSetting, this.selectedComponent),
6260
x: x, y: y, width: width, height: height,
63-
targetInputs: PanelUtility.findTargetInput(this.panelSetting, this.selectedComponent)),
61+
targetInputs: PanelUtility.findTargetInput(this.panelSetting, this.selectedComponent),
62+
inserts: {ComponentSettingType.LABEL: PanelUtility.findNewLabel(panelSetting, this.selectedComponent)},
63+
),
6464
);
6565
}
6666
notifyListeners();
@@ -71,9 +71,8 @@ class PagePanelBuilderController with ChangeNotifier {
7171
&& height >= COMPONENT_DEFINITION[this.selectedComponent].minHeight;
7272

7373
bool checkComponentPosition(int x, int y, int width, int height) {
74-
for (int w = x; w < width + x; w++) for (int h = y; h < height + y; h++) {
74+
for (int w = x; w < width + x; w++) for (int h = y; h < height + y; h++)
7575
if (this.componentPositionMap[w][h] == SelectableTileState.USED) return false;
76-
}
7776
return true;
7877
}
7978

lib/page/panel/builder/widget/component_builder_dialog.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:VirtualFlightThrottle/utility/utility_system.dart';
99
import 'package:card_settings/card_settings.dart';
1010
import 'package:flutter/cupertino.dart';
1111
import 'package:flutter/material.dart';
12-
import 'package:fluttertoast/fluttertoast.dart';
1312

1413
class ComponentBuilderDialog extends StatefulWidget {
1514

@@ -37,11 +36,11 @@ class _ComponentBuilderDialogState extends State<ComponentBuilderDialog> {
3736
else return CardSettingsNumberPicker(
3837
label: S.of(context).dialogComponentBuilder_target_button(index + 1),
3938
initialValue: widget.targetComponentSetting.targetInputs[index] == 0
40-
? 0 : widget.targetComponentSetting.targetInputs[index] - NetworkProtocol.ANALOGUE_INPUT_COUNT + 1,
39+
? 0 : widget.targetComponentSetting.targetInputs[index] - NetworkProtocol.ANALOGUE_INPUT_COUNT,
4140
min: 0,
4241
max: NetworkProtocol.DIGITAL_INPUT_COUNT,
4342
onChanged: (val) => widget.targetComponentSetting.targetInputs[index] = val == 0
44-
? 0 : val + NetworkProtocol.ANALOGUE_INPUT_COUNT - 1,
43+
? 0 : val + NetworkProtocol.ANALOGUE_INPUT_COUNT,
4544
);
4645
}
4746

lib/panel/component/component_definition.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class ComponentDefinition {
153153
final String Function(BuildContext) getL10nComponentName;
154154
final String Function(BuildContext) getL10nDescription;
155155
final String shortName;
156+
final String labelName;
156157

157158
final int minWidth;
158159
final int minHeight;
@@ -168,6 +169,7 @@ class ComponentDefinition {
168169
@required this.getL10nComponentName,
169170
@required this.getL10nDescription,
170171
@required this.shortName,
172+
@required this.labelName,
171173

172174
@required this.minWidth,
173175
@required this.minHeight,
@@ -190,6 +192,7 @@ final Map<ComponentType, ComponentDefinition> COMPONENT_DEFINITION = {
190192
getL10nComponentName: (context) => S.of(context).componentInfo_slider_name,
191193
getL10nDescription: (context) => S.of(context).componentInfo_slider_description,
192194
shortName: "Slider",
195+
labelName: "SLIDR",
193196

194197
minWidth: 1,
195198
minHeight: 1,
@@ -219,6 +222,7 @@ final Map<ComponentType, ComponentDefinition> COMPONENT_DEFINITION = {
219222
getL10nComponentName: (context) => S.of(context).componentInfo_button_name,
220223
getL10nDescription: (context) => S.of(context).componentInfo_button_description,
221224
shortName: "Button",
225+
labelName: "BTN",
222226

223227
minWidth: 1,
224228
minHeight: 1,
@@ -240,6 +244,7 @@ final Map<ComponentType, ComponentDefinition> COMPONENT_DEFINITION = {
240244
getL10nComponentName: (context) => S.of(context).componentInfo_toggleButton_name,
241245
getL10nDescription: (context) => S.of(context).componentInfo_toggleButton_description,
242246
shortName: "Toggle Button",
247+
labelName: "TBTN",
243248

244249
minWidth: 1,
245250
minHeight: 1,
@@ -261,6 +266,7 @@ final Map<ComponentType, ComponentDefinition> COMPONENT_DEFINITION = {
261266
getL10nComponentName: (context) => S.of(context).componentInfo_toggleSwitch_name,
262267
getL10nDescription: (context) => S.of(context).componentInfo_toggleSwitch_description,
263268
shortName: "Toggle Switch",
269+
labelName: "SWICH",
264270

265271
minWidth: 1,
266272
minHeight: 1,
@@ -280,6 +286,7 @@ final Map<ComponentType, ComponentDefinition> COMPONENT_DEFINITION = {
280286
getL10nComponentName: (context) => S.of(context).componentInfo_hatSwitch_name,
281287
getL10nDescription: (context) => S.of(context).componentInfo_hatSwitch_description,
282288
shortName: "Hat Switch",
289+
labelName: "HAT",
283290

284291
minWidth: 2,
285292
minHeight: 2,

lib/panel/panel.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ class Panel extends StatelessWidget {
4343
this.panelSetting.components.forEach((key, component) {
4444
if (component.componentType == ComponentType.SLIDER) {
4545
for (ComponentSetting targetComponent in this.panelSetting.components.values) {
46-
if (component.x + 1 == targetComponent.x && component.y == targetComponent.y
47-
&& component.width == targetComponent.width && component.height == targetComponent.height) {
46+
if (component.x + component.width == targetComponent.x
47+
&& component.y == targetComponent.y
48+
&& component.height == targetComponent.height) {
4849
result.add(Selector<PanelController, bool>(
4950
selector: (context, value) => value.hasAnalogueSync(component.targetInputs[0]),
5051
builder: (context, bool enabled, Widget _) {
5152
PanelController panelController = Provider.of<PanelController>(context, listen: false);
5253
return Positioned(
53-
left: (component.x + 1) * this.blockWidth - 14,
54+
left: (component.x + component.width) * this.blockWidth - 14,
5455
bottom: component.y * this.blockHeight + 4,
5556
child: GestureDetector(
5657
child: Center(
@@ -59,8 +60,7 @@ class Panel extends StatelessWidget {
5960
color: panelController.hasAnalogueSync(component.targetInputs[0]) ? Colors.green : Colors.grey,
6061
),
6162
),
62-
onTap: () =>
63-
panelController.switchAnalogueSync(component.targetInputs[0], targetComponent.targetInputs[0]),
63+
onTap: () => panelController.switchAnalogueSync(component.targetInputs[0], targetComponent.targetInputs[0]),
6464
),
6565
);
6666
}

lib/panel/panel_manager.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ class PanelUtility {
3333
return "UNNAMED";
3434
}
3535

36+
static String findNewLabel(PanelSetting panelSetting, ComponentType componentType) {
37+
for (int idx = 1; idx < 100; idx ++) {
38+
bool include = false;
39+
panelSetting.components.entries.forEach((val) {
40+
if (val.value.settings[ComponentSettingType.LABEL].value == "${COMPONENT_DEFINITION[componentType].labelName}$idx")
41+
include = true;
42+
});
43+
if (!include)
44+
return "${COMPONENT_DEFINITION[componentType].labelName}$idx";
45+
}
46+
return "NAME";
47+
}
48+
3649
static List<int> findTargetInput(PanelSetting panelSetting, ComponentType componentType) {
3750
Set<int> usedInputs = Set<int>();
3851
panelSetting.components.forEach((key, val) {

0 commit comments

Comments
 (0)