- server log and item lists in editor can be filtered

- changes to item highlighting logic (easier in cramped subs)
- sub name/description boxes and selected items are reset when leaving the editor
This commit is contained in:
Regalis
2016-07-06 18:08:26 +03:00
parent cd3ecd36e8
commit 19915fc4e5
12 changed files with 162 additions and 54 deletions

View File

@@ -7,5 +7,5 @@
<Ladder canbeselected = "true"/>
<trigger x="-40" width="90"/>
<trigger x="-40" y ="20" width="90"/>
</Item>

View File

@@ -752,8 +752,10 @@ namespace Barotrauma
}
}
private Item FindClosestItem(Vector2 mouseSimPos)
private Item FindClosestItem(Vector2 mouseSimPos, out float distance)
{
distance = 0.0f;
Limb torso = AnimController.GetLimb(LimbType.Torso);
if (torso == null) return null;
@@ -769,7 +771,7 @@ namespace Barotrauma
if (selectedConstruction != null) pickPos = ConvertUnits.ToSimUnits(selectedConstruction.WorldPosition);
return Item.FindPickable(pos, pickPos, AnimController.CurrentHull, selectedItems);
return Item.FindPickable(pos, pickPos, AnimController.CurrentHull, selectedItems, out distance);
}
private Character FindClosestCharacter(Vector2 mouseSimPos, float maxDist = 150.0f)
@@ -890,11 +892,12 @@ namespace Barotrauma
closestCharacter = null;
}
closestItem = FindClosestItem(mouseSimPos);
float closestItemDist = 0.0f;
closestItem = FindClosestItem(mouseSimPos, out closestItemDist);
if (closestCharacter != null && closestItem != null)
{
if (Vector2.Distance(closestCharacter.SimPosition, mouseSimPos) < Vector2.Distance(closestItem.SimPosition, mouseSimPos))
if (Vector2.Distance(closestCharacter.SimPosition, mouseSimPos) < ConvertUnits.ToSimUnits(closestItemDist))
{
if (selectedConstruction != closestItem) closestItem = null;
}

View File

@@ -309,7 +309,7 @@ namespace Barotrauma
for (int i = 0; i < children.Count; i++)
{
GUIComponent child = children[i];
if (child == frame) continue;
if (child == frame || !child.Visible) continue;
child.Rect = new Rectangle(x, y, child.Rect.Width, child.Rect.Height);
if (scrollBar.IsHorizontal)
@@ -321,7 +321,6 @@ namespace Barotrauma
y += child.Rect.Height + spacing;
}
child.Visible = false;
if (scrollBar.IsHorizontal)
{
@@ -345,11 +344,7 @@ namespace Barotrauma
continue;
}
}
child.Visible = true;
if (enabled && child.CanBeFocused &&
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
{

View File

@@ -191,11 +191,6 @@ namespace Barotrauma
//barScroll = (float)newY / ((float)frame.Rect.Height - (float)bar.Rect.Height);
}
if (moveAmount != 0)
{
int asdf = 1;
}
BarScroll = barScroll;
if (moveAmount != 0 && OnMoved != null) OnMoved(this, BarScroll);

View File

@@ -169,6 +169,8 @@ namespace Barotrauma.Items.Components
if (targetBody == null || targetBody.UserData == null) return;
pickedPosition = Submarine.LastPickedPosition;
Structure targetStructure;
Limb targetLimb;
Item targetItem;

View File

@@ -589,8 +589,11 @@ namespace Barotrauma.Items.Components
var sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
if (sender != null)
{
Networking.GameServer.Log("Reactor settings adjusted by " + sender.name+": ", Color.Orange);
Networking.GameServer.Log("Autotemp: " +(autoTemp ? "ON " : "OFF") + " Shutdown temp: "+shutDownTemp+" Cooling rate: "+(int)coolingRate+" Fission rate: "+(int)fissionRate, Color.Orange);
Networking.GameServer.Log(
"Reactor settings adjusted by " + sender.name+": \n"+
"Autotemp: " + (autoTemp ? "ON " : "OFF") + " Shutdown temp: " + shutDownTemp +
" Cooling rate: " + (int)coolingRate + " Fission rate: " + (int)fissionRate,
Color.Orange);
}
}

View File

@@ -1116,10 +1116,16 @@ namespace Barotrauma
yield return CoroutineStatus.Success;
}
public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull = null, Item[] ignoredItems = null)
{
float dist;
return FindPickable(position, pickPosition, hull, ignoredItems, out dist);
}
/// <param name="position">Position of the Character doing the pick, only items that are close enough to this are checked</param>
/// <param name="pickPosition">the item closest to pickPosition is returned</param>
/// <param name="hull">If a hull is specified, only items within that hull are checked</param>
public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull = null, Item[] ignoredItems=null)
public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull, Item[] ignoredItems, out float distance)
{
float closestDist = 0.0f, dist;
Item closest = null;
@@ -1127,55 +1133,59 @@ namespace Barotrauma
Vector2 displayPos = ConvertUnits.ToDisplayUnits(position);
Vector2 displayPickPos = ConvertUnits.ToDisplayUnits(pickPosition);
distance = 1000.0f;
foreach (Item item in ItemList)
{
if (ignoredItems!=null && ignoredItems.Contains(item)) continue;
//if (hull != item.CurrentHull && (hull==null || (item.Rect.Height<hull.Rect.Height && item.rect.Width < hull.Rect.Width))) continue;
if (ignoredItems != null && ignoredItems.Contains(item)) continue;
if (item.body != null && !item.body.Enabled) continue;
if (item.PickDistance == 0.0f && !item.prefab.Triggers.Any()) continue;
Pickable pickableComponent = item.GetComponent<Pickable>();
if (pickableComponent != null && (pickableComponent.Picker != null && !pickableComponent.Picker.IsDead)) continue;
float pickDist = Vector2.Distance(item.WorldPosition, displayPickPos);
bool outsideTrigger = false;
foreach (Rectangle trigger in item.prefab.Triggers)
{
Rectangle transformedTrigger = item.TransformTrigger(trigger, true);
if (!Submarine.RectContains(transformedTrigger, displayPos)) continue;
Vector2 triggerCenter =
new Vector2(
transformedTrigger.X + transformedTrigger.Width / 2.0f,
transformedTrigger.Y - transformedTrigger.Height / 2.0f);
//dist = MathHelper.Min(Math.Abs(triggerCenter.X - displayPos.X), Math.Abs(triggerCenter.Y-displayPos.Y));
//if (dist > closestDist && closest!=null) continue;
dist = MathHelper.Min(Math.Abs(triggerCenter.X - displayPickPos.X), Math.Abs(triggerCenter.Y - displayPickPos.Y));
if (closest == null || dist < closestDist)
if (!Submarine.RectContains(transformedTrigger, displayPos))
{
closest = item;
closestDist = dist;
outsideTrigger = true;
continue;
}
}
if (item.prefab.PickDistance == 0.0f) continue;
if (Vector2.Distance(displayPos, item.WorldPosition) > item.prefab.PickDistance) continue;
if (!item.prefab.PickThroughWalls)
{
Body body = Submarine.CheckVisibility(item.Submarine == null ? position : position - item.Submarine.SimPosition, item.SimPosition, true);
if (body != null && body.UserData as Item != item) continue;
Vector2 triggerCenter = new Vector2(transformedTrigger.Center.X, transformedTrigger.Y - transformedTrigger.Height / 2);
pickDist = Math.Min(Math.Abs(triggerCenter.X - displayPickPos.X), Math.Abs(triggerCenter.Y - displayPickPos.Y));
}
dist = Vector2.Distance(displayPickPos, item.WorldPosition);
if (dist < item.prefab.PickDistance && (closest == null || dist < closestDist))
if (outsideTrigger) continue;
if (pickDist > item.PickDistance && item.PickDistance > 0.0f) continue;
dist = item.Sprite.Depth * 10.0f + pickDist;
if (item.IsMouseOn(displayPickPos)) dist = dist * 0.1f;
if (closest == null || dist < closestDist)
{
closest = item;
if (item.PickDistance > 0.0f && Vector2.Distance(displayPos, item.WorldPosition) > item.prefab.PickDistance) continue;
if (!item.prefab.PickThroughWalls)
{
Body body = Submarine.CheckVisibility(item.Submarine == null ? position : position - item.Submarine.SimPosition, item.SimPosition, true);
if (body != null && body.UserData as Item != item) continue;
}
closestDist = dist;
closest = item;
distance = pickDist;
}
}
return closest;
}

View File

@@ -467,13 +467,19 @@ namespace Barotrauma
}
}
public static void SelectEntity(MapEntity entity)
public static void DeselectAll()
{
foreach (MapEntity e in selectedList)
{
{
e.isSelected = false;
}
selectedList.Clear();
}
public static void SelectEntity(MapEntity entity)
{
DeselectAll();
entity.isSelected = true;
selectedList.Add(entity);

View File

@@ -927,6 +927,8 @@ namespace Barotrauma
subBody = null;
if (MainSub == this) MainSub = null;
DockedTo.Clear();
}
}

View File

@@ -272,7 +272,6 @@ namespace Barotrauma.Networking
{
if (ShowNetStats) netStats.Update(deltaTime);
if (settingsFrame != null) settingsFrame.Update(deltaTime);
if (log.LogFrame != null) log.LogFrame.Update(deltaTime);
if (!started) return;
@@ -1345,6 +1344,7 @@ namespace Barotrauma.Networking
}
else if (log.LogFrame!=null)
{
log.LogFrame.Update(0.016f);
log.LogFrame.Draw(spriteBatch);
}

View File

@@ -62,7 +62,18 @@ namespace Barotrauma.Networking
GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,400, 400), null, Alignment.Center, GUI.Style, LogFrame);
innerFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
listBox = new GUIListBox(new Rectangle(0,0,0,355), GUI.Style, innerFrame);
new GUITextBlock(new Rectangle(-200,0,100,15), "Filter", GUI.Style, Alignment.TopRight, Alignment.TopRight, innerFrame, false, GUI.SmallFont);
GUITextBox searchBox = new GUITextBox(new Rectangle(-20,0,180,15), Alignment.TopRight, GUI.Style, innerFrame);
searchBox.Font = GUI.SmallFont;
searchBox.OnTextChanged = FilterMessages;
GUIComponent.KeyboardDispatcher.Subscriber = searchBox;
var clearButton = new GUIButton(new Rectangle(0,0,15,15), "x", Alignment.TopRight, GUI.Style, innerFrame);
clearButton.OnClicked = ClearFilter;
clearButton.UserData = searchBox;
listBox = new GUIListBox(new Rectangle(0,20,0,335), GUI.Style, innerFrame);
var currLines = lines.ToList();
@@ -92,6 +103,36 @@ namespace Barotrauma.Networking
textBlock.CanBeFocused = false;
}
private bool FilterMessages(GUITextBox textBox, string text)
{
if (string.IsNullOrWhiteSpace(text))
{
listBox.children.ForEach( c => c.Visible = true);
return true;
}
text = text.ToLower();
foreach (GUITextBlock textBlock in listBox.children)
{
if (textBlock == null) continue;
textBlock.Visible = textBlock.Text.ToLower().Contains(text);
}
return true;
}
public bool ClearFilter(GUIComponent button, object obj)
{
FilterMessages(null, "");
var searchBox = button.UserData as GUITextBox;
if (searchBox != null) searchBox.Text = "";
return true;
}
public void Save()
{
if (!Directory.Exists(SavePath))

View File

@@ -137,7 +137,18 @@ namespace Barotrauma
GUItabs[i] = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style);
GUItabs[i].Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
GUIListBox itemList = new GUIListBox(new Rectangle(0, 0, 0, 0), Color.White * 0.7f, GUI.Style, GUItabs[i]);
new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", GUI.Style, Alignment.TopRight, Alignment.TopRight, GUItabs[i], false, GUI.SmallFont);
GUITextBox searchBox = new GUITextBox(new Rectangle(-20, 0, 180, 15), Alignment.TopRight, GUI.Style, GUItabs[i]);
searchBox.Font = GUI.SmallFont;
searchBox.OnTextChanged = FilterMessages;
GUIComponent.KeyboardDispatcher.Subscriber = searchBox;
var clearButton = new GUIButton(new Rectangle(0, 0, 15, 15), "x", Alignment.TopRight, GUI.Style, GUItabs[i]);
clearButton.OnClicked = ClearFilter;
clearButton.UserData = searchBox;
GUIListBox itemList = new GUIListBox(new Rectangle(0, 20, 0, 0), Color.White * 0.7f, GUI.Style, GUItabs[i]);
itemList.OnSelected = SelectPrefab;
itemList.CheckSelected = MapEntityPrefab.GetSelected;
@@ -269,6 +280,8 @@ namespace Barotrauma
MapEntityPrefab.Selected = null;
MapEntity.DeselectAll();
if (characterMode) ToggleCharacterMode();
if (wiringMode) ToggleWiringMode();
@@ -425,9 +438,47 @@ namespace Barotrauma
private bool SelectTab(GUIButton button, object obj)
{
selectedTab = (int)obj;
ClearFilter(GUItabs[selectedTab].GetChild<GUIButton>(), null);
GUIComponent.KeyboardDispatcher.Subscriber = GUItabs[selectedTab].GetChild<GUITextBox>();
return true;
}
private bool FilterMessages(GUITextBox textBox, string text)
{
if (selectedTab == -1)
{
GUIComponent.KeyboardDispatcher.Subscriber = null;
return false;
}
if (string.IsNullOrWhiteSpace(text))
{
GUItabs[selectedTab].GetChild<GUIListBox>().children.ForEach(c => c.Visible = true);
return true;
}
text = text.ToLower();
foreach (GUIComponent child in GUItabs[selectedTab].GetChild<GUIListBox>().children)
{
child.Visible = child.GetChild<GUITextBlock>().Text.ToLower().Contains(text);
}
return true;
}
public bool ClearFilter(GUIComponent button, object obj)
{
FilterMessages(null, "");
var searchBox = button.UserData as GUITextBox;
if (searchBox != null) searchBox.Text = "";
return true;
}
public void ToggleCharacterMode()
{