private GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, int yPos, GUIComponent parent) { var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute <Editable>().ToolTip; GUIDropDown enumDropDown = new GUIDropDown(new Rectangle(180, yPos, 0, 18), "", "", Alignment.TopLeft, parent); enumDropDown.ToolTip = property.GetAttribute <Editable>().ToolTip; foreach (object enumValue in Enum.GetValues(value.GetType())) { var enumTextBlock = new GUITextBlock(new Rectangle(0, 0, 200, 25), enumValue.ToString(), "", enumDropDown); enumTextBlock.UserData = enumValue; } enumDropDown.OnSelected += (selected, val) => { if (property.TrySetValue(val)) { TrySendNetworkUpdate(entity, property); } return(true); }; enumDropDown.SelectItem(value); return(enumDropDown); }
private bool CreateTestSetupMenu() { var msgBox = new GUIMessageBox(TextManager.Get("EventEditor.TestPromptHeader"), "", new[] { TextManager.Get("Cancel"), TextManager.Get("OK") }, relativeSize: new Vector2(0.2f, 0.3f), minSize: new Point(300, 175)); var layout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.5f), msgBox.Content.RectTransform)); new GUITextBlock(new RectTransform(new Vector2(1, 0.25f), layout.RectTransform), TextManager.Get("EventEditor.OutpostGenParams"), font: GUI.SubHeadingFont); GUIDropDown paramInput = new GUIDropDown(new RectTransform(new Vector2(1, 0.25f), layout.RectTransform), string.Empty, OutpostGenerationParams.Params.Count); foreach (OutpostGenerationParams param in OutpostGenerationParams.Params) { paramInput.AddItem(param.Identifier, param); } paramInput.OnSelected = (_, param) => { lastTestParam = param as OutpostGenerationParams; return(true); }; paramInput.SelectItem(lastTestParam ?? OutpostGenerationParams.Params.FirstOrDefault()); new GUITextBlock(new RectTransform(new Vector2(1, 0.25f), layout.RectTransform), TextManager.Get("EventEditor.LocationType"), font: GUI.SubHeadingFont); GUIDropDown typeInput = new GUIDropDown(new RectTransform(new Vector2(1, 0.25f), layout.RectTransform), string.Empty, LocationType.List.Count); foreach (LocationType type in LocationType.List) { typeInput.AddItem(type.Identifier, type); } typeInput.OnSelected = (_, type) => { lastTestType = type as LocationType; return(true); }; typeInput.SelectItem(lastTestType ?? LocationType.List.FirstOrDefault()); // Cancel button msgBox.Buttons[0].OnClicked = (button, o) => { msgBox.Close(); return(true); }; // Ok button msgBox.Buttons[1].OnClicked = (button, o) => { TestEvent(lastTestParam, lastTestType); msgBox.Close(); return(true); }; return(true); }
private void RefreshCreateItemFileList() { createItemFileList.ClearChildren(); if (itemContentPackage == null) { return; } var contentTypes = Enum.GetValues(typeof(ContentType)); foreach (ContentFile contentFile in itemContentPackage.Files) { var fileFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.1f), createItemFileList.Content.RectTransform) { MinSize = new Point(0, 15) }, style: "ListBoxElement") { UserData = contentFile }; new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), fileFrame.RectTransform, Anchor.CenterLeft), contentFile.Path); var contentTypeSelection = new GUIDropDown(new RectTransform(new Vector2(0.4f, 1.0f), fileFrame.RectTransform, Anchor.CenterRight), elementCount: contentTypes.Length) { UserData = contentFile, }; contentTypeSelection.OnSelected = (GUIComponent selected, object userdata) => { ((ContentFile)contentTypeSelection.UserData).Type = (ContentType)userdata; itemContentPackage.Save(itemContentPackage.Path); return(true); }; foreach (ContentType contentType in contentTypes) { contentTypeSelection.AddItem(contentType.ToString(), contentType); } contentTypeSelection.SelectItem(contentFile.Type); } }
public GUIComponent CreateEditor(GUIComponent parent, List <SpriteDeformation> deformations, string parentDebugName) { var container = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform)) { AbsoluteSpacing = 5, CanBeFocused = true }; new GUITextBlock(new RectTransform(new Point(container.Rect.Width, (int)(60 * GUI.Scale)), container.RectTransform) { IsFixedSize = true }, "Sprite Deformations", textAlignment: Alignment.BottomCenter, font: GUI.LargeFont); var resolutionField = GUI.CreatePointField(new Point(subDivX + 1, subDivY + 1), (int)(30 * GUI.Scale), "Resolution", container.RectTransform, "How many vertices the deformable sprite has on the x and y axes. Larger values make the deformations look smoother, but are more performance intensive."); resolutionField.RectTransform.IsFixedSize = true; GUINumberInput xField = null, yField = null; foreach (GUIComponent child in resolutionField.GetAllChildren()) { if (yField == null) { yField = child as GUINumberInput; } else { xField = child as GUINumberInput; if (xField != null) { break; } } } xField.MinValueInt = 2; xField.MaxValueInt = SpriteDeformationParams.ShaderMaxResolution.X - 1; xField.OnValueChanged = (numberInput) => { ChangeResolution(); }; yField.MinValueInt = 2; yField.MaxValueInt = SpriteDeformationParams.ShaderMaxResolution.Y - 1; yField.OnValueChanged = (numberInput) => { ChangeResolution(); }; void ChangeResolution() { subDivX = xField.IntValue - 1; subDivY = yField.IntValue - 1; foreach (SpriteDeformation deformation in deformations) { deformation.SetResolution(new Point(xField.IntValue, yField.IntValue)); } SetupVertexBuffers(); SetupIndexBuffer(); } foreach (SpriteDeformation deformation in deformations) { var deformEditor = new SerializableEntityEditor(container.RectTransform, deformation.Params, inGame: false, showName: true, titleFont: GUI.SubHeadingFont); deformEditor.RectTransform.MinSize = new Point(deformEditor.Rect.Width, deformEditor.Rect.Height); } var deformationDD = new GUIDropDown(new RectTransform(new Point(container.Rect.Width, 30), container.RectTransform), "Add new sprite deformation"); deformationDD.OnSelected = (selected, userdata) => { deformations.Add(SpriteDeformation.Load((string)userdata, parentDebugName)); deformationDD.Text = "Add new sprite deformation"; return(false); }; foreach (string deformationType in SpriteDeformation.DeformationTypes) { deformationDD.AddItem(deformationType, deformationType); } container.RectTransform.Resize(new Point( container.Rect.Width, container.Children.Sum(c => c.Rect.Height + container.AbsoluteSpacing)), false); container.RectTransform.MinSize = new Point(0, container.Rect.Height); container.RectTransform.MaxSize = new Point(int.MaxValue, container.Rect.Height); container.RectTransform.IsFixedSize = true; container.Recalculate(); return(container); }
private static void CreateEditMenu(ValueNode?node, NodeConnection?connection = null) { object?newValue; Type? type; if (node != null) { newValue = node.Value; type = node.Type; } else if (connection != null) { newValue = connection.OverrideValue; type = connection.ValueType; } else { return; } if (connection?.Type == NodeConnectionType.Option) { newValue = connection.OptionText; type = typeof(string); } if (type == null) { return; } Vector2 size = type == typeof(string) ? new Vector2(0.2f, 0.3f) : new Vector2(0.2f, 0.175f); var msgBox = new GUIMessageBox(TextManager.Get("EventEditor.Edit"), "", new[] { TextManager.Get("Cancel"), TextManager.Get("OK") }, size, minSize: new Point(300, 175)); Vector2 layoutSize = type == typeof(string) ? new Vector2(1f, 0.5f) : new Vector2(1f, 0.25f); var layout = new GUILayoutGroup(new RectTransform(layoutSize, msgBox.Content.RectTransform), isHorizontal: true); if (type.IsEnum) { Array enums = Enum.GetValues(type); GUIDropDown valueInput = new GUIDropDown(new RectTransform(Vector2.One, layout.RectTransform), newValue?.ToString(), enums.Length); foreach (object? @enum in enums) { valueInput.AddItem(@enum?.ToString(), @enum); } valueInput.OnSelected += (component, o) => { newValue = o; return(true); }; } else { if (type == typeof(string)) { GUIListBox listBox = new GUIListBox(new RectTransform(Vector2.One, layout.RectTransform)) { CanBeFocused = false }; GUITextBox valueInput = new GUITextBox(new RectTransform(Vector2.One, listBox.Content.RectTransform, Anchor.TopRight), wrap: true, style: "GUITextBoxNoBorder"); valueInput.OnTextChanged += (component, o) => { Vector2 textSize = valueInput.Font.MeasureString(valueInput.WrappedText); valueInput.RectTransform.NonScaledSize = new Point(valueInput.RectTransform.NonScaledSize.X, (int)textSize.Y + 10); listBox.UpdateScrollBarSize(); listBox.BarScroll = 1.0f; newValue = o; return(true); }; valueInput.Text = newValue?.ToString() ?? "<type here>"; } else if (type == typeof(float) || type == typeof(int)) { GUINumberInput valueInput = new GUINumberInput(new RectTransform(Vector2.One, layout.RectTransform), GUINumberInput.NumberType.Float) { FloatValue = (float)(newValue ?? 0.0f) }; valueInput.OnValueChanged += component => { newValue = component.FloatValue; }; } else if (type == typeof(bool)) { GUITickBox valueInput = new GUITickBox(new RectTransform(Vector2.One, layout.RectTransform), "Value") { Selected = (bool)(newValue ?? false) }; valueInput.OnSelected += component => { newValue = component.Selected; return(true); }; } } // Cancel button msgBox.Buttons[0].OnClicked = (button, o) => { msgBox.Close(); return(true); }; // Ok button msgBox.Buttons[1].OnClicked = (button, o) => { if (node != null) { node.Value = newValue; } else if (connection != null) { if (connection.Type == NodeConnectionType.Option) { connection.OptionText = newValue?.ToString(); } else { connection.ClearConnections(); connection.OverrideValue = newValue; } } msgBox.Close(); return(true); }; }
private void CreateGUI() { GuiFrame = new GUIFrame(new RectTransform(new Vector2(0.2f, 0.4f), GUICanvas.Instance) { MinSize = new Point(300, 400) }); GUILayoutGroup layoutGroup = new GUILayoutGroup(RectTransform(0.9f, 0.9f, GuiFrame, Anchor.Center)) { Stretch = true }; // === BUTTONS === // GUILayoutGroup buttonLayout = new GUILayoutGroup(RectTransform(1.0f, 0.50f, layoutGroup)) { RelativeSpacing = 0.04f }; GUIButton newProjectButton = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.NewProject")); GUIButton saveProjectButton = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.SaveProject")); GUIButton loadProjectButton = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.LoadProject")); GUIButton exportProjectButton = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.Export")); // === LOAD PREFAB === // GUILayoutGroup loadEventLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup)); new GUITextBlock(RectTransform(1.0f, 0.5f, loadEventLayout), TextManager.Get("EventEditor.LoadEvent"), font: GUI.SubHeadingFont); GUILayoutGroup loadDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, loadEventLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft); GUIDropDown loadDropdown = new GUIDropDown(RectTransform(0.8f, 1.0f, loadDropdownLayout), elementCount: 10); GUIButton loadButton = new GUIButton(RectTransform(0.2f, 1.0f, loadDropdownLayout), TextManager.Get("Load")); // === ADD ACTION === // GUILayoutGroup addActionLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup)); new GUITextBlock(RectTransform(1.0f, 0.5f, addActionLayout), TextManager.Get("EventEditor.AddAction"), font: GUI.SubHeadingFont); GUILayoutGroup addActionDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, addActionLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft); GUIDropDown addActionDropdown = new GUIDropDown(RectTransform(0.8f, 1.0f, addActionDropdownLayout), elementCount: 10); GUIButton addActionButton = new GUIButton(RectTransform(0.2f, 1.0f, addActionDropdownLayout), TextManager.Get("EventEditor.Add")); // === ADD VALUE === // GUILayoutGroup addValueLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup)); new GUITextBlock(RectTransform(1.0f, 0.5f, addValueLayout), TextManager.Get("EventEditor.AddValue"), font: GUI.SubHeadingFont); GUILayoutGroup addValueDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, addValueLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft); GUIDropDown addValueDropdown = new GUIDropDown(RectTransform(0.8f, 1.0f, addValueDropdownLayout), elementCount: 7); GUIButton addValueButton = new GUIButton(RectTransform(0.2f, 1.0f, addValueDropdownLayout), TextManager.Get("EventEditor.Add")); // === ADD SPECIAL === // GUILayoutGroup addSpecialLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup)); new GUITextBlock(RectTransform(1.0f, 0.5f, addSpecialLayout), TextManager.Get("EventEditor.AddSpecial"), font: GUI.SubHeadingFont); GUILayoutGroup addSpecialDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, addSpecialLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft); GUIDropDown addSpecialDropdown = new GUIDropDown(RectTransform(0.8f, 1.0f, addSpecialDropdownLayout), elementCount: 1); GUIButton addSpecialButton = new GUIButton(RectTransform(0.2f, 1.0f, addSpecialDropdownLayout), TextManager.Get("EventEditor.Add")); // Add event prefabs with identifiers to the list foreach (EventPrefab eventPrefab in EventSet.GetAllEventPrefabs().Where(prefab => !string.IsNullOrWhiteSpace(prefab.Identifier)).Distinct()) { loadDropdown.AddItem(eventPrefab.Identifier, eventPrefab); } // Add all types that inherit the EventAction class foreach (Type type in Assembly.GetExecutingAssembly().GetTypes().Where(type => type.IsSubclassOf(typeof(EventAction)))) { addActionDropdown.AddItem(type.Name, type); } addSpecialDropdown.AddItem("Custom", typeof(CustomNode)); addValueDropdown.AddItem(nameof(Single), typeof(float)); addValueDropdown.AddItem(nameof(Boolean), typeof(bool)); addValueDropdown.AddItem(nameof(String), typeof(string)); addValueDropdown.AddItem(nameof(SpawnType), typeof(SpawnType)); addValueDropdown.AddItem(nameof(LimbType), typeof(LimbType)); addValueDropdown.AddItem(nameof(ReputationAction.ReputationType), typeof(ReputationAction.ReputationType)); addValueDropdown.AddItem(nameof(SpawnAction.SpawnLocationType), typeof(SpawnAction.SpawnLocationType)); loadButton.OnClicked += (button, o) => Load(loadDropdown.SelectedData as EventPrefab); addActionButton.OnClicked += (button, o) => AddAction(addActionDropdown.SelectedData as Type); addValueButton.OnClicked += (button, o) => AddValue(addValueDropdown.SelectedData as Type); addSpecialButton.OnClicked += (button, o) => AddSpecial(addSpecialDropdown.SelectedData as Type); exportProjectButton.OnClicked += ExportEventToFile; saveProjectButton.OnClicked += SaveProjectToFile; newProjectButton.OnClicked += TryCreateNewProject; loadProjectButton.OnClicked += (button, o) => { FileSelection.OnFileSelected = (file) => { XDocument?document = XMLExtensions.TryLoadXml(file); if (document?.Root != null) { Load(document.Root); } }; string directory = Path.GetFullPath("EventProjects"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } FileSelection.ClearFileTypeFilters(); FileSelection.AddFileTypeFilter("Scripted Event", "*.sevproj"); FileSelection.SelectFileTypeFilter("*.sevproj"); FileSelection.CurrentDirectory = directory; FileSelection.Open = true; return(true); }; screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight); }
private void CreateLevelObjectEditor(LevelObjectPrefab levelObjectPrefab) { editorContainer.ClearChildren(); var editor = new SerializableEntityEditor(editorContainer.Content.RectTransform, levelObjectPrefab, false, true, elementHeight: 20, titleFont: GUI.LargeFont); if (selectedParams != null) { var commonnessContainer = new GUILayoutGroup(new RectTransform(new Point(editor.Rect.Width, 70)) { IsFixedSize = true }, isHorizontal: false, childAnchor: Anchor.TopCenter) { AbsoluteSpacing = 5, Stretch = true }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.4f), commonnessContainer.RectTransform), TextManager.GetWithVariable("leveleditor.levelobjcommonness", "[leveltype]", selectedParams.Name), textAlignment: Alignment.Center); new GUINumberInput(new RectTransform(new Vector2(0.5f, 0.4f), commonnessContainer.RectTransform), GUINumberInput.NumberType.Float) { MinValueFloat = 0, MaxValueFloat = 100, FloatValue = levelObjectPrefab.GetCommonness(selectedParams.Name), OnValueChanged = (numberInput) => { levelObjectPrefab.OverrideCommonness[selectedParams.Name] = numberInput.FloatValue; } }; new GUIFrame(new RectTransform(new Vector2(1.0f, 0.2f), commonnessContainer.RectTransform), style: null); editor.AddCustomContent(commonnessContainer, 1); } Sprite sprite = levelObjectPrefab.Sprites.FirstOrDefault() ?? levelObjectPrefab.DeformableSprite?.Sprite; if (sprite != null) { editor.AddCustomContent(new GUIButton(new RectTransform(new Point(editor.Rect.Width / 2, (int)(25 * GUI.Scale))) { IsFixedSize = true }, TextManager.Get("leveleditor.editsprite")) { OnClicked = (btn, userdata) => { editingSprite = sprite; GameMain.SpriteEditorScreen.SelectSprite(editingSprite); return(true); } }, 1); } if (levelObjectPrefab.DeformableSprite != null) { var deformEditor = levelObjectPrefab.DeformableSprite.CreateEditor(editor, levelObjectPrefab.SpriteDeformations, levelObjectPrefab.Name); deformEditor.GetChild <GUIDropDown>().OnSelected += (selected, userdata) => { CreateLevelObjectEditor(selectedLevelObject); return(true); }; editor.AddCustomContent(deformEditor, editor.ContentCount); } //child object editing new GUITextBlock(new RectTransform(new Point(editor.Rect.Width, 40), editorContainer.Content.RectTransform), TextManager.Get("leveleditor.childobjects"), font: GUI.SubHeadingFont, textAlignment: Alignment.BottomCenter); foreach (LevelObjectPrefab.ChildObject childObj in levelObjectPrefab.ChildObjects) { var childObjFrame = new GUIFrame(new RectTransform(new Point(editor.Rect.Width, 30))); var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), childObjFrame.RectTransform, Anchor.Center), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; var selectedChildObj = childObj; var dropdown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1.0f), paddedFrame.RectTransform), elementCount: 10, selectMultiple: true); foreach (LevelObjectPrefab objPrefab in LevelObjectPrefab.List) { dropdown.AddItem(objPrefab.Name, objPrefab); if (childObj.AllowedNames.Contains(objPrefab.Name)) { dropdown.SelectItem(objPrefab); } } dropdown.OnSelected = (selected, obj) => { childObj.AllowedNames = dropdown.SelectedDataMultiple.Select(d => ((LevelObjectPrefab)d).Name).ToList(); return(true); }; new GUINumberInput(new RectTransform(new Vector2(0.2f, 1.0f), paddedFrame.RectTransform), GUINumberInput.NumberType.Int) { MinValueInt = 0, MaxValueInt = 10, OnValueChanged = (numberInput) => { selectedChildObj.MinCount = numberInput.IntValue; selectedChildObj.MaxCount = Math.Max(selectedChildObj.MaxCount, selectedChildObj.MinCount); } }.IntValue = childObj.MinCount; new GUINumberInput(new RectTransform(new Vector2(0.2f, 1.0f), paddedFrame.RectTransform), GUINumberInput.NumberType.Int) { MinValueInt = 0, MaxValueInt = 10, OnValueChanged = (numberInput) => { selectedChildObj.MaxCount = numberInput.IntValue; selectedChildObj.MinCount = Math.Min(selectedChildObj.MaxCount, selectedChildObj.MinCount); } }.IntValue = childObj.MaxCount; new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), paddedFrame.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "GUICancelButton") { OnClicked = (btn, userdata) => { selectedLevelObject.ChildObjects.Remove(selectedChildObj); CreateLevelObjectEditor(selectedLevelObject); return(true); } }; childObjFrame.RectTransform.Parent = editorContainer.Content.RectTransform; } var buttonContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), editorContainer.Content.RectTransform), style: null); new GUIButton(new RectTransform(new Point(editor.Rect.Width / 2, 20), buttonContainer.RectTransform, Anchor.Center), TextManager.Get("leveleditor.addchildobject")) { OnClicked = (btn, userdata) => { selectedLevelObject.ChildObjects.Add(new LevelObjectPrefab.ChildObject()); CreateLevelObjectEditor(selectedLevelObject); return(true); } }; buttonContainer.RectTransform.MinSize = buttonContainer.RectTransform.Children.First().MinSize; //light editing new GUITextBlock(new RectTransform(new Point(editor.Rect.Width, 40), editorContainer.Content.RectTransform), TextManager.Get("leveleditor.lightsources"), textAlignment: Alignment.BottomCenter, font: GUI.SubHeadingFont); foreach (LightSourceParams lightSourceParams in selectedLevelObject.LightSourceParams) { new SerializableEntityEditor(editorContainer.Content.RectTransform, lightSourceParams, inGame: false, showName: true); } buttonContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), editorContainer.Content.RectTransform), style: null); new GUIButton(new RectTransform(new Point(editor.Rect.Width / 2, 20), buttonContainer.RectTransform, Anchor.Center), TextManager.Get("leveleditor.addlightsource")) { OnClicked = (btn, userdata) => { selectedLevelObject.LightSourceTriggerIndex.Add(-1); selectedLevelObject.LightSourceParams.Add(new LightSourceParams(100.0f, Color.White)); CreateLevelObjectEditor(selectedLevelObject); return(true); } }; buttonContainer.RectTransform.MinSize = buttonContainer.RectTransform.Children.First().MinSize; }
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 GUIComponent CreateEditingHUD(bool inGame = false) { int width = 500; int height = spawnType == SpawnType.Path ? 80 : 200; int x = GameMain.GraphicsWidth / 2 - width / 2, y = 30; editingHUD = new GUIFrame(new RectTransform(new Point(width, height), GUI.Canvas) { ScreenSpaceOffset = new Point(x, y) }) { UserData = this }; var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), editingHUD.RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.05f }; if (spawnType == SpawnType.Path) { new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get("Editing") + " " + TextManager.Get("Waypoint")); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get("LinkWaypoint")); } else { new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get("Editing") + " " + TextManager.Get("Spawnpoint")); var spawnTypeContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), spawnTypeContainer.RectTransform), TextManager.Get("SpawnType")); var button = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), spawnTypeContainer.RectTransform), "-") { UserData = -1, OnClicked = ChangeSpawnType }; new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), spawnTypeContainer.RectTransform), spawnType.ToString(), textAlignment: Alignment.Center) { UserData = "spawntypetext" }; button = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), spawnTypeContainer.RectTransform), "+") { UserData = 1, OnClicked = ChangeSpawnType }; var descText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get("IDCardDescription"), font: GUI.SmallFont); GUITextBox propertyBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), descText.RectTransform, Anchor.CenterRight), idCardDesc) { MaxTextLength = 150, OnEnterPressed = EnterIDCardDesc, ToolTip = TextManager.Get("IDCardDescriptionTooltip") }; propertyBox.OnTextChanged += TextBoxChanged; var tagsText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get("IDCardTags"), font: GUI.SmallFont); propertyBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), tagsText.RectTransform, Anchor.CenterRight), string.Join(", ", idCardTags)) { MaxTextLength = 60, OnEnterPressed = EnterIDCardTags, ToolTip = TextManager.Get("IDCardTagsTooltip") }; propertyBox.OnTextChanged += TextBoxChanged; var jobsText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get("SpawnpointJobs"), font: GUI.SmallFont) { ToolTip = TextManager.Get("SpawnpointJobsTooltip") }; var jobDropDown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1.0f), jobsText.RectTransform, Anchor.CenterRight)) { ToolTip = TextManager.Get("SpawnpointJobsTooltip"), OnSelected = (selected, userdata) => { assignedJob = userdata as JobPrefab; return(true); } }; jobDropDown.AddItem(TextManager.Get("Any"), null); foreach (JobPrefab jobPrefab in JobPrefab.List) { jobDropDown.AddItem(jobPrefab.Name, jobPrefab); } jobDropDown.SelectItem(assignedJob); } PositionEditingHUD(); return(editingHUD); }
private void CreateFirstPage(GUILayoutGroup firstPageLayout, IEnumerable <SubmarineInfo> submarines) { firstPageLayout.RelativeSpacing = 0.02f; var columnContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.9f), firstPageLayout.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.02f }; var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform)) { Stretch = true, RelativeSpacing = 0.015f }; var rightColumn = new GUILayoutGroup(new RectTransform(new Vector2(1.5f, 1.0f), columnContainer.RectTransform)) { Stretch = true, RelativeSpacing = 0.015f }; columnContainer.Recalculate(); // New game left side new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, TextManager.Get("SaveName"), font: GUI.SubHeadingFont); saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, string.Empty) { textFilterFunction = (string str) => { return(ToolBox.RemoveInvalidFileNameChars(str)); } }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, TextManager.Get("MapSeed"), font: GUI.SubHeadingFont); seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, ToolBox.RandomSeed(8)); new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, TextManager.Get("SelectedSub"), font: GUI.SubHeadingFont); var moddedDropdown = new GUIDropDown(new RectTransform(new Vector2(1f, 0.02f), leftColumn.RectTransform), "", 3); moddedDropdown.AddItem(TextManager.Get("clientpermission.all"), CategoryFilter.All); moddedDropdown.AddItem(TextManager.Get("servertag.modded.false"), CategoryFilter.Vanilla); moddedDropdown.AddItem(TextManager.Get("customrank"), CategoryFilter.Custom); moddedDropdown.Select(0); var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), isHorizontal: true) { Stretch = true }; subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform)) { ScrollBarVisible = true }; var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font); var searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform, Anchor.CenterRight), font: GUI.Font, createClearButton: true); filterContainer.RectTransform.MinSize = searchBox.RectTransform.MinSize; searchBox.OnSelected += (sender, userdata) => { searchTitle.Visible = false; }; searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; }; searchBox.OnTextChanged += (textBox, text) => { FilterSubs(subList, text); return(true); }; moddedDropdown.OnSelected = (component, data) => { searchBox.Text = string.Empty; subFilter = (CategoryFilter)data; UpdateSubList(SubmarineInfo.SavedSubmarines); return(true); }; subList.OnSelected = OnSubSelected; // New game right side subPreviewContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), rightColumn.RectTransform)) { Stretch = true }; var firstPageButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.08f), firstPageLayout.RectTransform), childAnchor: Anchor.BottomLeft, isHorizontal: true) { RelativeSpacing = 0.025f }; InitialMoneyText = new GUITextBlock(new RectTransform(new Vector2(0.3f, 1f), firstPageButtonContainer.RectTransform), "", font: GUI.Style.Font, textColor: GUI.Style.Green, textAlignment: Alignment.CenterLeft) { TextGetter = () => { int initialMoney = CampaignMode.InitialMoney; if (subList.SelectedData is SubmarineInfo subInfo) { initialMoney -= subInfo.Price; } initialMoney = Math.Max(initialMoney, 0); return(TextManager.GetWithVariable("campaignstartingmoney", "[money]", string.Format(CultureInfo.InvariantCulture, "{0:N0}", initialMoney))); } }; CampaignCustomizeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1f), firstPageButtonContainer.RectTransform, Anchor.CenterLeft), TextManager.Get("SettingsButton")) { OnClicked = (tb, userdata) => { CreateCustomizeWindow(); return(true); } }; nextButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1f), firstPageButtonContainer.RectTransform, Anchor.BottomRight), TextManager.Get("Next")) { OnClicked = (GUIButton btn, object userData) => { SetPage(1); return(false); } }; var disclaimerBtn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.8f), rightColumn.RectTransform, Anchor.TopRight) { AbsoluteOffset = new Point(5) }, style: "GUINotificationButton") { IgnoreLayoutGroups = true, OnClicked = (btn, userdata) => { GameMain.Instance.ShowCampaignDisclaimer(); return(true); } }; disclaimerBtn.RectTransform.MaxSize = new Point((int)(30 * GUI.Scale)); columnContainer.Recalculate(); leftColumn.Recalculate(); rightColumn.Recalculate(); if (submarines != null) { UpdateSubList(submarines); } }
private void CreateUI() { if (parentComponent.FindChild(c => c.UserData as string == "glow") is GUIComponent glowChild) { parentComponent.RemoveChild(glowChild); } if (parentComponent.FindChild(c => c.UserData as string == "container") is GUIComponent containerChild) { parentComponent.RemoveChild(containerChild); } new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), parentComponent.RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { UserData = "glow" }; new GUIFrame(new RectTransform(new Vector2(0.95f), parentComponent.RectTransform, anchor: Anchor.Center), style: null) { CanBeFocused = false, UserData = "container" }; var availableMainGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 1.0f), campaignUI.GetTabContainer(CampaignMode.InteractionType.Crew).RectTransform) { MaxSize = new Point(560, campaignUI.GetTabContainer(CampaignMode.InteractionType.Crew).Rect.Height) }) { Stretch = true, RelativeSpacing = 0.02f }; // Header ------------------------------------------------ var headerGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.75f / 14.0f), availableMainGroup.RectTransform), isHorizontal: true) { RelativeSpacing = 0.005f }; var imageWidth = (float)headerGroup.Rect.Height / headerGroup.Rect.Width; new GUIImage(new RectTransform(new Vector2(imageWidth, 1.0f), headerGroup.RectTransform), "CrewManagementHeaderIcon"); new GUITextBlock(new RectTransform(new Vector2(1.0f - imageWidth, 1.0f), headerGroup.RectTransform), TextManager.Get("campaigncrew.header"), font: GUI.LargeFont) { CanBeFocused = false, ForceUpperCase = true }; var hireablesGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), anchor: Anchor.Center, parent: new GUIFrame(new RectTransform(new Vector2(1.0f, 13.25f / 14.0f), availableMainGroup.RectTransform)).RectTransform)) { RelativeSpacing = 0.015f, Stretch = true }; var sortGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.04f), hireablesGroup.RectTransform), isHorizontal: true) { RelativeSpacing = 0.015f }; new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sortGroup.RectTransform), text: TextManager.Get("campaignstore.sortby")); sortingDropDown = new GUIDropDown(new RectTransform(new Vector2(0.4f, 1.0f), sortGroup.RectTransform), elementCount: 5) { OnSelected = (child, userData) => { SortCharacters(hireableList, (SortingMethod)userData); return(true); } }; var tag = "sortingmethod."; sortingDropDown.AddItem(TextManager.Get(tag + SortingMethod.JobAsc), userData: SortingMethod.JobAsc); sortingDropDown.AddItem(TextManager.Get(tag + SortingMethod.SkillAsc), userData: SortingMethod.SkillAsc); sortingDropDown.AddItem(TextManager.Get(tag + SortingMethod.SkillDesc), userData: SortingMethod.SkillDesc); sortingDropDown.AddItem(TextManager.Get(tag + SortingMethod.PriceAsc), userData: SortingMethod.PriceAsc); sortingDropDown.AddItem(TextManager.Get(tag + SortingMethod.PriceDesc), userData: SortingMethod.PriceDesc); hireableList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.96f), hireablesGroup.RectTransform, anchor: Anchor.Center)) { Spacing = 1 }; var pendingAndCrewMainGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 1.0f), campaignUI.GetTabContainer(CampaignMode.InteractionType.Crew).RectTransform, anchor: Anchor.TopRight) { MaxSize = new Point(560, campaignUI.GetTabContainer(CampaignMode.InteractionType.Crew).Rect.Height) }) { Stretch = true, RelativeSpacing = 0.02f }; var playerBalanceContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.75f / 14.0f), pendingAndCrewMainGroup.RectTransform), childAnchor: Anchor.TopRight) { RelativeSpacing = 0.005f }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), playerBalanceContainer.RectTransform), TextManager.Get("campaignstore.balance"), font: GUI.Font, textAlignment: Alignment.BottomRight) { AutoScaleVertical = true, ForceUpperCase = true }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), playerBalanceContainer.RectTransform), "", font: GUI.SubHeadingFont, textAlignment: Alignment.TopRight) { AutoScaleVertical = true, TextScale = 1.1f, TextGetter = () => FormatCurrency(campaign.Money) }; var pendingAndCrewGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), anchor: Anchor.Center, parent: new GUIFrame(new RectTransform(new Vector2(1.0f, 13.25f / 14.0f), pendingAndCrewMainGroup.RectTransform) { MaxSize = new Point(560, campaignUI.GetTabContainer(CampaignMode.InteractionType.Crew).Rect.Height) }).RectTransform)); float height = 0.05f; new GUITextBlock(new RectTransform(new Vector2(1.0f, height), pendingAndCrewGroup.RectTransform), TextManager.Get("campaigncrew.pending"), font: GUI.SubHeadingFont); pendingList = new GUIListBox(new RectTransform(new Vector2(1.0f, 8 * height), pendingAndCrewGroup.RectTransform)) { Spacing = 1 }; new GUITextBlock(new RectTransform(new Vector2(1.0f, height), pendingAndCrewGroup.RectTransform), TextManager.Get("campaignmenucrew"), font: GUI.SubHeadingFont); crewList = new GUIListBox(new RectTransform(new Vector2(1.0f, (8) * height), pendingAndCrewGroup.RectTransform)) { Spacing = 1 }; var group = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, height), pendingAndCrewGroup.RectTransform), isHorizontal: true); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), group.RectTransform), TextManager.Get("campaignstore.total")); totalBlock = new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), group.RectTransform), "", font: GUI.SubHeadingFont, textAlignment: Alignment.Right) { TextScale = 1.1f }; group = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, height), pendingAndCrewGroup.RectTransform), isHorizontal: true, childAnchor: Anchor.TopRight) { RelativeSpacing = 0.01f }; validateHiresButton = new GUIButton(new RectTransform(new Vector2(1.0f / 3.0f, 1.0f), group.RectTransform), text: TextManager.Get("campaigncrew.validate")) { ClickSound = GUISoundType.HireRepairClick, ForceUpperCase = true, OnClicked = (b, o) => ValidatePendingHires(true) }; clearAllButton = new GUIButton(new RectTransform(new Vector2(1.0f / 3.0f, 1.0f), group.RectTransform), text: TextManager.Get("campaignstore.clearall")) { ForceUpperCase = true, Enabled = HasPermission, OnClicked = (b, o) => RemoveAllPendingHires() }; resolutionWhenCreated = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight); }
public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable <SubmarineInfo> submarines, IEnumerable <string> saveFiles = null) { this.isMultiplayer = isMultiplayer; this.newGameContainer = newGameContainer; this.loadGameContainer = loadGameContainer; var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = isMultiplayer ? 0.0f : 0.02f }; var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform)) { Stretch = true, RelativeSpacing = 0.015f }; var rightColumn = new GUILayoutGroup(new RectTransform(isMultiplayer ? Vector2.Zero : new Vector2(1.5f, 1.0f), columnContainer.RectTransform)) { Stretch = true, RelativeSpacing = 0.015f }; columnContainer.Recalculate(); // New game left side new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, TextManager.Get("SaveName"), font: GUI.SubHeadingFont); saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, string.Empty) { textFilterFunction = (string str) => { return(ToolBox.RemoveInvalidFileNameChars(str)); } }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, TextManager.Get("MapSeed"), font: GUI.SubHeadingFont); seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, ToolBox.RandomSeed(8)); if (!isMultiplayer) { new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform) { MinSize = new Point(0, 20) }, TextManager.Get("SelectedSub"), font: GUI.SubHeadingFont); var moddedDropdown = new GUIDropDown(new RectTransform(new Vector2(1f, 0.02f), leftColumn.RectTransform), "", 3); moddedDropdown.AddItem(TextManager.Get("clientpermission.all"), CategoryFilter.All); moddedDropdown.AddItem(TextManager.Get("servertag.modded.false"), CategoryFilter.Vanilla); moddedDropdown.AddItem(TextManager.Get("customrank"), CategoryFilter.Custom); moddedDropdown.Select(0); var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), isHorizontal: true) { Stretch = true }; subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform)) { ScrollBarVisible = true }; var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font); var searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform, Anchor.CenterRight), font: GUI.Font, createClearButton: true); filterContainer.RectTransform.MinSize = searchBox.RectTransform.MinSize; searchBox.OnSelected += (sender, userdata) => { searchTitle.Visible = false; }; searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; }; searchBox.OnTextChanged += (textBox, text) => { FilterSubs(subList, text); return(true); }; moddedDropdown.OnSelected = (component, data) => { searchBox.Text = string.Empty; subFilter = (CategoryFilter)data; UpdateSubList(SubmarineInfo.SavedSubmarines); return(true); }; subList.OnSelected = OnSubSelected; } else // Spacing to fix the multiplayer campaign setup layout { CreateMultiplayerCampaignSubList(leftColumn.RectTransform); //spacing //new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), leftColumn.RectTransform), style: null); } // New game right side subPreviewContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), rightColumn.RectTransform)) { Stretch = true }; var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.12f), (isMultiplayer ? leftColumn : rightColumn).RectTransform) { MaxSize = new Point(int.MaxValue, 60) }, childAnchor: Anchor.BottomRight, isHorizontal: true); if (!isMultiplayer) { buttonContainer.IgnoreLayoutGroups = true; } StartButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1f), buttonContainer.RectTransform, Anchor.BottomRight) { MaxSize = new Point(350, 60) }, TextManager.Get("StartCampaignButton")) { OnClicked = (GUIButton btn, object userData) => { if (string.IsNullOrWhiteSpace(saveNameBox.Text)) { saveNameBox.Flash(GUI.Style.Red); return(false); } SubmarineInfo selectedSub = null; if (!isMultiplayer) { if (!(subList.SelectedData is SubmarineInfo)) { return(false); } selectedSub = subList.SelectedData as SubmarineInfo; } else { if (GameMain.NetLobbyScreen.SelectedSub == null) { return(false); } selectedSub = GameMain.NetLobbyScreen.SelectedSub; } if (selectedSub.SubmarineClass == SubmarineClass.Undefined) { new GUIMessageBox(TextManager.Get("error"), TextManager.Get("undefinedsubmarineselected")); return(false); } if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash)) { ((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f; subList.SelectedComponent.CanBeFocused = false; subList.Deselect(); return(false); } string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text); bool hasRequiredContentPackages = selectedSub.RequiredContentPackagesInstalled; if (selectedSub.HasTag(SubmarineTag.Shuttle) || !hasRequiredContentPackages) { if (!hasRequiredContentPackages) { var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"), TextManager.GetWithVariable("ContentPackageMismatchWarning", "[requiredcontentpackages]", string.Join(", ", selectedSub.RequiredContentPackages)), new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); msgBox.Buttons[0].OnClicked = msgBox.Close; msgBox.Buttons[0].OnClicked += (button, obj) => { if (GUIMessageBox.MessageBoxes.Count == 0) { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); if (isMultiplayer) { CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup"); } } return(true); }; msgBox.Buttons[1].OnClicked = msgBox.Close; } if (selectedSub.HasTag(SubmarineTag.Shuttle)) { var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"), TextManager.Get("ShuttleWarning"), new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); msgBox.Buttons[0].OnClicked = (button, obj) => { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); if (isMultiplayer) { CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup"); } return(true); }; msgBox.Buttons[0].OnClicked += msgBox.Close; msgBox.Buttons[1].OnClicked = msgBox.Close; return(false); } } else { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); if (isMultiplayer) { CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup"); } } return(true); } }; InitialMoneyText = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1f), buttonContainer.RectTransform), "", font: isMultiplayer ? GUI.Style.SmallFont : GUI.Style.Font, textColor: GUI.Style.Green) { TextGetter = () => { int initialMoney = CampaignMode.InitialMoney; if (isMultiplayer) { if (GameMain.NetLobbyScreen.SelectedSub != null) { initialMoney -= GameMain.NetLobbyScreen.SelectedSub.Price; } } else if (subList.SelectedData is SubmarineInfo subInfo) { initialMoney -= subInfo.Price; } initialMoney = Math.Max(initialMoney, isMultiplayer ? MultiPlayerCampaign.MinimumInitialMoney : 0); return(TextManager.GetWithVariable("campaignstartingmoney", "[money]", string.Format(CultureInfo.InvariantCulture, "{0:N0}", initialMoney))); } }; if (!isMultiplayer) { var disclaimerBtn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.8f), rightColumn.RectTransform, Anchor.TopRight) { AbsoluteOffset = new Point(5) }, style: "GUINotificationButton") { IgnoreLayoutGroups = true, OnClicked = (btn, userdata) => { GameMain.Instance.ShowCampaignDisclaimer(); return(true); } }; disclaimerBtn.RectTransform.MaxSize = new Point((int)(30 * GUI.Scale)); } columnContainer.Recalculate(); leftColumn.Recalculate(); rightColumn.Recalculate(); if (submarines != null) { UpdateSubList(submarines); } UpdateLoadMenu(saveFiles); }
public LevelEditorScreen() { cam = new Camera() { MinZoom = 0.01f, MaxZoom = 1.0f }; leftPanel = new GUIFrame(new RectTransform(new Vector2(0.125f, 0.8f), Frame.RectTransform) { MinSize = new Point(150, 0) }); 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, RelativeSpacing = 0.01f }; paramsList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.3f), paddedLeftPanel.RectTransform)); paramsList.OnSelected += (GUIComponent component, object obj) => { selectedParams = obj as LevelGenerationParams; editorContainer.ClearChildren(); SortLevelObjectsList(selectedParams); new SerializableEntityEditor(editorContainer.Content.RectTransform, selectedParams, false, true, elementHeight: 20); return(true); }; var ruinTitle = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.ruinparams"), font: GUI.SubHeadingFont); ruinParamsList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.1f), paddedLeftPanel.RectTransform)); ruinParamsList.OnSelected += (GUIComponent component, object obj) => { var ruinGenerationParams = obj as RuinGenerationParams; editorContainer.ClearChildren(); new SerializableEntityEditor(editorContainer.Content.RectTransform, ruinGenerationParams, false, true, elementHeight: 20); return(true); }; var outpostTitle = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.outpostparams"), font: GUI.SubHeadingFont); GUITextBlock.AutoScaleAndNormalize(ruinTitle, outpostTitle); outpostParamsList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.2f), paddedLeftPanel.RectTransform)); outpostParamsList.OnSelected += (GUIComponent component, object obj) => { var outpostGenerationParams = obj as OutpostGenerationParams; editorContainer.ClearChildren(); var outpostParamsEditor = new SerializableEntityEditor(editorContainer.Content.RectTransform, outpostGenerationParams, false, true, elementHeight: 20); // location type ------------------------- var locationTypeGroup = new GUILayoutGroup(new RectTransform(new Point(editorContainer.Content.Rect.Width, 20)), isHorizontal: true, childAnchor: Anchor.CenterLeft) { Stretch = true }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), locationTypeGroup.RectTransform), TextManager.Get("outpostmoduleallowedlocationtypes"), textAlignment: Alignment.CenterLeft); HashSet <string> availableLocationTypes = new HashSet <string> { "any" }; foreach (LocationType locationType in LocationType.List) { availableLocationTypes.Add(locationType.Identifier); } var locationTypeDropDown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1f), locationTypeGroup.RectTransform), text: string.Join(", ", outpostGenerationParams.AllowedLocationTypes.Select(lt => TextManager.Capitalize(lt)) ?? "any".ToEnumerable()), selectMultiple: true); foreach (string locationType in availableLocationTypes) { locationTypeDropDown.AddItem(TextManager.Capitalize(locationType), locationType); if (outpostGenerationParams.AllowedLocationTypes.Contains(locationType)) { locationTypeDropDown.SelectItem(locationType); } } if (!outpostGenerationParams.AllowedLocationTypes.Any()) { locationTypeDropDown.SelectItem("any"); } locationTypeDropDown.OnSelected += (_, __) => { outpostGenerationParams.SetAllowedLocationTypes(locationTypeDropDown.SelectedDataMultiple.Cast <string>()); locationTypeDropDown.Text = ToolBox.LimitString(locationTypeDropDown.Text, locationTypeDropDown.Font, locationTypeDropDown.Rect.Width); return(true); }; locationTypeGroup.RectTransform.MinSize = new Point(locationTypeGroup.Rect.Width, locationTypeGroup.RectTransform.Children.Max(c => c.MinSize.Y)); outpostParamsEditor.AddCustomContent(locationTypeGroup, 100); // module count ------------------------- var moduleLabel = new GUITextBlock(new RectTransform(new Point(editorContainer.Content.Rect.Width, (int)(70 * GUI.Scale))), TextManager.Get("submarinetype.outpostmodules"), font: GUI.SubHeadingFont); outpostParamsEditor.AddCustomContent(moduleLabel, 100); foreach (KeyValuePair <string, int> moduleCount in outpostGenerationParams.ModuleCounts) { var moduleCountGroup = new GUILayoutGroup(new RectTransform(new Point(editorContainer.Content.Rect.Width, (int)(25 * GUI.Scale))), isHorizontal: true, childAnchor: Anchor.CenterLeft); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), moduleCountGroup.RectTransform), TextManager.Capitalize(moduleCount.Key), textAlignment: Alignment.CenterLeft); new GUINumberInput(new RectTransform(new Vector2(0.5f, 1f), moduleCountGroup.RectTransform), GUINumberInput.NumberType.Int) { MinValueInt = 0, MaxValueInt = 100, IntValue = moduleCount.Value, OnValueChanged = (numInput) => { outpostGenerationParams.SetModuleCount(moduleCount.Key, numInput.IntValue); if (numInput.IntValue == 0) { outpostParamsList.Select(outpostParamsList.SelectedData); } } }; moduleCountGroup.RectTransform.MinSize = new Point(moduleCountGroup.Rect.Width, moduleCountGroup.RectTransform.Children.Max(c => c.MinSize.Y)); outpostParamsEditor.AddCustomContent(moduleCountGroup, 100); } // add module count ------------------------- var addModuleCountGroup = new GUILayoutGroup(new RectTransform(new Point(editorContainer.Content.Rect.Width, (int)(40 * GUI.Scale))), isHorizontal: true, childAnchor: Anchor.Center); HashSet <string> availableFlags = new HashSet <string>(); foreach (string flag in OutpostGenerationParams.Params.SelectMany(p => p.ModuleCounts.Select(m => m.Key))) { availableFlags.Add(flag); } foreach (var sub in SubmarineInfo.SavedSubmarines) { if (sub.OutpostModuleInfo == null) { continue; } foreach (string flag in sub.OutpostModuleInfo.ModuleFlags) { availableFlags.Add(flag); } } var moduleTypeDropDown = new GUIDropDown(new RectTransform(new Vector2(0.8f, 0.8f), addModuleCountGroup.RectTransform), text: TextManager.Get("leveleditor.addmoduletype")); foreach (string flag in availableFlags) { if (outpostGenerationParams.ModuleCounts.Any(mc => mc.Key.Equals(flag, StringComparison.OrdinalIgnoreCase))) { continue; } moduleTypeDropDown.AddItem(TextManager.Capitalize(flag), flag); } moduleTypeDropDown.OnSelected += (_, userdata) => { outpostGenerationParams.SetModuleCount(userdata as string, 1); outpostParamsList.Select(outpostParamsList.SelectedData); return(true); }; addModuleCountGroup.RectTransform.MinSize = new Point(addModuleCountGroup.Rect.Width, addModuleCountGroup.RectTransform.Children.Max(c => c.MinSize.Y)); outpostParamsEditor.AddCustomContent(addModuleCountGroup, 100); return(true); }; var createLevelObjButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.createlevelobj")) { OnClicked = (btn, obj) => { Wizard.Instance.Create(); return(true); } }; GUITextBlock.AutoScaleAndNormalize(createLevelObjButton.TextBlock); lightingEnabled = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.025f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.lightingenabled")); cursorLightEnabled = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.025f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.cursorlightenabled")); new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.reloadtextures")) { OnClicked = (btn, obj) => { Level.Loaded?.ReloadTextures(); return(true); } }; new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedLeftPanel.RectTransform), TextManager.Get("editor.saveall")) { OnClicked = (btn, obj) => { SerializeAll(); return(true); } }; rightPanel = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), Frame.RectTransform, Anchor.TopRight) { MinSize = new Point(450, 0) }); 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 }; editorContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), paddedRightPanel.RectTransform)); var seedContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), paddedRightPanel.RectTransform), isHorizontal: true); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), seedContainer.RectTransform), TextManager.Get("leveleditor.levelseed")); seedBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), seedContainer.RectTransform), ToolBox.RandomSeed(8)); new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedRightPanel.RectTransform), TextManager.Get("leveleditor.generate")) { OnClicked = (btn, obj) => { Submarine.Unload(); GameMain.LightManager.ClearLights(); LevelData levelData = LevelData.CreateRandom(seedBox.Text, generationParams: selectedParams); levelData.ForceOutpostGenerationParams = outpostParamsList.SelectedData as OutpostGenerationParams; Level.Generate(levelData, mirror: false); GameMain.LightManager.AddLight(pointerLightSource); cam.Position = new Vector2(Level.Loaded.Size.X / 2, Level.Loaded.Size.Y / 2); foreach (GUITextBlock param in paramsList.Content.Children) { param.TextColor = param.UserData == selectedParams ? GUI.Style.Green : param.Style.TextColor; } seedBox.Deselect(); return(true); } }; new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedRightPanel.RectTransform), TextManager.Get("leveleditor.test")) { OnClicked = (btn, obj) => { if (Level.Loaded?.LevelData == null) { return(false); } GameMain.GameScreen.Select(); var currEntities = Entity.GetEntities().ToList(); if (Submarine.MainSub != null) { var toRemove = Entity.GetEntities().Where(e => e.Submarine == Submarine.MainSub).ToList(); foreach (Entity ent in toRemove) { ent.Remove(); } Submarine.MainSub.Remove(); } //TODO: hacky workaround to check for wrecks and outposts, refactor SubmarineInfo and ContentType at some point var nonPlayerFiles = ContentPackage.GetFilesOfType(GameMain.Config.AllEnabledPackages, ContentType.Wreck).ToList(); nonPlayerFiles.AddRange(ContentPackage.GetFilesOfType(GameMain.Config.AllEnabledPackages, ContentType.Outpost)); nonPlayerFiles.AddRange(ContentPackage.GetFilesOfType(GameMain.Config.AllEnabledPackages, ContentType.OutpostModule)); SubmarineInfo subInfo = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name.Equals(GameMain.Config.QuickStartSubmarineName, StringComparison.InvariantCultureIgnoreCase)); subInfo ??= SubmarineInfo.SavedSubmarines.GetRandom(s => s.IsPlayer && !s.HasTag(SubmarineTag.Shuttle) && !nonPlayerFiles.Any(f => f.Path.CleanUpPath().Equals(s.FilePath.CleanUpPath(), StringComparison.InvariantCultureIgnoreCase))); GameSession gameSession = new GameSession(subInfo, "", GameModePreset.TestMode, null); gameSession.StartRound(Level.Loaded.LevelData); (gameSession.GameMode as TestGameMode).OnRoundEnd = () => { GameMain.LevelEditorScreen.Select(); Submarine.MainSub.Remove(); var toRemove = Entity.GetEntities().Where(e => !currEntities.Contains(e)).ToList(); foreach (Entity ent in toRemove) { ent.Remove(); } Submarine.MainSub = null; }; GameMain.GameSession = gameSession; return(true); } }; bottomPanel = new GUIFrame(new RectTransform(new Vector2(0.75f, 0.22f), Frame.RectTransform, Anchor.BottomLeft) { MaxSize = new Point(GameMain.GraphicsWidth - rightPanel.Rect.Width, 1000) }, style: "GUIFrameBottom"); levelObjectList = new GUIListBox(new RectTransform(new Vector2(0.99f, 0.85f), bottomPanel.RectTransform, Anchor.Center)) { UseGridLayout = true }; levelObjectList.OnSelected += (GUIComponent component, object obj) => { selectedLevelObject = obj as LevelObjectPrefab; CreateLevelObjectEditor(selectedLevelObject); return(true); }; spriteEditDoneButton = new GUIButton(new RectTransform(new Point(200, 30), anchor: Anchor.BottomRight) { AbsoluteOffset = new Point(20, 20) }, TextManager.Get("leveleditor.spriteeditdone")) { OnClicked = (btn, userdata) => { editingSprite = null; return(true); } }; topPanel = new GUIFrame(new RectTransform(new Point(400, 100), GUI.Canvas) { RelativeOffset = new Vector2(leftPanel.RectTransform.RelativeSize.X * 2, 0.0f) }, style: "GUIFrameTop"); }
public EditMapScreen() { cam = new Camera(); //cam.Translate(new Vector2(-10.0f, 50.0f)); selectedTab = -1; topPanel = new GUIFrame(new Rectangle(0, 0, 0, 35), "GUIFrameTop"); topPanel.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); hullVolumeFrame = new GUIFrame(new Rectangle(145, 26, 280, 70), "", topPanel); hullVolumeFrame.Visible = false; hullVolumeFrame.Padding = new Vector4(3.0f, 3.0f, 3.0f, 3.0f); GUITextBlock totalHullVolume = new GUITextBlock(new Rectangle(0, 0, 0, 20), "", "", hullVolumeFrame, GUI.SmallFont); totalHullVolume.TextGetter = GetTotalHullVolume; GUITextBlock selectedHullVolume = new GUITextBlock(new Rectangle(0, 30, 0, 20), "", "", hullVolumeFrame, GUI.SmallFont); selectedHullVolume.TextGetter = GetSelectedHullVolume; var button = new GUIButton(new Rectangle(0, 0, 70, 20), "Open...", "", topPanel); button.OnClicked = (GUIButton btn, object data) => { saveFrame = null; selectedTab = -1; CreateLoadScreen(); return(true); }; button = new GUIButton(new Rectangle(80, 0, 70, 20), "Save", "", topPanel); button.OnClicked = (GUIButton btn, object data) => { loadFrame = null; selectedTab = -1; CreateSaveScreen(); return(true); }; var nameLabel = new GUITextBlock(new Rectangle(170, 0, 150, 20), "", "", Alignment.TopLeft, Alignment.CenterLeft, topPanel, false, GUI.LargeFont); nameLabel.TextGetter = GetSubName; linkedSubBox = new GUIDropDown(new Rectangle(750, 0, 200, 20), "Add submarine", "", topPanel); linkedSubBox.ToolTip = "Places another submarine into the current submarine file. " + "Can be used for adding things such as smaller vessels, " + "escape pods or detachable sections into the main submarine."; foreach (Submarine sub in Submarine.SavedSubmarines) { linkedSubBox.AddItem(sub.Name, sub); } linkedSubBox.OnSelected += SelectLinkedSub; leftPanel = new GUIFrame(new Rectangle(0, 0, 150, GameMain.GraphicsHeight), "GUIFrameLeft"); leftPanel.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); GUITextBlock itemCount = new GUITextBlock(new Rectangle(0, 30, 0, 20), "", "", leftPanel); itemCount.TextGetter = GetItemCount; GUITextBlock structureCount = new GUITextBlock(new Rectangle(0, 50, 0, 20), "", "", leftPanel); structureCount.TextGetter = GetStructureCount; GUItabs = new GUIComponent[Enum.GetValues(typeof(MapEntityCategory)).Length]; int width = 400, height = 400; int y = 90; int i = 0; foreach (MapEntityCategory category in Enum.GetValues(typeof(MapEntityCategory))) { var catButton = new GUIButton(new Rectangle(0, y, 0, 20), category.ToString(), Alignment.Left, "", leftPanel); catButton.UserData = i; catButton.OnClicked = SelectTab; y += 25; GUItabs[i] = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), ""); GUItabs[i].Padding = new Vector4(10.0f, 30.0f, 10.0f, 20.0f); new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", "", Alignment.TopRight, Alignment.CenterRight, GUItabs[i], false, GUI.SmallFont); GUITextBox searchBox = new GUITextBox(new Rectangle(-20, 0, 180, 15), null, null, Alignment.TopRight, Alignment.CenterLeft, "", GUItabs[i]); searchBox.Font = GUI.SmallFont; searchBox.OnTextChanged = FilterMessages; var clearButton = new GUIButton(new Rectangle(0, 0, 15, 15), "x", Alignment.TopRight, "", GUItabs[i]); clearButton.OnClicked = ClearFilter; clearButton.UserData = searchBox; GUIListBox itemList = new GUIListBox(new Rectangle(0, 20, 0, 0), Color.White * 0.7f, "", GUItabs[i]); itemList.OnSelected = SelectPrefab; itemList.CheckSelected = MapEntityPrefab.GetSelected; foreach (MapEntityPrefab ep in MapEntityPrefab.list) { if (!ep.Category.HasFlag(category)) { continue; } GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), Color.Transparent, "ListBoxElement", itemList); frame.UserData = ep; frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); GUITextBlock textBlock = new GUITextBlock( new Rectangle(40, 0, 0, 25), ep.Name, "", Alignment.Top, Alignment.CenterLeft, frame); textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f); if (!string.IsNullOrWhiteSpace(ep.Description)) { textBlock.ToolTip = ep.Description; } if (ep.sprite != null) { GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), ep.sprite, Alignment.CenterLeft, frame); img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f); img.Color = ep.SpriteColor; } } itemList.children.Sort((i1, i2) => (i1.UserData as MapEntityPrefab).Name.CompareTo((i2.UserData as MapEntityPrefab).Name)); i++; } y += 10; button = new GUIButton(new Rectangle(0, y, 0, 20), "Character mode", Alignment.Left, "", leftPanel); button.ToolTip = "Allows you to pick up and use items. Useful for things such as placing items inside closets, turning devices on/off and doing the wiring."; button.OnClicked = ToggleCharacterMode; y += 25; button = new GUIButton(new Rectangle(0, y, 0, 20), "Wiring mode", Alignment.Left, "", leftPanel); //button.ToolTip = "Allows you to pick up and use items. Useful for things such as placing items inside closets, turning devices on/off and doing the wiring."; button.OnClicked = ToggleWiringMode; y += 35; button = new GUIButton(new Rectangle(0, y, 0, 20), "Generate waypoints", Alignment.Left, "", leftPanel); button.ToolTip = "AI controlled crew members require waypoints to navigate around the sub."; button.OnClicked = GenerateWaypoints; y += 30; new GUITextBlock(new Rectangle(0, y, 0, 20), "Show:", "", leftPanel); var tickBox = new GUITickBox(new Rectangle(0, y + 20, 20, 20), "Waypoints", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { WayPoint.ShowWayPoints = !WayPoint.ShowWayPoints; return(true); }; tickBox.Selected = true; tickBox = new GUITickBox(new Rectangle(0, y + 45, 20, 20), "Spawnpoints", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { WayPoint.ShowSpawnPoints = !WayPoint.ShowSpawnPoints; return(true); }; tickBox.Selected = true; tickBox = new GUITickBox(new Rectangle(0, y + 70, 20, 20), "Links", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { Item.ShowLinks = !Item.ShowLinks; return(true); }; tickBox.Selected = true; tickBox = new GUITickBox(new Rectangle(0, y + 95, 20, 20), "Hulls", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { Hull.ShowHulls = !Hull.ShowHulls; return(true); }; tickBox.Selected = true; tickBox = new GUITickBox(new Rectangle(0, y + 120, 20, 20), "Gaps", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { Gap.ShowGaps = !Gap.ShowGaps; return(true); }; tickBox.Selected = true; y += 150; if (y < GameMain.GraphicsHeight - 100) { new GUITextBlock(new Rectangle(0, y, 0, 15), "Previously used:", "", leftPanel); previouslyUsedList = new GUIListBox(new Rectangle(0, y + 20, 0, Math.Min(GameMain.GraphicsHeight - y - 80, 150)), "", leftPanel); previouslyUsedList.OnSelected = SelectPrefab; } }
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); }
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 GUIComponent CreateEditingHUD(bool inGame = false) { List <ObjectProperty> editableProperties = inGame ? GetProperties <InGameEditable>() : GetProperties <Editable>(); int requiredItemCount = 0; if (!inGame) { foreach (ItemComponent ic in components) { requiredItemCount += ic.requiredItems.Count; } } int width = 450; int height = 80 + requiredItemCount * 20; int x = GameMain.GraphicsWidth / 2 - width / 2, y = 10; foreach (var objectProperty in editableProperties) { var editable = objectProperty.Attributes.OfType <Editable>().FirstOrDefault(); if (editable != null) { height += (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f) + 5; } } editingHUD = new GUIFrame(new Rectangle(x, y, width, height), ""); editingHUD.Padding = new Vector4(10, 10, 0, 0); editingHUD.UserData = this; new GUITextBlock(new Rectangle(0, 0, 100, 20), prefab.Name, "", Alignment.TopLeft, Alignment.TopLeft, editingHUD, false, GUI.LargeFont); y += 25; if (!inGame) { if (prefab.IsLinkable) { new GUITextBlock(new Rectangle(0, 5, 0, 20), "Hold space to link to another item", "", Alignment.TopRight, Alignment.TopRight, editingHUD).Font = GUI.SmallFont; } foreach (ItemComponent ic in components) { foreach (RelatedItem relatedItem in ic.requiredItems) { new GUITextBlock(new Rectangle(0, y, 100, 15), ic.Name + ": " + relatedItem.Type.ToString() + " required", "", Alignment.TopLeft, Alignment.CenterLeft, editingHUD, false, GUI.SmallFont); GUITextBox namesBox = new GUITextBox(new Rectangle(-10, y, 160, 15), Alignment.Right, "", editingHUD); namesBox.Font = GUI.SmallFont; PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(relatedItem); PropertyDescriptor property = properties.Find("JoinedNames", false); namesBox.Text = relatedItem.JoinedNames; namesBox.UserData = new ObjectProperty(property, relatedItem); namesBox.OnEnterPressed = EnterProperty; namesBox.OnTextChanged = PropertyChanged; y += 20; } } if (requiredItemCount > 0) { y += 10; } } foreach (var objectProperty in editableProperties) { int boxHeight = 18; var editable = objectProperty.Attributes.OfType <Editable>().FirstOrDefault(); if (editable != null) { boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f); } object value = objectProperty.GetValue(); if (value is bool) { GUITickBox propertyTickBox = new GUITickBox(new Rectangle(10, y, 18, boxHeight), objectProperty.Name, Alignment.Left, editingHUD); propertyTickBox.Font = GUI.SmallFont; propertyTickBox.Selected = (bool)value; propertyTickBox.UserData = objectProperty; propertyTickBox.OnSelected = EnterProperty; } else if (value.GetType().IsEnum) { new GUITextBlock(new Rectangle(0, y, 100, 18), objectProperty.Name, "", Alignment.TopLeft, Alignment.Left, editingHUD, false, GUI.SmallFont); GUIDropDown enumDropDown = new GUIDropDown(new Rectangle(180, y, 250, boxHeight), "", "", editingHUD); foreach (object enumValue in Enum.GetValues(value.GetType())) { var enumTextBlock = new GUITextBlock(new Rectangle(0, 0, 200, 25), enumValue.ToString(), "", enumDropDown); enumTextBlock.UserData = enumValue; } enumDropDown.OnSelected += (selected, val) => { objectProperty.TrySetValue(val); return(true); }; enumDropDown.SelectItem(value); } else { new GUITextBlock(new Rectangle(0, y, 100, 18), objectProperty.Name, "", Alignment.TopLeft, Alignment.Left, editingHUD, false, GUI.SmallFont); GUITextBox propertyBox = new GUITextBox(new Rectangle(180, y, 250, boxHeight), "", editingHUD); propertyBox.Font = GUI.SmallFont; if (boxHeight > 18) { propertyBox.Wrap = true; } if (value != null) { if (value is float) { propertyBox.Text = ((float)value).ToString("G", System.Globalization.CultureInfo.InvariantCulture); } else { propertyBox.Text = value.ToString(); } } propertyBox.UserData = objectProperty; propertyBox.OnEnterPressed = EnterProperty; propertyBox.OnTextChanged = PropertyChanged; } y = y + boxHeight + 5; } return(editingHUD); }
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; }
public static void Init() { backgroundFrame = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: null) { Color = Color.Black * 0.5f, HoverColor = Color.Black * 0.5f, SelectedColor = Color.Black * 0.5f, PressedColor = Color.Black * 0.5f, }; window = new GUIFrame(new RectTransform(Vector2.One * 0.8f, backgroundFrame.RectTransform, Anchor.Center)); var horizontalLayout = new GUILayoutGroup(new RectTransform(Vector2.One * 0.9f, window.RectTransform, Anchor.Center), true); sidebar = new GUIListBox(new RectTransform(new Vector2(0.29f, 1.0f), horizontalLayout.RectTransform)); var drives = DriveInfo.GetDrives(); foreach (var drive in drives) { if (drive.DriveType == DriveType.Ram) { continue; } if (ignoredDrivePrefixes.Any(p => drive.Name.StartsWith(p))) { continue; } new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), sidebar.Content.RectTransform), drive.Name.Replace('\\', '/')); } sidebar.OnSelected = (child, userdata) => { CurrentDirectory = (child as GUITextBlock).Text; return(false); }; //spacing between sidebar and fileListLayout new GUIFrame(new RectTransform(new Vector2(0.01f, 1.0f), horizontalLayout.RectTransform), style: null); var fileListLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.7f, 1.0f), horizontalLayout.RectTransform)); var firstRow = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.04f), fileListLayout.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft); new GUIButton(new RectTransform(new Vector2(0.05f, 1.0f), firstRow.RectTransform), "^") { OnClicked = MoveToParentDirectory }; directoryBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), firstRow.RectTransform)) { OverflowClip = true, OnEnterPressed = (tb, txt) => { if (Directory.Exists(txt)) { CurrentDirectory = txt; return(true); } else { tb.Text = CurrentDirectory; return(false); } } }; filterBox = new GUITextBox(new RectTransform(new Vector2(0.25f, 1.0f), firstRow.RectTransform)) { OverflowClip = true }; firstRow.RectTransform.MinSize = new Point(0, firstRow.RectTransform.Children.Max(c => c.MinSize.Y)); filterBox.OnTextChanged += (txtbox, txt) => { RefreshFileList(); return(true); }; //spacing between rows new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), fileListLayout.RectTransform), style: null); fileList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.85f), fileListLayout.RectTransform)) { OnSelected = (child, userdata) => { if (userdata == null) { return(false); } var fileName = (child as GUITextBlock).Text; fileBox.Text = fileName; if (PlayerInput.DoubleClicked()) { bool isDir = (userdata as bool?).Value; if (isDir) { CurrentDirectory += fileName; } else { OnFileSelected?.Invoke(CurrentDirectory + fileName); Open = false; } } return(true); } }; //spacing between rows new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), fileListLayout.RectTransform), style: null); var thirdRow = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.04f), fileListLayout.RectTransform), true); fileBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), thirdRow.RectTransform)) { OnEnterPressed = (tb, txt) => openButton?.OnClicked?.Invoke(openButton, null) ?? false }; fileTypeDropdown = new GUIDropDown(new RectTransform(new Vector2(0.3f, 1.0f), thirdRow.RectTransform), dropAbove: true) { OnSelected = (child, userdata) => { currentFileTypePattern = (child as GUITextBlock).UserData as string; RefreshFileList(); return(true); } }; fileTypeDropdown.Select(4); //spacing between rows new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), fileListLayout.RectTransform), style: null); var fourthRow = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.04f), fileListLayout.RectTransform), true); //padding for open/cancel buttons new GUIFrame(new RectTransform(new Vector2(0.7f, 1.0f), fourthRow.RectTransform), style: null); openButton = new GUIButton(new RectTransform(new Vector2(0.15f, 1.0f), fourthRow.RectTransform), TextManager.Get("opensubbutton")) { OnClicked = (btn, obj) => { if (Directory.Exists(Path.Combine(CurrentDirectory, fileBox.Text))) { CurrentDirectory += fileBox.Text; } if (!File.Exists(CurrentDirectory + fileBox.Text)) { return(false); } OnFileSelected?.Invoke(CurrentDirectory + fileBox.Text); Open = false; return(false); } }; new GUIButton(new RectTransform(new Vector2(0.15f, 1.0f), fourthRow.RectTransform), TextManager.Get("cancel")) { OnClicked = (btn, obj) => { Open = false; return(false); } }; CurrentDirectory = Directory.GetCurrentDirectory(); }