예제 #1
0
        public void Edit(ProceduralObject obj, Vector2 position)
        {
            editingObject       = obj;
            scrollParams        = Vector2.zero;
            scrollTex           = Vector2.zero;
            movingField         = -1;
            dragTexPos          = Vector2.zero;
            windowRect.position = position;
            Texture tex = ProceduralUtils.GetOriginalTexture(obj);

            originalTex = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, false);
            originalTex.SetPixels(((Texture2D)tex).GetPixels());
            windowTex = (Texture2D)GameObject.Instantiate(originalTex);
            // load stored data if it exists
            if (editingObject.m_textParameters == null)
            {
                parameters    = new TextParameters();
                parametersOld = new TextParameters();
            }
            else
            {
                parameters    = editingObject.m_textParameters;
                parametersOld = TextParameters.Clone(editingObject.m_textParameters, false);
                windowTex     = parameters.ApplyParameters(originalTex);
                editingObject.m_material.mainTexture = windowTex as Texture;
            }
            updateTimer = 0f;
            dragTimer   = 0f;
            zoomFactor  = 1f;
            if (!showWindow)
            {
                showWindow = true;
            }
        }
 public void CloseWindow()
 {
     CloseCharTable();
     showWindow          = false;
     editingObject       = null;
     originalTex         = null;
     windowTex           = null;
     parameters          = null;
     parametersOld       = null;
     colorPickerSelected = null;
     if (selectedField != null)
     {
         selectedField.expandFontsSelector = false;
         selectedField.scrollFontsPos      = Vector2.zero;
         selectedField = null;
     }
     scrollParams = Vector2.zero;
     scrollTex    = Vector2.zero;
     updateTimer  = 0f;
     dragTimer    = 0f;
     placingText  = false;
     placingRect  = false;
     _justPlacedTextNowFocusField = false;
     placingRectFirstpoint        = Vector2.down;
     zoomFactor  = 1f;
     movingField = -1;
     dragTexPos  = Vector2.zero;
     // GUIUtils.SetMouseScrolling(true);
 }
 public static bool IsEmpty(TextParameters param)
 {
     if (param == null)
     {
         return(true);
     }
     if (param.Count() == 0)
     {
         return(true);
     }
     return(false);
 }
        public static TextParameters Clone(TextParameters paramSource, bool useFontname)
        {
            if (paramSource == null)
            {
                return(null);
            }
            var param = new TextParameters();

            for (int i = 0; i < paramSource.Count(); i++)
            {
                param.m_textFields.Add(TextField.Clone(paramSource.m_textFields[i], useFontname));
            }
            return(param);
        }
 public static bool IsDifference(TextParameters A, TextParameters B)
 {
     if (A.Count() != B.Count())
     {
         return(true);
     }
     for (int i = 0; i < A.Count(); i++)
     {
         if (TextField.IsDifference(A.m_textFields[i], B.m_textFields[i]))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #6
0
 public void CloseWindow()
 {
     CloseCharTable();
     showWindow    = false;
     editingObject = null;
     originalTex   = null;
     windowTex     = null;
     parameters    = null;
     parametersOld = null;
     scrollParams  = Vector2.zero;
     scrollTex     = Vector2.zero;
     updateTimer   = 0f;
     dragTimer     = 0f;
     zoomFactor    = 1f;
     movingField   = -1;
     dragTexPos    = Vector2.zero;
     // GUIUtils.SetMouseScrolling(true);
 }
예제 #7
0
 public void Update()
 {
     if (canDrawWindow)
     {
         /*
          * if (showWindow)
          *  GUIUtils.SetMouseScrolling(!windowRect.IsMouseInside());
          * */
         updateTimer += TimeUtils.deltaTime;
         if (dragTimer < .14f)
         {
             dragTimer += TimeUtils.deltaTime;
         }
         if (new Rect(windowRect.x + 5, windowRect.y + 30, 375, 285).IsMouseInside())
         {
             if (movingField != -1)
             {
                 parameters[movingField].x = (GUIUtils.MousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor;
                 parameters[movingField].y = (GUIUtils.MousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor;
                 if (Input.GetMouseButtonDown(0))
                 {
                     ProceduralObjectsLogic.PlaySound();
                     movingField = -1;
                 }
             }
             else
             {
                 if (Input.GetMouseButton(0))
                 {
                     if (dragTimer >= .14f)
                     {
                         if (dragTexPos == Vector2.zero)
                         {
                             dragTexPos = new Vector2((GUIUtils.MousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor, (GUIUtils.MousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor);
                         }
                     }
                 }
             }
         }
         if (Input.GetMouseButton(0))
         {
             if (dragTimer >= .14f)
             {
                 if (dragTexPos != Vector2.zero)
                 {
                     scrollTex = new Vector2(zoomFactor * dragTexPos.x - GUIUtils.MousePos.x + windowRect.x + 5, zoomFactor * dragTexPos.y - GUIUtils.MousePos.y + windowRect.y + 30);
                 }
             }
         }
         else if (Input.GetMouseButtonUp(0))
         {
             dragTexPos = Vector2.zero;
             dragTimer  = 0f;
         }
         if (updateTimer > .22f)
         {
             if (TextParameters.IsDifference(parameters, parametersOld))
             {
                 // apply changes
                 windowTex = parameters.ApplyParameters(originalTex);
                 editingObject.m_material.mainTexture = windowTex as Texture;
                 editingObject.m_textParameters       = parameters;
                 // save textparameters to the editingObject instance
             }
             parametersOld = TextParameters.Clone(parameters, false);
             updateTimer   = 0f;
         }
     }
 }
        public void Update()
        {
            if (canDrawWindow)
            {
                /*
                 * if (showWindow)
                 *  GUIUtils.SetMouseScrolling(!windowRect.IsMouseInside());
                 * */
                updateTimer += TimeUtils.deltaTime;
                var mousePos = GUIUtils.MousePos;
                if (colorPickerSelected != null)
                {
                    GUIPainter.UpdatePainter(colorPickerSelected, () => { colorPickerSelected = null; });
                }

                if (dragTimer < .14f && dragTimer != 0f)
                {
                    dragTimer += TimeUtils.deltaTime;
                }
                cursorIsInsideTextureArea = windowRect.IsMouseInside();
                if (new Rect(windowRect.x + 5, windowRect.y + 30, windowRect.width - 285, windowRect.height - 80).IsMouseInside())
                {
                    if (Input.GetKey(KeyCode.LeftControl))
                    {
                        zoomFactor *= 1f + Input.mouseScrollDelta.y * 0.3f;
                    }

                    if (placingText)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            var field = parameters.AddField(fontManager.Arial, 0);
                            field.x       = (mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor;
                            field.y       = (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor;
                            selectedField = field;
                            placingText   = false;
                            _justPlacedTextNowFocusField = true;
                        }
                    }
                    else if (placingRect)
                    {
                        if (placingRectFirstpoint != Vector2.down)
                        {
                            var field       = selectedField;
                            var secondPoint = new Vector2((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor,
                                                          (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor);
                            field.x        = Mathf.Min(placingRectFirstpoint.x, secondPoint.x);
                            field.y        = Mathf.Min(placingRectFirstpoint.y, secondPoint.y);
                            field.m_width  = (uint)Mathf.RoundToInt(Mathf.Abs(secondPoint.x - placingRectFirstpoint.x));
                            field.m_height = (uint)Mathf.RoundToInt(Mathf.Abs(secondPoint.y - placingRectFirstpoint.y));
                        }
                        if (Input.GetMouseButtonDown(0))
                        {
                            if (placingRectFirstpoint == Vector2.down)
                            {
                                ProceduralObjectsLogic.PlaySound();
                                var field = parameters.AddField(fontManager.Arial, 1);
                                placingRectFirstpoint = new Vector2((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor,
                                                                    (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor);
                                field.x       = placingRectFirstpoint.x;
                                field.y       = placingRectFirstpoint.y;
                                selectedField = field;
                            }
                            else
                            {
                                ProceduralObjectsLogic.PlaySound();
                                placingRectFirstpoint = Vector2.down;
                                placingRect           = false;
                            }
                        }
                    }
                    else
                    {
                        if (movingField > -1)
                        {
                            parameters[movingField].x = ((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor) - dragTexPos.x;
                            parameters[movingField].y = ((mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor) - dragTexPos.y;
                            if (Input.GetMouseButtonDown(0))
                            {
                                ProceduralObjectsLogic.PlaySound();
                                dragTexPos  = Vector2.zero;
                                movingField = -1;
                            }
                        }
                        else if (movingField == -1)
                        {
                            if (Input.GetMouseButtonDown(0))
                            {
                                dragTimer = 0.0001f;
                            }
                            if (Input.GetMouseButton(0))
                            {
                                if (dragTimer >= .14f)
                                {
                                    if (dragTexPos == Vector2.zero)
                                    {
                                        dragTexPos = new Vector2((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor, (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor);
                                    }
                                }
                            }
                        }
                    }
                }

                if (Input.GetMouseButton(0))
                {
                    if (movingField == -2)
                    {
                        var size = mousePos - windowRect.position;
                        windowRect.size = new Vector2(Mathf.Max(windowRect.x + 400, size.x), Mathf.Max(windowRect.y + 350, size.y));
                    }
                    else if (movingField == -3)
                    {
                        separatorListEditionZone = Mathf.Clamp(mousePos.y - windowRect.y, 125, 450);
                    }
                    else if (dragTimer >= .14f)
                    {
                        if (dragTexPos != Vector2.zero)
                        {
                            scrollTex = new Vector2(zoomFactor * dragTexPos.x - mousePos.x + windowRect.x + 5, zoomFactor * dragTexPos.y - mousePos.y + windowRect.y + 30);
                        }
                    }
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    if (movingField <= -2)
                    {
                        movingField = -1;
                    }

                    if (movingField <= -1)
                    {
                        dragTexPos = Vector2.zero;
                    }
                    dragTimer = 0f;
                }
                else
                {
                    if (movingField == -2)
                    {
                        movingField = -1;
                    }
                }
                if (updateTimer > .1f)
                {
                    if (TextParameters.IsDifference(parameters, parametersOld))
                    {
                        var oldTex = windowTex;
                        // apply changes
                        windowTex = parameters.ApplyParameters(originalTex);
                        editingObject.m_material.mainTexture = windowTex as Texture;
                        // save textparameters to the editingObject instance
                        editingObject.m_textParameters = parameters;
                        // try save on RAM usage
                        if (!TextParameters.IsEmpty(parametersOld))
                        {
                            oldTex.DisposeTexFromMemory();
                        }
                    }
                    parametersOld = TextParameters.Clone(parameters, false);
                    updateTimer   = 0f;
                }
            }
        }