OSDN Git Service

loggign chat
[radegast/radegast.git] / Radegast / GUI / Consoles / AnimTab.cs
1 // \r
2 // Radegast Metaverse Client\r
3 // Copyright (c) 2009, Radegast Development Team\r
4 // All rights reserved.\r
5 // \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
8 // \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
17 // \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
28 //\r
29 // $Id$\r
30 //\r
31 using System;\r
32 using System.Collections.Generic;\r
33 using System.ComponentModel;\r
34 using System.Drawing;\r
35 using System.Data;\r
36 using System.Text;\r
37 using System.Windows.Forms;\r
38 using System.IO;\r
39 using OpenMetaverse;\r
40 using OpenMetaverse.Packets;\r
41 \r
42 namespace Radegast\r
43 {\r
44     public partial class AnimTab : UserControl\r
45     {\r
46         private GridClient client;\r
47         private RadegastInstance instance;\r
48         private Avatar av;\r
49         private List<UUID> seenAnim = new List<UUID>();\r
50         private int n = 0;\r
51         private static bool checkedDir = false;\r
52 \r
53         public AnimTab(RadegastInstance instance, Avatar av)\r
54         {\r
55             InitializeComponent();\r
56             Disposed += new EventHandler(AnimTab_Disposed);\r
57             this.instance = instance;\r
58             this.av = av;\r
59             this.client = instance.Client;\r
60 \r
61             // Callbacks\r
62             client.Avatars.OnAvatarAnimation += new AvatarManager.AvatarAnimationCallback(Avatars_OnAvatarAnimationUpdate);\r
63         }\r
64 \r
65         void AnimTab_Disposed(object sender, EventArgs e)\r
66         {\r
67             client.Avatars.OnAvatarAnimation -= new AvatarManager.AvatarAnimationCallback(Avatars_OnAvatarAnimationUpdate);\r
68         }\r
69 \r
70         void Avatars_OnAvatarAnimationUpdate(UUID avatarID, InternalDictionary<UUID, int> anims)\r
71         {\r
72             if (InvokeRequired) {\r
73                 Invoke(new MethodInvoker(delegate()\r
74                 {\r
75                     Avatars_OnAvatarAnimationUpdate(avatarID, anims);\r
76                 }));\r
77                 return;\r
78             }\r
79             if (avatarID == av.ID)\r
80             {\r
81                 anims.ForEach(delegate(UUID AnimID)\r
82                 {\r
83                     if (!seenAnim.Contains(AnimID))\r
84                     {\r
85                         Logger.Log("New anim for " + av.Name + ": " + AnimID, Helpers.LogLevel.Debug);\r
86                         seenAnim.Add(AnimID);\r
87                         AnimDetail ad = new AnimDetail(instance, av, AnimID, n);\r
88                         ad.Location = new Point(0, n++ * ad.Height);\r
89                         ad.Dock = DockStyle.Top;\r
90                         Controls.Add(ad);\r
91                     }\r
92                 });\r
93             }\r
94         }\r
95 \r
96         private void AnimTab_Load(object sender, EventArgs e)\r
97         {\r
98             if (!checkedDir) {\r
99                 checkedDir = true;\r
100                 if (!Directory.Exists(instance.AnimCacheDir))\r
101                 {\r
102                     Directory.CreateDirectory(instance.AnimCacheDir);\r
103                 }\r
104             }\r
105         }\r
106 \r
107     }\r
108 }\r