using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuestGameLigature : ASteinUIBase
{
ContainerWidget mPlan;
Transform mLinePlan;
GameObject mCloseBtn;
public Transform[] tr;
Dictionary<int, Vector3> data = new Dictionary<int, Vector3>();
int gameid;
bool fromOrgan;
OrganGame organGame;
bool alwaysSucc;
GameObject reset;
UISprite mSetP;
GameObject m_Line;
GameObject mGuideArrow;
GameObject meffer;
GameObject mbox;
CausualGameInfo resp;
SteinTimer mTimer;
private UILabel countDownLbl;
Dictionary<int, List<int>> mOriLinkDic = new Dictionary<int, List<int>>(); //存储原始的连线信息
Dictionary<int, List<int>> mLinkDic = new Dictionary<int, List<int>>(); //当前剩余的连线信息
int mCurSelectNodeId; //当前选中点
bool mHasGuide = false; //是否有提示
public override void OnStart (object param = null)
{
mHasGuide = false;
//if (PlayerGuideManager.GetInstance().GuideIsOpen(XBModuleDefine.DefinePlayerGuide.Ligature, 1))
{
mHasGuide = true;
// PlayerGuideManager.GetInstance().RemovePlayerGuideByIndex(XBModuleDefine.DefinePlayerGuide.Ligature);
}
CommonTools.ShowOrHideUI(false);
resp = param as CausualGameInfo;
alwaysSucc = resp.mDetail.timeoutMeansSuccess;
gameid = resp.mDetail.id;
fromOrgan = resp.mDetail.fromOrgan;
organGame = resp.mOrgan;
mSetP.spriteName = resp.mDetail.oneStrokeItem.bgImageId;
mSetP.MakePixelPerfect();
for (int i = 0; i < resp.mDetail.oneStrokeItem.nodeList.Count; i++)
{
data.Add(resp.mDetail.oneStrokeItem.nodeList[i].id, new Vector3(resp.mDetail.oneStrokeItem.nodeList[i].x, resp.mDetail.oneStrokeItem.nodeList[i].y, 0));
}
SetCollEct();
countDownLbl.text = "";
//if (mTimer == null && resp.mDetail.countdown > 0)
//{
// mTimer = SteinTimer.GenerateCountDownTimer();
// mTimer.OnSteinTimerEvent += HandleOnSteinTimerEvent;
// mTimer.StartTimer(resp.mDetail.countdown);
//}
}
private void HandleOnSteinTimerEvent (SteinTimerEvent eventType, float[] paramArray)
{
if (eventType == SteinTimerEvent.TimeInterval)
{
countDownLbl.text = string.Format(ManualLangCommon.GetString(392), (int)paramArray[0]);
}
else if (eventType == SteinTimerEvent.TimeUp)
{
alwaysSucc = false;
QuestGameOverStr str = new QuestGameOverStr();
str.questId = gameid;
str.fromOrgan = fromOrgan;
str.organGame = organGame;
str.titleInfo = ManualLangCommon.GetString(alwaysSucc ? 68000 : 68001);
str.finishState = alwaysSucc ? 1 : 0;
if (alwaysSucc)
{
str.tipsInfo = ManualLangCommon.GetString(68007);
}
else
{
str.tipsInfo = ManualLangCommon.GetString(str.finishState == 1 ? 68002 : 68003);
}
Module.OpenUI(XBModuleDefine.DefineQuestSmallGames.UI_GameOver, str);
}
}
public override void OnOpenBegin ()
{
}
public override void OnPostWidgetAssemble (WidgetBase widget)
{
base.OnPostWidgetAssemble(widget);
switch (widget.widgetGo.name)
{
case "OufitGrid":
mPlan = widget as ContainerWidget;
GameLigatureItem pItem = SteinGeneralUtils.EnsureComponent<GameLigatureItem>(Module.LoadGameObject("GameLigatureItem"));
mPlan.SetPrefab(pItem);
break;
case "LineGrid":
mLinePlan = widget.widgetGo.transform;
break;
case "Close":
mCloseBtn = widget.widgetGo;
UIEventListener.Get(widget.widgetGo).onClick = OnClickClose;
break;
case "SetP":
mSetP = widget.widgetGo.GetComponent<UISprite>();
break;
case "Line":
m_Line = widget.widgetGo;
break;
case "countDownLbl":
countDownLbl = widget.widgetGo.GetComponent<UILabel>();
break;
case "Reset":
UIEventListener.Get(widget.widgetGo).onClick = Resetone;
break;
case "GuideArrow":
mGuideArrow = widget.widgetGo;
mGuideArrow.SetActive(false);
break;
case "guideOffset":
widget.widgetGo.transform.localPosition = new Vector3(-340, 85, 0);
break;
case "effer":
meffer = widget.widgetGo;
break;
case "box":
mbox = widget.widgetGo;
break;
}
}
private void OnClickClose (GameObject go)
{
SelfClose();
}
void SetCollEct ()
{
mPlan.container.Clear();
mPlan.SetContents(resp.mDetail.oneStrokeItem.nodeList.ToArray());
mPlan.container.Reposition();
SetData();
for (int i = 0; i < resp.mDetail.oneStrokeItem.nodeList.Count; i++)
{
GameLigatureItem item = mPlan.container.GetItem(i) as GameLigatureItem;
item.gameObject.transform.localPosition = new Vector3(resp.mDetail.oneStrokeItem.nodeList[i].x, resp.mDetail.oneStrokeItem.nodeList[i].y, 0);
}
foreach (int key in mOriLinkDic.Keys)
{
List<int> neighbors = mOriLinkDic[key];
foreach (int neighbor in neighbors)
{
if (neighbor > key)
{
GameObject line = Instantiate(m_Line, mLinePlan);
SetSegment(data[key], data[neighbor], line, Color.black, false);
}
}
}
}
public ParticleEffectProxy mLightEffect;
public void SetOverEffer (string tx, GameObject effer)
{
if (mLightEffect != null)
{
mLightEffect.Terminate();
mLightEffect = null;
}
if (mLightEffect == null)
mLightEffect = new ParticleEffectProxy(effer);
mLightEffect.SetAttachToPanel(true);
mLightEffect.SetScale(1.0f);
mLightEffect.Play(tx);
}
public override void OnCloseComplete ()
{
base.OnCloseComplete();
CommonTools.ShowOrHideUI(true);
//mTimer.OnSteinTimerEvent -= HandleOnSteinTimerEvent;
}
public override bool FullScreen
{
get
{
return true;
}
}
private void Resetone (GameObject obj)
{
if (mCurSelectNodeId == -1)
{
AlertHelper.Text(ManualLangCommon.GetString(99109));
return;
}
mCurSelectNodeId = -1;
BroadcastMessage("DestoryMe");
for (int i = 0; i < resp.mDetail.oneStrokeItem.nodeList.Count; i++)
{
GameLigatureItem item = mPlan.container.GetItem(i) as GameLigatureItem;
item.m_non.gameObject.SetActive(false);
item.SetEffer("26010");
}
SetData();
AlertHelper.Text(ManualLangCommon.GetString(99120));
}
void SetData ()
{
mCurSelectNodeId = -1;
mOriLinkDic.Clear();
mLinkDic.Clear();
for (int i = 0; i < resp.mDetail.oneStrokeItem.nodeList.Count; i++)
{
mOriLinkDic.Add(resp.mDetail.oneStrokeItem.nodeList[i].id, new List<int>(resp.mDetail.oneStrokeItem.nodeList[i].neighbor));
mLinkDic.Add(resp.mDetail.oneStrokeItem.nodeList[i].id, new List<int>(resp.mDetail.oneStrokeItem.nodeList[i].neighbor));
}
CheckGuide();
}
//List<List<Vector3>> n = new List<List<Vector3>>();
public bool RturnV3 (int id)
{
//go.GetComponent<UISprite>().color = Color.black;
if (mCurSelectNodeId == -1) //第一步
{
mCurSelectNodeId = id;
CheckGuide();
return true;
}
if (mCurSelectNodeId == id) //如果是同一个点
return false;
if (!mLinkDic.ContainsKey(mCurSelectNodeId)) //不包含在剩余连线信息里面,理论上不存在
return false;
if (!mLinkDic[mCurSelectNodeId].Contains(id)) //是否在剩余连线里面
{
if (mOriLinkDic[mCurSelectNodeId].Contains(id)) //是否是之前连过的线
{
AlertHelper.Text(ManualLangCommon.GetString(99116));
}
return false;
}
GameObject line = Instantiate(m_Line, mLinePlan);
SetSegment(data[mCurSelectNodeId], data[id], line, Color.white, true);
mLinkDic[mCurSelectNodeId].Remove(id);
mLinkDic[id].Remove(mCurSelectNodeId);
mCurSelectNodeId = id;
OnFinished();
CheckGuide();
return true;
}
void SetSegment (Vector3 beginPos, Vector3 currentPos, GameObject obj, Color col, bool addson)
{
//Vector3 angle;
Vector3 angleVec = beginPos - currentPos;
obj.AddComponent<BoxCollider>();
float angle1 = Vector3.Angle(Vector3.down, angleVec);
Vector3 crossAngle = Vector3.Cross(Vector3.down, angleVec);
if (crossAngle.z < 0)
angle1 = -angle1;
UISprite m_xian = obj.GetComponent<UISprite>();
m_xian.transform.localPosition = new Vector3((beginPos.x + currentPos.x) / 2, (beginPos.y + currentPos.y) / 2, 0);
m_xian.color = col;
m_xian.alpha = 0.5f;
m_xian.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, angle1));
m_xian.GetComponent<UISprite>().height = Mathf.CeilToInt(angleVec.magnitude);
m_xian.GetComponent<UISprite>().pivot = UIWidget.Pivot.Center;
m_xian.transform.localScale = Vector3.one;
obj.GetComponent<BoxCollider>().size = new Vector3(10, m_xian.localSize.y, 1);
if (addson == true)
{
obj.AddComponent<Son>();
m_xian.width = 25;
Transform effects = obj.transform.Find("tx");
effects.localPosition = angle1 > 0 ? new Vector3(0, effects.localPosition.y + m_xian.localSize.y / 2, 0) : new Vector3(0, effects.localPosition.y - m_xian.localSize.y / 2, 0);
float angle1s = Vector3.Angle(beginPos, currentPos);
effects.localRotation = angle1 > 0 ? Quaternion.Euler(new Vector3(0, 0, -90)): Quaternion.Euler(new Vector3(0, 0, 90));
ParticleEffectProxy mLightEffect = new ParticleEffectProxy(effects.gameObject);
mLightEffect.SetAttachToPanel(true);
mLightEffect.SetScale(m_xian.localSize.y / 200.0f);
mLightEffect.Play("26009");
}
UIEventListener.Get(obj).onPress = (o, k) =>
{
if (obj.GetComponent<Son>() != null)
{
if (k)
{
m_xian.color = Color.red;
return;
}
m_xian.color = Color.white;
AlertHelper.Text(ManualLangCommon.GetString(99119));
}
};
}
void OnFinished ()
{
bool bOver = true;
foreach (List<int> leftNode in mLinkDic.Values) //判断是否还有连线信息
{
if (leftNode.Count > 0)
{
bOver = false;
break;
}
}
if (bOver)
{
Son[] son = mPlan.container.transform.gameObject.GetComponentsInChildren<Son>();
for (int i = 0; i < son.Length; i++)
{
//son[i].GetComponent<UISprite>().color =new Color (0,1,1);
son[i].GetComponent<UISprite>().alpha = 1;
}
if (resp.mDetail.endEffect != null)
{
SetOverEffer(resp.mDetail.endEffect, meffer);
}
if (resp.mDetail.closeEndUI)
{
SetOverEffer("26011", meffer);
mbox.SetActive(false);
StartCoroutine(TimeAnim());
}
else
{
SetOverEffer("26011", meffer);
StartCoroutine(TimeAnim1());
}
}
}
void CheckGuide ()
{
mGuideArrow.SetActive(false);
if (RoleCharacter.GetInstance().RolePlayer.Level >= 35)
return;
if (mHasGuide)
{
int startID = mCurSelectNodeId;
if (startID == -1)
{
startID = 1;
}
if (startID != -1)
{
if (mLinkDic.ContainsKey(startID) && mLinkDic[startID].Count > 0)
{
mGuideArrow.SetActive(true);
mGuideArrow.transform.localPosition = data[mLinkDic[startID][mLinkDic[startID].Count - 1]];
TweenPosition pTwen = TweenPosition.Begin(mGuideArrow, 0.3f, data[mLinkDic[startID][mLinkDic[startID].Count - 1]] - Vector3.up * 10);
pTwen.style = TweenPosition.Style.PingPong;
}
}
}
}
IEnumerator TimeAnim ()
{
yield return new WaitForSeconds(1.8f);
mSetP.transform.parent.GetComponent<TweenAlpha>().enabled = true;
yield return new WaitForSeconds(1.2f);
}
public class GameLigatureItem : ASUIItemBase
{
GameObject m_act;
public UISprite m_non;
GameObject m_nature;
public UISprite m_xian;
public GameObject mEffer;
public override void OnPostWidgetAssemble (WidgetBase widget)
{
base.OnPostWidgetAssemble(widget);
switch (widget.widgetGo.name)
{
case "act":
m_act = widget.widgetGo;
UIEventListener.Get(m_act).onClick = ClickItem;
break;
case "non":
m_non = widget.widgetGo.GetComponent<UISprite>();
break;
case "Effer":
mEffer = widget.widgetGo;
mEffer.SetActive(false);
break;
}
}
ParticleEffectProxy mLightEffect;
ProtoCasualGames.CasualGamesOneStrokeNodeItem mNodeInfo;
public override void SetContentImpl (object content)
{
mNodeInfo = (content as ProtoCasualGames.CasualGamesOneStrokeNodeItem);
}
public void SetEffer (string tx)
{
if (mLightEffect != null)
{
mLightEffect.Terminate();
mLightEffect = null;
}
if (mLightEffect == null)
mLightEffect = new ParticleEffectProxy(m_act.gameObject);
mLightEffect.SetAttachToPanel(true);
mLightEffect.SetScale(1.0f);
mLightEffect.Play(tx);
}
public void ClickItem (GameObject go)
{
if (SteinModuleManager.GetInstance().IsOpen(XBModuleDefine.DefineQuestSmallGames.MODULE_ID, XBModuleDefine.DefineQuestSmallGames.UI_QuestOneLine))
{
QuestGameLigature main = SteinModuleManager.GetInstance().GetOpennedUi(XBModuleDefine.DefineQuestSmallGames.MODULE_ID, XBModuleDefine.DefineQuestSmallGames.UI_QuestOneLine) as QuestGameLigature;
if (main.RturnV3(mNodeInfo.id))
{
m_non.gameObject.SetActive(true);
SetEffer("26008");
}
else
{
AlertHelper.Text(ManualLangCommon.GetString(99122));
}
}
}
}
public class Son : MonoBehaviour
{
// 作为被广播通知的方法,由父物体通知执行
public void DestoryMe ()
{
Destroy(gameObject);
}
}
转载自原文链接, 如需删除请联系管理员。
原文链接:一款连线小游戏,转载请注明来源!