Esempio n. 1
0
	/// <summary>
	/// Make the following widget be managed by the panel.
	/// </summary>

	public void AddWidget (UIWidget w)
	{
		mUpdateScroll = true;

		if (widgets.size == 0)
		{
			widgets.Add(w);
		}
		else if (mSortWidgets)
		{
			widgets.Add(w);
			SortWidgets();
		}
		else if (UIWidget.PanelCompareFunc(w, widgets[0]) == -1)
		{
			widgets.Insert(0, w);
		}
		else
		{
			for (int i = widgets.size; i > 0; )
			{
				if (UIWidget.PanelCompareFunc(w, widgets[--i]) == -1) continue;
				widgets.Insert(i+1, w);
				break;
			}
		}
		FindDrawCall(w);
	}
Esempio n. 2
0
    void AddWidget(UIWidget w)
    {
        // add to list by depth
        if (widgets.size == 0)
        {
            widgets.Add(w);
        }
        else if (UIWidget.PanelCompareFunc(w, widgets[0]) == -1)
        {
            widgets.Insert(0, w);
        }
        else
        {
            for (int i = widgets.size; i > 0;)
            {
                if (UIWidget.PanelCompareFunc(w, widgets[--i]) == -1)
                {
                    continue
                    widgets.Insert(i + 1, w);
                }
                break;
            }
        }


        // set dc
        FindDrawCall(w);
    }
Esempio n. 3
0
 // add to panel & find dc
 public void AddWidget(UIWidget w)
 {
     if (widgets.size == 0)
     {
         widgets.Add(w);
     }
     //else if (mSortWidgets)
     //{
     //    widgets.Add(w);
     //    SortWidgets();
     //}
     else if (UIWidget.PanelCompareFunc(w, widgets[0]) == -1)
     {
         widgets.Insert(0, w);
     }
     else
     {
         for (int i = widgets.size; i > 0;)
         {
             if (UIWidget.PanelCompareFunc(w, widgets[--i]) == -1)
             {
                 continue;
             }
             widgets.Insert(i + 1, w);
             break;
         }
     }
     FindDrawCall(w);
 }
Esempio n. 4
0
    /// <summary>
    /// Add a new item to the list.
    /// </summary>

    void AddItem(GameObject go, int index)
    {
        string guid = NGUIEditorTools.ObjectToGUID(go);

        if (string.IsNullOrEmpty(guid))
        {
#if UNITY_3_5
            string path = EditorUtility.SaveFilePanel("Save a prefab",
                                                      NGUISettings.currentPath, go.name + ".prefab", "prefab");
#else
            string path = EditorUtility.SaveFilePanelInProject("Save a prefab",
                                                               go.name + ".prefab", "prefab", "Save prefab as...", NGUISettings.currentPath);
#endif
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);

#if UNITY_2018_3_OR_NEWER
            go = PrefabUtility.SaveAsPrefabAsset(go, path);
#else
            go = PrefabUtility.CreatePrefab(path, go);
#endif
            if (go == null)
            {
                return;
            }

            guid = NGUIEditorTools.ObjectToGUID(go);
            if (string.IsNullOrEmpty(guid))
            {
                return;
            }
        }

        Item ent = new Item();
        ent.prefab = go;
        ent.guid   = guid;
        GeneratePreview(ent, null);
        RectivateLights();

        if (index < mItems.size)
        {
            mItems.Insert(index, ent);
        }
        else
        {
            mItems.Add(ent);
        }
        Save();
    }
Esempio n. 5
0
    public void SetDigitStr(BetterList <string> list, int nnn)
    {
        nnn = Mathf.Abs(nnn);
        while (true)
        {
            int aa = nnn / 10;
            int bb = nnn % 10;
            if (aa == 0)
            {
                if (completion)
                {
                    if (list.size < completionBytes)
                    {
                        list.Insert(0, symbolAry[bb]);
                    }
                }
                else
                {
                    list.Insert(0, symbolAry[bb]);
                }
                break;
            }
            else
            {
                if (completion)
                {
                    if (list.size < completionBytes)
                    {
                        list.Insert(0, symbolAry[bb]);
                    }
                }
                else
                {
                    list.Insert(0, symbolAry[bb]);
                }
            }
            nnn = aa;
        }

        if (completion && list.size < completionBytes)
        {
            int kk = completionBytes - list.size;
            for (int i = 0; i < kk; ++i)
            {
                list.Insert(0, "0");
            }
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Ensure we have a panel referencing this widget.
    /// </summary>

    public void CreatePanel()
    {
        if (mStarted && mPanel == null && enabled && NGUITools.GetActive(gameObject))
        {
            mPanel = UIPanel.Find(cachedTransform, mStarted);

            if (mPanel != null)
            {
                int  rd       = raycastDepth;
                bool inserted = false;

                // Try to insert this widget at the appropriate location within the list
                for (int i = 0; i < list.size; ++i)
                {
                    if (list[i].raycastDepth > rd)
                    {
                        list.Insert(i, this);
                        inserted = true;
                        break;
                    }
                }

                // Add this widget to the end of the list if it's not already there
                if (!inserted)
                {
                    list.Add(this);
                }

                CheckLayer();
                mChanged = true;
                drawCall = UIPanel.InsertWidget(this);
            }
        }
    }
Esempio n. 7
0
 public void AddCardOnTop(Card card)
 {
     cards.Insert(0, card);
     card.transform.parent = transform;
     card.MoveToPosition(Vector3.zero);
     SetAllCardsDepth();
 }
Esempio n. 8
0
        void AddItem(GameObject go, int index)
        {
            string guid = U3DExtends.UIEditorHelper.ObjectToGUID(go);

            if (string.IsNullOrEmpty(guid))
            {
                string path = EditorUtility.SaveFilePanelInProject("Save a prefab",
                                                                   go.name + ".prefab", "prefab", "Save prefab as...", "");

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                go = PrefabUtility.CreatePrefab(path, go);
                if (go == null)
                {
                    return;
                }

                guid = U3DExtends.UIEditorHelper.ObjectToGUID(go);
                if (string.IsNullOrEmpty(guid))
                {
                    return;
                }
            }

            Item ent = new Item();

            ent.prefab = go;
            ent.guid   = guid;
            GeneratePreview(ent);
            RectivateLights();

            if (index < mItems.size)
            {
                mItems.Insert(index, ent);
            }
            else
            {
                mItems.Add(ent);
            }
            Save();
        }
Esempio n. 9
0
 public void SetDigitStr(BetterList <string> list, int nnn)
 {
     nnn = Mathf.Abs(nnn);
     while (true)
     {
         int aa = nnn / 10;
         int bb = nnn % 10;
         if (aa == 0)
         {
             list.Insert(0, symbolAry[bb]);
             break;
         }
         else
         {
             list.Insert(0, symbolAry[bb]);
         }
         nnn = aa;
     }
 }
Esempio n. 10
0
    public void AddScrollContent(UIScrollContent content, int index)
    {
        listVirtualContents.Insert(index, content);

        CalculateBounds();

        if (onUpdateScrollSection != null)
        {
            onUpdateScrollSection();
        }
    }
Esempio n. 11
0
 public void AddChild(Transform trans, int index)
 {
     if (trans != null)
     {
         if (this.sorting != UIGrid.Sorting.None)
         {
             Debug.LogWarning("The Grid has sorting enabled, so AddChild at index may not work as expected.", this);
         }
         BetterList <Transform> childList = this.GetChildList();
         childList.Insert(index, trans);
         this.ResetPosition(childList);
     }
 }
Esempio n. 12
0
    /// <summary>
    /// Convenience method -- add a new child at the specified index.
    /// Note that if you plan on adding multiple objects, it's faster to GetChildList() and modify that instead.
    /// </summary>

    public void AddChild(Transform trans, int index)
    {
        if (trans != null)
        {
            if (sorting != Sorting.None)
            {
                ClientLog.Instance.LogWarning("The Grid has sorting enabled, so AddChild at index may not work as expected.", this);
            }

            BetterList <Transform> list = GetChildList();
            list.Insert(index, trans);
            ResetPositionPos(list);
        }
    }
Esempio n. 13
0
    public void insertGameObj(GameObject coinObj, bool bGold, bool bActive, int nIndex = 9999999)
    {
        CoinObjInfo coin = new CoinObjInfo();

        coin.CoinObj = coinObj;
        coin.Active  = bActive;

        Animator animator = coinObj.transform.Find("Icon").GetComponent <Animator>();

        animator.enabled = false;

        PListMono plistMono = coinObj.transform.Find("Icon").GetComponent <PListMono>();

        plistMono.enabled = false;

        coin.CoinObj.transform.position = new Vector3(1000, 1000, coin.CoinObj.transform.position.z);

        if (bGold)
        {
            if (nIndex == 9999999)
            {
                _goldList.Add(coin);
            }
            else
            {
                _goldList.Insert(nIndex, coin);
            }
        }
        else
        {
            if (nIndex == 9999999)
            {
                _silverList.Add(coin);
            }
            else
            {
                _silverList.Insert(nIndex, coin);
            }
        }
    }
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        InvDatabase db = target as InvDatabase;

        NGUIEditorTools.DrawSeparator();

        InvBaseItem item = null;

        if (db.items == null || db.items.Count == 0)
        {
            mIndex = 0;
        }
        else
        {
            mIndex = Mathf.Clamp(mIndex, 0, db.items.Count - 1);
            item   = db.items[mIndex];
        }

        if (mConfirmDelete)
        {
            // Show the confirmation dialog
            GUILayout.Label("Are you sure you want to delete '" + item.name + "'?");
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            {
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Cancel"))
                {
                    mConfirmDelete = false;
                }
                GUI.backgroundColor = Color.red;

                if (GUILayout.Button("Delete"))
                {
                    NGUIEditorTools.RegisterUndo("Delete Inventory Item", db);
                    db.items.RemoveAt(mIndex);
                    mConfirmDelete = false;
                }
                GUI.backgroundColor = Color.white;
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            // Database icon atlas
            UIAtlas atlas = EditorGUILayout.ObjectField("Icon Atlas", db.iconAtlas, typeof(UIAtlas), false) as UIAtlas;

            if (atlas != db.iconAtlas)
            {
                NGUIEditorTools.RegisterUndo("Databse Atlas change", db);
                db.iconAtlas = atlas;
                foreach (InvBaseItem i in db.items)
                {
                    i.iconAtlas = atlas;
                }
            }

            // Database ID
            int dbID = EditorGUILayout.IntField("Database ID", db.databaseID);

            if (dbID != db.databaseID)
            {
                NGUIEditorTools.RegisterUndo("Database ID change", db);
                db.databaseID = dbID;
            }

            // "New" button
            GUI.backgroundColor = Color.green;

            if (GUILayout.Button("New Item"))
            {
                NGUIEditorTools.RegisterUndo("Add Inventory Item", db);

                InvBaseItem bi = new InvBaseItem();
                bi.iconAtlas = db.iconAtlas;
                bi.id16      = (db.items.Count > 0) ? db.items[db.items.Count - 1].id16 + 1 : 0;
                db.items.Add(bi);
                mIndex = db.items.Count - 1;

                if (item != null)
                {
                    bi.name         = "Copy of " + item.name;
                    bi.description  = item.description;
                    bi.slot         = item.slot;
                    bi.color        = item.color;
                    bi.iconName     = item.iconName;
                    bi.attachment   = item.attachment;
                    bi.minItemLevel = item.minItemLevel;
                    bi.maxItemLevel = item.maxItemLevel;

                    foreach (InvStat stat in item.stats)
                    {
                        InvStat copy = new InvStat();
                        copy.id       = stat.id;
                        copy.amount   = stat.amount;
                        copy.modifier = stat.modifier;
                        bi.stats.Add(copy);
                    }
                }
                else
                {
                    bi.name        = "New Item";
                    bi.description = "Item Description";
                }

                item = bi;
            }
            GUI.backgroundColor = Color.white;

            if (item != null)
            {
                NGUIEditorTools.DrawSeparator();

                // Navigation section
                GUILayout.BeginHorizontal();
                {
                    if (mIndex == 0)
                    {
                        GUI.color = Color.grey;
                    }
                    if (GUILayout.Button("<<"))
                    {
                        mConfirmDelete = false; --mIndex;
                    }
                    GUI.color = Color.white;
                    mIndex    = EditorGUILayout.IntField(mIndex + 1, GUILayout.Width(40f)) - 1;
                    GUILayout.Label("/ " + db.items.Count, GUILayout.Width(40f));
                    if (mIndex + 1 == db.items.Count)
                    {
                        GUI.color = Color.grey;
                    }
                    if (GUILayout.Button(">>"))
                    {
                        mConfirmDelete = false; ++mIndex;
                    }
                    GUI.color = Color.white;
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawSeparator();

                // Item name and delete item button
                GUILayout.BeginHorizontal();
                {
                    string itemName = EditorGUILayout.TextField("Item Name", item.name);

                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("Delete", GUILayout.Width(55f)))
                    {
                        mConfirmDelete = true;
                    }
                    GUI.backgroundColor = Color.white;

                    if (!itemName.Equals(item.name))
                    {
                        NGUIEditorTools.RegisterUndo("Rename Item", db);
                        item.name = itemName;
                    }
                }
                GUILayout.EndHorizontal();

                string           itemDesc   = GUILayout.TextArea(item.description, 200, GUILayout.Height(100f));
                InvBaseItem.Slot slot       = (InvBaseItem.Slot)EditorGUILayout.EnumPopup("Slot", item.slot);
                string           iconName   = "";
                float            iconSize   = 64f;
                bool             drawIcon   = false;
                float            extraSpace = 0f;

                if (item.iconAtlas != null)
                {
                    BetterList <string> sprites = item.iconAtlas.GetListOfSprites();
                    sprites.Insert(0, "<None>");

                    int    index      = 0;
                    string spriteName = (item.iconName != null) ? item.iconName : sprites[0];

                    // We need to find the sprite in order to have it selected
                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        for (int i = 1; i < sprites.size; ++i)
                        {
                            if (spriteName.Equals(sprites[i], System.StringComparison.OrdinalIgnoreCase))
                            {
                                index = i;
                                break;
                            }
                        }
                    }

                    // Draw the sprite selection popup
                    index = EditorGUILayout.Popup("Icon", index, sprites.ToArray());
                    UIAtlas.Sprite sprite = (index > 0) ? item.iconAtlas.GetSprite(sprites[index]) : null;

                    if (sprite != null)
                    {
                        iconName = sprite.name;

                        Material mat = item.iconAtlas.spriteMaterial;

                        if (mat != null)
                        {
                            Texture2D tex = mat.mainTexture as Texture2D;

                            if (tex != null)
                            {
                                drawIcon = true;
                                Rect rect = sprite.outer;

                                if (item.iconAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                                {
                                    rect = NGUIMath.ConvertToTexCoords(rect, tex.width, tex.height);
                                }

                                GUILayout.Space(4f);
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(Screen.width - iconSize);
                                    DrawSprite(tex, rect, null, false);
                                }
                                GUILayout.EndHorizontal();

                                extraSpace = iconSize * (float)sprite.outer.height / sprite.outer.width;
                            }
                        }
                    }
                }

                // Item level range
                GUILayout.BeginHorizontal();
                GUILayout.Label("Level Range", GUILayout.Width(77f));
                int min = EditorGUILayout.IntField(item.minItemLevel, GUILayout.MinWidth(40f));
                int max = EditorGUILayout.IntField(item.maxItemLevel, GUILayout.MinWidth(40f));
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Game Object attachment field, left of the icon
                GUILayout.BeginHorizontal();
                GameObject go = (GameObject)EditorGUILayout.ObjectField("Attachment", item.attachment, typeof(GameObject), false);
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Color tint field, left of the icon
                GUILayout.BeginHorizontal();
                Color color = EditorGUILayout.ColorField("Color", item.color);
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Calculate the extra spacing necessary for the icon to show up properly and not overlap anything
                if (drawIcon)
                {
                    extraSpace = Mathf.Max(0f, extraSpace - 60f);
                    GUILayout.Space(extraSpace);
                }

                // Item stats
                NGUIEditorTools.DrawSeparator();

                if (item.stats != null)
                {
                    for (int i = 0; i < item.stats.Count; ++i)
                    {
                        InvStat stat = item.stats[i];

                        GUILayout.BeginHorizontal();
                        {
                            InvStat.Identifier iden = (InvStat.Identifier)EditorGUILayout.EnumPopup(stat.id, GUILayout.Width(80f));

                            // Color the field red if it's negative, green if it's positive
                            if (stat.amount > 0)
                            {
                                GUI.backgroundColor = Color.green;
                            }
                            else if (stat.amount < 0)
                            {
                                GUI.backgroundColor = Color.red;
                            }
                            int amount = EditorGUILayout.IntField(stat.amount, GUILayout.Width(40f));
                            GUI.backgroundColor = Color.white;

                            InvStat.Modifier mod = (InvStat.Modifier)EditorGUILayout.EnumPopup(stat.modifier);

                            GUI.backgroundColor = Color.red;
                            if (GUILayout.Button("X", GUILayout.Width(20f)))
                            {
                                NGUIEditorTools.RegisterUndo("Delete Item Stat", db);
                                item.stats.RemoveAt(i);
                                --i;
                            }
                            else if (iden != stat.id || amount != stat.amount || mod != stat.modifier)
                            {
                                NGUIEditorTools.RegisterUndo("Item Stats", db);
                                stat.id       = iden;
                                stat.amount   = amount;
                                stat.modifier = mod;
                            }
                            GUI.backgroundColor = Color.white;
                        }
                        GUILayout.EndHorizontal();
                    }
                }

                if (GUILayout.Button("Add Stat", GUILayout.Width(80f)))
                {
                    NGUIEditorTools.RegisterUndo("Add Item Stat", db);
                    InvStat stat = new InvStat();
                    stat.id = InvStat.Identifier.Armor;
                    item.stats.Add(stat);
                }

                // Save all values
                if (!itemDesc.Equals(item.description) ||
                    slot != item.slot ||
                    go != item.attachment ||
                    color != item.color ||
                    min != item.minItemLevel ||
                    max != item.maxItemLevel ||
                    !iconName.Equals(item.iconName))
                {
                    NGUIEditorTools.RegisterUndo("Item Properties", db);
                    item.description  = itemDesc;
                    item.slot         = slot;
                    item.attachment   = go;
                    item.color        = color;
                    item.iconName     = iconName;
                    item.minItemLevel = min;
                    item.maxItemLevel = max;
                }
            }
        }
    }
Esempio n. 15
0
    private void NeedCreate()
    {
        float showHeadLine = 0;
        float showFootLine = 0;

        //显示列表
        if (showList.size > 0)
        {
            RectTransform showHeadTs = showList[0].transform as RectTransform;
            showHeadLine = vertical ? showHeadTs.localPosition.y : showHeadTs.localPosition.x;
        }
        else
        {
            showHeadLine = vertical ? -(viewport.rect.height - footPadding) - content.position.y :
                           viewport.rect.width - footPadding - content.position.x;
        }
        // 先创建前头需要创建的
        if (numHeadHide > 0 &&
            vertical ? (showHeadLine + content.localPosition.y < 0) : (showHeadLine + content.localPosition.x > 0))
        {
            GameObject cell = CreateCell();
            if (OnShowCell != null)
            {
                OnShowCell(numHeadHide - 1, cell);
            }
            RectTransform cellTs = cell.transform as RectTransform;
            cellTs.localPosition = vertical ? new Vector3(cellTs.localPosition.x, cellTs.rect.height + padding + showHeadLine, cellTs.localPosition.z) :
                                   new Vector3(showHeadLine - padding - cellTs.rect.width, cellTs.localPosition.y, cellTs.localPosition.z);

            showList.Insert(0, cell);
            numHeadHide--;
            if (numHeadHide == 0) //这里要调整一下content
            {
                //float offset = vertical?
            }

            NeedCreate();
        }
        //这里之所以要放在这里算位置是因为上面会调整
        if (showList.size > 0)
        {
            RectTransform showFootTs = showList[showList.size - 1].transform as RectTransform;
            showFootLine = vertical ? showFootTs.localPosition.y - showFootTs.rect.height : showFootTs.localPosition.x + showFootTs.rect.width;
        }
        else
        {
            showFootLine = vertical ? -headPadding - content.position.y : headPadding - content.position.x;
        }
        // 再创建后头 , 调整 content
        if (numHeadHide + showList.size < GetNumCell() &&
            vertical ? (showFootLine + content.localPosition.y > -viewport.rect.height) : (showFootLine + content.localPosition.x < viewport.rect.width))
        {
            GameObject cell = CreateCell();
            if (OnShowCell != null)
            {
                OnShowCell(numHeadHide + showList.size, cell);
            }
            RectTransform cellTs = cell.transform as RectTransform;
            cellTs.localPosition = vertical ? new Vector3(cellTs.localPosition.x, showFootLine - padding, cellTs.localPosition.z) :
                                   new Vector3(showFootLine + padding, cellTs.localPosition.y, cellTs.localPosition.z);

            showList.Add(cell);

            //调整了 content
            content.sizeDelta = vertical ?
                                new Vector2(content.sizeDelta.x, Mathf.Max(viewport.rect.height, Mathf.Abs(cellTs.localPosition.y - cellTs.rect.height - footPadding))) :
                                new Vector2(Mathf.Max(viewport.rect.width, Mathf.Abs(cellTs.localPosition.x + cellTs.rect.width + footPadding)), content.sizeDelta.y);

            NeedCreate();
        }
    }