private void Button_Click(object sender, RoutedEventArgs e) { try { //Condition returnCondition = Activator.CreateInstance(_CurrentConditionType) as Condition; //Dictionary<string, object> _values = new Dictionary<string, object>(); //var controls = Util.FindVisualChildren<FrameworkElement>(variablesGrid).Where(d => d.Tag != null && d.Tag.ToString().StartsWith("variable::")); //foreach (var c in controls) //{ // _values.Add(c.Tag.ToString().Substring(10), GetValueFromControl(c)); //} //foreach (var k in _values) //{ // var field = returnCondition.GetType().GetField(k.Key); // field.SetValue(returnCondition, Convert.ChangeType(k.Value, field.FieldType)); //} if (variablesGrid.DataContext == null) { DialogResult = false; } else { DialogResult = true; } Result = variablesGrid.DataContext as Condition; Close(); } catch { MessageBox.Show(LocalizationManager.Current.Interface["Editor_Condition_Fail"]); } // write some error message or something like that }
public NPCMessage() { pages = new List <string>(); conditions = new Condition[0]; rewards = new Reward[0]; prev = 0; }
public NPCResponse() { mainText = ""; conditions = new Condition[0]; rewards = new Reward[0]; visibleIn = new int[0]; }
private void TypeBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { saveButton.IsEnabled = true; if (e.AddedItems.Count == 0) { return; } Type type = (typeBox.SelectedItem as ComboBoxItem).Tag as Type; Condition newCondition = (Condition)Activator.CreateInstance(type); _CurrentConditionType = type; ClearParameters(); variablesGrid.DataContext = newCondition; System.Collections.Generic.IEnumerable <FrameworkElement> controls = newCondition.GetControls(); int mult = controls.Count(); foreach (FrameworkElement c in controls) { variablesGrid.Children.Add(c); } double newHeight = (baseHeight + (heightDelta * (mult + (mult > 1 ? 1 : 0)))); if (AppConfig.Instance.animateControls) { DoubleAnimation anim = new DoubleAnimation(Height, newHeight, new Duration(new TimeSpan(0, 0, 0, 0, 500))); BeginAnimation(HeightProperty, anim); } else { Height = newHeight; } }
public Universal_ConditionEditor(Condition condition = null, bool viewLocalization = false) { InitializeComponent(); double scale = AppConfig.Instance.scale; viewLocalizationField = viewLocalization; ClearParameters(); Height *= scale; Width *= scale; baseHeight = Height; heightDelta *= scale; gridScale.ScaleX = scale; gridScale.ScaleY = scale; bool _chosen = false; int _index = 0; foreach (Type t in Condition.GetTypes()) { ComboBoxItem cbi = new ComboBoxItem { Content = LocalizationManager.Current.Condition[$"Type{Condition.GetLocalizationKey(t.Name)}"], Tag = t }; typeBox.Items.Add(cbi); if (!_chosen && condition != null && condition.GetType() == t) { typeBox.SelectedIndex = _index; _chosen = true; //var fieldControls = Util.FindVisualChildren<FrameworkElement>(variablesGrid). // Where(d => d.Tag != null && d.Tag.ToString().StartsWith("variable::")); //foreach (var fControl in fieldControls) //{ // SetValueToControl(fControl, condition.GetType().GetField(fControl.Tag.ToString().Substring(10)).GetValue(condition)); //} } _index++; } if (condition != null) { variablesGrid.DataContext = condition; } saveButton.IsEnabled = condition != null; }
private void Button_Click(object sender, RoutedEventArgs e) { try { if (variablesGrid.DataContext == null) { DialogResult = false; } else { DialogResult = true; } Result = variablesGrid.DataContext as Condition; Close(); } catch { MessageBox.Show(LocalizationManager.Current.Interface["Editor_Condition_Fail"]); } // write some error message or something like that }
public Universal_ConditionEditor(Condition condition = null) { InitializeComponent(); double scale = AppConfig.Instance.scale; ClearParameters(); Height *= scale; Width *= scale; baseHeight = Height; heightDelta *= scale; gridScale.ScaleX = scale; gridScale.ScaleY = scale; bool _chosen = false; int _index = 0; foreach (Type t in Condition.GetTypes()) { ComboBoxItem cbi = new ComboBoxItem { Content = LocalizationManager.Current.Condition[$"Type{Condition.GetLocalizationKey(t.Name)}"], Tag = t }; typeBox.Items.Add(cbi); if (!_chosen && condition != null && condition.GetType() == t) { typeBox.SelectedIndex = _index; _chosen = true; } _index++; } if (condition != null) { variablesGrid.DataContext = condition; } saveButton.IsEnabled = condition != null; }
private void EditButton_Click(object sender, RoutedEventArgs e) { if (Type == ReturnType.Condition) { Condition Condition = Value as Condition; Forms.Universal_ConditionEditor uce = new Forms.Universal_ConditionEditor(Condition, Localizable); uce.ShowDialog(); if (uce.DialogResult == true) { Value = uce.Result; mainLabel.Content = Value is IHasUIText ? (Value as IHasUIText).UIText : Value.ToString(); mainLabel.ToolTip = mainLabel.Content; } } else if (Type == ReturnType.Dialogue) { return; } else if (Type == ReturnType.Quest) { return; } else if (Type == ReturnType.Reward) { Reward reward = Value as Reward; Forms.Universal_RewardEditor ure = new Forms.Universal_RewardEditor(reward, Localizable); ure.ShowDialog(); if (ure.DialogResult == true) { Value = ure.Result; mainLabel.Content = Value is IHasUIText ? (Value as IHasUIText).UIText : Value.ToString(); mainLabel.ToolTip = mainLabel.Content; } } else if (Type == ReturnType.Vendor) { return; } else if (Type == ReturnType.VendorItem) { NPC.VendorItem Item = Value as NPC.VendorItem; bool old = Item.isBuy; Forms.Universal_VendorItemEditor uvie = new Forms.Universal_VendorItemEditor(Item); if (uvie.ShowDialog() == true) { NPC.VendorItem NewItem = uvie.Result as NPC.VendorItem; if (old != NewItem.isBuy) { if (NewItem.isBuy) { MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.RemoveItemSell(Util.FindParent <Universal_ItemList>(sender as Button)); MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.AddItemBuy(NewItem); } else { MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.RemoveItemBuy(Util.FindParent <Universal_ItemList>(sender as Button)); MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.AddItemSell(NewItem); } } Value = NewItem; } mainLabel.Content = Value is IHasUIText ? (Value as IHasUIText).UIText : Value.ToString(); mainLabel.ToolTip = mainLabel.Content; } else if (Type == ReturnType.Character) { return; } else if (Type == ReturnType.Object) { return; } }
private void EditButton_Click(object sender, RoutedEventArgs e) { switch (Type) { case ReturnType.Condition: { Condition Condition = Value as Condition; Forms.Universal_ConditionEditor uce = new Forms.Universal_ConditionEditor(Condition); uce.Owner = this.TryFindParent <Window>(); uce.ShowDialog(); if (uce.DialogResult == true) { Value = uce.Result; mainLabel.Content = Value is IHasUIText ? (Value as IHasUIText).UIText : Value.ToString(); mainLabel.ToolTip = mainLabel.Content; } break; } case ReturnType.Dialogue: return; case ReturnType.Quest: return; case ReturnType.Reward: { Reward reward = Value as Reward; Forms.Universal_RewardEditor ure = new Forms.Universal_RewardEditor(reward); ure.Owner = this.TryFindParent <Window>(); ure.ShowDialog(); if (ure.DialogResult == true) { Value = ure.Result; mainLabel.Content = Value is IHasUIText ? (Value as IHasUIText).UIText : Value.ToString(); mainLabel.ToolTip = mainLabel.Content; } break; } case ReturnType.Vendor: return; case ReturnType.VendorItem: { VendorItem Item = Value as VendorItem; bool old = Item.isBuy; Forms.Universal_VendorItemEditor uvie = new Forms.Universal_VendorItemEditor(Item); uvie.Owner = this.TryFindParent <Window>(); if (uvie.ShowDialog() == true) { VendorItem NewItem = uvie.Result as VendorItem; if (old != NewItem.isBuy) { if (NewItem.isBuy) { MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.RemoveItemSell(Util.FindParent <Universal_ItemList>(sender as Button)); MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.AddItemBuy(NewItem); } else { MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.RemoveItemBuy(Util.FindParent <Universal_ItemList>(sender as Button)); MainWindow.Instance.MainWindowViewModel.VendorTabViewModel.AddItemSell(NewItem); } } Value = NewItem; } mainLabel.Content = Value is IHasUIText ? (Value as IHasUIText).UIText : Value.ToString(); mainLabel.ToolTip = mainLabel.Content; break; } case ReturnType.Character: return; case ReturnType.Object: return; } }