Project_WL/Assets/Script/UI/Kettle/Content_Exchange.cs

141 lines
5.0 KiB
C#
Raw Normal View History

2024-12-15 01:39:39 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Content_Exchange : MonoBehaviourSingletonTemplate<Content_Exchange>
{
public ArrowUI m_ArrowUI;
public KettleExchangeCard[] arr_Card; // 0 왼쪽, 1 오른쪽
int[] arr_id = new int[] { 0, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 201, 202, 203, 204, 205, 206, 207, 208 };
int LeftSelectIndex, RightSelectIndex;
int Get_LeftID() { return arr_id[LeftSelectIndex]; }
int Get_RightID() { return arr_id[RightSelectIndex]; }
private void OnEnable()
{
LeftSelectIndex = 0;
RightSelectIndex = 0;
Set();
}
public void Set()
{
var sdata = ServerInfo.Ins.m_ServerData;
if (Get_LeftID() == 0 && Get_RightID() == 0)
m_ArrowUI.Set(null, 0);
arr_Card[0].Set(Get_LeftID());
var leftAmount = sdata.Get_ItemAmount(eItem.Food, Get_LeftID());
m_ArrowUI.Set(totalcount => { Set_Amount(totalcount); }, (int)(leftAmount / 2));
arr_Card[1].Set(Get_RightID());
}
void Set_Amount(int totalCount)
{
arr_Card[0].Set_Amount(new Color32(0, 239, 255, 255), 2 * totalCount);
arr_Card[1].Set_Amount(new Color32(89, 255, 72, 255), totalCount);
}
public void OnClick_SelectCardArrow(GameObject _go)
{
switch (_go.name)
{
case "arrow_left_left":
--LeftSelectIndex;
if (LeftSelectIndex < 0)
{
LeftSelectIndex = arr_id.Length - 1;
RightSelectIndex = 0; // 채소에서 과일로 변해서 오른쪽 초기화
}
else if (LeftSelectIndex == 0 || LeftSelectIndex == 20)
RightSelectIndex = 0; // 과일에서 채소로 변해서 오른쪽 초기화
if (RightSelectIndex > 0 && LeftSelectIndex > 0 && RightSelectIndex == LeftSelectIndex)
RightSelectIndex = 0;
break;
case "arrow_left_right":
++LeftSelectIndex;
if (LeftSelectIndex >= arr_id.Length)
{
LeftSelectIndex = 0;
RightSelectIndex = 0; // 과일에서 채소로 변해서 오른쪽 초기화
}
else if (LeftSelectIndex == 21)
RightSelectIndex = 0; // 채소에서 과일로 변해서 오른쪽 초기화
if (RightSelectIndex > 0 && LeftSelectIndex > 0 && RightSelectIndex == LeftSelectIndex)
RightSelectIndex = 0;
break;
case "arrow_right_left":
Right_Left();
if (RightSelectIndex > 0 && LeftSelectIndex > 0 && RightSelectIndex == LeftSelectIndex)
Right_Left();
break;
case "arrow_right_right":
Right_Right();
if (RightSelectIndex > 0 && LeftSelectIndex > 0 && RightSelectIndex == LeftSelectIndex)
Right_Right();
break;
}
Set();
arr_Card[1].Set_Amount(new Color32(89, 255, 72, 255), m_ArrowUI.Get_TotalCount());
}
void Right_Left()
{
if (Get_LeftID() > 0)
{
--RightSelectIndex;
if (Get_LeftID() < 201)
{ // 채소
if (RightSelectIndex < 0)
RightSelectIndex = 20;
}
else if (Get_LeftID() > 200)
{ // 과일
if (RightSelectIndex == 20)
RightSelectIndex = 0;
else if (RightSelectIndex < 0)
RightSelectIndex = 28;
}
}
}
void Right_Right()
{
if (Get_LeftID() > 0)
{
++RightSelectIndex;
if (Get_LeftID() < 201)
{ // 채소
if (RightSelectIndex > 20)
RightSelectIndex = 0;
}
else if (Get_LeftID() > 200)
{ // 과일
if (RightSelectIndex >= arr_id.Length)
RightSelectIndex = 0;
else if (RightSelectIndex > 0 && RightSelectIndex < 21)
RightSelectIndex = 21;
}
}
}
public void OnClick_Exchange()
{
if (Get_LeftID() == 0)
ToastUI.Ins.Set(168);
else if (Get_RightID() == 0)
ToastUI.Ins.Set(169);
else if (m_ArrowUI.Get_TotalCount() > 0)
{
var sdata = ServerInfo.Ins.m_ServerData;
sdata.Use_Item(eItem.Food, m_ArrowUI.Get_TotalCount() * 2, Get_LeftID(), "exchange");
var items = sdata.Add_Item(new ItemData(eItem.Food, Get_RightID(), m_ArrowUI.Get_TotalCount(), "exchange", eUICardType.GetItem));
GetItemUI.Ins.Set(items);
GetItemUI.Ins.Show_Items();
Set();
GameUI.Ins.LobbyUI.Get_MenuKettle().Show_CombineEffect();
}
}
}