Esempio n. 1
0
        private void buttonAddPreset_Click(object sender, EventArgs e)
        {
            PlayerSettings settings = PlayerSettings.Get();

            string UniqueName = "";

            for (int Idx = 1; Idx < 10000; Idx++)
            {
                UniqueName = "Preset#" + Idx;
                bool alreadyExists = settings.Presets.Find(x => (x.Name == UniqueName)) != null;
                if (!alreadyExists)
                {
                    break;
                }
            }

            ActorFilterPreset preset = new ActorFilterPreset
            {
                Name             = UniqueName,
                ShowOnlyMatching = false
            };

            settings.Presets.Add(preset);

            ListViewItem lvi = new ListViewItem(preset.Name);

            lvi.Tag = preset;
            listViewPresetManage.Items.Add(lvi);

            int itemIdx = comboBoxPreset.Items.Add(preset);

            comboBoxPreset.SelectedIndex = itemIdx;
        }
Esempio n. 2
0
        private bool LoadFromJson(JsonParser.ObjectValue jsonOb)
        {
            bool hasLoaded = false;

            try
            {
                FontSize = (JsonParser.FloatValue)jsonOb["fontSize"];
                MaxDistanceFromCenter = (JsonParser.FloatValue)jsonOb["maxCenterDist"];
                MaxDistanceFromCamera = (JsonParser.FloatValue)jsonOb["maxCameraDist"];

                FilterNearbyActors = jsonOb.entries.ContainsKey("filterNearby") ? (JsonParser.BoolValue)jsonOb["filterNearby"] : false;

                JsonParser.ArrayValue arrPresets = (JsonParser.ArrayValue)jsonOb["presets"];
                foreach (JsonParser.Value v in arrPresets.entries)
                {
                    JsonParser.ObjectValue presetJsonOb = (JsonParser.ObjectValue)v;
                    ActorFilterPreset      presetOb     = new ActorFilterPreset();

                    bool loadedPreset = presetOb.LoadFromJson(presetJsonOb);
                    if (loadedPreset)
                    {
                        Presets.Add(presetOb);
                    }
                }

                hasLoaded = true;
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Failed to load settings, exception:" + ex);
            }

            return(hasLoaded);
        }
Esempio n. 3
0
 private void comboBoxPreset_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!ignorePresetSelection)
     {
         activePreset = comboBoxPreset.SelectedItem as ActorFilterPreset;
         UpdatePresetFilters();
     }
 }
Esempio n. 4
0
        private void toolStripMenuItemPresetExport_Click(object sender, EventArgs e)
        {
            if (listViewPresetManage.SelectedItems.Count == 1)
            {
                ActorFilterPreset preset = (ActorFilterPreset)listViewPresetManage.SelectedItems[0].Tag;

                JsonWriter writer = new JsonWriter();
                preset.SaveToJson(writer);

                Clipboard.SetText(writer.ToString());
            }
        }
Esempio n. 5
0
        private void toolStripMenuItemPresetDelete_Click(object sender, EventArgs e)
        {
            if (listViewPresetManage.SelectedItems.Count == 1)
            {
                ActorFilterPreset preset = (ActorFilterPreset)listViewPresetManage.SelectedItems[0].Tag;

                PlayerSettings settings = PlayerSettings.Get();
                settings.Presets.Remove(preset);

                if (settings.Presets.Count == 0)
                {
                    settings.CreateDefaultPreset();
                }

                UpdatePresetList();
            }
        }
Esempio n. 6
0
        private void MergeOnlinePresets(List <string> onlinePresets)
        {
            PlayerSettings settings   = PlayerSettings.Get();
            bool           hasChanges = false;

            for (int importIdx = 0; importIdx < onlinePresets.Count; importIdx++)
            {
                ActorFilterPreset testPreset = new ActorFilterPreset();
                bool isValid = false;
                try
                {
                    JsonParser.ObjectValue rootOb = JsonParser.ParseJson(onlinePresets[importIdx]);
                    isValid = testPreset.LoadFromJson(rootOb);
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Failed to merge synced preset #" + importIdx + ": " + ex);
                }

                if (isValid)
                {
                    ActorFilterPreset existingPreset = settings.Presets.Find(x => x.Name == testPreset.Name);
                    if (existingPreset != null && existingPreset.version >= testPreset.version)
                    {
                        Logger.WriteLine("Ignoring online preset #" + importIdx + ": " + testPreset.Name + " (v" + testPreset.version + ") => local version: " + existingPreset.version);
                        continue;
                    }

                    if (existingPreset != null)
                    {
                        settings.Presets.Remove(existingPreset);
                    }

                    Logger.WriteLine("Using online preset #" + importIdx + ": " + testPreset.Name + " (v" + testPreset.version + ")");
                    settings.Presets.Add(testPreset);
                    hasChanges = true;
                }
            }

            if (hasChanges)
            {
                UpdatePresetList();
            }
        }
Esempio n. 7
0
        private void listViewPresetManage_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (e.Item >= 0 && !string.IsNullOrEmpty(e.Label))
            {
                PlayerSettings settings = PlayerSettings.Get();

                bool bAlreadyExisting = settings.Presets.Find(x => x.Name.Equals(e.Label, StringComparison.InvariantCultureIgnoreCase)) != null;
                if (!bAlreadyExisting)
                {
                    ActorFilterPreset preset = (ActorFilterPreset)listViewPresetManage.Items[e.Item].Tag;
                    preset.Name = e.Label;

                    RefreshPresetDropdown();
                }
                else
                {
                    e.CancelEdit = true;
                }
            }
            else
            {
                e.CancelEdit = true;
            }
        }
Esempio n. 8
0
        private void buttonImportPreset_Click(object sender, EventArgs e)
        {
            ActorFilterPreset loadedPreset = null;

            string importText = Clipboard.GetText();

            if (!string.IsNullOrEmpty(importText) && importText.Length > 2 && importText[0] == '{')
            {
                ActorFilterPreset preset = new ActorFilterPreset();
                try
                {
                    JsonParser.ObjectValue jsonOb = JsonParser.ParseJson(importText);
                    bool hasLoaded = preset.LoadFromJson(jsonOb);
                    if (hasLoaded)
                    {
                        loadedPreset = preset;
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Import failed text:'" + importText + "', exception:" + ex);
                }
            }

            if (loadedPreset != null)
            {
                PlayerSettings    settings       = PlayerSettings.Get();
                ActorFilterPreset existingPreset = settings.Presets.Find(x => (x.Name == loadedPreset.Name));
                bool bCanAdd = false;

                if (existingPreset != null)
                {
                    DialogResult dr = MessageBox.Show("Preset '" + existingPreset.Name + "' already exists, do you want to merge it?", Text, MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.Yes)
                    {
                        // merge
                        existingPreset.Filters.AddRange(loadedPreset.Filters);
                    }
                    else if (dr == DialogResult.No)
                    {
                        // keep separate, create new name

                        string UseName = existingPreset.Name;
                        int    sepIdx  = UseName.LastIndexOf('#');
                        if (sepIdx > 0)
                        {
                            UseName = UseName.Substring(0, sepIdx);
                        }

                        for (int Idx = 2; Idx < 10000; Idx++)
                        {
                            string UniqueName    = UseName + "#" + Idx;
                            bool   alreadyExists = settings.Presets.Find(x => (x.Name == UniqueName)) != null;
                            if (!alreadyExists)
                            {
                                loadedPreset.Name = UniqueName;
                                bCanAdd           = true;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    bCanAdd = true;
                }

                if (bCanAdd)
                {
                    settings.Presets.Add(loadedPreset);

                    ListViewItem lvi = new ListViewItem(loadedPreset.Name);
                    lvi.Tag = loadedPreset;
                    listViewPresetManage.Items.Add(lvi);

                    int itemIdx = comboBoxPreset.Items.Add(loadedPreset);
                    comboBoxPreset.SelectedIndex = itemIdx;
                }
            }
        }