private void DrawSlot(Rect row, LoadoutSlot slot, bool slotDraggable = true) { // set up rects // dragging handle (square) | label (fill) | count (50px) | delete (iconSize) Rect draggingHandle = new Rect(row); draggingHandle.width = row.height; Rect labelRect = new Rect(row); if (slotDraggable) { labelRect.xMin = draggingHandle.xMax; } labelRect.xMax = row.xMax - _countFieldSize.x - _iconSize - 2 * _margin; Rect countRect = new Rect( row.xMax - _countFieldSize.x - _iconSize - 2 * _margin, row.yMin + (row.height - _countFieldSize.y) / 2f, _countFieldSize.x, _countFieldSize.y); Rect ammoRect = new Rect( countRect.xMin - _iconSize - _margin, row.yMin + (row.height - _iconSize) / 2f, _iconSize, _iconSize); Rect countModeRect = new Rect( ammoRect.xMin - _iconSize - _margin, row.yMin + (row.height - _iconSize) / 2f, _iconSize, _iconSize); Rect deleteRect = new Rect(countRect.xMax + _margin, row.yMin + (row.height - _iconSize) / 2f, _iconSize, _iconSize); // dragging on dragHandle if (slotDraggable) { TooltipHandler.TipRegion(draggingHandle, "CE_DragToReorder".Translate()); GUI.DrawTexture(draggingHandle, _iconMove); if (Mouse.IsOver(draggingHandle) && Input.GetMouseButtonDown(0)) { Dragging = slot; } } // interactions (main row rect) if (!Mouse.IsOver(deleteRect)) { Widgets.DrawHighlightIfMouseover(row); TooltipHandler.TipRegion(row, slot.genericDef != null ? slot.genericDef.GetWeightAndBulkTip(slot.count) : slot.thingDef.GetWeightAndBulkTip(slot.count)); } // label Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(labelRect, slot.LabelCap); Text.Anchor = TextAnchor.UpperLeft; // easy ammo adder, ranged weapons only if (slot.thingDef != null && slot.thingDef.IsRangedWeapon) { // make sure there's an ammoset defined AmmoSetDef ammoSet = ((slot.thingDef.GetCompProperties <CompProperties_AmmoUser>() == null) ? null : slot.thingDef.GetCompProperties <CompProperties_AmmoUser>().ammoSet); bool?temp = !((((ammoSet == null) ? null : ammoSet.ammoTypes)).NullOrEmpty()); if (temp ?? false) { if (Widgets.ButtonImage(ammoRect, _iconAmmoAdd)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); int magazineSize = (slot.thingDef.GetCompProperties <CompProperties_AmmoUser>() == null) ? 0 : slot.thingDef.GetCompProperties <CompProperties_AmmoUser>().magazineSize; foreach (AmmoLink link in ((ammoSet == null) ? null : ammoSet.ammoTypes)) { options.Add(new FloatMenuOption(link.ammo.LabelCap, delegate { CurrentLoadout.AddSlot(new LoadoutSlot(link.ammo, (magazineSize <= 1 ? link.ammo.defaultAmmoCount : magazineSize))); })); } // Add in the generic for this gun. LoadoutGenericDef generic = DefDatabase <LoadoutGenericDef> .GetNamed("GenericAmmo-" + slot.thingDef.defName); if (generic != null) { options.Add(new FloatMenuOption(generic.LabelCap, delegate { CurrentLoadout.AddSlot(new LoadoutSlot(generic)); })); } Find.WindowStack.Add(new FloatMenu(options, "CE_AddAmmoFor".Translate(slot.thingDef.LabelCap))); } } } // count DrawCountField(countRect, slot); // toggle count mode if (slot.genericDef != null) { Texture2D curModeIcon = slot.countType == LoadoutCountType.dropExcess ? _iconDropExcess : _iconPickupDrop; string tipString = slot.countType == LoadoutCountType.dropExcess ? "Drop Excess" : "Pickup Missing and Drop Excess"; if (Widgets.ButtonImage(countModeRect, curModeIcon)) { slot.countType = slot.countType == LoadoutCountType.dropExcess ? LoadoutCountType.pickupDrop : LoadoutCountType.dropExcess; } TooltipHandler.TipRegion(countModeRect, tipString); } // delete if (Mouse.IsOver(deleteRect)) { GUI.DrawTexture(row, TexUI.HighlightTex); } if (Widgets.ButtonImage(deleteRect, _iconClear)) { CurrentLoadout.RemoveSlot(slot); } TooltipHandler.TipRegion(deleteRect, "CE_DeleteFilter".Translate()); }
private void DrawSlot(Rect row, LoadoutSlot slot, bool slotDraggable = true) { // set up rects // dragging handle (square) | label (fill) | count (50px) | delete (iconSize) Rect draggingHandle = new Rect(row); draggingHandle.width = row.height; Rect labelRect = new Rect(row); if (slotDraggable) { labelRect.xMin = draggingHandle.xMax; } labelRect.xMax = row.xMax - _countFieldSize.x - _iconSize - 2 * _margin; Rect countRect = new Rect( row.xMax - _countFieldSize.x - _iconSize - 2 * _margin, row.yMin + (row.height - _countFieldSize.y) / 2f, _countFieldSize.x, _countFieldSize.y); Rect ammoRect = new Rect( countRect.xMin - _iconSize - _margin, row.yMin + (row.height - _iconSize) / 2f, _iconSize, _iconSize); Rect deleteRect = new Rect(countRect.xMax + _margin, row.yMin + (row.height - _iconSize) / 2f, _iconSize, _iconSize); // dragging on dragHandle if (slotDraggable) { TooltipHandler.TipRegion(draggingHandle, "CR.DragToReorder".Translate()); GUI.DrawTexture(draggingHandle, _iconMove); if (Mouse.IsOver(draggingHandle) && Input.GetMouseButtonDown(0)) { Dragging = slot; } } // interactions (main row rect) if (!Mouse.IsOver(deleteRect)) { Widgets.DrawHighlightIfMouseover(row); TooltipHandler.TipRegion(row, slot.Def.GetWeightAndBulkTip(slot.Count)); } // label Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(labelRect, slot.Def.LabelCap); Text.Anchor = TextAnchor.UpperLeft; // easy ammo adder, ranged weapons only if (slot.Def.IsRangedWeapon) { // make sure there's an ammoset defined AmmoSetDef ammoSet = ((slot.Def.GetCompProperties <CompProperties_AmmoUser>() == null) ? null : slot.Def.GetCompProperties <CompProperties_AmmoUser>().ammoSet); bool?temp = !((((ammoSet == null) ? null : ammoSet.ammoTypes)).NullOrEmpty()); if (temp ?? false) { if (Widgets.ButtonImage(ammoRect, _iconAmmoAdd)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (var ammo in ((ammoSet == null) ? null : ammoSet.ammoTypes)) { options.Add(new FloatMenuOption(ammo.LabelCap, delegate { CurrentLoadout.AddSlot(new LoadoutSlot(ammo)); })); } Find.WindowStack.Add(new FloatMenu(options, "CR.AddAmmoFor".Translate(slot.Def.LabelCap))); } } } // count DrawCountField(countRect, slot); // delete if (Mouse.IsOver(deleteRect)) { GUI.DrawTexture(row, TexUI.HighlightTex); } if (Widgets.ButtonImage(deleteRect, _iconClear)) { CurrentLoadout.RemoveSlot(slot); } TooltipHandler.TipRegion(deleteRect, "CR.DeleteFilter".Translate()); }