public PlayerSlotWidget(RootWidget root, bool thisPlayer = false)
 {
     this.root = root;
     InitLayout();
     playerPic.Pixbuf = ResourceManager.GetPixbuf("Resources", "DefaultPlayerImage.png");
     if(thisPlayer)
     {
         NoActionButtonWidget button = new NoActionButtonWidget();
         button.OnClick += delegate() {
             System.Threading.ThreadPool.QueueUserWorkItem((state) => {
                 IPlayerControl control = ConnectionManager.PlayerGameControl;
                 if(control == null)
                     return;
                 try
                 {
                     control.RespondNoAction();
                     Gdk.Threads.Enter();
                     root.SetResponseType(Catalog.GetString("No action"));
                 }
                 catch(GameException e)
                 {
                     Gdk.Threads.Enter();
                     root.SetResponseType(Catalog.GetString("No action"), e);
                 }
                 RequestRedraw();
                 Gdk.Threads.Leave();
             });
         };
         padding9.Children.Add(button);
     }
     lifePointsCard = new CharacterCardWidget(CharacterType.Unknown);
     onlinePic.Pixbuf = ResourceManager.GetPixbuf("Resources", "Offline.png");
 }
 public void Update(CharacterCardWidget other)
 {
     type = other.type;
     Card = other.Card;
 }
        public AnimationLayer(RootWidget rootWidget)
        {
            root = rootWidget;

            animQueue = new Queue<Animation>();
            playingCardWidgets = new Dictionary<int, PlayingCardWidget>();
            playerRoleWidgets = new Dictionary<int, RoleCardWidget>(8);
            playerCharacterWidgets = new Dictionary<int, CharacterCardWidget>(8);

            playingCardZoomWidget = new PlayingCardWidget();
            roleCardZoomWidget = new RoleCardWidget();
            characterCardZoomWidget = new CharacterCardWidget();

            playingCardZoomWidget.OnLClick += (w) => UnsetCardZoomWidget();
            playingCardZoomWidget.OnRClick += (w) => UnsetCardZoomWidget();
            roleCardZoomWidget.OnLClick += (w) => UnsetCardZoomWidget();
            roleCardZoomWidget.OnRClick += (w) => UnsetCardZoomWidget();
            characterCardZoomWidget.OnLClick += (w) => UnsetCardZoomWidget();
            characterCardZoomWidget.OnRClick += (w) => UnsetCardZoomWidget();

            timerThread = new Thread(RunTimer);
            timerThread.IsBackground = true;
            timerThread.Start();

            listener = new EventListener(this);
            ConnectionManager.SessionEventListener.AddListener((IPlayerSessionEventListener)listener);
            ConnectionManager.SessionEventListener.AddListener((ISpectatorSessionEventListener)listener);
            ConnectionManager.OnSessionDisconnected += () => {
                Gdk.Threads.Enter();
                Clear();
                Gdk.Threads.Leave();
            };
        }
        /// <summary>
        /// Updates the animation layer.
        /// </summary>
        /// <remarks>
        /// This method is used to update the animation layer for a new game.
        /// </remarks>
        private void Update()
        {
            lock(animLock)
            {
                Clear();

                int thisPlayerId = 0;
                if(ConnectionManager.PlayerGameControl != null)
                    thisPlayerId = ConnectionManager.PlayerGameControl.PrivatePlayerView.ID;

                foreach(IPublicPlayerView player in ConnectionManager.Game.Players)
                {
                    int id = player.ID;
                    playerRoleWidgets[id] = new RoleCardWidget(player.Role);
                    playerRoleWidgets[id].OnRClick += (w) => SetCardZoomWidget((RoleCardWidget)w);
                    playerCharacterWidgets[id] = new CharacterCardWidget(player.CharacterType);
                    if(id == thisPlayerId)
                        playerCharacterWidgets[id].OnLClick += (w) => {
                            System.Threading.ThreadPool.QueueUserWorkItem((state) => {
                                IPlayerControl control = ConnectionManager.PlayerGameControl;
                                if(control == null)
                                    return;
                                try
                                {
                                    control.RespondUseAbility();
                                    Gdk.Threads.Enter();
                                    root.SetResponseType(Catalog.GetString("Use Ability"));
                                }
                                catch(GameException e)
                                {
                                    Gdk.Threads.Enter();
                                    root.SetResponseType(Catalog.GetString("Use Ability"), e);
                                }
                                RequestRedraw();
                                Gdk.Threads.Leave();
                            });
                        };
                    playerCharacterWidgets[id].OnRClick += (w) => SetCardZoomWidget((CharacterCardWidget)w);
                }
            }
        }
        public void SetCardZoomWidget(CharacterCardWidget cardWidget)
        {
            lock(animLock)
            {
                if(cardZoomWidgetSet)
                    return;

                characterCardZoomWidget.Update(cardWidget);
                cardZoomWidgetSet = true;

                if(animQueue.Count == 0)
                {
                    Animation anim = new Animation(this, current, new TimeSpan(0, 0, 0, 0, 500));
                    anim.EndAllocManager.SetCharacterCardZoomVisible(true);
                    EnqueueAnimation(anim);
                }
                else
                {
                    bool first = true;
                    foreach(Animation anim in animQueue)
                    {
                        if(first)
                            first = false;
                        else
                            anim.StartAllocManager.SetCharacterCardZoomVisible(true);
                        anim.EndAllocManager.SetCharacterCardZoomVisible(true);
                    }
                }
            }
        }