Esempio n. 1
0
        protected override void DoContent(Rect rect)
        {
            var listing = new Listing_StandardPlus();

            listing.Begin(rect);
            listing.Label(_label);
            GUI.SetNextControlName("NameField");
            _name = listing.TextEntry(_name);
            UI.FocusControl("NameField", this);
            listing.Gap();
            listing.End();

            var grid = rect.AdjustedBy(0f, listing.CurHeight, 0f, -listing.CurHeight).GetHGrid(4f, -1f, -1f);

            listing.Begin(grid[1]);
            if (listing.ButtonText(Lang.Get("Button.OK"), null, NameIsValid()))
            {
                CommitName();
            }
            listing.End();

            listing.Begin(grid[2]);
            if (listing.ButtonText(Lang.Get("Button.Cancel")))
            {
                Close();
            }
            listing.End();
        }
Esempio n. 2
0
        public override void DoContent(Rect rect)
        {
            var listing = new Listing_StandardPlus();

            listing.Begin(rect);
            listing.Label(Lang.Get("Dialog_PresetName.Label"));
            GUI.SetNextControlName("RenameField");
            _name = listing.TextEntry(_name);
            var valid = NameIsValid();

            if (!_focused)
            {
                UI.FocusControl("RenameField", this);
                _focused = true;
            }
            listing.Gap();
            listing.End();

            var grid = rect.AdjustedBy(0f, listing.CurHeight, 0f, -listing.CurHeight).GetHGrid(4f, 0f, 0f);

            listing.Begin(grid[0]);
            if (listing.ButtonText(Lang.Get("Button.OK"), null, valid))
            {
                CommitName();
                Close();
            }
            listing.End();

            listing.Begin(grid[1]);
            if (listing.ButtonText(Lang.Get("Button.Cancel")))
            {
                Close();
            }
            listing.End();
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        protected override void DoContent(Rect rect)
        {
            var listing = new Listing_StandardPlus();

            listing.Begin(rect);

            Registry.AllowDrugsRestriction = listing.CheckboxLabeled(Lang.Get("Dialog_Global.AllowDrugsRestriction"), Registry.AllowDrugsRestriction);
            Registry.AllowEmergencyFood    = listing.CheckboxLabeled(Lang.Get("Dialog_Global.AllowEmergencyFood"), Registry.AllowEmergencyFood);
            Registry.AllowTrainingFood     = listing.CheckboxLabeled(Lang.Get("Dialog_Global.AllowTrainingFood"), Registry.AllowTrainingFood);

            listing.Gap();
            listing.GapLine();
            listing.Gap();

            Registry.ShowFoodPolicy    = listing.CheckboxLabeled(GetShowRuleLabel(Lang.Get("RestrictionType.Food")), Registry.ShowFoodPolicy);
            Registry.ShowBondingPolicy = listing.CheckboxLabeled(GetShowRuleLabel(Lang.Get("RestrictionType.Bonding")), Registry.ShowBondingPolicy);
            Registry.ShowAllowCourting = listing.CheckboxLabeled(GetShowRuleLabel(Lang.Get("Rules.AllowCourting")), Registry.ShowAllowCourting);
            Registry.ShowAllowArtisan  = listing.CheckboxLabeled(GetShowRuleLabel(Lang.Get("Rules.AllowArtisan")), Registry.ShowAllowArtisan);

            listing.Gap();
            listing.GapLine();
            listing.Gap();

            if (listing.ButtonText(Lang.Get("Dialog_Global.Plans")))
            {
                Close();
                Dialog_Plans.Open();
            }

            listing.End();
        }
Esempio n. 5
0
        protected override void DoContent(Rect rect)
        {
            if (!Registry.IsActive)
            {
                Close();
                return;
            }

            Title = _type == null?Lang.Get("Dialog_Rules.Title", _pawn.Name.ToStringFull.Bold(), _preset.Type.Label) : Lang.Get("Dialog_Rules.TitleDefault", _type.LabelPlural.Bold());

            var listing = new Listing_StandardPlus();
            var hGrid   = rect.GetHGrid(8f, 200f, -1f);
            var lGrid   = hGrid[1].GetVGrid(4f, 42f, -1f);

            listing.Begin(lGrid[1]);
            listing.Label(Lang.Get("Preset.Header").Italic().Bold());
            listing.GapLine();
            listing.End();
            _preset.DoContent(lGrid[2]);

            var vGrid = hGrid[2].GetVGrid(4f, 42f, -1f, 62f);

            listing.Begin(vGrid[1]);
            listing.Label(Lang.Get("Dialog_Rules.Configuration").Italic().Bold());
            listing.GapLine();
            listing.End();

            var editMode = _preset.EditMode || (_template == _personalized);

            var color = GUI.color;

            if (!editMode)
            {
                GUI.color = GuiPlus.ReadOnlyColor;
            }

            listing.Begin(vGrid[2]);
            if (Registry.ShowFoodPolicy && listing.ButtonText(Lang.Get("Rules.FoodRestrictions", GetRestrictionDisplayName(_template.GetRestriction(RestrictionType.Food))), Lang.Get("Rules.FoodRestrictionsDesc")) && editMode)
            {
                ChangeRestriction(RestrictionType.Food);
            }
            if (_template.Type == PawnType.Colonist)
            {
                if (Registry.ShowBondingPolicy && listing.ButtonText(Lang.Get("Rules.BondingRestrictions", GetRestrictionDisplayName(_template.GetRestriction(RestrictionType.Bonding))), Lang.Get("Rules.BondingRestrictionsDesc")) && editMode)
                {
                    ChangeRestriction(RestrictionType.Bonding);
                }

                if ((Registry.ShowFoodPolicy || Registry.ShowBondingPolicy) && (Registry.ShowAllowCourting || Registry.ShowAllowArtisan))
                {
                    listing.GapLine();
                }
                if (Registry.ShowAllowCourting)
                {
                    listing.CheckboxLabeled(Lang.Get("Rules.AllowCourting"), ref _template.AllowCourting, Lang.Get("Rules.AllowCourtingDesc"), editMode);
                }
                if (Registry.ShowAllowArtisan)
                {
                    listing.CheckboxLabeled(Lang.Get("Rules.AllowArtisan"), ref _template.AllowArtisan, Lang.Get("Rules.AllowArtisanDesc"), editMode);
                }
            }

            if (Registry.ShowFoodPolicy || Registry.ShowBondingPolicy || Registry.ShowAllowCourting || Registry.ShowAllowArtisan)
            {
                listing.GapLine();
            }

            listing.End();

            if (_template.HasAddons)
            {
                var addonsRect = vGrid[2].GetVGrid(4f, listing.CurHeight, -1f)[2];
                _addons.Begin(addonsRect, addonsRect.height <= _template.AddonsRectHeight);
                GuiPlus.DoAddonsListing(_addons, _template, editMode);
                _addons.End();
            }

            GUI.color = color;

            var optionGrid = vGrid[3].GetVGrid(2f, -1f, -1f);

            listing.Begin(optionGrid[1]);
            if (listing.ButtonText(Lang.Get("Button.AssignTo"), Lang.Get("Button.AssignToDesc"), (_floatMenuAssign.Count > 0) && (!editMode || (_template == _personalized))))
            {
                Find.WindowStack.Add(new FloatMenu(_floatMenuAssign));
            }
            listing.End();

            listing.Begin(optionGrid[2]);
            if (listing.ButtonText(_type == null ? Lang.Get("Button.ViewType", Lang.Get("PawnType.Individual")) : Lang.Get("Button.ViewTypeDefault", _type.LabelPlural), Lang.Get("Button.ViewTypeDesc"), !editMode || (_template == _personalized)))
            {
                Find.WindowStack.Add(new FloatMenu(_floatMenuViews));
            }
            listing.End();

            GUI.EndGroup();

            if (GuiPlus.ButtonText(new Rect(rect.xMax - (80f - Margin), rect.yMax + (Margin * 2), OptionButtonSize, CloseButSize.y), Lang.Get("Button.GlobalOptions"), Lang.Get("Button.GlobalOptionsDesc")))
            {
                Dialog_Global.Open();
            }
            GUI.BeginGroup(windowRect);
        }
Esempio n. 6
0
        public static void DoAddonsListing(Listing_StandardPlus listing, Rules rules, bool editMode)
        {
            foreach (var addon in rules.GetAddons())
            {
                if (rules.IsPreset && !addon.AllowedInPreset)
                {
                    continue;
                }

                if (addon.Widget == OptionWidget.Checkbox)
                {
                    var value = rules.GetAddonValue(addon, (bool)addon.DefaultValue);
                    if (!listing.CheckboxLabeled(addon.Label, ref value, addon.Tooltip, editMode))
                    {
                        continue;
                    }
                    if (rules.IsPreset)
                    {
                        addon.Handle.ChangePresetValue(rules, value);
                    }
                    else
                    {
                        addon.Handle.ChangeValue(rules.Pawn, value);
                    }
                }
                else if (addon.Widget == OptionWidget.TextEntry)
                {
                    if (addon.Type == typeof(string))
                    {
                        var oldValue = rules.GetAddonValue(addon, (string)addon.DefaultValue);
                        var newValue = listing.TextEntryLabeled(addon.Label, oldValue, addon.Tooltip);
                        if (!editMode || oldValue.Equals(newValue))
                        {
                            continue;
                        }

                        if (rules.IsPreset)
                        {
                            addon.Handle.ChangePresetValue(rules, newValue);
                        }
                        else
                        {
                            addon.Handle.ChangeValue(rules.Pawn, newValue);
                        }
                    }
                    else if (addon.Type == typeof(int))
                    {
                        var oldValue = rules.GetAddonValue(addon, (int)addon.DefaultValue).ToString();
                        var newValue = listing.TextEntryLabeled(addon.Label, oldValue, addon.Tooltip);
                        if (!editMode || oldValue.Equals(newValue))
                        {
                            continue;
                        }

                        if (rules.IsPreset)
                        {
                            addon.Handle.ChangePresetValue(rules, newValue.ToInt());
                        }
                        else
                        {
                            addon.Handle.ChangeValue(rules.Pawn, newValue.ToInt());
                        }
                    }
                    else if (addon.Type == typeof(float))
                    {
                        var oldValue = rules.GetAddonValue(addon, (float)addon.DefaultValue).ToString(CultureInfo.InvariantCulture);
                        var newValue = listing.TextEntryLabeled(addon.Label, oldValue, addon.Tooltip);
                        if (!editMode || oldValue.Equals(newValue))
                        {
                            continue;
                        }

                        if (rules.IsPreset)
                        {
                            addon.Handle.ChangePresetValue(rules, newValue.ToFloat());
                        }
                        else
                        {
                            addon.Handle.ChangeValue(rules.Pawn, newValue.ToFloat());
                        }
                    }
                }
                else if (addon.Widget == OptionWidget.Button)
                {
                    if (!listing.ButtonText(addon.Label, addon.Tooltip) && editMode)
                    {
                        continue;
                    }

                    if (rules.IsPreset)
                    {
                        addon.Handle.DoDefaultClick(rules.Type.AsTarget);
                    }
                    else
                    {
                        addon.Handle.DoClick(rules.Pawn);
                    }
                }
            }
        }
Esempio n. 7
0
        public void DoContent(Rect rect)
        {
            var selectedIsIgnored = Selected.IsIgnored();
            var presets           = Registry.GetPresets <T>(Type).ToArray();

            _listing.Begin(rect);
            foreach (var preset in FixedPresets)
            {
                var isSelected = (Selected == preset) || (Selected.Name == preset.Name);
                if (_listing.RadioButtonInverted(preset.GetDisplayName().Italic(), isSelected, null, !EditMode || isSelected))
                {
                    ChangeSelected(preset);
                }
            }
            if (presets.Any())
            {
                _listing.GapLine();
            }
            _listing.End();

            var presetGrid = rect.GetVGrid(4f, _listing.CurHeight, -1f, 62f);

            _presetListing.Begin(presetGrid[2], true);
            foreach (var preset in presets)
            {
                var isSelected = (Selected == preset) || (Selected.Name == preset.Name);
                if (_presetListing.RadioButtonInverted(preset.Name, isSelected, null, !EditMode || isSelected))
                {
                    ChangeSelected(preset);
                }
            }
            _presetListing.End();

            var buttonGrid = presetGrid[3].GetHGrid(4f, -1f, -1f);

            _listing.Begin(buttonGrid[1]);

            if (_listing.ButtonText(Lang.Get("Button.PresetNew"), Lang.Get("Button.PresetNewDesc"), !EditMode))
            {
                Presetable.SetName <T>(Type, CreatePreset);
            }

            if (EditMode)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetSave"), Lang.Get("Button.PresetSaveDesc")))
                {
                    Commit();
                    ChangeEditMode(false);
                    OnSave?.Invoke();
                }
            }
            else if (Selected.IsPreset)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetEdit"), Lang.Get("Button.PresetEditDesc"), !Selected.IsVoid))
                {
                    ChangeEditMode(true);
                }
            }
            else
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetSaveAs"), Lang.Get("Button.PresetSaveAsDesc"), !Selected.IsVoid && !selectedIsIgnored))
                {
                    OnSave?.Invoke();
                }
            }

            _listing.End();
            _listing.Begin(buttonGrid[2]);

            if (_listing.ButtonText(Lang.Get("Button.PresetDelete"), Lang.Get("Button.PresetDeleteDesc"), !Selected.IsVoid && Selected.IsPreset && !EditMode))
            {
                Dialog_Alert.Open(Lang.Get("Button.PresetDeleteConfirm", Selected.Name), Dialog_Alert.Buttons.YesNo, DeletePreset);
            }

            if (EditMode)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetRevert"), Lang.Get("Button.PresetRevertDesc"), !Selected.IsVoid))
                {
                    Revert();

                    ChangeEditMode(false);
                    OnRevert?.Invoke();
                }
            }
            else if (Selected.IsPreset)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetRename"), Lang.Get("Button.PresetRenameDesc"), !Selected.IsVoid && !EditMode))
                {
                    Presetable.SetName(Selected, ChangeSelected);
                }
            }
            else
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetClear"), Lang.Get("Button.PresetClearDesc"), !Selected.IsVoid && !selectedIsIgnored))
                {
                    OnRevert?.Invoke();
                }
            }

            _listing.End();
        }
Esempio n. 8
0
        public void DoContent(Rect rect)
        {
            var selectedIsIgnored = Selected.IsIgnored();
            var presets           = Registry.GetPresets <T>(Type);

            _listing.Begin(rect);
            foreach (var preset in FixedPresets)
            {
                var isSelected = (Selected == preset) || (Selected.Name == preset.Name);
                if (_listing.RadioButtonInverted((preset.IsPreset ? preset.Name : Lang.Get("Preset.Personalized")).Italic(), isSelected, null, !EditMode || isSelected))
                {
                    ChangeSelected(preset);
                }
            }
            if (presets.Any())
            {
                _listing.GapLine();
            }
            _listing.End();

            var presetGrid = rect.GetVGrid(4f, _listing.CurHeight, 0f, 62f);

            _presetListing.Begin(presetGrid[1], true);
            foreach (var preset in presets)
            {
                var isSelected = (Selected == preset) || (Selected.Name == preset.Name);
                if (_presetListing.RadioButtonInverted(preset.Name, isSelected, null, !EditMode || isSelected))
                {
                    ChangeSelected(preset);
                }
            }
            _presetListing.End();

            var buttonGrid = presetGrid[2].GetHGrid(4f, 0f, 0f);

            _listing.Begin(buttonGrid[0]);

            if (_listing.ButtonText(Lang.Get("Button.PresetNew"), Lang.Get("Button.PresetNewDesc"), !EditMode))
            {
                Find.WindowStack.Add(new Dialog_PresetName <T>(Type, preset =>
                {
                    _lastSelected = Selected;
                    ChangeEditMode(true);
                    ChangeSelected(preset);
                }));
            }

            if (EditMode)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetSave"), Lang.Get("Button.PresetSaveDesc")))
                {
                    Commit();
                    ChangeEditMode(false);
                    OnSave?.Invoke();
                }
            }
            else if (Selected.IsPreset)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetEdit"), Lang.Get("Button.PresetEditDesc"), !Selected.IsVoid))
                {
                    ChangeEditMode(true);
                }
            }
            else
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetSaveAs"), Lang.Get("Button.PresetSaveAsDesc"), !Selected.IsVoid && !selectedIsIgnored))
                {
                    OnSave?.Invoke();
                }
            }

            _listing.End();
            _listing.Begin(buttonGrid[1]);

            if (_listing.ButtonText(Lang.Get("Button.PresetDelete"), Lang.Get("Button.PresetDeleteDesc"), !Selected.IsVoid && Selected.IsPreset && !EditMode))
            {
                Find.WindowStack.Add(new Dialog_Alert(Lang.Get("Button.PresetDeleteConfirm", Selected.Name), Dialog_Alert.Buttons.YesNo, () =>
                {
                    Registry.DeletePreset(Selected);
                    ChangeSelected(Registry.GetVoidPreset <T>(Type));
                }));
            }

            if (EditMode)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetRevert"), Lang.Get("Button.PresetRevertDesc"), !Selected.IsVoid))
                {
                    Revert();

                    ChangeEditMode(false);
                    OnRevert?.Invoke();
                }
            }
            else if (Selected.IsPreset)
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetRename"), Lang.Get("Button.PresetRenameDesc"), !Selected.IsVoid && !EditMode))
                {
                    Find.WindowStack.Add(new Dialog_PresetName <T>(Selected, ChangeSelected));
                }
            }
            else
            {
                if (_listing.ButtonText(Lang.Get("Button.PresetClear"), Lang.Get("Button.PresetClearDesc"), !Selected.IsVoid && !selectedIsIgnored))
                {
                    OnRevert?.Invoke();
                }
            }

            _listing.End();
        }