2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2014, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Collections.Generic;
33 using System.Windows.Forms;
38 public partial class frmPay : RadegastForm
40 private RadegastInstance instance;
41 private GridClient client { get { return instance.Client; } }
45 private bool isObject;
46 private Button[] buttons;
47 private int[] defaultAmounts = new int[4] { 1, 5, 10, 20 };
48 public static int LastPayed = -1;
50 public frmPay(RadegastInstance instance, UUID target, string name, bool isObject)
52 InitializeComponent();
53 Disposed += new EventHandler(frmPay_Disposed);
55 this.instance = instance;
58 this.isObject = isObject;
61 buttons = new Button[4] { btnFastPay1, btnFastPay2, btnFastPay3, btnFastPay4 };
62 for (int i = 0; i < buttons.Length; i++)
64 buttons[i].Click += new EventHandler(frmPay_Click);
65 buttons[i].Text = string.Format("L${0}", defaultAmounts[i]);
66 buttons[i].Tag = defaultAmounts[i];
70 client.Objects.PayPriceReply += new EventHandler<PayPriceReplyEventArgs>(Objects_PayPriceReply);
71 client.Objects.ObjectPropertiesFamily += new EventHandler<ObjectPropertiesFamilyEventArgs>(Objects_ObjectPropertiesFamily);
72 instance.Names.NameUpdated += new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
76 client.Objects.RequestPayPrice(client.Network.CurrentSim, target);
77 client.Objects.RequestObjectPropertiesFamily(client.Network.CurrentSim, target);
78 lblObject.Visible = true;
79 lblObject.Text = string.Format("Via object: {0}: ", name);
83 lblObject.Visible = false;
84 lblResident.Text = string.Format("Pay resident: {0}", name);
89 txtAmount.Text = LastPayed.ToString();
93 void frmPay_Disposed(object sender, EventArgs e)
95 client.Objects.PayPriceReply -= new EventHandler<PayPriceReplyEventArgs>(Objects_PayPriceReply);
96 client.Objects.ObjectPropertiesFamily -= new EventHandler<ObjectPropertiesFamilyEventArgs>(Objects_ObjectPropertiesFamily);
97 instance.Names.NameUpdated -= new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
100 void frmPay_Click(object sender, EventArgs e)
102 int amount = (int)((Button)sender).Tag;
106 client.Self.GiveAvatarMoney(target, amount);
110 client.Self.GiveObjectMoney(target, amount, name);
115 void UpdateResident()
119 BeginInvoke(new MethodInvoker(delegate()
127 lblResident.Text = string.Format("Pay resident: {0}", instance.Names.Get(owner));
130 void Avatars_UUIDNameReply(object sender, UUIDNameReplyEventArgs e)
132 if (e.Names.ContainsKey(owner))
134 instance.Names.NameUpdated -= new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
140 void Objects_ObjectPropertiesFamily(object sender, ObjectPropertiesFamilyEventArgs e)
142 if (e.Properties.ObjectID == target)
144 owner = e.Properties.OwnerID;
149 void Objects_PayPriceReply(object sender, PayPriceReplyEventArgs e)
151 if (e.ObjectID != target) return;
155 BeginInvoke(new MethodInvoker(() => Objects_PayPriceReply(sender, e)));
159 switch (e.DefaultPrice)
161 case (int)PayPriceType.Default:
162 txtAmount.Text = string.Empty;
164 case (int)PayPriceType.Hide:
165 txtAmount.Visible = false;
168 txtAmount.Text = e.DefaultPrice.ToString();
172 for (int i = 0; i < buttons.Length; i++)
174 switch (e.ButtonPrices[i])
176 case (int)PayPriceType.Default:
177 buttons[i].Text = string.Format("L${0}", defaultAmounts[i]);
178 buttons[i].Tag = defaultAmounts[i];
180 case (int)PayPriceType.Hide:
181 buttons[i].Visible = false;
184 buttons[i].Text = string.Format("L${0}", e.ButtonPrices[i]);
185 buttons[i].Tag = e.ButtonPrices[i];
193 private void btnCancel_Click(object sender, EventArgs e)
198 private void btnPay_Click(object sender, EventArgs e)
202 if (int.TryParse(txtAmount.Text, out amount) && amount > 0)
204 if (amount > client.Self.Balance)
206 lblStatus.Visible = true;
214 client.Self.GiveAvatarMoney(target, amount);
218 client.Self.GiveObjectMoney(target, amount, name);
224 private void txtAmount_KeyPress(object sender, KeyPressEventArgs e)
226 if (!(char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)))
232 private void txtAmount_TextChanged(object sender, EventArgs e)
235 if (int.TryParse(txtAmount.Text, out amount) && amount > 0)
237 if (amount > client.Self.Balance)
239 lblStatus.Visible = true;
240 btnPay.Enabled = false;
244 lblStatus.Visible = false;
245 btnPay.Enabled = true;
250 btnPay.Enabled = false;