public void SelectWithName(string name) { CircuitPart cp = null; switch (name) { case "Bullet": cp = ListOfTurrets[0]; break; case "Explosive": cp = ListOfTurrets[1]; break; case "Shield": cp = ListOfTurrets[2]; break; case "Bullet2": cp = ListOfTurrets[3]; break; case "Explosive2": cp = ListOfTurrets[4]; break; case "Shield2": cp = ListOfTurrets[5]; break; case "Wire": cp = ListOfWires[0]; break; case "Wire2": cp = ListOfWires[1]; break; case "Battery": cp = ListOfBatteries[0]; break; case "Battery2": cp = ListOfBatteries[1]; break; default: break; } cp.visual.transform.position = selectedCircuitPart.visual.transform.position; selectedCircuitPart.gameObject.SetActive(false); selectedCircuitPart = cp; selectedCircuitPart.gameObject.SetActive(true); targetToMove = selectedCircuitPart.target.gameObject; }
public void GoToNext(CircuitPart next) { previousPart = nextPart; cachePath.Add(previousPart); nextPart = next; if (nextPart && !nextPart._To.Any()) { nextPart.NeighbourAction(); } }
void ChangeSelectedItemType() { int index = (int)selectedItemType; int listSize = Enum.GetNames(typeof(ItemType)).Length; if (inputManager.ShiftMouseScroll < 0f) //move left { index--; } if (inputManager.ShiftMouseScroll > 0f) //move right { index++; } if (index >= listSize) { index = 0; } if (index < 0) { index = listSize - 1; } selectedItemType = (ItemType)index; CircuitPart nextSelected = null; switch (selectedItemType) { case ItemType.TURRETS: nextSelected = ListOfTurrets[0]; break; case ItemType.WIRES: nextSelected = ListOfWires[0]; break; case ItemType.BATTERIES: nextSelected = ListOfBatteries[0]; break; default: break; } nextSelected.visual.transform.position = selectedCircuitPart.visual.transform.position; selectedCircuitPart.gameObject.SetActive(false); selectedCircuitPart = nextSelected; selectedCircuitPart.gameObject.SetActive(true); targetToMove = selectedCircuitPart.transform.Find("Target").gameObject; }
private void DragTop(double scale, CircuitPart item, SelectionService selectionService) { IEnumerable <CircuitPart> groupItems = selectionService.GetGroupMembers(item).Cast <CircuitPart>(); double groupBottom = Canvas.GetTop(item) + item.Height; foreach (CircuitPart groupItem in groupItems) { double groupItemTop = Canvas.GetTop(groupItem); double delta = (groupBottom - groupItemTop) * (scale - 1); Canvas.SetTop(groupItem, groupItemTop - delta); groupItem.Height = groupItem.ActualHeight * scale; } }
public static CircuitPart GetBlankPartOfType(CircuitPartTypes type) { CircuitPart part = new CircuitPart(); switch (type) { case CircuitPartTypes.PowerGenerator1: part.name = "Power Generator 1"; part.type = CircuitPartTypes.PowerGenerator1; part.prefab = xa.pp.Get(CircuitPartTypes.PowerGenerator1); part.outPower = new Vector2[1]; part.outPower[0] = new Vector2(0, 2); part.stats.Add(Stat.IsPowerSource, (object)true); part.stats.Add(Stat.PowerGenerated, (object)10f); break; case CircuitPartTypes.Button: part.name = "Button"; part.type = CircuitPartTypes.Button; part.prefab = xa.pp.Get(CircuitPartTypes.Button); part.inPower = new Vector2[1]; part.inPower[0] = new Vector2(0, -2); part.outPower = new Vector2[1]; part.outPower[0] = new Vector2(0, 2); break; case CircuitPartTypes.BulletFabricator: part.name = "Bullet Fabricator"; part.type = CircuitPartTypes.BulletFabricator; part.prefab = xa.pp.Get(CircuitPartTypes.BulletFabricator); part.inPower = new Vector2[1]; part.inPower[0] = new Vector2(0, -2); break; case CircuitPartTypes.Battery: part.name = "Battery"; part.type = CircuitPartTypes.Battery; part.prefab = xa.pp.Get(CircuitPartTypes.Battery); part.stats.Add(Stat.IsPowerSource, (object)true); part.stats.Add(Stat.PowerStored, (object)0f); break; case CircuitPartTypes.Wire: part.name = "Wire"; part.type = CircuitPartTypes.Wire; part.prefab = xa.pp.Get(CircuitPartTypes.Wire); part.inPower = new Vector2[1]; part.inPower[0] = new Vector2(0, 0); break; } return part; }
private void DragLeft(double scale, CircuitPart item, SelectionService selectionService) { IEnumerable <CircuitPart> groupItems = selectionService.GetGroupMembers(item).Cast <CircuitPart>(); double groupLeft = Canvas.GetLeft(item) + item.Width; foreach (CircuitPart groupItem in groupItems) { double groupItemLeft = Canvas.GetLeft(groupItem); double delta = (groupLeft - groupItemLeft) * (scale - 1); Canvas.SetLeft(groupItem, groupItemLeft - delta); groupItem.Width = groupItem.ActualWidth * scale; } }
void PlacePart() { Vector3 snapArea = selectedCircuitPart.snapArea; if (selectedCircuitPart.m_gridSystem.CheckFreeSpace(snapArea) && money.Value - selectedCircuitPart.Cost >= 0) { money.Value -= selectedCircuitPart.Cost; CircuitPart placedCircuitPart = Instantiate(selectedCircuitPart.prefab, Vector3.zero, Quaternion.identity).GetComponent <CircuitPart> (); placedCircuitPart.visual.transform.position = snapArea; placedCircuitPart.snapArea = snapArea; placedCircuitPart.isPlaced = true; placedCircuitPart.target.gameObject.SetActive(false); placedCircuitPart.AddSelfToGridSystem(); } }
void DragThumb_DragDelta(object sender, DragDeltaEventArgs e) { CircuitPart circuitPart = this.DataContext as CircuitPart; DesignerCanvas designer = VisualTreeHelper.GetParent(circuitPart) as DesignerCanvas; if (circuitPart != null && designer != null && circuitPart.IsSelected) { double minLeft = double.MaxValue; double minTop = double.MaxValue; // we only move CircuitPart var circuitParts = designer.SelectionService.CurrentSelection.OfType <CircuitPart>(); foreach (CircuitPart item in circuitParts) { double left = Canvas.GetLeft(item); double top = Canvas.GetTop(item); minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft); minTop = double.IsNaN(top) ? 0 : Math.Min(top, minTop); } double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange); double deltaVertical = Math.Max(-minTop, e.VerticalChange); foreach (CircuitPart item in circuitParts) { double left = Canvas.GetLeft(item); double top = Canvas.GetTop(item); if (double.IsNaN(left)) { left = 0; } if (double.IsNaN(top)) { top = 0; } Canvas.SetLeft(item, left + deltaHorizontal); Canvas.SetTop(item, top + deltaVertical); } designer.InvalidateMeasure(); e.Handled = true; } }
void ChangeSelectedPart(ItemType itemType) { int index = 0; int listSize = 0; switch (itemType) { case ItemType.TURRETS: index = ListOfTurrets.IndexOf((Buildings)selectedCircuitPart); listSize = ListOfTurrets.Count; break; case ItemType.WIRES: index = ListOfWires.IndexOf((Wire)selectedCircuitPart); listSize = ListOfWires.Count; break; case ItemType.BATTERIES: index = ListOfBatteries.IndexOf((Battery)selectedCircuitPart); listSize = ListOfWires.Count; break; default: break; } if (inputManager.MouseScroll < 0) //move left { index--; } if (inputManager.MouseScroll > 0) //move right { index++; } if (index >= listSize) { index = 0; } if (index < 0) { index = listSize - 1; } CircuitPart nextSelected = null; switch (itemType) { case ItemType.TURRETS: nextSelected = ListOfTurrets[index]; break; case ItemType.WIRES: nextSelected = ListOfWires[index]; break; case ItemType.BATTERIES: nextSelected = ListOfBatteries[index]; break; default: break; } nextSelected.visual.transform.position = selectedCircuitPart.visual.transform.position; selectedCircuitPart.gameObject.SetActive(false); selectedCircuitPart = nextSelected; selectedCircuitPart.gameObject.SetActive(true); targetToMove = selectedCircuitPart.target.gameObject; }
void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e) { CircuitPart circuitPart = this.DataContext as CircuitPart; DesignerCanvas designer = VisualTreeHelper.GetParent(circuitPart) as DesignerCanvas; if (circuitPart != null && designer != null && circuitPart.IsSelected) { double minLeft, minTop, minDeltaHorizontal, minDeltaVertical; double dragDeltaVertical, dragDeltaHorizontal, scale; IEnumerable <CircuitPart> selectedCircuitParts = designer.SelectionService.CurrentSelection.OfType <CircuitPart>(); CalculateDragLimits(selectedCircuitParts, out minLeft, out minTop, out minDeltaHorizontal, out minDeltaVertical); foreach (CircuitPart item in selectedCircuitParts) { if (item != null && item.ParentID == Guid.Empty) { switch (base.VerticalAlignment) { case VerticalAlignment.Bottom: dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical); scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight; DragBottom(scale, item, designer.SelectionService); break; case VerticalAlignment.Top: double top = Canvas.GetTop(item); dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical); scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight; DragTop(scale, item, designer.SelectionService); break; default: break; } switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: double left = Canvas.GetLeft(item); dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal); scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth; DragLeft(scale, item, designer.SelectionService); break; case HorizontalAlignment.Right: dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal); scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth; DragRight(scale, item, designer.SelectionService); break; default: break; } } } e.Handled = true; } }