Example #1
0
 private void DestroChildAtIndex(EntityManager EntityManager, int index)
 {
     if (EntityManager.Exists(children[index]))
     {
         if (EntityManager.HasComponent <Childrens>(children[index]))
         {
             Childrens childrensChildren = EntityManager.GetComponentData <Childrens>(children[index]);
             childrensChildren.DestroyEntities(EntityManager);
         }
         if (EntityManager.HasComponent <RenderText>(children[index]))
         {
             RenderText text = EntityManager.GetComponentData <RenderText>(children[index]);
             text.DestroyLetters(EntityManager);
         }
         EntityManager.DestroyEntity(children[index]);
     }
 }
Example #2
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            var dialogueTree = Bootstrap.instance.data.dialogues[0].dialogueTree;
            //int startingDialogueID = dialogueTree.id;
            //DialogueDatam dialogueTree = meta[startingDialogueID];
            var        branch     = dialogueTree.branches[0];
            float      fontSize   = 0.03f;
            RenderText renderText = new RenderText
            {
                fontSize = fontSize,
                offsetX  = ((-branch.speech.Length - 1f) / 2f) * fontSize
            };

            renderText.SetColor(Color.blue);
            DialogueUI dialogueUI = new DialogueUI
            {
                treeID           = dialogueTree.id,
                timePerLetterMin = 0.07f,
                timePerLetterMax = 0.21f
            };

            dialogueUI.RandomizeCooldown();
            dialogueUI.SetText(branch.speech, ref renderText);
            //UnityEngine.Debug.LogError("Testing dialogue - self talking: " + dialogueTree.data[0].speech);
            World.EntityManager.AddComponentData(panelUI, dialogueUI);
            World.EntityManager.AddComponentData(panelUI, renderText);
            byte uiIndex = ((byte)((int)PlayerUIType.DialogueUI));

            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = World.EntityManager.GetComponentData <ZoxID>(character).id,
                size        = new float2((branch.speech.Length) * (fontSize * 1.1f), fontSize),
                dirty       = 1,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            Childrens children = new Childrens {
            };

            World.EntityManager.AddComponentData(panelUI, children);
        }
Example #3
0
        private List <Entity> GetButtonsLoop(EntityManager EntityManager, Childrens moreChildren)
        {
            List <Entity> entities = new List <Entity>();

            for (int i = 0; i < moreChildren.children.Length; i++)
            {
                if (EntityManager.Exists(moreChildren.children[i]))
                {
                    if (EntityManager.HasComponent <Button>(moreChildren.children[i]))
                    {
                        entities.Add(moreChildren.children[i]);
                    }
                    if (EntityManager.HasComponent <Childrens>(moreChildren.children[i]))
                    {
                        Childrens childrensChildren = EntityManager.GetComponentData <Childrens>(moreChildren.children[i]);
                        entities.AddRange(GetButtonsLoop(EntityManager, childrensChildren));
                    }
                }
            }
            return(entities);
        }
Example #4
0
 public void DestroyEntities(EntityManager EntityManager)
 {
     for (int i = 0; i < children.Length; i++)
     {
         if (EntityManager.Exists(children[i]))
         {
             if (EntityManager.HasComponent <Childrens>(children[i]))
             {
                 Childrens childrensChildren = EntityManager.GetComponentData <Childrens>(children[i]);
                 childrensChildren.DestroyEntities(EntityManager);
             }
             if (EntityManager.HasComponent <RenderText>(children[i]))
             {
                 RenderText text = EntityManager.GetComponentData <RenderText>(children[i]);
                 text.DestroyLetters(EntityManager);
             }
             EntityManager.DestroyEntity(children[i]);
         }
     }
     if (children.Length > 0)
     {
         children.Dispose();
     }
 }
Example #5
0
        public void UpdateStatUI(UpdateStatUICommand command)
        {
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(command.character);

            if (!uis.ContainsKey(zoxID.id))
            {
                return; // character died
            }
            Stats     stats        = World.EntityManager.GetComponentData <Stats>(command.character);
            Entity    ui           = uis[zoxID.id];
            Childrens children     = World.EntityManager.GetComponentData <Childrens>(ui);
            int       uiArrayIndex = command.statIndex;

            if (command.statType == (byte)StatType.Base)
            {
                Staz      stat  = stats.stats[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.stats.Length;
            }
            if (command.statType == (byte)StatType.State)
            {
                StateStaz stat  = stats.states[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);

                /*Entity textEntity2 = texts.children[0];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.maxValue).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);*/
            }
            else
            {
                uiArrayIndex += stats.states.Length;
            }
            if (command.statType == (byte)StatType.Regen)
            {
                RegenStaz stat  = stats.regens[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.regens.Length;
            }
            if (command.statType == (byte)StatType.Attribute)
            {
                AttributeStaz stat  = stats.attributes[command.statIndex];
                Entity        icon  = children.children[uiArrayIndex];
                Childrens     texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.attributes.Length;
            }
            if (command.statType == (byte)StatType.Level)
            {
                Level      stat       = stats.levels[command.statIndex];
                Entity     icon       = children.children[uiArrayIndex];
                Childrens  texts      = World.EntityManager.GetComponentData <Childrens>(icon);
                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
                // experience required

                /*Entity textEntity2 = texts.children[1];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.experienceGained).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);
                 * // experience gained
                 * Entity textEntity3 = texts.children[2];
                 * RenderText renderText3 = World.EntityManager.GetComponentData<RenderText>(textEntity3);
                 * renderText3.SetText(((int)stat.experienceRequired).ToString());
                 * World.EntityManager.SetComponentData(textEntity3, renderText3);*/
            }
        }
Example #6
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            // spawn stat icon for each thing
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character);
            Stats stats = World.EntityManager.GetComponentData <Stats>(character);

            #region StatIcons
            List <Entity> statIcons = new List <Entity>();
            //List<Entity> statTexts = new List<Entity>();
            float2 iconSize = uiDatam.defaultIconSize;
            for (int i = 0; i < stats.stats.Length; i++)
            {
                if (meta.ContainsKey(stats.stats[i].id) == false)
                {
                    continue;
                }
                statIcons.Add(UIUtilities.SpawnButton(
                                  World.EntityManager,
                                  panelUI,
                                  float3.zero,
                                  iconSize,
                                  meta[stats.stats[i].id].texture.texture, uiDatam.defaultPlayerIcon));
                var textA = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                                                  ((int)stats.stats[i].value).ToString());//, iconSize);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.states.Length; i++)
            {
                if (meta.ContainsKey(stats.states[i].id) == false)
                {
                    continue;
                }
                statIcons.Add(UIUtilities.SpawnButton(
                                  World.EntityManager,
                                  panelUI,
                                  float3.zero,
                                  iconSize,
                                  meta[stats.states[i].id].texture.texture, uiDatam.defaultPlayerIcon));
                var textA = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                                                  ((int)stats.states[i].value).ToString());//,// iconSize,
                // new float3(0, iconSize.y / 2f, 0));
                //var textB = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                //                    ((int)stats.states[i].maxValue).ToString());//, iconSize);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                //children2.children[1] = textB;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.regens.Length; i++)
            {
                Entity icon = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    meta[stats.regens[i].id].texture.texture, uiDatam.defaultPlayerIcon);
                Entity textA = UIUtilities.SpawnText(World.EntityManager, icon, ((int)stats.regens[i].value).ToString());//, iconSize);
                statIcons.Add(icon);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.attributes.Length; i++)
            {
                Entity icon = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    meta[stats.attributes[i].id].texture.texture, uiDatam.defaultPlayerIcon);
                statIcons.Add(icon);
                var textA = UIUtilities.SpawnText(World.EntityManager, icon, ((int)stats.attributes[i].value).ToString());//, iconSize);
                //statTexts.Add(text);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.levels.Length; i++)
            {
                Entity icon = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    meta[stats.levels[i].id].texture.texture, uiDatam.defaultPlayerIcon);
                statIcons.Add(icon);
                var textA = UIUtilities.SpawnText(World.EntityManager, icon,
                                                  ((int)stats.levels[i].value).ToString());//, iconSize);

                /*var textB = UIUtilities.SpawnText(World.EntityManager, icon,
                 *                  ((int)stats.levels[i].experienceGained).ToString(),
                 *                  //iconSize,
                 *                  new float3(0, iconSize.y / 3, 0));
                 * var textC = UIUtilities.SpawnText(World.EntityManager, icon,
                 *                  ((int)stats.levels[i].experienceRequired).ToString(),
                 *                  //iconSize,
                 *                  new float3(0, 2 * iconSize.y / 3, 0));*/
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;

                /*children2.children[1] = textB;
                *  children2.children[2] = textC;*/
                World.EntityManager.AddComponentData(icon, children2);
            }
            #endregion
            Childrens children = new Childrens {
            };
            children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < statIcons.Count; i++)
            {
                children.children[i] = statIcons[i];
            }
            World.EntityManager.AddComponentData(panelUI, children);
            //float2 iconSize = new float2(uiDatam.skillbarIconSize, uiDatam.skillbarIconSize);
            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = uiDatam.statsUIGridSize,
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.003f, 0.003f),
            });
            byte uiIndex = ((byte)((int)PlayerUIType.StatsUI));
            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = zoxID.id,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            //characterStatUIs.Add(zoxID.id, CharacterStatUIData);
            //CreateSelected(character, panelUI, ((byte)PlayerUIType.StatsUI), iconSize);
            OnSelectedButton(zoxID.id, 0);
        }
Example #7
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            var position = World.EntityManager.GetComponentData <ChunkStreamPoint>(character).chunkPosition;
            //EntityBunch icons = new EntityBunch();
            List <Entity> icons2        = new List <Entity>();
            int           mapResolution = 4;

            if (Bootstrap.instance)
            {
                mapResolution = Bootstrap.instance.mapResolution;
            }
            int    rowsCount    = mapResolution;
            int    columnsCount = mapResolution;
            float2 iconSize     = uiDatam.defaultIconSize;

            //for (int j = -(columnsCount / 2); j < (columnsCount / 2); j++)
            for (int j = (columnsCount / 2) - 1; j >= -(columnsCount / 2); j--)
            {
                for (int i = -(rowsCount / 2); i < (rowsCount / 2); i++)
                {
                    float2 mapPosition = new float2(i + position.x, j + position.z);
                    if (chunkMapSystem.maps.ContainsKey(mapPosition))
                    {
                        float3 localMapPosition = float3.zero;// GetGridPosition(i + rowsCount / 2, -(j - (columnsCount / 2) + 1), rowsCount, columnsCount); // + columnsCount / 2
                        icons2.Add(UIUtilities.SpawnVisualElement(
                                       World.EntityManager,
                                       panelUI, localMapPosition,
                                       iconSize,
                                       chunkMapSystem.maps[mapPosition], uiDatam.mapIcon));
                    }
                    else
                    {
                        //Debug.LogError("Could not find map for positoin: " + mapPosition.ToString());
                    }
                }
            }
            Childrens children = new Childrens {
            };

            children.children = new BlitableArray <Entity>(icons2.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < icons2.Count; i++)
            {
                children.children[i] = icons2[i]; // icons2.Count - 1 -
            }
            World.EntityManager.AddComponentData(panelUI, children);
            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = new float2(mapResolution, mapResolution),
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.00f, 0.00f),
            });
            byte  uiIndex     = ((byte)((int)PlayerUIType.SkillbookUI));
            ZoxID characterID = World.EntityManager.GetComponentData <ZoxID>(character);

            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = characterID.id,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });

            /*icons.entities = icons2.ToArray();;
             * if (mapIcons.ContainsKey(characterID.id))
             * {
             *  mapIcons.Remove(characterID.id);
             * // Debug.LogError("Map Icons in there twice for: " + characterID.id);
             * }
             * mapIcons.Add(characterID.id, icons);*/
        }
Example #8
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            if (World.EntityManager.HasComponent <QuestLog>(character) == false)
            {
                Debug.LogError("Tried to add character without questlog.");
                return;
            }
            int      zoxID    = World.EntityManager.GetComponentData <ZoxID>(character).id;
            QuestLog questlog = World.EntityManager.GetComponentData <QuestLog>(character);

            //EntityBunch iconGroup = new EntityBunch();
            //EntityBunch textGroup = new EntityBunch();
            List <Entity> statIcons = new List <Entity>();
            List <Entity> statTexts = new List <Entity>();
            float2        iconSize  = uiDatam.defaultIconSize;

            for (int i = 0; i < questlog.quests.Length; i++)
            {
                Texture2D iconTexture = null;
                if (questlog.quests[i].metaID != 0)
                {
                    QuestDatam questMeta = meta[questlog.quests[i].metaID];
                    if (questMeta != null && questMeta.texture)
                    {
                        iconTexture = questMeta.texture.texture;
                    }
                }
                float3 position = float3.zero;// GetGridPosition(i, 3, 3);
                Entity icon     = UIUtilities.SpawnVisualElement(
                    World.EntityManager,
                    panelUI,
                    position,
                    iconSize,
                    iconTexture, uiDatam.defaultPlayerIcon);
                //Entity text = SpawnText(icon, ((int)questlog.quests[i].GetCompleted()).ToString());
                Entity text = UIUtilities.SpawnText(World.EntityManager, icon, ((int)questlog.quests[i].GetCompleted()).ToString());//, iconSize);
                statIcons.Add(icon);
                statTexts.Add(text);
            }
            //iconGroup.entities = statIcons.ToArray(); // new Entity[stats.stats.Length];
            //textGroup.entities = statTexts.ToArray(); // new Entity[stats.stats.Length];

            Childrens children = new Childrens {
            };

            children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < statIcons.Count; i++)
            {
                children.children[i] = statIcons[i];
            }
            World.EntityManager.AddComponentData(panelUI, children);
            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = uiDatam.questlogGridSize,
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.003f, 0.003f),
            });
            byte uiIndex = ((byte)((int)PlayerUIType.QuestlogUI));

            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = zoxID,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            OnSelectedButton(zoxID, 0);
        }
Example #9
0
        //public override void OnClickedButton(int characterID, int arrayIndex)
        //{
        //int originalArrayIndex = arrayIndex;
        //Entity character = characterSpawnSystem.characters[characterID];
        //Stats stats = World.EntityManager.GetComponentData<Stats>(character);
        //}

        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            // spawn stat icon for each thing
            ZoxID  zoxID  = World.EntityManager.GetComponentData <ZoxID>(character);
            Skills skills = World.EntityManager.GetComponentData <Skills>(character);

            #region StatIcons
            List <Entity> statIcons = new List <Entity>();
            //List<Entity> statTexts = new List<Entity>();
            float2 iconSize = uiDatam.defaultIconSize;

            for (int i = 0; i < skills.skills.Length; i++)
            {
                int metaID = skills.skills[i].id;
                if (meta.ContainsKey(metaID))
                {
                    statIcons.Add(UIUtilities.SpawnButton(
                                      World.EntityManager,
                                      panelUI,
                                      float3.zero,
                                      iconSize,
                                      meta[metaID].texture.texture, uiDatam.defaultPlayerIcon));
                    Childrens textLink = new Childrens {
                        children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent)
                    };
                    textLink.children[0] = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                                                                 ((int)skills.skills[i].attackDamage).ToString()); //, iconSize);
                    World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], textLink);
                }
                else
                {
                    Debug.LogError("Trying to add meta id in StatsUI (Stats(" + i + ")) that doesn't exist: " + metaID);
                }
            }
            #endregion
            Childrens children = new Childrens {
            };
            children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < statIcons.Count; i++)
            {
                children.children[i] = statIcons[i];
            }
            World.EntityManager.AddComponentData(panelUI, children);
            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = uiDatam.inventoryGridSize,
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.003f, 0.003f),
            });
            byte uiIndex = ((byte)((int)PlayerUIType.SkillbookUI));
            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = zoxID.id,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            OnSelectedButton(zoxID.id, 0);
        }
Example #10
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            int           zoxID     = World.EntityManager.GetComponentData <ZoxID>(character).id;
            var           inventory = World.EntityManager.GetComponentData <Equipment>(character);
            List <Entity> cells     = new List <Entity>();
            float2        iconSize  = uiDatam.defaultIconSize;

            for (int i = 0; i < inventory.body.Length; i++)
            {
                var       piece       = inventory.body[i];
                Texture2D iconTexture = null;
                if (piece.data.id != 0)
                {
                    ItemDatam itemDatam = meta[piece.data.id];
                    if (itemDatam != null && itemDatam.texture)
                    {
                        iconTexture = itemDatam.texture.texture;
                    }
                }
                Entity icon = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    iconTexture,
                    uiDatam.defaultPlayerIcon);
                cells.Add(icon);
            }

            /*for (int i = 0; i < inventory.gear.Length; i++)
             * {
             *  var piece = inventory.gear[i];
             *  Texture2D iconTexture = null;
             *  if (piece.metaID != 0)
             *  {
             *      ItemDatam itemDatam = meta[piece.metaID];
             *      if (itemDatam != null && itemDatam.texture)
             *      {
             *          iconTexture = itemDatam.texture.texture;
             *      }
             *  }
             *  float3 position = float3.zero; // GetGridPosition(i, 3, 3);
             *  Entity icon = UIUtilities.SpawnVisualElement(
             *      World.EntityManager,
             *      panelUI,
             *      position,
             *      iconSize,
             *      iconTexture,
             *      uiDatam.defaultPlayerIcon);
             *  Childrens textLink = new Childrens { children = new BlitableArray<Entity>(1, Unity.Collections.Allocator.Persistent) };
             *  textLink.children[0] = UIUtilities.SpawnText(World.EntityManager, icon, ((int)piece.durability).ToString()); //, iconSize);
             *  World.EntityManager.AddComponentData(icon, textLink);
             *  icons.Add(icon);
             * }*/

            Childrens children = new Childrens {
            };

            children.children = new BlitableArray <Entity>(cells.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < cells.Count; i++)
            {
                children.children[i] = cells[i];
            }
            World.EntityManager.AddComponentData(panelUI, children);

            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = uiDatam.inventoryGridSize,
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.003f, 0.003f),
            });

            byte uiIndex = ((byte)((int)PlayerUIType.EquipmentUI));

            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = zoxID,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            OnSelectedButton(zoxID, 0);
        }
Example #11
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            if (World.EntityManager.HasComponent <Inventory>(character) == false)
            {
                Debug.LogError("Cannot spawn Inventory UI as character does not have inventory.");
                return;
            }
            int           zoxID     = World.EntityManager.GetComponentData <ZoxID>(character).id;
            Inventory     inventory = World.EntityManager.GetComponentData <Inventory>(character);
            List <Entity> buttons   = new List <Entity>();
            float2        iconSize  = uiDatam.defaultIconSize;

            for (int i = 0; i < inventory.items.Length; i++)
            {
                Texture2D iconTexture = null;
                if (inventory.items[i].data.id != 0 && meta.ContainsKey(inventory.items[i].data.id))
                {
                    ItemDatam itemDatam = meta[inventory.items[i].data.id];
                    if (itemDatam != null && itemDatam.texture)
                    {
                        iconTexture = itemDatam.texture.texture;
                    }
                }
                Entity button = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    iconTexture,
                    uiDatam.defaultPlayerIcon);
                World.EntityManager.AddComponentData(button, new ItemUI {
                    index = i
                });
                buttons.Add(button);
                Childrens textLink = new Childrens {
                    children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent)
                };
                string numberString = ((int)inventory.items[i].quantity).ToString();
                if (numberString == "0" || numberString == "1")
                {
                    numberString = "";
                }
                textLink.children[0] = UIUtilities.SpawnText(World.EntityManager, button, numberString, float3.zero, uiDatam.overlayTextColor);
                World.EntityManager.AddComponentData(button, textLink);
            }

            Childrens children = new Childrens {
            };

            children.children = new BlitableArray <Entity>(buttons.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < buttons.Count; i++)
            {
                children.children[i] = buttons[i];
            }
            World.EntityManager.AddComponentData(panelUI, children);

            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = uiDatam.inventoryGridSize,
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.003f, 0.003f),
            });

            byte uiIndex = ((byte)((int)PlayerUIType.InventoryUI));

            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = zoxID,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            OnSelectedButton(zoxID, 0);
        }
Example #12
0
        protected override void OnUpdate()
        {
            Entities.WithAll <DialogueUI, RenderText>().ForEach((Entity e, ref DialogueUI dialogue, ref RenderText renderText) =>
            {
                if (UnityEngine.Time.time - dialogue.timeBegun >= dialogue.timePerLetter)
                {
                    if (dialogue.HasFinished())
                    {
                        // spawn next button now
                        // if has not spawned next buttons
                        if (dialogue.hasSpawnedButtons == 0)
                        {
                            dialogue.hasSpawnedButtons = 1;
                            Color textColor            = Color.blue; //  uiDatam.menuTextColor
                            DialogueDatam dialogueTree = meta[dialogue.treeID];
                            var currentBranch          = dialogueTree.dialogueTree.branches[dialogue.branchID];
                            Childrens children         = new Childrens {
                            };
                            if (currentBranch.links.Length <= 1)
                            {
                                // spawn next button
                                children.children      = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                                float3 buttonPosition  = new float3(0, (-renderText.fontSize / 2f - buttonFontSize / 2f), 0);
                                string dialogueOptionA = "Next";
                                children.children[0]   = UIUtilities.SpawnButtonWithText(World.EntityManager, e,
                                                                                         buttonPosition, buttonFontSize, dialogueOptionA,
                                                                                         uiDatam.menuButton, uiDatam.defaultMenuColor, textColor);
                            }
                            else
                            {
                                children.children = new BlitableArray <Entity>(currentBranch.links.Length, Unity.Collections.Allocator.Persistent);
                                // spawn a button for all links
                                float3 offset               = new float3();
                                children.children           = new BlitableArray <Entity>(currentBranch.links.Length, Unity.Collections.Allocator.Persistent);
                                DialogueDatam dialogueDatam = meta[dialogue.treeID];
                                for (int i = 0; i < currentBranch.links.Length; i++)
                                {
                                    float3 buttonPosition = new float3(0, (-renderText.fontSize / 2f - buttonFontSize / 2f), 0);
                                    buttonPosition       += offset;
                                    offset = buttonPosition;
                                    string dialogueOptionA = "Leave";
                                    for (int j = 0; j < dialogueDatam.dialogueTree.branches.Length; j++)
                                    {
                                        var otherBranch = dialogueDatam.dialogueTree.branches[j];
                                        if (otherBranch.id == currentBranch.links[i])
                                        {
                                            dialogueOptionA = otherBranch.speech;
                                            break;
                                        }
                                    }
                                    children.children[i] = UIUtilities.SpawnButtonWithText(World.EntityManager, e,
                                                                                           buttonPosition, buttonFontSize, dialogueOptionA,
                                                                                           uiDatam.menuButton, uiDatam.defaultMenuColor, textColor);
                                }
                            }
                            World.EntityManager.SetComponentData(e, children);
                            // set navigation dirty
                            var panelUI             = World.EntityManager.GetComponentData <PanelUI>(e);
                            panelUI.navigationDirty = 1;
                            World.EntityManager.SetComponentData(e, panelUI);
                        }
                        // or spawn dialogue options
                        else if (dialogue.confirmedChoice != 0)
                        {
                            IncrementDialogue(e, ref dialogue, ref renderText);
                            dialogue.confirmedChoice   = 0;
                            dialogue.hasSpawnedButtons = 0;
                            // remove previous buttons
                            Childrens childrens = World.EntityManager.GetComponentData <Childrens>(e);
                            childrens.DestroyEntities(World.EntityManager);
                            World.EntityManager.SetComponentData(e, new Childrens {
                            });

                            var panelUI             = World.EntityManager.GetComponentData <PanelUI>(e);
                            panelUI.navigationDirty = 1;
                            World.EntityManager.SetComponentData(e, panelUI);
                        }
                    }
                    else
                    {
                        IncrementLetters(ref dialogue, ref renderText);
                        if (dialogue.confirmedChoice != 0)
                        {
                            dialogue.confirmedChoice = 0;   // shouldn't be able to get here
                        }
                    }
                }
            });
        }