예제 #1
0
 /// <summary>
 /// Writes the mod options to its config file.
 /// </summary>
 private void WriteOptions()
 {
     if (options != null)
     {
         // Update from local options
         foreach (var catEntries in optionCategories)
         {
             foreach (var option in catEntries.Value)
             {
                 option.WriteTo(options);
             }
         }
         POptions.WriteSettings(options, POptions.GetConfigFilePath(optionsType),
                                configAttr?.IndentOutput ?? false);
         TriggerUpdateOptions(options);
     }
 }
예제 #2
0
        /// <summary>
        /// Triggered when the Mod Options button is clicked.
        /// </summary>
        public void ShowDialog()
        {
            string title;

            if (string.IsNullOrEmpty(displayInfo.Title))
            {
                title = PLibStrings.BUTTON_OPTIONS;
            }
            else
            {
                title = string.Format(PLibStrings.DIALOG_TITLE, OptionsEntry.LookInStrings(
                                          displayInfo.Title));
            }
            // Close current dialog if open
            CloseDialog();
            // Ensure that it is on top of other screens (which may be +100 modal)
            var pDialog = new PDialog("ModOptions")
            {
                Title              = title, Size = SETTINGS_DIALOG_SIZE, SortKey = 150.0f,
                DialogBackColor    = PUITuning.Colors.OptionsBackground,
                DialogClosed       = OnOptionsSelected, MaxSize = SETTINGS_DIALOG_MAX_SIZE,
                RoundToNearestEven = true
            }.AddButton("ok", STRINGS.UI.CONFIRMDIALOG.OK, PLibStrings.TOOLTIP_OK,
                        PUITuning.Colors.ButtonPinkStyle).AddButton(PDialog.DIALOG_KEY_CLOSE,
                                                                    STRINGS.UI.CONFIRMDIALOG.CANCEL, PLibStrings.TOOLTIP_CANCEL,
                                                                    PUITuning.Colors.ButtonBlueStyle);

            options = POptions.ReadSettings(POptions.GetConfigFilePath(optionsType),
                                            optionsType);
            if (options == null)
            {
                options = CreateOptions(optionsType);
            }
            AddModInfoScreen(pDialog);
            FillModOptions(pDialog);
            // Manually build the dialog so the options can be updated after realization
            var obj = pDialog.Build();

            UpdateOptions();
            dialog = obj.GetComponent <KScreen>();
            dialog.Activate();
        }
예제 #3
0
        /// <summary>
        /// Invoked when the manual config button is pressed.
        /// </summary>
        private void OnManualConfig(GameObject _)
        {
            string uri = null, path = POptions.GetConfigFilePath(optionsType);

            try {
                uri = new Uri(Path.GetDirectoryName(path)).AbsoluteUri;
            } catch (UriFormatException e) {
                PUtil.LogWarning("Unable to convert parent of " + path + " to a URI:");
                PUtil.LogExcWarn(e);
            }
            if (!string.IsNullOrEmpty(uri))
            {
                // Open the config folder, opening the file itself might start an unknown
                // editor which could execute the json somehow...
                WriteOptions();
                CloseDialog();
                PUtil.LogDebug("Opening config folder: " + uri);
                Application.OpenURL(uri);
                CheckForRestart();
            }
        }