private void DragItemToLoadout(Rect iconRect, ThingGroupSelector groupSelector) { if (InputUtility.IsLeftMouseClick && iconRect.Contains(Event.current.mousePosition)) { if (InputUtility.IsControl && InputUtility.IsLeftMouseClick) { _groupSelectCopy = groupSelector; _dragging = true; Event.current.Use(); } } if (InputUtility.IsLeftMouseUp && _dragging) { int index = Mathf.FloorToInt(Event.current.mousePosition.y / _rowHeight); if (index > -1 && index < _colonist.Count && _colonist[index].UseLoadout(out CompAwesomeInventoryLoadout comp)) { comp.Loadout.Add(new ThingGroupSelector(_groupSelectCopy)); } _dragging = false; Event.current.Use(); } if (_dragging) { DrawUtility.DrawMouseAttachmentWithThing(_groupSelectCopy.AllowedThing, _groupSelectCopy.SingleThingSelectors.FirstOrDefault()?.AllowedStuff); } }
private void DrawItemsInCostume(Rect canvas) { Widgets.NoneLabelCenteredVertically(canvas.ReplaceHeight(GenUI.ListSpacing), UIText.ItemsInCostume.TranslateSimple()); Rect outRect = canvas.ReplaceyMin(canvas.y + GenUI.ListSpacing); Rect viewRect = new Rect(outRect); viewRect.height = _loadout.Count * GenUI.ListSpacing; GUI.DrawTexture(outRect, TexResource.DarkBackground); Widgets.BeginScrollView(outRect, ref _getupdetailScrollPos, viewRect); if (_costume != null) { bool alternate = true; Rect labelRect = new Rect(viewRect.x + GenUI.GapTiny, viewRect.y, viewRect.width - GenUI.ListSpacing - GenUI.ScrollBarWidth, GenUI.ListSpacing); for (int i = 0; i < _costume.CostumeItems.Count; i++) { ThingGroupSelector selector = _costume.CostumeItems[i]; Text.WordWrap = false; GUI.DrawTexture(labelRect, (alternate ^= true) ? TexUI.TextBGBlack : TexUI.GrayTextBG); Widgets.Label(labelRect, selector.LabelCapNoCount); if (Widgets.ButtonImage(new Rect(labelRect.xMax, labelRect.y, GenUI.SmallIconSize, GenUI.SmallIconSize), TexResource.CloseXSmall)) { _costume.RemoveItemFromCostume(selector); } labelRect = labelRect.ReplaceY(labelRect.yMax); } } Widgets.EndScrollView(); }
/// <summary> /// Open loadout window, and if appropriately, open stuff window as well. /// </summary> /// <param name="pawn"> Pawn who interact with <paramref name="thing"/>. </param> /// <param name="comp"> Comp on <paramref name="pawn"/>. </param> /// <param name="thing"> Thing that <paramref name="pawn"/> interacts with. </param> public static void AddToLoadoutDialog(Pawn pawn, CompAwesomeInventoryLoadout comp, Thing thing) { ValidateArg.NotNull(comp, nameof(comp)); ThingGroupSelector groupSelector = thing.MakeThingGrouopSelector(); comp.Loadout.Add(groupSelector); OpenLoadoutWindow(pawn, comp, groupSelector); }
/// <summary> /// Initializes a new instance of the <see cref="Dialog_AddAmmoPerMagSize"/> class. /// </summary> /// <param name="selector"> Selector for ammo. </param> /// <param name="ammoUser"> The user of ammo. </param> /// <param name="magazineSize"> Size of the magazine. </param> public Dialog_AddAmmoPerMagSize(ThingGroupSelector selector, ThingDef ammoUser, int magazineSize) { _selector = selector; _magazineSize = magazineSize; _ammoUser = ammoUser; this.closeOnClickedOutside = true; this.absorbInputAroundWindow = true; }
protected ThingGroupSelector BuildGroupSelector(ThingDef thingDef, QualityCategory qualityCategory, int stackCount) { ThingGroupSelector groupSelector = new ThingGroupSelector(thingDef); SingleThingSelector singleThingSelector = new SingleThingSelector(thingDef); singleThingSelector.SetQualityRange(new QualityRange(qualityCategory, QualityCategory.Legendary)); groupSelector.Add(singleThingSelector); groupSelector.SetStackCount(stackCount); return(groupSelector); }
public override void Setup() { _strict = this.BuildGroupSelector(_weaponThingDef, QualityCategory.Masterwork, 2); _loose = this.BuildGroupSelector(_weaponThingDef, QualityCategory.Awful, 2); _loadout.Add(_strict); _loadout.Add(_loose); _comp.UpdateForNewLoadout(_loadout); }
public override void Setup() { _controlGroup = this.BuildGroupSelector(_weaponThingDef, QualityCategory.Masterwork, 2); _experimentGroup = this.BuildGroupSelector(_weaponThingDef, QualityCategory.Masterwork, 2); _loadout.Add(_controlGroup); _loadout.Add(_experimentGroup); _comp.UpdateForNewLoadout(_loadout); }
/// <summary> /// Initializes a new instance of the <see cref="Dialog_RestockTrigger"/> class. /// </summary> /// <param name="groupSelector"> Set restock trigger for this selector. </param> public Dialog_RestockTrigger(ThingGroupSelector groupSelector) { ValidateArg.NotNull(groupSelector, nameof(groupSelector)); _groupSelector = groupSelector; _checked = _groupSelector.UseBottomThreshold; this.doCloseX = true; this.absorbInputAroundWindow = true; this.closeOnClickedOutside = true; this.draggable = true; }
/// <summary> /// Draw ammo selection for <paramref name="thingDef"/> if it is an ammo user. /// </summary> /// <param name="widgetRow"> Drawing helper. </param> /// <param name="thingDef"> Ammo user. </param> protected virtual void DrawAmmoSelection(WidgetRow widgetRow, ThingDef thingDef) { ValidateArg.NotNull(widgetRow, nameof(widgetRow)); ValidateArg.NotNull(thingDef, nameof(thingDef)); if (thingDef.HasComp(typeof(CompAmmoUser)) && widgetRow.ButtonIcon(ImageResource.IconAmmo)) { CompProperties_AmmoUser ammoUser = thingDef.GetCompProperties <CompProperties_AmmoUser>(); GenericAmmo genericAmmo = this.CreateGenericAmmoDef(thingDef); List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (ThingDef ammoDef in ammoUser.ammoSet?.ammoTypes.Select(al => al.ammo as ThingDef).Concat(genericAmmo as ThingDef)) { options.Add( new FloatMenuOption( ammoDef.LabelCap , () => { ThingGroupSelector groupSelector = new ThingGroupSelector(ammoDef); ThingSelector thingSelector; thingSelector = AwesomeInventoryServiceProvider.MakeInstanceOf <SingleThingSelector>(ammoDef, null); groupSelector.SetStackCount(ammoUser.magazineSize); groupSelector.Add(thingSelector); if (WhiteBlacklistView.IsWishlist) { _currentLoadout.Add(groupSelector); } else { _currentLoadout.AddToBlacklist(groupSelector); } })); } Find.WindowStack.Add(new FloatMenu(options)); } }
public override void Run(out bool result) { result = true && AssertUtility.Expect(_comp.InventoryMargins.Count, 1, "ThingGroupSelector count"); _groupSelector = this.BuildGroupSelector(_apparelThingDef, QualityCategory.Normal, 1); _loadout.Add(_groupSelector); result &= AssertUtility.Expect(_comp.InventoryMargins.Count, 2, "ThingGroupSelector count"); _groupSelector = this.BuildGroupSelector(_apparelThingDef, QualityCategory.Normal, 1); _loadout.Add(_groupSelector); result &= AssertUtility.Expect(_comp.InventoryMargins.Count, 3, "ThingGroupSelector count"); _loadout.RemoveAt(0); result &= AssertUtility.Expect(_comp.InventoryMargins.Count, 2, "ThingGroupSelector count"); _loadout.RemoveAt(0); result &= AssertUtility.Expect(_comp.InventoryMargins.Count, 1, "ThingGroupSelector count"); }
/// <summary> /// Initializes a new instance of the <see cref="Dialog_StuffAndQuality"/> class. /// </summary> /// <param name="groupSelector"> Draw dialog from this selector. </param> public Dialog_StuffAndQuality(ThingGroupSelector groupSelector) { _groupSelector = groupSelector ?? throw new ArgumentNullException(nameof(groupSelector)); IEnumerable <SingleThingSelector> singleThingSelectors = _groupSelector.OfType <SingleThingSelector>(); _useSeparateButton = false; _isSeparated = false; _selectedSingleThingSelector = null; if (singleThingSelectors.Count() > 1) { _useSeparateButton = true; _isSeparated = singleThingSelectors.Select(t => t.AllowedQualityLevel).ToHashSet().Count > 1 || singleThingSelectors.Select(t => t.AllowedHitPointsPercent).ToHashSet().Count > 1; if (_isSeparated) { _selectedSingleThingSelector = singleThingSelectors.First(); } } closeOnClickedOutside = true; absorbInputAroundWindow = true; doCloseX = true; }
/// <inheritdoc/> protected override void DrawItemRow(Rect row, int index, IList <ThingGroupSelector> groupSelectors, int reorderableGroup, bool drawShadow = false) { ValidateArg.NotNull(row, nameof(row)); ValidateArg.NotNull(groupSelectors, nameof(groupSelectors)); /* Label (fill) | Weight | Gear Icon | Count Field | Delete Icon */ WidgetRow widgetRow = new WidgetRow(row.width, row.y, UIDirection.LeftThenDown, row.width); ThingGroupSelector groupSelector = groupSelectors[index]; // Draw delete icon. this.DrawDeleteIconInThingRow(widgetRow, groupSelectors, groupSelector); Text.Anchor = TextAnchor.MiddleLeft; // Draw count field. if (WhiteBlacklistView.IsWishlist) { this.DrawCountFieldInThingRow( new Rect(widgetRow.FinalX - WidgetRow.IconSize * 2 - WidgetRow.DefaultGap, widgetRow.FinalY, WidgetRow.IconSize * 2, GenUI.ListSpacing), groupSelector); widgetRow.GapButtonIcon(); widgetRow.GapButtonIcon(); } // Draw threshold. if (widgetRow.ButtonIcon(TexResource.Threshold, UIText.StockMode.TranslateSimple())) { Find.WindowStack.Add(new Dialog_RestockTrigger(groupSelector)); } // Draw gear icon. this.DrawGearIconInThingRow(widgetRow, groupSelector); // Draw ammo if thing is ammo user. this.DrawAmmoSelection(widgetRow, groupSelector.AllowedThing); Text.WordWrap = false; // Draw weight or bulk. if (_drawWeight) { widgetRow.Label(groupSelector.Weight.ToStringMass()); } else { widgetRow.Label(groupSelector.AllowedThing.GetStatValueAbstract(CE_StatDefOf.Bulk).ToString() + " b"); } // Draw label. Rect labelRect = widgetRow.Label( drawShadow ? groupSelector.LabelCapNoCount.StripTags().Colorize(Theme.MilkySlicky.ForeGround) : groupSelector.LabelCapNoCount , widgetRow.FinalX); Text.WordWrap = true; Text.Anchor = TextAnchor.UpperLeft; if (!drawShadow) { ReorderableWidget.Reorderable(reorderableGroup, labelRect); // Tooltips && Highlights Widgets.DrawHighlightIfMouseover(row); if (Event.current.type == EventType.MouseDown && Mouse.IsOver(row)) { TooltipHandler.ClearTooltipsFrom(labelRect); if (Event.current.button == 1) { FloatMenu floatMenu = new FloatMenu( new List <FloatMenuOption>() { new FloatMenuOption( UIText.AddToAllLoadout.TranslateSimple() , () => { var loadout = _currentLoadout; if (loadout is AwesomeInventoryCostume costume) { loadout = costume.Base; } groupSelector.AddToLoadouts(Loadout.LoadoutManager.PlainLoadouts.Except(loadout)); }), });
private static void OpenLoadoutWindow(Pawn pawn, CompAwesomeInventoryLoadout comp, ThingGroupSelector groupSelector) { Find.WindowStack.Add(AwesomeInventoryServiceProvider.MakeInstanceOf <Dialog_ManageLoadouts>(new object[] { comp.Loadout, pawn, false })); ThingDef allowedThing = groupSelector.AllowedThing; if (allowedThing.MadeFromStuff || allowedThing.HasComp(typeof(CompQuality)) || allowedThing.useHitPoints) { Find.WindowStack.Add(new Dialog_StuffAndQuality(groupSelector)); } }
private void DrawStats(Rect rect, ThingGroupSelector groupSelector) { // Create thing stuff pair for drawing. List <TSPWQuality> pairListToDraw = new List <TSPWQuality>(); if (groupSelector.AllowedThing.MadeFromStuff) { foreach (SingleThingSelector singleThingSelector in groupSelector.OfType <SingleThingSelector>()) { if (singleThingSelector.AllowedStuff != null) { pairListToDraw.Add( new TSPWQuality( groupSelector.AllowedThing, singleThingSelector.AllowedStuff, singleThingSelector.AllowedQualityLevel.min)); } } if (_stuffPreview != null) { pairListToDraw.Add(new TSPWQuality(groupSelector.AllowedThing, _stuffPreview, _qualityPreview)); } } else { pairListToDraw.Add(new TSPWQuality(groupSelector.AllowedThing, null, QualityCategory.Normal)); } _statScrollWidth = pairListToDraw.Count * _statColumnWidth; WidgetRow row = new WidgetRow( rect.x + (_groupSelector.AllowedThing.IsWeapon ? _lineHeaderWidthForWeapon : _lineHeaderWidth), rect.y, UIDirection.RightThenDown, _statScrollWidth); Rect outRect = new Rect(row.FinalX, row.FinalY, _statColumnWidth * 3, rect.height); Rect viewRect = new Rect(row.FinalX, row.FinalY, _statScrollWidth, rect.height); DrawUtility.GetIndexRangeFromScrollPosition(outRect.width, _statScrollPosition.y, out int from, out int to, _statColumnWidth); Rect startRect = new Rect( rect.x + (_groupSelector.AllowedThing.IsWeapon ? _lineHeaderWidthForWeapon : _lineHeaderWidth) + from * _statColumnWidth, rect.y, _statColumnWidth, GenUI.ListSpacing); // Draw stats if (groupSelector.AllowedThing.IsApparel) { DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidth, GenUI.ListSpacing), _armorStats, out _); Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect); Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect); DrawStatTableHeader(startRect, from, to, pairListToDraw); DrawStatRows(_armorStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out _); Widgets.EndScrollView(); } else if (groupSelector.AllowedThing.IsMeleeWeapon) { DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _baseWeaponStats, out float nameColumnY); DrawStatNameColumn(new Rect(rect.x, nameColumnY, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _meleeWeaponStats, out _); Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect); Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect); DrawStatTableHeader(startRect, from, to, pairListToDraw); DrawStatRows(_baseWeaponStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out float rollingY); DrawStatRows(_meleeWeaponStats, pairListToDraw, startRect.ReplaceY(rollingY), from, to, out _); Widgets.EndScrollView(); } else if (groupSelector.AllowedThing.IsRangedWeapon) { DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _baseWeaponStats, out float nameColumnY); DrawStatNameColumn(new Rect(rect.x, nameColumnY, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _rangedWeaponStats, out _); Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect); Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect); DrawStatTableHeader(startRect, from, to, pairListToDraw); DrawStatRows(_baseWeaponStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out float rollingY); DrawRangedStatRows(pairListToDraw, startRect.ReplaceY(rollingY), from, to); Widgets.EndScrollView(); } else { DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidth, GenUI.ListSpacing), _generalItemStats, out _); Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect); Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect); DrawStatTableHeader(startRect, from, to, pairListToDraw); DrawStatRows(_generalItemStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out _); Widgets.EndScrollView(); } Text.Anchor = TextAnchor.UpperLeft; }
public override void Setup() { _groupSelector = new ThingGroupSelector(_thingDef); _groupSelector.Add(new SingleThingSelector(_thingDef)); _loadout.Add(_groupSelector); }