private async Task OnAddPresetCommand() { _logger.Info("Opening add preset dialog"); var dp = new DialogParameters { { "GameModule", _game } }; _dialogService.ShowDialog(nameof(AddPresetDialog), dp, async(dr) => { if (dr.Result == ButtonResult.OK) { var newPreset = await _presetManager.GetPresetAsync(Paths.GetPresetsDirectory(_game.Module), dr.Parameters.GetValue <string>("PresetName")); Presets.Add(newPreset); RaisePropertyChanged(nameof(Presets)); _eventAggregator.GetEvent <ShowSnackbarMessageEvent>().Publish(Strings.PRESET_ADDED); _logger.Info("Preset added"); } }); await Task.CompletedTask; }
private void AddPreset(Preset newPreset) { newPreset.Name = "Preset " + (Presets.Count + 1); Presets.Add(newPreset); this.listBox1.SelectedItem = newPreset; UpdateDisplay(); }
private void Save(object sender, RoutedEventArgs e) { Preset presetWithSameName = Presets.FirstOrDefault(preset => preset.Name == WorkingPreset.Name); if (presetWithSameName == null) { Presets.Add(new Preset(WorkingPreset)); using (SqlConnection connection = new SqlConnection(DATA_SOURCE)) { SqlCommand command = new SqlCommand("INSERT INTO Presets (Name, Parts, Delay) VALUES (@Name, @Parts, @Delay);", connection); command.Parameters.AddWithValue("Name", WorkingPreset.Name); command.Parameters.AddWithValue("Parts", WorkingPreset.Parts); command.Parameters.AddWithValue("Delay", WorkingPreset.Delay); command.Connection.Open(); command.ExecuteNonQuery(); } } else { presetWithSameName = new Preset(WorkingPreset); using (SqlConnection connection = new SqlConnection(DATA_SOURCE)) { SqlCommand command = new SqlCommand("UPDATE Presets SET Name = @Name, Parts = @Parts, Delay = @Delay WHERE Name = @Name", connection); command.Parameters.AddWithValue("Name", WorkingPreset.Name); command.Parameters.AddWithValue("Parts", WorkingPreset.Parts); command.Parameters.AddWithValue("Delay", WorkingPreset.Delay); command.Connection.Open(); command.ExecuteNonQuery(); } } }
protected void ReadSavedConfig() { if (File.Exists(ConfigFilePath)) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(ConfigFilePath); XmlNode libraryNode = xmldoc.SelectSingleNode("Library"); XmlNode presetsNode = libraryNode.SelectSingleNode("Presets"); XmlNodeList presetNodes = presetsNode.SelectNodes("Preset"); foreach (XmlNode presetNode in presetNodes) { // Create preset object, then assign Name, Territory, etc. Presets.Add(new WaymarkPreset()); Presets.Last().Name = presetNode.Attributes.GetNamedItem("Name").Value; Presets.Last().ZoneID = UInt16.Parse(presetNode.Attributes.GetNamedItem("ZoneID").Value); Presets.Last().LastModified = DateTimeOffset.Parse(presetNode.Attributes.GetNamedItem("Time").Value); XmlNodeList waymarkNodes = presetNode.SelectNodes("Waymarks/Waymark"); // Assign the data for each waymark in the preset. foreach (XmlNode waymarkNode in waymarkNodes) { int waymarkNumber = WaymarkPreset.GetWaymarkNumber(waymarkNode.Attributes.GetNamedItem("ID").Value.First()); if (waymarkNumber < 0) { throw new Exception("Error: Invalid waymark ID while reading waymark library."); } Presets.Last().Waymarks[waymarkNumber].IsEnabled = bool.Parse(waymarkNode.Attributes.GetNamedItem("Active").Value); XmlNode coordsNode = waymarkNode.SelectSingleNode("Coordinates"); Presets.Last().Waymarks[waymarkNumber].Pos.X = Double.Parse(coordsNode.Attributes.GetNamedItem("X").Value); Presets.Last().Waymarks[waymarkNumber].Pos.Y = Double.Parse(coordsNode.Attributes.GetNamedItem("Y").Value); Presets.Last().Waymarks[waymarkNumber].Pos.Z = Double.Parse(coordsNode.Attributes.GetNamedItem("Z").Value); } } } }
public async Task InitializeAsync() { try { StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("_Settings_LoadPresets".GetLocalized())); string dataString = await FileIO.ReadTextAsync(file); Presets.Clear(); foreach (Preset p in JsonConvert.DeserializeObject <List <Preset> >(dataString)) { Presets.Add(p); } ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; if (localSettings.Values.TryGetValue("SELECTED_PRESET", out object obj)) { SelectedPreset = Presets.Where(p => p.Id == (string)(obj)).FirstOrDefault(); } else { SelectedPreset = Presets.Where(p => p.Id == "Default").FirstOrDefault(); } } catch (Exception) { } }
public int ImportPreset(WaymarkPreset preset) { WaymarkPreset importedPreset = new WaymarkPreset(preset); Presets.Add(importedPreset); return(Presets.Count - 1); }
void InitData() { //InitDefaultPTZSpaces(); //Nodes.Clear(); Presets.Clear(); model.presets.ForEach(x => { Presets.Add(x); }); valuePresetName.CreateBinding(TextBox.TextProperty, this, x => x.PresetName, (m, v) => { m.PresetName = v; }); valuePresetsList.ItemsSource = Presets; valuePresetsList.CreateBinding(ListBox.SelectedItemProperty, this, x => x.SelectedPreset, (m, v) => m.SelectedPreset = v); var node = model.node; if (node == null) { return; } var supportedPtzSpaces = node.supportedPTZSpaces; if (supportedPtzSpaces == null) { return; } ptzConfig = model.profile.ptzConfiguration; if (ptzConfig == null) { return; } ptzSpacesConfig.Setup(ptzConfig, supportedPtzSpaces); }
// TODO: Split for optimization? private async Task RebuildPresetsList() { if (_reloading) { return; } _reloading = true; PresetsReady = false; try { Presets.Clear(); _builtInPresets = await ScanAsync(ControlsSettings.SubBuiltInPresets); _userPresets = await ScanAsync(ControlsSettings.SubUserPresets); Presets.Add(Rebuild(ControlsStrings.Controls_BuiltInPresets, ControlsSettings.SubBuiltInPresets, _builtInPresets)); Presets.Add(Rebuild(ControlsStrings.Controls_UserPresets, ControlsSettings.SubUserPresets, _userPresets)); PresetsReady = true; } catch (Exception e) { Logging.Warning("RebuildPresetsList(): " + e); } finally { _reloading = false; } }
private void NewExec(object sender, ExecutedRoutedEventArgs e) { mPresetsList.ItemContainerGenerator.StatusChanged += OnNewItemContainerGenerated; mNewlyAddedPreset = new Preset("(New Preset)", ""); Presets.Add(mNewlyAddedPreset); mPresetsList.SelectedItem = mNewlyAddedPreset; }
private async Task OnSaveCurrentPresetCommand() { // Create preset _logger.Info("Creating preset"); var newPreset = _presetManager.CreateExistingPreset(_game.InstalledLocation); // Validate file count without any binaries if (newPreset.Files.Count() == 0) { var messageDialog = new MessageDialog(Strings.INVALID_PRESET_NO_FILES); await messageDialog.OpenAsync(); _logger.Info(Strings.INVALID_PRESET_NO_FILES); return; } // Prompt name var inputDialog = new InputDialog(Strings.ENTER_A_NEW_NAME); var result = await inputDialog.OpenAsync(); if (result) { using (var dialog = new ProgressDialog(true)) { try { _ = dialog.OpenAsync(); // Save preset _logger.Info("Saving current preset"); newPreset.Name = inputDialog.Value; await _presetManager.SaveCurrentPresetAsync(Paths.GetPresetsDirectory(_game.Module), _game.InstalledLocation, newPreset); // Reload preset newPreset = await _presetManager.GetPresetAsync(Paths.GetPresetsDirectory(_game.Module), newPreset.Name); newPreset.IsActive = true; Presets.Add(newPreset); await OnActivatePresetCommand(newPreset); RaisePropertyChanged(nameof(Presets)); _eventAggregator.GetEvent <ShowSnackbarMessageEvent>().Publish(Strings.PRESET_ADDED); } catch (IdenticalNameException ex) { await new MessageDialog(Strings.AN_ITEM_WITH_THIS_NAME_ALREADY_EXISTS).OpenAsync(); _logger.Debug(ex.Message); } catch (IOException ex) { await new MessageDialog(Strings.INVALID_NAME).OpenAsync(); _logger.Warn(ex); } } } }
bool LoadPresets(bool silentErrors = true) { var loadedPresets = new List <AutoSplitList>(); var corruptedPresets = new List <string>(); var success = true; try { var doc = new XmlDocument(); doc.Load(PRESETS_FILE_PATH); foreach (XmlElement listElem in doc.DocumentElement) { AutoSplitList preset; try { preset = AutoSplitList.FromXml(listElem, _autoSplitEnv); } catch { corruptedPresets.Add(listElem["Name"]?.InnerText); continue; } loadedPresets.Add(preset); } if (!silentErrors && corruptedPresets.Count != 0) { var errorMessage = new System.Text.StringBuilder(); errorMessage.AppendLine("The following presets could not be loaded:"); foreach (var preset in corruptedPresets) { string name = preset != null ? $"\"{preset}\"" : "(could not retrieve the name)"; errorMessage.AppendLine($"\t{name}"); } MessageBox.Show(errorMessage.ToString(), "Preset import error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { success = false; if (!silentErrors) { MessageBox.Show("Update failed.", "Presets update failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } Presets.Clear(); Presets.Add(CustomAutosplits); foreach (var item in loadedPresets.OrderBy(x => x.Name)) { Presets.Add(item); } return(success); }
private void AddPreset(ImageEffectPreset preset) { if (preset != null) { Presets.Add(preset); ListViewItem lvi = new ListViewItem(preset.ToString()); lvPresets.Items.Add(lvi); lvPresets.SelectLast(); txtPresetName.Focus(); } }
/// <summary> /// Add a new preset to the settings preset list. /// </summary> /// <param name="preset">Preset object to add.</param> /// <param name="save">If you want to save the file afterwards.</param> public void AddPreset(Preset preset, bool save = true) { // Add the preset to the list. Presets.Add(preset); // Save the file if save is true if (save) { Save(this); } }
private void AddPreset(ImageEffectPreset preset) { if (preset != null) { Presets.Add(preset); cbPresets.Items.Add(preset); cbPresets.SelectedIndex = cbPresets.Items.Count - 1; LoadPreset(preset); txtPresetName.Focus(); } }
public void SavingAndLoadingCustom(string name, string flags) { Presets.Add(name, flags); var loaded = Presets.Load(name); Assert.Equal(name, loaded.Name); Assert.Equal(flags, loaded.FlagString); Presets.Remove(name); }
public VCPCode(eVCPCode code, String name = "", String description = "", params byte[] presets) : this() { this.Code = code; foreach (byte preset in presets) { Presets.Add(preset); } this.Name = name; this.Description = description; }
/// <summary> /// Adding new preset. /// </summary> private void OnAddPreset() { // Can't do unless game is loaded. if (!CheckCanDo()) { return; } try { // Create window for add preset. var win = new NewPreset { // Owner set to MainWindow. Owner = Application.Current.MainWindow }; // Get the VM for this window. var vm = win.DataContext as NewPresetViewModel; // Show the dialog for the preset window. if (win.ShowDialog() == true) { // Initialize the creation of our preset with the preset name. var p = new Preset() { Name = vm.Name }; // If we use the current waymarks, set them in our preset. if (vm.UseCurrentWaymarks) { p.A = GameMemory.A; p.B = GameMemory.B; p.C = GameMemory.C; p.D = GameMemory.D; p.One = GameMemory.One; p.Two = GameMemory.Two; p.Three = GameMemory.Three; p.Four = GameMemory.Four; p.MapID = GameMemory.MapID; } // Add the preset. Presets.Add(p); } } catch (Exception ex) { MessageBox.Show("Something happened while creating your preset!", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Error); logger.Error(ex, "Exception while adding a new preset."); } }
private void AddPreset(ImageEffectPreset preset) { if (preset != null) { Presets.Add(preset); cbPresets.Items.Add(preset); ignorePresetsSelectedIndexChanged = true; cbPresets.SelectedIndex = cbPresets.Items.Count - 1; ignorePresetsSelectedIndexChanged = false; LoadPreset(preset); txtPresetName.Focus(); } }
void UpdatePresetList() { Presets.Clear(); for (var a = 0; a < 128; ++a) { var name = BassMidi.FontGetPreset(_font, a, _drums ? 128 : 0) ?? ""; // get preset name Presets.Add(new KeyValuePair <int, string>(a, $"{a:D3}: {name}")); } Preset = 0; }
/// <summary> /// Sets a few defaults the players to use /// </summary> private static void InitializeDefaultPresetWindows() { Standard = CreatePresetWindows("Standard*", 0); Presets.Add(CreatePresetWindows("Peaceful", -3)); Presets.Add(CreatePresetWindows("Lenient", -2)); Presets.Add(CreatePresetWindows("Chill", -1)); Presets.Add(Standard); Presets.Add(CreatePresetWindows("Strict", 1)); Presets.Add(CreatePresetWindows("Tough", 2)); Presets.Add(CreatePresetWindows("Extreme", 3)); Presets.Add(CreatePresetWindows("Impossible", 8)); }
private void BuildPresets(XmlElement presetsElement) { foreach (XmlNode child in presetsElement.ChildNodes) { XmlElement childElement = child as XmlElement; if (childElement == null) { continue; } Preset preset = new Preset(RootGroup, childElement); Presets.Add(preset); } }
public int ImportPreset(GamePreset gamePresetData) { try { WaymarkPreset importedPreset = WaymarkPreset.Parse(gamePresetData); importedPreset.Name = "Imported"; Presets.Add(importedPreset); return(Presets.Count - 1); } catch { return(-1); } }
void ReloadPresets() { Presets.Clear(); subscription.Add(CurrentSession.GetPresets(profileToken) .ObserveOnCurrentDispatcher() .Subscribe(presets => { presets.ForEach(pres => { Presets.Add(pres); }); }, err => { dbg.Error(err); SetErrorMessage(err.Message); })); }
public PresetStyle GetPresetStyle(string name) { string key = DevNotepad.Config.Themes.ClassName(name); if (_PresetsDict.ContainsKey(key)) { return(_PresetsDict[key]); } PresetStyle style = new PresetStyle() { Name = key }; _PresetsDict.Add(key, style); Presets.Add(style); return(style); }
public static void AddPreset(ImagePreset preset) { if (preset == null) { throw new ArgumentException("Preset may not be null."); } if (string.IsNullOrEmpty(preset.Name)) { throw new ArgumentException("Preset name may not be null or empty."); } if (Presets.ContainsKey(preset.Name)) { throw new ArgumentException("Preset name already exists in collection."); } Presets.Add(preset.Name, preset); }
/// <summary> /// Clicking import button. /// </summary> private void OnImport() { // Create new import window. var import = new Import { // Owner set to MainWindow. Owner = Application.Current.MainWindow }; // Get the view model. var vm = import.DataContext as ImportViewModel; // Add the imported preset if it came back okay. if (import.ShowDialog() == true && vm.ImportedPreset != null) { Presets.Add(vm.ImportedPreset); } }
public async Task NewItemClickedAsync(ButtonClickArgs args) { var e = (ButtonClickArgs)args; var title = $"{e.Action} {e.ItemDescriptor}"; var message = $"{e.Action} {e.ItemDescriptor}: "; var selectedItem = SelectedPreset; var results = CrudDialogProvider.Show(new NestedViewModel <PresetViewModel>(title, message, selectedItem, DialogButtons.OkCancel)); if (results.DialogResult != DialogResults.Ok) { return; } var newPreset = await _presetController.CreateAsync(results.InnerResults.Name, results.InnerResults.ProcessName); Presets.Add(newPreset); SelectedPreset = newPreset; }
/// <summary> /// Adding new preset. /// </summary> private void OnAddPreset() { // Can't do unless game is loaded. if (!CheckCanDo()) { return; } // Create window for add preset. var win = new NewPreset { // Owner set to MainWindow. Owner = Application.Current.MainWindow }; // Get the VM for this window. var vm = win.DataContext as NewPresetViewModel; // Show the dialog for the preset window. if (win.ShowDialog() == true) { // Initialize the creation of our preset with the preset name. var p = new Preset() { Name = vm.Name }; // If we use the current waymarks, set them in our preset. if (vm.UseCurrentWaymarks) { p.A = GameMemory.A; p.B = GameMemory.B; p.C = GameMemory.C; p.D = GameMemory.D; p.One = GameMemory.One; p.Two = GameMemory.Two; p.MapID = GameMemory.MapID; } // Add the preset. Presets.Add(p); } }
public PresetSaveResultEnum AddPreset(int presetId, int symbolId, bool saveEquipement) { if (presetId < 0 || presetId > 8) { return(PresetSaveResultEnum.PRESET_SAVE_ERR_UNKNOWN); } if (Presets.Count > MaxPresets) { return(PresetSaveResultEnum.PRESET_SAVE_ERR_TOO_MANY); } var preset = new PlayerPresetRecord { OwnerId = Owner.Id, PresetId = presetId, SymbolId = symbolId, Objects = new List <PresetItem>(), IsNew = true }; if (IsPresetExist(presetId) && !saveEquipement) { var oldPreset = GetPreset(presetId); preset.Objects = oldPreset.Objects; } else { foreach (var item in GetEquipedItems()) { preset.AddObject(new PresetItem((byte)item.Position, (short)item.Template.Id, item.Guid)); } Owner.Shortcuts.AddPresetShortcut(Owner.Shortcuts.GetNextFreeSlot(ShortcutBarEnum.GENERAL_SHORTCUT_BAR), presetId); } RemovePreset(presetId); Presets.Add(preset); InventoryHandler.SendInventoryPresetUpdateMessage(Owner.Client, preset.GetNetworkPreset()); return(PresetSaveResultEnum.PRESET_SAVE_OK); }
public int ImportPreset(string importStr) { try { WaymarkPreset importedPreset = JsonConvert.DeserializeObject <WaymarkPreset>(importStr); if (importedPreset != null) { Presets.Add(importedPreset); return(Presets.Count - 1); } else { return(-1); } } catch { return(-1); } }