public ScenesWindowElementReference(Rect aStartPos, GUIContent aContent, GUIStyle aStyle,
                                            params GUILayoutOption[] aOptions)
            : base(aStartPos, aContent, aStyle, aOptions)
        {
            clearImg   = (Texture2D)Resources.Load("EAdventureData/img/icons/deleteContent", typeof(Texture2D));
            addTexture = (Texture2D)Resources.Load("EAdventureData/img/icons/addNode", typeof(Texture2D));
            moveUp     = (Texture2D)Resources.Load("EAdventureData/img/icons/moveNodeUp", typeof(Texture2D));
            moveDown   = (Texture2D)Resources.Load("EAdventureData/img/icons/moveNodeDown", typeof(Texture2D));

            if (GameRources.GetInstance().selectedSceneIndex >= 0)
            {
                currentIndex   = GameRources.GetInstance().selectedSceneIndex;
                currentScene   = Controller.getInstance().getSelectedChapterDataControl().getScenesList().getScenes()[currentIndex];
                backgroundPath = currentScene.getPreviewBackground();
            }
            if (backgroundPath != null && !backgroundPath.Equals(""))
            {
                backgroundPreviewTex = AssetsController.getImage(backgroundPath).texture;
            }

            conditionTex = (Texture2D)Resources.Load("EAdventureData/img/icons/no-conditions-24x24", typeof(Texture2D));

            selectedElementSkin = (GUISkin)Resources.Load("Editor/EditorLeftMenuItemSkinConcreteOptions", typeof(GUISkin));
            noBackgroundSkin    = (GUISkin)Resources.Load("Editor/EditorNoBackgroundSkin", typeof(GUISkin));


            selectedElement = null;
            addMenu         = new AddItemActionMenu();
        }
        // this function was made to insert player in correct position in SwapPlayerModeTool
        // CAUTION!! dont check if has layer or if it is allowed, because where it is call that has been checked
        //			 dont call to setPlayerLayer() because it has been checked
        public void restorePlayer()
        {
            ElementContainer ec = new ElementContainer(null, sceneDataControl.getPlayerLayer(), Controller.ResourceManager.getSprite(this.playerImagePath));
            int layer           = insertInOrder(ec, true);

            reassignLayerAllReferencesDataControl(layer);
        }
Beispiel #3
0
        /**
         * Insert in order in allReferencesDataControl attribute
         *
         * @param element
         *            The element container to be added
         * @param hasLayer
         *            Take either layer or depth value to order value
         * @param playerLayer
         *            Take the layer if player has it, or the y position if the
         *            player has not layer.
         *
         * @return i returns the position where the element has been inserted. It
         *         will be use to reassign layer
         */
        public int insertInOrder(ElementContainer element, bool hasLayer)
        {
            bool added = false;
            int  i     = 0;
            bool empty = allReferencesDataControl.Count == 0;

            // While the element has not been added, and
            // we haven't checked every previous element
            while (!added && (i < allReferencesDataControl.Count || empty))
            {
                if (!empty)
                {
                    if (hasLayer)
                    {
                        if (element.getLayer() <= allReferencesDataControl[i].getLayer())
                        {
                            allReferencesDataControl.Insert(i, element);
                            added = true;
                        }
                    }
                    else
                    {
                        if (element.getY() <= Mathf.Round(allReferencesDataControl[i].getY()))
                        {
                            allReferencesDataControl.Insert(i, element);
                            reassignLayerAllReferencesDataControl(i);
                            added = true;
                        }
                    }
                    i++;
                }
                else
                {
                    allReferencesDataControl.Insert(i, element);
                    if (!hasLayer)
                    {
                        reassignLayerAllReferencesDataControl(i);
                    }
                    added = true;
                    i++;
                }
            }

            // If the element wasn't added, add it in the last position
            if (!added)
            {
                //element.setLayer(i);
                allReferencesDataControl.Add(element);
                if (!hasLayer)
                {
                    reassignLayerAllReferencesDataControl(i - 1);
                }
            }
            return(i - 1);
        }
 public void addPlayer()
 {
     if (sceneDataControl.isForcedPlayerLayer())
     {
         playerImagePath = Controller.Instance.getPlayerImagePath();
         ElementContainer ec = new ElementContainer(null, 0, Controller.ResourceManager.getSprite(this.playerImagePath));
         int layer           = insertInOrder(ec, true);
         reassignLayerAllReferencesDataControl(layer);
         sceneDataControl.setPlayerLayer(layer);
     }
 }
Beispiel #5
0
        /**
         * Constructor.
         *
         * @param sceneDataControl
         *            Link to the parent scene controller
         * @param itemReferencesList
         *            List of item references
         */
        public ReferencesListDataControl(string playerImagePath, SceneDataControl sceneDataControl, List <ElementReference> itemReferencesList, List <ElementReference> atrezzoReferencesList, List <ElementReference> npcReferencesList)
        {
            this.playerImagePath               = playerImagePath;
            this.sceneDataControl              = sceneDataControl;
            this.itemReferencesList            = itemReferencesList;
            this.atrezzoReferencesList         = atrezzoReferencesList;
            this.npcReferencesList             = npcReferencesList;
            this.allReferencesDataControl      = new List <ElementContainer>();
            this.lastElementContainer          = null;
            this.playerPositionInAllReferences = NO_PLAYER;
            this.imagePathHasChanged           = false;
            // Check if one of references has layer -1: if it is true, it means that element references has no layer.
            // Create subcontrollers

            bool hasLayerV = hasLayer();

            foreach (ElementReference itemReference in itemReferencesList)
            {
                int counter = count(itemReference);
                ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, itemReference, Controller.ITEM_REFERENCE, counter);
                insertInOrder(new ElementContainer(erdc, -1, null), hasLayerV);
            }

            foreach (ElementReference atrezzoReference in atrezzoReferencesList)
            {
                int counter = count(atrezzoReference);
                ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, atrezzoReference, Controller.ATREZZO_REFERENCE, counter);
                insertInOrder(new ElementContainer(erdc, -1, null), hasLayerV);
            }

            foreach (ElementReference npcReference in npcReferencesList)
            {
                int counter = count(npcReference);
                ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, npcReference, Controller.NPC_REFERENCE, counter);
                insertInOrder(new ElementContainer(erdc, -1, null), hasLayerV);
            }

            // insert player
            // by default, if player don´t have layer, we give it to him.
            if (playerImagePath != null && (!Controller.getInstance().isPlayTransparent()) && sceneDataControl.isForcedPlayerLayer())
            {
                int layer;
                if (sceneDataControl.getPlayerLayer() == Scene.PLAYER_WITHOUT_LAYER)
                {
                    layer = 0;
                }
                else
                {
                    layer = sceneDataControl.getPlayerLayer();
                }
                reassignLayerAllReferencesDataControl(insertInOrder(new ElementContainer(null, layer, AssetsController.getImage(this.playerImagePath)), true));
            }
        }
        /**
         * Constructor.
         *
         * @param sceneDataControl
         *            Link to the parent scene controller
         * @param itemReferencesList
         *            List of item references
         */
        public ReferencesListDataControl(string playerImagePath, SceneDataControl sceneDataControl)
        {
            this.playerImagePath   = playerImagePath;
            this.sceneDataControl  = sceneDataControl;
            this.typeReferenceList = new Dictionary <Type, List <ElementReference> >();
            var content = sceneDataControl.getContent() as Scene;

            typeReferenceList.Add(typeof(Item), content.getItemReferences());
            typeReferenceList.Add(typeof(Atrezzo), content.getAtrezzoReferences());
            typeReferenceList.Add(typeof(NPC), content.getCharacterReferences());

            this.allReferencesDataControl      = new List <ElementContainer>();
            this.lastElementContainer          = null;
            this.playerPositionInAllReferences = NO_PLAYER;
            // Check if one of references has layer -1: if it is true, it means that element references has no layer.
            // Create subcontrollers

            bool hasLayerV = false;

            foreach (var itemReference in getReferencesList(typeof(Item)))
            {
                hasLayerV |= InsertReference(itemReference, Controller.ITEM_REFERENCE);
            }

            foreach (var atrezzoReference in getReferencesList(typeof(Atrezzo)))
            {
                hasLayerV |= InsertReference(atrezzoReference, Controller.ATREZZO_REFERENCE);
            }

            foreach (var npcReference in getReferencesList(typeof(NPC)))
            {
                hasLayerV |= InsertReference(npcReference, Controller.NPC_REFERENCE);
            }

            // insert player
            // by default, if player don´t have layer, we give it to him.
            if (playerImagePath != null && (!Controller.Instance.PlayTransparent) && sceneDataControl.isForcedPlayerLayer())
            {
                int layer;
                if (sceneDataControl.getPlayerLayer() == Scene.PLAYER_WITHOUT_LAYER)
                {
                    layer = 0;
                }
                else
                {
                    layer = sceneDataControl.getPlayerLayer();
                }
                reassignLayerAllReferencesDataControl(insertInOrder(new ElementContainer(null, layer, Controller.ResourceManager.getSprite(this.playerImagePath)), true));
            }
        }
        private void deleteReferenceFromAll(System.Object reference)
        {
            int i = 0;

            while (i < allReferencesDataControl.Count)
            {
                ElementContainer element = allReferencesDataControl[i];
                if (!element.isPlayer() && element.getErdc().getContent() == reference)
                {
                    allReferencesDataControl.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
        }
Beispiel #8
0
 public void addElement(ElementContainer element)
 {
     if (element.getErdc().getType() == Controller.ITEM_REFERENCE)
     {
         itemReferencesList.Add((ElementReference)element.getErdc().getContent());
     }
     else if (element.getErdc().getType() == Controller.ATREZZO_REFERENCE)
     {
         atrezzoReferencesList.Add((ElementReference)element.getErdc().getContent());
     }
     else if (element.getErdc().getType() == Controller.NPC_REFERENCE)
     {
         npcReferencesList.Add((ElementReference)element.getErdc().getContent());
     }
     allReferencesDataControl.Insert(element.getLayer(), element);
     reassignLayerAllReferencesDataControl(element.getLayer());
 }
        private void performAddElement(int type, string id)
        {
            var elementType = controller.IdentifierSummary.getType(id);

            if (elementType != null)
            {
                ElementReference newElementReference = new ElementReference(id, 50, 50);
                int counter = count(newElementReference);
                getReferencesList(elementType).Add(newElementReference);
                ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, newElementReference, type, counter);
                var defaultPos = sceneDataControl.getDefaultInitialPosition();
                newElementReference.setPosition((int)defaultPos.x, (int)defaultPos.y);
                newElementReference.setScale(sceneDataControl.getElementAppropiateScale(erdc.getReferencedElementDataControl() as DataControlWithResources));
                ElementContainer ec = new ElementContainer(erdc, -1, null);
                lastElementContainer = ec;
                reassignLayerAllReferencesDataControl(insertInOrder(ec, false));
            }
        }
Beispiel #10
0
        private void moveDown(DataControl dataControl)
        {
            bool player;
            int  index = 0;

            if (dataControl != null)
            {
                player = false;
                for (index = 0; index < allReferencesDataControl.Count; index++)
                {
                    if (!allReferencesDataControl[index].isPlayer())
                    {
                        if (allReferencesDataControl[index].getErdc().Equals(dataControl))
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                index  = playerPositionInAllReferences;
                player = true;
            }
            if (index >= 0 && index < allReferencesDataControl.Count - 1)
            {
                //change the elements
                ElementContainer e = allReferencesDataControl[index];
                allReferencesDataControl.RemoveAt(index);
                allReferencesDataControl.Insert(index + 1, e);
                //update element layer
                allReferencesDataControl[index].setLayer(index);
                allReferencesDataControl[index + 1].setLayer(index + 1);
                if (player)
                {
                    setPlayerPosition(index + 1);
                }
                if (allReferencesDataControl[index].isPlayer())
                {
                    setPlayerPosition(index);
                }
            }
        }
        public void addElement(ElementContainer element)
        {
            var elementRef = (ElementReference)element.getErdc().getContent();

            if (elementRef == null)
            {
                return;
            }

            var type = controller.IdentifierSummary.getType(elementRef.getTargetId());

            if (type == null)
            {
                return;
            }

            getReferencesList(type).Add(elementRef);
            allReferencesDataControl.Insert(element.getLayer(), element);
            reassignLayerAllReferencesDataControl(element.getLayer());
        }
        private bool moveElement(DataControl dataControl, bool up)
        {
            bool moved = false;

            bool player;
            int  index = 0;

            if (dataControl != null)
            {
                player = false;
                index  = allReferencesDataControl.FindIndex(dc => !dc.isPlayer() && (dc == dataControl || dc.getErdc() == dataControl));
            }
            else
            {
                player = true;
                index  = playerPositionInAllReferences;
            }

            if (index >= 0)
            {
                int toIndex = up ? index - 1 : index + 1;

                ElementContainer e = allReferencesDataControl[index];
                allReferencesDataControl.RemoveAt(index);
                allReferencesDataControl.Insert(toIndex, e);
                allReferencesDataControl[index].setLayer(index);
                allReferencesDataControl[toIndex].setLayer(toIndex);
                if (player)
                {
                    setPlayerPosition(toIndex);
                }
                if (allReferencesDataControl[index].isPlayer())
                {
                    setPlayerPosition(index);
                }
                Controller.Instance.DataModified();
                moved = true;
            }

            return(moved);
        }
 /**
  * Change the last element container
  *
  * @param lastElementContainer
  *            the new element container
  */
 public void setLastElementContainer(ElementContainer lastElementContainer)
 {
     this.lastElementContainer = lastElementContainer;
 }
        public override void Draw(int aID)
        {
            if (GameRources.GetInstance().selectedSceneIndex >= 0)
            {
                currentIndex = GameRources.GetInstance().selectedSceneIndex;
                currentScene = Controller.getInstance().getSelectedChapterDataControl().getScenesList().getScenes()[currentIndex];
            }

            if (currentScene == null)
            {
                if (GameRources.GetInstance().selectedSceneIndex >= 0 && currentIndex != GameRources.GetInstance().selectedSceneIndex)
                {
                    currentIndex = GameRources.GetInstance().selectedSceneIndex;
                    currentScene = Controller.getInstance().getSelectedChapterDataControl().getScenesList().getScenes()[currentIndex];
                }
                else
                {
                    return;
                }
            }

            var windowWidth  = m_Rect.width;
            var windowHeight = m_Rect.height;

            tableRect       = new Rect(0f, 0.1f * windowHeight, 0.9f * windowWidth, windowHeight * 0.33f);
            rightPanelRect  = new Rect(0.9f * windowWidth, 0.1f * windowHeight, 0.08f * windowWidth, 0.33f * windowHeight);
            infoPreviewRect = new Rect(0f, 0.45f * windowHeight, windowWidth, windowHeight * 0.05f);
            previewRect     = new Rect(0f, 0.5f * windowHeight, windowWidth, windowHeight * 0.45f);

            GUILayout.BeginArea(tableRect);
            GUILayout.BeginHorizontal();
            GUILayout.Box(TC.get("ElementList.Layer"), GUILayout.Width(windowWidth * 0.12f));
            GUILayout.Box("", GUILayout.Width(windowWidth * 0.06f));
            GUILayout.Box(TC.get("ElementList.Title"), GUILayout.Width(windowWidth * 0.39f));
            GUILayout.Box(TC.get("Conditions.Title"), GUILayout.Width(windowWidth * 0.29f));
            GUILayout.EndHorizontal();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            int i = 0;

            foreach (ElementContainer element in currentScene.getReferencesList().getAllReferencesDataControl())
            {
                if (element == selectedElement)
                {
                    GUI.skin = selectedElementSkin;
                }

                GUILayout.BeginHorizontal();

                if (GUILayout.Button(element.getLayer().ToString(), GUILayout.Width(windowWidth * 0.12f)))
                {
                    selectedElement = element;
                }

                if (element.getErdc() != null)
                {
                    // FOR ELEMENT ERDC
                    element.getErdc().setVisible(GUILayout.Toggle(element.getErdc().isVisible(), "", GUILayout.Width(windowWidth * 0.06f)));
                    if (GUILayout.Button(element.getErdc().getElementId(), GUILayout.Width(windowWidth * 0.39f)))
                    {
                        selectedElement = element;
                    }

                    if (GUILayout.Button(conditionTex, GUILayout.Width(windowWidth * 0.29f)))
                    {
                        selectedElement = element;
                        ConditionEditorWindow window = ScriptableObject.CreateInstance <ConditionEditorWindow>();
                        window.Init(element.getErdc().getConditions());
                    }
                }
                else
                {
                    if (GUILayout.Button("", GUILayout.Width(windowWidth * 0.06f)))
                    {
                        selectedElement = element;
                    }
                    if (GUILayout.Button("", GUILayout.Width(windowWidth * 0.39f)))
                    {
                        selectedElement = element;
                    }
                    if (GUILayout.Button(conditionTex, GUILayout.Width(windowWidth * 0.29f)))
                    {
                        selectedElement = element;
                    }
                }


                GUILayout.EndHorizontal();
                GUI.skin = defaultSkin;
            }
            GUILayout.EndScrollView();
            GUILayout.EndArea();


            /*
             * Right panel
             */
            GUILayout.BeginArea(rightPanelRect);
            GUI.skin = noBackgroundSkin;
            if (GUILayout.Button(addTexture, GUILayout.MaxWidth(0.08f * windowWidth)))
            {
                addMenu.menu.ShowAsContext();
            }
            if (GUILayout.Button(moveUp, GUILayout.MaxWidth(0.08f * windowWidth)))
            {
                currentScene.getReferencesList().moveElementUp(selectedElement.getErdc());
            }
            if (GUILayout.Button(moveDown, GUILayout.MaxWidth(0.08f * windowWidth)))
            {
                currentScene.getReferencesList().moveElementDown(selectedElement.getErdc());
            }
            if (GUILayout.Button(clearImg, GUILayout.MaxWidth(0.08f * windowWidth)))
            {
                currentScene.getReferencesList().deleteElement(selectedElement.getErdc(), false);
            }
            GUI.skin = defaultSkin;
            GUILayout.EndArea();


            if (backgroundPath != "")
            {
                GUILayout.BeginArea(infoPreviewRect);
                // Show preview dialog
                // Button visible only is there is at least 1 object
                if (currentScene != null && selectedElement != null)
                {
                    if (GUILayout.Button(TC.get("DefaultClickAction.ShowDetails") + "/" + TC.get("GeneralText.Edit")))
                    {
                        ObjectInSceneRefrencesEditor window = ScriptableObject.CreateInstance <ObjectInSceneRefrencesEditor>();
                        window.Init(this, currentScene, currentScene.getReferencesList().getAllReferencesDataControl().IndexOf(selectedElement));
                    }
                }
                GUILayout.EndArea();
                GUI.DrawTexture(previewRect, backgroundPreviewTex, ScaleMode.ScaleToFit);
            }
            else
            {
                GUILayout.BeginArea(infoPreviewRect);
                GUILayout.Button("No background!");
                GUILayout.EndArea();
            }
        }
Beispiel #15
0
        public override bool addElement(int type, string id)
        {
            bool   elementAdded = false;
            string selectedItem = id;

            if (type == Controller.ITEM_REFERENCE)
            {
                // Take the list of the items
                string[] items = controller.getIdentifierSummary().getItemIds();
                // If the list has elements, show the dialog with the options
                if (items.Length > 0)
                {
                    // If some value was selected
                    if (selectedItem != null)
                    {
                        ElementReference newElementReference = new ElementReference(selectedItem, 50, 50);
                        int counter = count(newElementReference);
                        ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, newElementReference, type, counter);
                        itemReferencesList.Add(newElementReference);
                        ElementContainer ec = new ElementContainer(erdc, -1, null);
                        lastElementContainer = ec;
                        reassignLayerAllReferencesDataControl(insertInOrder(ec, false));
                        elementAdded = true;
                    }
                }
                else
                {
                    controller.showErrorDialog(TC.get("Operation.AddItemReferenceTitle"), TC.get("Operation.AddItemReferenceErrorNoItems"));
                }
            }

            if (type == Controller.ATREZZO_REFERENCE)
            {
                string[] items = controller.getIdentifierSummary().getAtrezzoIds();

                // If the list has elements, show the dialog with the options
                if (items.Length > 0)
                {
                    if (selectedItem != null)
                    {
                        ElementReference newElementReference = new ElementReference(selectedItem, 50, 50);
                        int counter = count(newElementReference);
                        ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, newElementReference, type, counter);
                        atrezzoReferencesList.Add(newElementReference);
                        ElementContainer ec = new ElementContainer(erdc, -1, null);
                        lastElementContainer = ec;
                        reassignLayerAllReferencesDataControl(insertInOrder(ec, false));
                        elementAdded = true;
                    }
                }
                else
                {
                    controller.showErrorDialog(TC.get("Operation.AddAtrezzoReferenceTitle"), TC.get("Operation.AddReferenceErrorNoAtrezzo"));
                }
            }

            if (type == Controller.NPC_REFERENCE)
            {
                string[] items = controller.getIdentifierSummary().getNPCIds();
                if (items.Length > 0)
                {
                    if (selectedItem != null)
                    {
                        ElementReference newElementReference = new ElementReference(selectedItem, 50, 50);
                        int counter = count(newElementReference);
                        ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, newElementReference, type, counter);
                        npcReferencesList.Add(newElementReference);
                        ElementContainer ec = new ElementContainer(erdc, -1, null);
                        lastElementContainer = ec;
                        reassignLayerAllReferencesDataControl(insertInOrder(ec, false));
                        elementAdded = true;
                    }
                }
                else
                {
                    controller.showErrorDialog(TC.get("Operation.AddNPCReferenceTitle"), TC.get("Operation.AddReferenceErrorNoNPC"));
                }
            }

            return(elementAdded);
        }