Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MenuCommand.cs
Go to the documentation of this file.
3
5
6public class MenuCommand
7{
8 private readonly EventHandler _execHandler;
9
10 private int _status;
11
13
14 public virtual bool Checked
15 {
16 get
17 {
18 return (_status & 4) != 0;
19 }
20 set
21 {
22 SetStatus(4, value);
23 }
24 }
25
26 public virtual bool Enabled
27 {
28 get
29 {
30 return (_status & 2) != 0;
31 }
32 set
33 {
34 SetStatus(2, value);
35 }
36 }
37
39
40 public virtual bool Supported
41 {
42 get
43 {
44 return (_status & 1) != 0;
45 }
46 set
47 {
48 SetStatus(1, value);
49 }
50 }
51
52 public virtual bool Visible
53 {
54 get
55 {
56 return (_status & 0x10) == 0;
57 }
58 set
59 {
60 SetStatus(16, !value);
61 }
62 }
63
64 public virtual CommandID? CommandID { get; }
65
66 public virtual int OleStatus => _status;
67
68 public event EventHandler? CommandChanged;
69
70 public MenuCommand(EventHandler? handler, CommandID? command)
71 {
72 _execHandler = handler;
73 CommandID = command;
74 _status = 3;
75 }
76
77 private void SetStatus(int mask, bool value)
78 {
79 int status = _status;
80 status = ((!value) ? (status & ~mask) : (status | mask));
81 if (status != _status)
82 {
83 _status = status;
85 }
86 }
87
88 public virtual void Invoke()
89 {
90 if (_execHandler == null)
91 {
92 return;
93 }
94 try
95 {
97 }
98 catch (CheckoutException ex)
99 {
100 if (ex == CheckoutException.Canceled)
101 {
102 return;
103 }
104 throw;
105 }
106 }
107
108 public virtual void Invoke(object arg)
109 {
110 Invoke();
111 }
112
113 protected virtual void OnCommandChanged(EventArgs e)
114 {
115 this.CommandChanged?.Invoke(this, e);
116 }
117
118 public override string ToString()
119 {
120 string text = CommandID?.ToString() + " : ";
121 if (((uint)_status & (true ? 1u : 0u)) != 0)
122 {
123 text += "Supported";
124 }
125 if (((uint)_status & 2u) != 0)
126 {
127 text += "|Enabled";
128 }
129 if ((_status & 0x10) == 0)
130 {
131 text += "|Visible";
132 }
133 if (((uint)_status & 4u) != 0)
134 {
135 text += "|Checked";
136 }
137 return text;
138 }
139}
static readonly CheckoutException Canceled
void SetStatus(int mask, bool value)
virtual void OnCommandChanged(EventArgs e)
MenuCommand(EventHandler? handler, CommandID? command)
static readonly EventArgs Empty
Definition EventArgs.cs:9