4using UnityEngine.EventSystems;
5using UnityEngine.Events;
8public class UIContextMenu : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
28 public CanvasGroup
cg;
106 _rect = base.transform as RectTransform;
107 base.gameObject.SetActive(value:
false);
125 if (Input.GetKeyDown(KeyCode.Escape) || Input.GetMouseButtonDown(1))
141 if (Input.GetMouseButtonUp(0))
207 base.gameObject.SetActive(value:
true);
208 this.RebuildLayout(recursive:
true);
216 _rect.anchoredPosition =
new Vector2(-10000f, -10000f);
238 UnityEngine.Object.DestroyImmediate(base.gameObject);
251 if (!base.gameObject.activeSelf)
255 base.gameObject.SetActive(value:
false);
270 UnityEngine.Object.Instantiate(
separators[index]).transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
273 public void AddButton(Func<string> funcText, UnityAction action =
null)
276 item.transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
277 item.textName.text = funcText();
281 button.onClick.AddListener(action);
283 button.onClick.AddListener(delegate
287 item.textName.text = funcText();
295 uIContextMenuItem.transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
296 uIContextMenuItem.textName.text =
Lang.
Get(idLang);
300 uIButton.onClick.AddListener(
Hide);
302 if ((
bool)
popper && hideAfter)
308 uIButton.onClick.AddListener(delegate
319 uIContextMenuItem.transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
320 uIContextMenuItem.textName.text = idLang.lang().ToTitleCase();
321 uIContextMenuItem.toggle.isOn = isOn;
324 uIContextMenuItem.
toggle.onValueChanged.AddListener(action);
326 return uIContextMenuItem;
329 public UIContextMenuItem AddSlider(
string text, Func<float, string> textFunc,
float value, Action<float> action,
float min = 0f,
float max = 1f,
bool isInt =
false,
bool hideOther =
true,
bool useInput =
false)
332 return AddSlider(
item, text, textFunc, value, action, min, max, isInt, hideOther, useInput);
335 public UIContextMenuItem AddSlider(
string id,
string text, Func<float, string> textFunc,
float value, Action<float> action,
float min = 0f,
float max = 1f,
bool isInt =
false,
bool hideOther =
true,
bool useInput =
false)
338 return AddSlider(
item, text, textFunc, value, action, min, max, isInt, hideOther, useInput);
341 public UIContextMenuItem AddSlider(
UIContextMenuItem item,
string text, Func<float, string> textFunc,
float value, Action<float> action,
float min = 0f,
float max = 1f,
bool isInt =
false,
bool hideOther =
true,
bool useInput =
false)
344 Slider s =
item.slider;
345 item.transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
346 item.textName.text = text.lang();
353 s.wholeNumbers = isInt;
354 s.SetValueWithoutNotify(value);
355 item.textSlider.text = textFunc(value);
356 s.onValueChanged.AddListener(delegate(
float a)
358 item.textSlider.text = textFunc(a);
362 input.text = s.value.ToString() ??
"";
369 input.SetActive(useInput);
370 input.text = s.value.ToString() ??
"";
371 input.onValueChanged.AddListener(delegate(
string text)
375 float num2 = Mathf.Clamp(text.ToInt(), min, max);
376 s.SetValueWithoutNotify(num2);
380 input.onUpdate = delegate
382 if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
387 else if (!input.text.IsEmpty())
389 int num = input.text.ToInt();
390 if ((
float)num > max)
393 input.text = num.ToString() ??
"";
394 s.SetValueWithoutNotify(num);
400 input.onDisable = delegate
412 RectTransform blocker =
null;
413 EventTrigger component = s.GetComponent<EventTrigger>();
414 component.triggers.
Clear();
415 EventTrigger.Entry entry =
new EventTrigger.Entry
417 eventID = EventTriggerType.PointerDown
419 entry.callback.AddListener(delegate
421 blocker =
Util.Instantiate<RectTransform>(
"Items/sliderBlocker",
this);
422 blocker.SetAsFirstSibling();
423 UIContextMenu[] componentsInParent2 = GetComponentsInParent<UIContextMenu>();
424 for (
int j = 0; j < componentsInParent2.Length; j++)
426 componentsInParent2[j].
cg.DOFade(0.01f, 1f);
428 if ((
bool)s && s.gameObject !=
null)
430 s.gameObject.AddComponent<CanvasGroup>().ignoreParentGroups =
true;
433 component.triggers.Add(entry);
434 entry =
new EventTrigger.Entry
436 eventID = EventTriggerType.PointerUp
438 entry.callback.AddListener(delegate
446 UIContextMenu[] componentsInParent = GetComponentsInParent<UIContextMenu>();
449 DOTween.Kill(obj.
cg);
452 UnityEngine.Object.Destroy(s.GetComponent<CanvasGroup>());
453 UnityEngine.Object.DestroyImmediate(blocker.gameObject);
456 component.triggers.Add(entry);
463 GridLayoutGroup gridLayoutGroup = UnityEngine.Object.Instantiate(
defaultGridLayout);
464 gridLayoutGroup.transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
465 return gridLayoutGroup;
475 c.transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
488 if (componentsInDirectChild.
id == idLang)
490 return componentsInDirectChild.
menu;
499 uIContextMenu.layoutGroup.childAlignment = anchor;
500 return uIContextMenu;
506 uIContextMenuPopper.transform.SetParent(
layoutGroup.transform, worldPositionStays:
false);
507 uIContextMenuPopper.textName.text =
Lang.
Get(idLang);
508 uIContextMenuPopper.parent =
this;
509 uIContextMenuPopper.id = idLang;
513 uIContextMenuPopper.
button.onClick.RemoveAllListeners();
514 return uIContextMenuPopper.
menu;
519 base.gameObject.SetActive(value:
true);
520 this.RebuildLayout(recursive:
true);
521 _rect.anchoredPosition =
showPos;
522 RectTransform obj = _rect.parent as RectTransform;
523 Vector3 localPosition =
_rect.localPosition;
524 Vector3 vector = obj.rect.min -
_rect.rect.min;
525 Vector3 vector2 = obj.rect.max -
_rect.rect.max;
526 localPosition.x = Mathf.Clamp(
_rect.localPosition.x, vector.x, vector2.x);
527 localPosition.y = Mathf.Clamp(
_rect.localPosition.y, vector.y, vector2.y +
margin.y);
528 _rect.localPosition = localPosition;
virtual void ConsumeInput()
static string Get(string id)