Moved the whitelist UI to server settings, GUITextBoxes can't be selected through other UI elements anymore

This commit is contained in:
Regalis
2016-09-05 18:12:56 +03:00
parent 59c3773995
commit 53b3ef533e
5 changed files with 67 additions and 94 deletions

View File

@@ -223,26 +223,6 @@ namespace Barotrauma
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)
{
Character.DisableControls = true;
@@ -268,6 +248,24 @@ namespace Barotrauma
{
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);
if (!CaretEnabled) return;

View File

@@ -115,11 +115,6 @@ namespace Barotrauma.Networking
settingsButton.UserData = "settingsButton";
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();
LoadSettings();
@@ -288,7 +283,6 @@ namespace Barotrauma.Networking
{
if (ShowNetStats) netStats.Update(deltaTime);
if (settingsFrame != null) settingsFrame.Update(deltaTime);
if (whitelist.WhiteListFrame != null) whitelist.WhiteListFrame.Update(deltaTime);
if (!started) return;
@@ -1305,10 +1299,6 @@ namespace Barotrauma.Networking
log.LogFrame.Update(0.016f);
log.LogFrame.Draw(spriteBatch);
}
else if (whitelist.WhiteListFrame != null)
{
whitelist.WhiteListFrame.Draw(spriteBatch);
}
if (!ShowNetStats) return;

View File

@@ -265,14 +265,14 @@ namespace Barotrauma.Networking
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];
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].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.OnClicked = SelectSettingsTab;
}
@@ -524,6 +524,12 @@ namespace Barotrauma.Networking
banList.CreateBanFrame(settingsTabs[2]);
//--------------------------------------------------------------------------------
// whitelist
//--------------------------------------------------------------------------------
whitelist.CreateWhiteListFrame(settingsTabs[3]);
}
@@ -647,21 +653,7 @@ namespace Barotrauma.Networking
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)
{
GUIListBox cList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, GUI.Style, infoFrame);

View File

@@ -30,21 +30,15 @@ namespace Barotrauma.Networking
}
private GUIComponent whitelistFrame;
private GUIComponent innerlistFrame;
private GUITextBox nameBox;
private GUITextBox ipBox;
public bool enabled;
public GUIComponent WhiteListFrame
{
get { return whitelistFrame; }
}
public bool Enabled;
public WhiteList()
{
enabled = false;
Enabled = false;
whitelistedPlayers = new List<WhiteListedPlayer>();
if (File.Exists(SavePath))
@@ -69,11 +63,11 @@ namespace Barotrauma.Networking
Int32.TryParse(lineval, out intVal);
if (lineval.ToLower() == "true" || intVal != 0)
{
enabled = true;
Enabled = true;
}
else
{
enabled = false;
Enabled = false;
}
}
else
@@ -96,7 +90,7 @@ namespace Barotrauma.Networking
List<string> lines = new List<string>();
if (enabled)
if (Enabled)
{
lines.Add("#true");
}
@@ -121,56 +115,57 @@ namespace Barotrauma.Networking
public bool IsWhiteListed(string name, string ip)
{
if (!enabled) return true;
if (!Enabled) return true;
WhiteListedPlayer wlp = whitelistedPlayers.Find(p => p.Name == name);
if (wlp == null) return false;
if (wlp.IP != ip && !string.IsNullOrWhiteSpace(wlp.IP)) return false;
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);
innerFrame.Padding = new Vector4(20.0f, 50.0f, 20.0f, 100.0f);
parent.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
var closeButton = new GUIButton(new Rectangle(0, 85, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
closeButton.OnClicked = GameMain.Server.ToggleWhiteListFrame;
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;
var enabledTick = new GUITickBox(new Rectangle(0, 0, 20, 20), "Enabled", Alignment.TopLeft, parent);
enabledTick.Selected = Enabled;
enabledTick.OnSelected = (GUITickBox box) =>
{
enabled = !enabled;
if (enabled)
Enabled = !Enabled;
if (Enabled)
{
foreach (Client c in GameMain.Server.ConnectedClients)
{
if (!IsWhiteListed(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();
return true;
};
new GUITextBlock(new Rectangle(0, 35, 90, 25), "Name:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, innerFrame, false, GUI.Font);
nameBox = new GUITextBox(new Rectangle(100, 30, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
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, -25, 170, 20), Alignment.BottomLeft, GUI.Style, parent);
nameBox.Font = GUI.Font;
new GUITextBlock(new Rectangle(0, 65, 90, 25), "IP Address:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, innerFrame, false, GUI.Font);
ipBox = new GUITextBox(new Rectangle(100, 60, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
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, 5, 170, 20), Alignment.BottomLeft, GUI.Style, parent);
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;
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)
{
@@ -180,7 +175,7 @@ namespace Barotrauma.Networking
new Rectangle(0, 0, 0, 25),
blockText,
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.UserData = wlp;
@@ -188,8 +183,8 @@ namespace Barotrauma.Networking
removeButton.UserData = wlp;
removeButton.OnClicked = RemoveFromWhiteList;
}
return whitelistFrame;
return parent;
}
private bool RemoveFromWhiteList(GUIButton button, object obj)
@@ -202,7 +197,12 @@ namespace Barotrauma.Networking
whitelistedPlayers.Remove(wlp);
Save();
CloseFrame(); CreateWhiteListFrame();
if (whitelistFrame != null)
{
whitelistFrame.Parent.ClearChildren();
CreateWhiteListFrame(whitelistFrame.Parent);
}
return true;
}
@@ -210,17 +210,14 @@ namespace Barotrauma.Networking
private bool AddToWhiteList(GUIButton button, object obj)
{
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));
Save();
CloseFrame(); CreateWhiteListFrame();
return true;
}
public bool CloseFrame(GUIButton button=null, object obj=null)
{
whitelistFrame = null;
if (whitelistFrame != null)
{
CreateWhiteListFrame(whitelistFrame.Parent);
}
return true;
}
}

View File

@@ -398,10 +398,6 @@ namespace Barotrauma
settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame;
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 (shuttleList.Selected == null)
{