| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- using Client.MirGraphics;
- using Client.MirSounds;
- namespace Client.MirControls
- {
- public sealed class MirAmountBox : MirImageControl
- {
- public MirLabel TitleLabel, TextLabel;
- public MirButton OKButton, CancelButton, CloseButton;
- public MirTextBox InputTextBox;
- public MirControl ItemImage;
- public int ImageIndex;
- public uint Amount, MinAmount, MaxAmount;
- public MirAmountBox(string title, int image, uint max, uint min = 0, uint defaultAmount = 0)
- {
- ImageIndex = image;
- MaxAmount = max;
- MinAmount = min;
- Amount = max;
- Modal = true;
- Movable = false;
- Index = 238;
- Library = Libraries.Prguse;
- Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
- TitleLabel = new MirLabel
- {
- AutoSize = true,
- Location = new Point(19, 8),
- Parent = this,
- NotControl = true,
- Text = title
- };
- CloseButton = new MirButton
- {
- HoverIndex = 361,
- Index = 360,
- Location = new Point(180, 3),
- Library = Libraries.Prguse2,
- Parent = this,
- PressedIndex = 362,
- Sound = SoundList.ButtonA,
- };
- CloseButton.Click += (o, e) => Dispose();
- ItemImage = new MirControl
- {
- Location = new Point(15, 34),
- Size = new Size(38, 34),
- Parent = this,
- };
- ItemImage.AfterDraw += (o, e) => DrawItem();
- OKButton = new MirButton
- {
- HoverIndex = 201,
- Index = 200,
- Library = Libraries.Title,
- Location = new Point(23, 76),
- Parent = this,
- PressedIndex = 202,
- };
- OKButton.Click += (o, e) => Dispose();
- CancelButton = new MirButton
- {
- HoverIndex = 204,
- Index = 203,
- Library = Libraries.Title,
- Location = new Point(110, 76),
- Parent = this,
- PressedIndex = 205,
- };
- CancelButton.Click += (o, e) => Dispose();
- InputTextBox = new MirTextBox
- {
- Parent = this,
- Border = true,
- BorderColour = Color.Lime,
- Location = new Point(58, 43),
- Size = new Size(132, 19),
- };
- InputTextBox.SetFocus();
- InputTextBox.TextBox.KeyPress += MirInputBox_KeyPress;
- InputTextBox.TextBox.TextChanged += TextBox_TextChanged;
- InputTextBox.Text = (defaultAmount > 0 && defaultAmount <= MaxAmount) ? defaultAmount.ToString() : MaxAmount.ToString();
- InputTextBox.TextBox.SelectionStart = 0;
- InputTextBox.TextBox.SelectionLength = InputTextBox.Text.Length;
- }
- public MirAmountBox(string title, int image, string message)
- {
- ImageIndex = image;
- Modal = true;
- Movable = false;
- Index = 238;
- Library = Libraries.Prguse;
- Location = new Point((800 - Size.Width) / 2, (600 - Size.Height) / 2);
- TitleLabel = new MirLabel
- {
- AutoSize = true,
- Location = new Point(19, 8),
- Parent = this,
- NotControl = true,
- Text = title
- };
- TextLabel = new MirLabel
- {
- AutoSize = true,
- Location = new Point(60, 43),
- ForeColour = Color.Yellow,
- Parent = this,
- NotControl = true,
- Text = message
- };
- CloseButton = new MirButton
- {
- HoverIndex = 361,
- Index = 360,
- Location = new Point(180, 3),
- Library = Libraries.Prguse2,
- Parent = this,
- PressedIndex = 362,
- Sound = SoundList.ButtonA,
- };
- CloseButton.Click += (o, e) => Dispose();
- ItemImage = new MirControl
- {
- Location = new Point(15, 34),
- Size = new Size(38, 34),
- Parent = this,
- };
- ItemImage.AfterDraw += (o, e) => DrawItem();
- OKButton = new MirButton
- {
- HoverIndex = 201,
- Index = 200,
- Library = Libraries.Title,
- Location = new Point(23, 76),
- Parent = this,
- PressedIndex = 202,
- };
- OKButton.Click += (o, e) => Dispose();
- CancelButton = new MirButton
- {
- HoverIndex = 204,
- Index = 203,
- Library = Libraries.Title,
- Location = new Point(110, 76),
- Parent = this,
- PressedIndex = 205,
- };
- CancelButton.Click += (o, e) => Dispose();
- }
- void TextBox_TextChanged(object sender, EventArgs e)
- {
- if (uint.TryParse(InputTextBox.Text, out Amount) && Amount >= MinAmount)
- {
- InputTextBox.BorderColour = Color.Lime;
- OKButton.Visible = true;
- if (Amount > MaxAmount)
- {
- Amount = MaxAmount;
- InputTextBox.Text = MaxAmount.ToString();
- InputTextBox.TextBox.SelectionStart = InputTextBox.Text.Length;
- }
- if (Amount == MaxAmount)
- InputTextBox.BorderColour = Color.Orange;
- }
- else
- {
- InputTextBox.BorderColour = Color.Red;
- OKButton.Visible = false;
- }
- }
- void MirInputBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!char.IsControl(e.KeyChar)
- && !char.IsDigit(e.KeyChar))
- {
- e.Handled = true;
- }
- if (e.KeyChar == (char)Keys.Enter)
- {
- if (OKButton != null && !OKButton.IsDisposed)
- OKButton.InvokeMouseClick(EventArgs.Empty);
- e.Handled = true;
- }
- else if (e.KeyChar == (char)Keys.Escape)
- {
- if (CancelButton != null && !CancelButton.IsDisposed)
- CancelButton.InvokeMouseClick(EventArgs.Empty);
- e.Handled = true;
- }
- }
- void DrawItem()
- {
- int x = ItemImage.DisplayLocation.X, y = ItemImage.DisplayLocation.Y;
- Size s = Libraries.Items.GetTrueSize(ImageIndex);
- x += (ItemImage.Size.Width - s.Width) / 2;
- y += (ItemImage.Size.Height - s.Height) / 2;
- Libraries.Items.Draw(ImageIndex, x, y);
- }
- public override void Show()
- {
- if (Parent != null) return;
- Parent = MirScene.ActiveScene;
- Highlight();
- for (int i = 0; i < Program.Form.Controls.Count; i++)
- {
- TextBox T = Program.Form.Controls[i] as TextBox;
- if (T != null && T.Tag != null && T.Tag != null)
- ((MirTextBox)T.Tag).DialogChanged();
- }
-
- /*
- CMain.Shift = false;
- CMain.Ctrl = false;
- CMain.Alt = false;
- Parent = MirScene.ActiveScene;
- Activate();
- Highlight();
- for (int i = 0; i < Main.This.Controls.Count; i++)
- {
- TextBox T = (TextBox)Main.This.Controls[i];
- if (T != null && T.Tag != null && T.Tag != null)
- ((MirTextBox)T.Tag).DialogChanged();
- }*/
- }
- public override void OnKeyDown(KeyEventArgs e)
- {
- base.OnKeyDown(e);
- e.Handled = true;
- }
- public override void OnKeyUp(KeyEventArgs e)
- {
- base.OnKeyUp(e);
- e.Handled = true;
- }
- public override void OnKeyPress(KeyPressEventArgs e)
- {
- base.OnKeyPress(e);
- if (e.KeyChar == (char)Keys.Escape)
- CancelButton.InvokeMouseClick(EventArgs.Empty);
- else if (e.KeyChar == (char)Keys.Enter)
- OKButton.InvokeMouseClick(EventArgs.Empty);
- e.Handled = true;
- }
- #region Disposable
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- for (int i = 0; i < Program.Form.Controls.Count; i++)
- {
- TextBox T = (TextBox)Program.Form.Controls[i];
- if (T != null && T.Tag != null && T.Tag != null)
- ((MirTextBox)T.Tag).DialogChanged();
- }
- }
- #endregion
- }
- }
|