Пример #1
0
        private void OnLoadAutoCraftGrid(DisplayData data)
        {
            try
            {
                if (_isBeingDestroyed || _mono == null || _mono?.Manager == null)
                {
                    return;
                }

                _autoCraftingGrid.ClearPage();

                var grouped = BaseManager.Crafts;

                if (grouped == null)
                {
                    QuickLogger.Debug("Grouped returned null canceling operation");
                    return;
                }

                //if (!string.IsNullOrEmpty(_toCurrentSearchString?.Trim()))
                //{
                //    grouped = grouped.Where(p => p.Value.UnitID.StartsWith(_toCurrentSearchString.Trim(), StringComparison.OrdinalIgnoreCase)).ToDictionary(p => p.Key, p => p.Value);
                //}

                if (data.EndPosition > grouped.Count)
                {
                    data.EndPosition = grouped.Count;
                }

                if (data.ItemsGrid?.transform == null)
                {
                    QuickLogger.Debug("Grid returned null canceling operation");
                    return;
                }

                for (int i = data.StartPosition; i < data.EndPosition; i++)
                {
                    var craft = grouped.ElementAt(i);

                    GameObject buttonPrefab = Instantiate(data.ItemsPrefab);

                    if (buttonPrefab == null || data.ItemsGrid == null)
                    {
                        if (buttonPrefab != null)
                        {
                            QuickLogger.Debug("Destroying Tab", true);
                            Destroy(buttonPrefab);
                        }
                        return;
                    }

                    buttonPrefab.transform.SetParent(data.ItemsGrid.transform, false);

                    uGUI_Icon icon = InterfaceHelpers.FindGameObject(buttonPrefab, "Icon").AddComponent <uGUI_Icon>();
                    icon.sprite = SpriteManager.Get(craft.TechType);

                    var deleteBTN = InterfaceHelpers.FindGameObject(buttonPrefab, "Delete")?.AddComponent <InterfaceButton>();
                    if (deleteBTN != null)
                    {
                        deleteBTN.BtnName        = "AutoCraftItemDeleteBTN";
                        deleteBTN.TextLineOne    = AuxPatchers.Delete();
                        deleteBTN.STARTING_COLOR = _startColor;
                        deleteBTN.HOVER_COLOR    = _hoverColor;
                        deleteBTN.OnButtonClick  = delegate
                        {
                            BaseManager.DeleteAutoCraft(craft);
                            Refresh();
                        };
                    }

                    var buttonText = buttonPrefab.GetComponentInChildren <Text>();
                    buttonText.text = Language.main.Get(craft.TechType);

                    var checkbox = buttonPrefab.GetComponentInChildren <Toggle>();
                    checkbox.isOn = craft.IsCraftable;
                    checkbox.onValueChanged.AddListener((value) =>
                    {
                        craft.IsCraftable = value;
                    });

                    var craftBTN = InterfaceHelpers.FindGameObject(buttonPrefab, "AutocraftBTN")?.AddComponent <InterfaceButton>();

                    if (craftBTN != null)
                    {
                        craftBTN.BtnName        = "AutoCraftItemDeleteBTN";
                        craftBTN.TextLineOne    = AuxPatchers.Craft();
                        craftBTN.STARTING_COLOR = _startColor;
                        craftBTN.HOVER_COLOR    = _hoverColor;
                        craftBTN.OnButtonClick  = delegate { BaseManager.PerformCraft(craft); };
                    }
                }

                _autoCraftingGrid.UpdaterPaginator(grouped.Count);
            }
            catch (Exception e)
            {
                QuickLogger.Error("Error Caught");
                QuickLogger.Error($"Error Message: {e.Message}");
                QuickLogger.Error($"Error StackTrace: {e.StackTrace}");
            }
        }