/// <summary> /// A callback to handle event where stack count is changed in <paramref name="groupSelector"/>. /// </summary> /// <param name="groupSelector"> Whose stack count has changed. </param> /// <param name="oldStackCount"> The stack count value before current stack count. </param> protected virtual void StackCountChangedCallback(ThingGroupSelector groupSelector, int oldStackCount) { ValidateArg.NotNull(groupSelector, nameof(groupSelector)); this.InventoryMargins[groupSelector] += oldStackCount - groupSelector.AllowedStackCount; this.UpdateThreshold(new[] { groupSelector }); }
private bool ItemNeedsRestock(ThingGroupSelector groupSelector) { return(this.InventoryMargins[groupSelector] < 0 && (_bottomThresholdLookup.TryGetValue(groupSelector, out ThresholdState state) ? state.CanRestock : true)); }
/// <summary> /// Add <paramref name="selector"/> to all loadout in <paramref name="loadouts"/>. /// </summary> /// <param name="selector"> Selector to add. </param> /// <param name="loadouts"> A list of loadouts that <paramref name="selector"/> will be added to. </param> public static void AddToLoadouts(this ThingGroupSelector selector, IEnumerable <AwesomeInventoryLoadout> loadouts) { ValidateArg.NotNull(loadouts, nameof(Loadout)); foreach (AwesomeInventoryLoadout loadout in loadouts) { loadout.Add(new ThingGroupSelector(selector)); } }
/// <summary> /// A callback to handle event where a new <see cref="ThingGroupSelector"/> is added to loadout. /// </summary> /// <param name="groupSelector"> The newly added selector. </param> protected virtual void AddNewThingGroupSelectorCallback(ThingGroupSelector groupSelector) { List <ThingGroupSelector> selectors = this.InventoryMargins .Where(pair => ThingDefComparer.Instance.Equals(pair.Key.AllowedThing, groupSelector.AllowedThing)) .Select(pair => pair.Key) .ToList(); selectors.Add(groupSelector); this.UpdateInventoryMargin(selectors); }
/// <summary> /// Make <see cref="ThingGroupSelector"/> from <paramref name="thing"/>. The selector doen't contain reference to <paramref name="thing"/>. /// </summary> /// <param name="thing"> Source for <see cref="ThingGroupSelector"/>. </param> /// <returns> A <see cref="ThingGroupSelector"/> made from <paramref name="thing"/>. </returns> public static ThingGroupSelector MakeThingGrouopSelector(this Thing thing) { SingleThingSelector singleThingSelector = AwesomeInventoryServiceProvider.MakeInstanceOf <SingleThingSelector>(new[] { thing }); ThingGroupSelector thingSelectors = new ThingGroupSelector(thing.def) { singleThingSelector, }; thingSelectors.SetStackCount(1); return(thingSelectors); }
/// <summary> /// A callback to handle event where a new <see cref="ThingGroupSelector"/> is added to loadout. /// </summary> /// <param name="groupSelector"> The newly added selector. </param> protected virtual void AddNewThingGroupSelectorCallback(ThingGroupSelector groupSelector) { ValidateArg.NotNull(groupSelector, nameof(groupSelector)); List <ThingGroupSelector> selectors = this.InventoryMargins .Where(pair => ThingDefComparer.Instance.Equals(pair.Key.AllowedThing, groupSelector.AllowedThing)) .Select(pair => pair.Key) .ToList(); selectors.Add(groupSelector); this.UpdateInventoryMargin(selectors); this.UpdateThreshold(new[] { groupSelector }); }
/// <summary> /// Initializes a new instance of the <see cref="ThingGroupSelector"/> class. /// </summary> /// <param name="other"> Copy <paramref name="other"/> to this selector. </param> public ThingGroupSelector(ThingGroupSelector other) { ValidateArg.NotNull(other, nameof(other)); this.GroupID = LoadoutManager.ThingGroupSelectorID; AllowedStackCount = other.AllowedStackCount; AllowedThing = other.AllowedThing; foreach (ThingSelector thingSelector in other._selectors) { Type selectorType = thingSelector.GetType(); ThingSelector newSelector = (ThingSelector)Activator.CreateInstance(selectorType, new object[] { thingSelector }); this.Add(newSelector); } }
/// <summary> /// A callback to handle event where a <see cref="ThingGroupSelector"/> is removed from loadout. /// </summary> /// <param name="groupSelector"> The selector that has been removed. </param> protected virtual void RemoveThingGroupSelectorCallback(ThingGroupSelector groupSelector) => this.InventoryMargins.Remove(groupSelector);
/// <summary> /// A callback to handle event where a <see cref="ThingGroupSelector"/> is removed from loadout. /// </summary> /// <param name="groupSelector"> The selector that has been removed. </param> protected virtual void RemoveThingGroupSelectorCallback(ThingGroupSelector groupSelector) { this.InventoryMargins.Remove(groupSelector); _bottomThresholdLookup.Remove(groupSelector); }
/// <inheritdoc/> public override bool Remove(ThingGroupSelector item, bool fromSibling) { this.RemoveItemFromCostume(item); return(base.Remove(item, fromSibling)); }
/// <summary> /// Remove item from costume. /// </summary> /// <param name="selector"> Item to remove. </param> public void RemoveItemFromCostume(ThingGroupSelector selector) { _costumeItems.Remove(selector); }
/// <summary> /// Add item to costume. /// </summary> /// <param name="selector"> Item to add. </param> public void AddItemToCostume(ThingGroupSelector selector) { ValidateArg.NotNull(selector, nameof(selector)); _costumeItems.Add(selector); }