예제 #1
0
        public override void Close(bool doCloseSound = true)
        {
            if (_preset.EditMode)
            {
                void OnAccept()
                {
                    CommitTemplate();
                    base.Close(doCloseSound);
                }

                void OnCancel()
                {
                    _preset.Revert();
                    base.Close(doCloseSound);
                }

                Dialog_Alert.Open(Lang.Get("Button.PresetSaveConfirm"), Dialog_Alert.Buttons.YesNo, OnAccept, OnCancel);
                return;
            }

            if (_preset.Selected == _personalized)
            {
                Registry.ReplaceRules(_pawn, _personalized);
            }
            base.Close(doCloseSound);
        }
예제 #2
0
        public override void Close(bool doCloseSound = true)
        {
            if (_presetList.EditMode && (_presetList.IsUnsaved || HasMadeChanges()))
            {
                void OnAccept()
                {
                    _presetList.Selected.Update(_template);
                    RefreshTemplate();
                    _presetList.Commit();
                    base.Close(doCloseSound);
                }

                void OnCancel()
                {
                    if (_presetList.IsUnsaved)
                    {
                        _presetList.Revert();
                    }

                    base.Close(doCloseSound);
                }

                Dialog_Alert.Open(Lang.Get("Button.PresetSaveConfirm"), Dialog_Alert.Buttons.YesNo, OnAccept, OnCancel);
                return;
            }

            base.Close(doCloseSound);
        }
예제 #3
0
        private void LoadPlan()
        {
            Close();
            var loaded = Persistent.Load(_selected);

            Dialog_Alert.Open(Lang.Get(loaded ? "Dialog_Plans.LoadSuccess" : "Dialog_Plans.LoadFail", _selected));
        }
예제 #4
0
        private void AssignAll(bool byKind)
        {
            var pawns = GetOtherPawnsOfType(byKind).ToArray();

            void OnAccept()
            {
                foreach (var pawn in pawns)
                {
                    Registry.ReplaceRules(pawn, _preset.Selected.IsPreset ? _preset.Selected : _template.ClonePreset());
                }
            }

            var count = pawns.Count();

            Dialog_Alert.Open(Lang.Get("Dialog_Rules.AssignAllConfirm", GetPresetNameDefinite(), count.ToString().Bold(), byKind ? _pawn.kindDef.GetLabelPlural(count) : count > 1 ? _preset.Selected.Type.LabelPlural : _preset.Selected.Type.Label), Dialog_Alert.Buttons.YesNo, OnAccept);
        }
예제 #5
0
        protected override void DoContent(Rect rect)
        {
            var vGrid = rect.GetVGrid(4f, -1f, 30f, 30f);

            var hasPlans = _plans.Any();

            if (hasPlans)
            {
                _listing.Begin(vGrid[1], true);
                foreach (var plan in _plans)
                {
                    if (_listing.RadioButton(plan, _selected == plan))
                    {
                        _selected = plan;
                    }
                }
            }
            else
            {
                _listing.Begin(vGrid[1]);
                _listing.Label(Lang.Get("Dialog_Plans.NoneFound"));
            }
            _listing.End();

            var tGrid = vGrid[2].GetHGrid(4f, -1f, -1f);
            var bGrid = vGrid[3].GetHGrid(4f, -1f, -1f);

            if (GuiPlus.ButtonText(tGrid[1], Lang.Get("Dialog_Plans.Import"), Lang.Get("Dialog_Plans.ImportDesc"), !_selected.NullOrEmpty()))
            {
                LoadPlan();
            }
            if (GuiPlus.ButtonText(tGrid[2], Lang.Get("Dialog_Plans.Delete"), Lang.Get("Dialog_Plans.DeleteDesc"), !_selected.NullOrEmpty()))
            {
                Dialog_Alert.Open(Lang.Get("Dialog_Plans.ConfirmDelete", _selected), Dialog_Alert.Buttons.YesNo, DeletePlan);
            }
            if (GuiPlus.ButtonText(bGrid[1], Lang.Get("Dialog_Plans.Export"), Lang.Get("Dialog_Plans.ExportDesc")))
            {
                Dialog_SetName.Open(Lang.Get("Dialog_SetName.PlanTitle"), Lang.Get("Dialog_SetName.PlanLabel"), SavePlan, Persistent.NameIsValid, Persistent.CreateDefaultName());
            }
            if (GuiPlus.ButtonText(bGrid[2], "CloseButton".Translate()))
            {
                Close();
            }
        }
예제 #6
0
        private void AssignSpecific(Pawn pawn)
        {
            void OnAccept() => Registry.ReplaceRules(pawn, _preset.Selected.IsPreset ? _preset.Selected : _template.ClonePreset());

            Dialog_Alert.Open(Lang.Get("Dialog_Rules.AssignSpecificConfirm", GetPresetNameDefinite(), pawn.Name.ToString().Italic()), Dialog_Alert.Buttons.YesNo, OnAccept);
        }
예제 #7
0
        private List <FloatMenuOption> GetAssignmentOptions()
        {
            var options = new List <FloatMenuOption>();

            var otherPawnsOfType = GetOtherPawnsOfType(false);

            if (GetOtherPawnsOfType(false).Any())
            {
                options.Add(new FloatMenuOption(Lang.Get("Dialog_Rules.AssignAll", _preset.Type.LabelPlural.ToLower()), () => AssignAll(false)));
            }
            if ((_type == null) && _pawn.RaceProps.Animal && otherPawnsOfType.Any(kind => kind.kindDef == _pawn.kindDef))
            {
                options.Add(new FloatMenuOption(Lang.Get("Dialog_Rules.AssignAll", _pawn.kindDef.GetLabelPlural().ToLower()), () => AssignAll(true)));
            }
            options.AddRange(Find.CurrentMap.mapPawns.AllPawns.Where(pawn => ((_type != null) || (pawn != _pawn)) && (pawn.GetTargetType() == _preset.Type)).Select(pawn => new FloatMenuOption(Lang.Get("Dialog_Rules.AssignSpecific", pawn.Name.ToString().Italic()), () => AssignSpecific(pawn))));
            if ((_type == null) && _preset.Selected.IsPreset)
            {
                options.Add(new FloatMenuOption(Lang.Get("Dialog_Rules.AssignDefault", _preset.Type.LabelPlural.ToLower()), () => Dialog_Alert.Open(Lang.Get("Dialog_Rules.AssignDefaultConfirm", _preset.Type.LabelPlural.ToLower(), _preset.Selected.Name.Bold()), Dialog_Alert.Buttons.YesNo, () => Registry.SetDefaultRules(_preset.Selected))));
            }

            return(options);
        }
예제 #8
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();
        }