Beispiel #1
0
        private void OnInputBChanged(ChangeEvent <string> eventInfo, StatDatam statDatam)
        {
            if (eventInfo.newValue == "Rate" || eventInfo.newValue == "Multiplier" || eventInfo.newValue == "Experience Required")
            {
                //Debug.LogError("New Value is weird: " + eventInfo.newValue);
                return;
            }
            Stats stats     = (Stats)cachedProperty.GetValue();
            int   statIndex = stats.GetStatIndex(statDatam);

            if (statDatam.type == StatType.State)
            {
                stats.SetStateMaxValue(statIndex, float.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
            else if (statDatam.type == StatType.Regen)
            {
                //Debug.LogError("eventInfo.newValue: " + eventInfo.eventTypeId + "::" + eventInfo.newValue);
                stats.SetRegenRate(statIndex, float.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
            else if (statDatam.type == StatType.Attribute)
            {
                stats.SetAttributeMultiplier(statIndex, float.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
            else if (statDatam.type == StatType.Level)
            {
                stats.SetLevelExperienceRequired(statIndex, int.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
        }
Beispiel #2
0
        private void OnInputAChanged(ChangeEvent <string> eventInfo, StatDatam statDatam)
        {
            Stats stats     = (Stats)cachedProperty.GetValue();
            int   statIndex = stats.GetStatIndex(statDatam);

            if (statDatam.type == StatType.Base)
            {
                stats.SetStatValue(statIndex, float.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
            else if (statDatam.type == StatType.State)
            {
                stats.SetStateValue(statIndex, float.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
            else if (statDatam.type == StatType.Regen)
            {
                stats.SetRegenValue(statIndex, float.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
            else if (statDatam.type == StatType.Attribute)
            {
                stats.SetAttributeValue(statIndex, float.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
            else if (statDatam.type == StatType.Level)
            {
                stats.SetLevelValue(statIndex, int.Parse(eventInfo.newValue));
                cachedProperty.SetValue(stats);
            }
        }
Beispiel #3
0
 public int GetStatIndex(StatDatam statDatam)
 {
     if (statDatam.type == StatType.Base)
     {
         for (int i = 0; i < stats.Length; i++)
         {
             if (stats[i].id == statDatam.Value.id)
             {
                 return(i);
             }
         }
     }
     else if (statDatam.type == StatType.Regen)
     {
         for (int i = 0; i < regens.Length; i++)
         {
             if (regens[i].id == statDatam.Value.id)
             {
                 return(i);
             }
         }
     }
     else if (statDatam.type == StatType.State)
     {
         for (int i = 0; i < states.Length; i++)
         {
             if (states[i].id == statDatam.Value.id)
             {
                 return(i);
             }
         }
     }
     else if (statDatam.type == StatType.Attribute)
     {
         for (int i = 0; i < attributes.Length; i++)
         {
             if (attributes[i].id == statDatam.Value.id)
             {
                 return(i);
             }
         }
     }
     else if (statDatam.type == StatType.Level)
     {
         for (int i = 0; i < levels.Length; i++)
         {
             if (levels[i].id == statDatam.Value.id)
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Beispiel #4
0
        private void InitializeInputB(VisualElement inputB, StatDatam statDatam, Stats stats, int statIndex)
        {
            #region StatMaxValue
            TextField statInput = inputB as TextField;
            if (statIndex != -1 && statDatam.type != StatType.Base)
            {
                // inputB.visible = true;
                SetVisibility(inputB, true);
                if (statDatam.type == StatType.State)
                {
                    statInput.value = stats.states[statIndex].maxValue.ToString();
                }
                else if (statDatam.type == StatType.Regen)
                {
                    statInput.value = stats.regens[statIndex].rate.ToString();
                }
                else if (statDatam.type == StatType.Attribute)
                {
                    statInput.value = stats.attributes[statIndex].multiplier.ToString();
                }
                else if (statDatam.type == StatType.Level)
                {
                    statInput.value = stats.levels[statIndex].experienceRequired.ToString();
                }
            }
            else
            {
                //inputB.visible = false;
                SetVisibility(inputB, false);
            }

            if (statDatam.type == StatType.State)
            {
                statInput.label = "Max Value";
            }
            else if (statDatam.type == StatType.Regen)
            {
                statInput.label = "Rate";
            }
            else if (statDatam.type == StatType.Attribute)
            {
                statInput.label = "Multiplier";
            }
            else if (statDatam.type == StatType.Level)
            {
                statInput.label = "Experience Required";
            }
            statInput.RegisterValueChangedCallback((eventInfo) =>
            {
                OnInputBChanged(eventInfo, statDatam);
            });
            #endregion
        }
Beispiel #5
0
 public void RemoveStat(StatDatam statDatam, int indexOf)
 {
     if (statDatam.type == StatType.Base)
     {
         List <Staz> priorStates = new List <Staz>(stats.ToArray());
         stats = new BlitableArray <Staz>(stats.Length - 1, Allocator.Persistent);
         priorStates.RemoveAt(indexOf);
         for (int i = 0; i < priorStates.Count; i++)
         {
             stats[i] = priorStates[i];
         }
     }
     else if (statDatam.type == StatType.State)
     {
         List <StateStaz> priorStates = new List <StateStaz>(states.ToArray());
         states = new BlitableArray <StateStaz>(states.Length - 1, Allocator.Persistent);
         priorStates.RemoveAt(indexOf);
         for (int i = 0; i < priorStates.Count; i++)
         {
             states[i] = priorStates[i];
         }
     }
     else if (statDatam.type == StatType.Regen)
     {
         List <RegenStaz> priorStates = new List <RegenStaz>(regens.ToArray());
         regens = new BlitableArray <RegenStaz>(regens.Length - 1, Allocator.Persistent);
         priorStates.RemoveAt(indexOf);
         for (int i = 0; i < priorStates.Count; i++)
         {
             regens[i] = priorStates[i];
         }
     }
     else if (statDatam.type == StatType.Attribute)
     {
         List <AttributeStaz> priorStats = new List <AttributeStaz>(attributes.ToArray());
         attributes = new BlitableArray <AttributeStaz>(attributes.Length - 1, Allocator.Persistent);
         priorStats.RemoveAt(indexOf);
         for (int i = 0; i < priorStats.Count; i++)
         {
             attributes[i] = priorStats[i];
         }
     }
     else if (statDatam.type == StatType.Level)
     {
         List <Level> priorStats = new List <Level>(levels.ToArray());
         levels = new BlitableArray <Level>(levels.Length - 1, Allocator.Persistent);
         priorStats.RemoveAt(indexOf);
         for (int i = 0; i < priorStats.Count; i++)
         {
             levels[i] = priorStats[i];
         }
     }
 }
Beispiel #6
0
 private void SetStatLabel(Foldout statsFoldout, StatDatam statDatam, Button initButton, bool hasStat)
 {
     if (!hasStat)
     {
         statsFoldout.text = "   - no " + statDatam.name; //  "[" + statDatam.Value.id + "] " +
         if (initButton != null)
         {
             initButton.text = "Give " + statDatam.name;
         }
     }
     else
     {
         statsFoldout.text = "Has " + statDatam.name; //  "[" + statDatam.Value.id + "] " +
         if (initButton != null)
         {
             initButton.text = "Take " + statDatam.name + " Away";
         }
     }
 }
Beispiel #7
0
        private void OnInitButtonClicked(StatDatam statDatam, Button initButton, VisualElement buttonA, VisualElement buttonB, Foldout statsFoldout)
        {
            Stats stats     = (Stats)cachedProperty.GetValue();
            int   statIndex = stats.GetStatIndex(statDatam);

            if (statIndex == -1)
            {
                statIndex = stats.AddStat(statDatam);
            }
            else
            {
                //Debug.LogError("Removing Stat at: " + statIndex);
                stats.RemoveStat(statDatam, statIndex);
                statIndex = -1;
            }
            if (buttonA != null)
            {
                SetVisibility(buttonA, statIndex != -1);
                SetVisibility(buttonB, statIndex != -1 && statDatam.type != StatType.Base);
                //buttonA.visible = statIndex != -1;
                //buttonB.visible = statIndex != -1 && statDatam.type != StatType.Base;
            }
            else
            {
                Debug.LogError("Lambda has nulled button reference.");
            }

            /*if (statIndex == -1)
             * {
             *  initButton.text = "Add " + statDatam.name + "";
             *  statsFoldout.text = statDatam.name + " (0)"; //  "[" + statDatam.Value.id + "] " +
             * }
             * else
             * {
             *  initButton.text = "Remove " + statDatam.name;
             *  statsFoldout.text = statDatam.name + " (X)"; // "[" + statDatam.Value.id + "] " +
             * }*/
            SetStatLabel(statsFoldout, statDatam, initButton, statIndex != -1);
            cachedProperty.SetValue(stats);
        }
Beispiel #8
0
        private void InitializeInputA(VisualElement inputA, StatDatam statDatam, Stats stats, int statIndex)
        {
            TextField statInput = inputA as TextField;

            if (statIndex != -1)
            {
                // inputA.visible = true;
                SetVisibility(inputA, true);
                if (statDatam.type == StatType.Base)
                {
                    statInput.value = stats.stats[statIndex].value.ToString();
                }
                else if (statDatam.type == StatType.State)
                {
                    statInput.value = stats.states[statIndex].value.ToString();
                }
                else if (statDatam.type == StatType.Regen)
                {
                    statInput.value = stats.regens[statIndex].value.ToString();
                }
                else if (statDatam.type == StatType.Attribute)
                {
                    statInput.value = stats.attributes[statIndex].multiplier.ToString();
                }
                else if (statDatam.type == StatType.Level)
                {
                    statInput.value = stats.levels[statIndex].experienceRequired.ToString();
                }
            }
            else
            {
                //inputA.visible = false;
                SetVisibility(inputA, false);
            }
            statInput.RegisterValueChangedCallback((eventInfo) =>
            {
                OnInputAChanged(eventInfo, statDatam);
            });
        }
Beispiel #9
0
        void AddStatUI(StatDatam statDatam)
        {
            int indexOf = stats.GetStatIndex(statDatam);

            //quickToolVisualTree.CloneTree(container);
            // add new statsid to our container
            //var statUI = new VisualElement(statsPrefab);
            statsPrefab.CloneTree(statsHeader);
            var parentFoldout = statsHeader.Query("StatID").First();

            statUIs.Add(parentFoldout);
            parentFoldout.name = statDatam.name;
            Foldout       statsFoldout = parentFoldout as Foldout;
            var           template     = parentFoldout.Query("TemplateStat").First();
            VisualElement inputA       = null;
            VisualElement inputB       = null;

            Image icon = template.Query("IconImage").First() as Image;

            if (icon != null)
            {
                icon.image = statDatam.texture.texture;
            }
            Label descriptionLabel = template.Query("StatDescription").First() as Label;

            if (icon != null)
            {
                descriptionLabel.text = statDatam.description;
            }
            Button initButton = template.Query("InitiateButton").First() as Button;

            if (statsFoldout != null)
            {
                SetStatLabel(statsFoldout, statDatam, initButton, indexOf != -1);
            }
            if (initButton != null)
            {
                initButton.clicked += () =>
                {
                    OnInitButtonClicked(statDatam, initButton, inputA, inputB, statsFoldout);
                };
            }

            foreach (var child in template.Children())
            {
                //Debug.LogError("Child Template names: " + child.name);
                if (child.name == "StatValue")
                {
                    inputA = child;
                    InitializeInputA(inputA, statDatam, stats, indexOf);
                }
                else if (child.name == "StatMaxValue")
                {
                    inputB = child;
                    InitializeInputB(inputB, statDatam, stats, indexOf);
                }

                /*else if (child.name == "IconImage")
                 * {
                 *  Image icon = child as Image;
                 *  if (icon != null)
                 *  {
                 *      icon.image = statDatam.texture.texture;
                 *  }
                 * }
                 * else if (child.name == "StatDescription")
                 * {
                 *  (child as Label).text = statDatam.description;
                 * }*/
            }
        }
Beispiel #10
0
        public int AddStat(StatDatam statDatam)
        {
            int indexOf = -1;

            if (statDatam.type == StatType.Base)
            {
                Staz[] priorStates = stats.ToArray();
                stats = new BlitableArray <Staz>(stats.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStates.Length; i++)
                {
                    stats[i] = priorStates[i];
                }
                Staz newState = new Staz();
                newState.id = statDatam.Value.id;
                stats[priorStates.Length] = newState;
                indexOf = priorStates.Length;
            }
            else if (statDatam.type == StatType.State)
            {
                StateStaz[] priorStates = states.ToArray();
                states = new BlitableArray <StateStaz>(states.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStates.Length; i++)
                {
                    states[i] = priorStates[i];
                }
                StateStaz newState = new StateStaz();
                newState.id = statDatam.Value.id;
                states[priorStates.Length] = newState;
                indexOf = priorStates.Length;
            }
            else if (statDatam.type == StatType.Regen)
            {
                RegenStaz[] priorStates = regens.ToArray();
                regens = new BlitableArray <RegenStaz>(regens.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStates.Length; i++)
                {
                    regens[i] = priorStates[i];
                }
                RegenStaz newState = new RegenStaz();
                newState.id                = statDatam.Value.id;
                newState.targetID          = statDatam.targetStatID;
                regens[priorStates.Length] = newState;
                indexOf = priorStates.Length;
            }
            else if (statDatam.type == StatType.Attribute)
            {
                AttributeStaz[] priorStats = attributes.ToArray();
                attributes = new BlitableArray <AttributeStaz>(attributes.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStats.Length; i++)
                {
                    attributes[i] = priorStats[i];
                }
                AttributeStaz newStat = new AttributeStaz();
                newStat.id       = statDatam.Value.id;
                newStat.targetID = statDatam.targetStatID;
                attributes[priorStats.Length] = newStat;
                indexOf = priorStats.Length;
            }
            else if (statDatam.type == StatType.Level)
            {
                Level[] priorStats = levels.ToArray();
                levels = new BlitableArray <Level>(levels.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStats.Length; i++)
                {
                    levels[i] = priorStats[i];
                }
                Level newStat = new Level();
                newStat.id = statDatam.Value.id;
                //newStat.targetID = statDatam.targetStatID;
                levels[priorStats.Length] = newStat;
                indexOf = priorStats.Length;
            }
            return(indexOf);
        }