forked from Relicta-Team/ReSDK_A3.vr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.sqf
547 lines (408 loc) · 17.6 KB
/
container.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
// ======================================================
// Copyright (c) 2017-2024 the ReSDK_A3 project
// sdk.relicta.ru
// ======================================================
#include "..\WidgetSystem\widgets.hpp"
#include "..\..\host\engine.hpp"
#include "..\..\host\keyboard.hpp"
#include "..\ClientRpc\clientRpc.hpp"
#include "inventory.hpp"
#include "helpers.hpp"
#include "..\Interactions\interact.hpp"
#define CONTAINER_SIZE_W 3
#define CONTAINER_SIZE_Y
#define SIZE_BUTTON 3
#define TIME_CONTAINER_ONLOAD 0.25
//из TIME_PREPARE_SLOTS
#define TIME_CONTAINER_ONUNLOAD 0.09
inventory_openContainer = {
if (!isInventoryOpen) exitWith {};
inventory_invWidgetSize params ["_leftX","_leftY","_rigthX","_rigthY"];
private _d = getDisplay;
_w = abs (_leftX - _rigthX);
_h = abs (_leftY - _rigthY);
// fix for 4:3 screensize (after 0.8.239)
private _xContPos = _leftX - (_w * CONTAINER_SIZE_W);
private _isProblemScreenSize = false;
private _biasXContPos = if (_xContPos < 0) then {
_isProblemScreenSize = true;
_leftX
} else {
_w * CONTAINER_SIZE_W
};
private _ctgRealPos = [(_xContPos) max 0,_leftY,_biasXContPos,_h];
private _ctg = [_d,WIDGETGROUP,_ctgRealPos] call createWidget;
private _back = [_d,BACKGROUND,WIDGET_FULLSIZE,_ctg] call createWidget;
_back setBackgroundColor [1,1,1,0.2];
private _ctgScrolling = [_d,WIDGETGROUP_H,[1.5,2.5,100 - 1.5,100 - 2.5],_ctg] call createWidget;
private _textRealPos = [_leftX - (_w * CONTAINER_SIZE_W),_leftY - SIZE_BUTTON,_w * CONTAINER_SIZE_W,SIZE_BUTTON];
// fix for 4:3 screensize (after 0.8.239)
if (_isProblemScreenSize) then {
_textRealPos set [0,_ctgRealPos select 0];
_textRealPos set [2,_ctgRealPos select 2];
};
private _text = [_d,TEXT,_textRealPos] call createWidget;
_text setBackgroundColor [0,0.02,0,0.8];
private _containerName = inventory_containerCommonData select 0;
[_text,format["<t align='center' valign='middle'>%1</t>",_containerName]] call widgetSetText;
inventory_contWidgetSize = [
_leftX - (_w * CONTAINER_SIZE_W),
_leftY - SIZE_BUTTON,
_leftX - (_w * CONTAINER_SIZE_W) + (_w * CONTAINER_SIZE_W) ,
_leftY - SIZE_BUTTON + SIZE_BUTTON + _h];
inventory_containerWidgets = [_ctg,_ctgScrolling,_text];
//creating icons
call inventory_loadContainerSlots;
//positions saving
_ctg setvariable ['realPos',_ctgRealPos];
_ctg setVariable ['textwidget',_text];
private _ctgNotReadyPos = [_leftX - (_w * CONTAINER_SIZE_W) + (_w * CONTAINER_SIZE_W),_leftY,0,_h];
_ctg setFade 1;
[_ctg,_ctgNotReadyPos] call widgetSetPosition;
_ctg setVariable ["notreadypos",_ctgNotReadyPos];
_text setVariable ['realPos',_textRealPos];
private _textNotReadyPos = +_textRealPos;
MODARR(_textNotReadyPos,0,+ (_w * CONTAINER_SIZE_W));
_textNotReadyPos set [2,0];
_text setFade 1;
[_text,_textNotReadyPos] call widgetSetPosition;
_text setVariable ["notreadypos",_textNotReadyPos];
//added close event for text
_text ctrlAddEventHandler ["MouseButtonUp",{
params ["_text","_key"];
if (_key != MOUSE_LEFT) exitWith {};
_text ctrlEnable false;
getContainerMainCtg ctrlEnable false;
nextFrame(inventory_closeContainer);
}];
true call inventory_onPrepareContainer;
inventory_isOpenContainer = true;
};
createWidget_contSlot = {
params ["_display","_slotName","_pos","_slotId","_ctgScr"];
private _offsetW = transformSizeByAR(SIZE_INVSLOT);
//private _isDragger = if (_slotName isequalto INDEX_DRAGGER) then {true} else {false};
private _ctg = [_display,WIDGETGROUP,_pos,_ctgScr] call createWidget;
private _background = [_display,BACKGROUND,[0,0,100,100],_ctg] call createWidget;
_background setBackgroundColor BACKGROUND_COLOR;
private _pic = [_display,PICTURE,[0,0,100,100],_ctg] call createWidget;
_ctg setvariable ['background',_background];
_ctg setVariable ["icon",_pic];
_ctg setVariable ["slotid",_slotId];
_ctg setvariable ["isContainerSlot",true];
inventory_containerSlots pushBack _ctg;
/*if (!_isDragger) then {
if (isEmptySlot(_slotId)) then {
[_pic,_slotId call inventoryGetPictureById] call widgetSetPicture;
} else {
[_pic,getSlotDataById(_slotId) select SD_ICON] call widgetSetPicture;
};
//common vars
_ctg setvariable ["slotname",_slotname];
_ctg setVariable ["slotid",_slotId];
//post save
inventor_slot_widgets set [_slotId,_ctg];
};*/
_ctg
};
inventory_loadContainerSlots = {
private _ctgScrolling = getContainerSlotsCtg;
private _d = getDisplay;
// Если в момент обновления драгали контейнерный слот то отменяем процесс
if (isDragProcess) then {
private _pressed = getPressedSlot;
if isContainerSlot(_pressed) then {
// сброс таскания
inventory_pressedwidget set [PRESSED_LINK,widgetNull];
getDragSlot setFade 1;
getDragSlot commit TIME_PREPARE_DRAG;
isInsidePressedSlot = false;
};
};
//Если уже был открыт перегружаем содержимое
{
ctrlDelete _x;
} foreach (inventory_containerSlots+inventory_freeSpaceSlots);
inventory_freeSpaceSlots = [];
inventory_containerSlots = [];// сброс
//Переустанавливаем текст (имя) контейнера
private _containerName = inventory_containerCommonData select container_index_name;
[getContainerNameText,format["<t align='center' valign='middle'>%1</t>",_containerName]] call widgetSetText;
//столбец col, ряд row
private _colCount = 0;
private _curRow = 0;
private _ctgSizeW = _w * CONTAINER_SIZE_W;
private _ctgSizeH = _h;
//logformat(" CONTAINER:: %1",[_ctgSizeW arg _ctgSizeH]);
private _sizeH = 100 / 3 * 0.9;
private _sizeW = 100 / 9 * 0.9;
//logformat(" SIZES:: %1",[_sizeW arg _sizeH]);
private _curData = "";
private _freeSpace = inventory_containerData deleteAt 0; //first always freespace
private _maxIndexSlot = (count inventory_containerData) - 1;
for "_i" from 0 to _maxIndexSlot do {
_curData = inventory_containerData select _i;
_slot = [_d,INDEX_DRAGGER,[
_sizeW * _colCount + (_sizeW / 8 * _colCount),//_sizeW * _colCount, //x
_sizeH * _curRow + (_sizeH / 8 * _curRow),//_sizeH * _curRow, //y
_sizeW,
_sizeH
],_i,_ctgScrolling] call createWidget_contSlot;
//realocate picutre path
private _icn = _curData select SD_ICON;
if (!(".paa" in _icn)) then {
_curData set [SD_ICON,PATH_PICTURE_INV(_curData select SD_ICON)];
};
(_slot getvariable 'icon') ctrlSetText (_curData select SD_ICON);
(_slot getvariable 'icon') ctrlSetTooltip (_curData select SD_NAME);
if (_colCount == 7) then {
INC(_curRow);
_colCount = 0;
} else {
INC(_colCount);
};
};
for "_i" from 1 to _freeSpace do {
_slot = [_d,BACKGROUND,[
_sizeW * _colCount + (_sizeW / 8 * _colCount),//_sizeW * _colCount, //x
_sizeH * _curRow + (_sizeH / 8 * _curRow),//_sizeH * _curRow, //y
_sizeW,
_sizeH
],_ctgScrolling] call createWidget;
_slot setBackgroundColor BACKGROUND_COLOR_NOITEM;
inventory_freeSpaceSlots pushBack _slot;
if (_colCount == 7) then {
INC(_curRow);
_colCount = 0;
} else {
INC(_colCount);
};
};
};
inventory_onPrepareContainer = {
private _ctg = getContainerMainCtg;
private _text = _ctg getvariable 'textwidget';
if (_this) then {
_ctg setFade 0;
[_ctg,_ctg getVariable 'realPos',TIME_CONTAINER_ONLOAD] call widgetSetPosition;
_text setFade 0;
[_text,_text getVariable 'realpos',TIME_CONTAINER_ONLOAD] call widgetSetPosition;
} else {
_ctg setFade 1;
[_ctg,_ctg getVariable 'notreadypos',TIME_CONTAINER_ONUNLOAD] call widgetSetPosition;
_text setFade 1;
[_text,_text getVariable 'notreadypos',TIME_CONTAINER_ONUNLOAD] call widgetSetPosition;
};
};
inventory_closeContainer = {
rpcSendToServer("onContainerClose",[player arg getContainerRef]);
call inventory_unloadContainerMenu;
//reset common container vars
inventory_containerCommonData = nullContainerCommonData;
inventory_containerData = [];// check SD_<var>
inventory_containerSlots = [];//список виджетов иконок внутри контейнера
inventory_contWidgetSize = [0,0,0,0];
};
inventory_onChangeLocContainer = {
if (isInventoryOpen) then {
if (inventory_isOpenContainer) then {
call inventory_unloadContainerMenu;
};
};
inventory_containerCommonData = nullContainerCommonData;
inventory_containerData = [];// check SD_<var>
inventory_containerSlots = [];//список виджетов иконок внутри контейнера
inventory_contWidgetSize = [0,0,0,0];
};
inventory_unloadContainerMenu = {
false call inventory_onPrepareContainer;
_postcallCode = {
inventory_isOpenContainer = false;
if (isDragProcess) then {
getDragSlot setFade 1;
getDragSlot commit TIME_PREPARE_DRAG;
};
private _ctg = getContainerMainCtg;
if (_ctg isEqualTo widgetNull) exitWith {};
private _text = _ctg getVariable 'textwidget';
[_ctg] call deleteWidget;
if (_text isEqualTo widgetNull) exitWith {};
[_text] call deleteWidget;
};
invokeAfterDelay(_postcallCode,TIME_CONTAINER_ONUNLOAD + 0.01);
};
// Открывает контейнер и загружает данные
inventory_onContainerOpen = {
private _prms = _this;
params ["_main","_data"];
FHEADER;
if (nd_isOpenDisplay) exitWith {
call nd_onClose;
nextFrameParams(inventory_onContainerOpen,_prms);
};
//Предварительный диспос контейнера. Вторая проверка сравнивает полученную ссылку с существующей
if (inventory_isOpenContainer && {!((_main select container_index_ref) isEqualTo getContainerRef)}) then {
traceformat("inventory::onContainerOpen() - reload container: %1 %2",_main select container_index_ref arg getContainerRef)
rpcSendToServer("onContainerClose",[player arg getContainerRef]);
};
//realloc visobj ptr
// if pointer nonexisten on local client and need generate visual reference -> throw error
//if (equals(_main select container_index_object,container_object_awaitGenerateValue)) then {
//container in world
if (_main select container_index_isInWorld) then {
if (!array_exists(noe_client_allPointers,_main select container_index_ref)) exitWith {
errorformat("inventory::onContainerOpen() - Cant find pointer %1",criptPtr(_main select container_index_ref));
RETURN(false);
};
_main set [container_index_object,noe_client_allPointers get (_main select container_index_ref)];
} else {
//container in inventory
};
//} else {
//warningformat("inventory::onContainerOpen() - Object already initialized as %1",tolower typeName (_main select container_index_object));
//};
inventory_containerCommonData = _main;
inventory_containerData = _data;
if isWorldContainer then {
_main set [container_index_posoffset,((getWorldContainer worldToModelVisual (call interact_getCursorIntersectPos)))];
} else {
_main set [container_index_posoffset,[0,0,0]];
};
//NOT NEED
/*if (interact_isOpenMousemode) then {
call interact_closeMouseMode;
};*/
_nextFrame = {
FHEADER;
if (!isInventoryOpen) then {
call openInventory;
} else {
//fix 0.7.378 - cant open container on mainaction as activated verb in world
if (inventory_supressInventoryOpen) then {
nextFrameParams(_this,_this);
RETURN(0);
};
};
if (inventory_isOpenContainer) then {
call inventory_loadContainerSlots;
} else {
call inventory_openContainer;
};
};
nextFrameParams(_nextFrame,_nextFrame);
};
inventory_onContainerContentUpdate = {
private _data = _this;
// Если контейнер уже закрыт (общая дата очищена то обновление или открытие не требуется) - возможно пришёл устаревший пакет
if equals(inventory_containerCommonData,nullContainerCommonData) exitWith {
warning("inventory::onContainerContentUpdate - Obsolete info getting. Container already closed on client");
};
// fix singleplayer debug mode - nextframe bug
//inventory_containerData = _data;
/*if (interact_isOpenMousemode) then {
call interact_closeMouseMode;
};*/
_nextFrame = {
//for synced work. updated after 0.5.158
inventory_containerData = _this;
//Вот это условие не должно отрабатывать.
if (!isInventoryOpen) then {
//todo если будет вызвано данное предупреждение хоть раз - убрать открытие инвентаря из этого условия
warning("inventory::onContainerContentUpdate() - critical case of updating with closed inventory");
call openInventory;
};
if (inventory_isOpenContainer) then {
call inventory_loadContainerSlots;
} else {
call inventory_openContainer;
};
};
nextFrameParams(_nextFrame,_data); //Засчёт передачи данных через параметры мы не пропустим подмену данных в соседнем кадре.
};
//цикл в маин треде
inventory_onUpdateContainer = {
if (isWorldContainer) then {
private _worldObj = getWorldContainer;
if (_worldObj isEqualTo objnull) exitWith {
warning("Inventory::onUpdateContainer - world object is null reference");
};
//updated alg 0.7.378
// Поскольку мировые контейнеры больше не открываются с центральной точки
// экрана а только через верб меню (кстати ранее в интеракте эта проблема
// тоже бы возникала), то проверки делаются до точки нажатия по вербу
if !([_worldObj,(_worldObj modelToWorldVisual getContainerPosOffset)] call interact_canInteractWithObject) exitWith {
invlog("Inventory::onUpdateContainer - cant interact with object >> %1",inventory_containerCommonData)
call inventory_closeContainer;
};
//traceformat("DATA CHECK %1",verb_internal_bufferedObjData select 0);
/*(objnull call interact_getIntersectData) params ["_obj","_pos"];
if not_equals(_obj,_worldObj) exitWith {
["Я не смотрю в контейнер...","error"] call chatPrint;
invlog("Inventory::onUpdateContainer - not equals objects: %1 %2",_worldObj arg _obj)
call inventory_closeContainer;
};
if !([_obj,_pos] call interact_canInteractWithObject) exitWith {
invlog("Inventory::onUpdateContainer - cant interact with object",0)
call inventory_closeContainer;
};*/
};
};
inventory_onPressContainerSlot = {
private _slotFrom = _this;
//setPressedSlotPosition(_slotFrom call getMousePositionInWidget); //TODO fixme. returns wrong positions
setPressedSlotPosition([0 arg 0]);
inventory_pressedwidget set [PRESSED_LINK,_slotFrom];
getDragSlot setFade DRAG_FADE_PROCESS;
getDragSlot commit TIME_PREPARE_DRAG; //Если не нужно мигание при нажатии - поставь тут 0
private _fromIcon = widgetGetPicture(getSlotIcon(_slotFrom));
[getSlotIcon(getDragSlot),_fromIcon] call widgetSetPicture;
isInsidePressedSlot = true;
getSlotBackground(getDragSlot) setBackgroundColor BACKGROUND_COLOR; //fix on green after onMainAction
invlog("Inventory::onPressContainerSlot - start dragging with icon %1. Drag is %2",_fromIcon arg getDragSlot);
//(getSlotId(_slotFrom) call inventory_getModelById) call inventory_createPreviewObject;
};
inventory_onReleaseSlotFromContainer = {
private _slotTo = _this;
private _pressedSlot = getPressedSlot;
inventory_pressedwidget set [PRESSED_LINK,widgetNull];
getDragSlot setFade 1;
getDragSlot commit TIME_PREPARE_DRAG;
isInsidePressedSlot = false;
if (_slotTo isEqualTo widgetNull) exitWith {
invlog("Inventory::onReleaseSlotFromContainer - slot to is null reference",0);
/*if (isInteractibleAction) then {
invlog("Inventory::onInteractTargetWith - Interacting on target with <%1> item.",getSlotDataById(getSlotId(_pressedSlot)));
[getInteractibleTarget,getSlotDataById(getSlotId(_pressedSlot))] call inventory_onInteractTargetWith;
} else {
invlog("Inventory::onReleaseSlot - Droping item. Data: <%1>",getSlotDataById(getSlotId(_pressedSlot)));
[getSlotId(_pressedSlot)] call inventory_onPutDownItem;
};
call inventory_deletePreviewObject;*/ //on post putdown
};
//call inventory_deletePreviewObject; //при драге с контейнера превью не создаётся
invlog("Inventory::onReleaseSlotFromContainer - transfer container item from id:%1 to %2",getSlotId(_pressedSlot) arg getSlotName(_slotTo));
[_pressedSlot,_slotTo] call inventory_onTransferSlotContainer;
};
inventory_onTransferSlotContainer = {
params ["_containerSlot","_slotTo"];
private _idFrom = getSlotId(_containerSlot);
private _IdTo = getSlotId(_slotTo);
if (!array_exists(INV_LIST_HANDS,_idTo)) exitWith {
invlog("Inventory::onTransferSlotContainer - Cant transfer from non hand slot %1. Process aborted.",_idTo);
private _cantrerquip = selectRandom ["%1 можно вытащить только в руки.","%1 надо сначала взять в руки."];
[format[_cantrerquip,(_idFrom call inventory_getContainerSlotDataById) select SD_NAME],"error"] call chatprint;
};
private _hashContainer = getContainerRef;
private _hashContItem = (_idFrom call inventory_getContainerSlotDataById) select SD_POINTER;
rpcSendToServer("onRemoveItemFromContainer",[player arg _hashContainer arg _hashContItem arg _idTo]);
};
inventory_onReleaseSlotToContainer = {
private _pressedSlot = getPressedSlot;
inventory_pressedwidget set [PRESSED_LINK,widgetNull];
getDragSlot setFade 1;
getDragSlot commit TIME_PREPARE_DRAG;
isInsidePressedSlot = false;
private _targHash = getContainerRef;
private _withHash = (getSlotId(_pressedSlot) call inventory_getSlotDataById) select SD_POINTER;
rpcSendToServer("onInteractInventoryWith",[player arg _withHash arg _targHash]);
};