Ejemplo n.º 1
0
        public static BuyItemWindow ShowBuyItemWindow(int buyItemId, int costItemId)
        {
            BuyItemWindow win = ShowWindow <BuyItemWindow>(Constants.StarcardWindowPath);

            win.MaskColor = new Color(0, 0, 0, 0.5f);
            win.InitWindowInfo(buyItemId, costItemId);
            return(win);
        }
        // <summary>
        // 显示
        // </summary>
        // 只显示价格为正的产品(价格为零的是非卖品)
        public void Show(Shop shop)
        {
            AllSellButton.Visibility = System.Windows.Visibility.Collapsed;
            Type      = ShopType.SHOP;
            this.shop = shop;
            UIHost uiHost = RuntimeData.Instance.gameEngine.uihost;

            uiHost.RightClickCallback                = null;
            uiHost.shopPanel.SuggestText.Text        = "右键快捷购买";
            uiHost.shopPanel.myItemsPanel.Visibility = Visibility.Collapsed;
            Dictionary <ShopItem, int> sales = shop.GetAvaliableSales();

            RootPanel.Children.Clear();
            uiHost.itemSelectPanel.Show(RuntimeData.Instance.Items);//刷新物品栏
            this.money.Text   = RuntimeData.Instance.Money.ToString();
            this.yuanbao.Text = RuntimeData.Instance.YuanBao.ToString();

            foreach (var sale in sales.Keys)
            {
                Item item     = sale.Item;
                int  maxLimit = sales[sale];
                if (ItemTypeCombo.SelectedItem.ToString() == "武器" && (item.Type != (int)ItemType.Weapon))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "消耗品" && (item.Type != (int)ItemType.Costa))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "防具" && (item.Type != (int)ItemType.Armor))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "饰品" && (item.Type != (int)ItemType.Accessories))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "经书" && (item.Type != (int)ItemType.Book))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "任务物品" && (item.Type != (int)ItemType.Mission))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "技能书" && (item.Type != (int)ItemType.TalentBook) && item.Type != (int)ItemType.Upgrade)
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "残章" && (item.Type != (int)ItemType.Canzhang))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "特殊物品" && (item.Type != (int)ItemType.Special))
                {
                    continue;
                }

                ItemUnit c = new ItemUnit();
                c.image.Source = item.Pic;
                c.ItemName     = item.Name;
                c.Margin       = new Thickness(2, 2, 2, 5);
                if (maxLimit != -1)
                {
                    c.count.Text = maxLimit.ToString();
                }
                else
                {
                    c.count.Text = "";
                }
                string   info  = item.ToString();
                int      price = sale.Price;
                ShopItem tmp   = sale;
                c.MouseRightButtonUp += (s, e) =>
                {
                    if (uiHost.selectPanel.Visibility == System.Windows.Visibility.Visible)
                    {
                        return;
                    }
                    if (tmp.YuanBao == -1)
                    {
                        if (RuntimeData.Instance.Money >= price)
                        {
                            RuntimeData.Instance.Money -= price;
                            RuntimeData.Instance.Items.Add(tmp.Item.Clone());
                            AudioManager.PlayEffect(ResourceManager.Get("音效.装备"));
                            this.money.Text = RuntimeData.Instance.Money.ToString();
                            shop.BuyItem(tmp.Name);
                            this.Show(shop);
                        }
                        else
                        {
                            uiHost.dialogPanel.ShowDialog("汉家松鼠", "你的金钱不足!", null);
                        }
                    }
                    else
                    {
                        if (RuntimeData.Instance.YuanBao >= tmp.YuanBao)
                        {
                            RuntimeData.Instance.YuanBao -= tmp.YuanBao;
                            RuntimeData.Instance.Items.Add(tmp.Item.Clone());
                            AudioManager.PlayEffect(ResourceManager.Get("音效.装备"));
                            shop.BuyItem(tmp.Name);
                            this.Show(shop);
                        }
                        else
                        {
                            uiHost.dialogPanel.ShowDialog("汉家松鼠", "你的元宝不足!", null);
                        }
                    }
                    e.Handled = true;
                };
                c.MouseLeftButtonUp += (s, e) =>
                {
                    BuyItemWindow win = new BuyItemWindow();
                    win.Bind(tmp.Item, "购买物品", (number) =>
                    {
                        if (tmp.YuanBao == -1)
                        {
                            if (RuntimeData.Instance.Money >= price * number)
                            {
                                RuntimeData.Instance.Money -= price * number;
                                for (int i = 0; i < number; ++i)
                                {
                                    RuntimeData.Instance.Items.Add(tmp.Item.Clone());
                                }
                                AudioManager.PlayEffect(ResourceManager.Get("音效.装备"));
                                shop.BuyItem(tmp.Name, number);
                                this.Show(shop);
                            }
                            else
                            {
                                uiHost.dialogPanel.ShowDialog("汉家松鼠", "你的金钱不足!", null);
                            }
                        }
                        else
                        {
                            if (RuntimeData.Instance.YuanBao >= tmp.YuanBao * number)
                            {
                                RuntimeData.Instance.YuanBao -= tmp.YuanBao * number;
                                for (int i = 0; i < number; ++i)
                                {
                                    RuntimeData.Instance.Items.Add(tmp.Item.Clone());
                                }
                                AudioManager.PlayEffect(ResourceManager.Get("音效.装备"));
                                shop.BuyItem(tmp.Name, number);
                                this.Show(shop);
                            }
                            else
                            {
                                uiHost.dialogPanel.ShowDialog("汉家松鼠", "你的元宝不足!", null);
                            }
                        }
                    }, maxLimit);
                    win.Show();
                };



                RichTextBox rtb = item.GenerateTooltip();
                (rtb.Blocks[0] as Paragraph).Inlines.Add(new LineBreak());
                (rtb.Blocks[0] as Paragraph).Inlines.Add(new LineBreak());
                if (sale.YuanBao != -1)
                {
                    (rtb.Blocks[0] as Paragraph).Inlines.Add(new Run()
                    {
                        Text = "价格:" + tmp.YuanBao.ToString() + "个元宝", FontSize = 12, FontWeight = FontWeights.Bold
                    });
                }
                else
                {
                    (rtb.Blocks[0] as Paragraph).Inlines.Add(new Run()
                    {
                        Text = "价格:" + price.ToString() + "两白银", FontSize = 12, FontWeight = FontWeights.Bold
                    });
                }

                ToolTipService.SetToolTip(c, rtb);
                RootPanel.Children.Add(c);
            }

            this.Visibility = System.Windows.Visibility.Visible;
        }
        // <summary>
        // 显示
        // </summary>
        // 只显示价格为正的产品(价格为零的是非卖品)
        public void Show(SellShop shop)
        {
            AllSellButton.Visibility = System.Windows.Visibility.Visible;
            Type     = ShopType.SELL;
            sellShop = shop;
            UIHost uiHost = RuntimeData.Instance.gameEngine.uihost;

            uiHost.RightClickCallback = null;
            uiHost.shopPanel.myItemsPanel.Visibility = Visibility.Collapsed;
            uiHost.shopPanel.SuggestText.Text        = "右键快捷出售";
            Dictionary <Item, int> items = shop.GetAvaliableItems();
            int count = 0;

            RootPanel.Children.Clear();
            this.money.Text   = RuntimeData.Instance.Money.ToString();
            this.yuanbao.Text = RuntimeData.Instance.YuanBao.ToString();

            List <string> visitedItem = new List <string>();

            foreach (var item in items.Keys)
            {
                if (ItemTypeCombo.SelectedItem.ToString() == "武器" && (item.Type != (int)ItemType.Weapon))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "消耗品" && (item.Type != (int)ItemType.Costa))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "防具" && (item.Type != (int)ItemType.Armor))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "饰品" && (item.Type != (int)ItemType.Accessories))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "经书" && (item.Type != (int)ItemType.Book))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "任务物品" && (item.Type != (int)ItemType.Mission))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "技能书" && (item.Type != (int)ItemType.TalentBook) && item.Type != (int)ItemType.Upgrade)
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "残章" && (item.Type != (int)ItemType.Canzhang))
                {
                    continue;
                }
                if (ItemTypeCombo.SelectedItem.ToString() == "特殊物品" && (item.Type != (int)ItemType.Special))
                {
                    continue;
                }
                int itemCount = 1;
                //如果不是装备,则层叠
                if (!(item.Type == (int)ItemType.Armor || item.Type == (int)ItemType.Accessories || item.Type == (int)ItemType.Weapon))
                {
                    if (visitedItem.Contains(item.Name))
                    {
                        continue;
                    }
                    itemCount = items.Keys.Count(p => p.Name == item.Name);
                    visitedItem.Add(item.Name);
                }

                if (count > 5)
                {
                    count = 0;
                }

                ItemUnit c = new ItemUnit();
                c.BindItem(item);
                c.ItemCount = itemCount;
                c.Margin    = new Thickness(2, 2, 2, 5);
                string info  = item.ToString();
                int    price = items[item];
                Item   tmp   = item;
                c.MouseRightButtonUp += (s, e) =>
                {
                    if (uiHost.selectPanel.Visibility == System.Windows.Visibility.Visible)
                    {
                        return;
                    }
                    RuntimeData.Instance.Money += price;
                    RuntimeData.Instance.Items.Remove(tmp);
                    AudioManager.PlayEffect(ResourceManager.Get("音效.装备"));
                    this.money.Text = RuntimeData.Instance.Money.ToString();
                    //uiHost.itemSelectPanel.Show(RuntimeData.Instance.Items);//刷新物品栏
                    this.Show(shop);
                    e.Handled = true;
                };
                c.MouseLeftButtonUp += (s, e) =>
                {
                    //uiHost.selectPanel.CallBack = () =>
                    //{
                    //    if (uiHost.selectPanel.currentSelection == "yes")
                    //    {
                    //        RuntimeData.Instance.Money += price;
                    //        RuntimeData.Instance.Items.Remove(tmp);
                    //        AudioManager.PlayEffect(ResourceManager.Get("音效.装备"));
                    //        this.money.Text = RuntimeData.Instance.Money.ToString();
                    //        //uiHost.itemSelectPanel.Show(RuntimeData.Instance.Items);//刷新物品栏
                    //        this.Show(shop);
                    //    }
                    //};
                    //uiHost.selectPanel.title.Text = "确定出售?";
                    //uiHost.selectPanel.yes.Content = "出售";
                    //uiHost.selectPanel.no.Content = "取消";
                    //uiHost.selectPanel.ShowSelection();
                    BuyItemWindow win = new BuyItemWindow();
                    win.Bind(tmp, "出售物品", (number) =>
                    {
                        RuntimeData.Instance.Money += price * number;
                        RuntimeData.Instance.RemoveItem(tmp.Name, number);
                        AudioManager.PlayEffect(ResourceManager.Get("音效.装备"));
                        this.Show(shop);
                    }, itemCount);
                    win.Show();
                    e.Handled = true;
                };
                //ToolTipService.SetToolTip(c,info + "\n价格:" + price.ToString() + "两白银");
                RichTextBox rtb = item.GenerateTooltip();
                (rtb.Blocks[0] as Paragraph).Inlines.Add(new LineBreak());
                (rtb.Blocks[0] as Paragraph).Inlines.Add(new LineBreak());
                (rtb.Blocks[0] as Paragraph).Inlines.Add(new Run()
                {
                    Text = "价格:" + price.ToString() + "两白银", FontSize = 12, FontWeight = FontWeights.Bold
                });
                ToolTipService.SetToolTip(c, rtb);

                RootPanel.Children.Add(c);
                count++;
            }

            this.Visibility = System.Windows.Visibility.Visible;
        }