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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
//-----------------------------------------------------------------------------
class UIMenuPanel: Managed
{
	proto native UIMenuPanel GetSubMenu();
	proto native UIMenuPanel GetParentMenu();
	proto native UIMenuPanel GetVisibleMenu();
	proto native void SetSubMenu(UIMenuPanel submenu);
	proto native void SetParentMenu(UIMenuPanel parent);
	proto native bool CanClose();
	proto native bool CanCloseOnEscape();
	//! Create & open menu with specific id (see \ref MenuID) and set this menu as its parent
	proto native UIScriptedMenu EnterScriptedMenu(int id);
	
	proto native void DestroySubmenu();
	proto native bool IsAnyMenuVisible();
	proto native bool IsVisible();

#ifdef FEATURE_CURSOR
	//! Signal when the menu is created through 'UIManager.CreateScriptedMenu'
	proto native bool IsCreatedHidden();
#endif
	
	//! If visibility of application is changed. On console it is called when application is suspended or constrained.
	//! @param isVisible indicate if application is visible in foreground
	void OnVisibilityChanged(bool isVisible)
	{
	}
	
	//! Safe way to close window, using this function can even window safely close itself
	proto native void Close();

	bool UseMouse()	{
		#ifdef PLATFORM_CONSOLE
		return GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
		#else
		return true;
		#endif
	}

	bool UseKeyboard()	{
		#ifdef PLATFORM_CONSOLE
		return GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
		#else
		return true;
		#endif
	}
	
	bool UseGamepad()	{
		return true;
	}

	//! Returns \ref MenuID
	int GetID()	{
		return MENU_UNKNOWN;
	}
	
	//! Refresh request, called from anywhere
	void Refresh()
	{
	}
};

//-----------------------------------------------------------------------------
//! Part of main menu hierarchy to create custom menus from script
class UIScriptedMenu extends UIMenuPanel
{
	int m_id;
	Widget layoutRoot;
	private Widget	m_AnimAlphaWidget;
	private bool	m_AnimAlphaIsIncreasing;
	private float	m_AnimAlphaValue;

	Widget GetLayoutRoot()
	{
		return layoutRoot;
	}
	
	void LockControls()
	{
#ifdef FEATURE_CURSOR
		if (IsCreatedHidden())
			return;
#endif

		if (UseMouse())
		{
			GetGame().GetInput().ChangeGameFocus(1, INPUT_DEVICE_MOUSE);
			GetGame().GetUIManager().ShowUICursor(true);
		}

		if (UseKeyboard())
		{
			GetGame().GetInput().ChangeGameFocus(1, INPUT_DEVICE_KEYBOARD);
		}
		
		if (UseGamepad())
		{
			GetGame().GetInput().ChangeGameFocus(1, INPUT_DEVICE_GAMEPAD);
		}
	}
	
	void UnlockControls()
	{
#ifdef FEATURE_CURSOR
		if (IsCreatedHidden())
			return;
#endif

		if (UseMouse())
		{
			GetGame().GetInput().ChangeGameFocus(-1, INPUT_DEVICE_MOUSE);
		}

		if (GetParentMenu() && GetParentMenu().UseMouse())
		{
			GetGame().GetUIManager().ShowUICursor(true);
		}
		else
		{
			GetGame().GetUIManager().ShowUICursor(false);
		}

		if(UseKeyboard())
		{
			GetGame().GetInput().ChangeGameFocus(-1, INPUT_DEVICE_KEYBOARD);
		}
		
		if(UseGamepad())
		{
			GetGame().GetInput().ChangeGameFocus(-1, INPUT_DEVICE_GAMEPAD);
		}
	}
	
	void UIScriptedMenu() 
	{
		m_id = MENU_UNKNOWN;
	}
	
	void ~UIScriptedMenu()
	{
	}

	//! Sets \ref MenuID
	void SetID(int id) {
		m_id = id;
	}

	//! Returns \ref MenuID
	override int GetID()	{
		return m_id;
	}

	void SetWidgetAnimAlpha( Widget widget )
	{
		m_AnimAlphaValue = 0.3;
		m_AnimAlphaWidget = widget;
	}
	
	//create widgets here and return layout root Widget
	//widgets will be destroyed automatically by c++ side
	Widget Init()
	{
		return NULL;
	}

	void Cleanup()
	{
	}

	//after show
	void OnShow()
	{
		LockControls();	
	}

	//after hide
	void OnHide()
	{
		UnlockControls();
	}

	//! Per frame update, called from engine
	void Update(float timeslice)
	{
		#ifdef PLATFORM_CONSOLE
		if ( m_AnimAlphaWidget )
		{
			float anim_speed = 1.2;
			float anim_value_max = 1.0;
			float anim_value_min = 0.3;
			if ( m_AnimAlphaIsIncreasing )
			{
				m_AnimAlphaValue += anim_speed * timeslice;
				
				if ( m_AnimAlphaValue >= anim_value_max )
				{
					m_AnimAlphaValue = anim_value_max;
					m_AnimAlphaIsIncreasing = false;
				}
			}
			else
			{
				m_AnimAlphaValue -= anim_speed * timeslice;
				
				if ( m_AnimAlphaValue <= anim_value_min )
				{
					m_AnimAlphaValue = anim_value_min;
					m_AnimAlphaIsIncreasing = true;
				}
			}
			
			
			m_AnimAlphaWidget.SetAlpha( m_AnimAlphaValue );
		}
		#endif
	}

	// Moved to parent
	//! Refresh request, called from anywhere
	//void Refresh()
	//{
	//}

	proto native void SetFadingPanels(Widget panel0, Widget panel1, Widget panel2, Widget panel3, Widget panel4);
	
	bool OnClick(Widget w, int x, int y, int button)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnClick( w, x, y, button ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnModalResult(Widget w, int x, int y, int code, int result)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnModalResult( w, x, y, code, result ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnDoubleClick(Widget w, int x, int y, int button)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDoubleClick( w, x, y, button ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnSelect(Widget w, int x, int y)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnSelect( w, x, y ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnItemSelected(Widget w, int x, int y, int row, int  column,	int  oldRow, int  oldColumn)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnItemSelected( w, x, y, row, column, oldRow, oldColumn ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnFocus(Widget w, int x, int y)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnFocus( w, x, y ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnFocusLost(Widget w, int x, int y)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnFocusLost( w, x, y ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnMouseEnter(Widget w, int x, int y)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseEnter( w, x, y ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseLeave( w, enterW, x, y ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnMouseButtonDown(Widget w, int x, int y, int button)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseButtonDown( w, x, y, button ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnMouseButtonUp(Widget w, int x, int y, int button)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseButtonUp( w, x, y, button ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnMouseWheel(Widget w, int x, int y, int wheel)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseWheel( w, x, y, wheel ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnController(Widget w, int control, int value)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnController( w, control, value ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnKeyDown(Widget w, int x, int y, int key)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnKeyDown( w, x, y, key ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnKeyUp(Widget w, int x, int y, int key)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnKeyUp( w, x, y, key ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnKeyPress(Widget w, int x, int y, int key)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnKeyPress( w, x, y, key ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnChange(Widget w, int x, int y, bool finished)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnChange( w, x, y, finished ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnDrag(Widget w, int x, int y)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDrag( w, x, y ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnDragging(Widget w, int x, int y, Widget reciever)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDragging( w, x, y, reciever ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnDraggingOver(Widget w, int x, int y, Widget reciever)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDraggingOver( w, x, y, reciever ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnDrop(Widget w, int x, int y, Widget reciever)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDrop( w, x, y, reciever ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}
	bool OnDropReceived(Widget w, int x, int y, Widget reciever)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDropReceived( w, x, y, reciever ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}

	bool OnEvent(EventType eventType, Widget target, int parameter0, int parameter1)
	{
		if ( UIScriptedWindow.GetActiveWindows() )
		{
			for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
			{
				if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnEvent( eventType, target, parameter0, parameter1 ) )
				{
					return true;
				}
			}
		}
		
		return false;
	}

	ScriptedWidgetEventHandler GetContextMenu()
	{
		return null;
	}
	
	bool OnXboxEvent(int xboxEvent)
	{
		return true;
	}
	
	void OnRPC(ParamsReadContext ctx){}
	void OnRPCEx(int rpc_type, ParamsReadContext ctx){}
	
	void InitNoteWrite(EntityAI paper, EntityAI pen, string text = "") {}
	void InitNoteRead(string text = "") {}
	void InitMapItem(EntityAI item) {}
	void LoadMapMarkers() {}
};