Moved the whitelist UI to server settings, GUITextBoxes can't be selected through other UI elements anymore
This commit is contained in:
@@ -223,26 +223,6 @@ namespace Barotrauma
|
|||||||
caretVisible = ((caretTimer * 1000.0f) % 1000) < 500;
|
caretVisible = ((caretTimer * 1000.0f) % 1000) < 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rect.Contains(PlayerInput.MousePosition))
|
|
||||||
{
|
|
||||||
|
|
||||||
state = ComponentState.Hover;
|
|
||||||
if (PlayerInput.LeftButtonClicked())
|
|
||||||
{
|
|
||||||
if (MouseOn != null && MouseOn != this && MouseOn!=textBlock && !MouseOn.IsParentOf(this)) return;
|
|
||||||
|
|
||||||
Select();
|
|
||||||
if (OnSelected != null) OnSelected(this, Keys.None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state = ComponentState.None;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
textBlock.State = state;
|
|
||||||
|
|
||||||
if (keyboardDispatcher.Subscriber == this)
|
if (keyboardDispatcher.Subscriber == this)
|
||||||
{
|
{
|
||||||
Character.DisableControls = true;
|
Character.DisableControls = true;
|
||||||
@@ -268,6 +248,24 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (!Visible) return;
|
if (!Visible) return;
|
||||||
|
|
||||||
|
if (rect.Contains(PlayerInput.MousePosition) && Enabled &&
|
||||||
|
(MouseOn == null || MouseOn == this || IsParentOf(MouseOn) || MouseOn.IsParentOf(this)))
|
||||||
|
{
|
||||||
|
|
||||||
|
state = ComponentState.Hover;
|
||||||
|
if (PlayerInput.LeftButtonClicked())
|
||||||
|
{
|
||||||
|
Select();
|
||||||
|
if (OnSelected != null) OnSelected(this, Keys.None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state = ComponentState.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
textBlock.State = state;
|
||||||
|
|
||||||
DrawChildren(spriteBatch);
|
DrawChildren(spriteBatch);
|
||||||
|
|
||||||
if (!CaretEnabled) return;
|
if (!CaretEnabled) return;
|
||||||
|
|||||||
@@ -115,11 +115,6 @@ namespace Barotrauma.Networking
|
|||||||
settingsButton.UserData = "settingsButton";
|
settingsButton.UserData = "settingsButton";
|
||||||
|
|
||||||
whitelist = new WhiteList();
|
whitelist = new WhiteList();
|
||||||
|
|
||||||
GUIButton whitelistButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170 - 170 - 170 - 170, 20, 150, 20), "Whitelist", Alignment.TopLeft, GUI.Style, inGameHUD);
|
|
||||||
whitelistButton.OnClicked = ToggleWhiteListFrame;
|
|
||||||
whitelistButton.UserData = "whitelistButton";
|
|
||||||
|
|
||||||
banList = new BanList();
|
banList = new BanList();
|
||||||
|
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
@@ -288,7 +283,6 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (ShowNetStats) netStats.Update(deltaTime);
|
if (ShowNetStats) netStats.Update(deltaTime);
|
||||||
if (settingsFrame != null) settingsFrame.Update(deltaTime);
|
if (settingsFrame != null) settingsFrame.Update(deltaTime);
|
||||||
if (whitelist.WhiteListFrame != null) whitelist.WhiteListFrame.Update(deltaTime);
|
|
||||||
|
|
||||||
if (!started) return;
|
if (!started) return;
|
||||||
|
|
||||||
@@ -1305,10 +1299,6 @@ namespace Barotrauma.Networking
|
|||||||
log.LogFrame.Update(0.016f);
|
log.LogFrame.Update(0.016f);
|
||||||
log.LogFrame.Draw(spriteBatch);
|
log.LogFrame.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
else if (whitelist.WhiteListFrame != null)
|
|
||||||
{
|
|
||||||
whitelist.WhiteListFrame.Draw(spriteBatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ShowNetStats) return;
|
if (!ShowNetStats) return;
|
||||||
|
|
||||||
|
|||||||
@@ -265,14 +265,14 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, -5, 0, 20), "Settings", GUI.Style, innerFrame, GUI.LargeFont);
|
new GUITextBlock(new Rectangle(0, -5, 0, 20), "Settings", GUI.Style, innerFrame, GUI.LargeFont);
|
||||||
|
|
||||||
string[] tabNames = { "Rounds", "Server", "Banlist" };
|
string[] tabNames = { "Rounds", "Server", "Banlist", "Whitelist" };
|
||||||
settingsTabs = new GUIFrame[tabNames.Length];
|
settingsTabs = new GUIFrame[tabNames.Length];
|
||||||
for (int i = 0; i < tabNames.Length; i++)
|
for (int i = 0; i < tabNames.Length; i++)
|
||||||
{
|
{
|
||||||
settingsTabs[i] = new GUIFrame(new Rectangle(0, 15, 0, innerFrame.Rect.Height - 120), null, Alignment.Center, GUI.Style, innerFrame);
|
settingsTabs[i] = new GUIFrame(new Rectangle(0, 15, 0, innerFrame.Rect.Height - 120), null, Alignment.Center, GUI.Style, innerFrame);
|
||||||
settingsTabs[i].Padding = new Vector4(40.0f, 20.0f, 40.0f, 40.0f);
|
settingsTabs[i].Padding = new Vector4(40.0f, 20.0f, 40.0f, 40.0f);
|
||||||
|
|
||||||
var tabButton = new GUIButton(new Rectangle(105 * i, 35, 100, 20), tabNames[i], GUI.Style, innerFrame);
|
var tabButton = new GUIButton(new Rectangle(85 * i, 35, 80, 20), tabNames[i], GUI.Style, innerFrame);
|
||||||
tabButton.UserData = i;
|
tabButton.UserData = i;
|
||||||
tabButton.OnClicked = SelectSettingsTab;
|
tabButton.OnClicked = SelectSettingsTab;
|
||||||
}
|
}
|
||||||
@@ -525,6 +525,12 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
banList.CreateBanFrame(settingsTabs[2]);
|
banList.CreateBanFrame(settingsTabs[2]);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// whitelist
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
whitelist.CreateWhiteListFrame(settingsTabs[3]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadClientPermissions()
|
public void LoadClientPermissions()
|
||||||
@@ -648,20 +654,6 @@ namespace Barotrauma.Networking
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ToggleWhiteListFrame(GUIButton button, object obj)
|
|
||||||
{
|
|
||||||
if (whitelist.WhiteListFrame == null)
|
|
||||||
{
|
|
||||||
whitelist.CreateWhiteListFrame();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
whitelist.CloseFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ManagePlayersFrame(GUIFrame infoFrame)
|
public void ManagePlayersFrame(GUIFrame infoFrame)
|
||||||
{
|
{
|
||||||
GUIListBox cList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, GUI.Style, infoFrame);
|
GUIListBox cList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, GUI.Style, infoFrame);
|
||||||
|
|||||||
@@ -30,21 +30,15 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GUIComponent whitelistFrame;
|
private GUIComponent whitelistFrame;
|
||||||
private GUIComponent innerlistFrame;
|
|
||||||
|
|
||||||
private GUITextBox nameBox;
|
private GUITextBox nameBox;
|
||||||
private GUITextBox ipBox;
|
private GUITextBox ipBox;
|
||||||
|
|
||||||
public bool enabled;
|
public bool Enabled;
|
||||||
|
|
||||||
public GUIComponent WhiteListFrame
|
|
||||||
{
|
|
||||||
get { return whitelistFrame; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public WhiteList()
|
public WhiteList()
|
||||||
{
|
{
|
||||||
enabled = false;
|
Enabled = false;
|
||||||
whitelistedPlayers = new List<WhiteListedPlayer>();
|
whitelistedPlayers = new List<WhiteListedPlayer>();
|
||||||
|
|
||||||
if (File.Exists(SavePath))
|
if (File.Exists(SavePath))
|
||||||
@@ -69,11 +63,11 @@ namespace Barotrauma.Networking
|
|||||||
Int32.TryParse(lineval, out intVal);
|
Int32.TryParse(lineval, out intVal);
|
||||||
if (lineval.ToLower() == "true" || intVal != 0)
|
if (lineval.ToLower() == "true" || intVal != 0)
|
||||||
{
|
{
|
||||||
enabled = true;
|
Enabled = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
enabled = false;
|
Enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -96,7 +90,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
|
|
||||||
if (enabled)
|
if (Enabled)
|
||||||
{
|
{
|
||||||
lines.Add("#true");
|
lines.Add("#true");
|
||||||
}
|
}
|
||||||
@@ -121,56 +115,57 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public bool IsWhiteListed(string name, string ip)
|
public bool IsWhiteListed(string name, string ip)
|
||||||
{
|
{
|
||||||
if (!enabled) return true;
|
if (!Enabled) return true;
|
||||||
WhiteListedPlayer wlp = whitelistedPlayers.Find(p => p.Name == name);
|
WhiteListedPlayer wlp = whitelistedPlayers.Find(p => p.Name == name);
|
||||||
if (wlp == null) return false;
|
if (wlp == null) return false;
|
||||||
if (wlp.IP != ip && !string.IsNullOrWhiteSpace(wlp.IP)) return false;
|
if (wlp.IP != ip && !string.IsNullOrWhiteSpace(wlp.IP)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUIComponent CreateWhiteListFrame()
|
public GUIComponent CreateWhiteListFrame(GUIComponent parent)
|
||||||
{
|
{
|
||||||
whitelistFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f);
|
if (whitelistFrame!=null)
|
||||||
|
{
|
||||||
|
whitelistFrame.Parent.ClearChildren();
|
||||||
|
whitelistFrame = null;
|
||||||
|
}
|
||||||
|
|
||||||
GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 500, 430), null, Alignment.Center, GUI.Style, whitelistFrame);
|
parent.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||||
innerFrame.Padding = new Vector4(20.0f, 50.0f, 20.0f, 100.0f);
|
|
||||||
|
|
||||||
var closeButton = new GUIButton(new Rectangle(0, 85, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
|
var enabledTick = new GUITickBox(new Rectangle(0, 0, 20, 20), "Enabled", Alignment.TopLeft, parent);
|
||||||
closeButton.OnClicked = GameMain.Server.ToggleWhiteListFrame;
|
enabledTick.Selected = Enabled;
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, -35, 200, 20), "Whitelist", GUI.Style, innerFrame, GUI.LargeFont);
|
|
||||||
var enabledTick = new GUITickBox(new Rectangle(200, -30, 20, 20), "Enabled", Alignment.Left, innerFrame);
|
|
||||||
enabledTick.Selected = enabled;
|
|
||||||
enabledTick.OnSelected = (GUITickBox box) =>
|
enabledTick.OnSelected = (GUITickBox box) =>
|
||||||
{
|
{
|
||||||
enabled = !enabled;
|
Enabled = !Enabled;
|
||||||
if (enabled)
|
|
||||||
|
if (Enabled)
|
||||||
{
|
{
|
||||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||||
{
|
{
|
||||||
if (!IsWhiteListed(c.name,c.Connection.RemoteEndPoint.Address.ToString()))
|
if (!IsWhiteListed(c.name,c.Connection.RemoteEndPoint.Address.ToString()))
|
||||||
{
|
{
|
||||||
whitelistedPlayers.Add(new WhiteListedPlayer(c.name, c.Connection.RemoteEndPoint.Address.ToString()));
|
whitelistedPlayers.Add(new WhiteListedPlayer(c.name, c.Connection.RemoteEndPoint.Address.ToString()));
|
||||||
CloseFrame(); CreateWhiteListFrame();
|
if (whitelistFrame != null) CreateWhiteListFrame(whitelistFrame.Parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Save();
|
Save();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, 35, 90, 25), "Name:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, innerFrame, false, GUI.Font);
|
new GUITextBlock(new Rectangle(0, -25, 90, 20), "Name:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, parent, false, GUI.Font);
|
||||||
nameBox = new GUITextBox(new Rectangle(100, 30, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
|
nameBox = new GUITextBox(new Rectangle(100, -25, 170, 20), Alignment.BottomLeft, GUI.Style, parent);
|
||||||
nameBox.Font = GUI.Font;
|
nameBox.Font = GUI.Font;
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, 65, 90, 25), "IP Address:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, innerFrame, false, GUI.Font);
|
new GUITextBlock(new Rectangle(0, 5, 90, 20), "IP Address:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, parent, false, GUI.Font);
|
||||||
ipBox = new GUITextBox(new Rectangle(100, 60, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
|
ipBox = new GUITextBox(new Rectangle(100, 5, 170, 20), Alignment.BottomLeft, GUI.Style, parent);
|
||||||
ipBox.Font = GUI.Font;
|
ipBox.Font = GUI.Font;
|
||||||
|
|
||||||
var addnewButton = new GUIButton(new Rectangle(300, 45, 150, 20), "Add to whitelist", Alignment.BottomLeft, GUI.Style, innerFrame);
|
var addnewButton = new GUIButton(new Rectangle(0, 45, 150, 20), "Add to whitelist", Alignment.BottomLeft, GUI.Style, parent);
|
||||||
addnewButton.OnClicked = AddToWhiteList;
|
addnewButton.OnClicked = AddToWhiteList;
|
||||||
|
|
||||||
innerlistFrame = new GUIListBox(new Rectangle(0, 0, 0, 0), GUI.Style, innerFrame);
|
whitelistFrame = new GUIListBox(new Rectangle(0, 30, 0, parent.Rect.Height-100), GUI.Style, parent);
|
||||||
|
|
||||||
foreach (WhiteListedPlayer wlp in whitelistedPlayers)
|
foreach (WhiteListedPlayer wlp in whitelistedPlayers)
|
||||||
{
|
{
|
||||||
@@ -180,7 +175,7 @@ namespace Barotrauma.Networking
|
|||||||
new Rectangle(0, 0, 0, 25),
|
new Rectangle(0, 0, 0, 25),
|
||||||
blockText,
|
blockText,
|
||||||
GUI.Style,
|
GUI.Style,
|
||||||
Alignment.Left, Alignment.Left, innerlistFrame);
|
Alignment.Left, Alignment.Left, whitelistFrame);
|
||||||
textBlock.Padding = new Vector4(10.0f, 10.0f, 0.0f, 0.0f);
|
textBlock.Padding = new Vector4(10.0f, 10.0f, 0.0f, 0.0f);
|
||||||
textBlock.UserData = wlp;
|
textBlock.UserData = wlp;
|
||||||
|
|
||||||
@@ -189,7 +184,7 @@ namespace Barotrauma.Networking
|
|||||||
removeButton.OnClicked = RemoveFromWhiteList;
|
removeButton.OnClicked = RemoveFromWhiteList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return whitelistFrame;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool RemoveFromWhiteList(GUIButton button, object obj)
|
private bool RemoveFromWhiteList(GUIButton button, object obj)
|
||||||
@@ -202,7 +197,12 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
whitelistedPlayers.Remove(wlp);
|
whitelistedPlayers.Remove(wlp);
|
||||||
Save();
|
Save();
|
||||||
CloseFrame(); CreateWhiteListFrame();
|
|
||||||
|
if (whitelistFrame != null)
|
||||||
|
{
|
||||||
|
whitelistFrame.Parent.ClearChildren();
|
||||||
|
CreateWhiteListFrame(whitelistFrame.Parent);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -210,17 +210,14 @@ namespace Barotrauma.Networking
|
|||||||
private bool AddToWhiteList(GUIButton button, object obj)
|
private bool AddToWhiteList(GUIButton button, object obj)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(nameBox.Text)) return false;
|
if (string.IsNullOrWhiteSpace(nameBox.Text)) return false;
|
||||||
if (whitelistedPlayers.Find(x => x.Name.ToLower() == nameBox.Text.ToLower() && x.IP == ipBox.Text) != null) return false;
|
if (whitelistedPlayers.Any(x => x.Name.ToLower() == nameBox.Text.ToLower() && x.IP == ipBox.Text)) return false;
|
||||||
whitelistedPlayers.Add(new WhiteListedPlayer(nameBox.Text,ipBox.Text));
|
whitelistedPlayers.Add(new WhiteListedPlayer(nameBox.Text,ipBox.Text));
|
||||||
Save();
|
Save();
|
||||||
CloseFrame(); CreateWhiteListFrame();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CloseFrame(GUIButton button=null, object obj=null)
|
|
||||||
{
|
|
||||||
whitelistFrame = null;
|
|
||||||
|
|
||||||
|
if (whitelistFrame != null)
|
||||||
|
{
|
||||||
|
CreateWhiteListFrame(whitelistFrame.Parent);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -398,10 +398,6 @@ namespace Barotrauma
|
|||||||
settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame;
|
settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame;
|
||||||
settingsButton.UserData = "settingsButton";
|
settingsButton.UserData = "settingsButton";
|
||||||
|
|
||||||
GUIButton whitelistButton = new GUIButton(new Rectangle(-200, 0, 80, 30), "Whitelist", Alignment.BottomRight, GUI.Style, infoFrame);
|
|
||||||
whitelistButton.OnClicked = GameMain.Server.ToggleWhiteListFrame;
|
|
||||||
whitelistButton.UserData = "whitelistButton";
|
|
||||||
|
|
||||||
if (subList.Selected == null) subList.Select(Math.Max(0, prevSelectedSub));
|
if (subList.Selected == null) subList.Select(Math.Max(0, prevSelectedSub));
|
||||||
if (shuttleList.Selected == null)
|
if (shuttleList.Selected == null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user