Пример #1
0
    public void HandleEvent(UIControl control, int command, float wparam, float lparam)
    {
        if (control == returnButton)
        {
            AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>());
            GameApp.GetInstance().Save();
            Hide();
            GameObject.Find("ArenaMenuUI").GetComponent <ArenaMenuUI>().GetPanel(MenuName.ARENA).Show();
        }
        else if (control == weaponScroller)
        {
            int index = (int)wparam;
            //scroller at
            if (command == (int)UIImageScroller.Command.ScrollSelect)
            {
                currentSelectionWeaponIndex = gameState.GetWeaponByOwnedIndex(index);
                UpdateWeaponInfo();
            }
            // long press
            else if (command == (int)UIImageScroller.Command.PressSelect)
            {
                if (gameState != null)
                {
                    Material weaponIconMaterial = UIResourceMgr.GetInstance().GetMaterial("Weapons3");
                    Rect     rect = WeaponsLogoTexturePosition.GetWeaponIconTextureRect(currentSelectionWeaponIndex);
                    selectionImage.SetTexture(weaponIconMaterial, rect, AutoRect.AutoSize(rect));
                    selectionImage.Rect = weaponScroller.GetCenterRect();
                }
            }
            //long end
            else if (command == (int)UIImageScroller.Command.PressEnd)
            {
                selectionImage.Rect = new Rect(-1000, -1000, 200, 200);
                for (int i = 0; i < SELECTION_NUM; i++)
                {
                    if (selectionRect[i].Contains(new Vector2(wparam, lparam)))
                    {
                        SelectWeapon(currentSelectionWeaponIndex, i);
                        break;
                    }
                }
            }
            //drag move
            else if (command == (int)UIImageScroller.Command.DragMove)
            {
                selectionImage.Rect = new Rect(wparam - 438 * 1.2f / 2, lparam - 192 * 1.2f / 2, 438 * 1.2f, 192 * 1.2f);
            }
        }
        else if (control == battleWeaponGrid)
        {
            if (command == (int)UIDragGrid.Command.DragOutSide)
            {
                int i = (int)wparam;
                if (InBattleWeaponCount() > 1)
                {
                    int weaponID = rectToWeaponMap[i];
                    if (weaponID != -1)
                    {
                        weaponList[weaponID].IsSelectedForBattle = false;

                        rectToWeaponMap[i] = -1;
                        battleWeaponGrid.HideGridTexture(i);
                        avatarFrame.ChangeAvatar(GameApp.GetInstance().GetGameState().Avatar);
                    }
                }
                else
                {
                    battleWeaponGrid.SetGridTexturePosition(i, i);
                }
            }
            else if (command == (int)UIDragGrid.Command.DragExchange)
            {
                int i = (int)wparam;
                int j = (int)lparam;

                int temp = rectToWeaponMap[i];
                rectToWeaponMap[i] = rectToWeaponMap[j];
                rectToWeaponMap[j] = temp;

                if (rectToWeaponMap[i] != -1)
                {
                    Material weaponIconMaterial = UIResourceMgr.GetInstance().GetMaterial("Weapons3");
                    Rect     rect = WeaponsLogoTexturePosition.GetWeaponIconTextureRect(rectToWeaponMap[i]);
                    battleWeaponGrid.SetGridTexture(i, weaponIconMaterial, rect);


                    battleWeaponGrid.SetGridTexturePosition(i, i);
                }
                else
                {
                    battleWeaponGrid.HideGridTexture(i);
                }

                if (rectToWeaponMap[j] != -1)
                {
                    Material weaponIconMaterial = UIResourceMgr.GetInstance().GetMaterial("Weapons3");
                    Rect     rect = WeaponsLogoTexturePosition.GetWeaponIconTextureRect(rectToWeaponMap[j]);
                    battleWeaponGrid.SetGridTexture(j, weaponIconMaterial, rect);


                    battleWeaponGrid.SetGridTexturePosition(j, j);
                }
                else
                {
                    battleWeaponGrid.HideGridTexture(j);
                }
                avatarFrame.ChangeAvatar(GameApp.GetInstance().GetGameState().Avatar);
            }
        }
        else if (control == getMoreMoneyButton)
        {
            AudioPlayer.PlayAudio(ArenaMenuUI.GetInstance().GetComponent <AudioSource>());
            Hide();
            ShopUI shopUI = GameObject.Find("ArenaMenuUI").GetComponent <ArenaMenuUI>().GetPanel(MenuName.SHOP) as ShopUI;
            shopUI.SetFromPanel(this);
            shopUI.Show();
        }
    }