Пример #1
0
        public DXItemAmountWindow(string caption, ClientUserItem item)
        {
            HasFooter = true;

            TitleLabel.Text = caption;
            SetClientSize(new Size(200, DXItemCell.CellHeight + 10));

            Parent = ActiveScene;
            MessageBoxList.Add(this);
            Modal = true;

            Location = new Point((ActiveScene.DisplayArea.Width - DisplayArea.Width) / 2, (ActiveScene.DisplayArea.Height - DisplayArea.Height) / 2);

            ConfirmButton = new DXButton
            {
                Location = new Point(Size.Width / 2 + 10, Size.Height - 43),
                Size     = new Size(80, DefaultHeight),
                Parent   = this,
                Label    = { Text = "Confirm" }
            };
            ConfirmButton.MouseClick += (o, e) => Dispose();

            AmountBox = new DXNumberBox
            {
                Parent   = this,
                MaxValue = item.Count,
                Change   = Math.Max(1, item.Count / 5),
            };

            AmountBox.ValueTextBox.ValueChanged += (o, e) =>
            {
                Amount = AmountBox.Value;

                if (Amount <= 0)
                {
                    AmountBox.ValueTextBox.BorderColour = Color.Red;
                }
                else if (Amount == AmountBox.MaxValue)
                {
                    AmountBox.ValueTextBox.BorderColour = Color.Orange;
                }
                else
                {
                    AmountBox.ValueTextBox.BorderColour = Color.Green;
                }

                ConfirmButton.Enabled = Amount > 0;

                if (CEnvir.IsCurrencyItem(item.Info))
                {
                    item.Count = Amount;
                    ItemCell.RefreshItem();
                }
            };

            ItemCell = new DXItemCell
            {
                Location    = new Point(ClientArea.Location.X + (ClientArea.Width - DXItemCell.CellWidth - AmountBox.Size.Width - 5) / 2, ClientArea.Location.Y + 5),
                Parent      = this,
                FixedBorder = true,
                Border      = true,
                ItemGrid    = new[] { item },
                Slot        = 0,
                GridType    = GridType.None,
                ReadOnly    = true,
            };

            AmountBox.Location = new Point(ItemCell.Location.X + ItemCell.Size.Width + 10, ItemCell.Location.Y + (ItemCell.Size.Height - AmountBox.Size.Height) / 2);

            AmountBox.Value = 1;
            AmountBox.ValueTextBox.KeepFocus = true;
            AmountBox.ValueTextBox.SetFocus();
            AmountBox.ValueTextBox.TextBox.KeyPress += AmountBox_KeyPress;
        }