protected DynamicEntry[] AddBulk(string[] proposedIndices) { var dynamicEntries = new DynamicEntry[proposedIndices.Length]; var mode = proposedIndices.Length > 1 ? "Bulk" : "Single"; for (var i = 0; i < proposedIndices.Length; i++) { var proposedIndex = proposedIndices[i]; DynamicEntry dynamicEntry = PoolSpawnEntry(); string resultIndex = InitDynamicEntry(dynamicEntry, proposedIndex); if (resultIndex != string.Empty) { Logger.LogTraceFormat("{0} spawning dynamic entry #[{1}]: proposed: [{2}], entry: {3}", Category.NetUI, mode, resultIndex, proposedIndex, dynamicEntry); } else { Logger.LogWarning($"Dynamic entry \"{proposedIndex}\" {mode} spawn failure, something's wrong with {dynamicEntry}", Category.NetUI); } dynamicEntries[i] = dynamicEntry; } RearrangeListItems(); return(dynamicEntries); }
/// Sets entry name to index, also makes its elements unique by appending index as postfix private string InitDynamicEntry(DynamicEntry entry, string desiredName = "") { if (!entry) { return(""); } string index = desiredName; if (desiredName == "") { index = entryCount++.ToString(); } entry.name = index; //Making inner elements' names unique by adding "index" to the end for (var i = 0; i < entry.Elements.Length; i++) { if (entry.Elements[i] == entry) { //not including self! continue; } //postfix and not prefix because of how NetKeyButton works entry.Elements[i].name = entry.Elements[i].name + "_" + index; } return(index); }
private void UpdateGasEntry(int index, string name, float ratio, float moles, AcuStatus molStatus) { DynamicEntry dynamicEntry = metricsContainer.Entries[index]; var entry = dynamicEntry.GetComponent <GUI_AcuGasEntry>(); entry.SetValues(name, ratio, moles, molStatus); }
/// <summary> /// Generates new entries for the manifest. /// </summary> private void GenerateEntries() { List <CrewManifestEntry> crewManifest = CrewManifestManager.Instance.CrewManifest; crewManifestTemplate.AddItems(crewManifest.Count); for (int i = 0; i < crewManifest.Count; i++) { DynamicEntry dynamicEntry = crewManifestTemplate.Entries[i]; var entry = dynamicEntry.GetComponent <GUI_PDAManifestTemplate>(); CrewManifestEntry record = crewManifest[i]; Occupation occupation = OccupationList.Instance.Get(record.JobType); entry.ReInit(record.Name, occupation != null ? occupation.DisplayName : "[Redacted]"); } }
// TODO: Consider generic method or, perhaps, restructure AirVents/Scrubbers private void PopulateVents() { List <AirVent> vents = Acu.ConnectedDevices.OfType <AirVent>().ToList(); if (vents.Count != ventsList.Entries.Length) { ventsList.SetItems(vents.Count); } for (int i = 0; i < ventsList.Entries.Length; i++) { DynamicEntry dynamicEntry = ventsList.Entries[i]; var entry = dynamicEntry.GetComponent <GUI_AcuVentEntry>(); entry.SetValues(AcuUi, vents[i]); } }
private void PopulateScrubbers() { List <Scrubber> scrubbers = Acu.ConnectedDevices.OfType <Scrubber>().ToList(); if (scrubbers.Count != scrubbersList.Entries.Length) { scrubbersList.SetItems(scrubbers.Count); } for (int i = 0; i < scrubbersList.Entries.Length; i++) { DynamicEntry dynamicEntry = scrubbersList.Entries[i]; var entry = dynamicEntry.GetComponent <GUI_AcuScrubberEntry>(); entry.SetValues(AcuUi, scrubbers[i]); } }
/// Sets entry name to index, also makes its elements unique by appending index as postfix private string InitDynamicEntry(DynamicEntry entry, string desiredName = "") { if (!entry) { return(string.Empty); } string index = desiredName; if (desiredName == string.Empty) { index = EntryPrefix == string.Empty ? entryCount++.ToString() : EntryPrefix + ":" + entryCount++; } entry.name = index; //Making inner elements' names unique by adding "index" to the end foreach (NetUIElement innerElement in entry.Elements) { if (innerElement == entry) { //not including self! continue; } if (innerElement.name.Contains(DELIMITER)) { if (innerElement.name.Contains(DELIMITER + index)) { //Same index - ignore return(index); } else { Logger.LogTraceFormat("Reuse: Inner element {0} already had indexed name, while {1} was expected", Category.NetUI, innerElement, index); //Different index - cut and let set it again innerElement.name = innerElement.name.Split(DELIMITER)[0]; } } //postfix and not prefix because of how NetKeyButton works innerElement.name = innerElement.name + DELIMITER + index; } return(index); }
/// <summary> /// Loading contentm from Format and convert it /// to Nda model using dynamic object to represent it /// </summary> private void LoadContentToFileDynamic() { var fullContent = FileFormat.GetContent(); var enumerable = fullContent as IList <IEnumerable <string> > ?? fullContent.ToList(); Titles = enumerable.First().ToList(); foreach (var singleNdaEntry in enumerable.Skip(1)) { dynamic ndaEntry = new DynamicEntry(); var index = 0; foreach (var entryPart in singleNdaEntry) { ndaEntry.SetProperty(Titles[index].Replace(" ", ""), entryPart); index++; } DynamicContent.Add(ndaEntry); } }
public bool AddItem(GameObject prefab) { if (!prefab || prefab.GetComponent <ItemAttributesV2>() != null) { Logger.LogWarning($"No valid prefab found: {prefab}", Category.ItemSpawn); return(false); } var entryArray = Entries; for (var i = 0; i < entryArray.Length; i++) { DynamicEntry entry = entryArray[i]; var item = entry as ItemEntry; if (!item || !item.Prefab || item.Prefab.Equals(prefab)) { Logger.Log($"Item {prefab} already exists in ItemList", Category.ItemSpawn); return(false); } } //add new entry ItemEntry newEntry = Add() as ItemEntry; if (newEntry == null) { Logger.LogWarning($"Added {newEntry} is not an ItemEntry!", Category.ItemSpawn); return(false); } //set its elements newEntry.Prefab = prefab; Logger.Log($"ItemList: Item add success! newEntry={newEntry}", Category.ItemSpawn); //rescan elements and notify NetworkTabManager.Instance.Rescan(MasterTab.NetTabDescriptor); UpdatePeepers(); return(true); }
protected DynamicEntry[] AddBulk(string[] proposedIndices) { var dynamicEntries = new DynamicEntry[proposedIndices.Length]; var mode = proposedIndices.Length > 1 ? "Bulk" : "Single"; string elementType = $"{MasterTab.Type}Entry"; GameObject prefab = Resources.Load <GameObject>(elementType); for (var i = 0; i < proposedIndices.Length; i++) { var proposedIndex = proposedIndices[i]; //future suggestion: support more than one kind of entries per tab (introduce EntryType field or something) GameObject entryObject = Instantiate(prefab, transform, false); DynamicEntry dynamicEntry = entryObject.GetComponent <DynamicEntry>(); string resultIndex = InitDynamicEntry(dynamicEntry, proposedIndex); RefreshPositions(); if (resultIndex != "") { // Debug.Log( $"{mode} spawning entry #[{resultIndex}]: proposed: [{proposedIndex}], entry: {dynamicEntry}" ); } else { Debug.LogWarning($"Entry \"{proposedIndex}\" {mode} spawn failure, no such entryObject {elementType}"); } dynamicEntries[i] = dynamicEntry; } if (MasterTab.IsServer) { NetworkTabManager.Instance.Rescan(MasterTab.NetTabDescriptor); } return(dynamicEntries); }
public bool AddItem() { var entryArray = Entries; for (var i = 0; i < entryArray.Length; i++) { DynamicEntry entry = entryArray[i]; var item = entry as GUI_CloningRecordItem; } //add new entry GUI_CloningRecordItem newEntry = Add() as GUI_CloningRecordItem; if (!newEntry) { return(false); } //rescan elements and notify NetworkTabManager.Instance.Rescan(MasterTab.NetTabDescriptor); UpdatePeepers(); return(true); }
/// Defines the way list items are positioned. /// Adds next entries directly below (using height) by default protected virtual void SetProperPosition(DynamicEntry entry, int index = 0) { RectTransform rect = entry.gameObject.GetComponent <RectTransform>(); rect.anchoredPosition = Vector3.down * rect.rect.height * index; }
public DynamicOption(OptionMessage messageExpression, OptionAction action, OptionColor colorExpression = null) { Entry = new DynamicEntry <T>(messageExpression, colorExpression); Action = action; }
protected override void SetProperPosition(DynamicEntry entry, int sortIndex = 0) { }