public VarConditionEditor() { var stateToStringEnumerator = stateToString.GetEnumerator(); for (int i = 0; i < stateToString.Count; i++) { stateToStringEnumerator.MoveNext(); indexToState.Add(i, stateToStringEnumerator.Current.Key); stateToIndex.Add(stateToStringEnumerator.Current.Key, i); } valueStrings = stateToString.Values.ToArray(); if (Available) { condition = new VarCondition(Controller.Instance.VarFlagSummary.getVars()[0], 4, 0); } if (collapseStyle == null) { collapseStyle = new GUIStyle(GUI.skin.button); collapseStyle.padding = new RectOffset(0, 0, 0, 0); collapseStyle.margin = new RectOffset(0, 5, 2, 0); collapseStyle.normal.textColor = Color.blue; collapseStyle.focused.textColor = Color.blue; collapseStyle.active.textColor = Color.blue; collapseStyle.hover.textColor = Color.blue; } }
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 VarConditionEditor() { if (Available) { condition = new VarCondition(Controller.Instance.VarFlagSummary.getVars()[0], 4, 0); } }
public override object Clone() { VarCondition vc = (VarCondition)base.Clone(); vc.id = (id != null ? id : null); vc.state = state; vc.type = type; vc.value = value; return(vc); }
public void ConditionsSetup() { flagCondition = new FlagCondition(FlagId, 1); varCondition = new VarCondition(VarId, 1, 2); globalStateCondition = new GlobalStateCondition(GlobalStateId); conditions = new Conditions(); conditions.Add(flagCondition); conditions.Add(varCondition); conditions.Add(varCondition); }
public VarConditionEditor() { vars = Controller.getInstance().getVarFlagSummary().getVars(); if (vars == null || vars.Length == 0) { Avaiable = false; } else { Avaiable = true; condition = new VarCondition(vars[0], 4, 0); } }
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; case VarCondition.VAR_NOT_EQUALS: ret = val != c.getValue(); break; } break; } return(ret); }
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 VarConditionEditor() { var stateToStringEnumerator = stateToString.GetEnumerator(); for (int i = 0; i < stateToString.Count; i++) { stateToStringEnumerator.MoveNext(); indexToState.Add(i, stateToStringEnumerator.Current.Key); stateToIndex.Add(stateToStringEnumerator.Current.Key, i); } valueStrings = stateToString.Values.ToArray(); if (Available) { condition = new VarCondition(Controller.Instance.VarFlagSummary.getVars()[0], 4, 0); } }
public void OnDialogOk(string message, object workingObject = null, object workingObjectSecond = null) { if (string.IsNullOrEmpty(message)) { return; } Controller.Instance.VarFlagSummary.addVar(message); if (condition == null) { condition = new VarCondition(message, 0, 0); } else { condition.setId(message); } }
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(); }
public void OnDialogOk(string message, object workingObject = null, object workingObjectSecond = null) { if (string.IsNullOrEmpty(message)) { return; } Controller.Instance.VarFlagSummary.addVar(message); if (condition == null) { condition = new VarCondition(message, 0, 0); } else { if (!string.IsNullOrEmpty(condition.getId())) { Controller.Instance.VarFlagSummary.deleteVarReference(condition.getId()); } condition.setId(message); } Controller.Instance.VarFlagSummary.addVarReference(message); Controller.Instance.DataModified(); }
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); }
public override bool doTool() { Condition newCondition = null; int type = ConditionsController.getTypeFromstring(conditionType); if (type == ConditionsController.FLAG_CONDITION) { newCondition = new FlagCondition(conditionId, ConditionsController.getStateFromstring(conditionState)); } else if (type == ConditionsController.VAR_CONDITION) { newCondition = new VarCondition(conditionId, ConditionsController.getStateFromstring(conditionState), int.Parse(value)); } else if (type == ConditionsController.GLOBAL_STATE_CONDITION) { newCondition = new GlobalStateCondition(conditionId, ConditionsController.getStateFromstring(conditionState)); } if (newCondition != null) { if (index1 < conditions.size()) { if (index2 == ConditionsController.INDEX_NOT_USED) { // Add new block List <Condition> newBlock = new List <Condition>(); newBlock.Add(newCondition); conditions.add(index1, newBlock); indexAdded = index1; blockAdded = newBlock; } else { List <Condition> block = conditions.get(index1); if (index2 < 0 || index2 > block.Count) { return(false); } if (index2 == conditions.size()) { block.Add(newCondition); indexAdded = block.IndexOf(newCondition); conditionAdded = newCondition; } else { indexAdded = index2; conditionAdded = newCondition; block.Insert(index2, newCondition); } } } else { // Add new block List <Condition> newBlock = new List <Condition>(); newBlock.Add(newCondition); conditions.add(newBlock); indexAdded = conditions.size() - 1; blockAdded = newBlock; } Controller.getInstance().updateVarFlagSummary(); Controller.getInstance().updatePanel(); return(true); } return(false); }
/* * (non-Javadoc) * @see org.xml.sax.ContentHandler#startElement(java.lang.string, java.lang.string, java.lang.string, org.xml.sax.Attributes) */ public override void startElement(string namespaceURI, string sName, string qName, Dictionary <string, string> attrs) { if (qName.Equals("assessment")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("show-report-at-end")) { profile.setShowReportAtEnd(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("send-to-email")) { if (entry.Value.ToString() == null || entry.Value.ToString().Length < 1) { profile.setEmail(""); profile.setSendByEmail(false); } else { profile.setEmail(entry.Value.ToString()); profile.setSendByEmail(true); } } if (entry.Key.Equals("scorm12")) { profile.setScorm12(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("scorm2004")) { profile.setScorm2004(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("name")) { profile.setName(entry.Value.ToString()); } } } else if (qName.Equals("smtp-config")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("smtp-ssl")) { profile.setSmtpSSL(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("smtp-server")) { profile.setSmtpServer(entry.Value.ToString()); } if (entry.Key.Equals("smtp-port")) { profile.setSmtpPort(entry.Value.ToString()); } if (entry.Key.Equals("smtp-user")) { profile.setSmtpUser(entry.Value.ToString()); } if (entry.Key.Equals("smtp-pwd")) { profile.setSmtpPwd(entry.Value.ToString()); } } } else if (qName.Equals("assessment-rule")) { string id = null; int importance = 0; bool repeatRule = false; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } if (entry.Key.Equals("importance")) { for (int j = 0; j < AssessmentRule.N_IMPORTANCE_VALUES; j++) { if (entry.Value.ToString().Equals(AssessmentRule.IMPORTANCE_VALUES[j])) { importance = j; } } } if (entry.Key.Equals("repeatRule")) { repeatRule = entry.Value.ToString().Equals("yes"); } } currentAssessmentRule = new AssessmentRule(id, importance, repeatRule); } else if (qName.Equals("timed-assessment-rule")) { string id = null; int importance = 0; bool usesEndConditions = false; bool has = false; bool repeatRule = false; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } if (entry.Key.Equals("importance")) { for (int j = 0; j < AssessmentRule.N_IMPORTANCE_VALUES; j++) { if (entry.Value.ToString().Equals(AssessmentRule.IMPORTANCE_VALUES[j])) { importance = j; } } } if (entry.Key.Equals("usesEndConditions")) { has = true; usesEndConditions = entry.Value.ToString().Equals("yes"); } if (entry.Key.Equals("repeatRule")) { repeatRule = entry.Value.ToString().Equals("yes"); } } currentAssessmentRule = new TimedAssessmentRule(id, importance, repeatRule); if (has) { ((TimedAssessmentRule)currentAssessmentRule).setUsesEndConditions(usesEndConditions); } } else if (qName.Equals("condition") || qName.Equals("init-condition") || qName.Equals("end-condition")) { currentConditions = new Conditions(); } // If it is an either tag, create a new either conditions and switch the state else if (qName.Equals("either")) { currentEitherCondition = new Conditions(); reading = READING_EITHER; } // If it is an active tag else if (qName.Equals("active")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("flag")) { // Store the active flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new FlagCondition(entry.Value.ToString(), FlagCondition.FLAG_ACTIVE)); } if (reading == READING_EITHER) { currentEitherCondition.add(new FlagCondition(entry.Value.ToString(), FlagCondition.FLAG_ACTIVE)); } profile.addFlag(entry.Value.ToString()); } } } // If it is an inactive tag else if (qName.Equals("inactive")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("flag")) { // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new FlagCondition(entry.Value.ToString(), FlagCondition.FLAG_INACTIVE)); } if (reading == READING_EITHER) { currentEitherCondition.add(new FlagCondition(entry.Value.ToString(), FlagCondition.FLAG_INACTIVE)); } profile.addFlag(entry.Value.ToString()); } } } // If it is a greater-than tag else if (qName.Equals("greater-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_GREATER_THAN, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_GREATER_THAN, value)); } profile.addVar(var); } // If it is a greater-Equals-than tag else if (qName.Equals("greater-equals-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.GetVAR_GREATER_EQUALS_THAN(), value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.GetVAR_GREATER_EQUALS_THAN(), value)); } profile.addVar(var); } // If it is a less-than tag else if (qName.Equals("less-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_LESS_THAN, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_LESS_THAN, value)); } profile.addVar(var); } // If it is a less-Equals-than tag else if (qName.Equals("less-equals-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.GetVAR_LESS_EQUALS_THAN(), value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.GetVAR_LESS_EQUALS_THAN(), value)); } profile.addVar(var); } // If it is a Equals-than tag else if (qName.Equals("equals")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.GetVAR_EQUALS(), value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.GetVAR_EQUALS(), value)); } profile.addVar(var); } // If it is a not-Equals-than tag else if (qName.Equals("not-equals")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.GetVAR_NOT_EQUALS(), value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.GetVAR_NOT_EQUALS(), value)); } profile.addVar(var); } // If it is a global-state-reference tag else if (qName.Equals("global-state-ref")) { // Id string id = null; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new GlobalStateCondition(id)); } if (reading == READING_EITHER) { currentEitherCondition.add(new GlobalStateCondition(id)); } } else if (qName.Equals("set-property")) { string id = null; string value = null; string varName = null; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } if (entry.Key.Equals("value")) { value = entry.Value.ToString(); } if (entry.Key.Equals("varName")) { varName = entry.Value.ToString(); } } if (varName == null) { currentAssessmentRule.addProperty(new AssessmentProperty(id, value)); } else { currentAssessmentRule.addProperty(new AssessmentProperty(id, value, varName)); } } else if (qName.Equals("assessEffect")) { if (currentAssessmentRule is TimedAssessmentRule) { int timeMin = int.MinValue; int timeMax = int.MinValue; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("time-min")) { timeMin = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("time-max")) { timeMax = int.Parse(entry.Value.ToString()); } } TimedAssessmentRule tRule = (TimedAssessmentRule)currentAssessmentRule; if (timeMin != int.MinValue && timeMax != int.MaxValue) { tRule.addEffect(timeMin, timeMax); } else { tRule.addEffect(); } } } }