private void NextWeaponStorage(int increment)
        {
            List <Building_WeaponStorage> ws = WorldComp.GetWeaponStorages();

            if (this.weaponStorage == null)
            {
                this.weaponStorage = ws[(increment < 0) ? ws.Count - 1 : 0];
            }
            else
            {
                for (int i = 0; i < ws.Count; ++i)
                {
                    if (this.weaponStorage == ws[i])
                    {
                        i += increment;
                        if (i < 0)
                        {
                            this.weaponStorage = ws[ws.Count - 1];
                        }
                        else if (i >= ws.Count)
                        {
                            this.weaponStorage = ws[0];
                        }
                        else
                        {
                            this.weaponStorage = ws[i];
                        }
                        break;
                    }
                }
            }
            this.RebuildPossibleWeapons();
        }
Example #2
0
        /*private List<TabRecord> tabs = new List<TabRecord>();
         * private Tabs selectedTab = Tabs.WeaponStorage_General;
         *
         * private List<ThingDefCount> general = new List<ThingDefCount>();
         * private List<ThingDefCount> neolithic = new List<ThingDefCount>();
         * private List<ThingDefCount> grenades = new List<ThingDefCount>();
         * private List<ThingDefCount> rockets = new List<ThingDefCount>();
         * private List<ThingDefCount> shotguns = new List<ThingDefCount>();
         * private List<ThingDefCount> advanced = new List<ThingDefCount>();*/

        public AmmoUI(Building_WeaponStorage weaponStorage)
        {
            this.weaponStorage = weaponStorage;

            this.closeOnClickedOutside = true;
            this.doCloseButton         = true;
            this.doCloseX = true;
            this.absorbInputAroundWindow = true;
            this.forcePause = true;

            this.RebuildItems();
        }
        public AssignUI(Building_WeaponStorage weaponStorage, Pawn pawn = null)
        {
            this.weaponStorage = weaponStorage;

            this.PossibleWeapons = null;

            this.closeOnClickedOutside = true;
            this.doCloseButton         = true;
            this.doCloseX = true;
            this.absorbInputAroundWindow = true;
            this.forcePause = true;

            this.selectablePawns = Util.GetPawns(true);
            this.UpdatePawnIndex(pawn);
        }
Example #4
0
 public Dialog_Rename(Building_WeaponStorage weaponStorage) : base()
 {
     this.WeaponStorage = weaponStorage;
     base.curName       = weaponStorage.Name;
 }
Example #5
0
 private static void FindMatches(ref bool __result, Bill bill, List <ThingCount> chosen, Building_WeaponStorage ws, KeyValuePair <ThingDef, LinkedList <ThingWithComps> > kv)
 {
     if (bill.ingredientFilter.Allows(kv.Key))
     {
         foreach (ThingWithComps t in kv.Value)
         {
             if (bill.ingredientFilter.Allows(t) &&
                 t.HitPoints != t.MaxHitPoints)
             {
                 if (ws.Remove(t))
                 {
                     if (t.Spawned == false)
                     {
                         Log.Error("Failed to spawn weapon-to-mend [" + t.Label + "] from weapon storage [" + ws.Label + "].");
                         __result = false;
                     }
                     else
                     {
                         __result = true;
                         chosen.Add(new ThingCount(t, 1));
                     }
                 }
                 else
                 {
                     __result = false;
                 }
                 return;
             }
         }
     }
 }
        public override void DoWindowContents(Rect inRect)
        {
#if TRACE
            ++i;
#endif
            GUI.color = Color.white;
            Text.Font = GameFont.Small;
            try
            {
                float x = 0, y = 0;

                string label = "";
                if (Settings.EnableAssignWeapons)
                {
                    #region Assign To
                    Widgets.Label(new Rect(x, y + 4, 100, 30), "WeaponStorage.AssignTo".Translate());
                    x += 80;

                    if (this.selectablePawns.Count > 0 &&
                        GUI.Button(new Rect(x, y, 30, 30), previousTexture))
                    {
                        --this.pawnIndex;
                        if (this.pawnIndex < 0 || this.assignedWeapons == null)
                        {
                            this.pawnIndex = this.selectablePawns.Count - 1;
                        }
                        this.LoadAssignedWeapons();
                    }
                    x += 30;

                    label = (this.assignedWeapons != null) ? SelectablePawns.GetLabelAndStatsFor(this.assignedWeapons.Pawn) : "";
                    if (Widgets.ButtonText(new Rect(x, y, 400, 30), label))
                    {
                        List <FloatMenuOption> options = new List <FloatMenuOption>();
                        foreach (SelectablePawns p in this.selectablePawns)
                        {
                            options.Add(new FloatMenuOption(p.LabelAndStats, delegate
                            {
                                this.UpdatePawnIndex(p.Pawn);
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        }
                        Find.WindowStack.Add(new FloatMenu(options));
                    }
                    x += 400;

                    if (this.selectablePawns.Count > 0 &&
                        GUI.Button(new Rect(x, y, 30, 30), nextTexture))
                    {
                        ++this.pawnIndex;
                        if (this.pawnIndex >= this.selectablePawns.Count || this.assignedWeapons == null)
                        {
                            this.pawnIndex = 0;
                        }
                        this.LoadAssignedWeapons();
                    }
                    x += 40;
                    #endregion
                    y += 40;
                }

                #region Weapon Storage
                x = 0;
                Widgets.Label(new Rect(x, y - 4, 100, 60), "WeaponStorage".Translate());
                x += 80;

                if (WorldComp.HasStorages() &&
                    GUI.Button(new Rect(x, y, 30, 30), previousTexture))
                {
                    this.NextWeaponStorage(-1);
                }
                x += 30;

                label = (this.weaponStorage != null) ? this.weaponStorage.Label : "";
                if (Widgets.ButtonText(new Rect(x, y, 400, 30), label))
                {
                    List <FloatMenuOption> options = new List <FloatMenuOption>();
                    foreach (var ws in WorldComp.GetWeaponStorages())
                    {
                        options.Add(new FloatMenuOption(ws.Label, delegate
                        {
                            this.weaponStorage = ws;
                            this.RebuildPossibleWeapons();
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(options));
                }
                x += 400;

                if (WorldComp.HasStorages() &&
                    GUI.Button(new Rect(x, y, 30, 30), nextTexture))
                {
                    this.NextWeaponStorage(1);
                }
                x += 40;
                #endregion
                y += 40;

                Widgets.Label(new Rect(0, y + 4, 70, 30), "WeaponStorage.Search".Translate());
                this.textBuffer = Widgets.TextField(new Rect(80, y, 200, 30), this.textBuffer);
                y += 40;

                const int HEIGHT = 30;
                const int BUFFER = 2;
                float     width  = inRect.width - 100;
                scrollPosition = GUI.BeginScrollView(new Rect(40, y, width, inRect.height - y - 121), scrollPosition, new Rect(0, 0, width - 16, this.PreviousY));
                x = y = 0;
                if (this.PossibleWeapons != null)
                {
                    ThingWithComps weapon;
                    for (int i = 0; i < this.PossibleWeapons.Count; ++i)
                    {
                        x      = 0;
                        weapon = this.PossibleWeapons[i];
                        bool isChecked = false;

                        if (this.assignedWeapons != null && this.weaponStorage != null)
                        {
                            isChecked = this.IsAssignedWeapon(i);
                            if (!isChecked && !this.IncludeWeapon(weapon))
                            {
                                continue;
                            }

                            bool backup = isChecked;
                            Widgets.Checkbox(x, y, ref isChecked, 20);
                            x += 20 + BUFFER;
                            if (isChecked != backup)
                            {
                                if (this.IsAssignedWeapon(i))
                                {
                                    if (this.assignedWeapons.Pawn.equipment.Primary == weapon)
                                    {
                                        this.assignedWeapons.Pawn.equipment.Remove(weapon);
                                        if (this.assignedWeapons.Pawn.jobs.curJob.def == JobDefOf.Hunt)
                                        {
                                            this.assignedWeapons.Pawn.jobs.StopAll();
                                        }
                                    }
                                    if (this.assignedWeapons.Remove(weapon))
                                    {
                                        if (this.weaponStorage == null ||
                                            (!this.weaponStorage.AddWeapon(weapon) &&
                                             !WorldComp.Add(weapon)))
                                        {
                                            BuildingUtil.DropSingleThing(weapon, this.assignedWeapons.Pawn.Position, this.assignedWeapons.Pawn.Map);
                                        }
                                    }
                                    else
                                    {
                                        Log.Error("Unable to remove weapon " + weapon);
                                    }
                                }
                                else
                                {
                                    if (this.weaponStorage != null && this.weaponStorage.RemoveNoDrop(weapon))
                                    {
                                        this.assignedWeapons.Add(weapon);
                                    }
                                    else
                                    {
                                        Log.Error("Unable to remove weapon " + weapon);
                                    }
                                }
                                this.RebuildPossibleWeapons();
                                break;
                            }
                        }

                        if (!isChecked && !this.IncludeWeapon(weapon))
                        {
                            continue;
                        }

                        Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), weapon);
                        x += HEIGHT + BUFFER;

                        if (Widgets.InfoCardButton(x, y, weapon))
                        {
                            Find.WindowStack.Add(new Dialog_InfoCard(weapon));
                        }
                        x += HEIGHT + BUFFER;

                        Widgets.Label(new Rect(x, y, 250, HEIGHT), weapon.Label);
                        x += 250 + BUFFER;

                        if (this.weaponStorage != null &&
                            Widgets.ButtonImage(new Rect(width - 16 - HEIGHT, y, 20, 20), DropTexture))
                        {
                            if (this.IsAssignedWeapon(i))
                            {
                                if (!this.assignedWeapons.Remove(weapon))
                                {
                                    Log.Error("Unable to drop assigned weapon");
                                }
                            }
                            else
                            {
                                if (this.weaponStorage == null || !this.weaponStorage.Remove(weapon))
                                {
                                    Log.Error("Unable to remove weapon " + weapon);
                                }
                            }
                            this.RebuildPossibleWeapons();
                            break;
                        }

                        var biocodableComp = weapon.GetComp <CompBiocodable>();
                        if (biocodableComp?.CodedPawn != null)
                        {
                            y += HEIGHT - 4;
                            Widgets.Label(new Rect(x - 250 - BUFFER, y, 250, 20), biocodableComp.CompInspectStringExtra());
                            y += 4;
                        }

                        this.PossibleWeapons[i] = weapon;
                        y += HEIGHT + BUFFER;
                    }
                }
                else
                {
#if TRACE
                    if (i > 600)
                    {
                        Log.Warning("WeaponStorage DoWindowContents: Display non-checkbox weapons. Count: " + this.weaponStorage.Count);
                    }
#endif
                    if (this.weaponStorage != null)
                    {
                        foreach (ThingWithComps t in this.weaponStorage.GetWeapons(false))
                        {
#if TRACE
                            if (i > 600)
                            {
                                Log.Warning("-" + t.Label);
                            }
#endif
                            //if (!IncludeWeapon(t))
                            //    continue;

                            if (!this.IncludeWeapon(t))
                            {
                                continue;
                            }

                            x = 34;
                            Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), t);
                            x += HEIGHT + BUFFER;

                            if (Widgets.InfoCardButton(x, y, t))
                            {
                                Find.WindowStack.Add(new Dialog_InfoCard(t));
                            }
                            x += HEIGHT + BUFFER;

                            Widgets.Label(new Rect(x, y, 250, HEIGHT), t.Label);
                            x += 250 + BUFFER;

                            if (Widgets.ButtonImage(new Rect(x + 100, y, 20, 20), DropTexture))
                            {
                                this.weaponStorage.Remove(t);
                                break;
                            }
                            y += HEIGHT + BUFFER;
                        }

                        foreach (ThingWithComps t in this.weaponStorage.GetBioEncodedWeapons())
                        {
#if TRACE
                            if (i > 600)
                            {
                                Log.Warning("-" + t.Label);
                            }
#endif
                            //if (!IncludeWeapon(t))
                            //    continue;

                            x = 34;
                            Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), t);
                            x += HEIGHT + BUFFER;

                            if (Widgets.InfoCardButton(x, y, t))
                            {
                                Find.WindowStack.Add(new Dialog_InfoCard(t));
                            }
                            x += HEIGHT + BUFFER;

                            Widgets.Label(new Rect(x, y, 250, HEIGHT), t.Label);
                            x += 250 + BUFFER;

                            if (Widgets.ButtonImage(new Rect(x + 100, y, 20, 20), DropTexture))
                            {
                                this.weaponStorage.Remove(t);
                                break;
                            }

                            var biocodableComp = t.GetComp <CompBiocodable>();
                            if (biocodableComp?.CodedPawn != null)
                            {
                                y += HEIGHT - 4;
                                Widgets.Label(new Rect(x - 250 - BUFFER, y, 250, 20), biocodableComp.CompInspectStringExtra());
                                y += 4;
                            }

                            y += HEIGHT + BUFFER;
                        }
                    }
                }

                GUI.EndScrollView();
                this.PreviousY = y;
            }
            catch (Exception e)
            {
                String msg = this.GetType().Name + " closed due to: " + e.GetType().Name + " " + e.Message;
                Log.Error(msg);
                Messages.Message(msg, MessageTypeDefOf.NegativeEvent);
                base.Close();
            }
            finally
            {
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
        }