Exemplo n.º 1
0
        public override GizmoResult GizmoOnGUI(UnityEngine.Vector2 topLeft)
        {
            Rect overRect = new Rect(topLeft.x, topLeft.y, curWidth, Height);

            Widgets.DrawWindowBackground(overRect);

            //Equipment slot
            Pawn           wearer = backpack.wearer;
            ThingWithComps dummy;

            Rect thingIconRect = new Rect(topLeft.x, topLeft.y, widthPerItem, Height / 2);
            int  numOfCurItem  = 0;

            List <Thing> things = wearer.inventory.container.ToList();

            //Draw Gizmo
            for (int i = 0; i < numOfMaxItemsPerRow * numOfRow; i++)
            {
                if (i >= backpack.MaxItem)
                {
                    thingIconRect.x = topLeft.x + widthPerItem * (i % numOfMaxItemsPerRow);
                    thingIconRect.y = topLeft.y + (Height / 2) * (i / numOfMaxItemsPerRow);
                    Widgets.DrawTextureFitted(thingIconRect, NoAvailableTex, 1.0f);
                    continue;
                }

                if (i >= things.Count)
                {
                    thingIconRect.x = topLeft.x + widthPerItem * (i % numOfMaxItemsPerRow);
                    thingIconRect.y = topLeft.y + (Height / 2) * (i / numOfMaxItemsPerRow);
                    Widgets.DrawTextureFitted(thingIconRect, EmptyTex, 1.0f);
                    continue;
                }

                Thing item = things[i];
                Widgets.DrawBox(thingIconRect, 1);
                Widgets.ThingIcon(thingIconRect, item);
                if (thingIconRect.Contains(Event.current.mousePosition))
                {
                    Widgets.DrawTextureFitted(thingIconRect, FilledTex, 1.0f);
                }
                //Interaction with item
                if (Widgets.InvisibleButton(thingIconRect))
                {
                    thingIconSound = SoundDefOf.Click;
                    if (Event.current.button == 0)
                    {
                        //Weapon
                        if (item.def.equipmentType == EquipmentType.Primary)
                        {
                            if (wearer.equipment.Primary != null)
                            {
                                wearer.equipment.TryTransferEquipmentToContainer(wearer.equipment.Primary, wearer.inventory.container, out dummy);
                            }
                            else
                            {
                                backpack.numOfSavedItems--;
                            }
                            wearer.equipment.AddEquipment(item as ThingWithComps);
                            wearer.inventory.container.Remove(item as ThingWithComps);
                            if (wearer.jobs.curJob != null)
                            {
                                wearer.jobs.EndCurrentJob(JobCondition.InterruptForced);
                            }
                        }
                        //Medicine
                        else if (item.def.thingCategories.Contains(medicine))
                        {
                            if (wearer.workSettings.WorkIsActive(WorkTypeDefOf.Doctor))
                            {
                                Designator_ApplyMedicine designator = new Designator_ApplyMedicine();
                                designator.medicine      = item;
                                designator.doctor        = wearer;
                                designator.icon          = item.def.uiIcon;
                                designator.activateSound = SoundDef.Named("Click");

                                DesignatorManager.Select(designator);
                            }
                            else
                            {
                                Messages.Message(txtNoDoctor.Translate(), MessageSound.RejectInput);
                                Messages.Update();
                                thingIconSound = SoundDefOf.ClickReject;
                            }
                        }
                        //Food
                        else if (item.def.thingCategories.Contains(foodMeals))
                        {
                            if (wearer.needs.food.CurCategory != HungerCategory.Fed)
                            {
                                Job jobNew = new Job(JobDefOf.Ingest, item);
                                jobNew.maxNumToCarry   = 1;
                                jobNew.ignoreForbidden = true;
                                wearer.drafter.TakeOrderedJob(jobNew);
                            }
                            else
                            {
                                Messages.Message(txtCannotEatAnymore.Translate(), MessageSound.RejectInput);
                                Messages.Update();
                                thingIconSound = SoundDefOf.ClickReject;
                            }
                        }
                        //Apparel
                        else if (item is Apparel)
                        {
                            //if (!wearer.apparel.CanWearWithoutDroppingAnything(item.def))
                            //    wearer.apparel.WornApparel.Find(apparel => apparel.def.apparel.layers.Any);
                            for (int index = wearer.apparel.WornApparel.Count - 1; index >= 0; --index)
                            {
                                Apparel ap = wearer.apparel.WornApparel[index];
                                if (!ApparelUtility.CanWearTogether(item.def, ap.def))
                                {
                                    Apparel resultingAp;
                                    wearer.apparel.TryDrop(ap, out resultingAp, wearer.Position, false);
                                    wearer.inventory.container.TryAdd(resultingAp);
                                    backpack.numOfSavedItems++;
                                }
                            }
                            wearer.apparel.Wear(item as Apparel);
                            wearer.inventory.container.Remove(item as ThingWithComps);
                            backpack.numOfSavedItems--;
                        }

                        else
                        {
                            //Add another type of item you want to interact
                        }
                    }
                    else if (Event.current.button == 1)
                    {
                        List <FloatMenuOption> options = new List <FloatMenuOption>();
                        options.Add(new FloatMenuOption(txtThingInfo, () =>
                        {
                            Find.WindowStack.Add((Window) new Dialog_InfoCard(item));
                        }));
                        options.Add(new FloatMenuOption(txtDropThing, () =>
                        {
                            Thing dummy1;
                            wearer.inventory.container.TryDrop(item, wearer.Position, ThingPlaceMode.Near, out dummy1);
                        }));

                        Find.WindowStack.Add((Window) new FloatMenu(options, item.LabelCap, false, false));
                    }

                    SoundStarter.PlayOneShotOnCamera(thingIconSound);
                }

                numOfCurItem++;
                thingIconRect.x = topLeft.x + widthPerItem * (numOfCurItem % numOfMaxItemsPerRow);
                thingIconRect.y = topLeft.y + (Height / 2) * (numOfCurItem / numOfMaxItemsPerRow);
            }

            if (numOfCurItem == 0)
            {
                Rect textRect = new Rect(topLeft.x + Width / 2 - textWidth / 2, topLeft.y + Height / 2 - textHeight / 2, textWidth, textHeight);
                Widgets.Label(textRect, txtNoItem.Translate());
            }
            return(new GizmoResult(GizmoState.Clear));
        }
        public override GizmoResult GizmoOnGUI(UnityEngine.Vector2 topLeft)
        {
            Rect overRect = new Rect(topLeft.x, topLeft.y, curWidth, Height);
            Widgets.DrawWindowBackground(overRect);

            //Equipment slot
            Pawn wearer = backpack.wearer;
            ThingWithComps dummy;

            Rect thingIconRect = new Rect(topLeft.x, topLeft.y, widthPerItem, Height / 2);
            int numOfCurItem = 0;

            List<Thing> things = wearer.inventory.container.ToList();

            //Draw Gizmo
            for (int i = 0;i < numOfMaxItemsPerRow * numOfRow; i++)
            {
                if ( i >= backpack.MaxItem )
                {
                    thingIconRect.x = topLeft.x + widthPerItem * (i % numOfMaxItemsPerRow);
                    thingIconRect.y = topLeft.y + (Height / 2) * (i / numOfMaxItemsPerRow);
                    Widgets.DrawTextureFitted(thingIconRect, NoAvailableTex, 1.0f);
                    continue;
                }

                if (i >= things.Count)
                {
                    thingIconRect.x = topLeft.x + widthPerItem * (i % numOfMaxItemsPerRow);
                    thingIconRect.y = topLeft.y + (Height / 2) * (i / numOfMaxItemsPerRow);
                    Widgets.DrawTextureFitted(thingIconRect, EmptyTex, 1.0f);
                    continue;
                }

                Thing item = things[i];
                Widgets.DrawBox(thingIconRect, 1);
                Widgets.ThingIcon(thingIconRect, item);
                if (thingIconRect.Contains(Event.current.mousePosition))
                {
                    Widgets.DrawTextureFitted(thingIconRect, FilledTex, 1.0f);
                }
                //Interaction with item
                if (Widgets.InvisibleButton(thingIconRect))
                {
                    thingIconSound = SoundDefOf.Click;
                    if (Event.current.button == 0)
                    {
                        //Weapon
                        if (item.def.equipmentType == EquipmentType.Primary)
                        {
                            if (wearer.equipment.Primary != null)
                                wearer.equipment.TryTransferEquipmentToContainer(wearer.equipment.Primary, wearer.inventory.container, out dummy);
                            else
                                backpack.numOfSavedItems--;
                            wearer.equipment.AddEquipment(item as ThingWithComps);
                            wearer.inventory.container.Remove(item as ThingWithComps);
                            if (wearer.jobs.curJob != null)
                                wearer.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        }
                        //Medicine
                        else if (item.def.thingCategories.Contains(medicine))
                        {
                            if (wearer.workSettings.WorkIsActive(WorkTypeDefOf.Doctor))
                            {
                                Designator_ApplyMedicine designator = new Designator_ApplyMedicine();
                                designator.medicine = item;
                                designator.doctor = wearer;
                                designator.icon = item.def.uiIcon;
                                designator.activateSound = SoundDef.Named("Click");

                                DesignatorManager.Select(designator);
                            }
                            else
                            {
                                Messages.Message(txtNoDoctor.Translate(), MessageSound.RejectInput);
                                Messages.Update();
                                thingIconSound = SoundDefOf.ClickReject;
                            }
                        }
                        //Food
                        else if (item.def.thingCategories.Contains(foodMeals))
                        {
                            if (wearer.needs.food.CurCategory != HungerCategory.Fed)
                            {
                                Job jobNew = new Job(JobDefOf.Ingest, item);
                                jobNew.maxNumToCarry = 1;
                                jobNew.ignoreForbidden = true;
                                wearer.drafter.TakeOrderedJob(jobNew);
                            }
                            else
                            {
                                Messages.Message(txtCannotEatAnymore.Translate(), MessageSound.RejectInput);
                                Messages.Update();
                                thingIconSound = SoundDefOf.ClickReject;
                            }
                        }
                        //Apparel
                        else if (item is Apparel)
                        {
                            //if (!wearer.apparel.CanWearWithoutDroppingAnything(item.def))
                            //    wearer.apparel.WornApparel.Find(apparel => apparel.def.apparel.layers.Any);
                            for (int index = wearer.apparel.WornApparel.Count - 1; index >= 0; --index)
                            {
                                Apparel ap = wearer.apparel.WornApparel[index];
                                if (!ApparelUtility.CanWearTogether(item.def, ap.def))
                                {
                                    Apparel resultingAp;
                                    wearer.apparel.TryDrop(ap, out resultingAp, wearer.Position, false);
                                    wearer.inventory.container.TryAdd(resultingAp);
                                    backpack.numOfSavedItems++;
                                }
                            }
                            wearer.apparel.Wear(item as Apparel);
                            wearer.inventory.container.Remove(item as ThingWithComps);
                            backpack.numOfSavedItems--;
                        }

                        else
                        {
                            //Add another type of item you want to interact
                        }
                    }
                    else if (Event.current.button == 1)
                    {
                        List<FloatMenuOption> options = new List<FloatMenuOption>();
                        options.Add(new FloatMenuOption(txtThingInfo, () =>
                        {
                            Find.WindowStack.Add((Window)new Dialog_InfoCard(item));
                        }));
                        options.Add(new FloatMenuOption(txtDropThing, () =>
                        {
                            Thing dummy1;
                            wearer.inventory.container.TryDrop(item, wearer.Position, ThingPlaceMode.Near, out dummy1);
                        }));

                        Find.WindowStack.Add((Window)new FloatMenu(options, item.LabelCap, false, false));
                    }

                    SoundStarter.PlayOneShotOnCamera(thingIconSound);
                }

                numOfCurItem++;
                thingIconRect.x = topLeft.x + widthPerItem * (numOfCurItem % numOfMaxItemsPerRow);
                thingIconRect.y = topLeft.y + (Height / 2) * (numOfCurItem / numOfMaxItemsPerRow);
            }

            if (numOfCurItem == 0 )
            {
                Rect textRect = new Rect(topLeft.x + Width / 2 - textWidth / 2, topLeft.y + Height / 2 - textHeight / 2, textWidth, textHeight);
                Widgets.Label(textRect, txtNoItem.Translate());
            }
            return new GizmoResult(GizmoState.Clear);
        }