private void CheckScreenSize(AC.Menu menu) { if (screenSize.x != Screen.width || screenSize.y != Screen.height) { screenSize = new Vector2 (Screen.width, Screen.height); menu.Recalculate (); } }
public static void OnMenuEnable(AC.Menu _menu) { // This function is called whenever a menu is enabled. if (_menu.title == "Pause") { MenuElement saveButton = _menu.GetElementWithName ("SaveButton"); if (saveButton) { saveButton.isVisible = !PlayerMenus.IsSavingLocked (); } _menu.Recalculate (); } }
public override void ProcessClick(AC.Menu _menu, int _slot, MouseState _mouseState) { if (KickStarter.stateHandler.gameState == GameState.Cutscene) { return; } base.ProcessClick (_menu, _slot, _mouseState); if (craftingType == CraftingElementType.Ingredients) { HandleDefaultClick (_mouseState, _slot); } else if (craftingType == CraftingElementType.Output) { ClickOutput (_menu, _mouseState); } _menu.Recalculate (); }
private void AddElement(string className, AC.Menu _menu) { Undo.RecordObject (_menu, "Add element"); List<int> idArray = new List<int>(); foreach (MenuElement _element in _menu.elements) { if (_element != null) { idArray.Add (_element.ID); } } idArray.Sort (); className = "Menu" + className; MenuElement newElement = (MenuElement) CreateInstance (className); newElement.Declare (); newElement.title = className.Substring (4); // Update id based on array foreach (int _id in idArray.ToArray()) { if (newElement.ID == _id) { newElement.ID ++; } } _menu.elements.Add (newElement); if (!Application.isPlaying) { _menu.Recalculate (); } DeactivateAllElements (_menu); newElement.isEditing = true; selectedMenuElement = newElement; newElement.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset (newElement, this); AssetDatabase.ImportAsset (AssetDatabase.GetAssetPath (newElement)); AssetDatabase.SaveAssets (); CleanUpAsset (); }
private void UpdateMenu(AC.Menu menu) { Vector2 invertedMouse = KickStarter.playerInput.GetInvertedMouse (); UpdateMenuPosition (menu, invertedMouse); menu.HandleTransition (); if (KickStarter.settingsManager.inputMethod == InputMethod.KeyboardOrController && menu.IsEnabled ()) { KickStarter.playerInput.InputControlMenu (menu); } if (menu.appearType == AppearType.Manual) { if (menu.IsVisible () && !menu.isLocked && menu.IsPointInside (invertedMouse) && !menu.ignoreMouseClicks) { foundMouseOverMenu = true; } } else if (menu.appearType == AppearType.DuringGameplay) { if (KickStarter.stateHandler.gameState == GameState.Normal && !menu.isLocked) { if (menu.IsOff ()) { menu.TurnOn (true); } if (menu.IsOn () && menu.IsPointInside (invertedMouse)) { foundMouseOverMenu = true; } } else if (KickStarter.stateHandler.gameState == GameState.Paused) { menu.TurnOff (true); } //else if (KickStarter.stateHandler.gameState != GameState.Normal && menu.IsOn () && (KickStarter.actionListManager.AreActionListsRunning () || KickStarter.playerInput.activeConversation != null)) else if (menu.IsOn () && KickStarter.actionListManager.IsGameplayBlocked ()) { menu.TurnOff (true); } } else if (menu.appearType == AppearType.MouseOver) { if (KickStarter.stateHandler.gameState == GameState.Normal && !menu.isLocked && menu.IsPointInside (invertedMouse)) { if (menu.IsOff ()) { menu.TurnOn (true); } if (!menu.ignoreMouseClicks) { foundMouseOverMenu = true; } } else if (KickStarter.stateHandler.gameState == GameState.Paused) { menu.ForceOff (); } else { menu.TurnOff (true); } } else if (menu.appearType == AppearType.OnContainer) { if (KickStarter.playerInput.activeContainer != null && !menu.isLocked && (KickStarter.stateHandler.gameState == GameState.Normal || (KickStarter.stateHandler.gameState == AC.GameState.Paused && menu.pauseWhenEnabled))) { if (menu.IsVisible () && menu.IsPointInside (invertedMouse) && !menu.ignoreMouseClicks) { foundMouseOverMenu = true; } menu.TurnOn (true); } else { menu.TurnOff (true); } } else if (menu.appearType == AppearType.DuringConversation) { if (KickStarter.playerInput.activeConversation != null && KickStarter.stateHandler.gameState == GameState.DialogOptions) { menu.TurnOn (true); } else if (KickStarter.stateHandler.gameState == GameState.Paused) { menu.ForceOff (); } else { menu.TurnOff (true); } } else if (menu.appearType == AppearType.OnInputKey) { if (menu.IsEnabled () && !menu.isLocked && menu.IsPointInside (invertedMouse) && !menu.ignoreMouseClicks) { foundMouseOverMenu = true; } try { if (KickStarter.playerInput.InputGetButtonDown (menu.toggleKey, true)) { if (!menu.IsEnabled ()) { if (KickStarter.stateHandler.gameState == GameState.Paused) { CrossFade (menu); } else { menu.TurnOn (true); } } else { menu.TurnOff (true); } } } catch { if (KickStarter.settingsManager.inputMethod != InputMethod.TouchScreen) { Debug.LogWarning ("No '" + menu.toggleKey + "' button exists - please define one in the Input Manager."); } } } else if (menu.appearType == AppearType.OnHotspot) { if (KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive && !menu.isLocked && KickStarter.runtimeInventory.selectedItem == null) { Hotspot hotspot = KickStarter.playerInteraction.GetActiveHotspot (); if (hotspot != null) { menu.HideInteractions (); if (hotspot.HasContextUse ()) { menu.MatchUseInteraction (hotspot.GetFirstUseButton ()); } if (hotspot.HasContextLook ()) { menu.MatchLookInteraction (hotspot.lookButton); } menu.Recalculate (); } } if (hotspotLabel != "" && !menu.isLocked && KickStarter.stateHandler.gameState != GameState.Cutscene) //(KickStarter.stateHandler.gameState == GameState.Normal || KickStarter.stateHandler.gameState == GameState.DialogOptions)) { if (!menu.IsOn ()) { menu.TurnOn (true); if (menu.IsUnityUI ()) { // Update position before next frame (Unity UI bug) UpdateMenuPosition (menu, invertedMouse); } } } //else if (KickStarter.stateHandler.gameState == GameState.Paused) else if (KickStarter.stateHandler.gameState == GameState.Cutscene) { menu.ForceOff (); } else { menu.TurnOff (true); } } else if (menu.appearType == AppearType.OnInteraction) { if (KickStarter.settingsManager.CanClickOffInteractionMenu ()) { if (menu.IsEnabled () && (KickStarter.stateHandler.gameState == GameState.Normal || menu.pauseWhenEnabled)) { interactionMenuIsOn = true; if (menu.IsPointInside (invertedMouse) && !menu.ignoreMouseClicks) { foundMouseOverInteractionMenu = true; } else if (KickStarter.playerInput.GetMouseState () == MouseState.SingleClick) { KickStarter.playerInput.ResetMouseClick (); interactionMenuIsOn = false; menu.TurnOff (true); } } else if (KickStarter.stateHandler.gameState == GameState.Paused) { interactionMenuIsOn = false; menu.ForceOff (); } else if (KickStarter.playerInteraction.GetActiveHotspot () == null) { interactionMenuIsOn = false; menu.TurnOff (true); } } else { if (menu.IsEnabled () && (KickStarter.stateHandler.gameState == GameState.Normal || menu.pauseWhenEnabled)) { if (menu.IsPointInside (invertedMouse) && !menu.ignoreMouseClicks) { foundMouseOverInteractionMenu = true; } else if (!menu.IsPointInside (invertedMouse) && !menu.ignoreMouseClicks && KickStarter.playerInteraction.GetActiveHotspot () == null && KickStarter.runtimeInventory.hoverItem == null && (KickStarter.settingsManager.interactionMethod != AC_InteractionMethod.ChooseHotspotThenInteraction || KickStarter.settingsManager.cancelInteractions == CancelInteractions.CursorLeavesMenuOrHotspot)) { interactionMenuIsOn = false; menu.TurnOff (true); } else if (!menu.IsPointInside (invertedMouse) && !menu.ignoreMouseClicks && KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction && KickStarter.settingsManager.cancelInteractions == CancelInteractions.CursorLeavesMenu && !menu.IsFadingIn ()) { interactionMenuIsOn = false; menu.TurnOff (true); } else if (KickStarter.playerInteraction.GetActiveHotspot () == null && KickStarter.runtimeInventory.hoverItem == null && KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction && KickStarter.settingsManager.selectInteractions == AC.SelectInteractions.CyclingMenuAndClickingHotspot) { interactionMenuIsOn = false; menu.TurnOff (true); } else if (KickStarter.settingsManager.SelectInteractionMethod () == SelectInteractions.CyclingMenuAndClickingHotspot && KickStarter.playerInteraction.GetActiveHotspot () != null) {} else if (KickStarter.settingsManager.SelectInteractionMethod () == SelectInteractions.CyclingMenuAndClickingHotspot && KickStarter.runtimeInventory.hoverItem != null) {} else if (KickStarter.playerInteraction.GetActiveHotspot () == null || KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen) {} else if (KickStarter.runtimeInventory.selectedItem == null && KickStarter.playerInteraction.GetActiveHotspot () != null && KickStarter.runtimeInventory.hoverItem != null) { interactionMenuIsOn = false; menu.TurnOff (true); } else if (KickStarter.runtimeInventory.selectedItem != null && KickStarter.runtimeInventory.selectedItem != KickStarter.runtimeInventory.hoverItem) { interactionMenuIsOn = false; menu.TurnOff (true); } } else if (KickStarter.stateHandler.gameState == GameState.Paused) { interactionMenuIsOn = false; menu.ForceOff (); } else if (KickStarter.playerInteraction.GetActiveHotspot () == null) { interactionMenuIsOn = false; menu.TurnOff (true); } } } else if (menu.appearType == AppearType.WhenSpeechPlays) { if (KickStarter.stateHandler.gameState == GameState.Paused) { menu.TurnOff (); } else { Speech speech = menu.speech; if (!menu.oneMenuPerSpeech) { speech = KickStarter.dialog.GetLatestSpeech (); } if (speech != null && (menu.speechMenuType == SpeechMenuType.All || (menu.speechMenuType == SpeechMenuType.CharactersOnly && speech.GetSpeakingCharacter () != null) || (menu.speechMenuType == SpeechMenuType.NarrationOnly && speech.GetSpeakingCharacter () == null)) && (menu.speechMenuLimit == SpeechMenuLimit.All || (menu.speechMenuLimit == SpeechMenuLimit.BlockingOnly && !speech.isBackground) || (menu.speechMenuLimit == SpeechMenuLimit.BackgroundOnly && speech.isBackground))) { if (Options.optionsData == null || (Options.optionsData != null && Options.optionsData.showSubtitles) || (KickStarter.speechManager.forceSubtitles && !KickStarter.dialog.FoundAudio ())) { menu.TurnOn (true); } else { menu.TurnOff (true); } } else { menu.TurnOff (true); } } } }
/** * <summary>Updates a Menu's position.</summary> * <param name = "menu">The Menu to reposition</param> * <param name = "invertedMouse">The y-inverted mouse position</param> */ public void UpdateMenuPosition(AC.Menu menu, Vector2 invertedMouse) { if (menu.IsUnityUI ()) { if (Application.isPlaying) { Vector2 screenPosition = Vector2.zero; if (menu.uiPositionType == UIPositionType.Manual) { return; } else if (menu.uiPositionType == UIPositionType.FollowCursor) { screenPosition = new Vector2 (invertedMouse.x, Screen.height + 1f - invertedMouse.y); menu.SetCentre (screenPosition); } else if (menu.uiPositionType == UIPositionType.OnHotspot) { if (!menu.IsFadingOut ()) { if (mouseOverInventory) { screenPosition = new Vector2 (activeInventoryBoxCentre.x, Screen.height + 1f - activeInventoryBoxCentre.y); menu.SetCentre (screenPosition); } else if (KickStarter.playerInteraction.GetActiveHotspot ()) { if (menu.canvas.renderMode == RenderMode.WorldSpace) { menu.SetCentre (KickStarter.playerInteraction.GetActiveHotspot ().transform.position); } else { screenPosition = KickStarter.playerInteraction.GetHotspotScreenCentre (); screenPosition = new Vector2 (screenPosition.x * Screen.width, (1f - screenPosition.y) * Screen.height); menu.SetCentre (screenPosition); } } } } else if (menu.uiPositionType == UIPositionType.AboveSpeakingCharacter) { Char speaker = null; if (dupMenus.Contains (menu)) { if (menu.speech != null) { speaker = menu.speech.GetSpeakingCharacter (); } } else { speaker = KickStarter.dialog.GetSpeakingCharacter (); } if (speaker != null) { if (menu.canvas.renderMode == RenderMode.WorldSpace) { menu.SetCentre (speaker.transform.position); } else { screenPosition = speaker.GetScreenCentre (); screenPosition = new Vector2 (screenPosition.x * Screen.width, (1f - screenPosition.y) * Screen.height); menu.SetCentre (screenPosition); } } } else if (menu.uiPositionType == UIPositionType.AbovePlayer) { if (KickStarter.player) { if (menu.canvas.renderMode == RenderMode.WorldSpace) { menu.SetCentre (KickStarter.player.transform.position); } else { screenPosition = KickStarter.player.GetScreenCentre (); screenPosition = new Vector2 (screenPosition.x * Screen.width, (1f - screenPosition.y) * Screen.height); menu.SetCentre (screenPosition); } } } } return; } if (menu.sizeType == AC_SizeType.Automatic && menu.autoSizeEveryFrame) { menu.Recalculate (); } if (invertedMouse == Vector2.zero) { invertedMouse = KickStarter.playerInput.GetInvertedMouse (); } if (menu.positionType == AC_PositionType.FollowCursor) { menu.SetCentre (new Vector2 ((invertedMouse.x / Screen.width) + (menu.manualPosition.x / 100f) - 0.5f, (invertedMouse.y / Screen.height) + (menu.manualPosition.y / 100f) - 0.5f)); } else if (menu.positionType == AC_PositionType.OnHotspot) { if (!menu.IsFadingOut ()) { if (mouseOverInventory) { Vector2 screenPosition = new Vector2 (activeInventoryBoxCentre.x / Screen.width, activeInventoryBoxCentre.y / Screen.height); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } else if (KickStarter.playerInteraction.GetActiveHotspot ()) { Vector2 screenPosition = KickStarter.playerInteraction.GetHotspotScreenCentre (); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } } } else if (menu.positionType == AC_PositionType.AboveSpeakingCharacter) { Char speaker = null; if (dupMenus.Contains (menu)) { if (menu.speech != null) { speaker = menu.speech.GetSpeakingCharacter (); } } else { speaker = KickStarter.dialog.GetSpeakingCharacter (); } if (speaker != null) { Vector2 screenPosition = speaker.GetScreenCentre (); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } } else if (menu.positionType == AC_PositionType.AbovePlayer) { if (KickStarter.player) { Vector2 screenPosition = KickStarter.player.GetScreenCentre (); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } } }
/** * <summary>Processes the clicking of an inventory item within a MenuInventoryBox element</summary> * <param name = "_menu">The Menu that contains the MenuInventoryBox element</param> * <param name = "inventoryBox">The MenuInventoryBox element that was clicked on</param> * <param name = "_slot">The index number of the MenuInventoryBox slot that was clicked on</param> * <param name = "_mouseState">The state of the mouse when the click occured (Normal, SingleClick, RightClick, DoubleClick, HeldDown, LetGo)</param> */ public void ProcessInventoryBoxClick(AC.Menu _menu, MenuInventoryBox inventoryBox, int _slot, MouseState _mouseState) { if (inventoryBox.inventoryBoxType == AC_InventoryBoxType.Default || inventoryBox.inventoryBoxType == AC_InventoryBoxType.DisplayLastSelected) { if (KickStarter.settingsManager.inventoryInteractions == InventoryInteractions.Multiple && KickStarter.playerMenus.IsInteractionMenuOn ()) { KickStarter.playerMenus.SetInteractionMenus (false); ClickInvItemToInteract (); } else if (KickStarter.settingsManager.inventoryInteractions == InventoryInteractions.Multiple && KickStarter.settingsManager.SelectInteractionMethod () == AC.SelectInteractions.CyclingCursorAndClickingHotspot) { if (KickStarter.settingsManager.autoCycleWhenInteract && _mouseState == MouseState.SingleClick && (selectedItem == null || KickStarter.settingsManager.cycleInventoryCursors)) { int originalIndex = KickStarter.playerInteraction.GetInteractionIndex (); KickStarter.playerInteraction.SetNextInteraction (); KickStarter.playerInteraction.SetInteractionIndex (originalIndex); } if (!KickStarter.settingsManager.cycleInventoryCursors && selectedItem != null) { inventoryBox.HandleDefaultClick (_mouseState, _slot, KickStarter.settingsManager.interactionMethod); } else if (_mouseState != MouseState.RightClick) { KickStarter.playerMenus.SetInteractionMenus (false); ClickInvItemToInteract (); } if (KickStarter.settingsManager.autoCycleWhenInteract && _mouseState == MouseState.SingleClick) { KickStarter.playerInteraction.RestoreInventoryInteraction (); } } else if (KickStarter.settingsManager.interactionMethod != AC_InteractionMethod.ContextSensitive && KickStarter.settingsManager.inventoryInteractions == InventoryInteractions.Single) { inventoryBox.HandleDefaultClick (_mouseState, _slot, AC_InteractionMethod.ContextSensitive); } else { inventoryBox.HandleDefaultClick (_mouseState, _slot, KickStarter.settingsManager.interactionMethod); } _menu.Recalculate (); } else if (inventoryBox.inventoryBoxType == AC_InventoryBoxType.Container) { inventoryBox.ClickContainer (_mouseState, _slot, KickStarter.playerInput.activeContainer); _menu.Recalculate (); } else if (inventoryBox.inventoryBoxType == AC_InventoryBoxType.HotspotBased) { if (KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction) { if (_menu.GetTargetInvItem () != null) { //Combine (hoverItem, inventoryBox.items [_slot]); Combine (_menu.GetTargetInvItem (), inventoryBox.items [_slot + inventoryBox.GetOffset ()]); } else if (_menu.GetTargetHotspot ()) { InvItem _item = inventoryBox.items [_slot + inventoryBox.GetOffset ()]; if (_item != null) { //SelectItem (_item, SelectItemMode.Use); _menu.TurnOff (false); KickStarter.playerInteraction.ClickButton (InteractionType.Inventory, -2, _item.id, _menu.GetTargetHotspot ()); KickStarter.playerCursor.ResetSelectedCursor (); } } else { ACDebug.LogWarning ("Cannot handle inventory click since there is no active Hotspot."); } } else { ACDebug.LogWarning ("This type of InventoryBox only works with the Choose Hotspot Then Interaction method of interaction."); } } }
/** * <summary>Performs what should happen when the element is clicked on.</summary> * <param name = "_menu">The element's parent Menu</param> * <param name = "_slot">Ignored by this subclass</param> * <param name = "_mouseState">The state of the mouse button</param> */ public override void ProcessClick(AC.Menu _menu, int _slot, MouseState _mouseState) { if (KickStarter.stateHandler.gameState == GameState.Cutscene) { return; } base.ProcessClick (_menu, _slot, _mouseState); ShowClick (); if (buttonClickType == AC_ButtonClickType.TurnOffMenu) { _menu.TurnOff (doFade); } else if (buttonClickType == AC_ButtonClickType.Crossfade) { AC.Menu menuToSwitchTo = PlayerMenus.GetMenuWithName (switchMenuTitle); if (menuToSwitchTo != null) { KickStarter.playerMenus.CrossFade (menuToSwitchTo); } else { ACDebug.LogWarning ("Cannot find any menu of name '" + switchMenuTitle + "'"); } } else if (buttonClickType == AC_ButtonClickType.OffsetElementSlot) { if (elementToShift != null) { elementToShift.Shift (shiftInventory, shiftAmount); elementToShift.RecalculateSize (_menu.menuSource); _menu.Recalculate (); } else { ACDebug.LogWarning ("Cannot find '" + inventoryBoxTitle + "' inside '" + _menu.title + "'"); } } else if (buttonClickType == AC_ButtonClickType.OffsetJournal) { MenuJournal journalToShift = (MenuJournal) PlayerMenus.GetElementWithName (_menu.title, inventoryBoxTitle); if (journalToShift != null) { journalToShift.Shift (shiftInventory, loopJournal, shiftAmount); journalToShift.RecalculateSize (_menu.menuSource); _menu.Recalculate (); } else { ACDebug.LogWarning ("Cannot find '" + inventoryBoxTitle + "' inside '" + _menu.title + "'"); } } else if (buttonClickType == AC_ButtonClickType.RunActionList) { if (actionList) { AdvGame.RunActionListAsset (actionList, parameterID, parameterValue); } } else if (buttonClickType == AC_ButtonClickType.CustomScript) { MenuSystem.OnElementClick (_menu, this, _slot, (int) _mouseState); } else if (buttonClickType == AC_ButtonClickType.SimulateInput) { KickStarter.playerInput.SimulateInput (simulateInput, inputAxis, simulateValue); } }