OSDN Git Service

4b872629ee81821ddeafdcb8365ee5f3c81b0f2c
[radegast/radegast.git] / Radegast / GUI / Notifications / ScriptDialog.cs
1 // 
2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, Radegast Development Team
4 // All rights reserved.
5 // 
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 
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.
17 // 
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.
28 //
29 // $Id$
30 //
31 using System;
32 using System.Collections.Generic;
33 using System.Drawing;
34 using System.Windows.Forms;
35 using OpenMetaverse;
36
37 namespace Radegast
38 {
39     public partial class ntfScriptDialog : Notification
40     {
41         RadegastInstance instance;
42         UUID objectID;
43         int chatChannel;
44
45         public ntfScriptDialog(RadegastInstance instance, string message, string objectName, UUID imageID, UUID objectID, string firstName, string lastName, int chatChannel, List<string> buttons)
46             : base(NotificationType.ScriptDialog)
47         {
48             InitializeComponent();
49
50             this.instance = instance;
51             this.chatChannel = chatChannel;
52             this.objectID = objectID;
53
54             descBox.BackColor = instance.MainForm.NotificationBackground;
55             descBox.Text = firstName + " " + lastName + "'s " + objectName + "\r\n\r\n" + message.Replace("\n", "\r\n") + "\r\n";
56
57             NotificationEventArgs args = new NotificationEventArgs(instance);
58             args.Text = descBox.Text;
59
60             int btnWidth = 90;
61             int btnHeight = 23;
62
63             int i = 0;
64             if (buttons.Count == 1 && buttons[0] == "!!llTextBox!!")
65             {
66                 txtTextBox.Visible = true;
67                 sendBtn.Visible = true;
68                 args.Buttons.Add(ignoreBtn);
69             }
70             else
71             {
72                 foreach (string label in buttons)
73                 {
74                     Button b = new Button();
75                     b.Size = new Size(btnWidth, btnHeight);
76                     b.Text = label;
77                     b.Location = new Point(5 + (i % 3) * (btnWidth + 5), btnsPanel.Size.Height - (i / 3) * (btnHeight + 5) - (btnHeight + 5));
78                     b.Name = i.ToString();
79                     b.Click += new EventHandler(b_Click);
80                     b.UseVisualStyleBackColor = true;
81                     b.Margin = new Padding(0, 3, 0, 3);
82                     b.Padding = new Padding(0);
83                     btnsPanel.Controls.Add(b);
84                     args.Buttons.Add(b);
85                     i++;
86                 }
87             }
88             // Fire off event
89             args.Buttons.Add(ignoreBtn);
90             FireNotificationCallback(args);
91         }
92
93         void b_Click(object sender, EventArgs e)
94         {
95             string label = ((Button)sender).Text;
96             int index = int.Parse(((Button)sender).Name);
97             instance.Client.Self.ReplyToScriptDialog(chatChannel, index, label, objectID);
98             instance.MainForm.RemoveNotification(this);
99         }
100
101         private void ignoreBtn_Click(object sender, EventArgs e)
102         {
103             instance.MainForm.RemoveNotification(this);
104         }
105
106         private void sendBtn_Click(object sender, EventArgs e)
107         {
108             instance.Client.Self.ReplyToScriptDialog(chatChannel, 0, txtTextBox.Text, objectID);
109             instance.MainForm.RemoveNotification(this);
110         }
111     }
112 }