protected override void InitClassSelection() { SetTopText("Select a class"); DnDCharacter character = (DnDCharacter)AppStorage.Instance.CurrentCharacter; GameObject buttonPref = Resources.Load(cTwoPartPrefab) as GameObject; int buttonHeight = (int)buttonPref.GetComponent <LayoutElement>().minHeight; int spacing = (int)DragArea.transform.FindChild("ScrollArea").GetComponent <VerticalLayoutGroup>().spacing; buttonHeight += spacing; for (int i = 0; i < character.Classes.Count; ++i) { if (character.Classes[i].NeedsToPrepareSpells) { GameObject button = GameObject.Instantiate(buttonPref) as GameObject; button.transform.SetParent(DragArea.transform.FindChild("ScrollArea")); ViewUtility.ChangeTwoPartButtonText(character.Classes[i].CharacterClass.ToString(), "level " + character.Classes[i].ClassLevel, button); button.GetComponent <IntButtonHandler>().NotificationInt = i; button.GetComponent <IntButtonHandler>().NotificationCatcher = this; mTotalHeight += buttonHeight; mButtonList.Add(button); } } if (mViewHeight < mTotalHeight) { mTotalHeight -= spacing; } if (mButtonList.Count == 1) { int selected = mButtonList[0].GetComponent <IntButtonHandler>().NotificationInt; int sender = mButtonList[0].GetComponent <IntButtonHandler>().ButtonID; ButtonCLickHandler(selected, sender, gameObject); } UpdateNow = true; }
public void InitButtons() { if (mViewHeight.HasValue) { int height = 0; GameObject buttonPref = Resources.Load(cButtonPrefab) as GameObject; int buttonHeight = (int)buttonPref.GetComponent <LayoutElement>().minHeight; int spacing = (int)DragArea.transform.FindChild("ScrollArea").GetComponent <VerticalLayoutGroup>().spacing; buttonHeight += spacing; for (int i = 0; i < AppStorage.Instance.Characters.Count; ++i) { GameObject button = GameObject.Instantiate(buttonPref) as GameObject; button.transform.SetParent(DragArea.transform.FindChild("ScrollArea")); button.GetComponent <IntButtonHandler>().NotificationCatcher = this; button.GetComponent <IntButtonHandler>().NotificationInt = i; string gameText = ViewUtility.ToViewString(AppStorage.Instance.Characters[i].Game); ViewUtility.ChangeTwoPartButtonText(AppStorage.Instance.Characters[i].Name, gameText, button); mButtons.Add(button); height += buttonHeight; } if (height > mViewHeight.Value) { // removing the spacing from the last button for nicer view height -= spacing; } mTotalHeight = height; } }
/// <summary> /// for clerics, wizards and other hard learners /// </summary> private void InitPreparedSpells() { int mainSpells = 0; bool extraSpell = false; if (mSoul.MainSpells.Count > mSelectedRank) { mainSpells = mSoul.MainSpells[mSelectedRank].Count; } if (mSoul.CanCastExtraSpell && mSoul.ExtraSpells.Count > mSelectedRank) { if (mSoul.ExtraSpells[mSelectedRank].Key != null) { extraSpell = true; } } GameObject buttonPref = null; int buttonHeight = 0; if (mainSpells == 0 && !extraSpell) { buttonPref = Resources.Load(cLabelPrefab) as GameObject; buttonHeight = (int)buttonPref.GetComponent <LayoutElement>().minHeight; mTotalHeight += buttonHeight; // display label GameObject obj = GameObject.Instantiate(buttonPref) as GameObject; obj.transform.SetParent(DragArea.transform.FindChild("ScrollArea")); ViewUtility.ChangeSimpleButtonText("no spells prepared for this rank", obj); mButtonList.Add(obj); } if (mainSpells > 0) { buttonPref = Resources.Load(cSimplePrefab) as GameObject; buttonHeight = (int)buttonPref.GetComponent <LayoutElement>().minHeight; // for loop to add main spells for (int i = 0; i < mainSpells; ++i) { GameObject button = GameObject.Instantiate(buttonPref) as GameObject; button.transform.SetParent(DragArea.transform.FindChild("ScrollArea")); ViewUtility.ChangeSimpleButtonText(mSoul.MainSpells[mSelectedRank][i].Key.ToShortString(), button); button.GetComponent <IntButtonHandler>().NotificationInt = i; button.GetComponent <IntButtonHandler>().NotificationCatcher = this; mTotalHeight += buttonHeight; ViewUtility.EnableSimpleButton(button, !mSoul.MainSpells[mSelectedRank][i].Value); mButtonList.Add(button); } } if (extraSpell) { buttonPref = Resources.Load(cTwoPartPrefab) as GameObject; buttonHeight = (int)buttonPref.GetComponent <LayoutElement>().minHeight; // add extra spell button GameObject eButton = GameObject.Instantiate(buttonPref) as GameObject; eButton.transform.SetParent(DragArea.transform.FindChild("ScrollArea")); ViewUtility.ChangeTwoPartButtonText(mSoul.ExtraSpells[mSelectedRank].Key.ToShortString(), "(extra)", eButton); eButton.GetComponent <IntButtonHandler>().NotificationInt = mSelectedRank; eButton.GetComponent <IntButtonHandler>().ButtonID = cExtraSpell; eButton.GetComponent <IntButtonHandler>().NotificationCatcher = this; mTotalHeight += buttonHeight; ViewUtility.EnableSimpleButton(eButton, !mSoul.ExtraSpells[mSelectedRank].Value); mButtonList.Add(eButton); } }