Example #1
0
    //Main GUI goes here
    void OnGUI()
    {
        GUI.depth           = 1;
        GUI.backgroundColor = Color.clear;
        GUI.color           = new Color(1.0f, 1.0f, 1.0f, _mainAlpha);

        if (MainGuiShow)
        {
            if (currentSelect.chess != null)
            {
                CurrentChess = currentSelect.chess;
            }
            if (CurrentChess != null)
            {
                CharacterProperty chessProperty = CurrentChess.GetComponent <CharacterProperty>();
                // move button
                if (chessProperty.Moved)
                {
                    GUI.enabled = false;
                }
                else
                {
                    GUI.enabled = true;
                }
                if (GUI.Button(posMoveBt, MoveTex))
                {
                    MainGuiFade = false;
                    SubGuiFade  = true;
                    moveShow    = true;
                    currentSelect.moveCommand(CurrentChess);
                    currentSelect.MoveCommandNetwork();
                    if (InTutorial)
                    {
                        init.ShowMoveCmd = false;
                        GameObject.Find("InitStage").transform.GetComponent <Tutorial>().AfterMove();
                        init.ShowMap = true;
                    }
                }
                GUI.enabled = true;
                //roll over move button
                if (!chessProperty.Moved && !InTutorial)
                {
                    if (posMoveBt.Contains(mousePos))
                    {
                        GUI.DrawTexture(posMoveBt, MoveTex);
                        GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + 16, 100, 30), "move", mainStyle);
                    }
                }
                // summon button
                if (!chessProperty.Summoner || init.stage == 1)
                {
                    GUI.enabled = false;
                }
                else
                {
                    GUI.enabled = true;
                }

                if (GUI.Button(posSummonBt, SummonTex))
                {
                    MainGuiFade = false;
                    SubGuiFade  = true;
                    summonShow  = true;
                }
                GUI.enabled = true;
                //roll over summon button
                if (chessProperty.Summoner && init.stage != 1)
                {
                    if (posSummonBt.Contains(mousePos))
                    {
                        GUI.DrawTexture(posSummonBt, SummonTex);
                        GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment + 16, 100, 30), "summon", mainStyle);
                    }
                }
                // Attack button
                if (chessProperty.Attacked || !MapHelper.Attackable(CurrentChess))
                {
                    GUI.enabled = false;
                }
                else
                {
                    GUI.enabled = true;
                }

                if (GUI.Button(posAttackBt, AttackTex))
                {
                    MainGuiFade = false;
                    SubGuiFade  = true;
                    attackShow  = true;
                    currentSelect.attackCommand(CurrentChess);
                    currentSelect.AttackCommandNetwork();
                    if (InSecondTutor)
                    {
                        init.ShowAtk = false;
                    }
                }
                GUI.enabled = true;
                //roll over attack button
                if (!chessProperty.Attacked && MapHelper.Attackable(CurrentChess))
                {
                    if (posAttackBt.Contains(mousePos))
                    {
                        GUI.DrawTexture(posAttackBt, AttackTex);
                        GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 2 + 16, 100, 30), "attack", mainStyle);
                    }
                }
                // skill button
                if (chessProperty.Activated || init.stage == 1)
                {
                    GUI.enabled = false;
                }
                else
                {
                    GUI.enabled = true;
                }
                if (GUI.Button(posSkillBt, SkillTex))
                {
                    MainGuiFade = false;
                    SubGuiFade  = true;
                    skillShow   = true;
                }
                GUI.enabled = true;
                //roll over skill button
                if (!chessProperty.Activated && init.stage != 1)
                {
                    if (posSkillBt.Contains(mousePos))
                    {
                        GUI.DrawTexture(posSkillBt, SkillTex);
                        GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 3 + 16, 100, 30), "skill", mainStyle);
                    }
                }
                //Defense button

                if (chessProperty.Attacked || init.ShowBuff || InSecondTutor)
                {
                    GUI.enabled = false;
                }
                else
                {
                    GUI.enabled = true;
                }

                if (GUI.Button(posDefenseBt, DefenseTex))
                {
                    DefenseCmd(CurrentChess);
                    if (init.ShowDef)
                    {
                        init.ShowDef  = false;
                        InTutorial    = false;
                        InSecondTutor = true;
                    }
                }
                GUI.enabled = true;
                //roll over defense button
                if (!chessProperty.Attacked)
                {
                    if (posDefenseBt.Contains(mousePos))
                    {
                        GUI.DrawTexture(posDefenseBt, DefenseTex);
                        GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 4 + 16, 100, 30), "defence", mainStyle);
                    }
                }
                // End turn button
                if (InTutorial)
                {
                    GUI.enabled = false;
                }
                else
                {
                    GUI.enabled = true;
                }

                if (GUI.Button(posEndTurnBt, EndTurnTex))
                {
                    MainGuiFade = false;
                    //SubGuiFade = true;
                    chessProperty.Activated       = true;
                    chessProperty.Attacked        = true;
                    chessProperty.Moved           = true;
                    chessProperty.TurnFinished    = true;
                    CurrentChess.gameObject.layer = 10;
                    currentSelect.MoveToLayer(CurrentChess, 10);
                    currentSelect.EndTurnNetwork();
                }

                GUI.enabled = true;

                //roll over end turn button
                if (!InTutorial)
                {
                    if (posEndTurnBt.Contains(mousePos))
                    {
                        GUI.DrawTexture(posEndTurnBt, EndTurnTex);
                        GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 5 + 13, 100, 30), "end turn", mainStyle);
                    }
                }
            }
        }
        GUI.color = new Color(1.0f, 1.0f, 1.0f, _subAlpha);

        if (moveShow)
        {
            GUI.DrawTexture(posMoveBt, MoveTex);
            GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + 16, 100, 30), "move", mainStyle);
            if (Input.GetMouseButtonDown(0) && posMoveBt.Contains(mousePos))
            {
                Cancel      = true;
                MainGuiFade = true;
                SubGuiFade  = false;
                TurnFinished(CurrentChess);
            }
        }
        if (attackShow)
        {
            GUI.DrawTexture(posAttackBt, AttackTex);
            GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 2 + 16, 100, 30), "attack", mainStyle);
            if (Input.GetMouseButtonDown(0) && posAttackBt.Contains(mousePos))
            {
                Cancel      = true;
                MainGuiFade = true;
                SubGuiFade  = false;
                TurnFinished(CurrentChess);
            }
        }
        if (summonShow)
        {
            Rect posSummonList = new Rect(posSummonBt.x + posSummonBt.width / 2, posSummonBt.y + posSummonBt.height / 2, 200.0f, 200.0f);
            GUI.DrawTexture(posSummonList, SubWindow);
            GUI.DrawTexture(posSummonBt, SummonTex);
            GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment + 16, 100, 30), "summon", mainStyle);
            if (Input.GetMouseButtonDown(0) && posSummonBt.Contains(mousePos))
            {
                Cancel      = true;
                MainGuiFade = true;
                SubGuiFade  = false;
            }
            IList soldiers = new List <Transform>();
            if (CurrentChess.GetComponent <CharacterProperty>().Player == 1)
            {
                foreach (Transform gf in players.PlayerAChesses)
                {
                    if (!gf.GetComponent <CharacterProperty>().Summoner)
                    {
                        soldiers.Add(gf);
                    }
                }
            }
            else if (CurrentChess.GetComponent <CharacterProperty>().Player == 2)
            {
                foreach (Transform gf in players.PlayerBChesses)
                {
                    if (!gf.GetComponent <CharacterProperty>().Summoner)
                    {
                        soldiers.Add(gf);
                    }
                }
            }
            int seg = 0;
            foreach (Transform gf in soldiers)
            {
                CharacterProperty gfp = gf.GetComponent <CharacterProperty>();
                if (gfp.Ready && (gfp.summonCost <= currentSelect.player.GetComponent <ManaCounter>().Mana) && gfp.death)
                {
                    GUI.enabled = true;
                }
                else
                {
                    GUI.enabled = false;
                }
                Rect posGFBt = CreateGFBt(gf, seg);
                if (posGFBt.Contains(mousePos))
                {
                    infoUI.CreatedGFRollOver(gf, subStyle);
                }
                if (GUI.Button(posGFBt, "", subStyle))
                {
                    currentSelect.summonCommand(CurrentChess, gf);
                    //update network UI
                    currentSelect.SummonNetwork();
                }
                seg += 1;
            }
        }
        if (skillShow)
        {
            Rect posSkillsBt = new Rect(posSkillBt.x + posSkillBt.width / 2, posSkillBt.y + posSkillBt.height / 2, 200.0f, 100.0f);
            GUI.DrawTexture(posSkillsBt, SubWindow);
            GUI.DrawTexture(posSkillBt, SkillTex);
            GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 3 + 16, 100, 30), "skill", mainStyle);
            if (Input.GetMouseButtonDown(0) && posSkillBt.Contains(mousePos))
            {
                Cancel      = true;
                MainGuiFade = true;
                SubGuiFade  = false;
            }
            Transform[] skills = CurrentChess.GetComponent <SkillSets>().Skills;
            int         seg    = 0;
            if (skills.Length > 0)
            {
                foreach (Transform skill in skills)
                {
                    if (currentSelect.player.GetComponent <ManaCounter>().Mana >= skill.GetComponent <SkillProperty>().SkillCost)
                    {
                        GUI.enabled = true;
                    }
                    else
                    {
                        GUI.enabled = false;
                    }
                    Rect skillBtRect = CreateSkillBt(skill, seg);
                    if (skillBtRect.Contains(mousePos))
                    {
                        ShowSkillInfo(skill);
                    }
                    if (GUI.Button(skillBtRect, "", subStyle))
                    {
                        currentSelect.SkillUINetwork();
                        if (!skill.GetComponent <SkillProperty>().NeedToSelect)
                        {
                            skill.GetComponent <SkillProperty>().GetRealSkillRate();
                            skill.GetComponent <SkillProperty>().PassSkillRate = MapHelper.Success(skill.GetComponent <SkillProperty>().SkillRate);
                            skill.GetComponent <SkillProperty>().ActivateSkill();
                            currentSelect.player.GetComponent <ManaCounter>().Mana   -= skill.GetComponent <SkillProperty>().SkillCost;
                            CurrentChess.GetComponent <CharacterProperty>().Activated = true;
                            currentSelect.AnimStateNetWork(CurrentChess, AnimVault.AnimState.skill);
                            SubGuiFade = false;
                            TurnFinished(CurrentChess);
                            //update network
                            currentSelect.SkillCmdNetwork(CurrentChess, skill);
                        }
                        else
                        {
                            currentSelect.skillCommand(skill);
                        }
                    }
                    seg        += 1;
                    GUI.enabled = true;
                }
            }
        }
    }