//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, January 28, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using vnxbqy.UI;
|
|
public class MergeServerTurntableWin : ILWindow
|
{
|
Text usedMoney;
|
Text m_OpenTime;
|
Button goButton;
|
Transform itemObjects;
|
List<ItemCell> itemCells = new List<ItemCell>();
|
List<Image> emptyImages = new List<Image>();
|
List<Image> runImages = new List<Image>(); //跑圈图显示
|
List<Image> hitImages = new List<Image>(); //已抽中的显示
|
List<UIEffect> uiEffectJPs = new List<UIEffect>();
|
List<UIEffect> uiEffectZJs = new List<UIEffect>();
|
Button startButton;
|
Button selectButton;
|
Text count;
|
ScaleTween startButtonTween;
|
Image usedMoneyType;
|
|
Image imageLogin;
|
Image imageCTG;
|
Image imageUse;
|
|
MergeServerTurntableModel model = MergeServerTurntableModel.Instance;
|
|
|
#region Built-in
|
protected override void BindController()
|
{
|
usedMoney = proxy.GetWidgtEx<Text>("useText");
|
m_OpenTime = proxy.GetWidgtEx<Text>("Txt_CoolDown");
|
goButton = proxy.GetWidgtEx<Button>("goButton");
|
itemObjects = proxy.GetWidgtEx<Transform>("itemGameObjects");
|
for (int i = 0; i < MergeServerTurntableModel.itemCount; i++)
|
{
|
itemCells.Add(itemObjects.transform.Find("itemcell" + i +"/itemcell").GetComponent<ItemCell>());
|
emptyImages.Add(itemObjects.transform.Find("itemcell" + i + "/ImageEmpty").GetComponent<Image>());
|
hitImages.Add(itemObjects.transform.Find("itemcell" + i + "/ImageHit").GetComponent<Image>());
|
uiEffectJPs.Add(itemObjects.transform.Find("itemcell" + i + "/uieffectJP").GetComponent<UIEffect>());
|
uiEffectZJs.Add(itemObjects.transform.Find("itemcell" + i + "/uieffectZJ").GetComponent<UIEffect>());
|
runImages.Add(itemObjects.transform.Find("itemcell" + i + "/ImageRun").GetComponent<Image>());
|
}
|
startButton = proxy.GetWidgtEx<Button>("StartButton");
|
selectButton = proxy.GetWidgtEx<Button>("SelectButton");
|
count = proxy.GetWidgtEx<Text>("count");
|
startButtonTween = proxy.GetWidgtEx<ScaleTween>("StartButtonTween");
|
usedMoneyType = proxy.GetWidgtEx<Image>("usedMoneyType");
|
|
for (int i = 0; i < MergeServerTurntableModel.itemCount; i++)
|
{
|
uiEffectJPs[i].effect = 3057;
|
uiEffectJPs[i].loop = true;
|
uiEffectJPs[i].renderQueue = 2500;
|
uiEffectZJs[i].effect = 3055;
|
uiEffectZJs[i].loop = true;
|
uiEffectZJs[i].renderQueue = 2500;
|
}
|
|
imageLogin = proxy.GetWidgtEx<Image>("Imagelogin");
|
imageCTG = proxy.GetWidgtEx<Image>("Imagectg");
|
imageUse = proxy.GetWidgtEx<Image>("Imageuse");
|
}
|
|
protected override void AddListeners()
|
{
|
goButton.SetListener(()=> {
|
//WindowCenter.Instance.OpenEx<VipRechargeWin>(false, 0);
|
WindowJumpMgr.Instance.WindowJumpToEx("VipRechargeWin");
|
});
|
|
startButton.SetListener(StartTurntable);
|
selectButton.SetListener(()=> {
|
WindowJumpMgr.Instance.WindowJumpToEx("MergeServerTurntableSelectItemWin");
|
});
|
}
|
|
protected override void OnPreOpen()
|
{
|
ItemLogicUtility.Instance.hidePickItem = true;
|
model.OnOperationTimeUpdateEvent += operationTimeUpdateEvent;
|
model.PlayerTurntableEvent += OnPlayerTurntableEvent;
|
WindowCenter.Instance.windowAfterCloseEvent += WindowAfterCloseEvent;
|
model.runIndex = model.GetRunStartIndex();
|
model.runState = 0;
|
runList.Clear();
|
|
}
|
protected override void OnAfterOpen()
|
{
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
ItemLogicUtility.Instance.hidePickItem = false;
|
model.OnOperationTimeUpdateEvent -= operationTimeUpdateEvent;
|
model.PlayerTurntableEvent -= OnPlayerTurntableEvent;
|
WindowCenter.Instance.windowAfterCloseEvent -= WindowAfterCloseEvent;
|
}
|
|
|
List<int> runList = new List<int>(); //未抽中的格子
|
float runTime = 0; //格子停留的起始时间
|
float curSpeed = 0;
|
float lowSpeed = 0.4f; //最慢速度
|
float fastSpeed = 0.1f; //最快速度
|
float changeSpeed = 0.1f; //变化量
|
int circleMaxCnt = 2; //最少转几圈
|
int curCircle = 0; //当前圈
|
int hitIndex = -1; //当前命中的物品
|
|
protected override void LateUpdate()
|
{
|
if (model.runState == 0 || model.runIndex == -1)
|
return;
|
|
if (Time.time - runTime < curSpeed)
|
{
|
return;
|
}
|
runTime = Time.time;
|
if (model.runState == 1)
|
{
|
curSpeed = Math.Max(curSpeed - changeSpeed, fastSpeed);
|
}
|
else if (model.runState == 2)
|
{
|
curSpeed = Math.Min(curSpeed + changeSpeed, lowSpeed);
|
}
|
|
int index = runList.IndexOf(model.runIndex);
|
index++;
|
if (index == runList.Count)
|
{
|
index = 0;
|
curCircle++;
|
if (curCircle >= circleMaxCnt) model.runState = 2;
|
}
|
model.runIndex = runList[index];
|
|
for (int i = 0; i < MergeServerTurntableModel.itemCount; i++)
|
{
|
runImages[i].SetActiveIL(model.runIndex == i);
|
}
|
|
SoundPlayer.Instance.PlayUIAudio(66);
|
if (model.runState == 2 && hitIndex != -1 && hitIndex == model.runIndex)
|
{
|
model.runState = 0;
|
//打开奖励界面
|
WindowCenter.Instance.OpenIL<MergeServerTurntableResultWin>();
|
}
|
}
|
#endregion
|
|
void Display()
|
{
|
ShowItemObjects();
|
DisplayPlayerInfo();
|
DisplayOpenTime();
|
}
|
|
void WindowAfterCloseEvent(Window window)
|
{
|
if (window.name == "MergeServerTurntableResultWin")
|
{
|
Display();
|
}
|
}
|
|
void DisplayPlayerInfo()
|
{
|
int remind = GetNeedUseMoney();
|
usedMoney.text = remind.ToString();
|
count.text = Language.Get("HFTurntable_2", model.turntableCount);
|
imageCTG.SetActiveIL(model.ctgTotal > 0);
|
imageUse.SetActiveIL(remind == 0);
|
ShowTurntableBtn();
|
}
|
|
int GetNeedUseMoney()
|
{
|
OperationBase operationBase = null;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(model.operationType, out operationBase))
|
{
|
OperationTurntable operation = operationBase as OperationTurntable;
|
for (int i = 0; i < operation.useMoneyPrizeList.Count; i++)
|
{
|
if (model.useMoneyTotal < operation.useMoneyPrizeList[i])
|
{
|
return (int)operation.useMoneyPrizeList[i] - model.useMoneyTotal;
|
}
|
}
|
|
}
|
return 0;
|
}
|
|
void DisplayOpenTime()
|
{
|
OperationBase operationBase = null;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(model.operationType, out operationBase))
|
{
|
OperationTurntable operation = operationBase as OperationTurntable;
|
m_OpenTime.text = StringUtility.Contact(Language.Get("ExpActivity_Text1"), operation.ToDisplayTime());
|
|
}
|
}
|
|
private void operationTimeUpdateEvent()
|
{
|
Display();
|
}
|
|
void OnPlayerTurntableEvent()
|
{
|
if (model.runState != 0)
|
{
|
hitIndex = model.GetHitIndex();
|
}
|
DisplayPlayerInfo();
|
}
|
|
|
|
//转盘物品显示处理
|
void ShowItemObjects()
|
{
|
OperationBase operationBase = null;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(model.operationType, out operationBase))
|
{
|
return;
|
}
|
OperationTurntable operation = operationBase as OperationTurntable;
|
|
usedMoneyType.SetSprite("Money_Type_" + operation.useMoneyType);
|
|
for (int i = 0; i < MergeServerTurntableModel.itemCount; i++)
|
{
|
if (model.itemSort[i] >= 0)
|
{
|
itemCells[i].SetActiveIL(true);
|
emptyImages[i].SetActiveIL(false);
|
|
var itemInfo = operation.turnItemList[model.itemSort[i]];
|
var itemModel = new ItemCellModel((int)itemInfo.ItemID, false, itemInfo.ItemCount);
|
itemCells[i].Init(itemModel);
|
itemCells[i].button.SetListener(() => {
|
ItemTipUtility.Show((int)itemInfo.ItemID);
|
});
|
hitImages[i].SetActiveIL(model.IsHitItemState(itemInfo.ItemNum));
|
}
|
else
|
{
|
itemCells[i].SetActiveIL(false);
|
emptyImages[i].SetActiveIL(true);
|
hitImages[i].SetActiveIL(false);
|
}
|
runImages[i].SetActiveIL(model.runIndex == i);
|
if (Array.IndexOf(model.jpPosition, i) != -1)
|
{
|
uiEffectJPs[i].SetActiveIL(true);
|
uiEffectJPs[i].Play();
|
}
|
else
|
{
|
uiEffectJPs[i].SetActiveIL(false);
|
uiEffectJPs[i].Stop();
|
}
|
if (Array.IndexOf(model.zjPosition, i) != -1)
|
{
|
uiEffectZJs[i].SetActiveIL(true);
|
uiEffectZJs[i].Play();
|
}
|
else
|
{
|
uiEffectZJs[i].SetActiveIL(false);
|
uiEffectZJs[i].Stop();
|
}
|
}
|
}
|
|
void ShowTurntableBtn()
|
{
|
startButtonTween.SetStartState();
|
if (model.itemSort.Contains(-2))
|
{
|
startButton.SetActiveIL(false);
|
selectButton.SetActiveIL(true);
|
startButtonTween.Stop();
|
}
|
else
|
{
|
startButton.SetActiveIL(true);
|
selectButton.SetActiveIL(false);
|
startButtonTween.Stop();
|
if (model.turntableCount > 0 && model.runState == 0)
|
{
|
//if (startButtonTween.gameObject.activeSelf)
|
startButtonTween.Play();
|
}
|
}
|
|
}
|
|
|
void StartTurntable()
|
{
|
if (model.itemSort.Contains(-2))
|
{
|
//未选择不能开始
|
return;
|
}
|
if (model.runState != 0 || model.runIndex == -1)
|
{
|
return;
|
}
|
|
if (model.turntableCount == 0)
|
{
|
return;
|
}
|
|
OperationBase operationBase = null;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(model.operationType, out operationBase))
|
{
|
return;
|
}
|
OperationTurntable operation = operationBase as OperationTurntable;
|
|
var pack = new IL_CAA13_tagCMActTurntableStart();
|
pack.ActNum = (byte)operation.ActNum;
|
GameNetSystem.Instance.SendInfo(pack);
|
|
|
runList.Clear();
|
for (int i = 0; i < MergeServerTurntableModel.itemCount; i++)
|
{
|
if (model.IsHitItemState(operation.turnItemList[model.itemSort[i]].ItemNum))
|
continue;
|
|
runList.Add(i);
|
}
|
if (runList.Count > 0)
|
{
|
model.runIndex = runList[0];
|
for (int i = 0; i < MergeServerTurntableModel.itemCount; i++)
|
{
|
|
runImages[i].SetActiveIL(model.runIndex == i);
|
}
|
}
|
model.runState = 1;
|
curCircle = 0;
|
runTime = Time.time;
|
curSpeed = lowSpeed;
|
SoundPlayer.Instance.PlayUIAudio(66);
|
}
|
}
|