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;
34 using System.Windows.Forms;
35 using OpenMetaverse.StructuredData;
36 #if (COGBOT_LIBOMV || USE_STHREADS)
38 using Thread = ThreadPoolUtil.Thread;
39 using ThreadPool = ThreadPoolUtil.ThreadPool;
40 using Monitor = ThreadPoolUtil.Monitor;
42 using System.Threading;
44 using Radegast.Netcom;
49 public partial class MasterTab : UserControl
51 private RadegastInstance instance;
52 private GridClient client { get { return instance.Client; } }
53 private RadegastNetcom netcom { get { return instance.Netcom; } }
54 private Avatar avatar;
55 public UUID selectedID;
56 public Primitive selectedPrim;
58 public MasterTab(RadegastInstance instance, Avatar avatar)
60 InitializeComponent();
61 Disposed += new EventHandler(MasterTab_Disposed);
63 if (!instance.advancedDebugging)
65 saveBtn.Visible = false;
66 texturesBtn.Visible = false;
69 this.instance = instance;
73 client.Avatars.ViewerEffectPointAt += new EventHandler<ViewerEffectPointAtEventArgs>(Avatars_ViewerEffectPointAt);
74 client.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_ObjectProperties);
77 void MasterTab_Disposed(object sender, EventArgs e)
79 client.Avatars.ViewerEffectPointAt -= new EventHandler<ViewerEffectPointAtEventArgs>(Avatars_ViewerEffectPointAt);
80 client.Objects.ObjectProperties -= new EventHandler<ObjectPropertiesEventArgs>(Objects_ObjectProperties);
83 void Objects_ObjectProperties(object sender, ObjectPropertiesEventArgs e)
85 if (selectedPrim != null) {
86 if (selectedPrim.ID == e.Properties.ObjectID) {
87 selectedPrim.Properties = e.Properties;
96 Invoke(new MethodInvoker(delegate()
102 lastPrimName.Text = selectedPrim.Properties.Name;
103 lastPrimLocalID.Text = selectedPrim.LocalID.ToString();
108 if (InvokeRequired) {
109 Invoke(new MethodInvoker(delegate()
115 lastPrimLLUUID.Text = selectedID.ToString();
116 lastPrimLocalID.Text = selectedPrim.LocalID.ToString();
117 sitBitn.Enabled = true;
118 if (selectedPrim.ParentID != 0) {
119 objInfoBtn.Enabled = true;
121 objInfoBtn.Enabled = false;
123 touchBtn.Enabled = true;
124 if ((selectedPrim.Flags & PrimFlags.Money) != 0)
126 payBtn.Enabled = true;
130 payBtn.Enabled = false;
132 saveBtn.Enabled = true;
133 if (selectedPrim.Textures != null) {
134 texturesBtn.Enabled = true;
136 btnPoint.Enabled = true;
139 void Avatars_ViewerEffectPointAt(object sender, ViewerEffectPointAtEventArgs e)
141 if (e.SourceID == avatar.ID && e.TargetID != UUID.Zero) {
142 selectedID = e.TargetID;
143 selectedPrim = client.Network.CurrentSim.ObjectsPrimitives.Find(
144 delegate(Primitive prim) { return prim.ID == selectedID; }
146 if (selectedPrim != null) {
147 client.Objects.SelectObject(client.Network.CurrentSim, selectedPrim.LocalID);
153 private void objInfoBtn_Click(object sender, EventArgs e)
155 selectedPrim = client.Network.CurrentSim.ObjectsPrimitives.Find(
156 delegate(Primitive prim) { return prim.LocalID == selectedPrim.ParentID; }
158 selectedID = selectedPrim.ID;
160 client.Objects.SelectObject(client.Network.CurrentSim, selectedPrim.LocalID);
163 private void sitBitn_Click(object sender, EventArgs e)
165 if (selectedPrim != null) {
166 instance.State.SetSitting(true, selectedPrim.ID);
170 private void standBtn_Click(object sender, EventArgs e)
172 instance.State.SetSitting(false, UUID.Zero);
175 private void touchBtn_Click(object sender, EventArgs e)
177 client.Self.Touch(selectedPrim.LocalID);
180 private void payBtn_Click(object sender, EventArgs e)
182 (new frmPay(instance, selectedPrim.ID, selectedPrim.Properties.Name, true)).ShowDialog();
185 private void texturesBtn_Click(object sender, EventArgs e)
187 pnlImages.Controls.Clear();
189 List<UUID> textures = new List<UUID>();
191 textures.Add(selectedPrim.Textures.DefaultTexture.TextureID);
193 for (int i = 0; i < selectedPrim.Textures.FaceTextures.Length; i++) {
194 if (selectedPrim.Textures.FaceTextures[i] != null && (!textures.Contains(selectedPrim.Textures.FaceTextures[i].TextureID))) {
195 textures.Add(selectedPrim.Textures.FaceTextures[i].TextureID);
201 foreach (UUID textureID in textures) {
202 SLImageHandler img = new SLImageHandler(instance, textureID, "Texture " + (nTextures + 1).ToString());
203 img.Location = new Point(0, nTextures++ * img.Height);
204 img.Dock = DockStyle.Top;
206 pnlImages.Controls.Add(img);
210 if (selectedPrim.Sculpt != null && selectedPrim.Sculpt.SculptTexture != UUID.Zero)
212 SLImageHandler img = new SLImageHandler(instance, selectedPrim.Sculpt.SculptTexture, "Sculp Texture");
213 img.Location = new Point(0, nTextures * img.Height);
214 img.Dock = DockStyle.Top;
216 pnlImages.Controls.Add(img);
222 private void saveBtn_Click(object sender, EventArgs e)
224 WindowWrapper mainWindow = new WindowWrapper(frmMain.ActiveForm.Handle);
225 System.Windows.Forms.SaveFileDialog dlg = new SaveFileDialog();
226 dlg.AddExtension = true;
227 dlg.RestoreDirectory = true;
228 dlg.Title = "Save object as...";
229 dlg.Filter = "XML file (*.xml)|*.xml";
230 DialogResult res = dlg.ShowDialog();
232 if (res == DialogResult.OK)
234 Thread t = new Thread(new ThreadStart(delegate()
238 PrimSerializer s = new PrimSerializer(client);
239 string primsXmls = s.GetSerializedPrims(client.Network.CurrentSim, selectedPrim.LocalID);
240 System.IO.File.WriteAllText(dlg.FileName, primsXmls);
243 MessageBox.Show(mainWindow, "Successfully saved " + dlg.FileName, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
245 catch (Exception excp)
247 MessageBox.Show(mainWindow, excp.Message, "Saving failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
250 t.IsBackground = true;
254 private void loadBtn_Click(object sender, EventArgs e)
256 PrimDeserializer.ImportFromFile(client);
259 private void btnPoint_Click(object sender, EventArgs e)
261 if (instance.State.IsPointing)
263 instance.State.UnSetPointing();
264 btnPoint.Text = "Point at";
268 instance.State.SetPointing(selectedPrim, 3);
269 btnPoint.Text = "Unpoint";
276 public class WindowWrapper : System.Windows.Forms.IWin32Window
278 public WindowWrapper(IntPtr handle)
285 get { return _hwnd; }
288 private IntPtr _hwnd;