99 lines
2.3 KiB
C#
99 lines
2.3 KiB
C#
using Audio;
|
|
|
|
using LightJSON;
|
|
|
|
using Misc;
|
|
|
|
using UI;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace ConsoleConnection
|
|
{
|
|
public class SimpleButton : MonoBehaviour
|
|
{
|
|
public delegate void PressEventHandler(JSON command);
|
|
public static event PressEventHandler OnPress;
|
|
|
|
public JSON Command;
|
|
public bool IsBack = false;
|
|
public bool IsShortcut = false;
|
|
|
|
public ImageLoader IconLoader;
|
|
|
|
public string IconUrl
|
|
{
|
|
get
|
|
{
|
|
if(IconLoader == null) {
|
|
Debug.Log("Icon Loader not set on " + gameObject);
|
|
return string.Empty;
|
|
}
|
|
return IconLoader.ImageUrl;
|
|
}
|
|
|
|
set
|
|
{
|
|
if(IconLoader == null) {
|
|
Debug.Log("Icon Loader not set on " + gameObject);
|
|
return;
|
|
}
|
|
|
|
IconLoader.ImageUrl = value;
|
|
}
|
|
}
|
|
|
|
public Text Text;
|
|
|
|
public string Title
|
|
{
|
|
get
|
|
{
|
|
if(Text == null)
|
|
return string.Empty;
|
|
|
|
return Text.text;
|
|
}
|
|
|
|
set
|
|
{
|
|
if(Text == null)
|
|
return;
|
|
|
|
var style = new GUIStyle
|
|
{
|
|
font = Text.font,
|
|
fontSize = Text.fontSize,
|
|
fontStyle = Text.fontStyle
|
|
};
|
|
Text.text = StringProcessor.applyEllipsis(value, style, Text.rectTransform.rect.width);
|
|
}
|
|
}
|
|
|
|
private Button button = null;
|
|
|
|
private void Start()
|
|
{
|
|
button = GetComponent<Button>();
|
|
button.onClick.AddListener(() =>
|
|
{
|
|
if (Command != null && OnPress != null)
|
|
{
|
|
OnPress(Command);
|
|
}
|
|
|
|
AudioManager.Instance.Play(IsBack ? AudioManager.SoundIds.Return : AudioManager.SoundIds.Shortcut);
|
|
});
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (IsShortcut)
|
|
{
|
|
if (button.interactable != ShortcutModel.enabled)
|
|
button.interactable = ShortcutModel.enabled;
|
|
}
|
|
}
|
|
}
|
|
}
|