Ejemplo n.º 1
0
        public static bool doHoldDownButton(int myID, int x, int y, int width, int height, string text, bool hasOutline,
                                            Color?outlineColor, Color?selectedColor)
        {
            wasPressedDown = false;
            wasReleased    = false;
            if (!outlineColor.HasValue)
            {
                outlineColor = Color.White;
            }
            if (!selectedColor.HasValue)
            {
                selectedColor = GuiData.Default_Selected_Color;
            }
            var destinationRectangle = GuiData.tmpRect;

            destinationRectangle.X      = x;
            destinationRectangle.Y      = y;
            destinationRectangle.Width  = width;
            destinationRectangle.Height = height;
            var flag = GuiData.isMouseLeftDown() && GuiData.active == myID;

            if (destinationRectangle.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                if (GuiData.mouseWasPressed())
                {
                    wasPressedDown = true;
                }
                if (GuiData.isMouseLeftDown())
                {
                    GuiData.active = myID;
                    flag           = true;
                }
            }
            else
            {
                if (GuiData.hot == myID)
                {
                    GuiData.hot = -1;
                }
                if (!GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            if (GuiData.mouseLeftUp())
            {
                wasReleased = true;
            }
            GuiData.spriteBatch.Draw(Utils.white, destinationRectangle,
                                     GuiData.active == myID
                    ? selectedColor.Value
                    : (GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Light_Backing_Color));
            if (hasOutline)
            {
                RenderedRectangle.doRectangleOutline(x, y, width, height, 2, outlineColor);
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public static bool doCheckBox(int myID, int x, int y, bool isChecked, Color?selectedColor)
        {
            if (!selectedColor.HasValue)
            {
                selectedColor = GuiData.Default_Selected_Color;
            }
            if (GuiData.hot == myID && GuiData.active == myID && GuiData.mouseLeftUp())
            {
                isChecked      = !isChecked;
                GuiData.active = -1;
            }
            RenderedRectangle.doRectangleOutline(x, y, 20, 20, 2,
                                                 GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Light_Backing_Color);
            RenderedRectangle.doRectangle(x + 4, y + 4, 12, 12,
                                          isChecked
                    ? selectedColor
                    : (GuiData.active == myID ? GuiData.Default_Unselected_Color : GuiData.Default_Backing_Color));
            var rectangle = GuiData.tmpRect;

            rectangle.X      = x;
            rectangle.Y      = y;
            rectangle.Width  = 20;
            rectangle.Height = 20;
            if (rectangle.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                if (GuiData.isMouseLeftDown())
                {
                    GuiData.active = myID;
                }
            }
            else
            {
                if (GuiData.hot == myID)
                {
                    GuiData.hot = -1;
                }
                if (GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            return(isChecked);
        }
Ejemplo n.º 3
0
        public static bool doButton(int myID, int x, int y, int width, int height, string text, Color?selectedColor,
                                    Texture2D tex)
        {
            var flag = false;

            if (GuiData.hot == myID && !GuiData.blockingInput && GuiData.active == myID &&
                (GuiData.mouseLeftUp() || GuiData.mouse.LeftButton == ButtonState.Released))
            {
                flag           = true;
                GuiData.active = -1;
            }
            var rectangle = GuiData.tmpRect;

            rectangle.X      = x;
            rectangle.Y      = y;
            rectangle.Width  = width;
            rectangle.Height = height;
            if (rectangle.Contains(GuiData.getMousePoint()) && !GuiData.blockingInput)
            {
                GuiData.hot = myID;
                if (GuiData.isMouseLeftDown() && (!DisableIfAnotherIsActive || GuiData.active == -1))
                {
                    GuiData.active = myID;
                }
            }
            else
            {
                if (GuiData.hot == myID)
                {
                    GuiData.hot = -1;
                }
                if (GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            drawModernButton(myID, x, y, width, height, text, selectedColor, tex);
            return(flag);
        }
Ejemplo n.º 4
0
        public static Vector2 doDraggableRectangle(int myID, float x, float y, int width, int height, float selectableBorder, Color?selectedColor, Color?deselectedColor, bool canMoveY, bool canMoveX, float xMax, float yMax, float xMin, float yMin)
        {
            DraggableRectangle.isDragging = false;
            if (!selectedColor.HasValue)
            {
                selectedColor = new Color?(GuiData.Default_Selected_Color);
            }
            if (!deselectedColor.HasValue)
            {
                deselectedColor = new Color?(GuiData.Default_Unselected_Color);
            }
            Vector2 temp = GuiData.temp;

            temp.X = 0.0f;
            temp.Y = 0.0f;
            Rectangle tmpRect1 = GuiData.tmpRect;

            tmpRect1.X      = (int)x;
            tmpRect1.Y      = (int)y;
            tmpRect1.Width  = width;
            tmpRect1.Height = height;
            Rectangle tmpRect2 = GuiData.tmpRect;

            tmpRect2.X      = (int)((double)x + (double)selectableBorder);
            tmpRect2.Y      = (int)((double)y + (double)selectableBorder);
            tmpRect2.Width  = (double)selectableBorder == -1.0 ? 0 : (int)((double)width - 2.0 * (double)selectableBorder);
            tmpRect2.Height = (double)selectableBorder == -1.0 ? 0 : (int)((double)height - 2.0 * (double)selectableBorder);
            if (tmpRect1.Contains(GuiData.getMousePoint()) && !tmpRect2.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                if (GuiData.active != myID && GuiData.mouseWasPressed())
                {
                    GuiData.active = myID;
                    DraggableRectangle.originalClickPos    = GuiData.getMousePos();
                    DraggableRectangle.originalClickPos.X -= x;
                    DraggableRectangle.originalClickPos.Y -= y;
                    DraggableRectangle.originalClickOffset = new Vector2(DraggableRectangle.originalClickPos.X - x, DraggableRectangle.originalClickPos.Y - y);
                }
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            if (GuiData.active == myID)
            {
                if (GuiData.mouseLeftUp())
                {
                    GuiData.active = -1;
                }
                else
                {
                    if (canMoveX)
                    {
                        temp.X = (float)GuiData.mouse.X - x - DraggableRectangle.originalClickPos.X;
                        temp.X = Math.Min(Math.Max((float)tmpRect1.X + temp.X, xMin), xMax) - (float)tmpRect1.X;
                    }
                    if (canMoveY)
                    {
                        temp.Y = (float)GuiData.mouse.Y - y - DraggableRectangle.originalClickPos.Y;
                        temp.Y = Math.Min(Math.Max((float)tmpRect1.Y + temp.Y, yMin), yMax) - (float)tmpRect1.Y;
                    }
                    tmpRect1.X += (int)temp.X;
                    tmpRect1.Y += (int)temp.Y;
                    DraggableRectangle.isDragging = true;
                }
            }
            if (GuiData.active == myID || GuiData.hot == myID)
            {
                GuiData.blockingInput = true;
            }
            GuiData.spriteBatch.Draw(Utils.white, tmpRect1, GuiData.hot == myID || GuiData.active == myID ? selectedColor.Value : deselectedColor.Value);
            return(temp);
        }
Ejemplo n.º 5
0
        public static int doList(int myID, int x, int y, int width, int height, string[] text, int lastSelectedIndex, Color?selectedColor)
        {
            if (!selectedColor.HasValue)
            {
                selectedColor = new Color?(GuiData.Default_Selected_Color);
            }
            int num1 = -1;

            SelectableTextList.wasActivated = false;
            int num2 = lastSelectedIndex;

            SelectableTextList.selectionWasChanged = false;
            Vector2   mousePos = GuiData.getMousePos();
            Rectangle tmpRect  = GuiData.tmpRect;

            tmpRect.X      = x;
            tmpRect.Y      = y;
            tmpRect.Width  = width;
            tmpRect.Height = height;
            if (tmpRect.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                SelectableTextList.scrollOffset += (int)GuiData.getMouseWheelScroll();
                SelectableTextList.scrollOffset  = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0)));
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            int num3 = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0)));

            if (GuiData.hot == myID)
            {
                for (int index = 0; index < text.Length; ++index)
                {
                    if ((double)mousePos.Y >= (double)y + (double)index * 18.0 && (double)mousePos.Y <= (double)y + (double)(index + 1) * 18.0 && (double)mousePos.Y < (double)(y + height))
                    {
                        num1 = index + num3;
                        SelectableTextList.wasActivated = true;
                    }
                }
            }
            if (num1 != -1 && num1 != lastSelectedIndex && GuiData.mouseLeftUp())
            {
                lastSelectedIndex = num1;
            }
            GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Backing_Color);
            tmpRect.X      += 2;
            tmpRect.Width  -= 4;
            tmpRect.Y      += 2;
            tmpRect.Height -= 4;
            GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.Default_Dark_Background_Color);
            Vector2 position = new Vector2((float)tmpRect.X, (float)tmpRect.Y);

            tmpRect.Height = 18;
            for (int index = num3; index < text.Length; ++index)
            {
                GuiData.spriteBatch.Draw(Utils.white, tmpRect, lastSelectedIndex == index ? selectedColor.Value : (num1 == index ? GuiData.Default_Unselected_Color : GuiData.Default_Dark_Neutral_Color));
                Vector2 scale = GuiData.UITinyfont.MeasureString(text[index]);
                scale.X = (double)scale.X <= (double)(width - 4) ? 1f : (float)(width - 4) / scale.X;
                scale.Y = (double)scale.Y <= 18.0 ? 1f : 14f / scale.Y;
                GuiData.spriteBatch.DrawString(GuiData.UITinyfont, text[index], position, Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.5f);
                position.Y += 18f;
                tmpRect.Y  += 18;
                if ((double)position.Y > (double)(y + height - 4))
                {
                    break;
                }
            }
            if ((double)text.Length * 18.0 > (double)height)
            {
                float num4 = 2f;
                float num5 = (float)height / ((float)text.Length * 18f) * (float)height;
                height -= 4;
                float num6 = (float)-height + (float)(((double)height - (double)num5) * ((double)num3 / (((double)text.Length * 18.0 - (double)height) / 18.0)));
                tmpRect.X      = (int)((double)position.X + (double)width - 3.0 * (double)num4 - 2.0);
                tmpRect.Y      = (int)((double)position.Y + (double)num6 + 2.0);
                tmpRect.Height = (int)num5;
                tmpRect.Width  = (int)num4;
                GuiData.spriteBatch.Draw(Utils.white, tmpRect, SelectableTextList.scrollBarColor);
            }
            if (lastSelectedIndex != num2)
            {
                SelectableTextList.selectionWasChanged = true;
            }
            return(lastSelectedIndex);
        }
Ejemplo n.º 6
0
        public static int doFancyList(int myID, int x, int y, int width, int height, string[] text, int lastSelectedIndex, Color?selectedColor, bool HasDraggableScrollbar = false)
        {
            if (!selectedColor.HasValue)
            {
                selectedColor = new Color?(GuiData.Default_Selected_Color);
            }
            int num1 = -1;

            SelectableTextList.wasActivated = false;
            int num2 = lastSelectedIndex;

            SelectableTextList.selectionWasChanged = false;
            Vector2   mousePos = GuiData.getMousePos();
            Rectangle tmpRect  = GuiData.tmpRect;

            tmpRect.X      = x;
            tmpRect.Y      = y;
            tmpRect.Width  = width;
            tmpRect.Height = height;
            if (tmpRect.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                SelectableTextList.scrollOffset += (int)GuiData.getMouseWheelScroll();
                SelectableTextList.scrollOffset  = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0)));
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            int   num3 = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0)));
            float num4 = HasDraggableScrollbar ? 4f : 2f;

            if (GuiData.hot == myID && (!HasDraggableScrollbar || (double)mousePos.X < (double)(x + width) - 2.0 * (double)num4))
            {
                for (int index = 0; index < text.Length; ++index)
                {
                    if ((double)mousePos.Y >= (double)y + (double)index * 18.0 && (double)mousePos.Y <= (double)y + (double)(index + 1) * 18.0 && (double)mousePos.Y < (double)(y + height))
                    {
                        num1 = index + num3;
                    }
                }
            }
            if (num1 != -1 && num1 != lastSelectedIndex && GuiData.mouseLeftUp())
            {
                lastSelectedIndex = num1;
                SelectableTextList.wasActivated = true;
            }
            tmpRect.X      += 2;
            tmpRect.Width  -= 4;
            tmpRect.Y      += 2;
            tmpRect.Height -= 4;
            Vector2 input = new Vector2((float)tmpRect.X, (float)tmpRect.Y);

            tmpRect.Height = 18;
            for (int index = num3; index < text.Length; ++index)
            {
                GuiData.spriteBatch.Draw(Utils.white, tmpRect, lastSelectedIndex == index ? selectedColor.Value : (num1 == index ? selectedColor.Value * 0.45f : GuiData.Default_Dark_Neutral_Color));
                Vector2 scale = GuiData.UITinyfont.MeasureString(text[index]);
                scale.X = (double)scale.X <= (double)(width - 4) ? 1f : (float)(width - 4) / scale.X;
                scale.Y = (double)scale.Y <= 18.0 ? 1f : 18f / scale.Y;
                scale.X = Math.Min(scale.X, scale.Y);
                scale.Y = Math.Min(scale.X, scale.Y);
                bool flag = !LocaleActivator.ActiveLocaleIsCJK() && Settings.ActiveLocale != "en-us";
                if (flag)
                {
                    input.Y += 3f;
                }
                GuiData.spriteBatch.DrawString(GuiData.UITinyfont, text[index], Utils.ClipVec2ForTextRendering(input), lastSelectedIndex == index ? Color.Black : Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.5f);
                if (flag)
                {
                    input.Y -= 3f;
                }
                input.Y   += 18f;
                tmpRect.Y += 18;
                if ((double)input.Y > (double)(y + height - 4))
                {
                    break;
                }
            }
            if ((double)text.Length * 18.0 > (double)height)
            {
                float num5 = num4;
                float num6 = (float)height / ((float)text.Length * 18f) * (float)height;
                height -= 4;
                float num7 = (float)-height + (float)(((double)height - (double)num6) * ((double)num3 / (((double)text.Length * 18.0 - (double)height) / 18.0)));
                tmpRect.X      = (int)((double)input.X + (double)width - (HasDraggableScrollbar ? 2.0 : 3.0) * (double)num5 - 2.0);
                tmpRect.Y      = (int)((double)input.Y + (double)num7 + 2.0);
                tmpRect.Height = (int)num6;
                tmpRect.Width  = (int)num5;
                if (!HasDraggableScrollbar)
                {
                    GuiData.spriteBatch.Draw(Utils.white, tmpRect, SelectableTextList.scrollBarColor);
                }
                else
                {
                    SelectableTextList.scrollOffset = (int)((double)ScrollBar.doVerticalScrollBar(myID + 101, tmpRect.X, y, tmpRect.Width, height, (int)((double)text.Length * 18.0), (float)num3 * 18f) / 18.0);
                }
            }
            if (lastSelectedIndex != num2)
            {
                SelectableTextList.selectionWasChanged = true;
            }
            return(lastSelectedIndex);
        }
Ejemplo n.º 7
0
 public static int doFancyList(int myID, int x, int y, int width, int height, string[] text,
     int lastSelectedIndex, Color? selectedColor, bool HasDraggableScrollbar = false)
 {
     if (!selectedColor.HasValue)
         selectedColor = GuiData.Default_Selected_Color;
     var num1 = -1;
     wasActivated = false;
     var num2 = lastSelectedIndex;
     selectionWasChanged = false;
     var mousePos = GuiData.getMousePos();
     var destinationRectangle = GuiData.tmpRect;
     destinationRectangle.X = x;
     destinationRectangle.Y = y;
     destinationRectangle.Width = width;
     destinationRectangle.Height = height;
     if (destinationRectangle.Contains(GuiData.getMousePoint()))
     {
         GuiData.hot = myID;
         scrollOffset += (int) GuiData.getMouseWheelScroll();
         scrollOffset = Math.Max(0, Math.Min(scrollOffset, text.Length - (int) (height/18.0)));
     }
     else if (GuiData.hot == myID)
         GuiData.hot = -1;
     var num3 = Math.Max(0, Math.Min(scrollOffset, text.Length - (int) (height/18.0)));
     var num4 = HasDraggableScrollbar ? 4f : 2f;
     if (GuiData.hot == myID && (!HasDraggableScrollbar || mousePos.X < x + width - 2.0*num4))
     {
         for (var index = 0; index < text.Length; ++index)
         {
             if (mousePos.Y >= y + index*18.0 && mousePos.Y <= y + (index + 1)*18.0 &&
                 mousePos.Y < (double) (y + height))
             {
                 num1 = index + num3;
                 wasActivated = true;
             }
         }
     }
     if (num1 != -1 && num1 != lastSelectedIndex && GuiData.mouseLeftUp())
         lastSelectedIndex = num1;
     destinationRectangle.X += 2;
     destinationRectangle.Width -= 4;
     destinationRectangle.Y += 2;
     destinationRectangle.Height -= 4;
     var position = new Vector2(destinationRectangle.X, destinationRectangle.Y);
     destinationRectangle.Height = 18;
     for (var index = num3; index < text.Length; ++index)
     {
         GuiData.spriteBatch.Draw(Utils.white, destinationRectangle,
             lastSelectedIndex == index
                 ? selectedColor.Value
                 : (num1 == index ? selectedColor.Value*0.45f : GuiData.Default_Dark_Neutral_Color));
         var scale = GuiData.UITinyfont.MeasureString(text[index]);
         scale.X = scale.X <= (double) (width - 4) ? 1f : (width - 4)/scale.X;
         scale.Y = scale.Y <= 18.0 ? 1f : 14f/scale.Y;
         scale.X = Math.Min(scale.X, scale.Y);
         scale.Y = Math.Min(scale.X, scale.Y);
         GuiData.spriteBatch.DrawString(GuiData.UITinyfont, text[index], position, Color.White, 0.0f,
             Vector2.Zero, scale, SpriteEffects.None, 0.5f);
         position.Y += 18f;
         destinationRectangle.Y += 18;
         if (position.Y > (double) (y + height - 4))
             break;
     }
     if (text.Length*18.0 > height)
     {
         var num5 = num4;
         var num6 = height/(text.Length*18f)*height;
         height -= 4;
         var num7 = -height + (float) ((height - (double) num6)*(num3/((text.Length*18.0 - height)/18.0)));
         destinationRectangle.X =
             (int) (position.X + (double) width - (HasDraggableScrollbar ? 2.0 : 3.0)*num5 - 2.0);
         destinationRectangle.Y = (int) (position.Y + (double) num7 + 2.0);
         destinationRectangle.Height = (int) num6;
         destinationRectangle.Width = (int) num5;
         if (!HasDraggableScrollbar)
             GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, scrollBarColor);
         else
             scrollOffset =
                 (int)
                     (ScrollBar.doVerticalScrollBar(myID + 101, destinationRectangle.X, y,
                         destinationRectangle.Width, height, (int) (text.Length*18.0), num3*18f)/18.0);
     }
     if (lastSelectedIndex != num2)
         selectionWasChanged = true;
     return lastSelectedIndex;
 }
Ejemplo n.º 8
0
        public static Vector2 doDraggableRectangle(int myID, float x, float y, int width, int height,
                                                   float selectableBorder, Color?selectedColor, Color?deselectedColor, bool canMoveY, bool canMoveX,
                                                   float xMax, float yMax, float xMin, float yMin)
        {
            isDragging = false;
            if (!selectedColor.HasValue)
            {
                selectedColor = GuiData.Default_Selected_Color;
            }
            if (!deselectedColor.HasValue)
            {
                deselectedColor = GuiData.Default_Unselected_Color;
            }
            var vector2 = GuiData.temp;

            vector2.X = 0.0f;
            vector2.Y = 0.0f;
            var destinationRectangle = GuiData.tmpRect;

            destinationRectangle.X      = (int)x;
            destinationRectangle.Y      = (int)y;
            destinationRectangle.Width  = width;
            destinationRectangle.Height = height;
            var rectangle = GuiData.tmpRect;

            rectangle.X      = (int)(x + (double)selectableBorder);
            rectangle.Y      = (int)(y + (double)selectableBorder);
            rectangle.Width  = selectableBorder == -1.0 ? 0 : (int)(width - 2.0 * selectableBorder);
            rectangle.Height = selectableBorder == -1.0 ? 0 : (int)(height - 2.0 * selectableBorder);
            if (destinationRectangle.Contains(GuiData.getMousePoint()) && !rectangle.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                if (GuiData.active != myID && GuiData.mouseWasPressed())
                {
                    GuiData.active      = myID;
                    originalClickPos    = GuiData.getMousePos();
                    originalClickPos.X -= x;
                    originalClickPos.Y -= y;
                    originalClickOffset = new Vector2(originalClickPos.X - x, originalClickPos.Y - y);
                }
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            if (GuiData.active == myID)
            {
                if (GuiData.mouseLeftUp())
                {
                    GuiData.active = -1;
                }
                else
                {
                    if (canMoveX)
                    {
                        vector2.X = GuiData.mouse.X - x - originalClickPos.X;
                        vector2.X = Math.Min(Math.Max(destinationRectangle.X + vector2.X, xMin), xMax) -
                                    destinationRectangle.X;
                    }
                    if (canMoveY)
                    {
                        vector2.Y = GuiData.mouse.Y - y - originalClickPos.Y;
                        vector2.Y = Math.Min(Math.Max(destinationRectangle.Y + vector2.Y, yMin), yMax) -
                                    destinationRectangle.Y;
                    }
                    destinationRectangle.X += (int)vector2.X;
                    destinationRectangle.Y += (int)vector2.Y;
                    isDragging              = true;
                }
            }
            if (GuiData.active == myID || GuiData.hot == myID)
            {
                GuiData.blockingInput = true;
            }
            GuiData.spriteBatch.Draw(Utils.white, destinationRectangle,
                                     GuiData.hot == myID || GuiData.active == myID ? selectedColor.Value : deselectedColor.Value);
            return(vector2);
        }