示例#1
0
			/// <summary>
			/// Applied before RefreshRows runs.
			/// </summary>
			internal static bool Prefix(TableScreen __instance) {
				var identities = HashSetPool<IAssignableIdentity, TableScreen>.Allocate();
				var living = Components.LiveMinionIdentities.Items;
				StoredMinionIdentity smi;
				// Living Duplicants
				for (int i = 0; i < living.Count; i++) {
					var dupe = living[i];
					if (dupe != null)
						identities.Add(dupe);
				}
				// Duplicants in vanilla rockets and similar
				foreach (var minionStorage in Components.MinionStorages.Items)
					foreach (var info in minionStorage.GetStoredMinionInfo()) {
						var dupe = info.serializedMinion;
						if (dupe != null && (smi = dupe.Get<StoredMinionIdentity>()) != null)
							__instance.AddRow(smi);
					}
				ClearAndAddRows(__instance, identities);
				// Add the missing rows
				foreach (var missingMinion in identities)
					__instance.AddRow(missingMinion);
				identities.Recycle();
				if (DlcManager.FeatureClusterSpaceEnabled())
					AddDividers(__instance);
				SortRows(__instance);
				__instance.rows_dirty = false;
				return false;
			}
示例#2
0
		/// <summary>
		/// Removes and pools any existing rows. Leaves the default and header row if present,
		/// otherwise creates and adds one when requested.
		/// </summary>
		/// <param name="instance">The table screen to clear.</param>
		/// <param name="toAdd">The Duplicants to be added or updated.</param>
		private static void ClearAndAddRows(TableScreen instance,
				ISet<IAssignableIdentity> toAdd) {
			var columns = instance.columns;
			var hr = instance.header_row;
			List<TableRow> rows = instance.rows, sortableRows = instance.all_sortable_rows;
			int n = rows.Count;
			TableRow defaultRow = null, headerRow = null;
			var newRows = TableRowList.Allocate();
			var deadRows = HashSetPool<TableRow, TableScreen>.Allocate();
			IAssignableIdentity minion;
			for (int i = 0; i < n; i++) {
				var row = rows[i];
				var go = row.gameObject;
				// Do not destroy the default or header; pull out any rows for existing minion
				// identities
				if (row.rowType == TableRow.RowType.Default) {
					ThawLayout(go);
					defaultRow = row;
				} else if (go == hr && hr != null) {
					ThawLayout(go);
					headerRow = row;
				} else if (row.rowType != TableRow.RowType.WorldDivider && (minion = row.
						minion) != null && toAdd.Remove(minion)) {
					ThawLayout(go);
					ConfigureContent(row, minion, columns, instance);
					newRows.Add(row);
				} else
					deadRows.Add(row);
			}
			sortableRows.Clear();
			rows.Clear();
			// Restore cached default and header rows; header first
			if (headerRow != null) {
				ConfigureContent(headerRow, null, columns, instance);
				rows.Add(headerRow);
			} else
				instance.AddRow(null);
			if (defaultRow != null) {
				ConfigureContent(defaultRow, null, columns, instance);
				rows.Add(defaultRow);
			} else if (instance.has_default_duplicant_row)
				instance.AddDefaultRow();
			// Add reused rows, delete removed rows
			sortableRows.AddRange(newRows);
			rows.AddRange(newRows);
			newRows.Recycle();
			TakeOutTrash(instance, deadRows);
			deadRows.Recycle();
		}