Skip to content

Commit

Permalink
Fix unable find link-button between ether width slider and add auto l…
Browse files Browse the repository at this point in the history
…abel name generation
  • Loading branch information
junghyun397 committed Feb 11, 2020
1 parent e0d3572 commit 9f9f763
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
11 changes: 5 additions & 6 deletions lib/page/panel/builder/page_panel_builder_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:VirtualFlightThrottle/utility/utility_dart.dart';
import 'package:VirtualFlightThrottle/utility/utility_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

enum SelectableTileState {
USED,
Expand Down Expand Up @@ -54,13 +53,14 @@ class PagePanelBuilderController with ChangeNotifier {
if (!this.checkComponentSize(width, height)) {
SystemUtility.showToast(message: "The selected area is smaller than the minimum size required by component.");
return;
}
else if (!this.checkComponentPosition(x, y, width, height)) return;
} else if (!this.checkComponentPosition(x, y, width, height)) return;
this.firstPoint = null;
this.insertComponent(getDefaultComponentSetting(this.selectedComponent,
name: PanelUtility.findNewName(this.panelSetting, this.selectedComponent),
x: x, y: y, width: width, height: height,
targetInputs: PanelUtility.findTargetInput(this.panelSetting, this.selectedComponent)),
targetInputs: PanelUtility.findTargetInput(this.panelSetting, this.selectedComponent),
inserts: {ComponentSettingType.LABEL: PanelUtility.findNewLabel(panelSetting, this.selectedComponent)},
),
);
}
notifyListeners();
Expand All @@ -71,9 +71,8 @@ class PagePanelBuilderController with ChangeNotifier {
&& height >= COMPONENT_DEFINITION[this.selectedComponent].minHeight;

bool checkComponentPosition(int x, int y, int width, int height) {
for (int w = x; w < width + x; w++) for (int h = y; h < height + y; h++) {
for (int w = x; w < width + x; w++) for (int h = y; h < height + y; h++)
if (this.componentPositionMap[w][h] == SelectableTileState.USED) return false;
}
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/page/panel/builder/widget/component_builder_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:VirtualFlightThrottle/utility/utility_system.dart';
import 'package:card_settings/card_settings.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class ComponentBuilderDialog extends StatefulWidget {

Expand Down Expand Up @@ -37,11 +36,11 @@ class _ComponentBuilderDialogState extends State<ComponentBuilderDialog> {
else return CardSettingsNumberPicker(
label: S.of(context).dialogComponentBuilder_target_button(index + 1),
initialValue: widget.targetComponentSetting.targetInputs[index] == 0
? 0 : widget.targetComponentSetting.targetInputs[index] - NetworkProtocol.ANALOGUE_INPUT_COUNT + 1,
? 0 : widget.targetComponentSetting.targetInputs[index] - NetworkProtocol.ANALOGUE_INPUT_COUNT,
min: 0,
max: NetworkProtocol.DIGITAL_INPUT_COUNT,
onChanged: (val) => widget.targetComponentSetting.targetInputs[index] = val == 0
? 0 : val + NetworkProtocol.ANALOGUE_INPUT_COUNT - 1,
? 0 : val + NetworkProtocol.ANALOGUE_INPUT_COUNT,
);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/panel/component/component_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class ComponentDefinition {
final String Function(BuildContext) getL10nComponentName;
final String Function(BuildContext) getL10nDescription;
final String shortName;
final String labelName;

final int minWidth;
final int minHeight;
Expand All @@ -168,6 +169,7 @@ class ComponentDefinition {
@required this.getL10nComponentName,
@required this.getL10nDescription,
@required this.shortName,
@required this.labelName,

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

minWidth: 1,
minHeight: 1,
Expand Down Expand Up @@ -219,6 +222,7 @@ final Map<ComponentType, ComponentDefinition> COMPONENT_DEFINITION = {
getL10nComponentName: (context) => S.of(context).componentInfo_button_name,
getL10nDescription: (context) => S.of(context).componentInfo_button_description,
shortName: "Button",
labelName: "BTN",

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

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

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

minWidth: 2,
minHeight: 2,
Expand Down
10 changes: 5 additions & 5 deletions lib/panel/panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ class Panel extends StatelessWidget {
this.panelSetting.components.forEach((key, component) {
if (component.componentType == ComponentType.SLIDER) {
for (ComponentSetting targetComponent in this.panelSetting.components.values) {
if (component.x + 1 == targetComponent.x && component.y == targetComponent.y
&& component.width == targetComponent.width && component.height == targetComponent.height) {
if (component.x + component.width == targetComponent.x
&& component.y == targetComponent.y
&& component.height == targetComponent.height) {
result.add(Selector<PanelController, bool>(
selector: (context, value) => value.hasAnalogueSync(component.targetInputs[0]),
builder: (context, bool enabled, Widget _) {
PanelController panelController = Provider.of<PanelController>(context, listen: false);
return Positioned(
left: (component.x + 1) * this.blockWidth - 14,
left: (component.x + component.width) * this.blockWidth - 14,
bottom: component.y * this.blockHeight + 4,
child: GestureDetector(
child: Center(
Expand All @@ -59,8 +60,7 @@ class Panel extends StatelessWidget {
color: panelController.hasAnalogueSync(component.targetInputs[0]) ? Colors.green : Colors.grey,
),
),
onTap: () =>
panelController.switchAnalogueSync(component.targetInputs[0], targetComponent.targetInputs[0]),
onTap: () => panelController.switchAnalogueSync(component.targetInputs[0], targetComponent.targetInputs[0]),
),
);
}
Expand Down
13 changes: 13 additions & 0 deletions lib/panel/panel_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ class PanelUtility {
return "UNNAMED";
}

static String findNewLabel(PanelSetting panelSetting, ComponentType componentType) {
for (int idx = 1; idx < 100; idx ++) {
bool include = false;
panelSetting.components.entries.forEach((val) {
if (val.value.settings[ComponentSettingType.LABEL].value == "${COMPONENT_DEFINITION[componentType].labelName}$idx")
include = true;
});
if (!include)
return "${COMPONENT_DEFINITION[componentType].labelName}$idx";
}
return "NAME";
}

static List<int> findTargetInput(PanelSetting panelSetting, ComponentType componentType) {
Set<int> usedInputs = Set<int>();
panelSetting.components.forEach((key, val) {
Expand Down

0 comments on commit 9f9f763

Please sign in to comment.