Exemple #1
0
        public IrcLogic(Widget widget)
        {
            var historyPanel     = widget.Get <ScrollPanelWidget>("HISTORY_PANEL");
            var historyTemplate  = widget.Get <LabelWidget>("HISTORY_TEMPLATE");
            var nicknamePanel    = widget.Get <ScrollPanelWidget>("NICKNAME_PANEL");
            var nicknameTemplate = widget.Get <LabelWidget>("NICKNAME_TEMPLATE");

            inputBox            = widget.Get <TextFieldWidget>("INPUT_BOX");
            inputBox.OnEnterKey = EnterPressed;
            inputBox.OnTabKey   = TabPressed;
            inputBox.IsDisabled = () => IrcClient.Instance.GetChannel(IrcClient.MainChannel) == null;

            nicknameBox      = widget.Get <TextFieldWidget>("NICKNAME_BOX");
            nicknameBox.Text = ChooseNickname(Game.Settings.Irc.Nickname);

            connectBG    = widget.Get("IRC_CONNECT_BG");
            ircContainer = widget.Get("IRC_CONTAINER");

            widget.Get <ButtonWidget>("DISCONNECT_BUTTON").OnClick = IrcClient.Instance.Disconnect;

            MaybeShowConnectPanel();

            historyPanel.Bind(IrcClient.Instance.History, item => MakeLabelWidget(historyTemplate, item), LabelItemEquals, true);

            var mainChannel = IrcClient.Instance.GetChannel(IrcClient.MainChannel);

            if (mainChannel != null)
            {
                nicknamePanel.Bind(mainChannel.Users, item => MakeLabelWidget(nicknameTemplate, item), LabelItemEquals, false);
            }

            IrcClient.Instance.OnSync += l =>
            {
                var channel = l.GetChannel();
                if (channel.Name.EqualsIC(IrcClient.MainChannel))
                {
                    nicknamePanel.Bind(channel.Users, item => MakeLabelWidget(nicknameTemplate, item), LabelItemEquals, false);
                }
            };
            IrcClient.Instance.OnKick += l =>
            {
                if (l.KickeeNickname.EqualsIC(IrcClient.Instance.LocalUser.Nickname) && l.Target.EqualsIC(IrcClient.MainChannel))
                {
                    nicknamePanel.Unbind();
                }
            };
            IrcClient.Instance.OnPart += l =>
            {
                if (l.PrefixIsSelf() && l.Target.EqualsIC(IrcClient.MainChannel))
                {
                    nicknamePanel.Unbind();
                }
            };
            IrcClient.Instance.OnDisconnect += () =>
            {
                nicknamePanel.Unbind();
                MaybeShowConnectPanel();
            };

            commands.Add("me", args =>
            {
                IrcClient.Instance.Act(IrcClient.MainChannel, args);
                IrcClient.AddAction(IrcClient.Instance.LocalUser.Nickname, args);
            });
            commands.Add("slap", args =>
            {
                IrcClient.Instance.Act(IrcClient.MainChannel, "slaps {0} around a bit with a large trout".F(args));
                IrcClient.AddAction(IrcClient.Instance.LocalUser.Nickname, "slaps {0} around a bit with a large trout".F(args));
            });
            commands.Add("notice", args =>
            {
                var split = args.Split(new[] { ' ' }, 2);
                if (split.Length < 2)
                {
                    IrcClient.AddHistory("/notice: Not enough arguments");
                    return;
                }
                IrcClient.Instance.Notice(split[0], split[1]);
                IrcClient.AddSelfNotice(split[0], split[1]);
            });
            commands.Add("disconnect", args =>
            {
                Game.Settings.Irc.ConnectAutomatically = false;
                Game.Settings.Save();
                IrcClient.Instance.Disconnect();
            });
            commands.Add("quit", args =>
            {
                Game.Settings.Irc.ConnectAutomatically = false;
                Game.Settings.Save();
                if (IrcClient.Instance.IsConnected)
                {
                    IrcClient.Instance.Quit(args);
                }
                else
                {
                    IrcClient.Instance.Disconnect();
                }
            });
            commands.Add("nick", args => IrcClient.Instance.SetNickname(args));
            commands.Add("topic", args => IrcClient.Instance.GetTopic(IrcClient.MainChannel));
        }