public override void Initialize() { DecisionPanel = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/UI/DecisionsPanel"), GameObject.Find("UI/DecisionPanelHolder").transform); DecisionPanel.name = "DecisionsPanel"; ButtonsHolder = DecisionPanel.transform.Find("Center/DecisionsPanel").gameObject; if (DescriptionShort != null) { ShowDecisionDescription(DescriptionShort, DescriptionLong, ImageSource); } float defaultWindowHeight = (DescriptionLong != null) ? 190f : 70f; float buttonHeight = 70f; if (decisions.Count != 0) { if (DescriptionLong == null) { DecisionPanel.transform.Find("DescriptionHolder/Description").GetComponentInChildren <Text>().text = DescriptionShort; } int i = 0; int rowsUsed = 0; int currentColumn = 1; foreach (var decision in decisions) { GameObject prefab = null; switch (DecisionViewType) { case DecisionViewTypes.TextButtons: prefab = (GameObject)Resources.Load("Prefabs/DecisionButton", typeof(GameObject)); break; case DecisionViewTypes.ImagesUpgrade: case DecisionViewTypes.ImagesDamageCard: prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/SmallCardPanel", typeof(GameObject)); break; default: break; } GameObject button = MonoBehaviour.Instantiate(prefab, ButtonsHolder.transform); SmallCardPanel script = null; switch (DecisionViewType) { case DecisionViewTypes.TextButtons: if (!decision.IsCentered) { float offsetX = (currentColumn == 1) ? 7.5f : 350; button.transform.localPosition = new Vector3(offsetX, -(buttonHeight + 5) * rowsUsed, 0); button.GetComponent <RectTransform>().sizeDelta = new Vector2(335, 67.5f); if (currentColumn == 1) { currentColumn++; } else { currentColumn = 1; rowsUsed++; } } else { button.transform.localPosition = new Vector3(182.5f, -(buttonHeight + 5) * rowsUsed, 0); button.GetComponent <RectTransform>().sizeDelta = new Vector2(335, 67.5f); rowsUsed++; currentColumn = 1; } button.GetComponentInChildren <Text>().text = decision.Name; switch (decision.Color) { case ActionColor.White: button.GetComponentInChildren <Text>().color = Color.white; break; case ActionColor.Red: button.GetComponentInChildren <Text>().color = Color.red; break; case ActionColor.Purple: button.GetComponentInChildren <Text>().color = new Color(128, 0, 128); break; default: break; } if (decision.HasTooltip) { Tooltips.AddTooltip(button, decision.Tooltip); } EventTrigger trigger = button.AddComponent <EventTrigger>(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener( (data) => { DecisionButtonWasPressed(decision, button); } ); trigger.triggers.Add(entry); break; case DecisionViewTypes.ImagesUpgrade: button.transform.localPosition = new Vector3(15 * (i + 1) + i * Editions.Edition.Current.UpgradeCardSize.x, 0, 0); script = button.GetComponent <SmallCardPanel>(); script.Initialize( decision.Name, decision.Tooltip, delegate { GameCommand command = GenerateDecisionCommand(decision.Name); GameMode.CurrentGameMode.ExecuteCommand(command); }, DecisionViewTypes.ImagesUpgrade, decision.Count ); break; case DecisionViewTypes.ImagesDamageCard: if (currentColumn == 6) { currentColumn = 1; rowsUsed++; } button.transform.localPosition = new Vector3(15 * (currentColumn) + (currentColumn - 1) * ImagesDamageCardSize.x, rowsUsed * -ImagesDamageCardSize.y - 15 * rowsUsed, 0); script = button.GetComponent <SmallCardPanel>(); script.Initialize( decision.Name, decision.Tooltip, delegate { GameCommand command = GenerateDecisionCommand(decision.Name); GameMode.CurrentGameMode.ExecuteCommand(command); }, DecisionViewTypes.ImagesDamageCard, decision.Count ); currentColumn++; break; default: break; } button.name = "Button" + i; i++; } switch (DecisionViewType) { case DecisionViewTypes.TextButtons: if (currentColumn == 2) { rowsUsed++; } DecisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( 700f, defaultWindowHeight + rowsUsed * (buttonHeight + 5) ); ButtonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( 700f, defaultWindowHeight + rowsUsed * (buttonHeight + 5) ); break; case DecisionViewTypes.ImagesUpgrade: DecisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( Mathf.Max(700f, decisions.Count * Editions.Edition.Current.UpgradeCardSize.x + (decisions.Count + 1) * 15), defaultWindowHeight + Editions.Edition.Current.UpgradeCardSize.y + 15 ); ButtonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( decisions.Count * Editions.Edition.Current.UpgradeCardSize.x + (decisions.Count + 1) * 15, defaultWindowHeight + Editions.Edition.Current.UpgradeCardSize.y + 15 ); break; case DecisionViewTypes.ImagesDamageCard: DecisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( Mathf.Max(700f, Mathf.Min(decisions.Count, 5) * ImagesDamageCardSize.x + (Mathf.Min(decisions.Count, 5) + 1) * 15), defaultWindowHeight + ImagesDamageCardSize.y * (rowsUsed + 1) + 10 * (rowsUsed + 1) ); ButtonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( Mathf.Min(decisions.Count, 5) * ImagesDamageCardSize.x + (Mathf.Min(decisions.Count, 5) + 1) * 15, defaultWindowHeight + ImagesDamageCardSize.y * (rowsUsed + 1) + 15 * (rowsUsed + 1) ); break; default: break; } ButtonsHolder.transform.localPosition = new Vector2(-ButtonsHolder.GetComponent <RectTransform>().sizeDelta.x / 2, -185); if (DecisionOwner == null) { DecisionOwner = Roster.GetPlayer(Phases.CurrentPhasePlayer); } RequiredPlayer = DecisionOwner.PlayerNo; Roster.HighlightPlayer(RequiredPlayer); if (ShowSkipButton) { UI.ShowSkipButton(); } else { UI.HideSkipButton(); } } }
public override void Initialize() { if (decisions.Count != 0) { decisionPanel.transform.Find("InformationPanel").GetComponentInChildren <Text>().text = InfoText; int i = 0; int rowsUsed = 0; int currentColumn = 1; foreach (var decision in decisions) { GameObject prefab = null; switch (DecisionViewType) { case DecisionViewTypes.TextButtons: prefab = (GameObject)Resources.Load("Prefabs/DecisionButton", typeof(GameObject)); break; case DecisionViewTypes.ImagesUpgrade: case DecisionViewTypes.ImagesDamageCard: prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/SmallCardPanel", typeof(GameObject)); break; default: break; } GameObject button = MonoBehaviour.Instantiate(prefab, buttonsHolder.transform); SmallCardPanel script = null; switch (DecisionViewType) { case DecisionViewTypes.TextButtons: if (!decision.IsCentered) { float offsetX = (currentColumn == 1) ? 7.5f : 300; button.transform.localPosition = new Vector3(offsetX, -buttonHeight * rowsUsed, 0); if (currentColumn == 1) { currentColumn++; } else { currentColumn = 1; rowsUsed++; } } else { button.transform.localPosition = new Vector3(105 * 1.5f, -buttonHeight * rowsUsed, 0); rowsUsed++; currentColumn = 1; } button.GetComponentInChildren <Text>().text = decision.Name; button.GetComponentInChildren <Text>().color = (decision.IsRed) ? Color.red : Color.white; if (decision.HasTooltip) { Tooltips.AddTooltip(button, decision.Tooltip); } EventTrigger trigger = button.AddComponent <EventTrigger>(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener( (data) => { DecisionButtonWasPressed(decision, button); } ); trigger.triggers.Add(entry); break; case DecisionViewTypes.ImagesUpgrade: button.transform.localPosition = new Vector3(15 * (i + 1) + i * Editions.Edition.Current.UpgradeCardSize.x, 0, 0); script = button.GetComponent <SmallCardPanel>(); script.Initialize( decision.Name, decision.Tooltip, delegate { GameCommand command = GenerateDecisionCommand(decision.Name); GameMode.CurrentGameMode.ExecuteCommand(command); }, DecisionViewTypes.ImagesUpgrade, decision.Count ); break; case DecisionViewTypes.ImagesDamageCard: button.transform.localPosition = new Vector3(15 * (i + 1) + i * ImagesDamageCardSize.x, 0, 0); script = button.GetComponent <SmallCardPanel>(); script.Initialize( decision.Name, decision.Tooltip, delegate { GameCommand command = GenerateDecisionCommand(decision.Name); GameMode.CurrentGameMode.ExecuteCommand(command); }, DecisionViewTypes.ImagesDamageCard, decision.Count ); break; default: break; } button.name = "Button" + i; i++; } switch (DecisionViewType) { case DecisionViewTypes.TextButtons: if (currentColumn == 2) { rowsUsed++; } decisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( 395 * 1.5f, defaultWindowHeight + rowsUsed * buttonHeight ); buttonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( 395 * 1.5f, defaultWindowHeight + rowsUsed * buttonHeight ); break; case DecisionViewTypes.ImagesUpgrade: decisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( Mathf.Max(395 * 1.5f, decisions.Count * Editions.Edition.Current.UpgradeCardSize.x + (decisions.Count + 1) * 15), defaultWindowHeight + Editions.Edition.Current.UpgradeCardSize.y + 15 ); buttonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( decisions.Count * Editions.Edition.Current.UpgradeCardSize.x + (decisions.Count + 1) * 15, defaultWindowHeight + Editions.Edition.Current.UpgradeCardSize.y + 15 ); break; case DecisionViewTypes.ImagesDamageCard: decisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( Mathf.Max(395 * 1.5f, decisions.Count * ImagesDamageCardSize.x + (decisions.Count + 1) * 15), defaultWindowHeight + ImagesDamageCardSize.y + 10 ); buttonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( decisions.Count * ImagesDamageCardSize.x + (decisions.Count + 1) * 15, defaultWindowHeight + ImagesDamageCardSize.y + 15 ); break; default: break; } buttonsHolder.transform.localPosition = new Vector2(-buttonsHolder.GetComponent <RectTransform>().sizeDelta.x / 2, -105); if (DecisionOwner == null) { DecisionOwner = Roster.GetPlayer(Phases.CurrentPhasePlayer); } if (ShowSkipButton) { UI.ShowSkipButton(); } else { UI.HideSkipButton(); } } }
public override void Initialize() { if (decisions.Count != 0) { decisionPanel.transform.Find("InformationPanel").GetComponentInChildren <Text>().text = InfoText; switch (DecisionViewType) { case DecisionViewTypes.TextButtons: decisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( 395, defaultWindowHeight + ((decisions.Count + 1) / 2) * buttonHeight ); buttonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( 395, defaultWindowHeight + ((decisions.Count + 1) / 2) * buttonHeight ); break; case DecisionViewTypes.ImagesUpgrade: decisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( Mathf.Max(395, decisions.Count * RuleSets.RuleSet.Instance.UpgradeCardSize.x + (decisions.Count + 1) * 10), defaultWindowHeight + RuleSets.RuleSet.Instance.UpgradeCardSize.y + 10 ); buttonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( decisions.Count * RuleSets.RuleSet.Instance.UpgradeCardSize.x + (decisions.Count + 1) * 10, defaultWindowHeight + RuleSets.RuleSet.Instance.UpgradeCardSize.y + 10 ); break; case DecisionViewTypes.ImagesDamageCard: decisionPanel.GetComponent <RectTransform>().sizeDelta = new Vector3( Mathf.Max(395, decisions.Count * ImagesDamageCardSize.x + (decisions.Count + 1) * 10), defaultWindowHeight + ImagesDamageCardSize.y + 10 ); buttonsHolder.GetComponent <RectTransform>().sizeDelta = new Vector3( decisions.Count * ImagesDamageCardSize.x + (decisions.Count + 1) * 10, defaultWindowHeight + ImagesDamageCardSize.y + 10 ); break; default: break; } buttonsHolder.transform.localPosition = new Vector2(-buttonsHolder.GetComponent <RectTransform>().sizeDelta.x / 2, -70); int i = 0; foreach (var decision in decisions) { GameObject prefab = null; switch (DecisionViewType) { case DecisionViewTypes.TextButtons: prefab = (GameObject)Resources.Load("Prefabs/DecisionButton", typeof(GameObject)); break; case DecisionViewTypes.ImagesUpgrade: case DecisionViewTypes.ImagesDamageCard: prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/SmallCardPanel", typeof(GameObject)); break; default: break; } GameObject button = MonoBehaviour.Instantiate(prefab, buttonsHolder.transform); SmallCardPanel script = null; switch (DecisionViewType) { case DecisionViewTypes.TextButtons: button.transform.localPosition = new Vector3((i % 2 == 0) ? 5 : 200, -buttonHeight * (i / 2), 0); button.GetComponentInChildren <Text>().text = decision.Name; button.GetComponentInChildren <Text>().color = (decision.IsRed) ? Color.red : Color.white; if (decision.HasTooltip) { Tooltips.AddTooltip(button, decision.Tooltip); } EventTrigger trigger = button.AddComponent <EventTrigger>(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener( (data) => { DecisionButtonWasPressed(decision, button); } ); trigger.triggers.Add(entry); break; case DecisionViewTypes.ImagesUpgrade: button.transform.localPosition = new Vector3(10 * (i + 1) + i * RuleSets.RuleSet.Instance.UpgradeCardSize.x, 0, 0); script = button.GetComponent <SmallCardPanel>(); script.Initialize( decision.Name, decision.Tooltip, delegate { GameMode.CurrentGameMode.TakeDecision(decision, button); }, DecisionViewTypes.ImagesUpgrade, decision.Count ); break; case DecisionViewTypes.ImagesDamageCard: button.transform.localPosition = new Vector3(10 * (i + 1) + i * ImagesDamageCardSize.x, 0, 0); script = button.GetComponent <SmallCardPanel>(); script.Initialize( decision.Name, decision.Tooltip, delegate { GameMode.CurrentGameMode.TakeDecision(decision, button); }, DecisionViewTypes.ImagesDamageCard, decision.Count ); break; default: break; } button.name = "Button" + i; i++; } if (DecisionOwner == null) { DecisionOwner = Roster.GetPlayer(Phases.CurrentPhasePlayer); } if (ShowSkipButton) { UI.ShowSkipButton(); } else { UI.HideSkipButton(); } } }