void setUpBuyButton(GameShopCell cell, int row)
    {
        GameFairyModel cellData = fairiesDataSource.dataArray[row];

        cell.fairyButton.onClick.RemoveAllListeners();
        cell.fairyButton.onClick.AddListener(() => {
            if (_playerData.playerFairies.Contains(row) == false)
            {
                if (_playerData.playerScore >= cellData.fairyPrice)
                {
                    _playerData.playerFairies.Add(row);
                    _playerData.playerScore -= cellData.fairyPrice;
                    uncheckPreviousFairy();
                    selectFairyOnIndexWithCell(row, cell);
                    _playerData.savePlayerData();
                    cell.price.gameObject.SetActive(false);

                    GameAnaliticsController analiticsController = GameObject.FindObjectOfType <GameAnaliticsController>();
                    analiticsController.buyFairyPressed();
                }
                else
                {
                    inAppPurchasesPopUp.SetActive(true);
                }
            }
            else
            {
                uncheckPreviousFairy();
                selectFairyOnIndexWithCell(row, cell);
            }
        });
    }
    void setUpDescription(GameShopCell cell, int row)
    {
        GameFairyModel cellData = fairiesDataSource.dataArray[row];

        cell.descriptionDamageTime.text   = cellData.fairyCreateSlowBonusTime.ToString();
        cell.descriptionSlowdownTime.text = cellData.fairyCreateDamageBonusTime.ToString();
    }
    void uncheckPreviousFairy()
    {
        if (_lastSelectedFairyIndex >= 0)
        {
            GameShopCell selectedFairyCell = m_tableView.GetCellAtRow(_lastSelectedFairyIndex) as GameShopCell;

            if (selectedFairyCell != null)
            {
                selectedFairyCell.selectFairyToggle.gameObject.SetActive(false);
            }
        }
    }
    void setUpPrice(GameShopCell cell, int row)
    {
        GameFairyModel cellData = fairiesDataSource.dataArray[row];

        if (_playerData.playerFairies.Contains(row) == true)
        {
            cell.price.gameObject.SetActive(false);
        }
        else
        {
            cell.price.gameObject.SetActive(true);
            cell.price.text = cellData.fairyPrice.ToString();
        }
    }
    public TableViewCell GetCellForRowInTableView(TableView tableView, int row)
    {
        GameShopCell cell = tableView.GetReusableCell(m_cellPrefab.reuseIdentifier) as GameShopCell;

        if (cell == null)
        {
            cell = (GameShopCell)GameObject.Instantiate(m_cellPrefab);
        }

        setUpPrice(cell, row);
        setUpDescription(cell, row);
        setUpBuyButton(cell, row);
        setUpToggle(cell, row);
        setUpFairyImage(cell, row);

        return(cell);
    }
    void setUpToggle(GameShopCell cell, int row)
    {
        if (_playerData.playerFairies.Contains(row) == false)
        {
            cell.selectFairyToggle.gameObject.SetActive(false);
            return;
        }

        if (_lastSelectedFairyIndex == row)
        {
            cell.selectFairyToggle.gameObject.SetActive(true);
        }
        else
        {
            cell.selectFairyToggle.gameObject.SetActive(false);
        }
    }
Ejemplo n.º 7
0
        public void UpdateShop()
        {
            List <GameShopItem> ShopList;

            if (Search.TextBox.Text != "")
            {
                ShopList = GameScene.GameShopInfoList.Where(f => f.Info.FriendlyName.ToLower().Contains(Search.TextBox.Text.ToLower())).ToList();
            }
            else
            {
                ShopList = GameScene.GameShopInfoList;
            }

            for (int i = 0; i < Grid.Length; i++)
            {
                if (Grid[i] != null)
                {
                    Grid[i].Dispose();
                }
                Grid[i].Item = null;
            }
            ;


            filteredShop.Clear();

            for (int i = 0; i < ShopList.Count; i++)
            {
                if (ShopList[i].Class == ClassFilter || ShopList[i].Class == "显示所有" || ClassFilter == "显示所有")
                {
                    if (ShopList[i].Category == TypeFilter || TypeFilter == "显示所有")
                    {
                        if (SectionFilter == "显示所有" || SectionFilter == "热门" && ShopList[i].TopItem || SectionFilter == "打折" && ShopList[i].Deal || SectionFilter == "新品" && ShopList[i].Date > DateTime.Now.AddDays(-7))
                        {
                            filteredShop.Add(ShopList[i]);
                        }
                    }
                }
            }


            maxPage = ((decimal)filteredShop.Count / 8);
            maxPage = Math.Ceiling(maxPage);
            if (maxPage < 1)
            {
                maxPage = 1;
            }

            PageNumberLabel.Text = (Page + 1) + " / " + maxPage;

            int maxIndex = filteredShop.Count - 1;

            if (StartIndex > maxIndex)
            {
                StartIndex = maxIndex;
            }
            if (StartIndex < 0)
            {
                StartIndex = 0;
            }

            filteredShop = filteredShop.OrderBy(e => e.Info.FriendlyName).ToList();

            for (int i = 0; i < Grid.Length; i++)
            {
                if (i + StartIndex >= filteredShop.Count)
                {
                    break;
                }

                if (Grid[i] != null)
                {
                    Grid[i].Dispose();
                }

                Grid[i] = new GameShopCell
                {
                    Visible  = true,
                    Item     = filteredShop[i + StartIndex],
                    Size     = new Size(125, 146),
                    Location = i < 4 ? new Point(152 + (i * 132), 115) : new Point(152 + ((i - 4) * 132), 275),
                    Parent   = this,
                };
            }

            GameScene.Scene.GameShopDialog.Viewer.Visible = false;
        }
Ejemplo n.º 8
0
        public GameShopDialog()
        {
            GameScene.GameShopInfoList.Clear();
            Index    = 749;
            Library  = Libraries.Title;
            Movable  = true;
            Location = Center;
            Sort     = true;

            TitleLabel = new MirImageControl
            {
                Index    = 26,
                Library  = Libraries.Title,
                Location = new Point(18, 9),
                Parent   = this
            };

            Grid = new GameShopCell[4 * 2];
            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    int idx = 4 * y + x;
                    Grid[idx] = new GameShopCell
                    {
                        Size    = new Size(125, 146),
                        Visible = true,
                        Parent  = this,
                    };
                }
            }

            CloseButton = new MirButton
            {
                HoverIndex   = 361,
                Index        = 360,
                Location     = new Point(671, 4),
                Library      = Libraries.Prguse2,
                Parent       = this,
                PressedIndex = 362,
                Sound        = SoundList.ButtonA,
            };
            CloseButton.Click += (o, e) => Hide();

            totalGold = new MirLabel
            {
                Size       = new Size(100, 20),
                DrawFormat = TextFormatFlags.RightToLeft | TextFormatFlags.Right,

                Location   = new Point(123, 449),
                Parent     = this,
                NotControl = true,
                Font       = new Font(Settings.FontName, 9F),
            };
            totalCredits = new MirLabel
            {
                Size       = new Size(100, 20),
                DrawFormat = TextFormatFlags.RightToLeft | TextFormatFlags.Right,
                Location   = new Point(5, 449),
                Parent     = this,
                NotControl = true,
                Font       = new Font(Settings.FontName, 9F)
            };

            UpButton = new MirButton
            {
                Index        = 197,
                HoverIndex   = 198,
                PressedIndex = 199,
                Library      = Libraries.Prguse2,
                Parent       = this,
                Size         = new Size(16, 14),
                Location     = new Point(120, 103),
                Sound        = SoundList.ButtonA,
                Visible      = true
            };
            UpButton.Click += (o, e) =>
            {
                if (CStartIndex <= 0)
                {
                    return;
                }

                CStartIndex--;

                SetCategories();
                UpdatePositionBar();
            };

            DownButton = new MirButton
            {
                Index        = 207,
                HoverIndex   = 208,
                Library      = Libraries.Prguse2,
                PressedIndex = 209,
                Parent       = this,
                Size         = new Size(16, 14),
                Location     = new Point(120, 421),
                Sound        = SoundList.ButtonA,
                Visible      = true
            };
            DownButton.Click += (o, e) =>
            {
                if (CStartIndex + 22 >= CategoryList.Count)
                {
                    return;
                }

                CStartIndex++;

                SetCategories();
                UpdatePositionBar();
            };

            PositionBar = new MirButton
            {
                Index        = 205,
                HoverIndex   = 206,
                PressedIndex = 206,
                Library      = Libraries.Prguse2,
                Location     = new Point(120, 117),
                Parent       = this,
                Movable      = true,
                Sound        = SoundList.None,
                Visible      = true
            };
            PositionBar.OnMoving += PositionBar_OnMoving;



            FilterBackground = new MirImageControl
            {
                Index    = 769,
                Library  = Libraries.Title,
                Location = new Point(11, 102),
                Parent   = this,
            };
            FilterBackground.MouseWheel += FilterScrolling;

            Search = new MirTextBox
            {
                BackColour   = Color.FromArgb(4, 4, 4),
                ForeColour   = Color.White,
                Parent       = this,
                Size         = new Size(140, 16),
                Location     = new Point(540, 69),
                Font         = new Font(Settings.FontName, 9F),
                MaxLength    = 23,
                CanLoseFocus = true,
            };
            Search.TextBox.KeyUp += (o, e) =>
            {
                GetCategories();
            };

            allItems = new MirButton
            {
                Index    = 770,
                Library  = Libraries.Title,
                Location = new Point(138, 68),
                Visible  = true,
                Parent   = this,
                Sound    = SoundList.ButtonA,
            };
            allItems.Click += (o, e) =>
            {
                SectionFilter = "显示所有";
                ResetTabs();
                GetCategories();
            };
            topItems = new MirButton
            {
                Index    = 776,
                Library  = Libraries.Title,
                Location = new Point(209, 68),
                Visible  = true,
                Parent   = this,
                Sound    = SoundList.ButtonA,
            };
            topItems.Click += (o, e) =>
            {
                SectionFilter = "热消";
                ResetTabs();
                GetCategories();
            };
            Deals = new MirButton
            {
                Index    = 772,
                Library  = Libraries.Title,
                Location = new Point(280, 68),
                Visible  = true,
                Parent   = this,
                Sound    = SoundList.ButtonA,
            };
            Deals.Click += (o, e) =>
            {
                SectionFilter = "打折";
                ResetTabs();
                GetCategories();
            };
            New = new MirButton
            {
                Index    = 774,
                Library  = Libraries.Title,
                Location = new Point(351, 68),
                Visible  = false,
                Parent   = this,
                Sound    = SoundList.ButtonA,
            };
            New.Click += (o, e) =>
            {
                SectionFilter = "新品";
                ResetTabs();
                New.Index = 775;
                GetCategories();
            };


            ALL = new MirButton
            {
                Index        = 751,
                HoverIndex   = 752,
                PressedIndex = 753,
                Library      = Libraries.Title,
                Location     = new Point(539, 37),
                Visible      = true,
                Parent       = this,
            };
            ALL.Click += (o, e) =>
            {
                ClassFilter = "显示所有";
                TypeFilter  = "显示所有";
                GetCategories();
                ResetClass();
            };
            War = new MirButton
            {
                Index        = 754,
                HoverIndex   = 755,
                PressedIndex = 756,
                Library      = Libraries.Title,
                Location     = new Point(568, 38),
                Visible      = true,
                Parent       = this,
            };
            War.Click += (o, e) =>
            {
                ClassFilter = "战士";
                TypeFilter  = "显示所有";
                GetCategories();
                ResetClass();
            };
            Sin = new MirButton
            {
                Index        = 757,
                HoverIndex   = 758,
                PressedIndex = 759,
                Library      = Libraries.Title,
                Location     = new Point(591, 38),
                Visible      = true,
                Parent       = this,
            };
            Sin.Click += (o, e) =>
            {
                ClassFilter = "刺客";
                TypeFilter  = "显示所有";
                GetCategories();
                ResetClass();
            };
            Tao = new MirButton
            {
                Index        = 760,
                HoverIndex   = 761,
                PressedIndex = 762,
                Library      = Libraries.Title,
                Location     = new Point(614, 38),
                Visible      = true,
                Parent       = this,
            };
            Tao.Click += (o, e) =>
            {
                ClassFilter = "道士";
                TypeFilter  = "显示所有";
                GetCategories();
                ResetClass();
            };
            Wiz = new MirButton
            {
                Index        = 763,
                HoverIndex   = 764,
                PressedIndex = 765,
                Library      = Libraries.Title,
                Location     = new Point(637, 38),
                Visible      = true,
                Parent       = this,
            };
            Wiz.Click += (o, e) =>
            {
                ClassFilter = "法师";
                TypeFilter  = "显示所有";
                GetCategories();
                ResetClass();
            };
            Arch = new MirButton
            {
                Index        = 766,
                HoverIndex   = 767,
                PressedIndex = 768,
                Library      = Libraries.Title,
                Location     = new Point(660, 38),
                Visible      = true,
                Parent       = this,
            };
            Arch.Click += (o, e) =>
            {
                ClassFilter = "弓箭手";
                TypeFilter  = "显示所有";
                GetCategories();
                ResetClass();
            };

            PageNumberLabel = new MirLabel
            {
                Text       = "",
                Parent     = this,
                Size       = new Size(83, 17),
                Location   = new Point(597, 446),
                DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
                Font       = new Font(Settings.FontName, 9F),
            };

            PreviousButton = new MirButton
            {
                Index        = 240,
                HoverIndex   = 241,
                PressedIndex = 242,
                Library      = Libraries.Prguse2,
                Parent       = this,
                Location     = new Point(600, 448),
                Sound        = SoundList.ButtonA,
            };
            PreviousButton.Click += (o, e) =>
            {
                Page--;
                if (Page < 0)
                {
                    Page = 0;
                }
                StartIndex = Grid.Length * Page;

                UpdateShop();
            };

            NextButton = new MirButton
            {
                Index        = 243,
                HoverIndex   = 244,
                PressedIndex = 245,
                Library      = Libraries.Prguse2,
                Parent       = this,
                Location     = new Point(660, 448),
                Sound        = SoundList.ButtonA,
            };
            NextButton.Click += (o, e) =>
            {
                Page++;
                if ((Page + 1) > maxPage)
                {
                    Page--;
                }
                StartIndex = Grid.Length * Page;
                UpdateShop();
            };

            for (int i = 0; i < Filters.Length; i++)
            {
                Filters[i] = new MirLabel
                {
                    Parent     = this,
                    Size       = new Size(90, 20),
                    Location   = new Point(15, 103 + (15 * i)),
                    Text       = "Testing - " + i.ToString(),
                    ForeColour = Color.Gray,
                    Font       = new Font(Settings.FontName, 9F),
                };
                Filters[i].Click += (o, e) =>
                {
                    MirLabel lab = (MirLabel)o;
                    TypeFilter = lab.Text;
                    Page       = 0;
                    StartIndex = 0;
                    UpdateShop();
                    for (int p = 0; p < Filters.Length; p++)
                    {
                        if (Filters[p].Text == lab.Text)
                        {
                            Filters[p].ForeColour = Color.FromArgb(230, 200, 160);
                        }
                        else
                        {
                            Filters[p].ForeColour = Color.Gray;
                        }
                    }
                };
                Filters[i].MouseEnter += (o, e) =>
                {
                    MirLabel lab = (MirLabel)o;
                    for (int p = 0; p < Filters.Length; p++)
                    {
                        if (Filters[p].Text == lab.Text && Filters[p].ForeColour != Color.FromArgb(230, 200, 160))
                        {
                            Filters[p].ForeColour = Color.FromArgb(160, 140, 110);
                        }
                    }
                };
                Filters[i].MouseLeave += (o, e) =>
                {
                    MirLabel lab = (MirLabel)o;
                    for (int p = 0; p < Filters.Length; p++)
                    {
                        if (Filters[p].Text == lab.Text && Filters[p].ForeColour != Color.FromArgb(230, 200, 160))
                        {
                            Filters[p].ForeColour = Color.Gray;
                        }
                    }
                };
                Filters[i].MouseWheel += FilterScrolling;
            }

            Viewer = new GameShopViewer();
        }
    void setUpFairyImage(GameShopCell aCell, int aIndex)
    {
        GameFairyModel cellData = fairiesDataSource.dataArray[aIndex];

        aCell.fairyImage.sprite = Sprite.Create(cellData.fairyTexture, new Rect(0, 0, cellData.fairyTexture.width, cellData.fairyTexture.height), new Vector2(0.5f, 0.5f));
    }
 void selectFairyOnIndexWithCell(int aIndex, GameShopCell aCell)
 {
     _playerData.selectedFairyIndex = aIndex;
     _lastSelectedFairyIndex        = aIndex;
     aCell.selectFairyToggle.gameObject.SetActive(true);
 }