コード例 #1
0
        private void DoCategories(Rect rect)
        {
            var vGrid = rect.GetVGrid(4f, 0f, 30f);

            _categoryList.Begin(vGrid[0]);

            foreach (var category in _template.Categories)
            {
                var state = category.GetListState();

                if (_presetList.EditMode)
                {
                    _categoryList.CheckboxPartial(category.Label, ref state);
                    category.UpdateState(state);
                    continue;
                }

                if ((_type == RestrictionType.Food) && (_rules.Pawn != null) && !category.Members.Any(member => _rules.Pawn.RaceProps.CanEverEat((ThingDef)member.Def)))
                {
                    continue;
                }

                GUI.color = GuiPlus.ReadOnlyColor;
                _categoryList.CheckboxPartial(category.Label, ref state);
                GUI.color = _color;
            }
            _categoryList.End();

            if (!_presetList.EditMode)
            {
                return;
            }

            var hGrid = vGrid[1].GetHGrid(4f, 0f, 0f);

            _categoryList.Begin(hGrid[0]);
            if (_categoryList.ButtonText(Lang.Get("Button.RestrictionsAllowOn")))
            {
                _template.ToggleAll(true);
            }
            _categoryList.End();
            _categoryList.Begin(hGrid[1]);
            if (_categoryList.ButtonText(Lang.Get("Button.RestrictionsAllowOff")))
            {
                _template.ToggleAll(false);
            }
            _categoryList.End();
        }
コード例 #2
0
        private void DoCategories(Rect categoriesRect, Rect membersRect)
        {
            var vGrid = categoriesRect.GetVGrid(4f, -1f, 30f);

            _categoryList.Begin(vGrid[1], true);

            var members = new Dictionary <string, RestrictionTemplate.Toggle[]>();

            foreach (var category in _template.Categories)
            {
                var state = category.GetListState();

                var showAll = _presetList.EditMode || (_rules.Pawn == null);
                if (_type == RestrictionType.Food)
                {
                    members[category.Label] = category.Members.Where(member => member.Def is ThingDef def && (!def.IsDrug || Registry.AllowDrugsRestriction) && (showAll || _rules.Pawn.RaceProps.CanEverEat(def))).ToArray();
                }
                else if (_type == RestrictionType.Bonding)
                {
                    members[category.Label] = category.Members.ToArray();
                }
                else
                {
                    throw new Mod.Exception("Unsupported restriction type");
                }

                if (members[category.Label].Length == 0)
                {
                    continue;
                }

                if (_presetList.EditMode)
                {
                    _categoryList.CheckboxPartial(category.Label, ref state);
                    category.UpdateState(state);
                }
                else
                {
                    GUI.color = GuiPlus.ReadOnlyColor;
                    _categoryList.CheckboxPartial(category.Label, ref state);
                    GUI.color = _color;
                }
            }

            _membersList.Gap();
            _categoryList.End();

            if (!_presetList.EditMode)
            {
                DoMembers(membersRect, members);
                return;
            }

            var hGrid           = vGrid[2].GetHGrid(4f, -1f, -1f);
            var categoryButtons = new Listing_Standard();

            categoryButtons.Begin(hGrid[1]);
            if (categoryButtons.ButtonText(Lang.Get("Button.RestrictionsAllowOn")))
            {
                _template.ToggleAll(true);
            }
            categoryButtons.End();
            categoryButtons.Begin(hGrid[2]);
            if (categoryButtons.ButtonText(Lang.Get("Button.RestrictionsAllowOff")))
            {
                _template.ToggleAll(false);
            }
            categoryButtons.End();

            DoMembers(membersRect, members);
        }