Host can have subs spawn with more items

TODO: check if clients see the extra cargo, they probably don't
This commit is contained in:
juanjp600
2016-10-04 22:27:10 -03:00
parent 6f136c8daf
commit 4874ad2ef8
6 changed files with 243 additions and 40 deletions
+5 -2
View File
@@ -1,6 +1,8 @@
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System; using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma namespace Barotrauma
{ {
@@ -49,8 +51,9 @@ namespace Barotrauma
{ {
if (GameMain.Server != null) if (GameMain.Server != null)
{ {
string tryKey = GameMain.Server.monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower())); List<string> monsterNames = GameMain.Server.monsterEnabled.Keys.ToList();
if (tryKey != null) string tryKey = monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower()));
if (!string.IsNullOrWhiteSpace(tryKey))
{ {
if (!GameMain.Server.monsterEnabled[tryKey]) return; //spawn was disallowed by host if (!GameMain.Server.monsterEnabled[tryKey]) return; //spawn was disallowed by host
} }
+14
View File
@@ -116,6 +116,20 @@ namespace Barotrauma
} }
} }
public override Rectangle Rect
{
get
{
return rect;
}
set
{
frame.Rect = new Rectangle(value.X, value.Y, frame.Rect.Width, frame.Rect.Height);
textBlock.Rect = value;
rect = value;
}
}
public bool Selected { get; set; } public bool Selected { get; set; }
public GUIButton(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null) public GUIButton(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null)
+92 -32
View File
@@ -185,11 +185,101 @@ namespace Barotrauma
} }
} }
private void UpdateChildrenRect(float deltaTime)
{
int x = rect.X, y = rect.Y;
if (!scrollBarHidden)
{
if (scrollBar.IsHorizontal)
{
x -= (int)((totalSize - rect.Width) * scrollBar.BarScroll);
}
else
{
y -= (int)((totalSize - rect.Height) * scrollBar.BarScroll);
}
}
for (int i = 0; i < children.Count; i++)
{
GUIComponent child = children[i];
if (child == frame || !child.Visible) continue;
child.Rect = new Rectangle(x, y, child.Rect.Width, child.Rect.Height);
if (scrollBar.IsHorizontal)
{
x += child.Rect.Width + spacing;
}
else
{
y += child.Rect.Height + spacing;
}
if (scrollBar.IsHorizontal)
{
if (child.Rect.Right < rect.X) continue;
if (child.Rect.Right > rect.Right) break;
if (child.Rect.X < rect.X && child.Rect.Right >= rect.X)
{
x = rect.X;
continue;
}
}
else
{
if (child.Rect.Y + child.Rect.Height < rect.Y) continue;
if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) break;
if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y)
{
y = rect.Y;
continue;
}
}
if (deltaTime>0.0f) child.Update(deltaTime);
if (enabled && child.CanBeFocused &&
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
{
child.State = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Debug.WriteLine("clicked");
Select(i);
//selected = child;
//if (OnSelected != null)
//{
// if (!OnSelected(selected, child.UserData)) selected = null;
//}
}
}
else if (selected.Contains(child))
{
child.State = ComponentState.Selected;
if (CheckSelected != null)
{
if (CheckSelected() != child.UserData) selected.Remove(child);
}
}
else
{
child.State = ComponentState.None;
}
}
}
public override void Update(float deltaTime) public override void Update(float deltaTime)
{ {
if (!Visible) return; if (!Visible) return;
base.Update(deltaTime); UpdateChildrenRect(deltaTime);
//base.Update(deltaTime);
if (scrollBarEnabled && !scrollBarHidden) scrollBar.Update(deltaTime); if (scrollBarEnabled && !scrollBarHidden) scrollBar.Update(deltaTime);
@@ -258,6 +348,7 @@ namespace Barotrauma
//float oldScroll = scrollBar.BarScroll; //float oldScroll = scrollBar.BarScroll;
//float oldSize = scrollBar.BarSize; //float oldSize = scrollBar.BarSize;
UpdateScrollBarSize(); UpdateScrollBarSize();
UpdateChildrenRect(0.0f);
//if (oldSize == 1.0f && scrollBar.BarScroll == 0.0f) scrollBar.BarScroll = 1.0f; //if (oldSize == 1.0f && scrollBar.BarScroll == 0.0f) scrollBar.BarScroll = 1.0f;
@@ -325,7 +416,6 @@ namespace Barotrauma
GUIComponent child = children[i]; GUIComponent child = children[i];
if (child == frame || !child.Visible) continue; if (child == frame || !child.Visible) continue;
child.Rect = new Rectangle(x, y, child.Rect.Width, child.Rect.Height);
if (scrollBar.IsHorizontal) if (scrollBar.IsHorizontal)
{ {
x += child.Rect.Width + spacing; x += child.Rect.Width + spacing;
@@ -359,36 +449,6 @@ namespace Barotrauma
} }
} }
if (enabled && child.CanBeFocused &&
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
{
child.State = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Debug.WriteLine("clicked");
Select(i);
//selected = child;
//if (OnSelected != null)
//{
// if (!OnSelected(selected, child.UserData)) selected = null;
//}
}
}
else if (selected.Contains(child))
{
child.State = ComponentState.Selected;
if (CheckSelected != null)
{
if (CheckSelected() != child.UserData) selected.Remove(child);
}
}
else
{
child.State = ComponentState.None;
}
child.Draw(spriteBatch); child.Draw(spriteBatch);
} }
+7 -2
View File
@@ -61,7 +61,12 @@ namespace Barotrauma
set set
{ {
if (base.Rect == value) return; if (base.Rect == value) return;
base.Rect = value; foreach (GUIComponent child in children)
{
child.Rect = new Rectangle(child.Rect.X + value.X - rect.X, child.Rect.Y + value.Y - rect.Y, child.Rect.Width, child.Rect.Height);
}
rect = value;
SetTextPos(); SetTextPos();
} }
} }
@@ -163,7 +168,7 @@ namespace Barotrauma
} }
} }
private void SetTextPos() public void SetTextPos()
{ {
if (text==null) return; if (text==null) return;
@@ -960,6 +960,26 @@ namespace Barotrauma.Networking
} }
} }
foreach (Submarine sub in Submarine.Loaded)
{
WayPoint cargoSpawnPos = WayPoint.GetRandom(SpawnType.Cargo, null, sub);
var cargoRoom = cargoSpawnPos.CurrentHull;
Vector2 position = new Vector2(
cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, false),
cargoRoom.Rect.Y - cargoRoom.Rect.Height);
foreach (string s in extraCargo.Keys)
{
ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == s) as ItemPrefab;
for (int i = 0; i < extraCargo[s]; i++)
{
var item = new Item(itemPrefab, position, cargoRoom.Submarine);
item.FindHull();
Item.ItemList.Add(item);
}
}
}
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset); var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
@@ -46,8 +46,8 @@ namespace Barotrauma.Networking
private set; private set;
} }
public List<string> monsterNames;
public Dictionary<string, bool> monsterEnabled; public Dictionary<string, bool> monsterEnabled;
public Dictionary<string, int> extraCargo;
public bool ShowNetStats; public bool ShowNetStats;
@@ -258,7 +258,7 @@ namespace Barotrauma.Networking
showLogButton.Visible = SaveServerLogs; showLogButton.Visible = SaveServerLogs;
monsterNames = Directory.GetDirectories("Content/Characters").ToList(); List<string> monsterNames = Directory.GetDirectories("Content/Characters").ToList();
for (int i=0;i<monsterNames.Count;i++) for (int i=0;i<monsterNames.Count;i++)
{ {
monsterNames[i] = monsterNames[i].Replace("Content/Characters", "").Replace("/", "").Replace("\\", ""); monsterNames[i] = monsterNames[i].Replace("Content/Characters", "").Replace("/", "").Replace("\\", "");
@@ -268,6 +268,7 @@ namespace Barotrauma.Networking
{ {
monsterEnabled.Add(s, true); monsterEnabled.Add(s, true);
} }
extraCargo = new Dictionary<string, int>();
} }
private void CreateSettingsFrame() private void CreateSettingsFrame()
@@ -448,9 +449,16 @@ namespace Barotrauma.Networking
monsterButton.UserData = monsterFrame; monsterButton.UserData = monsterFrame;
monsterButton.OnClicked = (button, obj) => monsterButton.OnClicked = (button, obj) =>
{ {
if (gameStarted)
{
((GUIComponent)obj).Visible = false;
button.Enabled = false;
return true;
}
((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible;
return true; return true;
}; };
List<string> monsterNames = monsterEnabled.Keys.ToList();
foreach (string s in monsterNames) foreach (string s in monsterNames)
{ {
GUITextBlock textBlock = new GUITextBlock( GUITextBlock textBlock = new GUITextBlock(
@@ -466,14 +474,107 @@ namespace Barotrauma.Networking
monsterEnabledBox.Selected = monsterEnabled[s]; monsterEnabledBox.Selected = monsterEnabled[s];
monsterEnabledBox.OnSelected = (GUITickBox) => monsterEnabledBox.OnSelected = (GUITickBox) =>
{ {
if (gameStarted)
{
monsterFrame.Visible = false;
monsterButton.Enabled = false;
return true;
}
monsterEnabled[s] = !monsterEnabled[s]; monsterEnabled[s] = !monsterEnabled[s];
return true; return true;
}; };
} }
var cargoButton = new GUIButton(new Rectangle(160, y, 130, 20), "Additional Cargo", GUI.Style, settingsTabs[0]); var cargoButton = new GUIButton(new Rectangle(160, y, 130, 20), "Additional Cargo", GUI.Style, settingsTabs[0]);
cargoButton.Enabled = !GameStarted; cargoButton.Enabled = !GameStarted;
var cargoFrame = new GUIListBox(new Rectangle(300, 60, 280, 250), GUI.Style, settingsTabs[0]);
cargoFrame.Visible = false;
cargoButton.UserData = cargoFrame;
cargoButton.OnClicked = (button, obj) =>
{
if (gameStarted)
{
((GUIComponent)obj).Visible = false;
button.Enabled = false;
return true;
}
((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible;
return true;
};
foreach (MapEntityCategory category in Enum.GetValues(typeof(MapEntityCategory)))
{
if (category == MapEntityCategory.Machine || category == MapEntityCategory.Structure) continue;
var items = MapEntityPrefab.list.FindAll(ep => ep.Price > 0.0f && ep.Category.HasFlag(category));
foreach (MapEntityPrefab pf in items)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 260, 25),
pf.Name,
GUI.Style,
Alignment.Left, Alignment.Left, cargoFrame);
textBlock.Padding = new Vector4(30.0f, 3.0f, 0.0f, 0.0f);
textBlock.UserData = cargoFrame;
textBlock.CanBeFocused = false;
if (pf.sprite != null)
{
float scale = Math.Min(Math.Min(30.0f / pf.sprite.SourceRect.Width, 30.0f / pf.sprite.SourceRect.Height), 1.0f);
GUIImage img = new GUIImage(new Rectangle(-15-(int)(pf.sprite.SourceRect.Width*scale*0.5f), 12-(int)(pf.sprite.SourceRect.Height*scale*0.5f), 40, 40), pf.sprite, Alignment.Left, textBlock);
img.Color = pf.SpriteColor;
img.Scale = scale;
}
int cargoVal = 0;
extraCargo.TryGetValue(pf.Name, out cargoVal);
var countText = new GUITextBlock(
new Rectangle(180, 0, 50, 25),
cargoVal.ToString(),
GUI.Style,
Alignment.Left, Alignment.Center, textBlock);
var incButton = new GUIButton(new Rectangle(220, 5, 10, 15), ">", GUI.Style, textBlock);
incButton.UserData = countText;
incButton.OnClicked = (button, obj) =>
{
int val;
if (extraCargo.TryGetValue(pf.Name, out val))
{
extraCargo[pf.Name]++; val = extraCargo[pf.Name];
}
else
{
extraCargo.Add(pf.Name,1); val = 1;
}
((GUITextBlock)obj).Text = val.ToString();
((GUITextBlock)obj).SetTextPos();
return true;
};
var decButton = new GUIButton(new Rectangle(180, 5, 10, 15), "<", GUI.Style, textBlock);
decButton.UserData = countText;
decButton.OnClicked = (button, obj) =>
{
int val;
if (extraCargo.TryGetValue(pf.Name, out val))
{
extraCargo[pf.Name]--;
val = extraCargo[pf.Name];
if (val <= 0)
{
extraCargo.Remove(pf.Name);
val = 0;
}
((GUITextBlock)obj).Text = val.ToString();
((GUITextBlock)obj).SetTextPos();
}
return true;
};
}
}
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// server settings // server settings
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------