private void Draw(SpriteBatch spriteBatch, Item item, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval) { //spriteBatch.DrawString(GUI.SmallFont, Name, new Vector2(labelPos.X, labelPos.Y-10), Color.White); GUI.DrawString(spriteBatch, labelPos, Name, IsPower ? Color.Red : Color.White, Color.Black, 0, GUI.SmallFont); GUI.DrawRectangle(spriteBatch, new Rectangle((int)position.X - 10, (int)position.Y - 10, 20, 20), Color.White); spriteBatch.Draw(panelTexture, position - new Vector2(16.0f, 16.0f), new Rectangle(64, 256, 32, 32), Color.White); for (int i = 0; i < MaxLinked; i++) { if (Wires[i] == null || Wires[i].Hidden || draggingConnected == Wires[i]) { continue; } Connection recipient = Wires[i].OtherConnection(this); DrawWire(spriteBatch, Wires[i], (recipient == null) ? Wires[i].Item : recipient.item, position, wirePosition, mouseIn, equippedWire); wirePosition.Y += wireInterval; } if (draggingConnected != null && Vector2.Distance(position, PlayerInput.MousePosition) < 13.0f) { spriteBatch.Draw(panelTexture, position - new Vector2(21.5f, 21.5f), new Rectangle(106, 250, 43, 43), Color.White); if (!PlayerInput.LeftButtonHeld()) { //find an empty cell for the new connection int index = FindWireIndex(null); if (index > -1 && !Wires.Contains(draggingConnected)) { bool alreadyConnected = draggingConnected.IsConnectedTo(item); draggingConnected.RemoveConnection(item); if (draggingConnected.Connect(this, !alreadyConnected, true)) { Wires[index] = draggingConnected; } } } } int screwIndex = (position.Y % 60 < 30) ? 0 : 1; if (Wires.Any(w => w != null && w != draggingConnected)) { spriteBatch.Draw(panelTexture, position - new Vector2(16.0f, 16.0f), new Rectangle(screwIndex * 32, 256, 32, 32), Color.White); } }
private void Draw(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval) { //spriteBatch.DrawString(GUI.SmallFont, Name, new Vector2(labelPos.X, labelPos.Y-10), Color.White); GUI.DrawString(spriteBatch, labelPos, Name, IsPower ? Color.Red : Color.White, Color.Black, 0, GUI.SmallFont); connectionSprite.Draw(spriteBatch, position); for (int i = 0; i < MaxLinked; i++) { if (wires[i] == null || wires[i].Hidden || draggingConnected == wires[i]) { continue; } Connection recipient = wires[i].OtherConnection(this); string label = recipient == null ? "" : wires[i].Locked ? recipient.item.Name + "\n" + TextManager.Get("ConnectionLocked") : recipient.item.Name; DrawWire(spriteBatch, wires[i], (recipient == null) ? wires[i].Item : recipient.item, position, wirePosition, mouseIn, equippedWire, panel, label); wirePosition.Y += wireInterval; } if (draggingConnected != null && Vector2.Distance(position, PlayerInput.MousePosition) < 13.0f) { connectionSpriteHighlight.Draw(spriteBatch, position); if (!PlayerInput.LeftButtonHeld()) { //find an empty cell for the new connection int index = FindEmptyIndex(); if (index > -1 && !Wires.Contains(draggingConnected)) { bool alreadyConnected = draggingConnected.IsConnectedTo(panel.Item); draggingConnected.RemoveConnection(panel.Item); if (draggingConnected.Connect(this, !alreadyConnected, true)) { var otherConnection = draggingConnected.OtherConnection(this); SetWire(index, draggingConnected); } } } } if (Wires.Any(w => w != null && w != draggingConnected)) { int screwIndex = (int)Math.Floor(position.Y / 30.0f) % screwSprites.Count; screwSprites[screwIndex].Draw(spriteBatch, position); } }
private void Draw(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval) { GUI.DrawString(spriteBatch, labelPos, DisplayName, IsPower ? Color.Red : Color.White, Color.Black, 0, GUI.SmallFont); connectionSprite.Draw(spriteBatch, position); for (int i = 0; i < MaxLinked; i++) { if (wires[i] == null || wires[i].Hidden || (draggingConnected == wires[i] && (mouseIn || Screen.Selected == GameMain.SubEditorScreen))) { continue; } Connection recipient = wires[i].OtherConnection(this); string label = recipient == null ? "" : recipient.item.Name + $" ({recipient.DisplayName})"; if (wires[i].Locked) { label += "\n" + TextManager.Get("ConnectionLocked"); } DrawWire(spriteBatch, wires[i], position, wirePosition, equippedWire, panel, label); wirePosition.Y += wireInterval; } if (draggingConnected != null && Vector2.Distance(position, PlayerInput.MousePosition) < (20.0f * GUI.Scale)) { connectionSpriteHighlight.Draw(spriteBatch, position); if (!PlayerInput.LeftButtonHeld()) { //find an empty cell for the new connection int index = FindEmptyIndex(); if (index > -1 && !Wires.Contains(draggingConnected)) { bool alreadyConnected = draggingConnected.IsConnectedTo(panel.Item); draggingConnected.RemoveConnection(panel.Item); if (draggingConnected.Connect(this, !alreadyConnected, true)) { var otherConnection = draggingConnected.OtherConnection(this); SetWire(index, draggingConnected); } } if (GameMain.Client != null) { panel.Item.CreateClientEvent(panel); } draggingConnected = null; } } if (flashTimer > 0.0f) { //the number of flashes depends on the duration, 1 flash per 1 full second int flashCycleCount = (int)Math.Max(flashDuration, 1); float flashCycleDuration = flashDuration / flashCycleCount; //MathHelper.Pi * 0.8f -> the curve goes from 144 deg to 0, //i.e. quickly bumps up from almost full brightness to full and then fades out connectionSpriteHighlight.Draw(spriteBatch, position, flashColor * (float)Math.Sin(flashTimer % flashCycleDuration / flashCycleDuration * MathHelper.Pi * 0.8f)); } if (Wires.Any(w => w != null && w != draggingConnected)) { int screwIndex = (int)Math.Floor(position.Y / 30.0f) % screwSprites.Count; screwSprites[screwIndex].Draw(spriteBatch, position); } }