private GUINumberInput CreateLabeledNumberInput(GUIComponent parent, string labelTag, int min, int max, string toolTipTag = null) { var container = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), parent.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f, ToolTip = TextManager.Get(labelTag) }; var label = new GUITextBlock(new RectTransform(new Vector2(0.7f, 1.0f), container.RectTransform), TextManager.Get(labelTag), textAlignment: Alignment.CenterLeft, font: GUI.SmallFont) { AutoScaleHorizontal = true }; if (!string.IsNullOrEmpty(toolTipTag)) { label.ToolTip = TextManager.Get(toolTipTag); } var input = new GUINumberInput(new RectTransform(new Vector2(0.3f, 1.0f), container.RectTransform), GUINumberInput.NumberType.Int) { MinValueInt = min, MaxValueInt = max }; container.RectTransform.MinSize = new Point(0, input.RectTransform.MinSize.Y); container.RectTransform.MaxSize = new Point(int.MaxValue, input.RectTransform.MaxSize.Y); return(input); }
public void CreateKickReasonPrompt(string clientName, bool ban, bool rangeBan = false) { var banReasonPrompt = new GUIMessageBox(ban ? "Reason for the ban?" : "Reason for kicking?", "", new string[] { "OK", "Cancel" }, 400, 300); var banReasonBox = new GUITextBox(new Rectangle(0, 30, 0, 50), Alignment.TopCenter, "", banReasonPrompt.children[0]); banReasonBox.Wrap = true; banReasonBox.MaxTextLength = 100; GUINumberInput durationInputDays = null, durationInputHours = null; GUITickBox permaBanTickBox = null; if (ban) { new GUITextBlock(new Rectangle(0, 80, 0, 0), "Duration:", "", banReasonPrompt.children[0]); permaBanTickBox = new GUITickBox(new Rectangle(0, 110, 15, 15), "Permanent", Alignment.TopLeft, banReasonPrompt.children[0]); permaBanTickBox.Selected = true; var durationContainer = new GUIFrame(new Rectangle(0, 130, 0, 40), null, banReasonPrompt.children[0]); durationContainer.Visible = false; permaBanTickBox.OnSelected += (tickBox) => { durationContainer.Visible = !tickBox.Selected; return(true); }; new GUITextBlock(new Rectangle(0, 0, 30, 20), "Days:", "", Alignment.TopLeft, Alignment.CenterLeft, durationContainer); durationInputDays = new GUINumberInput(new Rectangle(40, 0, 50, 20), "", GUINumberInput.NumberType.Int, durationContainer); durationInputDays.MinValueInt = 0; durationInputDays.MaxValueFloat = 1000; new GUITextBlock(new Rectangle(100, 0, 30, 20), "Hours:", "", Alignment.TopLeft, Alignment.CenterLeft, durationContainer); durationInputHours = new GUINumberInput(new Rectangle(150, 0, 50, 20), "", GUINumberInput.NumberType.Int, durationContainer); durationInputDays.MinValueInt = 0; durationInputDays.MaxValueFloat = 24; } banReasonPrompt.Buttons[0].OnClicked += (btn, userData) => { if (ban) { if (!permaBanTickBox.Selected) { TimeSpan banDuration = new TimeSpan(durationInputDays.IntValue, durationInputHours.IntValue, 0, 0); BanPlayer(clientName, banReasonBox.Text, ban, banDuration); } else { BanPlayer(clientName, banReasonBox.Text, ban); } } else { KickPlayer(clientName, banReasonBox.Text); } return(true); }; banReasonPrompt.Buttons[0].OnClicked += banReasonPrompt.Close; banReasonPrompt.Buttons[1].OnClicked += banReasonPrompt.Close; }
private static GUINumberInput CreateFloatEntry(string label, float defaultValue, RectTransform parent) { GUILayoutGroup layout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.08f), parent), isHorizontal: true); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), layout.RectTransform), label); GUINumberInput input = new GUINumberInput(new RectTransform(new Vector2(0.5f, 1f), layout.RectTransform), GUINumberInput.NumberType.Float) { FloatValue = defaultValue, DecimalsToDisplay = 2 }; return(input); }
private static GUINumberInput[] CreateMinMaxEntry(string label, float[] values, float max, RectTransform parent, float min = 0f) { GUILayoutGroup layout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.08f), parent), isHorizontal: true); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), layout.RectTransform), label); GUINumberInput[] inputs = new GUINumberInput[values.Length]; for (var i = 0; i < values.Length; i++) { float value = values[i]; GUINumberInput input = new GUINumberInput(new RectTransform(new Vector2(0.5f / values.Length, 1f), layout.RectTransform), GUINumberInput.NumberType.Float) { FloatValue = value, DecimalsToDisplay = 2, MinValueFloat = min, MaxValueFloat = max }; inputs[i] = input; } return(inputs); }
public void CreateDebugHUD(Planter planter, PlantSlot slot) { Vector2 relativeSize = new Vector2(0.3f, 0.6f); GUIMessageBox msgBox = new GUIMessageBox(item.Name, "", new[] { TextManager.Get("applysettingsbutton") }, relativeSize); GUILayoutGroup content = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.85f), msgBox.Content.RectTransform)) { Stretch = true }; GUINumberInput seedInput = CreateIntEntry("Random Seed", seed, content.RectTransform); GUINumberInput vineTileSizeInput = CreateIntEntry("Vine Tile Size (Global)", VineTile.Size, content.RectTransform); GUINumberInput[] leafScaleRangeInput = CreateMinMaxEntry("Leaf Scale Range (Global)", new [] { MinLeafScale, MaxLeafScale }, 1.5f, content.RectTransform); GUINumberInput[] flowerScaleRangeInput = CreateMinMaxEntry("Flower Scale Range (Global)", new [] { MinFlowerScale, MaxFlowerScale }, 1.5f, content.RectTransform); GUINumberInput vineCountInput = CreateIntEntry("Vine Count", MaximumVines, content.RectTransform); GUINumberInput vineScaleInput = CreateFloatEntry("Vine Scale", VineScale, content.RectTransform); GUINumberInput flowerInput = CreateIntEntry("Flower Quantity", FlowerQuantity, content.RectTransform); GUINumberInput flowerScaleInput = CreateFloatEntry("Flower Scale", BaseFlowerScale, content.RectTransform); GUINumberInput leafScaleInput = CreateFloatEntry("Leaf Scale", BaseLeafScale, content.RectTransform); GUINumberInput leafProbabilityInput = CreateFloatEntry("Leaf Probability", LeafProbability, content.RectTransform); GUINumberInput[] leafTintInputs = CreateMinMaxEntry("Leaf Tint", new [] { LeafTint.R / 255f, LeafTint.G / 255f, LeafTint.B / 255f }, 1.0f, content.RectTransform); GUINumberInput[] flowerTintInputs = CreateMinMaxEntry("Flower Tint", new [] { FlowerTint.R / 255f, FlowerTint.G / 255f, FlowerTint.B / 255f }, 1.0f, content.RectTransform); GUINumberInput[] vineTintInputs = CreateMinMaxEntry("Branch Tint", new [] { VineTint.R / 255f, VineTint.G / 255f, VineTint.B / 255f }, 1.0f, content.RectTransform); // Apply msgBox.Buttons[0].OnClicked = (button, o) => { seed = seedInput.IntValue; MaximumVines = vineCountInput.IntValue; FlowerQuantity = flowerInput.IntValue; BaseFlowerScale = flowerScaleInput.FloatValue; VineScale = vineScaleInput.FloatValue; BaseLeafScale = leafScaleInput.FloatValue; LeafProbability = leafProbabilityInput.FloatValue; VineTile.Size = vineTileSizeInput.IntValue; MinFlowerScale = flowerScaleRangeInput[0].FloatValue; MaxFlowerScale = flowerScaleRangeInput[1].FloatValue; MinLeafScale = leafScaleRangeInput[0].FloatValue; MaxLeafScale = leafScaleRangeInput[1].FloatValue; LeafTint = new Color(leafTintInputs[0].FloatValue, leafTintInputs[1].FloatValue, leafTintInputs[2].FloatValue); FlowerTint = new Color(flowerTintInputs[0].FloatValue, flowerTintInputs[1].FloatValue, flowerTintInputs[2].FloatValue); VineTint = new Color(vineTintInputs[0].FloatValue, vineTintInputs[1].FloatValue, vineTintInputs[2].FloatValue); if (FlowerQuantity >= MaximumVines - 1) { vineCountInput.Flash(Color.Red); flowerInput.Flash(Color.Red); return(false); } if (MinFlowerScale > MaxFlowerScale) { foreach (GUINumberInput input in flowerScaleRangeInput) { input.Flash(Color.Red); } return(false); } if (MinLeafScale > MaxLeafScale) { foreach (GUINumberInput input in leafScaleRangeInput) { input.Flash(Color.Red); } return(false); } msgBox.Close(); Random random = new Random(seed); Random flowerRandom = new Random(seed); Vines.Clear(); GenerateFlowerTiles(flowerRandom); GenerateStem(); Decayed = false; FullyGrown = false; while (MaximumVines > Vines.Count) { if (!CanGrowMore()) { Decayed = true; break; } TryGenerateBranches(planter, slot, random, flowerRandom); } if (!Decayed) { FullyGrown = true; } foreach (VineTile vineTile in Vines) { vineTile.GrowthStep = 2.0f; } return(true); }; }
public void CreateKickReasonPrompt(string clientName, bool ban, bool rangeBan = false) { var banReasonPrompt = new GUIMessageBox( TextManager.Get(ban ? "BanReasonPrompt" : "KickReasonPrompt"), "", new string[] { TextManager.Get("OK"), TextManager.Get("Cancel") }, 400, 300); var content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.6f), banReasonPrompt.InnerFrame.RectTransform, Anchor.Center)); var banReasonBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.3f), content.RectTransform)) { Wrap = true, MaxTextLength = 100 }; GUINumberInput durationInputDays = null, durationInputHours = null; GUITickBox permaBanTickBox = null; if (ban) { new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.15f), content.RectTransform), TextManager.Get("BanDuration")); permaBanTickBox = new GUITickBox(new RectTransform(new Vector2(0.8f, 0.15f), content.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.0f) }, TextManager.Get("BanPermanent")) { Selected = true }; var durationContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.15f), content.RectTransform), isHorizontal: true) { Visible = false }; permaBanTickBox.OnSelected += (tickBox) => { durationContainer.Visible = !tickBox.Selected; return(true); }; durationInputDays = new GUINumberInput(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), GUINumberInput.NumberType.Int) { MinValueInt = 0, MaxValueFloat = 1000 }; new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), TextManager.Get("Days")); durationInputHours = new GUINumberInput(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), GUINumberInput.NumberType.Int) { MinValueInt = 0, MaxValueFloat = 24 }; new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), TextManager.Get("Hours")); } banReasonPrompt.Buttons[0].OnClicked += (btn, userData) => { if (ban) { if (!permaBanTickBox.Selected) { TimeSpan banDuration = new TimeSpan(durationInputDays.IntValue, durationInputHours.IntValue, 0, 0); BanPlayer(clientName, banReasonBox.Text, ban, banDuration); } else { BanPlayer(clientName, banReasonBox.Text, ban); } } else { KickPlayer(clientName, banReasonBox.Text); } return(true); }; banReasonPrompt.Buttons[0].OnClicked += banReasonPrompt.Close; banReasonPrompt.Buttons[1].OnClicked += banReasonPrompt.Close; }
private void CreateSettingsFrame() { foreach (NetPropertyData prop in netProperties.Values) { prop.TempValue = prop.Value; } //background frame settingsFrame = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: null, color: Color.Black * 0.5f); new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null).OnClicked += (btn, userData) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) { ToggleSettingsFrame(btn, userData); } return(true); }; new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null) { OnClicked = ToggleSettingsFrame }; //center frames GUIFrame innerFrame = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.75f), settingsFrame.RectTransform, Anchor.Center) { MinSize = new Point(400, 430) }); GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center), style: null); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), paddedFrame.RectTransform), TextManager.Get("Settings"), font: GUI.LargeFont); var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), paddedFrame.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.1f) }, isHorizontal: true) { Stretch = true, RelativeSpacing = 0.01f }; //tabs var tabValues = Enum.GetValues(typeof(SettingsTab)).Cast <SettingsTab>().ToArray(); string[] tabNames = new string[tabValues.Count()]; for (int i = 0; i < tabNames.Length; i++) { tabNames[i] = TextManager.Get("ServerSettings" + tabValues[i] + "Tab"); } settingsTabs = new GUIFrame[tabNames.Length]; tabButtons = new GUIButton[tabNames.Length]; for (int i = 0; i < tabNames.Length; i++) { settingsTabs[i] = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.79f), paddedFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.05f) }, style: "InnerFrame"); tabButtons[i] = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform), tabNames[i], style: "GUITabButton") { UserData = i, OnClicked = SelectSettingsTab }; } GUITextBlock.AutoScaleAndNormalize(tabButtons.Select(b => b.TextBlock)); SelectSettingsTab(tabButtons[0], 0); //"Close" var closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), paddedFrame.RectTransform, Anchor.BottomRight), TextManager.Get("Close")) { OnClicked = ToggleSettingsFrame }; //-------------------------------------------------------------------------------- // server settings //-------------------------------------------------------------------------------- var serverTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.General].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; //*********************************************** new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsSubSelection")); var selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; GUIRadioButtonGroup selectionMode = new GUIRadioButtonGroup(); for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), TextManager.Get(((SelectionMode)i).ToString()), font: GUI.SmallFont); selectionMode.AddRadioButton((SelectionMode)i, selectionTick); } DebugConsole.NewMessage(SubSelectionMode.ToString(), Color.White); GetPropertyData("SubSelectionMode").AssignGUIComponent(selectionMode); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsModeSelection")); selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; selectionMode = new GUIRadioButtonGroup(); for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), TextManager.Get(((SelectionMode)i).ToString()), font: GUI.SmallFont); selectionMode.AddRadioButton((SelectionMode)i, selectionTick); } GetPropertyData("ModeSelectionMode").AssignGUIComponent(selectionMode); //*********************************************** var voiceChatEnabled = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsVoiceChatEnabled")); GetPropertyData("VoiceChatEnabled").AssignGUIComponent(voiceChatEnabled); //*********************************************** string autoRestartDelayLabel = TextManager.Get("ServerSettingsAutoRestartDelay") + " "; var startIntervalText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), autoRestartDelayLabel); var startIntervalSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), barSize: 0.1f) { UserData = startIntervalText, Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; text.Text = autoRestartDelayLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); return(true); } }; startIntervalSlider.Range = new Vector2(10.0f, 300.0f); GetPropertyData("AutoRestartInterval").AssignGUIComponent(startIntervalSlider); startIntervalSlider.OnMoved(startIntervalSlider, startIntervalSlider.BarScroll); //*********************************************** var startWhenClientsReady = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsStartWhenClientsReady")); GetPropertyData("StartWhenClientsReady").AssignGUIComponent(startWhenClientsReady); CreateLabeledSlider(serverTab, "ServerSettingsStartWhenClientsReadyRatio", out GUIScrollBar slider, out GUITextBlock sliderLabel); string clientsReadyRequiredLabel = sliderLabel.Text; slider.Step = 0.2f; slider.Range = new Vector2(0.5f, 1.0f); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = clientsReadyRequiredLabel.Replace("[percentage]", ((int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f)).ToString()); return(true); }; GetPropertyData("StartWhenClientsReadyRatio").AssignGUIComponent(slider); slider.OnMoved(slider, slider.BarScroll); //*********************************************** var allowSpecBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowSpectating")); GetPropertyData("AllowSpectating").AssignGUIComponent(allowSpecBox); var shareSubsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsShareSubFiles")); GetPropertyData("AllowFileTransfers").AssignGUIComponent(shareSubsBox); var randomizeLevelBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsRandomizeSeed")); GetPropertyData("RandomizeSeed").AssignGUIComponent(randomizeLevelBox); var saveLogsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsSaveLogs")) { OnSelected = (GUITickBox) => { //TODO: fix? //showLogButton.Visible = SaveServerLogs; return(true); } }; GetPropertyData("SaveServerLogs").AssignGUIComponent(saveLogsBox); //-------------------------------------------------------------------------------- // game settings //-------------------------------------------------------------------------------- var roundsTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; var endBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsEndRoundWhenDestReached")); GetPropertyData("EndRoundAtLevelEnd").AssignGUIComponent(endBox); var endVoteBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsEndRoundVoting")); GetPropertyData("AllowEndVoting").AssignGUIComponent(endVoteBox); CreateLabeledSlider(roundsTab, "ServerSettingsEndRoundVotesRequired", out slider, out sliderLabel); string endRoundLabel = sliderLabel.Text; slider.Step = 0.2f; slider.Range = new Vector2(0.5f, 1.0f); GetPropertyData("EndVoteRequiredRatio").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = endRoundLabel + " " + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %"; return(true); }; slider.OnMoved(slider, slider.BarScroll); var respawnBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsAllowRespawning")); GetPropertyData("AllowRespawn").AssignGUIComponent(respawnBox); CreateLabeledSlider(roundsTab, "ServerSettingsRespawnInterval", out slider, out sliderLabel); string intervalLabel = sliderLabel.Text; slider.Step = 0.05f; slider.Range = new Vector2(10.0f, 600.0f); GetPropertyData("RespawnInterval").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; text.Text = intervalLabel + " " + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); return(true); }; slider.OnMoved(slider, slider.BarScroll); var minRespawnText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "") { ToolTip = TextManager.Get("ServerSettingsMinRespawnToolTip") }; string minRespawnLabel = TextManager.Get("ServerSettingsMinRespawn") + " "; CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel); slider.ToolTip = minRespawnText.ToolTip; slider.UserData = minRespawnText; slider.Step = 0.1f; slider.Range = new Vector2(0.0f, 1.0f); GetPropertyData("MinRespawnRatio").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = minRespawnLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %"; return(true); }; slider.OnMoved(slider, MinRespawnRatio); var respawnDurationText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "") { ToolTip = TextManager.Get("ServerSettingsRespawnDurationToolTip") }; string respawnDurationLabel = TextManager.Get("ServerSettingsRespawnDuration") + " "; CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel); slider.ToolTip = respawnDurationText.ToolTip; slider.UserData = respawnDurationText; slider.Step = 0.1f; slider.Range = new Vector2(60.0f, 660.0f); slider.ScrollToValue = (GUIScrollBar scrollBar, float barScroll) => { return(barScroll >= 1.0f ? 0.0f : barScroll *(scrollBar.Range.Y - scrollBar.Range.X) + scrollBar.Range.X); }; slider.ValueToScroll = (GUIScrollBar scrollBar, float value) => { return(value <= 0.0f ? 1.0f : (value - scrollBar.Range.X) / (scrollBar.Range.Y - scrollBar.Range.X)); }; GetPropertyData("MaxTransportTime").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { if (barScroll == 1.0f) { ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + TextManager.Get("Unlimited"); } else { ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); } return(true); }; slider.OnMoved(slider, slider.BarScroll); var ragdollButtonBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsAllowRagdollButton")); GetPropertyData("AllowRagdollButton").AssignGUIComponent(ragdollButtonBox); /*var traitorRatioBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsUseTraitorRatio")); * * CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel); * var traitorRatioSlider = slider; * traitorRatioBox.OnSelected = (GUITickBox) => * { * traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll); * return true; * }; * * if (TraitorUseRatio) * { * traitorRatioSlider.Range = new Vector2(0.1f, 1.0f); * } * else * { * traitorRatioSlider.Range = new Vector2(1.0f, maxPlayers); * } * * string traitorRatioLabel = TextManager.Get("ServerSettingsTraitorRatio") + " "; * string traitorCountLabel = TextManager.Get("ServerSettingsTraitorCount") + " "; * * traitorRatioSlider.Range = new Vector2(0.1f, 1.0f); * traitorRatioSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => * { * GUITextBlock traitorText = scrollBar.UserData as GUITextBlock; * if (traitorRatioBox.Selected) * { * scrollBar.Step = 0.01f; * scrollBar.Range = new Vector2(0.1f, 1.0f); * traitorText.Text = traitorRatioLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 1.0f) + " %"; * } * else * { * scrollBar.Step = 1f / (maxPlayers - 1); * scrollBar.Range = new Vector2(1.0f, maxPlayers); * traitorText.Text = traitorCountLabel + scrollBar.BarScrollValue; * } * return true; * }; * * GetPropertyData("TraitorUseRatio").AssignGUIComponent(traitorRatioBox); * GetPropertyData("TraitorRatio").AssignGUIComponent(traitorRatioSlider); * * traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll); * traitorRatioBox.OnSelected(traitorRatioBox);*/ var buttonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), roundsTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; var monsterButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform), TextManager.Get("ServerSettingsMonsterSpawns")) { Enabled = !GameMain.NetworkMember.GameStarted }; var monsterFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomLeft, Pivot.BottomRight)) { Visible = false }; monsterButton.UserData = monsterFrame; monsterButton.OnClicked = (button, obj) => { if (GameMain.NetworkMember.GameStarted) { ((GUIComponent)obj).Visible = false; button.Enabled = false; return(true); } ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; return(true); }; InitMonstersEnabled(); List <string> monsterNames = MonsterEnabled.Keys.ToList(); tempMonsterEnabled = new Dictionary <string, bool>(MonsterEnabled); foreach (string s in monsterNames) { string translatedLabel = TextManager.Get($"Character.{s}", true); var monsterEnabledBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), monsterFrame.Content.RectTransform) { MinSize = new Point(0, 25) }, label: translatedLabel ?? s) { Selected = tempMonsterEnabled[s], OnSelected = (GUITickBox tb) => { tempMonsterEnabled[s] = tb.Selected; return(true); } }; } var cargoButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform), TextManager.Get("ServerSettingsAdditionalCargo")) { Enabled = !GameMain.NetworkMember.GameStarted }; var cargoFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomRight, Pivot.BottomLeft)) { Visible = false }; cargoButton.UserData = cargoFrame; cargoButton.OnClicked = (button, obj) => { if (GameMain.NetworkMember.GameStarted) { ((GUIComponent)obj).Visible = false; button.Enabled = false; return(true); } ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; return(true); }; GUITextBlock.AutoScaleAndNormalize(buttonHolder.Children.Select(c => ((GUIButton)c).TextBlock)); foreach (ItemPrefab ip in MapEntityPrefab.List.Where(p => p is ItemPrefab).Select(p => p as ItemPrefab)) { if (!ip.CanBeBought && !ip.Tags.Contains("smallitem")) { continue; } var itemFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), cargoFrame.Content.RectTransform) { MinSize = new Point(0, 30) }, isHorizontal: true) { Stretch = true, UserData = cargoFrame, RelativeSpacing = 0.05f }; if (ip.InventoryIcon != null || ip.sprite != null) { GUIImage img = new GUIImage(new RectTransform(new Point(itemFrame.Rect.Height), itemFrame.RectTransform), ip.InventoryIcon ?? ip.sprite, scaleToFit: true) { CanBeFocused = false }; img.Color = img.Sprite == ip.InventoryIcon ? ip.InventoryIconColor : ip.SpriteColor; } new GUITextBlock(new RectTransform(new Vector2(0.75f, 1.0f), itemFrame.RectTransform), ip.Name, font: GUI.SmallFont) { Wrap = true, CanBeFocused = false }; ExtraCargo.TryGetValue(ip, out int cargoVal); var amountInput = new GUINumberInput(new RectTransform(new Vector2(0.35f, 1.0f), itemFrame.RectTransform), GUINumberInput.NumberType.Int, textAlignment: Alignment.CenterLeft) { MinValueInt = 0, MaxValueInt = 100, IntValue = cargoVal }; amountInput.OnValueChanged += (numberInput) => { if (ExtraCargo.ContainsKey(ip)) { ExtraCargo[ip] = numberInput.IntValue; if (numberInput.IntValue <= 0) { ExtraCargo.Remove(ip); } } else { ExtraCargo.Add(ip, numberInput.IntValue); } }; } //-------------------------------------------------------------------------------- // antigriefing //-------------------------------------------------------------------------------- var antigriefingTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Antigriefing].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; var voteKickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform), TextManager.Get("ServerSettingsAllowVoteKick")); GetPropertyData("AllowVoteKick").AssignGUIComponent(voteKickBox); CreateLabeledSlider(antigriefingTab, "ServerSettingsKickVotesRequired", out slider, out sliderLabel); string votesRequiredLabel = sliderLabel.Text + " "; slider.Step = 0.2f; slider.Range = new Vector2(0.5f, 1.0f); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = votesRequiredLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %"; return(true); }; GetPropertyData("KickVoteRequiredRatio").AssignGUIComponent(slider); slider.OnMoved(slider, slider.BarScroll); CreateLabeledSlider(antigriefingTab, "ServerSettingsAutobanTime", out slider, out sliderLabel); string autobanLabel = sliderLabel.Text + " "; slider.Step = 0.01f; slider.Range = new Vector2(0.0f, MaxAutoBanTime); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = autobanLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); return(true); }; GetPropertyData("AutoBanTime").AssignGUIComponent(slider); slider.OnMoved(slider, slider.BarScroll); // karma -------------------------------------------------------------------------- var karmaBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform), TextManager.Get("ServerSettingsUseKarma")); GetPropertyData("KarmaEnabled").AssignGUIComponent(karmaBox); karmaPresetDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform)); foreach (string karmaPreset in GameMain.NetworkMember.KarmaManager.Presets.Keys) { karmaPresetDD.AddItem(TextManager.Get("KarmaPreset." + karmaPreset), karmaPreset); } var karmaSettingsContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), antigriefingTab.RectTransform), style: null); var karmaSettingsList = new GUIListBox(new RectTransform(Vector2.One, karmaSettingsContainer.RectTransform)); karmaSettingsBlocker = new GUIFrame(new RectTransform(Vector2.One, karmaSettingsContainer.RectTransform, Anchor.CenterLeft) { MaxSize = new Point(karmaSettingsList.Content.Rect.Width, int.MaxValue) }, style: "InnerFrame"); karmaPresetDD.OnSelected = (selected, obj) => { List <NetPropertyData> properties = netProperties.Values.ToList(); List <object> prevValues = new List <object>(); foreach (NetPropertyData prop in netProperties.Values) { prevValues.Add(prop.TempValue); if (prop.GUIComponent != null) { prop.Value = prop.GUIComponentValue; } } if (KarmaPreset == "custom") { GameMain.NetworkMember?.KarmaManager?.SaveCustomPreset(); GameMain.NetworkMember?.KarmaManager?.Save(); } KarmaPreset = obj as string; GameMain.NetworkMember.KarmaManager.SelectPreset(KarmaPreset); karmaSettingsList.Content.ClearChildren(); karmaSettingsBlocker.Visible = !karmaBox.Selected || KarmaPreset != "custom"; GameMain.NetworkMember.KarmaManager.CreateSettingsFrame(karmaSettingsList.Content); for (int i = 0; i < netProperties.Count; i++) { properties[i].TempValue = prevValues[i]; } return(true); }; karmaPresetDD.SelectItem(KarmaPreset); AssignGUIComponent("KarmaPreset", karmaPresetDD); karmaBox.OnSelected = (tb) => { karmaSettingsBlocker.Visible = !tb.Selected || KarmaPreset != "custom"; return(true); }; //-------------------------------------------------------------------------------- // banlist //-------------------------------------------------------------------------------- BanList.CreateBanFrame(settingsTabs[(int)SettingsTab.Banlist]); //-------------------------------------------------------------------------------- // whitelist //-------------------------------------------------------------------------------- Whitelist.CreateWhiteListFrame(settingsTabs[(int)SettingsTab.Whitelist]); }
private void CreateSettingsFrame() { settingsFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, null); GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 400, 430), null, Alignment.Center, "", settingsFrame); innerFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); new GUITextBlock(new Rectangle(0, -5, 0, 20), "Settings", "", innerFrame, GUI.LargeFont); 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, "InnerFrame", innerFrame); settingsTabs[i].Padding = new Vector4(40.0f, 20.0f, 40.0f, 40.0f); var tabButton = new GUIButton(new Rectangle(85 * i, 35, 80, 20), tabNames[i], "", innerFrame); tabButton.UserData = i; tabButton.OnClicked = SelectSettingsTab; } settingsTabs[2].Padding = Vector4.Zero; SelectSettingsTab(null, 0); var closeButton = new GUIButton(new Rectangle(10, 0, 100, 20), "Close", Alignment.BottomRight, "", innerFrame); closeButton.OnClicked = ToggleSettingsFrame; //-------------------------------------------------------------------------------- // game settings //-------------------------------------------------------------------------------- int y = 0; settingsTabs[0].Padding = new Vector4(40.0f, 5.0f, 40.0f, 40.0f); new GUITextBlock(new Rectangle(0, y, 100, 20), "Submarine selection:", "", settingsTabs[0]); var selectionFrame = new GUIFrame(new Rectangle(0, y + 20, 300, 20), null, settingsTabs[0]); for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new Rectangle(i * 100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame); selectionTick.Selected = i == (int)subSelectionMode; selectionTick.OnSelected = SwitchSubSelection; selectionTick.UserData = (SelectionMode)i; } y += 45; new GUITextBlock(new Rectangle(0, y, 100, 20), "Mode selection:", "", settingsTabs[0]); selectionFrame = new GUIFrame(new Rectangle(0, y + 20, 300, 20), null, settingsTabs[0]); for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new Rectangle(i * 100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame); selectionTick.Selected = i == (int)modeSelectionMode; selectionTick.OnSelected = SwitchModeSelection; selectionTick.UserData = (SelectionMode)i; } y += 60; var endBox = new GUITickBox(new Rectangle(0, y, 20, 20), "End round when destination reached", Alignment.Left, settingsTabs[0]); endBox.Selected = EndRoundAtLevelEnd; endBox.OnSelected = (GUITickBox) => { EndRoundAtLevelEnd = GUITickBox.Selected; return(true); }; y += 25; var endVoteBox = new GUITickBox(new Rectangle(0, y, 20, 20), "End round by voting", Alignment.Left, settingsTabs[0]); endVoteBox.Selected = Voting.AllowEndVoting; endVoteBox.OnSelected = (GUITickBox) => { Voting.AllowEndVoting = !Voting.AllowEndVoting; GameMain.Server.UpdateVoteStatus(); return(true); }; var votesRequiredText = new GUITextBlock(new Rectangle(20, y + 15, 20, 20), "Votes required: 50 %", "", settingsTabs[0], GUI.SmallFont); var votesRequiredSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[0]); votesRequiredSlider.UserData = votesRequiredText; votesRequiredSlider.Step = 0.2f; votesRequiredSlider.BarScroll = (EndVoteRequiredRatio - 0.5f) * 2.0f; votesRequiredSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock voteText = scrollBar.UserData as GUITextBlock; EndVoteRequiredRatio = barScroll / 2.0f + 0.5f; voteText.Text = "Votes required: " + (int)MathUtils.Round(EndVoteRequiredRatio * 100.0f, 10.0f) + " %"; return(true); }; votesRequiredSlider.OnMoved(votesRequiredSlider, votesRequiredSlider.BarScroll); y += 35; var respawnBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow respawning", Alignment.Left, settingsTabs[0]); respawnBox.Selected = AllowRespawn; respawnBox.OnSelected = (GUITickBox) => { AllowRespawn = !AllowRespawn; return(true); }; var respawnIntervalText = new GUITextBlock(new Rectangle(20, y + 13, 20, 20), "Respawn interval", "", settingsTabs[0], GUI.SmallFont); var respawnIntervalSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 15), "", 0.1f, settingsTabs[0]); respawnIntervalSlider.UserData = respawnIntervalText; respawnIntervalSlider.Step = 0.05f; respawnIntervalSlider.BarScroll = RespawnInterval / 600.0f; respawnIntervalSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; RespawnInterval = Math.Max(barScroll * 600.0f, 10.0f); text.Text = "Interval: " + ToolBox.SecondsToReadableTime(RespawnInterval); return(true); }; respawnIntervalSlider.OnMoved(respawnIntervalSlider, respawnIntervalSlider.BarScroll); y += 35; var minRespawnText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Minimum players to respawn", "", settingsTabs[0]); minRespawnText.ToolTip = "What percentage of players has to be dead/spectating until a respawn shuttle is dispatched"; var minRespawnSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 15), "", 0.1f, settingsTabs[0]); minRespawnSlider.ToolTip = minRespawnText.ToolTip; minRespawnSlider.UserData = minRespawnText; minRespawnSlider.Step = 0.1f; minRespawnSlider.BarScroll = MinRespawnRatio; minRespawnSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock txt = scrollBar.UserData as GUITextBlock; MinRespawnRatio = barScroll; txt.Text = "Minimum players to respawn: " + (int)MathUtils.Round(MinRespawnRatio * 100.0f, 10.0f) + " %"; return(true); }; minRespawnSlider.OnMoved(minRespawnSlider, MinRespawnRatio); y += 30; var respawnDurationText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Duration of respawn transport", "", settingsTabs[0]); respawnDurationText.ToolTip = "The amount of time respawned players have to navigate the respawn shuttle to the main submarine. " + "After the duration expires, the shuttle will automatically head back out of the level."; var respawnDurationSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 15), "", 0.1f, settingsTabs[0]); respawnDurationSlider.ToolTip = minRespawnText.ToolTip; respawnDurationSlider.UserData = respawnDurationText; respawnDurationSlider.Step = 0.1f; respawnDurationSlider.BarScroll = MaxTransportTime <= 0.0f ? 1.0f : (MaxTransportTime - 60.0f) / 600.0f; respawnDurationSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock txt = scrollBar.UserData as GUITextBlock; if (barScroll == 1.0f) { MaxTransportTime = 0; txt.Text = "Duration of respawn transport: unlimited"; } else { MaxTransportTime = barScroll * 600.0f + 60.0f; txt.Text = "Duration of respawn transport: " + ToolBox.SecondsToReadableTime(MaxTransportTime); } return(true); }; respawnDurationSlider.OnMoved(respawnDurationSlider, respawnDurationSlider.BarScroll); y += 35; var monsterButton = new GUIButton(new Rectangle(0, y, 130, 20), "Monster Spawns", "", settingsTabs[0]); monsterButton.Enabled = !GameStarted; var monsterFrame = new GUIListBox(new Rectangle(-290, 60, 280, 250), "", settingsTabs[0]); monsterFrame.Visible = false; monsterButton.UserData = monsterFrame; monsterButton.OnClicked = (button, obj) => { if (gameStarted) { ((GUIComponent)obj).Visible = false; button.Enabled = false; return(true); } ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; return(true); }; List <string> monsterNames = monsterEnabled.Keys.ToList(); foreach (string s in monsterNames) { GUITextBlock textBlock = new GUITextBlock( new Rectangle(0, 0, 260, 25), s, "", Alignment.Left, Alignment.Left, monsterFrame); textBlock.Padding = new Vector4(35.0f, 3.0f, 0.0f, 0.0f); textBlock.UserData = monsterFrame; textBlock.CanBeFocused = false; var monsterEnabledBox = new GUITickBox(new Rectangle(-25, 0, 20, 20), "", Alignment.Left, textBlock); monsterEnabledBox.Selected = monsterEnabled[s]; monsterEnabledBox.OnSelected = (GUITickBox) => { if (gameStarted) { monsterFrame.Visible = false; monsterButton.Enabled = false; return(true); } monsterEnabled[s] = !monsterEnabled[s]; return(true); }; } var cargoButton = new GUIButton(new Rectangle(160, y, 130, 20), "Additional Cargo", "", settingsTabs[0]); cargoButton.Enabled = !GameStarted; var cargoFrame = new GUIListBox(new Rectangle(300, 60, 280, 250), "", 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 (MapEntityPrefab pf in MapEntityPrefab.List) { if (!(pf is ItemPrefab) || (pf.Price <= 0.0f && !pf.Tags.Contains("smallitem"))) { continue; } GUITextBlock textBlock = new GUITextBlock( new Rectangle(0, 0, 260, 25), pf.Name, "", Alignment.Left, Alignment.CenterLeft, cargoFrame, false, GUI.SmallFont); textBlock.Padding = new Vector4(40.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(-20 - (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 amountInput = new GUINumberInput(new Rectangle(160, 0, 50, 20), "", GUINumberInput.NumberType.Int, textBlock); amountInput.MinValueInt = 0; amountInput.MaxValueInt = 100; amountInput.IntValue = cargoVal; amountInput.OnValueChanged += (numberInput) => { if (extraCargo.ContainsKey(pf.Name)) { extraCargo[pf.Name] = numberInput.IntValue; } else { extraCargo.Add(pf.Name, numberInput.IntValue); } }; } //-------------------------------------------------------------------------------- // server settings //-------------------------------------------------------------------------------- y = 0; var startIntervalText = new GUITextBlock(new Rectangle(-10, y, 100, 20), "Autorestart delay", "", settingsTabs[1]); var startIntervalSlider = new GUIScrollBar(new Rectangle(10, y + 22, 100, 15), "", 0.1f, settingsTabs[1]); startIntervalSlider.UserData = startIntervalText; startIntervalSlider.Step = 0.05f; startIntervalSlider.BarScroll = AutoRestartInterval / 300.0f; startIntervalSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; AutoRestartInterval = Math.Max(barScroll * 300.0f, 10.0f); text.Text = "Autorestart delay: " + ToolBox.SecondsToReadableTime(AutoRestartInterval); return(true); }; startIntervalSlider.OnMoved(startIntervalSlider, startIntervalSlider.BarScroll); y += 45; var allowSpecBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow spectating", Alignment.Left, settingsTabs[1]); allowSpecBox.Selected = AllowSpectating; allowSpecBox.OnSelected = (GUITickBox) => { AllowSpectating = GUITickBox.Selected; GameMain.NetLobbyScreen.LastUpdateID++; return(true); }; y += 40; var voteKickBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow vote kicking", Alignment.Left, settingsTabs[1]); voteKickBox.Selected = Voting.AllowVoteKick; voteKickBox.OnSelected = (GUITickBox) => { Voting.AllowVoteKick = !Voting.AllowVoteKick; GameMain.Server.UpdateVoteStatus(); return(true); }; var kickVotesRequiredText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), "Votes required: 50 %", "", settingsTabs[1], GUI.SmallFont); var kickVoteSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[1]); kickVoteSlider.UserData = kickVotesRequiredText; kickVoteSlider.Step = 0.2f; kickVoteSlider.BarScroll = (KickVoteRequiredRatio - 0.5f) * 2.0f; kickVoteSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock voteText = scrollBar.UserData as GUITextBlock; KickVoteRequiredRatio = barScroll / 2.0f + 0.5f; voteText.Text = "Votes required: " + (int)MathUtils.Round(KickVoteRequiredRatio * 100.0f, 10.0f) + " %"; return(true); }; kickVoteSlider.OnMoved(kickVoteSlider, kickVoteSlider.BarScroll); y += 45; var shareSubsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Share submarine files with players", Alignment.Left, settingsTabs[1]); shareSubsBox.Selected = AllowFileTransfers; shareSubsBox.OnSelected = (GUITickBox) => { AllowFileTransfers = GUITickBox.Selected; return(true); }; y += 40; var randomizeLevelBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Randomize level seed between rounds", Alignment.Left, settingsTabs[1]); randomizeLevelBox.Selected = RandomizeSeed; randomizeLevelBox.OnSelected = (GUITickBox) => { RandomizeSeed = GUITickBox.Selected; return(true); }; y += 40; var saveLogsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Save server logs", Alignment.Left, settingsTabs[1]); saveLogsBox.Selected = SaveServerLogs; saveLogsBox.OnSelected = (GUITickBox) => { SaveServerLogs = GUITickBox.Selected; showLogButton.Visible = SaveServerLogs; return(true); }; //-------------------------------------------------------------------------------- // banlist //-------------------------------------------------------------------------------- banList.CreateBanFrame(settingsTabs[2]); //-------------------------------------------------------------------------------- // whitelist //-------------------------------------------------------------------------------- whitelist.CreateWhiteListFrame(settingsTabs[3]); }
private void CreateSettingsFrame() { foreach (NetPropertyData prop in netProperties.Values) { prop.TempValue = prop.Value; } //background frame settingsFrame = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null); new GUIFrame(new RectTransform(GUI.Canvas.RelativeSize, settingsFrame.RectTransform, Anchor.Center), style: "GUIBackgroundBlocker"); new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null).OnClicked += (btn, userData) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) { ToggleSettingsFrame(btn, userData); } return(true); }; new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null) { OnClicked = ToggleSettingsFrame }; //center frames GUIFrame innerFrame = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.8f), settingsFrame.RectTransform, Anchor.Center) { MinSize = new Point(400, 430) }); GUILayoutGroup paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), innerFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter) { Stretch = true, RelativeSpacing = 0.02f }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform), TextManager.Get("Settings"), font: GUI.LargeFont); var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.04f), paddedFrame.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.01f }; var tabContent = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.85f), paddedFrame.RectTransform), style: "InnerFrame"); //tabs var tabValues = Enum.GetValues(typeof(SettingsTab)).Cast <SettingsTab>().ToArray(); string[] tabNames = new string[tabValues.Count()]; for (int i = 0; i < tabNames.Length; i++) { tabNames[i] = TextManager.Get("ServerSettings" + tabValues[i] + "Tab"); } settingsTabs = new GUIFrame[tabNames.Length]; tabButtons = new GUIButton[tabNames.Length]; for (int i = 0; i < tabNames.Length; i++) { settingsTabs[i] = new GUIFrame(new RectTransform(Vector2.One, tabContent.RectTransform, Anchor.Center), style: null); tabButtons[i] = new GUIButton(new RectTransform(new Vector2(0.2f, 1.2f), buttonArea.RectTransform), tabNames[i], style: "GUITabButton") { UserData = i, OnClicked = SelectSettingsTab }; } GUITextBlock.AutoScaleAndNormalize(tabButtons.Select(b => b.TextBlock)); SelectSettingsTab(tabButtons[0], 0); //"Close" var buttonContainer = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.05f), paddedFrame.RectTransform), style: null); var closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), buttonContainer.RectTransform, Anchor.BottomRight), TextManager.Get("Close")) { OnClicked = ToggleSettingsFrame }; //-------------------------------------------------------------------------------- // server settings //-------------------------------------------------------------------------------- var serverTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.General].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.01f }; //*********************************************** // Sub Selection new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), serverTab.RectTransform), TextManager.Get("ServerSettingsSubSelection"), font: GUI.SubHeadingFont); var selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.02f), serverTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; GUIRadioButtonGroup selectionMode = new GUIRadioButtonGroup(); for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), TextManager.Get(((SelectionMode)i).ToString()), font: GUI.SmallFont, style: "GUIRadioButton"); selectionMode.AddRadioButton(i, selectionTick); } selectionFrame.RectTransform.NonScaledSize = new Point(selectionFrame.Rect.Width, selectionFrame.Children.First().Rect.Height); selectionFrame.RectTransform.IsFixedSize = true; GetPropertyData("SubSelectionMode").AssignGUIComponent(selectionMode); // Mode Selection new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), serverTab.RectTransform), TextManager.Get("ServerSettingsModeSelection"), font: GUI.SubHeadingFont); selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.02f), serverTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; selectionMode = new GUIRadioButtonGroup(); for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), TextManager.Get(((SelectionMode)i).ToString()), font: GUI.SmallFont, style: "GUIRadioButton"); selectionMode.AddRadioButton(i, selectionTick); } selectionFrame.RectTransform.NonScaledSize = new Point(selectionFrame.Rect.Width, selectionFrame.Children.First().Rect.Height); selectionFrame.RectTransform.IsFixedSize = true; GetPropertyData("ModeSelectionMode").AssignGUIComponent(selectionMode); new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), serverTab.RectTransform), style: "HorizontalLine"); //*********************************************** var voiceChatEnabled = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsVoiceChatEnabled")); GetPropertyData("VoiceChatEnabled").AssignGUIComponent(voiceChatEnabled); //*********************************************** string autoRestartDelayLabel = TextManager.Get("ServerSettingsAutoRestartDelay") + " "; var startIntervalText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), serverTab.RectTransform), autoRestartDelayLabel); var startIntervalSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), barSize: 0.1f, style: "GUISlider") { UserData = startIntervalText, Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; text.Text = autoRestartDelayLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); return(true); } }; startIntervalSlider.Range = new Vector2(10.0f, 300.0f); GetPropertyData("AutoRestartInterval").AssignGUIComponent(startIntervalSlider); startIntervalSlider.OnMoved(startIntervalSlider, startIntervalSlider.BarScroll); //*********************************************** var startWhenClientsReady = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsStartWhenClientsReady")); GetPropertyData("StartWhenClientsReady").AssignGUIComponent(startWhenClientsReady); CreateLabeledSlider(serverTab, "ServerSettingsStartWhenClientsReadyRatio", out GUIScrollBar slider, out GUITextBlock sliderLabel); string clientsReadyRequiredLabel = sliderLabel.Text; slider.Step = 0.2f; slider.Range = new Vector2(0.5f, 1.0f); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = clientsReadyRequiredLabel.Replace("[percentage]", ((int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f)).ToString()); return(true); }; GetPropertyData("StartWhenClientsReadyRatio").AssignGUIComponent(slider); slider.OnMoved(slider, slider.BarScroll); //*********************************************** var allowSpecBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowSpectating")); GetPropertyData("AllowSpectating").AssignGUIComponent(allowSpecBox); var shareSubsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsShareSubFiles")); GetPropertyData("AllowFileTransfers").AssignGUIComponent(shareSubsBox); var randomizeLevelBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsRandomizeSeed")); GetPropertyData("RandomizeSeed").AssignGUIComponent(randomizeLevelBox); var saveLogsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsSaveLogs")) { OnSelected = (GUITickBox) => { //TODO: fix? //showLogButton.Visible = SaveServerLogs; return(true); } }; GetPropertyData("SaveServerLogs").AssignGUIComponent(saveLogsBox); //-------------------------------------------------------------------------------- // game settings //-------------------------------------------------------------------------------- var roundsTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; // Play Style Selection new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsPlayStyle"), font: GUI.SubHeadingFont); var playstyleList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.16f), roundsTab.RectTransform)) { AutoHideScrollBar = true, UseGridLayout = true }; playstyleList.Padding *= 2.0f; List <GUITickBox> playStyleTickBoxes = new List <GUITickBox>(); GUIRadioButtonGroup selectionPlayStyle = new GUIRadioButtonGroup(); foreach (PlayStyle playStyle in Enum.GetValues(typeof(PlayStyle))) { var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.32f, 0.49f), playstyleList.Content.RectTransform), TextManager.Get("servertag." + playStyle), font: GUI.SmallFont, style: "GUIRadioButton") { ToolTip = TextManager.Get("servertagdescription." + playStyle) }; selectionPlayStyle.AddRadioButton((int)playStyle, selectionTick); playStyleTickBoxes.Add(selectionTick); } GetPropertyData("PlayStyle").AssignGUIComponent(selectionPlayStyle); GUITextBlock.AutoScaleAndNormalize(playStyleTickBoxes.Select(t => t.TextBlock)); playstyleList.RectTransform.MinSize = new Point(0, (int)(playstyleList.Content.Children.First().Rect.Height * 2.0f + playstyleList.Padding.Y + playstyleList.Padding.W)); var endVoteBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsEndRoundVoting")); GetPropertyData("AllowEndVoting").AssignGUIComponent(endVoteBox); CreateLabeledSlider(roundsTab, "ServerSettingsEndRoundVotesRequired", out slider, out sliderLabel); string endRoundLabel = sliderLabel.Text; slider.Step = 0.2f; slider.Range = new Vector2(0.5f, 1.0f); GetPropertyData("EndVoteRequiredRatio").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = endRoundLabel + " " + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %"; return(true); }; slider.OnMoved(slider, slider.BarScroll); var respawnBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsAllowRespawning")); GetPropertyData("AllowRespawn").AssignGUIComponent(respawnBox); CreateLabeledSlider(roundsTab, "ServerSettingsRespawnInterval", out slider, out sliderLabel); string intervalLabel = sliderLabel.Text; slider.Range = new Vector2(10.0f, 600.0f); slider.StepValue = 10.0f; GetPropertyData("RespawnInterval").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; text.Text = intervalLabel + " " + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); return(true); }; slider.OnMoved(slider, slider.BarScroll); var minRespawnText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "") { ToolTip = TextManager.Get("ServerSettingsMinRespawnToolTip") }; string minRespawnLabel = TextManager.Get("ServerSettingsMinRespawn") + " "; CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel); slider.ToolTip = minRespawnText.RawToolTip; slider.UserData = minRespawnText; slider.Step = 0.1f; slider.Range = new Vector2(0.0f, 1.0f); GetPropertyData("MinRespawnRatio").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = minRespawnLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %"; return(true); }; slider.OnMoved(slider, MinRespawnRatio); var respawnDurationText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "") { ToolTip = TextManager.Get("ServerSettingsRespawnDurationToolTip") }; string respawnDurationLabel = TextManager.Get("ServerSettingsRespawnDuration") + " "; CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel); slider.ToolTip = respawnDurationText.RawToolTip; slider.UserData = respawnDurationText; slider.Step = 0.1f; slider.Range = new Vector2(60.0f, 660.0f); slider.ScrollToValue = (GUIScrollBar scrollBar, float barScroll) => { return(barScroll >= 1.0f ? 0.0f : barScroll *(scrollBar.Range.Y - scrollBar.Range.X) + scrollBar.Range.X); }; slider.ValueToScroll = (GUIScrollBar scrollBar, float value) => { return(value <= 0.0f ? 1.0f : (value - scrollBar.Range.X) / (scrollBar.Range.Y - scrollBar.Range.X)); }; GetPropertyData("MaxTransportTime").AssignGUIComponent(slider); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { if (barScroll == 1.0f) { ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + TextManager.Get("Unlimited"); } else { ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); } return(true); }; slider.OnMoved(slider, slider.BarScroll); var traitorsMinPlayerCount = CreateLabeledNumberInput(roundsTab, "ServerSettingsTraitorsMinPlayerCount", 1, 16, "ServerSettingsTraitorsMinPlayerCountToolTip"); GetPropertyData("TraitorsMinPlayerCount").AssignGUIComponent(traitorsMinPlayerCount); var ragdollButtonBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsAllowRagdollButton")); GetPropertyData("AllowRagdollButton").AssignGUIComponent(ragdollButtonBox); var disableBotConversationsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsDisableBotConversations")); GetPropertyData("DisableBotConversations").AssignGUIComponent(disableBotConversationsBox); var buttonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), roundsTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; var monsterButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform), TextManager.Get("ServerSettingsMonsterSpawns"), style: "GUIButtonSmall") { Enabled = !GameMain.NetworkMember.GameStarted }; var monsterFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomLeft, Pivot.BottomRight)) { Visible = false }; monsterButton.UserData = monsterFrame; monsterButton.OnClicked = (button, obj) => { if (GameMain.NetworkMember.GameStarted) { ((GUIComponent)obj).Visible = false; button.Enabled = false; return(true); } ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; return(true); }; InitMonstersEnabled(); List <string> monsterNames = MonsterEnabled.Keys.ToList(); tempMonsterEnabled = new Dictionary <string, bool>(MonsterEnabled); foreach (string s in monsterNames) { string translatedLabel = TextManager.Get($"Character.{s}", true); var monsterEnabledBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), monsterFrame.Content.RectTransform) { MinSize = new Point(0, 25) }, label: translatedLabel ?? s) { Selected = tempMonsterEnabled[s], OnSelected = (GUITickBox tb) => { tempMonsterEnabled[s] = tb.Selected; return(true); } }; } var cargoButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform), TextManager.Get("ServerSettingsAdditionalCargo"), style: "GUIButtonSmall") { Enabled = !GameMain.NetworkMember.GameStarted }; var cargoFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomRight, Pivot.BottomLeft)) { Visible = false }; cargoButton.UserData = cargoFrame; cargoButton.OnClicked = (button, obj) => { if (GameMain.NetworkMember.GameStarted) { ((GUIComponent)obj).Visible = false; button.Enabled = false; return(true); } ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; return(true); }; GUITextBlock.AutoScaleAndNormalize(buttonHolder.Children.Select(c => ((GUIButton)c).TextBlock)); foreach (ItemPrefab ip in ItemPrefab.Prefabs) { if (ip.AllowAsExtraCargo.HasValue) { if (!ip.AllowAsExtraCargo.Value) { continue; } } else { if (!ip.CanBeBought) { continue; } } var itemFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), cargoFrame.Content.RectTransform) { MinSize = new Point(0, 30) }, isHorizontal: true) { Stretch = true, UserData = cargoFrame, RelativeSpacing = 0.05f }; if (ip.InventoryIcon != null || ip.sprite != null) { GUIImage img = new GUIImage(new RectTransform(new Point(itemFrame.Rect.Height), itemFrame.RectTransform), ip.InventoryIcon ?? ip.sprite, scaleToFit: true) { CanBeFocused = false }; img.Color = img.Sprite == ip.InventoryIcon ? ip.InventoryIconColor : ip.SpriteColor; } new GUITextBlock(new RectTransform(new Vector2(0.75f, 1.0f), itemFrame.RectTransform), ip.Name, font: GUI.SmallFont) { Wrap = true, CanBeFocused = false }; ExtraCargo.TryGetValue(ip, out int cargoVal); var amountInput = new GUINumberInput(new RectTransform(new Vector2(0.35f, 1.0f), itemFrame.RectTransform), GUINumberInput.NumberType.Int, textAlignment: Alignment.CenterLeft) { MinValueInt = 0, MaxValueInt = 100, IntValue = cargoVal }; amountInput.OnValueChanged += (numberInput) => { if (ExtraCargo.ContainsKey(ip)) { ExtraCargo[ip] = numberInput.IntValue; if (numberInput.IntValue <= 0) { ExtraCargo.Remove(ip); } } else { ExtraCargo.Add(ip, numberInput.IntValue); } }; } //-------------------------------------------------------------------------------- // antigriefing //-------------------------------------------------------------------------------- var antigriefingTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Antigriefing].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; var tickBoxContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.16f), antigriefingTab.RectTransform)) { AutoHideScrollBar = true, UseGridLayout = true }; tickBoxContainer.Padding *= 2.0f; var allowFriendlyFire = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsAllowFriendlyFire")); GetPropertyData("AllowFriendlyFire").AssignGUIComponent(allowFriendlyFire); var killableNPCs = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsKillableNPCs")); GetPropertyData("KillableNPCs").AssignGUIComponent(killableNPCs); var destructibleOutposts = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsDestructibleOutposts")); GetPropertyData("DestructibleOutposts").AssignGUIComponent(destructibleOutposts); var lockAllDefaultWires = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsLockAllDefaultWires")); GetPropertyData("LockAllDefaultWires").AssignGUIComponent(lockAllDefaultWires); var allowRewiring = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsAllowRewiring")); GetPropertyData("AllowRewiring").AssignGUIComponent(allowRewiring); var allowWifiChatter = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsAllowWifiChat")); GetPropertyData("AllowLinkingWifiToChat").AssignGUIComponent(allowWifiChatter); var allowDisguises = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsAllowDisguises")); GetPropertyData("AllowDisguises").AssignGUIComponent(allowDisguises); var voteKickBox = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform), TextManager.Get("ServerSettingsAllowVoteKick")); GetPropertyData("AllowVoteKick").AssignGUIComponent(voteKickBox); GUITextBlock.AutoScaleAndNormalize(tickBoxContainer.Content.Children.Select(c => ((GUITickBox)c).TextBlock)); tickBoxContainer.RectTransform.MinSize = new Point(0, (int)(tickBoxContainer.Content.Children.First().Rect.Height * 2.0f + tickBoxContainer.Padding.Y + tickBoxContainer.Padding.W)); CreateLabeledSlider(antigriefingTab, "ServerSettingsKickVotesRequired", out slider, out sliderLabel); string votesRequiredLabel = sliderLabel.Text + " "; slider.Step = 0.2f; slider.Range = new Vector2(0.5f, 1.0f); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = votesRequiredLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %"; return(true); }; GetPropertyData("KickVoteRequiredRatio").AssignGUIComponent(slider); slider.OnMoved(slider, slider.BarScroll); CreateLabeledSlider(antigriefingTab, "ServerSettingsAutobanTime", out slider, out sliderLabel); string autobanLabel = sliderLabel.Text + " "; slider.Step = 0.01f; slider.Range = new Vector2(0.0f, MaxAutoBanTime); slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { ((GUITextBlock)scrollBar.UserData).Text = autobanLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue); return(true); }; GetPropertyData("AutoBanTime").AssignGUIComponent(slider); slider.OnMoved(slider, slider.BarScroll); var wrongPasswordBanBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform), TextManager.Get("ServerSettingsBanAfterWrongPassword")); GetPropertyData("BanAfterWrongPassword").AssignGUIComponent(wrongPasswordBanBox); var allowedPasswordRetries = CreateLabeledNumberInput(antigriefingTab, "ServerSettingsPasswordRetriesBeforeBan", 0, 10); GetPropertyData("MaxPasswordRetriesBeforeBan").AssignGUIComponent(allowedPasswordRetries); wrongPasswordBanBox.OnSelected += (tb) => { allowedPasswordRetries.Enabled = tb.Selected; return(true); }; // karma -------------------------------------------------------------------------- var karmaBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform), TextManager.Get("ServerSettingsUseKarma")); GetPropertyData("KarmaEnabled").AssignGUIComponent(karmaBox); karmaPresetDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform)); foreach (string karmaPreset in GameMain.NetworkMember.KarmaManager.Presets.Keys) { karmaPresetDD.AddItem(TextManager.Get("KarmaPreset." + karmaPreset), karmaPreset); } var karmaSettingsContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), antigriefingTab.RectTransform), style: null); var karmaSettingsList = new GUIListBox(new RectTransform(Vector2.One, karmaSettingsContainer.RectTransform)) { Spacing = (int)(8 * GUI.Scale) }; karmaSettingsList.Padding *= 2.0f; karmaSettingsBlocker = new GUIFrame(new RectTransform(Vector2.One, karmaSettingsContainer.RectTransform, Anchor.CenterLeft) { MaxSize = new Point(karmaSettingsList.ContentBackground.Rect.Width, int.MaxValue) }, style: null) { UserData = "karmasettingsblocker", Color = Color.Black * 0.95f }; karmaSettingsBlocker.Color *= 0.5f; karmaPresetDD.SelectItem(KarmaPreset); karmaSettingsBlocker.Visible = !karmaBox.Selected || KarmaPreset != "custom"; GameMain.NetworkMember.KarmaManager.CreateSettingsFrame(karmaSettingsList.Content); karmaPresetDD.OnSelected = (selected, obj) => { string newKarmaPreset = obj as string; if (newKarmaPreset == KarmaPreset) { return(true); } List <NetPropertyData> properties = netProperties.Values.ToList(); List <object> prevValues = new List <object>(); foreach (NetPropertyData prop in netProperties.Values) { prevValues.Add(prop.TempValue); if (prop.GUIComponent != null) { prop.Value = prop.GUIComponentValue; } } if (KarmaPreset == "custom") { GameMain.NetworkMember?.KarmaManager?.SaveCustomPreset(); GameMain.NetworkMember?.KarmaManager?.Save(); } KarmaPreset = newKarmaPreset; GameMain.NetworkMember.KarmaManager.SelectPreset(KarmaPreset); karmaSettingsList.Content.ClearChildren(); karmaSettingsBlocker.Visible = !karmaBox.Selected || KarmaPreset != "custom"; GameMain.NetworkMember.KarmaManager.CreateSettingsFrame(karmaSettingsList.Content); for (int i = 0; i < netProperties.Count; i++) { properties[i].TempValue = prevValues[i]; } return(true); }; AssignGUIComponent("KarmaPreset", karmaPresetDD); karmaBox.OnSelected = (tb) => { karmaSettingsBlocker.Visible = !tb.Selected || KarmaPreset != "custom"; return(true); }; //-------------------------------------------------------------------------------- // banlist //-------------------------------------------------------------------------------- BanList.CreateBanFrame(settingsTabs[(int)SettingsTab.Banlist]); //-------------------------------------------------------------------------------- // whitelist //-------------------------------------------------------------------------------- Whitelist.CreateWhiteListFrame(settingsTabs[(int)SettingsTab.Whitelist]); }
private void CreateSettingsFrame() { settingsFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker") { OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) { ToggleSettingsFrame(btn, userdata); } return(true); } }; new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null) { OnClicked = ToggleSettingsFrame }; GUIFrame innerFrame = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.7f), settingsFrame.RectTransform, Anchor.Center) { MinSize = new Point(400, 430) }); GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center), style: null); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), paddedFrame.RectTransform), "Settings", font: GUI.LargeFont); var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), paddedFrame.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.1f) }, isHorizontal: true) { Stretch = true, RelativeSpacing = 0.01f }; var tabValues = Enum.GetValues(typeof(SettingsTab)).Cast <SettingsTab>().ToArray(); string[] tabNames = new string[tabValues.Count()]; for (int i = 0; i < tabNames.Length; i++) { tabNames[i] = TextManager.Get("ServerSettings" + tabValues[i] + "Tab"); } settingsTabs = new GUIFrame[tabNames.Length]; for (int i = 0; i < tabNames.Length; i++) { settingsTabs[i] = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.79f), paddedFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.05f) }, style: "InnerFrame"); var tabButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform), tabNames[i]) { UserData = i, OnClicked = SelectSettingsTab }; } SelectSettingsTab(null, 0); var closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), paddedFrame.RectTransform, Anchor.BottomRight), TextManager.Get("Close")) { OnClicked = ToggleSettingsFrame }; //-------------------------------------------------------------------------------- // game settings //-------------------------------------------------------------------------------- var roundsTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsSubSelection")); var selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), ((SelectionMode)i).ToString(), font: GUI.SmallFont) { Selected = i == (int)subSelectionMode, OnSelected = SwitchSubSelection, UserData = (SelectionMode)i, }; } GUITickBox.CreateRadioButtonGroup(selectionFrame.Children.Select(c => c as GUITickBox)); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsModeSelection")); selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; for (int i = 0; i < 3; i++) { var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), ((SelectionMode)i).ToString(), font: GUI.SmallFont) { Selected = i == (int)modeSelectionMode, OnSelected = SwitchModeSelection, UserData = (SelectionMode)i }; } GUITickBox.CreateRadioButtonGroup(selectionFrame.Children.Select(c => c as GUITickBox)); var endBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsEndRoundWhenDestReached")) { Selected = EndRoundAtLevelEnd, OnSelected = (GUITickBox) => { EndRoundAtLevelEnd = GUITickBox.Selected; return(true); } }; var endVoteBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsEndRoundVoting")) { Selected = Voting.AllowEndVoting, OnSelected = (GUITickBox) => { Voting.AllowEndVoting = !Voting.AllowEndVoting; GameMain.Server.UpdateVoteStatus(); return(true); } }; CreateLabeledSlider(roundsTab, "ServerSettingsEndRoundVotesRequired", out GUIScrollBar slider, out GUITextBlock sliderLabel); string endRoundLabel = sliderLabel.Text; slider.Step = 0.2f; slider.BarScroll = (EndVoteRequiredRatio - 0.5f) * 2.0f; slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { EndVoteRequiredRatio = barScroll / 2.0f + 0.5f; ((GUITextBlock)scrollBar.UserData).Text = endRoundLabel + (int)MathUtils.Round(EndVoteRequiredRatio * 100.0f, 10.0f) + " %"; return(true); }; slider.OnMoved(slider, slider.BarScroll); var respawnBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsAllowRespawning")) { Selected = AllowRespawn, OnSelected = (GUITickBox) => { AllowRespawn = !AllowRespawn; return(true); } }; CreateLabeledSlider(roundsTab, "ServerSettingsRespawnInterval", out slider, out sliderLabel); string intervalLabel = sliderLabel.Text; slider.Step = 0.05f; slider.BarScroll = RespawnInterval / 600.0f; slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; RespawnInterval = Math.Max(barScroll * 600.0f, 10.0f); text.Text = intervalLabel + ToolBox.SecondsToReadableTime(RespawnInterval); return(true); }; slider.OnMoved(slider, slider.BarScroll); var minRespawnText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "") { ToolTip = TextManager.Get("ServerSettingsMinRespawnToolTip") }; string minRespawnLabel = TextManager.Get("ServerSettingsMinRespawn"); CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel); slider.ToolTip = minRespawnText.ToolTip; slider.UserData = minRespawnText; slider.Step = 0.1f; slider.BarScroll = MinRespawnRatio; slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { MinRespawnRatio = barScroll; ((GUITextBlock)scrollBar.UserData).Text = minRespawnLabel + (int)MathUtils.Round(MinRespawnRatio * 100.0f, 10.0f) + " %"; return(true); }; slider.OnMoved(slider, MinRespawnRatio); var respawnDurationText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "") { ToolTip = TextManager.Get("ServerSettingsRespawnDurationToolTip") }; string respawnDurationLabel = TextManager.Get("ServerSettingsRespawnDuration"); CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel); slider.ToolTip = respawnDurationText.ToolTip; slider.UserData = respawnDurationText; slider.Step = 0.1f; slider.BarScroll = MaxTransportTime <= 0.0f ? 1.0f : (MaxTransportTime - 60.0f) / 600.0f; slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { if (barScroll == 1.0f) { MaxTransportTime = 0; ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + "unlimited"; } else { MaxTransportTime = barScroll * 600.0f + 60.0f; ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + ToolBox.SecondsToReadableTime(MaxTransportTime); } return(true); }; slider.OnMoved(slider, slider.BarScroll); var buttonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), roundsTab.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; var monsterButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform), TextManager.Get("ServerSettingsMonsterSpawns")) { Enabled = !GameStarted }; var monsterFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomLeft, Pivot.BottomRight)) { Visible = false }; monsterButton.UserData = monsterFrame; monsterButton.OnClicked = (button, obj) => { if (gameStarted) { ((GUIComponent)obj).Visible = false; button.Enabled = false; return(true); } ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; return(true); }; List <string> monsterNames = monsterEnabled.Keys.ToList(); foreach (string s in monsterNames) { var monsterEnabledBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), monsterFrame.Content.RectTransform) { MinSize = new Point(0, 25) }, label: s) { Selected = monsterEnabled[s], OnSelected = (GUITickBox) => { if (gameStarted) { monsterFrame.Visible = false; monsterButton.Enabled = false; return(true); } monsterEnabled[s] = !monsterEnabled[s]; return(true); } }; } var cargoButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform), TextManager.Get("ServerSettingsAdditionalCargo")) { Enabled = !GameStarted }; var cargoFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomRight, Pivot.BottomLeft)) { 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 (MapEntityPrefab pf in MapEntityPrefab.List) { ItemPrefab ip = pf as ItemPrefab; if (ip == null || (!ip.CanBeBought && !ip.Tags.Contains("smallitem"))) { continue; } var itemFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), cargoFrame.Content.RectTransform) { MinSize = new Point(0, 30) }, isHorizontal: true) { Stretch = true, UserData = cargoFrame, RelativeSpacing = 0.05f }; if (ip.InventoryIcon != null || ip.sprite != null) { GUIImage img = new GUIImage(new RectTransform(new Point(itemFrame.Rect.Height), itemFrame.RectTransform), ip.InventoryIcon ?? ip.sprite, scaleToFit: true) { CanBeFocused = false }; img.Color = img.Sprite == ip.InventoryIcon ? ip.InventoryIconColor : ip.SpriteColor; } new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), itemFrame.RectTransform), ip.Name, font: GUI.SmallFont) { CanBeFocused = false }; extraCargo.TryGetValue(ip, out int cargoVal); var amountInput = new GUINumberInput(new RectTransform(new Vector2(0.3f, 1.0f), itemFrame.RectTransform), GUINumberInput.NumberType.Int, textAlignment: Alignment.CenterLeft) { MinValueInt = 0, MaxValueInt = 100, IntValue = cargoVal }; amountInput.OnValueChanged += (numberInput) => { if (extraCargo.ContainsKey(ip)) { extraCargo[ip] = numberInput.IntValue; } else { extraCargo.Add(ip, numberInput.IntValue); } }; } //-------------------------------------------------------------------------------- // server settings //-------------------------------------------------------------------------------- var serverTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Server].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; string autoRestartDelayLabel = TextManager.Get("ServerSettingsAutoRestartDelay"); var startIntervalText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), autoRestartDelayLabel); var startIntervalSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), barSize: 0.1f) { UserData = startIntervalText, Step = 0.05f, BarScroll = AutoRestartInterval / 300.0f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock text = scrollBar.UserData as GUITextBlock; AutoRestartInterval = Math.Max(barScroll * 300.0f, 10.0f); text.Text = autoRestartDelayLabel + ToolBox.SecondsToReadableTime(AutoRestartInterval); return(true); } }; startIntervalSlider.OnMoved(startIntervalSlider, startIntervalSlider.BarScroll); //*********************************************** var startWhenClientsReady = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsStartWhenClientsReady")) { Selected = StartWhenClientsReady, OnSelected = (tickBox) => { StartWhenClientsReady = tickBox.Selected; return(true); } }; CreateLabeledSlider(serverTab, "ServerSettingsStartWhenClientsReadyRatio", out slider, out sliderLabel); string clientsReadyRequiredLabel = sliderLabel.Text; slider.Step = 0.2f; slider.BarScroll = (StartWhenClientsReadyRatio - 0.5f) * 2.0f; slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { StartWhenClientsReadyRatio = barScroll / 2.0f + 0.5f; ((GUITextBlock)scrollBar.UserData).Text = clientsReadyRequiredLabel.Replace("[percentage]", ((int)MathUtils.Round(StartWhenClientsReadyRatio * 100.0f, 10.0f)).ToString()); return(true); }; slider.OnMoved(slider, slider.BarScroll); //*********************************************** var allowSpecBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowSpectating")) { Selected = AllowSpectating, OnSelected = (GUITickBox) => { AllowSpectating = GUITickBox.Selected; GameMain.NetLobbyScreen.LastUpdateID++; return(true); } }; var voteKickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowVoteKick")) { Selected = Voting.AllowVoteKick, OnSelected = (GUITickBox) => { Voting.AllowVoteKick = !Voting.AllowVoteKick; GameMain.Server.UpdateVoteStatus(); return(true); } }; CreateLabeledSlider(serverTab, "ServerSettingsKickVotesRequired", out slider, out sliderLabel); string votesRequiredLabel = sliderLabel.Text; slider.Step = 0.2f; slider.BarScroll = (KickVoteRequiredRatio - 0.5f) * 2.0f; slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { KickVoteRequiredRatio = barScroll / 2.0f + 0.5f; ((GUITextBlock)scrollBar.UserData).Text = votesRequiredLabel + (int)MathUtils.Round(KickVoteRequiredRatio * 100.0f, 10.0f) + " %"; return(true); }; slider.OnMoved(slider, slider.BarScroll); CreateLabeledSlider(serverTab, "ServerSettingsAutobanTime", out slider, out sliderLabel); string autobanLabel = sliderLabel.Text; slider.Step = 0.05f; slider.BarScroll = AutoBanTime / MaxAutoBanTime; slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { AutoBanTime = Math.Max(barScroll * MaxAutoBanTime, 0); ((GUITextBlock)scrollBar.UserData).Text = autobanLabel + ToolBox.SecondsToReadableTime(AutoBanTime); return(true); }; slider.OnMoved(slider, slider.BarScroll); var shareSubsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsShareSubFiles")) { Selected = AllowFileTransfers, OnSelected = (GUITickBox) => { AllowFileTransfers = GUITickBox.Selected; return(true); } }; var randomizeLevelBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsRandomizeSeed")) { Selected = RandomizeSeed, OnSelected = (GUITickBox) => { RandomizeSeed = GUITickBox.Selected; return(true); } }; var saveLogsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsSaveLogs")) { Selected = SaveServerLogs, OnSelected = (GUITickBox) => { SaveServerLogs = GUITickBox.Selected; showLogButton.Visible = SaveServerLogs; return(true); } }; var ragdollButtonBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowRagdollButton")) { Selected = AllowRagdollButton, OnSelected = (GUITickBox) => { AllowRagdollButton = GUITickBox.Selected; return(true); } }; var traitorRatioBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsUseTraitorRatio")); CreateLabeledSlider(serverTab, "", out slider, out sliderLabel); /*var traitorRatioText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), "Traitor ratio: 20 %", "", settingsTabs[1], GUI.SmallFont); * var traitorRatioSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[1]);*/ var traitorRatioSlider = slider; traitorRatioBox.Selected = TraitorUseRatio; traitorRatioBox.OnSelected = (GUITickBox) => { TraitorUseRatio = GUITickBox.Selected; traitorRatioSlider.Step = TraitorUseRatio ? 0.01f : 1f / (maxPlayers - 1); traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll); return(true); }; string traitorRatioLabel = TextManager.Get("ServerSettingsTraitorRatio"); string traitorCountLabel = TextManager.Get("ServerSettingsTraitorCount"); traitorRatioSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { GUITextBlock traitorText = scrollBar.UserData as GUITextBlock; if (TraitorUseRatio) { TraitorRatio = barScroll * 0.9f + 0.1f; traitorText.Text = traitorRatioLabel + (int)MathUtils.Round(TraitorRatio * 100.0f, 1.0f) + " %"; } else { TraitorRatio = MathUtils.Round(barScroll * (maxPlayers - 1), 1f) + 1; traitorText.Text = traitorCountLabel + TraitorRatio; } return(true); }; traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll); traitorRatioBox.OnSelected(traitorRatioBox); new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsUseKarma")) { Selected = KarmaEnabled, OnSelected = (GUITickBox) => { KarmaEnabled = GUITickBox.Selected; return(true); } }; new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsRandomPreferences")) { Selected = RandomPreferences, OnSelected = (GUITickBox) => { RandomPreferences = GUITickBox.Selected; return(true); } }; //-------------------------------------------------------------------------------- // banlist //-------------------------------------------------------------------------------- banList.CreateBanFrame(settingsTabs[2]); //-------------------------------------------------------------------------------- // whitelist //-------------------------------------------------------------------------------- whitelist.CreateWhiteListFrame(settingsTabs[3]); }
protected override void CreateGUI() { uiElements.Clear(); var visibleElements = customInterfaceElementList.Where(ciElement => !string.IsNullOrEmpty(ciElement.Label)); uiElementContainer = new GUILayoutGroup(new RectTransform(GuiFrame.Rect.Size - GUIStyle.ItemFrameMargin, GuiFrame.RectTransform, Anchor.Center) { AbsoluteOffset = GUIStyle.ItemFrameOffset }, childAnchor: customInterfaceElementList.Count > 1 ? Anchor.TopCenter : Anchor.Center) { RelativeSpacing = 0.05f, Stretch = visibleElements.Count() > 2, }; float elementSize = Math.Min(1.0f / visibleElements.Count(), 1); foreach (CustomInterfaceElement ciElement in visibleElements) { if (ciElement.HasPropertyName) { var layoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, elementSize), uiElementContainer.RectTransform), isHorizontal: true) { RelativeSpacing = 0.02f, UserData = ciElement }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), TextManager.Get(ciElement.Label, returnNull: true) ?? ciElement.Label); if (!ciElement.IsIntegerInput) { var textBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), ciElement.Signal, style: "GUITextBoxNoIcon") { OverflowClip = true, UserData = ciElement }; //reset size restrictions set by the Style to make sure the elements can fit the interface textBox.RectTransform.MinSize = textBox.Frame.RectTransform.MinSize = new Point(0, 0); textBox.RectTransform.MaxSize = textBox.Frame.RectTransform.MaxSize = new Point(int.MaxValue, int.MaxValue); textBox.OnDeselected += (tb, key) => { if (GameMain.Client == null) { TextChanged(tb.UserData as CustomInterfaceElement, textBox.Text); } else { item.CreateClientEvent(this); } }; textBox.OnEnterPressed += (tb, text) => { tb.Deselect(); return(true); }; uiElements.Add(textBox); } else { int.TryParse(ciElement.Signal, out int signal); var numberInput = new GUINumberInput(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), GUINumberInput.NumberType.Int) { UserData = ciElement, MinValueInt = ciElement.NumberInputMin, MaxValueInt = ciElement.NumberInputMax, IntValue = Math.Clamp(signal, ciElement.NumberInputMin, ciElement.NumberInputMax) }; //reset size restrictions set by the Style to make sure the elements can fit the interface numberInput.RectTransform.MinSize = numberInput.LayoutGroup.RectTransform.MinSize = new Point(0, 0); numberInput.RectTransform.MaxSize = numberInput.LayoutGroup.RectTransform.MaxSize = new Point(int.MaxValue, int.MaxValue); numberInput.OnValueChanged += (ni) => { if (GameMain.Client == null) { ValueChanged(ni.UserData as CustomInterfaceElement, ni.IntValue); } else { item.CreateClientEvent(this); } }; uiElements.Add(numberInput); } } else if (ciElement.ContinuousSignal) { var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, elementSize), uiElementContainer.RectTransform) { MaxSize = ElementMaxSize }, TextManager.Get(ciElement.Label, returnNull: true) ?? ciElement.Label) { UserData = ciElement }; tickBox.OnSelected += (tBox) => { if (GameMain.Client == null) { TickBoxToggled(tBox.UserData as CustomInterfaceElement, tBox.Selected); } else { item.CreateClientEvent(this); } return(true); }; //reset size restrictions set by the Style to make sure the elements can fit the interface tickBox.RectTransform.MinSize = new Point(0, 0); tickBox.RectTransform.MaxSize = new Point(int.MaxValue, int.MaxValue); uiElements.Add(tickBox); } else { var btn = new GUIButton(new RectTransform(new Vector2(1.0f, elementSize), uiElementContainer.RectTransform), TextManager.Get(ciElement.Label, returnNull: true) ?? ciElement.Label, style: "DeviceButton") { UserData = ciElement }; btn.OnClicked += (_, userdata) => { if (GameMain.Client == null) { ButtonClicked(userdata as CustomInterfaceElement); } else { GameMain.Client.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.GetComponentIndex(this), userdata as CustomInterfaceElement }); } return(true); }; //reset size restrictions set by the Style to make sure the elements can fit the interface btn.RectTransform.MinSize = btn.Frame.RectTransform.MinSize = new Point(0, 0); btn.RectTransform.MaxSize = btn.Frame.RectTransform.MaxSize = ElementMaxSize; uiElements.Add(btn); } } }