예제 #1
0
        public void Place(HUDStandardItem hudItem, float dx, float dy)
        {
            Frame3f initFrame = hudItem.GetObjectFrame();
            Frame3f hudFrame  = HUDUtil.GetSphereFrame(Radius, dx, dy);

            hudItem.SetObjectFrame(
                initFrame.Translated(hudFrame.Origin)
                .Rotated(Quaternionf.FromTo(initFrame.Z, hudFrame.Z)));
        }
예제 #2
0
        public void Initialize(Cockpit cockpit, float fCockpitRadius)
        {
            activeCockpit = cockpit;
            activeCockpit.PositionMode = Cockpit.MovementMode.Static;
            activeCockpit.GrabFocus    = true;
            activeHUDRadius            = fCockpitRadius;

            string[] files, folders;
            try {
                files   = Source.GetFiles(FolderPath);
                folders = Source.GetFolders(FolderPath);
            } catch (Exception e) {
                Debug.Log("[CurrentFolderList.Initialize] exception! " + e.Message);
                return;
            }

            float fMinHorz = -45.0f, fMaxHorz = 45.0f;
            float fStartVert = 15.0f;
            float fTop       = HUDUtil.GetSphereFrame(fCockpitRadius, 0.0f, fStartVert).Origin.y;

            int folderi = 0, filei = 0;

            Mesh  folderMesh              = Resources.Load <Mesh>("icon_meshes/folder_v1");
            Color folderColor             = ColorUtil.make(241, 213, 146);
            Color inaccessibleFolderColor = ColorUtil.make(100, 100, 100);
            Mesh  fileMesh                = Resources.Load <Mesh>("icon_meshes/file_v1");
            Color fileColor               = ColorUtil.make(250, 250, 250);

            // [TODO] something wrong here, icons are loading backwards...??
            Quaternion meshRotation =
                Quaternion.AngleAxis(270.0f, Vector3.right) *
                Quaternion.AngleAxis(180.0f + 25.0f, Vector3.forward);
            float meshScale = IconSize * 0.9f;

            HUDCylinder hudSurf = new HUDCylinder()
            {
                Radius = fCockpitRadius, VerticalCoordIsAngle = false
            };
            float fStepH     = VRUtil.HorizontalStepAngle(fCockpitRadius, 0, IconSize + IconPadding);
            int   nStepsHorz = (int)((fMaxHorz - fMinHorz) / fStepH);

            fMinHorz = -(nStepsHorz * fStepH * 0.5f);
            fMaxHorz = (nStepsHorz * fStepH * 0.5f);
            float fStepV = IconSize + IconPadding;


            IconCollection = new HUDCollection();
            IconCollection.Create();

            bool bDone = false;
            int  yi    = 0;

            while (!bDone)
            {
                float fCurV = fTop - yi * fStepV;
                yi++;

                for (int xi = 0; xi < nStepsHorz && bDone == false; ++xi)
                {
                    float fCurH = fMinHorz + ((float)xi + 0.5f) * fStepH;

                    string name        = "x";
                    fMesh  useMesh     = null;
                    Color  useColor    = Color.white;
                    bool   bAccessible = true;
                    bool   bIsFile     = false;
                    if (folderi < folders.Length)
                    {
                        name     = folders[folderi++];
                        useMesh  = new fMesh(UnityEngine.Object.Instantiate <Mesh>(folderMesh));
                        useColor = folderColor;
                        if (Source.FilterInaccessibleFolders == false &&
                            FileSystemUtils.CanAccessFolder(Path.Combine(FolderPath, name)) == false)
                        {
                            bAccessible = false;
                            useColor    = inaccessibleFolderColor;
                        }
                    }
                    else if (filei < files.Length)
                    {
                        name     = files[filei++];
                        useMesh  = new fMesh(UnityEngine.Object.Instantiate <Mesh>(fileMesh));
                        useColor = fileColor;
                        bIsFile  = true;
                    }
                    else
                    {
                        bDone = true;
                        break;
                    }
                    //useColor.a = 0.999f;        // [RMS] can use this to force into alpha pass

                    string displayName = name;
                    if (displayName.Length > 12)
                    {
                        displayName = name.Substring(0, 12) + "...";
                    }

                    //float TextScale = 0.01f, ShiftX = -IconSize * 0.5f;
                    float TextScale = 0.005f, ShiftX = -IconSize * 0.5f;

                    HUDButton iconButton = HUDBuilder.CreateMeshClickButton(
                        useMesh, useColor, meshScale, meshRotation,
                        hudSurf, fCurH, fCurV,
                        new TextLabelGenerator()
                    {
                        Text = displayName, Scale = TextScale, Translate = new Vector3(ShiftX, 0.0f, 0.0f)
                    });
                    iconButton.Name = name;
                    //cockpit.AddUIElement(iconButton, true);
                    IconCollection.AddChild(iconButton);

                    if (bIsFile)
                    {
                        iconButton.OnClicked += (o, e) => {
                            if (this.OnFileClicked != null)
                            {
                                this.OnFileClicked(name);
                            }
                        };
                    }

                    if (bAccessible)
                    {
                        iconButton.OnDoubleClicked += IconButton_DoubleClick;
                    }
                }
            }

            cockpit.AddUIElement(IconCollection, true);
            fCurMaxScroll = Mathf.Max(0, (yi - 4) * fStepV);
        }