public VideoOptionsState(GuiPanoramaSkyBox skyBox) : base(skyBox) { TitleTranslationKey = "options.videoTitle"; AddGuiRow(CreateSlider("Render Distance: {0} chunks", o => Options.VideoOptions.RenderDistance, 2, 32, 1), GuiScaleGlider = CreateSlider("GUI Scale: {0}", options => options.VideoOptions.GuiScale, 0, 3, 1)); AddGuiRow(CreateSlider("Chunk Processing Threads: {0}", o => Options.VideoOptions.ChunkThreads, 1, Environment.ProcessorCount, 1), CreateSlider("Brightness: {0}%", o => Options.VideoOptions.Brightness, 0, 100, 1) /*, * CreateSlider("Max Framerate: {0} fps", o => Options.VideoOptions.MaxFramerate, 1, 120, 1)*/); AddGuiRow(CreateToggle("Use VSync: {0}", o => { return(Options.VideoOptions.UseVsync); }), CreateToggle("Fullscreen: {0}", o => { return(Options.VideoOptions.Fullscreen); })); }
public ConstructionSiteView() { this.Background = new BackgroundTexture(GalaxyTextures.Get.PanelBackground, 6); this.Position.FixedSize(360, 116); this.title = new GuiText { Margins = new Vector2(8, 4), TextColor = Color.Black, TextHeight = 12 }; this.title.Position.WrapContent().Then.ParentRelative(-1, 1).UseMargins(); this.AddChild(this.title); this.projectButton = new GuiButton { BackgroundHover = new BackgroundTexture(GalaxyTextures.Get.ButtonHover, 9), BackgroundNormal = new BackgroundTexture(GalaxyTextures.Get.ButtonNormal, 9), Padding = 10, Margins = new Vector2(8, 8), TextColor = Color.Black, TextHeight = 12, ClickCallback = projectButton_Click }; this.projectButton.Position.FixedSize(88, 88).ParentRelative(-1, -1).UseMargins(); this.AddChild(this.projectButton); this.detailsButton = new GuiButton { BackgroundHover = new BackgroundTexture(GalaxyTextures.Get.ButtonHover, 9), BackgroundNormal = new BackgroundTexture(GalaxyTextures.Get.ButtonNormal, 9), Padding = 10, Margins = new Vector2(8, 8), TextColor = Color.Black, TextHeight = 12, Text = context["SiteDetails"].Text(), ClickCallback = detailsButton_Click }; this.detailsButton.Position.WrapContent().Then.ParentRelative(1, -1).UseMargins(); this.AddChild(this.detailsButton); this.investmentSlider = new GuiSlider { Margins = new Vector2(8, 0), ScrollStep = 0.05f, SlideCallback = investmentSlider_Change }; this.investmentSlider.Position.FixedSize(150, 15).RelativeTo(this.projectButton, 1, 1, -1, 1).UseMargins().StretchRightTo(this, 1); this.AddChild(this.investmentSlider); this.estimationLabel = new GuiText { Margins = new Vector2(0, 8), TextColor = Color.Black, TextHeight = 12 }; this.estimationLabel.Position.WrapContent().Then.RelativeTo(this.investmentSlider, -1, -1, -1, 1).UseMargins(); this.AddChild(this.estimationLabel); this.policyToggle = new CycleButton <PolicyInfo> { BackgroundHover = new BackgroundTexture(GalaxyTextures.Get.ToggleHover, 8), BackgroundNormal = new BackgroundTexture(GalaxyTextures.Get.ToggleNormal, 8), Padding = 4, Margins = new Vector2(8, 0), CycleCallback = x => { this.controller.Policy = x; this.investmentSlider.Value = (float)this.controller.DesiredSpendingRatio; this.resetView(); this.scene.ResetTooltipContents(); }, ItemImage = x => GalaxyTextures.Get.Sprite(x.Id + "Policy"), Tooltip = new DynamicTooltip("FormMain", () => this.controller.Policy.Id + "PolicyTooltip") }; this.policyToggle.Position.FixedSize(32, 32).RelativeTo(this.projectButton, 1, -1, -1, -1).UseMargins(); this.AddChild(this.policyToggle); this.policyName = new GuiText { Margins = new Vector2(8, 0), TextColor = Color.Black, TextHeight = 12 }; this.policyName.Position.WrapContent().Then.RelativeTo(this.policyToggle, 1, 0, -1, 0).UseMargins(); this.AddChild(this.policyName); }
public CustomFormDialog(uint formId, BedrockFormManager parent, CustomForm form, InputManager inputManager) : base(formId, parent, inputManager) { Container.AddChild(new GuiTextElement() { Anchor = Alignment.TopCenter, Text = form.Title, FontStyle = FontStyle.Bold, Scale = 2f, TextColor = TextColor.White }); Form = form; GuiScrollableStackContainer stackContainer = new GuiScrollableStackContainer(); stackContainer.Orientation = Orientation.Vertical; stackContainer.Anchor = Alignment.Fill; stackContainer.ChildAnchor = Alignment.MiddleFill; var margin = new Thickness(5, 5); foreach (var element in form.Content) { switch (element) { case Label label: { stackContainer.AddChild(new GuiTextElement() { Text = label.Text, Margin = margin }); } break; case Input input: { GuiTextInput guiInput = new GuiTextInput() { Value = input.Value, PlaceHolder = input.Placeholder, Margin = margin }; guiInput.ValueChanged += (sender, s) => { input.Value = s; }; stackContainer.AddChild(guiInput); } break; case Toggle toggle: { GuiToggleButton guiToggle; stackContainer.AddChild(guiToggle = new GuiToggleButton(toggle.Text) { Margin = margin, Value = !toggle.Value }); guiToggle.DisplayFormat = new ValueFormatter <bool>((val) => { return($"{toggle.Text}: {val.ToString()}"); }); guiToggle.Value = toggle.Value; guiToggle.ValueChanged += (sender, b) => { toggle.Value = b; }; } break; case Slider slider: { GuiSlider guiSlider; stackContainer.AddChild(guiSlider = new GuiSlider() { Label = { Text = slider.Text }, Value = slider.Value, MaxValue = slider.Max, MinValue = slider.Min, StepInterval = slider.Step, Margin = margin }); guiSlider.ValueChanged += (sender, d) => { slider.Value = (float)d; }; } break; case StepSlider stepSlider: { stackContainer.AddChild(new GuiTextElement() { Text = "Unsupported stepslider", TextColor = TextColor.Red, Margin = margin }); } break; case Dropdown dropdown: { stackContainer.AddChild(new GuiTextElement() { Text = "Unsupported dropdown", TextColor = TextColor.Red, Margin = margin }); } break; } } SubmitButton = new GuiButton("Submit", SubmitPressed); stackContainer.AddChild(SubmitButton); Container.AddChild(stackContainer); }
public CustomFormDialog(uint formId, BedrockFormManager parent, CustomForm form, InputManager inputManager) : base(formId, parent, inputManager) { Form = form; GuiScrollableStackContainer stackContainer = new GuiScrollableStackContainer(); stackContainer.Orientation = Orientation.Vertical; stackContainer.Anchor = Alignment.Fill; stackContainer.ChildAnchor = Alignment.MiddleFill; stackContainer.Background = Color.Black * 0.35f; var margin = new Thickness(5, 5); foreach (var element in form.Content) { switch (element) { case Label label: { stackContainer.AddChild(new GuiTextElement() { Text = label.Text, Margin = margin }); } break; case Input input: { GuiTextInput guiInput = new GuiTextInput() { Value = input.Value, PlaceHolder = !string.IsNullOrWhiteSpace(input.Placeholder) ? input.Placeholder : input.Text, Margin = margin }; guiInput.ValueChanged += (sender, s) => { input.Value = s; }; stackContainer.AddChild(guiInput); } break; case Toggle toggle: { GuiToggleButton guiToggle; stackContainer.AddChild(guiToggle = new GuiToggleButton(toggle.Text) { Margin = margin, Value = !toggle.Value }); guiToggle.DisplayFormat = new ValueFormatter <bool>((val) => { return($"{toggle.Text}: {val.ToString()}"); }); guiToggle.Value = toggle.Value; guiToggle.ValueChanged += (sender, b) => { toggle.Value = b; }; } break; case Slider slider: { GuiSlider guiSlider; stackContainer.AddChild(guiSlider = new GuiSlider() { Label = { Text = slider.Text }, Value = slider.Value, MaxValue = slider.Max, MinValue = slider.Min, StepInterval = slider.Step, Margin = margin }); guiSlider.ValueChanged += (sender, d) => { slider.Value = (float)d; }; } break; case StepSlider stepSlider: { stackContainer.AddChild(new GuiTextElement() { Text = "Unsupported stepslider", TextColor = TextColor.Red, Margin = margin }); } break; case Dropdown dropdown: { stackContainer.AddChild(new GuiTextElement() { Text = "Unsupported dropdown", TextColor = TextColor.Red, Margin = margin }); } break; } } SubmitButton = new GuiButton("Submit", SubmitPressed); stackContainer.AddChild(SubmitButton); Background = Color.Transparent; var width = 356; var height = width; ContentContainer.Width = ContentContainer.MinWidth = ContentContainer.MaxWidth = width; ContentContainer.Height = ContentContainer.MinHeight = ContentContainer.MaxHeight = height; SetFixedSize(width, height); ContentContainer.AutoSizeMode = AutoSizeMode.None; Container.Anchor = Alignment.MiddleCenter; var bodyWrapper = new GuiContainer(); bodyWrapper.Anchor = Alignment.Fill; bodyWrapper.Padding = new Thickness(5, 0); bodyWrapper.AddChild(stackContainer); Container.AddChild(bodyWrapper); Container.AddChild(Header = new GuiStackContainer() { Anchor = Alignment.TopFill, ChildAnchor = Alignment.BottomCenter, Height = 32, Padding = new Thickness(3), Background = Color.Black * 0.5f }); Header.AddChild(new GuiTextElement() { Text = FixContrast(form.Title), TextColor = TextColor.White, Scale = 2f, FontStyle = FontStyle.DropShadow, Anchor = Alignment.BottomCenter, }); stackContainer.Margin = new Thickness(0, Header.Height, 0, 0); }
/** * Creates a control for given property. * * ToggleButtons will be used for boolean properties. * For the moment other types of properties are not supported. * * @param source The source object this property belongs to. * @param property The property to create a control for. */ private GuiLabeledComponent CreateControl(object source, PropertyInfo property) { GuiLabeledComponent result = null; var rangeAttribute = getAttribute <SettingRange>(property); if (property.PropertyType == typeof(System.Boolean)) { var toggleButton = new GuiToggleButton(); toggleButton.Value = (bool)property.GetValue(source, null); if (property.CanWrite) { toggleButton.OnValueChanged += delegate { property.SetValue(source, toggleButton.Value, null); } } ; result = toggleButton; } else if (property.PropertyType.IsEnum) { var radioGroup = new GuiRadioButtonGroup(); radioGroup.EnableBackground = false; radioGroup.ButtonSpacing = 2; radioGroup.ButtonSize = new Vector2(80, 32); var enumNames = Enum.GetNames(property.PropertyType); foreach (string enumValueName in enumNames) { if (!enumValueName.StartsWith("_")) { radioGroup.AddItem(enumValueName); } } radioGroup.SelectedIndex = (int)property.GetValue(source, null); if (property.CanWrite) { radioGroup.OnValueChanged += delegate { property.SetValue(source, radioGroup.SelectedIndex, null); }; } result = radioGroup; } else if (property.PropertyType == typeof(System.Single) && (rangeAttribute != null)) { var slider = new GuiSlider(); slider.Min = rangeAttribute.Min; slider.Max = rangeAttribute.Max; slider.Value = (float)property.GetValue(source, null); if (property.CanWrite) { slider.OnValueChanged += delegate { property.SetValue(source, slider.Value, null); } } ; result = slider; } else if ( // fallback to edit box (property.PropertyType == typeof(int)) || (property.PropertyType == typeof(float)) || (property.PropertyType == typeof(string))) { int editWidth = (property.PropertyType == typeof(string)) ? 325 : 60; var editBox = new GuiTextField(0, 0, editWidth); object propertyValue = property.GetValue(source, null); if (propertyValue != null) { editBox.Value = propertyValue.ToString(); if (editBox.Value.Length > 35) { editBox.FontSize = 12; } if (editBox.Value.Length > 55) { editBox.FontSize = 10; } if (editBox.Value.Length > 75) { editBox.FontSize = 8; } } if (property.CanWrite) { editBox.OnValueChanged += delegate { if (property.PropertyType == typeof(int)) { property.SetValue(source, Util.ParseIntDefault(editBox.Value, 0), null); } else if (property.PropertyType == typeof(float)) { property.SetValue(source, Util.ParseFloatDefault(editBox.Value, 0), null); } else if (property.PropertyType == typeof(string)) { property.SetValue(source, editBox.Value, null); } } } ; result = editBox; } if (result != null) { if (!property.CanWrite) { result.SelfEnabled = false; } result.LabelText = property.Name; result.LabelPosition = LabelPosition.Left; result.Name = property.Name; } return(result); }