123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using CommonLang;
- using CommonLang.Property;
- using pomelo.chat;
- using Pomelo.DotNetClient;
- using SimpleJson;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using XmdsBattleClientBot.Bot;
- namespace XmdsBattleClientWin32.Func
- {
- public partial class FormChat : Form
- {
- private readonly BotClient bot;
- private readonly HashMap<BotClient.ChatChannel, Channel> channels = new HashMap<BotClient.ChatChannel, Channel>();
- private readonly PushHandler listen;
- public FormChat(BotClient bot)
- {
- this.bot = bot;
- InitializeComponent();
- foreach (BotClient.ChatChannel ch in Enum.GetValues(typeof(BotClient.ChatChannel)))
- {
- var channel = new Channel(bot, ch);
- comboChannel.Items.Add(channel);
- tabControl1.TabPages.Add(channel.tab);
- channels.Add(ch, channel);
- }
- this.comboChannel.SelectedItem = comboChannel.Items[0];
- this.listen = bot.Client.GameSocket.listen<OnChatPush>(onChatPush);
- this.Text += " : " + bot.Account;
- this.bot.Client.GameSocket.playerHandler.getGMHelpRequest((err, rsp) =>
- {
- if (rsp != null)
- {
- appendLine(richTextBoxAll, rsp.s2c_msg);
- }
- });
- }
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- this.listen.Clear();
- base.OnFormClosing(e);
- }
- private void btnSend_Click(object sender, EventArgs e)
- {
- if (textSending.Text.Length > 0)
- {
- if (textSending.Text.StartsWith("@gm"))
- {
- bot.Client.GameSocket.playerHandler.sendGMCmdRequest(textSending.Text, (err, msg) =>
- {
- if (err != null) appendLine(richTextBoxAll, err.Message);
- else appendLine(richTextBoxAll, msg.s2c_msg);
- });
- }
- else
- {
- var channel = comboChannel.SelectedItem as Channel;
- if (channel != null)
- {
- bot.chat_SendChat(onSendResult, textSending.Text, "", channel.value);
- textSending.Clear();
- textSending.Focus();
- }
- }
- }
- }
- private void onChatPush(OnChatPush push)
- {
- var ch = (BotClient.ChatChannel)push.s2c_scope;
- var channel = channels.Get(ch);
- if (channel != null)
- {
- var line = bot.FormatChat(push) + "\r\n";
- appendLine(richTextBoxAll, line);
- appendLine(channel.rich, line);
- }
- }
- private static void appendLine(RichTextBox rich, string line)
- {
- if (rich.MaxLength <= rich.TextLength + line.Length)
- {
- rich.Clear();
- }
- rich.AppendText(line);
- rich.ScrollToCaret();
- }
- private void onSendResult(Exception err, JsonObject obj)
- {
- if (err != null)
- {
- sendStatus.Text = err.Message;
- }
- else
- {
- sendStatus.Text = obj.ToString();
- }
- }
- public class Channel
- {
- public readonly BotClient bot;
- public readonly DescAttribute desc;
- public readonly BotClient.ChatChannel value;
- public readonly TabPage tab;
- public readonly RichTextBox rich;
- internal Channel(BotClient bot, BotClient.ChatChannel ch)
- {
- this.bot = bot;
- this.value = ch;
- this.desc = PropertyUtil.GetEnumAttribute<DescAttribute>(ch);
- this.rich = new RichTextBox();
- this.rich.Tag = this;
- this.rich.Dock = DockStyle.Fill;
- this.rich.Dock = System.Windows.Forms.DockStyle.Fill;
- this.rich.Location = new System.Drawing.Point(3, 3);
- this.rich.Name = "richTextBox1";
- this.rich.Size = new System.Drawing.Size(992, 387);
- this.rich.TabIndex = 0;
- this.rich.Text = "";
- this.rich.ReadOnly = true;
- this.tab = new TabPage(desc.Desc);
- this.tab.Controls.Add(this.rich);
- this.tab.Tag = this;
- }
- public override string ToString()
- {
- return desc.Desc;
- }
- }
- }
- }
|