private TextWidget getSettingInfoData(OrganizerSettingsData settingData)
        {
            string extraSettings = settingData.ExtraSettings;

            extraSettings = extraSettings.Replace("\\n", "\n");
            TextWidget dataTypeInfo = new TextWidget(extraSettings, pointSize: 10);

            dataTypeInfo.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            dataTypeInfo.Margin    = new BorderDouble(5, 0);
            return(dataTypeInfo);
        }
        private TabControl CreateExtraSettingsSideTabsAndPages(int minSettingNameWidth, TabControl categoryTabs, out int count)
        {
            count = 0;
            TabControl sideTabs = new TabControl(Orientation.Vertical);

            sideTabs.Margin             = new BorderDouble(0, 0, 0, 5);
            sideTabs.TabBar.BorderColor = RGBA_Bytes.White;
            {
                TabPage             groupTabPage   = new TabPage("Extra Settings");
                SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget(groupTabPage, 14,
                                                                             ActiveTheme.Instance.TabLabelSelected, new RGBA_Bytes(), ActiveTheme.Instance.TabLabelUnselected, new RGBA_Bytes());
                sideTabs.AddTab(groupTabWidget);

                FlowLayoutWidget subGroupLayoutTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
                subGroupLayoutTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
                subGroupLayoutTopToBottom.VAnchor = VAnchor.FitToChildren;

                FlowLayoutWidget topToBottomSettings = new FlowLayoutWidget(FlowDirection.TopToBottom);
                topToBottomSettings.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;

                foreach (KeyValuePair <string, DataStorage.SliceSetting> item in ActiveSliceSettings.Instance.DefaultSettings)
                {
                    if (!SliceSettingsOrganizer.Instance.Contains(UserLevel, item.Key))
                    {
                        OrganizerSettingsData settingInfo            = new OrganizerSettingsData(item.Key, item.Key, OrganizerSettingsData.DataEditTypes.STRING);
                        GuiWidget             controlsForThisSetting = CreateSettingInfoUIControls(settingInfo, minSettingNameWidth);
                        topToBottomSettings.AddChild(controlsForThisSetting);
                        count++;
                    }
                }

                GroupBox groupBox = new GroupBox(new LocalizedString("Extra").Translated);
                groupBox.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
                groupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
                groupBox.AddChild(topToBottomSettings);
                groupBox.VAnchor = VAnchor.FitToChildren;
                groupBox.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;

                subGroupLayoutTopToBottom.AddChild(groupBox);

                ScrollableWidget scrollOnGroupTab = new ScrollableWidget(true);
                scrollOnGroupTab.AnchorAll();
                scrollOnGroupTab.AddChild(subGroupLayoutTopToBottom);
                groupTabPage.AddChild(scrollOnGroupTab);
            }
            return(sideTabs);
        }
        private void AddInHelpText(FlowLayoutWidget topToBottomSettings, OrganizerSettingsData settingInfo)
        {
            FlowLayoutWidget allText         = new FlowLayoutWidget(FlowDirection.TopToBottom);
            double           textRegionWidth = 380;

            allText.Margin          = new BorderDouble(3);
            allText.Padding         = new BorderDouble(5);
            allText.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;

            double helpPointSize = 10;

            string[] wrappedText = TypeFacePrinter.WrapText(settingInfo.HelpText, textRegionWidth - allText.Padding.Width, helpPointSize);
            foreach (string line in wrappedText)
            {
                GuiWidget helpWidget = new TextWidget(line, pointSize: helpPointSize, textColor: RGBA_Bytes.White);
                allText.AddChild(helpWidget);
            }

            allText.MinimumSize = new Vector2(textRegionWidth, allText.MinimumSize.y);
            if (wrappedText.Length > 0)
            {
                topToBottomSettings.AddChild(allText);
            }
        }
Beispiel #4
0
        void LoadAndParseSettingsFiles(string properties, string layout)
        {
            {
                string propertiesFileContents = "";
                using (FileStream fileStream = new FileStream(properties, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader propertiesReader = new StreamReader(fileStream))
                    {
                        propertiesFileContents = propertiesReader.ReadToEnd();
                    }
                }

                string[] lines = propertiesFileContents.Split('\n');
                foreach (string line in lines)
                {
                    if (line.Trim().Length > 0)
                    {
                        settingsData.Add(OrganizerSettingsData.NewOrganizerSettingData(line));
                    }
                }
            }

            {
                string layoutFileContents = "";
                using (FileStream fileStream = new FileStream(layout, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader layoutReader = new StreamReader(fileStream))
                    {
                        layoutFileContents = layoutReader.ReadToEnd();
                    }
                }

                OrganizerUserLevel userLevelToAddTo = null;
                OrganizerCategory  categoryToAddTo  = null;
                OrganizerGroup     groupToAddTo     = null;
                OrganizerSubGroup  subGroupToAddTo  = null;
                string[]           lines            = layoutFileContents.Split('\n');
                foreach (string line in lines)
                {
                    if (line.Length > 0)
                    {
                        switch (CountLeadingSpaces(line))
                        {
                        case 0:
                            string userLevelText = line.Replace('"', ' ').Trim();
                            userLevelToAddTo = new OrganizerUserLevel(userLevelText);
                            UserLevels.Add(userLevelText, userLevelToAddTo);
                            break;

                        case 2:
                            categoryToAddTo = new OrganizerCategory(line.Replace('"', ' ').Trim());
                            userLevelToAddTo.CategoriesList.Add(categoryToAddTo);
                            break;

                        case 4:
                            groupToAddTo = new OrganizerGroup(line.Replace('"', ' ').Trim());
                            categoryToAddTo.GroupsList.Add(groupToAddTo);
                            break;

                        case 6:
                            subGroupToAddTo = new OrganizerSubGroup(line.Replace('"', ' ').Trim());
                            groupToAddTo.SubGroupsList.Add(subGroupToAddTo);
                            break;

                        case 8:
                            subGroupToAddTo.SettingDataList.Add(GetSettingsData(line.Replace('"', ' ').Trim()));
                            break;

                        default:
                            throw new Exception("Bad file, too many spaces (must be 0, 2, 4 or 6).");
                        }
                    }
                }
            }
        }
        private GuiWidget CreateSettingInfoUIControls(OrganizerSettingsData settingData, double minSettingNameWidth)
        {
            FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();

            if (ActiveSliceSettings.Instance.Contains(settingData.SlicerConfigName))
            {
                int intEditWidth        = 60;
                int doubleEditWidth     = 60;
                int vectorXYEditWidth   = 60;
                int multiLineEditHeight = 60;

                string sliceSettingValue = ActiveSliceSettings.Instance.GetActiveValue(settingData.SlicerConfigName);
                leftToRightLayout.Margin   = new BorderDouble(0, 5);
                leftToRightLayout.HAnchor |= Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;

                if (settingData.DataEditType != OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT)
                {
                    string convertedNewLines = settingData.PresentationName.Replace("\\n ", "\n");
                    convertedNewLines = convertedNewLines.Replace("\\n", "\n");
                    convertedNewLines = new LocalizedString(convertedNewLines).Translated;
                    TextWidget settingName = new TextWidget(convertedNewLines);
                    settingName.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                    settingName.Width     = minSettingNameWidth;
                    //settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                    leftToRightLayout.AddChild(settingName);
                }

                switch (settingData.DataEditType)
                {
                case OrganizerSettingsData.DataEditTypes.INT:
                {
                    int currentValue = 0;
                    int.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit intEditWidget = new MHNumberEdit(currentValue, pixelWidth: intEditWidth, tabIndex: tabIndexForItem++);
                    intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(intEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.POSITVE_DOUBLE:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET:
                {
                    double currentValue = 0;
                    double.TryParse(sliceSettingValue, out currentValue);
                    MHNumberEdit doubleEditWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: doubleEditWidth, tabIndex: tabIndexForItem++);
                    doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString()); };
                    leftToRightLayout.AddChild(doubleEditWidget);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.DOUBLE_OR_PERCENT:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 60, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) =>
                    {
                        TextEditWidget textEditWidget = (TextEditWidget)sender;
                        string         text           = textEditWidget.Text;
                        text = text.Trim();
                        bool isPercent = text.Contains("%");
                        if (isPercent)
                        {
                            text = text.Substring(0, text.IndexOf("%"));
                        }
                        double result;
                        double.TryParse(text, out result);
                        text = result.ToString();
                        if (isPercent)
                        {
                            text += "%";
                        }
                        textEditWidget.Text = text;
                        SaveSetting(settingData.SlicerConfigName, textEditWidget.Text);
                    };

                    leftToRightLayout.AddChild(stringEdit);
                    leftToRightLayout.AddChild(getSettingInfoData(settingData));
                }
                break;

                case OrganizerSettingsData.DataEditTypes.CHECK_BOX:
                {
                    CheckBox checkBoxWidget = new CheckBox("");
                    checkBoxWidget.VAnchor              = Agg.UI.VAnchor.ParentBottom;
                    checkBoxWidget.TextColor            = ActiveTheme.Instance.PrimaryTextColor;
                    checkBoxWidget.Checked              = (sliceSettingValue == "1");
                    checkBoxWidget.CheckedStateChanged += (sender, e) =>
                    {
                        if (((CheckBox)sender).Checked)
                        {
                            SaveSetting(settingData.SlicerConfigName, "1");
                        }
                        else
                        {
                            SaveSetting(settingData.SlicerConfigName, "0");
                        }
                    };
                    leftToRightLayout.AddChild(checkBoxWidget);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.STRING:
                {
                    MHTextEditWidget stringEdit = new MHTextEditWidget(sliceSettingValue, pixelWidth: 120, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text); };
                    leftToRightLayout.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.MULTI_LINE_TEXT:
                {
                    string           convertedNewLines = sliceSettingValue.Replace("\\n", "\n");
                    MHTextEditWidget stringEdit        = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++);
                    stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n")); };
                    leftToRightLayout.AddChild(stringEdit);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.LIST:
                {
                    StyledDropDownList selectableOptions = new StyledDropDownList("None", Direction.Up);
                    selectableOptions.Margin = new BorderDouble();

                    string[] listItems = settingData.ExtraSettings.Split(',');
                    foreach (string listItem in listItems)
                    {
                        MenuItem newItem = selectableOptions.AddItem(listItem);
                        if (newItem.Text == sliceSettingValue)
                        {
                            selectableOptions.SelectedValue = sliceSettingValue;
                        }

                        newItem.Selected += (sender, e) =>
                        {
                            MenuItem menuItem = ((MenuItem)sender);
                            SaveSetting(settingData.SlicerConfigName, menuItem.Text);
                        };
                    }
                    leftToRightLayout.AddChild(selectableOptions);
                }
                break;

                case OrganizerSettingsData.DataEditTypes.VECTOR2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split(',');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(yText);
                    }
                }
                break;

                case OrganizerSettingsData.DataEditTypes.OFFSET2:
                {
                    string[] xyValueStrings = sliceSettingValue.Split('x');
                    if (xyValueStrings.Length != 2)
                    {
                        xyValueStrings = new string[] { "0", "0" };
                    }
                    double currentXValue = 0;
                    double.TryParse(xyValueStrings[0], out currentXValue);
                    MHNumberEdit xEditWidget = new MHNumberEdit(currentXValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);

                    double currentYValue = 0;
                    double.TryParse(xyValueStrings[1], out currentYValue);
                    MHNumberEdit yEditWidget = new MHNumberEdit(currentYValue, allowDecimals: true, allowNegatives: true, pixelWidth: vectorXYEditWidth, tabIndex: tabIndexForItem++);
                    {
                        xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(xEditWidget);
                        TextWidget xText = new TextWidget("x");
                        xText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        xText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(xText);
                    }
                    {
                        yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "x" + yEditWidget.ActuallNumberEdit.Value.ToString()); };
                        leftToRightLayout.AddChild(yEditWidget);
                        TextWidget yText = new TextWidget("y");
                        yText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                        yText.Margin    = new BorderDouble(5, 0);
                        leftToRightLayout.AddChild(yText);
                    }
                }
                break;

                default:
                    TextWidget missingSetting = new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()));
                    missingSetting.TextColor       = ActiveTheme.Instance.PrimaryTextColor;
                    missingSetting.BackgroundColor = RGBA_Bytes.Red;
                    leftToRightLayout.AddChild(missingSetting);
                    break;
                }
            }
            else // the setting we think we are adding is not in the config.ini it may have been depricated
            {
                TextWidget settingName = new TextWidget(String.Format("Setting '{0}' not found in config.ini", settingData.SlicerConfigName));
                settingName.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
                settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
                leftToRightLayout.AddChild(settingName);
                leftToRightLayout.BackgroundColor = RGBA_Bytes.Red;
            }

            return(leftToRightLayout);
        }