static void createToolBox() { GUIEnvironment env = device.GUIEnvironment; GUIElement root = env.RootElement; // remove tool box if already there GUIElement e = root.GetElementFromID((int)guiID.DialogRootWindow, true); if (e != null) { e.Remove(); } // create the toolbox window GUIWindow w = env.AddWindow(new Recti(600, 45, 800, 480), false, "Toolset", null, (int)guiID.DialogRootWindow); // create tab control and tabs GUITabControl tab = env.AddTabControl(new Recti(2, 20, 800 - 602, 480 - 7), w, -1, true, true); GUITab t1 = tab.AddTab("Config"); // add some edit boxes and a button to tab one env.AddStaticText("Scale:", new Recti(10, 20, 60, 45), false, false, t1); env.AddStaticText("X:", new Recti(22, 48, 40, 66), false, false, t1); env.AddEditBox("1.0", new Recti(40, 46, 130, 66), true, t1, (int)guiID.XScale); env.AddStaticText("Y:", new Recti(22, 78, 40, 96), false, false, t1); env.AddEditBox("1.0", new Recti(40, 76, 130, 96), true, t1, (int)guiID.YScale); env.AddStaticText("Z:", new Recti(22, 108, 40, 126), false, false, t1); env.AddEditBox("1.0", new Recti(40, 106, 130, 126), true, t1, (int)guiID.ZScale); env.AddButton(new Recti(10, 134, 85, 165), t1, (int)guiID.ButtonSetScale, "Set"); // quick scale buttons env.AddButton(new Recti(65, 20, 95, 40), t1, (int)guiID.ButtonScaleMul10, "* 10"); env.AddButton(new Recti(100, 20, 130, 40), t1, (int)guiID.ButtonScaleDiv10, "* 0.1"); updateScaleInfo(model); // add transparency control env.AddStaticText("GUI Transparency Control:", new Recti(10, 200, 150, 225), true, false, t1); GUIScrollBar b = env.AddScrollBar(true, new Recti(10, 225, 150, 240), t1, (int)guiID.SkinTransparency); b.MaxValue = 255; b.Position = 255; // add framerate control env.AddStaticText("Framerate:", new Recti(10, 240, 150, 265), true, false, t1); b = env.AddScrollBar(true, new Recti(10, 265, 150, 280), t1, (int)guiID.SkinAnimationFPS); b.MaxValue = MaxFramerate; b.MinValue = -MaxFramerate; b.Position = DefaultFramerate; // bring irrlicht engine logo to front, because it now may be below the newly created toolbox root.BringToFront(root.GetElementFromID((int)guiID.Logo, true)); }
private void CreateLabeledSlider(GUIComponent parent, string labelTag, out GUIScrollBar slider, out GUITextBlock label) { var container = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), parent.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; slider = new GUIScrollBar(new RectTransform(new Vector2(0.5f, 0.8f), container.RectTransform), barSize: 0.1f); label = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.8f), container.RectTransform), string.IsNullOrEmpty(labelTag) ? "" : TextManager.Get(labelTag), font: GUI.SmallFont); //slider has a reference to the label to change the text when it's used slider.UserData = label; }
partial void InitProjSpecific() { if (GuiFrame == null) { return; } var paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.75f, 0.75f), GuiFrame.RectTransform, Anchor.Center) { //RelativeOffset = new Vector2(0, 0.05f) }, style: null); var upperArea = new GUIFrame(new RectTransform(new Vector2(1, 0.4f), paddedFrame.RectTransform, Anchor.TopCenter), style: null); var lowerArea = new GUIFrame(new RectTransform(new Vector2(1, 0.6f), paddedFrame.RectTransform, Anchor.BottomCenter), style: null); string rechargeStr = TextManager.Get("PowerContainerRechargeRate"); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), upperArea.RectTransform, Anchor.TopCenter), "RechargeRate", textColor: GUI.Style.TextColor, font: GUI.SubHeadingFont, textAlignment: Alignment.Center) { TextGetter = () => { return(rechargeStr.Replace("[rate]", ((int)((rechargeSpeed / maxRechargeSpeed) * 100.0f)).ToString())); } }; rechargeSpeedSlider = new GUIScrollBar(new RectTransform(new Vector2(0.9f, 0.4f), upperArea.RectTransform, Anchor.BottomCenter), barSize: 0.15f, style: "DeviceSlider") { Step = 0.1f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { float newRechargeSpeed = maxRechargeSpeed * barScroll; if (Math.Abs(newRechargeSpeed - rechargeSpeed) < 0.1f) { return(false); } RechargeSpeed = newRechargeSpeed; if (GameMain.Client != null) { item.CreateClientEvent(this); correctionTimer = CorrectionDelay; } return(true); } }; rechargeSpeedSlider.Bar.RectTransform.MaxSize = new Point(rechargeSpeedSlider.Bar.Rect.Height); // lower area -------------------------- var textArea = new GUIFrame(new RectTransform(new Vector2(1, 0.4f), lowerArea.RectTransform), style: null); var chargeLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 0.0f), textArea.RectTransform, Anchor.CenterLeft), TextManager.Get("charge"), textColor: GUI.Style.TextColor, font: GUI.SubHeadingFont, textAlignment: Alignment.CenterLeft) { ToolTip = TextManager.Get("PowerTransferTipPower") }; string kWmin = TextManager.Get("kilowattminute"); var chargeText = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1), textArea.RectTransform, Anchor.CenterRight), "", textColor: GUI.Style.TextColor, font: GUI.Font, textAlignment: Alignment.CenterRight) { TextGetter = () => $"{(int)Math.Round(charge)}/{(int)capacity} {kWmin} ({(int)Math.Round(MathUtils.Percentage(charge, capacity))} %)" }; if (chargeText.TextSize.X > chargeText.Rect.Width) { chargeText.Font = GUI.SmallFont; } chargeIndicator = new GUIProgressBar(new RectTransform(new Vector2(1.1f, 0.5f), lowerArea.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0, 0.1f) }, barSize: 0.0f, style: "DeviceProgressBar") { ProgressGetter = () => { return(capacity <= 0.0f ? 1.0f : charge / capacity); } }; }
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]); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } device.SetWindowCaption("Irrlicht Engine - User Interface Demo"); device.SetWindowResizable(true); VideoDriver driver = device.VideoDriver; GUIEnvironment env = device.GUIEnvironment; GUISkin skin = env.Skin; GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { skin.SetFont(font); } skin.SetFont(env.BuiltInFont, GUIDefaultFont.Tooltip); env.AddButton(new Recti(10, 240, 110, 240 + 32), null, GUI_ID_ButtonQuit, "Quit", "Exits Program"); env.AddButton(new Recti(10, 280, 110, 280 + 32), null, GUI_ID_ButtonWindowNew, "New Window", "Launches a new Window"); env.AddButton(new Recti(10, 320, 110, 320 + 32), null, GUI_ID_ButtonFileOpen, "File Open", "Opens a file"); env.AddStaticText("Transparent Control:", new Recti(150, 20, 350, 40), true); GUIScrollBar scrollbar = env.AddScrollBar(true, new Recti(150, 45, 350, 60), null, GUI_ID_ScrollbarTransparency); scrollbar.MaxValue = 255; scrollbar.Position = (int)env.Skin.GetColor(GUIDefaultColor.WindowBackground).Alpha; GUIStaticText trq = env.AddStaticText("Logging ListBox:", new Recti(50, 110, 250, 130), true); listbox = env.AddListBox(new Recti(50, 140, 250, 210)); env.AddEditBox("Editable Text", new Recti(350, 80, 550, 100)); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10, 10)); while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); env.DrawAll(); driver.EndScene(); } } device.Drop(); }
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]); }
partial void InitProjSpecific(XElement element) { foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "pumpoutemitter": pumpOutEmitters.Add(new Pair <Vector2, ParticleEmitter>( subElement.GetAttributeVector2("position", Vector2.Zero), new ParticleEmitter(subElement))); break; case "pumpinemitter": pumpInEmitters.Add(new Pair <Vector2, ParticleEmitter>( subElement.GetAttributeVector2("position", Vector2.Zero), new ParticleEmitter(subElement))); break; } } if (GuiFrame == null) { return; } GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center), style: null); isActiveSlider = new GUIScrollBar(new RectTransform(new Point((int)(50 * GUI.Scale), (int)(100 * GUI.Scale)), paddedFrame.RectTransform, Anchor.CenterLeft), barSize: 0.2f, style: "OnOffLever") { IsBooleanSwitch = true, MinValue = 0.25f, MaxValue = 0.75f }; var sliderHandle = isActiveSlider.GetChild <GUIButton>(); sliderHandle.RectTransform.NonScaledSize = new Point((int)(84 * GUI.Scale), sliderHandle.Rect.Height); isActiveSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { bool active = scrollBar.BarScroll < 0.5f; if (active == IsActive) { return(false); } targetLevel = null; IsActive = active; if (!IsActive) { currPowerConsumption = 0.0f; } if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); }; var rightArea = new GUILayoutGroup(new RectTransform(new Vector2(0.75f, 0.95f), paddedFrame.RectTransform, Anchor.CenterRight)) { RelativeSpacing = 0.1f, Stretch = true }; powerIndicator = new GUITickBox(new RectTransform(new Point((int)(30 * GUI.Scale)), rightArea.RectTransform), TextManager.Get("PumpPowered"), style: "IndicatorLightGreen") { CanBeFocused = false }; autoControlIndicator = new GUITickBox(new RectTransform(new Point((int)(30 * GUI.Scale)), rightArea.RectTransform), TextManager.Get("PumpAutoControl", fallBackTag: "ReactorAutoControl"), style: "IndicatorLightGreen") { CanBeFocused = false }; var pumpSpeedText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), rightArea.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.0f) }, "", textAlignment: Alignment.BottomLeft, wrap: true); string pumpSpeedStr = TextManager.Get("PumpSpeed"); pumpSpeedText.TextGetter = () => { return(TextManager.AddPunctuation(':', pumpSpeedStr, (int)flowPercentage + " %")); }; var sliderArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.3f), rightArea.RectTransform, Anchor.CenterLeft), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.01f }; var outLabel = new GUITextBlock(new RectTransform(new Vector2(0.25f, 1.0f), sliderArea.RectTransform), TextManager.Get("PumpOut"), textAlignment: Alignment.Center, wrap: false, font: GUI.SmallFont); pumpSpeedSlider = new GUIScrollBar(new RectTransform(new Vector2(0.5f, 1.0f), sliderArea.RectTransform), barSize: 0.25f, style: "GUISlider") { Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { float newValue = barScroll * 200.0f - 100.0f; if (Math.Abs(newValue - FlowPercentage) < 0.1f) { return(false); } FlowPercentage = newValue; if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); } }; var inLabel = new GUITextBlock(new RectTransform(new Vector2(0.25f, 1.0f), sliderArea.RectTransform), TextManager.Get("PumpIn"), textAlignment: Alignment.Center, wrap: false, font: GUI.SmallFont); rightArea.Recalculate(); sliderArea.Recalculate(); GUITextBlock.AutoScaleAndNormalize(outLabel, inLabel); }
partial void InitProjSpecific(XElement element) { foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "pumpoutemitter": pumpOutEmitters.Add(new Pair <Vector2, ParticleEmitter>( subElement.GetAttributeVector2("position", Vector2.Zero), new ParticleEmitter(subElement))); break; case "pumpinemitter": pumpInEmitters.Add(new Pair <Vector2, ParticleEmitter>( subElement.GetAttributeVector2("position", Vector2.Zero), new ParticleEmitter(subElement))); break; } } if (GuiFrame == null) { return; } GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.85f, 0.65f), GuiFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0, 0.04f) }, style: null); // Power button float powerButtonSize = 1f; var powerArea = new GUIFrame(new RectTransform(new Vector2(0.3f, 1) * powerButtonSize, paddedFrame.RectTransform, Anchor.CenterLeft), style: null); var paddedPowerArea = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.8f), powerArea.RectTransform, Anchor.Center), style: "PowerButtonFrame"); var powerLightArea = new GUIFrame(new RectTransform(new Vector2(0.87f, 0.2f), powerArea.RectTransform, Anchor.TopRight), style: null); powerLight = new GUITickBox(new RectTransform(Vector2.One, powerLightArea.RectTransform, Anchor.Center), TextManager.Get("PowerLabel"), font: GUI.SubHeadingFont, style: "IndicatorLightPower") { CanBeFocused = false }; powerLight.TextBlock.AutoScaleHorizontal = true; powerLight.TextBlock.OverrideTextColor(GUI.Style.TextColor); PowerButton = new GUIButton(new RectTransform(new Vector2(0.8f, 0.75f), paddedPowerArea.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0, 0.1f) }, style: "PowerButton") { OnClicked = (button, data) => { TargetLevel = null; IsActive = !IsActive; if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } powerLight.Selected = IsActive; return(true); } }; var rightArea = new GUIFrame(new RectTransform(new Vector2(0.65f, 1), paddedFrame.RectTransform, Anchor.CenterRight), style: null); autoControlIndicator = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.25f), rightArea.RectTransform, Anchor.TopLeft), TextManager.Get("PumpAutoControl", fallBackTag: "ReactorAutoControl"), font: GUI.SubHeadingFont, style: "IndicatorLightYellow") { Selected = false, Enabled = false, ToolTip = TextManager.Get("AutoControlTip") }; autoControlIndicator.TextBlock.AutoScaleHorizontal = true; autoControlIndicator.TextBlock.OverrideTextColor(GUI.Style.TextColor); var sliderArea = new GUIFrame(new RectTransform(new Vector2(1, 0.65f), rightArea.RectTransform, Anchor.BottomLeft), style: null); var pumpSpeedText = new GUITextBlock(new RectTransform(new Vector2(1, 0.3f), sliderArea.RectTransform, Anchor.TopLeft), "", textColor: GUI.Style.TextColor, textAlignment: Alignment.CenterLeft, wrap: false, font: GUI.SubHeadingFont) { AutoScaleHorizontal = true }; string pumpSpeedStr = TextManager.Get("PumpSpeed"); pumpSpeedText.TextGetter = () => { return(TextManager.AddPunctuation(':', pumpSpeedStr, (int)flowPercentage + " %")); }; pumpSpeedSlider = new GUIScrollBar(new RectTransform(new Vector2(1, 0.35f), sliderArea.RectTransform, Anchor.Center), barSize: 0.1f, style: "DeviceSlider") { Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { if (pumpSpeedLockTimer <= 0.0f) { TargetLevel = null; } float newValue = barScroll * 200.0f - 100.0f; if (Math.Abs(newValue - FlowPercentage) < 0.1f) { return(false); } FlowPercentage = newValue; if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); } }; var textsArea = new GUIFrame(new RectTransform(new Vector2(1, 0.25f), sliderArea.RectTransform, Anchor.BottomCenter), style: null); var outLabel = new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), textsArea.RectTransform, Anchor.CenterLeft), TextManager.Get("PumpOut"), textColor: GUI.Style.TextColor, textAlignment: Alignment.CenterLeft, wrap: false, font: GUI.SubHeadingFont); var inLabel = new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), textsArea.RectTransform, Anchor.CenterRight), TextManager.Get("PumpIn"), textColor: GUI.Style.TextColor, textAlignment: Alignment.CenterRight, wrap: false, font: GUI.SubHeadingFont); GUITextBlock.AutoScaleAndNormalize(outLabel, inLabel); }
partial void InitProjSpecific(XElement element) { // TODO: need to recreate the gui when the resolution changes fissionRateMeter = new Sprite(element.GetChildElement("fissionratemeter")?.GetChildElement("sprite")); turbineOutputMeter = new Sprite(element.GetChildElement("turbineoutputmeter")?.GetChildElement("sprite")); meterPointer = new Sprite(element.GetChildElement("meterpointer")?.GetChildElement("sprite")); sectorSprite = new Sprite(element.GetChildElement("sectorsprite")?.GetChildElement("sprite")); tempMeterFrame = new Sprite(element.GetChildElement("tempmeterframe")?.GetChildElement("sprite")); tempMeterBar = new Sprite(element.GetChildElement("tempmeterbar")?.GetChildElement("sprite")); tempRangeIndicator = new Sprite(element.GetChildElement("temprangeindicator")?.GetChildElement("sprite")); graphLine = new Sprite(element.GetChildElement("graphline")?.GetChildElement("sprite")); var paddedFrame = new GUILayoutGroup(new RectTransform( GuiFrame.Rect.Size - GUIStyle.ItemFrameMargin, GuiFrame.RectTransform, Anchor.Center) { AbsoluteOffset = GUIStyle.ItemFrameOffset }, isHorizontal: true) { RelativeSpacing = 0.012f, Stretch = true }; GUILayoutGroup columnLeft = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), paddedFrame.RectTransform)) { RelativeSpacing = 0.012f, Stretch = true }; GUILayoutGroup columnRight = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 1.0f), paddedFrame.RectTransform)) { CanBeFocused = true, RelativeSpacing = 0.012f, Stretch = true }; //---------------------------------------------------------- //left column //---------------------------------------------------------- GUIFrame inventoryWindow = new GUIFrame(new RectTransform(new Vector2(0.1f, 0.75f), GuiFrame.RectTransform, Anchor.TopLeft, Pivot.TopRight) { MinSize = new Point(85, 220), RelativeOffset = new Vector2(-0.02f, 0) }, style: "ItemUI"); GUILayoutGroup inventoryContent = new GUILayoutGroup(new RectTransform(inventoryWindow.Rect.Size - GUIStyle.ItemFrameMargin, inventoryWindow.RectTransform, Anchor.Center) { AbsoluteOffset = GUIStyle.ItemFrameOffset }, childAnchor: Anchor.TopCenter) { Stretch = true }; /*new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), inventoryContent.RectTransform), "", * textAlignment: Alignment.Center, font: GUI.SubHeadingFont, wrap: true);*/ inventoryContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.9f), inventoryContent.RectTransform), style: null); //---------------------------------------------------------- //mid column //---------------------------------------------------------- var topLeftArea = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.2f), columnLeft.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft) { Stretch = true }; Point maxIndicatorSize = new Point(int.MaxValue, (int)(40 * GUI.Scale)); criticalHeatWarning = new GUITickBox(new RectTransform(new Vector2(0.33f, 1.0f), topLeftArea.RectTransform) { MaxSize = maxIndicatorSize }, TextManager.Get("ReactorWarningCriticalTemp"), font: GUI.SubHeadingFont, style: "IndicatorLightRed") { CanBeFocused = false }; lowTemperatureWarning = new GUITickBox(new RectTransform(new Vector2(0.33f, 1.0f), topLeftArea.RectTransform) { MaxSize = maxIndicatorSize }, TextManager.Get("ReactorWarningCriticalLowTemp"), font: GUI.SubHeadingFont, style: "IndicatorLightRed") { CanBeFocused = false }; criticalOutputWarning = new GUITickBox(new RectTransform(new Vector2(0.33f, 1.0f), topLeftArea.RectTransform) { MaxSize = maxIndicatorSize }, TextManager.Get("ReactorWarningCriticalOutput"), font: GUI.SubHeadingFont, style: "IndicatorLightRed") { CanBeFocused = false }; List <GUITickBox> indicatorLights = new List <GUITickBox>() { criticalHeatWarning, lowTemperatureWarning, criticalOutputWarning }; indicatorLights.ForEach(l => l.TextBlock.OverrideTextColor(GUI.Style.TextColor)); topLeftArea.Recalculate(); new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), columnLeft.RectTransform), style: "HorizontalLine"); float relativeYMargin = 0.02f; Vector2 relativeTextSize = new Vector2(0.9f, 0.2f); Vector2 sliderSize = new Vector2(1.0f, 0.125f); Vector2 meterSize = new Vector2(1, 1 - relativeTextSize.Y - relativeYMargin - sliderSize.Y - 0.1f); var meterArea = new GUIFrame(new RectTransform(new Vector2(1, 0.6f - relativeYMargin * 2), columnLeft.RectTransform), style: null); var leftArea = new GUIFrame(new RectTransform(new Vector2(0.49f, 1), meterArea.RectTransform), style: null); var rightArea = new GUIFrame(new RectTransform(new Vector2(0.49f, 1), meterArea.RectTransform, Anchor.TopCenter, Pivot.TopLeft), style: null); var fissionRateTextBox = new GUITextBlock(new RectTransform(relativeTextSize, leftArea.RectTransform, Anchor.TopCenter), TextManager.Get("ReactorFissionRate"), textColor: GUI.Style.TextColor, textAlignment: Alignment.Center, font: GUI.SubHeadingFont) { AutoScaleHorizontal = true }; var fissionMeter = new GUICustomComponent(new RectTransform(meterSize, leftArea.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, relativeTextSize.Y + relativeYMargin) }, DrawFissionRateMeter, null) { ToolTip = TextManager.Get("ReactorTipFissionRate") }; var turbineOutputTextBox = new GUITextBlock(new RectTransform(relativeTextSize, rightArea.RectTransform, Anchor.TopCenter), TextManager.Get("ReactorTurbineOutput"), textColor: GUI.Style.TextColor, textAlignment: Alignment.Center, font: GUI.SubHeadingFont) { AutoScaleHorizontal = true }; GUITextBlock.AutoScaleAndNormalize(turbineOutputTextBox, fissionRateTextBox); var turbineMeter = new GUICustomComponent(new RectTransform(meterSize, rightArea.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, relativeTextSize.Y + relativeYMargin) }, DrawTurbineOutputMeter, null) { ToolTip = TextManager.Get("ReactorTipTurbineOutput") }; FissionRateScrollBar = new GUIScrollBar(new RectTransform(sliderSize, leftArea.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0, fissionMeter.RectTransform.RelativeOffset.Y + meterSize.Y) }, style: "DeviceSlider", barSize: 0.15f) { Enabled = false, Step = 1.0f / 255, OnMoved = (GUIScrollBar bar, float scrollAmount) => { LastUser = Character.Controlled; unsentChanges = true; targetFissionRate = scrollAmount * 100.0f; return(false); } }; TurbineOutputScrollBar = new GUIScrollBar(new RectTransform(sliderSize, rightArea.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0, turbineMeter.RectTransform.RelativeOffset.Y + meterSize.Y) }, style: "DeviceSlider", barSize: 0.15f, isHorizontal: true) { Enabled = false, Step = 1.0f / 255, OnMoved = (GUIScrollBar bar, float scrollAmount) => { LastUser = Character.Controlled; unsentChanges = true; targetTurbineOutput = scrollAmount * 100.0f; return(false); } }; var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.2f), columnLeft.RectTransform)) { Stretch = true, RelativeSpacing = 0.02f }; var upperButtons = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.5f), buttonArea.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.01f }; var lowerButtons = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.5f), buttonArea.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.01f }; int buttonCount = warningTexts.Length; for (int i = 0; i < buttonCount; i++) { string text = warningTexts[i]; var b = new GUIButton(new RectTransform(Vector2.One, (i < 4) ? upperButtons.RectTransform : lowerButtons.RectTransform), TextManager.Get(text), style: "IndicatorButton") { Font = GUI.SubHeadingFont, CanBeFocused = false }; warningButtons.Add(text, b); } upperButtons.Recalculate(); lowerButtons.Recalculate(); //only wrap texts that consist of multiple words and are way too big to fit otherwise warningButtons.Values.ForEach(b => b.TextBlock.Wrap = b.Text.Contains(' ') && b.TextBlock.TextSize.X > b.TextBlock.Rect.Width * 1.5f); GUITextBlock.AutoScaleAndNormalize(warningButtons.Values.Select(b => b.TextBlock)); //---------------------------------------------------------- //right column //---------------------------------------------------------- // Auto temp var topRightArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.25f), columnRight.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft) { Stretch = true, RelativeSpacing = 0.02f }; topRightArea.RectTransform.MinSize = new Point(0, topLeftArea.Rect.Height); topRightArea.RectTransform.MaxSize = new Point(int.MaxValue, topLeftArea.Rect.Height); new GUIFrame(new RectTransform(new Vector2(0.01f, 1.0f), topRightArea.RectTransform), style: "VerticalLine"); AutoTempSwitch = new GUIButton(new RectTransform(new Vector2(0.15f, 0.9f), topRightArea.RectTransform), style: "SwitchVertical") { Enabled = false, Selected = AutoTemp, OnClicked = (button, data) => { AutoTemp = !AutoTemp; LastUser = Character.Controlled; unsentChanges = true; return(true); } }; AutoTempSwitch.RectTransform.MaxSize = new Point((int)(AutoTempSwitch.Rect.Height * 0.4f), int.MaxValue); autoTempLight = new GUITickBox(new RectTransform(new Vector2(0.4f, 1.0f), topRightArea.RectTransform), TextManager.Get("ReactorAutoTemp"), font: GUI.SubHeadingFont, style: "IndicatorLightYellow") { ToolTip = TextManager.Get("ReactorTipAutoTemp"), CanBeFocused = false, Selected = AutoTemp }; autoTempLight.RectTransform.MaxSize = new Point(int.MaxValue, criticalHeatWarning.Rect.Height); autoTempLight.TextBlock.OverrideTextColor(GUI.Style.TextColor); new GUIFrame(new RectTransform(new Vector2(0.01f, 1.0f), topRightArea.RectTransform), style: "VerticalLine"); // Power button var powerArea = new GUIFrame(new RectTransform(new Vector2(0.4f, 1.0f), topRightArea.RectTransform), style: null); var paddedPowerArea = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), powerArea.RectTransform, Anchor.Center, scaleBasis: ScaleBasis.BothHeight), style: "PowerButtonFrame"); powerLight = new GUITickBox(new RectTransform(new Vector2(0.87f, 0.3f), paddedPowerArea.RectTransform, Anchor.TopCenter, Pivot.Center), TextManager.Get("PowerLabel"), font: GUI.SubHeadingFont, style: "IndicatorLightPower") { CanBeFocused = false, Selected = _powerOn }; powerLight.TextBlock.Padding = new Vector4(5.0f, 0.0f, 0.0f, 0.0f); powerLight.TextBlock.AutoScaleHorizontal = true; powerLight.TextBlock.OverrideTextColor(GUI.Style.TextColor); PowerButton = new GUIButton(new RectTransform(new Vector2(0.8f, 0.75f), paddedPowerArea.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0, 0.1f) }, style: "PowerButton") { OnClicked = (button, data) => { PowerOn = !PowerOn; LastUser = Character.Controlled; unsentChanges = true; return(true); } }; topRightArea.Recalculate(); autoTempLight.TextBlock.Wrap = true; indicatorLights.Add(autoTempLight); GUITextBlock.AutoScaleAndNormalize(indicatorLights.Select(l => l.TextBlock)); // right bottom (graph area) ----------------------- new GUIFrame(new RectTransform(new Vector2(0.95f, 0.01f), columnRight.RectTransform), style: "HorizontalLine"); var bottomRightArea = new GUILayoutGroup(new RectTransform(Vector2.One, columnRight.RectTransform), isHorizontal: true) { Stretch = true, CanBeFocused = true, RelativeSpacing = 0.02f }; new GUIFrame(new RectTransform(new Vector2(0.01f, 1.0f), bottomRightArea.RectTransform), style: "VerticalLine"); new GUICustomComponent(new RectTransform(new Vector2(0.1f, 1), bottomRightArea.RectTransform, Anchor.Center), DrawTempMeter, null); var graphArea = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), bottomRightArea.RectTransform)) { Stretch = true, RelativeSpacing = 0.02f }; relativeTextSize = new Vector2(1.0f, 0.15f); var loadText = new GUITextBlock(new RectTransform(relativeTextSize, graphArea.RectTransform), "Load", textColor: loadColor, font: GUI.SubHeadingFont, textAlignment: Alignment.CenterLeft) { ToolTip = TextManager.Get("ReactorTipLoad") }; string loadStr = TextManager.Get("ReactorLoad"); string kW = TextManager.Get("kilowatt"); loadText.TextGetter += () => $"{loadStr.Replace("[kw]", ((int)load).ToString())} {kW}"; var graph = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.9f), graphArea.RectTransform), style: "InnerFrameRed"); new GUICustomComponent(new RectTransform(new Vector2(0.9f, 0.98f), graph.RectTransform, Anchor.Center), DrawGraph, null); var outputText = new GUITextBlock(new RectTransform(relativeTextSize, graphArea.RectTransform), "Output", textColor: outputColor, font: GUI.SubHeadingFont, textAlignment: Alignment.CenterLeft) { ToolTip = TextManager.Get("ReactorTipPower") }; string outputStr = TextManager.Get("ReactorOutput"); outputText.TextGetter += () => $"{outputStr.Replace("[kw]", ((int)-currPowerConsumption).ToString())} {kW}"; }
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]); }
partial void InitProjSpecific(XElement element) { sonarBlips = new List <SonarBlip>(); int viewSize = (int)Math.Min(GuiFrame.Rect.Width - 150, GuiFrame.Rect.Height * 0.9f); sonarView = new GUICustomComponent(new RectTransform(new Point(viewSize), GuiFrame.RectTransform, Anchor.CenterLeft), (spriteBatch, guiCustomComponent) => { DrawSonar(spriteBatch, guiCustomComponent.Rect); }, null); var controlContainer = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.35f), GuiFrame.RectTransform, Anchor.TopLeft) { MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0) }, "SonarFrame"); controlContainer.RectTransform.SetAsFirstChild(); var paddedControlContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), controlContainer.RectTransform, Anchor.Center)) { RelativeSpacing = 0.03f, Stretch = true }; passiveTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.2f), paddedControlContainer.RectTransform), TextManager.Get("SonarPassive"), style: "GUIRadioButton") { ToolTip = TextManager.Get("SonarTipPassive"), Selected = true }; activeTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.2f), paddedControlContainer.RectTransform), TextManager.Get("SonarActive"), style: "GUIRadioButton") { ToolTip = TextManager.Get("SonarTipActive"), OnSelected = (GUITickBox box) => { if (GameMain.Server != null) { unsentChanges = true; } else if (GameMain.Client != null) { unsentChanges = true; correctionTimer = CorrectionDelay; } IsActive = box.Selected; return(true); } }; var zoomContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.2f), paddedControlContainer.RectTransform), isHorizontal: true); new GUITextBlock(new RectTransform(new Vector2(0.35f, 1.0f), zoomContainer.RectTransform), TextManager.Get("SonarZoom"), font: GUI.SmallFont) { Padding = Vector4.Zero }; zoomSlider = new GUIScrollBar(new RectTransform(new Vector2(0.65f, 1.0f), zoomContainer.RectTransform), barSize: 0.1f, isHorizontal: true) { OnMoved = (scrollbar, scroll) => { zoom = MathHelper.Lerp(MinZoom, MaxZoom, scroll); if (GameMain.Server != null) { unsentChanges = true; } else if (GameMain.Client != null) { unsentChanges = true; correctionTimer = CorrectionDelay; } return(true); } }; var activeControls = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.6f), paddedControlContainer.RectTransform) { RelativeOffset = new Vector2(0.1f, 0.0f) }, "InnerFrame"); activeControlsContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), activeControls.RectTransform, Anchor.Center)) { RelativeSpacing = 0.03f, Stretch = true }; directionalTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.3f), activeControlsContainer.RectTransform), TextManager.Get("SonarDirectionalPing")) { OnSelected = (tickBox) => { useDirectionalPing = tickBox.Selected; if (GameMain.Server != null) { unsentChanges = true; } else if (GameMain.Client != null) { unsentChanges = true; correctionTimer = CorrectionDelay; } return(true); } }; directionalSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.3f), activeControlsContainer.RectTransform), barSize: 0.1f, isHorizontal: true) { OnMoved = (scrollbar, scroll) => { float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, scroll); pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle)); if (GameMain.Server != null) { unsentChanges = true; } else if (GameMain.Client != null) { unsentChanges = true; correctionTimer = CorrectionDelay; } return(true); } }; signalWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedControlContainer.RectTransform), "", Color.Orange, textAlignment: Alignment.Center); GUITickBox.CreateRadioButtonGroup(new List <GUITickBox>() { activeTickBox, passiveTickBox }); GuiFrame.CanBeFocused = false; }
partial void InitProjSpecific(XElement element) { var paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.85f, 0.65f), GuiFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0, 0.04f) }, style: null); var lightsArea = new GUIFrame(new RectTransform(new Vector2(1, 0.38f), paddedFrame.RectTransform, Anchor.TopLeft), style: null); powerIndicator = new GUITickBox(new RectTransform(new Vector2(0.45f, 0.8f), lightsArea.RectTransform, Anchor.Center, Pivot.CenterRight) { RelativeOffset = new Vector2(-0.05f, 0) }, TextManager.Get("EnginePowered"), font: GUI.SubHeadingFont, style: "IndicatorLightGreen") { CanBeFocused = false }; autoControlIndicator = new GUITickBox(new RectTransform(new Vector2(0.45f, 0.8f), lightsArea.RectTransform, Anchor.Center, Pivot.CenterLeft) { RelativeOffset = new Vector2(0.05f, 0) }, TextManager.Get("PumpAutoControl", fallBackTag: "ReactorAutoControl"), font: GUI.SubHeadingFont, style: "IndicatorLightYellow") { Selected = false, Enabled = false, ToolTip = TextManager.Get("AutoControlTip") }; powerIndicator.TextBlock.Wrap = autoControlIndicator.TextBlock.Wrap = true; powerIndicator.TextBlock.OverrideTextColor(GUI.Style.TextColor); autoControlIndicator.TextBlock.OverrideTextColor(GUI.Style.TextColor); GUITextBlock.AutoScaleAndNormalize(powerIndicator.TextBlock, autoControlIndicator.TextBlock); var sliderArea = new GUIFrame(new RectTransform(new Vector2(1, 0.6f), paddedFrame.RectTransform, Anchor.BottomLeft), style: null); string powerLabel = TextManager.Get("EngineForce"); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), sliderArea.RectTransform, Anchor.TopCenter), "", textColor: GUI.Style.TextColor, font: GUI.SubHeadingFont, textAlignment: Alignment.Center) { AutoScaleHorizontal = true, TextGetter = () => { return(TextManager.AddPunctuation(':', powerLabel, (int)(targetForce) + " %")); } }; forceSlider = new GUIScrollBar(new RectTransform(new Vector2(0.95f, 0.45f), sliderArea.RectTransform, Anchor.Center), barSize: 0.1f, style: "DeviceSlider") { Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { float newTargetForce = barScroll * 200.0f - 100.0f; if (Math.Abs(newTargetForce - targetForce) < 0.01) { return(false); } targetForce = newTargetForce; User = Character.Controlled; if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); } }; var textsArea = new GUIFrame(new RectTransform(new Vector2(1, 0.25f), sliderArea.RectTransform, Anchor.BottomCenter), style: null); var backwardsLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1.0f), textsArea.RectTransform, Anchor.CenterLeft), TextManager.Get("EngineBackwards"), textColor: GUI.Style.TextColor, font: GUI.SubHeadingFont, textAlignment: Alignment.CenterLeft); var forwardsLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1.0f), textsArea.RectTransform, Anchor.CenterRight), TextManager.Get("EngineForwards"), textColor: GUI.Style.TextColor, font: GUI.SubHeadingFont, textAlignment: Alignment.CenterRight); GUITextBlock.AutoScaleAndNormalize(backwardsLabel, forwardsLabel); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "propellersprite": propellerSprite = new SpriteSheet(subElement); AnimSpeed = subElement.GetAttributeFloat("animspeed", 1.0f); break; } } }
partial void InitProjSpecific(XElement element) { foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "pumpoutemitter": pumpOutEmitters.Add(new Pair <Vector2, ParticleEmitter>( subElement.GetAttributeVector2("position", Vector2.Zero), new ParticleEmitter(subElement))); break; case "pumpinemitter": pumpInEmitters.Add(new Pair <Vector2, ParticleEmitter>( subElement.GetAttributeVector2("position", Vector2.Zero), new ParticleEmitter(subElement))); break; } } if (GuiFrame == null) { return; } GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center), style: null); isActiveSlider = new GUIScrollBar(new RectTransform(new Point(50, 100), paddedFrame.RectTransform, Anchor.CenterLeft), barSize: 0.2f, style: "OnOffLever") { IsBooleanSwitch = true, MinValue = 0.25f, MaxValue = 0.75f }; var sliderHandle = isActiveSlider.GetChild <GUIButton>(); sliderHandle.RectTransform.NonScaledSize = new Point(84, sliderHandle.Rect.Height); isActiveSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { bool active = scrollBar.BarScroll < 0.5f; if (active == IsActive) { return(false); } targetLevel = null; IsActive = active; if (!IsActive) { currPowerConsumption = 0.0f; } if (GameMain.Server != null) { item.CreateServerEvent(this); GameServer.Log(Character.Controlled.LogName + (IsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction); } else if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); }; var rightArea = new GUILayoutGroup(new RectTransform(new Vector2(0.75f, 1.0f), paddedFrame.RectTransform, Anchor.CenterRight)) { RelativeSpacing = 0.1f }; powerIndicator = new GUITickBox(new RectTransform(new Point(30, 30), rightArea.RectTransform), TextManager.Get("PumpPowered"), style: "IndicatorLightGreen") { CanBeFocused = false }; var pumpSpeedText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), rightArea.RectTransform) { RelativeOffset = new Vector2(0.25f, 0.0f) }, "", textAlignment: Alignment.BottomLeft); string pumpSpeedStr = TextManager.Get("PumpSpeed"); pumpSpeedText.TextGetter = () => { return(pumpSpeedStr + ": " + (int)flowPercentage + " %"); }; var sliderArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.3f), rightArea.RectTransform, Anchor.CenterLeft), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform), TextManager.Get("PumpOut"), textAlignment: Alignment.Center); pumpSpeedSlider = new GUIScrollBar(new RectTransform(new Vector2(0.8f, 1.0f), sliderArea.RectTransform), barSize: 0.25f, style: "GUISlider") { Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { float newValue = barScroll * 200.0f - 100.0f; if (Math.Abs(newValue - FlowPercentage) < 0.1f) { return(false); } FlowPercentage = newValue; if (GameMain.Server != null) { item.CreateServerEvent(this); GameServer.Log(Character.Controlled.LogName + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", ServerLog.MessageType.ItemInteraction); } else if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); } }; new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform), TextManager.Get("PumpIn"), textAlignment: Alignment.Center); }
partial void InitProjSpecific(XElement element) { var content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.05f }; int indicatorSize = (int)(30 * GUI.Scale); powerIndicator = new GUITickBox(new RectTransform(new Point(indicatorSize, indicatorSize), content.RectTransform), TextManager.Get("EnginePowered"), style: "IndicatorLightGreen") { CanBeFocused = false }; string powerLabel = TextManager.Get("EngineForce"); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), content.RectTransform), "", textAlignment: Alignment.Center) { TextGetter = () => { return(TextManager.AddPunctuation(':', powerLabel, (int)(targetForce) + " %")); } }; forceSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.3f), content.RectTransform), barSize: 0.2f, style: "GUISlider") { Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { float newTargetForce = barScroll * 200.0f - 100.0f; if (Math.Abs(newTargetForce - targetForce) < 0.01) { return(false); } targetForce = newTargetForce; if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); } }; var textArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.2f), content.RectTransform), isHorizontal: true) { Stretch = true }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), textArea.RectTransform), TextManager.Get("EngineBackwards"), font: GUI.SmallFont, textAlignment: Alignment.CenterLeft); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), textArea.RectTransform), TextManager.Get("EngineForwards"), font: GUI.SmallFont, textAlignment: Alignment.CenterRight); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "propellersprite": propellerSprite = new SpriteSheet(subElement); AnimSpeed = subElement.GetAttributeFloat("animspeed", 1.0f); break; } } }
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { base.Draw(spriteBatch); if (settingsFrame != null) { settingsFrame.Draw(spriteBatch); } else if (log.LogFrame != null) { log.LogFrame.Draw(spriteBatch); } if (!ShowNetStats) { return; } GUI.Font.DrawString(spriteBatch, "Unique Events: " + entityEventManager.UniqueEvents.Count, new Vector2(10, 50), Color.White); int width = 200, height = 300; int x = GameMain.GraphicsWidth - width, y = (int)(GameMain.GraphicsHeight * 0.3f); if (clientListScrollBar == null) { clientListScrollBar = new GUIScrollBar(new Rectangle(x + width - 10, y, 10, height), "", 1.0f); } GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black * 0.7f, true); GUI.Font.DrawString(spriteBatch, "Network statistics:", new Vector2(x + 10, y + 10), Color.White); GUI.SmallFont.DrawString(spriteBatch, "Connections: " + server.ConnectionsCount, new Vector2(x + 10, y + 30), Color.White); GUI.SmallFont.DrawString(spriteBatch, "Received bytes: " + MathUtils.GetBytesReadable(server.Statistics.ReceivedBytes), new Vector2(x + 10, y + 45), Color.White); GUI.SmallFont.DrawString(spriteBatch, "Received packets: " + server.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White); GUI.SmallFont.DrawString(spriteBatch, "Sent bytes: " + MathUtils.GetBytesReadable(server.Statistics.SentBytes), new Vector2(x + 10, y + 75), Color.White); GUI.SmallFont.DrawString(spriteBatch, "Sent packets: " + server.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); int resentMessages = 0; int clientListHeight = connectedClients.Count * 40; float scrollBarHeight = (height - 110) / (float)Math.Max(clientListHeight, 110); if (clientListScrollBar.BarSize != scrollBarHeight) { clientListScrollBar.BarSize = scrollBarHeight; } int startY = y + 110; y = (startY - (int)(clientListScrollBar.BarScroll * (clientListHeight - (height - 110)))); foreach (Client c in connectedClients) { Color clientColor = c.Connection.AverageRoundtripTime > 0.3f ? Color.Red : Color.White; if (y >= startY && y < startY + height - 120) { GUI.SmallFont.DrawString(spriteBatch, c.name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")", new Vector2(x + 10, y), clientColor); GUI.SmallFont.DrawString(spriteBatch, "Ping: " + (int)(c.Connection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x + 20, y + 10), clientColor); } if (y + 25 >= startY && y < startY + height - 130) { GUI.SmallFont.DrawString(spriteBatch, "Resent messages: " + c.Connection.Statistics.ResentMessages, new Vector2(x + 20, y + 20), clientColor); } resentMessages += (int)c.Connection.Statistics.ResentMessages; y += 40; } clientListScrollBar.Update(1.0f / 60.0f); clientListScrollBar.Draw(spriteBatch); netStats.AddValue(NetStats.NetStatType.ResentMessages, Math.Max(resentMessages, 0)); netStats.AddValue(NetStats.NetStatType.SentBytes, server.Statistics.SentBytes); netStats.AddValue(NetStats.NetStatType.ReceivedBytes, server.Statistics.ReceivedBytes); netStats.Draw(spriteBatch, new Rectangle(200, 0, 800, 200), this); }
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 countText = new GUITextBlock( new Rectangle(160, 0, 55, 25), cargoVal.ToString(), "", Alignment.Left, Alignment.Center, textBlock); var incButton = new GUIButton(new Rectangle(200, 5, 15, 15), ">", "", textBlock); incButton.UserData = countText; incButton.OnClicked = (button, obj) => { int val; if (extraCargo.TryGetValue(pf.Name, out val)) { extraCargo[pf.Name]++; val = extraCargo[pf.Name]; } else { extraCargo.Add(pf.Name, 1); val = 1; } ((GUITextBlock)obj).Text = val.ToString(); ((GUITextBlock)obj).SetTextPos(); return(true); }; var decButton = new GUIButton(new Rectangle(160, 5, 15, 15), "<", "", textBlock); decButton.UserData = countText; decButton.OnClicked = (button, obj) => { int val; if (extraCargo.TryGetValue(pf.Name, out val)) { extraCargo[pf.Name]--; val = extraCargo[pf.Name]; if (val <= 0) { extraCargo.Remove(pf.Name); val = 0; } ((GUITextBlock)obj).Text = val.ToString(); ((GUITextBlock)obj).SetTextPos(); } return(true); }; } //-------------------------------------------------------------------------------- // server settings //-------------------------------------------------------------------------------- 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; 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]); }
partial void InitProjSpecific(XElement element) { foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "fissionratemeter": fissionRateMeter = new Sprite(subElement); break; case "turbineoutputmeter": turbineOutputMeter = new Sprite(subElement); break; case "meterpointer": meterPointer = new Sprite(subElement); break; case "sectorsprite": sectorSprite = new Sprite(subElement); break; case "tempmeterframe": tempMeterFrame = new Sprite(subElement); break; case "tempmeterbar": tempMeterBar = new Sprite(subElement); break; case "temprangeindicator": tempRangeIndicator = new Sprite(subElement); break; case "graphline": graphLine = new Sprite(subElement); break; } } var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.85f), GuiFrame.RectTransform, Anchor.Center), isHorizontal: true) { RelativeSpacing = 0.012f, Stretch = true }; GUIFrame columnLeft = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), paddedFrame.RectTransform), style: null); GUIFrame columnMid = new GUIFrame(new RectTransform(new Vector2(0.45f, 1.0f), paddedFrame.RectTransform), style: null); GUIFrame columnRight = new GUIFrame(new RectTransform(new Vector2(0.3f, 1.0f), paddedFrame.RectTransform), style: null); leftHUDColumn = columnLeft; midHUDColumn = columnMid; rightHUDColumn = columnRight; //---------------------------------------------------------- //left column //---------------------------------------------------------- int buttonsPerRow = 2; int spacing = 5; int buttonWidth = columnLeft.Rect.Width / buttonsPerRow - (spacing * (buttonsPerRow - 1)); int buttonHeight = (int)(columnLeft.Rect.Height * 0.5f) / 4; for (int i = 0; i < warningTexts.Length; i++) { var warningBtn = new GUIButton(new RectTransform(new Point(buttonWidth, buttonHeight), columnLeft.RectTransform) { AbsoluteOffset = new Point((i % buttonsPerRow) * (buttonWidth + spacing), (int)Math.Floor(i / (float)buttonsPerRow) * (buttonHeight + spacing)) }, TextManager.Get(warningTexts[i]), style: "IndicatorButton") { CanBeFocused = false }; var btnText = warningBtn.GetChild <GUITextBlock>(); btnText.Font = GUI.Font; btnText.Wrap = false; btnText.SetTextPos(); warningButtons.Add(warningTexts[i], warningBtn); } GUITextBlock.AutoScaleAndNormalize(warningButtons.Values.Select(b => b.TextBlock)); inventoryContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.45f), columnLeft.RectTransform, Anchor.BottomLeft), style: null); //---------------------------------------------------------- //mid column //---------------------------------------------------------- criticalHeatWarning = new GUITickBox(new RectTransform(new Point(columnMid.Rect.Width / 3, (int)(30 * GUI.Scale)), columnMid.RectTransform), TextManager.Get("ReactorWarningCriticalTemp"), font: GUI.SmallFont, style: "IndicatorLightRed") { CanBeFocused = false }; lowTemperatureWarning = new GUITickBox(new RectTransform(new Point(columnMid.Rect.Width / 3, (int)(30 * GUI.Scale)), columnMid.RectTransform) { RelativeOffset = new Vector2(0.27f, 0.0f) }, TextManager.Get("ReactorWarningCriticalLowTemp"), font: GUI.SmallFont, style: "IndicatorLightRed") { CanBeFocused = false }; criticalOutputWarning = new GUITickBox(new RectTransform(new Point(columnMid.Rect.Width / 3, (int)(30 * GUI.Scale)), columnMid.RectTransform) { RelativeOffset = new Vector2(0.66f, 0.0f) }, TextManager.Get("ReactorWarningCriticalOutput"), font: GUI.SmallFont, style: "IndicatorLightRed") { CanBeFocused = false }; GUITextBlock.AutoScaleAndNormalize(criticalHeatWarning.TextBlock, lowTemperatureWarning.TextBlock, criticalOutputWarning.TextBlock); float gaugeOffset = criticalHeatWarning.Rect.Height / (float)columnMid.Rect.Height + 0.05f * GUI.Scale; new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.05f), columnMid.RectTransform) { RelativeOffset = new Vector2(0.0f, gaugeOffset) }, TextManager.Get("ReactorFissionRate")); new GUICustomComponent(new RectTransform(new Vector2(0.5f, 0.5f), columnMid.RectTransform) { RelativeOffset = new Vector2(0.0f, gaugeOffset + 0.05f) }, DrawFissionRateMeter, null) { ToolTip = TextManager.Get("ReactorTipFissionRate") }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.05f), columnMid.RectTransform, Anchor.TopRight) { RelativeOffset = new Vector2(0.0f, gaugeOffset) }, TextManager.Get("ReactorTurbineOutput")); new GUICustomComponent(new RectTransform(new Vector2(0.5f, 0.5f), columnMid.RectTransform, Anchor.TopRight) { RelativeOffset = new Vector2(0.0f, gaugeOffset + 0.05f) }, DrawTurbineOutputMeter, null) { ToolTip = TextManager.Get("ReactorTipTurbineOutput") }; GUILayoutGroup sliderControls = new GUILayoutGroup(new RectTransform(new Point(columnMid.Rect.Width, (int)(114 * GUI.Scale)), columnMid.RectTransform, Anchor.BottomCenter)) { Stretch = true, AbsoluteSpacing = (int)(5 * GUI.Scale) }; sliderControlsContainer = sliderControls; new GUITextBlock(new RectTransform(new Point(0, (int)(20 * GUI.Scale)), sliderControls.RectTransform, Anchor.TopLeft), TextManager.Get("ReactorFissionRate")); fissionRateScrollBar = new GUIScrollBar(new RectTransform(new Point(sliderControls.Rect.Width, (int)(30 * GUI.Scale)), sliderControls.RectTransform, Anchor.TopCenter), style: "GUISlider", barSize: 0.1f) { OnMoved = (GUIScrollBar bar, float scrollAmount) => { LastUser = Character.Controlled; unsentChanges = true; targetFissionRate = scrollAmount * 100.0f; return(false); } }; new GUITextBlock(new RectTransform(new Point(0, (int)(20 * GUI.Scale)), sliderControls.RectTransform, Anchor.BottomLeft), TextManager.Get("ReactorTurbineOutput")); turbineOutputScrollBar = new GUIScrollBar(new RectTransform(new Point(sliderControls.Rect.Width, (int)(30 * GUI.Scale)), sliderControls.RectTransform, Anchor.BottomCenter), style: "GUISlider", barSize: 0.1f, isHorizontal: true) { OnMoved = (GUIScrollBar bar, float scrollAmount) => { LastUser = Character.Controlled; unsentChanges = true; targetTurbineOutput = scrollAmount * 100.0f; return(false); } }; //---------------------------------------------------------- //right column //---------------------------------------------------------- new GUITextBlock(new RectTransform(new Vector2(0.7f, 0.1f), columnRight.RectTransform), TextManager.Get("ReactorAutoTemp")) { ToolTip = TextManager.Get("ReactorTipAutoTemp"), AutoScale = true }; autoTempSlider = new GUIScrollBar(new RectTransform(new Vector2(0.6f, 0.15f), columnRight.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.1f) }, barSize: 0.55f, style: "OnOffSlider", isHorizontal: true) { ToolTip = TextManager.Get("ReactorTipAutoTemp"), IsBooleanSwitch = true, BarScroll = 1.0f, OnMoved = (scrollBar, scrollAmount) => { LastUser = Character.Controlled; unsentChanges = true; return(true); } }; var sliderSprite = autoTempSlider.Frame.Style.Sprites[GUIComponent.ComponentState.None].First(); autoTempSlider.RectTransform.MaxSize = new Point((int)(sliderSprite.Sprite.SourceRect.Size.X * GUI.Scale), (int)(sliderSprite.Sprite.SourceRect.Size.Y * GUI.Scale)); onOffSwitch = new GUIScrollBar(new RectTransform(new Vector2(0.4f, 0.3f), columnRight.RectTransform, Anchor.TopRight), barSize: 0.2f, style: "OnOffLever", isHorizontal: false) { IsBooleanSwitch = true, MinValue = 0.25f, MaxValue = 0.75f, OnMoved = (scrollBar, scrollAmount) => { LastUser = Character.Controlled; unsentChanges = true; return(true); } }; var switchSprite = onOffSwitch.Frame.Style.Sprites[GUIComponent.ComponentState.None].First(); onOffSwitch.RectTransform.MaxSize = new Point((int)(switchSprite.Sprite.SourceRect.Size.X * GUI.Scale), (int)(switchSprite.Sprite.SourceRect.Size.Y * GUI.Scale)); var lever = onOffSwitch.GetChild <GUIButton>(); lever.RectTransform.NonScaledSize = new Point(lever.Rect.Width + (int)(30 * GUI.Scale), lever.Rect.Height); var graphArea = new GUICustomComponent(new RectTransform(new Vector2(1.0f, 0.5f), columnRight.RectTransform, Anchor.BottomCenter) { AbsoluteOffset = new Point(0, 30) }, DrawGraph, null); Point textSize = new Point((int)(100 * GUI.Scale), (int)(30 * GUI.Scale)); var loadText = new GUITextBlock(new RectTransform(textSize, graphArea.RectTransform, Anchor.TopLeft, Pivot.BottomLeft), "Load", textColor: Color.LightBlue, textAlignment: Alignment.CenterLeft) { ToolTip = TextManager.Get("ReactorTipLoad") }; string loadStr = TextManager.Get("ReactorLoad"); loadText.TextGetter += () => { return(loadStr.Replace("[kw]", ((int)load).ToString())); }; var outputText = new GUITextBlock(new RectTransform(textSize, graphArea.RectTransform, Anchor.BottomLeft, Pivot.TopLeft), "Output", textColor: Color.LightGreen, textAlignment: Alignment.CenterLeft) { ToolTip = TextManager.Get("ReactorTipPower") }; string outputStr = TextManager.Get("ReactorOutput"); outputText.TextGetter += () => { return(outputStr.Replace("[kw]", ((int)-currPowerConsumption).ToString())); }; }
partial void InitProjSpecific() { if (GuiFrame == null) { return; } GUILayoutGroup paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.7f), GuiFrame.RectTransform, Anchor.Center)) { RelativeSpacing = 0.1f, Stretch = true }; string rechargeStr = TextManager.Get("PowerContainerRechargeRate"); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform), "RechargeRate", textAlignment: Alignment.Center) { TextGetter = () => { return(rechargeStr.Replace("[rate]", ((int)((rechargeSpeed / maxRechargeSpeed) * 100.0f)).ToString())); } }; var sliderArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform, Anchor.BottomCenter), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform), "0 %", textAlignment: Alignment.Center); rechargeSpeedSlider = new GUIScrollBar(new RectTransform(new Vector2(0.8f, 1.0f), sliderArea.RectTransform), barSize: 0.25f, style: "GUISlider") { Step = 0.1f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { float newRechargeSpeed = maxRechargeSpeed * barScroll; if (Math.Abs(newRechargeSpeed - rechargeSpeed) < 0.1f) { return(false); } RechargeSpeed = newRechargeSpeed; if (GameMain.Client != null) { item.CreateClientEvent(this); correctionTimer = CorrectionDelay; } return(true); } }; new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform), "100 %", textAlignment: Alignment.Center); string chargeStr = TextManager.Get("PowerContainerCharge"); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform), "Charge", textAlignment: Alignment.Center) { TextGetter = () => { return(chargeStr.Replace("[charge]", (int)charge + "/" + (int)capacity).Replace("[percentage]", ((int)((charge / capacity) * 100.0f)).ToString())); } }; chargeIndicator = new GUIProgressBar(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), barSize: 0.0f) { ProgressGetter = () => { return(capacity <= 0.0f ? 1.0f : charge / capacity); } }; }
partial void InitProjSpecific(XElement element) { powerIndicator = new GUITickBox(new RectTransform(new Point(30, 30), GuiFrame.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.15f) }, TextManager.Get("EnginePowered"), style: "IndicatorLightGreen") { CanBeFocused = false }; string powerLabel = TextManager.Get("EngineForce"); new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.3f), GuiFrame.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0.0f, 0.4f) }, "", textAlignment: Alignment.Center) { TextGetter = () => { return(powerLabel + ": " + (int)(targetForce) + " %"); } }; var sliderArea = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.25f), GuiFrame.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0.0f, 0.2f) }, isHorizontal: true); new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), sliderArea.RectTransform), TextManager.Get("EngineBackwards"), font: GUI.SmallFont, textAlignment: Alignment.Center); forceSlider = new GUIScrollBar(new RectTransform(new Vector2(0.6f, 1.0f), sliderArea.RectTransform), barSize: 0.25f, style: "GUISlider") { Step = 0.05f, OnMoved = (GUIScrollBar scrollBar, float barScroll) => { float newTargetForce = barScroll * 200.0f - 100.0f; if (Math.Abs(newTargetForce - targetForce) < 0.01) { return(false); } targetForce = newTargetForce; if (GameMain.Server != null) { item.CreateServerEvent(this); GameServer.Log(Character.Controlled.LogName + " set the force speed of " + item.Name + " to " + (int)(targetForce) + " %", ServerLog.MessageType.ItemInteraction); } else if (GameMain.Client != null) { correctionTimer = CorrectionDelay; item.CreateClientEvent(this); } return(true); } }; new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), sliderArea.RectTransform), TextManager.Get("EngineForwards"), font: GUI.SmallFont, textAlignment: Alignment.Center); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "propellersprite": propellerSprite = new SpriteSheet(subElement); AnimSpeed = subElement.GetAttributeFloat("animspeed", 1.0f); break; } } }