Beispiel #1
0
 public void Populate()
 {
     _buttonContainer.DisposeAllChildren();
     AddButtonPlayers();
     AddButtonLocations();
     OpenCentered();
 }
        public override async void Refresh()
        {
            _memberList.DisposeAllChildren();

            if (Instance.Object != null)
            {
                var first = true;
                foreach (var group in ViewVariablesInstance.LocalPropertyList(Instance.Object,
                                                                              Instance.ViewVariablesManager, _robustSerializer))
                {
                    CreateMemberGroupHeader(
                        ref first,
                        TypeAbbreviation.Abbreviate(group.Key),
                        _memberList);

                    foreach (var control in group)
                    {
                        _memberList.AddChild(control);
                    }
                }
            }
            else
            {
                DebugTools.AssertNotNull(Instance.Session);

                var blob = await Instance.ViewVariablesManager.RequestData <ViewVariablesBlobMembers>(
                    Instance.Session !, new ViewVariablesRequestMembers());

                var otherStyle = false;
                var first      = true;
                foreach (var(groupName, groupMembers) in blob.MemberGroups)
                {
                    CreateMemberGroupHeader(ref first, groupName, _memberList);

                    foreach (var propertyData in groupMembers)
                    {
                        var propertyEdit = new ViewVariablesPropertyControl(_vvm, _robustSerializer);
                        propertyEdit.SetStyle(otherStyle = !otherStyle);
                        var editor = propertyEdit.SetProperty(propertyData);

                        var selectorChain = new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) };
                        editor.WireNetworkSelector(Instance.Session !.SessionId, selectorChain);
                        editor.OnValueChanged += o =>
                        {
                            Instance.ViewVariablesManager.ModifyRemote(Instance.Session !,
                                                                       selectorChain, o);
                        };

                        _memberList.AddChild(propertyEdit);
                    }
                }
            }
        }
            /// <summary>
            /// Loops through stored entities creating buttons for each, updates information labels
            /// </summary>
            public void BuildEntityList()
            {
                EntityList.DisposeAllChildren();

                var storagelist = StorageEntity.StoredEntities;

                foreach (var entityuid in storagelist)
                {
                    var entity = IoCManager.Resolve <IEntityManager>().GetEntity(entityuid.Key);

                    var button = new EntityButton()
                    {
                        EntityuID = entityuid.Key
                    };
                    var container = button.GetChild("HBoxContainer");
                    button.ActualButton.OnToggled += OnItemButtonToggled;
                    //Name and Size labels set
                    container.GetChild <Label>("Name").Text = entity.Name;
                    container.GetChild <Control>("Control").GetChild <Label>("Size").Text = string.Format("{0}", entityuid.Value);

                    //Gets entity sprite and assigns it to button texture
                    if (entity.TryGetComponent(out IconComponent icon))
                    {
                        var tex  = icon.Icon.Default;
                        var rect = container.GetChild("TextureWrap").GetChild <TextureRect>("TextureRect");

                        if (tex != null)
                        {
                            rect.Texture = tex;
                            // Copypasted but replaced with 32 dunno if good
                            var scale = (float)32 / tex.Height;
                            rect.Scale = new Vector2(scale, scale);
                        }
                        else
                        {
                            rect.Dispose();
                        }
                    }

                    EntityList.AddChild(button);
                }

                //Sets information about entire storage container current capacity
                if (StorageEntity.StorageCapacityMax != 0)
                {
                    Information.Text = String.Format("Items: {0}, Stored: {1}/{2}", storagelist.Count, StorageEntity.StorageSizeUsed, StorageEntity.StorageCapacityMax);
                }
                else
                {
                    Information.Text = String.Format("Items: {0}", storagelist.Count);
                }
            }
            public void BuildDisplay(Dictionary <string, string> targets)
            {
                _bodyPartList.DisposeAllChildren();
                foreach (var(slotName, partname) in targets)
                {
                    var button = new BodyPartButton(slotName);
                    button.ActualButton.OnToggled += OnButtonPressed;
                    button.LimbName.Text           = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(slotName + " - " + partname);

                    //button.SpriteView.Sprite = sprite;

                    _bodyPartList.AddChild(button);
                }
            }
        public void BuildDisplay(Dictionary <string, int> data, OptionSelectedCallback callback)
        {
            _optionsBox.DisposeAllChildren();
            _optionSelectedCallback = callback;
            foreach (var(displayText, callbackData) in data)
            {
                var button = new SurgeryButton(callbackData);
                button.SetOnToggleBehavior(OnButtonPressed);
                button.SetDisplayText(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(displayText));


                _optionsBox.AddChild(button);
            }
        }
        private void BuildEntityList(string searchStr = null)
        {
            PrototypeList.DisposeAllChildren();
            SelectedButton = null;
            searchStr      = searchStr?.ToLowerInvariant();

            var prototypes = new List <EntityPrototype>();

            foreach (var prototype in prototypeManager.EnumeratePrototypes <EntityPrototype>())
            {
                if (prototype.Abstract)
                {
                    continue;
                }

                if (searchStr != null && !_doesPrototypeMatchSearch(prototype, searchStr))
                {
                    continue;
                }

                prototypes.Add(prototype);
            }

            prototypes.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));

            foreach (var prototype in prototypes)
            {
                var button = new EntitySpawnButton()
                {
                    Prototype = prototype,
                };
                button.ActualButton.OnToggled += OnItemButtonToggled;
                button.EntityLabel.Text        = prototype.Name;

                var tex  = IconComponent.GetPrototypeIcon(prototype, resourceCache);
                var rect = button.EntityTextureRect;
                if (tex != null)
                {
                    rect.Texture = tex.Default;
                }
                else
                {
                    rect.Dispose();
                }

                PrototypeList.AddChild(button);
            }
        }
Beispiel #7
0
            /// <summary>
            /// Loops through stored entities creating buttons for each, updates information labels
            /// </summary>
            public void BuildEntityList()
            {
                _entityList.DisposeAllChildren();

                var storageList = StorageEntity.StoredEntities;

                var storedGrouped = storageList.GroupBy(e => e).Select(e => new
                {
                    Entity = e.Key,
                    Amount = e.Count()
                });

                foreach (var group in storedGrouped)
                {
                    var entity = group.Entity;
                    var button = new EntityButton()
                    {
                        EntityUid   = entity.Uid,
                        MouseFilter = MouseFilterMode.Stop,
                    };
                    button.ActualButton.OnToggled += OnItemButtonToggled;
                    //Name and Size labels set
                    button.EntityName.Text = entity.Name;

                    button.EntitySize.Text = group.Amount.ToString();

                    //Gets entity sprite and assigns it to button texture
                    if (entity.TryGetComponent(out ISpriteComponent sprite))
                    {
                        button.EntitySpriteView.Sprite = sprite;
                    }

                    _entityList.AddChild(button);
                }

                //Sets information about entire storage container current capacity
                if (StorageEntity.StorageCapacityMax != 0)
                {
                    _information.Text = String.Format("Items: {0}, Stored: {1}/{2}", storageList.Count,
                                                      StorageEntity.StorageSizeUsed, StorageEntity.StorageCapacityMax);
                }
                else
                {
                    _information.Text = String.Format("Items: {0}", storageList.Count);
                }
            }
Beispiel #8
0
        public override async void Refresh()
        {
            _memberList.DisposeAllChildren();

            if (Instance.Object != null)
            {
                foreach (var control in ViewVariablesInstance.LocalPropertyList(Instance.Object,
                                                                                Instance.ViewVariablesManager, _resourceCache))
                {
                    _memberList.AddChild(control);
                }
            }
            else
            {
                DebugTools.AssertNotNull(Instance.Session);

                var blob = await Instance.ViewVariablesManager.RequestData <ViewVariablesBlobMembers>(
                    Instance.Session !, new ViewVariablesRequestMembers());

                var otherStyle = false;
                foreach (var propertyData in blob.Members)
                {
                    var propertyEdit = new ViewVariablesPropertyControl(_vvm, _resourceCache);
                    propertyEdit.SetStyle(otherStyle = !otherStyle);
                    var editor = propertyEdit.SetProperty(propertyData);
                    // TODO: should this maybe not be hardcoded?
                    if (editor is ViewVariablesPropertyEditorReference refEditor)
                    {
                        refEditor.OnPressed += () =>
                                               Instance.ViewVariablesManager.OpenVV(
                            new ViewVariablesSessionRelativeSelector(Instance.Session !.SessionId,
                                                                     new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) }));
                    }

                    editor.OnValueChanged += o =>
                    {
                        Instance.ViewVariablesManager.ModifyRemote(Instance.Session !,
                                                                   new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) }, o);
                    };

                    _memberList.AddChild(propertyEdit);
                }
            }
        }
Beispiel #9
0
            /// <summary>
            /// Loops through stored entities creating buttons for each, updates information labels
            /// </summary>
            public void BuildEntityList()
            {
                EntityList.DisposeAllChildren();

                var storagelist = StorageEntity.StoredEntities;

                foreach (var entityuid in storagelist)
                {
                    var entity = IoCManager.Resolve <IEntityManager>().GetEntity(entityuid.Key);

                    var button = new EntityButton()
                    {
                        EntityuID   = entityuid.Key,
                        MouseFilter = MouseFilterMode.Stop,
                    };
                    button.ActualButton.OnToggled += OnItemButtonToggled;
                    //Name and Size labels set
                    button.EntityName.Text = entity.Name;
                    button.EntitySize.Text = string.Format("{0}", entityuid.Value);

                    //Gets entity sprite and assigns it to button texture
                    if (entity.TryGetComponent(out ISpriteComponent sprite))
                    {
                        button.EntitySpriteView.Sprite = sprite;
                    }

                    EntityList.AddChild(button);
                }

                //Sets information about entire storage container current capacity
                if (StorageEntity.StorageCapacityMax != 0)
                {
                    Information.Text = String.Format("Items: {0}, Stored: {1}/{2}", storagelist.Count,
                                                     StorageEntity.StorageSizeUsed, StorageEntity.StorageCapacityMax);
                }
                else
                {
                    Information.Text = String.Format("Items: {0}", storagelist.Count);
                }
            }
Beispiel #10
0
        public override async void Refresh()
        {
            _memberList.DisposeAllChildren();

            if (Instance.Object != null)
            {
                foreach (var control in ViewVariablesInstance.LocalPropertyList(Instance.Object,
                                                                                Instance.ViewVariablesManager, _resourceCache))
                {
                    _memberList.AddChild(control);
                }
            }
            else
            {
                DebugTools.AssertNotNull(Instance.Session);

                var blob = await Instance.ViewVariablesManager.RequestData <ViewVariablesBlobMembers>(
                    Instance.Session !, new ViewVariablesRequestMembers());

                var otherStyle = false;
                foreach (var propertyData in blob.Members)
                {
                    var propertyEdit = new ViewVariablesPropertyControl(_vvm, _resourceCache);
                    propertyEdit.SetStyle(otherStyle = !otherStyle);
                    var editor = propertyEdit.SetProperty(propertyData);

                    var selectorChain = new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) };
                    editor.WireNetworkSelector(Instance.Session !.SessionId, selectorChain);
                    editor.OnValueChanged += o =>
                    {
                        Instance.ViewVariablesManager.ModifyRemote(Instance.Session !,
                                                                   selectorChain, o);
                    };

                    _memberList.AddChild(propertyEdit);
                }
            }
        }
Beispiel #11
0
        private void PopulateClientComponents()
        {
            _clientComponents.DisposeAllChildren();

            _clientComponents.AddChild(_clientComponentsSearchBar = new LineEdit
            {
                PlaceHolder         = Loc.GetString("Search"),
                SizeFlagsHorizontal = SizeFlags.FillExpand
            });

            _clientComponents.AddChild(_clientComponentsAddButton = new Button()
            {
                Text = Loc.GetString("Add Component"),
                SizeFlagsHorizontal = SizeFlags.FillExpand
            });

            _clientComponentsAddButton.OnPressed     += OnClientComponentsAddButtonPressed;
            _clientComponentsSearchBar.OnTextChanged += OnClientComponentsSearchBarChanged;

            var componentList = _entity.GetAllComponents().OrderBy(c => c.GetType().ToString());

            foreach (var component in componentList)
            {
                var button = new Button {
                    Text = TypeAbbreviation.Abbreviate(component.GetType()), TextAlign = Label.AlignMode.Left
                };
                var removeButton = new TextureButton()
                {
                    StyleClasses        = { SS14Window.StyleClassWindowCloseButton },
                    SizeFlagsHorizontal = SizeFlags.ShrinkEnd
                };
                button.OnPressed       += _ => ViewVariablesManager.OpenVV(component);
                removeButton.OnPressed += _ => RemoveClientComponent(component);
                button.AddChild(removeButton);
                _clientComponents.AddChild(button);
            }
        }
Beispiel #12
0
        private async Task _moveToPage(int page)
        {
            // TODO: Network overhead optimization potential:
            // Right now, (in NETWORK mode) if I request page 5, it has to cache all 5 pages,
            // now the server obviously (enumerator and all that) has to TOO, but whatever.
            // The waste is that all pages are also SENT, even though we only really care about the fifth at the moment.
            // Because the cache can't have holes (and also the network system is too simplistic at the moment,
            // if you do do a by-page pull and you're way too far along,
            // you'll just get 0 elements which doesn't tell you where it ended but that's kinda necessary.
            if (page < 0)
            {
                page = 0;
            }

            if (page > HighestKnownPage || (!_ended && page == HighestKnownPage))
            {
                if (_ended)
                {
                    // The requested page is higher than the highest page we have (and we know this because the enumerator ended).
                    page = HighestKnownPage;
                }
                else
                {
                    // The page is higher than the highest page we have, but the enumerator hasn't ended yet so that might be valid.
                    // Gotta get more data.
                    await _cacheTo((page + 1) *ElementsPerPage);

                    if (page > HighestKnownPage)
                    {
                        // We tried, but the enumerator ended before we reached our goal.
                        // Oh well.
                        DebugTools.Assert(_ended);
                        page = HighestKnownPage;
                    }
                }
            }

            _elementsVBox.DisposeAllChildren();

            for (var i = page * ElementsPerPage; i < ElementsPerPage * (page + 1) && i < _cache.Count; i++)
            {
                var element = _cache[i];
                ViewVariablesPropertyEditor editor;
                if (element == null)
                {
                    editor = new ViewVariablesPropertyEditorDummy();
                }
                else
                {
                    var type = element.GetType();
                    editor = Instance.ViewVariablesManager.PropertyFor(type);
                }

                var control = editor.Initialize(element, true);
                if (editor is ViewVariablesPropertyEditorReference refEditor)
                {
                    if (_networked)
                    {
                        var iSafe = i;
                        refEditor.OnPressed += () =>
                                               Instance.ViewVariablesManager.OpenVV(
                            new ViewVariablesSessionRelativeSelector(Instance.Session.SessionId,
                                                                     new object[] { new ViewVariablesEnumerableIndexSelector(iSafe), }));
                    }
                    else
                    {
                        refEditor.OnPressed += () => Instance.ViewVariablesManager.OpenVV(element);
                    }
                }
                _elementsVBox.AddChild(control);
            }

            _page = page;

            _updateControls();
        }
        private async void _tabsOnTabChanged(int tab)
        {
            if (_serverLoaded || tab != TabServerComponents && tab != TabServerVars)
            {
                return;
            }

            _serverLoaded = true;

            if (_entitySession == null)
            {
                try
                {
                    _entitySession =
                        await ViewVariablesManager.RequestSession(new ViewVariablesEntitySelector(_entity.Uid));
                }
                catch (SessionDenyException e)
                {
                    var text = $"Server denied VV request: {e.Reason}";
                    _serverVariables.AddChild(new Label {
                        Text = text
                    });
                    _serverComponents.AddChild(new Label {
                        Text = text
                    });
                    return;
                }

                _membersBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobMembers>(_entitySession, new ViewVariablesRequestMembers());
            }

            var otherStyle = false;

            foreach (var propertyData in _membersBlob.Members)
            {
                var propertyEdit = new ViewVariablesPropertyControl(ViewVariablesManager, _resourceCache);
                propertyEdit.SetStyle(otherStyle = !otherStyle);
                var editor = propertyEdit.SetProperty(propertyData);
                editor.OnValueChanged += o =>
                                         ViewVariablesManager.ModifyRemote(_entitySession, new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) }, o);
                if (editor is ViewVariablesPropertyEditorReference refEditor)
                {
                    refEditor.OnPressed += () =>
                                           ViewVariablesManager.OpenVV(
                        new ViewVariablesSessionRelativeSelector(_entitySession.SessionId,
                                                                 new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) }));
                }

                _serverVariables.AddChild(propertyEdit);
            }

            var componentsBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobEntityComponents>(_entitySession, new ViewVariablesRequestEntityComponents());

            _serverComponents.DisposeAllChildren();
            componentsBlob.ComponentTypes.Sort();
            foreach (var componentType in componentsBlob.ComponentTypes.OrderBy(t => t.Stringified))
            {
                var button = new Button {
                    Text = componentType.Stringified, TextAlign = Button.AlignMode.Left
                };
                button.OnPressed += args =>
                {
                    ViewVariablesManager.OpenVV(
                        new ViewVariablesComponentSelector(_entity.Uid, componentType.Qualified));
                };
                _serverComponents.AddChild(button);
            }
        }
Beispiel #14
0
        private async void PopulateServerComponents(bool request = true)
        {
            _serverComponents.DisposeAllChildren();

            _serverComponents.AddChild(_serverComponentsSearchBar = new LineEdit
            {
                PlaceHolder         = Loc.GetString("Search"),
                SizeFlagsHorizontal = SizeFlags.FillExpand
            });

            _serverComponents.AddChild(_serverComponentsAddButton = new Button()
            {
                Text = Loc.GetString("Add Component"),
                SizeFlagsHorizontal = SizeFlags.FillExpand
            });

            _serverComponentsSearchBar.OnTextChanged += OnServerComponentsSearchBarChanged;
            _serverComponentsAddButton.OnPressed     += OnServerComponentsAddButtonPressed;

            if (!request || _entitySession == null)
            {
                return;
            }

            var componentsBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobEntityComponents>(_entitySession, new ViewVariablesRequestEntityComponents());

            componentsBlob.ComponentTypes.Sort();

            var componentTypes = componentsBlob.ComponentTypes.AsEnumerable();

            if (!string.IsNullOrEmpty(_serverComponentsSearchBar.Text))
            {
                componentTypes = componentTypes
                                 .Where(t => t.Stringified.Contains(_serverComponentsSearchBar.Text,
                                                                    StringComparison.InvariantCultureIgnoreCase));
            }

            componentTypes = componentTypes.OrderBy(t => t.Stringified);

            foreach (var componentType in componentTypes)
            {
                var button = new Button {
                    Text = componentType.Stringified, TextAlign = Label.AlignMode.Left
                };
                var removeButton = new TextureButton()
                {
                    StyleClasses        = { SS14Window.StyleClassWindowCloseButton },
                    SizeFlagsHorizontal = SizeFlags.ShrinkEnd
                };
                button.OnPressed += _ =>
                {
                    ViewVariablesManager.OpenVV(
                        new ViewVariablesComponentSelector(_entity.Uid, componentType.FullName));
                };
                removeButton.OnPressed += _ =>
                {
                    // We send a command to remove the component.
                    IoCManager.Resolve <IClientConsoleHost>().RemoteExecuteCommand(null, $"rmcomp {_entity.Uid} {componentType.ComponentName}");
                    PopulateServerComponents();
                };
                button.AddChild(removeButton);
                _serverComponents.AddChild(button);
            }
        }
Beispiel #15
0
        private async void _tabsOnTabChanged(int tab)
        {
            if (_serverLoaded || tab != TabServerComponents && tab != TabServerVars)
            {
                return;
            }

            _serverLoaded = true;

            if (_entitySession == null)
            {
                try
                {
                    _entitySession =
                        await ViewVariablesManager.RequestSession(new ViewVariablesEntitySelector(_entity.Uid));
                }
                catch (SessionDenyException e)
                {
                    var text = $"Server denied VV request: {e.Reason}";
                    _serverVariables.AddChild(new Label {
                        Text = text
                    });
                    _serverComponents.AddChild(new Label {
                        Text = text
                    });
                    return;
                }

                _membersBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobMembers>(_entitySession, new ViewVariablesRequestMembers());
            }

            var otherStyle = false;
            var first      = true;

            foreach (var(groupName, groupMembers) in _membersBlob !.MemberGroups)
            {
                ViewVariablesTraitMembers.CreateMemberGroupHeader(ref first, groupName, _serverVariables);

                foreach (var propertyData in groupMembers)
                {
                    var propertyEdit = new ViewVariablesPropertyControl(ViewVariablesManager, _resourceCache);
                    propertyEdit.SetStyle(otherStyle = !otherStyle);
                    var editor        = propertyEdit.SetProperty(propertyData);
                    var selectorChain = new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) };
                    editor.OnValueChanged += o => ViewVariablesManager.ModifyRemote(_entitySession, selectorChain, o);
                    editor.WireNetworkSelector(_entitySession.SessionId, selectorChain);

                    _serverVariables.AddChild(propertyEdit);
                }
            }

            var componentsBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobEntityComponents>(_entitySession, new ViewVariablesRequestEntityComponents());

            _serverComponents.DisposeAllChildren();

            _serverComponents.AddChild(_serverComponentsSearchBar = new LineEdit
            {
                PlaceHolder         = Loc.GetString("Search"),
                SizeFlagsHorizontal = SizeFlags.FillExpand
            });

            _serverComponentsSearchBar.OnTextChanged += OnServerComponentsSearchBarChanged;

            componentsBlob.ComponentTypes.Sort();

            var componentTypes = componentsBlob.ComponentTypes.AsEnumerable();

            if (!string.IsNullOrEmpty(_serverComponentsSearchBar.Text))
            {
                componentTypes = componentTypes
                                 .Where(t => t.Stringified.Contains(_serverComponentsSearchBar.Text,
                                                                    StringComparison.InvariantCultureIgnoreCase));
            }

            componentTypes = componentTypes.OrderBy(t => t.Stringified);

            foreach (var componentType in componentTypes)
            {
                var button = new Button {
                    Text = componentType.Stringified, TextAlign = Label.AlignMode.Left
                };
                button.OnPressed += args =>
                {
                    ViewVariablesManager.OpenVV(
                        new ViewVariablesComponentSelector(_entity.Uid, componentType.FullName));
                };
                _serverComponents.AddChild(button);
            }
        }
Beispiel #16
0
 public void ClearButtons()
 {
     _vboxContainer.DisposeAllChildren();
 }