Example #1
0
        private GridIndexProvider _findGrid(ICollection values)
        {
            int maxRow;
            int maxCol;

            if (values.Count < 10)
            {
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });
                maxRow = values.Count;
                maxCol = 1;
            }
            else if (values.Count < 20)
            {
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });

                maxRow = (values.Count + 1) / 2;
                maxCol = 2;
            }
            else if (values.Count < 30)
            {
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });

                maxRow = (values.Count + 1) / 3;
                maxCol = 3;
            }
            else
            {
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto), MaxWidth = _maxColWidth
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 20
                });

                maxRow = (values.Count + 1) / 4;
                maxCol = 4;
            }

            for (int i = 0; i < maxRow; i++)
            {
                _upperGrid.RowDefinitions.Add(new RowDefinition());
            }

            GridIndexProvider provider = new GridIndexProvider(maxRow, maxCol);

            return(provider);
        }
Example #2
0
        public GenericFlagDialog(DbAttribute attribute, string text, Type enumType, FlagTypeData flagTypeData, string description) : base(description, "cde.ico", SizeToContent.WidthAndHeight, ResizeMode.CanResize)
        {
            InitializeComponent();

            _value = text.ToLong();

            if (flagTypeData != null)
            {
                List <long> valuesEnum = flagTypeData.Values.Where(p => (p.DataFlag & FlagDataProperty.Hide) == 0).Select(p => p.Value).ToList();
                var         values     = flagTypeData.Values.Where(p => (p.DataFlag & FlagDataProperty.Hide) == 0).ToList();

                GridIndexProvider provider = _findGrid(values);

                var toolTips = new string[values.Count];

                for (int i = 0; i < values.Count; i++)
                {
                    toolTips[i] = _getTooltip(values[i].Description);
                }

                AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count);
                ToolTipsBuilder.Initialize(toolTips, this);

                int row;
                int col;

                for (int i = 0; i < values.Count; i++)
                {
                    provider.Next(out row, out col);

                    int      index = (int)iProvider.Next();
                    CheckBox box   = new CheckBox {
                        Content = values[index].Name, Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center
                    };

                    var      menu = new ContextMenu();
                    MenuItem item = new MenuItem();
                    item.Header     = "Restrict search to [" + values[index].Name + "]";
                    box.ContextMenu = menu;
                    menu.Items.Add(item);
                    item.Click += delegate {
                        var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

                        if (selected != null)
                        {
                            selected._dbSearchPanel._searchTextBox.Text = "([" + attribute.AttributeName + "] & " + "Flags." + values[index].Name + ") != 0";
                        }
                    };

                    box.Tag = valuesEnum[index];
                    WpfUtils.AddMouseInOutEffectsBox(box);
                    _boxes.Add(box);
                    _upperGrid.Children.Add(box);
                    WpfUtilities.SetGridPosition(box, row, 2 * col);
                }

                _boxes.ForEach(_addEvents);
            }
            else
            {
                if (enumType.BaseType != typeof(Enum))
                {
                    throw new Exception("Invalid argument type, excepted an enum.");
                }

                if (enumType == typeof(MobModeType))
                {
                    if (DbPathLocator.GetServerType() == ServerType.RAthena && !ProjectConfiguration.UseOldRAthenaMode)
                    {
                        enumType = typeof(MobModeTypeNew);
                    }
                }

                List <long> valuesEnum = Enum.GetValues(enumType).Cast <int>().Select(p => (long)p).ToList();
                var         values     = Enum.GetValues(enumType).Cast <Enum>().ToList();

                string[] commands = Description.GetAnyDescription(enumType).Split('#');

                if (commands.Any(p => p.StartsWith("max_col_width:")))
                {
                    _maxColWidth = Int32.Parse(commands.First(p => p.StartsWith("max_col_width")).Split(':')[1]);
                }

                GridIndexProvider provider = _findGrid(values);

                var toolTips = new string[values.Count];

                if (!commands.Contains("disable_tooltips"))
                {
                    for (int i = 0; i < values.Count; i++)
                    {
                        toolTips[i] = _getTooltip(Description.GetDescription(values[i]));
                    }
                }

                AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count);

                if (commands.Any(p => p.StartsWith("order:")))
                {
                    List <int> order = commands.First(p => p.StartsWith("order:")).Split(':')[1].Split(',').Select(Int32.Parse).ToList();

                    for (int i = 0; i < values.Count; i++)
                    {
                        if (!order.Contains(i))
                        {
                            order.Add(i);
                        }
                    }

                    iProvider = new SpecifiedIndexProvider(order);
                }

                ToolTipsBuilder.Initialize(toolTips, this);

                int        row;
                int        col;
                ServerType currentType = DbPathLocator.GetServerType();

                for (int i = 0; i < values.Count; i++)
                {
                    provider.Next(out row, out col);

                    int      index = (int)iProvider.Next();
                    CheckBox box   = new CheckBox {
                        Content = _getDisplay(Description.GetDescription(values[index])), Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center
                    };
                    ServerType type = _getEmuRestrition(Description.GetDescription(values[index]));

                    if ((type & currentType) != currentType)
                    {
                        box.IsEnabled = false;
                    }

                    var      menu = new ContextMenu();
                    MenuItem item = new MenuItem();
                    item.Header     = "Restrict search to [" + _getDisplay(Description.GetDescription(values[index])) + "]";
                    box.ContextMenu = menu;
                    menu.Items.Add(item);
                    item.Click += delegate {
                        var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

                        if (selected != null)
                        {
                            selected._dbSearchPanel._searchTextBox.Text = "([" + attribute.AttributeName + "] & " + valuesEnum[index] + ") != 0";
                        }
                    };

                    box.Tag = valuesEnum[index];
                    WpfUtils.AddMouseInOutEffectsBox(box);
                    _boxes.Add(box);
                    _upperGrid.Children.Add(box);
                    WpfUtilities.SetGridPosition(box, row, 2 * col);
                }

                _boxes.ForEach(_addEvents);
            }
        }
        public GenericFlagDialog(string text, Type enumType) : base(_getDisplay(Description.GetAnyDescription(enumType)), "cde.ico", SizeToContent.WidthAndHeight, ResizeMode.CanResize)
        {
            InitializeComponent();

            _value = text.ToInt();

            if (enumType.BaseType != typeof(Enum))
            {
                throw new Exception("Invalid argument type, excepted an enum.");
            }

            if (enumType == typeof(MobModeType))
            {
                if (DbPathLocator.GetServerType() == ServerType.RAthena && !ProjectConfiguration.UseOldRAthenaMode)
                {
                    enumType = typeof(MobModeTypeNew);
                }
            }

            var values     = Enum.GetValues(enumType).Cast <Enum>().ToList();
            var valuesEnum = Enum.GetValues(enumType).Cast <int>().ToList();

            string[] commands = Description.GetAnyDescription(enumType).Split('#');

            if (commands.Any(p => p.StartsWith("max_col_width:")))
            {
                _maxColWidth = Int32.Parse(commands.First(p => p.StartsWith("max_col_width")).Split(':')[1]);
            }

            GridIndexProvider provider = _findGrid(values);

            var toolTips = new string[values.Count];

            if (!commands.Contains("disable_tooltips"))
            {
                for (int i = 0; i < values.Count; i++)
                {
                    toolTips[i] = _getTooltip(Description.GetDescription(values[i]));
                }
            }

            AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count);

            if (commands.Any(p => p.StartsWith("order:")))
            {
                List <int> order = commands.First(p => p.StartsWith("order:")).Split(':')[1].Split(',').Select(Int32.Parse).ToList();

                for (int i = 0; i < values.Count; i++)
                {
                    if (!order.Contains(i))
                    {
                        order.Add(i);
                    }
                }

                iProvider = new SpecifiedIndexProvider(order);
            }

            ToolTipsBuilder.Initialize(toolTips, this);

            int        row;
            int        col;
            ServerType currentType = DbPathLocator.GetServerType();

            for (int i = 0; i < values.Count; i++)
            {
                provider.Next(out row, out col);

                int      index = (int)iProvider.Next();
                CheckBox box   = new CheckBox {
                    Content = _getDisplay(Description.GetDescription(values[index])), Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center
                };
                ServerType type = _getEmuRestrition(Description.GetDescription(values[index]));

                if ((type & currentType) != currentType)
                {
                    box.IsEnabled = false;
                }

                box.Tag = valuesEnum[index];
                WpfUtils.AddMouseInOutEffectsBox(box);
                _boxes.Add(box);
                _upperGrid.Children.Add(box);
                WpfUtilities.SetGridPosition(box, row, 2 * col);
            }

            _boxes.ForEach(_addEvents);
        }