Exemplo n.º 1
0
        private void SetItemAtSerialized(int i, string serializedItem, MyObjectBuilder_ToolbarItem data)
        {
            if (!m_items.IsValidIndex(i))
            {
                return;
            }

            //old saves
            if (data == null)
            {
                if (String.IsNullOrEmpty(serializedItem))
                {
                    return;
                }

                var split = serializedItem.Split(':');
                MyObjectBuilderType typeId;

                if (!MyObjectBuilderType.TryParse(split[0], out typeId))
                {
                    return;
                }

                string subtypeString = (split.Length == 2) ? split[1] : null;
                var    defId         = new MyDefinitionId(typeId, subtypeString);

                SetItemAtSerializedCompat(i, defId);
            }

            //new saves
            else
            {
                SetItemAtIndexInternal(i, MyToolbarItemFactory.CreateToolbarItem(data), true);
            }
        }
Exemplo n.º 2
0
        public override MyObjectBuilder_ToolbarItem GetObjectBuilder()
        {
            // Lets try what happens, may be can avoid saving by this
            return(null);

            return((MyObjectBuilder_ToolbarItemEmpty)MyToolbarItemFactory.CreateObjectBuilder(this));
        }
        public static MyToolbarItem CreateToolbarItemFromInventoryItem(IMyInventoryItem inventoryItem)
        {
            var itemDefinitionId = inventoryItem.GetDefinitionId();
            MyDefinitionBase itemDefinition;

            if (MyDefinitionManager.Static.TryGetDefinition(itemDefinitionId, out itemDefinition))
            {
                if ((itemDefinition is MyPhysicalItemDefinition) || (itemDefinition is MyCubeBlockDefinition))
                {
                    var itemBuilder = MyToolbarItemFactory.ObjectBuilderFromDefinition(itemDefinition);
                    if (itemBuilder is MyObjectBuilder_ToolbarItemMedievalWeapon)
                    {
                        var meWeaponBuilder = itemBuilder as MyObjectBuilder_ToolbarItemMedievalWeapon;
                        meWeaponBuilder.ItemId = inventoryItem.ItemId;
                    }

                    if (itemBuilder != null && !(itemBuilder is MyObjectBuilder_ToolbarItemEmpty))
                    {
                        return(MyToolbarItemFactory.CreateToolbarItem(itemBuilder));
                    }
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        public void SetItemAtIndex(int i, MyDefinitionId defId, MyObjectBuilder_ToolbarItem data)
        {
            if (!m_items.IsValidIndex(i))
            {
                return;
            }

            MyDefinitionBase definition;

            if (MyDefinitionManager.Static.TryGetDefinition(defId, out definition))
            {
                SetItemAtIndex(i, MyToolbarItemFactory.CreateToolbarItem(data));
            }
        }
Exemplo n.º 5
0
        //THIS FUNCTION IS ONLY NEEDED FOR OLD SAVE COMPATIBILITY
        public void SetItemAtSerializedCompat(int i, MyDefinitionId defId)
        {
            if (!m_items.IsValidIndex(i))
            {
                return;
            }

            MyDefinitionBase definition;

            if (MyDefinitionManager.Static.TryGetDefinition(defId, out definition))
            {
                MyObjectBuilder_ToolbarItem data = MyToolbarItemFactory.ObjectBuilderFromDefinition(definition);
                SetItemAtIndexInternal(i, MyToolbarItemFactory.CreateToolbarItem(data), true);
            }
        }
Exemplo n.º 6
0
        public void SetDefaults(bool sendEvent = true)
        {
            if (m_toolbarType == MyToolbarType.Character)
            {
                MyDefinitionBase armorblock, cockpit, smallgenerator, smallthrust, gyro;
                MyDefinitionId   armorblockid     = new MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock");
                MyDefinitionId   cockpitid        = new MyDefinitionId(typeof(MyObjectBuilder_Cockpit), "LargeBlockCockpit");
                MyDefinitionId   smallgeneratorid = new MyDefinitionId(typeof(MyObjectBuilder_Reactor), "LargeBlockSmallGenerator");
                MyDefinitionId   smallthrustid    = new MyDefinitionId(typeof(MyObjectBuilder_Thrust), "LargeBlockSmallThrust");
                MyDefinitionId   gyroid           = new MyDefinitionId(typeof(MyObjectBuilder_Gyro), "LargeBlockGyro");

                int v = 0;
                if (MyDefinitionManager.Static.TryGetDefinition(armorblockid, out armorblock))
                {
                    SetItemAtIndex(v++, armorblockid, MyToolbarItemFactory.ObjectBuilderFromDefinition(armorblock));
                }
                if (MyDefinitionManager.Static.TryGetDefinition(cockpitid, out cockpit))
                {
                    SetItemAtIndex(v++, armorblockid, MyToolbarItemFactory.ObjectBuilderFromDefinition(cockpit));
                }
                if (MyDefinitionManager.Static.TryGetDefinition(smallgeneratorid, out smallgenerator))
                {
                    SetItemAtIndex(v++, armorblockid, MyToolbarItemFactory.ObjectBuilderFromDefinition(smallgenerator));
                }
                if (MyDefinitionManager.Static.TryGetDefinition(smallthrustid, out smallthrust))
                {
                    SetItemAtIndex(v++, armorblockid, MyToolbarItemFactory.ObjectBuilderFromDefinition(smallthrust));
                }
                if (MyDefinitionManager.Static.TryGetDefinition(gyroid, out gyro))
                {
                    SetItemAtIndex(v++, armorblockid, MyToolbarItemFactory.ObjectBuilderFromDefinition(gyro));
                }

                for (int i = v; i < m_items.Length; ++i)
                {
                    SetItemAtIndex(i, null);
                }

                m_currentColorMaskHSV = 0;
                SetDefaultColors();
            }
        }
Exemplo n.º 7
0
        public override MyObjectBuilder_ToolbarItem GetObjectBuilder()
        {
            MyObjectBuilder_ToolbarItemTerminalGroup output = (MyObjectBuilder_ToolbarItemTerminalGroup)MyToolbarItemFactory.CreateObjectBuilder(this);

            output.GroupName     = this.m_groupName.ToString();
            output.BlockEntityId = this.m_blockEntityId;
            output.Action        = this.ActionId;
            return(output);
        }
Exemplo n.º 8
0
        public sealed override MyObjectBuilder_ToolbarItem GetObjectBuilder()
        {
            //This can happen when using mods
            //Initially, the mod is used and an action is added to the toolbar. Later, the mod is removed, but the item is still present in the toolbar
            if (Definition == null)
            {
                return(null);
            }

            MyObjectBuilder_ToolbarItemDefinition output = (MyObjectBuilder_ToolbarItemDefinition)MyToolbarItemFactory.CreateObjectBuilder(this);

            output.DefinitionId = Definition.Id;
            return(output);
        }
Exemplo n.º 9
0
        public override MyObjectBuilder_ToolbarItem GetObjectBuilder()
        {
            if (Definition == null)
            {
                return(null);
            }

            MyObjectBuilder_ToolbarItemUsable builder = (MyObjectBuilder_ToolbarItemUsable)MyToolbarItemFactory.CreateObjectBuilder(this);

            builder.DefinitionId = Definition.Id;

            return(builder);
        }
        public override MyObjectBuilder_ToolbarItem GetObjectBuilder()
        {
            MyObjectBuilder_ToolbarItemTerminalBlock output = (MyObjectBuilder_ToolbarItemTerminalBlock)MyToolbarItemFactory.CreateObjectBuilder(this);

            output.BlockEntityId = this.m_blockEntityId;
            output.Action        = this.ActionId;

            output.Parameters.Clear();
            foreach (var item in m_parameters)
            {
                output.Parameters.Add(item.GetObjectBuilder());
            }

            return(output);
        }