FM/Assets/Scripts/Runtime/UI/Logic/ProductUI.cs

286 lines
9.5 KiB
C#

using System.Collections.Generic;
using Data;
using Runtime;
using UnityEngine.UI;
using TMPro;
using UnityEngine;
using ZGame;
namespace HK
{
public class ProductUI : UIBase
{
[SerializeField] private Button btnStepDesign;
[SerializeField] private Button btnStepText;
[SerializeField] private Button btnStepLayout;
[SerializeField] private RawImage rawShow;
[SerializeField] private UpMenuItem goUpMenu;
[SerializeField] private Product1ColorItem Product1Color;
[SerializeField] private Product2StickerItem Product2Sticker;
[SerializeField] private Product3TextItem Product3Text;
[SerializeField] private Product4LineItem Product4Line;
[SerializeField] private Product5ConfirmItem Product5Confirm;
[SerializeField] private DesignCoverItem designCoverItem;
GameObject model;
Book_M book;
NotebookModelBar notebook;
private int index;
public override void OnInit()
{
base.OnInit();
#region AutoGen_Init
btnStepDesign = GetValue<Button>("btnStepDesign");
btnStepText = GetValue<Button>("btnStepText");
btnStepLayout = GetValue<Button>("btnStepLayout");
rawShow = GetValue<RawImage>("rawShow");
goUpMenu = GetValue<UpMenuItem>("goUpMenu");
Product1Color = GetValue<Product1ColorItem>("Product1Color");
Product2Sticker = GetValue<Product2StickerItem>("Product2Sticker");
Product3Text = GetValue<Product3TextItem>("Product3Text");
Product4Line = GetValue<Product4LineItem>("Product4Line");
Product5Confirm = GetValue<Product5ConfirmItem>("Product5Confirm");
designCoverItem = GetValue<DesignCoverItem>("DesignCover");
btnStepDesign.onClick.AddListener(OnValueChangedtogStepDesign);
btnStepText.onClick.AddListener(OnValueChangedtogStepText);
btnStepLayout.onClick.AddListener(OnValueChangedtogStepLayout);
#endregion
goUpMenu.OnClickReturn += ClickReturn;
Product1Color.ClickAction += ClickNext;
Product2Sticker.ClickAction += ClickNext;
Product3Text.ClickAction += ClickNext;
Product4Line.ClickAction += ClickNext;
Product5Confirm.ClickAction += ClickDesignFinish;
}
private void ClickDesignFinish()
{
var index = PlayerPersistent.GetInt("ProductIndex");
var informationData = ExcelManager.NoteBookInformation.GetData(index);
List<byte[]> bytes = notebook.GenPreviewImage();
var cartData = new ShoppingCartData()
{
bookAmount = informationData.BookPrice + informationData.DesignPrice,
bookName = informationData.BookEnglishName,
bookDiscount = informationData.DiscountPrice,
count = 1,
previewImage = bytes[0],
designImage = bytes[1]
};
ShoppingCartManager.Instance.AddToCart(cartData);
UIManager.Instance.ShowUIOnly(nameof(ShoppingCartUI));
}
public override void OnOpen()
{
base.OnOpen();
goUpMenu.OnShow();
HideAll();
model = ResourcesManager.Instance.LoadGameObject(AssetConst.Assets_Res_Prefab_ModelMeshesVariant_prefab);
book = model.transform.GetComponentInChildren<Book_M>();
notebook = model.transform.GetComponentInChildren<NotebookModelBar>();
Product1Color.SetBook(book);
Product2Sticker.SetBook(book);
Product3Text.SetBook(book);
Product4Line.SetBook(book);
Product5Confirm.SetBook(book);
Product1Color.OnShow();
designCoverItem.OnShow();
index = 1;
EventManager.Instance.FireNow(this, new ProductIsShowDesignCoverEventArgs(true));
}
public override void OnClose()
{
base.OnClose();
GameObject.Destroy(model);
}
void ClickNext()
{
HideAll();
index++;
ChangeStepsIndex(index - 1);
notebook.PlayIndex(index - 1);
IsShowDesign(index);
switch (index)
{
case 1:
Product1Color.OnShow();
break;
case 2:
Product2Sticker.OnShow();
break;
case 3:
Product3Text.OnShow();
break;
case 4:
Product4Line.OnShow();
break;
case 5:
Product5Confirm.OnShow();
break;
}
}
private void ClickReturn()
{
HideAll();
index--;
ChangeStepsIndex(index - 1);
notebook.PlayIndex(index - 1);
IsShowDesign(index);
switch (index)
{
case 0:
UIManager.Instance.BackLast();
break;
case 1:
Product1Color.OnShow();
break;
case 2:
Product2Sticker.OnShow();
break;
case 3:
Product3Text.OnShow();
break;
case 4:
Product4Line.OnShow();
break;
case 5:
Product5Confirm.OnShow();
break;
}
}
void HideAll()
{
Product1Color.OnHide();
Product2Sticker.OnHide();
Product3Text.OnHide();
Product4Line.OnHide();
Product5Confirm.OnHide();
}
void IsShowDesign(int index)
{
// Debug.Log(index);
// if (index < 4)
// {
// EventManager.Instance.FireNow(this, new ProductIsShowDesignCoverEventArgs(true));
// }
// else
// {
// EventManager.Instance.FireNow(this, new ProductIsShowDesignCoverEventArgs(false));
// }
}
void ChangeStepsIndex(int inde)
{
int num = 1;
if (inde == 0)
{
btnStepDesign.transform.GetChild(num).gameObject.SetActive(false);
btnStepText.transform.GetChild(num).gameObject.SetActive(false);
btnStepLayout.transform.GetChild(num).gameObject.SetActive(false);
}
else if (inde == 1)
{
btnStepDesign.transform.GetChild(num).gameObject.SetActive(true);
btnStepText.transform.GetChild(num).gameObject.SetActive(false);
btnStepLayout.transform.GetChild(num).gameObject.SetActive(false);
}
else if (inde == 2)
{
btnStepDesign.transform.GetChild(num).gameObject.SetActive(true);
btnStepText.transform.GetChild(num).gameObject.SetActive(true);
btnStepLayout.transform.GetChild(num).gameObject.SetActive(false);
}
else if (inde == 3)
{
btnStepDesign.transform.GetChild(num).gameObject.SetActive(true);
btnStepText.transform.GetChild(num).gameObject.SetActive(true);
btnStepLayout.transform.GetChild(num).gameObject.SetActive(true);
}
}
#region AutoGen_Method
private void OnValueChangedtogStepDesign()
{
index = 2;
ChangeStepsIndex(1);
IsShowDesign(index);
notebook.PlayIndex(1);
HideAll();
Product2Sticker.OnShow();
}
private void OnValueChangedtogStepText()
{
index = 3;
ChangeStepsIndex(2);
IsShowDesign(index);
notebook.PlayIndex(2);
HideAll();
Product3Text.OnShow();
}
private void OnValueChangedtogStepLayout()
{
index = 4;
ChangeStepsIndex(3);
IsShowDesign(index);
notebook.PlayIndex(3);
HideAll();
Product4Line.OnShow();
}
#endregion
public override void OnDispose()
{
base.OnDispose();
goUpMenu.OnClickReturn -= ClickReturn;
Product1Color.ClickAction -= ClickNext;
Product2Sticker.ClickAction -= ClickNext;
Product3Text.ClickAction -= ClickNext;
Product4Line.ClickAction -= ClickNext;
Product5Confirm.ClickAction -= ClickDesignFinish;
Product1Color.OnDispose();
Product2Sticker.OnDispose();
Product3Text.OnDispose();
Product4Line.OnDispose();
Product5Confirm.OnDispose();
designCoverItem.OnDispose();
#region AutoGen_Dispose
btnStepDesign.onClick.RemoveListener(OnValueChangedtogStepDesign);
btnStepText.onClick.RemoveListener(OnValueChangedtogStepText);
btnStepLayout.onClick.RemoveListener(OnValueChangedtogStepLayout);
btnStepDesign = null;
btnStepText = null;
btnStepLayout = null;
rawShow = null;
goUpMenu = null;
Product1Color = null;
Product2Sticker = null;
Product3Text = null;
Product4Line = null;
Product5Confirm = null;
#endregion
}
}
}