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
|
@ -1987,6 +1987,9 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
inputField: {fileID: 23275626}
|
inputField: {fileID: 23275626}
|
||||||
|
unlockedSprite: {fileID: 6091405373536128358, guid: e70f17ed9e81410418db04270295ae3c, type: 3}
|
||||||
|
lockedSprite: {fileID: 21300000, guid: d8f3c281772d8ce428ce642723fa4ef9, type: 3}
|
||||||
|
button: {fileID: 1152326135}
|
||||||
--- !u!114 &1152326134
|
--- !u!114 &1152326134
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -2063,7 +2066,7 @@ MonoBehaviour:
|
||||||
m_OnCullStateChanged:
|
m_OnCullStateChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
m_Sprite: {fileID: 6091405373536128358, guid: e70f17ed9e81410418db04270295ae3c, type: 3}
|
m_Sprite: {fileID: 21300000, guid: d8f3c281772d8ce428ce642723fa4ef9, type: 3}
|
||||||
m_Type: 0
|
m_Type: 0
|
||||||
m_PreserveAspect: 0
|
m_PreserveAspect: 0
|
||||||
m_FillCenter: 1
|
m_FillCenter: 1
|
||||||
|
|
|
@ -1,17 +1,33 @@
|
||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Messaging.Composer {
|
namespace Messaging.Composer {
|
||||||
public class SendButton : MonoBehaviour {
|
public class SendButton : MonoBehaviour {
|
||||||
[SerializeField] private InputField inputField;
|
[SerializeField] private InputField inputField;
|
||||||
|
|
||||||
|
[SerializeField] private Sprite unlockedSprite;
|
||||||
|
[SerializeField] private Sprite lockedSprite;
|
||||||
|
private bool _locked;
|
||||||
|
|
||||||
|
[SerializeField] private Image button;
|
||||||
|
|
||||||
private MessageManager _messageManager;
|
private MessageManager _messageManager;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
_messageManager = FindObjectOfType<MessageManager>();
|
_messageManager = FindObjectOfType<MessageManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Lock() {
|
||||||
|
_locked = true;
|
||||||
|
button.sprite = lockedSprite;
|
||||||
|
}
|
||||||
|
public void Unlock() {
|
||||||
|
_locked = false;
|
||||||
|
button.sprite = unlockedSprite;
|
||||||
|
}
|
||||||
|
|
||||||
public void SendEmojis() {
|
public void SendEmojis() {
|
||||||
if (CanSendText()) {
|
if (CanSendText()) {
|
||||||
_messageManager.CreateMessage(inputField.Text, true);
|
_messageManager.CreateMessage(inputField.Text, true);
|
||||||
|
@ -20,7 +36,8 @@ namespace Messaging.Composer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanSendText() {
|
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 readonly Regex _emojiGetter = new("<([a-z]+)(?![^>]*\\/>)[^>]*>");
|
||||||
private const int NumEmojis = 35;
|
private const int NumEmojis = 35;
|
||||||
private EmojiButtonManager _emojiButtonManager;
|
private EmojiButtonManager _emojiButtonManager;
|
||||||
|
private SendButton _sendButton;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
_messages = messageStructureGenerator.GenerateMessages();
|
_messages = messageStructureGenerator.GenerateMessages();
|
||||||
_jokesBag = new List<TextAsset>(jokes);
|
_jokesBag = new List<TextAsset>(jokes);
|
||||||
_lives = FindObjectOfType<Lives>();
|
_lives = FindObjectOfType<Lives>();
|
||||||
_emojiButtonManager = FindObjectOfType<EmojiButtonManager>();
|
_emojiButtonManager = FindObjectOfType<EmojiButtonManager>();
|
||||||
|
_sendButton = FindObjectOfType<SendButton>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
|
@ -44,8 +46,10 @@ namespace Messaging {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void SendRandomJoke(float delay) {
|
private async void SendRandomJoke(float delay) {
|
||||||
//TODO: Lock send button here
|
_sendButton.Lock();
|
||||||
await Task.Delay((int)(delay * 1000));
|
await Task.Delay((int)(delay * 1000));
|
||||||
|
_sendButton.Unlock();
|
||||||
|
|
||||||
_currentJoke = GetRandomJoke();
|
_currentJoke = GetRandomJoke();
|
||||||
CreateMessage(_currentJoke.QuestionMessage.Key, false);
|
CreateMessage(_currentJoke.QuestionMessage.Key, false);
|
||||||
_emojiButtonManager.SetButtonImages(GenerateButtonOptions());
|
_emojiButtonManager.SetButtonImages(GenerateButtonOptions());
|
||||||
|
|
|
@ -34,7 +34,7 @@ TextureImporter:
|
||||||
maxTextureSize: 2048
|
maxTextureSize: 2048
|
||||||
textureSettings:
|
textureSettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
filterMode: 1
|
filterMode: 0
|
||||||
aniso: 1
|
aniso: 1
|
||||||
mipBias: 0
|
mipBias: 0
|
||||||
wrapU: 1
|
wrapU: 1
|
||||||
|
@ -48,7 +48,7 @@ TextureImporter:
|
||||||
spriteMeshType: 1
|
spriteMeshType: 1
|
||||||
alignment: 0
|
alignment: 0
|
||||||
spritePivot: {x: 0.5, y: 0.5}
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
spritePixelsToUnits: 100
|
spritePixelsToUnits: 16
|
||||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
spriteGenerateFallbackPhysicsShape: 1
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
alphaUsage: 1
|
alphaUsage: 1
|
||||||
|
@ -72,7 +72,7 @@ TextureImporter:
|
||||||
maxTextureSize: 2048
|
maxTextureSize: 2048
|
||||||
resizeAlgorithm: 0
|
resizeAlgorithm: 0
|
||||||
textureFormat: -1
|
textureFormat: -1
|
||||||
textureCompression: 1
|
textureCompression: 0
|
||||||
compressionQuality: 50
|
compressionQuality: 50
|
||||||
crunchedCompression: 0
|
crunchedCompression: 0
|
||||||
allowsAlphaSplitting: 0
|
allowsAlphaSplitting: 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue