/
GumpTextEdit.cs
121 lines (109 loc) · 5.48 KB
/
GumpTextEdit.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// /*
// ███████╗ ██████╗██████╗ ██╗██████╗ ████████╗███████╗██████╗ ██╗ ██╗
// ██╔════╝██╔════╝██╔══██╗██║██╔══██╗╚══██╔══╝██╔════╝██╔══██╗██║ ██╔╝
// ███████╗██║ ██████╔╝██║██████╔╝ ██║ ███████╗██║ ██║█████╔╝
// ╚════██║██║ ██╔══██╗██║██╔═══╝ ██║ ╚════██║██║ ██║██╔═██╗
// ███████║╚██████╗██║ ██║██║██║ ██║ ███████║██████╔╝██║ ██╗
// ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚══════╝╚═════╝ ╚═╝ ╚═╝
// */
using ScriptSDK.Data;
using StealthAPI;
namespace ScriptSDK.Gumps
{
/// <summary>
/// GumpTextEdit control exposes a TextEdit, the player can read or modify.<br/>
/// This control is a pseudo equivalent to a windows form control but with uo suitable properties only.<br/>
/// There are no constructors or generators exposed due the design, that the gump should parse that control.
/// Whenever the owner gump performs an action through radiobutton, button or checkbox (which cause an update of gump)<br/>
/// the gump will update text controls internal before sending those actions.
/// </summary>
public sealed class GumpTextEdit : IGumpControl
{
internal GumpTextEdit(Gump owner, TextEntry c)
{
Owner = owner;
Serial = owner.Serial;
Location = new Point2D(c.X, c.Y);
Size = new Size(c.Height, c.Width);
Color = c.Color;
TextID = c.DefaultTextId;
//Text = Owner.RawText.Count > TextID ? Owner.RawText[TextID] : string.Empty;
//Drabadan edit, due to Text setter sends useless api call to stealth, so using private value in ctor;
_text = Owner.RawText.Count > TextID ? Owner.RawText[TextID] : string.Empty;
Limit = -1;
Page = c.Page;
ElementID = c.ElemNum;
ReturnValue = c.ReturnValue;
}
internal GumpTextEdit(Gump owner, TextEntryLimited c)
{
Owner = owner;
Serial = owner.Serial;
Location = new Point2D(c.X, c.Y);
Size = new Size(c.Height, c.Width);
Color = c.Color;
TextID = c.DefaultTextId;
//Text = Owner.RawText.Count > TextID ? Owner.RawText[TextID] : string.Empty;
//Drabadan edit, due to Text setter sends useless api call to stealth, so using private value in ctor;
_text = Owner.RawText.Count > TextID ? Owner.RawText[TextID] : string.Empty;
Limit = c.Limit;
Page = c.Page;
ElementID = c.ElemNum;
ReturnValue = c.ReturnValue;
}
private Gump Owner { get; set; }
// ReSharper disable once UnusedAutoPropertyAccessor.Local
private Serial Serial { get; set; }
/// <summary>
/// Stores ElementID which expose the unique queue number of element.
/// </summary>
public int ElementID { get; private set; }
/// <summary>
/// Stores PageID which expose on which layer of gump the element is assigned.
/// </summary>
public int Page { get; private set; }
/// <summary>
/// Stores coords which expose location of element.
/// </summary>
public Point2D Location { get; private set; }
/// <summary>
/// Stores size of control.
/// </summary>
public Size Size { get; private set; }
/// <summary>
/// Stores text color of text.
/// </summary>
public int Color { get; private set; }
/// <summary>
/// Stores TextID of control, which is only exposed for debug research. The control will handle actions standalone.
/// </summary>
public int TextID { get; private set; }
/// <summary>
/// Stores ReturnValue of control, which is only exposed for debug research. The control will handle actions standalone.
/// </summary>
public int ReturnValue { get; private set; }
private string _text { get; set; }
/// <summary>
/// Allows to read and write text content. Will be automated updated via gump.
/// </summary>
public string Text
{
get { return _text; }
set
{
if (!Limit.Equals(-1))
value = value.Substring(0, Limit);
var index = Gump.GetGumpIndex(Owner.GumpType);
if (Events.InvokeOnGumpReply(Owner,
new GumpReplyEventArgs(this,
(index >= 0) && Stealth.Client.NumGumpTextEntry((ushort) index, ReturnValue, value))))
_text = value;
}
}
/// <summary>
/// Stores the character limit of text. Returns -1 if length is infinite.<br/>
/// Be aware, that the gump has to cut down text if size greater limit.
/// </summary>
public int Limit { get; private set; }
}
}