Esempio n. 1
0
        private void _tbImport_Click(object sender, RoutedEventArgs e)
        {
            Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs);

            SelectFromDialog select = new SelectFromDialog(btable, ServerDbs.Mobs, "");

            select.Owner = WpfUtilities.TopWindow;

            if (select.ShowDialog() == true)
            {
                _eventsDisabled = true;
                ReadableTuple <int> tuple = btable.GetTuple(select.Id.ToInt());
                _level = tuple.GetValue <int>(ServerMobAttributes.Lv);

                for (int i = 0; i < 6; i++)
                {
                    _rates[i] = tuple.GetValue <int>(ServerMobAttributes.Str.Index + i);
                }

                _gpRate.SetPosition(_level / Limit, false);

                _setValues();
                _eventsDisabled = false;
            }
        }
Esempio n. 2
0
        private void _buttonQuery_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SelectFromDialog(_gdb.GetMetaTable <int>(_sdb), _sdb, _tbId.Text);

            dialog.Owner = this;

            if (dialog.ShowDialog() == true)
            {
                _tbId.Text = dialog.Id;
            }
        }
Esempio n. 3
0
        private void _buttonSearch_Click(object sender, RoutedEventArgs e)
        {
            try {
                SelectFromDialog dialog = new SelectFromDialog(_tab.To <int>().Table, _tab.DbComponent.DbSource, _tab._listView.SelectedItem == null ? "" : (_tab._listView.SelectedItem as ReadableTuple <int>).Key.ToString());
                if (dialog.ShowDialog() == true)
                {
                    var id = Int32.Parse(dialog.Id);

                    _based = _tab.To <int>().GetMetaTable <int>(_tab.DbComponent.DbSource).TryGetTuple(id);

                    if (_based != null)
                    {
                        _tbBasedOn.Text     = id.ToString(CultureInfo.InvariantCulture);
                        _imReset.Visibility = Visibility.Visible;
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Esempio n. 4
0
        public LevelEditDialog(string text, object maxLevel, LevelEditFlag flag) : base("Level edit", "cde.ico", SizeToContent.Height, ResizeMode.CanResize)
        {
            _autoFill = (flag & LevelEditFlag.AutoFill) == LevelEditFlag.AutoFill;
            InitializeComponent();
            Extensions.SetMinimalSize(this);
            _flag   = flag;
            _itemDb = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items);

            int max;

            if (maxLevel is int)
            {
                max = (int)maxLevel;
            }
            else if (maxLevel is string)
            {
                if (!Int32.TryParse((string)maxLevel, out max))
                {
                    max = 20;
                }
            }
            else
            {
                max = 20;
            }

            if (max <= 0)
            {
                _tkInfo.Visibility = Visibility.Visible;
                _partialFill       = true;
                max = 30;
            }

            List <string> values       = new List <string>();
            List <string> valuesAmount = new List <string>();

            if ((flag & LevelEditFlag.ShowAmount) == LevelEditFlag.ShowAmount)
            {
                var temp = text.Split(new char[] { ':' });

                for (int i = 0; i < temp.Length; i += 2)
                {
                    values.Add(temp[i]);

                    if (i + 1 < temp.Length)
                    {
                        valuesAmount.Add(temp[i + 1]);
                    }
                    else
                    {
                        valuesAmount.Add("0");
                    }
                }
            }
            else
            {
                values = text.Split(new char[] { ':' }).ToList();
            }

            if (values.Count > max)
            {
                max = values.Count;
            }

            for (int i = 0; i < max; i++)
            {
                Label label = new Label();
                label.Content           = "Level " + (i + 1);
                label.Padding           = new Thickness(0);
                label.Margin            = new Thickness(3);
                label.VerticalAlignment = VerticalAlignment.Center;

                label.SetValue(Grid.RowProperty, i % 10);
                label.SetValue(Grid.ColumnProperty, (i / 10) * 3);

                _upperGrid.Children.Add(label);
            }

            int numOfColumns = ((max - 1) / 10) + 1;

            numOfColumns = numOfColumns > 3 ? 3 : numOfColumns;

            Width = 300 * numOfColumns;

            for (int i = 0; i < numOfColumns; i++)
            {
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto)
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition());
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto)
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto)
                });
                _upperGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto)
                });
            }

            for (int i = 0; i < max; i++)
            {
                Label preview = new Label();
                preview.Padding             = new Thickness(0);
                preview.Margin              = new Thickness(3);
                preview.VerticalAlignment   = VerticalAlignment.Center;
                preview.HorizontalAlignment = HorizontalAlignment.Right;

                TextBlock preview2 = new TextBlock();
                preview2.Padding           = new Thickness(0);
                preview2.Margin            = new Thickness(7, 6, 3, 6);
                preview2.TextAlignment     = TextAlignment.Left;
                preview2.IsHitTestVisible  = false;
                preview2.VerticalAlignment = VerticalAlignment.Center;
                preview2.Foreground        = Brushes.DarkGray;

                Label amountLabel = new Label();
                amountLabel.Padding             = new Thickness(0);
                amountLabel.Margin              = new Thickness(3);
                amountLabel.VerticalAlignment   = VerticalAlignment.Center;
                amountLabel.HorizontalAlignment = HorizontalAlignment.Right;
                amountLabel.Content             = "Amount " + (i + 1);

                TextBox box = new TextBox();
                box.Margin            = new Thickness(3, 6, 3, 6);
                box.VerticalAlignment = VerticalAlignment.Center;
                box.TabIndex          = i * 10 + 0;

                TextBox amount = new TextBox();
                amount.Margin            = new Thickness(3, 6, 3, 6);
                amount.VerticalAlignment = VerticalAlignment.Center;
                amount.TabIndex          = i * 10 + 1;

                box.SetValue(Grid.RowProperty, i % 10);
                preview2.SetValue(Grid.RowProperty, i % 10);
                preview.SetValue(Grid.RowProperty, i % 10);
                amountLabel.SetValue(Grid.RowProperty, i % 10);
                amount.SetValue(Grid.RowProperty, i % 10);

                box.SetValue(Grid.ColumnProperty, (i / 10) * 5 + 1);
                preview2.SetValue(Grid.ColumnProperty, (i / 10) * 5 + 1);
                preview.SetValue(Grid.ColumnProperty, (i / 10) * 5 + 2);
                amountLabel.SetValue(Grid.ColumnProperty, (i / 10) * 5 + 3);
                amount.SetValue(Grid.ColumnProperty, (i / 10) * 5 + 4);

                amount.Width = 30;

                if ((flag & LevelEditFlag.ItemDbPick) == LevelEditFlag.ItemDbPick)
                {
                    Button selectButton = new Button();

                    selectButton.Content = new Image {
                        Source = ApplicationManager.PreloadResourceImage("arrowdown.png"), Stretch = Stretch.None
                    };

                    selectButton.Click += delegate {
                        try {
                            SelectFromDialog select = new SelectFromDialog(_itemDb, ServerDbs.Items, box.Text);
                            select.Owner = WpfUtilities.TopWindow;

                            if (select.ShowDialog() == true)
                            {
                                box.Text = select.Id;
                            }
                        }
                        catch (Exception err) {
                            ErrorHandler.HandleException(err);
                        }
                    };

                    selectButton.SetValue(Grid.RowProperty, i % 10);
                    selectButton.SetValue(Grid.ColumnProperty, (i / 10) * 3 + 2);
                    selectButton.Width  = 22;
                    selectButton.Height = 22;
                    selectButton.Margin = new Thickness(3, 3, 3, 3);
                    _upperGrid.Children.Add(selectButton);
                }

                _upperGrid.Children.Add(box);
                _upperGrid.Children.Add(preview2);

                if ((flag & LevelEditFlag.ShowPreview) == LevelEditFlag.ShowPreview)
                {
                    _upperGrid.Children.Add(preview);
                }

                if ((flag & LevelEditFlag.ShowAmount) == LevelEditFlag.ShowAmount)
                {
                    _upperGrid.Children.Add(amountLabel);
                    _upperGrid.Children.Add(amount);
                }

                if ((flag & LevelEditFlag.ShowPreview2) == LevelEditFlag.ShowPreview2)
                {
                    box.GotFocus += delegate {
                        box.Foreground      = Application.Current.Resources["TextForeground"] as Brush;
                        preview2.Visibility = Visibility.Collapsed;
                    };

                    box.LostFocus += delegate {
                        if ((flag & LevelEditFlag.ItemDbPick) == LevelEditFlag.ItemDbPick)
                        {
                            preview2.Text = _getPreview(box.Text);

                            if (preview2.Text == "")
                            {
                                box.Foreground      = Application.Current.Resources["TextForeground"] as Brush;
                                preview2.Visibility = Visibility.Collapsed;
                            }
                            else
                            {
                                box.Foreground      = Application.Current.Resources["UIThemeTextBoxBackgroundColor"] as Brush;
                                preview2.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            if (box.Text == "")
                            {
                                preview2.Visibility = Visibility.Visible;
                            }
                        }
                    };
                }

                if ((flag & LevelEditFlag.ShowPreview) == LevelEditFlag.ShowPreview)
                {
                    box.TextChanged += delegate {
                        int val;

                        if (Int32.TryParse(box.Text, out val))
                        {
                            if (val % 1000 == 0)
                            {
                                if (val > 60000)
                                {
                                    preview.Content = String.Format("{0:0}m:{1:00}s", val / 60000, (val % 60000) / 1000);
                                }
                                else
                                {
                                    preview.Content = String.Format("{0:0}s", val / 1000);
                                }
                            }
                            else
                            {
                                if (val > 60000)
                                {
                                    preview.Content = String.Format("{0:0}m:{1:00}.{2:000}s", val / 60000, (val % 60000) / 1000, val % 1000);
                                }
                                else
                                {
                                    preview.Content = String.Format("{0:0}.{1:000}s", val / 1000, val % 1000);
                                }
                            }
                        }
                        else
                        {
                            preview.Content = "";
                        }
                    };
                }

                box.KeyDown += delegate {
                    if (Keyboard.IsKeyDown(Key.Enter))
                    {
                        if (!SdeAppConfiguration.UseIntegratedDialogsForLevels)
                        {
                            DialogResult = true;
                        }

                        Close();
                    }
                };

                box.GotKeyboardFocus += delegate {
                    if (Keyboard.IsKeyDown(Key.Tab))
                    {
                        box.SelectAll();
                    }
                };

                amount.GotKeyboardFocus += delegate {
                    if (Keyboard.IsKeyDown(Key.Tab))
                    {
                        amount.SelectAll();
                    }
                };

                if (i < values.Count)
                {
                    box.Text = values[i];
                }

                if (i < valuesAmount.Count)
                {
                    amount.Text = valuesAmount[i];
                }

                if ((flag & LevelEditFlag.ShowPreview2) == LevelEditFlag.ShowPreview2)
                {
                    box.TextChanged += delegate {
                        if ((flag & LevelEditFlag.ItemDbPick) == LevelEditFlag.ItemDbPick)
                        {
                            if (!box.IsFocused)
                            {
                                box.Foreground      = Application.Current.Resources["UIThemeTextBoxBackgroundColor"] as Brush;
                                preview2.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            if (box.Text != "")
                            {
                                preview2.Visibility = Visibility.Collapsed;
                            }
                        }

                        _updatePreviews();
                    };
                }

                _boxes.Add(box);

                if ((flag & LevelEditFlag.ShowAmount) == LevelEditFlag.ShowAmount)
                {
                    _amounts.Add(amount);
                }

                box.TextChanged += delegate {
                    OnValueChanged();
                };

                if ((flag & LevelEditFlag.ShowPreview2) == LevelEditFlag.ShowPreview2)
                {
                    _previews.Add(preview2);
                }
            }

            _updatePreviews();

            if (_boxes.Count > 0)
            {
                _boxes[0].Loaded += delegate {
                    Keyboard.Focus(_boxes[0]);
                    _boxes[0].SelectAll();
                };
            }
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
        }
        public ShopSimulatorDialog()
            : base("Shop simulator", "editor.png", SizeToContent.Height, ResizeMode.NoResize)
        {
            InitializeComponent();
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            Owner = WpfUtilities.TopWindow;

            _shopItems           = new RangeObservableCollection <ShopItem>();
            _lvItems.ItemsSource = _shopItems;

            Binder.Bind(_cbColorZeny, () => SdeAppConfiguration.UseZenyColors, () => _shopItems.ToList().ForEach(p => p.Update()));
            Binder.Bind(_cbDiscount, () => SdeAppConfiguration.UseDiscount, () => _shopItems.ToList().ForEach(p => p.Update()));
            Binder.Bind(_cbUseViewId, () => SdeAppConfiguration.AlwaysUseViewId, () => {
                if (!_enableEvents || _primaryShop == null)
                {
                    return;
                }

                try {
                    _enableEvents = false;

                    string viewId = _primaryShop.NpcViewId;
                    int ival;

                    if (SdeAppConfiguration.AlwaysUseViewId)
                    {
                        if (!Int32.TryParse(viewId, out ival))
                        {
                            var constDb = SdeEditor.Instance.ProjectDatabase.GetDb <string>(ServerDbs.Constants);
                            var tuple   = constDb.Table.TryGetTuple(viewId);

                            if (tuple != null)
                            {
                                ival = tuple.GetValue <int>(ServerConstantsAttributes.Value);
                            }
                            else
                            {
                                ival = -1;
                            }

                            _primaryShop.NpcViewId = ival.ToString(CultureInfo.InvariantCulture);
                            _tbNpcViewId.Text      = _primaryShop.NpcViewId;
                            _primaryShop.Reload();
                        }
                    }
                    else
                    {
                        if (Int32.TryParse(viewId, out ival))
                        {
                            viewId = _viewIdToString(ival);

                            if (!String.IsNullOrEmpty(viewId))
                            {
                                if (viewId.IsExtension(".act", ".spr"))
                                {
                                    _primaryShop.NpcViewId = Path.GetFileNameWithoutExtension(viewId.ToUpper());
                                }
                                else
                                {
                                    _primaryShop.NpcViewId = Path.GetFileName(viewId);
                                }

                                _tbNpcViewId.Text = _primaryShop.NpcViewId;
                                _primaryShop.Reload();
                            }
                        }
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
                finally {
                    _enableEvents = true;
                }
            });

            _shop.TextChanged += new EventHandler(_shop_TextChanged);

            AvalonLoader.Load(_shop);
            WpfUtils.AddMouseInOutEffectsBox(_cbColorZeny, _cbDiscount, _cbUseViewId);

            _helper = new PreviewHelper(new RangeListView(), SdeEditor.Instance.ProjectDatabase.GetDb <int>(ServerDbs.Items), null, null, null, null);

            FrameViewerSettings settings = new FrameViewerSettings();

            settings.Act            = () => _act;
            settings.SelectedAction = () => _actIndexSelected.SelectedAction;
            settings.SelectedFrame  = () => _actIndexSelected.SelectedFrame;
            _frameViewer.InitComponent(settings);

            _actIndexSelected.Init(_frameViewer);
            _actIndexSelected.Load(_act);
            _actIndexSelected.FrameChanged  += (s, p) => _frameViewer.Update();
            _actIndexSelected.ActionChanged += (s, p) => {
                _frameViewer.Update();

                if (!_enableEvents || _primaryShop == null)
                {
                    return;
                }

                try {
                    _enableEvents = false;

                    var elements = _tbNpcPosition.Text.Split(',');
                    var dir      = _convertAction(_actIndexSelected.SelectedAction);

                    if (elements.Length == 4)
                    {
                        elements[3] = dir.ToString(CultureInfo.InvariantCulture);
                        _primaryShop.ShopLocation = string.Join(",", elements);
                        _primaryShop.Reload();
                    }
                    else
                    {
                        _primaryShop.ShopLocation = "prontera,150,150," + dir.ToString(CultureInfo.InvariantCulture);
                        _primaryShop.Reload();
                    }

                    _tbNpcPosition.Text = _primaryShop.ShopLocation;
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
                finally {
                    _enableEvents = true;
                }
            };

            _actIndexSelected.SpecialFrameChanged += (s, p) => _frameViewer.Update();

            _lvItems.MouseRightButtonUp += new MouseButtonEventHandler(_lvItems_MouseRightButtonUp);
            _lvItems.SelectionChanged   += new SelectionChangedEventHandler(_lvItems_SelectionChanged);

            _tbItemId.TextChanged          += new TextChangedEventHandler(_tbItemId_TextChanged);
            _tbPrice.TextChanged           += new TextChangedEventHandler(_tbPrice_TextChanged);
            _tbNpcViewId.TextChanged       += new TextChangedEventHandler(_tbNpcViewId_TextChanged);
            _tbNpcPosition.TextChanged     += new TextChangedEventHandler(_tbNpcPosition_TextChanged);
            _tbNpcDisplayName.TextChanged  += new TextChangedEventHandler(_tbNpcDisplayName_TextChanged);
            _tbNpcShopCurrency.TextChanged += new TextChangedEventHandler(_tbNpcShopCurrency_TextChanged);

            _comboBoxShopType.SelectionChanged += new SelectionChangedEventHandler(_comboBoxShopType_SelectionChanged);

            _buttonResetPrice.Click += delegate {
                _tbPrice.Text = "-1";
            };

            _buttonCurItemQuery.Click += delegate {
                try {
                    Table <int, ReadableTuple <int> > btable = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items);

                    SelectFromDialog select = new SelectFromDialog(btable, ServerDbs.Items, _tbNpcShopCurrency.Text);
                    select.Owner = WpfUtilities.TopWindow;

                    if (select.ShowDialog() == true)
                    {
                        _tbNpcShopCurrency.Text = select.Id;
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            };

            _buttonViewIdQuery.Click += delegate {
                try {
                    MultiGrfExplorer dialog = new MultiGrfExplorer(SdeEditor.Instance.ProjectDatabase.MetaGrf, "data\\sprite\\npc", "", _viewIdToString(FormatConverters.IntOrHexConverter(_primaryShop.NpcViewId ?? "")));

                    if (dialog.ShowDialog() == true)
                    {
                        var    path = dialog.SelectedPath.GetFullPath();
                        string result;

                        if (path.IsExtension(".act", ".spr"))
                        {
                            result = Path.GetFileNameWithoutExtension(path.ToUpper());
                        }
                        else
                        {
                            result = Path.GetFileName(path);
                        }

                        if (SdeAppConfiguration.AlwaysUseViewId)
                        {
                            var constDb = SdeEditor.Instance.ProjectDatabase.GetDb <string>(ServerDbs.Constants);
                            var tuple   = constDb.Table.TryGetTuple(result);
                            int ival;

                            if (tuple != null)
                            {
                                ival = tuple.GetValue <int>(ServerConstantsAttributes.Value);
                            }
                            else
                            {
                                _tbNpcViewId.Text = result;
                                return;
                            }

                            if (!_enableEvents || _primaryShop == null)
                            {
                                return;
                            }

                            try {
                                _enableEvents = false;

                                _primaryShop.NpcViewId = ival.ToString(CultureInfo.InvariantCulture);
                                _tbNpcViewId.Text      = _primaryShop.NpcViewId;
                                _updateViewShop();
                                _primaryShop.Reload();
                            }
                            catch (Exception err) {
                                ErrorHandler.HandleException(err);
                            }
                            finally {
                                _enableEvents = true;
                            }
                        }
                        else
                        {
                            _tbNpcViewId.Text = result;
                        }
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            };

            _buttonQueryItem.Click += delegate {
                try {
                    Table <int, ReadableTuple <int> > btable = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items);

                    SelectFromDialog select = new SelectFromDialog(btable, ServerDbs.Items, _tbItemId.Text);
                    select.Owner = WpfUtilities.TopWindow;

                    if (select.ShowDialog() == true)
                    {
                        _tbItemId.Text = select.Id;
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            };

            _gridColumnPrimary.Width = new GridLength(230 + SystemParameters.VerticalScrollBarWidth + 7);

            this.Loaded += delegate {
                this.MinHeight  = this.ActualHeight + 10;
                this.MinWidth   = this.ActualWidth;
                this.ResizeMode = ResizeMode.CanResize;
                SizeToContent   = SizeToContent.Manual;
            };

            ApplicationShortcut.Link(ApplicationShortcut.Delete, () => _buttonDelete_Click(null, null), _lvItems);
            ApplicationShortcut.Link(ApplicationShortcut.New, () => _buttonNew_Click(null, null), this);
            ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Up", "MoveUp"), () => _buttonUp_Click(null, null), _lvItems);
            ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Down", "MoveDown"), () => _buttonDown_Click(null, null), _lvItems);
            ApplicationShortcut.Link(ApplicationShortcut.Undo, () => _undo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.Redo, () => _redo(), this);
            //_shop.Text = "alberta_in,182,97,0	shop	Tool Dealer#alb2	73,1750:-1,611:-1,501:-1,502:-1,503:-1,504:-1,506:-1,645:-1,656:-1,601:-1,602:-1,2243:-1";
        }