- "wiring mode" which makes wiring a bit more convenient in editor

- invisible entities (items inside cabinets, hulls/gaps when they've been hidden) can't be highlighted or selected in the editor
- fixed And Components always sending a signal out during the first frame if timeframe is set to 0.0
- fixed moloch not appearing in the tutorial
This commit is contained in:
Regalis
2016-03-11 16:10:36 +02:00
parent 581c95b065
commit ad17b1a9bf
9 changed files with 174 additions and 40 deletions
@@ -1,4 +1,5 @@
using Barotrauma.Items.Components; using Barotrauma.Items.Components;
using FarseerPhysics;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -17,7 +18,7 @@ namespace Barotrauma.Tutorials
public override IEnumerable<object> UpdateState() public override IEnumerable<object> UpdateState()
{ {
//Submarine.Loaded.SetPosition(new Vector2(Submarine.Loaded.Position.X, 38500.0f)); Submarine.Loaded.SetPosition(new Vector2(Submarine.Loaded.Position.X, 38500.0f));
//spawn some fish next to the player //spawn some fish next to the player
GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(2, GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(2,
@@ -275,7 +276,7 @@ namespace Barotrauma.Tutorials
infoBox = CreateInfoFrame("Steer the submarine downwards, heading further into the cavern."); infoBox = CreateInfoFrame("Steer the submarine downwards, heading further into the cavern.");
while (Submarine.Loaded.WorldPosition.Y > 39000.0f) while (Submarine.Loaded.WorldPosition.Y > 25000.0f)
{ {
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
} }
@@ -449,6 +450,8 @@ namespace Barotrauma.Tutorials
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
} }
moloch.AnimController.SetPosition(ConvertUnits.ToSimUnits(Character.Controlled.WorldPosition + Vector2.UnitY*1000.0f));
infoBox = CreateInfoFrame("Now we're ready to shoot! Select the railgun controller."); infoBox = CreateInfoFrame("Now we're ready to shoot! Select the railgun controller.");
while (Character.Controlled.SelectedConstruction == null || Character.Controlled.SelectedConstruction.Name != "Railgun Controller") while (Character.Controlled.SelectedConstruction == null || Character.Controlled.SelectedConstruction.Name != "Railgun Controller")
@@ -42,7 +42,7 @@ namespace Barotrauma.Tutorials
GameMain.GameSession = new GameSession(Submarine.Loaded, "", GameModePreset.list.Find(gm => gm.Name.ToLower() == "tutorial")); GameMain.GameSession = new GameSession(Submarine.Loaded, "", GameModePreset.list.Find(gm => gm.Name.ToLower() == "tutorial"));
(GameMain.GameSession.gameMode as TutorialMode).tutorialType = this; (GameMain.GameSession.gameMode as TutorialMode).tutorialType = this;
GameMain.GameSession.StartShift("tutorial"); GameMain.GameSession.StartShift("tuto1");
GameMain.GameSession.TaskManager.Tasks.Clear(); GameMain.GameSession.TaskManager.Tasks.Clear();
@@ -13,7 +13,7 @@ namespace Barotrauma.Items.Components
//the output is sent if both inputs have received a signal within the timeframe //the output is sent if both inputs have received a signal within the timeframe
protected float timeFrame; protected float timeFrame;
[InGameEditable, HasDefaultValue(0.1f, true)] [InGameEditable, HasDefaultValue(0.0f, true)]
public float TimeFrame public float TimeFrame
{ {
get { return timeFrame; } get { return timeFrame; }
@@ -33,7 +33,7 @@ namespace Barotrauma.Items.Components
public AndComponent(Item item, XElement element) public AndComponent(Item item, XElement element)
: base (item, element) : base (item, element)
{ {
timeSinceReceived = new float[] { timeFrame*2.0f, timeFrame*2.0f}; timeSinceReceived = new float[] { Math.Max(timeFrame*2.0f,0.1f), Math.Max(timeFrame*2.0f, 0.1f) };
//output = "1"; //output = "1";
} }
@@ -328,7 +328,7 @@ namespace Barotrauma.Items.Components
//nodes.Add(newNodePos); //nodes.Add(newNodePos);
} }
if (!editing || !PlayerInput.MouseInsideWindow || GameMain.EditMapScreen.CharacterMode) return; if (!editing || !PlayerInput.MouseInsideWindow || !GameMain.EditMapScreen.WiringMode ) return;
for (int i = 0; i < Nodes.Count; i++) for (int i = 0; i < Nodes.Count; i++)
{ {
@@ -371,7 +371,6 @@ namespace Barotrauma.Items.Components
{ {
if (selectedNodeIndex != null && draggingWire == this) if (selectedNodeIndex != null && draggingWire == this)
{ {
MapEntity.DisableSelect = true; MapEntity.DisableSelect = true;
//Nodes[(int)selectedNodeIndex] = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition)-Submarine.HiddenSubPosition+Submarine.Loaded.Position; //Nodes[(int)selectedNodeIndex] = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition)-Submarine.HiddenSubPosition+Submarine.Loaded.Position;
+8
View File
@@ -86,6 +86,14 @@ namespace Barotrauma
private set; private set;
} }
public override bool SelectableInEditor
{
get
{
return ParentInventory == null && (body == null || !body.Enabled);
}
}
public List<FixRequirement> FixRequirements; public List<FixRequirement> FixRequirements;
public override string Name public override string Name
+8 -1
View File
@@ -30,7 +30,6 @@ namespace Barotrauma
private float higherSurface; private float higherSurface;
private float lowerSurface; private float lowerSurface;
public float Open public float Open
{ {
get { return open; } get { return open; }
@@ -73,6 +72,14 @@ namespace Barotrauma
} }
} }
public override bool SelectableInEditor
{
get
{
return ShowGaps;
}
}
public Gap(MapEntityPrefab prefab, Rectangle rectangle) public Gap(MapEntityPrefab prefab, Rectangle rectangle)
: this (rectangle, Submarine.Loaded) : this (rectangle, Submarine.Loaded)
{ } { }
+8
View File
@@ -90,6 +90,14 @@ namespace Barotrauma
} }
} }
public override bool SelectableInEditor
{
get
{
return ShowHulls;
}
}
public override bool IsLinkable public override bool IsLinkable
{ {
get { return true; } get { return true; }
+12 -4
View File
@@ -92,6 +92,11 @@ namespace Barotrauma
get { return false; } get { return false; }
} }
public virtual bool SelectableInEditor
{
get { return true; }
}
public override Vector2 Position public override Vector2 Position
{ {
get get
@@ -288,9 +293,12 @@ namespace Barotrauma
foreach (MapEntity e in mapEntityList) foreach (MapEntity e in mapEntityList)
{ {
if (!e.SelectableInEditor) continue;
if (highLightedEntity == null || e.Sprite == null || if (highLightedEntity == null || e.Sprite == null ||
(highLightedEntity.Sprite!=null && e.Sprite.Depth < highLightedEntity.Sprite.Depth)) (highLightedEntity.Sprite!=null && e.Sprite.Depth < highLightedEntity.Sprite.Depth))
{ {
if (e.IsMouseOn(position)) highLightedEntity = e; if (e.IsMouseOn(position)) highLightedEntity = e;
} }
e.isSelected = false; e.isSelected = false;
@@ -315,8 +323,7 @@ namespace Barotrauma
if (moveAmount != Vector2.Zero) if (moveAmount != Vector2.Zero)
{ {
foreach (MapEntity e in selectedList) foreach (MapEntity e in selectedList) e.Move(moveAmount);
e.Move(moveAmount);
} }
startMovingPos = Vector2.Zero; startMovingPos = Vector2.Zero;
@@ -584,8 +591,9 @@ namespace Barotrauma
foreach (MapEntity e in mapEntityList) foreach (MapEntity e in mapEntityList)
{ {
if (Submarine.RectsOverlap(selectionRect, e.rect)) if (!e.SelectableInEditor) continue;
foundEntities.Add(e);
if (Submarine.RectsOverlap(selectionRect, e.rect)) foundEntities.Add(e);
} }
return foundEntities; return foundEntities;
+129 -28
View File
@@ -2,6 +2,7 @@
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -28,6 +29,9 @@ namespace Barotrauma
private bool characterMode; private bool characterMode;
private bool wiringMode;
private GUIFrame wiringToolPanel;
private Tutorials.EditorTutorial tutorial; private Tutorials.EditorTutorial tutorial;
public Camera Cam public Camera Cam
@@ -65,6 +69,11 @@ namespace Barotrauma
get { return characterMode; } get { return characterMode; }
} }
public bool WiringMode
{
get { return wiringMode; }
}
public EditMapScreen() public EditMapScreen()
{ {
@@ -176,6 +185,11 @@ namespace Barotrauma
button = new GUIButton(new Rectangle(0, y, 0, 20), "Character mode", Alignment.Left, GUI.Style, leftPanel); button = new GUIButton(new Rectangle(0, y, 0, 20), "Character mode", Alignment.Left, GUI.Style, leftPanel);
button.ToolTip = "Allows you to pick up and use items. Useful for things such as placing items inside closets, turning devices on/off and doing the wiring."; button.ToolTip = "Allows you to pick up and use items. Useful for things such as placing items inside closets, turning devices on/off and doing the wiring.";
button.OnClicked = ToggleCharacterMode; button.OnClicked = ToggleCharacterMode;
y += 35;
button = new GUIButton(new Rectangle(0, y, 0, 20), "Wiring mode", Alignment.Left, GUI.Style, leftPanel);
//button.ToolTip = "Allows you to pick up and use items. Useful for things such as placing items inside closets, turning devices on/off and doing the wiring.";
button.OnClicked = ToggleWiringMode;
y+=50; y+=50;
button = new GUIButton(new Rectangle(0, y, 0, 20), "Generate waypoints", Alignment.Left, GUI.Style, leftPanel); button = new GUIButton(new Rectangle(0, y, 0, 20), "Generate waypoints", Alignment.Left, GUI.Style, leftPanel);
@@ -252,6 +266,10 @@ namespace Barotrauma
MapEntityPrefab.Selected = null; MapEntityPrefab.Selected = null;
if (characterMode) ToggleCharacterMode();
if (wiringMode) ToggleWiringMode();
if (dummyCharacter != null) if (dummyCharacter != null)
{ {
dummyCharacter.Remove(); dummyCharacter.Remove();
@@ -444,6 +462,84 @@ namespace Barotrauma
return true; return true;
} }
private void ToggleWiringMode()
{
ToggleWiringMode(null, null);
}
private bool ToggleWiringMode(GUIButton button, object obj)
{
wiringMode = !wiringMode;
if (characterMode != wiringMode) ToggleCharacterMode();
if (wiringMode)
{
var screwdriverPrefab = ItemPrefab.list.Find(ip => ip.Name == "Screwdriver") as ItemPrefab;
var item = new Item(screwdriverPrefab, Vector2.Zero, null);
dummyCharacter.Inventory.TryPutItem(item, new List<LimbSlot>() { LimbSlot.RightHand }, false);
wiringToolPanel = CreateWiringPanel();
}
return true;
}
private GUIFrame CreateWiringPanel()
{
GUIFrame frame = new GUIFrame(new Rectangle(0,0,50,300), null, Alignment.Right | Alignment.CenterY, GUI.Style);
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
GUIListBox listBox = new GUIListBox(Rectangle.Empty, GUI.Style, frame);
listBox.OnSelected = SelectWire;
foreach (MapEntityPrefab ep in MapEntityPrefab.list)
{
var itemPrefab = ep as ItemPrefab;
if (itemPrefab == null || itemPrefab.Name == null || !itemPrefab.Name.Contains("Wire")) continue;
GUIFrame imgFrame = new GUIFrame(new Rectangle(0, 0, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), null, listBox);
imgFrame.UserData = itemPrefab;
imgFrame.HoverColor = Color.White * 0.5f;
imgFrame.SelectedColor = Color.Gold * 0.7f;
var img = new GUIImage(new Rectangle(0, 0, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), itemPrefab.sprite, Alignment.TopLeft, imgFrame);
img.Color = ep.SpriteColor;
}
return frame;
}
private bool SelectWire(GUIComponent component, object userData)
{
if (dummyCharacter == null) return false;
Item existingWire = dummyCharacter.SelectedItems.FirstOrDefault(i => i != null && i.Prefab == userData as ItemPrefab);
if (existingWire!=null)
{
existingWire.Drop();
existingWire.Remove();
return false;
}
var wire = new Item(userData as ItemPrefab, Vector2.Zero, null);
int slotIndex = dummyCharacter.Inventory.FindLimbSlot(LimbSlot.LeftHand);
if (dummyCharacter.Inventory.Items[slotIndex] != null && dummyCharacter.Inventory.Items[slotIndex].Prefab != userData as ItemPrefab)
{
dummyCharacter.Inventory.Items[slotIndex].Drop();
dummyCharacter.Inventory.Items[slotIndex].Remove();
}
dummyCharacter.Inventory.TryPutItem(wire, slotIndex, false, false);
return true;
}
private bool ChangeSubName(GUITextBox textBox, string text) private bool ChangeSubName(GUITextBox textBox, string text)
{ {
if (string.IsNullOrWhiteSpace(text)) if (string.IsNullOrWhiteSpace(text))
@@ -528,7 +624,7 @@ namespace Barotrauma
if (characterMode) if (characterMode)
{ {
if (dummyCharacter == null || Entity.FindEntityByID(dummyCharacter.ID)!=dummyCharacter) if (dummyCharacter == null || Entity.FindEntityByID(dummyCharacter.ID) != dummyCharacter)
{ {
ToggleCharacterMode(null, null); ToggleCharacterMode(null, null);
} }
@@ -551,6 +647,7 @@ namespace Barotrauma
dummyCharacter.ControlLocalPlayer((float)deltaTime, cam, false); dummyCharacter.ControlLocalPlayer((float)deltaTime, cam, false);
dummyCharacter.Control((float)deltaTime, cam); dummyCharacter.Control((float)deltaTime, cam);
cam.TargetPos = Vector2.Zero; cam.TargetPos = Vector2.Zero;
} }
} }
else else
@@ -564,6 +661,15 @@ namespace Barotrauma
leftPanel.Update((float)deltaTime); leftPanel.Update((float)deltaTime);
topPanel.Update((float)deltaTime); topPanel.Update((float)deltaTime);
if (wiringMode)
{
if (!dummyCharacter.SelectedItems.Any(it => it.HasTag("Wire")))
{
wiringToolPanel.GetChild<GUIListBox>().Deselect();
}
wiringToolPanel.Update((float)deltaTime);
}
if (loadFrame!=null) if (loadFrame!=null)
{ {
loadFrame.Update((float)deltaTime); loadFrame.Update((float)deltaTime);
@@ -617,38 +723,33 @@ namespace Barotrauma
//EntityPrefab.DrawList(spriteBatch, new Vector2(20,50)); //EntityPrefab.DrawList(spriteBatch, new Vector2(20,50));
if (characterMode) if (characterMode && dummyCharacter != null)
{ {
if (dummyCharacter != null) dummyCharacter.AnimController.FindHull(dummyCharacter.CursorWorldPosition, false);
foreach (Item item in dummyCharacter.SelectedItems)
{ {
dummyCharacter.AnimController.FindHull(dummyCharacter.CursorWorldPosition, false); if (item == null) continue;
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
foreach (Item item in dummyCharacter.SelectedItems) item.Update(cam, (float)deltaTime);
{
if (item == null) continue;
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
item.Update(cam, (float)deltaTime);
}
if (dummyCharacter.SelectedConstruction != null)
{
//if (dummyCharacter.SelectedConstruction == dummyCharacter.ClosestItem)
//{
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter);
//}
//else
//{
// dummyCharacter.SelectedConstruction = null;
//}
if (PlayerInput.KeyHit(InputType.Select) && dummyCharacter.ClosestItem != dummyCharacter.SelectedConstruction) dummyCharacter.SelectedConstruction = null;
}
} }
dummyCharacter.DrawHUD(spriteBatch, cam); if (dummyCharacter.SelectedConstruction != null)
{
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter);
if (PlayerInput.KeyHit(InputType.Select) && dummyCharacter.ClosestItem != dummyCharacter.SelectedConstruction) dummyCharacter.SelectedConstruction = null;
}
if (!wiringMode)
{
dummyCharacter.DrawHUD(spriteBatch, cam);
}
else
{
wiringToolPanel.Draw(spriteBatch);
}
} }
else else
{ {