示例#1
0
 private void SHubConfigPanel_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (SHubConfiguration.isSetup())
     {
         DialogResult = DialogResult.OK;
     }
 }
示例#2
0
        public SHubMain(SHubConfig cfg)
        {
            InitializeComponent();

            #region Load Configuration
            cfg    = cfg ?? new SHubConfig();
            config = cfg;

            config.Overlay_FontSize = (config.Overlay_FontSize == 0 ? 14 : config.Overlay_FontSize);

            SHubConfigPanel ConfigPannel = new SHubConfigPanel(config);
            while (!config.isSetup())
            {
                DialogResult r = MessageBox.Show("Setting incomplete. Retry or Quit software ?", "Configuration issue", MessageBoxButtons.RetryCancel);
                if (r == DialogResult.Retry)
                {
                    ConfigPannel.ShowDialog();
                }
                else
                {
                    Load += (s, e) => Close(); break;
                }
            }

            Text = $"{config.BotName}";
            #endregion

            #region Twitch
            client = new TwitchClient();

            try
            {
                var clientOptions = new ClientOptions
                {
                    MessagesAllowedInPeriod = 750,
                    ThrottlingPeriod        = TimeSpan.FromSeconds(30)
                };
                WebSocketClient customClient = new WebSocketClient(clientOptions);
                client = new TwitchClient(customClient);
                client.Initialize(config.GetCredential(), config.ChannelName);
                client.OnLog             += Client_OnLog;
                client.OnJoinedChannel   += Client_OnJoinedChannel;
                client.OnMessageReceived += Client_OnMessageReceived;
                client.OnWhisperReceived += Client_OnWhisperReceived;
                client.OnNewSubscriber   += Client_OnNewSubscriber;
                client.OnConnected       += Client_OnConnected;
                client.OnUserJoined      += Client_OnUserJoined;
                client.OnUserLeft        += Client_OnUserLeft;

                client.Connect();

                ExcludedNames.Add(client.TwitchUsername);
                //ExcludedNames.Add(client.JoinedChannels)
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            #endregion

            #region Twitch_Features
            c_GTAPool.AutoGenerateColumns = true;

            //Bindings
            GTAList = new BindingList <GTA_User>(GTAPoolList);
            BindingSource source = new BindingSource(GTAList, null);
            c_GTAPool.DataSource = source;

            VoteList = new BindingList <RoleVote>(config.RoleVotes);
            BindingSource sourceVoteRole = new BindingSource(VoteList, null);
            c_VotesRoles.DataSource = sourceVoteRole;

            UsersList = new BindingList <GameUser>(ConnectedUsers);
            BindingSource sourceUsers = new BindingSource(UsersList, null);
            c_ConnectedUsers.DataSource = sourceUsers;

            //txt File output for OBS
            UpdateObsFiles();
            UpdateGTACount();
            #endregion

            #region Overlay
            _brushes = new Dictionary <string, SolidBrush>();
            _fonts   = new Dictionary <string, Font>();
            _images  = new Dictionary <string, Image>();

            var gfx = new Graphics()
            {
                MeasureFPS = true,
                PerPrimitiveAntiAliasing = true,
                TextAntiAliasing         = true
            };

            _window = new GraphicsWindow(config.Overlay_width, 1080 - config.Overlay_height, config.Overlay_width, config.Overlay_height, gfx)
            {
                FPS       = 30,
                IsTopmost = true,
                IsVisible = true
            };

            _window.DestroyGraphics += _window_DestroyGraphics;
            _window.DrawGraphics    += _window_DrawGraphics;
            _window.SetupGraphics   += _window_SetupGraphics;

            _window.Create();
            //_window.Join(); //seems to replace or take over the WinForm
            #endregion

            #region Discord
            _client = new DiscordSocketClient();

            _client.Log             += LogAsync;
            _client.Ready           += ReadyAsync;
            _client.MessageReceived += MessageReceivedAsync;

            _ = DiscordTask();
            #endregion

            #region RolesVoteFeature

            #endregion
        }