2 // Radegast Metaverse Client
\r
3 // Copyright (c) 2009, Radegast Development Team
\r
4 // All rights reserved.
\r
6 // Redistribution and use in source and binary forms, with or without
\r
7 // modification, are permitted provided that the following conditions are met:
\r
9 // * Redistributions of source code must retain the above copyright notice,
\r
10 // this list of conditions and the following disclaimer.
\r
11 // * Redistributions in binary form must reproduce the above copyright
\r
12 // notice, this list of conditions and the following disclaimer in the
\r
13 // documentation and/or other materials provided with the distribution.
\r
14 // * Neither the name of the application "Radegast", nor the names of its
\r
15 // contributors may be used to endorse or promote products derived from
\r
16 // this software without specific prior written permission.
\r
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 using System.Collections.Generic;
\r
33 using System.Windows.Forms;
\r
35 using OpenMetaverse;
\r
36 using OpenMetaverse.Assets;
\r
40 public partial class AnimDetail : UserControl
\r
42 private RadegastInstance instance;
\r
46 private List<FriendInfo> friends;
\r
47 private FriendInfo friend;
\r
48 private byte[] animData;
\r
50 public AnimDetail(RadegastInstance instance, Avatar av, UUID anim, int n)
\r
52 InitializeComponent();
\r
53 Disposed += new EventHandler(AnimDetail_Disposed);
\r
54 this.instance = instance;
\r
60 void AnimDetail_Disposed(object sender, EventArgs e)
\r
64 private void AnimDetail_Load(object sender, EventArgs e)
\r
66 if (Animations.ToDictionary().ContainsKey(anim))
\r
73 groupBox1.Text = "Animation " + n + " (" + anim + ") for " + av.Name;
\r
75 friends = instance.Client.Friends.FriendList.FindAll(delegate(FriendInfo f) { return true; });
\r
77 pnlSave.Visible = false;
\r
78 boxAnimName.Text = "Animation " + n;
\r
79 cbFriends.DropDownStyle = ComboBoxStyle.DropDownList;
\r
81 foreach (FriendInfo f in friends)
\r
83 cbFriends.Items.Add(f);
\r
86 instance.Client.Assets.RequestAsset(anim, AssetType.Animation, true, Assets_OnAssetReceived);
\r
89 private void btnSave_Click(object sender, EventArgs e)
\r
91 WindowWrapper mainWindow = new WindowWrapper(frmMain.ActiveForm.Handle);
\r
92 System.Windows.Forms.SaveFileDialog dlg = new SaveFileDialog();
\r
93 dlg.AddExtension = true;
\r
94 dlg.RestoreDirectory = true;
\r
95 dlg.Title = "Save animation as...";
\r
96 dlg.Filter = "Second Life Animation (*.sla)|*.sla";
\r
97 DialogResult res = dlg.ShowDialog();
\r
99 if (res == DialogResult.OK)
\r
103 File.WriteAllBytes(dlg.FileName, animData);
\r
105 catch (Exception ex)
\r
107 Logger.Log("Saving animation failed: " + ex.Message, Helpers.LogLevel.Debug);
\r
112 void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
\r
114 if (InvokeRequired)
\r
116 Invoke(new MethodInvoker(() => Assets_OnAssetReceived(transfer, asset)));
\r
120 if (transfer.Success)
\r
122 Logger.Log("Animation " + anim + " download success " + asset.AssetData.Length + " bytes.", Helpers.LogLevel.Debug);
\r
123 pnlSave.Visible = true;
\r
124 animData = asset.AssetData;
\r
128 Logger.Log("Animation " + anim + " download failed.", Helpers.LogLevel.Debug);
\r
134 private void playBox_CheckStateChanged(object sender, EventArgs e)
\r
136 if (playBox.CheckState == CheckState.Checked)
\r
138 instance.Client.Self.AnimationStart(anim, true);
\r
142 instance.Client.Self.AnimationStop(anim, true);
\r
146 private void btnSend_Click(object sender, EventArgs e)
\r
148 if (animData == null) return;
\r
150 instance.Client.Inventory.RequestCreateItemFromAsset(animData, boxAnimName.Text, "(No description)", AssetType.Animation, InventoryType.Animation, instance.Client.Inventory.FindFolderForType(AssetType.Animation), On_ItemCreated);
\r
151 lblStatus.Text = "Uploading...";
\r
152 cbFriends.Enabled = false;
\r
155 void On_ItemCreated(bool success, string status, UUID itemID, UUID assetID)
\r
157 if (InvokeRequired)
\r
159 Invoke(new MethodInvoker(delegate()
\r
161 On_ItemCreated(success, status, itemID, assetID);
\r
169 lblStatus.Text = "Failed.";
\r
170 Logger.Log("Failed creating asset", Helpers.LogLevel.Debug);
\r
175 Logger.Log("Created inventory item " + itemID.ToString(), Helpers.LogLevel.Info);
\r
177 lblStatus.Text = "Sending to " + friend.Name;
\r
178 Logger.Log("Sending item to " + friend.Name, Helpers.LogLevel.Info);
\r
180 instance.Client.Inventory.GiveItem(itemID, boxAnimName.Text, AssetType.Animation, friend.UUID, false);
\r
181 lblStatus.Text = "Sent";
\r
184 cbFriends.Enabled = true;
\r
188 private void cbFriends_SelectedValueChanged(object sender, EventArgs e)
\r
190 if (cbFriends.SelectedIndex >= 0)
\r
192 btnSend.Enabled = true;
\r
193 friend = friends[cbFriends.SelectedIndex];
\r
197 btnSend.Enabled = false;
\r