Пример #1
0
        public static ToolbarEntity GetCurrent(ToolbarLocation location)
        {
            var isAllowed = Schema.Current.GetInMemoryFilter <ToolbarEntity>(userInterface: true);

            var result = Toolbars.Value.Values
                         .Where(t => isAllowed(t) && t.Location == location)
                         .OrderByDescending(a => a.Priority)
                         .FirstOrDefault();

            return(result);
        }
Пример #2
0
 public void SetToolbarItem(string name, ToolbarLocation toolbarLocation)
 {
     if (IsWeapon(name))
     {
         SetToolbarWeapon(toolbarLocation.Slot, toolbarLocation.Page, name);
     }
     else
     {
         SetToolbarBlock(toolbarLocation.Slot, toolbarLocation.Page, name);
     }
 }
Пример #3
0
        private void SetToolbarItem <T>(MyDefinitionId id, ToolbarLocation toolbarLocation)
            where T : MyObjectBuilder_ToolbarItemDefinition, new()
        {
            var toolbarItemBuilder = MyObjectBuilderSerializer.CreateNewObject <T>();

            toolbarItemBuilder.DefinitionId = id;

            var toolbar = m_session.Character.Toolbar;

            toolbar.SwitchToPage(toolbarLocation.Page);
            var item = MyToolbarItemFactory.CreateToolbarItem(toolbarItemBuilder);

            toolbar.SetItemAtSlot(toolbarLocation.Slot, item);
        }
Пример #4
0
        public void SetToolbarItem(DefinitionId definitionId, ToolbarLocation toolbarLocation)
        {
            var myDefinitionId = definitionId.ToMyDefinitionId();

            Definitions.CheckDefinitionIdExists(myDefinitionId);
            if (IsWeapon(definitionId.Type))
            {
                SetToolbarItem <MyObjectBuilder_ToolbarItemWeapon>(myDefinitionId, toolbarLocation);
            }
            else
            {
                SetToolbarItem <MyObjectBuilder_ToolbarItemCubeBlock>(myDefinitionId, toolbarLocation);
            }
        }
Пример #5
0
        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        // --------------------------------------------------------------------------------------------
        protected ToolWindowPane()
        {
            _BitmapIndex      = -1;
            _BitmapResourceID = -1;
            _ToolBarLocation  = ToolbarLocation.Top;

            // --- Obtain attributes of the class
            foreach (object attr in GetType().GetCustomAttributes(false))
            {
                var captionAttr = attr as InitialCaptionAttribute;
                if (captionAttr != null)
                {
                    Caption = ResourceResolver <TPackage> .GetString(captionAttr.Value);

                    continue;
                }
                var resIdAttr = attr as BitmapResourceIdAttribute;
                if (resIdAttr != null)
                {
                    BitmapResourceID = resIdAttr.ResourceId;
                    BitmapIndex      = resIdAttr.BitmapIndex;
                    continue;
                }
                var toolbarAttr = attr as ToolbarAttribute;
                if (toolbarAttr != null)
                {
                    var toolbarProvider =
                        Activator.CreateInstance(toolbarAttr.Value) as IToolbarProvider;
                    if (toolbarProvider != null)
                    {
                        ToolBar = toolbarProvider.CommandId;
                    }
                    continue;
                }
                var toolLocAttr = attr as ToolbarLocationAttribute;
                if (toolLocAttr != null)
                {
                    _ToolBarLocation = toolLocAttr.Location;
                    continue;
                }
            }
        }
Пример #6
0
        public void EquipToolbarItem(ToolbarLocation toolbarLocation, bool allowSizeChange)
        {
            var toolbar = m_session.Character.Toolbar;

            toolbar.SwitchToPageOrNot(toolbarLocation.Page);

            if (!allowSizeChange && toolbar.SelectedSlot.HasValue &&
                (toolbar.SelectedSlot.Value == toolbarLocation.Slot))
            {
                return; // Already set (setting it again would change grid size).
            }
            var toolbarItem = toolbar[toolbarLocation.Slot];

            if (toolbarItem is MyToolbarItemWeapon weapon)
            {
                // Very dirty and fast hack, but works for tools, needs more sophistication.
                m_session.Character.SwitchToWeapon(weapon);
            }
            else
            {
                toolbar.ActivateItemAtSlot(toolbarLocation.Slot);
            }
        }
Пример #7
0
        public static ToolbarResponse GetCurrentToolbarResponse(ToolbarLocation location)
        {
            var curr = GetCurrent(location);

            if (curr == null)
            {
                return(null);
            }

            var responses = ToResponseList(curr.Elements);

            if (responses.Count == 0)
            {
                return(null);
            }

            return(new ToolbarResponse
            {
                type = ToolbarElementType.Menu,
                content = curr.ToLite(),
                label = curr.Name,
                elements = responses,
            });
        }
Пример #8
0
        public static ToolbarResponse?GetCurrentToolbarResponse(ToolbarLocation location)
        {
            var curr = GetCurrent(location);

            if (curr == null)
            {
                return(null);
            }

            var responses = ToResponseList(TranslatedInstanceLogic.TranslatedMList(curr, c => c.Elements).ToList());

            if (responses.Count == 0)
            {
                return(null);
            }

            return(new ToolbarResponse
            {
                type = ToolbarElementType.Header,
                content = curr.ToLite(),
                label = TranslatedInstanceLogic.TranslatedField(curr, a => a.Name),
                elements = responses,
            });
        }
 void SetToolbarItem(string name, ToolbarLocation toolbarLocation)
 {
     m_se.Items.SetToolbarItem(name, toolbarLocation);
 }
 void Equip(ToolbarLocation toolbarLocation)
 {
     m_se.Items.Equip(toolbarLocation);
 }
Пример #11
0
 // --------------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes the toolbar location of the tool window pane.
 /// </summary>
 /// <param name="location">Location of the toolbar.</param>
 // --------------------------------------------------------------------------------------------
 public ToolbarLocationAttribute(ToolbarLocation location)
 {
     Location = location;
 }
Пример #12
0
 public void Equip(ToolbarLocation toolbarLocation)
 {
     EquipToolbarItem(toolbarLocation, false);
 }
Пример #13
0
 public ToolbarResponse Current(ToolbarLocation location)
 {
     return(ToolbarLogic.GetCurrentToolbarResponse(location));
 }
Пример #14
0
 public void SetToolbarItem(string name, ToolbarLocation toolbarLocation)
 {
     Enqueue(() => m_items.SetToolbarItem(name, toolbarLocation));
 }
Пример #15
0
 public void Equip(ToolbarLocation toolbarLocation)
 {
     Enqueue(() => m_items.Equip(toolbarLocation));
 }
Пример #16
0
 public void Equip(ToolbarLocation toolbarLocation)
 {
 }
Пример #17
0
 public void SetToolbarItem(string name, ToolbarLocation toolbarLocation)
 {
 }
Пример #18
0
 // --------------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes the toolbar location of the tool window pane.
 /// </summary>
 /// <param name="location">Location of the toolbar.</param>
 // --------------------------------------------------------------------------------------------
 public ToolbarLocationAttribute(ToolbarLocation location)
 {
     Location = location;
 }