Exemplo n.º 1
0
 public static bool IsAmmoSystemActive(AmmoSetDef ammoSet)
 {
     if (Controller.settings.EnableAmmoSystem)
     {
         return(true);
     }
     return(ammoSet != null && ammoSet.isMortarAmmoSet);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Process and check if this ammoSet is for a AOE weapons
 /// </summary>
 /// <param name="def">AmmoSetDef</param>
 private static void ProcessAmmo(AmmoSetDef def)
 {
     /*
      * Check is it's a mortar projectile then check if detonateProjectile is not null
      * This should cover most types of AOE ammo
      */
     isAOEArray[def.index] = def.isMortarAmmoSet || (def.ammoTypes?.Any(a => IsAOEAmmoLink(a)) ?? false);
 }
Exemplo n.º 3
0
        public override bool ShouldShowFor(StatRequest req)
        {
            if (!base.ShouldShowFor(req))
            {
                return(false);
            }

            AmmoSetDef ammoSet = GunDef(req)?.GetCompProperties <CompProperties_AmmoUser>()?.ammoSet;

            if (ShouldDisplayAmmoSet(ammoSet))
            {
                return(true);
            }
            else
            {
                return(GunDef(req)?.Verbs?.Any(x => x.defaultProjectile != null) ?? false);
            }
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
 private bool ShouldDisplayAmmoSet(AmmoSetDef ammoSet)
 {
     return(ammoSet != null && AmmoUtility.IsAmmoSystemActive(ammoSet));
 }
Exemplo n.º 6
0
        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, "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.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 (ThingDef 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, "CE_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, "CE_DeleteFilter".Translate());
        }