feature: Lock button when waiting for new message
This commit is contained in:
parent
b2bd875508
commit
cb907bc76a
4 changed files with 30 additions and 6 deletions
|
@ -1,17 +1,33 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Messaging.Composer {
|
||||
public class SendButton : MonoBehaviour {
|
||||
[SerializeField] private InputField inputField;
|
||||
|
||||
[SerializeField] private Sprite unlockedSprite;
|
||||
[SerializeField] private Sprite lockedSprite;
|
||||
private bool _locked;
|
||||
|
||||
[SerializeField] private Image button;
|
||||
|
||||
private MessageManager _messageManager;
|
||||
|
||||
private void Awake() {
|
||||
_messageManager = FindObjectOfType<MessageManager>();
|
||||
}
|
||||
|
||||
public void Lock() {
|
||||
_locked = true;
|
||||
button.sprite = lockedSprite;
|
||||
}
|
||||
public void Unlock() {
|
||||
_locked = false;
|
||||
button.sprite = unlockedSprite;
|
||||
}
|
||||
|
||||
public void SendEmojis() {
|
||||
if (CanSendText()) {
|
||||
_messageManager.CreateMessage(inputField.Text, true);
|
||||
|
@ -20,7 +36,8 @@ namespace Messaging.Composer {
|
|||
}
|
||||
|
||||
private bool CanSendText() {
|
||||
return !string.IsNullOrEmpty(inputField.Text) && !string.IsNullOrWhiteSpace(inputField.Text);
|
||||
bool isInputEmpty = string.IsNullOrEmpty(inputField.Text) || string.IsNullOrWhiteSpace(inputField.Text);
|
||||
return !isInputEmpty && !_locked;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,12 +31,14 @@ namespace Messaging {
|
|||
private readonly Regex _emojiGetter = new("<([a-z]+)(?![^>]*\\/>)[^>]*>");
|
||||
private const int NumEmojis = 35;
|
||||
private EmojiButtonManager _emojiButtonManager;
|
||||
private SendButton _sendButton;
|
||||
|
||||
private void Awake() {
|
||||
_messages = messageStructureGenerator.GenerateMessages();
|
||||
_jokesBag = new List<TextAsset>(jokes);
|
||||
_lives = FindObjectOfType<Lives>();
|
||||
_emojiButtonManager = FindObjectOfType<EmojiButtonManager>();
|
||||
_sendButton = FindObjectOfType<SendButton>();
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
|
@ -44,8 +46,10 @@ namespace Messaging {
|
|||
}
|
||||
|
||||
private async void SendRandomJoke(float delay) {
|
||||
//TODO: Lock send button here
|
||||
_sendButton.Lock();
|
||||
await Task.Delay((int)(delay * 1000));
|
||||
_sendButton.Unlock();
|
||||
|
||||
_currentJoke = GetRandomJoke();
|
||||
CreateMessage(_currentJoke.QuestionMessage.Key, false);
|
||||
_emojiButtonManager.SetButtonImages(GenerateButtonOptions());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue