public override void Load(params object[] data) { ElementTypeInfo armyType = ArmyTypes[Toggle.ActiveIndex]; ListUpgrade type = armyType.BaseType; // sv data int mainbaseLv = SyncData.CurrentBaseUpgrade[ListUpgrade.MainBase].Level; int selTypeLv = SyncData.CurrentBaseUpgrade[type].Level; for (int i = 0, level = 0; i < armyType.Types.Length; i++) { level = SyncData.CurrentBaseUpgrade[armyType.Types[i]].Level; elements[i].Icon.InteractableChange(level > 0); elements[i].LevelBar.Value = level; elements[i].LevelBar.SetDefaultPlaceholder(); } // check active or not for upgrade btn upgradeBtn.InteractableChange(mainbaseLv > selTypeLv); // set level bar value and rename element btn levelBar.Value = selTypeLv; levelBar.SetDefaultPlaceholder(); for (int i = 0; i < armyType.Types.Length; i++) { elements[i].Icon.Placeholder.text = armyType.Titles[i]; } }
private void DrawGroupPinNodeFakeEdge(ICircuitGroupPin <TElement> grpPin, PointF grpPinPos, bool inputSide, DiagramDrawingStyle style, D2dGraphics g) { ElementTypeInfo info = GetElementTypeInfo(grpPin.InternalElement, g); if (inputSide) { PointF op = grpPinPos; float x1 = op.X + CircuitGroupPinInfo.FloatingPinBoxWidth; float y1 = op.Y + CircuitGroupPinInfo.FloatingPinBoxHeight / 2; Point ip = grpPin.InternalElement.Bounds.Location; float x2 = ip.X; float y2 = ip.Y + GetPinOffset(grpPin.InternalElement, grpPin.InternalPinIndex, true); DrawWire(g, m_fakeInputLinkPen, x1, y1, x2, y2, 1.0f, m_VirtualLinkStrokeStyle); } else { Point op = grpPin.InternalElement.Bounds.Location; float x1 = op.X + info.Size.Width; float y1 = op.Y + GetPinOffset(grpPin.InternalElement, grpPin.InternalPinIndex, false); PointF ip = grpPinPos; float x2 = ip.X; float y2 = ip.Y + CircuitGroupPinInfo.FloatingPinBoxHeight / 2; DrawWire(g, m_fakeOutputLinkPen, x1, y1, x2, y2, 1.0f, m_VirtualLinkStrokeStyle); } }
/// <summary> /// Find output pin, if any, at given point</summary> /// <param name="element">Element</param> /// <param name="g">Graphics object</param> /// <param name="p">Point to test</param> /// <returns>Output pin hit by p; null otherwise</returns> private TPin PickOutput(TElement element, Graphics g, Point p) { ElementTypeInfo info = GetElementTypeInfo(element, g); Point ep = element.Bounds.Location; int x = ep.X + info.Size.Width - m_pinSize; int y = ep.Y + m_rowSpacing + 2 * PinMargin + m_pinOffset; int width = m_pinSize; Rectangle bounds = new Rectangle(x, y, width, m_pinSize); int pickTolerance = m_theme.PickTolerance; bounds.Inflate(pickTolerance, pickTolerance); ICircuitElementType type = element.Type; foreach (TPin output in type.Outputs) { if (bounds.Contains(p.X, p.Y)) { return(output); } bounds.Y += m_rowSpacing; } return(null); }
private void DrawWire( TElement element, TPin pin, Point p, bool fromOutput, Graphics g) { ElementTypeInfo info = GetElementTypeInfo(element, g); Point ep = element.Bounds.Location; int x = ep.X; int y = ep.Y + GetPinOffset(pin.Index); if (fromOutput) { x += info.Size.Width; } Matrix inverse = g.Transform; inverse.Invert(); Point end = GdiUtil.Transform(inverse, p); Pen pen = GetPen(pin); if (fromOutput) { DrawWire(g, pen, x, y, end.X, end.Y); } else { DrawWire(g, pen, end.X, end.Y, x, y); } }
private void DrawGhost(TElement element, Graphics g) { ElementTypeInfo info = GetElementTypeInfo(element, g); Point p = element.Bounds.Location; Rectangle bounds = new Rectangle(p, info.Size); // clip to window to speed up drawing when zoomed in if (g.ClipBounds.IntersectsWith(bounds)) { if (info.Path == null) { ICircuitElementType type = element.Type; BuildGraphics(type, info, g); } s_pathTransform.Translate(p.X, p.Y); info.Path.Transform(s_pathTransform); g.FillPath(m_theme.GhostBrush, info.Path); g.DrawPath(m_theme.GhostPen, info.Path); s_pathTransform.Translate(-2 * p.X, -2 * p.Y); info.Path.Transform(s_pathTransform); s_pathTransform.Reset(); } }
private bool PickEdge(TWire edge, Point p, Graphics g) { ElementTypeInfo fromInfo = GetElementTypeInfo(edge.FromNode, g); TPin inputPin = edge.ToRoute; TPin outputPin = edge.FromRoute; Point p1 = edge.FromNode.Bounds.Location; int x1 = p1.X + fromInfo.Size.Width; int y1 = p1.Y + GetPinOffset(outputPin.Index); Point p2 = edge.ToNode.Bounds.Location; int x2 = p2.X; int y2 = p2.Y + GetPinOffset(inputPin.Index); int tanLen = GetTangentLength(x1, x2); BezierCurve2F curve = new BezierCurve2F( new Vec2F(x1, y1), new Vec2F(x1 + tanLen, y1), new Vec2F(x2 - tanLen, y2), new Vec2F(x2, y2)); Vec2F hitPoint = new Vec2F(); return(BezierCurve2F.Pick(curve, new Vec2F(p.X, p.Y), m_theme.PickTolerance, ref hitPoint)); }
private void OnUpgradeBtn() { ElementTypeInfo armyType = ArmyTypes[Toggle.ActiveIndex]; ListUpgrade type = armyType.BaseType; // open Group.Open(WindowType.UpgradeResearch); Group[WindowType.UpgradeResearch].Load(type); }
private void DrawWire( TElement outputElement, TPin outputPin, TElement inputElement, TPin inputPin, Graphics g, Pen pen) { ElementTypeInfo info = GetElementTypeInfo(outputElement, g); Point op = outputElement.Bounds.Location; int x1 = op.X + info.Size.Width; int y1 = op.Y + GetPinOffset(outputPin.Index); Point ip = inputElement.Bounds.Location; int x2 = ip.X; int y2 = ip.Y + GetPinOffset(inputPin.Index); DrawWire(g, pen, x1, y1, x2, y2); }
private void BuildGraphics(ICircuitElementType elementType, ElementTypeInfo info, Graphics g) { int width = info.Size.Width; int height = info.Size.Height; // create rounded corner rect GraphicsPath gp = new GraphicsPath(); const float r = 6; const float d = 2 * r; gp.AddLine(r, 0, width - d, 0); gp.AddArc(width - d, 0, d, d, 270, 90); gp.AddLine(width, r, width, height - d); gp.AddArc(width - d, height - d, d, d, 0, 90); gp.AddLine(width - d, height, r, height); gp.AddArc(0, height - d, d, d, 90, 90); gp.AddLine(0, height - d, 0, r); gp.AddArc(0, 0, d, d, 180, 90); info.Path = gp; }
private void DrawOutline(TElement element, Pen pen, Graphics g) { ElementTypeInfo info = GetElementTypeInfo(element, g); if (info.Path == null) { ICircuitElementType type = element.Type; BuildGraphics(type, info, g); } Point p = element.Bounds.Location; s_pathTransform.Translate(p.X, p.Y); info.Path.Transform(s_pathTransform); g.DrawPath(pen, info.Path); s_pathTransform.Translate(2 * -p.X, 2 * -p.Y); info.Path.Transform(s_pathTransform); s_pathTransform.Reset(); }
private ElementTypeInfo GetElementTypeInfo(TElement element, Graphics g) { // look it up in the cache ICircuitElementType type = element.Type; ElementTypeInfo cachedInfo; if (m_elementTypeCache.TryGetValue(type, out cachedInfo)) { return(cachedInfo); } // not in cache, recompute ElementSizeInfo sizeInfo = GetElementSizeInfo(type, g); ElementTypeInfo info = new ElementTypeInfo { Size = sizeInfo.Size, Interior = sizeInfo.Interior, OutputLeftX = sizeInfo.OutputLeftX.ToArray() }; m_elementTypeCache.Add(type, info); return(info); }
private Rectangle GetElementBounds(TElement element, Graphics g) { ElementTypeInfo info = GetElementTypeInfo(element, g); return(new Rectangle(element.Bounds.Location, info.Size)); }
private void Draw(TElement element, Graphics g) { ElementTypeInfo info = GetElementTypeInfo(element, g); Point p = element.Bounds.Location; Rectangle bounds = new Rectangle(p, info.Size); // clip to window if (g.ClipBounds.IntersectsWith(bounds)) { ICircuitElementType type = element.Type; if (info.Path == null) { BuildGraphics(type, info, g); } s_pathTransform.Translate(p.X, p.Y); info.Path.Transform(s_pathTransform); // try to use custom brush if registered Brush fillBrush = m_theme.GetCustomBrush(type.Name); if (fillBrush != null) { g.FillPath(fillBrush, info.Path); } else { // use a default brush using (LinearGradientBrush lgb = new LinearGradientBrush( bounds, Color.White, Color.LightSteelBlue, LinearGradientMode.Vertical)) { g.FillPath(lgb, info.Path); } } g.DrawPath(m_theme.OutlinePen, info.Path); int titleHeight = m_rowSpacing + PinMargin; g.DrawLine(m_theme.OutlinePen, p.X, p.Y + titleHeight, p.X + info.Size.Width, p.Y + titleHeight); g.DrawString(type.Name, m_theme.Font, m_theme.TextBrush, p.X + PinMargin + 1, p.Y + PinMargin + 1); int pinY = p.Y + titleHeight + PinMargin; foreach (TPin inputPin in type.Inputs) { Pen pen = GetPen(inputPin); if (pen != null) { g.DrawRectangle(pen, p.X + 1, pinY + m_pinOffset, m_pinSize, m_pinSize); } g.DrawString(inputPin.Name, m_theme.Font, m_theme.TextBrush, p.X + m_pinSize + PinMargin, pinY); pinY += m_rowSpacing; } pinY = p.Y + titleHeight + PinMargin; int i = 0; foreach (TPin outputPin in type.Outputs) { Pen pen = GetPen(outputPin); if (pen != null) { g.DrawRectangle(pen, p.X + info.Size.Width - m_pinSize, pinY + m_pinOffset, m_pinSize, m_pinSize); } g.DrawString(outputPin.Name, m_theme.Font, m_theme.TextBrush, p.X + info.OutputLeftX[i], pinY); pinY += m_rowSpacing; i++; } Image image = type.Image; if (image != null) { g.DrawImage(image, p.X + info.Interior.X, p.Y + info.Interior.Y, info.Interior.Width, info.Interior.Height); } s_pathTransform.Translate(-2 * p.X, -2 * p.Y); info.Path.Transform(s_pathTransform); s_pathTransform.Reset(); string name = element.Name; if (!string.IsNullOrEmpty(name)) { RectangleF alignRect = new RectangleF( bounds.Left - MaxNameOverhang, bounds.Bottom + PinMargin, bounds.Width + 2 * MaxNameOverhang, m_rowSpacing); g.DrawString(name, m_theme.Font, m_theme.TextBrush, alignRect, m_theme.CenterStringFormat); } } }