193 lines
5.7 KiB
C#
193 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Net;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace GamerServices {
|
|
public partial class FormChat : Form {
|
|
private bool _CanChat = true;
|
|
public Friend ChattingWith;
|
|
|
|
public bool CanChat{
|
|
get {
|
|
return _CanChat;
|
|
}
|
|
|
|
set {
|
|
_CanChat = value;
|
|
this.button1.Enabled = _CanChat;
|
|
}
|
|
}
|
|
|
|
[DllImport("user32.dll")]
|
|
static extern bool FlashWindow(IntPtr hwnd, bool bInvert);
|
|
|
|
public FormMain Main;
|
|
private bool Editing = false;
|
|
|
|
|
|
public FormChat(FormMain main) {
|
|
Main = main;
|
|
|
|
InitializeComponent();
|
|
|
|
oldtext = textBox1.Text;
|
|
}
|
|
|
|
public void UpdateStatus() {
|
|
Game g = null;
|
|
if (this.ChattingWith.GameID != -1) {
|
|
g = this.Main.GetGame(this.ChattingWith.GameID);
|
|
}
|
|
|
|
label2.Text = this.ChattingWith.GameID < 1 ? "" : "Is playing: " + g.Name;
|
|
}
|
|
|
|
public void AddMessage(string user, string msg) {
|
|
Editing = true;
|
|
textBox1.Text += "\r\n" + String.Format("[{0:HH:mm:ss}] ", DateTime.Now) + user + ": " + msg;
|
|
Editing = false;
|
|
|
|
textBox1.SelectionStart = textBox1.Text.Length;
|
|
textBox1.ScrollToCaret();
|
|
textBox1.Refresh();
|
|
}
|
|
|
|
public void AddMessage(string msg) {
|
|
Editing = true;
|
|
textBox1.Text += "\r\n" + msg;
|
|
Editing = false;
|
|
|
|
textBox1.SelectionStart = textBox1.Text.Length;
|
|
textBox1.ScrollToCaret();
|
|
textBox1.Refresh();
|
|
}
|
|
|
|
private string oldtext = "";
|
|
private void textBox1_TextChanged(object sender, EventArgs e) {
|
|
int selstart = textBox1.SelectionStart;
|
|
int sellen = textBox1.SelectionLength;
|
|
|
|
if (!Editing) {
|
|
textBox1.Text = oldtext;
|
|
textBox1.Select(selstart, sellen);
|
|
return;
|
|
}
|
|
|
|
oldtext = textBox1.Text;
|
|
|
|
|
|
if (!this.ContainsFocus)
|
|
FlashWindow(this.Handle, true);
|
|
}
|
|
|
|
public void Flash() {
|
|
if (!this.ContainsFocus)
|
|
FlashWindow(this.Handle, true);
|
|
}
|
|
|
|
|
|
private void FormChat_Load(object sender, EventArgs e) {
|
|
this.Focus();
|
|
|
|
label1.Text = this.ChattingWith.Username;
|
|
|
|
label1.Focus();
|
|
|
|
WebClient wc = new WebClient();
|
|
wc.Proxy = null;
|
|
MemoryStream ms = new MemoryStream(wc.DownloadData("http://" + "www.gravatar.com/avatar/" + ChattingWith.AvatarURL + "?s=64"));
|
|
pictureBox1.Image = Image.FromStream(ms);
|
|
|
|
FlashWindow(this.Handle, true);
|
|
|
|
|
|
textBox1.Font = ChattingWith.Main.GetFont("Chat");
|
|
label1.Font = ChattingWith.Main.GetFont("Chat_Header");
|
|
label2.Font = ChattingWith.Main.GetFont("Chat_Sub");
|
|
|
|
this.UpdateStatus();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e) {
|
|
if (!button1.Enabled)
|
|
return;
|
|
|
|
textBox2.Focus();
|
|
|
|
if (!CanChat)
|
|
return;
|
|
|
|
if (textBox2.Text.Length == 0)
|
|
return;
|
|
|
|
Editing = true;
|
|
textBox1.Text += "\r\n" + String.Format("[{0:HH:mm:ss}] ", DateTime.Now) + Main.Username + ": " + textBox2.Text;
|
|
Main.Networker.Connection.Send(5, textBox2.Text.Length + 9, ChattingWith.UserID, textBox2.Text);
|
|
textBox2.Text = "";
|
|
Editing = false;
|
|
|
|
textBox1.SelectionStart = textBox1.Text.Length;
|
|
textBox1.ScrollToCaret();
|
|
textBox1.Refresh();
|
|
}
|
|
|
|
private void textBox2_KeyPress(object sender, KeyPressEventArgs e) {
|
|
if (!CanChat)
|
|
return;
|
|
|
|
if (e.KeyChar == 13) {
|
|
button1_Click(null, null);
|
|
}
|
|
}
|
|
|
|
private void FormChat_FormClosed(object sender, FormClosedEventArgs e) {
|
|
this.ChattingWith.ChatWindow = null;
|
|
}
|
|
|
|
private void FormChat_Resize(object sender, EventArgs e) {
|
|
this.panel1.Size = new Size(this.Size.Width - 16, 76);
|
|
this.textBox1.Size = new Size(this.Size.Width - 16, this.Size.Height - 82 - 70);
|
|
this.textBox2.Size = new Size(this.Size.Width - 168, 20);
|
|
this.textBox2.Location = new Point(12, this.Size.Height - 63);
|
|
this.button1.Location = new Point(this.Size.Width - 149, this.Size.Height - 67);
|
|
}
|
|
|
|
private void FormChat_MouseClick(object sender, MouseEventArgs e) {
|
|
textBox2.Focus();
|
|
}
|
|
|
|
private void panel1_MouseClick(object sender, MouseEventArgs e) {
|
|
textBox2.Focus();
|
|
}
|
|
|
|
private void label1_Click(object sender, EventArgs e) {
|
|
textBox2.Focus();
|
|
}
|
|
|
|
private void label2_Click(object sender, EventArgs e) {
|
|
textBox2.Focus();
|
|
}
|
|
|
|
private void panel1_Click(object sender, EventArgs e) {
|
|
textBox2.Focus();
|
|
}
|
|
|
|
public void FocusTextBar() {
|
|
textBox2.Focus();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e) {
|
|
|
|
}
|
|
}
|
|
}
|