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); } }
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); } }
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); }
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; * }*/ } }