Esempio n. 1
0
        public override void PreOpen()
        {
            base.PreOpen();

            /*
             * note: this code is in PreOpen() rather than in the ctor because otherwise RimWorld would crash (more precisely, Unity crashes).
             * I can't remember exactly where, but it deals with Unity calculating the text size of a floating menu.
             * So better to let this code here rather than in the ctor.
             */
            if (Enumerable.Any(_bottomButtonsDescriptorList, buttonDescriptor => buttonDescriptor.Label == "PLMWBB_LoadSave".Translate()))
            {
                return;
            }

            var buttonSaveLoadPreset = new ButtonDescriptor("PLMWBB_LoadSave".Translate(),
                                                            "PLMWBB_LoadOrSaveFilterPresets".Translate());

            buttonSaveLoadPreset.AddFloatMenuOption("PLMWLODSAV_Save".Translate(), delegate /* action click */
            {
                if (!(TabController.TabById("LoadSave") is TabLoadSave tab))
                {
                    return;
                }

                tab.LoadSaveMode = LoadSaveMode.Save;
                TabController.SetSelectedTabById("LoadSave");
            }, delegate     /* action mouse over */
Esempio n. 2
0
        public override void PreOpen()
        {
            base.PreOpen();

            /*
             * note: this code is in PreOpen() rather than in the ctor because otherwise RimWorld would crash (more precisely, Unity crashes).
             * I can't remember exactly where, but it deals with Unity calculating the text size of a floating menu.
             * So better to let this code here rather than in the ctor.
             */
            if (Enumerable.Any(_bottomButtonsDescriptorList, buttonDesctipor => buttonDesctipor.Label == "Load / Save"))
            {
                return;
            }

            var buttonSaveLoadPreset = new ButtonDescriptor("Load / Save", "Load or Save Filter Presets");

            buttonSaveLoadPreset.AddFloatMenuOption("Save", delegate
            {
                //_userData.PresetManager.TestSave();
                var tab = TabController.TabById("LoadSave") as TabLoadSave;
                if (tab == null)
                {
                    return;
                }

                tab.LoadSaveMode = LoadSaveMode.Save;
                TabController.SetSelectedTabById("LoadSave");
            }, delegate
            {
                var mousePos = Event.current.mousePosition;
                var rect     = new Rect(mousePos.x, mousePos.y, 30f, 30f);

                TooltipHandler.TipRegion(rect, "Save current filter states to a preset.");
            }
                                                    );
            buttonSaveLoadPreset.AddFloatMenuOption("Load", delegate
            {
                //_userData.PresetManager.TestLoad();
                var tab = TabController.TabById("LoadSave") as TabLoadSave;
                if (tab == null)
                {
                    return;
                }

                tab.LoadSaveMode = LoadSaveMode.Load;
                TabController.SetSelectedTabById("LoadSave");
            }, delegate
            {
                var mousePos = Event.current.mousePosition;
                var rect     = new Rect(mousePos.x, mousePos.y, 30f, 30f);

                TooltipHandler.TipRegion(rect, "Load a preset.");
            }
                                                    );
            buttonSaveLoadPreset.AddFloatMenu("Select Action");
            _bottomButtonsDescriptorList.Add(buttonSaveLoadPreset);

            // do not display the "close" button while playing (the "World" button on bottom menu bar was clicked)
            //    otherwise there's no way to get the window back...
            if (Current.ProgramState == ProgramState.Playing)
            {
                if (_bottomButtonsDescriptorList.Contains(_buttonCloseDescriptor))
                {
                    _bottomButtonsDescriptorList.Remove(_buttonCloseDescriptor);
                }
            }
            else
            {
                if (!_bottomButtonsDescriptorList.Contains(_buttonCloseDescriptor))
                {
                    _bottomButtonsDescriptorList.Add(_buttonCloseDescriptor);
                }
            }
        }