Esempio n. 1
0
 public static void RegisterShop(IShopDescriptor shop, IEnumerable <string> refresh_events)
 {
     if (register_shop(shop) && refresh_events != null)
     {
         foreach (var name in refresh_events)
         {
             AddToEvent(name, shop);
         }
     }
 }
        private static void FillInData(IShopDescriptor shop)
        {
            Control.LogDebug(DInfo.ShopInterface, $"- fill data");
            if (shop == null)
            {
                return;
            }

            ShopHelper.FillInWidget(shop);
        }
        public StoreButton(GameObject store_button, IShopDescriptor shop)
        {
            Shop         = shop;
            ButtonHolder = GameObject.Instantiate(store_button);
            ButtonHolder.transform.SetParent(store_button.transform.parent);

            Button  = ButtonHolder.transform.GetChild(0).GetComponent <HBSDOTweenStoreTypeToggle>();
            Overlay = ButtonHolder.transform.GetChild(1).gameObject;
            Button.OnClicked.RemoveAllListeners();
            Button.OnClicked.AddListener(OnClick);
            Icon = Button.transform.Find("tab_icon").GetComponent <Image>();
        }
Esempio n. 4
0
        internal static void AddToEvent(string name, IShopDescriptor shop)
        {
            var n = name.ToLower();

            if (!RefreshEvents.ContainsKey(n))
            {
                LogError($"Unknown Refresh event {name}, please check if registred");
                RegisterRefreshEvent(name);
            }

            RefreshEvents[n].Add(shop);
        }
        public static void RefreshColors(IShopDescriptor shop)
        {
            if (shop != null)
            {
                var color = shop.ShopColor;
                foreach (var crtrack in ShopHelper.ColorAffectors)
                {
                    crtrack.OverrideWithColor(color);
                }

                color.a *= SG_Shop_Screen.CENTER_BG_ALPHASCALAR;
                ShopHelper.LargeBGFillColor.OverrideWithColor(color);
            }
        }
        internal static void TabSelected(IShopDescriptor shop)
        {
            Control.LogDebug(DInfo.TabSwitch, $"Pressed {shop.Name}");
            ActiveShop = shop;

            try
            {
                SwitchAndInit(shop);
                RefreshColors(shop);
                FillInData(shop);
            }
            catch (Exception e)
            {
                Control.LogError("Error while switching shop", e);
            }
        }
        private static void SwitchAndInit(IShopDescriptor shop)
        {
            Control.LogDebug(DInfo.TabSwitch, $"- fill shop");
            if (shop == null)
            {
                return;
            }

            if (shop is IDefaultShop def_shop)
            {
                Control.LogDebug(DInfo.TabSwitch, $"-- IDefaultShop");
                ShopScreen.ChangeToBuy(def_shop.ShopToUse, true);
            }
            else if (shop is IListShop l_shop)
            {
                ShopHelper.ChangeToBuy(l_shop, true);
            }
        }
Esempio n. 8
0
 public static void RegisterShop(IShopDescriptor shop)
 {
     if (register_shop(shop))
     {
         if (shop.RefreshOnMonthChange)
         {
             AddToEvent("MonthEnd", shop);
         }
         if (shop.RefreshOnOwnerChange)
         {
             AddToEvent("OwnerChange", shop);
         }
         if (shop.RefreshOnSystemChange)
         {
             AddToEvent("SystemChange", shop);
         }
     }
 }
Esempio n. 9
0
        private static bool register_shop(IShopDescriptor shop)
        {
            if (shop == null)
            {
                return(false);
            }

            Log($"Shop [{shop.Name}] registred");
            Shops.Add(shop);

            if (shop is ISellShop ss)
            {
                SaleShops.Add(ss);
                SaleShops.Sort((i1, i2) => i1.SellPriority.CompareTo(i2.SellPriority));
            }

            return(true);
        }
        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());
            }
        }