private void ConnectWireBetweenPorts() { Wire wire = item.GetComponent <Wire>(); if (wire == null) { return; } wire.Hidden = true; wire.Locked = true; if (Item.Connections == null) { return; } var powerConnection = Item.Connections.Find(c => c.IsPower); if (powerConnection == null) { return; } if (DockingTarget == null || DockingTarget.item.Connections == null) { return; } var recipient = DockingTarget.item.Connections.Find(c => c.IsPower); if (recipient == null) { return; } wire.RemoveConnection(item); wire.RemoveConnection(DockingTarget.item); powerConnection.TryAddLink(wire); wire.Connect(powerConnection, false, false); recipient.TryAddLink(wire); wire.Connect(recipient, false, false); }
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); } }
public static void DrawConnections(SpriteBatch spriteBatch, ConnectionPanel panel, Character character) { Rectangle panelRect = panel.GuiFrame.Rect; int x = panelRect.X, y = panelRect.Y; int width = panelRect.Width, height = panelRect.Height; bool mouseInRect = panelRect.Contains(PlayerInput.MousePosition); int totalWireCount = 0; foreach (Connection c in panel.Connections) { totalWireCount += c.Wires.Count(w => w != null); } Wire equippedWire = null; bool allowRewiring = GameMain.NetworkMember?.ServerSettings == null || GameMain.NetworkMember.ServerSettings.AllowRewiring; if (allowRewiring && (!panel.Locked || Screen.Selected == GameMain.SubEditorScreen)) { //if the Character using the panel has a wire item equipped //and the wire hasn't been connected yet, draw it on the panel for (int i = 0; i < character.SelectedItems.Length; i++) { Item selectedItem = character.SelectedItems[i]; if (selectedItem == null) { continue; } Wire wireComponent = selectedItem.GetComponent <Wire>(); if (wireComponent != null) { equippedWire = wireComponent; } } } Vector2 rightPos = new Vector2(x + width - 110 * GUI.xScale, y + 80 * GUI.yScale); Vector2 leftPos = new Vector2(x + 110 * GUI.xScale, y + 80 * GUI.yScale); Vector2 rightWirePos = new Vector2(x + width - 5 * GUI.xScale, y + 30 * GUI.yScale); Vector2 leftWirePos = new Vector2(x + 5 * GUI.xScale, y + 30 * GUI.yScale); int wireInterval = (height - (int)(20 * GUI.yScale)) / Math.Max(totalWireCount, 1); int connectorIntervalLeft = (height - (int)(100 * GUI.yScale)) / Math.Max(panel.Connections.Count(c => c.IsOutput), 1); int connectorIntervalRight = (height - (int)(100 * GUI.yScale)) / Math.Max(panel.Connections.Count(c => !c.IsOutput), 1); foreach (Connection c in panel.Connections) { //if dragging a wire, let the Inventory know so that the wire can be //dropped or dragged from the panel to the players inventory if (draggingConnected != null) { //the wire can only be dragged out if it's not connected to anything at the other end if (Screen.Selected == GameMain.SubEditorScreen || (draggingConnected.Connections[0] == null && draggingConnected.Connections[1] == null) || (draggingConnected.Connections.Contains(c) && draggingConnected.Connections.Contains(null))) { int linkIndex = c.FindWireIndex(draggingConnected.Item); if (linkIndex > -1 || panel.DisconnectedWires.Contains(draggingConnected)) { Inventory.draggingItem = draggingConnected.Item; } } } //outputs are drawn at the right side of the panel, inputs at the left if (c.IsOutput) { c.Draw(spriteBatch, panel, rightPos, new Vector2(rightPos.X - GUI.SmallFont.MeasureString(c.DisplayName).X - 20 * GUI.xScale, rightPos.Y + 3 * GUI.yScale), rightWirePos, mouseInRect, equippedWire, wireInterval); rightPos.Y += connectorIntervalLeft; rightWirePos.Y += c.Wires.Count(w => w != null) * wireInterval; } else { c.Draw(spriteBatch, panel, leftPos, new Vector2(leftPos.X + 20 * GUI.xScale, leftPos.Y - 12 * GUI.yScale), leftWirePos, mouseInRect, equippedWire, wireInterval); leftPos.Y += connectorIntervalRight; leftWirePos.Y += c.Wires.Count(w => w != null) * wireInterval; //leftWireX -= wireInterval; } } if (draggingConnected != null) { if (mouseInRect) { DrawWire(spriteBatch, draggingConnected, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height - 10), null, panel, ""); } if (!PlayerInput.LeftButtonHeld()) { if (draggingConnected.Connections[0]?.ConnectionPanel == panel || draggingConnected.Connections[1]?.ConnectionPanel == panel) { draggingConnected.RemoveConnection(panel.Item); panel.DisconnectedWires.Add(draggingConnected); } if (GameMain.Client != null) { panel.Item.CreateClientEvent(panel); } draggingConnected = null; } } //if the Character using the panel has a wire item equipped //and the wire hasn't been connected yet, draw it on the panel if (equippedWire != null && (draggingConnected != equippedWire || !mouseInRect)) { if (panel.Connections.Find(c => c.Wires.Contains(equippedWire)) == null) { DrawWire(spriteBatch, equippedWire, new Vector2(x + width / 2, y + height - 150 * GUI.Scale), new Vector2(x + width / 2, y + height), null, panel, ""); if (draggingConnected == equippedWire) { Inventory.draggingItem = equippedWire.Item; } } } float step = (width * 0.75f) / panel.DisconnectedWires.Count(); x = (int)(x + width / 2 - step * (panel.DisconnectedWires.Count() - 1) / 2); foreach (Wire wire in panel.DisconnectedWires) { if (wire == draggingConnected && mouseInRect) { continue; } Connection recipient = wire.OtherConnection(null); string label = recipient == null ? "" : recipient.item.Name + $" ({recipient.DisplayName})"; if (wire.Locked) { label += "\n" + TextManager.Get("ConnectionLocked"); } DrawWire(spriteBatch, wire, new Vector2(x, y + height - 100 * GUI.Scale), new Vector2(x, y + height), null, panel, label); x += (int)step; } //stop dragging a wire item if the cursor is within any connection panel //(so we don't drop the item when dropping the wire on a connection) if (mouseInRect || GUI.MouseOn?.UserData is ConnectionPanel) { Inventory.draggingItem = null; } }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { List <Wire>[] wires = new List <Wire> [Connections.Count]; //read wire IDs for each connection for (int i = 0; i < Connections.Count; i++) { wires[i] = new List <Wire>(); for (int j = 0; j < Connection.MaxLinked; j++) { ushort wireId = msg.ReadUInt16(); Item wireItem = Entity.FindEntityByID(wireId) as Item; if (wireItem == null) { continue; } Wire wireComponent = wireItem.GetComponent <Wire>(); if (wireComponent != null) { wires[i].Add(wireComponent); } } } item.CreateServerEvent(this); //check if the character can access this connectionpanel //and all the wires they're trying to connect if (!item.CanClientAccess(c)) { return; } for (int i = 0; i < Connections.Count; i++) { foreach (Wire wire in wires[i]) { //wire not found in any of the connections yet (client is trying to connect a new wire) // -> we need to check if the client has access to it if (!Connections.Any(connection => connection.Wires.Contains(wire))) { if (!wire.Item.CanClientAccess(c)) { return; } } } } //go through existing wire links for (int i = 0; i < Connections.Count; i++) { for (int j = 0; j < Connection.MaxLinked; j++) { Wire existingWire = Connections[i].Wires[j]; if (existingWire == null) { continue; } //existing wire not in the list of new wires -> disconnect it if (!wires[i].Contains(existingWire)) { if (existingWire.Locked) { //this should not be possible unless the client is running a modified version of the game GameServer.Log(c.Character.LogName + " attempted to disconnect a locked wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.Error); continue; } existingWire.RemoveConnection(item); if (existingWire.Connections[0] == null && existingWire.Connections[1] == null) { GameServer.Log(c.Character.LogName + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.ItemInteraction); } else if (existingWire.Connections[0] != null) { GameServer.Log(c.Character.LogName + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")", ServerLog.MessageType.ItemInteraction); //wires that are not in anyone's inventory (i.e. not currently being rewired) //can never be connected to only one connection // -> the client must have dropped the wire from the connection panel if (existingWire.Item.ParentInventory == null && !wires.Any(w => w.Contains(existingWire))) { //let other clients know the item was also disconnected from the other connection existingWire.Connections[0].Item.CreateServerEvent(existingWire.Connections[0].Item.GetComponent <ConnectionPanel>()); existingWire.Item.Drop(c.Character); } } else if (existingWire.Connections[1] != null) { GameServer.Log(c.Character.LogName + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction); if (existingWire.Item.ParentInventory == null && !wires.Any(w => w.Contains(existingWire))) { //let other clients know the item was also disconnected from the other connection existingWire.Connections[1].Item.CreateServerEvent(existingWire.Connections[1].Item.GetComponent <ConnectionPanel>()); existingWire.Item.Drop(c.Character); } } Connections[i].Wires[j] = null; } } } //go through new wires for (int i = 0; i < Connections.Count; i++) { foreach (Wire newWire in wires[i]) { //already connected, no need to do anything if (Connections[i].Wires.Contains(newWire)) { continue; } Connections[i].TryAddLink(newWire); newWire.Connect(Connections[i], true, true); var otherConnection = newWire.OtherConnection(Connections[i]); if (otherConnection == null) { GameServer.Log(c.Character.LogName + " connected a wire to " + Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.ItemInteraction); } else { GameServer.Log(c.Character.LogName + " connected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + (otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"), ServerLog.MessageType.ItemInteraction); } } } }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { List <Wire>[] wires = new List <Wire> [Connections.Count]; //read wire IDs for each connection for (int i = 0; i < Connections.Count; i++) { wires[i] = new List <Wire>(); int wireCount = msg.ReadRangedInteger(0, Connection.MaxLinked); for (int j = 0; j < wireCount; j++) { ushort wireId = msg.ReadUInt16(); Item wireItem = Entity.FindEntityByID(wireId) as Item; if (wireItem == null) { continue; } Wire wireComponent = wireItem.GetComponent <Wire>(); if (wireComponent != null) { wires[i].Add(wireComponent); } } } item.CreateServerEvent(this); //check if the character can access this connectionpanel //and all the wires they're trying to connect if (!item.CanClientAccess(c)) { return; } for (int i = 0; i < Connections.Count; i++) { foreach (Wire wire in wires[i]) { //wire not found in any of the connections yet (client is trying to connect a new wire) // -> we need to check if the client has access to it if (!Connections.Any(connection => connection.Wires.Contains(wire))) { if (!wire.Item.CanClientAccess(c)) { return; } } } } //go through existing wire links for (int i = 0; i < Connections.Count; i++) { for (int j = 0; j < Connection.MaxLinked; j++) { Wire existingWire = Connections[i].Wires[j]; if (existingWire == null) { continue; } //existing wire not in the list of new wires -> disconnect it if (!wires[i].Contains(existingWire)) { existingWire.RemoveConnection(item); if (existingWire.Connections[0] == null && existingWire.Connections[1] == null) { GameServer.Log(c.Character.Name + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.ItemInteraction); } else if (existingWire.Connections[0] != null) { GameServer.Log(c.Character.Name + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")", ServerLog.MessageType.ItemInteraction); } else if (existingWire.Connections[1] != null) { GameServer.Log(c.Character.Name + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction); } Connections[i].Wires[j] = null; } } } //go through new wires for (int i = 0; i < Connections.Count; i++) { foreach (Wire newWire in wires[i]) { //already connected, no need to do anything if (Connections[i].Wires.Contains(newWire)) { continue; } Connections[i].TryAddLink(newWire); newWire.Connect(Connections[i], true, true); var otherConnection = newWire.OtherConnection(Connections[i]); if (otherConnection == null) { GameServer.Log(c.Character.Name + " connected a wire to " + Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.ItemInteraction); } else { GameServer.Log(c.Character.Name + " connected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + (otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"), ServerLog.MessageType.ItemInteraction); } } } }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { List <Wire>[] wires = new List <Wire> [Connections.Count]; //read wire IDs for each connection for (int i = 0; i < Connections.Count; i++) { wires[i] = new List <Wire>(); for (int j = 0; j < Connection.MaxLinked; j++) { ushort wireId = msg.ReadUInt16(); Item wireItem = Entity.FindEntityByID(wireId) as Item; if (wireItem == null) { continue; } Wire wireComponent = wireItem.GetComponent <Wire>(); if (wireComponent != null) { wires[i].Add(wireComponent); } } } item.CreateServerEvent(this); //check if the character can access this connectionpanel //and all the wires they're trying to connect if (!item.CanClientAccess(c)) { return; } for (int i = 0; i < Connections.Count; i++) { foreach (Wire wire in wires[i]) { //wire not found in any of the connections yet (client is trying to connect a new wire) // -> we need to check if the client has access to it if (!Connections.Any(connection => connection.Wires.Contains(wire))) { if (!wire.Item.CanClientAccess(c)) { return; } } } } //go through existing wire links for (int i = 0; i < Connections.Count; i++) { for (int j = 0; j < Connection.MaxLinked; j++) { Wire existingWire = Connections[i].Wires[j]; if (existingWire == null) { continue; } //NilMod Deny changes to locked wiring //if (existingWire.Locked == true) continue; //existing wire not in the list of new wires -> disconnect it if (!wires[i].Contains(existingWire)) { if (existingWire.Locked || c.Character?.SpawnRewireWaitTimer > 0) { if (!GameMain.NilMod.CanRewireMainSubs && c.Character?.SpawnRewireWaitTimer <= 0f) { //this should not be possible unless the client is running a modified version of the game GameServer.Log(c.Character.LogName + " attempted to disconnect a locked wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") - Could be a modified client.", ServerLog.MessageType.Rewire); } else if (c.Character?.SpawnRewireWaitTimer > 0f) { //this is simply the rewire protection from CanRewireMainSubs GameServer.Log(c.Character.LogName + " attempted to disconnect a locked wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") - but SpawnRewireWaitTimer Prevented it.", ServerLog.MessageType.Rewire); } else { //this is simply the rewire protection from CanRewireMainSubs GameServer.Log(c.Character.LogName + " attempted to disconnect a locked wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") - but CanRewireMainSubs Prevented it.", ServerLog.MessageType.Rewire); } continue; } existingWire.RemoveConnection(item); if (existingWire.Connections[0] == null && existingWire.Connections[1] == null) { GameServer.Log(c.Character.LogName + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.Rewire); } else if (existingWire.Connections[0] != null) { GameServer.Log(c.Character.LogName + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")", ServerLog.MessageType.Rewire); if (GameMain.NilMod.EnableGriefWatcher) { for (int z = 0; z < NilMod.NilModGriefWatcher.GWListWireKeyDevices.Count; z++) { if (NilMod.NilModGriefWatcher.GWListWireKeyDevices[z] == Connections[i].Item.Name || NilMod.NilModGriefWatcher.GWListWireKeyDevices[z] == existingWire.Connections[0].Item.Name) { NilMod.NilModGriefWatcher.SendWarning(c.Character.LogName + " Modified a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")" + ".", c); } } if (NilMod.NilModGriefWatcher.GWListWireJunctions.Contains(Connections[i].Item.Name) && NilMod.NilModGriefWatcher.GWListWireJunctions.Contains(existingWire.Connections[0].Item.Name)) { NilMod.NilModGriefWatcher.SendWarning(c.Character.LogName + " Modified a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")" + ".", c); } } //wires that are not in anyone's inventory (i.e. not currently being rewired) //can never be connected to only one connection // -> the client must have dropped the wire from the connection panel if (existingWire.Item.ParentInventory == null && !wires.Any(w => w.Contains(existingWire))) { //let other clients know the item was also disconnected from the other connection existingWire.Connections[0].Item.CreateServerEvent(existingWire.Connections[0].Item.GetComponent <ConnectionPanel>()); existingWire.Item.Drop(c.Character); } } else if (existingWire.Connections[1] != null) { GameServer.Log(c.Character.LogName + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")", ServerLog.MessageType.Rewire); if (GameMain.NilMod.EnableGriefWatcher) { for (int z = 0; z < NilMod.NilModGriefWatcher.GWListWireKeyDevices.Count - 1; z++) { if (NilMod.NilModGriefWatcher.GWListWireKeyDevices[z] == Connections[i].Item.Name || NilMod.NilModGriefWatcher.GWListWireKeyDevices[z] == existingWire.Connections[1].Item.Name) { NilMod.NilModGriefWatcher.SendWarning(c.Character.LogName + " Modified a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")" + ".", c); } } if (NilMod.NilModGriefWatcher.GWListWireJunctions.Contains(Connections[i].Item.Name) && NilMod.NilModGriefWatcher.GWListWireJunctions.Contains(existingWire.Connections[1].Item.Name)) { NilMod.NilModGriefWatcher.SendWarning(c.Character.LogName + " Modified a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")" + ".", c); } } if (existingWire.Item.ParentInventory == null && !wires.Any(w => w.Contains(existingWire))) { //let other clients know the item was also disconnected from the other connection existingWire.Connections[1].Item.CreateServerEvent(existingWire.Connections[1].Item.GetComponent <ConnectionPanel>()); existingWire.Item.Drop(c.Character); } } Connections[i].Wires[j] = null; } } } //go through new wires for (int i = 0; i < Connections.Count; i++) { foreach (Wire newWire in wires[i]) { //already connected, no need to do anything if (Connections[i].Wires.Contains(newWire)) { continue; } //NilMod Deny changes to locked wiring if (newWire.Locked || c.Character?.SpawnRewireWaitTimer > 0f) { continue; } Connections[i].TryAddLink(newWire); newWire.Connect(Connections[i], true, true); var otherConnection = newWire.OtherConnection(Connections[i]); if (otherConnection == null) { GameServer.Log(c.Character.LogName + " connected a wire to " + Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.Rewire); } else { GameServer.Log(c.Character.LogName + " connected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + (otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"), ServerLog.MessageType.Rewire); } } } }
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, 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]) { 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 (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); } }