// This function returns true if item given as parameter is cloned into a previous step. public bool GroupClonedIntoPreviousStep(FoodStateGroup fsg, int stepNo) { // Check if clone is before last step in bounded steps in food group. foreach (GroupFromSteps g in groups) { FoodStateGroup foodGroup = g.GetFoodStateGroup(); if (foodGroup.clone == fsg && stepNo < g.GetLastStepNumber()) { return(true); } } // Check if clone is before owner step of output object. foreach (Step s in steps) { if (s.GetOutput() is FoodStateGroup) { FoodStateGroup outputGroup = (FoodStateGroup)(s.GetOutput()); if (outputGroup.clone == fsg && stepNo < s.GetStepNumber()) { return(true); } } } return(false); }
public void StepChanged(Step s) { s.SetDirty(true); // Check for input item conditions if (s.GetInput() is FoodState) { FoodState input = (FoodState)(s.GetInput()); if (ItemClonedIntoPreviousStep(input, s.GetStepNumber())) { DestroyItem(input.gameObject); } } else if (s.GetInput() is FoodStateGroup) { FoodStateGroup input = (FoodStateGroup)(s.GetInput()); if (GroupClonedIntoPreviousStep(input, s.GetStepNumber())) { DestroyItem(input.gameObject); } } // Wrong type of item is dropped into input zone else { if (s.inputZoneRef.transform.childCount == 1) { DestroyItem(s.inputZoneRef.transform.GetChild(0).gameObject); } } // Check for output item conditions if (s.GetOutput() is FoodState) { FoodState outputToBeRemoved = (FoodState)(s.GetOutput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); } else if (s.GetOutput() is FoodStateGroup) { FoodStateGroup outputToBeRemoved = (FoodStateGroup)(s.GetOutput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); } // Wrong type of item is dropped into action zone if (s.GetPseudoAction() == null) { if (s.actionZoneRef.transform.childCount == 1) { DestroyItem(s.actionZoneRef.transform.GetChild(0).gameObject); } } // Finally recalculate outputs of each step RegenerateSteps(); }
public void RemoveGroup(FoodStateGroup fsg) { // Mark references of this group as dirty if (fsg.clone) { MarkRefsAsDirty(fsg.clone); DestroyItem(fsg.clone.gameObject); } GroupFromSteps gfs = fsg.transform.parent.parent.GetComponent <GroupFromSteps>(); // Destroy main group object groups.Remove(gfs); DestroyItem(gfs.gameObject); // Destroy grouping lines foreach (Step s in gfs.boundedSteps) { s.hasGroup = false; s.toggleRef.GetComponent <Toggle>().interactable = true; s.groupConnectorRef.SetActive(false); } // Regenerate Steps RegenerateSteps(); }
public Step GetNextRelatedStep(Step prevStep) { // Check if this food/foodGroup is used for creating a new group foreach (GroupFromSteps gfs in groups) { if (gfs.boundedSteps.Contains(prevStep)) { // Check if this group is used as input in a step foreach (Step s in steps) { if (s.GetInput() is FoodStateGroup) { if ((FoodStateGroup)(s.GetInput()) == gfs.GetFoodStateGroup().clone) { return(s); } } } } } if (prevStep.GetOutput() is FoodState) { FoodState prevFs = (FoodState)prevStep.GetOutput(); // Check if this food is used as input in a step foreach (Step s in steps) { if (s.GetInput() is FoodState) { if ((FoodState)(s.GetInput()) == prevFs.clone) { return(s); } } } } else if (prevStep.GetOutput() is FoodStateGroup) { FoodStateGroup prevFsg = (FoodStateGroup)prevStep.GetOutput(); // Check if this food group is used as input in a step foreach (Step s in steps) { if (s.GetInput() is FoodStateGroup) { if ((FoodStateGroup)(s.GetInput()) == prevFsg.clone) { return(s); } } } } return(null); }
public bool CheckGroupEligibility(Step s) { // If this step is already grouped, we cannot regroup it. if (s.GetHasGroup()) { return(false); } // If output is used in another step, we can't group this step anymore. if (s.GetOutput() is FoodState) { FoodState fs = (FoodState)s.GetOutput(); if (fs.clone != null) { return(false); } } else if (s.GetOutput() is FoodStateGroup) { FoodStateGroup fsg = (FoodStateGroup)s.GetOutput(); if (fsg.clone != null) { return(false); } } // There is no output else { return(false); } // It can be grouped return(true); }
public void MarkRefsAsDirty(FoodStateGroup foodStateGroup) { if (foodStateGroup == null) { return; } foreach (Step s in steps) { if (s.GetInput() is FoodStateGroup && (FoodStateGroup)(s.GetInput()) == foodStateGroup) { s.SetDirty(true); if (s.GetOutput() is FoodState) { FoodState outputToBeRemoved = (FoodState)(s.GetOutput()); FoodState inputToBeRemoved = (FoodState)(s.GetInput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); DestroyItem(inputToBeRemoved.gameObject); break; } else if (s.GetOutput() is FoodStateGroup) { FoodStateGroup outputToBeRemoved = (FoodStateGroup)(s.GetOutput()); FoodStateGroup inputToBeRemoved = (FoodStateGroup)(s.GetInput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); DestroyItem(inputToBeRemoved.gameObject); break; } } } }
public void Clone(FoodStateGroup fg) { this.foodStates = fg.foodStates; fg.clone = this; }
// Create a new foodgroup from selected steps public void CreateGroupFromSelectedSteps() { float avgYPos = 0; float minY = 10000; float maxY = -10000; List <FoodState> outputsToBeGrouped = new List <FoodState>(); GameObject newGroup = GameObject.Instantiate(emptyGroupRef); newGroup.GetComponent <GroupFromSteps>().boundedSteps = new List <Step>(); foreach (Step s in steps) { if (s.GetToggle()) { s.SetHasGroup(true); s.SetToggle(false); s.toggleRef.GetComponent <Toggle>().interactable = false; //Import single output into list if (s.GetOutput() is FoodState) { outputsToBeGrouped.Add(((FoodState)(s.GetOutput()))); } // Import a whole output group into list else if (s.GetOutput() is FoodStateGroup) { FoodStateGroup groupToBeImported = (FoodStateGroup)(s.GetOutput()); foreach (FoodState fs in groupToBeImported.foodStates) { outputsToBeGrouped.Add(fs); } } // Add this step as bounded step to group newGroup.GetComponent <GroupFromSteps>().boundedSteps.Add(s); Vector3 pos = s.GetComponent <RectTransform>().anchoredPosition3D; if (pos.y > maxY) { maxY = pos.y + 25; } if (pos.y < minY) { minY = pos.y + 25; } s.groupConnectorRef.SetActive(true); // Set offsets of group connector line for this new group Vector3 connectorPos = s.groupConnectorRef.GetComponent <RectTransform>().anchoredPosition3D; connectorPos.x += newGroupCount * newGroupOffsetX / 2.0f; s.groupConnectorRef.GetComponent <RectTransform>().anchoredPosition3D = connectorPos; Vector3 connectorScale = s.groupConnectorRef.transform.localScale; connectorScale.x += newGroupCount * 22; s.groupConnectorRef.transform.localScale = connectorScale; } } avgYPos = (minY + maxY) / 2.0f; newGroup.transform.SetParent(this.transform, false); Vector3 groupPos = newGroup.GetComponent <RectTransform>().anchoredPosition3D; groupPos.y = avgYPos; // Set an x offset to make it not override with previous groups groupPos.x += newGroupOffsetX * newGroupCount++; newGroup.GetComponent <RectTransform>().anchoredPosition3D = groupPos; Vector2 newDelta = new Vector2((maxY - minY) / 10.0f, 10); newGroup.GetComponent <GroupFromSteps>().verticalLineRef.sizeDelta = newDelta; // Set generated list as group members newGroup.GetComponent <GroupFromSteps>().GetFoodStateGroup().SetFoodStateGroup(outputsToBeGrouped); // Set names string groupStateName = GetNewGroupName(); newGroup.GetComponent <GroupFromSteps>().GetFoodStateGroup().GetComponent <Text>().text = "Group_" + groupStateName; newGroup.name = "Group_" + groupStateName; // Add this group to groups list groups.Add(newGroup.GetComponent <GroupFromSteps>()); newGroup.SetActive(true); }
// Generate output of this step, register it to recipe data structure. public bool GenerateOutput() { // Input or action is null, halt. if (GetInput() == null || GetPseudoAction() == null) { // Remove existing output object if it exists if (outputZoneRef.transform.childCount == 1) { GameObject oldOutputObject = outputZoneRef.transform.GetChild(0).gameObject; Destroy(oldOutputObject.GetComponent <Text>()); Destroy(oldOutputObject); } return(false); } // If input is single object if (GetInput() is FoodState) { // Create new output food object GameObject outputObject = GameObject.Instantiate(dummyOutputSingleFood); // Set new output name string stateName = ""; if (GetPseudoAction().GetActionType() == RecipeModule.Action.ActionType.Empty) { stateName = ((FoodState)GetInput()).gameObject.GetComponent <Text>().text; } else { stateName = "Output_" + recipeManager.GetNewOutputName(); } outputObject.name = stateName; outputObject.GetComponent <Text>().text = stateName; outputObject.GetComponent <Text>().color = Color.red; // Remove existing ouput object if (outputZoneRef.transform.childCount == 1) { GameObject oldOutputObject = outputZoneRef.transform.GetChild(0).gameObject; Destroy(oldOutputObject.GetComponent <Text>()); Destroy(oldOutputObject); } // Enable selecting this step for grouping toggleRef.GetComponent <Toggle>().enabled = true; // Swap output with new one outputObject.transform.SetParent(outputZoneRef.transform, false); outputObject.transform.GetComponent <VRTK_UIDraggableItem>().enabled = true; } // If input is food group else if (GetInput() is FoodStateGroup) { FoodStateGroup inputGroup = (FoodStateGroup)GetInput(); List <FoodState> outputFoods = new List <FoodState>(); // Create new list from input objects in group foreach (FoodState fs in inputGroup.foodStates) { outputFoods.Add(fs); } // Create new foodgroup object GameObject outputObject = GameObject.Instantiate(dummyOutputFoodGroup); outputObject.GetComponent <FoodStateGroup>().SetFoodStateGroup(outputFoods); // Set new output group name string stateName; if (GetPseudoAction().GetActionType() == RecipeModule.Action.ActionType.Empty) { stateName = inputGroup.gameObject.GetComponent <Text>().text; } else { stateName = "Output_" + recipeManager.GetNewOutputName(); } outputObject.name = stateName; outputObject.GetComponent <Text>().text = stateName; outputObject.GetComponent <Text>().color = Color.red; // Remove existing ouput object if (outputZoneRef.transform.childCount == 1) { GameObject oldOutputObject = outputZoneRef.transform.GetChild(0).gameObject; Destroy(oldOutputObject.GetComponent <Text>()); Destroy(oldOutputObject); } // Enable selecting this step for grouping toggleRef.GetComponent <Toggle>().enabled = true; // Swap output with new one outputObject.transform.SetParent(outputZoneRef.transform, false); outputObject.transform.GetComponent <VRTK_UIDraggableItem>().enabled = true; } outputZoneRef.transform.parent.gameObject.SetActive(true); CheckGroupEligibility(); return(true); }