private void DrawSlotSelection(Rect canvas) { GUI.DrawTexture(canvas, _darkBackground); if (_source.NullOrEmpty()) { return; } Rect viewRect = new Rect(canvas); viewRect.width -= 16f; viewRect.height = _source.Count * _rowHeight; Widgets.BeginScrollView(canvas, ref _availableScrollPosition, viewRect.AtZero()); int startRow = (int)Math.Floor((decimal)(_availableScrollPosition.y / _rowHeight)); startRow = (startRow < 0) ? 0 : startRow; int endRow = startRow + (int)(Math.Ceiling((decimal)(canvas.height / _rowHeight))); endRow = (endRow > _source.Count) ? _source.Count : endRow; for (int i = startRow; i < endRow; i++) { // gray out weapons not in stock Color baseColor = GUI.color; if (Find.VisibleMap.listerThings.AllThings.FindAll(x => x.def == _source[i]).Count <= 0) { GUI.color = Color.gray; } Rect row = new Rect(0f, i * _rowHeight, canvas.width, _rowHeight); Rect labelRect = new Rect(row); TooltipHandler.TipRegion(row, _source[i].GetWeightAndBulkTip()); labelRect.xMin += _margin; if (i % 2 == 0) { GUI.DrawTexture(row, _darkBackground); } Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(labelRect, _source[i].LabelCap); Text.Anchor = TextAnchor.UpperLeft; Widgets.DrawHighlightIfMouseover(row); if (Widgets.ButtonInvisible(row)) { LoadoutSlot slot = new LoadoutSlot(_source[i], 1); CurrentLoadout.AddSlot(slot); } // revert to original color GUI.color = baseColor; } Widgets.EndScrollView(); }
private void DrawSlotSelection(Rect canvas) { GUI.DrawTexture(canvas, _darkBackground); if (_source.NullOrEmpty()) { return; } Rect viewRect = new Rect(canvas); viewRect.width -= 16f; viewRect.height = _source.Count * _rowHeight; Widgets.BeginScrollView(canvas, ref _availableScrollPosition, viewRect.AtZero()); for (int i = 0; i < _source.Count; i++) { Rect row = new Rect(0f, i * _rowHeight, canvas.width, _rowHeight); Rect labelRect = new Rect(row); TooltipHandler.TipRegion(row, _source[i].GetWeightAndBulkTip()); labelRect.xMin += _margin; if (i % 2 == 0) { GUI.DrawTexture(row, _darkBackground); } Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(labelRect, _source[i].LabelCap); Text.Anchor = TextAnchor.UpperLeft; Widgets.DrawHighlightIfMouseover(row); if (Widgets.ButtonInvisible(row)) { var slot = new LoadoutSlot(_source[i], 1); CurrentLoadout.AddSlot(slot); } } Widgets.EndScrollView(); }
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()); }
private void DrawSlotSelection(Rect canvas) { int count = _sourceType == SourceSelection.Generic ? _sourceGeneric.Count : _source.Count; GUI.DrawTexture(canvas, _darkBackground); if ((_sourceType != SourceSelection.Generic && _source.NullOrEmpty()) || (_sourceType == SourceSelection.Generic && _sourceGeneric.NullOrEmpty())) { return; } Rect viewRect = new Rect(canvas); viewRect.width -= 16f; viewRect.height = count * _rowHeight; Widgets.BeginScrollView(canvas, ref _availableScrollPosition, viewRect.AtZero()); int startRow = (int)Math.Floor((decimal)(_availableScrollPosition.y / _rowHeight)); startRow = (startRow < 0) ? 0 : startRow; int endRow = startRow + (int)(Math.Ceiling((decimal)(canvas.height / _rowHeight))); endRow = (endRow > count) ? count : endRow; for (int i = startRow; i < endRow; i++) { // gray out weapons not in stock Color baseColor = GUI.color; if (_sourceType == SourceSelection.Generic) { if (GetVisibleGeneric(_sourceGeneric[i])) { GUI.color = Color.gray; } } else { if (_source[i].isGreyedOut) { GUI.color = Color.gray; } } Rect row = new Rect(0f, i * _rowHeight, canvas.width, _rowHeight); Rect labelRect = new Rect(row); if (_sourceType == SourceSelection.Generic) { TooltipHandler.TipRegion(row, _sourceGeneric[i].GetWeightAndBulkTip()); } else { TooltipHandler.TipRegion(row, _source[i].thingDef.GetWeightAndBulkTip()); } labelRect.xMin += _margin; if (i % 2 == 0) { GUI.DrawTexture(row, _darkBackground); } Text.Anchor = TextAnchor.MiddleLeft; Text.WordWrap = false; if (_sourceType == SourceSelection.Generic) { Widgets.Label(labelRect, _sourceGeneric[i].LabelCap); } else { Widgets.Label(labelRect, _source[i].thingDef.LabelCap); } Text.WordWrap = true; Text.Anchor = TextAnchor.UpperLeft; Widgets.DrawHighlightIfMouseover(row); if (Widgets.ButtonInvisible(row)) { LoadoutSlot slot; if (_sourceType == SourceSelection.Generic) { slot = new LoadoutSlot(_sourceGeneric[i]); } else { slot = new LoadoutSlot(_source[i].thingDef); } CurrentLoadout.AddSlot(slot); } // revert to original color GUI.color = baseColor; } Widgets.EndScrollView(); }