Пример #1
0
        internal void MapGroupClones(HashSet <InstanceState> m_states, CloneActionBase action)
        {
            if (!Enabled)
            {
                return;
            }

            Logic.MapGroupClones(m_states, action);
        }
Пример #2
0
        private void OnLeftMouseDown()
        {
            DebugUtils.Log("OnLeftMouseDown: " + ToolState);

            Vector3 mousePos = RaycastMouseLocation();

            if (ToolState == ToolStates.Default)
            {
                if (marqueeSelection && (m_hoverInstance == null || !Action.selection.Contains(m_hoverInstance)))
                {
                    m_selection        = default;
                    m_marqueeInstances = null;

                    SetToolState(ToolStates.DrawingSelection);
                }

                m_lastInstance = m_hoverInstance;

                m_sensitivityTogglePosAbs = mousePos;
                m_clickPositionAbs        = mousePos;
            }
            else if (ToolState == ToolStates.MouseDragging)
            {
                TransformAction action = ActionQueue.instance.current as TransformAction;
                m_dragStartRelative = action.moveDelta;
                UpdateSensitivityMode();

                m_sensitivityTogglePosAbs = mousePos;
                m_clickPositionAbs        = mousePos;
            }
            else if (ToolState == ToolStates.Cloning)
            {
                CloneActionBase action = ActionQueue.instance.current as CloneActionBase;
                action.followTerrain = followTerrain;

                if (POProcessing == 0)
                {
                    SetToolState();
                    m_nextAction = ToolAction.Do;

                    UpdateSensitivityMode();
                }
            }
        }
Пример #3
0
        internal void MapGroupClones(HashSet <InstanceState> m_states, CloneActionBase action)
        {
            action.m_POGroupMap = new Dictionary <PO_Group, PO_Group>();

            foreach (InstanceState state in m_states)
            {
                if (state is ProcState poState)
                {
                    MoveableProc mpo = (MoveableProc)poState.instance;
                    if (mpo.m_procObj.Group is null)
                    {
                        continue;
                    }

                    if (!action.m_POGroupMap.ContainsKey(mpo.m_procObj.Group))
                    {
                        action.m_POGroupMap.Add(mpo.m_procObj.Group, new PO_Group());
                    }
                }
            }
        }
Пример #4
0
        public IEnumerator <object> RetrieveClone(MoveableProc original, Vector3 position, float angle, Action action)
        {
            const uint      MaxAttempts = 100_000;
            CloneActionBase ca          = (CloneActionBase)action;

            if (!(original.m_procObj is PO_Object))
            {
                Log.Info($"PO Cloning failed: object not found");
                MoveItTool.POProcessing--;
                yield break;
            }

            Type[] types          = new Type[] { tPO, tPO.MakeByRefType(), typeof(uint).MakeByRefType() };
            object originalObject = original.m_procObj.GetProceduralObject();

            object[]   paramList = new[] { originalObject, null, null };
            MethodInfo retrieve  = tPOMoveIt.GetMethod("TryRetrieveClone", BindingFlags.Public | BindingFlags.Static, null, types, null);

            if (retrieve == null)
            {
                Log.Info($"PO Cloning failed: retrieve not found");
                MoveItTool.POProcessing--;
                yield break;
            }

            uint c = 0;

            while (c < MaxAttempts && !(bool)retrieve.Invoke(null, paramList))
            {
                //if (c % 100 == 0)
                //{
                //    BindingFlags f = BindingFlags.Static | BindingFlags.Public;
                //    object queueObj = tPOMoveIt.GetField("queuedCloning", f).GetValue(null);
                //    int queueCount = (int)queueObj.GetType().GetProperty("Count").GetValue(queueObj, null);
                //    object doneObj = tPOMoveIt.GetField("doneCloning", f).GetValue(null);
                //    int doneCount = (int)doneObj.GetType().GetProperty("Count").GetValue(doneObj, null);
                //}
                c++;
                yield return(new WaitForSeconds(0.05f));
            }

            if (c == MaxAttempts)
            {
                throw new Exception($"Failed to clone object #{original.m_procObj.Id}! [PO-F4]");
            }

            try
            {
                PO_Object clone = new PO_Object(paramList[1])
                {
                    POColor = original.m_procObj.POColor
                };

                if (original.m_procObj.Group != null && action is CloneActionBase cloneAction)
                {
                    if (!cloneAction.m_POGroupMap.ContainsKey(original.m_procObj.Group))
                    {
                        Log.Debug($"Clone Error: {original.m_procObj.Id}'s group isn't in group map");
                    }
                    else
                    {
                        clone.Group = cloneAction.m_POGroupMap[original.m_procObj.Group];
                        clone.Group.AddObject(clone);
                        if (original.m_procObj.isGroupRoot())
                        {
                            clone.Group.SetNewRoot(clone);
                        }
                    }
                }

                InstanceID cloneID = default;
                cloneID.NetLane = clone.Id;
                MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, clone);

                MoveableProc cloneInstance = new MoveableProc(cloneID)
                {
                    position = position,
                    angle    = angle
                };

                Action.selection.Add(cloneInstance);
                ca.m_clones.Add(cloneInstance);
                ca.m_origToClone.Add(original, cloneInstance);

                MoveItTool.SetToolState();
                MoveItTool.instance.ProcessSensitivityMode(false);
                Log.Info($"Cloned PO {original.m_procObj.Id} to #{clone.Id}");
            }
            catch (Exception e)
            {
                Log.Error($"Exception when cloning PO:\n{e}");
            }

            yield return(new WaitForSeconds(0.25f));

            MoveItTool.POProcessing--;
        }
Пример #5
0
        protected override void OnToolUpdate()
        {
            if (m_nextAction != ToolAction.None)
            {
                return;
            }

            if (m_pauseMenu != null && m_pauseMenu.isVisible)
            {
                if (ToolState == ToolStates.Default || ToolState == ToolStates.MouseDragging || ToolState == ToolStates.DrawingSelection)
                {
                    ToolsModifierControl.SetTool <DefaultTool>();
                }

                StopCloning();
                StopTool();

                SetToolState();

                UIView.library.Hide("PauseMenu");

                return;
            }

            lock (ActionQueue.instance)
            {
                bool isInsideUI = this.m_toolController.IsInsideUI;

                if (m_leftClickTime == 0 && Input.GetMouseButton(0))
                {
                    if (!isInsideUI)
                    {
                        m_leftClickTime = Stopwatch.GetTimestamp();
                        OnLeftMouseDown();
                    }
                }

                if (m_leftClickTime != 0)
                {
                    long elapsed = ElapsedMilliseconds(m_leftClickTime);

                    if (!Input.GetMouseButton(0))
                    {
                        m_leftClickTime = 0;

                        if (elapsed < 250)
                        {
                            try
                            {
                                OnLeftClick();
                            }
                            catch (MissingMethodException e)
                            {
                                Log.Debug("Prop Painter [OnLeftClick] error: " + e.ToString());
                            }
                        }
                        else
                        {
                            OnLeftDragStop();
                        }

                        try
                        {
                            OnLeftMouseUp();
                        }
                        catch (MissingMethodException e)
                        {
                            Log.Debug("Prop Painter [OnLeftMouseUp] error: " + e.ToString());
                        }
                    }
                    else if (elapsed >= 250)
                    {
                        OnLeftDrag();
                    }
                }

                if (m_rightClickTime == 0 && Input.GetMouseButton(1))
                {
                    if (!isInsideUI)
                    {
                        m_rightClickTime = Stopwatch.GetTimestamp();
                        OnRightMouseDown();
                    }
                }

                if (m_rightClickTime != 0)
                {
                    long elapsed = ElapsedMilliseconds(m_rightClickTime);

                    if (!Input.GetMouseButton(1))
                    {
                        m_rightClickTime = 0;

                        if (elapsed < 250)
                        {
                            OnRightClick();
                        }
                        else
                        {
                            OnRightDragStop();
                        }

                        OnRightMouseUp();
                    }
                    else if (elapsed >= 250)
                    {
                        OnRightDrag();
                    }
                }

                if (m_middleClickTime == 0 && Input.GetMouseButton(2) && Event.current.control)
                {
                    if (!isInsideUI)
                    {
                        m_middleClickTime = Stopwatch.GetTimestamp();
                        OnMiddleMouseDown();
                    }
                }

                if (m_middleClickTime != 0)
                {
                    long elapsed = ElapsedMilliseconds(m_middleClickTime);

                    if (!Input.GetMouseButton(2))
                    {
                        m_middleClickTime = 0;

                        if (elapsed < 250)
                        {
                            OnMiddleClick();
                        }
                        else
                        {
                            OnMiddleDragStop();
                        }

                        OnMiddleMouseUp();
                    }
                    else if (elapsed >= 250)
                    {
                        OnMiddleDrag();
                    }
                }

                if (!isInsideUI && Cursor.visible)
                {
                    Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);

                    m_hoverInstance    = null;
                    m_marqueeInstances = null;
                    m_segmentGuide     = default;

                    switch (ToolState)
                    {
                    case ToolStates.Default:
                    case ToolStates.Aligning:
                    case ToolStates.Picking:
                    case ToolStates.ToolActive:
                    {
                        RaycastHoverInstance(mouseRay);
                        break;
                    }

                    case ToolStates.MouseDragging:
                    {
                        TransformAction action = ActionQueue.instance.current as TransformAction;

                        Vector3 newMove      = action.moveDelta;
                        float   newAngle     = action.angleDelta;
                        float   newSnapAngle = 0f;

                        if (snapping)
                        {
                            action.Virtual = false;
                        }
                        else
                        {
                            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                            {
                                action.Virtual = !fastMove;
                            }
                            else
                            {
                                action.Virtual = fastMove;
                            }
                        }

                        if (m_leftClickTime > 0 != m_middleClickTime > 0)
                        {
                            UpdateSensitivityMode();

                            float y = action.moveDelta.y;

                            if (m_isLowSensitivity || m_middleClickTime > 0)
                            {
                                Vector3 mouseDeltaBefore = m_sensitivityTogglePosAbs - m_clickPositionAbs;
                                Vector3 mouseDeltaAfter  = (RaycastMouseLocation(mouseRay) - m_sensitivityTogglePosAbs) / 5f;
                                newMove = m_dragStartRelative + mouseDeltaBefore + mouseDeltaAfter;
                            }
                            else
                            {
                                newMove = m_dragStartRelative + (RaycastMouseLocation(mouseRay) - m_clickPositionAbs);
                            }

                            newMove.y = y;
                        }

                        if (m_rightClickTime > 0)
                        {
                            UpdateSensitivityMode();

                            if (m_isLowSensitivity)
                            {
                                float mouseRotateBefore = m_sensitivityTogglePosX - m_sensitivityAngleOffset;
                                float mouseRotateAfter  = (Input.mousePosition.x - m_sensitivityTogglePosX) / 5;
                                float mouseTravel       = (mouseRotateBefore + mouseRotateAfter - m_mouseStartX) / Screen.width * 1.2f;

                                newAngle = ushort.MaxValue * 9.58738E-05f * mouseTravel;
                            }
                            else
                            {
                                newAngle = ushort.MaxValue * 9.58738E-05f * (Input.mousePosition.x - m_mouseStartX) / Screen.width * 1.2f;
                            }
                            if (Event.current.alt)
                            {
                                float quarterPI = Mathf.PI / 4;
                                newAngle = quarterPI * Mathf.Round(newAngle / quarterPI);
                            }
                            newAngle        += m_startAngle;
                            action.autoCurve = false;
                        }
                        else if (snapping)
                        {
                            newMove = GetSnapDelta(newMove, newAngle, action.center, out action.autoCurve);

                            if (action.autoCurve)
                            {
                                action.segmentCurve = m_segmentGuide;
                            }
                        }
                        else
                        {
                            action.autoCurve = false;
                        }

                        if (action.moveDelta != newMove || action.angleDelta != newAngle || action.snapAngle != newSnapAngle)
                        {
                            action.moveDelta     = newMove;
                            action.angleDelta    = newAngle;
                            action.snapAngle     = newSnapAngle;
                            action.followTerrain = followTerrain;
                            m_nextAction         = ToolAction.Do;
                        }

                        UIToolOptionPanel.RefreshSnapButton();
                        break;
                    }

                    case ToolStates.Cloning:
                    {
                        if (m_rightClickTime != 0)
                        {
                            break;
                        }

                        UpdateSensitivityMode();

                        CloneActionBase action = ActionQueue.instance.current as CloneActionBase;

                        Vector3 newMove;
                        float   y = action.moveDelta.y;
                        if (m_isLowSensitivity)
                        {
                            Vector3 mouseDeltaBefore = m_sensitivityTogglePosAbs - m_clickPositionAbs;
                            Vector3 mouseDeltaAfter  = (RaycastMouseLocation(mouseRay) - m_sensitivityTogglePosAbs) / 5;
                            newMove = mouseDeltaBefore + mouseDeltaAfter;
                        }
                        else
                        {
                            newMove = RaycastMouseLocation(mouseRay) - action.center;
                        }
                        newMove.y = y;

                        if (snapping)
                        {
                            newMove = GetSnapDelta(newMove, action.angleDelta, action.center, out bool autoCurve);
                        }

                        if (action.moveDelta != newMove)
                        {
                            action.moveDelta = newMove;
                        }

                        UIToolOptionPanel.RefreshSnapButton();
                        break;
                    }

                    case ToolStates.RightDraggingClone:
                    {
                        UpdateSensitivityMode();

                        CloneActionBase action = ActionQueue.instance.current as CloneActionBase;

                        float newAngle;

                        if (m_isLowSensitivity)
                        {
                            float mouseRotateBefore = m_sensitivityTogglePosX - m_sensitivityAngleOffset;
                            float mouseRotateAfter  = (Input.mousePosition.x - m_sensitivityTogglePosX) / 5;
                            float mouseTravel       = (mouseRotateBefore + mouseRotateAfter - m_mouseStartX) / Screen.width * 1.2f;

                            newAngle = ushort.MaxValue * 9.58738E-05f * mouseTravel;
                        }
                        else
                        {
                            newAngle = ushort.MaxValue * 9.58738E-05f * (Input.mousePosition.x - m_mouseStartX) / Screen.width * 1.2f;
                        }

                        if (Event.current.alt)
                        {
                            float quarterPI = Mathf.PI / 4;
                            newAngle = quarterPI * Mathf.Round(newAngle / quarterPI);
                        }
                        newAngle += m_startAngle;

                        if (action.angleDelta != newAngle)
                        {
                            action.angleDelta = newAngle;
                        }

                        UIToolOptionPanel.RefreshSnapButton();
                        break;
                    }

                    case ToolStates.DrawingSelection:
                    {
                        RaycastHoverInstance(mouseRay);
                        m_marqueeInstances = GetMarqueeList(mouseRay);
                        break;
                    }
                    }
                }
            }
        }