Пример #1
0
 public EventListener(SessionWindow parent)
 {
     this.parent = parent;
 }
Пример #2
0
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            this.Build();

            ConnectionManager.OnServerConnected += () => {
                serverWindow = new ServerWindow(this);
                serverWindow.DeleteEvent += (o, args) => {
                    serverWindowAction.Active = false;
                    args.RetVal = true;
                };
                serverWindow.Show();
                connectAction.Sensitive = false;
                disconnectAction.Sensitive = true;
                serverWindowAction.Sensitive = true;
                serverWindowAction.Active = true;
            };
            ConnectionManager.OnServerDisconnected += () => {
                Gtk.Application.Invoke(delegate {
                    Gdk.Threads.Enter();
                    serverWindow.Destroy();
                    serverWindow = null;
                    connectAction.Sensitive = true;
                    disconnectAction.Sensitive = false;
                    serverWindowAction.Sensitive = false;
                    serverWindowAction.Active = false;
                    Gdk.Threads.Leave();
                });
            };
            ConnectionManager.OnSessionConnected += () => {
                Gtk.Application.Invoke(delegate {
                    Gdk.Threads.Enter();
                    sessionWindow = new SessionWindow(serverWindow);
                    sessionWindow.DeleteEvent += (o, args) => {
                        sessionWindowAction.Active = false;
                        args.RetVal = true;
                    };
                    sessionWindowAction.Sensitive = true;
                    sessionWindowAction.Active = true;
                    serverWindowAction.Active = false;

                    sessionDisconnectAction.Sensitive = true;
                    ISession session = ConnectionManager.Session;
                    IPlayerSessionControl playerControl = ConnectionManager.PlayerSessionControl;
                    if(playerControl != null && playerControl.Player.IsCreator)
                    {
                        if(session.State != SessionState.Playing && session.State != SessionState.Ended)
                            startGameAction.Sensitive = true;
                        else
                            startGameAction.Sensitive = false;
                        endSessionAction.Sensitive = true;
                    }
                    else
                    {
                        startGameAction.Sensitive = false;
                        endSessionAction.Sensitive = false;
                    }
                    Gdk.Threads.Leave();
                });
            };
            ConnectionManager.OnSessionDisconnected += () => {
                Gtk.Application.Invoke(delegate {
                    Gdk.Threads.Enter();
                    sessionWindow.Destroy();
                    sessionWindow = null;
                    sessionWindowAction.Sensitive = false;
                    sessionWindowAction.Active = false;
                    serverWindowAction.Active = true;

                    sessionDisconnectAction.Sensitive = false;
                    startGameAction.Sensitive = false;
                    endSessionAction.Sensitive = false;
                    Gdk.Threads.Leave();
                });
            };
            ConnectionManager.OnGameConnected += () => {
                if(Config.Instance.GetBoolean("Client.AutoHideSWWhilePlaying", true))
                    Gtk.Application.Invoke(delegate {
                        Gdk.Threads.Enter();
                        sessionWindowAction.Active = false;
                        NotifyUrgent();
                        Gdk.Threads.Leave();
                    });
            };
            listener = new EventListener(this);
            ConnectionManager.SessionEventListener.AddListener((IPlayerSessionEventListener)listener);
        }