UI update 02
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Bansonic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class storeSystem : MonoBehaviour
|
||||
{
|
||||
private static readonly Regex RichTextTagRegex = new Regex("<.*?>", RegexOptions.Compiled);
|
||||
private static readonly string[] SortDropdownOptionLabels =
|
||||
{
|
||||
"默认排序",
|
||||
"价格升序",
|
||||
"价格降序",
|
||||
"类型升序",
|
||||
"类型降序",
|
||||
"限购升序",
|
||||
"限购降序"
|
||||
};
|
||||
private const string ShowOnlyPurchasablePrefKey = "store.show_only_can_purchase";
|
||||
private const string SortDropdownPrefKey = "store.sort_dropdown_value";
|
||||
private const string StoreStateSaveCategory = "store_state";
|
||||
@@ -48,7 +60,10 @@ public class storeSystem : MonoBehaviour
|
||||
|
||||
[Header("selecting item purchase")]
|
||||
public Text p_itemName;
|
||||
[SerializeField] private bool p_itemNameFollowRichTextColor = true;
|
||||
public Image p_itemImage;
|
||||
public Image p_itemRarityBtmImage;
|
||||
public Sprite[] raritybtmImageSprite;
|
||||
public Image p_sumCostImage;
|
||||
public Text p_sumCostText;
|
||||
public Button p_iAmount_plus;
|
||||
@@ -89,6 +104,7 @@ public class storeSystem : MonoBehaviour
|
||||
defaultSumCostColor = p_sumCostText.color;
|
||||
}
|
||||
|
||||
InitializeSortDropdownOptions();
|
||||
CacheToggles();
|
||||
RegisterHeaderControlCallbacks();
|
||||
RegisterToggleCallbacks();
|
||||
@@ -361,6 +377,26 @@ public class storeSystem : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeSortDropdownOptions()
|
||||
{
|
||||
if (sortDropdown == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sortDropdown.onValueChanged.RemoveListener(OnSortDropdownValueChanged);
|
||||
sortDropdown.ClearOptions();
|
||||
|
||||
var options = new List<Dropdown.OptionData>(SortDropdownOptionLabels.Length);
|
||||
for (int i = 0; i < SortDropdownOptionLabels.Length; i++)
|
||||
{
|
||||
options.Add(new Dropdown.OptionData(SortDropdownOptionLabels[i]));
|
||||
}
|
||||
|
||||
sortDropdown.AddOptions(options);
|
||||
sortDropdown.RefreshShownValue();
|
||||
}
|
||||
|
||||
private void TryCacheStoreItem(storeItemSO itemSO, string sourceLabel, HashSet<int> uniqueItemIds)
|
||||
{
|
||||
if (itemSO == null)
|
||||
@@ -674,6 +710,7 @@ public class storeSystem : MonoBehaviour
|
||||
|
||||
itemView.thisItemSO = itemSO;
|
||||
itemView.onItemClicked = HandleItemClicked;
|
||||
itemView.onQuickBuyClicked = HandleQuickBuyClicked;
|
||||
|
||||
var button = instance.GetComponent<Button>();
|
||||
if (button != null)
|
||||
@@ -701,6 +738,7 @@ public class storeSystem : MonoBehaviour
|
||||
SetupPrice(itemView, itemSO);
|
||||
SetupAvailabilityState(itemView, itemSO);
|
||||
SetupReadState(itemView, itemSO);
|
||||
SetupQuickBuyState(itemView, itemSO);
|
||||
}
|
||||
|
||||
private void ResolveVisibleSelection(List<storeItemSO> visibleItems)
|
||||
@@ -750,9 +788,12 @@ public class storeSystem : MonoBehaviour
|
||||
|
||||
if (p_itemName != null)
|
||||
{
|
||||
p_itemName.text = itemSO.itemName ?? string.Empty;
|
||||
p_itemName.text = GetDisplayItemName(itemSO.itemName);
|
||||
ApplyItemNameColorState(p_itemName);
|
||||
}
|
||||
|
||||
ApplyItemRarityBottomState(itemSO);
|
||||
|
||||
if (p_itemImage != null)
|
||||
{
|
||||
p_itemImage.sprite = itemSO.itemIcon;
|
||||
@@ -790,6 +831,7 @@ public class storeSystem : MonoBehaviour
|
||||
if (p_itemName != null)
|
||||
{
|
||||
p_itemName.text = string.Empty;
|
||||
ApplyItemNameColorState(p_itemName);
|
||||
}
|
||||
|
||||
if (p_itemImage != null)
|
||||
@@ -808,6 +850,8 @@ public class storeSystem : MonoBehaviour
|
||||
p_itemUsageText.text = string.Empty;
|
||||
}
|
||||
|
||||
ApplyItemRarityBottomState(null);
|
||||
|
||||
if (p_sumCostText != null)
|
||||
{
|
||||
p_sumCostText.text = string.Empty;
|
||||
@@ -1081,37 +1125,55 @@ public class storeSystem : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlayerSkillService.IsPlayerSkillStoreItem(currentSelectedItem))
|
||||
ExecutePurchase(currentSelectedItem, currentPurchaseAmount, true);
|
||||
}
|
||||
|
||||
private void ExecutePurchase(storeItemSO itemSO, int purchaseAmount, bool refreshSummaryOnFailure)
|
||||
{
|
||||
if (itemSO == null)
|
||||
{
|
||||
HandlePlayerSkillStorePurchaseClicked(currentSelectedItem);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsSelectableEquipmentRewardItem(currentSelectedItem))
|
||||
if (PlayerSkillService.IsPlayerSkillStoreItem(itemSO))
|
||||
{
|
||||
HandleSelectableEquipmentPurchaseClicked(currentSelectedItem);
|
||||
HandlePlayerSkillStorePurchaseClicked(itemSO, purchaseAmount, refreshSummaryOnFailure);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsSelectableEquipmentRewardItem(itemSO))
|
||||
{
|
||||
HandleSelectableEquipmentPurchaseClicked(itemSO, purchaseAmount, refreshSummaryOnFailure);
|
||||
return;
|
||||
}
|
||||
|
||||
string failureMessage;
|
||||
int grantedCount;
|
||||
if (!StoreExpBottlePurchaseService.TryPurchase(playerData, currentSelectedItem, currentPurchaseAmount, out failureMessage, out grantedCount))
|
||||
if (!StoreExpBottlePurchaseService.TryPurchase(playerData, itemSO, purchaseAmount, out failureMessage, out grantedCount))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(failureMessage))
|
||||
{
|
||||
gNotice.warning.display(failureMessage);
|
||||
}
|
||||
|
||||
RefreshPurchaseSummary();
|
||||
if (refreshSummaryOnFailure)
|
||||
{
|
||||
RefreshPurchaseSummary();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterPurchasedCount(currentSelectedItem.itemID, grantedCount);
|
||||
gItemGet.display(gItemGet.FromStoreItem(currentSelectedItem, grantedCount));
|
||||
RegisterPurchasedCount(itemSO.itemID, grantedCount);
|
||||
gItemGet.display(gItemGet.FromStoreItem(itemSO, grantedCount));
|
||||
RefreshCurrentView();
|
||||
}
|
||||
|
||||
private void HandlePlayerSkillStorePurchaseClicked(storeItemSO itemSO)
|
||||
{
|
||||
HandlePlayerSkillStorePurchaseClicked(itemSO, currentPurchaseAmount, true);
|
||||
}
|
||||
|
||||
private void HandlePlayerSkillStorePurchaseClicked(storeItemSO itemSO, int purchaseAmount, bool refreshSummaryOnFailure)
|
||||
{
|
||||
if (itemSO == null)
|
||||
{
|
||||
@@ -1120,33 +1182,44 @@ public class storeSystem : MonoBehaviour
|
||||
|
||||
string failureMessage;
|
||||
gItemGet.ItemEntry rewardEntry;
|
||||
if (!PlayerSkillService.TryPurchasePlayerSkillStoreItem(itemSO, currentPurchaseAmount, out failureMessage, out rewardEntry))
|
||||
if (!PlayerSkillService.TryPurchasePlayerSkillStoreItem(itemSO, purchaseAmount, out failureMessage, out rewardEntry))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(failureMessage))
|
||||
{
|
||||
gNotice.warning.display(failureMessage);
|
||||
}
|
||||
|
||||
RefreshPurchaseSummary();
|
||||
if (refreshSummaryOnFailure)
|
||||
{
|
||||
RefreshPurchaseSummary();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterPurchasedCount(itemSO.itemID, currentPurchaseAmount);
|
||||
RegisterPurchasedCount(itemSO.itemID, purchaseAmount);
|
||||
gItemGet.display(rewardEntry);
|
||||
RefreshCurrentView();
|
||||
}
|
||||
|
||||
private void HandleSelectableEquipmentPurchaseClicked(storeItemSO itemSO)
|
||||
{
|
||||
HandleSelectableEquipmentPurchaseClicked(itemSO, currentPurchaseAmount, true);
|
||||
}
|
||||
|
||||
private void HandleSelectableEquipmentPurchaseClicked(storeItemSO itemSO, int purchaseAmount, bool refreshSummaryOnFailure)
|
||||
{
|
||||
if (itemSO == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPurchaseAmount != 1)
|
||||
if (purchaseAmount != 1)
|
||||
{
|
||||
SetPurchaseAmount(1, false);
|
||||
gNotice.warning.display("该物品仅支持单份购买");
|
||||
if (refreshSummaryOnFailure)
|
||||
{
|
||||
SetPurchaseAmount(1, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1169,7 +1242,10 @@ public class storeSystem : MonoBehaviour
|
||||
if (!HasEnoughCurrency(primaryCost.currencyType, totalCost))
|
||||
{
|
||||
gNotice.warning.display(insufficientMessage);
|
||||
RefreshPurchaseSummary();
|
||||
if (refreshSummaryOnFailure)
|
||||
{
|
||||
RefreshPurchaseSummary();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1178,7 +1254,7 @@ public class storeSystem : MonoBehaviour
|
||||
|
||||
if (!requireTypeSelection && !requireSkillSelection)
|
||||
{
|
||||
TryCompleteSelectableEquipmentPurchase(itemSO, rewardSource, requirement, null, 0);
|
||||
TryCompleteSelectableEquipmentPurchase(itemSO, rewardSource, requirement, null, 0, refreshSummaryOnFailure);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1218,7 +1294,7 @@ public class storeSystem : MonoBehaviour
|
||||
(selectedType, selectedSkillGroupId) =>
|
||||
{
|
||||
activeCtasInstance = null;
|
||||
TryCompleteSelectableEquipmentPurchase(itemSO, rewardSource, requirement, selectedType, selectedSkillGroupId);
|
||||
TryCompleteSelectableEquipmentPurchase(itemSO, rewardSource, requirement, selectedType, selectedSkillGroupId, refreshSummaryOnFailure);
|
||||
},
|
||||
() => { activeCtasInstance = null; });
|
||||
}
|
||||
@@ -1228,7 +1304,8 @@ public class storeSystem : MonoBehaviour
|
||||
smeltStageRewardSO rewardSource,
|
||||
smeltStageRewardSO.SmeltStageRewardRequirement requirement,
|
||||
equipmentSO.EquipmentSkillType? selectedType,
|
||||
int selectedSkillGroupId)
|
||||
int selectedSkillGroupId,
|
||||
bool refreshSummaryOnFailure)
|
||||
{
|
||||
if (itemSO == null || rewardSource == null || requirement == null || itemSO.costRequirements == null || itemSO.costRequirements.Count == 0)
|
||||
{
|
||||
@@ -1243,14 +1320,20 @@ public class storeSystem : MonoBehaviour
|
||||
if (!HasEnoughCurrency(primaryCost.currencyType, totalCost))
|
||||
{
|
||||
gNotice.warning.display(insufficientMessage);
|
||||
RefreshPurchaseSummary();
|
||||
if (refreshSummaryOnFailure)
|
||||
{
|
||||
RefreshPurchaseSummary();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TrySpendCurrency(primaryCost.currencyType, totalCost))
|
||||
{
|
||||
gNotice.warning.display(insufficientMessage);
|
||||
RefreshPurchaseSummary();
|
||||
if (refreshSummaryOnFailure)
|
||||
{
|
||||
RefreshPurchaseSummary();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1264,7 +1347,10 @@ public class storeSystem : MonoBehaviour
|
||||
{
|
||||
RefundCurrency(primaryCost.currencyType, totalCost);
|
||||
gNotice.warning.display("装备发放失败");
|
||||
RefreshPurchaseSummary();
|
||||
if (refreshSummaryOnFailure)
|
||||
{
|
||||
RefreshPurchaseSummary();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1329,9 +1415,88 @@ public class storeSystem : MonoBehaviour
|
||||
}
|
||||
|
||||
private bool CanPurchaseCurrentSelection(storeItemSO itemSO)
|
||||
{
|
||||
return CanPurchaseAmount(itemSO, currentPurchaseAmount);
|
||||
}
|
||||
|
||||
private bool CanPurchaseAmount(storeItemSO itemSO, int purchaseAmount)
|
||||
{
|
||||
return IsCurrentlyPurchasable(itemSO)
|
||||
&& (!IsSelectableEquipmentRewardItem(itemSO) || currentPurchaseAmount == 1);
|
||||
&& purchaseAmount >= MinPurchaseAmount
|
||||
&& (!IsSelectableEquipmentRewardItem(itemSO) || purchaseAmount == 1);
|
||||
}
|
||||
|
||||
private void ApplyItemNameColorState(Text itemNameText)
|
||||
{
|
||||
if (itemNameText == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
itemNameText.supportRichText = p_itemNameFollowRichTextColor;
|
||||
|
||||
if (!p_itemNameFollowRichTextColor)
|
||||
{
|
||||
itemNameText.color = Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDisplayItemName(string rawItemName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rawItemName))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (p_itemNameFollowRichTextColor)
|
||||
{
|
||||
return rawItemName;
|
||||
}
|
||||
|
||||
return RichTextTagRegex.Replace(rawItemName, string.Empty);
|
||||
}
|
||||
|
||||
private void ApplyItemRarityBottomState(storeItemSO itemSO)
|
||||
{
|
||||
if (p_itemRarityBtmImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite sprite = ResolveRarityBottomSprite(itemSO != null ? itemSO.itemRarity : ItemRarity.None);
|
||||
p_itemRarityBtmImage.sprite = sprite;
|
||||
p_itemRarityBtmImage.enabled = sprite != null;
|
||||
}
|
||||
|
||||
private Sprite ResolveRarityBottomSprite(ItemRarity rarity)
|
||||
{
|
||||
if (raritybtmImageSprite != null)
|
||||
{
|
||||
int enumIndex = (int)rarity;
|
||||
if (enumIndex >= 0 && enumIndex < raritybtmImageSprite.Length)
|
||||
{
|
||||
Sprite directSprite = raritybtmImageSprite[enumIndex];
|
||||
if (directSprite != null)
|
||||
{
|
||||
return directSprite;
|
||||
}
|
||||
}
|
||||
|
||||
if (rarity != ItemRarity.None)
|
||||
{
|
||||
int compactIndex = (int)rarity - 1;
|
||||
if (compactIndex >= 0 && compactIndex < raritybtmImageSprite.Length)
|
||||
{
|
||||
Sprite compactSprite = raritybtmImageSprite[compactIndex];
|
||||
if (compactSprite != null)
|
||||
{
|
||||
return compactSprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool CanAffordCurrentSelection(long totalCost)
|
||||
@@ -1522,6 +1687,16 @@ public class storeSystem : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupQuickBuyState(storeItemPrefab itemView, storeItemSO itemSO)
|
||||
{
|
||||
if (itemView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
itemView.RefreshQuickBuyState(itemSO != null && CanPurchaseAmount(itemSO, 1));
|
||||
}
|
||||
|
||||
private bool IsSoldOut(storeItemSO itemSO)
|
||||
{
|
||||
if (itemSO == null || itemSO.itemPurchaseQuota < 0)
|
||||
@@ -1558,6 +1733,16 @@ public class storeSystem : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleQuickBuyClicked(storeItemPrefab itemView)
|
||||
{
|
||||
if (itemView == null || itemView.thisItemSO == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ExecutePurchase(itemView.thisItemSO, 1, false);
|
||||
}
|
||||
|
||||
public void RegisterPurchasedCount(int itemID, int purchasedAmount)
|
||||
{
|
||||
if (purchasedAmount <= 0)
|
||||
|
||||
Reference in New Issue
Block a user