/
fnc_initExtendedDebugConsole.sqf
315 lines (239 loc) · 10.9 KB
/
fnc_initExtendedDebugConsole.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#include "\a3\ui_f\hpp\defineResinclDesign.inc"
#include "script_component.hpp"
#define MAX_STATEMENTS 50
#define INDENT_SPACES " "
params ["_display"];
// adjust position of the controls group
private _debugConsole = _display displayCtrl IDC_RSCDEBUGCONSOLE_RSCDEBUGCONSOLE;
_debugConsole ctrlSetPosition [
ctrlPosition _debugConsole select 0, // keep X
safezoneY + 1 * GUI_GRID_H, // top edge of the screen
22 * GUI_GRID_W, // slightly wider
1 - 2 * safezoneY // full screen height
];
_debugConsole ctrlCommit 0;
// --- adjust positions of all but a few controls
#define EXCLUDE [0, IDC_RSCDEBUGCONSOLE_LINK, IDC_RSCDEBUGCONSOLE_TITLE, IDC_RSCDEBUGCONSOLE_EXPRESSIONBACKGROUND, IDC_RSCDEBUGCONSOLE_EXPRESSIONTEXT, IDC_RSCDEBUGCONSOLE_EXPRESSION, IDC_RSCDEBUGCONSOLE_EXPRESSIONOUTPUT, IDC_RSCDEBUGCONSOLE_EXPRESSIONOUTPUTBACKGROUND]
{
if (ctrlParentControlsGroup _x == _debugConsole && {!(ctrlIDC _x in EXCLUDE)}) then {
private _position = ctrlPosition _x;
_position set [1, (_position select 1) + safezoneH - 25 * GUI_GRID_H];
_x ctrlSetPosition _position;
_x ctrlCommit 0;
};
} forEach allControls _display;
// flavor title
private _title = _display displayCtrl IDC_RSCDEBUGCONSOLE_TITLE;
_title ctrlSetText LLSTRING(ExtendedDebugConsole);
// --- EXPRESSION edit box
private _expression = _display displayCtrl IDC_RSCDEBUGCONSOLE_EXPRESSION;
private _position = ctrlPosition _expression;
_position set [3, safezoneH - 20.25 * GUI_GRID_H];
_expression ctrlSetPosition _position;
_expression ctrlCommit 0;
// Save expression when hitting enter key inside expression text field
_expression ctrlAddEventHandler ["KeyDown", {
params ["_expression", "_key", "_shift"];
if (_key in [DIK_RETURN, DIK_NUMPADENTER] && {!_shift}) then { // shift + enter is newline
// fix for enter key not working in MP
private _buttonLocalExec = ctrlParentControlsGroup _expression controlsGroupCtrl IDC_RSCDEBUGCONSOLE_BUTTONEXECUTELOCAL;
if (isMultiplayer && {ctrlEnabled _buttonLocalExec}) then {
[
"executeButton",
[ctrlParent _buttonLocalExec, _buttonLocalExec],
"RscDisplayDebugPublic",
0
] call compile preprocessFileLineNumbers "\A3\Ui_f\scripts\GUI\RscDebugConsole.sqf";
playSound "SoundClick";
};
_this call FUNC(logStatement);
};
if (_key isEqualTo DIK_TAB) then {
_expression setVariable [QGVAR(tabKey), [true, _shift]];
};
false
}];
// Reset Tab status on autocomplete
_expression ctrlAddEventHandler ["KeyUp", {
params ["_expression", "_key"];
if (_key isEqualTo DIK_TAB) then {
_expression setVariable [QGVAR(tabKey), nil];
};
}];
// Tab without autocomplete will move focus to another control, add whitespace
_expression ctrlAddEventHandler ["KillFocus", {
params ["_expression"];
if (GVAR(ConsoleIndentType) == -1) exitWith {};
private _tabKey = _expression getVariable [QGVAR(tabKey), [false, false]];
if (_tabKey isEqualTo [true, false]) then {
(ctrlTextSelection _expression) params ["_selStart", "_selLength"];
private _text = ctrlText _expression;
// replace selection with whitespace
private _indentType = [INDENT_SPACES, INDENT_TAB] select GVAR(ConsoleIndentType);
_expression ctrlSetText ([_text select [0, _selStart], _text select [_selStart + _selLength, count _text - 1]] joinString _indentType);
_expression ctrlSetTextSelection [_selStart + count _indentType, 0];
// change focus on next frame, using spawn as CBA_fnc_execNextFrame will not work in editor
_expression spawn {
ctrlSetFocus _this;
};
};
if (_tabKey isEqualTo [true, true]) then {
(ctrlTextSelection _expression) params ["_selStart"];
private _text = ctrlText _expression;
[_expression, _text, _selStart] call FUNC(removeIndentation);
// change focus on next frame, using spawn as CBA_fnc_execNextFrame will not work in editor
_expression spawn {
ctrlSetFocus _this;
};
};
_expression setVariable [QGVAR(tabDown), nil];
}];
private _expressionBackground = _display displayCtrl IDC_RSCDEBUGCONSOLE_EXPRESSIONBACKGROUND;
_position = ctrlPosition _expressionBackground;
_position set [3, safezoneH - 18.25 * GUI_GRID_H];
_expressionBackground ctrlSetPosition _position;
_expressionBackground ctrlCommit 0;
// --- EXPRESSION box output
{
private _expressionOutput = _display displayCtrl _x;
_position = ctrlPosition _expressionOutput;
_position set [1, (_position select 1) + safezoneH - 26.05 * GUI_GRID_H];
_expressionOutput ctrlSetPosition _position;
_expressionOutput ctrlCommit 0;
} forEach [IDC_RSCDEBUGCONSOLE_EXPRESSIONOUTPUT, IDC_RSCDEBUGCONSOLE_EXPRESSIONOUTPUTBACKGROUND];
// --- PREV button
private _prevButton = _display ctrlCreate ["RscButtonMenu", IDC_DEBUGCONSOLE_PREV, _debugConsole];
_prevButton ctrlSetPosition [
0 * GUI_GRID_W,
9.25 * GUI_GRID_H + safezoneH - 26.25 * GUI_GRID_H,
10.875 * GUI_GRID_W,
1 * GUI_GRID_H
];
_prevButton ctrlCommit 0;
_prevButton ctrlSetText LLSTRING(PrevStatement);
_prevButton ctrlAddEventHandler ["MouseButtonUp", {_this call FUNC(prevStatement); true}];
// --- NEXT button
private _nextButton = _display ctrlCreate ["RscButtonMenu", IDC_DEBUGCONSOLE_NEXT, _debugConsole];
_nextButton ctrlSetPosition [
11.125 * GUI_GRID_W,
9.25 * GUI_GRID_H + safezoneH - 26.25 * GUI_GRID_H,
10.875 * GUI_GRID_W,
1 * GUI_GRID_H
];
_nextButton ctrlCommit 0;
_nextButton ctrlSetText LLSTRING(NextStatement);
_nextButton ctrlAddEventHandler ["MouseButtonUp", {_this call FUNC(nextStatement); true}];
// disable PREV and/or NEXT button if needed
private _statementIndex = profileNamespace getVariable [QGVAR(statementIndex), 0];
private _prevStatements = profileNamespace getVariable [QGVAR(statements), []];
_prevButton ctrlEnable (_statementIndex < count _prevStatements - 1);
_nextButton ctrlEnable (_statementIndex > 0);
// --- EXEC buttons
private _execButtonLocal = _display displayCtrl IDC_RSCDEBUGCONSOLE_BUTTONEXECUTELOCAL;
_execButtonLocal ctrlAddEventHandler ["MouseButtonUp", {
_this call FUNC(logStatement);
false
}];
private _execButtonGlobal = _display displayCtrl IDC_RSCDEBUGCONSOLE_BUTTONEXECUTEALL;
_execButtonGlobal ctrlAddEventHandler ["MouseButtonUp", {
_this call FUNC(logStatement);
false
}];
private _execButtonServer = _display displayCtrl IDC_RSCDEBUGCONSOLE_BUTTONEXECUTESERVER;
_execButtonServer ctrlAddEventHandler ["MouseButtonUp", {
_this call FUNC(logStatement);
false
}];
private _codePerformance = _display displayCtrl IDC_RSCDEBUGCONSOLE_BUTTONCODEPERFORMANCE;
_codePerformance ctrlAddEventHandler ["MouseButtonUp", {
_this call FUNC(logStatement);
false
}];
// --- ui functions
FUNC(logStatement) = {
params ["_control"];
private _display = ctrlParent _control;
private _prevButton = _display displayCtrl IDC_DEBUGCONSOLE_PREV;
private _nextButton = _display displayCtrl IDC_DEBUGCONSOLE_NEXT;
private _expression = _display displayCtrl IDC_RSCDEBUGCONSOLE_EXPRESSION;
private _statement = ctrlText _expression;
private _statementIndex = profileNamespace getVariable [QGVAR(statementIndex), 0];
private _prevStatements = profileNamespace getVariable [QGVAR(statements), []];
if !((_prevStatements param [0, ""]) isEqualTo _statement) then {
_prevStatements deleteAt (_prevStatements find _statement);
// pushFront
reverse _prevStatements;
_prevStatements pushBack _statement;
reverse _prevStatements;
if (count _prevStatements > MAX_STATEMENTS) then {
_prevStatements resize MAX_STATEMENTS;
};
profileNamespace setVariable [QGVAR(statementIndex), 0];
profileNamespace setVariable [QGVAR(statements), _prevStatements];
// enable PREV, disable NEXT button
_prevButton ctrlEnable (count _prevStatements > 1);
_nextButton ctrlEnable false;
};
};
FUNC(prevStatement) = {
params ["_prevButton"];
private _display = ctrlParent _prevButton;
private _nextButton = _display displayCtrl IDC_DEBUGCONSOLE_NEXT;
private _expression = _display displayCtrl IDC_RSCDEBUGCONSOLE_EXPRESSION;
private _statementIndex = profileNamespace getVariable [QGVAR(statementIndex), 0];
private _prevStatements = profileNamespace getVariable [QGVAR(statements), []];
_statementIndex = (_statementIndex + 1) min ((count _prevStatements - 1) max 0);
profileNamespace setVariable [QGVAR(statementIndex), _statementIndex];
private _prevStatement = _prevStatements select _statementIndex;
_expression ctrlSetText _prevStatement;
// enable or disable PREV and NEXT button if needed
_prevButton ctrlEnable (_statementIndex < count _prevStatements - 1);
_nextButton ctrlEnable (_statementIndex > 0);
};
FUNC(nextStatement) = {
params ["_nextButton"];
private _display = ctrlParent _nextButton;
private _prevButton = _display displayCtrl IDC_DEBUGCONSOLE_PREV;
private _expression = _display displayCtrl IDC_RSCDEBUGCONSOLE_EXPRESSION;
private _statementIndex = profileNamespace getVariable [QGVAR(statementIndex), 0];
private _prevStatements = profileNamespace getVariable [QGVAR(statements), []];
_statementIndex = (_statementIndex - 1) max 0;
profileNamespace setVariable [QGVAR(statementIndex), _statementIndex];
private _nextStatement = _prevStatements select _statementIndex;
_expression ctrlSetText _nextStatement;
// enable or disable PREV and NEXT button if needed
_prevButton ctrlEnable (_statementIndex < count _prevStatements - 1);
_nextButton ctrlEnable (_statementIndex > 0);
};
FUNC(removeIndentation) = {
params ["_control", "_text", "_index"];
private _chars = toArray _text;
private _indexRev = count _chars - _index;
reverse _chars;
private _stepBack = 0;
// whitespace type to remove
private _whitespace = [ASCII_SPACE, ASCII_TAB];
{
if !(_x in _whitespace) exitWith {};
// do not remove mixed whitespace types
_whitespace = [_x];
_chars set [_indexRev + _forEachIndex, -1];
INC(_stepBack);
// remove only one Tab
if (_x == ASCII_TAB) exitWith {};
} forEach (_chars select [_indexRev, count INDENT_SPACES]);
_chars = _chars - [-1];
reverse _chars;
_expression ctrlSetText toString _chars;
_expression ctrlSetTextSelection [_index - _stepBack, 0];
};
// remove forced pause for watch fields
{
(_display displayCtrl _x) ctrlAddEventHandler ["SetFocus", {
_this spawn {
isNil {
(_this select 0) setVariable ["RscDebugConsole_watchPaused", false];
};
};
}];
} forEach [IDC_RSCDEBUGCONSOLE_WATCHINPUT1, IDC_RSCDEBUGCONSOLE_WATCHINPUT2, IDC_RSCDEBUGCONSOLE_WATCHINPUT3, IDC_RSCDEBUGCONSOLE_WATCHINPUT4];