protected override void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input, int panelIndex) { if (input.x == settings.submitAction) { if (data != null) { int buttonSelect = (int)data[0]; if (buttonSelect < 4) { bool origValue = (bool)data[1]; switch (buttonSelect) { case 0: UIManager.uiSettings.showCrosshair = !origValue; break; case 1: UIManager.uiSettings.showCompass = !origValue; break; case 2: UIManager.uiSettings.showSubtitles = !origValue; break; case 3: UIManager.uiSettings.showMiniMap = !origValue; break; } UpdateUIButtons(panelIndex);//, false); SaveLoad.SaveSettingsOptions(); } else { OnChangeColor(buttonSelect - 4); } } } }
static void MakeButton(UISelectable element, string text, object[] data) { element.uiText.SetText(text);//, -1); element.data = data; element.EnableFlair(0, false); element.EnableFlair(1, false); }
// public string fullTradeMenuName = "FullTradeMenu"; // [Action] public int singleTradeAction = 0, tradeAllAction = 1, switchToFullTradeAction = 2; // protected override void GetActionsAndHints (out List<int> actions, out List<string> hints) { // actions = GetActions(); // hints = new List<string>() { "Take", "Take All", "Trade" }; // } // protected override List<int> GetActions () { // return new List<int> () { singleTradeAction, tradeAllAction, switchToFullTradeAction }; // } protected override void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input, int panelIndex) { bool updateButtons = false; // single trade // if (input.x == singleTradeAction){ // if (data != null) { // InventorySlot item = data[0] as InventorySlot; // if (item != null) { // showingInventory.TransferItemAlreadyInInventoryTo(item, item.count, takingInventory, sendMessage: false); // updateButtons = true; // } // } // } // // take all // else if (input.x == tradeAllAction){ // // TODO: check if shown inventory has anything // showingInventory.TransferInventoryContentsTo(takingInventory, sendMessage: false); // updateButtons = true; // } // else if (input.x == switchToFullTradeAction){ // manualMenu.CloseMenu(); // //maybe use update mananger.... // StartCoroutine(OpenFullTrade()); // } if (updateButtons) { UpdateUIButtons(panelIndex);//, true); } }
// bool isCollection { get { return (uiObject as UIWithInputCollection) != null; } } // bool usesRadial { get { return (uiObject as UIRadial) != null; } } // bool isPaginated { get { return !usesRadial && MaxButtons() > 0; } } void OnEnable() { // defaultActions = new List<int> () { settings.submitAction }; // defaultHints = new List<string> () { "Select" }; int maxUIPanels = 1; UIWithInputCollection collection; if (IsCollection(out collection)) { maxUIPanels = collection.subHolders.Length; } buttonReferences = new UISelectable[maxUIPanels][]; paginatedOffsets = new int[maxUIPanels]; lastElementsShownCount = new int[maxUIPanels]; BuildActionsAndHints(out pageActions, out pageActionHints); if (allowCancel) { pageActions.Add(settings.cancelAction); pageActionHints.Add("Cancel/Back"); } }
UISelectable GetCurrentSelectedData(out object[] data) { data = null; GameObject currentSelected = UIManager.CurrentSelected(); if (currentSelected == null) { return(null); } if (!CurrentSelectedIsOurs(currentSelected)) { Debug.LogError("Getting Input for" + name + " but current selected isnt part of our set, " + currentSelected.name); return(null); } UISelectable currentSelectedCheck = currentSelected.GetComponent <UISelectable>(); if (currentSelectedCheck == null) { return(null); } data = currentSelectedCheck.data; return(currentSelectedCheck); }
public override void UpdateElementLayout() //bool firstBuild) { { rectTransform.sizeDelta = Vector2.one * parameters.panelSize; float sliceAngle = 360.0f / Mathf.Max(showElements.Count, 1); float radialAmount = 1f / Mathf.Max(showElements.Count, 1); Quaternion radialAngleRotation = Quaternion.Euler(0, 0, sliceAngle * .5f); float textHeight = 0; for (int i = 0; i < showElements.Count; i++) { float elementAngle = -i * sliceAngle; UISelectable element = showElements[i]; UIBaseParameters.CopyParameters(ref (element as UIRadialSelectable).parameters, parameters.selectableParams); element.transform.localRotation = Quaternion.Euler(0, 0, elementAngle); element.image.mainGraphic.fillAmount = radialAmount; element.image.mainGraphic.rectTransform.localRotation = radialAngleRotation; element.uiText.transform.localRotation = Quaternion.Euler(0, 0, -elementAngle); if (elementAngle == 0 || elementAngle == -180) { element.uiText.SetAnchor(TextAnchor.MiddleCenter, false, Vector2.zero); } else { element.uiText.SetAnchor(elementAngle < -180f ? TextAnchor.MiddleRight : TextAnchor.MiddleLeft, false, Vector2.zero); } // Vector2 elementTextSize = element.UpdateElementLayout();//firstBuild); if (i == 0) { textHeight = (element as UIRadialSelectable).textHeight; //elementTextSize.y; } } UIBaseParameters.CopyParameters(ref panel.parameters, parameters.panelParams); panel.UpdateElementLayout(); //firstBuild); float h = textHeight; //allElements.Count == 0 ? 0 : allElements[0].uiText.getHeight; actionHintsPanel.transform.localPosition = new Vector3(0, -(parameters.panelSize * .5f + (h) + parameters.hintsSpace), 0); UIBaseParameters.CopyParameters(ref actionHintsPanel.parameters, parameters.controlHintsParams); actionHintsPanel.UpdateElementLayout();//firstBuild); // return Vector2.zero; }
protected override void SetFlairs(UISelectable element, ManualMenuButton button, int panelIndex) { int slotSelect = (int)button.data[0]; if (SaveLoad.SaveExists(slotSelect)) { element.EnableFlair(0, true); } }
protected override void SetFlairs(UISelectable element, ManualMenuButton button, int panelIndex) { int buttonSelect = (int)button.data[0]; if (buttonSelect < 4) { element.EnableFlair(0, (bool)button.data[1]); } }
protected override void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input, int panelIndex) { if (input.x == settings.submitAction) { if (data != null) { int slotSelect = (int)data[0]; LoadGame(slotSelect); } } }
public void BroadcastSelectEvent(UISelectable buttonObject, object[] data) { if ((object)parent != null) { parent.BroadcastSelectEvent(buttonObject, data); return; } if (_onSelect != null) { _onSelect(buttonObject, data); } }
void MakeButton(UISelectable element, string text, ManualMenuButton button, int panelIndex, object[] data, bool enableFlairs) { element.uiText.SetText(text); element.data = data; element.EnableFlair(0, false); element.EnableFlair(1, false); if (enableFlairs) { SetFlairs(element, button, panelIndex); } }
protected override void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input, int panelIndex) { if (input.x == settings.submitAction) { manualMenu.CloseMenu(); if (data != null) { // InventorySlot item = data[0] as InventorySlot; // if (item != null) item.item.OnConsume(showingInventory, count: 1, input.y); } } }
public void BroadcastActionEvent(UISelectable selected, object[] data, Vector2Int submit) { // Debug.Log("Boradcast action" + name); if ((object)parent != null) { parent.BroadcastActionEvent(selected, data, submit); return; } if (_onAction != null) { _onAction(selected, data, submit); } }
public void DoAction(Vector2Int action) { if (parent != null) { parent.DoAction(action); return; } object[] data; UISelectable selected = GetCurrentSelectedData(out data); BroadcastActionEvent(selected, data, action); }
public virtual void OnUISelect(UISelectable selectedObject, object[] data) { if (uiObject.textPanel != null) { if (data != null) { ManualMenuButton menuButton = data[0] as ManualMenuButton; if (menuButton != null) { uiObject.SetPanelText(menuButton.displayDescription); } // uiObject.textPanel.SetTexts(string.Empty, menuButton.displayDescription, true); // uiObject.textPanel.mainText.SetText(menuButton.displayDescription); } } }
static void OnSliderSubmit(UISelectable selectedObject, object[] data, Vector2Int input) { if (input.x == settings.cancelAction) { OnCancelSliderUI(); return; } else if (input.x == settings.submitAction) { HidePopup(sliderPopup);//UISliderPopup.instance); if (sliderReturnCallback != null) { sliderReturnCallback(true, (int)sliderPopup.sliderValue); } } }
protected override void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input, int panelIndex) { if (input.x == settings.submitAction) { if (data != null) { int methodSelect = (int)data[0]; if (methodSelect == 0) { OnStartNewGame(); } else if (methodSelect == 1) { OnQuitGame(); } } } }
public virtual void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input) { if (input.x == settings.submitAction) { Debug.LogError("PRESSED SUBMIT"); if (actionsShowing) { uiVideoPlayer.Stop(); } else { ShowActionHints(); } // if action hints panel showing, stop movie // else fade in action hints panel } }
static void OnSelectionSubmit(UISelectable selectedObject, object[] data, Vector2Int input) { if (input.x == settings.cancelAction) { OnCancelSelectionUI(); return; } else if (input.x == settings.submitAction) { HidePopup(selectionPopup);//.instance); if (selectionReturnCallback != null) { selectionReturnCallback(true, (int)data[0]); // not setting to null because callback might bring up another popup... // selectionReturnCallback = null; } } }
public virtual void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input) { if (allowCancel) { if (input.x == settings.cancelAction) { // Debug.Log("GOINGBAKC"); manualMenu.GoToPage(backPage); return; } } if (data != null) { ManualMenuButton menuButton = data[0] as ManualMenuButton; if (menuButton != null) { if (input.x == settings.submitAction) { if (menuButton.goToPage != null) { // Debug.Log("GOING TO PAGE"); menuButton.goToPage.backPage = this; manualMenu.GoToPage(menuButton.goToPage); } else { if (!string.IsNullOrEmpty(menuButton.callStaticMethod)) { SystemTools.CallStaticMethodSimple(menuButton.callStaticMethod); } } } int panelIndex = (int)data[1]; OnUIInput(selectedObject, menuButton.data, input, panelIndex); } } }
UISelectable GetAvailableSelectable() { UISelectable s = selectablePool.GetAvailable(ElementPrefab(), null, false, null); s.selected = false; s.parentUI = this; // s.transform.SetParent(transform); s.transform.SetParent(transform, Vector3.zero, Quaternion.identity, Vector3.one); Button button = s.button;//.GetComponent<Button>(); if (button) { Navigation customNav = button.navigation; customNav.mode = Navigation.Mode.Automatic;// : Navigation.Mode.None; // customNav.mode = active ? Navigation.Mode.Horizontal : Navigation.Mode.None; button.navigation = customNav; } s.gameObject.SetActive(true); return(s); }
// just debugging.... public UISelectable AddNewElement(string elementText, bool updateHolder) { // if (isHoldersCollection) return null; UISelectable newElement = Instantiate(ElementPrefab()); newElement.parentUI = this; newElement.transform.SetParent(transform, Vector3.zero, Quaternion.identity, Vector3.one); // newElement.transform.localPosition = Vector3.zero; // newElement.transform.localRotation = Quaternion.identity; // newElement.transform.localScale = Vector3.one; // allElements.Add(newElement); showElements.Add(newElement); newElement.uiText.SetText(elementText); //, -1); if (updateHolder) { // Debug.Log("Updating after Add"); UpdateElementLayout();//true, true);// UpdateSelectableElementHolder(); } return(newElement); }
protected override void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input, int panelIndex) { }
protected override void SetFlairs(UISelectable element, ManualMenuButton button, int panelIndex) { }
static void OnSliderChange(UISelectable selected, object[] data) { float value = (float)data[0]; sliderChangeCallback((int)value); }
// ManualMenuButtonBuilder[] _buttonBuilders; // ManualMenuButtonBuilder[] buttonBuilders { get { return gameObject.GetComponentsIfNull<ManualMenuButtonBuilder>(ref _buttonBuilders); } } // handle paginated scrolling void OnPaginatedUISelect(UISelectable selectedObject, object[] data) { if (data != null) { string buttonSelectText = data[0] as string; if (buttonSelectText != null) { int panelIndex = (int)data[1]; bool updateButtons = false; UISelectable newSelection = null; // hovered over the page up button if (buttonSelectText == "B") { paginatedOffsets[panelIndex]--; if (paginatedOffsets[panelIndex] != 0) { newSelection = buttonReferences[panelIndex][1]; } if (paginatedOffsets[panelIndex] == 1) { paginatedOffsets[panelIndex]--; } updateButtons = true; } // hovered over the page down button else if (buttonSelectText == "F") { paginatedOffsets[panelIndex]++; // bool isAtEnd = paginatedOffsets[panelIndex] >= lastElementsShownCount[panelIndex] - MaxButtons(); // bool isAtEnd = paginatedOffsets[panelIndex] + (MaxButtons() - (paginatedOffsets[panelIndex] != 0 ? 2 : 0)) >= ((lastElementsShownCount[panelIndex])); bool isAtEnd = paginatedOffsets[panelIndex] + (MaxButtons() - (1)) >= ((lastElementsShownCount[panelIndex])); if (!isAtEnd) { newSelection = buttonReferences[panelIndex][MaxButtons() - 2]; paginatedOffsets[panelIndex]++; } updateButtons = true; } if (updateButtons) { UpdateUIButtons(panelIndex); //, false ); if (newSelection != null) { UIManager.SetSelectionDelayed(newSelection.gameObject); } } } } }
protected abstract void OnUIInput(UISelectable selectedObject, object[] data, Vector2Int input, int panelIndex);
// protected override void OnDisable () { // base.OnDisable(); // // Debug.LogError("setting selected false"); // for (int i =0 ; i < allElements.Count; i++) allElements[i].selected = false; // } public UISelectable[] GetAllSelectableElements(int targetCount, bool updateLayout) { // if (isHoldersCollection) return null; int c = showElements.Count; if (c < targetCount) { // for (int i = 0 ; i < c; i++) { // if (!shownElements[i].gameObject.activeSelf) // shownElements[i].gameObject.SetActive(true); // } int cnt = targetCount - c; for (int i = 0; i < cnt; i++) { // if (allElements.Count > 0) { // UISelectable s = allElements[0]; // allElements.Remove(s); // showElements.Add(s); // s.gameObject.SetActive(true); // } // else { showElements.Add(GetAvailableSelectable()); // AddNewElement("Adding new", updateLayout && i == (cnt - 1)); // } } // UpdateElementLayout();//true, true);// UpdateSelectableElementHolder(); } else if (c > targetCount) { // for (int i =0 ; i < targetCount; i++) { // if (!shownElements[i].gameObject.activeSelf) // shownElements[i].gameObject.SetActive(true); // } for (int i = c - 1; i >= targetCount; i--) // targetCount; i < c; i++) { { UISelectable s = showElements[i]; s.gameObject.SetActive(false); showElements.Remove(s); // allElements.Add(s); // if (shownElements[i].gameObject.activeSelf) // shownElements[i].gameObject.SetActive(false); s.transform.SetParent(UIMainCanvas.instance.transform); // shownElements.Remove(shownElements[i]); } // WiggleActive(); // List<UISelectable> r = new List<UISelectable>(); // for (int i = 0; i < targetCount; i++) { // r.Add(shownElements[i]); // } // UpdateElementLayout();//true, true);// UpdateSelectableElementHolder(); // return shownElements.ToArray();// // return r.ToArray(); } UpdateElementLayout(); // SetSelectablesActive(true); // WiggleActive(); return(showElements.ToArray()); }
protected abstract void SetFlairs(UISelectable element, ManualMenuButton button, int panelIndex);