public override void Update(float deltaTime) { if (!Visible) { return; } base.Update(deltaTime); if (MouseOn == frame) { if (PlayerInput.LeftButtonClicked()) { MoveButton(new Vector2( Math.Sign(PlayerInput.MousePosition.X - bar.Rect.Center.X) * bar.Rect.Width, Math.Sign(PlayerInput.MousePosition.Y - bar.Rect.Center.Y) * bar.Rect.Height)); } } if (draggingBar == this) { if (!PlayerInput.LeftButtonHeld()) { draggingBar = null; } MoveButton(PlayerInput.MouseSpeed); } }
private bool ChangeHUDScale(GUIScrollBar scrollBar, float barScroll) { UnsavedSettings = true; HUDScale = MathHelper.Lerp(MinHUDScale, MaxHUDScale, barScroll); OnHUDScaleChanged?.Invoke(); return(true); }
private void CreateLabeledSlider(GUIComponent parent, float min, float max, float step, string propertyName) { var container = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), parent.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f, ToolTip = TextManager.Get("Karma." + propertyName + "ToolTip") }; string labelText = TextManager.Get("Karma." + propertyName); var label = new GUITextBlock(new RectTransform(new Vector2(0.7f, 1.0f), container.RectTransform), labelText, textAlignment: Alignment.CenterLeft, font: GUI.SmallFont) { ToolTip = TextManager.Get("Karma." + propertyName + "ToolTip") }; var slider = new GUIScrollBar(new RectTransform(new Vector2(0.3f, 1.0f), container.RectTransform), barSize: 0.1f, style: "GUISlider") { Step = step <= 0.0f ? 0.0f : step / (max - min), Range = new Vector2(min, max), OnMoved = (GUIScrollBar scrollBar, float barScroll) => { string formattedValueStr = step >= 1.0f ? ((int)scrollBar.BarScrollValue).ToString() : scrollBar.BarScrollValue.Format(decimalCount: step <= 0.1f ? 2 : 1); label.Text = TextManager.AddPunctuation(':', labelText, formattedValueStr); return(true); } }; container.RectTransform.MinSize = new Point(0, container.RectTransform.Children.Max(c => c.MinSize.Y)); GameMain.NetworkMember.ServerSettings.AssignGUIComponent(propertyName, slider); slider.OnMoved(slider, slider.BarScroll); }
private bool ChangeParticleLimit(GUIScrollBar scrollBar, float barScroll) { UnsavedSettings = true; ParticleLimit = 200 + (int)(barScroll * 1300.0f); return(true); }
private bool ChangeMusicVolume(GUIScrollBar scrollBar, float barScroll) { UnsavedSettings = true; MusicVolume = barScroll; return(true); }
private bool ChangeSliderText(GUIScrollBar scrollBar, float barScroll) { UnsavedSettings = true; GUITextBlock text = scrollBar.UserData as GUITextBlock; //search for percentage value int index = text.Text.IndexOf("%"); string label = text.Text; //if "%" is found if (index > 0) { while (index > 0) { //search for end of label index -= 1; if (text.Text[index] == ' ') { break; } } label = text.Text.Substring(0, index); } text.Text = label + " " + barScroll * 100 + "%"; return(true); }
/// <param name="isScrollBarOnDefaultSide">For horizontal listbox, default side is on the bottom. For vertical, it's on the right.</param> public GUIListBox(RectTransform rectT, bool isHorizontal = false, Color?color = null, string style = "", bool isScrollBarOnDefaultSide = true, bool useMouseDownToSelect = false) : base(style, rectT) { this.isHorizontal = isHorizontal; HoverCursor = CursorState.Hand; CanBeFocused = true; selected = new List <GUIComponent>(); this.useMouseDownToSelect = useMouseDownToSelect; ContentBackground = new GUIFrame(new RectTransform(Vector2.One, rectT), style) { CanBeFocused = false }; Content = new GUIFrame(new RectTransform(Vector2.One, ContentBackground.RectTransform), style: null) { CanBeFocused = false }; Content.RectTransform.ChildrenChanged += (_) => { scrollBarNeedsRecalculation = true; childrenNeedsRecalculation = true; }; if (style != null) { GUI.Style.Apply(ContentBackground, "", this); } if (color.HasValue) { this.color = color.Value; } IsScrollBarOnDefaultSide = isScrollBarOnDefaultSide; Point size; Anchor anchor; if (isHorizontal) { size = new Point((int)(Rect.Width - Padding.X - Padding.Z), (int)(ScrollBarSize * GUI.Scale)); anchor = isScrollBarOnDefaultSide ? Anchor.BottomCenter : Anchor.TopCenter; } else { // TODO: Should this be multiplied by the GUI.Scale as well? size = new Point(ScrollBarSize, (int)(Rect.Height - Padding.Y - Padding.W)); anchor = isScrollBarOnDefaultSide ? Anchor.CenterRight : Anchor.CenterLeft; } ScrollBar = new GUIScrollBar( new RectTransform(size, rectT, anchor) { AbsoluteOffset = isHorizontal ? new Point(0, IsScrollBarOnDefaultSide ? (int)Padding.W : (int)Padding.Y) : new Point(IsScrollBarOnDefaultSide ? (int)Padding.Z : (int)Padding.X, 0) }, isHorizontal: isHorizontal); UpdateScrollBarSize(); Enabled = true; ScrollBar.BarScroll = 0.0f; RectTransform.ScaleChanged += () => dimensionsNeedsRecalculation = true; RectTransform.SizeChanged += () => dimensionsNeedsRecalculation = true; UpdateDimensions(); }
protected override void Update(float deltaTime) { if (!Visible) { return; } base.Update(deltaTime); if (!enabled) { return; } if (IsBooleanSwitch && (!PlayerInput.LeftButtonHeld() || (GUI.MouseOn != this && !IsParentOf(GUI.MouseOn)))) { int dir = Math.Sign(barScroll - (minValue + maxValue) / 2.0f); if (dir == 0) { dir = 1; } if ((barScroll <= maxValue && dir > 0) || (barScroll > minValue && dir < 0)) { BarScroll += dir * 0.1f; } } if (draggingBar == this) { if (!PlayerInput.LeftButtonHeld()) { OnReleased?.Invoke(this, BarScroll); draggingBar = null; } if ((isHorizontal && PlayerInput.MousePosition.X > Rect.X && PlayerInput.MousePosition.X < Rect.Right) || (!isHorizontal && PlayerInput.MousePosition.Y > Rect.Y && PlayerInput.MousePosition.Y < Rect.Bottom)) { MoveButton(PlayerInput.MouseSpeed); } } else if (GUI.MouseOn == Frame) { if (PlayerInput.LeftButtonClicked()) { draggingBar?.OnReleased?.Invoke(draggingBar, draggingBar.BarScroll); MoveButton(new Vector2( Math.Sign(PlayerInput.MousePosition.X - Bar.Rect.Center.X) * Bar.Rect.Width, Math.Sign(PlayerInput.MousePosition.Y - Bar.Rect.Center.Y) * Bar.Rect.Height)); } } }
public GUIListBox(RectTransform rectT, bool isHorizontal = false, Color?color = null, string style = "") : base(style, rectT) { CanBeFocused = true; selected = new List <GUIComponent>(); Point frameSize = isHorizontal ? new Point(rectT.NonScaledSize.X, rectT.NonScaledSize.Y - 20) : new Point(rectT.NonScaledSize.X - 20, rectT.NonScaledSize.Y); Content = new GUIFrame(new RectTransform(frameSize, rectT), style) { CanBeFocused = false }; Content.RectTransform.ChildrenChanged += (_) => { scrollBarNeedsRecalculation = true; childrenNeedsRecalculation = true; }; if (style != null) { GUI.Style.Apply(Content, "", this); } if (color.HasValue) { this.color = color.Value; } if (isHorizontal) { ScrollBar = new GUIScrollBar(new RectTransform(new Point(Rect.Width, 20), rectT, Anchor.BottomLeft, Pivot.TopLeft) { AbsoluteOffset = new Point(0, 20) }, isHorizontal: isHorizontal); } else { ScrollBar = new GUIScrollBar(new RectTransform(new Point(20, Rect.Height), rectT, Anchor.TopRight, Pivot.TopLeft) { AbsoluteOffset = new Point(20, 0) }, isHorizontal: isHorizontal); } UpdateScrollBarSize(); Enabled = true; ScrollBar.BarScroll = 0.0f; RectTransform.ScaleChanged += UpdateDimensions; RectTransform.SizeChanged += UpdateDimensions; }
public GUIListBox(Rectangle rect, Color?color, Alignment alignment, string style = null, GUIComponent parent = null, bool isHorizontal = false) : base(style) { this.rect = rect; this.alignment = alignment; selected = new List <GUIComponent>(); if (color != null) { this.color = (Color)color; } if (parent != null) { parent.AddChild(this); } scrollBarHidden = true; if (isHorizontal) { scrollBar = new GUIScrollBar( new Rectangle(this.rect.X, this.rect.Bottom - 20, this.rect.Width, 20), null, 1.0f, ""); } else { scrollBar = new GUIScrollBar( new Rectangle(this.rect.Right - 20, this.rect.Y, 20, this.rect.Height), null, 1.0f, ""); } scrollBar.IsHorizontal = isHorizontal; frame = new GUIFrame(new Rectangle(0, 0, this.rect.Width, this.rect.Height), style, this); if (style != null) { GUI.Style.Apply(frame, style, this); } UpdateScrollBarSize(); children.Clear(); enabled = true; scrollBarEnabled = true; scrollBar.BarScroll = 0.0f; }
private bool SelectBar() { if (!enabled) { return(false); } if (barSize == 1.0f) { return(false); } draggingBar = this; return(true); }
private bool SelectBar() { if (!enabled || !PlayerInput.LeftButtonDown()) { return(false); } if (barSize >= 1.0f) { return(false); } draggingBar = this; return(true); }
private void CreateSettingsFrame() { settingsFrame = new GUIFrame(new RectTransform(new Point(500, 500), GUI.Canvas, Anchor.Center)); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), settingsFrame.RectTransform), TextManager.Get("Settings"), textAlignment: Alignment.Center, font: GUI.LargeFont); var paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.8f), settingsFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.06f) }, style: null); var tabButtonHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.05f), settingsFrame.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.1f) }, isHorizontal: true); tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length]; tabButtons = new GUIButton[tabs.Length]; foreach (Tab tab in Enum.GetValues(typeof(Tab))) { tabs[(int)tab] = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.91f), paddedFrame.RectTransform), style: "InnerFrame") { UserData = tab }; tabButtons[(int)tab] = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), tabButtonHolder.RectTransform), tab.ToString()) { UserData = tab, OnClicked = (bt, userdata) => { SelectTab((Tab)userdata); return(true); } }; } var buttonArea = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.08f), paddedFrame.RectTransform, Anchor.BottomCenter), style: null); /// Graphics tab -------------------------------------------------------------- var leftColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.46f, 0.95f), tabs[(int)Tab.Graphics].RectTransform, Anchor.CenterLeft) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { RelativeSpacing = 0.01f, Stretch = true }; var rightColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.46f, 0.95f), tabs[(int)Tab.Graphics].RectTransform, Anchor.CenterRight) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { RelativeSpacing = 0.01f, Stretch = true }; var supportedDisplayModes = new List <DisplayMode>(); foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) { if (supportedDisplayModes.Any(m => m.Width == mode.Width && m.Height == mode.Height)) { continue; } supportedDisplayModes.Add(mode); } new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("Resolution")); var resolutionDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), elementCount: supportedDisplayModes.Count) { OnSelected = SelectResolution }; foreach (DisplayMode mode in supportedDisplayModes) { resolutionDD.AddItem(mode.Width + "x" + mode.Height, mode); if (GraphicsWidth == mode.Width && GraphicsHeight == mode.Height) { resolutionDD.SelectItem(mode); } } if (resolutionDD.SelectedItemData == null) { resolutionDD.SelectItem(GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Last()); } new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("DisplayMode")); var displayModeDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)); displayModeDD.AddItem(TextManager.Get("Fullscreen"), WindowMode.Fullscreen); displayModeDD.AddItem(TextManager.Get("Windowed"), WindowMode.Windowed); displayModeDD.AddItem(TextManager.Get("BorderlessWindowed"), WindowMode.BorderlessWindowed); displayModeDD.SelectItem(GameMain.Config.WindowMode); displayModeDD.OnSelected = (guiComponent, obj) => { UnsavedSettings = true; GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData; return(true); }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform), style: null); GUITickBox vsyncTickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("EnableVSync")) { OnSelected = (GUITickBox box) => { VSyncEnabled = box.Selected; GameMain.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = VSyncEnabled; GameMain.GraphicsDeviceManager.ApplyChanges(); UnsavedSettings = true; return(true); }, Selected = VSyncEnabled }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), leftColumn.RectTransform), style: null); GUITextBlock particleLimitText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("ParticleLimit")); GUIScrollBar particleScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = particleLimitText, BarScroll = (ParticleLimit - 200) / 1300.0f, OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); ParticleLimit = 200 + (int)(scroll * 1300.0f); return(true); }, Step = 0.1f }; particleScrollBar.OnMoved(particleScrollBar, particleScrollBar.BarScroll); //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), rightColumn.RectTransform), style: null); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("LosEffect")); var losModeDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform)); losModeDD.AddItem(TextManager.Get("LosModeNone"), LosMode.None); losModeDD.AddItem(TextManager.Get("LosModeTransparent"), LosMode.Transparent); losModeDD.AddItem(TextManager.Get("LosModeOpaque"), LosMode.Opaque); losModeDD.SelectItem(GameMain.Config.LosMode); losModeDD.OnSelected = (guiComponent, obj) => { UnsavedSettings = true; GameMain.Config.LosMode = (LosMode)guiComponent.UserData; //don't allow changing los mode when playing as a client if (GameMain.Client == null) { GameMain.LightManager.LosMode = GameMain.Config.LosMode; } return(true); }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), style: null); GUITextBlock LightText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("LightMapScale")) { ToolTip = TextManager.Get("LightMapScaleToolTip") }; GUIScrollBar lightScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = LightText, ToolTip = TextManager.Get("LightMapScaleToolTip"), BarScroll = MathUtils.InverseLerp(0.2f, 1.0f, LightMapScale), OnMoved = (scrollBar, barScroll) => { ChangeSliderText(scrollBar, barScroll); LightMapScale = MathHelper.Lerp(0.2f, 1.0f, barScroll); UnsavedSettings = true; return(true); }, Step = 0.25f }; lightScrollBar.OnMoved(lightScrollBar, lightScrollBar.BarScroll); //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), style: null); new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("SpecularLighting")) { ToolTip = TextManager.Get("SpecularLightingToolTip"), Selected = SpecularityEnabled, OnSelected = (tickBox) => { SpecularityEnabled = tickBox.Selected; UnsavedSettings = true; return(true); } }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), rightColumn.RectTransform), style: null); new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("ChromaticAberration")) { ToolTip = TextManager.Get("ChromaticAberrationToolTip"), Selected = ChromaticAberrationEnabled, OnSelected = (tickBox) => { ChromaticAberrationEnabled = tickBox.Selected; UnsavedSettings = true; return(true); } }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), style: null); GUITextBlock HUDScaleText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("HUDScale")); GUIScrollBar HUDScaleScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = HUDScaleText, BarScroll = (HUDScale - MinHUDScale) / (MaxHUDScale - MinHUDScale), OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); HUDScale = MathHelper.Lerp(MinHUDScale, MaxHUDScale, scroll); UnsavedSettings = true; OnHUDScaleChanged?.Invoke(); return(true); }, Step = 0.05f }; HUDScaleScrollBar.OnMoved(HUDScaleScrollBar, HUDScaleScrollBar.BarScroll); //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), rightColumn.RectTransform), style: null); GUITextBlock inventoryScaleText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("InventoryScale")); GUIScrollBar inventoryScaleScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = inventoryScaleText, BarScroll = (InventoryScale - MinInventoryScale) / (MaxInventoryScale - MinInventoryScale), OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); InventoryScale = MathHelper.Lerp(MinInventoryScale, MaxInventoryScale, scroll); UnsavedSettings = true; return(true); }, Step = 0.05f }; inventoryScaleScrollBar.OnMoved(inventoryScaleScrollBar, inventoryScaleScrollBar.BarScroll); //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.2f), rightColumn.RectTransform), style: null); /// General tab -------------------------------------------------------------- leftColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.46f, 0.95f), tabs[(int)Tab.General].RectTransform, Anchor.CenterLeft) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { RelativeSpacing = 0.01f, Stretch = true }; rightColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.46f, 0.95f), tabs[(int)Tab.General].RectTransform, Anchor.CenterRight) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { RelativeSpacing = 0.01f, Stretch = true }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("ContentPackages")); var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.4f), leftColumn.RectTransform)) { CanBeFocused = false }; foreach (ContentPackage contentPackage in ContentPackage.List) { var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), contentPackageList.Content.RectTransform, minSize: new Point(0, 15)), contentPackage.Name) { UserData = contentPackage, OnSelected = SelectContentPackage, Selected = SelectedContentPackages.Contains(contentPackage) }; if (!contentPackage.IsCompatible()) { tickBox.TextColor = Color.Red; tickBox.Enabled = false; tickBox.ToolTip = TextManager.Get(contentPackage.GameVersion <= new Version(0, 0, 0, 0) ? "IncompatibleContentPackageUnknownVersion" : "IncompatibleContentPackage") .Replace("[packagename]", contentPackage.Name) .Replace("[packageversion]", contentPackage.GameVersion.ToString()) .Replace("[gameversion]", GameMain.Version.ToString()); } else if (contentPackage.CorePackage && !contentPackage.ContainsRequiredCorePackageFiles(out List <ContentType> missingContentTypes)) { tickBox.TextColor = Color.Red; tickBox.Enabled = false; tickBox.ToolTip = TextManager.Get("ContentPackageMissingCoreFiles") .Replace("[packagename]", contentPackage.Name) .Replace("[missingfiletypes]", string.Join(", ", missingContentTypes)); } } //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform), style: null); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("Language")); var languageDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)); foreach (string language in TextManager.AvailableLanguages) { languageDD.AddItem(language, language); } languageDD.SelectItem(TextManager.Language); languageDD.OnSelected = (guiComponent, obj) => { string newLanguage = obj as string; if (newLanguage == Language) { return(true); } UnsavedSettings = true; Language = newLanguage; new GUIMessageBox(TextManager.Get("RestartRequiredLabel"), TextManager.Get("RestartRequiredLanguage")); return(true); }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform), style: null); GUITextBlock soundVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("SoundVolume")); GUIScrollBar soundScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), barSize: 0.1f) { UserData = soundVolumeText, BarScroll = SoundVolume, OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); SoundVolume = scroll; return(true); }, Step = 0.05f }; soundScrollBar.OnMoved(soundScrollBar, soundScrollBar.BarScroll); GUITextBlock musicVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("MusicVolume")); GUIScrollBar musicScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), barSize: 0.1f) { UserData = musicVolumeText, BarScroll = MusicVolume, OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); MusicVolume = scroll; return(true); }, Step = 0.05f }; musicScrollBar.OnMoved(musicScrollBar, musicScrollBar.BarScroll); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("Controls")); var inputFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.8f), rightColumn.RectTransform)) { Stretch = true }; var inputNames = Enum.GetValues(typeof(InputType)); for (int i = 0; i < inputNames.Length; i++) { var inputContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.06f), inputFrame.RectTransform), style: null); new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), inputContainer.RectTransform), TextManager.Get("InputType." + ((InputType)i)) + ": ", font: GUI.SmallFont); var keyBox = new GUITextBox(new RectTransform(new Vector2(0.4f, 1.0f), inputContainer.RectTransform, Anchor.TopRight), text: keyMapping[i].ToString(), font: GUI.SmallFont) { UserData = i }; keyBox.OnSelected += KeyBoxSelected; keyBox.SelectedColor = Color.Gold * 0.3f; } GUITextBlock aimAssistText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("AimAssist")); GUIScrollBar aimAssistSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = aimAssistText, BarScroll = MathUtils.InverseLerp(0.0f, 5.0f, AimAssistAmount), OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); AimAssistAmount = MathHelper.Lerp(0.0f, 5.0f, scroll); return(true); }, Step = 0.1f }; aimAssistSlider.OnMoved(aimAssistSlider, aimAssistSlider.BarScroll); new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomLeft), TextManager.Get("Cancel")) { IgnoreLayoutGroups = true, OnClicked = (x, y) => { if (GameMain.Config.UnsavedSettings) { GameMain.Config.Load("config.xml"); } if (Screen.Selected == GameMain.MainMenuScreen) { GameMain.MainMenuScreen.SelectTab(0); } GUI.SettingsMenuOpen = false; return(true); } }; applyButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomRight), TextManager.Get("ApplySettingsButton")) { IgnoreLayoutGroups = true, Enabled = false }; applyButton.OnClicked = ApplyClicked; SelectTab(Tab.General); }
private bool ChangeInventoryScale(GUIScrollBar scrollBar, float barScroll) { UnsavedSettings = true; InventoryScale = MathHelper.Lerp(MinInventoryScale, MaxInventoryScale, barScroll); return(true); }
public void RecreateFrameContents() { var info = CharacterInfo; HeadSelectionList = null; parentComponent.ClearChildren(); ClearSprites(); float contentWidth = HasIcon ? 0.75f : 1.0f; var listBox = new GUIListBox( new RectTransform(new Vector2(contentWidth, 1.0f), parentComponent.RectTransform, Anchor.CenterLeft)) { CanBeFocused = false, CanTakeKeyBoardFocus = false }; var content = listBox.Content; info.LoadHeadAttachments(); if (HasIcon) { info.CreateIcon( new RectTransform(new Vector2(0.25f, 1.0f), parentComponent.RectTransform, Anchor.CenterRight) { RelativeOffset = new Vector2(-0.01f, 0.0f) }); } RectTransform createItemRectTransform(string labelTag, float width = 0.6f) { var layoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.166f), content.RectTransform)); var label = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), layoutGroup.RectTransform), TextManager.Get(labelTag), font: GUI.SubHeadingFont); var bottomItem = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), layoutGroup.RectTransform), style: null); return(new RectTransform(new Vector2(width, 1.0f), bottomItem.RectTransform, Anchor.Center)); } RectTransform genderItemRT = createItemRectTransform("Gender", 1.0f); GUILayoutGroup genderContainer = new GUILayoutGroup(genderItemRT, isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; void createGenderButton(Gender gender) { new GUIButton(new RectTransform(new Vector2(1.0f, 1.0f), genderContainer.RectTransform), TextManager.Get(gender.ToString()), style: "ListBoxElement") { UserData = gender, OnClicked = OpenHeadSelection, Selected = info.Gender == gender }; } createGenderButton(Gender.Male); createGenderButton(Gender.Female); int countAttachmentsOfType(WearableType wearableType) => info.FilterByTypeAndHeadID( info.FilterElementsByGenderAndRace(info.Wearables, info.Head.gender, info.Head.race), wearableType, info.HeadSpriteId).Count(); List <GUIScrollBar> attachmentSliders = new List <GUIScrollBar>(); void createAttachmentSlider(int initialValue, WearableType wearableType) { int attachmentCount = countAttachmentsOfType(wearableType); if (attachmentCount > 0) { var labelTag = wearableType == WearableType.FaceAttachment ? "FaceAttachment.Accessories" : $"FaceAttachment.{wearableType}"; var sliderItemRT = createItemRectTransform(labelTag); var slider = new GUIScrollBar(sliderItemRT, style: "GUISlider") { Range = new Vector2(0, attachmentCount), StepValue = 1, OnMoved = (bar, scroll) => SwitchAttachment(bar, wearableType), OnReleased = OnSliderReleased, BarSize = 1.0f / (float)(attachmentCount + 1) }; slider.BarScrollValue = initialValue; attachmentSliders.Add(slider); } } createAttachmentSlider(info.HairIndex, WearableType.Hair); createAttachmentSlider(info.BeardIndex, WearableType.Beard); createAttachmentSlider(info.MoustacheIndex, WearableType.Moustache); createAttachmentSlider(info.FaceAttachmentIndex, WearableType.FaceAttachment); void createColorSelector(string labelTag, IEnumerable <(Color Color, float Commonness)> options, Func <Color> getter, Action <Color> setter) { var selectorItemRT = createItemRectTransform(labelTag, 0.4f); var dropdown = new GUIDropDown(selectorItemRT) { AllowNonText = true }; var listBoxSize = dropdown.ListBox.RectTransform.RelativeSize; dropdown.ListBox.RectTransform.RelativeSize = new Vector2(listBoxSize.X * 1.75f, listBoxSize.Y); var dropdownButton = dropdown.GetChild <GUIButton>(); var buttonFrame = new GUIFrame( new RectTransform(Vector2.One * 0.7f, dropdownButton.RectTransform, Anchor.CenterLeft) { RelativeOffset = new Vector2(0.05f, 0.0f) }, style: null); Color?previewingColor = null; dropdown.OnSelected = (component, color) => { previewingColor = null; setter((Color)color); buttonFrame.Color = getter(); buttonFrame.HoverColor = getter(); return(true); }; buttonFrame.Color = getter(); buttonFrame.HoverColor = getter(); dropdown.ListBox.UseGridLayout = true; foreach (var option in options) { var optionElement = new GUIFrame( new RectTransform(new Vector2(0.25f, 1.0f / 3.0f), dropdown.ListBox.Content.RectTransform), style: "ListBoxElement") { UserData = option.Color, CanBeFocused = true }; var colorElement = new GUIFrame( new RectTransform(Vector2.One * 0.75f, optionElement.RectTransform, Anchor.Center, scaleBasis: ScaleBasis.Smallest), style: null) { Color = option.Color, HoverColor = option.Color, OutlineColor = Color.Lerp(Color.Black, option.Color, 0.5f), CanBeFocused = false }; } var childToSelect = dropdown.ListBox.Content.FindChild(c => (Color)c.UserData == getter()); dropdown.Select(dropdown.ListBox.Content.GetChildIndex(childToSelect)); //The following exists to track mouseover to preview colors before selecting them new GUICustomComponent(new RectTransform(Vector2.One, buttonFrame.RectTransform), onUpdate: (deltaTime, component) => { if (GUI.MouseOn is GUIFrame { Parent: { } p } hoveredFrame&& dropdown.ListBox.Content.IsParentOf(hoveredFrame)) { previewingColor ??= getter(); Color color = (Color)(dropdown.ListBox.Content.FindChild(c => c == hoveredFrame || c.IsParentOf(hoveredFrame))?.UserData ?? dropdown.SelectedData ?? getter()); setter(color); buttonFrame.Color = getter(); buttonFrame.HoverColor = getter(); }
private void CreateGUIElements() { topPanel = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.1f), Frame.RectTransform) { MinSize = new Point(0, 60) }, "GUIFrameTop"); topPanelContents = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.8f), topPanel.RectTransform, Anchor.Center), style: null); new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0, 0.1f) }, "Reload Texture") { OnClicked = (button, userData) => { if (!(textureList.SelectedData is Texture2D selectedTexture)) { return(false); } var selected = selectedSprites; Sprite firstSelected = selected.First(); selected.ForEach(s => s.ReloadTexture()); RefreshLists(); textureList.Select(firstSelected.Texture, autoScroll: false); selected.ForEachMod(s => spriteList.Select(s, autoScroll: false)); texturePathText.Text = "Textures reloaded from " + firstSelected.FilePath; texturePathText.TextColor = Color.LightGreen; return(true); } }; new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.BottomLeft) { RelativeOffset = new Vector2(0, 0.1f) }, "Reset Changes") { OnClicked = (button, userData) => { if (selectedTexture == null) { return(false); } foreach (Sprite sprite in loadedSprites) { if (sprite.Texture != selectedTexture) { continue; } var element = sprite.SourceElement; if (element == null) { continue; } // Not all sprites have a sourcerect defined, in which case we'll want to use the current source rect instead of an empty rect. sprite.SourceRect = element.GetAttributeRect("sourcerect", sprite.SourceRect); sprite.RelativeOrigin = element.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f)); } ResetWidgets(); xmlPathText.Text = "Changes successfully reset"; xmlPathText.TextColor = Color.LightGreen; return(true); } }; new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.15f, 0.1f) }, "Save Selected Sprites") { OnClicked = (button, userData) => { return(SaveSprites(selectedSprites)); } }; new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.BottomLeft) { RelativeOffset = new Vector2(0.15f, 0.1f) }, "Save All Sprites") { OnClicked = (button, userData) => { return(SaveSprites(loadedSprites)); } }; new GUITextBlock(new RectTransform(new Vector2(0.2f, 0.2f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0, 0.3f) }, "Zoom: "); zoomBar = new GUIScrollBar(new RectTransform(new Vector2(0.2f, 0.35f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0.05f, 0.3f) }, barSize: 0.1f) { BarScroll = GetBarScrollValue(), Step = 0.01f, OnMoved = (scrollBar, value) => { zoom = MathHelper.Lerp(minZoom, maxZoom, value); viewAreaOffset = Point.Zero; return(true); } }; var resetBtn = new GUIButton(new RectTransform(new Vector2(0.05f, 0.35f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterLeft) { RelativeOffset = new Vector2(0.055f, 0.3f) }, "Reset Zoom") { OnClicked = (box, data) => { ResetZoom(); return(true); } }; resetBtn.TextBlock.AutoScale = true; new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), topPanelContents.RectTransform, Anchor.BottomCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0, 0.3f) }, "Show grid") { Selected = drawGrid, OnSelected = (tickBox) => { drawGrid = tickBox.Selected; return(true); } }; new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), topPanelContents.RectTransform, Anchor.BottomCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0.17f, 0.3f) }, "Snap to grid") { Selected = snapToGrid, OnSelected = (tickBox) => { snapToGrid = tickBox.Selected; return(true); } }; texturePathText = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.4f), topPanelContents.RectTransform, Anchor.Center, Pivot.BottomCenter) { RelativeOffset = new Vector2(0.4f, 0) }, "", Color.LightGray); xmlPathText = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.4f), topPanelContents.RectTransform, Anchor.Center, Pivot.TopCenter) { RelativeOffset = new Vector2(0.4f, 0) }, "", Color.LightGray); leftPanel = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f - topPanel.RectTransform.RelativeSize.Y), Frame.RectTransform, Anchor.BottomLeft) { MinSize = new Point(150, 0) }, style: "GUIFrameLeft"); var paddedLeftPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), leftPanel.RectTransform, Anchor.CenterLeft) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { Stretch = true }; textureList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), paddedLeftPanel.RectTransform)) { OnSelected = (listBox, userData) => { var previousTexture = selectedTexture; selectedTexture = userData as Texture2D; if (previousTexture != selectedTexture) { ResetZoom(); } foreach (GUIComponent child in spriteList.Content.Children) { var textBlock = (GUITextBlock)child; var sprite = (Sprite)textBlock.UserData; textBlock.TextColor = new Color(textBlock.TextColor, sprite.Texture == selectedTexture ? 1.0f : 0.4f); } if (selectedSprites.None(s => s.Texture == selectedTexture)) { spriteList.Select(loadedSprites.First(s => s.Texture == selectedTexture), autoScroll: false); UpdateScrollBar(spriteList); } texturePathText.TextColor = Color.LightGray; topPanelContents.Visible = true; return(true); } }; rightPanel = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f - topPanel.RectTransform.RelativeSize.Y), Frame.RectTransform, Anchor.BottomRight) { MinSize = new Point(150, 0) }, style: "GUIFrameRight"); var paddedRightPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), rightPanel.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { Stretch = true, RelativeSpacing = 0.01f }; spriteList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), paddedRightPanel.RectTransform)) { OnSelected = (listBox, userData) => { Sprite sprite = userData as Sprite; if (sprite == null) { return(false); } SelectSprite(sprite); return(true); } }; // Background color bottomPanel = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.05f), Frame.RectTransform, Anchor.BottomCenter), style: null, color: Color.Black * 0.5f); new GUITickBox(new RectTransform(new Vector2(0.2f, 0.5f), bottomPanel.RectTransform, Anchor.Center), "Edit Background Color") { Selected = editBackgroundColor, OnSelected = box => { editBackgroundColor = box.Selected; return(true); } }; backgroundColorPanel = new GUIFrame(new RectTransform(new Point(400, 80), Frame.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0, 0.1f) }, style: null, color: Color.Black * 0.4f); new GUITextBlock(new RectTransform(new Vector2(0.2f, 1), backgroundColorPanel.RectTransform) { MinSize = new Point(80, 26) }, "Background \nColor:", textColor: Color.WhiteSmoke); var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.7f, 1), backgroundColorPanel.RectTransform, Anchor.TopRight) { AbsoluteOffset = new Point(20, 0) }, isHorizontal: true, childAnchor: Anchor.CenterRight) { Stretch = true, RelativeSpacing = 0.01f }; var fields = new GUIComponent[4]; string[] colorComponentLabels = { "R", "G", "B" }; for (int i = 2; i >= 0; i--) { var element = new GUIFrame(new RectTransform(new Vector2(0.2f, 1), inputArea.RectTransform) { MinSize = new Point(40, 0), MaxSize = new Point(100, 50) }, style: null, color: Color.Black * 0.6f); var colorLabel = new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), colorComponentLabels[i], font: GUI.SmallFont, textAlignment: Alignment.CenterLeft); var numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight), GUINumberInput.NumberType.Int) { Font = GUI.SmallFont }; numberInput.MinValueInt = 0; numberInput.MaxValueInt = 255; numberInput.Font = GUI.SmallFont; switch (i) { case 0: colorLabel.TextColor = Color.Red; numberInput.IntValue = backgroundColor.R; numberInput.OnValueChanged += (numInput) => backgroundColor.R = (byte)(numInput.IntValue); break; case 1: colorLabel.TextColor = Color.LightGreen; numberInput.IntValue = backgroundColor.G; numberInput.OnValueChanged += (numInput) => backgroundColor.G = (byte)(numInput.IntValue); break; case 2: colorLabel.TextColor = Color.DeepSkyBlue; numberInput.IntValue = backgroundColor.B; numberInput.OnValueChanged += (numInput) => backgroundColor.B = (byte)(numInput.IntValue); break; } } }
public void CreateSettingsFrame(Tab selectedTab = Tab.Graphics) { settingsFrame = new GUIFrame(new RectTransform(new Vector2(0.8f, 0.8f), GUI.Canvas, Anchor.Center)); var settingsFramePadding = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), settingsFrame.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.05f) }) { RelativeSpacing = 0.01f, IsHorizontal = true }; /// General tab -------------------------------------------------------------- var leftPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.25f, 1.0f), settingsFramePadding.RectTransform, Anchor.TopLeft)); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftPanel.RectTransform), TextManager.Get("Settings"), textAlignment: Alignment.TopLeft, font: GUI.LargeFont); var generalLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), leftPanel.RectTransform, Anchor.TopLeft)); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), generalLayoutGroup.RectTransform), TextManager.Get("ContentPackages")); var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.75f), generalLayoutGroup.RectTransform)) { CanBeFocused = false, ScrollBarVisible = true }; foreach (ContentPackage contentPackage in ContentPackage.List) { var tickBox = new GUITickBox(new RectTransform(new Point(32, 32), contentPackageList.Content.RectTransform), contentPackage.Name) { UserData = contentPackage, OnSelected = SelectContentPackage, Selected = SelectedContentPackages.Contains(contentPackage) }; if (!contentPackage.IsCompatible()) { tickBox.TextColor = Color.Red; tickBox.Enabled = false; tickBox.ToolTip = TextManager.Get(contentPackage.GameVersion <= new Version(0, 0, 0, 0) ? "IncompatibleContentPackageUnknownVersion" : "IncompatibleContentPackage") .Replace("[packagename]", contentPackage.Name) .Replace("[packageversion]", contentPackage.GameVersion.ToString()) .Replace("[gameversion]", GameMain.Version.ToString()); } else if (contentPackage.CorePackage && !contentPackage.ContainsRequiredCorePackageFiles(out List <ContentType> missingContentTypes)) { tickBox.TextColor = Color.Red; tickBox.Enabled = false; tickBox.ToolTip = TextManager.Get("ContentPackageMissingCoreFiles") .Replace("[packagename]", contentPackage.Name) .Replace("[missingfiletypes]", string.Join(", ", missingContentTypes)); } } new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.045f), generalLayoutGroup.RectTransform), TextManager.Get("Language")); var languageDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.045f), generalLayoutGroup.RectTransform)); foreach (string language in TextManager.AvailableLanguages) { languageDD.AddItem(TextManager.Get("Language." + language), language); } languageDD.SelectItem(TextManager.Language); languageDD.OnSelected = (guiComponent, obj) => { string newLanguage = obj as string; if (newLanguage == Language) { return(true); } UnsavedSettings = true; Language = newLanguage; new GUIMessageBox(TextManager.Get("RestartRequiredLabel"), TextManager.Get("RestartRequiredLanguage")); return(true); }; var rightPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.99f - leftPanel.RectTransform.RelativeSize.X, 0.95f), settingsFramePadding.RectTransform, Anchor.TopLeft)); var tabButtonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), rightPanel.RectTransform, Anchor.TopCenter), isHorizontal: true); var paddedFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 1.0f), rightPanel.RectTransform, Anchor.Center), style: null); tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length]; tabButtons = new GUIButton[tabs.Length]; foreach (Tab tab in Enum.GetValues(typeof(Tab))) { tabs[(int)tab] = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.91f), paddedFrame.RectTransform), style: "InnerFrame") { UserData = tab }; tabButtons[(int)tab] = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), tabButtonHolder.RectTransform), TextManager.Get("SettingsTab." + tab.ToString()), style: "GUITabButton") { UserData = tab, OnClicked = (bt, userdata) => { SelectTab((Tab)userdata); return(true); } }; } var buttonArea = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.08f), paddedFrame.RectTransform, Anchor.BottomCenter), style: null); /// Graphics tab -------------------------------------------------------------- var leftColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.46f, 0.95f), tabs[(int)Tab.Graphics].RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.025f, 0.02f) }) { RelativeSpacing = 0.01f }; var rightColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.46f, 0.95f), tabs[(int)Tab.Graphics].RectTransform, Anchor.TopRight) { RelativeOffset = new Vector2(0.025f, 0.02f) }) { RelativeSpacing = 0.01f }; var supportedDisplayModes = new List <DisplayMode>(); foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) { if (supportedDisplayModes.Any(m => m.Width == mode.Width && m.Height == mode.Height)) { continue; } #if OSX // Monogame currently doesn't support retina displays // so we need to disable resolutions above the viewport size. // In a bundled .app you just disable HiDPI in the info.plist // but that's probably not gonna happen. if (mode.Width > GameMain.Instance.GraphicsDevice.DisplayMode.Width || mode.Height > GameMain.Instance.GraphicsDevice.DisplayMode.Height) { continue; } #endif supportedDisplayModes.Add(mode); } new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("Resolution")); var resolutionDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), elementCount: supportedDisplayModes.Count) { OnSelected = SelectResolution, #if OSX ButtonEnabled = GameMain.Config.WindowMode == WindowMode.Windowed #endif }; foreach (DisplayMode mode in supportedDisplayModes) { if (mode.Width < MinSupportedResolution.X || mode.Height < MinSupportedResolution.Y) { continue; } resolutionDD.AddItem(mode.Width + "x" + mode.Height, mode); if (GraphicsWidth == mode.Width && GraphicsHeight == mode.Height) { resolutionDD.SelectItem(mode); } } if (resolutionDD.SelectedItemData == null) { resolutionDD.SelectItem(GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Last()); } new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("DisplayMode")); var displayModeDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)); displayModeDD.AddItem(TextManager.Get("Fullscreen"), WindowMode.Fullscreen); displayModeDD.AddItem(TextManager.Get("Windowed"), WindowMode.Windowed); #if (!OSX) displayModeDD.AddItem(TextManager.Get("BorderlessWindowed"), WindowMode.BorderlessWindowed); displayModeDD.SelectItem(GameMain.Config.WindowMode); #else // Fullscreen option will just set itself to borderless on macOS. if (GameMain.Config.WindowMode == WindowMode.BorderlessWindowed) { displayModeDD.SelectItem(WindowMode.Fullscreen); } else { displayModeDD.SelectItem(GameMain.Config.WindowMode); } #endif displayModeDD.OnSelected = (guiComponent, obj) => { UnsavedSettings = true; GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData; #if OSX resolutionDD.ButtonEnabled = GameMain.Config.WindowMode == WindowMode.Windowed; #endif return(true); }; GUITickBox vsyncTickBox = new GUITickBox(new RectTransform(new Point(32, 32), leftColumn.RectTransform), TextManager.Get("EnableVSync")) { ToolTip = TextManager.Get("EnableVSyncToolTip"), OnSelected = (GUITickBox box) => { VSyncEnabled = box.Selected; GameMain.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = VSyncEnabled; GameMain.GraphicsDeviceManager.ApplyChanges(); UnsavedSettings = true; return(true); }, Selected = VSyncEnabled }; GUITextBlock particleLimitText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("ParticleLimit")); GUIScrollBar particleScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = particleLimitText, BarScroll = (ParticleLimit - 200) / 1300.0f, OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); ParticleLimit = 200 + (int)(scroll * 1300.0f); return(true); }, Step = 0.1f }; particleScrollBar.OnMoved(particleScrollBar, particleScrollBar.BarScroll); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("LosEffect")); var losModeDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform)); losModeDD.AddItem(TextManager.Get("LosModeNone"), LosMode.None); losModeDD.AddItem(TextManager.Get("LosModeTransparent"), LosMode.Transparent); losModeDD.AddItem(TextManager.Get("LosModeOpaque"), LosMode.Opaque); losModeDD.SelectItem(GameMain.Config.LosMode); losModeDD.OnSelected = (guiComponent, obj) => { UnsavedSettings = true; GameMain.Config.LosMode = (LosMode)guiComponent.UserData; //don't allow changing los mode when playing as a client if (GameMain.Client == null) { GameMain.LightManager.LosMode = GameMain.Config.LosMode; } return(true); }; GUITextBlock LightText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("LightMapScale")) { ToolTip = TextManager.Get("LightMapScaleToolTip") }; GUIScrollBar lightScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = LightText, ToolTip = TextManager.Get("LightMapScaleToolTip"), BarScroll = MathUtils.InverseLerp(0.2f, 1.0f, LightMapScale), OnMoved = (scrollBar, barScroll) => { ChangeSliderText(scrollBar, barScroll); LightMapScale = MathHelper.Lerp(0.2f, 1.0f, barScroll); UnsavedSettings = true; return(true); }, Step = 0.25f }; lightScrollBar.OnMoved(lightScrollBar, lightScrollBar.BarScroll); new GUITickBox(new RectTransform(new Point(32, 32), rightColumn.RectTransform), TextManager.Get("SpecularLighting")) { ToolTip = TextManager.Get("SpecularLightingToolTip"), Selected = SpecularityEnabled, OnSelected = (tickBox) => { SpecularityEnabled = tickBox.Selected; UnsavedSettings = true; return(true); } }; new GUITickBox(new RectTransform(new Point(32, 32), rightColumn.RectTransform), TextManager.Get("ChromaticAberration")) { ToolTip = TextManager.Get("ChromaticAberrationToolTip"), Selected = ChromaticAberrationEnabled, OnSelected = (tickBox) => { ChromaticAberrationEnabled = tickBox.Selected; UnsavedSettings = true; return(true); } }; GUITextBlock HUDScaleText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("HUDScale")); GUIScrollBar HUDScaleScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = HUDScaleText, BarScroll = (HUDScale - MinHUDScale) / (MaxHUDScale - MinHUDScale), OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); HUDScale = MathHelper.Lerp(MinHUDScale, MaxHUDScale, scroll); UnsavedSettings = true; OnHUDScaleChanged?.Invoke(); return(true); }, Step = 0.05f }; HUDScaleScrollBar.OnMoved(HUDScaleScrollBar, HUDScaleScrollBar.BarScroll); GUITextBlock inventoryScaleText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("InventoryScale")); GUIScrollBar inventoryScaleScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), barSize: 0.1f) { UserData = inventoryScaleText, BarScroll = (InventoryScale - MinInventoryScale) / (MaxInventoryScale - MinInventoryScale), OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); InventoryScale = MathHelper.Lerp(MinInventoryScale, MaxInventoryScale, scroll); UnsavedSettings = true; return(true); }, Step = 0.05f }; inventoryScaleScrollBar.OnMoved(inventoryScaleScrollBar, inventoryScaleScrollBar.BarScroll); /// Audio tab ---------------------------------------------------------------- var audioSliders = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), tabs[(int)Tab.Audio].RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) }) { RelativeSpacing = 0.01f }; GUITextBlock soundVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.Get("SoundVolume")); GUIScrollBar soundScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), barSize: 0.05f) { UserData = soundVolumeText, BarScroll = SoundVolume, OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); SoundVolume = scroll; return(true); }, Step = 0.05f }; soundScrollBar.OnMoved(soundScrollBar, soundScrollBar.BarScroll); GUITextBlock musicVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.Get("MusicVolume")); GUIScrollBar musicScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), barSize: 0.05f) { UserData = musicVolumeText, BarScroll = MusicVolume, OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); MusicVolume = scroll; return(true); }, Step = 0.05f }; musicScrollBar.OnMoved(musicScrollBar, musicScrollBar.BarScroll); GUITextBlock voiceChatVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.Get("VoiceChatVolume")); GUIScrollBar voiceChatScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), barSize: 0.05f) { UserData = voiceChatVolumeText, BarScroll = VoiceChatVolume, OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); VoiceChatVolume = scroll; return(true); }, Step = 0.05f }; voiceChatScrollBar.OnMoved(voiceChatScrollBar, voiceChatScrollBar.BarScroll); GUITickBox muteOnFocusLostBox = new GUITickBox(new RectTransform(new Point(32, 32), audioSliders.RectTransform), TextManager.Get("MuteOnFocusLost")); muteOnFocusLostBox.Selected = MuteOnFocusLost; muteOnFocusLostBox.ToolTip = TextManager.Get("MuteOnFocusLostToolTip"); muteOnFocusLostBox.OnSelected = (tickBox) => { MuteOnFocusLost = tickBox.Selected; UnsavedSettings = true; return(true); }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.Get("VoiceChat")); IList <string> deviceNames = Alc.GetString((IntPtr)null, AlcGetStringList.CaptureDeviceSpecifier); foreach (string name in deviceNames) { DebugConsole.NewMessage(name + " " + name.Length.ToString(), Color.Lime); } if (string.IsNullOrWhiteSpace(VoiceCaptureDevice)) { VoiceCaptureDevice = deviceNames[0]; } #if (!OSX) var deviceList = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), VoiceCaptureDevice, deviceNames.Count); foreach (string name in deviceNames) { deviceList.AddItem(name, name); } deviceList.OnSelected = (GUIComponent selected, object obj) => { string name = obj as string; if (VoiceCaptureDevice == name) { return(true); } VoipCapture.ChangeCaptureDevice(name); return(true); }; #else var suavemente = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.Get("CurrentDevice") + ": " + VoiceCaptureDevice) { ToolTip = TextManager.Get("CurrentDeviceToolTip.OSX"), TextAlignment = Alignment.CenterX }; new GUIButton(new RectTransform(new Vector2(1.0f, 0.15f), audioSliders.RectTransform), TextManager.Get("RefreshDefaultDevice")) { ToolTip = TextManager.Get("RefreshDefaultDeviceToolTip"), OnClicked = (bt, userdata) => { deviceNames = Alc.GetString((IntPtr)null, AlcGetStringList.CaptureDeviceSpecifier); if (VoiceCaptureDevice == deviceNames[0]) { return(true); } VoipCapture.ChangeCaptureDevice(deviceNames[0]); suavemente.Text = TextManager.Get("CurrentDevice") + ": " + VoiceCaptureDevice; suavemente.Flash(Color.Blue); return(true); } }; #endif //var radioButtonFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.12f), audioSliders.RectTransform)); GUIRadioButtonGroup voiceMode = new GUIRadioButtonGroup(); for (int i = 0; i < 3; i++) { string langStr = "VoiceMode." + ((VoiceMode)i).ToString(); var tick = new GUITickBox(new RectTransform(new Point(32, 32), audioSliders.RectTransform), TextManager.Get(langStr)) { ToolTip = TextManager.Get(langStr + "ToolTip") }; voiceMode.AddRadioButton((VoiceMode)i, tick); } var micVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), TextManager.Get("MicrophoneVolume")); var micVolumeSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), audioSliders.RectTransform), barSize: 0.05f) { UserData = micVolumeText, BarScroll = (float)Math.Sqrt(MathUtils.InverseLerp(0.2f, 5.0f, MicrophoneVolume)), OnMoved = (scrollBar, scroll) => { MicrophoneVolume = MathHelper.Lerp(0.2f, 5.0f, scroll * scroll); MicrophoneVolume = (float)Math.Round(MicrophoneVolume, 1); ChangeSliderText(scrollBar, MicrophoneVolume); scrollBar.Step = 0.05f; return(true); }, Step = 0.05f }; micVolumeSlider.OnMoved(micVolumeSlider, micVolumeSlider.BarScroll); var extraVoiceSettingsContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.2f), audioSliders.RectTransform, Anchor.BottomCenter), style: null); var voiceInputContainer = new GUILayoutGroup(new RectTransform(Vector2.One, extraVoiceSettingsContainer.RectTransform, Anchor.BottomCenter)); new GUITextBlock(new RectTransform(new Vector2(0.6f, 0.25f), voiceInputContainer.RectTransform), TextManager.Get("InputType.Voice") + ": "); var voiceKeyBox = new GUITextBox(new RectTransform(new Vector2(0.4f, 0.25f), voiceInputContainer.RectTransform, Anchor.TopRight), text: keyMapping[(int)InputType.Voice].ToString()) { UserData = InputType.Voice }; voiceKeyBox.OnSelected += KeyBoxSelected; voiceKeyBox.SelectedColor = Color.Gold * 0.3f; var voiceActivityGroup = new GUILayoutGroup(new RectTransform(Vector2.One, extraVoiceSettingsContainer.RectTransform)); GUITextBlock noiseGateText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), voiceActivityGroup.RectTransform), TextManager.Get("NoiseGateThreshold")) { TextGetter = () => { return(TextManager.Get("NoiseGateThreshold") + " " + ((int)NoiseGateThreshold).ToString() + " dB"); } }; var dbMeter = new GUIProgressBar(new RectTransform(new Vector2(1.0f, 0.25f), voiceActivityGroup.RectTransform), 0.0f, Color.Lime); dbMeter.ProgressGetter = () => { if (VoipCapture.Instance == null) { return(0.0f); } dbMeter.Color = VoipCapture.Instance.LastdB > NoiseGateThreshold ? Color.Lime : Color.Orange; //TODO: i'm a filthy hack return(((float)VoipCapture.Instance.LastdB + 100.0f) / 100.0f); }; var noiseGateSlider = new GUIScrollBar(new RectTransform(Vector2.One, dbMeter.RectTransform, Anchor.Center), color: Color.White, barSize: 0.03f); noiseGateSlider.Frame.Visible = false; noiseGateSlider.Step = 0.01f; noiseGateSlider.Range = new Vector2(-100.0f, 0.0f); noiseGateSlider.BarScrollValue = NoiseGateThreshold; noiseGateSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => { NoiseGateThreshold = scrollBar.BarScrollValue; UnsavedSettings = true; return(true); }; voiceMode.OnSelect = (GUIRadioButtonGroup rbg, Enum value) => { if (rbg.Selected != null && rbg.Selected.Equals(value)) { return; } try { VoiceMode vMode = (VoiceMode)value; VoiceSetting = vMode; if (vMode == VoiceMode.Activity) { voiceActivityGroup.Visible = true; if (GameMain.Client == null && VoipCapture.Instance == null) { VoipCapture.Create(GameMain.Config.VoiceCaptureDevice); if (VoipCapture.Instance == null) { VoiceSetting = vMode = VoiceMode.Disabled; voiceInputContainer.Visible = false; voiceActivityGroup.Visible = false; return; } } } else { voiceActivityGroup.Visible = false; if (GameMain.Client == null) { VoipCapture.Instance?.Dispose(); } } voiceInputContainer.Visible = (vMode == VoiceMode.PushToTalk); UnsavedSettings = true; } catch (Exception e) { DebugConsole.ThrowError("Failed to set voice capture mode.", e); GameAnalyticsManager.AddErrorEventOnce("SetVoiceCaptureMode", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, "Failed to set voice capture mode. " + e.Message + "\n" + e.StackTrace); VoiceSetting = VoiceMode.Disabled; } }; voiceMode.Selected = VoiceSetting; /// Controls tab ------------------------------------------------------------- var controlsLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), tabs[(int)Tab.Controls].RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) }) { RelativeSpacing = 0.01f }; GUITextBlock aimAssistText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), controlsLayoutGroup.RectTransform), TextManager.Get("AimAssist")) { ToolTip = TextManager.Get("AimAssistToolTip") }; GUIScrollBar aimAssistSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), controlsLayoutGroup.RectTransform), barSize: 0.05f) { UserData = aimAssistText, BarScroll = MathUtils.InverseLerp(0.0f, 5.0f, AimAssistAmount), ToolTip = TextManager.Get("AimAssistToolTip"), OnMoved = (scrollBar, scroll) => { ChangeSliderText(scrollBar, scroll); AimAssistAmount = MathHelper.Lerp(0.0f, 5.0f, scroll); return(true); }, Step = 0.1f }; aimAssistSlider.OnMoved(aimAssistSlider, aimAssistSlider.BarScroll); new GUITickBox(new RectTransform(new Point(32, 32), controlsLayoutGroup.RectTransform), TextManager.Get("EnableMouseLook")) { ToolTip = TextManager.Get("EnableMouseLookToolTip"), Selected = EnableMouseLook, OnSelected = (tickBox) => { EnableMouseLook = tickBox.Selected; UnsavedSettings = true; return(true); } }; var inputFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.75f), controlsLayoutGroup.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.03f }; var inputColumnLeft = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), inputFrame.RectTransform)) { Stretch = true, RelativeSpacing = 0.02f }; var inputColumnRight = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), inputFrame.RectTransform)) { Stretch = true, RelativeSpacing = 0.02f }; var inputNames = Enum.GetValues(typeof(InputType)); for (int i = 0; i < inputNames.Length; i++) { var inputContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.06f), (i <= (inputNames.Length / 2.2f) ? inputColumnLeft : inputColumnRight).RectTransform)) { Stretch = true, IsHorizontal = true, RelativeSpacing = 0.05f, Color = new Color(12, 14, 15, 215) }; new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), inputContainer.RectTransform, Anchor.TopLeft) { MinSize = new Point(150, 0) }, TextManager.Get("InputType." + ((InputType)i)) + ": ", font: GUI.SmallFont) { ForceUpperCase = true }; var keyBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), inputContainer.RectTransform), text: keyMapping[i].ToString(), font: GUI.SmallFont) { UserData = i }; keyBox.OnSelected += KeyBoxSelected; keyBox.SelectedColor = Color.Gold * 0.3f; } var resetControlsHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), controlsLayoutGroup.RectTransform), isHorizontal: true) { RelativeSpacing = 0.02f }; new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), resetControlsHolder.RectTransform), TextManager.Get("SetDefaultBindings")) { ToolTip = TextManager.Get("SetDefaultBindingsToolTip"), OnClicked = (button, data) => { ResetControls(legacy: false); return(true); } }; new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), resetControlsHolder.RectTransform), TextManager.Get("SetLegacyBindings")) { ToolTip = TextManager.Get("SetLegacyBindingsToolTip"), OnClicked = (button, data) => { ResetControls(legacy: true); return(true); } }; //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null); new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonArea.RectTransform, Anchor.BottomLeft), TextManager.Get("Cancel"), style: "GUIButtonLarge") { IgnoreLayoutGroups = true, OnClicked = (x, y) => { if (UnsavedSettings) { LoadPlayerConfig(); } if (Screen.Selected == GameMain.MainMenuScreen) { GameMain.MainMenuScreen.ReturnToMainMenu(null, null); } GUI.SettingsMenuOpen = false; return(true); } }; new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonArea.RectTransform, Anchor.BottomCenter), TextManager.Get("Reset"), style: "GUIButtonLarge") { IgnoreLayoutGroups = true, OnClicked = (button, data) => { // TODO: add a prompt LoadDefaultConfig(); CheckBindings(true); RefreshItemMessages(); ApplySettings(); if (Screen.Selected == GameMain.MainMenuScreen) { GameMain.MainMenuScreen.ResetSettingsFrame(currentTab); } else { ResetSettingsFrame(); CreateSettingsFrame(currentTab); } return(true); } }; applyButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonArea.RectTransform, Anchor.BottomRight), TextManager.Get("ApplySettingsButton"), style: "GUIButtonLarge") { IgnoreLayoutGroups = true, Enabled = false }; applyButton.OnClicked = ApplyClicked; UnsavedSettings = false; // Reset unsaved settings to false once the UI has been created SelectTab(selectedTab); }
private void CreateSettingsFrame() { settingsFrame = new GUIFrame(new Rectangle(0, 0, 500, 500), null, Alignment.Center, ""); new GUITextBlock(new Rectangle(0, -30, 0, 30), TextManager.Get("Settings"), "", Alignment.TopCenter, Alignment.TopCenter, settingsFrame, false, GUI.LargeFont); int x = 0, y = 10; new GUITextBlock(new Rectangle(0, y, 20, 20), TextManager.Get("Resolution"), "", Alignment.TopLeft, Alignment.TopLeft, settingsFrame); var resolutionDD = new GUIDropDown(new Rectangle(0, y + 20, 180, 20), "", "", settingsFrame); resolutionDD.OnSelected = SelectResolution; var supportedModes = new List <DisplayMode>(); foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) { if (supportedModes.FirstOrDefault(m => m.Width == mode.Width && m.Height == mode.Height) != null) { continue; } resolutionDD.AddItem(mode.Width + "x" + mode.Height, mode); supportedModes.Add(mode); if (GraphicsWidth == mode.Width && GraphicsHeight == mode.Height) { resolutionDD.SelectItem(mode); } } if (resolutionDD.SelectedItemData == null) { resolutionDD.SelectItem(GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Last()); } y += 50; //var fullScreenTick = new GUITickBox(new Rectangle(x, y, 20, 20), "Fullscreen", Alignment.TopLeft, settingsFrame); //fullScreenTick.OnSelected = ToggleFullScreen; //fullScreenTick.Selected = FullScreenEnabled; new GUITextBlock(new Rectangle(x, y, 20, 20), TextManager.Get("DisplayMode"), "", Alignment.TopLeft, Alignment.TopLeft, settingsFrame); var displayModeDD = new GUIDropDown(new Rectangle(x, y + 20, 180, 20), "", "", settingsFrame); displayModeDD.AddItem(TextManager.Get("Fullscreen"), WindowMode.Fullscreen); displayModeDD.AddItem(TextManager.Get("Windowed"), WindowMode.Windowed); displayModeDD.AddItem(TextManager.Get("BorderlessWindowed"), WindowMode.BorderlessWindowed); displayModeDD.SelectItem(GameMain.Config.WindowMode); displayModeDD.OnSelected = (guiComponent, obj) => { UnsavedSettings = true; GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData; return(true); }; y += 70; GUITickBox vsyncTickBox = new GUITickBox(new Rectangle(0, y, 20, 20), TextManager.Get("EnableVSync"), Alignment.CenterY | Alignment.Left, settingsFrame); vsyncTickBox.OnSelected = (GUITickBox box) => { VSyncEnabled = !VSyncEnabled; GameMain.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = VSyncEnabled; GameMain.GraphicsDeviceManager.ApplyChanges(); UnsavedSettings = true; return(true); }; vsyncTickBox.Selected = VSyncEnabled; y += 70; new GUITextBlock(new Rectangle(0, y, 100, 20), TextManager.Get("SoundVolume"), "", settingsFrame); GUIScrollBar soundScrollBar = new GUIScrollBar(new Rectangle(0, y + 20, 150, 20), "", 0.1f, settingsFrame); soundScrollBar.BarScroll = SoundVolume; soundScrollBar.OnMoved = ChangeSoundVolume; soundScrollBar.Step = 0.05f; new GUITextBlock(new Rectangle(0, y + 40, 100, 20), TextManager.Get("MusicVolume"), "", settingsFrame); GUIScrollBar musicScrollBar = new GUIScrollBar(new Rectangle(0, y + 60, 150, 20), "", 0.1f, settingsFrame); musicScrollBar.BarScroll = MusicVolume; musicScrollBar.OnMoved = ChangeMusicVolume; musicScrollBar.Step = 0.05f; x = 200; y = 10; new GUITextBlock(new Rectangle(x, y, 20, 20), TextManager.Get("ContentPackage"), "", Alignment.TopLeft, Alignment.TopLeft, settingsFrame); var contentPackageDD = new GUIDropDown(new Rectangle(x, y + 20, 200, 20), "", "", settingsFrame); contentPackageDD.OnSelected = SelectContentPackage; foreach (ContentPackage contentPackage in ContentPackage.list) { contentPackageDD.AddItem(contentPackage.Name, contentPackage); if (SelectedContentPackage == contentPackage) { contentPackageDD.SelectItem(contentPackage); } } y += 50; new GUITextBlock(new Rectangle(x, y, 100, 20), TextManager.Get("Controls"), "", settingsFrame); y += 30; var inputNames = Enum.GetNames(typeof(InputType)); for (int i = 0; i < inputNames.Length; i++) { new GUITextBlock(new Rectangle(x, y, 100, 18), inputNames[i] + ": ", "", Alignment.TopLeft, Alignment.CenterLeft, settingsFrame); var keyBox = new GUITextBox(new Rectangle(x + 100, y, 120, 18), null, null, Alignment.TopLeft, Alignment.CenterLeft, "", settingsFrame); keyBox.Text = keyMapping[i].ToString(); keyBox.UserData = i; keyBox.OnSelected += KeyBoxSelected; keyBox.SelectedColor = Color.Gold * 0.3f; y += 20; } applyButton = new GUIButton(new Rectangle(0, 0, 100, 20), TextManager.Get("ApplySettingsButton"), Alignment.BottomRight, "", settingsFrame); applyButton.OnClicked = ApplyClicked; }
private void CreateGUIElements() { topPanel = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.1f), Frame.RectTransform) { MinSize = new Point(0, 60) }, "GUIFrameTop"); topPanelContents = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.8f), topPanel.RectTransform, Anchor.Center), style: null); new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0, 0.1f) }, "Reload Texture") { OnClicked = (button, userData) => { if (!(textureList.SelectedData is Texture2D selectedTexture)) { return(false); } var selected = selectedSprites; Sprite firstSelected = selected.First(); selected.ForEach(s => s.ReloadTexture()); RefreshLists(); textureList.Select(firstSelected.Texture, autoScroll: false); selected.ForEachMod(s => spriteList.Select(s, autoScroll: false)); texturePathText.Text = "Textures reloaded from " + firstSelected.FilePath; texturePathText.TextColor = Color.LightGreen; return(true); } }; new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.BottomLeft) { RelativeOffset = new Vector2(0, 0.1f) }, "Reset Changes") { OnClicked = (button, userData) => { if (selectedTexture == null) { return(false); } foreach (Sprite sprite in loadedSprites) { if (sprite.Texture != selectedTexture) { continue; } var element = sprite.SourceElement; if (element == null) { continue; } // Not all sprites have a sourcerect defined, in which case we'll want to use the current source rect instead of an empty rect. sprite.SourceRect = element.GetAttributeRect("sourcerect", sprite.SourceRect); sprite.RelativeOrigin = element.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f)); } ResetWidgets(); xmlPathText.Text = "Changes successfully reset"; xmlPathText.TextColor = Color.LightGreen; return(true); } }; new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.15f, 0.1f) }, "Save Selected Sprites") { OnClicked = (button, userData) => { if (selectedSprites.None()) { return(false); } foreach (var sprite in selectedSprites) { var element = sprite.SourceElement; if (element == null) { xmlPathText.Text = "No xml element defined for the sprite"; xmlPathText.TextColor = Color.Red; return(false); } element.SetAttributeValue("sourcerect", XMLExtensions.RectToString(sprite.SourceRect)); element.SetAttributeValue("origin", XMLExtensions.Vector2ToString(sprite.RelativeOrigin)); } var firstSprite = selectedSprites.First(); XElement e = firstSprite.SourceElement; var d = XMLExtensions.TryLoadXml(xmlPath); if (d == null || d.BaseUri != e.Document.BaseUri) { xmlPathText.Text = "Failed to save to " + xmlPath; xmlPathText.TextColor = Color.Red; return(false); } e.Document.Save(xmlPath); xmlPathText.Text = "Selected sprites saved to " + xmlPath; xmlPathText.TextColor = Color.LightGreen; return(true); } }; new GUIButton(new RectTransform(new Vector2(0.12f, 0.4f), topPanelContents.RectTransform, Anchor.BottomLeft) { RelativeOffset = new Vector2(0.15f, 0.1f) }, "Save All Sprites") { OnClicked = (button, userData) => { if (selectedTexture == null) { return(false); } XDocument doc = null; foreach (Sprite sprite in loadedSprites) { if (sprite.Texture != selectedTexture) { continue; } var element = sprite.SourceElement; if (element == null) { continue; } element.SetAttributeValue("sourcerect", XMLExtensions.RectToString(sprite.SourceRect)); element.SetAttributeValue("origin", XMLExtensions.Vector2ToString(sprite.RelativeOrigin)); doc = element.Document; } if (doc != null) { var d = XMLExtensions.TryLoadXml(xmlPath); if (d == null || d.BaseUri != doc.BaseUri) { xmlPathText.Text = "Failed to save to " + xmlPath; xmlPathText.TextColor = Color.Red; return(false); } doc.Save(xmlPath); xmlPathText.Text = "All changes saved to " + xmlPath; xmlPathText.TextColor = Color.LightGreen; return(true); } else { xmlPathText.Text = "Failed to save to " + xmlPath; xmlPathText.TextColor = Color.Red; return(false); } } }; new GUITextBlock(new RectTransform(new Vector2(0.2f, 0.2f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0, 0.3f) }, "Zoom: "); zoomBar = new GUIScrollBar(new RectTransform(new Vector2(0.2f, 0.35f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0.05f, 0.3f) }, barSize: 0.1f) { BarScroll = GetBarScrollValue(), Step = 0.01f, OnMoved = (scrollBar, value) => { zoom = MathHelper.Lerp(minZoom, maxZoom, value); return(true); } }; new GUIButton(new RectTransform(new Vector2(0.05f, 0.35f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterLeft) { RelativeOffset = new Vector2(0.055f, 0.3f) }, "Reset Zoom") { OnClicked = (box, data) => { ResetZoom(); return(true); } }; texturePathText = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.4f), topPanelContents.RectTransform, Anchor.Center, Pivot.BottomCenter) { RelativeOffset = new Vector2(0.4f, 0) }, "", Color.LightGray); xmlPathText = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.4f), topPanelContents.RectTransform, Anchor.Center, Pivot.TopCenter) { RelativeOffset = new Vector2(0.4f, 0) }, "", Color.LightGray); leftPanel = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f - topPanel.RectTransform.RelativeSize.Y), Frame.RectTransform, Anchor.BottomLeft) { MinSize = new Point(150, 0) }, style: "GUIFrameLeft"); var paddedLeftPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), leftPanel.RectTransform, Anchor.CenterLeft) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { Stretch = true }; textureList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), paddedLeftPanel.RectTransform)) { OnSelected = (listBox, userData) => { var previousTexture = selectedTexture; selectedTexture = userData as Texture2D; if (previousTexture != selectedTexture) { ResetZoom(); } foreach (GUIComponent child in spriteList.Content.Children) { var textBlock = (GUITextBlock)child; var sprite = (Sprite)textBlock.UserData; textBlock.TextColor = new Color(textBlock.TextColor, sprite.Texture == selectedTexture ? 1.0f : 0.4f); } if (selectedSprites.None(s => s.Texture == selectedTexture)) { spriteList.Select(loadedSprites.First(s => s.Texture == selectedTexture), false); UpdateScrollBar(spriteList); } var firstSprite = selectedSprites.First(); texturePathText.Text = firstSprite.FilePath; texturePathText.TextColor = Color.LightGray; var element = firstSprite.SourceElement; if (element == null) { xmlPathText.Text = string.Empty; } else { xmlPath = element.ParseContentPathFromUri(); xmlPathText.Text = xmlPath; xmlPathText.TextColor = Color.LightGray; } topPanelContents.Visible = true; return(true); } }; rightPanel = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f - topPanel.RectTransform.RelativeSize.Y), Frame.RectTransform, Anchor.BottomRight) { MinSize = new Point(150, 0) }, style: "GUIFrameRight"); var paddedRightPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), rightPanel.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { Stretch = true, RelativeSpacing = 0.01f }; spriteList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), paddedRightPanel.RectTransform)) { OnSelected = (listBox, userData) => { Sprite sprite = userData as Sprite; if (sprite == null) { return(false); } if (selectedSprites.Any(s => s.Texture != selectedTexture)) { ResetWidgets(); } if (Widget.EnableMultiSelect) { if (selectedSprites.Contains(sprite)) { selectedSprites.Remove(sprite); } else { selectedSprites.Add(sprite); dirtySprites.Add(sprite); } } else { selectedSprites.Clear(); selectedSprites.Add(sprite); dirtySprites.Add(sprite); } if (selectedTexture != sprite.Texture) { textureList.Select(sprite.Texture, autoScroll: false); UpdateScrollBar(textureList); } return(true); } }; }