private void Item_dragged(OxBase obj, Vector2 delta) { if (horizontal) { preDrag += -delta.x; } else { preDrag += -delta.y; } if (items.Count > itemsShown && (Mathf.Abs(preDrag) > dragDeadZone || dragging)) { dragging = true; SetItemsClickBlock(true); //AppearanceInfo dimensions = CurrentAppearanceInfo(); amountDragged = -delta.y; //float itemSize = (dimensions.centerHeight - (cushion * (itemsShown - 1))) / itemsShown; if (horizontal) { amountDragged += -delta.x; //itemSize = (dimensions.centerWidth - (cushion * (itemsShown - 1))) / itemsShown; } } }
protected void FireSelectionChangedEvent(OxBase item, bool selected) { if (selectionChanged != null) { selectionChanged(this, item, selected); } }
protected override void Item_clicked(OxBase obj) { if (!dragging) { base.Item_clicked(obj); } }
private void ScrubButton_dragged(OxBase obj, Vector2 delta) { AppearanceInfo dimensions = CurrentAppearanceInfo(); float scrubPosition = scrubButton.x, scrubSize = scrubButton.width, barSize = dimensions.centerWidth, changeInProgress = delta.x; if (!horizontal) { scrubPosition = scrubButton.y; scrubSize = scrubButton.height; barSize = dimensions.centerHeight; changeInProgress = delta.y; } float amountChanged = progress; if (scrubPosition + changeInProgress < 0) { progress = 0; } else if (scrubPosition + changeInProgress > barSize - scrubSize) { progress = 1; } else { progress = OxHelpers.TruncateTo((scrubPosition + changeInProgress) / (barSize - scrubSize), 3); } amountChanged = progress - amountChanged; if (amountChanged != 0) { FireScrollValueChangedEvent(amountChanged); } }
private void promptButton_clicked(OxBase obj) { if (obj == acceptButton && selectedItem != null) { FireSelectionDoneEvent(acceptButton.elementFunction); } else if (obj == cancelButton) { FireSelectionDoneEvent(cancelButton.elementFunction); } }
private void OxCheckbox_highlightedChanged(OxBase obj, bool onOff) { if (onOff) { checkbox.currentState = OxHelpers.ElementState.Highlighted; } else { checkbox.currentState = OxHelpers.ElementState.Normal; } }
private void DirectoryButton_clicked(OxBase obj) { if (!dragging && (!directorySelection || obj.isSelected)) { string nextDirectory = currentDirectory + obj.text; if (OxHelpers.CanBrowseDirectory(nextDirectory)) { currentDirectory = nextDirectory; } savedScroll.Add(scrollProgress); scrollProgress = 0; } }
private void TabButton_clicked(OxBase obj) { //if (!tabs.dragging) //{ OxBase tab = obj; if (!tab.isSelected) { selectedIndex = tabs.IndexOf(tab); } //else // selectedIndex = -1; //} }
private void BackButton_clicked(OxBase obj) { if (!dragging) { currentDirectory = OxHelpers.ParentPath(currentDirectory); if (savedScroll.Count > 0) { scrollProgress = savedScroll[savedScroll.Count - 1]; savedScroll.RemoveAt(savedScroll.Count - 1); } else { scrollProgress = 0; } } }
public void SelectItem(OxBase item) { if (item != null && items.IndexOf(item) > -1) { if (enableMultiSelect) { if (item.isSelected) { selectedItems.Remove(item); } else { selectedItems.Add(item); } item.Select(!item.isSelected); FireSelectionChangedEvent(item, item.isSelected); } else { for (int i = selectedItems.Count - 1; i >= 0; i--) { if (selectedItems[i] != item) { selectedItems[i].Select(false); FireSelectionChangedEvent(selectedItems[i], false); selectedItems.RemoveAt(i); } } if (selectedItems.IndexOf(item) > -1 && !deselectionDisabled) { selectedItems.Remove(item); item.Select(false); FireSelectionChangedEvent(item, false); } else { selectedItems.Add(item); if (enableItemSelection) { item.Select(true); } FireSelectionChangedEvent(item, true); } } } }
public static void ApplyAppearanceFromResources(OxBase element, string location, bool normal = true, bool over = true, bool down = true) { string adjustedLocation = location.Replace("\\", "/"); if (adjustedLocation.LastIndexOf("/") < adjustedLocation.Length - 1) { adjustedLocation += "/"; } for (int i = 0; i < 3; i++) { if ((i == 0 && normal) || (i == 1 && over) || (i == 2 && down)) { bool nulled = false; Texture2D[] loadedTextures = new Texture2D[textureLocationTypes.Length]; for (int j = 0; j < textureLocationTypes.Length; j++) { string textureStateType = "Normal/"; if (i == 1) { textureStateType = "Over/"; } else if (i == 2) { textureStateType = "Down/"; } loadedTextures[j] = Resources.Load <Texture2D>(adjustedLocation + textureStateType + textureLocationTypes[j]); if (loadedTextures[j] == null) { Debug.Log("Assets/Resources/" + adjustedLocation + textureStateType + textureLocationTypes[j] + " does not exist"); nulled = true; break; } } if (!nulled) { element.AddAppearance(((OxHelpers.ElementState)i), loadedTextures); } } } }
public virtual int IndexOf(OxBase item) { return(items.IndexOf(item)); }
private void OxCheckbox_clicked(OxBase obj) { checkbox.currentState = OxHelpers.ElementState.Highlighted; checkboxChecked = !checkboxChecked; FireCheckboxSwitchedEvent(checkboxChecked); }
protected override void DrawContainedItems() { Rect group = new Rect(x, y, width, height); float xPos = 0, yPos = 0, drawWidth = width, drawHeight = height; GUI.BeginGroup(group); #region Tabs tabs.parentInfo.group = group; tabs.horizontal = !verticalTabs; if (verticalTabs) { tabs.switchScrollbarSide = !switchTabsSide; } else { tabs.switchScrollbarSide = switchTabsSide; } if (switchTabsScrollbarSide) { tabs.switchScrollbarSide = !tabs.switchScrollbarSide; } if (verticalTabs) { drawWidth *= tabPercentSize; if (switchTabsSide) { xPos = width - drawWidth; } } else { drawHeight *= tabPercentSize; if (switchTabsSide) { yPos = height - drawHeight; } } tabs.x = Mathf.RoundToInt(xPos); tabs.y = Mathf.RoundToInt(yPos); tabs.width = Mathf.RoundToInt(drawWidth); tabs.height = Mathf.RoundToInt(drawHeight); tabs.Draw(); #endregion #region Panel OxBase item = null; if (selectedIndex > -1 && selectedIndex < items.Count) { item = items[selectedIndex]; } if (item != null) { item.parentInfo.group = group; Rect tabPanelDimensions = CalculateTabPanelDimensions(); item.position = new Vector2(tabPanelDimensions.x, tabPanelDimensions.y); item.size = new Vector2(tabPanelDimensions.width, tabPanelDimensions.height); //Debug.Log("Drawing: " + selectedIndex); item.Draw(); } #endregion GUI.EndGroup(); }
public ParentInfo(OxBase parent) : this(parent, new Rect()) { }
private void OxCheckbox_pressed(OxBase obj) { checkbox.currentState = OxHelpers.ElementState.Down; }
private void Item_released(OxBase obj) { preDrag = 0; dragging = false; SetItemsClickBlock(false); }
public ParentInfo(OxBase parent, Rect group) { this.parent = parent; this.group = group; }
private void ContainerButton_dragged(OxBase obj, Vector2 delta) { if (obj is OxBase) { if (obj.elementFunction == OxHelpers.ElementType.Position_Changer) { Reposition(position + delta); } else if (obj.elementFunction == OxHelpers.ElementType.Size_Changer) { if (obj == containerButtons[((int)OxHelpers.Alignment.Right)]) { Resize(new Vector2(width + delta.x, height)); } if (obj == containerButtons[((int)OxHelpers.Alignment.Bottom)]) { Resize(new Vector2(width, height + delta.y)); } if (obj == containerButtons[((int)OxHelpers.Alignment.Bottom_Right)]) { Resize(size + delta); } if (obj == containerButtons[((int)OxHelpers.Alignment.Top_Right)]) { Reposition(new Vector2(x, y + delta.y)); Resize(new Vector2(width + delta.x, height - delta.y)); //MoveContainedItems(new Vector2(0, delta.y)); DeepMove(this, new Vector2(0, delta.y)); } if (obj == containerButtons[((int)OxHelpers.Alignment.Bottom_Left)]) { Reposition(new Vector2(x + delta.x, y)); Resize(new Vector2(width - delta.x, height + delta.y)); //MoveContainedItems(new Vector2(delta.x, 0)); DeepMove(this, new Vector2(delta.x, 0)); } if (obj == containerButtons[((int)OxHelpers.Alignment.Left)]) { Reposition(new Vector2(x + delta.x, y)); Resize(new Vector2(width - delta.x, height)); //MoveContainedItems(new Vector2(delta.x, 0)); DeepMove(this, new Vector2(delta.x, 0)); } if (obj == containerButtons[((int)OxHelpers.Alignment.Top)]) { Reposition(new Vector2(x, y + delta.y)); Resize(new Vector2(width, height - delta.y)); //MoveContainedItems(new Vector2(0, delta.y)); DeepMove(this, new Vector2(0, delta.y)); } if (obj == containerButtons[((int)OxHelpers.Alignment.Top_Left)]) { Reposition(position + delta); Resize(size - delta); //MoveContainedItems(delta); DeepMove(this, delta); } } } }
protected virtual void Item_clicked(OxBase obj) { SelectItem(obj); }
private void OxPanel_moved(OxBase obj, Vector2 delta) { //MoveContainedItems(delta); }
private void OxPanel_resized(OxBase obj, Vector2 delta) { ResizeContainedItems(delta); }
private static void InteractionSystem() { //if (currentIndex == 1) //{ //string activeElementsString = ""; //foreach(OxBase someElement in activeElements) //{ // if(!(someElement is OxButton)) activeElementsString += someElement.GetType().Name + ", "; //} //Debug.Log(activeElements.Count + ": " + activeElementsString); for (int i = activeElements.Count - 1; i >= currentIndex; i--) { if (activeElements[i] == null || activeElements[i].currentAlteration != alternator) { activeElements.RemoveAt(i); } } Vector2 mousePosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); for (int i = 0; i < activeElements.Count; i++) { OxBase element = activeElements[i]; if (element != null && element.enabled) { if (mousePosition.x > (element.absoluteX) && mousePosition.x < (element.absoluteX + element.width) && mousePosition.y > (element.absoluteY) && mousePosition.y < (element.absoluteY + element.height)) { if (!element.mouseIsOver && currentlyHighlighted == null) { element.FireMouseOverEvent(); element.mouseIsOver = true; element.Highlight(true); } } else { if (element.mouseIsOver) { element.FireMouseLeaveEvent(); element.mouseIsOver = false; element.Highlight(false); } } if (Input.GetMouseButton(0)) { if (element.mouseIsOver && !element.mouseIsDown && currentlyPressed == null) { element.FireMouseDownEvent(); element.mouseIsDown = true; element.Press(); } } else { if (element.mouseIsDown) { element.FireMouseUpEvent(); element.mouseIsDown = false; if (element.mouseIsOver && !element.blockClick) { element.Click(); } element.Release(); } } if (element.mouseIsOver && currentlyHighlighted == null) { currentlyHighlighted = element; } //else if (!element.mouseIsOver && currentlyHighlighted == element) currentlyHighlighted = null; if (element.mouseIsDown && currentlyPressed == null) { currentlyPressed = element; } if (currentlyPressed != null && (!currentlyPressed.mouseIsDown || activeElements.IndexOf(currentlyPressed) < 0)) { currentlyPressed = null; } //else if (!element.mouseIsDown && currentlyPressed == element) currentlyPressed = null; //if (activeElements.IndexOf(currentlyPressed) < 0) currentlyPressed = null; //if (currentlyPressed != null) Debug.Log("Pressed: " + currentlyPressed.text); //if (currentlyHighlighted != null) Debug.Log("Highlighted: " + currentlyHighlighted.text); if (Vector2.Distance(prevMousePosition, mousePosition) > 0) { element.FireMouseMovedEvent(mousePosition - prevMousePosition); if (element == currentlyPressed) { element.FireDraggedEvent(mousePosition - prevMousePosition); } } if (element.isSelected) { element.currentState = OxHelpers.ElementState.Highlighted; } } } currentlyHighlighted = null; //currentlyPressed = null; prevMousePosition = mousePosition; //} }