public void Init(TasClient tasClient) { client = tasClient; client.ConnectionLost += (s, e) => { { if (!client.WasDisconnectRequested) lbState.Text = "disconnected, reconnecting..."; else { lbState.Text = "disconnected"; tasClientConnectCalled = false; } } }; client.Connected += (s, e) => { btnLogout.Text = "Logout"; lbState.Text = "Connected, logging in ..."; if (string.IsNullOrEmpty(Program.Conf.LobbyPlayerName) || string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword)) LoginWithDialog("Please choose your name and password.\nThis will create a new account if it does not exist."); else client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword); }; client.LoginAccepted += (s, e) => { lbState.Text = client.UserName; pictureBox1.Image = Program.ServerImages.GetAvatarImage(client.MyUser); playerItem = new PlayerListItem() { UserName = client.UserName }; }; client.LoginDenied += (s, e) => { if (e.ResultCode == LoginResponse.Code.InvalidName && !string.IsNullOrEmpty(Program.Conf.LobbyPlayerPassword)) { if ( MessageBox.Show(string.Format("Account '{0}' does not exist yet, do you want to create it?", Program.Conf.LobbyPlayerName), "Confirm account registration", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { lbState.Text = "Registering a new account"; client.Register(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword); } else { LoginWithDialog(string.Format("Login denied: {0} {1}", e.ResultCode.Description(), e.Reason)); } } else { LoginWithDialog(string.Format("Login denied: {0} {1}\nChoose a different name to create new account.", e.ResultCode.Description(), e.Reason)); } }; client.RegistrationDenied += (s, e) => LoginWithDialog(string.Format("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason)); client.RegistrationAccepted += (s, e) => client.Login(Program.Conf.LobbyPlayerName, Program.Conf.LobbyPlayerPassword); }
protected void AddUser(string userName) { Channel channel; if (Program.TasClient.JoinedChannels.TryGetValue(ChannelName, out channel)) { if (!channel.Users.ContainsKey(userName)) { Trace.WriteLine("Trying to add a user to a channel he hasn't joined (" + ChannelName + "/" + userName + ")."); return; } } playerListItems.RemoveAll(u => u.UserName == userName); var item = new PlayerListItem { UserName = userName }; playerListItems.Add(item); playerBox.Items.Remove(playerBox.Items.SingleOrDefault(u => u.UserName == userName)); playerBox.Items.Add(item); if (filtering) FilterPlayers(); else SortByTeam(); }
void UpdateHoverItem(MouseEventArgs mouseEventArgs) { var cursorPoint = new Point(mouseEventArgs.X, mouseEventArgs.Y); // No need to update if the cursor hasn't moved. if (cursorPoint == previousCursorLocation) return; previousCursorLocation = cursorPoint; var currentMeasureY = +AutoScrollPosition.Y; var itemsToPaint = GetItemsToPaintInOrder(); foreach (var item in itemsToPaint) { currentMeasureY += item.Height; if (cursorPoint.Y < currentMeasureY) { HoverItem = item; // Found it! return; } } HoverItem = null; // The cursor is hovering over an empty area of control. }
public void DoLogout() { tasClientConnectCalled = false; client.RequestDisconnect(); Program.Conf.LobbyPlayerName = ""; Program.Conf.LobbyPlayerPassword = ""; lbState.Text = "Press button to login again"; btnLogout.Text = "Login"; pictureBox1.Image = null; playerItem = null; }
void PaintItem(int currentDrawY, PlayerListItem item, Graphics graphics) { var currentDrawPosition = new Point(0, currentDrawY); var itemSize = new Size(ClientSize.Width, item.Height); var itemBounds = new Rectangle(currentDrawPosition, itemSize); graphics.FillRectangle(backgroundBrush, itemBounds); item.DrawPlayerLine(graphics, itemBounds, Color.White, item.IsGrayedOut, IsBattle); }