ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -9,11 +9,18 @@ using Bansonic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
public class UI_Panel_Mail : MonoBehaviour
|
||||
{
|
||||
public static event Action OnUnreadStateChanged;
|
||||
private static readonly Dictionary<string, Sprite> ServerMailImageCache = new Dictionary<string, Sprite>(StringComparer.Ordinal);
|
||||
private static readonly HashSet<string> ServerMailImageLoadsInFlight = new HashSet<string>(StringComparer.Ordinal);
|
||||
#if UNITY_EDITOR
|
||||
private const string DefaultCoinRewardIconPath = "Assets/__UI_NEW/hallway/icon.90.90/icon_coin.png";
|
||||
private const string DefaultMaterialRewardIconPath = "Assets/__UI_NEW/hallway/icon.90.90/icon_piece.png";
|
||||
#endif
|
||||
|
||||
//1234567890
|
||||
[SerializeField] float anim_Time = 0.5f;
|
||||
@@ -31,6 +38,10 @@ public class UI_Panel_Mail : MonoBehaviour
|
||||
[Header("rewards objects")]
|
||||
public GameObject rewardSlotPrefab;
|
||||
[SerializeField] Transform content_Reward_Slot;
|
||||
[Header("reward fallback icons")]
|
||||
[SerializeField] private Sprite playerExpRewardIcon;
|
||||
[SerializeField] private Sprite coinRewardIcon;
|
||||
[SerializeField] private Sprite materialRewardIcon;
|
||||
|
||||
[Header("texts")]
|
||||
public Text thisMail_title;
|
||||
@@ -47,11 +58,12 @@ public class UI_Panel_Mail : MonoBehaviour
|
||||
|
||||
[Header("buttons")]
|
||||
public Button receive_this_mail;
|
||||
public Button backButton;
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
CloseMailPanel();
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
@@ -60,12 +72,14 @@ public class UI_Panel_Mail : MonoBehaviour
|
||||
{
|
||||
item.speed = Anim_Speed;
|
||||
}
|
||||
MailRewardGrantService.ConfigureBasicRewardIcons(playerExpRewardIcon, coinRewardIcon, materialRewardIcon);
|
||||
BindTopLevelButtons();
|
||||
InitializeMailSource();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
MailRewardGrantService.ConfigureBasicRewardIcons(playerExpRewardIcon, coinRewardIcon, materialRewardIcon);
|
||||
InitializeMailSource();
|
||||
}
|
||||
|
||||
@@ -74,6 +88,48 @@ public class UI_Panel_Mail : MonoBehaviour
|
||||
UnsubscribeMailService();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
TryAssignDefaultRewardIcons();
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
TryAssignDefaultRewardIcons();
|
||||
}
|
||||
|
||||
private void TryAssignDefaultRewardIcons()
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if (coinRewardIcon == null)
|
||||
{
|
||||
Sprite coinIcon = AssetDatabase.LoadAssetAtPath<Sprite>(DefaultCoinRewardIconPath);
|
||||
if (coinIcon != null)
|
||||
{
|
||||
coinRewardIcon = coinIcon;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (materialRewardIcon == null)
|
||||
{
|
||||
Sprite materialIcon = AssetDatabase.LoadAssetAtPath<Sprite>(DefaultMaterialRewardIconPath);
|
||||
if (materialIcon != null)
|
||||
{
|
||||
materialRewardIcon = materialIcon;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed && !Application.isPlaying)
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void InitializeMailSource()
|
||||
{
|
||||
if (!isActiveAndEnabled)
|
||||
@@ -445,14 +501,18 @@ public class UI_Panel_Mail : MonoBehaviour
|
||||
|
||||
void BindTopLevelButtons()
|
||||
{
|
||||
if (receive_this_mail == null)
|
||||
if (receive_this_mail != null)
|
||||
{
|
||||
return;
|
||||
receive_this_mail.onClick.RemoveListener(HandleReceiveCurrentMailClicked);
|
||||
receive_this_mail.onClick.AddListener(HandleReceiveCurrentMailClicked);
|
||||
RefreshReceiveButton();
|
||||
}
|
||||
|
||||
receive_this_mail.onClick.RemoveListener(HandleReceiveCurrentMailClicked);
|
||||
receive_this_mail.onClick.AddListener(HandleReceiveCurrentMailClicked);
|
||||
RefreshReceiveButton();
|
||||
if (backButton != null)
|
||||
{
|
||||
backButton.onClick.RemoveListener(HandleBackButtonClicked);
|
||||
backButton.onClick.AddListener(HandleBackButtonClicked);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleReceiveCurrentMailClicked()
|
||||
@@ -465,6 +525,16 @@ public class UI_Panel_Mail : MonoBehaviour
|
||||
OnMailReceived(selectedSlot, selectedMailData);
|
||||
}
|
||||
|
||||
void HandleBackButtonClicked()
|
||||
{
|
||||
CloseMailPanel();
|
||||
}
|
||||
|
||||
void CloseMailPanel()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void RefreshReceiveButton()
|
||||
{
|
||||
if (receive_this_mail == null)
|
||||
@@ -1282,6 +1352,27 @@ public static class MailRewardGrantService
|
||||
private static readonly Dictionary<int, storeItemSO> StoreItemsById = new Dictionary<int, storeItemSO>();
|
||||
private static readonly Dictionary<string, storeItemSO> StoreItemsByName = new Dictionary<string, storeItemSO>(StringComparer.OrdinalIgnoreCase);
|
||||
private static bool _assetsLoaded;
|
||||
private static Sprite _playerExpRewardIcon;
|
||||
private static Sprite _coinRewardIcon;
|
||||
private static Sprite _materialRewardIcon;
|
||||
|
||||
public static void ConfigureBasicRewardIcons(Sprite playerExpIcon, Sprite coinIcon, Sprite materialIcon)
|
||||
{
|
||||
if (playerExpIcon != null)
|
||||
{
|
||||
_playerExpRewardIcon = playerExpIcon;
|
||||
}
|
||||
|
||||
if (coinIcon != null)
|
||||
{
|
||||
_coinRewardIcon = coinIcon;
|
||||
}
|
||||
|
||||
if (materialIcon != null)
|
||||
{
|
||||
_materialRewardIcon = materialIcon;
|
||||
}
|
||||
}
|
||||
|
||||
public static void PopulateRewardDisplay(mail_so.rewardItem reward)
|
||||
{
|
||||
@@ -1296,15 +1387,15 @@ public static class MailRewardGrantService
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(reward.rewardName))
|
||||
if (ShouldOverrideRewardDisplayName(reward, resolved))
|
||||
{
|
||||
reward.rewardName = resolved.DisplayName;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(reward.reward_description))
|
||||
if (ShouldOverrideRewardDescription(reward, resolved))
|
||||
{
|
||||
reward.reward_description = resolved.Description;
|
||||
}
|
||||
if (reward.reward_image == null)
|
||||
if (resolved.Icon != null)
|
||||
{
|
||||
reward.reward_image = resolved.Icon;
|
||||
}
|
||||
@@ -1585,13 +1676,13 @@ public static class MailRewardGrantService
|
||||
switch (reward.reward_Type)
|
||||
{
|
||||
case mail_so.reward_type.exp_user:
|
||||
resolved = CreateBasicResolved(ResolvedKind.PlayerExp, amount, rewardName, reward.reward_image, reward.reward_description, reward, "\u73a9\u5bb6\u7ecf\u9a8c");
|
||||
resolved = CreateBasicResolved(ResolvedKind.PlayerExp, amount, rewardName, reward.reward_image != null ? reward.reward_image : _playerExpRewardIcon, reward.reward_description, reward, "\u73a9\u5bb6\u7ecf\u9a8c");
|
||||
return true;
|
||||
case mail_so.reward_type.money:
|
||||
resolved = CreateBasicResolved(ResolvedKind.Coins, amount, rewardName, reward.reward_image, reward.reward_description, reward, "\u91d1\u5e01");
|
||||
resolved = CreateBasicResolved(ResolvedKind.Coins, amount, rewardName, reward.reward_image != null ? reward.reward_image : _coinRewardIcon, reward.reward_description, reward, "\u91d1\u5e01");
|
||||
return true;
|
||||
case mail_so.reward_type.metarial:
|
||||
resolved = CreateBasicResolved(ResolvedKind.Material, amount, rewardName, reward.reward_image, reward.reward_description, reward, "\u8bb0\u5fc6\u788e\u7247");
|
||||
resolved = CreateBasicResolved(ResolvedKind.Material, amount, rewardName, reward.reward_image != null ? reward.reward_image : _materialRewardIcon, reward.reward_description, reward, "\u8bb0\u5fc6\u788e\u7247");
|
||||
return true;
|
||||
case mail_so.reward_type.expBottles_allies:
|
||||
if (TryResolveExpBottle(reward, rewardKey, rewardName, amount, out resolved))
|
||||
@@ -1644,6 +1735,44 @@ public static class MailRewardGrantService
|
||||
};
|
||||
}
|
||||
|
||||
private static bool ShouldOverrideRewardDisplayName(mail_so.rewardItem reward, ResolvedReward resolved)
|
||||
{
|
||||
if (reward == null || resolved == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (resolved.Kind)
|
||||
{
|
||||
case ResolvedKind.ExpBottle:
|
||||
case ResolvedKind.GrowthMaterial:
|
||||
case ResolvedKind.EquipmentConsumable:
|
||||
case ResolvedKind.StoreItem:
|
||||
return !string.IsNullOrWhiteSpace(resolved.DisplayName);
|
||||
default:
|
||||
return string.IsNullOrWhiteSpace(reward.rewardName) && !string.IsNullOrWhiteSpace(resolved.DisplayName);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ShouldOverrideRewardDescription(mail_so.rewardItem reward, ResolvedReward resolved)
|
||||
{
|
||||
if (reward == null || resolved == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (resolved.Kind)
|
||||
{
|
||||
case ResolvedKind.ExpBottle:
|
||||
case ResolvedKind.GrowthMaterial:
|
||||
case ResolvedKind.EquipmentConsumable:
|
||||
case ResolvedKind.StoreItem:
|
||||
return !string.IsNullOrWhiteSpace(resolved.Description);
|
||||
default:
|
||||
return string.IsNullOrWhiteSpace(reward.reward_description) && !string.IsNullOrWhiteSpace(resolved.Description);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryResolveByRewardKey(mail_so.rewardItem reward, string rewardKey, string rewardName, int amount, out ResolvedReward resolved)
|
||||
{
|
||||
if (TryResolveExpBottle(reward, rewardKey, rewardName, amount, out resolved))
|
||||
|
||||
Reference in New Issue
Block a user