コード例 #1
0
        private void _threadStart(object sender, TextChangedEventArgs e)
        {
            try {
                var    text  = _textBox.Text;
                var    tuple = e == null ? sender as ReadableTuple <int> : _tab._listView.SelectedItem as ReadableTuple <int>;
                byte[] data  = _tab.ProjectDatabase.MetaGrf.GetData(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath, text) + _ext));

                if (tuple != null)
                {
                    if (e != null)
                    {
                        _redirect = tuple.GetIntNoThrow(ServerMobAttributes.Sprite);
                    }

                    if (_redirect > 0)
                    {
                        var db = _tab.GetMetaTable <int>(ServerDbs.Mobs);
                        tuple     = db.TryGetTuple(_redirect);
                        _redirect = 0;

                        if (tuple != null)
                        {
                            var val = tuple.GetValue <string>(ServerMobAttributes.ClientSprite);
                            data = _tab.ProjectDatabase.MetaGrf.GetData(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath, val) + _ext));
                        }
                    }
                }

                if (data != null)
                {
                    if (_ext == ".spr")
                    {
                        try {
                            var image = Spr.GetFirstImage(data);

                            if (image != null)
                            {
                                _wrapper.Image = image;
                                _wrapper.Image.MakePinkTransparent();
                                _wrapper.Image.MakeFirstPixelTransparent();

                                _image.BeginDispatch(delegate {
                                    var bitmap    = _wrapper.Image.Cast <BitmapSource>();
                                    _image.Tag    = text;
                                    _image.Source = bitmap;
                                });
                            }
                            else
                            {
                                _cancelImage();
                            }
                        }
                        catch {
                            _cancelImage();
                        }
                    }
                    else
                    {
                        _wrapper.Image = ImageProvider.GetImage(data, _ext);
                        _wrapper.Image.MakePinkTransparent();
                        _wrapper.Image.MakeFirstPixelTransparent();

                        _image.BeginDispatch(delegate {
                            var bitmap    = _wrapper.Image.Cast <BitmapSource>();
                            _image.Tag    = text;
                            _image.Source = bitmap;
                        });
                    }
                }
                else
                {
                    _cancelImage();
                }
            }
            catch (Exception err) {
                _cancelImage();
                ErrorHandler.HandleException(err);
            }
        }
コード例 #2
0
        public void Init(GDbTabWrapper <TKey, TValue> tab, DisplayableProperty <TKey, TValue> dp)
        {
            _tab = tab;

            DisplayableProperty <TKey, TValue> .RemoveUndoAndRedoEvents(_textBox, _tab);

            //_autocompleteService = new AutocompleteService(_tab.List, _tbIdResource, _tbUnResource, _tbIdDisplayName, _tbUnDisplayName, _tbIdDesc, _tbUnDesc);

            dp.AddResetField(_textBox);
            dp.AddResetField(_realBox);

            Border border = new Border();

            border.BorderBrush     = SystemColors.ActiveBorderBrush;
            border.BorderThickness = new Thickness(1);
            border.Child           = _textBox;

            border.SetValue(Grid.RowProperty, _gridRow);
            border.SetValue(Grid.ColumnProperty, _gridColumn + 1);
            border.Margin = new Thickness(3);

            _tab.PropertiesGrid.Children.Add(border);

            StackPanel panel = new StackPanel();

            panel.SetValue(Grid.RowProperty, _gridRow);
            panel.SetValue(Grid.ColumnProperty, _gridColumn);

            Label label = new Label {
                Content = "Description"
            };

            label.SetValue(TextBlock.ForegroundProperty, Application.Current.Resources["TextForeground"] as Brush);

            Button button = new Button();

            button.Margin = new Thickness(3);

            panel.Children.Add(label);
            panel.Children.Add(button);
            _textBox.GotFocus += delegate { _lastAccessed = _textBox; };

            if (_quickEdit)
            {
                _tab.List.SelectionChanged += new SelectionChangedEventHandler(_list_SelectionChanged);
                button.Content              = "Quick edit...";
                button.Click += new RoutedEventHandler(_buttonQuickEdit_Click);

                TextEditorColorControl colorControl = new TextEditorColorControl();
                Label label2 = new Label {
                    Content = "Color picker"
                };
                label2.SetValue(TextBlock.ForegroundProperty, Application.Current.Resources["TextForeground"] as Brush);

                _tecc         = colorControl;
                _lastAccessed = _textBox;
                colorControl.Init(_getActive);

                Button itemScript = new Button {
                    Margin = new Thickness(3), Content = "Item bonus"
                };
                itemScript.Click += delegate {
                    itemScript.IsEnabled = false;

                    var meta = _tab.GetMetaTable <int>(ServerDbs.Items);
                    var item = _tab._listView.SelectedItem as ReadableTuple <int>;

                    _update = new Func <ReadableTuple <int>, string>(tuple => {
                        var output = new StringBuilder();

                        if (tuple != null)
                        {
                            var entry = meta.TryGetTuple(tuple.Key);

                            if (entry != null)
                            {
                                output.AppendLine("-- Script --");
                                output.AppendLine(entry.GetValue <string>(ServerItemAttributes.Script));
                                output.AppendLine("-- OnEquipScript --");
                                output.AppendLine(entry.GetValue <string>(ServerItemAttributes.OnEquipScript));
                                output.AppendLine("-- OnUnequipScript --");
                                output.AppendLine(entry.GetValue <string>(ServerItemAttributes.OnUnequipScript));
                            }
                            else
                            {
                                output.AppendLine("-- Not found in item_db_m --");
                            }
                        }
                        else
                        {
                            output.AppendLine("-- No entry selected --");
                        }

                        return(output.ToString());
                    });

                    _scriptEdit         = new ScriptEditDialog(_update(item));
                    _scriptEdit.Closed += delegate {
                        itemScript.IsEnabled = true;
                        _scriptEdit          = null;
                    };

                    _scriptEdit._textEditor.IsReadOnly = true;
                    _scriptEdit.DisableOk();
                    _scriptEdit.Show();
                    _scriptEdit.Owner = WpfUtilities.FindParentControl <Window>(_tab);
                };

                panel.Children.Add(itemScript);
                panel.Children.Add(label2);
                panel.Children.Add(colorControl);
            }
            else
            {
                if (_tecc != null)
                {
                    var t = _lastAccessed;
                    _lastAccessed = _textBox;
                    _tecc.Init(_getActive);
                    _lastAccessed = t;
                }

                button.Content = "Copy >";
                button.Click  += new RoutedEventHandler(_buttonAutocomplete_Click);
            }

            tab.PropertiesGrid.Children.Add(panel);

            dp.AddUpdateAction(new Action <TValue>(item => _textBox.Dispatch(delegate {
                Debug.Ignore(() => _realBox.Text = item.GetValue <string>(_attribute));
                //Debug.Ignore(() => _textBox.Text = item.GetValue<string>(_attribute));
                _realBox.UndoLimit = 0;
                _realBox.UndoLimit = int.MaxValue;

                //Debug.Ignore(() => _textBox.Text = item.GetValue<string>(_attribute));
                _textBox.Document.UndoStack.SizeLimit = 0;
                _textBox.Document.UndoStack.SizeLimit = int.MaxValue;
            })));

            _realBox.TextChanged += delegate {
                WpfUtilities.UpdateRtb(_previewTextBox, _realBox.Text, true);
                if (_avalonUpdate)
                {
                    return;
                }
                _textBox.Text = _realBox.Text;
            };
        }