Fixed null exception if switching to wiring mode while some item is selected
This commit is contained in:
@@ -508,44 +508,47 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
Wire selectedWire = ((Item)MapEntity.SelectedList[0]).GetComponent<Wire>();
|
Wire selectedWire = ((Item)MapEntity.SelectedList[0]).GetComponent<Wire>();
|
||||||
|
|
||||||
Vector2 mousePos = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
if (selectedWire != null)
|
||||||
if (selectedWire.item.Submarine != null) mousePos -= (selectedWire.item.Submarine.Position + selectedWire.item.Submarine.HiddenSubPosition);
|
|
||||||
|
|
||||||
//left click while holding ctrl -> check if the cursor is on a wire section,
|
|
||||||
//and add a new node if it is
|
|
||||||
if (PlayerInput.KeyDown(Keys.RightControl) || PlayerInput.KeyDown(Keys.LeftControl))
|
|
||||||
{
|
{
|
||||||
if (PlayerInput.LeftButtonClicked())
|
Vector2 mousePos = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||||
{
|
if (selectedWire.item.Submarine != null) mousePos -= (selectedWire.item.Submarine.Position + selectedWire.item.Submarine.HiddenSubPosition);
|
||||||
float temp = 0.0f;
|
|
||||||
int closestSectionIndex = selectedWire.GetClosestSectionIndex(mousePos, sectionSelectDist, out temp);
|
|
||||||
|
|
||||||
if (closestSectionIndex > -1)
|
//left click while holding ctrl -> check if the cursor is on a wire section,
|
||||||
|
//and add a new node if it is
|
||||||
|
if (PlayerInput.KeyDown(Keys.RightControl) || PlayerInput.KeyDown(Keys.LeftControl))
|
||||||
|
{
|
||||||
|
if (PlayerInput.LeftButtonClicked())
|
||||||
{
|
{
|
||||||
selectedWire.nodes.Insert(closestSectionIndex+1, mousePos);
|
float temp = 0.0f;
|
||||||
selectedWire.UpdateSections();
|
int closestSectionIndex = selectedWire.GetClosestSectionIndex(mousePos, sectionSelectDist, out temp);
|
||||||
|
|
||||||
|
if (closestSectionIndex > -1)
|
||||||
|
{
|
||||||
|
selectedWire.nodes.Insert(closestSectionIndex + 1, mousePos);
|
||||||
|
selectedWire.UpdateSections();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
|
||||||
{
|
|
||||||
//check if close enough to a node
|
|
||||||
float temp = 0.0f;
|
|
||||||
int closestIndex = selectedWire.GetClosestNodeIndex(mousePos, nodeSelectDist, out temp);
|
|
||||||
if (closestIndex > -1)
|
|
||||||
{
|
{
|
||||||
highlightedNodeIndex = closestIndex;
|
//check if close enough to a node
|
||||||
//start dragging the node
|
float temp = 0.0f;
|
||||||
if (PlayerInput.LeftButtonHeld())
|
int closestIndex = selectedWire.GetClosestNodeIndex(mousePos, nodeSelectDist, out temp);
|
||||||
|
if (closestIndex > -1)
|
||||||
{
|
{
|
||||||
draggingWire = selectedWire;
|
highlightedNodeIndex = closestIndex;
|
||||||
selectedNodeIndex = closestIndex;
|
//start dragging the node
|
||||||
}
|
if (PlayerInput.LeftButtonHeld())
|
||||||
//remove the node
|
{
|
||||||
else if (PlayerInput.RightButtonClicked() && closestIndex > 0 && closestIndex < selectedWire.nodes.Count-1)
|
draggingWire = selectedWire;
|
||||||
{
|
selectedNodeIndex = closestIndex;
|
||||||
selectedWire.nodes.RemoveAt(closestIndex);
|
}
|
||||||
selectedWire.UpdateSections();
|
//remove the node
|
||||||
|
else if (PlayerInput.RightButtonClicked() && closestIndex > 0 && closestIndex < selectedWire.nodes.Count - 1)
|
||||||
|
{
|
||||||
|
selectedWire.nodes.RemoveAt(closestIndex);
|
||||||
|
selectedWire.UpdateSections();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user