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;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
2018-06-04 09:55:54 -07:00
|
|
|
|
using System.Threading;
|
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;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2018-06-01 17:44:46 -07:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools.EditableTypes;
|
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-04-12 17:23:19 -07:00
|
|
|
|
public class EditableProperty
|
|
|
|
|
|
{
|
|
|
|
|
|
public IObject3D Item { get; private set; }
|
|
|
|
|
|
public PropertyInfo PropertyInfo { get; private set; }
|
|
|
|
|
|
public EditableProperty(PropertyInfo p, IObject3D item)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Item = item;
|
|
|
|
|
|
this.PropertyInfo = p;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetDescription(PropertyInfo prop)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nameAttribute = prop.GetCustomAttributes(true).OfType<DescriptionAttribute>().FirstOrDefault();
|
|
|
|
|
|
return nameAttribute?.Description ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetDisplayName(PropertyInfo prop)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nameAttribute = prop.GetCustomAttributes(true).OfType<DisplayNameAttribute>().FirstOrDefault();
|
|
|
|
|
|
return nameAttribute?.DisplayName ?? prop.Name.SplitCamelCase();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object Value => PropertyInfo.GetGetMethod().Invoke(Item, null);
|
|
|
|
|
|
public string DisplayName => GetDisplayName(PropertyInfo);
|
|
|
|
|
|
public string Description => GetDescription(PropertyInfo);
|
2018-04-23 16:18:16 -07:00
|
|
|
|
public Type PropertyType => PropertyInfo.PropertyType;
|
2018-04-12 17:23:19 -07: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
|
|
|
|
|
|
|
|
|
|
public bool Unlocked { get; } = true;
|
|
|
|
|
|
|
2018-05-22 09:45:01 -07:00
|
|
|
|
public IEnumerable<Type> SupportedTypes() => new Type[] { typeof(IPublicPropertyObject) };
|
2018-03-27 14:03:12 -07:00
|
|
|
|
|
2018-02-27 18:16:07 -08:00
|
|
|
|
private static 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),
|
2018-02-12 17:45:57 -08:00
|
|
|
|
typeof(Vector2), typeof(Vector3),
|
2018-06-01 17:44:46 -07:00
|
|
|
|
typeof(DirectionVector), typeof(DirectionAxis),
|
|
|
|
|
|
typeof(ChildrenSelector)
|
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
|
|
|
|
|
2018-01-20 12:58:14 -08:00
|
|
|
|
public GuiWidget Create(IObject3D item, View3DWidget view3DWidget, ThemeConfig theme)
|
|
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var context = new PPEContext()
|
|
|
|
|
|
{
|
|
|
|
|
|
view3DWidget = view3DWidget,
|
|
|
|
|
|
item = item
|
|
|
|
|
|
};
|
2018-01-20 12:58:14 -08:00
|
|
|
|
|
|
|
|
|
|
var mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-03-17 20:53:36 -07:00
|
|
|
|
if(item is IEditorDraw editorDraw)
|
|
|
|
|
|
{
|
|
|
|
|
|
view3DWidget.InteractionLayer.DrawGlOpaqueContent += editorDraw.DrawEditor;
|
|
|
|
|
|
mainContainer.Closed += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
view3DWidget.InteractionLayer.DrawGlOpaqueContent -= editorDraw.DrawEditor;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
if (context.item != null)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
this.CreateEditor(context, view3DWidget, mainContainer, theme);
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mainContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsRow(EditableProperty property, GuiWidget widget = null)
|
2018-05-09 13:35:38 -07:00
|
|
|
|
{
|
2018-06-08 16:20:57 -07:00
|
|
|
|
var row = CreateSettingsRow(property.DisplayName.Localize(), property.Description.Localize());
|
|
|
|
|
|
|
|
|
|
|
|
if (widget != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
row.AddChild(widget);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return row;
|
2018-05-09 13:35:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-10 20:17:09 -08:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsRow(string labelText, string toolTipText = null)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
var rowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-02-10 20:17:09 -08:00
|
|
|
|
Padding = new BorderDouble(5),
|
|
|
|
|
|
ToolTipText = toolTipText
|
2018-01-20 12:58:14 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-01-21 14:38:36 -08:00
|
|
|
|
var label = new TextWidget(labelText + ":", pointSize: 11, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, 3, 0),
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
};
|
|
|
|
|
|
rowContainer.AddChild(label);
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(new HorizontalSpacer());
|
|
|
|
|
|
|
|
|
|
|
|
return rowContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(EditableProperty property)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CreateSettingsColumn(property.DisplayName.Localize(), property.Description.Localize());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(string labelText, string toolTipText = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var columnContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
Padding = new BorderDouble(5),
|
|
|
|
|
|
ToolTipText = toolTipText
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var label = new TextWidget(labelText + ":", pointSize: 11, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 3, 0, 0),
|
|
|
|
|
|
HAnchor = HAnchor.Left
|
|
|
|
|
|
};
|
|
|
|
|
|
columnContainer.AddChild(label);
|
|
|
|
|
|
|
|
|
|
|
|
return columnContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
.Where(pi => (allowedTypes.Contains(pi.PropertyType) || pi.PropertyType.IsEnum)
|
|
|
|
|
|
&& pi.GetGetMethod() != null
|
|
|
|
|
|
&& pi.GetSetMethod() != null)
|
|
|
|
|
|
.Select(p => new EditableProperty(p, item));
|
2018-02-10 20:17:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
private void CreateEditor(PPEContext context, View3DWidget view3DWidget, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-03-08 17:23:03 -08:00
|
|
|
|
var undoBuffer = view3DWidget.sceneContext.Scene.UndoBuffer;
|
2018-02-13 13:42:57 -08:00
|
|
|
|
|
2018-05-22 09:45:01 -07:00
|
|
|
|
var rebuildable = context.item as IPublicPropertyObject;
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var propertyGridModifier = context.item as IPropertyGridModifier;
|
2018-01-26 17:53:54 -08:00
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var editableProperties = GetEditablePropreties(context.item);
|
2018-01-20 12:58:14 -08:00
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
AddWebPageLinkIfRequired(context, editControlsContainer, theme);
|
|
|
|
|
|
AddUnlockLinkIfRequired(context, editControlsContainer, theme);
|
2018-02-26 15:28:00 -08:00
|
|
|
|
|
2018-01-20 12:58:14 -08:00
|
|
|
|
foreach (var property in editableProperties)
|
|
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
AddPropertyEditor(this, view3DWidget, editControlsContainer, theme, undoBuffer, rebuildable, propertyGridModifier, property, context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-02-27 18:16:07 -08:00
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var hideUpdate = context.item.GetType().GetCustomAttributes(typeof(HideUpdateButtonAttribute), true).FirstOrDefault() as HideUpdateButtonAttribute;
|
2018-04-12 17:23:19 -07:00
|
|
|
|
if (hideUpdate == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var updateButton = theme.ButtonFactory.Generate("Update".Localize());
|
|
|
|
|
|
updateButton.Margin = new BorderDouble(5);
|
|
|
|
|
|
updateButton.HAnchor = HAnchor.Right;
|
|
|
|
|
|
updateButton.Click += (s, e) =>
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
|
|
|
|
|
};
|
|
|
|
|
|
editControlsContainer.AddChild(updateButton);
|
|
|
|
|
|
}
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// make sure the ui is set right to start
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
private static void AddPropertyEditor(PublicPropertyEditor publicPropertyEditor,
|
2018-04-23 16:18:16 -07:00
|
|
|
|
View3DWidget view3DWidget, FlowLayoutWidget editControlsContainer, ThemeConfig theme,
|
2018-05-22 09:45:01 -07:00
|
|
|
|
UndoBuffer undoBuffer, IPublicPropertyObject rebuildable, IPropertyGridModifier propertyGridModifier,
|
2018-05-02 10:59:08 -07:00
|
|
|
|
EditableProperty property, PPEContext context)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
GuiWidget rowContainer = null;
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a double editor
|
|
|
|
|
|
if (property.Value is double doubleValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = new DoubleField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.DoubleValue = doubleValue;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-01-21 14:38:36 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.DoubleValue });
|
|
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (property.Value is Vector2 vector2)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = new Vector2Field();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Vector2 = vector2;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.Vector2 });
|
|
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-10 20:17:09 -08:00
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (property.Value is Vector3 vector3)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = new Vector3Field();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Vector3 = vector3;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.Vector3 });
|
|
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-10 20:17:09 -08:00
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (property.Value is DirectionVector directionVector)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool simpleEdit = true;
|
|
|
|
|
|
if (simpleEdit)
|
2018-02-09 18:10:41 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
var dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
|
2018-02-14 19:56:46 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
BorderColor = theme.GetBorderColor(75)
|
|
|
|
|
|
};
|
2018-02-14 19:56:46 -08:00
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
foreach (var orderItem in new string[] { "Right", "Back", "Up" })
|
2018-02-09 18:10:41 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
MenuItem newItem = dropDownList.AddItem(orderItem);
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
var localOredrItem = orderItem;
|
|
|
|
|
|
newItem.Selected += (sender, e) =>
|
2018-02-14 19:56:46 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
switch (dropDownList.SelectedValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "Right":
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitX } });
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Back":
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitY } });
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Up":
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitZ } });
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2018-02-14 19:56:46 -08:00
|
|
|
|
|
2018-03-08 17:23:03 -08:00
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-02-14 19:56:46 -08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
|
|
|
|
|
|
dropDownList.SelectedLabel = "Right";
|
2018-06-08 16:20:57 -07:00
|
|
|
|
|
|
|
|
|
|
rowContainer = CreateSettingsRow(property, dropDownList);
|
|
|
|
|
|
|
2018-02-09 18:10:41 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
else // edit the vector
|
2018-02-09 18:10:41 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
var field = new Vector3Field();
|
2018-02-09 18:10:41 -08:00
|
|
|
|
field.Initialize(0);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
field.Vector3 = directionVector.Normal;
|
2018-02-09 18:10:41 -08:00
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = field.Vector3 } });
|
2018-03-08 17:23:03 -08:00
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-02-09 18:10:41 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content);
|
2018-01-21 14:38:36 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (property.Value is DirectionAxis directionAxis)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool simpleAxis = true;
|
|
|
|
|
|
if (simpleAxis)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// the direction axis
|
|
|
|
|
|
// the distance from the center of the part
|
|
|
|
|
|
// create a double editor
|
|
|
|
|
|
var field = new DoubleField();
|
2018-02-09 18:10:41 -08:00
|
|
|
|
field.Initialize(0);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
field.DoubleValue = directionAxis.Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
2018-02-09 18:10:41 -08:00
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[]
|
2018-06-08 16:20:57 -07:00
|
|
|
|
{
|
|
|
|
|
|
new DirectionAxis()
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-08 16:20:57 -07:00
|
|
|
|
Normal = Vector3.UnitZ, Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + new Vector3(field.DoubleValue, 0, 0)
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2018-03-08 17:23:03 -08:00
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-01-20 12:58:14 -08:00
|
|
|
|
};
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// update tihs when changed
|
2018-06-08 16:20:57 -07:00
|
|
|
|
EventHandler<InvalidateArgs> updateData = (s, e) =>
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
field.DoubleValue = ((DirectionAxis)property.PropertyInfo.GetGetMethod().Invoke(property.Item, null)).Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
};
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.Item.Invalidated += updateData;
|
|
|
|
|
|
editControlsContainer.Closed += (s, e) =>
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.Item.Invalidated -= updateData;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
};
|
2018-06-08 16:20:57 -07:00
|
|
|
|
|
|
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content);
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
else
|
2018-03-13 11:52:23 -07:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// add in the position
|
2018-05-09 13:35:38 -07:00
|
|
|
|
FlowLayoutWidget originRowContainer = CreateSettingsRow(property);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
|
|
|
|
|
|
var originField = new Vector3Field();
|
|
|
|
|
|
originField.Initialize(0);
|
|
|
|
|
|
originField.Vector3 = directionAxis.Origin;
|
|
|
|
|
|
|
|
|
|
|
|
var normalField = new Vector3Field();
|
|
|
|
|
|
normalField.Initialize(0);
|
|
|
|
|
|
normalField.Vector3 = directionAxis.Normal;
|
|
|
|
|
|
|
|
|
|
|
|
originField.ValueChanged += (s, e) =>
|
2018-03-13 11:52:23 -07:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionAxis() { Origin = originField.Vector3, Normal = normalField.Vector3 } });
|
|
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-03-13 11:52:23 -07:00
|
|
|
|
};
|
2018-04-12 17:23:19 -07:00
|
|
|
|
|
|
|
|
|
|
originRowContainer.AddChild(originField.Content);
|
|
|
|
|
|
editControlsContainer.AddChild(originRowContainer);
|
|
|
|
|
|
|
|
|
|
|
|
// add in the direction
|
2018-05-09 13:35:38 -07:00
|
|
|
|
FlowLayoutWidget directionRowContainer = CreateSettingsRow(property);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
|
|
|
|
|
|
normalField.ValueChanged += (s, e) =>
|
2018-03-13 11:52:23 -07:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionAxis() { Origin = originField.Vector3, Normal = normalField.Vector3 } });
|
2018-03-13 11:52:23 -07:00
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
directionRowContainer.AddChild(normalField.Content);
|
|
|
|
|
|
editControlsContainer.AddChild(directionRowContainer);
|
|
|
|
|
|
|
|
|
|
|
|
// update tihs when changed
|
2018-05-22 16:17:13 -07:00
|
|
|
|
EventHandler<InvalidateArgs> updateData = (s, e) =>
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
originField.Vector3 = ((DirectionAxis)property.PropertyInfo.GetGetMethod().Invoke(property.Item, null)).Origin;
|
|
|
|
|
|
};
|
|
|
|
|
|
property.Item.Invalidated += updateData;
|
|
|
|
|
|
editControlsContainer.Closed += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.Item.Invalidated -= updateData;
|
2018-03-13 11:52:23 -07:00
|
|
|
|
};
|
2018-01-28 07:53:23 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-01 17:44:46 -07:00
|
|
|
|
else if (property.Value is ChildrenSelector childSelector)
|
|
|
|
|
|
{
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property);
|
|
|
|
|
|
rowContainer.AddChild(CreateSelector(childSelector, property.Item, theme));
|
|
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a int editor
|
|
|
|
|
|
else if (property.Value is int intValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = new IntField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.IntValue = intValue;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-02-27 18:16:07 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.IntValue });
|
|
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-13 13:42:57 -08:00
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content);
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a bool editor
|
|
|
|
|
|
else if (property.Value is bool boolValue)
|
|
|
|
|
|
{
|
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;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.Checked });
|
|
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field.Content);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
// create a string editor
|
|
|
|
|
|
else if (property.Value is string stringValue)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
var textEditWidget = new MHTextEditWidget(stringValue, pixelWidth: 150 * GuiWidget.DeviceScale)
|
2018-03-08 17:23:03 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
SelectAllOnFocus = true,
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
};
|
|
|
|
|
|
textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { textEditWidget.Text });
|
2018-03-08 17:23:03 -08:00
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-03-08 17:23:03 -08:00
|
|
|
|
};
|
2018-06-08 16:20:57 -07:00
|
|
|
|
|
|
|
|
|
|
rowContainer = CreateSettingsRow(property, textEditWidget);
|
2018-03-08 17:23:03 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a char editor
|
|
|
|
|
|
else if (property.Value is char charValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var textEditWidget = new MHTextEditWidget(charValue.ToString(), pixelWidth: 150 * GuiWidget.DeviceScale)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectAllOnFocus = true,
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
};
|
|
|
|
|
|
textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (textEditWidget.Text.Length < 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
textEditWidget.Text = "a";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (textEditWidget.Text.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
textEditWidget.Text = textEditWidget.Text.Substring(0, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { textEditWidget.Text[0] });
|
|
|
|
|
|
rebuildable?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-06-08 16:20:57 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, textEditWidget);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
// create an enum editor
|
2018-04-23 16:18:16 -07:00
|
|
|
|
else if (property.PropertyType.IsEnum)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
rowContainer = CreateEnumEditor(context, rebuildable,
|
2018-04-23 16:18:16 -07:00
|
|
|
|
property, property.PropertyType, property.Value, property.DisplayName,
|
2018-04-12 17:23:19 -07:00
|
|
|
|
theme, undoBuffer);
|
|
|
|
|
|
}
|
|
|
|
|
|
// Use known IObject3D editors
|
|
|
|
|
|
else if (property.Value is IObject3D object3D
|
2018-04-23 16:18:16 -07:00
|
|
|
|
&& ApplicationController.Instance.GetEditorsForType(property.PropertyType)?.FirstOrDefault() is IObject3DEditor editor)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
rowContainer = editor.Create(object3D, view3DWidget, theme);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-08 16:20:57 -07:00
|
|
|
|
editControlsContainer.AddChild(rowContainer);
|
|
|
|
|
|
|
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-01-20 12:58:14 -08:00
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
private static GuiWidget CreateSelector(ChildrenSelector childSelector, IObject3D parent, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
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())
|
|
|
|
|
|
{
|
|
|
|
|
|
child.SuspendRebuild();
|
|
|
|
|
|
if (!childSelector.Contains(child.ID)
|
|
|
|
|
|
|| tabContainer.HasBeenClosed)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Color = new Color(child.WorldColor(), 255);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Color = new Color(child.WorldColor(), 200);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (selectionChanged)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Visible = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
child.ResumeRebuild();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tabContainer.Closed += (s, e) => UpdateSelectColors();
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
var children = parent.Children.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<ICheckbox, IObject3D> objectChecks = new Dictionary<ICheckbox, IObject3D>();
|
|
|
|
|
|
|
|
|
|
|
|
List<GuiWidget> radioSiblings = new List<GuiWidget>();
|
|
|
|
|
|
for (int i = 0; i < children.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var itemIndex = i;
|
|
|
|
|
|
var child = children[itemIndex];
|
|
|
|
|
|
FlowLayoutWidget rowContainer = new FlowLayoutWidget();
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget selectWidget;
|
|
|
|
|
|
if (children.Count == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
|
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
|
|
|
|
|
TextColor = ActiveTheme.Instance.PrimaryTextColor
|
|
|
|
|
|
};
|
|
|
|
|
|
radioSiblings.Add(radioButton);
|
|
|
|
|
|
radioButton.SiblingRadioButtonList = radioSiblings;
|
|
|
|
|
|
selectWidget = radioButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
|
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
|
|
|
|
|
TextColor = ActiveTheme.Instance.PrimaryTextColor
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
objectChecks.Add((ICheckbox)selectWidget, child);
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(selectWidget);
|
|
|
|
|
|
ICheckbox checkBox = selectWidget as ICheckbox;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
if(parent is MeshWrapperObject3D meshWrapper)
|
|
|
|
|
|
{
|
|
|
|
|
|
meshWrapper.SuspendRebuild();
|
|
|
|
|
|
meshWrapper.ResetMeshWrapperMeshes(Object3DPropertyFlags.All, CancellationToken.None);
|
|
|
|
|
|
meshWrapper.ResumeRebuild();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
bool operationApplied = parent.Descendants()
|
|
|
|
|
|
.Where((obj) => obj.OwnerID == parent.ID)
|
|
|
|
|
|
.Where((objId) => objId.Mesh != objId.Children.First().Mesh).Any();
|
|
|
|
|
|
|
|
|
|
|
|
bool selectionHasBeenMade = parent.Descendants()
|
|
|
|
|
|
.Where((obj) => obj.OwnerID == parent.ID && obj.OutputType == PrintOutputTypes.Hole)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
|
|
|
|
|
|
if (!operationApplied && !selectionHasBeenMade)
|
|
|
|
|
|
{
|
|
|
|
|
|
// select the last item
|
|
|
|
|
|
if (tabContainer.Descendants().Where((d) => d is ICheckbox).Last() is ICheckbox lastCheckBox)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastCheckBox.Checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
updateButton.Enabled = !operationApplied;
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
return tabContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
private void AddUnlockLinkIfRequired(PPEContext context, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
|
2018-02-26 15:28:00 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var unlockLink = context.item.GetType().GetCustomAttributes(typeof(UnlockLinkAttribute), true).FirstOrDefault() as UnlockLinkAttribute;
|
2018-02-26 15:28:00 -08:00
|
|
|
|
if (unlockLink != null
|
2018-03-10 16:32:04 -08:00
|
|
|
|
&& !string.IsNullOrEmpty(unlockLink.UnlockPageLink)
|
2018-05-02 10:59:08 -07:00
|
|
|
|
&& !context.item.Persistable)
|
2018-02-26 15:28:00 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var row = CreateSettingsRow(context.item.Persistable ? "Registered".Localize() : "Demo Mode".Localize());
|
2018-03-07 10:51:58 -08:00
|
|
|
|
|
2018-02-26 15:28:00 -08:00
|
|
|
|
Button detailsLink = theme.ButtonFactory.Generate("Unlock".Localize(), AggContext.StaticData.LoadIcon("locked.png", 16, 16));
|
2018-05-08 18:06:21 -07:00
|
|
|
|
detailsLink.BackgroundColor = theme.Colors.PrimaryAccentColor.AdjustContrast(theme.Colors.PrimaryTextColor, 10).ToColor();
|
2018-02-26 15:28:00 -08:00
|
|
|
|
detailsLink.Margin = new BorderDouble(5);
|
|
|
|
|
|
detailsLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
2018-03-10 16:32:04 -08:00
|
|
|
|
ApplicationController.Instance.LaunchBrowser(UnlockLinkAttribute.UnlockPageBaseUrl + unlockLink.UnlockPageLink);
|
|
|
|
|
|
};
|
|
|
|
|
|
row.AddChild(detailsLink);
|
|
|
|
|
|
editControlsContainer.AddChild(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var unlockLink = context.item.GetType().GetCustomAttributes(typeof(WebPageLinkAttribute), true).FirstOrDefault() as WebPageLinkAttribute;
|
2018-03-10 16:32:04 -08:00
|
|
|
|
if (unlockLink != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var row = CreateSettingsRow(unlockLink.Name.Localize());
|
|
|
|
|
|
|
|
|
|
|
|
Button detailsLink = theme.ButtonFactory.Generate("Open", AggContext.StaticData.LoadIcon("internet.png", 16, 16));
|
|
|
|
|
|
detailsLink.Margin = new BorderDouble(5);
|
|
|
|
|
|
detailsLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ApplicationController.Instance.LaunchBrowser(unlockLink.Url);
|
2018-02-26 15:28:00 -08:00
|
|
|
|
};
|
|
|
|
|
|
row.AddChild(detailsLink);
|
|
|
|
|
|
editControlsContainer.AddChild(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-22 09:45:01 -07:00
|
|
|
|
private static GuiWidget CreateEnumEditor(PPEContext context, IPublicPropertyObject item,
|
2018-04-12 17:23:19 -07:00
|
|
|
|
EditableProperty property, Type propertyType, object value, string displayName,
|
2018-03-08 17:23:03 -08:00
|
|
|
|
ThemeConfig theme,
|
|
|
|
|
|
UndoBuffer undoBuffer)
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2018-02-27 18:16:07 -08:00
|
|
|
|
var propertyGridModifier = item as IPropertyGridModifier;
|
|
|
|
|
|
|
2018-02-12 15:28:26 -08:00
|
|
|
|
// Enum keyed on name to friendly name
|
|
|
|
|
|
var enumItems = Enum.GetNames(propertyType).Select(enumName =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
Key = enumName,
|
|
|
|
|
|
Value = enumName.Replace('_', ' ')
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
FlowLayoutWidget rowContainer = CreateSettingsRow(displayName);
|
|
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
var iconsAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<IconsAttribute>().FirstOrDefault();
|
2018-02-12 17:45:57 -08:00
|
|
|
|
if (iconsAttribute != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
foreach (var enumItem in enumItems)
|
|
|
|
|
|
{
|
2018-02-13 13:42:57 -08:00
|
|
|
|
var localIndex = index;
|
2018-02-27 18:16:07 -08:00
|
|
|
|
ImageBuffer iconImage = null;
|
2018-03-26 16:29:23 -07:00
|
|
|
|
var iconPath = iconsAttribute.IconPaths[localIndex];
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(iconPath))
|
2018-02-27 18:16:07 -08:00
|
|
|
|
{
|
2018-03-26 16:29:23 -07:00
|
|
|
|
if (iconsAttribute.Width > 0)
|
2018-02-27 18:16:07 -08:00
|
|
|
|
{
|
2018-03-26 16:29:23 -07:00
|
|
|
|
iconImage = AggContext.StaticData.LoadIcon(iconPath, iconsAttribute.Width, iconsAttribute.Height);
|
2018-02-27 18:16:07 -08:00
|
|
|
|
}
|
2018-03-26 16:29:23 -07:00
|
|
|
|
else
|
2018-02-12 17:45:57 -08:00
|
|
|
|
{
|
2018-03-26 16:29:23 -07:00
|
|
|
|
iconImage = AggContext.StaticData.LoadIcon(iconPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
var radioButton = new RadioButton(new ImageWidget(iconImage));
|
|
|
|
|
|
radioButton.ToolTipText = enumItem.Key;
|
|
|
|
|
|
// set it if checked
|
|
|
|
|
|
if (enumItem.Value == value.ToString())
|
|
|
|
|
|
{
|
|
|
|
|
|
radioButton.Checked = true;
|
2018-02-27 18:16:07 -08:00
|
|
|
|
if (localIndex != 0
|
|
|
|
|
|
|| !iconsAttribute.Item0IsNone)
|
2018-02-13 13:42:57 -08:00
|
|
|
|
{
|
|
|
|
|
|
radioButton.BackgroundColor = new Color(Color.Black, 100);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-03-26 16:29:23 -07:00
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(radioButton);
|
|
|
|
|
|
|
|
|
|
|
|
var localItem = enumItem;
|
|
|
|
|
|
radioButton.CheckedStateChanged += (sender, e) =>
|
2018-02-13 13:42:57 -08:00
|
|
|
|
{
|
2018-03-26 16:29:23 -07:00
|
|
|
|
if (radioButton.Checked)
|
|
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(
|
|
|
|
|
|
property.Item,
|
2018-03-26 16:29:23 -07:00
|
|
|
|
new Object[] { Enum.Parse(propertyType, localItem.Key) });
|
|
|
|
|
|
item?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-03-26 16:29:23 -07:00
|
|
|
|
if (localIndex != 0
|
|
|
|
|
|
|| !iconsAttribute.Item0IsNone)
|
|
|
|
|
|
{
|
|
|
|
|
|
radioButton.BackgroundColor = new Color(Color.Black, 100);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
radioButton.BackgroundColor = Color.Transparent;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
2018-02-12 17:45:57 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2018-04-01 14:23:27 -07:00
|
|
|
|
var dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
BorderColor = theme.GetBorderColor(75)
|
|
|
|
|
|
};
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
var sortableAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<SortableAttribute>().FirstOrDefault();
|
2018-02-12 17:45:57 -08:00
|
|
|
|
var orderedItems = sortableAttribute != null ? enumItems.OrderBy(n => n.Value) : enumItems;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var orderItem in orderedItems)
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2018-02-12 17:45:57 -08:00
|
|
|
|
MenuItem newItem = dropDownList.AddItem(orderItem.Value);
|
|
|
|
|
|
|
2018-03-26 16:29:23 -07:00
|
|
|
|
var localOrderedItem = orderItem;
|
2018-02-12 17:45:57 -08:00
|
|
|
|
newItem.Selected += (sender, e) =>
|
|
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
property.PropertyInfo.GetSetMethod().Invoke(
|
|
|
|
|
|
property.Item,
|
2018-03-26 16:29:23 -07:00
|
|
|
|
new Object[] { Enum.Parse(propertyType, localOrderedItem.Key) });
|
2018-03-08 17:23:03 -08:00
|
|
|
|
item?.Rebuild(undoBuffer);
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-02-12 17:45:57 -08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
2018-02-12 17:45:57 -08:00
|
|
|
|
dropDownList.SelectedLabel = value.ToString().Replace('_', ' ');
|
|
|
|
|
|
rowContainer.AddChild(dropDownList);
|
|
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
|
|
|
|
|
return rowContainer;
|
|
|
|
|
|
}
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|