Beispiel #1
0
    void DisplayItemTypes()
    {
        if (selectedType != null)
        {
            foreach (int i in selectedType.childrenIDs)
            {
                ElementType e = InventoryDatabase.GetElementType(i);

                if (e != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button(e.name, GUILayout.ExpandWidth(true)))
                    {
                        GUI.FocusControl(null);
                        editType  = e;
                        editState = EditState.EDITTYPE;
                    }

                    if (GUILayout.Button(">", GUILayout.MaxWidth(25)))
                    {
                        GUI.FocusControl(null);
                        selectedType = e;
                        listState    = ListState.DEFAULT;
                        editState    = EditState.EMPTY;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
        else
        {
            for (int n = 0; n < InventoryDatabase.ElementTypeCount; n++)
            {
                ElementType et = InventoryDatabase.GetElementType(n);

                if (et != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (et.ID > -1 && et.parentID == -1)
                    {
                        if (GUILayout.Button(et.name, GUILayout.ExpandWidth(true)))
                        {
                            GUI.FocusControl(null);
                            editType  = et;
                            editState = EditState.EDITTYPE;
                        }
                        if (GUILayout.Button(">", GUILayout.MaxWidth(25)))
                        {
                            GUI.FocusControl(null);
                            selectedType = et;
                            listState    = ListState.DEFAULT;
                            editState    = EditState.EMPTY;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
    }
Beispiel #2
0
    void Search()
    {
        if (InventoryDatabase.ElementCount > 0)
        {
            GUILayout.Label("Elements", EditorStyles.boldLabel);
        }

        for (int i = 0; i < InventoryDatabase.ElementCount; i++)
        {
            InventoryElement item = InventoryDatabase.GetElement(i);

            if (item != null)
            {
                if (item.name.IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    if (GUILayout.Button(item.name))
                    {
                        editItem  = item;
                        editState = EditState.EDITITEM;
                    }
                }
            }
        }

        if (InventoryDatabase.ElementTypeCount > 0)
        {
            GUILayout.Label("Types", EditorStyles.boldLabel);
        }

        for (int i = 0; i < InventoryDatabase.ElementTypeCount; i++)
        {
            ElementType elemType = InventoryDatabase.GetElementType(i);

            if (elemType != null)
            {
                if (elemType.name != null)
                {
                    if (elemType.name.IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        if (GUILayout.Button(elemType.name))
                        {
                            editType  = elemType;
                            editState = EditState.EDITTYPE;
                        }
                    }
                }
            }
        }
    }
    public List <ElementType> GetSubTypes()
    {
        List <ElementType> temp = new List <ElementType>();

        foreach (int i in childrenIDs)
        {
            ElementType e = InventoryDatabase.GetElementType(i);

            if (e != null)
            {
                temp.Add(e);
                temp.AddRange(e.GetSubTypes());
            }
        }

        return(temp);
    }
    public List <ElementType> GetAncestors()
    {
        List <ElementType> temp = new List <ElementType>();

        if (InventoryDatabase.Instance != null)
        {
            if (parentID > -1)
            {
                ElementType e = InventoryDatabase.GetElementType(parentID);

                if (e != null)
                {
                    temp.Add(e);
                }

                temp.AddRange(e.GetAncestors());
            }
        }

        return(temp);
    }
Beispiel #5
0
    void ListArea()
    {
        EditorGUILayout.BeginVertical(GUILayout.Width(250));
        EditorGUILayout.Space();
        listScrollPos = EditorGUILayout.BeginScrollView(listScrollPos, "box", GUILayout.ExpandHeight(true));
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
        GUILayout.Label("Search");
        searchString = EditorGUILayout.TextField(searchString);
        EditorGUILayout.EndHorizontal();
        searchChanged = EditorGUI.EndChangeCheck();

        if (searchString != "")
        {
            if (searchChanged)
            {
                listState = ListState.SEARCHITEMS;
            }
        }
        else
        {
            if (listState == ListState.SEARCHITEMS)
            {
                listState = ListState.DEFAULT;
                editState = EditState.EMPTY;
            }
        }
        GUILayout.Space(15);
        GUIStyle gs = new GUIStyle();

        gs.fontStyle = FontStyle.BoldAndItalic;
        gs.alignment = TextAnchor.MiddleCenter;

        GUIStyle gs2 = new GUIStyle();

        gs2.fontStyle = FontStyle.BoldAndItalic;
        gs2.fontSize  = 10;
        gs2.alignment = TextAnchor.MiddleCenter;

        switch (listState)
        {
        case ListState.DEFAULT:
            if (selectedType != null)
            {
                if (GUILayout.Button("Back", GUILayout.ExpandWidth(true)))
                {
                    GUI.FocusControl(null);
                    selectedType = InventoryDatabase.GetElementType(selectedType.parentID);
                    editState    = EditState.EMPTY;
                    listState    = ListState.DEFAULT;
                }
            }
            if (selectedType != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(selectedType.name + "/...", gs, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                DisplayItems();
            }
            if (selectedType != null)
            {
                if (selectedType.GetSubTypes().Count > 0)
                {
                    GUILayout.Label("Types");
                }
            }

            DisplayItemTypes();
            break;

        case ListState.SEARCHITEMS:
            Search();
            break;
        }

        EditorGUILayout.EndScrollView();
        UnderList();
        EditorGUILayout.Space();
        EditorGUILayout.EndVertical();
    }
    public override void OnInspectorGUI()
    {
        Slot slot = (Slot)target;

        serializedObject.Update();

        items.Clear();
        items.Add("None");

        for (int a = 0; a < InventoryDatabase.ElementCount; a++)
        {
            InventoryElement element = InventoryDatabase.GetElement(a);

            if (element != null)
            {
                if (element.id != -1)
                {
                    items.Add(element.name);
                }
            }
        }

        itemTypes.Clear();
        itemTypes.Add("None");

        for (int i = 0; i < InventoryDatabase.ElementTypeCount; i++)
        {
            ElementType it = InventoryDatabase.GetElementType(i);

            if (it.name != "")
            {
                itemTypes.Add(it.name);
            }
        }

        GUILayout.BeginHorizontal();
        slot.itemTypesFoldout = EditorGUILayout.Foldout(slot.itemTypesFoldout, "Accepted Element Types");
        GUILayout.EndHorizontal();

        if (slot.itemTypesFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.selectedItemType = EditorGUILayout.Popup("Element Types", slot.selectedItemType, itemTypes.ToArray());
            if (GUILayout.Button("Add", EditorStyles.miniButton) && slot.selectedItemType > 0)
            {
                ElementType elementType = InventoryDatabase.FindElementType(itemTypes[slot.selectedItemType]);
                slot.acceptedTypes.Add(elementType);
            }

            GUILayout.EndHorizontal();
        }
        for (int b = 0; b < slot.acceptedTypes.Count; b++)
        {
            string it = slot.acceptedTypes[b].name;

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Space(15);
            EditorGUILayout.LabelField(b.ToString(), it);
            if (GUILayout.Button("-", EditorStyles.miniButton))
            {
                slot.acceptedTypes.RemoveAt(b);
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        slot.itemFoldout = EditorGUILayout.Foldout(slot.itemFoldout, "Element");
        GUILayout.EndHorizontal();

        if (slot.itemFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            if (slot.inventoryElement != null)
            {
                EditorGUILayout.LabelField("Current", slot.inventoryElement.name);
            }
            else
            {
                EditorGUILayout.LabelField("Current", "None", EditorStyles.boldLabel);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.lockItem = EditorGUILayout.Toggle("Lock In Slot", slot.lockItem);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.itemSelection = EditorGUILayout.Popup("Add", slot.itemSelection, items.ToArray());

            if (GUILayout.Button("Add", EditorStyles.miniButton))
            {
                if (slot.itemSelection == 0)
                {
                    slot.inventoryElement = new InventoryElement();
                }
                else if (slot.inventoryElement.name == "" || slot.inventoryElement.id != InventoryDatabase.FindElement(items[slot.itemSelection]).id)
                {
                    slot.inventoryElement = new InventoryElement(InventoryDatabase.FindElement(items[slot.itemSelection]));
                }
                else
                {
                    if (slot.inventoryElement.stack < slot.inventoryElement.maxStack)
                    {
                        slot.inventoryElement.stack++;
                    }
                }
                if (slot.inventoryObject != null)
                {
                    slot.inventoryObject.Save(slot.inventoryObject.GetType().ToString());
                }
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        slot.slotActivationSettingsFoldout = EditorGUILayout.Foldout(slot.slotActivationSettingsFoldout, "Hotkey Settings");
        GUILayout.EndHorizontal();

        if (slot.slotActivationSettingsFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("activationCharacterText"), new GUIContent("Text"));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.activationCharacterFoldout = EditorGUILayout.Foldout(slot.activationCharacterFoldout, "Hotkey Character");
            GUILayout.EndHorizontal();

            if (slot.activationCharacterFoldout)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                slot.activationInt = EditorGUILayout.Popup("Keys", slot.activationInt, slot.activationCharacters);
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.activationResponseFoldout = EditorGUILayout.Foldout(slot.activationResponseFoldout, "Response");
            GUILayout.EndHorizontal();

            if (slot.activationResponseFoldout)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                slot.ifActivateOnHotkey = EditorGUILayout.Toggle("Activate Slot", slot.ifActivateOnHotkey);
                GUILayout.EndHorizontal();

                if (slot.ifActivateOnHotkey)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(30);
                    slot.changeSize = EditorGUILayout.Toggle("Change Size", slot.changeSize);
                    GUILayout.EndHorizontal();

                    if (slot.changeSize)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(30);
                        slot.changeSizeVector2 = EditorGUILayout.Vector2Field("Size", slot.changeSizeVector2);
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(30);
                    slot.changeTexture = EditorGUILayout.Toggle("Change Texture", slot.changeTexture);
                    GUILayout.EndHorizontal();

                    if (slot.changeTexture)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(30);
                        slot.changeTextureImage = (Texture)EditorGUILayout.ObjectField("Texture", slot.changeTextureImage, typeof(Texture), true);
                        GUILayout.EndHorizontal();
                    }
                }
            }
        }

        GUILayout.BeginHorizontal();
        slot.backgroundFoldout = EditorGUILayout.Foldout(slot.backgroundFoldout, "Background");
        GUILayout.EndHorizontal();

        if (slot.backgroundFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("backgroundRawImage"), new GUIContent("Activation Character"));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.backgroundRawImage.texture = (Texture)EditorGUILayout.ObjectField("Background", slot.backgroundRawImage.texture, typeof(Texture), true);
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        slot.slotTextFoldout = EditorGUILayout.Foldout(slot.slotTextFoldout, "Text");
        GUILayout.EndHorizontal();

        if (slot.slotTextFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.disableTextIfItem = EditorGUILayout.Toggle("Disable Text if Element Exists", slot.disableTextIfItem);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("slotText"), new GUIContent("Activation Character"));
            GUILayout.EndHorizontal();
        }
        serializedObject.ApplyModifiedProperties();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }