2018-01-23 09:52:05 -08:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
2021-07-25 18:22:40 -07:00
|
|
|
|
using System.IO;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
2018-06-04 09:55:54 -07:00
|
|
|
|
using System.Threading;
|
2021-07-25 18:22:40 -07:00
|
|
|
|
using System.Web;
|
2021-04-17 22:35:53 -07:00
|
|
|
|
using Markdig.Agg;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2018-02-27 18:16:07 -08:00
|
|
|
|
using MatterHackers.Agg.Image;
|
2018-02-12 17:45:57 -08:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
2021-05-21 15:23:25 -07:00
|
|
|
|
using MatterHackers.ImageProcessing;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2021-07-25 18:22:40 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2018-06-01 17:44:46 -07:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools.EditableTypes;
|
2019-02-11 18:16:05 -08:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools.Operations;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2018-06-04 09:55:54 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
|
2018-02-09 18:10:41 -08:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
|
2018-01-23 09:52:05 -08:00
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-01-31 13:15:29 -08:00
|
|
|
|
public class PublicPropertyEditor : IObject3DEditor
|
2018-01-23 09:52:05 -08:00
|
|
|
|
{
|
|
|
|
|
|
public string Name => "Property Editor";
|
2018-01-20 12:58:14 -08:00
|
|
|
|
|
2018-06-20 08:09:35 -07:00
|
|
|
|
public IEnumerable<Type> SupportedTypes() => new Type[] { typeof(IObject3D) };
|
2018-03-27 14:03:12 -07:00
|
|
|
|
|
2020-09-14 07:36:32 -07:00
|
|
|
|
private static readonly Type[] AllowedTypes =
|
2018-01-28 07:53:23 -08:00
|
|
|
|
{
|
2018-03-13 11:52:23 -07:00
|
|
|
|
typeof(double), typeof(int), typeof(char), typeof(string), typeof(bool),
|
2021-06-06 09:07:18 -07:00
|
|
|
|
typeof(StringOrExpression),
|
2021-05-31 18:44:00 -07:00
|
|
|
|
typeof(DoubleOrExpression),
|
2021-06-01 17:48:43 -07:00
|
|
|
|
typeof(IntOrExpression),
|
2018-10-06 15:09:01 -07:00
|
|
|
|
typeof(Color),
|
2021-03-03 09:45:51 -08:00
|
|
|
|
typeof(Vector2), typeof(Vector3), typeof(Vector4),
|
2018-06-01 17:44:46 -07:00
|
|
|
|
typeof(DirectionVector), typeof(DirectionAxis),
|
2018-12-21 08:27:40 -08:00
|
|
|
|
typeof(SelectedChildren),
|
2018-06-18 09:07:48 -07:00
|
|
|
|
typeof(ImageBuffer),
|
2021-07-27 18:12:17 -07:00
|
|
|
|
typeof(Histogram),
|
2018-08-02 13:18:37 -07:00
|
|
|
|
typeof(List<string>)
|
2018-01-28 07:53:23 -08:00
|
|
|
|
};
|
2018-01-31 14:34:10 -08:00
|
|
|
|
public const BindingFlags OwnedPropertiesOnly = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
2018-01-28 07:53:23 -08:00
|
|
|
|
|
2021-08-30 08:47:11 -07:00
|
|
|
|
private SafeList<SettingsRow> rows = new SafeList<SettingsRow>();
|
2021-06-04 07:13:34 -07:00
|
|
|
|
|
2019-03-07 17:56:41 -08:00
|
|
|
|
public GuiWidget Create(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
var mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-09 09:26:37 -07:00
|
|
|
|
if (item != null)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-06-09 09:26:37 -07:00
|
|
|
|
var context = new PPEContext()
|
|
|
|
|
|
{
|
|
|
|
|
|
item = item
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// CreateEditor
|
2019-06-20 19:06:15 -07:00
|
|
|
|
AddUnlockLinkIfRequired(context.item, mainContainer, theme);
|
2021-04-17 22:35:53 -07:00
|
|
|
|
|
|
|
|
|
|
AddMarkDownDescription(context.item, mainContainer, theme);
|
2018-06-09 09:01:24 -07:00
|
|
|
|
|
2018-12-28 18:21:01 -08:00
|
|
|
|
GuiWidget scope = mainContainer;
|
|
|
|
|
|
|
2021-06-05 11:12:26 -07:00
|
|
|
|
rows.Clear();
|
|
|
|
|
|
|
2018-06-09 09:01:24 -07:00
|
|
|
|
// Create a field editor for each editable property detected via reflection
|
|
|
|
|
|
foreach (var property in GetEditablePropreties(context.item))
|
|
|
|
|
|
{
|
2019-05-18 07:25:00 -07:00
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<HideFromEditorAttribute>().Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 18:21:01 -08:00
|
|
|
|
// Create SectionWidget for SectionStartAttributes
|
|
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<SectionStartAttribute>().FirstOrDefault() is SectionStartAttribute sectionStart)
|
|
|
|
|
|
{
|
|
|
|
|
|
var column = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowDirection = FlowDirection.TopToBottom,
|
|
|
|
|
|
Padding = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-12-01 17:43:02 -08:00
|
|
|
|
bool expanded = true;
|
|
|
|
|
|
|
|
|
|
|
|
var sectionState = item as ISectionState;
|
|
|
|
|
|
if (sectionState != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
expanded = sectionState.GetSectionExpansion(sectionStart.Title);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var section = new SectionWidget(sectionStart.Title, column, theme, expanded: expanded);
|
2018-12-28 18:21:01 -08:00
|
|
|
|
theme.ApplyBoxStyle(section);
|
|
|
|
|
|
|
2019-12-01 17:43:02 -08:00
|
|
|
|
if (sectionState != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
section.ExpandedChanged += (s, e) => sectionState.SectionExpansionChanged(sectionStart.Title, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 18:21:01 -08:00
|
|
|
|
mainContainer.AddChild(section);
|
|
|
|
|
|
|
|
|
|
|
|
scope = column;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 18:28:01 -08:00
|
|
|
|
// Create SectionWidget for SectionStartAttributes
|
|
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<SectionEndAttribute>().Any())
|
|
|
|
|
|
{
|
2019-03-07 17:56:41 -08:00
|
|
|
|
// Push scope back to mainContainer on
|
2018-12-28 18:28:01 -08:00
|
|
|
|
scope = mainContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-04 07:13:34 -07:00
|
|
|
|
var editor = CreatePropertyEditor(rows, property, undoBuffer, context, theme);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
if (editor != null)
|
|
|
|
|
|
{
|
2018-12-28 18:21:01 -08:00
|
|
|
|
scope.AddChild(editor);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
}
|
2018-06-09 09:01:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-18 13:23:04 -07:00
|
|
|
|
AddWebPageLinkIfRequired(context, mainContainer, theme);
|
|
|
|
|
|
|
2018-06-09 09:01:24 -07:00
|
|
|
|
// add in an Update button if applicable
|
2019-04-22 09:23:56 -07:00
|
|
|
|
if (context.item.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() is ShowUpdateButtonAttribute showUpdate)
|
2018-06-09 09:01:24 -07:00
|
|
|
|
{
|
2018-06-25 08:40:09 -07:00
|
|
|
|
var updateButton = new TextButton("Update".Localize(), theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = 5,
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
HAnchor = HAnchor.Right,
|
|
|
|
|
|
VAnchor = VAnchor.Absolute
|
|
|
|
|
|
};
|
2018-06-09 09:01:24 -07:00
|
|
|
|
updateButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2019-01-28 14:19:40 -08:00
|
|
|
|
context.item.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties));
|
2018-06-09 09:01:24 -07:00
|
|
|
|
};
|
|
|
|
|
|
mainContainer.AddChild(updateButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-22 14:24:34 -07:00
|
|
|
|
// add any function buttons last
|
|
|
|
|
|
AddFunctionButtons(item, mainContainer, theme);
|
|
|
|
|
|
|
2018-06-09 09:01:24 -07:00
|
|
|
|
// Init with custom 'UpdateControls' hooks
|
2018-07-06 17:11:33 -07:00
|
|
|
|
(context.item as IPropertyGridModifier)?.UpdateControls(new PublicPropertyChange(context, "Update_Button"));
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mainContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-18 21:48:31 -08:00
|
|
|
|
private void AddFunctionButtons(IObject3D item, FlowLayoutWidget mainContainer, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item is IEditorButtonProvider editorButtonProvider)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var editorButtonData in editorButtonProvider.GetEditorButtonsData())
|
|
|
|
|
|
{
|
|
|
|
|
|
var editorButton = new TextButton(editorButtonData.Name, theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = 5,
|
|
|
|
|
|
ToolTipText = editorButtonData.HelpText,
|
2021-02-25 18:13:49 -08:00
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
2021-01-18 21:48:31 -08:00
|
|
|
|
};
|
2021-02-24 18:17:14 -08:00
|
|
|
|
if (editorButtonData.PrimaryAction)
|
|
|
|
|
|
{
|
|
|
|
|
|
theme.ApplyPrimaryActionStyle(editorButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-05 17:52:19 -08:00
|
|
|
|
var row = new SettingsRow("".Localize(), null, editorButton, theme);
|
2021-04-17 22:35:53 -07:00
|
|
|
|
editorButtonData.SetStates?.Invoke(editorButton, row);
|
2021-01-18 21:48:31 -08:00
|
|
|
|
editorButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
editorButtonData.Action?.Invoke();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-02-05 17:52:19 -08:00
|
|
|
|
mainContainer.AddChild(row);
|
2021-01-18 21:48:31 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-30 08:47:11 -07:00
|
|
|
|
private static SettingsRow CreateSettingsRow(EditableProperty property, GuiWidget content, ThemeConfig theme, SafeList<SettingsRow> rows = null)
|
2018-05-09 13:35:38 -07:00
|
|
|
|
{
|
2021-08-22 22:07:43 -07:00
|
|
|
|
var row = new SettingsRow(property.DisplayName.Localize(), property.Description, content, theme);
|
2021-06-05 11:12:26 -07:00
|
|
|
|
if (rows != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rows.Add(row);
|
|
|
|
|
|
row.SetTextRightMargin(rows);
|
|
|
|
|
|
}
|
2021-06-04 07:13:34 -07:00
|
|
|
|
return row;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-04 22:21:17 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(EditableProperty property, UIField field, bool fullWidth = false)
|
2018-07-02 14:50:51 -07:00
|
|
|
|
{
|
2020-10-04 22:21:17 -07:00
|
|
|
|
return CreateSettingsColumn(property.DisplayName.Localize(), field, property.Description, fullWidth: fullWidth);
|
2018-07-02 14:50:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(EditableProperty property)
|
|
|
|
|
|
{
|
2020-10-04 22:21:17 -07:00
|
|
|
|
return CreateSettingsColumn(property.DisplayName.Localize(), property.Description);
|
2018-06-01 17:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-04 22:21:17 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(string labelText, UIField field, string toolTipText = null, bool fullWidth = false)
|
2018-07-02 15:09:02 -07:00
|
|
|
|
{
|
|
|
|
|
|
var row = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
|
|
|
|
|
};
|
2020-10-10 16:18:14 -07:00
|
|
|
|
|
2020-10-04 22:21:17 -07:00
|
|
|
|
if (!fullWidth)
|
|
|
|
|
|
{
|
|
|
|
|
|
row.AddChild(new HorizontalSpacer());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-02 15:09:02 -07:00
|
|
|
|
row.AddChild(field.Content);
|
2019-06-11 12:54:51 -07:00
|
|
|
|
|
|
|
|
|
|
var column = CreateSettingsColumn(labelText, toolTipText);
|
2018-07-02 15:09:02 -07:00
|
|
|
|
column.AddChild(row);
|
2019-06-11 12:54:51 -07:00
|
|
|
|
|
2018-07-02 15:09:02 -07:00
|
|
|
|
return column;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(string labelText, string toolTipText = null)
|
|
|
|
|
|
{
|
2019-06-11 12:54:51 -07:00
|
|
|
|
var theme = AppContext.Theme;
|
|
|
|
|
|
|
|
|
|
|
|
var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2018-06-01 17:44:46 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2019-06-11 16:33:09 -07:00
|
|
|
|
Padding = new BorderDouble(9, 5, 5, 5), // Use hard-coded 9 pixel left margin to match SettingsRow
|
2018-06-01 17:44:46 -07:00
|
|
|
|
ToolTipText = toolTipText
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(labelText))
|
|
|
|
|
|
{
|
|
|
|
|
|
var label = SettingsRow.CreateSettingsLabel(labelText, toolTipText, theme.TextColor);
|
|
|
|
|
|
label.VAnchor = VAnchor.Absolute;
|
|
|
|
|
|
label.HAnchor = HAnchor.Left;
|
2019-06-11 16:33:09 -07:00
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
column.AddChild(label);
|
|
|
|
|
|
}
|
2018-06-01 17:44:46 -07:00
|
|
|
|
|
2019-06-11 12:54:51 -07:00
|
|
|
|
return column;
|
2018-06-01 17:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
public static IEnumerable<EditableProperty> GetEditablePropreties(IObject3D item)
|
2018-04-01 16:06:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
return item.GetType().GetProperties(OwnedPropertiesOnly)
|
2020-09-14 07:36:32 -07:00
|
|
|
|
.Where(pi => (AllowedTypes.Contains(pi.PropertyType) || pi.PropertyType.IsEnum)
|
2021-01-14 15:49:34 -08:00
|
|
|
|
&& pi.GetGetMethod() != null
|
|
|
|
|
|
&& pi.GetSetMethod() != null)
|
|
|
|
|
|
.Select(p => new EditableProperty(p, item));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<EditableProperty> GetExecutableFunctions(IObject3D item)
|
|
|
|
|
|
{
|
|
|
|
|
|
BindingFlags buttonFunctionsOnly = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
|
|
|
|
|
|
|
|
|
|
|
return item.GetType().GetProperties(buttonFunctionsOnly)
|
|
|
|
|
|
.Where(pi => (AllowedTypes.Contains(pi.PropertyType) || pi.PropertyType.IsEnum)
|
2018-04-01 16:06:31 -07:00
|
|
|
|
&& pi.GetGetMethod() != null
|
|
|
|
|
|
&& pi.GetSetMethod() != null)
|
|
|
|
|
|
.Select(p => new EditableProperty(p, item));
|
2018-02-10 20:17:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-31 09:01:42 -07:00
|
|
|
|
private static void EnsureFormating(EditableProperty property, UIField field)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!field.Value.StartsWith("=")
|
|
|
|
|
|
&& double.TryParse(field.Value, out double value))
|
|
|
|
|
|
{
|
|
|
|
|
|
var format = "0." + new string('#', 5);
|
|
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MaxDecimalPlacesAttribute>().FirstOrDefault() is MaxDecimalPlacesAttribute decimalPlaces)
|
|
|
|
|
|
{
|
|
|
|
|
|
format = "0." + new string('#', Math.Min(10, decimalPlaces.Number));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
field.SetValue(value.ToString(format), false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
public static GuiWidget GetFieldContentWithSlider(EditableProperty property, UIField field)
|
|
|
|
|
|
{
|
|
|
|
|
|
var sliderAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<SliderAttribute>().FirstOrDefault();
|
|
|
|
|
|
if (sliderAttribute != null)
|
|
|
|
|
|
{
|
2021-08-31 09:01:42 -07:00
|
|
|
|
var min = sliderAttribute.Min;
|
|
|
|
|
|
var max = sliderAttribute.Max;
|
|
|
|
|
|
var delta = max - min;
|
|
|
|
|
|
|
|
|
|
|
|
// the slider values go from 0 to 1 and are then mapped during translation to the field
|
|
|
|
|
|
var slider = new Slider(new Vector2(0, 0), 80 * GuiWidget.DeviceScale, 0, 1)
|
2021-08-22 22:07:43 -07:00
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Center,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-08-31 09:01:42 -07:00
|
|
|
|
Func<double> getFieldValue = null;
|
|
|
|
|
|
Action<double> setFieldValue = null;
|
|
|
|
|
|
|
|
|
|
|
|
double GetSlider0To1FromField()
|
|
|
|
|
|
{
|
|
|
|
|
|
var mapped0To1 = Math.Max(0, Math.Min(1, (getFieldValue() - min) / delta));
|
|
|
|
|
|
return Easing.CalculateInverse(sliderAttribute.EasingType, sliderAttribute.EaseOption, mapped0To1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double GetFieldFromSlider0To1()
|
2021-08-22 22:07:43 -07:00
|
|
|
|
{
|
2021-08-31 09:01:42 -07:00
|
|
|
|
var fieldValue = Easing.Calculate(sliderAttribute.EasingType,
|
2021-08-30 08:47:11 -07:00
|
|
|
|
sliderAttribute.EaseOption,
|
2021-08-31 09:01:42 -07:00
|
|
|
|
slider.Value) * delta + min;
|
|
|
|
|
|
|
|
|
|
|
|
var snapGridDistance = sliderAttribute.SnapDistance;
|
|
|
|
|
|
if (sliderAttribute.UseSnappingGrid)
|
2021-08-22 22:07:43 -07:00
|
|
|
|
{
|
2021-08-31 09:01:42 -07:00
|
|
|
|
snapGridDistance = SnapGridDistance();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (snapGridDistance > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// snap this position to the grid
|
|
|
|
|
|
// snap this position to the grid
|
|
|
|
|
|
fieldValue = ((int)((fieldValue / snapGridDistance) + .5)) * snapGridDistance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return fieldValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double SnapGridDistance()
|
|
|
|
|
|
{
|
|
|
|
|
|
var view3DWidget = slider.Parents<View3DWidget>().FirstOrDefault();
|
|
|
|
|
|
if (view3DWidget != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var object3DControlLayer = view3DWidget.Descendants<Object3DControlsLayer>().FirstOrDefault();
|
|
|
|
|
|
if (object3DControlLayer != null)
|
2021-08-22 22:07:43 -07:00
|
|
|
|
{
|
2021-08-31 09:01:42 -07:00
|
|
|
|
return object3DControlLayer.SnapGridDistance;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var changeDueToSlider = false;
|
|
|
|
|
|
var initialSliderValue = true;
|
|
|
|
|
|
slider.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
changeDueToSlider = true;
|
|
|
|
|
|
setFieldValue(GetFieldFromSlider0To1());
|
|
|
|
|
|
changeDueToSlider = false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget content = null;
|
|
|
|
|
|
var sliderRightMargin = 11;
|
|
|
|
|
|
if (field is DoubleField doubleField)
|
|
|
|
|
|
{
|
|
|
|
|
|
getFieldValue = () => doubleField.DoubleValue;
|
|
|
|
|
|
setFieldValue = (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!initialSliderValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.SetValue(value.ToString(), true);
|
|
|
|
|
|
EnsureFormating(property, field);
|
2021-08-22 22:07:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-08-31 09:01:42 -07:00
|
|
|
|
doubleField.ValueChanged += (s, e) =>
|
2021-08-22 22:07:43 -07:00
|
|
|
|
{
|
2021-08-31 09:01:42 -07:00
|
|
|
|
if (!changeDueToSlider)
|
|
|
|
|
|
{
|
|
|
|
|
|
slider.Value = GetSlider0To1FromField();
|
|
|
|
|
|
}
|
2021-08-22 22:07:43 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-08-31 09:01:42 -07:00
|
|
|
|
content = new FlowLayoutWidget();
|
2021-08-22 22:07:43 -07:00
|
|
|
|
content.AddChild(slider);
|
|
|
|
|
|
content.AddChild(new GuiWidget()
|
|
|
|
|
|
{
|
2021-08-31 09:01:42 -07:00
|
|
|
|
Width = sliderRightMargin * GuiWidget.DeviceScale,
|
2021-08-22 22:07:43 -07:00
|
|
|
|
Height = 3
|
|
|
|
|
|
});
|
|
|
|
|
|
content.AddChild(field.Content);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (field is ExpressionField expressionField)
|
|
|
|
|
|
{
|
2021-08-31 09:01:42 -07:00
|
|
|
|
getFieldValue = () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (double.TryParse(expressionField.Value, out double value))
|
|
|
|
|
|
{
|
|
|
|
|
|
return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
};
|
2021-08-22 22:07:43 -07:00
|
|
|
|
|
2021-08-31 09:01:42 -07:00
|
|
|
|
expressionField.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!changeDueToSlider)
|
|
|
|
|
|
{
|
|
|
|
|
|
slider.Value = GetSlider0To1FromField();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
setFieldValue = (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!initialSliderValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
expressionField.SetValue(value.ToString("0.##"), true);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var leftHold = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, field.Content.Children.First().Width / GuiWidget.DeviceScale + sliderRightMargin, 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
leftHold.AddChild(new HorizontalSpacer());
|
|
|
|
|
|
leftHold.AddChild(slider);
|
|
|
|
|
|
field.Content.AddChild(leftHold, 0);
|
|
|
|
|
|
|
|
|
|
|
|
content = field.Content;
|
2021-08-22 22:07:43 -07:00
|
|
|
|
}
|
2021-08-31 09:01:42 -07:00
|
|
|
|
|
|
|
|
|
|
// set the initial value of the slider
|
|
|
|
|
|
slider.Value = GetSlider0To1FromField();
|
|
|
|
|
|
initialSliderValue = false;
|
|
|
|
|
|
|
|
|
|
|
|
return content;
|
2021-08-22 22:07:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return field.Content;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-30 08:47:11 -07:00
|
|
|
|
public static GuiWidget CreatePropertyEditor(SafeList<SettingsRow> rows, EditableProperty property, UndoBuffer undoBuffer, PPEContext context, ThemeConfig theme)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2021-08-21 08:13:49 -07:00
|
|
|
|
var localItem = context.item;
|
2018-06-21 07:44:11 -07:00
|
|
|
|
var object3D = property.Item;
|
2018-06-09 08:56:16 -07:00
|
|
|
|
var propertyGridModifier = property.Item as IPropertyGridModifier;
|
|
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
GuiWidget rowContainer = null;
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-06-11 16:45:04 -07:00
|
|
|
|
// Get reflected property value once, then test for each case below
|
|
|
|
|
|
var propertyValue = property.Value;
|
|
|
|
|
|
|
2018-10-21 22:49:30 -07:00
|
|
|
|
void RegisterValueChanged(UIField field, Func<string, object> valueFromString, Func<object, string> valueToString = null)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-01-21 14:38:36 -08:00
|
|
|
|
{
|
2018-10-21 22:49:30 -07:00
|
|
|
|
var newValue = field.Value;
|
|
|
|
|
|
var oldValue = property.Value.ToString();
|
2021-06-11 11:23:15 -07:00
|
|
|
|
if (newValue == oldValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-10-21 22:49:30 -07:00
|
|
|
|
if (valueToString != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
oldValue = valueToString(property.Value);
|
|
|
|
|
|
}
|
2018-10-20 12:49:28 -07:00
|
|
|
|
|
2019-04-22 09:23:56 -07:00
|
|
|
|
// field.Content
|
2019-01-23 16:08:27 -08:00
|
|
|
|
if (undoBuffer != null)
|
2018-10-20 12:49:28 -07:00
|
|
|
|
{
|
2019-01-23 16:08:27 -08:00
|
|
|
|
undoBuffer.AddAndDo(new UndoRedoActions(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.SetValue(valueFromString(oldValue));
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2019-01-23 16:08:27 -08:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
|
|
|
|
|
},
|
|
|
|
|
|
() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.SetValue(valueFromString(newValue));
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2019-01-23 16:08:27 -08:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-10-20 12:49:28 -07:00
|
|
|
|
{
|
2018-10-21 22:49:30 -07:00
|
|
|
|
property.SetValue(valueFromString(newValue));
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2018-10-20 12:49:28 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
2019-01-23 16:08:27 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-10-21 22:49:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-14 08:24:34 -07:00
|
|
|
|
var readOnly = property.PropertyInfo.GetCustomAttributes(true).OfType<ReadOnlyAttribute>().FirstOrDefault() != null;
|
|
|
|
|
|
|
2018-10-21 22:49:30 -07:00
|
|
|
|
// create a double editor
|
|
|
|
|
|
if (propertyValue is double doubleValue)
|
|
|
|
|
|
{
|
2019-11-26 19:47:05 -08:00
|
|
|
|
if (readOnly)
|
|
|
|
|
|
{
|
2020-05-23 17:33:39 -07:00
|
|
|
|
var valueField = new TextWidget(string.Format("{0:n}", doubleValue), textColor: theme.TextColor, pointSize: 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
AutoExpandBoundsToText = true
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-11-26 19:47:05 -08:00
|
|
|
|
rowContainer = new SettingsRow(property.DisplayName.Localize(),
|
2020-10-04 22:21:17 -07:00
|
|
|
|
property.Description,
|
2019-11-26 19:47:05 -08:00
|
|
|
|
valueField,
|
|
|
|
|
|
theme);
|
2020-05-23 17:33:39 -07:00
|
|
|
|
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
|
|
|
|
|
double newValue = (double)property.Value;
|
|
|
|
|
|
valueField.Text = string.Format("{0:n}", newValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
valueField.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
2019-11-26 19:47:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
else // normal edit row
|
2018-06-21 07:44:11 -07:00
|
|
|
|
{
|
2019-11-26 19:47:05 -08:00
|
|
|
|
var field = new DoubleField(theme);
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.DoubleValue = doubleValue;
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field.ClearUndoHistory();
|
2019-11-26 19:47:05 -08:00
|
|
|
|
RegisterValueChanged(field, (valueString) => { return double.Parse(valueString); });
|
|
|
|
|
|
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
2018-06-21 07:44:11 -07:00
|
|
|
|
{
|
2019-11-26 19:47:05 -08:00
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
2018-06-21 07:44:11 -07:00
|
|
|
|
{
|
2019-11-26 19:47:05 -08:00
|
|
|
|
double newValue = (double)property.Value;
|
|
|
|
|
|
if (newValue != field.DoubleValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.DoubleValue = newValue;
|
|
|
|
|
|
}
|
2018-06-21 07:44:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-26 19:47:05 -08:00
|
|
|
|
object3D.Invalidated += RefreshField;
|
2020-11-17 12:11:42 -08:00
|
|
|
|
field.Content.Descendants<InternalTextEditWidget>().First().Name = property.DisplayName + " Edit";
|
2019-11-26 19:47:05 -08:00
|
|
|
|
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
2018-06-21 07:44:11 -07:00
|
|
|
|
|
2021-03-18 18:00:09 -07:00
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MaxDecimalPlacesAttribute>().FirstOrDefault() is MaxDecimalPlacesAttribute decimalPlaces)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.Content.Descendants<InternalNumberEdit>().First().MaxDecimalsPlaces = decimalPlaces.Number;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, GetFieldContentWithSlider(property, field), theme);
|
2019-11-26 19:47:05 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-10-06 15:09:01 -07:00
|
|
|
|
else if (propertyValue is Color color)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = new ColorField(theme, object3D.Color);
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.SetValue(field.Color);
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2018-10-06 15:09:01 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
2018-10-06 15:09:01 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is Vector2 vector2)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-10-14 20:05:37 -07:00
|
|
|
|
var field = new Vector2Field(theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Vector2 = vector2;
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
|
2018-10-21 22:49:30 -07:00
|
|
|
|
RegisterValueChanged(field,
|
2019-04-03 15:03:45 -07:00
|
|
|
|
(valueString) => Vector2.Parse(valueString),
|
2018-10-21 22:49:30 -07:00
|
|
|
|
(value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = ((Vector2)value).ToString();
|
|
|
|
|
|
return s.Substring(1, s.Length - 2);
|
|
|
|
|
|
});
|
2020-07-11 09:19:41 -07:00
|
|
|
|
|
2018-07-02 14:50:51 -07:00
|
|
|
|
rowContainer = CreateSettingsColumn(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is Vector3 vector3)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-10-14 20:05:37 -07:00
|
|
|
|
var field = new Vector3Field(theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Vector3 = vector3;
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field.ClearUndoHistory();
|
2019-04-03 15:03:45 -07:00
|
|
|
|
|
|
|
|
|
|
RegisterValueChanged(
|
|
|
|
|
|
field,
|
|
|
|
|
|
(valueString) => Vector3.Parse(valueString),
|
2018-10-21 22:49:30 -07:00
|
|
|
|
(value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = ((Vector3)value).ToString();
|
|
|
|
|
|
return s.Substring(1, s.Length - 2);
|
|
|
|
|
|
});
|
2019-04-03 15:03:45 -07:00
|
|
|
|
|
2018-07-02 14:50:51 -07:00
|
|
|
|
rowContainer = CreateSettingsColumn(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2021-03-03 09:45:51 -08:00
|
|
|
|
else if (propertyValue is Vector4 vector4)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = new Vector4Field(theme);
|
|
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<VectorFieldLabelsAttribute>().FirstOrDefault() is VectorFieldLabelsAttribute vectorFieldLabels)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.Labels = vectorFieldLabels.Labels;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Vector4 = vector4;
|
|
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
|
|
|
|
|
|
RegisterValueChanged(
|
|
|
|
|
|
field,
|
|
|
|
|
|
(valueString) => Vector4.Parse(valueString),
|
|
|
|
|
|
(value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = ((Vector4)value).ToString();
|
|
|
|
|
|
return s.Substring(1, s.Length - 2);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property, field);
|
|
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is DirectionVector directionVector)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-07-12 09:22:28 -07:00
|
|
|
|
var field = new DirectionVectorField(theme);
|
2018-06-08 20:42:06 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(directionVector);
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field.ClearUndoHistory();
|
2020-09-14 07:36:32 -07:00
|
|
|
|
|
2018-06-08 20:42:06 -07:00
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-02-09 18:10:41 -08:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.DirectionVector);
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2018-07-06 17:11:33 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
2018-06-08 16:25:35 -07:00
|
|
|
|
};
|
2018-02-14 19:56:46 -08:00
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is DirectionAxis directionAxis)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-07-02 08:11:52 -07:00
|
|
|
|
rowContainer = CreateSettingsColumn(property);
|
2019-05-24 09:03:27 -07:00
|
|
|
|
|
2018-07-12 09:22:28 -07:00
|
|
|
|
var field1 = new DirectionVectorField(theme);
|
2018-07-02 08:11:52 -07:00
|
|
|
|
field1.Initialize(0);
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field1.ClearUndoHistory();
|
|
|
|
|
|
|
2019-06-11 14:05:35 -07:00
|
|
|
|
field1.SetValue(new DirectionVector()
|
|
|
|
|
|
{
|
|
|
|
|
|
Normal = directionAxis.Normal
|
|
|
|
|
|
});
|
2018-07-02 08:11:52 -07:00
|
|
|
|
|
2019-05-26 11:08:08 -07:00
|
|
|
|
rowContainer.AddChild(new SettingsRow("Axis".Localize(), null, field1.Content, theme));
|
2018-07-02 08:11:52 -07:00
|
|
|
|
|
2018-06-08 16:25:35 -07:00
|
|
|
|
// the direction axis
|
|
|
|
|
|
// the distance from the center of the part
|
|
|
|
|
|
// create a double editor
|
2018-10-14 20:05:37 -07:00
|
|
|
|
var field2 = new Vector3Field(theme);
|
2018-07-02 08:11:52 -07:00
|
|
|
|
field2.Initialize(0);
|
2018-07-02 14:50:51 -07:00
|
|
|
|
field2.Vector3 = directionAxis.Origin - property.Item.Children.First().GetAxisAlignedBoundingBox().Center;
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field2.ClearUndoHistory();
|
2019-06-11 16:33:09 -07:00
|
|
|
|
|
|
|
|
|
|
var row2 = CreateSettingsColumn("Offset".Localize(), field2);
|
2018-06-08 16:20:57 -07:00
|
|
|
|
|
2018-06-08 21:08:56 -07:00
|
|
|
|
// update this when changed
|
2019-04-22 09:23:56 -07:00
|
|
|
|
void UpdateData(object s, InvalidateArgs e)
|
2018-03-13 11:52:23 -07:00
|
|
|
|
{
|
2018-07-02 14:50:51 -07:00
|
|
|
|
field2.Vector3 = ((DirectionAxis)property.Value).Origin - property.Item.Children.First().GetAxisAlignedBoundingBox().Center;
|
2019-04-22 09:23:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
property.Item.Invalidated += UpdateData;
|
2018-07-02 08:11:52 -07:00
|
|
|
|
field2.Content.Closed += (s, e) =>
|
2018-06-08 16:25:35 -07:00
|
|
|
|
{
|
2019-04-22 09:23:56 -07:00
|
|
|
|
property.Item.Invalidated -= UpdateData;
|
2018-06-08 16:25:35 -07:00
|
|
|
|
};
|
2018-04-12 17:23:19 -07:00
|
|
|
|
|
2018-07-02 08:11:52 -07:00
|
|
|
|
// update functions
|
|
|
|
|
|
field1.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.SetValue(new DirectionAxis()
|
|
|
|
|
|
{
|
|
|
|
|
|
Normal = field1.DirectionVector.Normal,
|
2018-07-02 14:50:51 -07:00
|
|
|
|
Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + field2.Vector3
|
2018-07-02 08:11:52 -07:00
|
|
|
|
});
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2018-07-06 17:11:33 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
2018-07-02 08:11:52 -07:00
|
|
|
|
};
|
|
|
|
|
|
field2.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.SetValue(new DirectionAxis()
|
|
|
|
|
|
{
|
|
|
|
|
|
Normal = field1.DirectionVector.Normal,
|
2018-07-02 14:50:51 -07:00
|
|
|
|
Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + field2.Vector3
|
2018-07-02 08:11:52 -07:00
|
|
|
|
});
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2018-07-06 17:11:33 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
2018-07-02 08:11:52 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(row2);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-12-21 08:27:40 -08:00
|
|
|
|
else if (propertyValue is SelectedChildren childSelector)
|
2018-06-01 17:44:46 -07:00
|
|
|
|
{
|
2021-03-03 09:45:51 -08:00
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<ShowAsListAttribute>().FirstOrDefault() is ShowAsListAttribute showAsList)
|
2018-08-13 13:48:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
UIField field = new ChildrenSelectorListField(property, theme);
|
|
|
|
|
|
|
|
|
|
|
|
field.Initialize(0);
|
2018-10-24 15:53:00 -07:00
|
|
|
|
RegisterValueChanged(field,
|
2019-03-07 17:56:41 -08:00
|
|
|
|
(valueString) =>
|
2018-10-24 15:53:00 -07:00
|
|
|
|
{
|
2018-12-21 08:27:40 -08:00
|
|
|
|
var childrenSelector = new SelectedChildren();
|
2018-10-24 15:53:00 -07:00
|
|
|
|
foreach (var child in valueString.Split(','))
|
|
|
|
|
|
{
|
|
|
|
|
|
childrenSelector.Add(child);
|
|
|
|
|
|
}
|
2019-04-22 09:23:56 -07:00
|
|
|
|
|
2018-10-24 15:53:00 -07:00
|
|
|
|
return childrenSelector;
|
|
|
|
|
|
});
|
2018-08-13 13:48:10 -07:00
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
2018-08-13 13:48:10 -07:00
|
|
|
|
}
|
2018-11-29 13:41:24 -08:00
|
|
|
|
else // show the subtract editor for boolean subtract and subtract and replace
|
2018-08-13 13:48:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property);
|
2019-02-11 18:16:05 -08:00
|
|
|
|
if (property.Item is OperationSourceContainerObject3D sourceContainer)
|
|
|
|
|
|
{
|
2020-10-16 16:25:11 -07:00
|
|
|
|
Action selected = null;
|
2021-08-21 08:13:49 -07:00
|
|
|
|
if (!(localItem.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() is ShowUpdateButtonAttribute showUpdate))
|
2020-10-16 16:25:11 -07:00
|
|
|
|
{
|
|
|
|
|
|
selected = () =>
|
|
|
|
|
|
{
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2020-10-16 16:25:11 -07:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(CreateSourceChildSelector(childSelector, sourceContainer, theme, selected));
|
2019-02-11 18:16:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
rowContainer.AddChild(CreateSelector(childSelector, property.Item, theme));
|
|
|
|
|
|
}
|
2018-08-13 13:48:10 -07:00
|
|
|
|
}
|
2018-06-01 17:44:46 -07:00
|
|
|
|
}
|
2018-06-18 09:07:48 -07:00
|
|
|
|
else if (propertyValue is ImageBuffer imageBuffer)
|
|
|
|
|
|
{
|
2021-07-25 07:40:43 -07:00
|
|
|
|
var imageDisplayAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<ImageDisplayAttribute>().FirstOrDefault();
|
|
|
|
|
|
|
2018-06-18 09:07:48 -07:00
|
|
|
|
rowContainer = CreateSettingsColumn(property);
|
2021-07-25 07:40:43 -07:00
|
|
|
|
GuiWidget imageWidget;
|
|
|
|
|
|
if (imageDisplayAttribute?.Stretch == true)
|
2020-05-18 21:47:35 -07:00
|
|
|
|
{
|
2021-08-17 17:35:17 -07:00
|
|
|
|
var responsiveImageWidget = new ResponsiveImageWidget(imageBuffer);
|
|
|
|
|
|
responsiveImageWidget.RenderCheckerboard = true;
|
|
|
|
|
|
imageWidget = responsiveImageWidget;
|
2021-07-25 07:40:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-07-26 08:47:04 -07:00
|
|
|
|
imageWidget = new ImageWidget(imageBuffer);
|
2021-07-25 07:40:43 -07:00
|
|
|
|
}
|
2021-08-22 22:07:43 -07:00
|
|
|
|
|
2021-07-25 07:40:43 -07:00
|
|
|
|
if (imageDisplayAttribute != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
imageWidget.MaximumSize = new Vector2(imageDisplayAttribute.MaxXSize * GuiWidget.DeviceScale, int.MaxValue);
|
|
|
|
|
|
imageWidget.Margin = imageDisplayAttribute.GetMargin();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
imageWidget.Margin = new BorderDouble(0, 3);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-25 18:22:40 -07:00
|
|
|
|
ImageBuffer GetImageCheckingForErrors()
|
|
|
|
|
|
{
|
|
|
|
|
|
var image = imageBuffer;
|
|
|
|
|
|
if (object3D is ImageObject3D imageObject2)
|
|
|
|
|
|
{
|
|
|
|
|
|
image = imageObject2.Image;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Show image load error if needed
|
|
|
|
|
|
if (image == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
image = new ImageBuffer(185, 185).SetPreMultiply();
|
|
|
|
|
|
var graphics2D = image.NewGraphics2D();
|
2021-07-25 07:40:43 -07:00
|
|
|
|
|
2021-07-25 18:22:40 -07:00
|
|
|
|
graphics2D.FillRectangle(0, 0, 185, 185, theme.MinimalShade);
|
|
|
|
|
|
graphics2D.Rectangle(0, 0, 185, 185, theme.SlightShade);
|
|
|
|
|
|
graphics2D.DrawString("Error Loading Image".Localize() + "...", 10, 185 / 2, baseline: Agg.Font.Baseline.BoundsCenter, color: Color.Red, pointSize: theme.DefaultFontSize, drawFromHintedCach: true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateEditorImage()
|
2021-07-25 07:40:43 -07:00
|
|
|
|
{
|
2021-07-25 18:22:40 -07:00
|
|
|
|
if (imageWidget is ResponsiveImageWidget responsive)
|
|
|
|
|
|
{
|
|
|
|
|
|
responsive.Image = GetImageCheckingForErrors();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
((ImageWidget)imageWidget).Image = GetImageCheckingForErrors();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateEditorImage();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
imageWidget.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
|
|
|
|
|
|
2021-08-17 11:31:40 -07:00
|
|
|
|
if (object3D is IEditorWidgetModifier editorWidgetModifier)
|
2021-07-25 18:22:40 -07:00
|
|
|
|
{
|
2021-08-17 11:31:40 -07:00
|
|
|
|
editorWidgetModifier.ModifyEditorWidget(imageWidget, theme, UpdateEditorImage);
|
2021-07-25 18:22:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(imageWidget);
|
2021-07-26 08:47:04 -07:00
|
|
|
|
}
|
2021-07-27 18:12:17 -07:00
|
|
|
|
else if (propertyValue is Histogram histogram)
|
2021-07-26 08:47:04 -07:00
|
|
|
|
{
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property);
|
2021-07-27 18:12:17 -07:00
|
|
|
|
var histogramWidget = histogram.NewEditWidget(theme);
|
2021-07-26 08:47:04 -07:00
|
|
|
|
rowContainer.AddChild(histogramWidget);
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
2021-07-27 09:38:41 -07:00
|
|
|
|
if (object3D is IImageProvider imageProvider)
|
|
|
|
|
|
{
|
|
|
|
|
|
var _ = imageProvider.Image;
|
|
|
|
|
|
}
|
2021-07-26 08:47:04 -07:00
|
|
|
|
}
|
2021-07-25 07:40:43 -07:00
|
|
|
|
}
|
2021-07-26 08:47:04 -07:00
|
|
|
|
|
|
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
rowContainer.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
2018-06-18 09:07:48 -07:00
|
|
|
|
}
|
2018-08-03 18:29:25 -07:00
|
|
|
|
else if (propertyValue is List<string> stringList)
|
|
|
|
|
|
{
|
2019-05-21 16:04:48 -07:00
|
|
|
|
var field = new SurfacedEditorsField(theme, property.Item);
|
2018-08-03 18:29:25 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.ListValue = stringList;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.SetValue(field.ListValue);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property, field);
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.Descendants<HorizontalSpacer>().FirstOrDefault()?.Close();
|
|
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a int editor
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is int intValue)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2020-02-19 22:07:09 -08:00
|
|
|
|
if (readOnly)
|
|
|
|
|
|
{
|
2021-06-24 10:36:32 -07:00
|
|
|
|
string FormateInt(int value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<DisplayAsTimeAttribute>().FirstOrDefault() != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var minutes = intValue / 60;
|
|
|
|
|
|
var hours = minutes / 60;
|
|
|
|
|
|
return $"{hours:00}:{minutes % 60:00}:{intValue % 60:00}";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("{0:n0}", intValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var valueField = new TextWidget(FormateInt(intValue),
|
2020-05-14 08:24:34 -07:00
|
|
|
|
textColor: theme.TextColor,
|
2020-05-23 17:33:39 -07:00
|
|
|
|
pointSize: 10)
|
|
|
|
|
|
{
|
2021-06-24 10:36:32 -07:00
|
|
|
|
AutoExpandBoundsToText = true,
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, 7, 0),
|
2020-05-23 17:33:39 -07:00
|
|
|
|
};
|
2020-05-14 08:24:34 -07:00
|
|
|
|
|
2020-02-19 22:07:09 -08:00
|
|
|
|
rowContainer = new SettingsRow(property.DisplayName.Localize(),
|
2020-10-04 22:21:17 -07:00
|
|
|
|
property.Description,
|
2020-02-19 22:07:09 -08:00
|
|
|
|
valueField,
|
|
|
|
|
|
theme);
|
2020-05-23 17:33:39 -07:00
|
|
|
|
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
2021-01-20 18:04:50 -08:00
|
|
|
|
int newValue = (int)property.Value;
|
2021-06-24 10:36:32 -07:00
|
|
|
|
valueField.Text = string.Format(FormateInt(intValue), newValue);
|
2020-05-23 17:33:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
valueField.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
2020-02-19 22:07:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
else // normal edit row
|
2018-07-08 13:57:45 -07:00
|
|
|
|
{
|
2020-02-19 22:07:09 -08:00
|
|
|
|
var field = new IntField(theme);
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.IntValue = intValue;
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
|
2020-02-19 22:07:09 -08:00
|
|
|
|
RegisterValueChanged(field, (valueString) => { return int.Parse(valueString); });
|
|
|
|
|
|
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
2018-07-08 13:57:45 -07:00
|
|
|
|
{
|
2020-02-19 22:07:09 -08:00
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
2018-07-08 13:57:45 -07:00
|
|
|
|
{
|
2020-02-19 22:07:09 -08:00
|
|
|
|
int newValue = (int)property.Value;
|
|
|
|
|
|
if (newValue != field.IntValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.IntValue = newValue;
|
|
|
|
|
|
}
|
2018-07-08 13:57:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-19 22:07:09 -08:00
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
2018-07-08 13:57:45 -07:00
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
2020-02-19 22:07:09 -08:00
|
|
|
|
}
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is bool boolValue)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2019-04-22 09:23:56 -07:00
|
|
|
|
// create a bool editor
|
2018-04-12 17:45:50 -07:00
|
|
|
|
var field = new ToggleboxField(theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Checked = boolValue;
|
2018-10-21 11:52:05 -07:00
|
|
|
|
|
2019-03-07 17:56:41 -08:00
|
|
|
|
RegisterValueChanged(field,
|
2018-10-21 22:49:30 -07:00
|
|
|
|
(valueString) => { return valueString == "1"; },
|
2019-04-22 09:23:56 -07:00
|
|
|
|
(value) => { return ((bool)value) ? "1" : "0"; });
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2021-05-31 18:44:00 -07:00
|
|
|
|
else if (propertyValue is DoubleOrExpression doubleExpresion)
|
2021-05-29 22:21:50 -07:00
|
|
|
|
{
|
|
|
|
|
|
// create a string editor
|
2021-06-06 22:18:29 -07:00
|
|
|
|
var field = new ExpressionField(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = property.DisplayName + " Field"
|
|
|
|
|
|
};
|
2021-05-29 22:21:50 -07:00
|
|
|
|
field.Initialize(0);
|
2021-05-31 18:44:00 -07:00
|
|
|
|
field.SetValue(doubleExpresion.Expression, false);
|
2021-05-29 22:21:50 -07:00
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
RegisterValueChanged(field,
|
2021-05-31 18:44:00 -07:00
|
|
|
|
(valueString) => new DoubleOrExpression(valueString),
|
2021-05-29 22:21:50 -07:00
|
|
|
|
(value) =>
|
|
|
|
|
|
{
|
2021-05-31 18:44:00 -07:00
|
|
|
|
return ((DoubleOrExpression)value).Expression;
|
2021-05-29 22:21:50 -07:00
|
|
|
|
});
|
2021-08-22 22:07:43 -07:00
|
|
|
|
|
|
|
|
|
|
rowContainer = CreateSettingsRow(property, GetFieldContentWithSlider(property, field), theme, rows);
|
2021-05-29 22:21:50 -07:00
|
|
|
|
|
2021-05-30 08:06:22 -07:00
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
|
|
|
|
|
{
|
2021-09-02 13:10:54 -07:00
|
|
|
|
// This code only executes when the in scene controls are updating the objects data and the display needs to tack them.
|
2021-05-30 08:06:22 -07:00
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
2021-05-31 18:44:00 -07:00
|
|
|
|
DoubleOrExpression newValue = (DoubleOrExpression)property.Value;
|
|
|
|
|
|
if (newValue.Expression != field.Value)
|
2021-05-30 08:06:22 -07:00
|
|
|
|
{
|
2021-09-02 13:10:54 -07:00
|
|
|
|
// we should never be in the situation where there is an '=' as the in scene controls should be disabled
|
|
|
|
|
|
if (newValue.Expression.StartsWith("="))
|
|
|
|
|
|
{
|
|
|
|
|
|
field.TextValue = newValue.Expression;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var format = "0." + new string('#', 5);
|
|
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MaxDecimalPlacesAttribute>().FirstOrDefault() is MaxDecimalPlacesAttribute decimalPlaces)
|
|
|
|
|
|
{
|
|
|
|
|
|
format = "0." + new string('#', Math.Min(10, decimalPlaces.Number));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
field.TextValue = newValue.Value(object3D).ToString(format);
|
|
|
|
|
|
}
|
2021-05-30 08:06:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
2021-05-29 22:21:50 -07:00
|
|
|
|
}
|
2021-06-01 17:48:43 -07:00
|
|
|
|
else if (propertyValue is IntOrExpression intExpresion)
|
|
|
|
|
|
{
|
|
|
|
|
|
// create a string editor
|
2021-06-03 17:43:49 -07:00
|
|
|
|
var field = new ExpressionField(theme);
|
2021-06-01 17:48:43 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(intExpresion.Expression, false);
|
|
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
RegisterValueChanged(field,
|
|
|
|
|
|
(valueString) => new IntOrExpression(valueString),
|
|
|
|
|
|
(value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return ((IntOrExpression)value).Expression;
|
|
|
|
|
|
});
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme, rows);
|
2021-06-01 17:48:43 -07:00
|
|
|
|
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
|
|
|
|
|
IntOrExpression newValue = (IntOrExpression)property.Value;
|
|
|
|
|
|
if (newValue.Expression != field.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.TextValue = newValue.Value(object3D).ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
|
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is string stringValue)
|
2021-07-25 18:22:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<GoogleSearchAttribute>().FirstOrDefault() != null)
|
|
|
|
|
|
{
|
2021-08-17 17:35:17 -07:00
|
|
|
|
rowContainer = NewImageSearchWidget(theme);
|
2021-07-25 18:22:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if(object3D is AssetObject3D assetObject
|
|
|
|
|
|
&& property.PropertyInfo.Name == "AssetPath")
|
|
|
|
|
|
{
|
|
|
|
|
|
// This is the AssetPath property of an asset object, add a button to set the AssetPath from a file
|
|
|
|
|
|
// Change button
|
|
|
|
|
|
var changeButton = new TextButton(property.Description, theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
Margin = 3
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer = new SettingsRow(property.DisplayName,
|
|
|
|
|
|
null,
|
|
|
|
|
|
changeButton,
|
|
|
|
|
|
theme);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
changeButton.Click += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2021-08-17 11:31:40 -07:00
|
|
|
|
ImageObject3D.ShowOpenDialog(assetObject);
|
2021-07-25 18:22:40 -07:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2020-05-14 20:19:47 -07:00
|
|
|
|
{
|
2021-07-26 08:47:04 -07:00
|
|
|
|
if (readOnly)
|
2020-05-18 21:47:35 -07:00
|
|
|
|
{
|
2021-07-26 08:47:04 -07:00
|
|
|
|
WrappedTextWidget wrappedTextWidget = null;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(property.DisplayName))
|
2021-05-07 11:29:59 -07:00
|
|
|
|
{
|
2021-07-26 08:47:04 -07:00
|
|
|
|
rowContainer = new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
Margin = 9
|
|
|
|
|
|
};
|
2021-05-07 11:29:59 -07:00
|
|
|
|
|
2021-07-26 08:47:04 -07:00
|
|
|
|
var displayName = rowContainer.AddChild(new TextWidget(property.DisplayName,
|
|
|
|
|
|
textColor: theme.TextColor,
|
|
|
|
|
|
pointSize: 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Center,
|
|
|
|
|
|
});
|
2021-05-07 11:29:59 -07:00
|
|
|
|
|
2021-07-26 08:47:04 -07:00
|
|
|
|
var wrapContainer = new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(displayName.Width + displayName.Margin.Width + 15, 3, 3, 3),
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
wrappedTextWidget = new WrappedTextWidget(stringValue, textColor: theme.TextColor, pointSize: 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
wrappedTextWidget.TextWidget.HAnchor = HAnchor.Right;
|
|
|
|
|
|
wrapContainer.AddChild(wrappedTextWidget);
|
|
|
|
|
|
rowContainer.AddChild(wrapContainer);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2021-05-07 11:29:59 -07:00
|
|
|
|
{
|
2021-07-26 08:47:04 -07:00
|
|
|
|
rowContainer = wrappedTextWidget = new WrappedTextWidget(stringValue,
|
|
|
|
|
|
textColor: theme.TextColor,
|
|
|
|
|
|
pointSize: 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = 9
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2021-05-07 11:29:59 -07:00
|
|
|
|
|
2021-07-26 08:47:04 -07:00
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
2021-05-07 11:29:59 -07:00
|
|
|
|
{
|
2021-07-26 08:47:04 -07:00
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
|
|
|
|
|
wrappedTextWidget.Text = property.Value.ToString();
|
|
|
|
|
|
}
|
2021-05-07 11:29:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-26 08:47:04 -07:00
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
wrappedTextWidget.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
2020-10-04 22:21:17 -07:00
|
|
|
|
}
|
2021-07-26 08:47:04 -07:00
|
|
|
|
else // normal edit row
|
2020-05-14 20:19:47 -07:00
|
|
|
|
{
|
2021-07-26 08:47:04 -07:00
|
|
|
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MultiLineEditAttribute>().FirstOrDefault() != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// create a a multi-line string editor
|
|
|
|
|
|
var field = new MultilineStringField(theme);
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(stringValue, false);
|
|
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
field.Content.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
field.Content.Descendants<ScrollableWidget>().FirstOrDefault().MaximumSize = new Vector2(double.MaxValue, 200);
|
|
|
|
|
|
field.Content.Descendants<ScrollingArea>().FirstOrDefault().Parent.VAnchor = VAnchor.Top;
|
|
|
|
|
|
field.Content.MinimumSize = new Vector2(0, 100 * GuiWidget.DeviceScale);
|
|
|
|
|
|
field.Content.Margin = new BorderDouble(0, 0, 0, 5);
|
|
|
|
|
|
RegisterValueChanged(field, (valueString) => valueString);
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property, field, fullWidth: true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// create a string editor
|
|
|
|
|
|
var field = new TextField(theme);
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(stringValue, false);
|
|
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
field.Content.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
RegisterValueChanged(field, (valueString) => valueString);
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme, rows);
|
2021-07-26 08:47:04 -07:00
|
|
|
|
}
|
2020-05-14 20:19:47 -07:00
|
|
|
|
}
|
2018-07-18 13:23:53 -07:00
|
|
|
|
}
|
2018-03-08 17:23:03 -08:00
|
|
|
|
}
|
2021-06-06 09:07:18 -07:00
|
|
|
|
else if (propertyValue is StringOrExpression stringOrExpression)
|
|
|
|
|
|
{
|
|
|
|
|
|
// create a string editor
|
|
|
|
|
|
var field = new TextField(theme);
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(stringOrExpression.Expression, false);
|
|
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
field.Content.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
RegisterValueChanged(field,
|
|
|
|
|
|
(valueString) => new StringOrExpression(valueString),
|
|
|
|
|
|
(value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return ((StringOrExpression)value).Expression;
|
|
|
|
|
|
});
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme, rows);
|
2021-06-06 09:07:18 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is char charValue)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2019-04-22 09:23:56 -07:00
|
|
|
|
// create a char editor
|
2018-10-14 20:05:37 -07:00
|
|
|
|
var field = new CharField(theme);
|
2018-06-08 18:19:06 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(charValue.ToString(), false);
|
2020-07-11 09:19:41 -07:00
|
|
|
|
field.ClearUndoHistory();
|
2018-06-08 18:19:06 -07:00
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(Convert.ToChar(field.Value));
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2018-07-06 17:11:33 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-06-08 18:19:06 -07:00
|
|
|
|
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-04-23 16:18:16 -07:00
|
|
|
|
else if (property.PropertyType.IsEnum)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2019-04-22 09:23:56 -07:00
|
|
|
|
// create an enum editor
|
2018-06-09 07:14:38 -07:00
|
|
|
|
UIField field;
|
2020-05-10 19:17:48 -07:00
|
|
|
|
var enumDisplayAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<EnumDisplayAttribute>().FirstOrDefault();
|
|
|
|
|
|
var addToSettingsRow = true;
|
|
|
|
|
|
if (enumDisplayAttribute != null)
|
2018-06-09 07:14:38 -07:00
|
|
|
|
{
|
2020-05-10 19:17:48 -07:00
|
|
|
|
field = new EnumDisplayField(property, enumDisplayAttribute, theme)
|
2018-06-11 16:47:31 -07:00
|
|
|
|
{
|
2020-05-18 21:47:35 -07:00
|
|
|
|
InitialValue = propertyValue.ToString(),
|
2018-06-11 16:47:31 -07:00
|
|
|
|
};
|
2020-05-10 19:17:48 -07:00
|
|
|
|
|
|
|
|
|
|
if (enumDisplayAttribute.Mode == EnumDisplayAttribute.PresentationMode.Tabs)
|
|
|
|
|
|
{
|
|
|
|
|
|
addToSettingsRow = false;
|
|
|
|
|
|
}
|
2018-06-09 07:14:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-10-22 17:42:26 -07:00
|
|
|
|
if (property.PropertyType == typeof(NamedTypeFace))
|
|
|
|
|
|
{
|
|
|
|
|
|
field = new FontSelectorField(property, theme);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
field = new EnumField(property, theme);
|
|
|
|
|
|
}
|
2018-06-09 07:14:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-09 06:34:31 -07:00
|
|
|
|
field.Initialize(0);
|
2018-10-24 15:53:00 -07:00
|
|
|
|
RegisterValueChanged(field,
|
|
|
|
|
|
(valueString) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return Enum.Parse(property.PropertyType, valueString);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2018-06-09 06:34:31 -07:00
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2021-02-10 21:44:44 -08:00
|
|
|
|
if (property.Value.ToString() != field.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
property.SetValue(Enum.Parse(property.PropertyType, field.Value));
|
2021-08-21 08:13:49 -07:00
|
|
|
|
object3D?.Invalidate(new InvalidateArgs(localItem, InvalidateType.Properties));
|
2021-02-10 21:44:44 -08:00
|
|
|
|
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
|
|
|
|
|
}
|
2018-06-09 06:34:31 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-05-10 19:17:48 -07:00
|
|
|
|
if (addToSettingsRow)
|
|
|
|
|
|
{
|
2021-08-22 22:07:43 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
2020-05-10 19:17:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-05-14 08:24:34 -07:00
|
|
|
|
// field.Content.Margin = new BorderDouble(3, 0);
|
|
|
|
|
|
field.Content.HAnchor = HAnchor.Stretch;
|
2020-05-10 19:17:48 -07:00
|
|
|
|
rowContainer = field.Content;
|
|
|
|
|
|
}
|
2021-05-15 22:33:27 -07:00
|
|
|
|
|
|
|
|
|
|
void RefreshField(object s, InvalidateArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
|
|
|
|
|
|
{
|
|
|
|
|
|
var newValue = property.Value.ToString();
|
|
|
|
|
|
if (field.Content is MHDropDownList dropDown)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (field.Value != newValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.SetValue(newValue, false);
|
|
|
|
|
|
dropDown.SelectedValue = newValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-18 13:22:56 -07:00
|
|
|
|
if (object3D != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
object3D.Invalidated += RefreshField;
|
|
|
|
|
|
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
|
|
|
|
|
}
|
2021-05-15 22:33:27 -07:00
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-21 07:44:11 -07:00
|
|
|
|
else if (propertyValue is IObject3D item
|
2019-02-04 08:41:08 -08:00
|
|
|
|
&& ApplicationController.Instance.Extensions.GetEditorsForType(property.PropertyType)?.FirstOrDefault() is IObject3DEditor iObject3DEditor)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2019-04-22 09:23:56 -07:00
|
|
|
|
// Use known IObject3D editors
|
2019-03-07 17:56:41 -08:00
|
|
|
|
rowContainer = iObject3DEditor.Create(item, undoBuffer, theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remember the row name and widget
|
2018-05-02 10:59:08 -07:00
|
|
|
|
context.editRows.Add(property.PropertyInfo.Name, rowContainer);
|
2018-06-09 09:55:25 -07:00
|
|
|
|
|
|
|
|
|
|
return rowContainer;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
2021-08-17 17:35:17 -07:00
|
|
|
|
public static GuiWidget NewImageSearchWidget(ThemeConfig theme, string postPend = "silhouette")
|
2021-07-25 18:22:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
var searchRow = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
Margin = new BorderDouble(5, 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var searchField = new MHTextEditWidget("", theme, messageWhenEmptyAndNotSelected: "Search Google for images")
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
};
|
|
|
|
|
|
searchRow.AddChild(searchField);
|
|
|
|
|
|
var searchButton = new IconButton(StaticData.Instance.LoadIcon("icon_search_24x24.png", 16, 16).SetToColor(theme.TextColor), theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
ToolTipText = "Search".Localize(),
|
|
|
|
|
|
};
|
|
|
|
|
|
searchRow.AddChild(searchButton);
|
|
|
|
|
|
|
|
|
|
|
|
void DoSearch(object s, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var search = HttpUtility.UrlEncode(searchField.Text);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(search))
|
|
|
|
|
|
{
|
|
|
|
|
|
ApplicationController.LaunchBrowser($"http://www.google.com/search?q={search} {postPend}&tbm=isch");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
searchField.ActualTextEditWidget.EditComplete += DoSearch;
|
|
|
|
|
|
searchButton.Click += DoSearch;
|
|
|
|
|
|
return searchRow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-16 16:25:11 -07:00
|
|
|
|
private static GuiWidget CreateSourceChildSelector(SelectedChildren childSelector, OperationSourceContainerObject3D sourceContainer, ThemeConfig theme, Action selectionChanged)
|
2019-02-11 18:16:05 -08:00
|
|
|
|
{
|
2020-08-11 17:58:53 -07:00
|
|
|
|
GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 3, 0, 0),
|
|
|
|
|
|
};
|
2019-02-11 18:16:05 -08:00
|
|
|
|
|
2019-03-22 10:29:05 -07:00
|
|
|
|
var parentOfSubtractTargets = sourceContainer.SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf();
|
|
|
|
|
|
|
|
|
|
|
|
var sourceChildren = parentOfSubtractTargets.Children.ToList();
|
2019-02-11 18:16:05 -08:00
|
|
|
|
|
|
|
|
|
|
var objectChecks = new Dictionary<ICheckbox, IObject3D>();
|
|
|
|
|
|
|
|
|
|
|
|
var radioSiblings = new List<GuiWidget>();
|
|
|
|
|
|
for (int i = 0; i < sourceChildren.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var itemIndex = i;
|
|
|
|
|
|
var child = sourceChildren[itemIndex];
|
2020-08-11 17:58:53 -07:00
|
|
|
|
var rowContainer = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Padding = new BorderDouble(15, 0, 0, 3)
|
|
|
|
|
|
};
|
2019-02-11 18:16:05 -08:00
|
|
|
|
|
|
|
|
|
|
GuiWidget selectWidget;
|
|
|
|
|
|
if (sourceChildren.Count == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
2019-05-18 06:55:57 -07:00
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
2020-08-11 17:58:53 -07:00
|
|
|
|
TextColor = theme.TextColor,
|
|
|
|
|
|
Margin = 0,
|
2019-02-11 18:16:05 -08:00
|
|
|
|
};
|
|
|
|
|
|
radioSiblings.Add(radioButton);
|
|
|
|
|
|
radioButton.SiblingRadioButtonList = radioSiblings;
|
|
|
|
|
|
selectWidget = radioButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
2019-05-18 06:55:57 -07:00
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
2020-08-11 17:58:53 -07:00
|
|
|
|
TextColor = theme.TextColor,
|
2019-02-11 18:16:05 -08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
objectChecks.Add((ICheckbox)selectWidget, child);
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(selectWidget);
|
|
|
|
|
|
var checkBox = selectWidget as ICheckbox;
|
|
|
|
|
|
|
|
|
|
|
|
checkBox.CheckedStateChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (s is ICheckbox checkbox)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (checkBox.Checked)
|
|
|
|
|
|
{
|
2019-05-18 06:55:57 -07:00
|
|
|
|
if (!childSelector.Contains(objectChecks[checkbox].ID))
|
2019-02-11 18:16:05 -08:00
|
|
|
|
{
|
2019-05-18 06:55:57 -07:00
|
|
|
|
childSelector.Add(objectChecks[checkbox].ID);
|
2019-02-11 18:16:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-05-18 06:55:57 -07:00
|
|
|
|
if (childSelector.Contains(objectChecks[checkbox].ID))
|
2019-02-11 18:16:05 -08:00
|
|
|
|
{
|
2019-05-18 06:55:57 -07:00
|
|
|
|
childSelector.Remove(objectChecks[checkbox].ID);
|
2019-02-11 18:16:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-10-16 16:25:11 -07:00
|
|
|
|
|
|
|
|
|
|
selectionChanged?.Invoke();
|
2019-02-11 18:16:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tabContainer.AddChild(rowContainer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tabContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-21 08:27:40 -08:00
|
|
|
|
private static GuiWidget CreateSelector(SelectedChildren childSelector, IObject3D parent, ThemeConfig theme)
|
2018-06-01 17:44:46 -07:00
|
|
|
|
{
|
|
|
|
|
|
GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
|
2018-06-04 09:55:54 -07:00
|
|
|
|
void UpdateSelectColors(bool selectionChanged = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var child in parent.Children.ToList())
|
|
|
|
|
|
{
|
2018-06-20 08:09:35 -07:00
|
|
|
|
using (child.RebuildLock())
|
2018-06-04 09:55:54 -07:00
|
|
|
|
{
|
2018-06-20 08:09:35 -07:00
|
|
|
|
if (selectionChanged)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Visible = true;
|
|
|
|
|
|
}
|
2018-06-04 09:55:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tabContainer.Closed += (s, e) => UpdateSelectColors();
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
var children = parent.Children.ToList();
|
|
|
|
|
|
|
2019-04-22 09:23:56 -07:00
|
|
|
|
var objectChecks = new Dictionary<ICheckbox, IObject3D>();
|
2018-06-01 17:44:46 -07:00
|
|
|
|
|
2019-04-22 09:23:56 -07:00
|
|
|
|
var radioSiblings = new List<GuiWidget>();
|
2018-06-01 17:44:46 -07:00
|
|
|
|
for (int i = 0; i < children.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var itemIndex = i;
|
|
|
|
|
|
var child = children[itemIndex];
|
2019-04-22 09:23:56 -07:00
|
|
|
|
var rowContainer = new FlowLayoutWidget();
|
2018-06-01 17:44:46 -07:00
|
|
|
|
|
|
|
|
|
|
GuiWidget selectWidget;
|
|
|
|
|
|
if (children.Count == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
|
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
2018-11-03 09:13:07 -07:00
|
|
|
|
TextColor = theme.TextColor
|
2018-06-01 17:44:46 -07:00
|
|
|
|
};
|
|
|
|
|
|
radioSiblings.Add(radioButton);
|
|
|
|
|
|
radioButton.SiblingRadioButtonList = radioSiblings;
|
|
|
|
|
|
selectWidget = radioButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
|
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
2018-11-03 09:13:07 -07:00
|
|
|
|
TextColor = theme.TextColor
|
2018-06-01 17:44:46 -07:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
objectChecks.Add((ICheckbox)selectWidget, child);
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(selectWidget);
|
2019-04-22 09:23:56 -07:00
|
|
|
|
var checkBox = selectWidget as ICheckbox;
|
2018-06-01 17:44:46 -07:00
|
|
|
|
|
|
|
|
|
|
checkBox.CheckedStateChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (s is ICheckbox checkbox)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (checkBox.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!childSelector.Contains(objectChecks[checkbox].ID))
|
|
|
|
|
|
{
|
|
|
|
|
|
childSelector.Add(objectChecks[checkbox].ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (childSelector.Contains(objectChecks[checkbox].ID))
|
|
|
|
|
|
{
|
|
|
|
|
|
childSelector.Remove(objectChecks[checkbox].ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-04 09:55:54 -07:00
|
|
|
|
|
2019-04-22 09:23:56 -07:00
|
|
|
|
if (parent is MeshWrapperObject3D meshWrapper)
|
2018-06-04 09:55:54 -07:00
|
|
|
|
{
|
2018-06-20 08:09:35 -07:00
|
|
|
|
using (meshWrapper.RebuildLock())
|
|
|
|
|
|
{
|
|
|
|
|
|
meshWrapper.ResetMeshWrapperMeshes(Object3DPropertyFlags.All, CancellationToken.None);
|
|
|
|
|
|
}
|
2018-06-04 09:55:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateSelectColors(true);
|
2018-06-01 17:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tabContainer.AddChild(rowContainer);
|
2018-06-04 09:55:54 -07:00
|
|
|
|
UpdateSelectColors();
|
2018-06-01 17:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tabContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-20 19:06:15 -07:00
|
|
|
|
public static void AddUnlockLinkIfRequired(IObject3D item, GuiWidget editControlsContainer, ThemeConfig theme)
|
2018-02-26 15:28:00 -08:00
|
|
|
|
{
|
2021-03-02 17:57:19 -08:00
|
|
|
|
(string url, GuiWidget markdownWidget)? unlockdata = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (item.GetType().GetCustomAttributes(typeof(RequiresPermissionsAttribute), true).FirstOrDefault() is RequiresPermissionsAttribute unlockLink
|
|
|
|
|
|
&& !ApplicationController.Instance.UserHasPermission(item))
|
|
|
|
|
|
{
|
|
|
|
|
|
unlockdata = ApplicationController.Instance.GetUnlockData?.Invoke(item, theme);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!item.Persistable)
|
2018-02-26 15:28:00 -08:00
|
|
|
|
{
|
2020-05-22 15:24:52 -07:00
|
|
|
|
// find the first self or child that is not authorized
|
2020-09-13 21:20:59 -07:00
|
|
|
|
var permission = item.DescendantsAndSelf()
|
|
|
|
|
|
.Where(i => !i.Persistable && !ApplicationController.Instance.UserHasPermission(i));
|
2020-05-22 15:24:52 -07:00
|
|
|
|
|
2020-09-13 21:20:59 -07:00
|
|
|
|
if (permission.Any())
|
2020-05-21 15:11:03 -07:00
|
|
|
|
{
|
2020-09-13 21:20:59 -07:00
|
|
|
|
var unlockItem = permission.First();
|
2021-03-02 17:57:19 -08:00
|
|
|
|
unlockdata = ApplicationController.Instance.GetUnlockData?.Invoke(unlockItem, theme);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-21 15:11:03 -07:00
|
|
|
|
|
2021-03-02 17:57:19 -08:00
|
|
|
|
if (unlockdata != null && !string.IsNullOrEmpty(unlockdata.Value.url))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (unlockdata.Value.markdownWidget != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
unlockdata.Value.markdownWidget.VAnchor = VAnchor.Fit;
|
|
|
|
|
|
editControlsContainer.AddChild(unlockdata.Value.markdownWidget);
|
2020-05-22 15:24:52 -07:00
|
|
|
|
}
|
2021-03-02 17:57:19 -08:00
|
|
|
|
|
|
|
|
|
|
editControlsContainer.AddChild(GetUnlockRow(theme, unlockdata.Value.url));
|
2018-03-10 16:32:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-17 22:35:53 -07:00
|
|
|
|
public static void AddMarkDownDescription(IObject3D item, GuiWidget editControlsContainer, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.GetType().GetCustomAttributes(typeof(MarkDownDescriptionAttribute), true).FirstOrDefault() is MarkDownDescriptionAttribute markdownDescription)
|
|
|
|
|
|
{
|
|
|
|
|
|
var markdownWidget = new MarkdownWidget(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Padding = new BorderDouble(left: theme.DefaultContainerPadding / 2),
|
|
|
|
|
|
Markdown = markdownDescription.Markdown,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
editControlsContainer.AddChild(markdownWidget);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-21 15:11:03 -07:00
|
|
|
|
public static GuiWidget GetUnlockRow(ThemeConfig theme, string url)
|
2018-12-31 12:12:05 -08:00
|
|
|
|
{
|
2021-05-21 15:23:25 -07:00
|
|
|
|
var detailsLink = new TextIconButton("Unlock".Localize(), StaticData.Instance.LoadIcon("locked.png", 16, 16).SetToColor(theme.TextColor), theme)
|
2018-12-31 12:12:05 -08:00
|
|
|
|
{
|
2019-05-04 08:35:43 -07:00
|
|
|
|
Margin = 5,
|
|
|
|
|
|
ToolTipText = "Visit MatterHackers.com to Purchase".Localize()
|
2018-12-31 12:12:05 -08:00
|
|
|
|
};
|
|
|
|
|
|
detailsLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
2020-09-22 17:52:57 -07:00
|
|
|
|
ApplicationController.LaunchBrowser(url);
|
2018-12-31 12:12:05 -08:00
|
|
|
|
};
|
|
|
|
|
|
theme.ApplyPrimaryActionStyle(detailsLink);
|
2019-05-24 09:03:27 -07:00
|
|
|
|
|
2019-05-26 11:08:08 -07:00
|
|
|
|
return new SettingsRow("Demo Mode".Localize(), null, detailsLink, theme);
|
2018-12-31 12:12:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
private void AddWebPageLinkIfRequired(PPEContext context, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
|
2018-03-10 16:32:04 -08:00
|
|
|
|
{
|
2019-04-22 09:23:56 -07:00
|
|
|
|
if (context.item.GetType().GetCustomAttributes(typeof(WebPageLinkAttribute), true).FirstOrDefault() is WebPageLinkAttribute unlockLink)
|
2018-03-10 16:32:04 -08:00
|
|
|
|
{
|
2021-05-21 15:23:25 -07:00
|
|
|
|
var detailsLink = new TextIconButton(unlockLink.ButtonName.Localize(), StaticData.Instance.LoadIcon("internet.png", 16, 16).SetToColor(theme.TextColor), theme)
|
2018-06-25 09:05:21 -07:00
|
|
|
|
{
|
2018-06-25 17:03:54 -07:00
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
ToolTipText = unlockLink.Url,
|
2018-06-25 09:05:21 -07:00
|
|
|
|
};
|
2018-03-10 16:32:04 -08:00
|
|
|
|
detailsLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
2020-09-22 17:52:57 -07:00
|
|
|
|
ApplicationController.LaunchBrowser(unlockLink.Url);
|
2018-02-26 15:28:00 -08:00
|
|
|
|
};
|
2019-05-24 09:03:27 -07:00
|
|
|
|
|
|
|
|
|
|
// website row
|
2021-04-22 14:24:34 -07:00
|
|
|
|
editControlsContainer.AddChild(new SettingsRow(unlockLink.RowName, null, detailsLink, theme));
|
2018-02-26 15:28:00 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|