public static UIBlocker Create(Transform requester) { // Make sure the requester is not null if (!requester) { throw new System.ArgumentNullException(nameof(requester)); } Canvas canvas = requester.GetComponentInParent <Canvas>(); // If there is no canvas in the parent then throw exception if (!canvas) { throw new System.ArgumentException( $"Cannot request a UIBlocker for object {requester} " + $"because it is not a canvas or a child of a canvas!"); } // Make sure we have the root canvas canvas = canvas.rootCanvas; // Create a UI blocker from resources UIBlocker instance = ResourcesExtensions.InstantiateFromResources <UIBlocker>(nameof(UIBlocker), canvas.transform); instance.transform.SetAsLastSibling(); return(instance); }
public void EnableDropdown() { // Enable the dropdown dropdown.SetActive(true); // Make sure the dropdown sorts above all other UI Canvas canvas = dropdown.GetOrAddComponent <Canvas>(); canvas.overrideSorting = true; canvas.sortingOrder = 30000; // Make sure the dropdown has a graphic raycaster dropdown.GetOrAddComponent <GraphicRaycaster>(); // Create a UI blocker currentUIBlocker = UIBlocker.Create(transform); currentUIBlocker.OnClick += DisableDropdown; }
public void ToggleBlocker(bool toggleOn, UIBlocker blocker) { Collider2D[] colliders = currentRatio.GetComponentsInChildren <Collider2D>(); switch (blocker) { case UIBlocker.INVENTORY: colliders[2].enabled = toggleOn; break; case UIBlocker.OPTIONS: colliders[3].enabled = toggleOn; break; case UIBlocker.TIPS: colliders[4].enabled = toggleOn; break; } }
public void SetPanel(int newPanel) { OptionsModeButton.Selected = false; BuyModeButton.Selected = false; BuildModeButton.Selected = false; LiveModeButton.Selected = false; if (Game.InLot) { Game.LotController.QueryPanel.Active = false; Game.LotController.QueryPanel.Visible = false; Game.LotController.LiveMode = true; Game.vm.Context.World.State.BuildMode = false; } if (CurrentPanel != -1) { this.Remove(Panel); Panel.Destroy(); if (Game.InLot) { Game.LotController.PanelActive = false; } } if (newPanel != CurrentPanel) { if (Game.InLot) { Game.LotController.PanelActive = true; } switch (newPanel) { case 5: Panel = new UIOptions(); Panel.X = 177; Panel.Y = 96; this.Add(Panel); OptionsModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 2: if (!Game.InLot) { break; //not ingame } Panel = new UIBuyMode(Game.LotController); Game.LotController.LiveMode = false; Panel.X = 177; Panel.Y = 96; ((UIBuyMode)Panel).vm = Game.vm; this.Add(Panel); BuyModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 3: if (!Game.InLot) { break; //not ingame } Panel = new UIBuildMode(Game.LotController); //enable air tile graphics Game.vm.Context.World.State.BuildMode = true; Game.LotController.LiveMode = false; Panel.X = 177; Panel.Y = 96; ((UIBuildMode)Panel).vm = Game.vm; this.Add(Panel); BuildModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 1: if (!Game.InLot) { break; //not ingame } Panel = new UILiveMode(Game.LotController); Panel.X = 177; Panel.Y = 63; this.Add(Panel); LiveModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; default: if (Game.InLot) { Game.LotController.PanelActive = false; } break; } CurrentPanel = newPanel; } else { Remove(PanelBlocker); PanelBlocker = null; CurrentPanel = -1; } }
/// <summary> /// Sets the "focus mode" of the UCP, used to make the UI accessible on phones. /// </summary> /// <param name="focus"></param> public void SetFocus(UCPFocusMode focus) { if (Focus == focus) { return; } if (FSOEnvironment.UIZoomFactor > 1f) { if (focus != UCPFocusMode.Game) { var tween = GameFacade.Screens.Tween.To(this, 0.33f, new Dictionary <string, float>() { { "ScaleX", FSOEnvironment.UIZoomFactor }, { "ScaleY", FSOEnvironment.UIZoomFactor }, { "Y", Game.ScreenHeight - (int)(210 * FSOEnvironment.UIZoomFactor) }, { "X", (focus == UCPFocusMode.ActiveTab)?-(int)(225 * FSOEnvironment.UIZoomFactor):0 } }, TweenQuad.EaseInOut); Remove(SelfBlocker); SelfBlocker = null; if (focus == UCPFocusMode.ActiveTab) { Remove(PanelBlocker); PanelBlocker = null; } if (GameBlocker == null) { GameBlocker = new UIBlocker(); GameBlocker.Position = new Vector2(0, 220 - Game.ScreenHeight); GameBlocker.OnMouseEvt += (evt, state) => { if (evt == UIMouseEventType.MouseDown) { SetFocus(UCPFocusMode.Game); } }; AddAt(0, GameBlocker); } } else { var tween = GameFacade.Screens.Tween.To(this, 0.33f, new Dictionary <string, float>() { { "ScaleX", 1f }, { "ScaleY", 1f }, { "Y", Game.ScreenHeight - 210 }, { "X", 0 } }, TweenQuad.EaseInOut); if (SelfBlocker == null) { SelfBlocker = new UIBlocker(220, 210); SelfBlocker.OnMouseEvt += (evt, state) => { if (evt == UIMouseEventType.MouseDown) { SetFocus(UCPFocusMode.UCP); } }; Add(SelfBlocker); } if (CurrentPanel > -1 && PanelBlocker == null) { PanelBlocker = new UIBlocker(580, 104); PanelBlocker.Position = new Vector2(220, 106); PanelBlocker.OnMouseEvt += (evt, state) => { if (evt == UIMouseEventType.MouseDown) { SetFocus(UCPFocusMode.ActiveTab); } }; Add(PanelBlocker); } Remove(GameBlocker); GameBlocker = null; } } Focus = focus; }
public void SetPanel(int newPanel) { GameFacade.Cursor.SetCursor(CursorType.Hourglass); OptionsModeButton.Selected = false; BuyModeButton.Selected = false; BuildModeButton.Selected = false; LiveModeButton.Selected = false; HouseModeButton.Selected = false; if (Game.InLot) { Game.LotControl.QueryPanel.Active = false; Game.LotControl.QueryPanel.Visible = false; Game.LotControl.LiveMode = true; Game.LotControl.World.State.BuildMode = 0; } if (CurrentPanel != -1) { switch (CurrentPanel) { case 3: case 2: if (Game.InLot && Game.vm.TSOState.Roommates.Contains(Game.vm.MyUID)) { FindController <CoreGameScreenController>()?.UploadLotThumbnail(); } break; } DynamicOverlay.Remove(Panel); Panel = null; if (Game.InLot) { Game.LotControl.SetDonatorDialogVisible(false); Game.LotControl.PanelActive = false; } } if (newPanel != CurrentPanel) { if (SpecialMusic || SpecialMusicTrigger()) { if (newPanel == 2) { HITVM.Get().PlaySoundEvent(UIMusic.Buy); } else if (newPanel == 3 || newPanel == 4) { HITVM.Get().PlaySoundEvent(UIMusic.Build); } else if (newPanel != 5) { HITVM.Get().PlaySoundEvent(UIMusic.None); } } if (Game.InLot) { Game.LotControl.SetDonatorDialogVisible(newPanel > 1 && newPanel < 4); Game.LotControl.PanelActive = true; if ((newPanel == 2 || newPanel == 3) && Game.vm.TSOState.CommunityLot) { if (Game.vm.TSOState.OwnerID == Game.vm.MyUID) { FSOFacade.Hints.TriggerHint("ui:mayor_buildbuy"); FSOFacade.Hints.TriggerHint("ui:mayor_donators"); } else if (Game.vm.TSOState.Roommates.Contains(Game.vm.MyUID)) { FSOFacade.Hints.TriggerHint("ui:donator"); } } } switch (newPanel) { case 5: Panel = new UIOptions(); Panel.X = 177; Panel.Y = 96; DynamicOverlay.Add(Panel); OptionsModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 2: if (!Game.InLot) { break; //not ingame } Panel = new UIBuyMode(Game.LotControl); //enable grid Game.LotControl.World.State.BuildMode = 1; Game.LotControl.LiveMode = false; Panel.X = 177; Panel.Y = 96; DynamicOverlay.Add(Panel); BuyModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 3: if (!Game.InLot) { break; //not ingame } Panel = new UIBuildMode(Game.LotControl); //enable air tile graphics + grid Game.LotControl.World.State.BuildMode = 2; Game.LotControl.LiveMode = false; Panel.X = 177; Panel.Y = 96; DynamicOverlay.Add(Panel); BuildModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); FSOFacade.Hints.TriggerHint("ui:buildmode"); break; case 4: if (!Game.InLot) { break; //not ingame } Panel = new UIHouseMode(Game.LotControl); //enable grid Game.LotControl.World.State.BuildMode = 1; Panel.X = 177; Panel.Y = 87; DynamicOverlay.Add(Panel); HouseModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 1: if (!Game.InLot) { break; //not ingame } Panel = new UILiveMode(Game.LotControl); Panel.X = 177; Panel.Y = 61; DynamicOverlay.Add(Panel); LiveModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; default: if (Game.InLot) { Game.LotControl.PanelActive = false; } break; } CurrentPanel = newPanel; } else { Remove(PanelBlocker); PanelBlocker = null; CurrentPanel = -1; } GameFacade.Cursor.SetCursor(CursorType.Normal); }
public void SetPanel(int newPanel) { GameFacade.Cursor.SetCursor(CursorType.Hourglass); OptionsModeButton.Selected = false; BuyModeButton.Selected = false; BuildModeButton.Selected = false; LiveModeButton.Selected = false; HouseModeButton.Selected = false; if (Game.InLot) { Game.LotControl.QueryPanel.Active = false; Game.LotControl.QueryPanel.Visible = false; Game.LotControl.LiveMode = true; Game.LotControl.World.State.BuildMode = 0; } if (CurrentPanel != -1) { switch (CurrentPanel) { case 3: case 2: if (Game.InLot && Game.vm.TSOState.Roommates.Contains(Game.vm.MyUID)) { FindController <CoreGameScreenController>().UploadLotThumbnail(); } break; } DynamicOverlay.Remove(Panel); Panel = null; if (Game.InLot) { Game.LotControl.PanelActive = false; } } if (newPanel != CurrentPanel) { if (Game.InLot) { Game.LotControl.PanelActive = true; } switch (newPanel) { case 5: Panel = new UIOptions(); Panel.X = 177; Panel.Y = 96; DynamicOverlay.Add(Panel); OptionsModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 2: if (!Game.InLot) { break; //not ingame } Panel = new UIBuyMode(Game.LotControl); //enable grid Game.LotControl.World.State.BuildMode = 1; Game.LotControl.LiveMode = false; Panel.X = 177; Panel.Y = 96; DynamicOverlay.Add(Panel); BuyModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 3: if (!Game.InLot) { break; //not ingame } Panel = new UIBuildMode(Game.LotControl); //enable air tile graphics + grid Game.LotControl.World.State.BuildMode = 2; Game.LotControl.LiveMode = false; Panel.X = 177; Panel.Y = 96; DynamicOverlay.Add(Panel); BuildModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 4: if (!Game.InLot) { break; //not ingame } Panel = new UIHouseMode(Game.LotControl); //enable grid Game.LotControl.World.State.BuildMode = 1; Panel.X = 177; Panel.Y = 87; DynamicOverlay.Add(Panel); HouseModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; case 1: if (!Game.InLot) { break; //not ingame } Panel = new UILiveMode(Game.LotControl); Panel.X = 177; Panel.Y = 61; DynamicOverlay.Add(Panel); LiveModeButton.Selected = true; SetFocus(UCPFocusMode.ActiveTab); break; default: if (Game.InLot) { Game.LotControl.PanelActive = false; } break; } CurrentPanel = newPanel; } else { Remove(PanelBlocker); PanelBlocker = null; CurrentPanel = -1; } GameFacade.Cursor.SetCursor(CursorType.Normal); }
void Awake() { instance = this; }