| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566 | using System;using System.Collections.Generic;using ET;using FairyGUI;using UI.MiniGame;using UnityEngine;namespace GFGGame{    public class MergeGameView : BaseWindow    {        private UI_MergeGameUI _ui;        private List<List<GComponent>> itemList = new List<List<GComponent>>();        private List<List<int>> idList = new List<List<int>>();        private int itemNum;        private int maxLv;        private System.Random rand;        private int _gameID;        private int _res;        //当前拖拽的index;        private int indexID;        //开始拖拽的坐标        private float startX;        private float startY;        private int indexX;        private int indexY;        //当前任务id;后台获取数据        private int taskId;        //当前点击id信息        private int materialID;        private int propID = 3000020;        public override void Dispose()        {            if (_ui != null)            {                _ui.Dispose();                _ui = null;            }            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_MergeGameUI.PACKAGE_NAME;            _ui = UI_MergeGameUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            _ui.m_backBtn.onClick.Add(Hide);            _ui.m_rewardGet.onClick.Add(SubmitTask);            _ui.m_MergeTipBtn.onClick.Add(ShowMergeRouteTips);            _ui.m_shopBtn.onClick.Add(ShowShopBtn);            _ui.m_sellBtn.target.onClick.Add(OnClickSellBtn);            _ui.target.onClick.Add(OnClickHideTips);            _ui.m_btnProp.target.onClick.Add(OnItemTips);        }        protected override void OnShown()        {            base.OnShown();            //进入这个界面的时候向后台获取任务id和历史id列表            UpdateView();            UpdateList();            UpdateTask();            UpdateItemData();        }        protected override void OnHide()        {            for (int i = 0; i < itemNum; i++)            {                for (int j = 0; j < itemNum; j++)                {                    itemList[i][j].Dispose();                    itemList[i][j] = null;                }            }            idList.Clear();            itemList.Clear();            base.OnHide();        }        private void UpdateData()        {        }        private void UpdateView()        {            itemNum = 5;            taskId = MiniGameDateManager.Instance.taskID;            _res = MergeGameArray.Instance.GetCfg(taskId).resArr[0];            maxLv = 5;            materialID = 0;            rand = new System.Random();            _ui.m_rewardGet.visible = false;            _ui.m_sellBtn.target.GetChild("sellGetNum").text = "";            //_ui.m_newMaterial.target.visible = false;            _ui.m_name.text = "";            _ui.m_desc.text = "";             _ui.m_bg.url = ResPathUtil.GetBgImgPath("jbnf_xyxbj");        }        private void UpdateList()        {            for (int i = 0; i < itemNum; i++)            {                itemList.Add(new List<GComponent>());                idList.Add(new List<int>());                for (int j = 0; j < itemNum; j++)                {                    idList[i].Add(j);                    itemList[i].Add(UIPackage.CreateObject(UI_MergeGameUI.PACKAGE_NAME, "MergeGameItemUI").asCom);                    _ui.m_rangeDown.AddChild(itemList[i][j]);                    //对两个按钮单独处理                    if (i == itemNum - 1)                    {                        itemList[i][j].data = -1;                        idList[i][j] = -1;                        itemList[i][j].SetPosition((_ui.m_rangeDown.width / 10.0f) * (1 + (j * 2.0f)), (_ui.m_rangeDown.height / 10) * (1 + (i * 2.0f)), 0);                        if (j == 0)                        {                            itemList[i][j].GetChild("icon").icon = "ui://MiniGame/jbnf_doubao_icon";                            itemList[i][j].onClick.Add(OnClickAFuBtn);                            continue;                        }                        if ( j == itemNum - 1)                        {                            itemList[i][j].GetChild("icon").icon = "ui://MiniGame/jbnf_afu_icon";                            itemList[i][j].onClick.Add(OnClickDouBaoBtn);                            continue;                        }                    }                    //表示id;这里后续要改                    idList[i][j] = 0;                    if (i == 1 && j == 2)                    {                        idList[i][j] = 1;                    }                    if(i== 2 && j== 2)                    {                        idList[i][j] = 1;                    }                    //                    itemList[i][j].data = idList[i][j];                    itemList[i][j].draggable = true;                    itemList[i][j].onDragStart.Add(onDragStart);                    itemList[i][j].onDragEnd.Add(onDragEnd);                    itemList[i][j].onClick.Add(OnClickItem);                    itemList[i][j].dragBounds = new Rect(_ui.m_rangeTop.x + 90, _ui.m_rangeTop.y + 90, _ui.m_rangeTop.width, _ui.m_rangeTop.height);                    itemList[i][j].SetPosition( (_ui.m_rangeDown.width / 10.0f) * (1+ (j * 2.0f)), (_ui.m_rangeDown.height / 10) * (1+(i * 2.0f)) , 0);                    if (idList[i][j] == 0)                    {                        itemList[i][j].GetChild("icon").icon = "";                        itemList[i][j].draggable = false;                    }                    else                    {                        itemList[i][j].GetChild("icon").icon = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, idList[i][j])[0].resName, "MergeGame");                    }                }            }        }        private void onDragStart(EventContext context)        {            GObject item = context.sender as GObject;            int itemInfo = (int)(context.sender as GObject).data;            indexY = Math.Min(itemNum - 1, (int)(item.x / (_ui.m_rangeDown.width / 5)));            indexX = Math.Min(itemNum - 1, (int)(item.y / (_ui.m_rangeDown.height / 5)));            startX = item.x;            startY = item.y;            indexID = itemInfo;            _ui.m_rangeDown.RemoveChild(item);            _ui.m_rangeTop.AddChild(item);        }        private void onDragEnd(EventContext context)        {            GObject item = context.sender as GObject;            int endIndexY = Math.Min(itemNum - 1 , (int)(item.x / (_ui.m_rangeDown.width/5)));            int endIndexX = Math.Min(itemNum - 1 ,(int)(item.y / (_ui.m_rangeDown.height/5)));            int itemEndInfo = (int)itemList[endIndexX][endIndexY].data;             //合成规则:相同合成,但是材料只有五级,5和5不能合成6, 6属于另一类材料的一级            if (itemEndInfo == indexID && (indexX != endIndexX || indexY != endIndexY) && (itemEndInfo % maxLv != 0))            {                indexID = 0;                idList[indexX][indexY] = 0;                itemList[indexX][indexY].data = 0;                itemList[indexX][indexY].GetChild("icon").icon = "";                idList[endIndexX][endIndexY] = itemEndInfo + 1;                itemList[endIndexX][endIndexY].data = itemEndInfo + 1;                itemList[endIndexX][endIndexY].GetChild("icon").icon = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, itemEndInfo + 1)[0].resName, "MergeGame");                ShowNewMaterialView(endIndexX, endIndexY);                 UI_MergeGameItemUI itemUI = UI_MergeGameItemUI.Proxy(itemList[endIndexX][endIndexY]);                itemUI.m_t0.Play();                UI_MergeGameItemUI.ProxyEnd();                if(InspectionTasks())                {                    _ui.m_rewardGet.visible = true;                }                else                {                    _ui.m_rewardGet.visible = false;                }            }            if (itemEndInfo != indexID && itemEndInfo == 0)            {                idList[indexX][indexY] = 0;                itemList[indexX][indexY].data = 0;                itemList[indexX][indexY].GetChild("icon").icon = "";                idList[endIndexX][endIndexY] = indexID;                itemList[endIndexX][endIndexY].data = indexID;                itemList[endIndexX][endIndexY].GetChild("icon").icon = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, indexID)[0].resName, "MergeGame");                itemEndInfo = indexID;                indexID = 0;            }            item.x = startX;            item.y = startY;            if(indexID == 0)            {                item.draggable = false;            }            if(itemEndInfo > 0 )            {                itemList[endIndexX][endIndexY].draggable = true;            }            startX = 0;            startY = 0;            indexX = 0;            indexY = 0;            indexID = 0;            _ui.m_rangeTop.RemoveChild(item);            _ui.m_rangeDown.AddChild(item);        }        private void OnClickItem(EventContext context)        {            GObject item = context.sender as GObject;            int id = (int)item.data;            if(id <= 0)            {                return;            }            indexY = Math.Min(itemNum - 1, (int)(item.x / (_ui.m_rangeDown.width / 5)));            indexX = Math.Min(itemNum - 1, (int)(item.y / (_ui.m_rangeDown.height / 5)));            materialID = id;            _ui.m_name.text = id.ToString();            _ui.m_desc.text = id.ToString();            ItemCfg itemReward = ItemCfgArray.Instance.GetCfg(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, id)[0].bonusSellArr[0][0]);            _ui.m_sellBtn.target.GetChild("sellReward").icon = ResPathUtil.GetCommonGameResPath(itemReward.res);            _ui.m_sellBtn.target.GetChild("sellGetNum").text = MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, id)[0].bonusSellArr[0][1].ToString();        }        private void OnClickSellBtn()        {            if(materialID == 0)            {                return;            }            //移除            _ui.m_name.text = "";            _ui.m_desc.text = "";            _ui.m_sellBtn.target.GetChild("sellReward").icon = "";            _ui.m_sellBtn.target.GetChild("sellGetNum").text = "";            materialID = 0;            idList[indexX][indexY] = 0;            itemList[indexX][indexY].data = 0;            UI_MergeGameItemUI itemUI = UI_MergeGameItemUI.Proxy(itemList[indexX][indexY]);            itemUI.m_t2.Play();            itemUI.m_t3.Play();            UI_MergeGameItemUI.ProxyEnd();            indexX = 0;            indexY = 0;            //获得奖励        }        private void OnClickAFuBtn()        {            bool gameOver = false;            bool isRand = false;            int materialID = 0;            for (int i = 0; i < itemNum; i++)            {                for (int j = 0; j < itemNum; j++)                {                    if (idList[i][j] == 0)                    {                        gameOver = true;                        break;                    }                }            }            if (!gameOver)            {                return;            }            if(MergeGameArray.Instance.GetCfg(taskId).materialId1Arr.Length > 1)            {                isRand = true;            }            else            {                isRand = false;                materialID = MergeGameArray.Instance.GetCfg(taskId).materialId1Arr[0];            }            while (true)            {                int x = rand.Next(0, itemNum);                int y = rand.Next(0, itemNum);                int num;                int randNum = rand.Next(0, 2);                if (randNum == 0)                {                    num = 1;                }                else                {                    num = 6;                }                if(!isRand)                {                    num = materialID;                }                if (idList[x][y] == 0)                {                    idList[x][y] = num;                    itemList[x][y].data = num;                    itemList[x][y].GetChild("icon").icon = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, num)[0].resName, "MergeGame");                    itemList[x][y].draggable = true;                    UI_MergeGameItemUI itemUI = UI_MergeGameItemUI.Proxy(itemList[x][y]);                    itemUI.m_t1.Play();                    UI_MergeGameItemUI.ProxyEnd();                    break;                }            }        }        private void OnClickDouBaoBtn()        {            bool gameOver = false;            bool isRand = false;            int materialID = 0;            for (int i = 0; i < itemNum; i++)            {                for (int j = 0; j < itemNum; j++)                {                    if (idList[i][j] == 0)                    {                        gameOver = true;                        break;                    }                }            }            if (!gameOver)            {                return;            }            if (MergeGameArray.Instance.GetCfg(taskId).materialId2Arr.Length > 1)            {                isRand = true;            }            else            {                isRand = false;                materialID = MergeGameArray.Instance.GetCfg(taskId).materialId2Arr[0];            }            while (true)            {                int x = rand.Next(0, itemNum);                int y = rand.Next(0, itemNum);                int num;                int randNum = rand.Next(0, 2);                if (randNum == 0)                {                    num = 11;                }                else                {                    num = 16;                }                if (!isRand)                {                    num = materialID;                }                if (idList[x][y] == 0)                {                    idList[x][y] = num;                    itemList[x][y].data = num;                    itemList[x][y].draggable = true;                    itemList[x][y].GetChild("icon").icon = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, num)[0].resName, "MergeGame");                    UI_MergeGameItemUI itemUI = UI_MergeGameItemUI.Proxy(itemList[x][y]);                    itemUI.m_t1.Play();                    UI_MergeGameItemUI.ProxyEnd();                    break;                }            }        }        private void UpdateTask()        {            _ui.m_rewardNum.text = String.Format("+{0}", MergeGameArray.Instance.GetCfg(taskId).bonusWinArr[0][1]);            ItemCfg itemReward = ItemCfgArray.Instance.GetCfg(MergeGameArray.Instance.GetCfg(taskId).bonusWinArr[0][0]);            _ui.m_rewardIcon.url = ResPathUtil.GetCommonGameResPath(itemReward.res);            for (int k = 0; k < MergeGameArray.Instance.GetCfg(taskId).targetIdArr.Length; k++)            {                int targetID = MergeGameArray.Instance.GetCfg(taskId).targetIdArr[k][0];                int targetNum = MergeGameArray.Instance.GetCfg(taskId).targetIdArr[k][1];                switch (k)                {                    case 0:                        _ui.m_rewardOne.target.visible = true;                        _ui.m_rewardTwo.target.visible = false;                        _ui.m_rewardOne.m_icon.url = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, targetID)[0].resName, "MergeGame");                        _ui.m_rewardOne.m_Count.text = targetNum.ToString();                        break;                    case 1:                        _ui.m_rewardTwo.target.visible = true;                        _ui.m_rewardTwo.m_icon.url = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, targetID)[0].resName, "MergeGame");                        _ui.m_rewardTwo.m_Count.text = targetNum.ToString();                        break;                    default:                        break;                }            }            if (InspectionTasks())            {                _ui.m_rewardGet.visible = true;            }            else            {                _ui.m_rewardGet.visible = false;            }        }        //提交任务        private void SubmitTask()        {            for(int k =  0;k< MergeGameArray.Instance.GetCfg(taskId).targetIdArr.Length; k++)            {                int targetID = MergeGameArray.Instance.GetCfg(taskId).targetIdArr[k][0];                int targetNum = MergeGameArray.Instance.GetCfg(taskId).targetIdArr[k][1];                for (int i = 0; i < itemNum; i++)                {                    for (int j = 0; j < itemNum; j++)                    {                        if(idList[i][j] == targetID)                        {                            idList[i][j] = 0;                            itemList[i][j].data = 0;                            UI_MergeGameItemUI itemUI = UI_MergeGameItemUI.Proxy(itemList[i][j]);                            itemUI.m_t2.Play();                            itemUI.m_t3.Play();                            UI_MergeGameItemUI.ProxyEnd();                            targetNum--;                            if(targetNum == 0)                            {                                break;                            }                        }                    }                    if (targetNum == 0)                    {                        break;                    }                }            }            //向后台发送任务ID,获得奖励            //taskId = MiniGameDateManager.Instance.taskID;            //暂用            taskId++;            //            UpdateTask();        }        //检查是否达到提交要求        private bool InspectionTasks()        {            bool isTarged = true;            for (int k = 0; k < MergeGameArray.Instance.GetCfg(taskId).targetIdArr.Length; k++)            {                int targetID = MergeGameArray.Instance.GetCfg(taskId).targetIdArr[k][0];                int targetNum = MergeGameArray.Instance.GetCfg(taskId).targetIdArr[k][1];                int currentNum = 0;                for (int i = 0; i < itemNum; i++)                {                    for (int j = 0; j < itemNum; j++)                    {                        if (idList[i][j] == targetID)                        {                            currentNum++;                            if (currentNum == targetNum)                            {                                break;                            }                        }                    }                    if (currentNum == targetNum)                    {                        break;                    }                }                if (currentNum == targetNum && isTarged)                {                    isTarged = true;                }                else                {                    isTarged = false;                }            }            return isTarged;        }        private void ShowNewMaterialView(int i ,int j)        {            //判断是否是新材料。再显示            _ui.m_newMaterial.target.x = itemList[i][j].x + _ui.m_rangeDown.x;            _ui.m_newMaterial.target.y = itemList[i][j].y + _ui.m_rangeDown.y;            _ui.m_newMaterial.target.visible = true;            _ui.m_newMaterial.target.GetChild("icon").icon = ResPathUtil.GetMiniGamePicPath(MergeCfgArray.Instance.GetCfgsByidAndmaterialId(_res, idList[i][j])[0].resName,"MergeGame");            UI_MergeGameItemUI itemUI = UI_MergeGameItemUI.Proxy(_ui.m_newMaterial.target);            itemUI.m_t0.Play();            UI_MergeGameItemUI.ProxyEnd();                   }        private void OnClickHideTips()        {            if(_ui.m_newMaterial.target.visible == true)            {                _ui.m_newMaterial.target.visible = false;            }         }        private void ShowMergeRouteTips()        {            ViewManager.Show<MergeGameMaterialTipView>(new object[]{ _res });           }        private void ShowShopBtn()        {            ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_ACTIVITY_EXCHANGE });        }        private void UpdateItemData()        {             ItemCfg itemcfg = ItemCfgArray.Instance.GetCfg(propID);            _ui.m_btnProp.target.icon = ResPathUtil.GetIconPath(itemcfg.res,"png");            ItemData item;            if (BagDataManager.Instance.GetBagData().TryGetValue(propID, out item))            {                _ui.m_btnProp.target.title = item.num.ToString();            }            else            {                _ui.m_btnProp.target.title = "0";            }        }        private void OnItemTips()        {            object[] sourceDatas = new object[] { propID, null };            GoodsItemTipsController.ShowItemTips(propID, sourceDatas);        }    }}
 |