diff --git a/Assets/Scripts/Model/Choices/Steal.meta b/Assets/Resources/Fonts.meta similarity index 77% rename from Assets/Scripts/Model/Choices/Steal.meta rename to Assets/Resources/Fonts.meta index 4c5fc5a..1b2f197 100644 --- a/Assets/Scripts/Model/Choices/Steal.meta +++ b/Assets/Resources/Fonts.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ea92e0400d884f24da7a1fd20ab7d203 +guid: 0accb89c98af4554ab34b128e2c543ef folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Resources/Fonts/cyberdyne.ttf b/Assets/Resources/Fonts/cyberdyne.ttf new file mode 100644 index 0000000..d6a4d31 Binary files /dev/null and b/Assets/Resources/Fonts/cyberdyne.ttf differ diff --git a/Assets/Resources/Fonts/cyberdyne.ttf.meta b/Assets/Resources/Fonts/cyberdyne.ttf.meta new file mode 100644 index 0000000..4e1951d --- /dev/null +++ b/Assets/Resources/Fonts/cyberdyne.ttf.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 03ace493c60fdb54e8f2c1e37acd83b3 +TrueTypeFontImporter: + externalObjects: {} + serializedVersion: 4 + fontSize: 16 + forceTextureCase: -2 + characterSpacing: 0 + characterPadding: 1 + includeFontData: 1 + fontName: Cyberdyne + fontNames: + - Cyberdyne + fallbackFontReferences: [] + customCharacters: + fontRenderingMode: 0 + ascentCalculationMode: 1 + useLegacyBoundsCalculation: 0 + shouldRoundAdvanceValue: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Runner Game.unity b/Assets/Scenes/Runner Game.unity index 240933e..2d754bf 100644 --- a/Assets/Scenes/Runner Game.unity +++ b/Assets/Scenes/Runner Game.unity @@ -206,7 +206,7 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 72 + m_fontSize: 50.35 m_fontSizeBase: 36 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -1236,8 +1236,9 @@ RectTransform: - {fileID: 392453616} - {fileID: 364526017} - {fileID: 1730285211} + - {fileID: 1600730671} m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -1385,8 +1386,83 @@ Transform: m_Children: - {fileID: 115784155} m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &798008800 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 798008803} + - component: {fileID: 798008802} + - component: {fileID: 798008801} + m_Layer: 5 + m_Name: Credit(Clone) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &798008801 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 798008800} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 3286163911610860551, guid: 14ded5a7c71921141b0312119ba4dce2, + type: 3} + m_Type: 0 + m_PreserveAspect: 1 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &798008802 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 798008800} + m_CullTransparentMesh: 1 +--- !u!224 &798008803 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 798008800} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -16, y: 42.666668} + m_SizeDelta: {x: 32, y: 64} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &836102266 GameObject: m_ObjectHideFlags: 0 @@ -1755,7 +1831,7 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 72 + m_fontSize: 50.35 m_fontSizeBase: 36 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -2505,6 +2581,41 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &1600730670 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1600730671} + m_Layer: 5 + m_Name: Game bracket + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1600730671 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1600730670} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 711624506} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0.25} + m_AnchorMax: {x: 1, y: 0.75} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1622406199 GameObject: m_ObjectHideFlags: 0 @@ -2634,7 +2745,7 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 72 + m_fontSize: 50.35 m_fontSizeBase: 36 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -2736,7 +2847,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1685858174 MonoBehaviour: diff --git a/Assets/Scripts/Config/GameConfig.cs b/Assets/Scripts/Config/GameConfig.cs index 18447db..4562773 100644 --- a/Assets/Scripts/Config/GameConfig.cs +++ b/Assets/Scripts/Config/GameConfig.cs @@ -5,7 +5,9 @@ using UnityEngine; using view; using view.gui; +using view.gui.brackets; using view.log; +using static view.gui.GameObjectExtensions; public class GameConfig : MonoBehaviour { @@ -14,7 +16,7 @@ public class GameConfig : MonoBehaviour void Start() { - var board = GameObject.Find("/Board"); + var board = FindOrFail("/Board"); gameMenu = board.GetComponentInChildren(); gameMenu.Resume(); var perception = new RunnerPerception(); @@ -44,6 +46,7 @@ void Start() flowLog.Display(game); var corpView = new CorpViewConfig().Display(game, parts); new RunnerViewConfig().Display(game.runner, flowView, corpView, parts); + new RunnerGameBracket(FindOrFail("Game bracket"), game); game.Start(corpDeck, runnerDeck); } diff --git a/Assets/Scripts/Model/Game.cs b/Assets/Scripts/Model/Game.cs index 56838d2..cb76130 100644 --- a/Assets/Scripts/Model/Game.cs +++ b/Assets/Scripts/Model/Game.cs @@ -13,8 +13,8 @@ public class Game public readonly Runner runner; private readonly Zone playArea; public readonly Checkpoint checkpoint; - public event EventHandler CurrentTurn = delegate { }; - public event EventHandler NextTurn = delegate { }; + public event Action CurrentTurn = delegate { }; + public event Action NextTurn = delegate { }; public event Action Finished = delegate { }; private bool ended = false; private Queue turns = new Queue(); @@ -82,8 +82,8 @@ async private Task StartTurns() private async Task StartNextTurn() { var currentTurn = turns.Dequeue(); - CurrentTurn(this, currentTurn); - NextTurn(this, turns.Peek()); + CurrentTurn(currentTurn); + NextTurn(turns.Peek()); await currentTurn.Start(); } diff --git a/Assets/Scripts/View/GUI/Brackets.meta b/Assets/Scripts/View/GUI/Brackets.meta new file mode 100644 index 0000000..58dd747 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b85d29d05b181614ea70167cf01f14bb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/View/GUI/Brackets/ActionBracket.cs b/Assets/Scripts/View/GUI/Brackets/ActionBracket.cs new file mode 100644 index 0000000..4c9dd61 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/ActionBracket.cs @@ -0,0 +1,51 @@ +using model.play; +using model.timing; +using System.Threading.Tasks; + +namespace view.gui.brackets +{ + public class ActionBracket + { + private readonly ITurn turn; + private readonly int actionOrder; + private readonly Bracket bracket; + + public ActionBracket(ITurn turn, int actionOrder, Bracket bracket) + { + this.turn = turn; + this.actionOrder = actionOrder; + this.bracket = bracket; + turn.TakingAction += UpdateActivation; + turn.ActionTaken += UpdateEffect; + } + + async private Task UpdateActivation(ITurn turn) + { + if (IsPresent()) + { + bracket.Open(); + } + await Task.CompletedTask; + } + + private bool IsPresent() + { + return turn.Clicks.Spent == actionOrder - 1; + } + + private bool IsPast() + { + return turn.Clicks.Spent >= actionOrder; + } + + async private Task UpdateEffect(ITurn turn, Ability action) + { + if (IsPast()) + { + bracket.Collapse(); + } + // action.effect.Graphics; + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/View/GUI/Brackets/ActionBracket.cs.meta b/Assets/Scripts/View/GUI/Brackets/ActionBracket.cs.meta new file mode 100644 index 0000000..b24deca --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/ActionBracket.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 74c1b4483aebac9438462adc385cc481 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/View/GUI/Brackets/Bracket.cs b/Assets/Scripts/View/GUI/Brackets/Bracket.cs new file mode 100644 index 0000000..3262449 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/Bracket.cs @@ -0,0 +1,100 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace view.gui.brackets +{ + public class Bracket + { + private static Font FONT = Resources.Load("Fonts/cyberdyne"); + private static float EDGE_WIDTH_RATIO = 0.05f; + + private readonly GameObject container; + private GameObject opening; + private GameObject content; + private GameObject closing; + private float margin; + + public Bracket(string name, GameObject container) : this(name, container, siblingIndex: 0, margin: 0.00f) { } + + private Bracket(string name, GameObject container, int siblingIndex, float margin) + { + this.container = container; + this.margin = margin; + opening = RenderOpening(siblingIndex, name); + content = RenderContent(siblingIndex + 1); + closing = RenderClosing(siblingIndex + 2); + Collapse(); + } + + private GameObject RenderOpening(int siblingIndex, string name) + { + var gameObject = new GameObject("Opening").AttachTo(container); + gameObject.transform.SetSiblingIndex(siblingIndex); + var image = gameObject.AddComponent(); + image.color = Color.magenta; + var rect = gameObject.GetComponent(); + rect.anchorMin = new Vector2(0.00f, margin); + rect.anchorMax = new Vector2(EDGE_WIDTH_RATIO, 1.00f - margin); + rect.offsetMin = Vector2.zero; + rect.offsetMax = Vector2.zero; + var label = new GameObject("Label").AttachTo(gameObject); + var text = label.AddComponent(); + text.font = FONT; + text.supportRichText = false; + text.alignByGeometry = true; + text.alignment = TextAnchor.MiddleCenter; + text.verticalOverflow = VerticalWrapMode.Overflow; + text.horizontalOverflow = HorizontalWrapMode.Overflow; + text.raycastTarget = false; + text.maskable = false; + text.text = name; + label.GetComponent().Expand(); + label.transform.rotation *= Quaternion.Euler(0.0f, 0.0f, 90.0f); + return gameObject; + } + + private GameObject RenderContent(int siblingIndex) + { + var gameObject = new GameObject("Content").AttachTo(container); + gameObject.transform.SetSiblingIndex(siblingIndex); + var image = gameObject.AddComponent(); + image.color = Color.white - new Color(0, 0, 0, 0.50f); + var rect = gameObject.GetComponent(); + rect.anchorMin = new Vector2(0.00f, margin); + rect.anchorMax = new Vector2(0.30f, 1.00f - margin); + rect.offsetMin = Vector2.zero; + rect.offsetMax = Vector2.zero; + return gameObject; + } + + private GameObject RenderClosing(int siblingIndex) + { + var gameObject = new GameObject("Closing").AttachTo(container); + gameObject.transform.SetSiblingIndex(siblingIndex); + var image = gameObject.AddComponent(); + image.color = Color.cyan; + var rect = gameObject.GetComponent(); + rect.anchorMin = new Vector2(0.00f, margin); + rect.anchorMax = new Vector2(EDGE_WIDTH_RATIO, 1.00f - margin); + rect.offsetMin = Vector2.zero; + rect.offsetMax = Vector2.zero; + return gameObject; + } + + public Bracket Nest(string name) + { + var nestedIndex = closing.transform.GetSiblingIndex() - 1; + return new Bracket(name, container, nestedIndex, margin + 0.08f); + } + + public void Open() + { + content.SetActive(true); + } + + public void Collapse() + { + content.SetActive(false); + } + } +} diff --git a/Assets/Scripts/View/GUI/Brackets/Bracket.cs.meta b/Assets/Scripts/View/GUI/Brackets/Bracket.cs.meta new file mode 100644 index 0000000..eea7ddb --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/Bracket.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4863ac71791743f4ea9298830c089109 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/View/GUI/Brackets/HorizontalLayoutWithAnchoredSize.cs b/Assets/Scripts/View/GUI/Brackets/HorizontalLayoutWithAnchoredSize.cs new file mode 100644 index 0000000..bf91087 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/HorizontalLayoutWithAnchoredSize.cs @@ -0,0 +1,38 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace view.gui.brackets +{ + public class HorizontalLayoutWithAnchoredSize : MonoBehaviour, ILayoutGroup + { + public void LayOutHorizontally() + { + var offset = 0.0f; + foreach (Transform child in gameObject.transform) + { + if (!child.gameObject.activeSelf) + { + continue; + } + if (child.gameObject.TryGetComponent(out var rect)) + { + rect.offsetMin = new Vector2(offset, 0); + rect.offsetMax = new Vector2(offset, 0); + UnityEngine.Debug.Log("Rect width: " + rect.rect.width); + offset += rect.rect.width; + } + } + UnityEngine.Debug.Log("Shifted for max offset of " + offset); + } + + void ILayoutController.SetLayoutHorizontal() + { + LayOutHorizontally(); + } + + void ILayoutController.SetLayoutVertical() + { + LayOutHorizontally(); + } + } +} diff --git a/Assets/Scripts/View/GUI/Brackets/HorizontalLayoutWithAnchoredSize.cs.meta b/Assets/Scripts/View/GUI/Brackets/HorizontalLayoutWithAnchoredSize.cs.meta new file mode 100644 index 0000000..62cdd49 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/HorizontalLayoutWithAnchoredSize.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6ada83a59a3a8dd4d98836dfa50d977a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/View/GUI/Brackets/RunnerGameBracket.cs b/Assets/Scripts/View/GUI/Brackets/RunnerGameBracket.cs new file mode 100644 index 0000000..e1c31a1 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/RunnerGameBracket.cs @@ -0,0 +1,39 @@ +using model; +using model.timing; +using UnityEngine; + +namespace view.gui.brackets +{ + class RunnerGameBracket + { + private Bracket bracket; + + public RunnerGameBracket(GameObject container, Game game) + { + bracket = new Bracket("Game", container); + container.AddComponent(); + game.CurrentTurn += DisplayTurn; + } + + private void DisplayTurn(ITurn turn) + { + switch (turn.Side) + { + case Side.RUNNER: DisplayRunnerTurn(turn); break; + case Side.CORP: DisplayCorpTurn(turn); break; + } + } + + private void DisplayRunnerTurn(ITurn turn) + { + var turnContainer = bracket.Nest("Runner turn"); + new TurnBracket(turnContainer, turn); + } + + private void DisplayCorpTurn(ITurn turn) + { + var turnContainer = bracket.Nest("Corp turn"); + new TurnBracket(turnContainer, turn); + } + } +} diff --git a/Assets/Scripts/View/GUI/Brackets/RunnerGameBracket.cs.meta b/Assets/Scripts/View/GUI/Brackets/RunnerGameBracket.cs.meta new file mode 100644 index 0000000..bfb4578 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/RunnerGameBracket.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 07c1b3d73b990434cb2fa1b202fdfc4d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/View/GUI/Brackets/TurnBracket.cs b/Assets/Scripts/View/GUI/Brackets/TurnBracket.cs new file mode 100644 index 0000000..ff209d9 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/TurnBracket.cs @@ -0,0 +1,17 @@ +using model.timing; + +namespace view.gui.brackets +{ + internal class TurnBracket + { + public TurnBracket(Bracket bracket, ITurn turn) + { + for (int i = 0; i < turn.Clicks.NextReplenishment; i++) + { + int actionOrder = i + 1; + var actionBracket = bracket.Nest("Action " + actionOrder); + new ActionBracket(turn, actionOrder, actionBracket); + } + } + } +} diff --git a/Assets/Scripts/View/GUI/Brackets/TurnBracket.cs.meta b/Assets/Scripts/View/GUI/Brackets/TurnBracket.cs.meta new file mode 100644 index 0000000..eff5985 --- /dev/null +++ b/Assets/Scripts/View/GUI/Brackets/TurnBracket.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5c871437f95405459f879515a137a67 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/View/GUI/CorpViewConfig.cs b/Assets/Scripts/View/GUI/CorpViewConfig.cs index 5019a92..2bc4bed 100644 --- a/Assets/Scripts/View/GUI/CorpViewConfig.cs +++ b/Assets/Scripts/View/GUI/CorpViewConfig.cs @@ -1,5 +1,5 @@ using model; -using UnityEngine; +using static view.gui.GameObjectExtensions; namespace view.gui { @@ -8,10 +8,10 @@ public class CorpViewConfig public CorpView Display(Game game, BoardParts parts) { var zones = game.corp.zones; - var credits = GameObject.Find("Corp/Credits"); + var credits = FindOrFail("Corp/Credits"); game.corp.credits.Changed += credits.AddComponent().UpdateBalance; game.corp.credits.Changed += credits.AddComponent().UpdateBalance; - var servers = new ServerRow(GameObject.Find("Servers"), parts, zones); + var servers = new ServerRow(FindOrFail("Servers"), parts, zones); var archivesBox = servers.Box(zones.archives); archivesBox.Printer.Sideways = true; var rd = servers.Box(zones.rd).Printer.PrintCorpFacedown("Top of R&D"); diff --git a/Assets/Scripts/View/GUI/GameFlowView.cs b/Assets/Scripts/View/GUI/GameFlowView.cs index 4eaa1fe..b31d3a6 100644 --- a/Assets/Scripts/View/GUI/GameFlowView.cs +++ b/Assets/Scripts/View/GUI/GameFlowView.cs @@ -3,6 +3,7 @@ using model.timing; using UnityEngine; using view.gui.timecross; +using static view.gui.GameObjectExtensions; namespace view.gui { @@ -23,8 +24,8 @@ public void Display(GameObject board, Game game) private PaidWindowView WirePaidWindow(PaidWindow window) { - var pass = GameObject.Find("Pass").AddComponent(); - PaidChoice = GameObject.Find("Paid choice").AddComponent(); + var pass = FindOrFail("Pass").AddComponent(); + PaidChoice = FindOrFail("Paid choice").AddComponent(); return new PaidWindowView(window, pass, PaidChoice); } diff --git a/Assets/Scripts/View/GUI/GameObjectExtensions.cs b/Assets/Scripts/View/GUI/GameObjectExtensions.cs index c20ef36..eb5eaec 100644 --- a/Assets/Scripts/View/GUI/GameObjectExtensions.cs +++ b/Assets/Scripts/View/GUI/GameObjectExtensions.cs @@ -1,12 +1,24 @@ -using UnityEngine; +using System; +using UnityEngine; namespace view.gui { public static class GameObjectExtensions { - public static void AttachTo(this GameObject child, GameObject parent) + public static GameObject AttachTo(this GameObject child, GameObject parent) { child.transform.SetParent(parent.transform, false); + return child; + } + + public static GameObject FindOrFail(string name) + { + var gameObject = GameObject.Find(name); + if (gameObject == null) + { + throw new SystemException("Cannot find game object named " + name + ". Maybe it's inactive?"); + } + return gameObject; } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/View/GUI/RectTransformExtensions.cs b/Assets/Scripts/View/GUI/RectTransformExtensions.cs new file mode 100644 index 0000000..f91d9f5 --- /dev/null +++ b/Assets/Scripts/View/GUI/RectTransformExtensions.cs @@ -0,0 +1,21 @@ +using UnityEngine; + +namespace view.gui +{ + public static class RectTransformExtensions + { + public static RectTransform AddCleanRectangle(this GameObject gameObject) + { + return gameObject.AddComponent().Expand(); + } + + public static RectTransform Expand(this RectTransform rect) + { + rect.anchorMin = Vector2.zero; + rect.anchorMax = Vector2.one; + rect.offsetMin = Vector2.zero; + rect.offsetMax = Vector2.zero; + return rect; + } + } +} diff --git a/Assets/Scripts/View/GUI/RectTransformExtensions.cs.meta b/Assets/Scripts/View/GUI/RectTransformExtensions.cs.meta new file mode 100644 index 0000000..d664f08 --- /dev/null +++ b/Assets/Scripts/View/GUI/RectTransformExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: baee744988816e148b3c46458f7ed243 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/View/GUI/RunnerViewConfig.cs b/Assets/Scripts/View/GUI/RunnerViewConfig.cs index 4f96beb..21774fe 100644 --- a/Assets/Scripts/View/GUI/RunnerViewConfig.cs +++ b/Assets/Scripts/View/GUI/RunnerViewConfig.cs @@ -1,6 +1,6 @@ using controller; using model; -using UnityEngine; +using static view.gui.GameObjectExtensions; namespace view.gui { @@ -9,18 +9,18 @@ public class RunnerViewConfig public void Display(Runner runner, GameFlowView flowView, CorpView corpView, BoardParts parts) { var presentBox = flowView.TimeCross.PresentBox; - RigGrid rigGrid = new RigGrid(GameObject.Find("Rig"), runner, flowView.PaidChoice, parts); - HeapPile heapPile = new HeapPile(GameObject.Find("Heap"), runner, parts); - GripFan gripFan = new GripFan(GameObject.Find("Grip"), runner, presentBox.RunnerActionPhase.AddComponent(), rigGrid.DropZone, heapPile.DropZone, parts); - new StackPile(GameObject.Find("Stack"), runner, gripFan.DropZone, parts); - new ZoneBox(GameObject.Find("Runner/Left hand/Score"), parts).Represent(runner.zones.score.zone); - runner.zones.identity.Added += (zone, identity) => parts.Print(GameObject.Find("Runner/Right hand/Core/Identity")).Print(identity); + RigGrid rigGrid = new RigGrid(FindOrFail("Rig"), runner, flowView.PaidChoice, parts); + HeapPile heapPile = new HeapPile(FindOrFail("Heap"), runner, parts); + GripFan gripFan = new GripFan(FindOrFail("Grip"), runner, presentBox.RunnerActionPhase.AddComponent(), rigGrid.DropZone, heapPile.DropZone, parts); + new StackPile(FindOrFail("Stack"), runner, gripFan.DropZone, parts); + new ZoneBox(FindOrFail("Runner/Left hand/Score"), parts).Represent(runner.zones.score.zone); + runner.zones.identity.Added += (zone, identity) => parts.Print(FindOrFail("Runner/Right hand/Core/Identity")).Print(identity); new RunInitiation( - gameObject: GameObject.Find("Run"), + gameObject: FindOrFail("Run"), serverRow: corpView.serverRow, runner: runner ); - var credits = GameObject.Find("Runner/Credits"); + var credits = FindOrFail("Runner/Credits"); presentBox .BankCredit .AddComponent() diff --git a/Assets/Scripts/View/GUI/TimeCross/DayNightCycle.cs b/Assets/Scripts/View/GUI/TimeCross/DayNightCycle.cs index bbd6146..d7e82a8 100644 --- a/Assets/Scripts/View/GUI/TimeCross/DayNightCycle.cs +++ b/Assets/Scripts/View/GUI/TimeCross/DayNightCycle.cs @@ -2,6 +2,7 @@ using UnityEngine.UI; using model; using model.timing; +using static view.gui.GameObjectExtensions; namespace view.gui.timecross { @@ -11,14 +12,14 @@ public class DayNightCycle private Color midnight = new Color(23, 17, 44, 255) / 255; private Sprite dayCity = Resources.Load("Images/Background/photo-of-cityscape-on-a-gloomy-day-2137195"); private Sprite nightCity = Resources.Load("Images/Background/high-rise-photography-of-city-2039630"); - private Image background = GameObject.Find("Board").GetComponent(); + private Image background = FindOrFail("Board").GetComponent(); public void Wire(Game game) { game.CurrentTurn += UpdateBackground; } - void UpdateBackground(object sender, ITurn turn) + void UpdateBackground(ITurn turn) { switch (turn.Side) { diff --git a/Assets/Scripts/View/GUI/TimeCross/FutureTrack.cs b/Assets/Scripts/View/GUI/TimeCross/FutureTrack.cs index 07b69f0..521fb14 100644 --- a/Assets/Scripts/View/GUI/TimeCross/FutureTrack.cs +++ b/Assets/Scripts/View/GUI/TimeCross/FutureTrack.cs @@ -53,13 +53,13 @@ void Awake() background = gameObject.AddComponent(); } - internal void DisplayCurrent(object sender, ITurn turn) + internal void DisplayCurrent(ITurn turn) { dayNight.Paint(background, turn.Side); TrackClicks(turn, UpdateRemainingClicks); } - internal void DisplayNext(object sender, ITurn turn) + internal void DisplayNext(ITurn turn) { dayNight.Paint(background, turn.Side); TrackClicks(turn, UpdateNextClicks); diff --git a/Assets/Scripts/View/GUI/TimeCross/PresentBox.cs b/Assets/Scripts/View/GUI/TimeCross/PresentBox.cs index 08e4988..3dde621 100644 --- a/Assets/Scripts/View/GUI/TimeCross/PresentBox.cs +++ b/Assets/Scripts/View/GUI/TimeCross/PresentBox.cs @@ -5,6 +5,7 @@ using model.timing; using UnityEngine; using UnityEngine.UI; +using static view.gui.GameObjectExtensions; namespace view.gui.timecross { @@ -31,10 +32,10 @@ internal void Wire(Game game, DayNightCycle dayNight, FutureTrack future) private void WireRunnerActionPhase(Game game) { - RunnerActionPhase = GameObject.Find("Runner action phase"); + RunnerActionPhase = FindOrFail("Runner action phase"); var background = RunnerActionPhase.GetComponent(); dayNight.Paint(background, Side.RUNNER); - BankCredit = GameObject.Find("Bank/Credit"); + BankCredit = FindOrFail("Bank/Credit"); SetRunnerActions(false); game.runner.turn.TakingAction += BeginRunnerAction; game.runner.turn.ActionTaken += EndRunnerAction; @@ -48,7 +49,7 @@ private void SetRunnerActions(bool takingAction) private void WireCorpActionPhase(Game game) { - corpActionPhase = GameObject.Find("Corp action phase"); + corpActionPhase = FindOrFail("Corp action phase"); var background = corpActionPhase.GetComponent(); dayNight.Paint(background, Side.CORP); corpActionPhase.SetActive(false); @@ -58,7 +59,7 @@ private void WireCorpActionPhase(Game game) private void WireDiscardPhase(Game game) { - discardPhase = GameObject.Find("Discard phase"); + discardPhase = FindOrFail("Discard phase"); discardBackground = discardPhase.GetComponent(); discardPhase.SetActive(false); game.runner.zones.grip.DiscardingOne += RenderRunnerDiscarding; diff --git a/Assets/Scripts/View/GUI/TimeCross/TimeCross.cs b/Assets/Scripts/View/GUI/TimeCross/TimeCross.cs index d0d7bd4..f6e2b33 100644 --- a/Assets/Scripts/View/GUI/TimeCross/TimeCross.cs +++ b/Assets/Scripts/View/GUI/TimeCross/TimeCross.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using static view.gui.GameObjectExtensions; using model; namespace view.gui.timecross @@ -9,12 +9,12 @@ public class TimeCross public TimeCross(Game game, DayNightCycle dayNight) { - var pastTrack = GameObject.Find("Past").AddComponent(); + var pastTrack = FindOrFail("Past").AddComponent(); pastTrack.DayNight = dayNight; pastTrack.Wire(game); - var futureTrack = GameObject.Find("Future").AddComponent(); + var futureTrack = FindOrFail("Future").AddComponent(); futureTrack.Wire(game, dayNight); - PresentBox = GameObject.Find("Present").AddComponent(); + PresentBox = FindOrFail("Present").AddComponent(); PresentBox.Wire(game, dayNight, futureTrack); } }