507 lines
14 KiB
C#
507 lines
14 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Server;
|
|
using Server.Gumps;
|
|
using Server.HuePickers;
|
|
using Knives.Utils;
|
|
|
|
namespace Knives.Chat3
|
|
{
|
|
public class MailGump : GumpPlus
|
|
{
|
|
public static void SendTo(Mobile m)
|
|
{
|
|
SendTo(m, m);
|
|
}
|
|
|
|
public static void SendTo(Mobile from, Mobile to)
|
|
{
|
|
General.ClearGump(from, typeof(MailGump));
|
|
|
|
new MailGump(from, to);
|
|
}
|
|
|
|
#region Class Definitions
|
|
|
|
private Mobile c_Target;
|
|
private int c_Width, c_Height, c_Page;
|
|
private bool c_Options, c_Search, c_Minimized;
|
|
private string c_CharSearch, c_TxtSearch;
|
|
|
|
public Data GetData { get { return Data.GetData(Owner); } }
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public MailGump(Mobile from, Mobile to) : base(from, 400, 50)
|
|
{
|
|
c_Target = to;
|
|
|
|
c_TxtSearch = "";
|
|
c_CharSearch = "";
|
|
|
|
NewGump();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
protected override void BuildGump()
|
|
{
|
|
Owner.CloseGump(typeof(MailGump));
|
|
|
|
c_Width = 300;
|
|
c_Height = 60 + (40 * GetData.MailPP);
|
|
|
|
if (c_Minimized)
|
|
{
|
|
if (GetData.NewMsg())
|
|
AddImage(0, 0, 0xFC4);
|
|
else
|
|
AddImage(0, 0, 0xFC5);
|
|
}
|
|
else
|
|
AddBackground(0, 0, c_Width, c_Height, 0x1400);
|
|
|
|
AddButton(0, 0, 0x13A8, 0x13A8, "Minimize", new TimerCallback(Minimize));
|
|
|
|
if (c_Minimized)
|
|
AddLabel(1, -3, 0x47E, "^");
|
|
else
|
|
AddLabel(2, -9, 0x47E, "_");
|
|
|
|
if (c_Minimized)
|
|
DisplayMin();
|
|
else
|
|
DisplayList();
|
|
}
|
|
|
|
private void DisplayMin()
|
|
{
|
|
}
|
|
|
|
private ArrayList BuildList()
|
|
{
|
|
ArrayList list = Data.GetData(c_Target).Messages;
|
|
|
|
if (c_CharSearch != "")
|
|
foreach (Message m in new ArrayList(list))
|
|
if (m.From.Name.ToLower().IndexOf(c_CharSearch.ToLower()) != 0)
|
|
list.Remove(m);
|
|
|
|
if (c_TxtSearch != "")
|
|
foreach (Message m in new ArrayList(list))
|
|
if (m.From.Name.ToLower().IndexOf(c_CharSearch.ToLower()) == -1)
|
|
list.Remove(m);
|
|
|
|
list.Sort(new InternalSort());
|
|
|
|
return list;
|
|
}
|
|
|
|
private void DisplayList()
|
|
{
|
|
if (c_Options)
|
|
OptionsTab();
|
|
if (c_Search)
|
|
SearchTab();
|
|
|
|
int y = 10;
|
|
|
|
AddImage(78, y - 1, 0x9C5);
|
|
AddHtml(0, y, c_Width, 21, HTML.White + "<CENTER>" + General.Local(56) + (c_Target == Owner ? "" : "(" + c_Target.Name + ")"), false, false, false);
|
|
|
|
AddButton(10, 32, 0x983, 0x983, "PerPage Down", new TimerCallback(PerPageDown));
|
|
AddButton(20, 32, 0x985, 0x985, "PerPage Up", new TimerCallback(PerPageUp));
|
|
|
|
ArrayList list = BuildList();
|
|
|
|
AddHtml(c_Width - 50, y, 60, 21, HTML.White + list.Count + "/" + Data.MaxMsgs, false, false);
|
|
|
|
int perpage = GetData.MailPP;
|
|
|
|
if (perpage * c_Page > list.Count || c_Page < 0)
|
|
c_Page = 0;
|
|
|
|
if (perpage * (c_Page + 1) < list.Count)
|
|
AddButton(c_Width / 2 - 10, c_Height - 25, 0x25E8, 0x25E9, "Page Up", new TimerCallback(PageUp));
|
|
if (c_Page != 0)
|
|
AddButton(c_Width / 2 - 10, 30, 0x25E4, 0x25E5, "Page Down", new TimerCallback(PageDown));
|
|
|
|
AddButton(6, c_Height - 30, 0x768, 0x768, "Options", new TimerCallback(Options));
|
|
AddButton(22, c_Height - 30, 0x768, 0x768, "Search", new TimerCallback(Search));
|
|
AddLabel(11, c_Height - 30, c_Options ? 0x34 : 0x47E, "O");
|
|
AddLabel(27, c_Height - 30, c_Search ? 0x34 : 0x47E, "S");
|
|
|
|
if (Owner.AccessLevel >= AccessLevel.GameMaster)
|
|
{
|
|
AddHtml(c_Width - 73, c_Height - 29, 80, 21, HTML.White + General.Local(95), false, false);
|
|
AddButton(c_Width - 90, c_Height - 26, 0x2716, 0x2716, "Broadcast", new TimerCallback(Broadcast));
|
|
}
|
|
|
|
y += 20;
|
|
|
|
Message msg;
|
|
|
|
try
|
|
{
|
|
for (int i = perpage * c_Page; i < list.Count && i < perpage * (c_Page + 1); ++i)
|
|
{
|
|
msg = (Message)list[i];
|
|
|
|
AddHtml(45, y += 20, 180, 21, ColorFor(msg) + (msg.Read ? "" : "<B>") + msg.Subject, false, false, false);
|
|
AddHtml(45, y += 16, 150, 21, HTML.White + General.Local(60) + " " + msg.From.Name, false, false);
|
|
|
|
AddButton(20, y - 10, 0x2716, 0x2716, "Open", new TimerStateCallback(Open), (Message)list[i]);
|
|
AddButton(c_Width - 40, y - 10, 0x5686, 0x5687, "Delete", new TimerStateCallback(Delete), (Message)list[i]);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
AddHtml(45, y += 20, 90, 21, HTML.White + "!!!", false, false);
|
|
}
|
|
}
|
|
|
|
private string ColorFor(Message msg)
|
|
{
|
|
switch (msg.Type)
|
|
{
|
|
case MsgType.Normal: return HTML.White;
|
|
case MsgType.Invite: return HTML.Yellow;
|
|
case MsgType.System: return HTML.Red;
|
|
default: return HTML.White;
|
|
}
|
|
}
|
|
|
|
private void SearchTab()
|
|
{
|
|
AddBackground(c_Width + 20, 10, 130, 40, 0x1400);
|
|
|
|
AddImageTiled(c_Width + 30, 20, 90, 21, 0xBBC);
|
|
AddTextField(c_Width + 30, 20, 90, 21, 0x480, 1, c_TxtSearch);
|
|
AddButton(c_Width + 127, 24, 0x2716, 0x2716, "Text Search", new TimerCallback(TxtSearch));
|
|
|
|
char[] chars = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
|
|
|
|
int x = c_Width + 17;
|
|
int y = 51;
|
|
|
|
foreach (char c in chars)
|
|
{
|
|
AddButton(x += 20, y, 0x2344, 0x2344, "Char Search", new TimerStateCallback(CharSearch), c.ToString());
|
|
AddHtml(x + 6, y, 20, 20, (c_CharSearch == c.ToString() ? HTML.Green : HTML.White) + c, false, false, false);
|
|
|
|
if (x >= c_Width + 115)
|
|
{
|
|
x = c_Width + 17;
|
|
y += 20;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OptionsTab()
|
|
{
|
|
int x = c_Width + 20;
|
|
|
|
AddHtml(x, 10, 300, 21, HTML.White + "<CENTER>" + General.Local(57), false, false);
|
|
|
|
int y = 10;
|
|
|
|
if (GetData.GlobalAccess && GetData.Global)
|
|
{
|
|
AddHtml(x + 120, y += 25, 120, 21, HTML.Red + General.Local(26), false, false, false);
|
|
AddButton(x + 70, y, GetData.GlobalM ? 0x2343 : 0x2342, GetData.GlobalM ? 0x2343 : 0x2342, "Global Messages", new TimerCallback(GlobalMsg));
|
|
AddImage(x + 90, y, 0x2342, GetData.GlobalMC);
|
|
AddButton(x + 94, y + 4, 0x2716, 0x2716, "GlobalMsgColor", new TimerCallback(GlobalMsgColor));
|
|
}
|
|
|
|
AddHtml(x + 60, y += 25, 220, 21, HTML.White + General.Local(58), false, false);
|
|
AddButton(x + 30, y, GetData.SevenDays ? 0x2343 : 0x2342, GetData.SevenDays ? 0x2343 : 0x2342, "Seven Days", new TimerCallback(SevenDays));
|
|
AddHtml(x + 60, y += 20, 220, 21, HTML.White + General.Local(24), false, false);
|
|
AddButton(x + 30, y, GetData.FriendsOnly ? 0x2343 : 0x2342, GetData.FriendsOnly ? 0x2343 : 0x2342, "Friends Only", new TimerCallback(FriendsOnly));
|
|
AddHtml(x + 60, y += 20, 220, 21, HTML.White + General.Local(25), false, false);
|
|
AddButton(x + 30, y, GetData.ByRequest ? 0x2343 : 0x2342, GetData.ByRequest ? 0x2343 : 0x2342, "Friend Request", new TimerCallback(FriendRequest));
|
|
AddHtml(x + 60, y += 20, 220, 21, HTML.White + General.Local(196), false, false);
|
|
AddButton(x + 30, y, GetData.ReadReceipt ? 0x2343 : 0x2342, GetData.ReadReceipt ? 0x2343 : 0x2342, "Read Receipt", new TimerCallback(ReadReceipt));
|
|
|
|
AddHtml(x + 30, y += 25, 170, 21, HTML.White + General.Local(59), false, false);
|
|
AddImageTiled(x + 175, y, 70, 21, 0xBBA);
|
|
AddTextField(x + 175, y, 70, 21, 0x480, 2, GetData.MailSpeech);
|
|
AddButton(x + 255, y + 3, 0x2716, 0x2716, "Submit Speech", new TimerCallback(SubmitSpeech));
|
|
|
|
AddHtml(x + 60, y += 23, 220, 21, HTML.White + General.Local(27), false, false);
|
|
AddButton(x + 30, y, GetData.MsgSound ? 0x2343 : 0x2342, GetData.MsgSound ? 0x2343 : 0x2342, "Message Sound", new TimerCallback(MessageSound));
|
|
|
|
if (GetData.MsgSound)
|
|
{
|
|
AddHtml(x, y += 25, 300, 21, HTML.White + "<CENTER>" + General.Local(28), false, false);
|
|
AddImageTiled(x + 125, y += 25, 50, 21, 0xBBA);
|
|
AddTextField(x + 125, y, 50, 21, 0x480, 1, GetData.DefaultSound.ToString());
|
|
AddButton(x + 185, y + 3, 0x15E1, 0x15E5, "Play Sound", new TimerCallback(PlaySound));
|
|
AddButton(x + 110, y, 0x983, 0x983, "Sound Up", new TimerCallback(SoundUp));
|
|
AddButton(x + 110, y + 10, 0x985, 0x985, "Sound Down", new TimerCallback(SoundDown));
|
|
}
|
|
|
|
Entries.Insert(0, new GumpBackground(x, 0, 300, y + 40, 0x1400));
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
if (c_Options || c_Search)
|
|
{
|
|
c_Options = false;
|
|
c_Search = false;
|
|
NewGump();
|
|
return;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Responses
|
|
|
|
private void Minimize()
|
|
{
|
|
c_Minimized = !c_Minimized;
|
|
|
|
if (c_Minimized)
|
|
Override = false;
|
|
else
|
|
Override = true;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void PageUp()
|
|
{
|
|
c_Page++;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void PageDown()
|
|
{
|
|
c_Page--;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void PerPageUp()
|
|
{
|
|
GetData.MailPP++;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void PerPageDown()
|
|
{
|
|
GetData.MailPP--;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void Open(object o)
|
|
{
|
|
if (!(o is Message))
|
|
return;
|
|
|
|
MessageGump.SendTo(Owner, (Message)o);
|
|
|
|
General.RefreshGump(Owner, typeof(FriendsGump));
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void Delete(object o)
|
|
{
|
|
if (!(o is Message))
|
|
return;
|
|
|
|
GetData.DeleteMessage((Message)o);
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void Search()
|
|
{
|
|
c_Search = !c_Search;
|
|
|
|
c_Options = false;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void Options()
|
|
{
|
|
c_Options = !c_Options;
|
|
|
|
c_Search = false;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void TxtSearch()
|
|
{
|
|
c_TxtSearch = GetTextField(1);
|
|
c_CharSearch = "";
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void CharSearch(object o)
|
|
{
|
|
if (!(o is string))
|
|
return;
|
|
|
|
if (c_CharSearch == o.ToString())
|
|
c_CharSearch = "";
|
|
else
|
|
c_CharSearch = o.ToString();
|
|
|
|
c_TxtSearch = "";
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void SevenDays()
|
|
{
|
|
GetData.SevenDays = !GetData.SevenDays;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void FriendsOnly()
|
|
{
|
|
GetData.FriendsOnly = !GetData.FriendsOnly;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void FriendRequest()
|
|
{
|
|
GetData.ByRequest = !GetData.ByRequest;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void ReadReceipt()
|
|
{
|
|
GetData.ReadReceipt = !GetData.ReadReceipt;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void GlobalMsg()
|
|
{
|
|
GetData.GlobalM = !GetData.GlobalM;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void GlobalMsgColor()
|
|
{
|
|
Owner.SendHuePicker(new InternalPicker(this));
|
|
}
|
|
|
|
private void MessageSound()
|
|
{
|
|
GetData.MsgSound = !GetData.MsgSound;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void PlaySound()
|
|
{
|
|
GetData.DefaultSound = Utility.ToInt32(GetTextField(1));
|
|
Owner.SendSound(GetData.DefaultSound);
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void SoundUp()
|
|
{
|
|
GetData.DefaultSound = GetData.DefaultSound + 1;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void SoundDown()
|
|
{
|
|
GetData.DefaultSound = GetData.DefaultSound - 1;
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void SubmitSpeech()
|
|
{
|
|
GetData.MailSpeech = GetTextField(2);
|
|
|
|
if (GetData.MailSpeech != "")
|
|
Owner.SendMessage(GetData.SystemC, General.Local(70) + " \"" + GetData.MailSpeech + "\"");
|
|
else
|
|
Owner.SendMessage(GetData.SystemC, General.Local(71));
|
|
|
|
NewGump();
|
|
}
|
|
|
|
private void Broadcast()
|
|
{
|
|
NewGump();
|
|
|
|
SendMessageGump.SendTo(Owner, null);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Internal Classes
|
|
|
|
private class InternalSort : IComparer
|
|
{
|
|
public InternalSort()
|
|
{
|
|
}
|
|
|
|
public int Compare(object x, object y)
|
|
{
|
|
if (x == null && y == null)
|
|
return 0;
|
|
if (x == null || !(x is Message))
|
|
return -1;
|
|
if (y == null || !(y is Message))
|
|
return 1;
|
|
|
|
Message a = (Message)x;
|
|
Message b = (Message)y;
|
|
|
|
if (a.Received > b.Received)
|
|
return -1;
|
|
if (a.Received < b.Received)
|
|
return 1;
|
|
|
|
return Insensitive.Compare(a.From.Name, b.From.Name);
|
|
}
|
|
}
|
|
|
|
private class InternalPicker : HuePicker
|
|
{
|
|
private GumpPlus c_Gump;
|
|
|
|
public InternalPicker(GumpPlus g) : base(0x1018)
|
|
{
|
|
c_Gump = g;
|
|
}
|
|
|
|
public override void OnResponse(int hue)
|
|
{
|
|
Data.GetData(c_Gump.Owner).GlobalMC = hue;
|
|
|
|
c_Gump.NewGump();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |