Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
scriptconsoleenfscripttab.c
Go to the documentation of this file.
2{
4 protected int m_EnscriptHistoryRow;
8 protected PluginLocalEnscriptHistory m_ModuleLocalEnscriptHistory;
9 protected PluginLocalEnscriptHistoryServer m_ModuleLocalEnscriptHistoryServer;
10 protected MultilineEditBoxWidget m_EnfScriptEdit;
11 protected ButtonWidget m_EnfScriptRun;
12 protected ButtonWidget m_EnfScriptClear;
13 protected TextListboxWidget m_ScriptOutputListbox;
14 protected bool m_AllowScriptOutput;
15 protected int m_RunColor;
16
18
19 void ScriptConsoleEnfScriptTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
20 {
21 m_Instance = this;
22 m_ModuleLocalEnscriptHistory = PluginLocalEnscriptHistory.Cast(GetPlugin(PluginLocalEnscriptHistory));
23 m_ModuleLocalEnscriptHistoryServer = PluginLocalEnscriptHistoryServer.Cast(GetPlugin(PluginLocalEnscriptHistoryServer));
26 m_EnfScriptEdit = MultilineEditBoxWidget.Cast(root.FindAnyWidget("MultilineEditBoxWidget0"));
27 m_EnfScriptRun = ButtonWidget.Cast(root.FindAnyWidget("RunButton"));
28 m_EnfScriptClear = ButtonWidget.Cast(root.FindAnyWidget("ClearButton"));
29 m_ScriptOutputListbox = TextListboxWidget.Cast(root.FindAnyWidget("ScriptOutputListbox"));
30 m_RunColor = m_EnfScriptRun.GetColor();
31 }
32
34 {
35 m_Instance = null;
36 }
37
38 override void OnSelected()
39 {
40 int index = m_EnscriptConsoleHistory.Count() - m_EnscriptHistoryRow - 1;
41 if (m_EnscriptConsoleHistory.IsValidIndex(index))
42 {
43 string text = m_EnscriptConsoleHistory.Get(index);
44 m_EnfScriptEdit.SetText(text);
45 }
47 }
48
49 static void PrintS(string message)
50 {
51 Print(message);
52 if (m_Instance)
53 m_Instance.Add(message);
54 }
55
56 static void PrintS(bool message)
57 {
58 PrintS(message.ToString());
59 }
60
61 static void PrintS(int message)
62 {
63 PrintS(message.ToString());
64 }
65
66 static void PrintS(float message)
67 {
68 PrintS(message.ToString());
69 }
70
71 static void PrintS(vector message)
72 {
73 PrintS(message.ToString());
74 }
75
76 static void PrintS(Object message)
77 {
78 PrintS(message.ToString());
79 }
80
81
82 void Add(string message, bool isReload = false)
83 {
84 if (message != string.Empty)
85 {
87 {
88 if (!isReload)
89 m_ScriptOutputHistory.Insert(message);
90 m_ScriptOutputListbox.AddItem(String(message), NULL, 0);
91 m_ScriptOutputListbox.EnsureVisible(m_ScriptOutputListbox.GetNumItems());
92 }
93 }
94 }
95
96 protected void Clear(bool clearFile = false)
97 {
98 if(clearFile)
99 Debug.ClearLogs();
100 m_ScriptOutputListbox.ClearItems();
101 }
102
103
104
105 protected void ReloadScriptOutput()
106 {
107 m_ScriptOutputListbox.ClearItems();
108 m_AllowScriptOutput = true;
109 foreach ( string s: m_ScriptOutputHistory)
110 {
111 Add(s, true);
112 }
113 m_AllowScriptOutput = false;
114 }
115
117 {
118
120 }
121
123 {
125 }
126
127 protected void RunEnscript()
128 {
129 #ifdef DEVELOPER
130 string code;
131 m_EnfScriptEdit.GetText(code);
132 string codeNoReplace = code;
134 m_AllowScriptOutput = true;
135 code.Replace("Print(","ScriptConsoleEnfScriptTab.PrintS(");
136 code.Replace("Print (","ScriptConsoleEnfScriptTab.PrintS(");
137 bool success = GetGame().ExecuteEnforceScript("void scConsMain() \n{\n" + code + "\n}\n", "scConsMain");
138 m_AllowScriptOutput = false;
139 ColorRunButton(success);
140
141 m_EnscriptConsoleHistory.Insert(codeNoReplace);
142 m_ModuleLocalEnscriptHistory.AddNewLine(codeNoReplace);
143 #endif
144 }
145
146 protected void ColorRunButton(bool success)
147 {
148 if (success)
149 {
150 m_EnfScriptRun.SetColor(ARGB(255,0,255,0));
151 }
152 else
153 {
154 m_EnfScriptRun.SetColor(ARGB(255,255,0,0));
155 }
156 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ResetRunButtonColor,600);
157 }
158
159 protected void ResetRunButtonColor()
160 {
161 m_EnfScriptRun.SetColor(m_RunColor);
162 }
163
164 protected void RunEnscriptServer()
165 {
166 string code;
167 m_EnfScriptEdit.GetText(code);
169 m_ModuleLocalEnscriptHistoryServer.AddNewLine(code);
170 CachedObjectsParams.PARAM1_STRING.param1 = code;
171 GetGame().RPCSingleParam(GetGame().GetPlayer(), ERPCs.DEV_RPC_SERVER_SCRIPT, CachedObjectsParams.PARAM1_STRING, true, GetGame().GetPlayer().GetIdentity());
172 }
173
174 protected void EnscriptHistoryBack()
175 {
176 int history_index;
177 if (m_EnfScriptEdit)
178 {
180 history_index = m_EnscriptConsoleHistory.Count() - m_EnscriptHistoryRow - 1;
181 if (history_index > -1)
182 {
183 m_EnfScriptEdit.SetText(m_EnscriptConsoleHistory.Get(history_index));
184 }
186 }
187 }
188
189
190 protected void EnscriptHistoryForward()
191 {
192 if (m_EnfScriptEdit)
193 {
194 int history_index;
196 history_index = m_EnscriptConsoleHistory.Count() - m_EnscriptHistoryRow - 1;
197 if (history_index < m_EnscriptConsoleHistory.Count())
198 {
199 m_EnfScriptEdit.SetText(m_EnscriptConsoleHistory.Get(history_index));
200 }
202 }
203 }
204
205 override void OnRPCEx(int rpc_type, ParamsReadContext ctx)
206 {
207 super.OnRPCEx(rpc_type, ctx);
208 #ifdef DIAG_DEVELOPER
209 switch (rpc_type)
210 {
211 case ERPCs.DEV_RPC_SERVER_SCRIPT_RESULT:
212 {
213 if (ctx.Read(CachedObjectsParams.PARAM1_BOOL))
214 {
215 ColorRunButton(CachedObjectsParams.PARAM1_BOOL.param1);
216 }
217 break;
218 }
219 }
220 #endif
221 }
222
223 override bool OnClick(Widget w, int x, int y, int button)
224 {
225 super.OnClick(w,x,y,button);
226 if (w == m_EnfScriptRun)
227 {
228 RunEnscript();
229 return true;
230 }
231 else if (w == m_EnfScriptClear)
232 {
233 m_ScriptOutputListbox.ClearItems();
234 m_ScriptOutputHistory.Clear();
235 return true;
236 }
237
238 return false;
239 }
240
241 override bool OnChange(Widget w, int x, int y, bool finished)
242 {
243 super.OnChange(w, x, y, finished);
244 return false;
245 }
246
247
248 override void Show(bool show, ScriptConsoleTabBase selectedHandler)
249 {
250 if (!show && (selectedHandler.Type() == ScriptConsoleEnfScriptTab || selectedHandler.Type() == ScriptConsoleEnfScriptServerTab))
251 {
252 //do nothing
253 }
254 else
255 {
256 m_Root.Show(show);
257 m_Root.Enable(show);
258 }
259 }
260
261}
262
263class ScriptConsoleEnfScriptServerTab : ScriptConsoleEnfScriptTab
264{
265 override void OnSelected()
266 {
268 if (m_EnscriptConsoleHistoryServer.IsValidIndex(index))
270 string text = m_EnscriptConsoleHistoryServer.Get(index);
271 m_EnfScriptEdit.SetText(text);
276 override protected void EnscriptHistoryBack()
278 int history_index;
279 if (m_EnfScriptEdit)
280 {
283 if (history_index > -1)
284 {
285 m_EnfScriptEdit.SetText(m_EnscriptConsoleHistoryServer.Get(history_index));
286 }
288 }
289 }
290
291 override protected void EnscriptHistoryForward()
292 {
293 if (m_EnfScriptEdit)
294 {
295 int history_index;
299 if (history_index < m_EnscriptConsoleHistoryServer.Count())
300 {
301 m_EnfScriptEdit.SetText(m_EnscriptConsoleHistoryServer.Get(history_index));
302 }
304 }
305 }
306
307 override bool OnClick(Widget w, int x, int y, int button)
308 {
309 if (w == m_EnfScriptRun)
310 {
312 return true;
313 }
314 else if (w == m_EnfScriptClear)
315 {
316 m_ScriptOutputListbox.ClearItems();
317 m_ScriptOutputHistory.Clear();
318 return true;
319 }
320
321 return false;
322 }
323
324}
Definition debug.c:2
static void PrintS(bool message)
override bool OnChange(Widget w, int x, int y, bool finished)
override void OnRPCEx(int rpc_type, ParamsReadContext ctx)
PluginLocalEnscriptHistoryServer m_ModuleLocalEnscriptHistoryServer
static void PrintS(string message)
static ScriptConsoleEnfScriptTab m_Instance
static void PrintS(float message)
void Clear(bool clearFile=false)
static ref TStringArray m_ScriptOutputHistory
MultilineEditBoxWidget m_EnfScriptEdit
ref TStringArray m_EnscriptConsoleHistoryServer
override bool OnClick(Widget w, int x, int y, int button)
void ScriptConsoleEnfScriptTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent=null)
void Add(string message, bool isReload=false)
static void PrintS(vector message)
PluginLocalEnscriptHistory m_ModuleLocalEnscriptHistory
static void PrintS(Object message)
override void Show(bool show, ScriptConsoleTabBase selectedHandler)
static void PrintS(int message)
Serialization general interface. Serializer API works with:
Definition serializer.c:56
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ERPCs
Definition erpcs.c:2
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
array< string > TStringArray
Definition enscript.c:709
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition enscript.c:339
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
Empty
Definition hand_states.c:14
Icon x
Icon y
PlayerBase GetPlayer()
PluginBase GetPlugin(typename plugin_type)
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
PlayerBase _player
ref TStringArray m_EnscriptConsoleHistoryServer
int m_EnscriptHistoryRowServer
ButtonWidget m_EnfScriptClear
TextListboxWidget m_ScriptOutputListbox
ButtonWidget m_EnfScriptRun
MultilineEditBoxWidget m_EnfScriptEdit