Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
scriptconsoleenfscripttab.c
Go to the documentation of this file.
2 {
3  protected static ScriptConsoleEnfScriptTab m_Instance;
4  protected int m_EnscriptHistoryRow;
5  protected int m_EnscriptHistoryRowServer;
6  protected ref TStringArray m_EnscriptConsoleHistory;
7  protected ref TStringArray m_EnscriptConsoleHistoryServer;
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 
17  static ref TStringArray m_ScriptOutputHistory = new TStringArray();
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  }
46  ReloadScriptOutput();
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 
116  void HistoryBack()
117  {
118 
119  EnscriptHistoryBack();
120  }
121 
122  void HistoryForward()
123  {
124  EnscriptHistoryForward();
125  }
126 
127  protected void RunEnscript()
128  {
129  #ifdef DEVELOPER
130  string code;
131  m_EnfScriptEdit.GetText(code);
132  string codeNoReplace = code;
133  _player = PlayerBase.Cast(GetGame().GetPlayer());
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);
168  m_EnscriptConsoleHistoryServer.Insert(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  }
185  else m_EnscriptHistoryRow--;
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  }
201  else m_EnscriptHistoryRow++;
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 
263 class ScriptConsoleEnfScriptServerTab : ScriptConsoleEnfScriptTab
264 {
265  override void OnSelected()
266  {
268  if (m_EnscriptConsoleHistoryServer.IsValidIndex(index))
269  {
270  string text = m_EnscriptConsoleHistoryServer.Get(index);
271  m_EnfScriptEdit.SetText(text);
272  }
274  }
275 
276  override protected void EnscriptHistoryBack()
277  {
278  int history_index;
279  if (m_EnfScriptEdit)
280  {
282  history_index = m_EnscriptConsoleHistoryServer.Count() - m_EnscriptHistoryRowServer - 1;
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;
296 
298  history_index = m_EnscriptConsoleHistoryServer.Count() - m_EnscriptHistoryRowServer - 1;
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 }
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
m_ModuleLocalEnscriptHistory
protected PluginLocalEnscriptHistory m_ModuleLocalEnscriptHistory
Definition: scriptconsoleenfscripttab.c:7
m_AllowScriptOutput
protected bool m_AllowScriptOutput
Definition: scriptconsoleenfscripttab.c:13
OnSelected
ScriptConsoleEnfScriptTab ScriptConsoleTabBase OnSelected()
Definition: scriptconsoleenfscripttab.c:265
m_ScriptOutputListbox
protected TextListboxWidget m_ScriptOutputListbox
Definition: scriptconsoleenfscripttab.c:12
String
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition: enscript.c:339
m_EnfScriptEdit
protected MultilineEditBoxWidget m_EnfScriptEdit
Definition: scriptconsoleenfscripttab.c:9
TStringArray
array< string > TStringArray
Definition: enscript.c:685
m_ModuleLocalEnscriptHistoryServer
protected PluginLocalEnscriptHistoryServer m_ModuleLocalEnscriptHistoryServer
Definition: scriptconsoleenfscripttab.c:8
y
Icon y
m_EnscriptHistoryRowServer
protected int m_EnscriptHistoryRowServer
Definition: scriptconsoleenfscripttab.c:4
m_EnscriptConsoleHistoryServer
protected ref TStringArray m_EnscriptConsoleHistoryServer
Definition: scriptconsoleenfscripttab.c:6
Print
proto void Print(void var)
Prints content of variable to console/log.
m_EnscriptConsoleHistory
protected ref TStringArray m_EnscriptConsoleHistory
Definition: scriptconsoleenfscripttab.c:5
m_EnfScriptClear
protected ButtonWidget m_EnfScriptClear
Definition: scriptconsoleenfscripttab.c:11
m_RunColor
protected int m_RunColor
Definition: scriptconsoleenfscripttab.c:14
CachedObjectsParams
Definition: utilityclasses.c:9
m_EnscriptHistoryRow
protected int m_EnscriptHistoryRow
Definition: scriptconsoleenfscripttab.c:3
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
_player
protected PlayerBase _player
Definition: quickbarbase.c:18
OnClick
override bool OnClick(Widget w, int x, int y, int button)
Definition: scriptconsoleenfscripttab.c:222
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
RunEnscriptServer
protected void RunEnscriptServer()
Definition: scriptconsoleenfscripttab.c:163
ReloadScriptOutput
protected void ReloadScriptOutput()
Definition: scriptconsoleenfscripttab.c:104
Object
Definition: objecttyped.c:1
array< string >
Empty
Empty
Definition: hand_states.c:3
EnscriptHistoryForward
protected void EnscriptHistoryForward()
Definition: scriptconsoleenfscripttab.c:189
x
Icon x
EnscriptHistoryBack
protected void EnscriptHistoryBack()
Definition: scriptconsoleenfscripttab.c:173
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Debug
Definition: debug.c:13
ScriptConsoleEnfScriptTab
Definition: scriptconsoleenfscripttab.c:1
ERPCs
ERPCs
Definition: erpcs.c:1
Widget
Definition: enwidgets.c:189
ScriptConsoleTabBase
Definition: scriptconsoletabbase.c:1
m_EnfScriptRun
protected ButtonWidget m_EnfScriptRun
Definition: scriptconsoleenfscripttab.c:10
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322