Example #1
0
        public override Capture UpdateCapture(InputState input, CaptureData data)
        {
            bool       bReleased = false;
            bool       bContinue = false;
            InputEvent e         = null;

            if (input.IsForDevice(InputDevice.Mouse))
            {
                bReleased = input.bRightMouseReleased;
                bContinue = input.bRightMouseDown;
                e         = InputEvent.Mouse(input);
            }
            else if (input.IsForDevice(InputDevice.Gamepad))
            {
                bReleased = input.bRightTriggerReleased;
                bContinue = input.bRightTriggerDown;
                e         = InputEvent.Gamepad(input);
            }
            else if (input.IsForDevice(InputDevice.AnySpatialDevice))
            {
                bReleased =
                    (data.which == CaptureSide.Left && input.bXButtonReleased) ||
                    (data.which == CaptureSide.Right && input.bAButtonReleased);
                bContinue =
                    (data.which == CaptureSide.Left && input.bXButtonDown) ||
                    (data.which == CaptureSide.Right && input.bAButtonDown);
                e = InputEvent.Spatial(data.which, input);
            }


            if (bReleased)
            {
                UIRayHit hit = new UIRayHit();
                if (popup.FindRayIntersection(e.ray, out hit))
                {
                    popup.EndCapture(e);
                }

                // do animated dismiss that will destroy menu on completion
                HUDUtil.AnimatedDimiss_Scene(popup, cockpit.Scene, true, 0.2f);

                // lose our reference
                popup = null;

                return(Capture.End);
            }
            else if (bContinue)
            {
                popup.UpdateCapture(e);
                return(Capture.Continue);
            }
            // should never get here...
            DebugUtil.Log(2, "[RightClickBehavior::UpdateCapture] how did we get here?");
            return(Capture.End);
        }
    ActivateToolButton add_tool_button(Cockpit cockpit, string sName,
                                       float fHUDRadius, float dx, float dy,
                                       float fButtonRadius,
                                       Material bgMaterial, Material activeMaterial, toolInfo info)
    {
        ActivateToolButton button = new ActivateToolButton()
        {
            TargetScene = cockpit.Scene,
            ToolType    = info.identifier
        };

        button.CreateMeshIconButton(fButtonRadius, info.sMeshPath, bgMaterial, info.fMeshScaleFudge);
        HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy);
        button.Name = sName;

        if (info.identifier == "cancel")
        {
            button.OnClicked += (s, e) => {
                int nSide = InputState.IsHandedDevice(e.device) ? (int)e.side : 1;
                cockpit.Context.ToolManager.DeactivateTool((ToolSide)nSide);
                if (activeButtons[nSide] != null)
                {
                    activeButtons[nSide].SetBackgroundMaterial(bgMaterial);
                    activeButtons[nSide] = null;
                }
            };
        }
        else
        {
            button.OnClicked += (s, e) => {
                int nSide = InputState.IsHandedDevice(e.device) ? (int)e.side : 1;
                cockpit.Context.ToolManager.SetActiveToolType(info.identifier, (ToolSide)nSide);
                cockpit.Context.ToolManager.ActivateTool((ToolSide)nSide);
                if (activeButtons[nSide] != null)
                {
                    activeButtons[nSide].SetBackgroundMaterial(bgMaterial);
                }
                activeButtons[nSide] = button;
                button.SetBackgroundMaterial(activeMaterial);
            };
        }
        return(button);
    }
Example #3
0
        public static void DoGCodeExport()
        {
            if (CC.Toolpather.CurrentGCode == null)
            {
                HUDUtil.ShowCenteredPopupMessage("Sorry", "Cannot Export GCode until Toolpaths are generated!", CC.ActiveCockpit);
                return;
            }

            int skipWarning = FPlatform.GetPrefsInt("WarnAboutGCodeExport", 0);

            if (skipWarning == 0)
            {
                ExportGCodeWarningDialog.ShowDialog();
            }
            else
            {
                DoGCodeExportInteractive();
            }
        }
    DropPrimitiveButton add_primitive_button(Cockpit cockpit, string sName, float fHUDRadius, float dx, float dy,
                                             PrimitiveType primType, SOType soType, float fPrimRadiusScale,
                                             Material bgMaterial, Material primMaterial,
                                             Func <SceneObject> CreatePrimitiveF,
                                             IGameObjectGenerator customGenerator = null
                                             )
    {
        float fButtonRadius = 0.08f;

        DropPrimitiveButton button = new DropPrimitiveButton()
        {
            TargetScene     = cockpit.Scene,
            CreatePrimitive = CreatePrimitiveF
        };

        button.Create(fButtonRadius, bgMaterial);
        var gen = (customGenerator != null) ? customGenerator :
                  new primitiveIconGenerator()
        {
            PrimType = primType, PrimMaterial = primMaterial, PrimSize = fButtonRadius * fPrimRadiusScale
        };

        button.AddVisualElements(gen.Generate(), true);
        HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy);
        button.Name       = sName;
        button.OnClicked += (s, e) => {
            cockpit.Scene.DefaultPrimitiveType = soType;
        };
        button.OnDoubleClicked += (s, e) => {
            // [TODO] could have a lighter record here because we can easily recreate primitive...
            cockpit.Scene.History.PushChange(
                new AddSOChange()
            {
                scene = cockpit.Scene, so = CreatePrimitiveF()
            });
            cockpit.Scene.History.PushInteractionCheckpoint();
        };
        return(button);
    }
Example #5
0
        public override Capture BeginCapture(InputState input, CaptureSide eSide)
        {
            if (input.LeftCaptureActive || input.RightCaptureActive || popup != null)
            {
                DebugUtil.Warning("SceneRightClickBehavior.BeginCapture - we should not be here...");
                return(Capture.Ignore);
            }

            Ray3f useRay = new Ray3f(Vector3f.Zero, Vector3f.AxisY);

            if (input.IsForDevice(InputDevice.Mouse) || input.IsForDevice(InputDevice.Gamepad))
            {
                useRay = (input.bRightMousePressed) ? input.vMouseWorldRay : input.vGamepadWorldRay;
            }
            else if (input.IsForDevice(InputDevice.AnySpatialDevice))
            {
                useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
            }

            // raycast into scene to find hit object/position for menu. We try Pivots first,
            // because they are special and have priority (?? always ??). Then we cast into general scene.
            SORayHit  pivotHit;
            bool      bHitPivot = cockpit.Scene.FindSORayIntersection(useRay, out pivotHit, (x) => { return(x is PivotSO); });
            AnyRayHit rayHit;

            if (bHitPivot)
            {
                rayHit = new AnyRayHit(pivotHit);
            }
            else
            {
                if (cockpit.Scene.FindSceneRayIntersection(useRay, out rayHit) == false)
                {
                    return(Capture.Ignore);
                }
            }

            // find center of menu in space
            Vector3f vHUDCenter   = cockpit.RootGameObject.GetPosition();
            Vector3f menuLocation = rayHit.hitPos;

            if (Placement == PlacementMode.OnHUDSphere)
            {
                float fRayT;
                bool  bHit = RayIntersection.Sphere(useRay.Origin, useRay.Direction,
                                                    vHUDCenter, HUDRadius, out fRayT);
                Debug.Assert(bHit);
                menuLocation = useRay.Origin + fRayT * useRay.Direction;
            }

            // compute extents
            float fDiameter = VRUtil.GetVRRadiusForVisualAngle(
                menuLocation, cockpit.ActiveCamera.GetPosition(), VisualDiameter);

            if (rayHit.eType == HitType.SceneObjectHit && rayHit.hitSO is PivotSO)
            {
                popup = GeneratePivotRadialMenu(fDiameter, rayHit.hitSO as PivotSO);
            }
            else if (rayHit.eType == HitType.SceneObjectHit)
            {
                popup = GenerateSceneObjectRadialMenu(fDiameter, rayHit);
            }
            else
            {
                popup = GenerateDefaultRadialMenu(fDiameter, rayHit);
            }
            popup.Create();
            popup.Name = "popup_menu";

            if (Placement == PlacementMode.InScene)
            {
                HUDUtil.PlaceInScene(popup, vHUDCenter, menuLocation);
            }
            else
            {
                HUDUtil.PlaceInSphere(popup, HUDRadius, vHUDCenter, menuLocation);
            }

            // this is a bit of a hack...radial menu lives in-scene, if we attach it to
            //   cockpit then it will move with cockpit, which is wrong. So we want to
            //   stick it in the scene. But, at least for now, we still want it to be
            //   drawn in the cockpit layer, so we add to cockpit first, them remove and
            //   re-add to the scene
            cockpit.AddUIElement(popup, false);
            cockpit.RemoveUIElement(popup, false);
            cockpit.Scene.AddUIElement(popup, false);

            HUDUtil.AnimatedShow(popup, 0.2f);

            return(Capture.Begin(this, eSide));
        }