Ejemplo n.º 1
0
        public static void DrawGizmoGrid(IEnumerable <Gizmo> gizmos, float startX, out Gizmo mouseoverGizmo)
        {
            GizmoGridDrawer.gizmoGroups.Clear();
            foreach (Gizmo current in gizmos)
            {
                bool flag = false;
                for (int i = 0; i < GizmoGridDrawer.gizmoGroups.Count; i++)
                {
                    if (GizmoGridDrawer.gizmoGroups[i][0].GroupsWith(current))
                    {
                        flag = true;
                        GizmoGridDrawer.gizmoGroups[i].Add(current);
                        break;
                    }
                }
                if (!flag)
                {
                    List <Gizmo> list = new List <Gizmo>();
                    list.Add(current);
                    GizmoGridDrawer.gizmoGroups.Add(list);
                }
            }
            GizmoGridDrawer.firstGizmos.Clear();
            for (int j = 0; j < GizmoGridDrawer.gizmoGroups.Count; j++)
            {
                List <Gizmo> source = GizmoGridDrawer.gizmoGroups[j];
                Gizmo        gizmo  = source.FirstOrDefault((Gizmo opt) => !opt.disabled);
                if (gizmo == null)
                {
                    gizmo = source.FirstOrDefault <Gizmo>();
                }
                GizmoGridDrawer.firstGizmos.Add(gizmo);
            }
            Verse.GizmoGridDrawer.drawnHotKeys.Clear();
            float num = (float)(Screen.width - 140);

            Text.Font = GameFont.Tiny;
            Vector2 topLeft = new Vector2(startX, (float)(Screen.height - 35) - GizmoGridDrawer.GizmoSpacing.y - 75f);

            mouseoverGizmo = null;
            Gizmo interactedGiz = null;
            Event @event        = null;

            for (int k = 0; k < GizmoGridDrawer.firstGizmos.Count; k++)
            {
                Gizmo gizmo2 = GizmoGridDrawer.firstGizmos[k];
                if (gizmo2.Visible)
                {
                    if (topLeft.x + gizmo2.Width + GizmoGridDrawer.GizmoSpacing.x > num)
                    {
                        topLeft.x  = startX;
                        topLeft.y -= 75f + GizmoGridDrawer.GizmoSpacing.x;
                    }
                    GizmoGridDrawer.heightDrawnFrame = Time.frameCount;
                    GizmoGridDrawer.heightDrawn      = (float)Screen.height - topLeft.y;
                    GizmoResult gizmoResult = gizmo2.GizmoOnGUI(topLeft);
                    if (gizmoResult.State == GizmoState.Interacted)
                    {
                        @event        = gizmoResult.InteractEvent;
                        interactedGiz = gizmo2;
                    }
                    if (gizmoResult.State >= GizmoState.Mouseover)
                    {
                        mouseoverGizmo = gizmo2;
                    }
                    Rect rect = new Rect(topLeft.x, topLeft.y, gizmo2.Width, 75f + GizmoGridDrawer.GizmoSpacing.y);
                    rect = rect.ContractedBy(-12f);
                    GenUI.AbsorbClicksInRect(rect);
                    topLeft.x += gizmo2.Width + GizmoGridDrawer.GizmoSpacing.x;
                }
            }
            if (interactedGiz != null)
            {
                List <Gizmo> list2 = GizmoGridDrawer.gizmoGroups.First((List <Gizmo> group) => group.Contains(interactedGiz));
                for (int l = 0; l < list2.Count; l++)
                {
                    Gizmo gizmo3 = list2[l];
                    if (gizmo3 != interactedGiz && !gizmo3.disabled && gizmo3.InheritInteractionsFrom(interactedGiz))
                    {
                        gizmo3.ProcessInput(@event);
                    }
                }
                if (interactedGiz is Designator_Build)
                {
                    if (@event.button != 1 && GizmoGridDrawer.rightClickMaterialPreference != null && GizmoGridDrawer.rightClickMaterialPreference.Value)
                    {
                        Command command = interactedGiz as Command;
                        if (command != null && command.CurActivateSound != null)
                        {
                            command.CurActivateSound.PlayOneShotOnCamera();
                        }
                        Designator designator = interactedGiz as Designator;
                        if (designator != null)
                        {
                            DesignatorManager.Select(designator);
                        }
                    }
                    else
                    {
                        interactedGiz.ProcessInput(@event);
                    }
                }
                else
                {
                    interactedGiz.ProcessInput(@event);
                }
                Event.current.Use();
            }
        }
 public void PanelClosing()
 {
     DesignatorManager.Deselect();
 }
Ejemplo n.º 3
0
        public void DrawSlots(Pawn wearer, CompSlotsBackpack SlotsBackpackComp, Rect inventoryRect)
        {
            // draw text message if no contents inside
            if (SlotsBackpackComp.slots.Count == 0)
            {
                Text.Font   = GameFont.Medium;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(inventoryRect, "No Items");
                Text.Anchor = TextAnchor.UpperLeft;
                Text.Font   = GameFont.Tiny;
            }
            // draw slots
            else
            {
                Rect slotRect = new Rect(inventoryRect.x, inventoryRect.y, Width / iconsPerRow - 1f, Height / 2 - 1f);
                for (int currentSlotInd = 0; currentSlotInd < iconsPerRow * numOfRow; currentSlotInd++)
                {
                    if (currentSlotInd >= backpack.MaxItem)
                    {
                        slotRect.x = inventoryRect.x + inventoryRect.width / iconsPerRow * (currentSlotInd % iconsPerRow);
                        slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / iconsPerRow);
                        Widgets.DrawTextureFitted(slotRect, NoAvailableTex, 1.0f);
                    }

                    if (currentSlotInd >= SlotsBackpackComp.slots.Count)
                    {
                        slotRect.x = inventoryRect.x + inventoryRect.width / iconsPerRow * (currentSlotInd % iconsPerRow);
                        slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / iconsPerRow);
                        Widgets.DrawTextureFitted(slotRect, EmptyTex, 1.0f);
                    }

                    // draw occupied slots
                    if (currentSlotInd < SlotsBackpackComp.slots.Count)
                    {
                        slotRect.x = inventoryRect.x + inventoryRect.width / iconsPerRow * (currentSlotInd % iconsPerRow);
                        slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / iconsPerRow);

                        Thing currentThing = SlotsBackpackComp.slots[currentSlotInd];

                        // draws greyish slot background
                        Widgets.DrawTextureFitted(slotRect.ContractedBy(3f), texOccupiedSlotBG, 1f);

                        if (currentThing.def.IsMeleeWeapon)
                        {
                            Widgets.DrawTextureFitted(slotRect, MeleeWeaponTex, 1.0f);
                        }
                        if (currentThing.def.IsRangedWeapon)
                        {
                            Widgets.DrawTextureFitted(slotRect, RangedWeaponTex, 1.0f);
                        }
                        Widgets.DrawBox(slotRect);

                        // highlights slot if mouse over
                        Widgets.DrawHighlightIfMouseover(slotRect.ContractedBy(3f));

                        // tooltip if mouse over
                        TooltipHandler.TipRegion(slotRect, currentThing.def.LabelCap);

                        // draw thing texture
                        Widgets.ThingIcon(slotRect, currentThing);

                        // interaction with slots
                        if (Widgets.ButtonInvisible(slotRect))
                        {
                            // mouse button pressed
                            if (Event.current.button == 0)
                            {
                                //Weapon
                                if (currentThing != null && currentThing.def.equipmentType == EquipmentType.Primary && (currentThing.def.IsRangedWeapon || currentThing.def.IsMeleeWeapon))
                                {
                                    SlotsBackpackComp.SwapEquipment(currentThing as ThingWithComps);
                                }

                                //// equip weapon in slot
                                //if (currentThing.def.equipmentType == EquipmentType.Primary)
                                //{
                                //    slotsComp.SwapEquipment(currentThing as ThingWithComps);
                                //}
                            }
                            // mouse button released
                            else if (Event.current.button == 1)
                            {
                                List <FloatMenuOption> options = new List <FloatMenuOption>
                                {
                                    new FloatMenuOption("Info",
                                                        () => { Find.WindowStack.Add(new Dialog_InfoCard(currentThing)); }),
                                    new FloatMenuOption("Drop", () =>
                                    {
                                        Thing resultThing;
                                        SlotsBackpackComp.slots.TryDrop(currentThing, wearer.Position,
                                                                        ThingPlaceMode.Near, out resultThing);
                                    })
                                };
                                // get thing info card
                                // drop thing

                                // Else

                                //Weapon
                                if (currentThing != null && currentThing.def.equipmentType == EquipmentType.Primary)
                                {
                                    options.Add(new FloatMenuOption("Equip".Translate(currentThing.LabelCap), () =>
                                    {
                                        SlotsBackpackComp.SwapEquipment(currentThing as ThingWithComps);
                                    }));
                                }


                                //Medicine
                                if (currentThing.def.IsMedicine)
                                {
                                    if (wearer.workSettings != null && wearer.workSettings.WorkIsActive(WorkTypeDefOf.Doctor))
                                    {
                                        options.Add(new FloatMenuOption("TreatPatientWithMedicine".Translate(), () =>
                                        {
                                            Designator_ApplyMedicine designator = new Designator_ApplyMedicine();
                                            designator.SlotsBackpackComp        = SlotsBackpackComp;
                                            designator.medicine      = currentThing;
                                            designator.doctor        = wearer;
                                            designator.icon          = currentThing.def.uiIcon;
                                            designator.activateSound = SoundDef.Named("Click");

                                            DesignatorManager.Select(designator);
                                        }));
                                    }
                                }
                                //Food
                                if (currentThing.def.thingCategories.Contains(DefDatabase <ThingCategoryDef> .GetNamed("FoodMeals")))
                                {
                                    //  if (compSlots.owner.needs.food.CurCategory != HungerCategory.Fed)
                                    options.Add(new FloatMenuOption("ConsumeThing".Translate(currentThing.LabelCap), () =>
                                    {
                                        Thing dummy;
                                        SlotsBackpackComp.slots.TryDrop(currentThing, wearer.Position, ThingPlaceMode.Direct, currentThing.def.ingestible.maxNumToIngestAtOnce, out dummy);

                                        Job jobNew             = new Job(JobDefOf.Ingest, dummy);
                                        jobNew.maxNumToCarry   = currentThing.def.ingestible.maxNumToIngestAtOnce;
                                        jobNew.ignoreForbidden = true;
                                        wearer.drafter.TakeOrderedJob(jobNew);
                                    }));
                                }
                                // Drugs
                                if (currentThing.def.ingestible?.drugCategory >= DrugCategory.Any)
                                {
                                    options.Add(new FloatMenuOption("ConsumeThing".Translate(currentThing.LabelCap), () =>
                                    {
                                        Thing dummy;
                                        SlotsBackpackComp.slots.TryDrop(currentThing, wearer.Position, ThingPlaceMode.Direct, currentThing.def.ingestible.maxNumToIngestAtOnce, out dummy);

                                        Job jobNew             = new Job(JobDefOf.Ingest, dummy);
                                        jobNew.maxNumToCarry   = dummy.def.ingestible.maxNumToIngestAtOnce;
                                        jobNew.ignoreForbidden = true;
                                        wearer.drafter.TakeOrderedJob(jobNew);
                                    }));
                                }



                                Find.WindowStack.Add(new FloatMenu(options, currentThing.LabelCap));
                            }

                            // plays click sound on each click
                            SoundDefOf.Click.PlayOneShotOnCamera();
                        }
                    }
                    slotRect.x = inventoryRect.x + Height / 2 * (currentSlotInd % iconsPerRow);
                    slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / iconsPerRow);
                    //      slotRect.x += Height;
                }
            }
        }
Ejemplo n.º 4
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));
        }