public override void Init(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, DisplayableProperty <TKey, ReadableTuple <TKey> > dp) { _tab = tab; _configuration = (CustomTableInitializer)tab.Settings.AttributeList[1].AttachedObject; _configuration.AttributeTable = tab.Settings.AttributeList[1]; _tab.Settings.NewItemAddedFunction += item => item.SetRawValue(_configuration.AttributeTable, new Dictionary <int, ReadableTuple <int> >()); SdeDatabase gdb = _tab.ProjectDatabase; _table.Commands.CommandUndo += _commandChanged; _table.Commands.CommandRedo += _commandChanged; _table.Commands.CommandExecuted += _commandChanged; _table.Commands.ModifiedStateChanged += _visualUpdate; gdb.Commands.CommandUndo += _commandChanged2; gdb.Commands.CommandRedo += _commandChanged2; gdb.Commands.CommandExecuted += _commandChanged2; Grid grid = new Grid(); grid.SetValue(Grid.RowProperty, _row); grid.SetValue(Grid.ColumnProperty, 0); grid.SetValue(Grid.ColumnSpanProperty, 1); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(-1, GridUnitType.Auto) }); grid.RowDefinitions.Add(new RowDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); _lv = new RangeListView(); _lv.SetValue(TextSearch.TextPathProperty, "ID"); _lv.SetValue(WpfUtils.IsGridSortableProperty, true); _lv.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); _lv.SetValue(Grid.RowProperty, 1); _lv.Width = 334; _lv.FocusVisualStyle = null; _lv.Margin = new Thickness(3); _lv.BorderThickness = new Thickness(1); _lv.HorizontalAlignment = HorizontalAlignment.Left; _lv.SelectionChanged += _lv_SelectionChanged; SdeEditor.Instance.ProjectDatabase.Reloaded += _database_Reloaded; OnInitListView(); _lv.PreviewMouseDown += delegate { _lv.Focus(); Keyboard.Focus(_lv); }; _lv.ContextMenu = new ContextMenu(); _configuration.ListView = _lv; dp.AddResetField(_lv); dp.AddUpdateAction(_updateTable); _dp = new DisplayableProperty <TKey, ReadableTuple <TKey> >(); _dp.IsDico = true; _dp.DicoConfiguration = _configuration; grid.Children.Add(_lv); OnDeplayTable(); _tab.PropertiesGrid.Children.Add(grid); _dp.Deploy(_tab, null, true); DbSearchPanel dbSearchPanel = new DbSearchPanel(); dbSearchPanel._border1.BorderThickness = new Thickness(1); dbSearchPanel.Margin = new Thickness(3, 0, 3, 0); grid.Children.Add(dbSearchPanel); Settings = new GTabSettings <TKey, ReadableTuple <TKey> >(ServerDbs.MobGroups, tab.DbComponent); var attributes = _configuration.SubTableAttributeList.Take(_configuration.MaxElementsToCopy).Where(p => !p.IsSkippable).ToList(); if (!attributes.Any(p => p.IsDisplayAttribute)) { var att = _configuration.SubTableAttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute); if (att != null) { attributes.Insert(1, att); } } if (attributes.Count % 2 != 0) { attributes.Add(null); } Settings.AttributeList = _configuration.SubTableAttributeList; Settings.DbData = _configuration.ServerDb; Settings.AttId = attributes[0]; Settings.AttDisplay = attributes[1]; SearchEngine = Settings.SearchEngine; SearchEngine.SetAttributes(); SearchEngine.SetSettings(attributes[0], true); SearchEngine.SetSettings(attributes[1], true); SearchEngine.SetAttributes(attributes); SearchEngine.Init(dbSearchPanel, _lv, () => { var dico = _getSelectedGroups(); if (dico == null) { return(new List <ReadableTuple <TKey> >()); } return(dico.Values.Cast <ReadableTuple <TKey> >().ToList()); }); ApplicationShortcut.Link(ApplicationShortcut.Cut, Cut, _lv); foreach (var update in _dp.Updates) { Tuple <DbAttribute, FrameworkElement> x = update; if (x.Item1.DataType == typeof(bool)) { CheckBox element = (CheckBox)x.Item2; _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch(p => Debug.Ignore(() => p.IsChecked = item.GetValue <bool>(x.Item1))))); element.Checked += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, true); }; element.Unchecked += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, false); }; } else if ( x.Item1.DataType == typeof(string) || x.Item1.DataType == typeof(int)) { // This will convert integers to strings, but the database engine // is smart enough to auto-convert them to integers afterwards. TextBox element = (TextBox)x.Item2; _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch( delegate { try { string val = item.GetValue <string>(x.Item1); if (val == element.Text) { return; } element.Text = item.GetValue <string>(x.Item1); element.UndoLimit = 0; element.UndoLimit = int.MaxValue; } catch { } }))); element.TextChanged += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, element.Text); }; } } foreach (var property in _dp.FormattedProperties) { //property.Initialize() property.Init(tab, _dp); } }
public override void Init(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, DisplayableProperty <TKey, ReadableTuple <TKey> > dp) { _tab = tab; _initSettings(tab, dp); _tab.Settings.NewItemAddedFunction += item => item.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); GenericDatabase gdb = ((GenericDatabase)_tab.Database); _itemGroupsTable.Commands.PreviewCommandUndo += _previewCommandChanged; _itemGroupsTable.Commands.PreviewCommandRedo += _previewCommandChanged; _itemGroupsTable.Commands.PreviewCommandExecuted += _previewCommandChanged; _itemGroupsTable.Commands.CommandUndo += _commandChanged; _itemGroupsTable.Commands.CommandRedo += _commandChanged; _itemGroupsTable.Commands.CommandExecuted += _commandChanged; gdb.Commands.PreviewCommandUndo += _previewCommandChanged2; gdb.Commands.PreviewCommandRedo += _previewCommandChanged2; gdb.Commands.PreviewCommandExecuted += _previewCommandChanged2; gdb.Commands.CommandUndo += _commandChanged2; gdb.Commands.CommandRedo += _commandChanged2; gdb.Commands.CommandExecuted += _commandChanged2; Grid grid = new Grid(); grid.SetValue(Grid.RowProperty, _row); grid.SetValue(Grid.ColumnProperty, 0); grid.SetValue(Grid.ColumnSpanProperty, 1); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(-1, GridUnitType.Auto) }); grid.RowDefinitions.Add(new RowDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); Label label = new Label(); label.Content = "Item IDs"; label.FontStyle = FontStyles.Italic; label.Padding = new Thickness(0); label.Margin = new Thickness(3); _lv = new RangeListView(); _lv.SetValue(TextSearch.TextPathProperty, "ID"); _lv.SetValue(WpfUtils.IsGridSortableProperty, true); _lv.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); _lv.SetValue(Grid.RowProperty, 1); _lv.FocusVisualStyle = null; _lv.Margin = new Thickness(3); _lv.BorderThickness = new Thickness(1); _lv.HorizontalAlignment = HorizontalAlignment.Left; _lv.SelectionChanged += _lv_SelectionChanged; Extensions.GenerateListViewTemplate(_lv, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = ServerItemAttributes.Id.DisplayName, DisplayExpression = "ID", SearchGetAccessor = "ID", FixedWidth = 60, TextAlignment = TextAlignment.Right, ToolTipBinding = "ID" }, new ListViewDataTemplateHelper.RangeColumnInfo { Header = ServerItemAttributes.Name.DisplayName, DisplayExpression = "Name", SearchGetAccessor = "Name", IsFill = true, ToolTipBinding = "Name", TextWrapping = TextWrapping.Wrap, MinWidth = 70 }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Freq", DisplayExpression = "Drop", SearchGetAccessor = "Rate", ToolTipBinding = "Rate", FixedWidth = 40, TextAlignment = TextAlignment.Right }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Drop %", DisplayExpression = "Chance", SearchGetAccessor = "ChanceInt", ToolTipBinding = "Chance", FixedWidth = 60, TextAlignment = TextAlignment.Right } }, new DefaultListViewComparer <ItemView>(), new string[] { "Added", "Blue", "Modified", "Green", "Normal", "Black" }); _lv.ContextMenu = new ContextMenu(); _lv.MouseDoubleClick += new MouseButtonEventHandler(_lv_MouseDoubleClick); MenuItem miSelect = new MenuItem { Header = "Select", Icon = new Image { Source = (BitmapSource)ApplicationManager.PreloadResourceImage("arrowdown.png") } }; MenuItem miEditDrop = new MenuItem { Header = "Edit", Icon = new Image { Source = (BitmapSource)ApplicationManager.PreloadResourceImage("properties.png") } }; MenuItem miRemoveDrop = new MenuItem { Header = "Remove", Icon = new Image { Source = (BitmapSource)ApplicationManager.PreloadResourceImage("delete.png") } }; MenuItem miAddDrop = new MenuItem { Header = "Add", Icon = new Image { Source = (BitmapSource)ApplicationManager.PreloadResourceImage("add.png") } }; _lv.ContextMenu.Items.Add(miSelect); _lv.ContextMenu.Items.Add(miEditDrop); _lv.ContextMenu.Items.Add(miRemoveDrop); _lv.ContextMenu.Items.Add(miAddDrop); dp.AddResetField(_lv); miSelect.Click += new RoutedEventHandler(_miSelect_Click); miEditDrop.Click += new RoutedEventHandler(_miEditDrop_Click); miRemoveDrop.Click += new RoutedEventHandler(_miRemoveDrop_Click); miAddDrop.Click += new RoutedEventHandler(_miAddDrop_Click); dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(delegate(ReadableTuple <TKey> item) { Dictionary <int, ReadableTuple <int> > groups = (Dictionary <int, ReadableTuple <int> >)item.GetRawValue(1); if (groups == null) { groups = new Dictionary <int, ReadableTuple <int> >(); item.SetRawValue(1, groups); } Table <int, ReadableTuple <int> > btable = ((GenericDatabase)tab.Database).GetMetaTable <int>(ServerDbs.Items); if (groups.Count == 0) { _lv.ItemsSource = new RangeObservableCollection <ItemView>(); return; } List <ItemView> result = new List <ItemView>(); try { int chances = groups.Where(p => p.Key != 0).Sum(p => p.Value.GetValue <int>(ServerItemGroupSubAttributes.Rate)); result.AddRange(groups.Select(keypair => new ItemView(btable, groups, keypair.Key, chances)).OrderBy(p => p, Extensions.BindDefaultSearch <ItemView>(_lv, "ID"))); } catch { } _lv.ItemsSource = new RangeObservableCollection <ItemView>(result); })); _dp = new DisplayableProperty <TKey, ReadableTuple <TKey> >(); int line = 0; Grid subGrid = GTabsMaker.PrintGrid(ref line, 2, 1, 1, new SpecifiedIndexProvider(new int[] { //ServerItemGroupSubAttributes.Id.Index, -1, ServerItemGroupSubAttributes.Rate.Index, -1, ServerItemGroupSubAttributes.Amount.Index, -1, ServerItemGroupSubAttributes.Random.Index, -1, ServerItemGroupSubAttributes.IsAnnounced.Index, -1, ServerItemGroupSubAttributes.Duration.Index, -1, ServerItemGroupSubAttributes.IsNamed.Index, -1, ServerItemGroupSubAttributes.IsBound.Index, -1 }), -1, 0, -1, -1, _dp, ServerItemGroupSubAttributes.AttributeList); subGrid.VerticalAlignment = VerticalAlignment.Top; grid.Children.Add(label); grid.Children.Add(_lv); tab.PropertiesGrid.RowDefinitions.Clear(); tab.PropertiesGrid.RowDefinitions.Add(new RowDefinition()); tab.PropertiesGrid.ColumnDefinitions.Clear(); tab.PropertiesGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(340) }); tab.PropertiesGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(10) }); tab.PropertiesGrid.ColumnDefinitions.Add(new ColumnDefinition()); tab.PropertiesGrid.Children.Add(grid); _dp.Deploy(_tab, null, true); foreach (var update in _dp.Updates) { Tuple <DbAttribute, FrameworkElement> x = update; if (x.Item1.DataType == typeof(int)) { TextBox element = (TextBox)x.Item2; _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch( delegate { Debug.Ignore(() => element.Text = item.GetValue <int>(x.Item1).ToString(CultureInfo.InvariantCulture)); element.UndoLimit = 0; element.UndoLimit = int.MaxValue; }))); element.TextChanged += delegate { if (tab.ItemsEventsDisabled) { return; } try { if (tab.List.SelectedItem != null && _lv.SelectedItem != null) { _setSelectedItem(x.Item1, element.Text); } } catch (Exception err) { ErrorHandler.HandleException(err); } }; } else if (x.Item1.DataType == typeof(bool)) { CheckBox element = (CheckBox)x.Item2; _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch(p => Debug.Ignore(() => p.IsChecked = item.GetValue <bool>(x.Item1))))); element.Checked += delegate { if (tab.ItemsEventsDisabled) { return; } try { if (tab.List.SelectedItem != null && _lv.SelectedItem != null) { _setSelectedItem(x.Item1, true); } } catch (Exception err) { ErrorHandler.HandleException(err); } }; element.Unchecked += delegate { if (tab.ItemsEventsDisabled) { return; } try { if (tab.List.SelectedItem != null && _lv.SelectedItem != null) { _setSelectedItem(x.Item1, false); } } catch (Exception err) { ErrorHandler.HandleException(err); } }; } else if (x.Item1.DataType == typeof(string)) { TextBox element = (TextBox)x.Item2; _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch( delegate { try { string val = item.GetValue <string>(x.Item1); if (val == element.Text) { return; } element.Text = item.GetValue <string>(x.Item1); element.UndoLimit = 0; element.UndoLimit = int.MaxValue; } catch { } }))); element.TextChanged += delegate { if (tab.ItemsEventsDisabled) { return; } _validateUndo(tab, element.Text, x.Item1); if (ReferenceEquals(x.Item1, ServerItemGroupSubAttributes.Rate)) { ((RangeObservableCollection <ItemView>)_lv.ItemsSource).ToList().ForEach(p => p.VisualUpdate()); } }; } } }