public override void DrawTab(Rect rect)
        {
            Rect SelectionBar  = new Rect(5, 45, 200, 30);
            Rect importButton  = new Rect(5, SelectionBar.y + SelectionBar.height + 10, 200, 30);
            Rect nameTextField = new Rect(5, importButton.y + importButton.height + 10, 250, 30);
            Rect isCivilian    = new Rect(5, nameTextField.y + nameTextField.height + 10, 100, 30);
            Rect isTrader      = new Rect(isCivilian.x, isCivilian.y + isCivilian.height + 5, isCivilian.width,
                                          isCivilian.height);

            Rect unitIcon   = new Rect(560, 235, 120, 120);
            Rect animalIcon = new Rect(560, 335, 120, 120);

            Rect ApparelHead      = new Rect(600, 140, 50, 50);
            Rect ApparelTorsoSkin = new Rect(700, 170, 50, 50);
            Rect ApparelBelt      = new Rect(700, 240, 50, 50);
            Rect ApparelLegs      = new Rect(700, 310, 50, 50);

            Rect AnimalCompanion    = new Rect(500, 160, 50, 50);
            Rect ApparelTorsoShell  = new Rect(500, 230, 50, 50);
            Rect ApparelTorsoMiddle = new Rect(500, 310, 50, 50);
            Rect EquipmentWeapon    = new Rect(440, 230, 50, 50);

            Rect ApparelWornItems   = new Rect(440, 385, 330, 175);
            Rect EquipmentTotalCost = new Rect(450, 50, 350, 40);

            Rect ResetButton  = new Rect(700, 50, 100, 30);
            Rect DeleteButton = new Rect(ResetButton.x, ResetButton.y + ResetButton.height + 5,
                                         ResetButton.width,
                                         ResetButton.height);
            Rect SavePawn = new Rect(DeleteButton.x, DeleteButton.y + DeleteButton.height + 5,
                                     DeleteButton.width,
                                     DeleteButton.height);
            Rect ChangeRace  = new Rect(325, ResetButton.y, SavePawn.width, SavePawn.height);
            Rect RollNewPawn = new Rect(325, ResetButton.y + SavePawn.height + 5, SavePawn.width,
                                        SavePawn.height);

            if (Widgets.CustomButtonText(ref SelectionBar, selectedText, Color.gray, Color.white, Color.black))
            {
                List <FloatMenuOption> Units = new List <FloatMenuOption>
                {
                    new FloatMenuOption("Create New Unit", delegate
                    {
                        MilUnitFC newUnit = new MilUnitFC(false)
                        {
                            name = $"New Unit {util.units.Count() + 1}"
                        };
                        selectedText = newUnit.name;
                        selectedUnit = newUnit;
                        util.units.Add(newUnit);
                        newUnit.unequipAllEquipment();
                    })
                };

                //Option to create new unit

                //Create list of selectable units
                foreach (MilUnitFC unit in util.units)
                {
                    void action()
                    {
                        selectedText = unit.name;
                        selectedUnit = unit;
                    }

                    //Prevent units being modified when their squads are deployed
                    FactionFC           factionFC                  = Find.World.GetComponent <FactionFC>();
                    List <MilSquadFC>   squadsContainingUnit       = factionFC?.militaryCustomizationUtil?.squads.Where(squad => squad?.units != null && squad.units.Contains(unit)).ToList();
                    List <SettlementFC> settlementsContainingSquad = factionFC?.settlements?.Where(settlement => settlement?.militarySquad?.outfit != null && squadsContainingUnit.Any(squad => settlement.militarySquad.outfit == squad)).ToList();

                    if ((settlementsContainingSquad?.Count ?? 0) > 0)
                    {
                        if (settlementsContainingSquad.Any(settlement => settlement.militarySquad.isDeployed))
                        {
                            Units.Add(new FloatMenuOption(unit.name, delegate { Messages.Message("CantBeModified".Translate(unit.name, "ReasonDeployed".Translate()), MessageTypeDefOf.NeutralEvent, false); }));
                            continue;
                        }
                        else if (settlementsContainingSquad.Any(settlement => settlement.isUnderAttack && settlementsContainingSquad.Contains(settlement.worldSettlement.defenderForce.homeSettlement)))
                        {
                            Units.Add(new FloatMenuOption(unit.name, delegate { Messages.Message("CantBeModified".Translate(unit.name, "ReasonDefending".Translate()), MessageTypeDefOf.NeutralEvent, false); }));
                            continue;
                        }
                    }

                    if (unit.defaultPawn.equipment.Primary != null)
                    {
                        Units.Add(new FloatMenuOption(unit.name, action, unit.defaultPawn.equipment.Primary.def));
                    }
                    else
                    {
                        Units.Add(new FloatMenuOption(unit.name, action));
                    }
                }

                FloatMenu selection = new Searchable_FloatMenu(Units);
                Find.WindowStack.Add(selection);
            }

            if (Widgets.ButtonText(importButton, "importUnit".Translate()))
            {
                Find.WindowStack.Add(new Dialog_ManageUnitExportsFC(
                                         FactionColoniesMilitary.SavedUnits.ToList()));
            }

            //Worn Items
            Widgets.DrawMenuSection(ApparelWornItems);

            //set text anchor and font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.UpperCenter;

            //if unit is not selected
            Widgets.Label(new Rect(new Vector2(ApparelHead.x, ApparelHead.y - 15), ApparelHead.size), "fcLabelHead".Translate());
            Widgets.DrawMenuSection(ApparelHead);
            Widgets.Label(
                new Rect(new Vector2(ApparelTorsoSkin.x, ApparelTorsoSkin.y - 15), ApparelTorsoSkin.size),
                "fcLabelShirt".Translate());
            Widgets.DrawMenuSection(ApparelTorsoSkin);
            Widgets.Label(
                new Rect(new Vector2(ApparelTorsoMiddle.x, ApparelTorsoMiddle.y - 15), ApparelTorsoMiddle.size),
                "fcLabelChest".Translate());
            Widgets.DrawMenuSection(ApparelTorsoMiddle);
            Widgets.Label(
                new Rect(new Vector2(ApparelTorsoShell.x, ApparelTorsoShell.y - 15), ApparelTorsoShell.size),
                "fcLabelOver".Translate());
            Widgets.DrawMenuSection(ApparelTorsoShell);
            Widgets.Label(new Rect(new Vector2(ApparelBelt.x, ApparelBelt.y - 15), ApparelBelt.size), "fcLabelBelt".Translate());
            Widgets.DrawMenuSection(ApparelBelt);
            Widgets.Label(new Rect(new Vector2(ApparelLegs.x, ApparelLegs.y - 15), ApparelLegs.size), "fcLabelPants".Translate());
            Widgets.DrawMenuSection(ApparelLegs);
            Widgets.Label(
                new Rect(new Vector2(EquipmentWeapon.x, EquipmentWeapon.y - 15), EquipmentWeapon.size),
                "fcLabelWeapon".Translate());
            Widgets.DrawMenuSection(EquipmentWeapon);
            Widgets.Label(
                new Rect(new Vector2(AnimalCompanion.x, AnimalCompanion.y - 15), AnimalCompanion.size),
                "fcLabelAnimal".Translate());
            Widgets.DrawMenuSection(AnimalCompanion);

            //Reset Text anchor and font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;

            //if unit is selected
            if (selectedUnit == null)
            {
                return;
            }
            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.UpperCenter;

            if (Widgets.ButtonText(ResetButton, "resetUnitToDefaultButton".Translate()))
            {
                selectedUnit.unequipAllEquipment();
            }

            if (Widgets.ButtonText(DeleteButton, "deleteUnitButton".Translate()))
            {
                selectedUnit.removeUnit();
                util.checkMilitaryUtilForErrors();
                selectedUnit = null;
                selectedText = "selectAUnitButton".Translate();

                //Reset Text anchor and font
                Text.Font   = fontBefore;
                Text.Anchor = anchorBefore;
                return;
            }

            if (Widgets.ButtonText(RollNewPawn, "rollANewUnitButton".Translate()))
            {
                selectedUnit.generateDefaultPawn();
                selectedUnit.unequipAllEquipment();
            }

            if (Widgets.ButtonText(ChangeRace, "changeUnitRaceButton".Translate()))
            {
                List <string>          races   = new List <string>();
                List <FloatMenuOption> options = new List <FloatMenuOption>();

                foreach (PawnKindDef def in DefDatabase <PawnKindDef> .AllDefsListForReading.Where(def => def.IsHumanLikeRace() && !races.Contains(def.race.label) && faction.raceFilter.Allows(def.race)))
                {
                    if (def.race == ThingDefOf.Human && def.LabelCap != "Colonist")
                    {
                        continue;
                    }
                    races.Add(def.race.label);

                    string optionStr = def.race.label.CapitalizeFirst() + " - Cost: " + Math.Floor(def.race.BaseMarketValue * FactionColonies.militaryRaceCostMultiplier);
                    options.Add(new FloatMenuOption(optionStr, delegate
                    {
                        selectedUnit.pawnKind = def;
                        selectedUnit.generateDefaultPawn();
                        selectedUnit.changeTick();
                    }));
                }

                if (!options.Any())
                {
                    options.Add(new FloatMenuOption("changeUnitRaceNoRaces".Translate(), null));
                }

                options.Sort(FactionColonies.CompareFloatMenuOption);
                FloatMenu menu = new Searchable_FloatMenu(options);
                Find.WindowStack.Add(menu);
            }

            if (Widgets.ButtonText(SavePawn, "exportUnitButton".Translate()))
            {
                // TODO: confirm
                FactionColoniesMilitary.SaveUnit(new SavedUnitFC(selectedUnit));
                Messages.Message("ExportUnit".Translate(), MessageTypeDefOf.TaskCompletion);
            }

            //Unit Name
            selectedUnit.name = Widgets.TextField(nameTextField, selectedUnit.name);

            Widgets.CheckboxLabeled(isCivilian, "unitIsCivilianLabel".Translate(), ref selectedUnit.isCivilian);
            Widgets.CheckboxLabeled(isTrader, "unitIsTraderLabel".Translate(), ref selectedUnit.isTrader);
            selectedUnit.setTrader(selectedUnit.isTrader);
            selectedUnit.setCivilian(selectedUnit.isCivilian);

            //Reset Text anchor and font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
            //Draw Pawn
            if (selectedUnit.defaultPawn != null)
            {
                if (selectedUnit.animal != null)
                {
                    //Widgets.DrawTextureFitted(animalIcon, selectedUnit.animal.race.graphicData.Graphic.MatNorth.mainTexture, 1);
                }

                Widgets.ThingIcon(unitIcon, selectedUnit.defaultPawn);
            }

            //Animal Companion
            if (Widgets.ButtonInvisible(AnimalCompanion))
            {
                List <FloatMenuOption> list = (from animal in DefDatabase <PawnKindDef> .AllDefs
                                               where animal.IsAnimalAndAllowed()
                                               select new FloatMenuOption(animal.LabelCap + " - Cost: " +
                                                                          Math.Floor(animal.race.BaseMarketValue *
                                                                                     FactionColonies.militaryAnimalCostMultiplier),
                                                                          delegate
                {
                    //Do add animal code here
                    selectedUnit.animal = animal;
                }, animal.race.uiIcon, Color.white)).ToList();

                list.Sort(FactionColonies.CompareFloatMenuOption);

                list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate
                {
                    //unequip here
                    selectedUnit.animal = null;
                }));
                FloatMenu menu = new Searchable_FloatMenu(list);
                Find.WindowStack.Add(menu);
            }

            //Weapon Equipment
            if (Widgets.ButtonInvisible(EquipmentWeapon))
            {
                List <FloatMenuOption> list = (from thing in DefDatabase <ThingDef> .AllDefs
                                               where thing.IsWeapon && thing.BaseMarketValue != 0 && FactionColonies.canCraftItem(thing)
                                               where true
                                               select new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate
                {
                    if (thing.MadeFromStuff)
                    {
                        //If made from stuff
                        List <FloatMenuOption> stuffList = (from stuff in DefDatabase <ThingDef> .AllDefs
                                                            where stuff.IsStuff &&
                                                            thing.stuffCategories.SharesElementWith(stuff.stuffProps.categories)
                                                            select new FloatMenuOption(stuff.LabelCap + " - Total Value: " +
                                                                                       StatWorker_MarketValue.CalculatedBaseMarketValue(
                                                                                           thing,
                                                                                           stuff),
                                                                                       delegate
                        {
                            selectedUnit.equipWeapon(
                                ThingMaker.MakeThing(thing, stuff) as ThingWithComps);
                        })).ToList();

                        stuffList.Sort(FactionColonies.CompareFloatMenuOption);
                        FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList);
                        Find.WindowStack.Add(stuffWindow);
                    }
                    else
                    {
                        //If not made from stuff

                        selectedUnit.equipWeapon(ThingMaker.MakeThing(thing) as ThingWithComps);
                    }
                }, thing)).ToList();


                list.Sort(FactionColonies.CompareFloatMenuOption);

                list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { selectedUnit.unequipWeapon(); }));

                FloatMenu menu = new Searchable_FloatMenu(list);

                Find.WindowStack.Add(menu);
            }

            //headgear Slot
            if (Widgets.ButtonInvisible(ApparelHead))
            {
                List <FloatMenuOption> headgearList = new List <FloatMenuOption>();


                foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs)
                {
                    if (thing.IsApparel)
                    {
                        if (thing.apparel.layers.Contains(ApparelLayerDefOf.Overhead) &&
                            FactionColonies.canCraftItem(thing))
                        {
                            headgearList.Add(new FloatMenuOption(
                                                 thing.LabelCap + " - Cost: " + thing.BaseMarketValue,
                                                 delegate
                            {
                                if (thing.MadeFromStuff)
                                {
                                    //If made from stuff
                                    List <FloatMenuOption> stuffList = new List <FloatMenuOption>();
                                    foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs)
                                    {
                                        if (stuff.IsStuff &&
                                            thing.stuffCategories.SharesElementWith(stuff.stuffProps
                                                                                    .categories))
                                        {
                                            stuffList.Add(new FloatMenuOption(
                                                              stuff.LabelCap + " - Total Value: " +
                                                              (StatWorker_MarketValue.CalculatedBaseMarketValue(thing,
                                                                                                                stuff)),
                                                              delegate
                                            {
                                                selectedUnit.wearEquipment(
                                                    ThingMaker.MakeThing(thing, stuff) as Apparel,
                                                    true);
                                            }));
                                        }
                                    }

                                    stuffList.Sort(FactionColonies.CompareFloatMenuOption);
                                    FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList);
                                    Find.WindowStack.Add(stuffWindow);
                                }
                                else
                                {
                                    //If not made from stuff

                                    selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel,
                                                               true);
                                }
                            }, thing));
                        }
                    }
                }

                headgearList.Sort(FactionColonies.CompareFloatMenuOption);

                headgearList.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate
                {
                    //Remove old
                    foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel
                             .Where(apparel => apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Overhead)))
                    {
                        selectedUnit.defaultPawn.apparel.Remove(apparel);
                        break;
                    }
                }));

                FloatMenu menu = new Searchable_FloatMenu(headgearList);

                Find.WindowStack.Add(menu);
            }


            //Torso Shell Slot
            if (Widgets.ButtonInvisible(ApparelTorsoShell))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();


                foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs)
                {
                    if (thing.IsApparel)
                    {
                        if (thing.apparel.layers.Contains(ApparelLayerDefOf.Shell) &&
                            thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) &&
                            FactionColonies.canCraftItem(thing)) //CHANGE THIS
                        {
                            list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue,
                                                         delegate
                            {
                                if (thing.MadeFromStuff)
                                {
                                    //If made from stuff
                                    List <FloatMenuOption> stuffList = new List <FloatMenuOption>();
                                    foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs)
                                    {
                                        if (stuff.IsStuff &&
                                            thing.stuffCategories.SharesElementWith(stuff.stuffProps
                                                                                    .categories))
                                        {
                                            stuffList.Add(new FloatMenuOption(
                                                              stuff.LabelCap + " - Total Value: " +
                                                              (StatWorker_MarketValue.CalculatedBaseMarketValue(thing,
                                                                                                                stuff)),
                                                              delegate
                                            {
                                                selectedUnit.wearEquipment(
                                                    ThingMaker.MakeThing(thing, stuff) as Apparel,
                                                    true);
                                            }));
                                        }
                                    }

                                    stuffList.Sort(FactionColonies.CompareFloatMenuOption);
                                    FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList);
                                    Find.WindowStack.Add(stuffWindow);
                                }
                                else
                                {
                                    //If not made from stuff

                                    selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel,
                                                               true);
                                }
                            }, thing));
                        }
                    }
                }

                list.Sort(FactionColonies.CompareFloatMenuOption);

                list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate
                {
                    //Remove old
                    foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel)
                    {
                        if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Shell) &&
                            apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) //CHANGE THIS
                        {
                            selectedUnit.defaultPawn.apparel.Remove(apparel);
                            break;
                        }
                    }
                }));
                FloatMenu menu = new Searchable_FloatMenu(list);

                Find.WindowStack.Add(menu);
            }


            //Torso Middle Slot
            if (Widgets.ButtonInvisible(ApparelTorsoMiddle))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();


                foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs)
                {
                    if (thing.IsApparel)
                    {
                        if (thing.apparel.layers.Contains(ApparelLayerDefOf.Middle) &&
                            thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) &&
                            FactionColonies.canCraftItem(thing)) //CHANGE THIS
                        {
                            list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue,
                                                         delegate
                            {
                                if (thing.MadeFromStuff)
                                {
                                    //If made from stuff
                                    List <FloatMenuOption> stuffList = new List <FloatMenuOption>();
                                    foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs)
                                    {
                                        if (stuff.IsStuff &&
                                            thing.stuffCategories.SharesElementWith(stuff.stuffProps
                                                                                    .categories))
                                        {
                                            stuffList.Add(new FloatMenuOption(
                                                              stuff.LabelCap + " - Total Value: " +
                                                              (StatWorker_MarketValue.CalculatedBaseMarketValue(thing,
                                                                                                                stuff)),
                                                              delegate
                                            {
                                                selectedUnit.wearEquipment(
                                                    ThingMaker.MakeThing(thing, stuff) as Apparel,
                                                    true);
                                            }));
                                        }
                                    }

                                    stuffList.Sort(FactionColonies.CompareFloatMenuOption);
                                    FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList);
                                    Find.WindowStack.Add(stuffWindow);
                                }
                                else
                                {
                                    //If not made from stuff

                                    selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel,
                                                               true);
                                }
                            }, thing));
                        }
                    }
                }

                list.Sort(FactionColonies.CompareFloatMenuOption);

                list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate
                {
                    //Remove old
                    foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel)
                    {
                        if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Middle) &&
                            apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) //CHANGE THIS
                        {
                            selectedUnit.defaultPawn.apparel.Remove(apparel);
                            break;
                        }
                    }
                }));
                FloatMenu menu = new Searchable_FloatMenu(list);

                Find.WindowStack.Add(menu);
            }


            //Torso Skin Slot
            if (Widgets.ButtonInvisible(ApparelTorsoSkin))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();


                foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs)
                {
                    if (thing.IsApparel)
                    {
                        if (thing.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) &&
                            thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) &&
                            FactionColonies.canCraftItem(thing)) //CHANGE THIS
                        {
                            list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue,
                                                         delegate
                            {
                                if (thing.MadeFromStuff)
                                {
                                    //If made from stuff
                                    List <FloatMenuOption> stuffList = new List <FloatMenuOption>();
                                    foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs)
                                    {
                                        if (stuff.IsStuff &&
                                            thing.stuffCategories.SharesElementWith(stuff.stuffProps
                                                                                    .categories))
                                        {
                                            stuffList.Add(new FloatMenuOption(
                                                              stuff.LabelCap + " - Total Value: " +
                                                              (StatWorker_MarketValue.CalculatedBaseMarketValue(thing,
                                                                                                                stuff)),
                                                              delegate
                                            {
                                                selectedUnit.wearEquipment(
                                                    ThingMaker.MakeThing(thing, stuff) as Apparel,
                                                    true);
                                            }));
                                        }
                                    }

                                    stuffList.Sort(FactionColonies.CompareFloatMenuOption);
                                    FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList);
                                    Find.WindowStack.Add(stuffWindow);
                                }
                                else
                                {
                                    //If not made from stuff

                                    selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel,
                                                               true);
                                }
                            }, thing));
                        }
                    }
                }

                list.Sort(FactionColonies.CompareFloatMenuOption);


                list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate
                {
                    //Remove old
                    foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel)
                    {
                        if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) &&
                            apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) //CHANGE THIS
                        {
                            selectedUnit.defaultPawn.apparel.Remove(apparel);
                            break;
                        }
                    }
                }));
                FloatMenu menu = new Searchable_FloatMenu(list);

                Find.WindowStack.Add(menu);
            }


            //Pants Slot
            if (Widgets.ButtonInvisible(ApparelLegs))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();

                foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs)
                {
                    if (thing.IsApparel)
                    {
                        if (thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) &&
                            thing.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) &&
                            FactionColonies.canCraftItem(thing)) //CHANGE THIS
                        {
                            list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue,
                                                         delegate
                            {
                                if (thing.MadeFromStuff)
                                {
                                    //If made from stuff
                                    List <FloatMenuOption> stuffList = new List <FloatMenuOption>();
                                    foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs)
                                    {
                                        if (stuff.IsStuff &&
                                            thing.stuffCategories.SharesElementWith(stuff.stuffProps
                                                                                    .categories))
                                        {
                                            stuffList.Add(new FloatMenuOption(
                                                              stuff.LabelCap + " - Total Value: " +
                                                              (StatWorker_MarketValue.CalculatedBaseMarketValue(thing,
                                                                                                                stuff)),
                                                              delegate
                                            {
                                                selectedUnit.wearEquipment(
                                                    ThingMaker.MakeThing(thing, stuff) as Apparel,
                                                    true);
                                            }));
                                        }
                                    }

                                    stuffList.Sort(FactionColonies.CompareFloatMenuOption);
                                    FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList);
                                    Find.WindowStack.Add(stuffWindow);
                                }
                                else
                                {
                                    //If not made from stuff

                                    selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel,
                                                               true);
                                }
                            }, thing));
                        }
                    }
                }

                list.Sort(FactionColonies.CompareFloatMenuOption);

                list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate
                {
                    //Remove old
                    foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel)
                    {
                        if (apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) &&
                            apparel.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin)) //CHANGE THIS
                        {
                            selectedUnit.defaultPawn.apparel.Remove(apparel);
                            break;
                        }
                    }
                }));
                FloatMenu menu = new Searchable_FloatMenu(list);

                Find.WindowStack.Add(menu);
            }


            //Apparel Belt Slot
            if (Widgets.ButtonInvisible(ApparelBelt))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();

                foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs)
                {
                    if (thing.IsApparel)
                    {
                        if (thing.apparel.layers.Contains(ApparelLayerDefOf.Belt) &&
                            FactionColonies.canCraftItem(thing))
                        {
                            list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue,
                                                         delegate
                            {
                                if (thing.MadeFromStuff)
                                {
                                    //If made from stuff
                                    List <FloatMenuOption> stuffList = new List <FloatMenuOption>();
                                    foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs)
                                    {
                                        if (stuff.IsStuff &&
                                            thing.stuffCategories.SharesElementWith(stuff.stuffProps
                                                                                    .categories))
                                        {
                                            stuffList.Add(new FloatMenuOption(
                                                              stuff.LabelCap + " - Total Value: " +
                                                              (StatWorker_MarketValue.CalculatedBaseMarketValue(thing,
                                                                                                                stuff)),
                                                              delegate
                                            {
                                                selectedUnit.wearEquipment(
                                                    ThingMaker.MakeThing(thing, stuff) as Apparel,
                                                    true);
                                            }));
                                        }
                                    }

                                    stuffList.Sort(FactionColonies.CompareFloatMenuOption);
                                    FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList);
                                    Find.WindowStack.Add(stuffWindow);
                                }
                                else
                                {
                                    //If not made from stuff
                                    //Remove old equipment
                                    foreach (Apparel apparel in selectedUnit.defaultPawn.apparel
                                             .WornApparel)
                                    {
                                        if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Belt))
                                        {
                                            selectedUnit.defaultPawn.apparel.Remove(apparel);
                                            break;
                                        }
                                    }

                                    selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel,
                                                               true);
                                }
                            }, thing));
                        }
                    }
                }

                list.Sort(FactionColonies.CompareFloatMenuOption);

                list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate
                {
                    //Remove old
                    foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel)
                    {
                        if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Belt))
                        {
                            selectedUnit.defaultPawn.apparel.Remove(apparel);
                            break;
                        }
                    }
                }));
                FloatMenu menu = new Searchable_FloatMenu(list);

                Find.WindowStack.Add(menu);
            }


            //worn items
            float totalCost = 0;
            int   i         = 0;

            totalCost += (float)Math.Floor(selectedUnit.defaultPawn.def.BaseMarketValue *
                                           FactionColonies.militaryRaceCostMultiplier);

            foreach (Thing thing in selectedUnit.defaultPawn.apparel.WornApparel.Concat(selectedUnit.defaultPawn
                                                                                        .equipment.AllEquipmentListForReading))
            {
                Rect tmp = new Rect(ApparelWornItems.x, ApparelWornItems.y + i * 25, ApparelWornItems.width,
                                    25);
                i++;

                totalCost += thing.MarketValue;

                if (Widgets.CustomButtonText(ref tmp, thing.LabelCap + " Cost: " + thing.MarketValue,
                                             Color.white,
                                             Color.black, Color.black))
                {
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }
            }

            if (selectedUnit.animal != null)
            {
                Widgets.ButtonImage(AnimalCompanion, selectedUnit.animal.race.uiIcon);
                totalCost += (float)Math.Floor(selectedUnit.animal.race.BaseMarketValue *
                                               FactionColonies.militaryAnimalCostMultiplier);
            }

            foreach (Thing thing in selectedUnit.defaultPawn.apparel.WornApparel)
            {
                //Log.Message(thing.Label);


                if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Overhead))
                {
                    Widgets.ButtonImage(ApparelHead, thing.def.uiIcon);
                }

                if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Belt))
                {
                    Widgets.ButtonImage(ApparelBelt, thing.def.uiIcon);
                }

                if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Shell) &&
                    thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso))
                {
                    Widgets.ButtonImage(ApparelTorsoShell, thing.def.uiIcon);
                }

                if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Middle) &&
                    thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso))
                {
                    Widgets.ButtonImage(ApparelTorsoMiddle, thing.def.uiIcon);
                }

                if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) &&
                    thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso))
                {
                    Widgets.ButtonImage(ApparelTorsoSkin, thing.def.uiIcon);
                }

                if (thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) &&
                    thing.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin))
                {
                    Widgets.ButtonImage(ApparelLegs, thing.def.uiIcon);
                }
            }

            foreach (Thing thing in selectedUnit.defaultPawn.equipment.AllEquipmentListForReading)
            {
                Widgets.ButtonImage(EquipmentWeapon, thing.def.uiIcon);
            }

            totalCost = (float)Math.Ceiling(totalCost);
            Widgets.Label(EquipmentTotalCost, "totalEquipmentCostLabel".Translate() + totalCost);
        }
示例#2
0
        private static void DoRightRect(Rect rect, Pawn pawn)
        {
            Widgets.DrawMenuSection(rect);
            if (selectedFaction == null)
            {
                return;
            }
            List <RoyalTitlePermitDef> allDefsListForReading = DefDatabase <RoyalTitlePermitDef> .AllDefsListForReading;
            Rect outRect = rect.ContractedBy(10f);
            Rect rect2   = default(Rect);

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                RoyalTitlePermitDef permit = allDefsListForReading[i];
                if (CanDrawPermit(permit))
                {
                    rect2.width  = Mathf.Max(rect2.width, DrawPosition(permit).x + 200f + 26f);
                    rect2.height = Mathf.Max(rect2.height, DrawPosition(permit).y + 50f + 26f);
                }
            }
            Widgets.BeginScrollView(outRect, ref rightScrollPosition, rect2);
            GUI.BeginGroup(rect2.ContractedBy(10f));
            DrawLines();
            for (int j = 0; j < allDefsListForReading.Count; j++)
            {
                RoyalTitlePermitDef royalTitlePermitDef = allDefsListForReading[j];
                if (CanDrawPermit(royalTitlePermitDef))
                {
                    Vector2 vector  = DrawPosition(royalTitlePermitDef);
                    Rect    rect3   = new Rect(vector.x, vector.y, 200f, 50f);
                    Color   color   = Widgets.NormalOptionColor;
                    Color   bgColor = (PermitUnlocked(royalTitlePermitDef, pawn) ? TexUI.FinishedResearchColor : TexUI.AvailResearchColor);
                    Color   borderColor;
                    if (selectedPermit == royalTitlePermitDef)
                    {
                        borderColor = TexUI.HighlightBorderResearchColor;
                        bgColor    += TexUI.HighlightBgResearchColor;
                    }
                    else
                    {
                        borderColor = TexUI.DefaultBorderResearchColor;
                    }
                    if (!royalTitlePermitDef.AvailableForPawn(pawn, selectedFaction) && !PermitUnlocked(royalTitlePermitDef, pawn))
                    {
                        color = Color.red;
                    }
                    if (Widgets.CustomButtonText(ref rect3, string.Empty, bgColor, color, borderColor))
                    {
                        SoundDefOf.Click.PlayOneShotOnCamera();
                        selectedPermit = royalTitlePermitDef;
                    }
                    TextAnchor anchor = Text.Anchor;
                    Color      color2 = GUI.color;
                    GUI.color   = color;
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(rect3, royalTitlePermitDef.LabelCap);
                    GUI.color   = color2;
                    Text.Anchor = anchor;
                }
            }
            GUI.EndGroup();
            Widgets.EndScrollView();
        }
        public override void DrawTab(Rect rect)
        {
            //set text anchor and font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            Rect SelectionBar  = new Rect(5, 45, 200, 30);
            Rect importButton  = new Rect(5, SelectionBar.y + SelectionBar.height + 10, 200, 30);
            Rect nameTextField = new Rect(5, importButton.y + importButton.height + 10, 250, 30);
            Rect isTrader      = new Rect(5, nameTextField.y + nameTextField.height + 10, 130, 30);

            Rect UnitStandBase      = new Rect(170, 220, 50, 30);
            Rect EquipmentTotalCost = new Rect(350, 50, 450, 40);
            Rect ResetButton        = new Rect(700, 100, 100, 30);
            Rect DeleteButton       = new Rect(ResetButton.x, ResetButton.y + ResetButton.height + 5, ResetButton.width,
                                               ResetButton.height);
            Rect PointRefButton = new Rect(DeleteButton.x, DeleteButton.y + DeleteButton.height + 5, DeleteButton.width,
                                           DeleteButton.height);
            Rect SaveSquadButton = new Rect(DeleteButton.x, PointRefButton.y + DeleteButton.height + 5,
                                            DeleteButton.width, DeleteButton.height);

            //If squad is not selected
            if (Widgets.CustomButtonText(ref SelectionBar, selectedText, Color.gray, Color.white, Color.black))
            {
                //check null
                if (util.squads == null)
                {
                    util.resetSquads();
                }

                List <FloatMenuOption> squads = new List <FloatMenuOption>
                {
                    new FloatMenuOption("Create New Squad", delegate
                    {
                        MilSquadFC newSquad = new MilSquadFC(true)
                        {
                            name = $"New Squad {(util.squads.Count + 1).ToString()}"
                        };
                        selectedText  = newSquad.name;
                        selectedSquad = newSquad;
                        selectedSquad.newSquad();
                        util.squads.Add(newSquad);
                    })
                };

                //Create list of selectable units
                squads.AddRange(util.squads.Select(squad => new FloatMenuOption(squad.name, delegate
                {
                    //Unit is selected
                    selectedText  = squad.name;
                    selectedSquad = squad;
                    selectedSquad.updateEquipmentTotalCost();
                })));
                FloatMenu selection = new Searchable_FloatMenu(squads);
                Find.WindowStack.Add(selection);
            }

            if (Widgets.ButtonText(importButton, "Import Squad"))
            {
                Find.WindowStack.Add(new Dialog_ManageSquadExportsFC(
                                         FactionColoniesMilitary.SavedSquads.ToList()));
            }


            //if squad is selected
            if (selectedSquad != null)
            {
                Text.Anchor = TextAnchor.MiddleLeft;
                Text.Font   = GameFont.Small;

                if (settlementPointReference != null)
                {
                    Widgets.Label(EquipmentTotalCost, "Total Squad Equipment Cost: " +
                                  selectedSquad.equipmentTotalCost +
                                  " / " + FactionColonies
                                  .calculateMilitaryLevelPoints(settlementPointReference
                                                                .settlementMilitaryLevel) +
                                  " (Max Cost)");
                }
                else
                {
                    Widgets.Label(EquipmentTotalCost, "Total Squad Equipment Cost: " +
                                  selectedSquad.equipmentTotalCost +
                                  " / " + "No Reference");
                }

                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.UpperCenter;


                Widgets.CheckboxLabeled(isTrader, "is Trader Caravan", ref selectedSquad.isTraderCaravan);
                selectedSquad.setTraderCaravan(selectedSquad.isTraderCaravan);

                //Unit Name
                selectedSquad.name = Widgets.TextField(nameTextField, selectedSquad.name);

                if (Widgets.ButtonText(ResetButton, "Reset to Default"))
                {
                    selectedSquad.newSquad();
                }

                if (Widgets.ButtonText(DeleteButton, "Delete Squad"))
                {
                    selectedSquad.deleteSquad();
                    util.checkMilitaryUtilForErrors();
                    selectedSquad = null;
                    selectedText  = "Select A Squad";

                    //Reset Text anchor and font
                    Text.Font   = fontBefore;
                    Text.Anchor = anchorBefore;
                    return;
                }

                if (Widgets.ButtonText(PointRefButton, "Set Point Ref"))
                {
                    List <FloatMenuOption> settlementList = Find.World.GetComponent <FactionFC>()
                                                            .settlements.Select(settlement => new FloatMenuOption(settlement.name + " - Military Level : " +
                                                                                                                  settlement.settlementMilitaryLevel,
                                                                                                                  delegate
                    {
                        //set points
                        settlementPointReference = settlement;
                    }))
                                                            .ToList();

                    if (!settlementList.Any())
                    {
                        settlementList.Add(new FloatMenuOption("No Valid Settlements", null));
                    }

                    FloatMenu floatMenu = new FloatMenu(settlementList)
                    {
                        vanishIfMouseDistant = true
                    };
                    Find.WindowStack.Add(floatMenu);
                }

                if (Widgets.ButtonText(SaveSquadButton, "Export Squad"))
                {
                    // TODO: Confirm if squad with name already exists
                    FactionColoniesMilitary.SaveSquad(new SavedSquadFC(selectedSquad));
                    Messages.Message("ExportSquad".Translate(), MessageTypeDefOf.TaskCompletion);
                }

                //for (int k = 0; k < 30; k++)
                //{
                //	Widgets.ButtonImage(new Rect(UnitStandBase.x + (k * 15), UnitStandBase.y + ((k % 5) * 70), 50, 20), texLoad.unitCircle);
                //}


                for (int k = 0; k < 30; k++)
                {
                    if (Widgets.ButtonImage(new Rect(UnitStandBase.x + k % 6 * 80,
                                                     UnitStandBase.y + (k - k % 6) / 5 * 70,
                                                     50, 20), TexLoad.unitCircle))
                    {
                        int click = k;
                        //Option to clear unit slot
                        List <FloatMenuOption> units = new List <FloatMenuOption>
                        {
                            new FloatMenuOption("clearUnitSlot".Translate(), delegate
                            {
                                //Log.Message(selectedSquad.units.Count().ToString());
                                //Log.Message(click.ToString());
                                selectedSquad.units[click] = new MilUnitFC(true);
                                selectedSquad.updateEquipmentTotalCost();
                                selectedSquad.ChangeTick();
                            })
                        };

                        //Create list of selectable units
                        units.AddRange(util.units.Select(unit => new FloatMenuOption(unit.name +
                                                                                     " - Cost: " + unit.equipmentTotalCost, delegate
                        {
                            //Unit is selected
                            selectedSquad.units[click] = unit;
                            selectedSquad.updateEquipmentTotalCost();
                            selectedSquad.ChangeTick();
                        })));

                        FloatMenu selection = new Searchable_FloatMenu(units);
                        Find.WindowStack.Add(selection);
                    }

                    if (selectedSquad.units[k].isBlank)
                    {
                        continue;
                    }
                    if (selectedSquad.units.ElementAt(k).animal != null)
                    {
                        Widgets.ButtonImage(
                            new Rect(UnitStandBase.x + 15 + ((k % 6) * 80), UnitStandBase.y - 45 + (k - k % 6) / 5 * 70,
                                     60, 60), selectedSquad.units.ElementAt(k).animal.race.uiIcon);
                    }

                    Widgets.ThingIcon(
                        new Rect(UnitStandBase.x - 5 + ((k % 6) * 80), UnitStandBase.y - 45 + (k - k % 6) / 5 * 70, 60,
                                 60), selectedSquad.units.ElementAt(k).defaultPawn);
                    if (selectedSquad.units.ElementAt(k).defaultPawn.equipment.AllEquipmentListForReading.Count > 0)
                    {
                        Widgets.ThingIcon(
                            new Rect(UnitStandBase.x - 5 + ((k % 6) * 80), UnitStandBase.y - 15 + (k - k % 6) / 5 * 70,
                                     40, 40),
                            selectedSquad.units.ElementAt(k).defaultPawn.equipment.AllEquipmentListForReading[0]);
                    }

                    Widgets.Label(
                        new Rect(UnitStandBase.x - 15 + ((k % 6) * 80), UnitStandBase.y - 65 + (k - k % 6) / 5 * 70, 80,
                                 60), selectedSquad.units.ElementAt(k).name);
                }

                //Reset Text anchor and font
                Text.Font   = fontBefore;
                Text.Anchor = anchorBefore;
            }

            //Reset Text anchor and font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
示例#4
0
        public override void DrawTab(Rect rect)
        {
            //set text anchor and font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            float projectileBoxHeight     = 30;
            Rect  SelectionBar            = new Rect(5, 45, 200, 30);
            Rect  nameTextField           = new Rect(5, 90, 250, 30);
            Rect  floatRangeAccuracyLabel = new Rect(nameTextField.x, nameTextField.y + nameTextField.height + 5,
                                                     nameTextField.width, (float)(nameTextField.height * 1.5));
            Rect floatRangeAccuracy = new Rect(floatRangeAccuracyLabel.x,
                                               floatRangeAccuracyLabel.y + floatRangeAccuracyLabel.height + 5, floatRangeAccuracyLabel.width,
                                               floatRangeAccuracyLabel.height);


            Rect UnitStandBase     = new Rect(140, 200, 50, 30);
            Rect TotalCost         = new Rect(325, 50, 450, 20);
            Rect numberProjectiles = new Rect(TotalCost.x, TotalCost.y + TotalCost.height + 5, TotalCost.width,
                                              TotalCost.height);
            Rect duration = new Rect(numberProjectiles.x, numberProjectiles.y + numberProjectiles.height + 5,
                                     numberProjectiles.width, numberProjectiles.height);

            Rect ResetButton  = new Rect(700 - 2, 100, 100, 30);
            Rect DeleteButton = new Rect(ResetButton.x, ResetButton.y + ResetButton.height + 5,
                                         ResetButton.width,
                                         ResetButton.height);
            Rect PointRefButton = new Rect(DeleteButton.x, DeleteButton.y + DeleteButton.height + 5,
                                           DeleteButton.width,
                                           DeleteButton.height);


            //Up here to make sure it goes behind other layers
            if (selectedSupport != null)
            {
                DrawFireSupportBox(10, 230, 30);
            }

            Widgets.DrawMenuSection(new Rect(0, 0, 800, 225));

            //If firesupport is not selected
            if (Widgets.CustomButtonText(ref SelectionBar, selectedText, Color.gray, Color.white, Color.black))
            {
                List <FloatMenuOption> supports = new List <FloatMenuOption>();

                //Option to create new firesupport
                supports.Add(new FloatMenuOption("Create New Fire Support", delegate
                {
                    MilitaryFireSupport newFireSupport = new MilitaryFireSupport();
                    newFireSupport.name = "New Fire Support " + (util.fireSupportDefs.Count + 1);
                    newFireSupport.setLoadID();
                    newFireSupport.projectiles = new List <ThingDef>();
                    selectedText    = newFireSupport.name;
                    selectedSupport = newFireSupport;
                    util.fireSupportDefs.Add(newFireSupport);
                }));

                //Create list of selectable firesupports
                foreach (MilitaryFireSupport support in util.fireSupportDefs)
                {
                    supports.Add(new FloatMenuOption(support.name, delegate
                    {
                        //Unit is selected
                        selectedText    = support.name;
                        selectedSupport = support;
                    }));
                }

                FloatMenu selection = new FloatMenuSearchable(supports);
                Find.WindowStack.Add(selection);
            }


            //if firesupport is selected
            if (selectedSupport != null)
            {
                //Need to adjust
                fireSupportMaxScroll =
                    selectedSupport.projectiles.Count * projectileBoxHeight - 10 * projectileBoxHeight;

                Text.Anchor = TextAnchor.MiddleLeft;
                Text.Font   = GameFont.Small;


                if (settlementPointReference != null)
                {
                    Widgets.Label(TotalCost,
                                  "Total Fire Support Silver Cost: " + selectedSupport.returnTotalCost() + " / " +
                                  FactionColonies.calculateMilitaryLevelPoints(settlementPointReference
                                                                               .settlementMilitaryLevel) +
                                  " (Max Cost)");
                }
                else
                {
                    Widgets.Label(TotalCost,
                                  "Total Fire Support Silver Cost: " + selectedSupport.returnTotalCost() + " / " +
                                  "No Reference");
                }

                Widgets.Label(numberProjectiles,
                              "Number of Projectiles: " + selectedSupport.projectiles.Count);
                Widgets.Label(duration,
                              "Duration of fire support: " + Math.Round(selectedSupport.projectiles.Count * .25, 2) +
                              " seconds");
                Widgets.Label(floatRangeAccuracyLabel,
                              selectedSupport.accuracy +
                              " = Accuracy of fire support (In tiles radius): Affecting cost by : " +
                              selectedSupport.returnAccuracyCostPercentage() + "%");
                selectedSupport.accuracy = Widgets.HorizontalSlider(floatRangeAccuracy,
                                                                    selectedSupport.accuracy,
                                                                    Math.Max(3, (15 - Find.World.GetComponent <FactionFC>().returnHighestMilitaryLevel())), 30,
                                                                    roundTo: 1);
                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.UpperCenter;


                //Unit Name
                selectedSupport.name = Widgets.TextField(nameTextField, selectedSupport.name);

                if (Widgets.ButtonText(ResetButton, "Reset to Default"))
                {
                    selectedSupport.projectiles = new List <ThingDef>();
                }

                if (Widgets.ButtonText(DeleteButton, "Delete Support"))
                {
                    selectedSupport.delete();
                    util.checkMilitaryUtilForErrors();
                    selectedSupport = null;
                    selectedText    = "Select A Fire Support";

                    //Reset Text anchor and font
                    Text.Font   = fontBefore;
                    Text.Anchor = anchorBefore;
                    return;
                }

                if (Widgets.ButtonText(PointRefButton, "Set Point Ref"))
                {
                    List <FloatMenuOption> settlementList = new List <FloatMenuOption>();

                    foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements)
                    {
                        settlementList.Add(new FloatMenuOption(
                                               settlement.name + " - Military Level : " + settlement.settlementMilitaryLevel,
                                               delegate
                        {
                            //set points
                            settlementPointReference = settlement;
                        }));
                    }

                    if (!settlementList.Any())
                    {
                        settlementList.Add(new FloatMenuOption("No Valid Settlements", null));
                    }

                    FloatMenu floatMenu = new FloatMenu(settlementList);
                    Find.WindowStack.Add(floatMenu);
                }

                //Reset Text anchor and font
                Text.Font   = fontBefore;
                Text.Anchor = anchorBefore;
            }

            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y, fireSupportMaxScroll);
            }

            //Reset Text anchor and font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
示例#5
0
        //draws the window's contents
        public override void DoWindowContents(Rect inRect)
        {
            //Title
            Rect titleRect = new Rect(inRect);

            titleRect        = titleRect.ContractedBy(17f);
            titleRect.height = 34f;
            titleRect.x     += 34f;
            Text.Font        = GameFont.Medium;
            Widgets.Label(titleRect, this.thing.LabelCapNoCount);
            Rect titleIconRect = new Rect(inRect.x + 9f, titleRect.y, 34f, 34f);

            if (this.thing != null)
            {
                Widgets.ThingIcon(titleIconRect, this.thing, 1f);
            }
            //Inner Rectangle
            Rect innerRect = new Rect(inRect);

            innerRect.yMin  = titleRect.yMax;
            innerRect.yMax -= 34f;
            Widgets.DrawLineVertical(innerRect.x + innerRect.width / 2, innerRect.y, innerRect.height);
            Text.Font = GameFont.Small;
            //Harddrive Info
            Rect harddriveInfo = new Rect(innerRect.x, innerRect.y, innerRect.width / 2 - 17f, innerRect.height);
            Rect cardRect      = new Rect(harddriveInfo);

            cardRect.y   += 34f;
            cardRect.yMax = innerRect.yMax;
            if (selectedHarddrive != null)
            {
                Rect             harddriveInfoTabs = harddriveInfo;
                List <TabRecord> tabs  = new List <TabRecord>();
                TabRecord        stats = new TabRecord("TabStats".Translate(), delegate() {
                    this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Stats;
                }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Stats);
                tabs.Add(stats);
                if (selectedHarddrive.pawn.RaceProps.Humanlike)
                {
                    TabRecord character = new TabRecord("TabCharacter".Translate(), delegate() {
                        this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Character;
                    }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Character);
                    tabs.Add(character);
                }
                TabRecord social = new TabRecord("TabSocial".Translate(), delegate() {
                    this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Social;
                }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Social);
                tabs.Add(social);
                TabRecord needs = new TabRecord("TabNeeds".Translate(), delegate() {
                    this.tab = Neurolink_Dialog_Mainframe.InfoCardTab.Needs;
                }, this.tab == Neurolink_Dialog_Mainframe.InfoCardTab.Needs);
                tabs.Add(needs);
                if (tabs.Count > 1)
                {
                    harddriveInfoTabs.yMin += 45f;
                    TabDrawer.DrawTabs(harddriveInfoTabs, tabs, cardRect.width);
                }
                this.FillInfoTabs(cardRect.ContractedBy(17f));
            }
            //Harddrives
            Rect harddrivesList = new Rect(innerRect.width / 2 + 17f, innerRect.y, innerRect.width / 2 - 17f, innerRect.height);

            Widgets.DrawBoxSolid(harddrivesList, Color.black);
            if (!thing.GetDirectlyHeldThings().NullOrEmpty())
            {
                Thing[] contents = ThingOwnerUtility.GetAllThingsRecursively(thing).ToArray();
                Rect[]  hdRect   = new Rect[contents.Length];
                Color   buttonBgColor;
                string  buttonText = null;
                Widgets.BeginScrollView(harddrivesList, ref this.scrollPosition, harddrivesList, true);                 //%TODO%
                for (int i = 0; i < contents.Length; i++)
                {
                    Pawn pawn = ((Neurolink_Harddrive)contents[i]).pawn;
                    hdRect[i]     = new Rect(harddrivesList.x, harddrivesList.y + 100f * i, harddrivesList.width, 100f);
                    buttonBgColor = Mouse.IsOver(hdRect[i]) ? Color.green : Color.gray;
                    buttonText    = pawn.GetHashCode() + " | " + pawn.Name.ToStringFull + " | " + pawn.story.TitleCap
                                    + " | " + pawn.ageTracker.AgeChronologicalYears;
                    if (Widgets.CustomButtonText(ref hdRect[i], buttonText, buttonBgColor, Color.white, Color.black))
                    {
                        this.selectedHarddrive = (Neurolink_Harddrive)contents.GetValue(i);
                    }
                }
                Widgets.EndScrollView();
            }
            //Simulation %TODO%
        }
示例#6
0
        private void DrawRightRect(Rect rightOutRect)
        {
            rightOutRect.yMin += 32f;
            Widgets.DrawMenuSection(rightOutRect);
            List <TabRecord> list = new List <TabRecord>();

            foreach (ResearchTabDef allDef in DefDatabase <ResearchTabDef> .AllDefs)
            {
                ResearchTabDef localTabDef = allDef;
                list.Add(new TabRecord(localTabDef.LabelCap, delegate
                {
                    CurTab = localTabDef;
                }, CurTab == localTabDef));
            }
            TabDrawer.DrawTabs(rightOutRect, list);
            if (Prefs.DevMode)
            {
                Rect rect = rightOutRect;
                rect.yMax = rect.yMin + 20f;
                rect.xMin = rect.xMax - 80f;
                Rect butRect = rect.RightPartPixels(30f);
                rect = rect.LeftPartPixels(rect.width - 30f);
                Widgets.CheckboxLabeled(rect, "Edit", ref editMode);
                if (Widgets.ButtonImageFitted(butRect, TexButton.Copy))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (ResearchProjectDef item in from def in DefDatabase <ResearchProjectDef> .AllDefsListForReading
                             where def.Debug_IsPositionModified()
                             select def)
                    {
                        stringBuilder.AppendLine(item.defName);
                        stringBuilder.AppendLine(string.Format("  <researchViewX>{0}</researchViewX>", item.ResearchViewX.ToString("F2")));
                        stringBuilder.AppendLine(string.Format("  <researchViewY>{0}</researchViewY>", item.ResearchViewY.ToString("F2")));
                        stringBuilder.AppendLine();
                    }
                    GUIUtility.systemCopyBuffer = stringBuilder.ToString();
                    Messages.Message("Modified data copied to clipboard.", MessageTypeDefOf.SituationResolved, historical: false);
                }
            }
            else
            {
                editMode = false;
            }
            Rect outRect = rightOutRect.ContractedBy(10f);
            Rect rect2   = new Rect(0f, 0f, rightViewWidth, rightViewHeight);
            Rect rect3   = rect2.ContractedBy(10f);

            rect2.width = rightViewWidth;
            rect3       = rect2.ContractedBy(10f);
            Vector2 start = default(Vector2);
            Vector2 end   = default(Vector2);

            Widgets.ScrollHorizontal(outRect, ref rightScrollPosition, rect2);
            Widgets.BeginScrollView(outRect, ref rightScrollPosition, rect2);
            GUI.BeginGroup(rect3);
            List <ResearchProjectDef> allDefsListForReading = DefDatabase <ResearchProjectDef> .AllDefsListForReading;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < allDefsListForReading.Count; j++)
                {
                    ResearchProjectDef researchProjectDef = allDefsListForReading[j];
                    if (researchProjectDef.tab == CurTab)
                    {
                        start.x = PosX(researchProjectDef);
                        start.y = PosY(researchProjectDef) + 25f;
                        for (int k = 0; k < researchProjectDef.prerequisites.CountAllowNull(); k++)
                        {
                            ResearchProjectDef researchProjectDef2 = researchProjectDef.prerequisites[k];
                            if (researchProjectDef2 != null && researchProjectDef2.tab == CurTab)
                            {
                                end.x = PosX(researchProjectDef2) + 140f;
                                end.y = PosY(researchProjectDef2) + 25f;
                                if (selectedProject == researchProjectDef || selectedProject == researchProjectDef2)
                                {
                                    if (i == 1)
                                    {
                                        Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                                    }
                                }
                                else if (i == 0)
                                {
                                    Widgets.DrawLine(start, end, TexUI.DefaultLineResearchColor, 2f);
                                }
                            }
                        }
                    }
                }
            }
            for (int l = 0; l < allDefsListForReading.Count; l++)
            {
                ResearchProjectDef researchProjectDef3 = allDefsListForReading[l];
                if (researchProjectDef3.tab == CurTab)
                {
                    Rect   source    = new Rect(PosX(researchProjectDef3), PosY(researchProjectDef3), 140f, 50f);
                    string label     = GetLabel(researchProjectDef3);
                    Rect   rect4     = new Rect(source);
                    Color  textColor = Widgets.NormalOptionColor;
                    Color  color     = default(Color);
                    Color  color2    = default(Color);
                    bool   flag      = !researchProjectDef3.IsFinished && !researchProjectDef3.CanStartNow;
                    if (researchProjectDef3 == Find.ResearchManager.currentProj)
                    {
                        color = TexUI.ActiveResearchColor;
                    }
                    else if (researchProjectDef3.IsFinished)
                    {
                        color = TexUI.FinishedResearchColor;
                    }
                    else if (flag)
                    {
                        color = TexUI.LockedResearchColor;
                    }
                    else if (researchProjectDef3.CanStartNow)
                    {
                        color = TexUI.AvailResearchColor;
                    }
                    if (selectedProject == researchProjectDef3)
                    {
                        color += TexUI.HighlightBgResearchColor;
                        color2 = TexUI.HighlightBorderResearchColor;
                    }
                    else
                    {
                        color2 = TexUI.DefaultBorderResearchColor;
                    }
                    if (flag)
                    {
                        textColor = ProjectWithMissingPrerequisiteLabelColor;
                    }
                    for (int m = 0; m < researchProjectDef3.prerequisites.CountAllowNull(); m++)
                    {
                        ResearchProjectDef researchProjectDef4 = researchProjectDef3.prerequisites[m];
                        if (researchProjectDef4 != null && selectedProject == researchProjectDef4)
                        {
                            color2 = TexUI.HighlightLineResearchColor;
                        }
                    }
                    if (requiredByThisFound)
                    {
                        for (int n = 0; n < researchProjectDef3.requiredByThis.CountAllowNull(); n++)
                        {
                            ResearchProjectDef researchProjectDef5 = researchProjectDef3.requiredByThis[n];
                            if (selectedProject == researchProjectDef5)
                            {
                                color2 = TexUI.HighlightLineResearchColor;
                            }
                        }
                    }
                    if (Widgets.CustomButtonText(ref rect4, label, color, textColor, color2, cacheHeight: true))
                    {
                        SoundDefOf.Click.PlayOneShotOnCamera();
                        selectedProject = researchProjectDef3;
                    }
                    if (editMode && Mouse.IsOver(rect4) && Input.GetMouseButtonDown(0))
                    {
                        draggingTab = researchProjectDef3;
                    }
                }
            }
            GUI.EndGroup();
            Widgets.EndScrollView();
            if (!Input.GetMouseButton(0))
            {
                draggingTab = null;
            }
            if (draggingTab != null && !Input.GetMouseButtonDown(0) && Event.current.type == EventType.Layout)
            {
                ResearchProjectDef researchProjectDef6 = draggingTab;
                Vector2            delta = Event.current.delta;
                float   x      = PixelsToCoordX(delta.x);
                Vector2 delta2 = Event.current.delta;
                researchProjectDef6.Debug_ApplyPositionDelta(new Vector2(x, PixelsToCoordY(delta2.y)));
            }
        }
        private void DrawRightRect(Rect rightOutRect)
        {
            rightOutRect.yMin += 32f;
            Widgets.DrawMenuSection(rightOutRect);
            List <TabRecord> list = new List <TabRecord>();

            foreach (ResearchTabDef allDef in DefDatabase <ResearchTabDef> .AllDefs)
            {
                ResearchTabDef localTabDef = allDef;
                list.Add(new TabRecord(localTabDef.LabelCap, delegate
                {
                    this.CurTab = localTabDef;
                }, this.CurTab == localTabDef));
            }
            TabDrawer.DrawTabs(rightOutRect, list);
            Rect outRect = rightOutRect.ContractedBy(10f);
            Rect rect    = new Rect(0f, 0f, this.rightViewWidth, this.rightViewHeight);
            Rect rect2   = rect.ContractedBy(10f);

            rect.width = this.rightViewWidth;
            rect2      = rect.ContractedBy(10f);
            Vector2 start = default(Vector2);
            Vector2 end   = default(Vector2);

            Widgets.ScrollHorizontal(outRect, ref this.rightScrollPosition, rect, 20f);
            Widgets.BeginScrollView(outRect, ref this.rightScrollPosition, rect, true);
            GUI.BeginGroup(rect2);
            List <ResearchProjectDef> allDefsListForReading = DefDatabase <ResearchProjectDef> .AllDefsListForReading;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < allDefsListForReading.Count; j++)
                {
                    ResearchProjectDef researchProjectDef = allDefsListForReading[j];
                    if (researchProjectDef.tab == this.CurTab)
                    {
                        start.x = this.PosX(researchProjectDef);
                        start.y = (float)(this.PosY(researchProjectDef) + 25.0);
                        for (int k = 0; k < researchProjectDef.prerequisites.CountAllowNull(); k++)
                        {
                            ResearchProjectDef researchProjectDef2 = researchProjectDef.prerequisites[k];
                            if (researchProjectDef2 != null && researchProjectDef2.tab == this.CurTab)
                            {
                                end.x = (float)(this.PosX(researchProjectDef2) + 140.0);
                                end.y = (float)(this.PosY(researchProjectDef2) + 25.0);
                                if (this.selectedProject == researchProjectDef || this.selectedProject == researchProjectDef2)
                                {
                                    if (i == 1)
                                    {
                                        Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                                    }
                                }
                                else if (i == 0)
                                {
                                    Widgets.DrawLine(start, end, TexUI.DefaultLineResearchColor, 2f);
                                }
                            }
                        }
                    }
                }
            }
            for (int l = 0; l < allDefsListForReading.Count; l++)
            {
                ResearchProjectDef researchProjectDef3 = allDefsListForReading[l];
                if (researchProjectDef3.tab == this.CurTab)
                {
                    Rect   source    = new Rect(this.PosX(researchProjectDef3), this.PosY(researchProjectDef3), 140f, 50f);
                    string label     = this.GetLabel(researchProjectDef3);
                    Rect   rect3     = new Rect(source);
                    Color  textColor = Widgets.NormalOptionColor;
                    Color  color     = default(Color);
                    Color  color2    = default(Color);
                    bool   flag      = !researchProjectDef3.IsFinished && !researchProjectDef3.CanStartNow;
                    if (researchProjectDef3 == Find.ResearchManager.currentProj)
                    {
                        color = TexUI.ActiveResearchColor;
                    }
                    else if (researchProjectDef3.IsFinished)
                    {
                        color = TexUI.FinishedResearchColor;
                    }
                    else if (flag)
                    {
                        color = TexUI.LockedResearchColor;
                    }
                    else if (researchProjectDef3.CanStartNow)
                    {
                        color = TexUI.AvailResearchColor;
                    }
                    if (this.selectedProject == researchProjectDef3)
                    {
                        color += TexUI.HighlightBgResearchColor;
                        color2 = TexUI.HighlightBorderResearchColor;
                    }
                    else
                    {
                        color2 = TexUI.DefaultBorderResearchColor;
                    }
                    if (flag)
                    {
                        textColor = MainTabWindow_Research.ProjectWithMissingPrerequisiteLabelColor;
                    }
                    for (int m = 0; m < researchProjectDef3.prerequisites.CountAllowNull(); m++)
                    {
                        ResearchProjectDef researchProjectDef4 = researchProjectDef3.prerequisites[m];
                        if (researchProjectDef4 != null && this.selectedProject == researchProjectDef4)
                        {
                            color2 = TexUI.HighlightLineResearchColor;
                        }
                    }
                    if (this.requiredByThisFound)
                    {
                        for (int n = 0; n < researchProjectDef3.requiredByThis.CountAllowNull(); n++)
                        {
                            ResearchProjectDef researchProjectDef5 = researchProjectDef3.requiredByThis[n];
                            if (this.selectedProject == researchProjectDef5)
                            {
                                color2 = TexUI.HighlightLineResearchColor;
                            }
                        }
                    }
                    if (Widgets.CustomButtonText(ref rect3, label, color, textColor, color2, true, 1, true, true))
                    {
                        SoundDefOf.Click.PlayOneShotOnCamera(null);
                        this.selectedProject = researchProjectDef3;
                    }
                }
            }
            GUI.EndGroup();
            Widgets.EndScrollView();
        }
        private void DrawRightRect(Rect rightOutRect)
        {
            rightOutRect.yMin += 32f;
            Widgets.DrawMenuSection(rightOutRect);
            TabDrawer.DrawTabs(rightOutRect, tabs);
            if (Prefs.DevMode)
            {
                Rect rect = rightOutRect;
                rect.yMax = rect.yMin + 20f;
                rect.xMin = rect.xMax - 80f;
                Rect butRect = rect.RightPartPixels(30f);
                rect = rect.LeftPartPixels(rect.width - 30f);
                Widgets.CheckboxLabeled(rect, "Edit", ref editMode);
                if (Widgets.ButtonImageFitted(butRect, TexButton.Copy))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (ResearchProjectDef item in DefDatabase <ResearchProjectDef> .AllDefsListForReading.Where((ResearchProjectDef def) => def.Debug_IsPositionModified()))
                    {
                        stringBuilder.AppendLine(item.defName);
                        stringBuilder.AppendLine(string.Format("  <researchViewX>{0}</researchViewX>", item.ResearchViewX.ToString("F2")));
                        stringBuilder.AppendLine(string.Format("  <researchViewY>{0}</researchViewY>", item.ResearchViewY.ToString("F2")));
                        stringBuilder.AppendLine();
                    }
                    GUIUtility.systemCopyBuffer = stringBuilder.ToString();
                    Messages.Message("Modified data copied to clipboard.", MessageTypeDefOf.SituationResolved, historical: false);
                }
            }
            else
            {
                editMode = false;
            }
            bool flag    = false;
            Rect outRect = rightOutRect.ContractedBy(10f);
            Rect rect2   = new Rect(0f, 0f, rightViewWidth, rightViewHeight);

            rect2.ContractedBy(10f);
            rect2.width = rightViewWidth;
            Rect    position = rect2.ContractedBy(10f);
            Vector2 start    = default(Vector2);
            Vector2 end      = default(Vector2);

            Widgets.ScrollHorizontal(outRect, ref rightScrollPosition, rect2);
            Widgets.BeginScrollView(outRect, ref rightScrollPosition, rect2);
            GUI.BeginGroup(position);
            List <ResearchProjectDef> allDefsListForReading = DefDatabase <ResearchProjectDef> .AllDefsListForReading;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < allDefsListForReading.Count; j++)
                {
                    ResearchProjectDef researchProjectDef = allDefsListForReading[j];
                    if (researchProjectDef.tab != CurTab)
                    {
                        continue;
                    }
                    start.x = PosX(researchProjectDef);
                    start.y = PosY(researchProjectDef) + 25f;
                    for (int k = 0; k < researchProjectDef.prerequisites.CountAllowNull(); k++)
                    {
                        ResearchProjectDef researchProjectDef2 = researchProjectDef.prerequisites[k];
                        if (researchProjectDef2 == null || researchProjectDef2.tab != CurTab)
                        {
                            continue;
                        }
                        end.x = PosX(researchProjectDef2) + 140f;
                        end.y = PosY(researchProjectDef2) + 25f;
                        if (selectedProject == researchProjectDef || selectedProject == researchProjectDef2)
                        {
                            if (i == 1)
                            {
                                Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                            }
                        }
                        else if (i == 0)
                        {
                            Widgets.DrawLine(start, end, TexUI.DefaultLineResearchColor, 2f);
                        }
                    }
                }
            }
            Rect other = new Rect(rightScrollPosition.x, rightScrollPosition.y, outRect.width, outRect.height).ExpandedBy(10f);

            for (int l = 0; l < allDefsListForReading.Count; l++)
            {
                ResearchProjectDef researchProjectDef3 = allDefsListForReading[l];
                if (researchProjectDef3.tab != CurTab)
                {
                    continue;
                }
                Rect   source = new Rect(PosX(researchProjectDef3), PosY(researchProjectDef3), 140f, 50f);
                Rect   rect3  = new Rect(source);
                string label  = GetLabel(researchProjectDef3);
                Widgets.LabelCacheHeight(ref rect3, GetLabelWithNewlineCached(label));
                if (!rect3.Overlaps(other))
                {
                    continue;
                }
                Color color   = Widgets.NormalOptionColor;
                Color bgColor = default(Color);
                Color color2  = default(Color);
                bool  flag2   = !researchProjectDef3.IsFinished && !researchProjectDef3.CanStartNow;
                if (researchProjectDef3 == Find.ResearchManager.currentProj)
                {
                    bgColor = TexUI.ActiveResearchColor;
                }
                else if (researchProjectDef3.IsFinished)
                {
                    bgColor = TexUI.FinishedResearchColor;
                }
                else if (flag2)
                {
                    bgColor = TexUI.LockedResearchColor;
                }
                else if (researchProjectDef3.CanStartNow)
                {
                    bgColor = TexUI.AvailResearchColor;
                }
                if (editMode && draggingTabs.Contains(researchProjectDef3))
                {
                    color2 = Color.yellow;
                }
                else if (selectedProject == researchProjectDef3)
                {
                    bgColor += TexUI.HighlightBgResearchColor;
                    color2   = TexUI.HighlightBorderResearchColor;
                }
                else
                {
                    color2 = TexUI.DefaultBorderResearchColor;
                }
                if (flag2)
                {
                    color = ProjectWithMissingPrerequisiteLabelColor;
                }
                if (selectedProject != null)
                {
                    if ((researchProjectDef3.prerequisites != null && researchProjectDef3.prerequisites.Contains(selectedProject)) || (researchProjectDef3.hiddenPrerequisites != null && researchProjectDef3.hiddenPrerequisites.Contains(selectedProject)))
                    {
                        color2 = TexUI.HighlightLineResearchColor;
                    }
                    if (!researchProjectDef3.IsFinished && ((selectedProject.prerequisites != null && selectedProject.prerequisites.Contains(researchProjectDef3)) || (selectedProject.hiddenPrerequisites != null && selectedProject.hiddenPrerequisites.Contains(researchProjectDef3))))
                    {
                        color2 = TexUI.DependencyOutlineResearchColor;
                    }
                }
                if (requiredByThisFound)
                {
                    for (int m = 0; m < researchProjectDef3.requiredByThis.CountAllowNull(); m++)
                    {
                        ResearchProjectDef researchProjectDef4 = researchProjectDef3.requiredByThis[m];
                        if (selectedProject == researchProjectDef4)
                        {
                            color2 = TexUI.HighlightLineResearchColor;
                        }
                    }
                }
                Rect rect4 = rect3;
                Widgets.LabelCacheHeight(ref rect4, " ");
                if (Widgets.CustomButtonText(ref rect3, "", bgColor, color, color2))
                {
                    SoundDefOf.Click.PlayOneShotOnCamera();
                    selectedProject = researchProjectDef3;
                }
                rect4.y = rect3.y + rect3.height - rect4.height;
                Rect rect5 = rect4;
                rect5.x    += 10f;
                rect5.width = rect5.width / 2f - 10f;
                Rect rect6 = rect5;
                rect6.x += rect5.width;
                TextAnchor anchor = Text.Anchor;
                Color      color3 = GUI.color;
                GUI.color   = color;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, label);
                GUI.color   = color;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(rect5, researchProjectDef3.CostApparent.ToString());
                if (researchProjectDef3.techprintCount > 0)
                {
                    GUI.color   = (researchProjectDef3.TechprintRequirementMet ? FulfilledPrerequisiteColor : MissingPrerequisiteColor);
                    Text.Anchor = TextAnchor.MiddleRight;
                    Widgets.Label(rect6, GetTechprintsInfoCached(researchProjectDef3.TechprintsApplied, researchProjectDef3.techprintCount));
                }
                GUI.color   = color3;
                Text.Anchor = anchor;
                if (!editMode || !Mouse.IsOver(rect3) || !Input.GetMouseButtonDown(0))
                {
                    continue;
                }
                flag = true;
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    if (!draggingTabs.Contains(researchProjectDef3))
                    {
                        draggingTabs.Add(researchProjectDef3);
                    }
                }
                else if (!Input.GetKey(KeyCode.LeftControl) && !draggingTabs.Contains(researchProjectDef3))
                {
                    draggingTabs.Clear();
                    draggingTabs.Add(researchProjectDef3);
                }
                if (Input.GetKey(KeyCode.LeftControl) && draggingTabs.Contains(researchProjectDef3))
                {
                    draggingTabs.Remove(researchProjectDef3);
                }
            }
            GUI.EndGroup();
            Widgets.EndScrollView();
            if (!editMode)
            {
                return;
            }
            if (!flag && Input.GetMouseButtonDown(0))
            {
                draggingTabs.Clear();
            }
            if (draggingTabs.NullOrEmpty())
            {
                return;
            }
            if (Input.GetMouseButtonUp(0))
            {
                for (int n = 0; n < draggingTabs.Count; n++)
                {
                    draggingTabs[n].Debug_SnapPositionData();
                }
            }
            else if (Input.GetMouseButton(0) && !Input.GetMouseButtonDown(0) && Event.current.type == EventType.Layout)
            {
                for (int num = 0; num < draggingTabs.Count; num++)
                {
                    draggingTabs[num].Debug_ApplyPositionDelta(new Vector2(PixelsToCoordX(Event.current.delta.x), PixelsToCoordY(Event.current.delta.y)));
                }
            }
        }
示例#9
0
        /******************************************************************************************
        *
        * DrawRightRect Prefix
        *
        * Heavily edited copy/paste from decompiled original
        *
        *
        ******************************************************************************************/
        void DrawRightRect(Rect rightOutRect)
        {
            _relevantProjects = relevantProjectsField.GetValue <List <ResearchProjectDef> >();
            _selectedProject  = selectedProjectField.GetValue <ResearchProjectDef>();

            float viewWidth = _layering.maxX * LayerWidth;

            Rect outRect  = rightOutRect.ContractedBy(10f);
            Rect rect     = new Rect(0f, 0f, viewWidth, outRect.height - 16f);
            Rect position = rect.ContractedBy(10f);

            rect.width = viewWidth;
            position   = rect.ContractedBy(10f);
            Widgets.ScrollHorizontal(outRect, ref _ScrollPosition, rect);
            Widgets.BeginScrollView(outRect, ref _ScrollPosition, rect);
            GUI.BeginGroup(position);

            //DEBUG
            //if (debuggin)
            //{
            //    Log.Message("relevant projects: " + _relevantProjects.Count);
            //    Log.Message("vertices: " + _layering.vertices.Count);
            //    debuggin = false;
            //}

            Vector2 start;
            Vector2 end;

            // draws the relationship lines
            foreach (Vertex v in _layering.vertices)
            {
                foreach (Vertex vParent in v.parents)
                {
                    start.x = v.x * LayerWidth;
                    start.y = v.y * LayerHeight + (VertexHeight / 2f);
                    end.x   = vParent.x * LayerWidth + VertexWidth;
                    end.y   = vParent.y * LayerHeight + VertexHeight / 2f;
                    Widgets.DrawLine(start, end, TexUI.DefaultLineResearchColor, 2f);
                    if (vParent.isDummy)
                    {
                        start.x = end.x - VertexWidth;
                        start.y = end.y;
                        Widgets.DrawLine(start, end, TexUI.DefaultLineResearchColor, 2f);
                    }
                }
            }

            // draw highlighted lines for selected project
            if (_selectedProject != null)
            {
                Vertex selected = _layering.MapProjectVertex[_selectedProject];
                DrawChildrenEdges(selected);
                DrawParentEdges(selected);
            }

            //draws each project box
            foreach (Vertex v in _layering.vertices)
            {
                if (v.isDummy)
                {
                    continue;
                }
                Rect   source      = new Rect(v.x * LayerWidth, v.y * LayerHeight, VertexWidth, VertexHeight);
                string label       = v.project.LabelCap + "\n(" + v.project.CostApparent.ToString("F0") + ")";
                Rect   rect2       = new Rect(source);
                Color  textColor   = Widgets.NormalOptionColor;
                Color  color       = default(Color);
                Color  borderColor = default(Color);
                bool   flag        = !v.project.IsFinished && !v.project.CanStartNow;
                if (v.project == Find.ResearchManager.currentProj)
                {
                    color = TexUI.ActiveResearchColor;
                }
                else if (v.project.IsFinished)
                {
                    color = TexUI.FinishedResearchColor;
                }
                else if (flag)
                {
                    color = TexUI.LockedResearchColor;
                }
                else if (v.project.CanStartNow)
                {
                    color = TexUI.AvailResearchColor;
                }
                if (_selectedProject == v.project)
                {
                    color      += TexUI.HighlightBgResearchColor;
                    borderColor = TexUI.HighlightBorderResearchColor;
                }
                else
                {
                    borderColor = TexUI.DefaultBorderResearchColor;
                }

                if (flag)
                {
                    textColor = Color.gray;
                }
                foreach (Vertex vParent in v.parents)
                {
                    if (vParent != null && _selectedProject == vParent.project)
                    {
                        borderColor = TexUI.HighlightLineResearchColor;
                    }
                }
                foreach (Vertex vChild in v.children)
                {
                    if (_selectedProject == vChild.project)
                    {
                        borderColor = TexUI.HighlightLineResearchColor;
                    }
                }

                if (Widgets.CustomButtonText(ref rect2, label, color, textColor, borderColor, true, 1, true, true))
                {
                    SoundDefOf.Click.PlayOneShotOnCamera();
                    selectedProjectField.SetValue(v.project);
                }
            }
            GUI.EndGroup();
            Widgets.EndScrollView();
        }