Esempio n. 1
0
        public static SerializableDefinitionId GetSelectedHotbarDefinition(IMyShipController cockpit)        //, ref int index)
        {
            if (cockpit == null)
            {
                return(default(SerializableDefinitionId));
            }

            MyObjectBuilder_ShipController builder = cockpit.GetObjectBuilderCubeBlock(false) as MyObjectBuilder_ShipController;

            int?slotIndex = builder?.Toolbar?.SelectedSlot;

            if (!slotIndex.HasValue)
            {
                return(default(SerializableDefinitionId));
            }

            MyObjectBuilder_Toolbar toolbar = builder.Toolbar;

            if (toolbar.Slots.Count <= slotIndex.Value)
            {
                return(default(SerializableDefinitionId));
            }

            var item = toolbar.Slots[slotIndex.Value];

            if (!(item.Data is MyObjectBuilder_ToolbarItemWeapon))
            {
                return(default(SerializableDefinitionId));
            }

            //index = toolbar.SelectedSlot.Value;
            return((item.Data as MyObjectBuilder_ToolbarItemWeapon).defId);
        }
Esempio n. 2
0
        public static SerializableDefinitionId GetWeaponDef(IMyShipController cockpit, ref int index)
        {
            MyObjectBuilder_ShipController builder = cockpit.GetObjectBuilderCubeBlock(false) as MyObjectBuilder_ShipController;

            if (builder == null || builder.Toolbar == null || !builder.Toolbar.SelectedSlot.HasValue)
            {
                return(default(SerializableDefinitionId));
            }

            MyObjectBuilder_Toolbar toolbar = builder.Toolbar;
            var item = toolbar.Slots[toolbar.SelectedSlot.Value];

            if (!(item.Data is MyObjectBuilder_ToolbarItemWeapon))
            {
                return(default(SerializableDefinitionId));
            }

            index = toolbar.SelectedSlot.Value;
            return((item.Data as MyObjectBuilder_ToolbarItemWeapon).defId);
        }