public string GetDefaultFilterName(string filterGroupName, IEditorData data) { FilterGroup filterGroup = m_filterGroups[filterGroupName]; List <Filter> candidates = new List <Filter>(); foreach (Filter filter in filterGroup.Filters.Values) { foreach (string attribute in filter.Attributes) { if (data.GetAttribute(attribute) != null) { candidates.Add(filter); break; } } } // If there is only one candidate then we have our result if (candidates.Count == 1) { return(candidates[0].Name); } // Otherwise just default to the first filter return(filterGroup.Filters.First().Value.Name); }
public void Populate(IEditorData data) { m_data = data; if (data == null) { m_value = null; return; } m_populating = true; PopulateList(); object attr = data.GetAttribute(m_definition.Attribute); IEditableObjectReference value = attr as IEditableObjectReference; if (value == null) { lstDropdown.Text = string.Empty; lstDropdown.IsEnabled = (attr == null); } else { lstDropdown.SelectedItem = value.Reference; lstDropdown.IsEnabled = !data.ReadOnly; } m_value = value; m_populating = false; }
private bool ExitsInverseExists(string to, string direction) { string inverseExit = GetInverseDirection(direction); bool inverseExitExists = false; foreach (string exitName in m_controller.GetObjectNames("exit", to, true)) { IEditorData otherRoomExitData = m_controller.GetEditorData(exitName); bool otherRoomLookOnly = otherRoomExitData.GetAttribute("lookonly") as bool? == true; if (!otherRoomLookOnly) { string otherRoomExitAlias = otherRoomExitData.GetAttribute("alias") as string; inverseExitExists = (inverseExit == otherRoomExitAlias); if (inverseExitExists) break; } } return inverseExitExists; }
internal bool CanEdit(IEditorData data) { object value = data.GetAttribute(ControlDefinition.Attribute); if (value == null) { return(true); } return(value is T); }
private void CreateNewVerb(string selectedPattern, string selectedAttribute) { string newVerbId = Controller.CreateNewVerb(null, false); IEditorData verbData = Controller.GetEditorData(newVerbId); verbData.SetAttribute("property", selectedAttribute); EditableCommandPattern pattern = (EditableCommandPattern)verbData.GetAttribute("pattern"); pattern.Pattern = selectedPattern; verbData.SetAttribute("defaultexpression", m_defaultExpression.Replace("#verb#", selectedPattern)); }
public void Populate(IEditorData data) { m_data = data; if (data != null) { Value = data.GetAttribute(m_attributeName); m_elementName = data.Name; ctlListEditor.IsReadOnly = data.ReadOnly; } else { Value = null; m_elementName = null; } }
public void Populate(IEditorData data) { m_data = data; listView.Items.Clear(); compassControl.Clear(); m_directionListIndexes.Clear(); CompassEditor.SimpleMode = m_controller.SimpleMode; PopulateCompassEditor(null); if (data != null) { IEnumerable<string> exits = m_controller.GetObjectNames("exit", data.Name, true); foreach (string exit in exits) { IEditorData exitData = m_controller.GetEditorData(exit); ExitListData exitListData = new ExitListData { Name = exitData.Name, ToRoom = exitData.GetAttribute("to") as IEditableObjectReference, Alias = exitData.GetAttribute("alias") as string, LookOnly = (exitData.GetAttribute("lookonly") as bool? == true) }; int addedIndex = listView.Items.Add(exitListData); if (m_directionNames.Contains(exitListData.Alias)) { int direction = m_directionNames.IndexOf(exitListData.Alias); compassControl.Populate(direction, exitListData.To, exitListData.LookOnly); m_directionListIndexes[exitListData.Alias] = addedIndex; } } } }
private object BindScript(IValueProvider provider, string attribute, IEditorData data, EditorController controller, string ignoreExpression) { IEditableScripts originalScript = (IEditableScripts)data.GetAttribute(attribute); if (originalScript == null) { return(null); } ElementSaveData.ScriptsSaveData result = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, attribute, controller, originalScript, result, ignoreExpression); return(result); }
internal T Populate(IEditorData data) { m_data = data; object value = data.GetAttribute(ControlDefinition.Attribute); if (value == null) { value = default(T); } if (!(value is T)) { value = default(T); } T result = (T)value; m_oldValue = result; return(result); }
public void Populate(IEditorData data) { m_data = data; m_storedValues.Clear(); if (m_data == null) { if (CurrentElementEditor != null) { CurrentElementEditor.Populate(m_data); } CurrentEditor = null; HideOtherEditors(); return; } object value = m_data.GetAttribute(m_definition.Attribute); bool canEdit = CanEditType(value) && m_definition.Attribute != "type" && m_definition.Attribute != "elementtype"; lstTypes.IsEnabled = canEdit && !data.ReadOnly && m_definition.Attribute != "name"; if (canEdit) { string typeName = GetTypeName(value); string editorName = GetEditorNameForType(typeName); SetSelectedType(typeName); GetOrCreateEditorControl(editorName); if (!string.IsNullOrEmpty(typeName)) { m_storedValues[typeName] = value; } } else { CurrentEditor = null; HideOtherEditors(); } }
public void Populate(IEditorData data) { m_data = data; m_storedValues.Clear(); if (m_data == null) { if (CurrentElementEditor != null) CurrentElementEditor.Populate(m_data); return; } object value = m_data.GetAttribute(m_definition.Attribute); bool canEdit = CanEditType(value); lstTypes.IsEnabled = canEdit && !data.ReadOnly && m_definition.Attribute != "name"; if (canEdit) { string typeName = GetTypeName(value); string editorName = GetEditorNameForType(typeName); SetSelectedType(typeName); GetOrCreateEditorControl(editorName); if (!string.IsNullOrEmpty(typeName)) { m_storedValues[typeName] = value; } } }
public bool IsVisible(IEditorData data) { if (m_alwaysVisible) return true; if (m_visibilityExpression != null) { // evaluate <onlydisplayif> expression, with "this" as the current element Scripts.Context context = new Scripts.Context(); context.Parameters = new Scripts.Parameters("this", m_worldModel.Elements.Get(data.Name)); bool result = m_visibilityExpression.Execute(context); if (!result) return false; } if (m_relatedAttribute != null) { object relatedAttributeValue = data.GetAttribute(m_relatedAttribute); if (relatedAttributeValue is IDataWrapper) relatedAttributeValue = ((IDataWrapper)relatedAttributeValue).GetUnderlyingValue(); string relatedAttributeType = relatedAttributeValue == null ? "null" : WorldModel.ConvertTypeToTypeName(relatedAttributeValue.GetType()); return relatedAttributeType == m_visibleIfRelatedAttributeIsType; } if (m_visibleIfElementInheritsType != null) { if (m_visibleIfElementInheritsTypeElement == null) { m_visibleIfElementInheritsTypeElement = m_worldModel.Elements.Get(ElementType.ObjectType, m_visibleIfElementInheritsType); } return m_worldModel.Elements.Get(data.Name).Fields.InheritsType(m_visibleIfElementInheritsTypeElement); } if (m_notVisibleIfElementInheritsType != null) { if (m_notVisibleIfElementInheritsTypeElement == null) { // convert "mustnotinherit" type names list into a list of type elements m_notVisibleIfElementInheritsTypeElement = new List<Element>( m_notVisibleIfElementInheritsType.Select(t => m_worldModel.Elements.Get(ElementType.ObjectType, t)) ); } // if the element does inherit any of the "forbidden" types, then this control is not visible Element element = m_worldModel.Elements.Get(data.Name); foreach (Element forbiddenType in m_notVisibleIfElementInheritsTypeElement) { if (element.Fields.InheritsType(forbiddenType)) { return false; } } return true; } if (m_filterGroup != null) { // This control is visible if the named filtergroup's current filter selection is this control's filter. string selectedFilter = data.GetSelectedFilter(m_filterGroup); // Or, if the named filtergroup's current filter selection is not set, infer the current filter value // based on which attribute is populated for this data. if (selectedFilter == null) selectedFilter = m_parent.GetDefaultFilterName(m_filterGroup, data); return (selectedFilter == m_filter); } return false; }
public void UpdateField(string attribute, bool setFocus) { var affectedControls = from ctl in m_controls where ctl.Helper.Attribute == attribute select ctl; foreach (var ctl in affectedControls) { ctl.Populate(m_data); } var multiAttributeControls = from ctl in m_controls where ctl.Helper.Options.MultipleAttributes select ctl; foreach (var ctl in multiAttributeControls) { ((IMultiAttributeElementEditorControl)ctl).AttributeChanged(attribute, m_data.GetAttribute(attribute)); } }
private void BindScriptLines(IValueProvider provider, string attribute, EditorController controller, IEditableScripts originalScript, ElementSaveData.ScriptsSaveData result, string ignoreExpression) { if (originalScript == null) { return; } int count = 0; foreach (IEditableScript script in originalScript.Scripts) { ElementSaveData.ScriptSaveData scriptLine = new ElementSaveData.ScriptSaveData(); scriptLine.IsSelected = (bool)provider.GetValue(string.Format("selected-{0}-{1}", attribute, count)).ConvertTo(typeof(bool)); if (script.Type != ScriptType.If) { IEditorDefinition definition = controller.GetEditorDefinition(script); foreach (IEditorControl ctl in definition.Controls.Where(c => c.Attribute != null)) { string key = string.Format("{0}-{1}-{2}", attribute, count, ctl.Attribute); if (ctl.ControlType == "script") { IEditorData scriptEditorData = controller.GetScriptEditorData(script); IEditableScripts originalSubScript = (IEditableScripts)scriptEditorData.GetAttribute(ctl.Attribute); ElementSaveData.ScriptsSaveData scriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, key, controller, originalSubScript, scriptResult, ignoreExpression); scriptLine.Attributes.Add(ctl.Attribute, scriptResult); } else if (ctl.ControlType == "scriptdictionary") { IEditorData dictionaryData = controller.GetScriptEditorData(script); IEditableDictionary <IEditableScripts> dictionary = (IEditableDictionary <IEditableScripts>)dictionaryData.GetAttribute(ctl.Attribute); ElementSaveData.ScriptSaveData switchResult = BindScriptDictionary(provider, controller, ignoreExpression, dictionary, key); scriptLine.Attributes.Add(ctl.Attribute, switchResult); } else if (ctl.ControlType == "list") { // do nothing } else { object value = GetScriptParameterValue( scriptLine, controller, provider, key, ctl.ControlType, ctl.GetString("simpleeditor") ?? "textbox", ctl.GetString("usetemplates"), (string)script.GetParameter(ctl.Attribute), ignoreExpression ); scriptLine.Attributes.Add(ctl.Attribute, value); } } } else { EditableIfScript ifScript = (EditableIfScript)script; object expressionValue = GetScriptParameterValue( scriptLine, controller, provider, string.Format("{0}-{1}-expression", attribute, count), "expression", null, "if", (string)ifScript.GetAttribute("expression"), ignoreExpression ); scriptLine.Attributes.Add("expression", expressionValue); ElementSaveData.ScriptsSaveData thenScriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, string.Format("{0}-{1}-then", attribute, count), controller, ifScript.ThenScript, thenScriptResult, ignoreExpression); scriptLine.Attributes.Add("then", thenScriptResult); int elseIfCount = 0; foreach (EditableIfScript.EditableElseIf elseIf in ifScript.ElseIfScripts) { object elseIfExpressionValue = GetScriptParameterValue( scriptLine, controller, provider, string.Format("{0}-{1}-elseif{2}-expression", attribute, count, elseIfCount), "expression", null, "if", elseIf.Expression, ignoreExpression ); scriptLine.Attributes.Add(string.Format("elseif{0}-expression", elseIfCount), elseIfExpressionValue); ElementSaveData.ScriptsSaveData elseIfScriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, string.Format("{0}-{1}-elseif{2}", attribute, count, elseIfCount), controller, elseIf.EditableScripts, elseIfScriptResult, ignoreExpression); scriptLine.Attributes.Add(string.Format("elseif{0}-then", elseIfCount), elseIfScriptResult); elseIfCount++; } if (ifScript.ElseScript != null) { ElementSaveData.ScriptsSaveData elseScriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, string.Format("{0}-{1}-else", attribute, count), controller, ifScript.ElseScript, elseScriptResult, ignoreExpression); scriptLine.Attributes.Add("else", elseScriptResult); } } result.ScriptLines.Add(scriptLine); count++; } }
private object BindScript(IValueProvider provider, string attribute, IEditorData data, EditorController controller, string ignoreExpression) { IEditableScripts originalScript = (IEditableScripts)data.GetAttribute(attribute); if (originalScript == null) return null; ElementSaveData.ScriptsSaveData result = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, attribute, controller, originalScript, result, ignoreExpression); return result; }
public string GetDefaultFilterName(string filterGroupName, IEditorData data) { FilterGroup filterGroup = m_filterGroups[filterGroupName]; List<Filter> candidates = new List<Filter>(); foreach (Filter filter in filterGroup.Filters.Values) { foreach (string attribute in filter.Attributes) { if (data.GetAttribute(attribute) != null) { candidates.Add(filter); break; } } } // If there is only one candidate then we have our result if (candidates.Count == 1) { return candidates[0].Name; } // Otherwise just default to the first filter return filterGroup.Filters.First().Value.Name; }
protected virtual void PopulateData(IEditorData data) { if (m_data == null) { Value = string.Empty; } else { Value = data.GetAttribute(m_attribute); } }
public bool IsVisible(IEditorData data) { if (m_alwaysVisible) { return(true); } if (m_visibilityExpression != null) { // evaluate <onlydisplayif> expression, with "this" as the current element Scripts.Context context = new Scripts.Context(); context.Parameters = new Scripts.Parameters("this", m_worldModel.Elements.Get(data.Name)); bool result = false; try { result = m_visibilityExpression.Execute(context); } catch { // ignore any exceptions which may occur, for example if the element is being deleted } if (!result) { return(false); } } if (m_notVisibleIfElementInheritsType != null) { if (m_notVisibleIfElementInheritsTypeElement == null) { // convert "mustnotinherit" type names list into a list of type elements m_notVisibleIfElementInheritsTypeElement = new List <Element>( m_notVisibleIfElementInheritsType.Select(t => m_worldModel.Elements.Get(ElementType.ObjectType, t)) ); } // if the element does inherit any of the "forbidden" types, then this control is not visible Element element = m_worldModel.Elements.Get(data.Name); foreach (Element forbiddenType in m_notVisibleIfElementInheritsTypeElement) { if (element.Fields.InheritsTypeRecursive(forbiddenType)) { return(false); } } } if (m_relatedAttribute != null) { object relatedAttributeValue = data.GetAttribute(m_relatedAttribute); if (relatedAttributeValue is IDataWrapper) { relatedAttributeValue = ((IDataWrapper)relatedAttributeValue).GetUnderlyingValue(); } string relatedAttributeType = relatedAttributeValue == null ? "null" : WorldModel.ConvertTypeToTypeName(relatedAttributeValue.GetType()); return(relatedAttributeType == m_visibleIfRelatedAttributeIsType); } if (m_visibleIfElementInheritsType != null) { if (m_visibleIfElementInheritsTypeElement == null) { // convert "mustinherit" type names list into a list of type elements m_visibleIfElementInheritsTypeElement = new List <Element>( m_visibleIfElementInheritsType.Select(t => m_worldModel.Elements.Get(ElementType.ObjectType, t)) ); } // if the element does inherit any of the types, then this control is visible Element element = m_worldModel.Elements.Get(data.Name); foreach (Element type in m_visibleIfElementInheritsTypeElement) { if (element.Fields.InheritsTypeRecursive(type)) { return(true); } } return(false); } if (m_filterGroup != null) { // This control is visible if the named filtergroup's current filter selection is this control's filter. string selectedFilter = data.GetSelectedFilter(m_filterGroup); // Or, if the named filtergroup's current filter selection is not set, infer the current filter value // based on which attribute is populated for this data. if (selectedFilter == null) { selectedFilter = m_parent.GetDefaultFilterName(m_filterGroup, data); } return(selectedFilter == m_filter); } return(true); }