protected static void DrawListControls <V>(StructureControl <List <V> > control, Div container) { container.Clear(); for (int i = 0; i < control.structure.Count; i++) { int index = i; if (control.specifiedFields.Contains(typeof(V))) { FieldControl <V> fieldControl = new FieldControl <V>(control.structure[index], control.name + "list-item", "item", false, control.world); fieldControl.eventManager.AddListener <FieldControlUpdated <V> >(e => { control.structure[index] = e.control.value; control.eventManager.Raise(new StructureControlUpdated <List <V> >(control)); }); ListItemImage delButton = fieldControl.AddImage(AssetDatabase.LoadAssetAtPath <Texture>("Assets/Icons/times.png")).AddToClassList("selectable", "hoverable", "icon"); delButton.eventManager.AddListener <MouseClickEvent>(e => { control.structure.RemoveAt(index); control.eventManager.Raise(new StructureControlUpdated <List <V> >(control)); DrawListControls <V>(control, container); }); container.Add(fieldControl); } else { V structure = control.structure[index]; StructureControl <V> structureControl = new StructureControl <V>(ref structure); structureControl.eventManager.AddListener <StructureControlUpdated <V> >(e => { control.eventManager.Raise(new StructureControlUpdated <List <V> >(control)); }); } } }
protected static void DrawSetControls <V>(StructureControl <HashSet <V> > control, Div container) { container.Clear(); foreach (V item in control.structure) { if (control.specifiedFields.Contains(typeof(V))) { FieldControl <V> fieldControl = new FieldControl <V>(item, control.name + "list-item", "item", false, control.world); fieldControl.eventManager.AddListener <FieldControlUpdated <V> >(e => { control.structure.Remove(item); control.structure.Add(e.control.value); control.eventManager.Raise(new StructureControlUpdated <HashSet <V> >(control)); }); ListItemImage delButton = fieldControl.AddImage(AssetDatabase.LoadAssetAtPath <Texture>("Assets/Icons/times.png")).AddToClassList("selectable", "hoverable", "icon"); delButton.eventManager.AddListener <MouseClickEvent>(e => { control.structure.Remove(item); control.eventManager.Raise(new StructureControlUpdated <HashSet <V> >(control)); DrawSetControls <V>(control, container); }); container.Add(fieldControl); } else { V structure = item; StructureControl <V> structureControl = new StructureControl <V>(ref structure); structureControl.eventManager.AddListener <StructureControlUpdated <V> >(e => { control.eventManager.Raise(new StructureControlUpdated <HashSet <V> >(control)); }); } } }
protected static void CreateControl <V>(StructureControl <ProvenceCollectionInstance <V> > control) where V : ProvenceCollectionEntry { //Change to picker ListItem item = new ListItem(); KeySelectorElement keySelector = item.AddKeySelector("Entry Name:", control.structure.key, ProvenceManager.Collections <V>().Keys.ToSet()); keySelector.eventManager.AddListener <MainframeKeySelection <string> >(e => { control.structure.key = e.value; control.eventManager.Raise <MainframeKeySelection <string> >(new MainframeKeySelection <string>(e.value)); control.eventManager.Raise(new StructureControlUpdated <ProvenceCollectionInstance <V> >(control)); }); item.AddButton("Set to Entry").eventManager.AddListener <MouseClickEvent>(e => { if (e.button != 0) { return; } if (control.world != null && control.entity != null) { control.world.eventManager.Raise(new SetEntityToManualEntry <V>(control.entity, keySelector.value)); control.eventManager.Raise(new StructureControlUpdated <ProvenceCollectionInstance <V> >(control)); control.eventManager.Raise(new StructureControlRefreshRequest(100)); } }); control.Add(item); }
protected void CreateNestedStructureControl <U>(FieldInfo info) { if (depth >= 5) { Debug.LogWarning("Nested too deep"); return; } string title = System.Text.RegularExpressions.Regex.Replace(info.Name, @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0"); ListItem titleItem = new ListItem(); titleItem.AddTitle(title); titleItem.name = this.name + "--" + typeof(U).Name.ToLower() + "-control-title"; titleItem.AddToClassList("structure-control-title", "spacer"); U structRef = (U)info.GetValue(structure); if (structRef == null) { return; } StructureControl <U> el = new StructureControl <U>(ref structRef, this.name + "--" + typeof(U).Name.ToLower(), startAlt, world, entity, depth + 1, attributeHideList.ToArray()); el.eventManager.AddListener <StructureControlUpdated <U> >(e => { eventManager.Raise <StructureControlUpdated <T> >(new StructureControlUpdated <T>(this)); }); this.Add(titleItem); this.Add(el); }
protected virtual Div DrawComponentControl <V>(V component) where V : ProvenceComponent { Div container = new Div(); container.name = typeof(V).Name.ToLower() + "-control-container"; StructureControl <V> control = new StructureControl <V>(ref component, null, false, null, null, 0, typeof(DontDisplayInManual)); control.eventManager.AddListener <StructureControlUpdated <V> >(e => { eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(SceneManager.GetActiveScene())); }); container.Add(control); return(container); }
protected void DrawSystemControl <T>() where T : ProvenceSystem { ColumnScroller scroller = root.Q <ColumnScroller>("editor-scroller"); T system = (T)chosenKey; if (scroller != null) { scroller.Clear(); StructureControl <T> control = new StructureControl <T>(ref system, system.GetType().Name, false, chosenKey.world); control.eventManager.AddListener <StructureControlUpdated <T> >(e => { eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(SceneManager.GetActiveScene())); }); scroller.Add(control); } }
protected static void CreateControl(StructureControl <Model> control) { ListItem keySelectorItem = new ListItem(); KeySelectorElement keySelector = keySelectorItem.AddKeySelector("Model Bank Key", control.structure.manualKey, new HashSet <string>(ProvenceManager.ModelBank.Keys)); keySelector.eventManager.AddListener <MainframeKeySelection <string> >(e => { control.structure.manualKey = e.value; control.eventManager.Raise <MainframeKeySelection <string> >(new MainframeKeySelection <string>(e.value)); control.eventManager.Raise <StructureControlUpdated <Model> >(new StructureControlUpdated <Model>(control)); }); keySelector.eventManager.AddListener <ListItemInputCancel>(e => { control.structure.manualKey = ""; control.eventManager.Raise <ListItemInputCancel>(new ListItemInputCancel(control)); control.eventManager.Raise <StructureControlUpdated <Model> >(new StructureControlUpdated <Model>(control)); }); control.Add(keySelectorItem); }
protected static void CreateControl <V>(StructureControl <List <V> > control) { Div container = new Div(); ListItem addBar = new ListItem().AddToClassList("spacer", "alternate"); addBar.AddDiv().AddToClassList("filler"); addBar.AddImage(AssetDatabase.LoadAssetAtPath <Texture>("Assets/Icons/plus.png")); addBar.eventManager.AddListener <MouseClickEvent>(e => { if (e.button != 0) { return; } control.structure.Add(default(V)); control.eventManager.Raise(new StructureControlUpdated <List <V> >(control)); DrawListControls(control, container); }); control.Add(container, addBar); DrawListControls(control, container); }
protected void DrawStructureControl <T>(T component) where T : ProvenceComponent { ListItem titleItem = new ListItem(); titleItem.name = typeof(T).Name.ToLower() + "-control-title"; titleItem.AddToClassList("spacer", "structure-control-title"); titleItem.AddTextDisplay(System.Text.RegularExpressions.Regex.Replace(component.GetType().Name, @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0"), true); StructureControl <T> control = new StructureControl <T>(ref component, component.GetType().Name, false, chosenKey.world, chosenKey.entity); control.eventManager.AddListener <StructureControlUpdated <T> >(e => { eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(SceneManager.GetActiveScene())); }); control.eventManager.AddListener <StructureControlRefreshRequest>(e => { Helpers.Delay(() => { chosenComponents.Clear(); eventManager.Raise <DrawColumnEventArgs <ProvenceComponent> >(new DrawColumnEventArgs <ProvenceComponent>(0)); }, 10); }); editorScroller.Add(titleItem); editorScroller.Add(control); }
/* protected void CreateDefaultControl(){ * bool alternate = startAlt; * FieldInfo[] fields = structure.GetType().GetFields(); * for(int i = 0; i < fields.Length; i++){ * try{ * Type fieldType = fields[i].FieldType; * bool hide = false; * foreach(Type attributeType in attributeHideList){ * if(fields[i].IsDefined(attributeType,false) || fieldType.IsDefined(attributeType,false)){ * hide = true; * break; * } * } * if(hide) continue; * if(specifiedFields.Contains(fieldType) || fieldType.IsDefined(typeof(CustomFieldControl), false) || fieldType.IsEnum) * Helpers.InvokeGenericMethod(this,"CreateFieldControl", fieldType, fields[i], alternate); * else * Helpers.InvokeGenericMethod(this,"CreateNestedStructureControl", fieldType, fields[i]); * alternate = !alternate; * }catch(Exception e){ * Debug.LogWarning(e); * } * } * } */ protected static void CreateControl <U>(StructureControl <U> control) { bool alternate = control.startAlt; FieldInfo[] fields = control.structure.GetType().GetFields(); for (int i = 0; i < fields.Length; i++) { try{ Type fieldType = fields[i].FieldType; bool hide = false; foreach (Type attributeType in control.attributeHideList) { if (fields[i].IsDefined(attributeType, false) || fieldType.IsDefined(attributeType, false)) { hide = true; break; } } if (hide) { continue; } if (control.specifiedFields.Contains(fieldType) || fieldType.IsDefined(typeof(CustomFieldControl), false) || fieldType.IsEnum) { Helpers.InvokeGenericMethod(control, "CreateFieldControl", fieldType, fields[i], alternate); } else { Helpers.InvokeGenericMethod(control, "CreateNestedStructureControl", fieldType, fields[i]); } alternate = !alternate; }catch (Exception e) { Debug.LogWarning(e); } } }
public StructureControlUpdated(StructureControl <T> control) { this.control = control; }