public StorageGroupUI(StoredApparelSet set, ApparelFromEnum apparelFrom, Building_Dresser dresser, Pawn pawn, bool isNew, bool fromGizmo = false)
        {
            this.set         = set;
            this.ApparelFrom = apparelFrom;
            this.Dresser     = dresser;
            this.Pawn        = pawn;
            this.IsNew       = isNew;
            this.FromGizmo   = fromGizmo;
            if (this.FromGizmo)
            {
                if (this.set.HasOwner)
                {
                    this.isRestricted = true;
                }

                this.PlayerPawns = new List <Pawn>();
                foreach (Pawn p in PawnsFinder.AllMaps_SpawnedPawnsInFaction(Faction.OfPlayer))
                {
                    if (p.def.defName.Equals("Human"))
                    {
                        this.PlayerPawns.Add(p);
                    }
                }
            }

            this.closeOnEscapeKey        = false;
            this.doCloseButton           = false;
            this.doCloseX                = false;
            this.absorbInputAroundWindow = true;
            this.forcePause              = true;
        }
Ejemplo n.º 2
0
        private List <StoredApparelSet> GetStoredApparelSetsFromStorageGroupDTOs()
        {
            List <StoredApparelSet> storedApparelSets = new List <StoredApparelSet>();

            if (groups != null && groups.Count > 0)
            {
                foreach (StorageGroupDTO group in groups)
                {
                    StoredApparelSet set = new StoredApparelSet(this, group.restrictToPawnId, group.isBeingWornById);
                    set.SetApparel(group.apparelList);
                    if (group.apparelList.Count == group.forcedApparel.Count)
                    {
                        List <string> forcedApparelIds = new List <string>();
                        for (int i = 0; i < forcedApparelIds.Count; ++i)
                        {
                            if (group.forcedApparel[i])
                            {
                                forcedApparelIds.Add(group.apparelList[i].ThingID);
                            }
                        }
                        set.SetForcedApparel(forcedApparelIds);
                    }
                    set.Name            = group.name;
                    set.SwitchForBattle = group.forceSwitchBattle;
                    storedApparelSets.Add(set);
                }
            }
            return(storedApparelSets);
        }
Ejemplo n.º 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedOrNull(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Building_Dresser dresser = (Building_Dresser)base.CurJob.targetA;
                    string apparelGroupName = ((SwapApparelJob)base.CurJob).ApparelGroupName;
                    Pawn pawn = this.GetActor();

                    StoredApparelSet setToGet = null;

                    IEnumerable <StoredApparelSet> sets;
                    if (Settings.LinkGroupsToDresser)
                    {
                        sets = StoredApparelContainer.GetApparelSets(dresser);
                    }
                    else
                    {
                        sets = StoredApparelContainer.GetAllApparelSets();
                    }

                    foreach (StoredApparelSet set in sets)
                    {
                        if (set.IsOwnedBy(pawn) && set.Name.Equals(apparelGroupName))
                        {
                            setToGet = set;
                            break;
                        }
                    }
                    if (setToGet == null)
                    {
                        Messages.Message(pawn.Name.ToStringShort + " " + "ChangeDresser.UnableToWearApparelGroup".Translate() + " " + apparelGroupName + ".", MessageSound.Negative);
                    }
                    else
                    {
                        setToGet.SwapApparel(pawn);
                    }
                }
            });

            yield break;
        }
Ejemplo n.º 4
0
        public override void DoWindowContents(Rect inRect)
        {
            try
            {
                Text.Font   = GameFont.Medium;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(new Rect(0, 0, 200, 50), "ChangeDresser.ApparelStorageLabel".Translate());

                Text.Font = GameFont.Small;
                if (Widgets.ButtonText(new Rect(inRect.width * 0.5f, 10, 200, 30), "ChangeDresser.ApparelGroup".Translate()))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    if (!this.FromGizmo)
                    {
                        list.Add(new FloatMenuOption("ChangeDresser.CreateFromWorn".Translate(), delegate
                        {
                            StoredApparelSet set = new StoredApparelSet(this.Dresser);
                            Find.WindowStack.Add(new StorageGroupUI(set, ApparelFromEnum.Pawn, this.Dresser, this.Pawn, true, this.FromGizmo));
                        }));
                    }
                    list.Add(new FloatMenuOption("ChangeDresser.CreateFromStorage".Translate(), delegate
                    {
                        StoredApparelSet set = new StoredApparelSet(this.Dresser);
                        Find.WindowStack.Add(new StorageGroupUI(set, ApparelFromEnum.Storage, this.Dresser, this.Pawn, true, this.FromGizmo));
                    }));

                    if (this.FromGizmo)
                    {
                        this.CreateOptionsForUser(list);
                    }
                    else
                    {
                        this.CreateOptionsForPawn(list);
                    }
                    Find.WindowStack.Add(new FloatMenu(list, null, false));
                }

                /*if (this.storageGroupDto.IsPawnRestricted)
                 * {
                 *  Widgets.Label(new Rect(250, 0, 200, 50), "Owner: " + this.storageGroupDto.RestrictToPawnName);
                 * }
                 *
                 * Rect rect = new Rect(0, 50, inRect.width, 30);
                 * Text.Font = GameFont.Small;
                 * GUI.BeginGroup(rect);
                 * GUI.Label(new Rect(0, 0, 100, rect.height), "Group Name:", WidgetUtil.MiddleCenter);
                 * this.storageGroupDto.GroupName = Widgets.TextField(new Rect(110, 0, 150, rect.height), this.storageGroupDto.GroupName);
                 *
                 * GUI.Label(new Rect(280, 0, 100, rect.height), "Restrict to Pawn:", WidgetUtil.MiddleCenter);
                 * this.storageGroupDto.IsPawnRestricted = GUI.Toggle(new Rect(390, 7, rect.height, rect.height), this.storageGroupDto.IsPawnRestricted, "");
                 *
                 * GUI.Label(new Rect(440, 0, 150, rect.height), "Force Switch Combat:", WidgetUtil.MiddleCenter);
                 * this.storageGroupDto.ForceSwitchBattle = GUI.Toggle(new Rect(600, 7, rect.height, rect.height), this.storageGroupDto.ForceSwitchBattle, "");
                 * GUI.EndGroup();*/

                List <Apparel> wornApparel   = (!this.FromGizmo) ? this.Pawn.apparel.WornApparel : null;
                List <Apparel> storedApparel = this.Dresser.StoredApparel;

                const float cellHeight       = 40f;
                float       apparelListWidth = inRect.width * 0.5f - 10f;
                Rect        apparelListRect;
                Rect        apparelScrollRect;

                if (!this.FromGizmo)
                {
                    apparelListRect   = new Rect(0, 90, apparelListWidth, inRect.height - 130);
                    apparelScrollRect = new Rect(0f, 0f, apparelListWidth - 16f, wornApparel.Count * cellHeight);

                    GUI.BeginGroup(apparelListRect);
                    this.scrollPosLeft = GUI.BeginScrollView(new Rect(GenUI.AtZero(apparelListRect)), this.scrollPosLeft, apparelScrollRect);

                    GUI.color = Color.white;
                    Text.Font = GameFont.Medium;
                    for (int i = 0; i < wornApparel.Count; ++i)
                    {
                        Apparel apparel = wornApparel[i];
                        Rect    rowRect = new Rect(0, 2f + i * cellHeight, apparelListRect.width, cellHeight);
                        GUI.BeginGroup(rowRect);

                        Widgets.ThingIcon(new Rect(0f, 0f, cellHeight, cellHeight), apparel);

                        Text.Font = GameFont.Small;
                        Widgets.Label(new Rect(cellHeight + 5f, 0f, rowRect.width - 40f - cellHeight, cellHeight), apparel.Label);

                        GUI.color = Color.white;
                        if (Widgets.ButtonImage(new Rect(rowRect.width - 35f, 10, 20, 20), WidgetUtil.nextTexture))
                        {
                            this.Pawn.apparel.Remove(apparel);
                            storedApparel.Add(apparel);
                            GUI.EndGroup();
                            break;
                        }
                        GUI.EndGroup();
                    }
                    GUI.EndScrollView();
                    GUI.EndGroup();
                }

                apparelListRect   = new Rect(inRect.width - apparelListWidth, 90, apparelListWidth, inRect.height - 130);
                apparelScrollRect = new Rect(0f, 0f, apparelListWidth - 16f, storedApparel.Count * cellHeight);

                GUI.BeginGroup(apparelListRect);
                this.scrollPosRight = GUI.BeginScrollView(new Rect(GenUI.AtZero(apparelListRect)), this.scrollPosRight, apparelScrollRect);

                GUI.color = Color.white;
                Text.Font = GameFont.Medium;
                for (int i = 0; i < storedApparel.Count; ++i)
                {
                    Apparel apparel = storedApparel[i];
                    Rect    rowRect = new Rect(0, 2f + i * cellHeight, apparelScrollRect.width, cellHeight);
                    GUI.BeginGroup(rowRect);

                    if (!this.FromGizmo)
                    {
                        Rect buttonRect = new Rect(5, 10, 20, 20);
                        bool canWear    = this.Pawn.apparel.CanWearWithoutDroppingAnything(apparel.def);
                        if (canWear)
                        {
                            if (Widgets.ButtonImage(buttonRect, WidgetUtil.previousTexture))
                            {
                                storedApparel.Remove(apparel);
                                this.Pawn.apparel.Wear(apparel);
                                GUI.EndGroup();
                                break;
                            }
                        }
                        else
                        {
                            Widgets.ButtonImage(buttonRect, WidgetUtil.cantTexture);
                        }
                    }

                    Widgets.ThingIcon(new Rect(35f, 0f, cellHeight, cellHeight), apparel);
                    Text.Font   = GameFont.Small;
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(new Rect(cellHeight + 45f, 0f, rowRect.width - cellHeight - 90f, cellHeight), apparel.Label);

                    if (Widgets.ButtonImage(new Rect(rowRect.width - 45f, 0f, cellHeight, cellHeight), WidgetUtil.dropTexture))
                    {
                        this.Dresser.Remove(apparel, false);
                        GUI.EndGroup();
                        break;
                    }

                    GUI.EndGroup();
                }
                GUI.EndScrollView();

                GUI.EndGroup();
            }
            catch (Exception e)
            {
                Log.Error(this.GetType().Name + " closed due to: " + e.GetType().Name + " " + e.Message);
                Messages.Message(this.GetType().Name + " closed due to: " + e.GetType().Name + " " + e.Message, MessageSound.Negative);
                base.Close();
            }
            finally
            {
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
        }
 public void Remove(StoredApparelSet set)
 {
     StoredApparelContainer.RemoveApparelSet(set);
 }