Пример #1
0
        public static Vector2 endPanel(int id, Vector2 scroll, Rectangle bounds, float maxScroll,
                                       bool onlyScrollWithMouseOver = false)
        {
            batches.Peek().End();
            var renderTarget2D = targets.Pop();

            GuiData.spriteBatch.GraphicsDevice.SetRenderTarget(targets.Peek());
            targetPool.Add(renderTarget2D);
            batchPool.Add(batches.Pop());
            GuiData.spriteBatch  = batches.Peek();
            GuiData.scrollOffset = offsetStack.Pop();
            var rectangle1 = GuiData.tmpRect;

            rectangle1.X      = (int)scroll.X;
            rectangle1.Y      = (int)scroll.Y;
            rectangle1.Width  = bounds.Width;
            rectangle1.Height = bounds.Height;
            try
            {
                GuiData.spriteBatch.Draw(renderTarget2D, bounds, rectangle1, Color.White);
            }
            catch (InvalidOperationException ex)
            {
                return(scroll);
            }
            if (!onlyScrollWithMouseOver || bounds.Contains(GuiData.getMousePoint()))
            {
                scroll.Y += GuiData.getMouseWheelScroll() * 20f;
            }
            scroll.Y = Math.Max(Math.Min(scroll.Y, maxScroll), 0.0f);
            var rectangle2 = GuiData.tmpRect;
            var num1       = 5f;
            var num2       = bounds.Height / maxScroll * bounds.Height;
            var num3       = bounds.Height - 4f;
            var num4       = scroll.Y / maxScroll * (bounds.Height - num2);

            rectangle2.Y      = (int)(num4 - num2 / 2.0 + num2 / 2.0 + bounds.Y);
            rectangle2.X      = (int)(bounds.X + bounds.Width - 1.5 * num1 - 2.0);
            rectangle2.Height = (int)num2;
            rectangle2.Width  = (int)num1;
            scroll.Y          = ScrollBar.doVerticalScrollBar(id, rectangle2.X, bounds.Y, rectangle2.Width, bounds.Height,
                                                              renderTarget2D.Height, scroll.Y);
            scroll.Y = Math.Max(Math.Min(scroll.Y, maxScroll), 0.0f);
            return(scroll);
        }
Пример #2
0
        public static Vector2 endPanel(int id, Vector2 scroll, Rectangle bounds, float maxScroll, bool onlyScrollWithMouseOver = false)
        {
            ScrollablePanel.batches.Peek().End();
            RenderTarget2D renderTarget2D = ScrollablePanel.targets.Pop();

            GuiData.spriteBatch.GraphicsDevice.SetRenderTarget(ScrollablePanel.targets.Peek());
            ScrollablePanel.targetPool.Add(renderTarget2D);
            ScrollablePanel.batchPool.Add(ScrollablePanel.batches.Pop());
            GuiData.spriteBatch  = ScrollablePanel.batches.Peek();
            GuiData.scrollOffset = ScrollablePanel.offsetStack.Pop();
            Rectangle tmpRect1 = GuiData.tmpRect;

            tmpRect1.X      = (int)scroll.X;
            tmpRect1.Y      = (int)scroll.Y;
            tmpRect1.Width  = bounds.Width;
            tmpRect1.Height = bounds.Height;
            try
            {
                GuiData.spriteBatch.Draw((Texture2D)renderTarget2D, bounds, new Rectangle?(tmpRect1), Color.White);
            }
            catch (InvalidOperationException ex)
            {
                return(scroll);
            }
            if (!onlyScrollWithMouseOver || bounds.Contains(GuiData.getMousePoint()))
            {
                scroll.Y += GuiData.getMouseWheelScroll() * 20f;
            }
            scroll.Y = Math.Max(Math.Min(scroll.Y, maxScroll), 0.0f);
            Rectangle tmpRect2 = GuiData.tmpRect;
            float     num1     = 5f;
            float     num2     = (float)bounds.Height / maxScroll * (float)bounds.Height;
            float     num3     = (float)bounds.Height - 4f;
            float     num4     = scroll.Y / maxScroll * ((float)bounds.Height - num2);

            tmpRect2.Y      = (int)((double)num4 - (double)num2 / 2.0 + (double)num2 / 2.0 + (double)bounds.Y);
            tmpRect2.X      = (int)((double)(bounds.X + bounds.Width) - 1.5 * (double)num1 - 2.0);
            tmpRect2.Height = (int)num2;
            tmpRect2.Width  = (int)num1;
            scroll.Y        = ScrollBar.doVerticalScrollBar(id, tmpRect2.X, bounds.Y, tmpRect2.Width, bounds.Height, renderTarget2D.Height, scroll.Y);
            scroll.Y        = Math.Max(Math.Min(scroll.Y, maxScroll), 0.0f);
            return(scroll);
        }
Пример #3
0
 private void UpdateInput(Rectangle dest)
 {
     ScrollDown += GuiData.getMouseWheelScroll() * 20f;
     ScrollDown  = Math.Max(Math.Min(ScrollDown, GetMaxScroll(dest)), 0.0f);
 }
Пример #4
0
        public static float doSliderBar(int myID, int x, int y, int width, int height, float maxValue, float minValue,
                                        float currentValue, float barStep)
        {
            var num1 = -1f;
            var val1 = currentValue;

            if (GuiData.hot == myID)
            {
                if (GuiData.isMouseLeftDown())
                {
                    GuiData.active = myID;
                }
                else if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
                if (GuiData.active == myID)
                {
                    num1 = Math.Min(Math.Max((GuiData.mouse.X - x) / (float)width, 0.0f), 1f);
                    val1 = minValue + num1 * (maxValue - minValue);
                }
                val1 += barStep * GuiData.getMouseWheelScroll();
            }
            if (num1 == -1.0)
            {
                var num2 = maxValue - minValue;
                num1 = currentValue / num2;
                if (minValue < 0.0)
                {
                    num1 += 0.5f;
                }
            }
            GuiData.tmpRect.X      = x;
            GuiData.tmpRect.Y      = y;
            GuiData.tmpRect.Width  = width;
            GuiData.tmpRect.Height = height;
            if (GuiData.tmpRect.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
            }
            else if (GuiData.hot == myID && GuiData.mouse.LeftButton == ButtonState.Released)
            {
                GuiData.hot = -1;
                if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            var num3 = Math.Min(Math.Max(val1, minValue), maxValue);

            GuiData.tmpRect.Width  = width;
            GuiData.tmpRect.X      = x;
            GuiData.tmpRect.Height = 10;
            GuiData.tmpRect.Y      = y + height / 4;
            GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect, GuiData.Default_Backing_Color);
            GuiData.tmpRect.Width  -= 4;
            GuiData.tmpRect.X      += 2;
            GuiData.tmpRect.Height -= 4;
            GuiData.tmpRect.Y      += 2;
            GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect, GuiData.Default_Dark_Background_Color);
            GuiData.tmpRect.Width  = 8;
            GuiData.tmpRect.X      = (int)(x + num1 * (double)width) - 4;
            GuiData.tmpRect.Y      = y - 5;
            GuiData.tmpRect.Height = height;
            GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect,
                                     GuiData.active != myID
                    ? (GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Selected_Color)
                    : GuiData.Default_Unselected_Color);
            if (GuiData.active == myID || GuiData.hot == myID)
            {
                var format = "0.000";
                var text   = num3.ToString(format) ?? "";
                text.TrimEnd('0');
                GuiData.temp.X = (int)(x + num1 * (double)width) + 4;
                GuiData.temp.Y = y - GuiData.smallfont.MeasureString(text).Y *0.8f;
                GuiData.spriteBatch.DrawString(GuiData.smallfont, text, GuiData.temp + Vector2.One, Color.Gray, 0.0f,
                                               Vector2.Zero, 0.8f, SpriteEffects.None, 0.51f);
                GuiData.spriteBatch.DrawString(GuiData.smallfont, text, GuiData.temp, Color.White, 0.0f, Vector2.Zero,
                                               0.8f, SpriteEffects.None, 0.5f);
            }
            return(num3);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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;
 }