Example #1
0
    protected void AddHai(Hai hai, int index)
    {
        int line        = Mathf.Max(0, (index - this.yama_start) % MaxLines);
        int indexInLine = Mathf.Max(0, (index - this.yama_start) / MaxLines);

        Transform parent = top;

        if (line == 0)
        {
            parent = top;
        }
        else
        {
            parent = bottom;
        }

        // set position. align right.
        float   posX     = AlignRightLocalPos.x - MahjongPai.Width * indexInLine;
        Vector3 localPos = new Vector3(posX, 0, 0);

        MahjongPai pai  = PlayerUI.CreateMahjongPai(parent, localPos, hai, false);
        string     name = ResManager.getMahjongTextureName(hai.Kind, hai.Num);

        //Debug.Log ("AddHai("+hai.ID+","+name+")");
        mahjongYama.Add(index, pai);

        //if(index == 0 || index == 2 || index == Yama.YAMA_HAIS_MAX-2) pai.Show();
    }
Example #2
0
 public MahjongPai PickUp(int index)
 {
     if (mahjongYama.ContainsKey(index))
     {
         MahjongPai pai = mahjongYama[index];
         mahjongYama.Remove(index);
         return(pai);
     }
     else
     {
         string indexList = "";
         foreach (var maj in mahjongYama)
         {
             indexList += maj.Key.ToString() + ",";
         }
         if (mahjongYama.Count > 0)
         {
             //Debug.LogWarningFormat ("No such mahjong in index {0}, range is [{1}] ", index, indexList.Substring (0, indexList.Length - 1));
         }
         else
         {
             //Debug.Log ("mahjongYama.Count="+mahjongYama.Count);
         }
         return(null);
     }
 }
Example #3
0
    public void Show()
    {
        Hai[] init_hais = new Hai[4] {
            new Hai(Hai.ID_TON), new Hai(Hai.ID_NAN),
            new Hai(Hai.ID_SYA), new Hai(Hai.ID_PE),
        };

        Hai temp;

        for (int i = 0; i < init_hais.Length; i++)
        {
            int index = Random.Range(0, init_hais.Length);

            temp             = init_hais[i];
            init_hais[i]     = init_hais[index];
            init_hais[index] = temp;
        }

        gameObject.SetActive(true);

        for (int i = 0; i < init_hais.Length; i++)
        {
            MahjongPai pai = PlayerUI.CreateMahjongPai(transform, new Vector3(leftPosX + i * offset, posY, 0), init_hais[i], false);
            pai.SetOnClick(OnClickMahjong);
            pai.EnableInput();

            kazePaiList.Add(pai);
        }
    }
Example #4
0
    protected void AddHai(Hai hai, int index)
    {
        int line        = Mathf.Max(0, (index - this.yama_start) % MaxLines);
        int indexInLine = Mathf.Max(0, (index - this.yama_start) / MaxLines);

        Transform parent = top;

        if (line == 0)
        {
            parent = top;
        }
        else
        {
            parent = bottom;
        }

        // set position. align right.
        float   posX     = AlignRightLocalPos.x - MahjongPai.Width * indexInLine;
        Vector3 localPos = new Vector3(posX, 0, 0);

        MahjongPai pai = PlayerUI.CreateMahjongPai(parent, localPos, hai, false);

        mahjongYama.Add(index, pai);

        //if(index == 0 || index == 2 || index == Yama.YAMA_HAIS_MAX-2) pai.Show();
    }
Example #5
0
    public void AddPai(MahjongPai pai, bool newPicked = false, bool isShow = false)
    {
        int   index = tehaiList.Count;
        float posX  = AlignLeftLocalPos.x + MahjongPai.Width * index + HaiPosOffsetX * index;

        pai.transform.parent        = transform;
        pai.transform.localPosition = new Vector3(posX, AlignLeftLocalPos.y, 0);

        if (isShow)
        {
            pai.Show();
        }
        else
        {
            pai.Hide();
        }

        if (OwnerPlayer.IsAI == false)
        {
            pai.SetOnClick(OnClickMahjong);
        }

        pai.gameObject.name = pai.ID.ToString();
        tehaiList.Add(pai);

        if (newPicked)
        {
            pai.transform.localPosition += new Vector3(NewHaiPosOffsetX, 0, 0);
        }
    }
Example #6
0
    IEnumerator MoveMahjongPaiToKaze(int startID)
    {
        for (int i = 0, id = startID; i < kazePaiList.Count; i++, id++)
        {
            if (id > Hai.ID_PE)
            {
                id = Hai.ID_TON;
            }

            MahjongPai pai = kazePaiList.Find(mp => mp.ID == id);
            pai.Show();

            yield return(new WaitForSeconds(0.4f));

            TweenPosition tweener = TweenPosition.Begin(pai.gameObject, 0.3f, kazePosList[i]);
            tweener.style = UITweener.Style.Once;

            if (i == kazePaiList.Count - 1)
            {
                tweener.SetOnFinished(OnMoveEnd);
            }

            yield return(new WaitForSeconds(0.2f));
        }
    }
Example #7
0
    void InitDoraHais(Hai[] allOmoteDoras, Hai[] allUraDoras)
    {
        if (_omoteDoraHais != null)
        {
            ClearMahjongList(_omoteDoraHais);

            for (int i = 0; i < DoraHaisColumn; i++)
            {
                Vector3 pos = new Vector3(-i * (MahjongPai.Width + haiOffset), 0f, 0f);
                Hai     hai = allOmoteDoras[i];

                MahjongPai pai = PlayerUI.CreateMahjongPai(omoteDoraRoot, pos, hai, false);
                _omoteDoraHais.Add(pai);
            }
        }

        if (_uraDoraHais != null)
        {
            ClearMahjongList(_uraDoraHais);

            for (int i = 0; i < DoraHaisColumn; i++)
            {
                Vector3 pos = new Vector3(-i * (MahjongPai.Width + haiOffset), 0f, 0f);
                Hai     hai = allUraDoras[i];

                MahjongPai pai = PlayerUI.CreateMahjongPai(uraDoraRoot, pos, hai, false);
                _uraDoraHais.Add(pai);
            }
        }
    }
Example #8
0
 protected void OnClick()
 {
     if (current == null && enabled)
     {
         current = this;
         if (_onClick != null)
         {
             _onClick();
         }
         current = null;
     }
 }
Example #9
0
    //出牌
    public MahjongPai SuteHai(int index)
    {
        if (index >= 0 && index < tehaiList.Count)
        {
            MahjongPai pai = tehaiList[index];
            tehaiList.RemoveAt(index);

            pai.transform.parent = null;

            return(pai);
        }
        return(null);
    }
Example #10
0
    public bool setTedashi(bool isTedashi)
    {
        if (_allHais.Count <= 0)
        {
            return(false);
        }

        // set last hai tedashi.
        MahjongPai lastHai = _allHais[_allHais.Count - 1];

        lastHai.SetTedashi(isTedashi);

        return(true);
    }
Example #11
0
    public bool setShining(bool isShining)
    {
        if (_allHais.Count <= 0)
        {
            return(false);
        }

        // set last hai shining.
        MahjongPai lastHai = _allHais[_allHais.Count - 1];

        lastHai.setShining(isShining);

        return(true);
    }
Example #12
0
    public override void Clear()
    {
        base.Clear();

        // clear all pai.
        for (int i = 0; i < fuuroHais.Count; i++)
        {
            MahjongPai pai = fuuroHais[i];
            PlayerUI.CollectMahjongPai(pai);
        }
        fuuroHais.Clear();

        curMaxPosX = 0;
    }
Example #13
0
    public bool setNaki(bool isNaki)
    {
        if (_allHais.Count <= 0)
        {
            return(false);
        }

        // set last hai naki.
        MahjongPai lastHai = _allHais[_allHais.Count - 1];

        lastHai.SetNaki(isNaki);

        setShining(false);

        return(true);
    }
Example #14
0
    public bool SetReach(bool isReach)
    {
        if (_allHais.Count <= 0)
        {
            return(false);
        }

        // set last hai reach.
        MahjongPai lastHai = _allHais[_allHais.Count - 1];

        lastHai.SetReach(isReach);

        _curLineRightAligPosX += (MahjongPai.Height - MahjongPai.Width);

        return(true);
    }
Example #15
0
    //public override void SetParentPanelDepth( int depth ) {
    //    for( int i = 0; i < lineParents.Count; i++ ) {
    //        UIPanel panel = lineParents[i].GetComponent<UIPanel>();
    //
    //        panel.depth = depth + (lineParents.Count - i);
    //    }
    //}

    public void AddHai(MahjongPai pai)
    {
        int inLine      = _allHais.Count / MaxCoutPerLine; //inLine=0,1,2. >2 has a small chance.
        int indexInLine = _allHais.Count % MaxCoutPerLine;

        int EndingLine = Max_Lines - 1;

        if (inLine != _curLine)
        {
            if (inLine <= EndingLine)
            {
                _curLine = inLine;
                _curLineRightAligPosX = AlignLeftLocalPos.x;
            }
            else if (inLine > EndingLine)
            {
                _curLine = EndingLine;

                indexInLine           += MaxCoutPerLine;
                _curLineRightAligPosX += MahjongPai.Width + HaiPosOffsetX;
            }
        }
        else
        {
            if (indexInLine > 0)
            {
                _curLineRightAligPosX += MahjongPai.Width + HaiPosOffsetX;
            }
        }
        //pai.gameObject.layer = LayerMask.NameToLayer ("Hou");
        Utils.SetLayerRecursively(pai.gameObject, LayerMask.NameToLayer("Hou"));
        //pai.transform.parent = lineParents[_curLine];
        //pai.transform.localPosition = new Vector3(_curLineRightAligPosX, 0, 0);

        pai.transform.parent        = AllHouUI.instance.GiveHouParent();
        pai.transform.localPosition = new Vector3(AllHouUI.instance.GiveHouPoistion(_allHais.Count), 0, 0);

        pai.DisableInput();
        pai.SetEnableStateColor(true);
        _allHais.Add(pai);

        pai.Show(); //轉90度
        //lineParents[_curLine].GetComponent<UIPanel>().Update();
    }
Example #16
0
    public static bool CollectMahjongPai(MahjongPai pai)
    {
        if (pai == null)
        {
            return(false);
        }

        pai.Clear();

        if (poolRoot == null)
        {
            poolRoot = new GameObject("MahjongPoolRoot").transform;
        }

        pai.transform.parent = poolRoot;
        Utils.SetLayerRecursively(pai.gameObject, LayerMask.NameToLayer("Default"));
        pai.gameObject.SetActive(false);
        _mahjongPaiPool.Add(pai.gameObject);

        return(true);
    }
Example #17
0
    public void SuteHai(int index)
    {
        //Debug.Log (this._ownerPlayer.Name+" SuteHai("+index+")");
        MahjongPai pai = tehai.SuteHai(index);

        if (pai != null)
        {
            Hai    hai  = pai.GetInfo();
            string name = ResManager.getMagjongName(hai.Kind, hai.Num);
            string wind = ResManager.getString("kaze_" + _ownerPlayer.JiKaze.ToString().ToLower());
            Debug.Log("[" + wind + "]" + this._ownerPlayer.Name + " 出牌(" + name + ")");
            RecordPreTedasi._instance.PreTedasiPlayerIndex = this._ownerPlayer.Order;
            Speak(ECvType.Throw, hai);
            //Speak( ECvType.Reach );
            AddSuteHai(pai);
        }
        else
        {
            Debug.LogError("沒有這個牌 index" + index);
        }
    }
Example #18
0
    public static bool CollectMahjongPai(MahjongPai pai)
    {
        if (pai == null)
        {
            return(false);
        }

        pai.Clear();

        if (poolRoot == null)
        {
            poolRoot = new GameObject("MahjongPoolRoot").transform;
        }

        pai.transform.parent = poolRoot;

        pai.gameObject.SetActive(false);
        _mahjongPaiPool.Add(pai.gameObject);

        return(true);
    }
Example #19
0
    public void AddHai(MahjongPai pai)
    {
        int inLine      = _allHais.Count / MaxCoutPerLine; //inLine=0,1,2. >2 has a small chance.
        int indexInLine = _allHais.Count % MaxCoutPerLine;

        int EndingLine = Max_Lines - 1;

        if (inLine != _curLine)
        {
            if (inLine <= EndingLine)
            {
                _curLine = inLine;
                _curLineRightAligPosX = AlignLeftLocalPos.x;
            }
            else if (inLine > EndingLine)
            {
                _curLine = EndingLine;

                indexInLine           += MaxCoutPerLine;
                _curLineRightAligPosX += MahjongPai.Width + HaiPosOffsetX;
            }
        }
        else
        {
            if (indexInLine > 0)
            {
                _curLineRightAligPosX += MahjongPai.Width + HaiPosOffsetX;
            }
        }

        pai.transform.parent        = lineParents[_curLine];
        pai.transform.localPosition = new Vector3(_curLineRightAligPosX, 0, 0);

        pai.DisableInput();
        pai.SetEnableStateColor(true);
        _allHais.Add(pai);

        pai.Show();
        lineParents[_curLine].GetComponent <UIPanel>().Update();
    }
Example #20
0
    public static MahjongPai CreateMahjongPai(Transform parent, Vector3 localPos, Hai info, bool isShow = true)
    {
        if (Hai.IsValidHai(info) == false)
        {
            Debug.LogError("PlayerUI: Invalid hai for ID == " + info.ID);
            return(null);
        }

        GameObject newInst = ResManager.CreateMahjongObject();

        newInst.transform.parent        = parent;
        newInst.transform.localScale    = Vector3.one;
        newInst.transform.localPosition = localPos;

        // set component info.
        MahjongPai pai = newInst.GetComponent <MahjongPai>();

        if (pai == null)
        {
            pai = newInst.AddComponent <MahjongPai>();
        }

        pai.SetInfo(info);
        pai.Init();
        pai.UpdateImage();

        if (isShow)
        {
            pai.Show();
        }
        else
        {
            pai.Hide();
        }

        return(pai);
    }
Example #21
0
    public void AddPai(MahjongPai pai, bool newPicked = false, bool isShow = false)
    {
        int   index = tehaiList.Count;
        float posX  = AlignLeftLocalPos.x + MahjongPai.Width * index + HaiPosOffsetX * index;

        pai.transform.parent        = transform;
        pai.transform.localPosition = new Vector3(posX, AlignLeftLocalPos.y, 0);

        if (isShow)
        {
            pai.Show();
        }
        else
        {
            pai.Hide();
        }

        if (OwnerPlayer.IsAI == false)
        {
            //pai.gameObject.layer = LayerMask.NameToLayer("PlayerTehai");
            Utils.SetLayerRecursively(pai.gameObject, LayerMask.NameToLayer("PlayerTehai"));
            pai.SetOnClick(OnClickMahjong);
            pai.isPlayer = true;
        }
        else
        {
            Utils.SetLayerRecursively(pai.gameObject, LayerMask.NameToLayer("Default"));
        }

        pai.gameObject.name = pai.ID.ToString();
        tehaiList.Add(pai);

        if (newPicked)
        {
            pai.transform.localPosition += new Vector3(NewHaiPosOffsetX, 0, 0);
        }
    }
Example #22
0
    // handle ui event.
    public void OnHandleEvent(UIEventType evtID, object[] args)
    {
        switch (evtID)
        {
        case UIEventType.Init_Game:     // game init /
        {
            Clear();
            Init();
            HideAllHudPanel();
        }
        break;

        case UIEventType.Select_ChiiCha:
        {
            selectChiiChanPanel.Show();
        }
        break;

        case UIEventType.Init_PlayerInfoUI:
        {
            List <Player> players = Model.PlayerList;
            for (int i = 0; i < players.Count; i++)
            {
                Player   player = players[i];
                PlayerUI ui     = playerUIDict[i];

                ui.SetKaze(player.JiKaze);
                ui.SetTenbou(player.Tenbou);
                ui.Reach(false);

                ui.SetOyaKaze(i == Model.OyaIndex);
                ui.BindPlayer(player);

                if (player.JiKaze == Model.getManKaze())
                {
                    playerInputPanel.BindPlayer(player);
                    playerInputPanel.SetOwnerPlayerUI(ui);
                }
            }
        }
        break;

        case UIEventType.SetYama_BeforeHaipai:
        {
            // Yama.
            Hai[] yamaHais = Model.Yama.getYamaHais();

            for (int i = 0; i < 4; i++)
            {
                Dictionary <int, Hai> haiDict = new Dictionary <int, Hai>();

                int[] indexRange = getStartEndOfYamaUIOfPlayer(i);
                for (int h = indexRange[0]; h <= indexRange[1]; h++)
                {
                    haiDict.Add(h, yamaHais[h]);
                }

                playerUIDict[i].SetYamaHais(haiDict, indexRange[0], indexRange[1]);
            }

            //TestYama();
        }
        break;

        case UIEventType.DisplayKyokuInfo:
        {
            string kyokuStr = (string)args[0];
            string honbaStr = (string)args[1];

            kyokuInfoPanel.Show(kyokuStr, honbaStr);
        }
        break;

        case UIEventType.Select_Wareme:
        {
            Sai[] sais = Model.Saifuri();

            saifuriPanel.Show(sais[0].Num, sais[1].Num);
        }
        break;

        case UIEventType.SetUI_AfterHaipai:     // 配牌 /
        {
            /// set game info.
            gameInfo.SetKyoku(Model.getBaKaze(), Model.Kyoku);
            gameInfo.SetReachCount(Model.ReachBou);
            gameInfo.SetHonba(Model.HonBa);
            gameInfo.SetRemain(Model.getTsumoRemainCount());

            int totalPickHaiCount = (4 * 3 + 1) * Model.PlayerList.Count;

            /// set yama.
            int waremeIndex        = Model.Wareme;
            int tsumoHaiStartIndex = waremeIndex + totalPickHaiCount;

            //Debug.Log(string.Format("remove yamahai in range[{0},{1}]", waremeIndex+1, tsumoHaiStartIndex % Yama.YAMA_HAIS_MAX));

            for (int i = waremeIndex + 1; i <= tsumoHaiStartIndex; i++)
            {
                int        index = i % Yama.YAMA_HAIS_MAX;
                int        p     = findPlayerForYamahaiIndex(index);
                MahjongPai pai   = playerUIDict[p].PickUpYamaHai(index);
                PlayerUI.CollectMahjongPai(pai);
            }

            /// set tehais.
            int PlayerCount = Model.PlayerList.Count;
            for (int i = 0; i < PlayerCount; i++)
            {
                Player player = Model.PlayerList[i];

                PlayerUI ui = playerUIDict[i];

                ui.SetTehai(player.Tehai.getJyunTehai());
                ui.SetTehaiVisiable(!player.IsAI);

                playerUIDict_Kaze[player.JiKaze] = ui;
            }


            /// set init Dora.
            int showIndex = waremeIndex - 5;
            if (showIndex < 0)
            {
                showIndex += Yama.YAMA_HAIS_MAX;
            }

            int pi = findPlayerForYamahaiIndex(showIndex);
            playerUIDict[pi].ShowYamaHai(showIndex);

            // set Wareme.
            showIndex = waremeIndex - 13;
            if (showIndex < 0)
            {
                showIndex += Yama.YAMA_HAIS_MAX;
            }
            pi = findPlayerForYamahaiIndex(showIndex);
            playerUIDict[pi].SetWareme(showIndex);
        }
        break;


        case UIEventType.DisplayMenuList:
        {
            // TODO: shouldn't use Model too frequently

            // if menu is for HandleSuteHai, set sute hai shining.
            if (Model.CurrentRequest == ERequest.Handle_SuteHai &&
                Model.ActivePlayer.Action.MenuList.Count > 0)
            {
                if (hasShining == false)
                {
                    shiningKaze = Model.FromKaze;
                    playerUIDict_Kaze[shiningKaze].SetShining(true);
                    hasShining = true;
                }
            }
            playerInputPanel.Show();
        }
        break;

        case UIEventType.HideMenuList:
        {
            playerInputPanel.Hide();

            // if menu is for HandleSuteHai, set sute hai not shining.
            if (hasShining)
            {
                playerUIDict_Kaze[shiningKaze].SetShining(false);
                hasShining = false;
            }
        }
        break;


        case UIEventType.PickTsumoHai:
        {
            gameInfo.SetRemain(Model.getTsumoRemainCount());

            Player activePlayer  = (Player)args[0];
            int    lastPickIndex = (int)args[1];
            Hai    newHai        = (Hai)args[2];

            int        yamaPlayerIndex = findPlayerForYamahaiIndex(lastPickIndex);
            MahjongPai pai             = playerUIDict[yamaPlayerIndex].PickUpYamaHai(lastPickIndex);
            PlayerUI.CollectMahjongPai(pai);

            PlayerUI playerUI = playerUIDict_Kaze[activePlayer.JiKaze];
            playerUI.PickHai(newHai, true, !activePlayer.IsAI);

            SetManInputEnable(!activePlayer.IsAI && !activePlayer.IsReach);
        }
        break;

        case UIEventType.PickRinshanHai:
        {
            Player activePlayer         = (Player)args[0];
            int    lastPickRinshanIndex = (int)args[1];
            Hai    newHai          = (Hai)args[2];
            int    newDoraHaiIndex = (int)args[3];

            int        yamaPlayerIndex = findPlayerForYamahaiIndex(lastPickRinshanIndex);
            MahjongPai pai             = playerUIDict[yamaPlayerIndex].PickUpYamaHai(lastPickRinshanIndex);
            PlayerUI.CollectMahjongPai(pai);

            PlayerUI playerUI = playerUIDict_Kaze[activePlayer.JiKaze];
            playerUI.PickHai(newHai, true, !activePlayer.IsAI);

            // open a omote dora hai
            int omoteDoraPlayerIndex = findPlayerForYamahaiIndex(newDoraHaiIndex);
            playerUIDict[omoteDoraPlayerIndex].ShowYamaHai(newDoraHaiIndex);

            SetManInputEnable(!activePlayer.IsAI && !activePlayer.IsReach);
        }
        break;

        case UIEventType.SuteHai:
        {
            UIAnimWillEndAfter(SuteHaiAnimationTime);

            Player activePlayer = (Player)args[0];
            int    sutehaiIndex = (int)args[1];
            //Hai suteHai = (Hai)args[2];
            bool isTedashi = (bool)args[3];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.SuteHai(sutehaiIndex);
            ui.SetTedashi(isTedashi);

            // needn't sort hais if sute the last one.
            if (sutehaiIndex < activePlayer.Tehai.getJyunTehaiCount())
            {
                ui.SortTehai(activePlayer.Tehai.getJyunTehai(), SuteHaiAnimationTime);
            }

            SetManInputEnable(false);

            // play a sute hai sound
            AudioManager.Get().PlaySFX(AudioConfig.GetSEPath(ESeType.SuteHai));
        }
        break;

        case UIEventType.Reach:
        {
            UIAnimWillEndAfter(ReachAnimationTime);

            Player activePlayer = (Player)args[0];
            int    sutehaiIndex = (int)args[1];
            //Hai suteHai = (Hai)args[2];
            bool isTedashi = (bool)args[3];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.SuteHai(sutehaiIndex);
            ui.SetTedashi(isTedashi);
            ui.Reach();

            ui.Speak(ECvType.Reach);

            // needn't sort hais if sute the last one.
            if (sutehaiIndex < activePlayer.Tehai.getJyunTehaiCount())
            {
                ui.SortTehai(activePlayer.Tehai.getJyunTehai(), SuteHaiAnimationTime);
            }

            ui.Info.SetReach(true);
            ui.Info.SetTenbou(activePlayer.Tenbou);
            gameInfo.SetReachCount(Model.ReachBou);

            SetManInputEnable(false);
        }
        break;

        case UIEventType.Kakan:
        {
            UIAnimWillEndAfter(NakiAnimationTime);

            Player activePlayer = (Player)args[0];
            //Hai kakanHai = (Hai)args[1];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.UpdateFuuro(activePlayer.Tehai.getFuuros());
            ui.SetTehai(activePlayer.Tehai.getJyunTehai(), true);

            ui.Speak(ECvType.Kan);

            SetManInputEnable(!activePlayer.IsAI);
        }
        break;

        case UIEventType.Ankan:
        {
            UIAnimWillEndAfter(NakiAnimationTime);

            Player activePlayer = (Player)args[0];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.UpdateFuuro(activePlayer.Tehai.getFuuros());
            ui.SetTehai(activePlayer.Tehai.getJyunTehai(), true);

            ui.Speak(ECvType.Kan);

            SetManInputEnable(!activePlayer.IsAI);
        }
        break;

        case UIEventType.DaiMinKan:
        {
            UIAnimWillEndAfter(NakiAnimationTime);

            Player activePlayer = (Player)args[0];
            EKaze  fromKaze     = (EKaze)args[1];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.UpdateFuuro(activePlayer.Tehai.getFuuros());
            ui.SetTehai(activePlayer.Tehai.getJyunTehai(), true);

            ui.Speak(ECvType.Kan);

            PlayerUI fromUI = playerUIDict_Kaze[fromKaze];
            fromUI.SetNaki();

            SetManInputEnable(!activePlayer.IsAI);
        }
        break;

        case UIEventType.Pon:
        {
            UIAnimWillEndAfter(NakiAnimationTime);

            Player activePlayer = (Player)args[0];
            EKaze  fromKaze     = (EKaze)args[1];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.UpdateFuuro(activePlayer.Tehai.getFuuros());
            ui.SetTehai(activePlayer.Tehai.getJyunTehai(), true);

            ui.Speak(ECvType.Pon);

            PlayerUI fromUI = playerUIDict_Kaze[fromKaze];
            fromUI.SetNaki();

            SetManInputEnable(!activePlayer.IsAI);
        }
        break;

        case UIEventType.Chii_Left:
        case UIEventType.Chii_Center:
        case UIEventType.Chii_Right:
        {
            UIAnimWillEndAfter(NakiAnimationTime);

            Player activePlayer = (Player)args[0];
            EKaze  fromKaze     = (EKaze)args[1];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.UpdateFuuro(activePlayer.Tehai.getFuuros());
            ui.SetTehai(activePlayer.Tehai.getJyunTehai(), true);

            ui.Speak(ECvType.Chii);

            PlayerUI fromUI = playerUIDict_Kaze[fromKaze];
            fromUI.SetNaki();

            SetManInputEnable(!activePlayer.IsAI);
        }
        break;

        case UIEventType.Ron_Agari:
        {
            UIAnimWillEndAfter(AgariAnimationTime);

            List <EKaze> ronPlayers = (List <EKaze>)args[0];
            EKaze        fromKaze   = (EKaze)args[1];
            Hai          ronHai     = (Hai)args[2];

            for (int i = 0; i < ronPlayers.Count; i++)
            {
                PlayerUI ui = playerUIDict_Kaze[ronPlayers[i]];
                ui.PickHai(ronHai, true, false);
                ui.SetTehaiVisiable(true);

                ui.Speak(ECvType.Ron);
            }

            PlayerUI fromUI = playerUIDict_Kaze[fromKaze];
            fromUI.SetNaki();

            // show out all players' tehai
            ShowAllPlayerTehai();
        }
        break;

        case UIEventType.Tsumo_Agari:
        {
            UIAnimWillEndAfter(AgariAnimationTime);

            Player activePlayer = (Player)args[0];

            PlayerUI ui = playerUIDict_Kaze[activePlayer.JiKaze];
            ui.SetTehaiVisiable(true);

            ui.Speak(ECvType.Tsumo);

            // show out all players' tehai
            ShowAllPlayerTehai();
        }
        break;

        case UIEventType.Display_Agari_Panel:
        {
            List <AgariUpdateInfo> agariList = (List <AgariUpdateInfo>)args[0];
            agariPanel.Show(agariList);
        }
        break;

        case UIEventType.RyuuKyoku:
        {
            ERyuuKyokuReason       reason    = (ERyuuKyokuReason)args[0];
            List <AgariUpdateInfo> agariList = (List <AgariUpdateInfo>)args[1];

            ShowAllPlayerTehai();

            ryuuKyokuPanel.Show(reason, agariList);
        }
        break;

        case UIEventType.End_Game:
        {
            List <AgariUpdateInfo> agariList = (List <AgariUpdateInfo>)args[0];
            gameOverPanel.Show(agariList);
        }
        break;
        }
    }
Example #23
0
    public void SuteHai(int index)
    {
        MahjongPai pai = tehai.SuteHai(index);

        AddSuteHai(pai);
    }
Example #24
0
 public static int MahjongPaiCompare(MahjongPai x, MahjongPai y)
 {
     return(x.ID - y.ID);
 }
Example #25
0
    public void AddPai(Hai hai, bool newPicked = false, bool isShow = false)
    {
        MahjongPai pai = PlayerUI.CreateMahjongPai(transform, Vector3.zero, hai, isShow);

        AddPai(pai, newPicked, isShow);
    }
Example #26
0
    void OnClickMahjong()
    {
        //Debug.Log ("OnClickMahjong()");
        int index = tehaiList.IndexOf(MahjongPai.current);

        //int index = 0;
        //Debug.Log("OnClickMahjong(" + index.ToString()+")");
        //index = OwnerPlayer.Tehai.getJyunTehaiCount() - 1; // Test: the last one.

        switch (PlayerAction.State)
        {
        case EActionState.Select_Agari:
        case EActionState.Select_Sutehai:
        {    //丟牌
            PlayerAction.Response     = EResponse.SuteHai;
            PlayerAction.SutehaiIndex = index;

            EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
            OwnerPlayer.OnPlayerInputFinished();
        }
        break;

        case EActionState.Select_Reach:
        {    //聽牌
            PlayerAction.Response         = EResponse.Reach;
            PlayerAction.ReachSelectIndex = PlayerAction.ReachHaiIndexList.FindIndex(i => i == index);

            SetEnableStateColor(true);
            EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
            OwnerPlayer.OnPlayerInputFinished();
        }
        break;

        case EActionState.Select_Kan:
        {    //槓
            Hai kanHai = new Hai(MahjongPai.current.ID);
            //Hai kanHai = new Hai( 0);

            if (OwnerPlayer.Tehai.validKaKan(kanHai))
            {
                PlayerAction.Response = EResponse.Kakan;
            }
            else
            {
                PlayerAction.Response = EResponse.Ankan;
            }

            PlayerAction.KanSelectIndex = PlayerAction.TsumoKanHaiList.FindIndex(h => h.ID == kanHai.ID);

            SetEnableStateColor(true);
            EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
            OwnerPlayer.OnPlayerInputFinished();
        }
        break;

        case EActionState.Select_Chii:
        {    //吃
            MahjongPai curSelect = MahjongPai.current;
            //MahjongPai curSelect = new MahjongPai();

            if (chiiPaiSelectList.Contains(curSelect))
            {
                chiiPaiSelectList.Remove(curSelect);
                curSelect.transform.localPosition -= SelectStatePosOffset;

                // check to enable select other chii type pai.
                List <int> enableIndexList = new List <int>();
                Hai[]      jyunTehais      = OwnerPlayer.Tehai.getJyunTehai();

                for (int i = 0; i < PlayerAction.AllSarashiHais.Count; i++)
                {
                    for (int j = 0; j < jyunTehais.Length; j++)
                    {
                        if (jyunTehais[j].ID == PlayerAction.AllSarashiHais[i].ID)
                        {
                            enableIndexList.Add(j);
                        }
                    }
                }

                EnableInput(enableIndexList);
            }
            else
            {
                chiiPaiSelectList.Add(curSelect);
                if (curSelect)
                {
                    curSelect.transform.localPosition += SelectStatePosOffset;
                }

                if (chiiPaiSelectList.Count >= 2)      // confirm Chii.
                {
                    chiiPaiSelectList.Sort(MahjongPaiCompare);

                    if (PlayerAction.SarashiHaiRight.Count >= 2)
                    {
                        PlayerAction.SarashiHaiRight.Sort(Tehai.Compare);
                        if (chiiPaiSelectList[0].ID == PlayerAction.SarashiHaiRight[0].ID &&
                            chiiPaiSelectList[1].ID == PlayerAction.SarashiHaiRight[1].ID)
                        {
                            PlayerAction.Response       = EResponse.Chii_Right;
                            PlayerAction.ChiiSelectType = PlayerAction.Chii_Select_Right;
                            Debug.Log("Chii type is Chii_Right");
                        }
                    }

                    if (PlayerAction.SarashiHaiCenter.Count >= 2)
                    {
                        PlayerAction.SarashiHaiCenter.Sort(Tehai.Compare);
                        if (chiiPaiSelectList[0].ID == PlayerAction.SarashiHaiCenter[0].ID &&
                            chiiPaiSelectList[1].ID == PlayerAction.SarashiHaiCenter[1].ID)
                        {
                            PlayerAction.Response       = EResponse.Chii_Center;
                            PlayerAction.ChiiSelectType = PlayerAction.Chii_Select_Center;
                            Debug.Log("Chii type is Chii_Center");
                        }
                    }

                    if (PlayerAction.SarashiHaiLeft.Count >= 2)
                    {
                        PlayerAction.SarashiHaiLeft.Sort(Tehai.Compare);
                        if (chiiPaiSelectList[0].ID == PlayerAction.SarashiHaiLeft[0].ID &&
                            chiiPaiSelectList[1].ID == PlayerAction.SarashiHaiLeft[1].ID)
                        {
                            PlayerAction.Response       = EResponse.Chii_Left;
                            PlayerAction.ChiiSelectType = PlayerAction.Chii_Select_Left;
                            Debug.Log("Chii type is Chii_Left");
                        }
                    }

                    EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
                    OwnerPlayer.OnPlayerInputFinished();

                    chiiPaiSelectList.Clear();
                }
                else     // check to disable select other chii type pai.
                {
                    List <int> enableIndexList = new List <int>();
                    Hai[]      jyunTehais      = OwnerPlayer.Tehai.getJyunTehai();

                    int curSelectID = chiiPaiSelectList[0].ID;
                    enableIndexList.Add(index);

                    if (PlayerAction.SarashiHaiRight.Exists(h => h.ID == curSelectID))
                    {
                        Hai otherHai = PlayerAction.SarashiHaiRight.Find(h => h.ID != curSelectID);

                        for (int i = 0; i < jyunTehais.Length; i++)
                        {
                            if (jyunTehais[i].ID == otherHai.ID && !enableIndexList.Contains(i))
                            {
                                enableIndexList.Add(i);
                            }
                        }
                    }

                    if (PlayerAction.SarashiHaiCenter.Exists(h => h.ID == curSelectID))
                    {
                        Hai otherHai = PlayerAction.SarashiHaiCenter.Find(h => h.ID != curSelectID);

                        for (int i = 0; i < jyunTehais.Length; i++)
                        {
                            if (jyunTehais[i].ID == otherHai.ID && !enableIndexList.Contains(i))
                            {
                                enableIndexList.Add(i);
                            }
                        }
                    }

                    if (PlayerAction.SarashiHaiLeft.Exists(h => h.ID == curSelectID))
                    {
                        Hai otherHai = PlayerAction.SarashiHaiLeft.Find(h => h.ID != curSelectID);

                        for (int i = 0; i < jyunTehais.Length; i++)
                        {
                            if (jyunTehais[i].ID == otherHai.ID && !enableIndexList.Contains(i))
                            {
                                enableIndexList.Add(i);
                            }
                        }
                    }

                    EnableInput(enableIndexList);
                }
            }
        }
        break;
        }
    }
Example #27
0
 public void PickPai(MahjongPai hai, bool newPicked = false, bool isShow = false)
 {
     tehai.AddPai(hai, newPicked, isShow);
 }
Example #28
0
 // 河. 打牌.
 protected void AddSuteHai(MahjongPai hai)
 {
     hou.AddHai(hai);
 }
Example #29
0
 public static void CollectMahjongPai(MahjongPai pai)
 {
     ResManager.CollectMahjongPai(pai);
 }
Example #30
0
    public void UpdateFuuro(Fuuro[] fuuros)
    {
        if (fuuros == null)
        {
            return;
        }

        // clear all fuuro.
        Clear();

        // create new.
        for (int i = 0; i < fuuros.Length; i++)
        {
            Fuuro      fuu       = fuuros[i];
            EFuuroType fuuroType = fuu.Type;

            if (i > 0)
            {
                curMaxPosX -= FuuroOffsetX;
            }

            int   newPickIndex = fuu.NewPickIndex;
            Hai[] hais         = fuu.Hais;
            //int relation = fuu.Relation;

            bool shouldSetLand = false;

            switch (fuuroType)
            {
            case EFuuroType.MinShun:     //Chii.
            case EFuuroType.MinKou:      // Pon.
            case EFuuroType.KaKan:       // 加杠.
            case EFuuroType.DaiMinKan:   // 大明杠.
            {
                for (int j = 0; j < hais.Length; j++)
                {
                    if (hais[j].ID < 0)
                    {
                        continue;
                    }

                    shouldSetLand = (j == newPickIndex);

                    float   posX     = curMaxPosX - GetMahjongRange(shouldSetLand) * 0.5f;
                    Vector3 localPos = new Vector3(posX, 0, 0);

                    MahjongPai pai = PlayerUI.CreateMahjongPai(transform, localPos, hais[j], true);

                    if (shouldSetLand)
                    {
                        pai.SetOrientation(EOrientation.Landscape_Left);

                        pai.transform.localPosition += new Vector3(0, MahjongPai.LandHaiPosOffsetY, 0);
                    }

                    pai.DisableInput();
                    fuuroHais.Add(pai);

                    // update curMaxPosX.
                    curMaxPosX -= GetMahjongRange(shouldSetLand);
                }
            }
            break;

            case EFuuroType.AnKan:     // 暗杠.
            {
                for (int j = 0; j < hais.Length; j++)
                {
                    if (hais[j].ID < 0)
                    {
                        continue;
                    }

                    shouldSetLand = false;

                    float   posX     = curMaxPosX - GetMahjongRange(shouldSetLand) * 0.5f;
                    Vector3 localPos = new Vector3(posX, 0, 0);

                    bool isShow = (j != 0 && j != hais.Length - 1);     // 2 sides hide.

                    MahjongPai pai = PlayerUI.CreateMahjongPai(transform, localPos, hais[j], isShow);

                    fuuroHais.Add(pai);

                    // update curMaxPosX.
                    curMaxPosX -= GetMahjongRange(shouldSetLand);
                }
            }
            break;
            }
        } // end for().
    }