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;
36 using OpenMetaverse.Assets;
40 public partial class AnimDetail : UserControl
42 private RadegastInstance instance;
46 private List<FriendInfo> friends;
47 private FriendInfo friend;
48 private byte[] animData;
50 public AnimDetail(RadegastInstance instance, Avatar av, UUID anim, int n)
52 InitializeComponent();
53 Disposed += new EventHandler(AnimDetail_Disposed);
54 this.instance = instance;
60 void AnimDetail_Disposed(object sender, EventArgs e)
64 private void AnimDetail_Load(object sender, EventArgs e)
66 if (Animations.ToDictionary().ContainsKey(anim))
73 groupBox1.Text = "Animation " + n + " (" + anim + ") for " + av.Name;
75 friends = instance.Client.Friends.FriendList.FindAll(delegate(FriendInfo f) { return true; });
77 pnlSave.Visible = false;
78 boxAnimName.Text = "Animation " + n;
79 cbFriends.DropDownStyle = ComboBoxStyle.DropDownList;
81 foreach (FriendInfo f in friends)
83 cbFriends.Items.Add(f);
86 instance.Client.Assets.RequestAsset(anim, AssetType.Animation, true, Assets_OnAssetReceived);
89 private void btnSave_Click(object sender, EventArgs e)
91 WindowWrapper mainWindow = new WindowWrapper(frmMain.ActiveForm.Handle);
92 System.Windows.Forms.SaveFileDialog dlg = new SaveFileDialog();
93 dlg.AddExtension = true;
94 dlg.RestoreDirectory = true;
95 dlg.Title = "Save animation as...";
96 dlg.Filter = "Second Life Animation (*.sla)|*.sla";
97 DialogResult res = dlg.ShowDialog();
99 if (res == DialogResult.OK)
103 File.WriteAllBytes(dlg.FileName, animData);
107 Logger.Log("Saving animation failed: " + ex.Message, Helpers.LogLevel.Debug);
112 void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
116 Invoke(new MethodInvoker(() => Assets_OnAssetReceived(transfer, asset)));
120 if (transfer.Success)
122 Logger.Log("Animation " + anim + " download success " + asset.AssetData.Length + " bytes.", Helpers.LogLevel.Debug);
123 pnlSave.Visible = true;
124 animData = asset.AssetData;
128 Logger.Log("Animation " + anim + " download failed.", Helpers.LogLevel.Debug);
134 private void playBox_CheckStateChanged(object sender, EventArgs e)
136 if (playBox.CheckState == CheckState.Checked)
138 instance.Client.Self.AnimationStart(anim, true);
142 instance.Client.Self.AnimationStop(anim, true);
146 private void btnSend_Click(object sender, EventArgs e)
148 if (animData == null) return;
150 instance.Client.Inventory.RequestCreateItemFromAsset(animData, boxAnimName.Text, "(No description)", AssetType.Animation, InventoryType.Animation, instance.Client.Inventory.FindFolderForType(AssetType.Animation), On_ItemCreated);
151 lblStatus.Text = "Uploading...";
152 cbFriends.Enabled = false;
155 void On_ItemCreated(bool success, string status, UUID itemID, UUID assetID)
159 Invoke(new MethodInvoker(delegate()
161 On_ItemCreated(success, status, itemID, assetID);
169 lblStatus.Text = "Failed.";
170 Logger.Log("Failed creating asset", Helpers.LogLevel.Debug);
175 Logger.Log("Created inventory item " + itemID.ToString(), Helpers.LogLevel.Info);
177 lblStatus.Text = "Sending to " + friend.Name;
178 Logger.Log("Sending item to " + friend.Name, Helpers.LogLevel.Info);
180 instance.Client.Inventory.GiveItem(itemID, boxAnimName.Text, AssetType.Animation, friend.UUID, false);
181 lblStatus.Text = "Sent";
184 cbFriends.Enabled = true;
188 private void cbFriends_SelectedValueChanged(object sender, EventArgs e)
190 if (cbFriends.SelectedIndex >= 0)
192 btnSend.Enabled = true;
193 friend = friends[cbFriends.SelectedIndex];
197 btnSend.Enabled = false;