Пример #1
0
 public List <ITerminalControl> GetControls(IMyTerminalBlock block)
 {
     if (m_customControlGetter != null)
     {
         // This is a double list copy :(
         var controlList = MyTerminalControlFactory.GetControls(block.GetType()).Cast <IMyTerminalControl>().ToList();
         m_customControlGetter(block, controlList);
         return(controlList.Cast <ITerminalControl>().ToList());
     }
     else
     {
         return(MyTerminalControlFactory.GetControls(block.GetType()).ToList());
     }
 }
Пример #2
0
 public List <ITerminalAction> GetActions(IMyTerminalBlock block)
 {
     if (m_customActionGetter != null)
     {
         // This is a double list copy :(
         var actionList = MyTerminalControlFactory.GetActions(block.GetType()).Cast <IMyTerminalAction>().ToList();
         m_customActionGetter(block, actionList);
         return(actionList.Cast <ITerminalAction>().ToList());
     }
     else
     {
         return(MyTerminalControlFactory.GetActions(block.GetType()).ToList());
     }
 }
Пример #3
0
        public void RemoveControl <TBlock>(IMyTerminalControl item)
        {
            if (!IsTypeValid <TBlock>())
            {
                return;
            }

            Type producedType = GetProducedType <TBlock>();

            if (producedType == null)
            {
                return;
            }

            MyTerminalControlFactory.RemoveControl(producedType, item);
        }
Пример #4
0
        public void AddControl <TBlock>(IMyTerminalControl item)
        {
            if (!IsTypeValid <TBlock>())
            {
                return;
            }

            Type producedType = GetProducedType <TBlock>();

            if (producedType == null)
            {
                return;
            }

            MyTerminalControlFactory.AddControl(producedType, (ITerminalControl)item);
            MyTerminalControlFactory.AddActions(producedType, (ITerminalControl)item);
        }
Пример #5
0
        public void RemoveAction <TBlock>(IMyTerminalAction action)
        {
            if (!IsTypeValid <TBlock>())
            {
                return;
            }

            Type producedType = GetProducedType <TBlock>();

            if (producedType == null)
            {
                return;
            }

            var blockList = MyTerminalControlFactory.GetList(producedType).Actions;

            blockList.Remove((ITerminalAction)action);
        }
Пример #6
0
        public void GetControls <TBlock>(out List <IMyTerminalControl> items)
        {
            items = new List <IMyTerminalControl>();
            if (!IsTypeValid <TBlock>())
            {
                return;
            }

            Type producedType = GetProducedType <TBlock>();

            if (producedType == null)
            {
                return;
            }

            var blockList = MyTerminalControlFactory.GetList(producedType);

            foreach (var item in blockList.Controls)
            {
                items.Add((IMyTerminalControl)item);
            }
        }
Пример #7
0
        /// <summary>
        /// This will create a control to be added to the terminal screen.  This only really applies to ModAPI, as MyTerminalControlFactory class isn't whitelist
        /// </summary>
        /// <typeparam name="TControl">Interface of control type</typeparam>
        /// <param name="blockType">Block type to add this control to</param>
        /// <param name="id">Identifier of this control</param>
        /// <returns>Interface of created control</returns>
        public TControl CreateControl <TControl, TBlock>(string id)
        {
            if (!IsTypeValid <TBlock>())
            {
                return(default(TControl));
            }

            Type producedType = GetProducedType <TBlock>();

            if (producedType == null)
            {
                return(default(TControl));
            }

            // Sanity check
            if (!typeof(MyTerminalBlock).IsAssignableFrom(producedType))
            {
                return(default(TControl));
            }

            if (!typeof(IMyTerminalControl).IsAssignableFrom(typeof(TControl)))
            {
                return(default(TControl));
            }

            if (!MyTerminalControlFactory.AreControlsCreated(producedType))
            {
                MyTerminalControlFactory.EnsureControlsAreCreated(producedType);
            }

            Type controlType = typeof(TControl);

            // This can be done better -- IMyTerminalControlXXX matches MyTerminalControlXXX, just see if I can
            // search for the classes in the assembly and map (interface) => (class).  Parameters may be an issue, but
            // I may just be able to pull parameter count and default all except for Id (might not be worth my time, just to save 19 lines of code)

            // Yes this is ugly, but I have to work around the fact that both MyTerminalControls and all block entities are not whitelisted, and the
            // control system expects both of those things.  So I need to wrap them for mods.
            if (controlType == typeof(IMyTerminalControlTextbox))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlTextbox <>), producedType, new object[] { id, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty }));
            }
            else if (controlType == typeof(IMyTerminalControlButton))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlButton <>), producedType, new object[] { id, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty, null }));
            }
            else if (controlType == typeof(IMyTerminalControlCheckbox))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlCheckbox <>), producedType, new object[] { id, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty }));
            }
            else if (controlType == typeof(IMyTerminalControlColor))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlColor <>), producedType, new object[] { id, MyStringId.NullOrEmpty }));
            }
            else if (controlType == typeof(IMyTerminalControlCombobox))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlCombobox <>), producedType, new object[] { id, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty }));
            }
            else if (controlType == typeof(IMyTerminalControlListbox))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlListbox <>), producedType, new object[] { id, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty, false, 0 }));
            }
            else if (controlType == typeof(IMyTerminalControlOnOffSwitch))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlOnOffSwitch <>), producedType, new object[] { id, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty }));
            }
            else if (controlType == typeof(IMyTerminalControlSeparator))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlSeparator <>), producedType, new object[] { }));
            }
            else if (controlType == typeof(IMyTerminalControlSlider))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlSlider <>), producedType, new object[] { id, MyStringId.NullOrEmpty, MyStringId.NullOrEmpty }));
            }
            else if (controlType == typeof(IMyTerminalControlLabel))
            {
                return(CreateGenericControl <TControl>(typeof(MyTerminalControlLabel <>), producedType, new object[] { MyStringId.NullOrEmpty }));
            }

            return(default(TControl));
        }