DayZ 1.24
Loading...
Searching...
No Matches
ScriptConsole.c
Go to the documentation of this file.
1class ScriptConsole extends UIScriptedMenu
2{
3 protected bool m_HintEditMode;
4 protected float m_HoverTime;
5 protected bool m_HoverSuccessTriggered;
15 protected float m_PrevMouseX;
16 protected float m_PrevMouseY;
19 protected int m_Id;
20
21 static ref array<ref MapMarker> m_MarkedEntities = new array<ref MapMarker>();
25
27
28
29 protected static const string HINTS_PATH_DEFAULT = "scripts/data/internal/script_console_hints.json";
30 protected static const string HINTS_PATH_OPTIONAL = "$mission:script_console_hints.json";
31
33
34 const string NO_HINT_TEXT = "No hint";
35
36
38 {
39#ifndef SERVER
40 if (GetGame() && GetGame().GetMission() && GetGame().GetMission().GetHud())
41 {
42 GetGame().GetMission().GetHud().ShowHudPlayer(false);
43 GetGame().GetMission().GetHud().ShowQuickbarPlayer(false);
44 }
45#endif
47 if (plugin)
48 plugin.OnScriptMenuOpened(true);
49 }
50
52 {
53#ifndef SERVER
54 if (GetGame() && GetGame().GetMission() && GetGame().GetMission().GetHud())
55 {
56 GetGame().GetMission().GetHud().ShowHudPlayer(true);
57 GetGame().GetMission().GetHud().ShowQuickbarPlayer(true);
58 }
60 m_HintWidgetRoot.Unlink();
61#endif
63 if (plugin)
64 plugin.OnScriptMenuOpened(false);
65
66 if (GetGame() && GetGame().GetMission())
67 GetGame().GetMission().EnableAllInputs(true);
68 }
69
74
75 static void SaveData()
76 {
77 string errorMessage;
78 if (!JsonFileLoader<JsonHintsData>.SaveFile(HINTS_PATH_OPTIONAL, m_JsonData, errorMessage))
80 }
81
82 protected static JsonHintsData GetData()
83 {
85 if (!FileExist(path))
86 {
88 //ErrorEx(string.Format("Using default hints file: %1", path), ErrorExSeverity.INFO);
89 }
90
91 string errorMessage;
95
96 return data;
97 }
98
99 void SetHintText(string text, Widget w)
100 {
101 if (m_JsonData && m_JsonData.WidgetHintBindings && w)
102 {
104 m_JsonData.WidgetHintBindings.Set(hash, text);
105 Print("setting: " + text);
106 }
108 }
109
111 {
112 m_TabHandlers.Insert(handler.GetButton(), handler);
113 m_TabHandlersByID.Insert(m_Id, handler);
114 handler.Init(m_Id);
115 m_Id++;
116 }
117
118 override Widget Init()
119 {
121
122 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/script_console/script_console.layout");
123 m_EditTooltipRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/script_console/script_console_tooltip_edit.layout", layoutRoot);
124 m_EditTooltipRoot.Show(false);
125 m_HintOkButton = ButtonWidget.Cast(m_EditTooltipRoot.FindAnyWidget("ButtonOk"));
126 m_HintCancelButton = ButtonWidget.Cast(m_EditTooltipRoot.FindAnyWidget("ButtonCancel"));
127 m_HintClearButton = ButtonWidget.Cast(m_EditTooltipRoot.FindAnyWidget("ButtonClear"));
128 m_HintInputText = EditBoxWidget.Cast(m_EditTooltipRoot.FindAnyWidget("InputText"));
129
130 m_ButtonsWindowWidget = layoutRoot.FindAnyWidget("TabButtons");
131 m_ButtonsWindowWidget.Show(true);
132 //(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
133 RegisterTab(new ScriptConsoleItemsTab(layoutRoot.FindAnyWidget("ItemsPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("ItemsButtonWidget"))));
134 RegisterTab(new ScriptConsoleConfigTab(layoutRoot.FindAnyWidget("ConfigsPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("ConfigsButtonWidget"))));
135 RegisterTab(new ScriptConsoleEnfScriptTab(layoutRoot.FindAnyWidget("EnScriptPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("EnScriptButtonWidget"))));
136 RegisterTab(new ScriptConsoleEnfScriptServerTab(layoutRoot.FindAnyWidget("EnScriptPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("EnScriptButtonWidgetServer"))));
137 RegisterTab(new ScriptConsoleGeneralTab(layoutRoot.FindAnyWidget("GeneralPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("GeneralButtonWidget"))));
138 RegisterTab(new ScriptConsoleOutputTab(layoutRoot.FindAnyWidget("OutputPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("OutputButtonWidget"))));
139 RegisterTab(new ScriptConsoleVicinityTab(layoutRoot.FindAnyWidget("VicinityPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("VicinityWidget"))));
140 RegisterTab(new ScriptConsoleSoundsTab(layoutRoot.FindAnyWidget("SoundsPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("SoundsWidget"))));
141 RegisterTab(new ScriptConsoleWeatherTab(layoutRoot.FindAnyWidget("WeatherPanel"), this, ButtonWidget.Cast(layoutRoot.FindAnyWidget("WeatherButtonWidget"))));
142
143 m_CloseConsoleButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("CloseConsoleButtonWidget"));
144
145 // load data from profile
146 m_SelectedTab = m_ConfigDebugProfile.GetTabSelected();
147 SelectTabByID(m_SelectedTab);
148
149 m_JsonData = GetData();
150
151 return layoutRoot;
152 }
153
154 protected void HideHint()
155 {
157 m_HintWidgetRoot.Unlink();
158 }
159
161 {
162 string nameThis = w.GetName();
163 string nameParent = "";
164
165 if (w.GetParent())
166 nameParent = w.GetParent().GetName();
167
169 return namesCombined.Hash();
170 }
171
172 protected string GetMessage()
173 {
175
176 if (m_JsonData && m_JsonData.WidgetHintBindings)
177 {
178 if (m_JsonData.WidgetHintBindings.Contains(hash))
179 return m_JsonData.WidgetHintBindings.Get(hash);
180 }
181 //return "";
182 //return "No hint" + hash.ToString();
183 return NO_HINT_TEXT;
184 }
185
186 protected void HoverSuccess()
187 {
190 }
191
192 protected void HoverInterrupt()
193 {
195
196 m_HoverTime = 0;
197 m_HintEditMode = false;
198 HideHint();
199 }
200
201 override bool OnKeyPress(Widget w, int x, int y, int key)
202 {
203 super.OnKeyPress(w, x, y, key);
204
205 if (m_SelectedHandler.OnKeyPress(w, x, y, key))
206 return true;
207 return false;
208
209 }
210
211 override bool OnKeyDown(Widget w, int x, int y, int key)
212 {
213 super.OnKeyDown(w, x, y, key);
214
215 if (m_SelectedHandler.OnKeyDown(w, x, y, key))
216 return true;
217 return false;
218
219 }
220
221 override void Update(float timeslice)
222 {
223 super.Update(timeslice);
224
225 int mouseX, mouseY;
227 float dist = Math.Sqrt(Math.AbsFloat(mouseX - m_PrevMouseX) + Math.AbsFloat(mouseY - m_PrevMouseY));
228 m_PrevMouseX = mouseX;
229 m_PrevMouseY = mouseY;
230
232 {
234 if (m_HoverTime > 1)
235 HoverSuccess();
236 }
237
238 if (dist > 1 && m_HoverSuccessTriggered)
240
241 if (GetGame() && GetUApi().GetInputByID(UAUIBack).LocalPress())
242 GetGame().GetUIManager().Back();
243
244
245 if (!GetGame().IsMultiplayer() && KeyState(KeyCode.KC_RCONTROL) && KeyState(KeyCode.KC_NUMPAD0) && m_HintWidgetRoot && m_HintWidgetRoot.IsVisible())
246 {
247 ClearKey(KeyCode.KC_NUMPAD0);
248 m_EditTooltipRoot.Show(true);
249 string text = GetMessage();
250 if (text == NO_HINT_TEXT)
251 text = "";
252 m_HintInputText.SetText(text);
253
254 }
255
256
258 handler.Update(timeslice);
259 }
260
261 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
262 {
263 super.OnMouseButtonDown(w, x, y, button);
264
265 if (m_SelectedHandler.OnMouseButtonDown(w, x, y, button))
266 return true;
267
268 return false;
269 }
270
271
272 override bool OnClick(Widget w, int x, int y, int button)
273 {
274 super.OnClick(w, x, y, button);
275
276 if (w == m_CloseConsoleButton)
277 {
278 Close();
279 GetGame().GetMission().EnableAllInputs(true);
280 return true;
281 }
282 else if (w == m_HintOkButton)
283 {
284 SetHintText(m_HintInputText.GetText(), m_CurrentHoverWidget);
286 m_EditTooltipRoot.Show(false);
287 SaveData();
288 }
289 else if (w == m_HintCancelButton)
290 {
292 m_EditTooltipRoot.Show(false);
293
294 }
295 else if (w == m_HintClearButton)
296 m_HintInputText.SetText("");
297
298
300
301 if (m_SelectedHandler.OnClick(w, x, y, button))
302 return true;
303 return false;
304 }
305
306 override bool OnDoubleClick(Widget w, int x, int y, int button)
307 {
308 super.OnDoubleClick(w, x, y, button);
309
310 if (m_SelectedHandler.OnDoubleClick(w, x, y, button))
311 return true;
312
313 return false;
314 }
315
316 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
317 {
318 super.OnMouseLeave(w, enterW, x, y);
319
320 if (!m_EditTooltipRoot.IsVisible())
322 return false;
323 }
324
325 override bool OnMouseEnter(Widget w, int x, int y)
326 {
327 super.OnMouseEnter(w, x, y);
328 if (!m_EditTooltipRoot.IsVisible())
330
331
332#ifdef PLATFORM_CONSOLE
333 return false;
334#endif
335 return true;
336 }
337
338 override bool OnChange(Widget w, int x, int y, bool finished)
339 {
340 super.OnChange(w, x, y, finished);
341
342 if (m_SelectedHandler.OnChange(w, x, y, finished))
343 return true;
344
345 return false;
346 }
347
348 override bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
349 {
350 super.OnItemSelected(w, x, y, row, column, oldRow, oldColumn);
351
352
353 if (m_SelectedHandler.OnItemSelected(w, x, y, row, column, oldRow, oldColumn))
354 return true;
355
356 return false;
357 }
358
360 {
362 {
363 if (tabType == handler.Type())
364 return handler;
365 }
366 return null;
367 }
368
369
370 void SelectTabByID(int id)
371 {
372 ScriptConsoleTabBase tab = m_TabHandlersByID.Get(id);
373 if (tab)
374 SelectTab(tab);
375 }
376
378 {
379 ScriptConsoleTabBase tab = m_TabHandlers.Get(button);
380 if (tab)
381 SelectTab(tab);
382 }
383
391
392 protected void DisplayHint(string message)
393 {
394 if (message)
395 {
396 m_HintWidgetRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/script_console/script_console_hint.layout");
397 m_HintWidgetBackground = ImageWidget.Cast(m_HintWidgetRoot.FindAnyWidget("Background"));
398 m_HintWidget = RichTextWidget.Cast(m_HintWidgetRoot.FindAnyWidget("HintText"));
399
400 m_HintWidgetRoot.Show(true);
401 m_HintWidget.SetText(message);
402
403 int offsetX = 0;
404 int offsetY = 10;
405
406 int screenW, screenH;
408
409 int mouseX, mouseY;
411
412 float relativeX = mouseX / screenW;
413 float relativeY = mouseY / screenH;
414
415 int width, height;
416 m_HintWidget.GetTextSize(width, height);
417 if (relativeX > 0.8)
418 offsetX = -width - offsetX;
419 if (relativeY > 0.8)
421
423 m_HintWidgetBackground.SetScreenSize(width + 5, height + 5);
424
425 }
426 }
427
429 {
430 super.OnRPCEx(rpc_type, ctx);
431#ifdef DIAG_DEVELOPER
432
434 handler.OnRPCEx(rpc_type, ctx);
435#endif
436
437 }
438
440}
441
442
444{
446 protected Widget m_Root;
447
448
449 protected float m_HoverTime;
455
456 protected ref Timer m_Timer;
457
459 {
460 m_Root = w;
461 m_Root.SetHandler(this);
462 m_Root.SetFlags(WidgetFlags.VEXACTPOS);
463 }
464
465 override bool OnMouseEnter(Widget w, int x, int y)
466 {
467 m_Timer = new Timer();
468 m_Timer.Run(0.1, this, "Tick", NULL, true);
469
471 return true;
472 }
473
474 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
475 {
477 return true;
478 }
479
480 protected bool Tick()
481 {
482 if (!m_Root.IsVisibleHierarchy())
485 {
486 m_HoverTime += 0.1;
487 if (m_HoverTime > 1)
488 HoverSuccess();
489 }
490 return true;
491 }
492
493 protected void DisplayHint(string message)
494 {
495 if (message)
496 {
497 m_HintWidgetRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/script_console/script_console_hint.layout");
498 m_HintWidgetBackground = ImageWidget.Cast(m_HintWidgetRoot.FindAnyWidget("Background"));
499 m_HintWidget = RichTextWidget.Cast(m_HintWidgetRoot.FindAnyWidget("HintText"));
500
501 m_HintWidgetRoot.Show(true);
502 m_HintWidget.SetText(message);
503
504 int offsetX = 0;
505 int offsetY = 10;
506
507 int screenW, screenH;
509
510 int mouseX, mouseY;
512
513 float relativeX = mouseX / screenW;
514 float relativeY = mouseY / screenH;
515
516 int width, height;
517 m_HintWidget.GetTextSize(width, height);
518 if (relativeX > 0.8)
519 offsetX = -width - offsetX;
520 if (relativeY > 0.8)
522
524 m_HintWidgetBackground.SetScreenSize(width + 5, height + 5);
525
526 }
527 }
528
529 protected void HideHint()
530 {
532 m_HintWidgetRoot.Show(false);
533 }
534
535
536 protected string GetMessage()
537 {
538 return HintMessage;
539 }
540
541 protected void HoverSuccess()
542 {
545 }
546
547 protected void HoverInterrupt()
548 {
549 m_Timer = null;
552 m_HoverTime = 0;
553 HideHint();
554 }
555}
556
557
562
class GetServerModListResult m_Id
GetServersResultRow the output structure of the GetServers operation that represents one game server.
ref Timer m_Timer
Definition DayZGame.c:675
Icon x
Icon y
void Close()
PluginConfigDebugProfile m_ConfigDebugProfile
void PluginItemDiagnostic()
PluginBase GetPlugin(typename plugin_type)
ImageWidget m_HintWidgetBackground
string GetMessage()
Widget m_CurrentHoverWidget
float m_HoverTime
void HoverSuccess()
RichTextWidget m_HintWidget
class ScriptConsole extends UIScriptedMenu HintMessage
void HoverInterrupt()
bool m_HoverSuccessTriggered
Widget m_HintWidgetRoot
void DisplayHint(string message)
void HideHint()
void ScriptConsoleEnfScriptTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent=null)
Widget m_Root
Definition SizeToChild.c:85
void OnWidgetScriptInit(Widget w)
Definition SizeToChild.c:88
void Tick()
proto native UAInputAPI GetUApi()
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
ref map< int, string > WidgetHintBindings
Definition EnMath.c:7
bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
bool OnKeyDown(Widget w, int x, int y, int key)
bool OnDoubleClick(Widget w, int x, int y, int button)
bool OnMouseButtonDown(Widget w, int x, int y, int button)
bool OnKeyPress(Widget w, int x, int y, int key)
bool OnChange(Widget w, int x, int y, bool finished)
bool OnClick(Widget w, int x, int y, int button)
map: item x vector(index, width, height)
Definition EnWidgets.c:651
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
void SetHintText(string text, Widget w)
override bool OnMouseEnter(Widget w, int x, int y)
Widget m_CurrentHoverWidget
ButtonWidget m_HintCancelButton
void SelectTabByButton(Widget button)
ButtonWidget m_HintClearButton
string GetMessage()
PluginConfigDebugProfile m_ConfigDebugProfile
EditBoxWidget m_HintInputText
override void Update(float timeslice)
override void OnRPCEx(int rpc_type, ParamsReadContext ctx)
void ~ScriptConsole()
static ref JsonHintsData m_JsonData
Widget m_ButtonsWindowWidget
const string NO_HINT_TEXT
int GetWidgetCombinedHash(Widget w)
Widget m_EditTooltipRoot
override bool OnDoubleClick(Widget w, int x, int y, int button)
void SelectTabByID(int id)
override bool OnKeyPress(Widget w, int x, int y, int key)
ref map< Widget, ref ScriptConsoleTabBase > m_TabHandlers
override bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
static const string HINTS_PATH_OPTIONAL
static JsonHintsData GetData()
void RegisterTab(ScriptConsoleTabBase handler)
RichTextWidget m_HintWidget
override bool OnKeyDown(Widget w, int x, int y, int key)
override bool OnChange(Widget w, int x, int y, bool finished)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
ScriptConsoleTabBase m_SelectedHandler
static void SaveData()
ButtonWidget m_HintOkButton
Widget m_HintWidgetRoot
bool m_HoverSuccessTriggered
override Widget Init()
ImageWidget m_HintWidgetBackground
void SelectTab(ScriptConsoleTabBase selectedHandler)
ScriptConsoleTabBase GetTabHandler(typename tabType)
ButtonWidget m_CloseConsoleButton
Definition HelpScreen.c:6
override bool OnClick(Widget w, int x, int y, int button)
static const string HINTS_PATH_DEFAULT
ScriptConsoleTabBase GetSelectedHandler()
void DisplayHint(string message)
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
enum ShapeType ErrorEx
proto bool FileExist(string name)
Check existence of file.
proto native void ClearKey(KeyCode key)
KeyCode
Definition EnSystem.c:157
proto native int KeyState(KeyCode key)
static proto float Sqrt(float val)
Returns square root.
static proto float AbsFloat(float f)
Returns absolute value.
proto void GetScreenSize(out int x, out int y)
proto void GetMousePos(out int x, out int y)
WidgetFlags
Definition EnWidgets.c:58