Пример #1
0
        private static void SetupButtons(SG_Shop_Screen shop_screen)
        {
            try
            {
                Control.LogDebug(DInfo.ShopInterface, "- First Time enter. Start to setup");
                ShopScreen = shop_screen;
                ShopHelper = new ShopScreenHelper(ShopScreen);
                Buttons    = new Dictionary <string, StoreButton>();


                var store_button = ShopHelper.SystemStoreButtonHoldingObject;
                var radio_set    = ShopHelper.SystemStoreButtonHoldingObject.transform.parent.GetComponent <HBSRadioSet>();

                Control.LogDebug(DInfo.ShopInterface, "-- Create buttons");
                foreach (var shop in Control.Shops.OrderBy(i => i.SortOrder))
                {
                    Control.LogDebug(DInfo.ShopInterface, $"--- {shop.Name}");
                    var button = new StoreButton(store_button, shop);
                    Buttons.Add(shop.Name, button);
                }

                Control.LogDebug(DInfo.ShopInterface, "-- Hide original buttons");
                ShopHelper.SystemStoreButtonHoldingObject.SetActive(false);
                ShopHelper.FactionStoreButtonHoldingObject.SetActive(false);
                ShopHelper.BlackMarketStoreButtonHoldingObject.SetActive(false);

                Control.LogDebug(DInfo.ShopInterface, "-- Setup radio set");
                radio_set.ClearRadioButtons();

                foreach (var pair in Buttons)
                {
                    radio_set.AddButtonToRadioSet(pair.Value.Button);
                }

                radio_set.defaultButton = Buttons.Values.First().Button;

                Control.LogDebug(DInfo.ShopInterface, "-- Replace Buy/Sell buttons");

                ShopHelper.BuyTabButton.OnClicked.RemoveAllListeners();
                ShopHelper.SellTabButton.OnClicked.RemoveAllListeners();
                ShopHelper.BuyButton.OnClicked.RemoveAllListeners();

                ShopHelper.BuyTabButton.OnClicked.AddListener(OnBuyTabPress);
                ShopHelper.SellTabButton.OnClicked.AddListener(OnSellTabPress);
                ShopHelper.BuyButton.OnClicked.AddListener(OnBuySellPress);
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
            Control.LogDebug(DInfo.ShopInterface, "-- done!");
        }
Пример #2
0
        internal static void InitShopWindow(SG_Shop_Screen shop_screen)
        {
            Control.LogDebug(DInfo.ShopInterface, "Enter Shop Screen");
            if (shop_screen != ShopScreen)
            {
                SetupButtons(shop_screen);
            }

            StoreButton active = null;

            Control.LogDebug(DInfo.ShopInterface, "- SetupButtons");
            foreach (var button in Buttons.Values)
            {
                try
                {
                    var shop = button.Shop;
                    Control.LogDebug(DInfo.ShopInterface, $"-- [{shop.Name}]");
                    Control.LogDebug(DInfo.ShopInterface, $"--- Exists:{shop.Exists} CanUse:{shop.CanUse}");

                    if (shop.Exists)
                    {
                        button.ButtonHolder.SetActive(true);

                        if (shop is ISpriteIcon spr_icon)
                        {
                            Control.LogDebug(DInfo.ShopInterface, $"--- sprite image - set");
                            button.Button.SetImageAndText(spr_icon.Sprite, shop.TabText);
                            Control.LogDebug(DInfo.ShopInterface, $"--- set icon color to  r{shop.IconColor.r:0.00} g{shop.IconColor.g:0.00} b{shop.IconColor.b:0.00}");
                            button.Icon.color = shop.IconColor;
                        }
                        else if (shop is ITextIcon txt_icon)
                        {
                            var id = txt_icon.SpriteID;
                            Control.LogDebug(DInfo.ShopInterface, $"--- txt image - {id} - request");
                            Control.State.Sim.RequestItem <Sprite>(
                                id,
                                (sprite) =>
                            {
                                Control.LogDebug(DInfo.ShopInterface, $"--- button image {id} received ");
                                button.Button.SetImageAndText(sprite, shop.TabText);
                                Control.LogDebug(DInfo.ShopInterface, $"--- set icon color to  r{shop.IconColor.r:0.00} g{shop.IconColor.g:0.00} b{shop.IconColor.b:0.00}");
                                button.Icon.color = shop.IconColor;
                                Control.LogDebug(DInfo.ShopInterface, $"--- set");
                            },
                                BattleTechResourceType.Sprite
                                );
                        }

                        if (shop.CanUse)
                        {
                            button.Button.SetState(ButtonState.Enabled);
                            button.Overlay.SetActive(false);
                            if (active == null)
                            {
                                active = button;
                            }
                        }
                        else
                        {
                            button.Button.SetState(ButtonState.Disabled);
                            button.Overlay.SetActive(true);
                        }
                    }
                    else
                    {
                        button.ButtonHolder.SetActive(false);
                    }
                }
                catch (Exception e)
                {
                    Control.LogError(e);
                }
            }
            if (active != null)
            {
                active.Button.ForceRadioSetSelection();
                ActiveShop = active.Shop;
                ShopScreen.StartCoroutine(SwitchAtEndOfFrame());
            }
        }