3 protected bool m_HintEditMode;
9 protected Widget m_EditTooltipRoot;
11 protected ButtonWidget m_HintOkButton;
12 protected ButtonWidget m_HintCancelButton;
13 protected ButtonWidget m_HintClearButton;
15 protected float m_PrevMouseX;
16 protected float m_PrevMouseY;
17 Widget m_ButtonsWindowWidget;
26 ButtonWidget m_CloseConsoleButton;
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";
34 const string NO_HINT_TEXT =
"No hint";
42 GetGame().GetMission().GetHud().ShowHudPlayer(
false);
43 GetGame().GetMission().GetHud().ShowQuickbarPlayer(
false);
48 plugin.OnScriptMenuOpened(
true);
56 GetGame().GetMission().GetHud().ShowHudPlayer(
true);
57 GetGame().GetMission().GetHud().ShowQuickbarPlayer(
true);
64 plugin.OnScriptMenuOpened(
false);
68 GetGame().GetMission().EnableAllInputs(
true);
74 return m_SelectedHandler;
77 static void SaveData()
80 if (!JsonFileLoader<JsonHintsData>.SaveFile(HINTS_PATH_OPTIONAL, m_JsonData, errorMessage))
86 string path = HINTS_PATH_OPTIONAL;
89 path = HINTS_PATH_DEFAULT;
95 if (!JsonFileLoader<JsonHintsData>.LoadFile(
path, data, errorMessage))
101 void SetHintText(
string text,
Widget w)
103 if (m_JsonData && m_JsonData.WidgetHintBindings && w)
105 int hash = GetWidgetCombinedHash(w);
106 m_JsonData.WidgetHintBindings.Set(hash, text);
107 Print(
"setting: " + text);
114 m_TabHandlers.Insert(handler.GetButton(), handler);
115 m_TabHandlersByID.Insert(
m_Id, handler);
124 layoutRoot =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/script_console/script_console.layout");
125 m_EditTooltipRoot =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/script_console/script_console_tooltip_edit.layout", layoutRoot);
126 m_EditTooltipRoot.Show(
false);
127 m_HintOkButton = ButtonWidget.Cast(m_EditTooltipRoot.FindAnyWidget(
"ButtonOk"));
128 m_HintCancelButton = ButtonWidget.Cast(m_EditTooltipRoot.FindAnyWidget(
"ButtonCancel"));
129 m_HintClearButton = ButtonWidget.Cast(m_EditTooltipRoot.FindAnyWidget(
"ButtonClear"));
130 m_HintInputText =
EditBoxWidget.Cast(m_EditTooltipRoot.FindAnyWidget(
"InputText"));
132 m_ButtonsWindowWidget = layoutRoot.FindAnyWidget(
"TabButtons");
133 m_ButtonsWindowWidget.Show(
true);
135 RegisterTab(
new ScriptConsoleItemsTab(layoutRoot.FindAnyWidget(
"ItemsPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"ItemsButtonWidget"))));
136 RegisterTab(
new ScriptConsoleConfigTab(layoutRoot.FindAnyWidget(
"ConfigsPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"ConfigsButtonWidget"))));
137 RegisterTab(
new ScriptConsoleEnfScriptTab(layoutRoot.FindAnyWidget(
"EnScriptPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"EnScriptButtonWidget"))));
138 RegisterTab(
new ScriptConsoleEnfScriptServerTab(layoutRoot.FindAnyWidget(
"EnScriptPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"EnScriptButtonWidgetServer"))));
139 RegisterTab(
new ScriptConsoleGeneralTab(layoutRoot.FindAnyWidget(
"GeneralPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"GeneralButtonWidget"))));
140 RegisterTab(
new ScriptConsoleOutputTab(layoutRoot.FindAnyWidget(
"OutputPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"OutputButtonWidget"))));
141 RegisterTab(
new ScriptConsoleVicinityTab(layoutRoot.FindAnyWidget(
"VicinityPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"VicinityWidget"))));
142 RegisterTab(
new ScriptConsoleSoundsTab(layoutRoot.FindAnyWidget(
"SoundsPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"SoundsWidget"))));
143 RegisterTab(
new ScriptConsoleWeatherTab(layoutRoot.FindAnyWidget(
"WeatherPanel"),
this,ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"WeatherButtonWidget"))));
145 m_CloseConsoleButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget(
"CloseConsoleButtonWidget"));
149 SelectTabByID(m_SelectedTab);
151 m_JsonData = GetData();
162 int GetWidgetCombinedHash(
Widget w)
164 string nameThis = w.GetName();
165 string nameParent =
"";
169 nameParent = w.GetParent().GetName();
172 string namesCombined = nameThis + nameParent;
173 return namesCombined.Hash();
180 if (m_JsonData && m_JsonData.WidgetHintBindings)
182 if (m_JsonData.WidgetHintBindings.Contains(hash))
184 return m_JsonData.WidgetHintBindings.Get(hash);
203 m_HintEditMode =
false;
207 override bool OnKeyPress(
Widget w,
int x,
int y,
int key)
209 super.OnKeyPress(w,
x,
y, key);
211 if (m_SelectedHandler.OnKeyPress(w,
x,
y,key))
219 super.OnKeyDown(w,
x,
y, key);
221 if (m_SelectedHandler.OnKeyDown(w,
x,
y,key))
227 override void Update(
float timeslice)
229 super.Update(timeslice);
233 float dist =
Math.Sqrt(
Math.AbsFloat(mouseX - m_PrevMouseX) +
Math.AbsFloat(mouseY - m_PrevMouseY));
234 m_PrevMouseX = mouseX;
235 m_PrevMouseY = mouseY;
251 GetGame().GetUIManager().Back();
259 m_EditTooltipRoot.Show(
true);
261 if (text == NO_HINT_TEXT)
263 m_HintInputText.SetText(text);
270 handler.Update(timeslice);
276 super.OnMouseButtonDown(w,
x,
y,button);
278 if (m_SelectedHandler.OnMouseButtonDown(w,
x,
y,button))
287 super.OnClick(w,
x,
y, button);
289 if (w == m_CloseConsoleButton)
292 GetGame().GetMission().EnableAllInputs(
true);
295 else if (w == m_HintOkButton)
299 m_EditTooltipRoot.Show(
false);
302 else if (w == m_HintCancelButton)
305 m_EditTooltipRoot.Show(
false);
308 else if (w == m_HintClearButton)
310 m_HintInputText.SetText(
"");
314 SelectTabByButton(w);
316 if (m_SelectedHandler.OnClick(w,
x,
y,button))
323 super.OnDoubleClick(w,
x,
y, button);
325 if (m_SelectedHandler.OnDoubleClick(w,
x,
y,button))
333 super.OnMouseLeave(w, enterW,
x,
y);
335 if (!m_EditTooltipRoot.IsVisible())
342 super.OnMouseEnter(w,
x,
y);
343 if (!m_EditTooltipRoot.IsVisible())
348 #ifdef PLATFORM_CONSOLE
356 super.OnChange(w,
x,
y, finished);
358 if (m_SelectedHandler.OnChange(w,
x,
y,finished))
364 override bool OnItemSelected(
Widget w,
int x,
int y,
int row,
int column,
int oldRow,
int oldColumn)
366 super.OnItemSelected(w,
x,
y, row, column, oldRow, oldColumn);
370 if (m_SelectedHandler.OnItemSelected(w,
x,
y, row, column,oldRow, oldColumn))
380 if (tabType == handler.Type())
389 void SelectTabByID(
int id)
396 void SelectTabByButton(
Widget button)
407 handler.Select(handler == selectedHandler, selectedHandler);
409 m_SelectedHandler = selectedHandler;
417 m_HintWidgetRoot =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/script_console/script_console_hint.layout");
427 int screenW, screenH;
433 float relativeX = mouseX / screenW;
434 float relativeY = mouseY / screenH;
439 offsetX = -width - offsetX;
441 offsetY = -height - offsetY;
451 super.OnRPCEx(rpc_type, ctx);
452 #ifdef DIAG_DEVELOPER
456 handler.OnRPCEx(rpc_type,ctx);
491 m_Timer.Run(0.1,
this,
"Tick", NULL,
true);
505 if (!
m_Root.IsVisibleHierarchy())
522 m_HintWidgetRoot =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/script_console/script_console_hint.layout");
532 int screenW, screenH;
538 float relativeX = mouseX / screenW;
539 float relativeY = mouseY / screenH;
544 offsetX = -width - offsetX;
546 offsetY = -height - offsetY;