/// <summary> /// what happens when its drawing the Window /// </summary> void OnGUI() { //a delayed copy of the create element method //this executes when it won't cause a repaint error if (Event.current.type != EventType.Repaint && Event.current.type != EventType.Used && createElementDelegate != null) { //causes it to execute the lines until there is a yield return createElementDelegate.MoveNext(); //empties it because there's only one yield createElementDelegate = null; } //the Bolded title GUILayout.Label("Element Window", EditorStyles.boldLabel); //moves everything down 50 pixles GUILayout.Space(50); #region Allow Elements to be added //a title / label for this section GUILayout.Label("Element Modification"); //add some space for viibility GUILayout.Space(5); //get the items to be a row GUILayout.BeginHorizontal(); //Take in the user's input for the name (also displays the text input field) newElementName = GUILayout.TextField(newElementName, 200, GUILayout.Width(100)); //Take in the user's input for the texture (also displays the texture input field) newElementTexture = (Texture)EditorGUI.ObjectField(new Rect(new Vector2(70, 115), new Vector2(100, 50)), "", newElementTexture, typeof(Texture), false); //Take in the user's input for the color (also displays the color input field) newElementColor = EditorGUI.ColorField(new Rect(new Vector2(5, 145), new Vector2(110, 20)), newElementColor); //determine if the user has entered enough information to be able to properly create an element. (Color is not nullable so it doesn't need to be checked) bool contentReady = !string.IsNullOrEmpty(newElementName) && newElementTexture != null; ShowCreateButton = contentReady && EditingElementIndex == -1; //some space GUILayout.Space(80); //change the color so that the create button is grayed out when it shouldn't be used (and won't function) GUI.backgroundColor = ShowCreateButton ? Color.white : Color.gray; //display the button, and if its pressed create the element (by executing the if statement) if (GUILayout.Button("Create", GUILayout.Width(100)) && ShowCreateButton) { //makes the create element delayed createElementDelegate = EManager.CreateElement(newElementName, newElementTexture, newElementColor); } //change color to indicate if update button can be used GUI.backgroundColor = EditingElementIndex == -1 ? Color.gray : contentReady ? Color.white : Color.red; //the update button and conditions to use it if (GUILayout.Button("Update", GUILayout.Width(100)) && EditingElementIndex > -1 && contentReady) { //update element EManager.UpdateElement(EditingElementIndex, newElementName, newElementTexture, newElementColor); //reset info newElementColor = Color.white; newElementName = ""; newElementTexture = null; EditingElementIndex = -1; } //set color of cancel update button (and delete button) GUI.backgroundColor = EditingElementIndex == -1 ? Color.gray : Color.white; //the button and when it will activate if (GUILayout.Button("Cancel Update", GUILayout.Width(100)) && EditingElementIndex > -1) { //clear out info newElementColor = Color.white; newElementName = ""; newElementTexture = null; EditingElementIndex = -1; } //delete button and condition of use if (GUILayout.Button("Delete Element", GUILayout.Width(100)) && EditingElementIndex > -1) { //deletes the element but doesn't clear out the info in case it was a mistake EManager.DeleteElement(EditingElementIndex); EditingElementIndex = -1; } //change the color back GUI.backgroundColor = Color.white; //end of the row GUILayout.EndHorizontal(); #endregion #region display the current elements //some space GUILayout.Space(50); GUILayout.BeginHorizontal(); //this groups label / title GUILayout.Label("Element Effectiveness"); //ability to reload the elements of there was an error or a change if (GUILayout.Button("Reload Elements")) { EManager = new ElementManager(); EManager.Load(); } //ability to save (although it should save any important changes when they happen) if (GUILayout.Button("Save Changes") && EManager != null) { EManager.Save(); } GUILayout.EndHorizontal(); //more space GUILayout.Space(5); if (EManager != null && EManager.HaveLoadedElements) { //if there are elemnts to display, display them if (EManager.ElementCount > 0) { #region draw the elements for the column //this allows the elements created to be scrolled through; that way a smaller window can still show all of the elements elementsViewPosition = GUILayout.BeginScrollView(elementsViewPosition); //gets the elements to go in a row GUILayout.BeginHorizontal(); //the top left spot; it needed to be something manual so that the rest of the elements would line up with each other GUILayout.Button("elements", GUILayout.Height(80), GUILayout.Width(250)); //the top row of elements foreach (Element e in EManager.Elements) { //change the color to match the element's color GUI.backgroundColor = e.elementColor; //if they press the elements I want to give them the option of modifying the element if (GUILayout.Button(new GUIContent(e.elementName, e.symbol), GUILayout.Height(80), GUILayout.Width(250))) { StartEdit(e); } } //end the row GUILayout.EndHorizontal(); #endregion //display one element and its relationship with the other elements for (int row = 0; row < EManager.ElementCount; row++) { //set it up nicely by having one row per element GUILayout.BeginHorizontal(); //change its color to match the elements GUI.backgroundColor = EManager.Elements[row].elementColor; //name the element used & let the user change the element's information if they click it if (GUILayout.Button(new GUIContent(EManager.Elements[row].elementName, EManager.Elements[row].symbol), GUILayout.Height(80), GUILayout.Width(250))) { StartEdit(EManager.Elements[row]); } //its relation with the other elements for (int col = 0; col < EManager.ElementCount; col++) { //the multiplyer to use when attacking this element float multiplyer = 1; //get the relation's information (creates if it doesn't exist) EManager.FindElementEffectiveness(row, col, out multiplyer); //set the color to that of the attacking element GUI.backgroundColor = EManager.Elements[row].elementColor; //display's the information and allows the relationship to be modified if (GUILayout.Button(new GUIContent("Takes " + multiplyer.ToString() + "x dmg", EManager.Elements[col].symbol), GUILayout.Height(80), GUILayout.Width(250))) { EditingEffectivenessWindow.ShowWindow(EManager, row, EManager.Elements[col].elementName); } } //end the row GUILayout.EndHorizontal(); } //end the area that will scroll GUILayout.EndScrollView(); } #endregion } }