public void draw(Condition c) { condition = c as VarCondition; EditorGUILayout.BeginHorizontal(); if (Available) { var vars = Controller.Instance.VarFlagSummary.getVars(); var index = Mathf.Max(0, Array.IndexOf(vars, c.getId())); condition.setId(vars[EditorGUILayout.Popup(index >= 0 ? index : 0, vars)]); } else { using (new GUILayout.HorizontalScope(GUILayout.Height(15))) { EditorGUILayout.HelpBox(TC.get("Condition.Var.Warning"), MessageType.Error); } } if (GUILayout.Button("New", collapseStyle, GUILayout.Width(35), GUILayout.Height(15))) { Controller.Instance.ShowInputDialog(TC.get("Vars.AddVar"), TC.get("Vars.AddVarMessage"), DEFAULT_VAR_ID, condition, this); } if (Available) { condition.setState(indexToState[EditorGUILayout.Popup(stateToIndex[condition.getState()], valueStrings)]); condition.setValue(int.Parse(EditorGUILayout.TextField(condition.getValue().ToString()))); } EditorGUILayout.EndHorizontal(); }
public static bool check(Condition condition) { bool ret = true; switch (condition.getType()) { case Condition.FLAG_CONDITION: ret = Game.Instance.GameState.CheckFlag(condition.getId()) == condition.getState(); break; case Condition.GLOBAL_STATE_CONDITION: ret = Game.Instance.GameState.CheckGlobalState(condition.getId()) == condition.getState(); break; case Condition.NO_STATE: break; case Condition.VAR_CONDITION: VarCondition c = (VarCondition)condition; int val = Game.Instance.GameState.GetVariable(condition.getId()); switch (c.getState()) { case VarCondition.VAR_EQUALS: ret = val == c.getValue(); break; case VarCondition.VAR_GREATER_THAN: ret = val > c.getValue(); break; case VarCondition.VAR_GREATER_EQUALS_THAN: ret = val >= c.getValue(); break; case VarCondition.VAR_LESS_THAN: ret = val < c.getValue(); break; case VarCondition.VAR_LESS_EQUALS_THAN: ret = val <= c.getValue(); break; } break; } return(ret); }
public void SerializeSingleVarConditionTest() { var serializedVarCondition = JsonUtility.ToJson(varCondition); Debug.Log(serializedVarCondition); var restoredVarCondition = JsonUtility.FromJson <VarCondition>(serializedVarCondition); Assert.NotNull(restoredVarCondition); Assert.AreEqual(varCondition.GetType(), restoredVarCondition.GetType()); Assert.AreEqual(varCondition.getType(), restoredVarCondition.getType()); Assert.AreEqual(varCondition.getState(), restoredVarCondition.getState()); Assert.AreEqual(varCondition.getValue(), restoredVarCondition.getValue()); }
public Dictionary <string, string> getCondition(int index1, int index2) { Dictionary <string, string> conditionProperties = new Dictionary <string, string>(); // Check index if (index1 < 0 || index1 >= conditions.size()) { return(null); } List <Condition> conditionsList = conditions.get(index1); // Check index2 if (index2 < 0 || index2 >= conditionsList.Count) { return(null); } Condition condition = conditionsList[index2]; // Put ID conditionProperties.Add(CONDITION_ID, condition.getId()); // Put State conditionProperties.Add(CONDITION_STATE, condition.getState().ToString()); // Put Type if (condition.getType() == Condition.FLAG_CONDITION) { conditionProperties.Add(CONDITION_TYPE, CONDITION_TYPE_FLAG); //Put value conditionProperties.Add(CONDITION_VALUE, condition.getState().ToString()); } else if (condition.getType() == Condition.VAR_CONDITION) { conditionProperties.Add(CONDITION_TYPE, CONDITION_TYPE_VAR); //Put value VarCondition varCondition = (VarCondition)condition; conditionProperties.Add(CONDITION_VALUE, varCondition.getValue().ToString()); } else if (condition.getType() == Condition.GLOBAL_STATE_CONDITION) { conditionProperties.Add(CONDITION_TYPE, CONDITION_TYPE_GS); //Put value conditionProperties.Add(CONDITION_VALUE, condition.getState().ToString()); } return(conditionProperties); }
public void draw(Condition c) { condition = c as VarCondition; EditorGUILayout.BeginHorizontal(); if (Available) { var vars = Controller.Instance.VarFlagSummary.getVars(); var index = Mathf.Max(0, Array.IndexOf(vars, c.getId())); condition.setId(vars[EditorGUILayout.Popup(index >= 0 ? index : 0, vars)]); condition.setState(indexToState[EditorGUILayout.Popup(stateToIndex[condition.getState()], valueStrings)]); condition.setValue(int.Parse(EditorGUILayout.TextField(condition.getValue().ToString()))); } else { EditorGUILayout.HelpBox(TC.get("Condition.Var.Warning"), MessageType.Error); } EditorGUILayout.EndHorizontal(); }
public void draw(Condition c) { condition = c as VarCondition; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(TC.get("Condition.VarID")); if (Avaiable) { int index = Array.IndexOf(vars, c.getId()); condition.setId(vars[EditorGUILayout.Popup(index >= 0 ? index : 0, vars)]); condition.setState(EditorGUILayout.Popup(c.getState() - 4, types) + 4); condition.setValue(int.Parse(EditorGUILayout.TextField(condition.getValue().ToString()))); } else { EditorGUILayout.HelpBox(TC.get("Condition.Var.Warning"), MessageType.Error); } EditorGUILayout.EndHorizontal(); }
private static XmlElement createConditionElement(XmlDocument doc, Condition condition) { XmlElement conditionElement = null; if (condition.getType() == Condition.FLAG_CONDITION) { // Create the tag if (condition.getState() == FlagCondition.FLAG_ACTIVE) { conditionElement = doc.CreateElement("active"); } else if (condition.getState() == FlagCondition.FLAG_INACTIVE) { conditionElement = doc.CreateElement("inactive"); } // Set the target flag and append it conditionElement.SetAttribute("flag", condition.getId()); } else if (condition.getType() == Condition.VAR_CONDITION) { VarCondition varCondition = (VarCondition)condition; // Create the tag if (varCondition.getState() == VarCondition.VAR_EQUALS) { conditionElement = doc.CreateElement("equals"); } else if (varCondition.getState() == VarCondition.VAR_NOT_EQUALS) { conditionElement = doc.CreateElement("not-equals"); } else if (condition.getState() == VarCondition.VAR_GREATER_EQUALS_THAN) { conditionElement = doc.CreateElement("greater-equals-than"); } else if (condition.getState() == VarCondition.VAR_GREATER_THAN) { conditionElement = doc.CreateElement("greater-than"); } else if (condition.getState() == VarCondition.VAR_LESS_EQUALS_THAN) { conditionElement = doc.CreateElement("less-equals-than"); } else if (condition.getState() == VarCondition.VAR_LESS_THAN) { conditionElement = doc.CreateElement("less-than"); } // Set the target flag and append it conditionElement.SetAttribute("var", varCondition.getId()); conditionElement.SetAttribute("value", varCondition.getValue().ToString()); } else if (condition.getType() == Condition.GLOBAL_STATE_CONDITION) { GlobalStateCondition globalStateCondition = (GlobalStateCondition)condition; // Create the tag conditionElement = doc.CreateElement("global-state-ref"); // Set the target flag and append it conditionElement.SetAttribute("id", globalStateCondition.getId()); conditionElement.SetAttribute("value", globalStateCondition.getState() == GlobalStateCondition.GS_SATISFIED ? "true" : "false"); } return(conditionElement); }