this.label2 = new System.Windows.Forms.Label();
this.tbox_Size = new System.Windows.Forms.TextBox();
this.tbox_Distance = new System.Windows.Forms.TextBox();
+ this.lstPrims = new Radegast.ListViewNoFlicker();
+ this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.btnSave = new System.Windows.Forms.Button();
+ this.label5 = new System.Windows.Forms.Label();
+ this.rotZ = new System.Windows.Forms.NumericUpDown();
+ this.rotY = new System.Windows.Forms.NumericUpDown();
+ this.rotX = new System.Windows.Forms.NumericUpDown();
+ this.label4 = new System.Windows.Forms.Label();
+ this.scaleZ = new System.Windows.Forms.NumericUpDown();
+ this.scaleY = new System.Windows.Forms.NumericUpDown();
+ this.scaleX = new System.Windows.Forms.NumericUpDown();
+ this.label3 = new System.Windows.Forms.Label();
+ this.numRadius = new System.Windows.Forms.NumericUpDown();
+ this.button7 = new System.Windows.Forms.Button();
+ this.groupBox1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.rotZ)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.rotY)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.rotX)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.scaleZ)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.scaleY)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.scaleX)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numRadius)).BeginInit();
this.SuspendLayout();
//
// btnBuildBox
this.tbox_Distance.TabIndex = 11;
this.tbox_Distance.Text = "1.000";
//
+ // lstPrims
+ //
+ this.lstPrims.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.lstPrims.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.columnHeader1});
+ this.lstPrims.FullRowSelect = true;
+ this.lstPrims.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
+ this.lstPrims.HideSelection = false;
+ this.lstPrims.LabelWrap = false;
+ this.lstPrims.Location = new System.Drawing.Point(392, 43);
+ this.lstPrims.MultiSelect = false;
+ this.lstPrims.Name = "lstPrims";
+ this.lstPrims.ShowGroups = false;
+ this.lstPrims.Size = new System.Drawing.Size(274, 262);
+ this.lstPrims.TabIndex = 12;
+ this.lstPrims.UseCompatibleStateImageBehavior = false;
+ this.lstPrims.View = System.Windows.Forms.View.Details;
+ this.lstPrims.VirtualMode = true;
+ this.lstPrims.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.lstPrims_RetrieveVirtualItem);
+ this.lstPrims.SelectedIndexChanged += new System.EventHandler(this.lstPrims_SelectedIndexChanged);
+ //
+ // columnHeader1
+ //
+ this.columnHeader1.Width = 270;
+ //
+ // groupBox1
+ //
+ this.groupBox1.Controls.Add(this.btnSave);
+ this.groupBox1.Controls.Add(this.label5);
+ this.groupBox1.Controls.Add(this.rotZ);
+ this.groupBox1.Controls.Add(this.rotY);
+ this.groupBox1.Controls.Add(this.rotX);
+ this.groupBox1.Controls.Add(this.label4);
+ this.groupBox1.Controls.Add(this.scaleZ);
+ this.groupBox1.Controls.Add(this.scaleY);
+ this.groupBox1.Controls.Add(this.scaleX);
+ this.groupBox1.Location = new System.Drawing.Point(18, 152);
+ this.groupBox1.Name = "groupBox1";
+ this.groupBox1.Size = new System.Drawing.Size(354, 155);
+ this.groupBox1.TabIndex = 13;
+ this.groupBox1.TabStop = false;
+ this.groupBox1.Text = "Transform";
+ //
+ // btnSave
+ //
+ this.btnSave.Location = new System.Drawing.Point(272, 129);
+ this.btnSave.Name = "btnSave";
+ this.btnSave.Size = new System.Drawing.Size(75, 23);
+ this.btnSave.TabIndex = 24;
+ this.btnSave.Text = "Save";
+ this.btnSave.UseVisualStyleBackColor = true;
+ this.btnSave.Click += new System.EventHandler(this.btn_Save_Click);
+ //
+ // label5
+ //
+ this.label5.AutoSize = true;
+ this.label5.Location = new System.Drawing.Point(15, 58);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(97, 13);
+ this.label5.TabIndex = 23;
+ this.label5.Text = "Rotate ( X / Y / Z )";
+ //
+ // rotZ
+ //
+ this.rotZ.DecimalPlaces = 4;
+ this.rotZ.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.rotZ.Location = new System.Drawing.Point(288, 51);
+ this.rotZ.Name = "rotZ";
+ this.rotZ.Size = new System.Drawing.Size(60, 20);
+ this.rotZ.TabIndex = 22;
+ //
+ // rotY
+ //
+ this.rotY.DecimalPlaces = 4;
+ this.rotY.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.rotY.Location = new System.Drawing.Point(209, 51);
+ this.rotY.Name = "rotY";
+ this.rotY.Size = new System.Drawing.Size(60, 20);
+ this.rotY.TabIndex = 21;
+ //
+ // rotX
+ //
+ this.rotX.DecimalPlaces = 4;
+ this.rotX.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.rotX.Location = new System.Drawing.Point(126, 53);
+ this.rotX.Name = "rotX";
+ this.rotX.Size = new System.Drawing.Size(60, 20);
+ this.rotX.TabIndex = 20;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(15, 26);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(92, 13);
+ this.label4.TabIndex = 19;
+ this.label4.Text = "Scale ( X / Y / Z )";
+ //
+ // scaleZ
+ //
+ this.scaleZ.DecimalPlaces = 4;
+ this.scaleZ.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.scaleZ.Location = new System.Drawing.Point(288, 19);
+ this.scaleZ.Name = "scaleZ";
+ this.scaleZ.Size = new System.Drawing.Size(60, 20);
+ this.scaleZ.TabIndex = 18;
+ //
+ // scaleY
+ //
+ this.scaleY.DecimalPlaces = 4;
+ this.scaleY.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.scaleY.Location = new System.Drawing.Point(209, 19);
+ this.scaleY.Name = "scaleY";
+ this.scaleY.Size = new System.Drawing.Size(60, 20);
+ this.scaleY.TabIndex = 17;
+ //
+ // scaleX
+ //
+ this.scaleX.DecimalPlaces = 4;
+ this.scaleX.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.scaleX.Location = new System.Drawing.Point(126, 21);
+ this.scaleX.Name = "scaleX";
+ this.scaleX.Size = new System.Drawing.Size(60, 20);
+ this.scaleX.TabIndex = 16;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(392, 17);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(115, 13);
+ this.label3.TabIndex = 14;
+ this.label3.Text = "Search radius in meter:";
+ //
+ // numRadius
+ //
+ this.numRadius.Location = new System.Drawing.Point(513, 15);
+ this.numRadius.Name = "numRadius";
+ this.numRadius.Size = new System.Drawing.Size(60, 20);
+ this.numRadius.TabIndex = 15;
+ this.numRadius.Value = new decimal(new int[] {
+ 5,
+ 0,
+ 0,
+ 0});
+ //
+ // button7
+ //
+ this.button7.Location = new System.Drawing.Point(591, 15);
+ this.button7.Name = "button7";
+ this.button7.Size = new System.Drawing.Size(75, 23);
+ this.button7.TabIndex = 25;
+ this.button7.Text = "Refresh";
+ this.button7.UseVisualStyleBackColor = true;
+ this.button7.Click += new System.EventHandler(this.button7_Click);
+ //
// SimpleBuilder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.button7);
+ this.Controls.Add(this.numRadius);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.groupBox1);
+ this.Controls.Add(this.lstPrims);
this.Controls.Add(this.tbox_Distance);
this.Controls.Add(this.tbox_Size);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.btnBuildBox);
this.Name = "SimpleBuilder";
- this.Size = new System.Drawing.Size(454, 286);
+ this.Size = new System.Drawing.Size(697, 349);
+ this.groupBox1.ResumeLayout(false);
+ this.groupBox1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.rotZ)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.rotY)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.rotX)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.scaleZ)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.scaleY)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.scaleX)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numRadius)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tbox_Size;
private System.Windows.Forms.TextBox tbox_Distance;
+ private System.Windows.Forms.GroupBox groupBox1;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.NumericUpDown numRadius;
+ public System.Windows.Forms.ColumnHeader columnHeader1;
+ public Radegast.ListViewNoFlicker lstPrims;
+ private System.Windows.Forms.NumericUpDown scaleZ;
+ private System.Windows.Forms.NumericUpDown scaleY;
+ private System.Windows.Forms.NumericUpDown scaleX;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.NumericUpDown rotZ;
+ private System.Windows.Forms.NumericUpDown rotY;
+ private System.Windows.Forms.NumericUpDown rotX;
+ private System.Windows.Forms.Button btnSave;
+ private System.Windows.Forms.Button button7;
}
}
// Methods needed for proper registration of a GUI tab
#region Template for GUI radegast tab
/// <summary>String for internal identification of the tab (change this!)</summary>
- static string tabID = "demo_tab";
+ static string tabID = "simplebuilder_tab";
/// <summary>Text displayed in the plugins menu and the tab label (change this!)</summary>
static string tabLabel = "Build Prims";
/// <summary>Menu item that gets added to the Plugins menu</summary>
ToolStripMenuItem ActivateTabButton;
+ public List<Primitive> Prims = new List<Primitive>();
+ PropertiesQueue propRequester;
+
+ private Primitive m_selectedPrim;
+ public Primitive selectedPrim {
+ get
+ {
+ return m_selectedPrim;
+ }
+ set
+ {
+ if(value == null)
+ btnSave.Enabled = false;
+ else
+ btnSave.Enabled = true;
+
+ m_selectedPrim = value;
+ }
+ }
+
/// <summary>Default constructor. Never used. Needed for VS designer</summary>
public SimpleBuilder()
{
Disposed += new EventHandler(DemoTab_Disposed);
instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);
RegisterClientEvents(client);
+
+ propRequester = new PropertiesQueue(instance);
+ propRequester.OnTick += new PropertiesQueue.TickCallback(propRequester_OnTick);
+
+ selectedPrim = null;
}
/// <summary>
public void StartPlugin(RadegastInstance inst)
{
this.instance = inst;
+
ActivateTabButton = new ToolStripMenuItem(tabLabel, null, MenuButtonClicked);
instance.MainForm.PluginsMenu.DropDownItems.Add(ActivateTabButton);
+
}
/// <summary>
{
instance.TabConsole.Tabs[tabID].Close();
}
+
+ propRequester.OnTick -= propRequester_OnTick;
+ }
+
+ void propRequester_OnTick(int remaining)
+ {
+ if (InvokeRequired)
+ {
+ BeginInvoke(new MethodInvoker(delegate()
+ {
+ propRequester_OnTick(remaining);
+ }
+ ));
+ return;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.AppendFormat("Tracking {0} objects", Prims.Count);
+
+ if (remaining > 10)
+ {
+ sb.AppendFormat(", fetching {0} object names.", remaining);
+ }
+ else
+ {
+ sb.Append(".");
+ }
+
+ lock (Prims)
+ {
+ if(lstPrims != null)
+ lstPrims.VirtualListSize = Prims.Count;
+ }
+ if(lstPrims != null)
+ lstPrims.Invalidate();
+ }
+
+ private bool IncludePrim(Primitive prim)
+ {
+ if (prim.ParentID == 0 && (prim.Flags & PrimFlags.ObjectYouOwner) == PrimFlags.ObjectYouOwner)
+ {
+ return true;
+ }
+ else return false;
+ }
+
+ private string GetObjectName(Primitive prim, int distance)
+ {
+ string name = "Loading...";
+ string ownerName = "Loading...";
+
+ if (prim.Properties != null)
+ {
+ name = prim.Properties.Name;
+ // prim.Properties.GroupID is the actual group when group owned, not prim.GroupID
+ if (UUID.Zero == prim.Properties.OwnerID &&
+ PrimFlags.ObjectGroupOwned == (prim.Flags & PrimFlags.ObjectGroupOwned) &&
+ UUID.Zero != prim.Properties.GroupID)
+ {
+ System.Threading.AutoResetEvent nameReceivedSignal = new System.Threading.AutoResetEvent(false);
+ EventHandler<GroupNamesEventArgs> cbGroupName = new EventHandler<GroupNamesEventArgs>(
+ delegate(object sender, GroupNamesEventArgs e)
+ {
+ if (e.GroupNames.ContainsKey(prim.Properties.GroupID))
+ {
+ e.GroupNames.TryGetValue(prim.Properties.GroupID, out ownerName);
+ if (string.IsNullOrEmpty(ownerName))
+ ownerName = "Loading...";
+ if (null != nameReceivedSignal)
+ nameReceivedSignal.Set();
+ }
+ });
+ client.Groups.GroupNamesReply += cbGroupName;
+ client.Groups.RequestGroupName(prim.Properties.GroupID);
+ nameReceivedSignal.WaitOne(5000, false);
+ nameReceivedSignal.Close();
+ client.Groups.GroupNamesReply -= cbGroupName;
+ }
+ else
+ ownerName = instance.Names.Get(prim.Properties.OwnerID);
+ }
+
+ if (prim.ParentID == client.Self.LocalID)
+ {
+ return string.Format("{0} attached to {1}", name, prim.PrimData.AttachmentPoint.ToString());
+ }
+ else if (ownerName != "Loading...")
+ {
+ return String.Format("{0} ({1}m) owned by {2}", name, distance, ownerName);
+ }
+ else
+ {
+ return String.Format("{0} ({1}m)", name, distance);
+ }
+
+ }
+
+ private string GetObjectName(Primitive prim)
+ {
+ int distance = (int)Vector3.Distance(client.Self.SimPosition, prim.Position);
+ if (prim.ParentID == client.Self.LocalID) distance = 0;
+ return GetObjectName(prim, distance);
+ }
+
+ private void lstPrims_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
+ {
+ Primitive prim = null;
+ try
+ {
+ lock (Prims)
+ {
+ prim = Prims[e.ItemIndex];
+ }
+ }
+ catch
+ {
+ e.Item = new ListViewItem();
+ return;
+ }
+
+ string name = GetObjectName(prim);
+ var item = new ListViewItem(name);
+ item.Tag = prim;
+ item.Name = prim.ID.ToString();
+ e.Item = item;
}
/// <summary>
#endregion Implementation of the custom tab functionality
-
+ private void lstPrims_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (lstPrims.SelectedIndices.Count > 0)
+ {
+ selectedPrim = Prims[lstPrims.SelectedIndices[0]];
+ getScaleFromSelection();
+ getRotFromSelection();
+ }
+ else
+ {
+ selectedPrim = null;
+ }
+ }
+
+ private void getScaleFromSelection(){
+ if (selectedPrim == null) return;
+ if (selectedPrim.Scale == null) return;
+
+ scaleX.Value = (Decimal)selectedPrim.Scale.X;
+ scaleY.Value = (Decimal)selectedPrim.Scale.Y;
+ scaleZ.Value = (Decimal)selectedPrim.Scale.Z;
+ }
+
+ private void getRotFromSelection()
+ {
+ if (selectedPrim == null) return;
+ if (selectedPrim.Rotation == null) return;
+
+ rotX.Value = (Decimal)selectedPrim.Rotation.X;
+ rotY.Value = (Decimal)selectedPrim.Rotation.Y;
+ rotZ.Value = (Decimal)selectedPrim.Rotation.Z;
+ }
+
+ private void setRotToSelection()
+ {
+ if (selectedPrim != null && selectedPrim.Rotation != null)
+ {
+ selectedPrim.Rotation.X = (float)rotX.Value;
+ selectedPrim.Rotation.Y = (float)rotY.Value;
+ selectedPrim.Rotation.Z = (float)rotZ.Value;
+ }
+ }
+
+ private void setScaleToSelection()
+ {
+ if (selectedPrim != null && selectedPrim.Scale != null)
+ {
+ selectedPrim.Scale.X = (float)scaleX.Value;
+ selectedPrim.Scale.Y = (float)scaleY.Value;
+ selectedPrim.Scale.Z = (float)scaleZ.Value;
+ }
+ }
+
+ private void button7_Click(object sender, EventArgs e)
+ {
+ Prims.Clear();
+ Vector3 location = client.Self.SimPosition;
+
+ lock (Prims)
+ {
+ client.Network.CurrentSim.ObjectsPrimitives.ForEach(prim =>
+ {
+ int distance = (int)Vector3.Distance(prim.Position, location);
+ if (prim.ParentID == client.Self.LocalID)
+ {
+ distance = 0;
+ }
+ if (IncludePrim(prim) && (prim.Position != Vector3.Zero) && (distance < (int)this.numRadius.Value))
+ {
+ Prims.Add(prim);
+ if (prim.Properties == null)
+ {
+ propRequester.RequestProps(prim);
+ }
+ }
+ });
+ }
+ lstPrims.VirtualListSize = Prims.Count;
+ lstPrims.Invalidate();
+ }
+
+ private void btn_Save_Click(object sender, EventArgs e)
+ {
+ setScaleToSelection();
+ setRotToSelection();
+ }
}
}