public LobbyGui(IEntityManager entityManager,
                 IClientPreferencesManager preferencesManager)
 {
     RobustXamlLoader.Load(this);
     ServerName.HorizontalExpand    = true;
     ServerName.HorizontalAlignment = HAlignment.Center;
 }
예제 #2
0
        public LobbyCharacterPreviewPanel(IEntityManager entityManager,
                                          IClientPreferencesManager preferencesManager)
        {
            _preferencesManager = preferencesManager;
            _previewDummy       = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace);

            var header = new NanoHeading
            {
                Text = Loc.GetString("Character setup")
            };

            CharacterSetupButton = new Button
            {
                Text = Loc.GetString("Customize"),
                SizeFlagsHorizontal = SizeFlags.None
            };

            _summaryLabel = new Label();

            var viewSouth = MakeSpriteView(_previewDummy, Direction.South);
            var viewNorth = MakeSpriteView(_previewDummy, Direction.North);
            var viewWest  = MakeSpriteView(_previewDummy, Direction.West);
            var viewEast  = MakeSpriteView(_previewDummy, Direction.East);

            var vBox = new VBoxContainer();

            vBox.AddChild(header);

            _unloaded = new Label {
                Text = "Your character preferences have not yet loaded, please stand by."
            };

            _loaded = new VBoxContainer {
                Visible = false
            };

            _loaded.AddChild(CharacterSetupButton);
            _loaded.AddChild(_summaryLabel);

            var hBox = new HBoxContainer();

            hBox.AddChild(viewSouth);
            hBox.AddChild(viewNorth);
            hBox.AddChild(viewWest);
            hBox.AddChild(viewEast);

            _loaded.AddChild(hBox);

            vBox.AddChild(_loaded);
            vBox.AddChild(_unloaded);
            AddChild(vBox);

            UpdateUI();

            _preferencesManager.OnServerDataLoaded += UpdateUI;
        }
        public LobbyCharacterPreviewPanel(IEntityManager entityManager,
                                          IClientPreferencesManager preferencesManager,
                                          IPrototypeManager prototypeManager)
        {
            _entMan             = entityManager;
            _preferencesManager = preferencesManager;
            _prototypeManager   = prototypeManager;

            var header = new NanoHeading
            {
                Text = Loc.GetString("lobby-character-preview-panel-header")
            };

            CharacterSetupButton = new Button
            {
                Text = Loc.GetString("lobby-character-preview-panel-character-setup-button"),
                HorizontalAlignment = HAlignment.Left
            };

            _summaryLabel = new Label();

            var vBox = new BoxContainer
            {
                Orientation = LayoutOrientation.Vertical
            };

            vBox.AddChild(header);

            _unloaded = new Label {
                Text = Loc.GetString("lobby-character-preview-panel-unloaded-preferences-label")
            };

            _loaded = new BoxContainer
            {
                Orientation = LayoutOrientation.Vertical,
                Visible     = false
            };

            _loaded.AddChild(CharacterSetupButton);
            _loaded.AddChild(_summaryLabel);

            _viewBox = new BoxContainer
            {
                Orientation = LayoutOrientation.Horizontal
            };

            _loaded.AddChild(_viewBox);

            vBox.AddChild(_loaded);
            vBox.AddChild(_unloaded);
            AddChild(vBox);

            UpdateUI();

            _preferencesManager.OnServerDataLoaded += UpdateUI;
        }
예제 #4
0
        public LobbyCharacterPreviewPanel(IEntityManager entityManager,
                                          IClientPreferencesManager preferencesManager)
        {
            _preferencesManager = preferencesManager;
            _previewDummy       = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace);

            var header = new NanoHeading
            {
                Text = Loc.GetString("lobby-character-preview-panel-header")
            };

            CharacterSetupButton = new Button
            {
                Text = Loc.GetString("lobby-character-preview-panel-character-setup-button"),
                HorizontalAlignment = HAlignment.Left
            };

            _summaryLabel = new Label();

            var viewSouth = MakeSpriteView(_previewDummy, Direction.South);
            var viewNorth = MakeSpriteView(_previewDummy, Direction.North);
            var viewWest  = MakeSpriteView(_previewDummy, Direction.West);
            var viewEast  = MakeSpriteView(_previewDummy, Direction.East);

            var vBox = new VBoxContainer();

            vBox.AddChild(header);

            _unloaded = new Label {
                Text = Loc.GetString("lobby-character-preview-panel-unloaded-preferences-label")
            };

            _loaded = new VBoxContainer {
                Visible = false
            };

            _loaded.AddChild(CharacterSetupButton);
            _loaded.AddChild(_summaryLabel);

            var hBox = new HBoxContainer();

            hBox.AddChild(viewSouth);
            hBox.AddChild(viewNorth);
            hBox.AddChild(viewWest);
            hBox.AddChild(viewEast);

            _loaded.AddChild(hBox);

            vBox.AddChild(_loaded);
            vBox.AddChild(_unloaded);
            AddChild(vBox);

            UpdateUI();

            _preferencesManager.OnServerDataLoaded += UpdateUI;
        }
예제 #5
0
        public LobbyGui(IEntityManager entityManager,
                        IClientPreferencesManager preferencesManager)
        {
            RobustXamlLoader.Load(this);

            ServerName.SizeFlagsHorizontal = SizeFlags.Expand | SizeFlags.ShrinkCenter;

            CharacterPreview = new LobbyCharacterPreviewPanel(
                entityManager,
                preferencesManager)
            {
                SizeFlagsHorizontal = SizeFlags.None
            };

            CLeftPanelContainer.AddChild(CharacterPreview);
            CharacterPreview.SetPositionFirst();
        }
        public LobbyCharacterPreviewPanel(IEntityManager entityManager,
                                          ILocalizationManager localization,
                                          IClientPreferencesManager preferencesManager)
        {
            _preferencesManager = preferencesManager;
            _previewDummy       = entityManager.SpawnEntityAt("HumanMob_Dummy", MapCoordinates.Nullspace);

            var header = new NanoHeading
            {
                Text = localization.GetString("Character setup")
            };

            CharacterSetupButton = new Button
            {
                Text = localization.GetString("Customize"),
                SizeFlagsHorizontal = SizeFlags.None
            };

            _summaryLabel = new Label();

            var viewSouth = MakeSpriteView(_previewDummy, Direction.South);
            var viewNorth = MakeSpriteView(_previewDummy, Direction.North);
            var viewWest  = MakeSpriteView(_previewDummy, Direction.West);
            var viewEast  = MakeSpriteView(_previewDummy, Direction.East);

            var vBox = new VBoxContainer();

            vBox.AddChild(header);
            vBox.AddChild(CharacterSetupButton);

            vBox.AddChild(_summaryLabel);

            var hBox = new HBoxContainer();

            hBox.AddChild(viewSouth);
            hBox.AddChild(viewNorth);
            hBox.AddChild(viewWest);
            hBox.AddChild(viewEast);

            vBox.AddChild(hBox);

            AddChild(vBox);

            UpdateUI();
        }
예제 #7
0
        public LobbyGui(IEntityManager entityManager,
                        IClientPreferencesManager preferencesManager)
        {
            RobustXamlLoader.Load(this);

            ServerName.HorizontalExpand    = true;
            ServerName.HorizontalAlignment = HAlignment.Center;

            CharacterPreview = new LobbyCharacterPreviewPanel(
                entityManager,
                preferencesManager)
            {
                HorizontalAlignment = HAlignment.Left
            };

            CLeftPanelContainer.AddChild(CharacterPreview);
            CharacterPreview.SetPositionFirst();
        }
예제 #8
0
        public CharacterSetupGui(
            IEntityManager entityManager,
            IResourceCache resourceCache,
            IClientPreferencesManager preferencesManager,
            IPrototypeManager prototypeManager,
            IConfigurationManager configurationManager)
        {
            RobustXamlLoader.Load(this);
            _entityManager        = entityManager;
            _prototypeManager     = prototypeManager;
            _preferencesManager   = preferencesManager;
            _configurationManager = configurationManager;

            var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
            var back     = new StyleBoxTexture
            {
                Texture  = panelTex,
                Modulate = new Color(37, 37, 42)
            };

            back.SetPatchMargin(StyleBox.Margin.All, 10);

            BackgroundPanel.PanelOverride = back;

            _createNewCharacterButton = new Button
            {
                Text = Loc.GetString("character-setup-gui-create-new-character-button"),
            };
            _createNewCharacterButton.OnPressed += args =>
            {
                preferencesManager.CreateCharacter(HumanoidCharacterProfile.Random());
                UpdateUI();
                args.Event.Handle();
            };

            _humanoidProfileEditor = new HumanoidProfileEditor(preferencesManager, prototypeManager, entityManager, configurationManager);
            _humanoidProfileEditor.OnProfileChanged += ProfileChanged;
            CharEditor.AddChild(_humanoidProfileEditor);

            UpdateUI();

            RulesButton.OnPressed += _ => new RulesAndInfoWindow().Open();
            preferencesManager.OnServerDataLoaded += UpdateUI;
        }
예제 #9
0
        public LobbyGui(IEntityManager entityManager,
                        IResourceCache resourceCache,
                        IClientPreferencesManager preferencesManager)
        {
            var margin = new MarginContainer
            {
                MarginBottomOverride = 20,
                MarginLeftOverride   = 20,
                MarginRightOverride  = 20,
                MarginTopOverride    = 20,
            };

            AddChild(margin);

            var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
            var back     = new StyleBoxTexture
            {
                Texture  = panelTex,
                Modulate = new Color(37, 37, 42),
            };

            back.SetPatchMargin(StyleBox.Margin.All, 10);

            var panel = new PanelContainer
            {
                PanelOverride = back
            };

            margin.AddChild(panel);

            var vBox = new VBoxContainer {
                SeparationOverride = 0
            };

            margin.AddChild(vBox);

            var topHBox = new HBoxContainer
            {
                CustomMinimumSize = (0, 40),
                Children          =
                {
                    new MarginContainer
                    {
                        MarginLeftOverride = 8,
                        Children           =
                        {
                            new Label
                            {
                                Text         = Loc.GetString("Lobby"),
                                StyleClasses ={ StyleNano.StyleClassLabelHeadingBigger                    },

                                /*MarginBottom = 40,
                                 * MarginLeft = 8,*/
                                VAlign = Label.VAlignMode.Center
                            }
                        }
                    },
                    (ServerName = new Label
                    {
                        StyleClasses ={ StyleNano.StyleClassLabelHeadingBigger                    },

                        /*MarginBottom = 40,
                         * GrowHorizontal = GrowDirection.Both,*/
                        VAlign = Label.VAlignMode.Center,
                        SizeFlagsHorizontal = SizeFlags.Expand | SizeFlags.ShrinkCenter
                    }),
                    (CreditsButton = new Button
                    {
                        SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
                        Text = Loc.GetString("Credits"),
                        StyleClasses ={ StyleNano.StyleClassButtonBig                             },
                        //GrowHorizontal = GrowDirection.Begin
                    }),
                    (LeaveButton = new Button
                    {
                        SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
                        Text = Loc.GetString("Leave"),
                        StyleClasses ={ StyleNano.StyleClassButtonBig                             },
                        //GrowHorizontal = GrowDirection.Begin
                    })
                }
            };

            vBox.AddChild(topHBox);

            vBox.AddChild(new PanelContainer
            {
                PanelOverride = new StyleBoxFlat
                {
                    BackgroundColor          = StyleNano.NanoGold,
                    ContentMarginTopOverride = 2
                },
            });

            var hBox = new HBoxContainer
            {
                SizeFlagsVertical  = SizeFlags.FillExpand,
                SeparationOverride = 0
            };

            vBox.AddChild(hBox);

            CharacterPreview = new LobbyCharacterPreviewPanel(
                entityManager,
                preferencesManager)
            {
                SizeFlagsHorizontal = SizeFlags.None
            };
            hBox.AddChild(new VBoxContainer
            {
                SizeFlagsHorizontal = SizeFlags.FillExpand,
                SeparationOverride  = 0,
                Children            =
                {
                    CharacterPreview,

                    new StripeBack
                    {
                        Children =
                        {
                            new MarginContainer
                            {
                                MarginRightOverride  = 3,
                                MarginLeftOverride   = 3,
                                MarginTopOverride    = 3,
                                MarginBottomOverride = 3,
                                Children             =
                                {
                                    new HBoxContainer
                                    {
                                        SeparationOverride = 6,
                                        Children           =
                                        {
                                            (ObserveButton          = new Button
                                            {
                                                Text                = Loc.GetString("Observe"),
                                                StyleClasses        = { StyleNano.StyleClassButtonBig }
                                            }),
                                            (StartTime              = new Label
                                            {
                                                SizeFlagsHorizontal = SizeFlags.FillExpand,
                                                Align               = Label.AlignMode.Right,
                                                FontColorOverride   = Color.DarkGray,
                                                StyleClasses        = { StyleNano.StyleClassLabelBig  }
                                            }),
                                            (ReadyButton            = new Button
                                            {
                                                ToggleMode          = true,
                                                Text                = Loc.GetString("Ready Up"),
                                                StyleClasses        = { StyleNano.StyleClassButtonBig }
                                            }),
                                        }
                                    }
                                }
                            }
                        }
                    },

                    new MarginContainer
                    {
                        MarginRightOverride  = 3,
                        MarginLeftOverride   = 3,
                        MarginTopOverride    = 3,
                        MarginBottomOverride = 3,
                        SizeFlagsVertical    = SizeFlags.FillExpand,
                        Children             =
                        {
                            (Chat     = new ChatBox
                            {
                                Input = { PlaceHolder = Loc.GetString("Say something!") }
                            })
                        }
                    },
                }
            });

            hBox.AddChild(new PanelContainer
            {
                PanelOverride = new StyleBoxFlat {
                    BackgroundColor = StyleNano.NanoGold
                }, CustomMinimumSize = (2, 0)
            });
        public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager,
                                     IEntityManager entityManager)
        {
            RobustXamlLoader.Load(this);
            _random             = IoCManager.Resolve <IRobustRandom>();
            _prototypeManager   = prototypeManager;
            _entMan             = entityManager;
            _preferencesManager = preferencesManager;

            #region Left

            #region Randomize

            #endregion Randomize

            #region Name

            _nameEdit.OnTextChanged              += args => { SetName(args.Text); };
            _nameRandomButton.OnPressed          += args => RandomizeName();
            _randomizeEverythingButton.OnPressed += args => { RandomizeEverything(); };
            _warningLabel.SetMarkup($"[color=red]{Loc.GetString("humanoid-profile-editor-naming-rules-warning")}[/color]");

            #endregion Name

            #region Appearance

            _tabContainer.SetTabTitle(0, Loc.GetString("humanoid-profile-editor-appearance-tab"));

            #region Sex

            var sexButtonGroup = new ButtonGroup();

            _sexMaleButton.Group      = sexButtonGroup;
            _sexMaleButton.OnPressed += args =>
            {
                SetSex(Sex.Male);
                if (Profile?.Gender == Gender.Female)
                {
                    SetGender(Gender.Male);
                    UpdateGenderControls();
                }
            };

            _sexFemaleButton.Group      = sexButtonGroup;
            _sexFemaleButton.OnPressed += _ =>
            {
                SetSex(Sex.Female);

                if (Profile?.Gender == Gender.Male)
                {
                    SetGender(Gender.Female);
                    UpdateGenderControls();
                }
            };

            #endregion Sex

            #region Age

            _ageEdit.OnTextChanged += args =>
            {
                if (!int.TryParse(args.Text, out var newAge))
                {
                    return;
                }
                SetAge(newAge);
            };

            #endregion Age

            #region Gender

            _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-male-text"), (int)Gender.Male);
            _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-female-text"), (int)Gender.Female);
            _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-epicene-text"), (int)Gender.Epicene);
            _genderButton.AddItem(Loc.GetString("humanoid-profile-editor-pronouns-neuter-text"), (int)Gender.Neuter);

            _genderButton.OnItemSelected += args =>
            {
                _genderButton.SelectId(args.Id);
                SetGender((Gender)args.Id);
            };

            #endregion Gender

            #region Species

            _speciesList = prototypeManager.EnumeratePrototypes <SpeciesPrototype>().ToList();
            for (var i = 0; i < _speciesList.Count; i++)
            {
                CSpeciesButton.AddItem(_speciesList[i].Name, i);
            }

            CSpeciesButton.OnItemSelected += args =>
            {
                CSpeciesButton.SelectId(args.Id);
                SetSpecies(_speciesList[args.Id].ID);
                OnSkinColorOnValueChanged(CSkin);
            };

            #endregion Species

            #region Skin

            // 0 - 100, 0 being gold/yellowish and 100 being dark
            // HSV based
            //
            // 0 - 20 changes the hue
            // 20 - 100 changes the value
            // 0 is 45 - 20 - 100
            // 20 is 25 - 20 - 100
            // 100 is 25 - 100 - 20
            _skinColor.OnValueChanged += OnSkinColorOnValueChanged;

            #endregion

            #region Hair

            _hairPicker.Populate();

            _hairPicker.OnHairStylePicked += newStyle =>
            {
                if (Profile is null)
                {
                    return;
                }
                Profile = Profile.WithCharacterAppearance(
                    Profile.Appearance.WithHairStyleName(newStyle));
                IsDirty = true;
            };

            _hairPicker.OnHairColorPicked += newColor =>
            {
                if (Profile is null)
                {
                    return;
                }
                Profile = Profile.WithCharacterAppearance(
                    Profile.Appearance.WithHairColor(newColor));
                IsDirty = true;
            };

            _facialHairPicker.Populate();

            _facialHairPicker.OnHairStylePicked += newStyle =>
            {
                if (Profile is null)
                {
                    return;
                }
                Profile = Profile.WithCharacterAppearance(
                    Profile.Appearance.WithFacialHairStyleName(newStyle));
                IsDirty = true;
            };

            _facialHairPicker.OnHairColorPicked += newColor =>
            {
                if (Profile is null)
                {
                    return;
                }
                Profile = Profile.WithCharacterAppearance(
                    Profile.Appearance.WithFacialHairColor(newColor));
                IsDirty = true;
            };

            #endregion Hair

            #region Clothing

            _clothingButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-jumpsuit"), (int)ClothingPreference.Jumpsuit);
            _clothingButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-jumpskirt"), (int)ClothingPreference.Jumpskirt);

            _clothingButton.OnItemSelected += args =>
            {
                _clothingButton.SelectId(args.Id);
                SetClothing((ClothingPreference)args.Id);
            };

            #endregion Clothing

            #region Backpack

            _backpackButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-backpack"), (int)BackpackPreference.Backpack);
            _backpackButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-satchel"), (int)BackpackPreference.Satchel);
            _backpackButton.AddItem(Loc.GetString("humanoid-profile-editor-preference-duffelbag"), (int)BackpackPreference.Duffelbag);

            _backpackButton.OnItemSelected += args =>
            {
                _backpackButton.SelectId(args.Id);
                SetBackpack((BackpackPreference)args.Id);
            };

            #endregion Backpack

            #region Eyes

            _eyesPicker.OnEyeColorPicked += newColor =>
            {
                if (Profile is null)
                {
                    return;
                }
                Profile = Profile.WithCharacterAppearance(
                    Profile.Appearance.WithEyeColor(newColor));
                IsDirty = true;
            };

            #endregion Eyes

            #endregion Appearance

            #region Jobs

            _tabContainer.SetTabTitle(1, Loc.GetString("humanoid-profile-editor-jobs-tab"));

            _preferenceUnavailableButton.AddItem(
                Loc.GetString("humanoid-profile-editor-preference-unavailable-stay-in-lobby-button"),
                (int)PreferenceUnavailableMode.StayInLobby);
            _preferenceUnavailableButton.AddItem(
                Loc.GetString("humanoid-profile-editor-preference-unavailable-spawn-as-overflow-button",
                              ("overflowJob", Loc.GetString(SharedGameTicker.FallbackOverflowJobName))),
                (int)PreferenceUnavailableMode.SpawnAsOverflow);

            _preferenceUnavailableButton.OnItemSelected += args =>
            {
                _preferenceUnavailableButton.SelectId(args.Id);

                Profile = Profile?.WithPreferenceUnavailable((PreferenceUnavailableMode)args.Id);
                IsDirty = true;
            };

            _jobPriorities = new List <JobPrioritySelector>();
            _jobCategories = new Dictionary <string, BoxContainer>();

            var firstCategory = true;

            foreach (var job in prototypeManager.EnumeratePrototypes <JobPrototype>().OrderBy(j => j.Name))
            {
                if (!job.SetPreference)
                {
                    continue;
                }

                foreach (var department in job.Departments)
                {
                    if (!_jobCategories.TryGetValue(department, out var category))
                    {
                        category = new BoxContainer
                        {
                            Orientation = LayoutOrientation.Vertical,
                            Name        = department,
                            ToolTip     = Loc.GetString("humanoid-profile-editor-jobs-amount-in-department-tooltip",
                                                        ("departmentName", department))
                        };

                        if (firstCategory)
                        {
                            firstCategory = false;
                        }
                        else
                        {
                            category.AddChild(new Control
                            {
                                MinSize = new Vector2(0, 23),
                            });
                        }

                        category.AddChild(new PanelContainer
                        {
                            PanelOverride = new StyleBoxFlat {
                                BackgroundColor = Color.FromHex("#464966")
                            },
                            Children =
                            {
                                new Label
                                {
                                    Text = Loc.GetString("humanoid-profile-editor-department-jobs-label",
                                                         ("departmentName", department))
                                }
                            }
                        });
예제 #11
0
        public CharacterSetupGui(
            IEntityManager entityManager,
            IResourceCache resourceCache,
            IClientPreferencesManager preferencesManager,
            IPrototypeManager prototypeManager)
        {
            AddChild(new ParallaxControl());

            _entityManager      = entityManager;
            _preferencesManager = preferencesManager;
            var margin = new Control
            {
                Margin = new Thickness(20),
            };

            AddChild(margin);

            var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
            var back     = new StyleBoxTexture
            {
                Texture  = panelTex,
                Modulate = new Color(37, 37, 42)
            };

            back.SetPatchMargin(StyleBox.Margin.All, 10);

            var panel = new PanelContainer
            {
                PanelOverride = back
            };

            margin.AddChild(panel);

            var vBox = new VBoxContainer {
                SeparationOverride = 0
            };

            margin.AddChild(vBox);

            var topHBox = new HBoxContainer
            {
                MinSize  = (0, 40),
                Children =
                {
                    new Label
                    {
                        Margin       = new Thickness(8, 0, 0, 0),
                        Text         = Loc.GetString("character-setup-gui-character-setup-label"),
                        StyleClasses ={ StyleNano.StyleClassLabelHeadingBigger                    },
                        VAlign       = Label.VAlignMode.Center,
                    },
                    (SaveButton = new Button
                    {
                        HorizontalExpand = true,
                        HorizontalAlignment = HAlignment.Right,
                        Text = Loc.GetString("character-setup-gui-character-setup-save-button"),
                        StyleClasses ={ StyleNano.StyleClassButtonBig                             },
                    }),
                    (CloseButton = new Button
                    {
                        Text = Loc.GetString("character-setup-gui-character-setup-close-button"),
                        StyleClasses ={ StyleNano.StyleClassButtonBig                             },
                    })
                }
            };

            vBox.AddChild(topHBox);

            vBox.AddChild(new PanelContainer
            {
                PanelOverride = new StyleBoxFlat
                {
                    BackgroundColor          = StyleNano.NanoGold,
                    ContentMarginTopOverride = 2
                }
            });

            var hBox = new HBoxContainer
            {
                VerticalExpand     = true,
                SeparationOverride = 0
            };

            vBox.AddChild(hBox);

            _charactersVBox = new VBoxContainer();

            hBox.AddChild(new ScrollContainer
            {
                MinSize  = (325, 0),
                Margin   = new Thickness(5, 5, 0, 0),
                Children =
                {
                    _charactersVBox
                }
            });
예제 #12
0
            public CharacterPickerButton(
                IEntityManager entityManager,
                IClientPreferencesManager preferencesManager,
                ButtonGroup group,
                ICharacterProfile profile)
            {
                AddStyleClass(StyleClassButton);
                ToggleMode = true;
                Group      = group;

                _previewDummy = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace);
                _previewDummy.GetComponent <HumanoidAppearanceComponent>().UpdateFromProfile(profile);
                var humanoid = profile as HumanoidCharacterProfile;

                if (humanoid != null)
                {
                    LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid);
                }

                var isSelectedCharacter = profile == preferencesManager.Preferences?.SelectedCharacter;

                if (isSelectedCharacter)
                {
                    Pressed = true;
                }

                var view = new SpriteView
                {
                    Sprite            = _previewDummy.GetComponent <SpriteComponent>(),
                    Scale             = (2, 2),
                    OverrideDirection = Direction.South
                };

                var description = profile.Name;

                var highPriorityJob = humanoid?.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key;

                if (highPriorityJob != null)
                {
                    var jobName = IoCManager.Resolve <IPrototypeManager>().Index <JobPrototype>(highPriorityJob).Name;
                    description = $"{description}\n{jobName}";
                }

                var descriptionLabel = new Label
                {
                    Text             = description,
                    ClipText         = true,
                    HorizontalExpand = true
                };
                var deleteButton = new Button
                {
                    Text    = Loc.GetString("character-setup-gui-character-picker-button-delete-button"),
                    Visible = !isSelectedCharacter,
                };

                deleteButton.OnPressed += _ =>
                {
                    Parent?.RemoveChild(this);
                    preferencesManager.DeleteCharacter(profile);
                };

                var internalHBox = new HBoxContainer
                {
                    HorizontalExpand   = true,
                    SeparationOverride = 0,
                    Children           =
                    {
                        view,
                        descriptionLabel,
                        deleteButton
                    }
                };

                AddChild(internalHBox);
            }
        public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager)
        {
            _random = IoCManager.Resolve <IRobustRandom>();

            _preferencesManager = preferencesManager;

            var margin = new MarginContainer
            {
                MarginTopOverride    = 10,
                MarginBottomOverride = 10,
                MarginLeftOverride   = 10,
                MarginRightOverride  = 10
            };

            AddChild(margin);

            var vBox = new VBoxContainer();

            margin.AddChild(vBox);

            var middleContainer = new HBoxContainer
            {
                SeparationOverride = 10
            };

            vBox.AddChild(middleContainer);

            var leftColumn = new VBoxContainer();

            middleContainer.AddChild(leftColumn);

            #region Randomize

            {
                var panel = HighlightedContainer();
                var randomizeEverythingButton = new Button
                {
                    Text = Loc.GetString("Randomize everything")
                };
                randomizeEverythingButton.OnPressed += args => { RandomizeEverything(); };
                panel.AddChild(randomizeEverythingButton);
                leftColumn.AddChild(panel);
            }

            #endregion Randomize

            #region Name

            {
                var panel = HighlightedContainer();
                var hBox  = new HBoxContainer
                {
                    SizeFlagsVertical = SizeFlags.FillExpand
                };
                var nameLabel = new Label {
                    Text = Loc.GetString("Name:")
                };
                _nameEdit = new LineEdit
                {
                    CustomMinimumSize = (270, 0),
                    SizeFlagsVertical = SizeFlags.ShrinkCenter
                };
                _nameEdit.OnTextChanged += args => { SetName(args.Text); };
                var nameRandomButton = new Button
                {
                    Text = Loc.GetString("Randomize"),
                };
                nameRandomButton.OnPressed += args => RandomizeName();
                hBox.AddChild(nameLabel);
                hBox.AddChild(_nameEdit);
                hBox.AddChild(nameRandomButton);
                panel.AddChild(hBox);
                leftColumn.AddChild(panel);
            }

            #endregion Name

            var tabContainer = new TabContainer {
                SizeFlagsVertical = SizeFlags.FillExpand
            };
            vBox.AddChild(tabContainer);

            #region Appearance

            {
                var appearanceVBox = new VBoxContainer();
                tabContainer.AddChild(appearanceVBox);
                tabContainer.SetTabTitle(0, Loc.GetString("Appearance"));

                var sexAndAgeRow = new HBoxContainer
                {
                    SeparationOverride = 10
                };

                appearanceVBox.AddChild(sexAndAgeRow);

                #region Sex

                {
                    var panel    = HighlightedContainer();
                    var hBox     = new HBoxContainer();
                    var sexLabel = new Label {
                        Text = Loc.GetString("Sex:")
                    };

                    var sexButtonGroup = new ButtonGroup();

                    _sexMaleButton = new Button
                    {
                        Text  = Loc.GetString("Male"),
                        Group = sexButtonGroup
                    };
                    _sexMaleButton.OnPressed += args => { SetSex(Sex.Male); };
                    _sexFemaleButton          = new Button
                    {
                        Text  = Loc.GetString("Female"),
                        Group = sexButtonGroup
                    };
                    _sexFemaleButton.OnPressed += args => { SetSex(Sex.Female); };
                    hBox.AddChild(sexLabel);
                    hBox.AddChild(_sexMaleButton);
                    hBox.AddChild(_sexFemaleButton);
                    panel.AddChild(hBox);
                    sexAndAgeRow.AddChild(panel);
                }

                #endregion Sex

                #region Age

                {
                    var panel    = HighlightedContainer();
                    var hBox     = new HBoxContainer();
                    var ageLabel = new Label {
                        Text = Loc.GetString("Age:")
                    };
                    _ageEdit = new LineEdit {
                        CustomMinimumSize = (40, 0)
                    };
                    _ageEdit.OnTextChanged += args =>
                    {
                        if (!int.TryParse(args.Text, out var newAge))
                        {
                            return;
                        }
                        SetAge(newAge);
                    };
                    hBox.AddChild(ageLabel);
                    hBox.AddChild(_ageEdit);
                    panel.AddChild(hBox);
                    sexAndAgeRow.AddChild(panel);
                }

                #endregion Age

                #region Hair

                {
                    var panel = HighlightedContainer();
                    panel.SizeFlagsHorizontal = SizeFlags.None;
                    var hairHBox = new HBoxContainer();

                    _hairPicker = new HairStylePicker();
                    _hairPicker.Populate();

                    _hairPicker.OnHairStylePicked += newStyle =>
                    {
                        if (Profile is null)
                        {
                            return;
                        }
                        Profile = Profile.WithCharacterAppearance(
                            Profile.Appearance.WithHairStyleName(newStyle));
                        IsDirty = true;
                    };

                    _hairPicker.OnHairColorPicked += newColor =>
                    {
                        if (Profile is null)
                        {
                            return;
                        }
                        Profile = Profile.WithCharacterAppearance(
                            Profile.Appearance.WithHairColor(newColor));
                        IsDirty = true;
                    };

                    _facialHairPicker = new FacialHairStylePicker();
                    _facialHairPicker.Populate();

                    _facialHairPicker.OnHairStylePicked += newStyle =>
                    {
                        if (Profile is null)
                        {
                            return;
                        }
                        Profile = Profile.WithCharacterAppearance(
                            Profile.Appearance.WithFacialHairStyleName(newStyle));
                        IsDirty = true;
                    };

                    _facialHairPicker.OnHairColorPicked += newColor =>
                    {
                        if (Profile is null)
                        {
                            return;
                        }
                        Profile = Profile.WithCharacterAppearance(
                            Profile.Appearance.WithFacialHairColor(newColor));
                        IsDirty = true;
                    };

                    hairHBox.AddChild(_hairPicker);
                    hairHBox.AddChild(_facialHairPicker);

                    panel.AddChild(hairHBox);
                    appearanceVBox.AddChild(panel);
                }

                #endregion Hair
            }

            #endregion

            #region Jobs

            {
                var jobList = new VBoxContainer();

                var jobVBox = new VBoxContainer
                {
                    Children =
                    {
                        (_preferenceUnavailableButton = new OptionButton()),
                        new ScrollContainer
                        {
                            SizeFlagsVertical = SizeFlags.FillExpand,
                            Children          =
                            {
                                jobList
                            }
                        }
                    }
                };

                tabContainer.AddChild(jobVBox);

                tabContainer.SetTabTitle(1, Loc.GetString("Jobs"));

                _preferenceUnavailableButton.AddItem(
                    Loc.GetString("Stay in lobby if preference unavailable."),
                    (int)PreferenceUnavailableMode.StayInLobby);
                _preferenceUnavailableButton.AddItem(
                    Loc.GetString("Be an {0} if preference unavailable.",
                                  Loc.GetString(SharedGameTicker.OverflowJobName)),
                    (int)PreferenceUnavailableMode.SpawnAsOverflow);

                _preferenceUnavailableButton.OnItemSelected += args =>
                {
                    _preferenceUnavailableButton.SelectId(args.Id);

                    Profile = Profile.WithPreferenceUnavailable((PreferenceUnavailableMode)args.Id);
                    IsDirty = true;
                };

                _jobPriorities = new List <JobPrioritySelector>();

                foreach (var job in prototypeManager.EnumeratePrototypes <JobPrototype>().OrderBy(j => j.Name))
                {
                    var selector = new JobPrioritySelector(job);
                    jobList.AddChild(selector);
                    _jobPriorities.Add(selector);

                    selector.PriorityChanged += priority =>
                    {
                        Profile = Profile.WithJobPriority(job.ID, priority);
                        IsDirty = true;

                        if (priority == JobPriority.High)
                        {
                            // Lower any other high priorities to medium.
                            foreach (var jobSelector in _jobPriorities)
                            {
                                if (jobSelector != selector && jobSelector.Priority == JobPriority.High)
                                {
                                    jobSelector.Priority = JobPriority.Medium;
                                    Profile = Profile.WithJobPriority(jobSelector.Job.ID, JobPriority.Medium);
                                }
                            }
                        }
                    };
                }
            }

            #endregion

            #region Antags

            {
                var antagList = new VBoxContainer();

                var antagVBox = new VBoxContainer
                {
                    Children =
                    {
                        new ScrollContainer
                        {
                            SizeFlagsVertical = SizeFlags.FillExpand,
                            Children          =
                            {
                                antagList
                            }
                        }
                    }
                };

                tabContainer.AddChild(antagVBox);

                tabContainer.SetTabTitle(2, Loc.GetString("Antags"));

                _antagPreferences = new List <AntagPreferenceSelector>();

                foreach (var antag in prototypeManager.EnumeratePrototypes <AntagPrototype>().OrderBy(a => a.Name))
                {
                    if (!antag.SetPreference)
                    {
                        continue;
                    }
                    var selector = new AntagPreferenceSelector(antag);
                    antagList.AddChild(selector);
                    _antagPreferences.Add(selector);

                    selector.PreferenceChanged += preference =>
                    {
                        Profile = Profile.WithAntagPreference(antag.ID, preference);
                        IsDirty = true;
                    };
                }
            }

            #endregion

            var rightColumn = new VBoxContainer();
            middleContainer.AddChild(rightColumn);

            #region Import/Export

            {
                var panelContainer = HighlightedContainer();
                var hBox           = new HBoxContainer();
                var importButton   = new Button
                {
                    Text     = Loc.GetString("Import"),
                    Disabled = true,
                    ToolTip  = "Not yet implemented!"
                };
                var exportButton = new Button
                {
                    Text     = Loc.GetString("Export"),
                    Disabled = true,
                    ToolTip  = "Not yet implemented!"
                };
                hBox.AddChild(importButton);
                hBox.AddChild(exportButton);
                panelContainer.AddChild(hBox);
                rightColumn.AddChild(panelContainer);
            }

            #endregion Import/Export

            #region Save

            {
                var panel = HighlightedContainer();
                _saveButton = new Button
                {
                    Text = Loc.GetString("Save"),
                    SizeFlagsHorizontal = SizeFlags.ShrinkCenter
                };
                _saveButton.OnPressed += args => { Save(); };
                panel.AddChild(_saveButton);
                rightColumn.AddChild(panel);
            }

            #endregion Save

            if (preferencesManager.ServerDataLoaded)
            {
                LoadServerData();
            }

            preferencesManager.OnServerDataLoaded += LoadServerData;

            IsDirty = false;
        }
        public CharacterSetupGui(IEntityManager entityManager,
                                 ILocalizationManager localization,
                                 IResourceCache resourceCache,
                                 IClientPreferencesManager preferencesManager,
                                 IPrototypeManager prototypeManager)
        {
            _entityManager      = entityManager;
            _preferencesManager = preferencesManager;
            var margin = new MarginContainer
            {
                MarginBottomOverride = 20,
                MarginLeftOverride   = 20,
                MarginRightOverride  = 20,
                MarginTopOverride    = 20
            };

            AddChild(margin);

            var panelTex = resourceCache.GetTexture("/Nano/button.svg.96dpi.png");
            var back     = new StyleBoxTexture
            {
                Texture  = panelTex,
                Modulate = new Color(37, 37, 42)
            };

            back.SetPatchMargin(StyleBox.Margin.All, 10);

            var panel = new PanelContainer
            {
                PanelOverride = back
            };

            margin.AddChild(panel);

            var vBox = new VBoxContainer {
                SeparationOverride = 0
            };

            margin.AddChild(vBox);

            CloseButton = new Button
            {
                SizeFlagsHorizontal = SizeFlags.Expand | SizeFlags.ShrinkEnd,
                Text         = localization.GetString("Save and close"),
                StyleClasses = { NanoStyle.StyleClassButtonBig }
            };

            var topHBox = new HBoxContainer
            {
                CustomMinimumSize = (0, 40),
                Children          =
                {
                    new MarginContainer
                    {
                        MarginLeftOverride = 8,
                        Children           =
                        {
                            new Label
                            {
                                Text                = localization.GetString("Character Setup"),
                                StyleClasses        = { NanoStyle.StyleClassLabelHeadingBigger },
                                VAlign              = Label.VAlignMode.Center,
                                SizeFlagsHorizontal = SizeFlags.Expand | SizeFlags.ShrinkCenter
                            }
                        }
                    },
                    CloseButton
                }
            };

            vBox.AddChild(topHBox);

            vBox.AddChild(new PanelContainer
            {
                PanelOverride = new StyleBoxFlat
                {
                    BackgroundColor          = NanoStyle.NanoGold,
                    ContentMarginTopOverride = 2
                }
            });

            var hBox = new HBoxContainer
            {
                SizeFlagsVertical  = SizeFlags.FillExpand,
                SeparationOverride = 0
            };

            vBox.AddChild(hBox);

            _charactersVBox = new VBoxContainer();

            hBox.AddChild(new MarginContainer
            {
                CustomMinimumSize   = (330, 0),
                SizeFlagsHorizontal = SizeFlags.Fill,
                MarginTopOverride   = 5,
                MarginLeftOverride  = 5,
                Children            =
                {
                    new ScrollContainer
                    {
                        SizeFlagsVertical = SizeFlags.FillExpand,
                        Children          =
                        {
                            _charactersVBox
                        }
                    }
                }
            });
            public CharacterPickerButton(
                IEntityManager entityManager,
                IClientPreferencesManager preferencesManager,
                ButtonGroup group,
                ICharacterProfile profile)
            {
                _previewDummy = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace);
                _previewDummy.GetComponent <HumanoidAppearanceComponent>().UpdateFromProfile(profile);
                var humanoid = profile as HumanoidCharacterProfile;

                if (humanoid != null)
                {
                    LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid);
                }

                var isSelectedCharacter = profile == preferencesManager.Preferences.SelectedCharacter;

                ActualButton = new Button
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand,
                    SizeFlagsVertical   = SizeFlags.FillExpand,
                    ToggleMode          = true,
                    Group = group
                };
                if (isSelectedCharacter)
                {
                    ActualButton.Pressed = true;
                }
                AddChild(ActualButton);

                var view = new SpriteView
                {
                    Sprite            = _previewDummy.GetComponent <SpriteComponent>(),
                    Scale             = (2, 2),
                    MouseFilter       = MouseFilterMode.Ignore,
                    OverrideDirection = Direction.South
                };

                var description = profile.Name;

                var highPriorityJob = humanoid?.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key;

                if (highPriorityJob != null)
                {
                    var jobName = IoCManager.Resolve <IPrototypeManager>().Index <JobPrototype>(highPriorityJob).Name;
                    description = $"{description}\n{jobName}";
                }

                var descriptionLabel = new Label
                {
                    Text                = description,
                    ClipText            = true,
                    SizeFlagsHorizontal = SizeFlags.FillExpand
                };
                var deleteButton = new Button
                {
                    Text    = "Delete",
                    Visible = !isSelectedCharacter,
                };

                deleteButton.OnPressed += args =>
                {
                    Parent.RemoveChild(this);
                    preferencesManager.DeleteCharacter(profile);
                };

                var internalHBox = new HBoxContainer
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand,
                    MouseFilter         = MouseFilterMode.Ignore,
                    SeparationOverride  = 0,
                    Children            =
                    {
                        view,
                        descriptionLabel,
                        deleteButton
                    }
                };

                AddChild(internalHBox);
            }