Beispiel #1
0
 IEnumerator FixTextWidth()
 {
     while (true)
     {
         if (UI && UI.gameObject && UI.tipBackground.gameObject.activeSelf)
         {
             if (UI.tipsContent.rectTransform.rect.width < 380 && UI.tipsFitter.horizontalFit != UnityEngine.UI.ContentSizeFitter.FitMode.PreferredSize)
             {
                 UI.tipsFitter.horizontalFit = UnityEngine.UI.ContentSizeFitter.FitMode.PreferredSize;
             }
             else if (UI.tipsContent.rectTransform.rect.width > 380 && UI.tipsFitter.horizontalFit != UnityEngine.UI.ContentSizeFitter.FitMode.Unconstrained)
             {
                 UI.tipsFitter.horizontalFit = UnityEngine.UI.ContentSizeFitter.FitMode.Unconstrained;
             }
             if (UI.tipBackground.rect.width > 400)
             {
                 UI.tipBackground.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 400);
             }
             ZetanUtility.KeepInsideScreen(UI.tipBackground);
             yield return(waitForSeconds);
         }
         else
         {
             yield return(new WaitUntil(() => { return UI && UI.gameObject && UI.tipBackground.gameObject.activeSelf; }));
         }
     }
 }
Beispiel #2
0
 IEnumerator FixTextWidth()
 {
     while (true)
     {
         if (IsOpen)
         {
             if (tipsContent.rectTransform.rect.width < 380 && tipsFitter.horizontalFit != ContentSizeFitter.FitMode.PreferredSize)
             {
                 tipsFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
             }
             else if (tipsContent.rectTransform.rect.width > 380 && tipsFitter.horizontalFit != ContentSizeFitter.FitMode.Unconstrained)
             {
                 tipsFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
             }
             if (tipBackground.rect.width > 400)
             {
                 tipBackground.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 400);
             }
             ZetanUtility.KeepInsideScreen(tipBackground);
             yield return(wait);
         }
         else
         {
             yield return(new WaitUntil(() => IsOpen));
         }
     }
 }
Beispiel #3
0
 public void New(Action confirmAction, Action cancelAction, long max, string title = "")
 {
     if (max < min)
     {
         max = max + min;
         min = max - min;
         max = max - min;
     }
     this.max       = max;
     min            = 0;
     Amount         = max >= 0 ? 0 : min;
     UI.amount.text = Amount.ToString();
     onConfirm      = confirmAction;
     onCancel       = cancelAction;
     UI.windowCanvas.sortingOrder = WindowsManager.Instance.TopOrder + 1;
     UI.window.alpha          = 1;
     UI.window.blocksRaycasts = true;
     if (string.IsNullOrEmpty(title))
     {
         UI.title.text = "输入数量";
     }
     else
     {
         UI.title.text = title;
     }
     ZetanUtility.KeepInsideScreen(UI.windowRect);
 }
Beispiel #4
0
 private void Refresh(string title)
 {
     field.shouldHideMobileInput = false;
     field.ActivateInputField();
     field.shouldHideMobileInput = true;
     if (string.IsNullOrEmpty(title))
     {
         titleText.text = "输入数量";
     }
     else
     {
         titleText.text = title;
     }
     ZetanUtility.KeepInsideScreen(windowRect);
     firstInput = true;
 }
Beispiel #5
0
 private void LeftOrRight(Vector2 position)
 {
     if (Screen.width * 0.5f < position.x)//在屏幕右半边
     {
         UI.subUI.window.transform.SetAsFirstSibling();
         UI.buttonsArea.transform.SetAsLastSibling();
         Rect rectAgent  = ZetanUtility.GetScreenSpaceRect(itemAgent.GetComponent <RectTransform>());
         Rect rectWin    = ZetanUtility.GetScreenSpaceRect(UI.subUI.GetComponent <RectTransform>());
         Rect rectButton = ZetanUtility.GetScreenSpaceRect(UI.buttonsArea.GetComponent <RectTransform>());
         UI.window.transform.position = new Vector2(position.x - rectAgent.width * 0.5f - rectWin.width - rectButton.width, UI.window.transform.position.y);
     }
     else
     {
         UI.subUI.window.transform.SetAsLastSibling();
         UI.buttonsArea.transform.SetAsFirstSibling();
         Rect rectAgent  = ZetanUtility.GetScreenSpaceRect(itemAgent.GetComponent <RectTransform>());
         Rect rectWin    = ZetanUtility.GetScreenSpaceRect(UI.subUI.GetComponent <RectTransform>());
         Rect rectButton = ZetanUtility.GetScreenSpaceRect(UI.buttonsArea.GetComponent <RectTransform>());
         UI.window.transform.position = new Vector2(position.x + rectAgent.width * 0.5f + rectWin.width + rectButton.width, UI.window.transform.position.y);
     }
     ZetanUtility.KeepInsideScreen(UI.window.GetComponent <RectTransform>(), true, true, false, false);
 }
Beispiel #6
0
    public void SetItemAndOpenWindow(ItemAgent itemAgent)
    {
        //UI.windowsRect.position = new Vector3(Input.mousePosition.x - UI.windowsRect.sizeDelta.x, UI.windowsRect.position.y);
        ZetanUtility.KeepInsideScreen(UI.window.transform as RectTransform);
        if (itemAgent == null || itemAgent.IsEmpty || this.itemAgent == itemAgent)
        {
            return;
        }
        itemAgent.Select();
        if (this.itemAgent)
        {
            this.itemAgent.DeSelect();
        }
        this.itemAgent = itemAgent;
        LeftOrRight(itemAgent.transform.position);
        animated = false;
        OpenWindow();
        MItemInfo               = itemAgent.MItemInfo;
        itemAgentType           = itemAgent.agentType;
        UI.icon.overrideSprite  = MItemInfo.item.Icon;
        UI.nameText.text        = MItemInfo.ItemName;
        UI.nameText.color       = GameManager.QualityToColor(MItemInfo.item.Quality);
        UI.typeText.text        = ItemBase.GetItemTypeString(MItemInfo.item.ItemType);
        UI.priceText.text       = MItemInfo.item.SellAble ? MItemInfo.item.SellPrice + GameManager.CoinName : "不可出售";
        UI.weightText.text      = "重量:" + MItemInfo.item.Weight.ToString("F2") + "WL";
        UI.descriptionText.text = MItemInfo.item.Description;
        switch (MItemInfo.item.ItemType)
        {
        case ItemType.Weapon:
            WeaponItem weapon = MItemInfo.item as WeaponItem;
            UI.effectText.text = (weapon.CutATK > 0 ? "斩击攻击力+" + weapon.CutATK + "\n" : string.Empty) +
                                 (weapon.PunATK > 0 ? "刺击攻击力+" + weapon.PunATK + "\n" : string.Empty) +
                                 (weapon.BluATK > 0 ? "钝击攻击力+" + weapon.BluATK + "\n" : string.Empty) +
                                 (weapon.DEF > 0 ? "防御力力+" + weapon.DEF + "\n" : string.Empty) +
                                 (weapon.Hit > 0 ? "命中+" + weapon.Hit + "\n" : string.Empty);
            if (weapon.Powerup.IsEffective)
            {
                ZetanUtility.SetActive(UI.mulFunTitle.gameObject, true);
                ZetanUtility.SetActive(UI.mulFunText.gameObject, true);
                UI.mulFunTitle.text = "-附加能力";
                UI.mulFunText.text  = weapon.Powerup.ToString();
            }
            else
            {
                ZetanUtility.SetActive(UI.mulFunTitle.gameObject, false);
                ZetanUtility.SetActive(UI.mulFunText.gameObject, false);
                UI.mulFunTitle.text = string.Empty;
                UI.mulFunText.text  = string.Empty;
            }
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, weapon.GemSlotAmout > 0);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, weapon.GemSlotAmout > 1);
            ZetanUtility.SetActive(UI.durability.gameObject, true);
            if (PlayerManager.Instance.PlayerInfo.HasPrimaryWeapon)
            {
                OpenSubItemWindow(PlayerManager.Instance.PlayerInfo.primaryWeapon);
            }
            else if (PlayerManager.Instance.PlayerInfo.HasSecondaryWeapon)
            {
                OpenSubItemWindow(PlayerManager.Instance.PlayerInfo.secondaryWeapon);
            }
            break;

        case ItemType.Bag:
            UI.effectText.text = GameManager.BackpackName + "容量+" + (MItemInfo.item as BagItem).ExpandSize;
            ZetanUtility.SetActive(UI.mulFunTitle.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunText.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, false);
            ZetanUtility.SetActive(UI.durability.gameObject, false);
            CloseSubWindow();
            break;

        case ItemType.Box:
            UI.effectText.text = string.Empty;
            BoxItem box = MItemInfo.item as BoxItem;
            UI.mulFunTitle.text = "-内含物品";
            ZetanUtility.SetActive(UI.mulFunTitle.gameObject, true);
            System.Text.StringBuilder itemsInfo = new System.Text.StringBuilder();
            for (int i = 0; i < box.ItemsInBox.Count; i++)
            {
                itemsInfo.Append("[" + box.ItemsInBox[i].ItemName + "] × " + box.ItemsInBox[i].Amount);
                if (i != box.ItemsInBox.Count - 1)
                {
                    itemsInfo.Append("\n");
                }
            }
            UI.mulFunText.text = itemsInfo.ToString();
            ZetanUtility.SetActive(UI.mulFunText.gameObject, true);
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, false);
            ZetanUtility.SetActive(UI.durability.gameObject, false);
            CloseSubWindow();
            break;

        default:
            UI.effectText.text = string.Empty;
            ZetanUtility.SetActive(UI.mulFunTitle.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunText.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, false);
            ZetanUtility.SetActive(UI.durability.gameObject, false);
            CloseSubWindow();
            break;
        }
        //UI.window.alpha = 1;
#if UNITY_STANDALONE
        UI.window.blocksRaycasts = false;
#elif UNITY_ANDROID
        //UI.window.blocksRaycasts = true;
        ZetanUtility.SetActive(UI.buttonsArea, true);
        UI.mulFunButton.onClick.RemoveAllListeners();
        ZetanUtility.SetActive(UI.closeButton.gameObject, true);
        UI.priceTitle.text = "贩卖价格";
#endif
        switch (itemAgentType)
        {
        case ItemAgentType.Backpack:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, MItemInfo.item.DiscardAble);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, false);
            UI.mulFunButton.onClick.RemoveAllListeners();
            if (!WarehouseManager.Instance.IsUIOpen && !ShopManager.Instance.IsUIOpen && !ItemSelectionManager.Instance.IsUIOpen)
            {
                if (MItemInfo.item.Usable)
                {
                    ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                    UI.mulFunButton.GetComponentInChildren <Text>().text = MItemInfo.item.IsEquipment ? "装备" : "使用";
                    UI.mulFunButton.onClick.AddListener(UseCurrenItem);
                }
            }
            else if (WarehouseManager.Instance.IsUIOpen)
            {
                ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                UI.mulFunButton.GetComponentInChildren <Text>().text = "存入";
                UI.mulFunButton.onClick.AddListener(StoreCurrentItem);
            }
            else if (ShopManager.Instance.IsUIOpen)
            {
                if (MItemInfo.item.SellAble)
                {
                    ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                    UI.mulFunButton.GetComponentInChildren <Text>().text = "出售";
                    UI.mulFunButton.onClick.AddListener(SellOrPurchaseCurrentItem);
                }
                ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            }
            else if (ItemSelectionManager.Instance.IsUIOpen)
            {
                switch (ItemSelectionManager.Instance.SelectionType)
                {
                case ItemSelectionType.Discard:
                    if (MItemInfo.item.DiscardAble)
                    {
                        ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                        UI.mulFunButton.GetComponentInChildren <Text>().text = "选取";
                        UI.mulFunButton.onClick.AddListener(delegate
                        {
                            if (ItemSelectionManager.Instance.Place(MItemInfo))
                            {
                                CloseWindow();
                            }
                        });
                    }
                    break;

                case ItemSelectionType.Gift:
                    break;

                case ItemSelectionType.Making:
                    if (MItemInfo.item.MaterialType != MaterialType.None)
                    {
                        ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                        UI.mulFunButton.GetComponentInChildren <Text>().text = "选取";
                        UI.mulFunButton.onClick.AddListener(delegate
                        {
                            if (ItemSelectionManager.Instance.Place(MItemInfo))
                            {
                                CloseWindow();
                            }
                        });
                    }
                    break;

                case ItemSelectionType.None:
                default:
                    break;
                }
                ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            }
#endif
            break;

        case ItemAgentType.Warehouse:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(TakeOutCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "取出";
#endif
            break;

        case ItemAgentType.Making:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, MItemInfo.Amount > 0);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(MakeCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "制作";
#endif
            break;

        case ItemAgentType.Selling:
            UI.priceTitle.text = "售价";
            if (ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo))
            {
                UI.priceText.text = ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo).merchandiseInfo.SellPrice.ToString() + GameManager.CoinName;
            }
            else
            {
                CloseWindow();
            }
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(SellOrPurchaseCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "购买";
#endif
            break;

        case ItemAgentType.Purchasing:
            UI.priceTitle.text = "收购价";
            if (ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo))
            {
                UI.priceText.text = ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo).merchandiseInfo.PurchasePrice.ToString() + GameManager.CoinName;
            }
            else
            {
                CloseWindow();
            }
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, BackpackManager.Instance.GetItemAmount(MItemInfo.ItemID) > 0);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(SellOrPurchaseCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "出售";
#endif
            break;

        case ItemAgentType.Loot:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(TakeCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "拾取";
#endif
            break;

        case ItemAgentType.Selection:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(TakeOutCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "取出";
#endif
            break;

        default:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.buttonsArea.gameObject, false);
            ZetanUtility.SetActive(UI.closeButton.gameObject, true);
#endif
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, false);
            UI.mulFunButton.onClick.RemoveAllListeners();
            break;
        }
    }
Beispiel #7
0
    private IEnumerator KeepInScreen()
    {
        yield return(new WaitForEndOfFrame());

        ZetanUtility.KeepInsideScreen(content.GetComponent <RectTransform>(), bottom: false);
    }
Beispiel #8
0
 public void SetPosition(Vector2 target)
 {
     UI.window.GetComponent <RectTransform>().position = target + defaultOffset;
     ZetanUtility.KeepInsideScreen(UI.windowRect);
 }
Beispiel #9
0
 public void SetPosition(Vector2 targetPos, Vector2 offset)
 {
     UI.windowRect.position = targetPos + offset;
     ZetanUtility.KeepInsideScreen(UI.windowRect);
 }