/* Displays on the GUI */ void OnGUI() { GUI.skin.button.wordWrap = true; //words wrap to next lines //Displays an "Army" button that the user presses to open up the army window if (GUI.Button (GUIInfo.guiInfo.armyManagerButton, GUIInfo.guiInfo.armyManagerButtonText)) { toggleArmyManager (); } //Displays the save button //TODO: Remove this later if (GUI.Button (new Rect(750, 0, 50, 50), "Save")) { data.SaveData(); } if (showArmyManager) { //displays the entire Army Manager GUI GUI.DrawTexture (GUIInfo.guiInfo.GUIWindow, armyManagerScreen); //shows the Army Manager screen if (Event.current.type == EventType.MouseDown) { //checks if the user presses down /* Checks if user pressed a valid soldier button */ if (!buttonPressed && //ensures that a button is only stored once per press IsNullButton(storedButton = CheckArmyPress()) == false && //stores the button and checks null storedButton.soldierIndex != -1) { //makes sure there's an actual soldier there buttonPressed = true; // a button has been pressed /* stores distance from mouse to the top left corner of the pressed button */ mouseDelta.x = Event.current.mousePosition.x - storedButton.buttonRect.x; mouseDelta.y = Event.current.mousePosition.y - storedButton.buttonRect.y; } else if (!buttonPressed && //if button wasnt pressed efore IsNullButton(storedButton = CheckPartyPress ()) == false && //button isnt null and is party pressed storedButton.soldierIndex != ArmyDataScript.nullSoldierIndex) { //soldier is there buttonPressed = true; //a button has been pressed /* Stores distance from mouse to top left corner of pressed button */ mouseDelta.x = Event.current.mousePosition.x - storedButton.buttonRect.x; mouseDelta.y = Event.current.mousePosition.y - storedButton.buttonRect.y; } } if (Event.current.type == EventType.MouseUp) { checkDragRelease(Event.current.mousePosition); buttonPressed = false; //a button is not being pressed partyPressed = -1; //a party button is not being pressed } if (Event.current.type == EventType.MouseDrag) { storedButton.buttonRect.x = Event.current.mousePosition.x - mouseDelta.x; storedButton.buttonRect.y = Event.current.mousePosition.y - mouseDelta.y; } if (GUI.Button (GUIInfo.guiInfo.addSlotButton, GUIInfo.guiInfo.addSlotButtonText)) { data.armyData.UnlockArmySlot(); } if (GUI.Button (GUIInfo.guiInfo.addSoldierButton, GUIInfo.guiInfo.addSoldierButtonText)) { data.armyData.AddSoldier(); } int emptySlots = data.armyData.GetEmptyArmySlots(); for (int i = 0; i < ArmyDataScript.armyCap; i++) { //if the button is a valid soldier if (armyButtonsArray[i].soldierIndex != ArmyDataScript.nullSoldierIndex) { if (GUI.Button(armyButtonsArray[i].buttonRect, armyData.GetSoldierName(armyButtonsArray[i].soldierIndex))) { LoadSoldierData (armyButtonsArray[i].soldierIndex); } } /* If a new soldier slot is available */ else if (emptySlots != 0) { if (GUI.Button(armyButtonsArray[i].buttonRect, "Empty Slot")) { } emptySlots--; } /* If the soldier slot is locked */ else { GUI.Button(armyButtonsArray[i].buttonRect, "Locked"); } } /* loops through each party button */ for (int i = 0; i < ArmyDataScript.partyCap; i++) { if (partyButtonsArray[i].soldierIndex != ArmyDataScript.nullSoldierIndex) { /* Creates the party soldier buttons */ if (GUI.Button (partyButtonsArray[i].buttonRect, armyData.GetSoldier (partyButtonsArray[i].soldierIndex).GetName ())) { LoadSoldierData(partyButtonsArray[i].soldierIndex); } } /* If no soldier has been slotted*/ else { GUI.Button (partyButtonsArray[i].buttonRect, "Drag Here"); } } if (buttonPressed) { GUI.Button (storedButton.buttonRect, armyData.GetSoldier (storedButton.soldierIndex).GetName ()); } } // end if army manager is open }
bool IsNullButton(soldierButton button) { if (button.buttonRect == new Rect(0,0,0,0) && button.soldierIndex == -1) { return true; } else { return false; } }