2020-12-22 03:13:43 +00:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-06-12 01:57:15 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
2021-01-05 02:56:17 +00:00
|
|
|
|
using UnityEngine.InputSystem;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
using UnityEngine.UI;
|
2020-06-12 01:57:15 +01:00
|
|
|
|
|
|
|
|
|
|
public class ConfirmationDialog : PropertiesPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
public ClickCatcher CancelClickCatcher;
|
2021-01-06 14:56:39 +00:00
|
|
|
|
public GameObject ButtonGroup;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
public Button Cancel;
|
|
|
|
|
|
public Button Confirm;
|
2020-06-12 01:57:15 +01:00
|
|
|
|
|
|
|
|
|
|
private Action _onCancel;
|
|
|
|
|
|
private Action _onConfirm;
|
|
|
|
|
|
|
2021-01-19 01:22:56 +00:00
|
|
|
|
private void Start()
|
2020-06-12 01:57:15 +01:00
|
|
|
|
{
|
2020-12-14 02:56:35 +00:00
|
|
|
|
Cancel.onClick.AddListener(() =>
|
2020-06-12 01:57:15 +01:00
|
|
|
|
{
|
|
|
|
|
|
_onCancel?.Invoke();
|
|
|
|
|
|
End();
|
2020-12-14 02:56:35 +00:00
|
|
|
|
});
|
|
|
|
|
|
Confirm.onClick.AddListener(() =>
|
2020-06-12 01:57:15 +01:00
|
|
|
|
{
|
|
|
|
|
|
_onConfirm?.Invoke();
|
|
|
|
|
|
End();
|
2020-12-14 02:56:35 +00:00
|
|
|
|
});
|
2020-06-12 01:57:15 +01:00
|
|
|
|
if (CancelClickCatcher != null)
|
|
|
|
|
|
CancelClickCatcher.OnClick += data =>
|
|
|
|
|
|
{
|
|
|
|
|
|
_onCancel?.Invoke();
|
|
|
|
|
|
End();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
OnPropertyAdded += go =>
|
|
|
|
|
|
{
|
|
|
|
|
|
go.SetActive(true);
|
|
|
|
|
|
go.transform.SetSiblingIndex(Title.transform.GetSiblingIndex() + 1);
|
|
|
|
|
|
};
|
2021-01-06 14:56:39 +00:00
|
|
|
|
gameObject.SetActive(false);
|
2020-06-12 01:57:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void End()
|
|
|
|
|
|
{
|
|
|
|
|
|
CancelClickCatcher.gameObject.SetActive(false);
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-31 19:53:16 +00:00
|
|
|
|
public void Show(Action onConfirm = null, Action onCancel = null)
|
2020-06-12 01:57:15 +01:00
|
|
|
|
{
|
2021-01-06 14:56:39 +00:00
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
|
|
|
2020-06-12 01:57:15 +01:00
|
|
|
|
_onConfirm = onConfirm;
|
2020-12-31 19:53:16 +00:00
|
|
|
|
Confirm.gameObject.SetActive(onConfirm!=null);
|
2021-01-06 14:56:39 +00:00
|
|
|
|
|
2020-06-12 01:57:15 +01:00
|
|
|
|
_onCancel = onCancel;
|
2020-12-31 19:53:16 +00:00
|
|
|
|
Cancel.gameObject.SetActive(onCancel!=null);
|
2021-01-06 14:56:39 +00:00
|
|
|
|
|
2021-01-19 01:22:56 +00:00
|
|
|
|
ButtonGroup.SetActive(onConfirm!=null || onCancel!=null);
|
2021-01-06 14:56:39 +00:00
|
|
|
|
|
2021-01-05 02:56:17 +00:00
|
|
|
|
transform.position = Mouse.current.position.ReadValue();
|
2020-06-12 01:57:15 +01:00
|
|
|
|
CancelClickCatcher.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|