public static bool isRelatedTo(UnitHuman source, UnitHuman other)
 {
     return source == All
         || (source == Crafter && CrafterList.Contains(other))
         || (source == Military && MilitaryList.Contains(other))
         || source == other;
 }
        private static List<UnitPreference> getPreferences(UnitHuman unitType)
        {
            typePreferences.Clear();

            foreach (UnitPreference preference in List)
            {
                if (UnitHuman.isRelatedTo(preference.unitType, unitType))
                {
                    typePreferences.Add(preference);
                }
            }

            return typePreferences;
        }
 private UnitPreference(String preferenceName, String description, UnitHuman unitType)
 {
     this.preferenceName = preferenceName;
     this.description = description;
     this.unitType = unitType;
 }
        public override void OnDraw(int windowId)
        {
            Window(this.title);

            CheckBox(sectionMain.ControlMargin, WINDOW_TITLE_HEIGHT + sectionMain.ControlMargin + sectionMain.ControlPadding,
                sectionMain.ControlWidth / 2, sectionMain.ControlHeight, "Creative", ref modSettings.isCreativeEnabled);

            sectionMain.Begin(0, WINDOW_TITLE_HEIGHT + sectionMain.ControlHeight + sectionMain.ControlPadding, this.width, this.height - WINDOW_TITLE_HEIGHT - sectionMain.ControlHeight);

            if (isMouseHover || isDesigning || isSelectingUnitType || isLivingEntitySelected)
            {
                if (isMouseHover && !isSelecting && !isDesigning && !isSelectingUnitType && !isLivingEntitySelected)
                {
                    if (Time.timeSinceLevelLoad > 12f)
                    {
                        sectionMain.Button("Save Game", ref doSaveGame);
                        if (!modSettings.isAutoBackupsEnabled)
                        {
                            sectionMain.Button("Save Backup", ref doSaveBackup);
                        }
                    }
                }

                if (modSettings.isCreativeEnabled)
                {
                    if (isSelectingHumanType && !isPlacingHuman)
                    {
                        sectionMain.LabelCentered("Player Units");
                    }
                    else if (isSelectingEnemyType && !isPlacingEnemy)
                    {
                        sectionMain.LabelCentered("Enemy Units");
                    }
                    else if (isSelectingAnimalType && !isPlacingAnimal)
                    {
                        sectionMain.LabelCentered("Animal Units");
                    }
                    else if (isPlacingHuman)
                    {
                        sectionMain.LabelCentered(selectedUnitType.Name);
                        sectionMain.LabelCentered(getKeyString(KEY_BUILD) + " To Place");
                    }
                    else if (isPlacingEnemy)
                    {
                        sectionMain.LabelCentered("Enemy: " + selectedEnemyType.Name);
                        sectionMain.LabelCentered(getKeyString(KEY_BUILD) + " To Place");
                    }
                    else if (isPlacingAnimal)
                    {
                        sectionMain.LabelCentered("Animal: " + selectedAnimalType.Name);
                        sectionMain.LabelCentered(getKeyString(KEY_BUILD) + " To Place");
                    }
                    else if (isBuilding)
                    {
                        if (isSelecting)
                        {
                            if (Input.GetKey(KEY_BUILD))
                            {
                                sectionMain.LabelCentered("Replacing");
                            }
                            else if (Input.GetKey(KEY_PICK_BLOCK))
                            {
                                sectionMain.LabelCentered("Smoothing");
                            }
                            else
                            {
                                sectionMain.LabelCentered("Hold " + getKeyString(KEY_BUILD) + " to Replace");
                                sectionMain.LabelCentered("Hold " + getKeyString(KEY_PICK_BLOCK) + " to Smooth");
                            }
                        }
                        else if (isDesigning)
                        {
                            sectionMain.LabelCentered(controlPlayer.buildingMaterial.getName());
                        }
                    }
                    else if (isChopping)
                    {
                        sectionMain.LabelCentered(getKeyString(KEY_BUILD) + " Place Tree");
                        sectionMain.LabelCentered(getKeyString(KEY_PICK_BLOCK) + " Place Shrub");
                        sectionMain.Button("Remove All Trees", ref doRemoveAllTrees);
                    }
                    else if (isLivingEntitySelected)
                    {
                        if (isPlayableUnitSelected && UnitService.isFriendly(selectedEntity))
                        {
                            sectionMain.LabelCentered(selectedUnit.getProfession().getProfessionName());

                            if (selectedUnit.isAlive())
                            {
                                if (sectionMain.NumberSelect("Level: ", selectedUnit.getProfession().getLevel(), out newLevelValue,
                                    increment: Input.GetKey(KeyCode.LeftShift) ? 5 : 1, min: 1, max: AProfession.maxLevel, showMinMax: true))
                                {
                                    selectedUnit.getProfession().setLevel(newLevelValue);
                                }

                                sectionMain.LabelCentered("Traits");
                                sectionScroll.Background(guiManager.windowBoxStyle);
                            }
                        }
                        else
                        {
                            sectionMain.LabelCentered(selectedEntity.unitName);
                            drawSelectedUnitButtons();
                        }
                    }
                    else if (!isSelecting && !isDesigning && !isSelectingUnitType)
                    {
                        if (sectionMain.Button("Add Player Units"))
                        {
                            isSelectingHumanType = true;
                        }

                        if (!modSettings.isPeacefulEnabled)
                        {
                            if (sectionMain.Button("Add Enemy Units"))
                            {
                                isSelectingEnemyType = true;
                            }
                        }

                        if (sectionMain.Button("Add Animal Units"))
                        {
                            isSelectingAnimalType = true;
                        }
                    }

                    if (isSelecting)
                    {
                        if (!isScrollOverride)
                        {
                            guiManager.mouseInGUI = isMouseInGUIOverride;
                        }
                    }
                }
            }

            sectionScroll.Begin(0, sectionMain.ControlYPosition - sectionScroll.ControlMargin, this.ParentContainer.width, sectionMain.ControlHeight * 10);

            if (isMouseHover || isDesigning || isSelectingUnitType || isLivingEntitySelected)
            {
                if (modSettings.isCreativeEnabled)
                {
                    if (isPlayableUnitSelected && UnitService.isFriendly(selectedUnit))
                    {
                        if (selectedUnit.isAlive())
                        {
                            foreach (IUnitSettingCollectionItem item in UnitTrait.List)
                            {
                                sectionScroll.CheckBox(item.Description, ref playerUnitTraitSettings.getSetting(item).Enabled, ref doSetPlayerUnitSettings);
                            }
                        }
                    }
                    else if (isSelectingHumanType && !isPlacingHuman)
                    {
                        //Place Human List
                        foreach (UnitHuman profession in UnitHuman.List)
                        {
                            if (sectionScroll.Button(profession.Name))
                            {
                                selectedUnitType = profession;
                                isPlacingHuman = true;
                            }
                        }
                    }
                    else if (isSelectingEnemyType && !isPlacingEnemy)
                    {
                        //Place Enemy List
                        foreach (UnitEnemy enemyType in UnitEnemy.List)
                        {
                            if (sectionScroll.Button(enemyType.Name))
                            {
                                selectedEnemyType = enemyType;
                                isPlacingEnemy = true;
                            }
                        }
                    }
                    else if (isSelectingAnimalType && !isPlacingAnimal)
                    {
                        //Place Animal List
                        foreach (UnitAnimal animalType in UnitAnimal.List)
                        {
                            if (sectionScroll.Button(animalType.Name))
                            {
                                selectedAnimalType = animalType;
                                isPlacingAnimal = true;
                            }
                        }
                    }
                    else if (isDesigning && !isSelecting)
                    {
                        if (isBuilding)
                        {
                            foreach (BlockProperties properties in availableBlockTypes)
                            {
                                if (sectionScroll.Button(properties.getName()))
                                {
                                    updateControlPlayerBlockProperties(properties);
                                }
                            }
                        }
                    }
                }
            }

            sectionScroll.End();

            if (sectionScroll.hasChildren)
            {
                sectionMain.addSection(sectionScroll);
            }

            if (isMouseHover || isDesigning || isSelectingUnitType || isLivingEntitySelected)
            {
                if (modSettings.isCreativeEnabled)
                {
                    if (isPlayableUnitSelected && UnitService.isFriendly(selectedUnit))
                    {
                        drawSelectedUnitButtons();
                    }
                }
            }

            sectionMain.End();

            if (sectionMain.hasChildren)
            {
                this.containerHeight = sectionMain.ControlYPosition + sectionMain.ControlMargin;
            }
            else this.containerHeight = sectionMain.ControlYPosition;
        }