modify scripts

This commit is contained in:
2025-10-17 10:59:23 +08:00
parent 9336ed0d6f
commit 4f782a638e
131 changed files with 79880 additions and 3549 deletions

View File

@ -11,14 +11,9 @@
// // THE SOFTWARE.
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Serialization;
using WordsToolkit.Scripts.Audio;
using WordsToolkit.Scripts.Data;
using WordsToolkit.Scripts.Enums;
using WordsToolkit.Scripts.GUI;
using WordsToolkit.Scripts.GUI.Labels;
using WordsToolkit.Scripts.Services;
using WordsToolkit.Scripts.Services.IAP;
using WordsToolkit.Scripts.Settings;
using WordsToolkit.Scripts.System;
@ -31,6 +26,8 @@ namespace WordsToolkit.Scripts.Popups
private CoinsShopSettings shopSettings;
public ProductID noAdsProduct;
[SerializeField]
public TextMeshProUGUI noAdsPriceText;
[SerializeField]
private AudioClip coinsSound;
private void OnEnable()
@ -49,11 +46,14 @@ namespace WordsToolkit.Scripts.Popups
}
EventManager.GetEvent<string>(EGameEvent.PurchaseSucceeded).Subscribe(PurchaseSucceded);
EventManager.GetEvent<(string, string)>(EGameEvent.PurchaseFailed).Subscribe(PurchaseFailed);
// Update NoAds price display
UpdateNoAdsPriceDisplay();
}
private void OnDisable()
protected override void OnDisable()
{
base.OnDisable();
EventManager.GetEvent<string>(EGameEvent.PurchaseSucceeded).Unsubscribe(PurchaseSucceded);
}
@ -86,44 +86,6 @@ namespace WordsToolkit.Scripts.Popups
}
}
private void PurchaseFailed((string, string) info)
{
var productId = info.Item1;
var errorMessage = info.Item2;
var errorType = IAPErrorHelper.ParseError(errorMessage);
Debug.LogWarning($"Purchase failed for product {productId}: {errorMessage}, Error Type: {errorType}");
switch (errorType)
{
case IAPErrorType.InvalidProductID:
Debug.LogError($"Invalid product ID: {productId}");
ShowErrorMessage("Invalid product ID. Please try again later.");
break;
case IAPErrorType.UserCancelled:
Debug.LogWarning("Purchase cancelled by user.");
break;
case IAPErrorType.DuplicateTransaction:
Debug.LogWarning($"Duplicate transaction for product {productId}. This usually means the purchase was already completed.");
break;
case IAPErrorType.IAPInitFailed:
Debug.LogError("IAP initialization failed. Please check your IAP settings.");
ShowErrorMessage("IAP initialization failed. Please try again later.");
break;
default:
ShowErrorMessage($"Payment failed: {errorMessage}");
break;
}
}
private void ShowErrorMessage(string message)
{
var popup = menuManager.ShowPopup<MessagePopup>();
if (popup != null)
{
popup.SetMessage(message);
}
}
public void BuyCoins(string id)
{
// StopInteration();
@ -133,5 +95,17 @@ namespace WordsToolkit.Scripts.Popups
iapManager.BuyProduct(id);
#endif
}
private void UpdateNoAdsPriceDisplay()
{
if (noAdsPriceText != null && noAdsProduct != null)
{
var localizedPrice = iapManager.GetProductLocalizedPriceString(noAdsProduct.ID);
if (!string.IsNullOrEmpty(localizedPrice))
{
noAdsPriceText.text = localizedPrice;
}
}
}
}
}

View File

@ -10,6 +10,8 @@
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// // THE SOFTWARE.
using TMPro;
using UnityEngine;
using WordsToolkit.Scripts.Enums;
using WordsToolkit.Scripts.GUI;
using WordsToolkit.Scripts.GUI.Buttons;
@ -23,11 +25,16 @@ namespace WordsToolkit.Scripts.Popups
{
public CustomButton removeAdsButton;
public ProductID productID;
[SerializeField]
public TextMeshProUGUI priceText; // Add price display UI element
private void OnEnable()
{
removeAdsButton.onClick.AddListener(RemoveAds);
EventManager.GetEvent<string>(EGameEvent.PurchaseSucceeded).Subscribe(PurchaseSucceeded);
// Set localized price when popup opens
UpdatePriceDisplay();
}
protected override void OnDisable()
@ -49,5 +56,17 @@ namespace WordsToolkit.Scripts.Popups
{
iapManager.BuyProduct(productID.ID);
}
private void UpdatePriceDisplay()
{
if (priceText != null && productID != null)
{
var localizedPrice = iapManager.GetProductLocalizedPriceString(productID.ID);
if (!string.IsNullOrEmpty(localizedPrice))
{
priceText.text = localizedPrice;
}
}
}
}
}

View File

@ -18,6 +18,7 @@ using WordsToolkit.Scripts.GUI;
using WordsToolkit.Scripts.System;
using VContainer;
using WordsToolkit.Scripts.GUI.Buttons;
using WordsToolkit.Scripts.Services;
namespace WordsToolkit.Scripts.Popups
{
@ -26,6 +27,9 @@ namespace WordsToolkit.Scripts.Popups
[SerializeField]
private CustomButton privacypolicy;
[SerializeField]
private CustomButton googleUMPConsent;
[SerializeField]
private Button restorePurchase;
@ -38,6 +42,7 @@ namespace WordsToolkit.Scripts.Popups
protected virtual void OnEnable()
{
privacypolicy?.onClick.AddListener(PrivacyPolicy);
googleUMPConsent?.onClick.AddListener(ReconsiderGoogleUMPConsent);
LoadVibrationLevel();
vibrationSlider.onValueChanged.AddListener(SaveVibrationLevel);
closeButton.onClick.RemoveAllListeners();
@ -94,6 +99,14 @@ namespace WordsToolkit.Scripts.Popups
Close();
}
private void ReconsiderGoogleUMPConsent()
{
StopInteration();
DisablePause();
adsManager.ReconsiderUMPConsent();
Close();
}
private void DisablePause()
{
if (stateManager.CurrentState == EScreenStates.Game)