Find() static public method

Find the UIPanel responsible for handling the specified transform.
static public Find ( Transform trans ) : UIPanel,
trans Transform
return UIPanel,
Exemplo n.º 1
0
        UIHelper CreateGroup(UIHelperBase parent, string name, string tooltip = null)
        {
            UIHelper   group     = parent.AddGroup(name) as UIHelper;
            UIPanel    content   = group.self as UIPanel;
            UIPanel    container = content?.parent as UIPanel;
            RectOffset rect      = content?.autoLayoutPadding;

            if (rect != null)
            {
                rect.bottom /= 2;
            }

            rect = container?.autoLayoutPadding;

            if (rect != null)
            {
                rect.bottom /= 4;
            }

            if (!string.IsNullOrEmpty(tooltip))
            {
                UILabel label = container?.Find <UILabel>("Label");

                if (label != null)
                {
                    label.tooltip = tooltip;
                }
            }

            return(group);
        }
Exemplo n.º 2
0
        UIHelper CreateGroup(UIHelperBase parent, string name, string tooltip = null)
        {
            UIHelper group = parent.AddGroup(name) as UIHelper;

            if (!string.IsNullOrEmpty(tooltip))
            {
                UIPanel content   = group.self as UIPanel;
                UIPanel container = content?.parent as UIPanel;
                UILabel label     = container?.Find <UILabel>("Label");

                if (label != null)
                {
                    label.tooltip = tooltip;
                }
            }

            return(group);
        }
        private static void InitializeModSortDropDown()
        {
            if (GameObject.Find("ModsSortBy") != null)
            {
                return;
            }

            var shadows = GameObject.Find("Shadows").GetComponent<UIPanel>();

            if (shadows == null)
            {
                return;
            }

            var moarGroup = GameObject.Find("MoarGroup").GetComponent<UIPanel>();

            if (moarGroup == null)
            {
                return;
            }

            var moarLabel = moarGroup.Find<UILabel>("Moar");
            var moarButton = moarGroup.Find<UIButton>("Button");

            moarGroup.position = new Vector3(moarGroup.position.x, -6.0f, moarGroup.position.z);

            moarLabel.isVisible = false;
            moarButton.isVisible = false;

            sortDropDown = GameObject.Instantiate(shadows);
            sortDropDown.gameObject.name = "ModsSortBy";
            sortDropDown.transform.parent = moarGroup.transform;
            sortDropDown.name = "ModsSortBy";
            sortDropDown.Find<UILabel>("Label").isVisible = false;

            var dropdown = sortDropDown.Find<UIDropDown>("ShadowsQuality");
            dropdown.name = "SortByDropDown";
            dropdown.size = new Vector2(200.0f, 24.0f);
            dropdown.textScale = 0.8f;

            dropdown.eventSelectedIndexChanged += (component, value) =>
            {
                sortMode = (SortMode)value;
                RefreshPlugins();
            };

            var sprite = dropdown.Find<UIButton>("Sprite");
            sprite.foregroundSpriteMode = UIForegroundSpriteMode.Scale;

            var enumValues = Enum.GetValues(typeof(SortMode));
            dropdown.items = new string[enumValues.Length];

            int i = 0;
            foreach (var value in enumValues)
            {
                dropdown.items[i] = String.Format("Sort by: {0}", EnumToString((SortMode)value));
                i++;
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// Show the popup list dialog.
    /// </summary>

    public void Show()
    {
        if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
        {
            mLabelList.Clear();

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = UIPanel.Find(transform);
                if (mPanel == null)
                {
                    return;
                }
            }

            // Disable the navigation script
            handleEvents = true;

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Transform myTrans = transform;
            Bounds    bounds  = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            Transform t = mChild.transform;
            t.parent        = myTrans.parent;
            t.localPosition = bounds.min;
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = UIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;
            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            UISpriteData hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null)
            {
                return;
            }

            float          hlspHeight = hlsp.borderTop;
            float          fontHeight = activeFontSize;
            float          dynScale = activeFontScale;
            float          labelHeight = fontHeight * dynScale;
            float          x = 0f, y = -padding.y;
            int            labelFontSize = (bitmapFont != null) ? bitmapFont.defaultSize : fontSize;
            List <UILabel> labels        = new List <UILabel>();

            // Clear the selection if it's no longer present
            if (!items.Contains(mSelectedItem))
            {
                mSelectedItem = null;
            }

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild);
                lbl.name         = i.ToString();
                lbl.pivot        = UIWidget.Pivot.TopLeft;
                lbl.bitmapFont   = bitmapFont;
                lbl.trueTypeFont = trueTypeFont;
                lbl.fontSize     = labelFontSize;
                lbl.fontStyle    = fontStyle;
                lbl.text         = isLocalized ? Localization.Get(s) : s;
                lbl.color        = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -1f);
                lbl.overflowMethod = UILabel.Overflow.ResizeFreely;
                lbl.alignment      = alignment;
                lbl.MakePixelPerfect();
                if (dynScale != 1f)
                {
                    lbl.cachedTransform.localScale = Vector3.one * dynScale;
                }
                labels.Add(lbl);

                y -= labelHeight;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.printedSize.x);

                // Add an event listener
                UIEventListener listener = UIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.onClick   = OnItemClick;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, bounds.size.x * dynScale - (bgPadding.x + padding.x) * 2f);

            float   cx       = x / dynScale;
            Vector3 bcCenter = new Vector3(cx * 0.5f, -fontHeight * 0.5f, 0f);
            Vector3 bcSize   = new Vector3(cx, (labelHeight + padding.y) / dynScale, 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                NGUITools.AddWidgetCollider(lbl.gameObject);
                lbl.autoResizeBoxCollider = false;
                BoxCollider bc = lbl.GetComponent <BoxCollider>();

                if (bc != null)
                {
                    bcCenter.z = bc.center.z;
                    bc.center  = bcCenter;
                    bc.size    = bcSize;
                }
                else
                {
                    BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>();
                    b2d.offset = bcCenter;
                    b2d.size   = bcSize;
                }
            }

            int lblWidth = Mathf.RoundToInt(x);
            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.width  = Mathf.RoundToInt(x);
            mBackground.height = Mathf.RoundToInt(-y + bgPadding.y);

            // Set the label width to make alignment work
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                lbl.overflowMethod = UILabel.Overflow.ShrinkContent;
                lbl.width          = lblWidth;
            }

            // Scale the highlight sprite to envelop a single item
            float scaleFactor = 2f * atlas.pixelSize;
            float w           = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor;
            float h           = labelHeight + hlspHeight * scaleFactor;
            mHighlight.width  = Mathf.RoundToInt(w);
            mHighlight.height = Mathf.RoundToInt(h);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.FindCameraForLayer(gameObject.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                float bottom = y + labelHeight;
                Animate(mHighlight, placeAbove, bottom);
                for (int i = 0, imax = labels.Count; i < imax; ++i)
                {
                    Animate(labels[i], placeAbove, bottom);
                }
                AnimateColor(mBackground);
                AnimateScale(mBackground, placeAbove, bottom);
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z);
            }
        }
        else
        {
            OnSelect(false);
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Show the popup list dialog.
    /// </summary>

    public virtual void Show()
    {
        if (enabled && NGUITools.GetActive(gameObject) && mChild == null && isValid && items.Count > 0)
        {
            mLabelList.Clear();
            StopCoroutine("CloseIfUnselected");

            // Ensure the popup's source has the selection
            UICamera.selectedObject = (UICamera.hoveredObject ?? gameObject);
            mSelection = UICamera.selectedObject;
            source     = UICamera.selectedObject;

            if (source == null)
            {
                Debug.LogError("Popup list needs a source object...");
                return;
            }

            mOpenFrame = Time.frameCount;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = UIPanel.Find(transform);
                if (mPanel == null)
                {
                    return;
                }
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Vector3 min;
            Vector3 max;

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            if (separatePanel)
            {
                if (GetComponent <Collider>() != null)
                {
                    Rigidbody rb = mChild.AddComponent <Rigidbody>();
                    rb.isKinematic = true;
                }
                else if (GetComponent <Collider2D>() != null)
                {
                    Rigidbody2D rb = mChild.AddComponent <Rigidbody2D>();
                    rb.isKinematic = true;
                }
                UIPanel panel = mChild.AddComponent <UIPanel>();
                panel.depth            = 1000000;
                panel.sortingLayerName = mPanel.sortingLayerName;
            }
            current = this;

            Transform t = mChild.transform;
            t.parent = mPanel.cachedTransform;

            // Manually triggered popup list on some other game object
            if (openOn == OpenOn.Manual && mSelection != gameObject)
            {
                startingPosition = UICamera.lastEventPosition;
                min              = mPanel.cachedTransform.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(startingPosition));
                max              = min;
                t.localPosition  = min;
                startingPosition = t.position;
            }
            else
            {
                Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, transform, false, false);
                min              = bounds.min;
                max              = bounds.max;
                t.localPosition  = min;
                startingPosition = t.position;
            }

            StartCoroutine("CloseIfUnselected");

            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            int depth = separatePanel ? 0 : NGUITools.CalculateNextDepth(mPanel.gameObject);

            // Add a sprite for the background
            if (background2DSprite != null)
            {
                UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(depth);
                sp2.sprite2D = background2DSprite;
                mBackground  = sp2;
            }
            else if (atlas != null)
            {
                mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite, depth);
            }
            else
            {
                return;
            }

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.FindCameraForLayer(mSelection.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(startingPosition);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            mBackground.pivot = UIWidget.Pivot.TopLeft;
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;
            mBackground.cachedTransform.localPosition = new Vector3(0f, placeAbove ? bgPadding.y * 2f - overlap : overlap, 0f);

            // Add a sprite used for the selection
            if (highlight2DSprite != null)
            {
                UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(++depth);
                sp2.sprite2D = highlight2DSprite;
                mHighlight   = sp2;
            }
            else if (atlas != null)
            {
                mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite, ++depth);
            }
            else
            {
                return;
            }

            float hlspHeight = 0f, hlspLeft = 0f;

            if (mHighlight.hasBorder)
            {
                hlspHeight = mHighlight.border.w;
                hlspLeft   = mHighlight.border.x;
            }

            mHighlight.pivot = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            float          fontHeight = activeFontSize;
            float          dynScale = activeFontScale;
            float          labelHeight = fontHeight * dynScale;
            float          lineHeight = labelHeight + padding.y;
            float          x = 0f, y = placeAbove ? bgPadding.y - padding.y - overlap : -padding.y - bgPadding.y + overlap;
            float          contentHeight = bgPadding.y * 2f + padding.y;
            List <UILabel> labels        = new List <UILabel>();

            // Clear the selection if it's no longer present
            if (!items.Contains(mSelectedItem))
            {
                mSelectedItem = null;
            }

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild, mBackground.depth + 2);
                lbl.name         = i.ToString();
                lbl.pivot        = UIWidget.Pivot.TopLeft;
                lbl.bitmapFont   = bitmapFont;
                lbl.trueTypeFont = trueTypeFont;
                lbl.fontSize     = fontSize;
                lbl.fontStyle    = fontStyle;
                lbl.text         = isLocalized ? Localization.Get(s) : s;
                lbl.color        = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f);
                lbl.overflowMethod = UILabel.Overflow.ResizeFreely;
                lbl.alignment      = alignment;
                labels.Add(lbl);

                contentHeight += lineHeight;

                y -= lineHeight;
                x  = Mathf.Max(x, lbl.printedSize.x);

                // Add an event listener
                UIEventListener listener = UIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, (max.x - min.x) - (bgPadding.x + padding.x) * 2f);

            float   cx       = x;
            Vector3 bcCenter = new Vector3(cx * 0.5f, -labelHeight * 0.5f, 0f);
            Vector3 bcSize   = new Vector3(cx, (labelHeight + padding.y), 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                NGUITools.AddWidgetCollider(lbl.gameObject);
                lbl.autoResizeBoxCollider = false;
                BoxCollider bc = lbl.GetComponent <BoxCollider>();

                if (bc != null)
                {
                    bcCenter.z = bc.center.z;
                    bc.center  = bcCenter;
                    bc.size    = bcSize;
                }
                else
                {
                    BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>();
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
                    b2d.center = bcCenter;
#else
                    b2d.offset = bcCenter;
#endif
                    b2d.size = bcSize;
                }
            }

            int lblWidth = Mathf.RoundToInt(x);
            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.width  = Mathf.RoundToInt(x);
            mBackground.height = Mathf.RoundToInt(contentHeight);

            // Set the label width to make alignment work
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                lbl.overflowMethod = UILabel.Overflow.ShrinkContent;
                lbl.width          = lblWidth;
            }

            // Scale the highlight sprite to envelop a single item
            float scaleFactor = (atlas != null) ? 2f * atlas.pixelSize : 2f;
            float w           = x - (bgPadding.x + padding.x) * 2f + hlspLeft * scaleFactor;
            float h           = labelHeight + hlspHeight * scaleFactor;
            mHighlight.width  = Mathf.RoundToInt(w);
            mHighlight.height = Mathf.RoundToInt(h);

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                AnimateColor(mBackground);

                if (Time.timeScale == 0f || Time.timeScale >= 0.1f)
                {
                    float bottom = y + labelHeight;
                    Animate(mHighlight, placeAbove, bottom);
                    for (int i = 0, imax = labels.Count; i < imax; ++i)
                    {
                        Animate(labels[i], placeAbove, bottom);
                    }
                    AnimateScale(mBackground, placeAbove, bottom);
                }
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                min.y           = max.y - bgPadding.y;
                max.y           = min.y + mBackground.height;
                max.x           = min.x + mBackground.width;
                t.localPosition = new Vector3(min.x, max.y - bgPadding.y, min.z);
            }
            else
            {
                max.y = min.y + bgPadding.y;
                min.y = max.y - mBackground.height;
                max.x = min.x + mBackground.width;
            }

            Transform pt = mPanel.cachedTransform.parent;

            if (pt != null)
            {
                min = mPanel.cachedTransform.TransformPoint(min);
                max = mPanel.cachedTransform.TransformPoint(max);
                min = pt.InverseTransformPoint(min);
                max = pt.InverseTransformPoint(max);
            }

            // Ensure that everything fits into the panel's visible range
            Vector3 offset = mPanel.hasClipping ? Vector3.zero : mPanel.CalculateConstrainOffset(min, max);
            Vector3 pos    = t.localPosition + offset;
            pos.x           = Mathf.Round(pos.x);
            pos.y           = Mathf.Round(pos.y);
            t.localPosition = pos;
        }
        else
        {
            OnSelect(false);
        }
    }
Exemplo n.º 6
0
 public static UIPanel Find(Transform trans)
 {
     return(UIPanel.Find(trans, false, -1));
 }
        public void setSliderPanel(String[] sliderPanels)
        {
            clearSliderPanel();

            settings.budgetSliderNameList.Clear();

            foreach (String sliderName in sliderPanels)
            {
                UIPanel originalSlider = _main.getSliderPanel(sliderName);
                if (originalSlider != null)
                {
                    settings.budgetSliderNameList.Add(sliderName);
                    UIPanel panel = InstanceManager.Instantiate(originalSlider);
                    panel.name = panel.name.Substring(0, panel.name.Length - 7); // delete ' (Copy)' mark
                    AttachUIComponent(panel.gameObject);
                    UIComponent sliderDay        = panel.Find("DaySlider");
                    UIComponent sliderNight      = panel.Find("NightSlider");
                    UIComponent sliderBackground = panel.Find <UISlicedSprite>("SliderBackground");
                    UILabel     total            = panel.Find <UILabel>("Total");
                    UILabel     percentageDay    = panel.Find <UILabel>("DayPercentage");
                    UILabel     percentageNight  = panel.Find <UILabel>("NightPercentage");
                    UISprite    icon             = panel.Find <UISprite>("Icon");

                    panel.transform.parent = this.transform;
                    panel.relativePosition = new Vector3(2, _sliderList.Count * 50 + 46);
                    panel.size             = new Vector2(width - 6, panel.height - 2);

                    sliderBackground.relativePosition = new Vector3(50, sliderBackground.relativePosition.y);
                    sliderBackground.size             = new Vector2(panel.width - 98 - 50, sliderBackground.height);
                    sliderDay.relativePosition        = new Vector3(50, sliderDay.relativePosition.y);
                    sliderDay.size = new Vector2(panel.width - 98 - 50, sliderDay.height);
                    sliderNight.relativePosition = new Vector3(50, sliderNight.relativePosition.y);
                    sliderNight.size             = new Vector2(panel.width - 98 - 50, sliderNight.height);

                    total.relativePosition           = new Vector3(panel.width - 92, total.relativePosition.y);
                    total.size                       = new Vector2(90, total.height);
                    percentageDay.relativePosition   = new Vector3(panel.width - 92, total.relativePosition.y);
                    percentageDay.size               = new Vector2(45, total.height);
                    percentageNight.relativePosition = new Vector3(panel.width - 47, total.relativePosition.y);
                    percentageNight.size             = new Vector2(45, total.height);

                    UIButton buttonPlusDay    = panel.AddUIComponent <UIButton>();
                    UIButton buttonMinusDay   = panel.AddUIComponent <UIButton>();
                    UIButton buttonPlusNight  = panel.AddUIComponent <UIButton>();
                    UIButton buttonMinusNight = panel.AddUIComponent <UIButton>();

                    buttonPlusDay.name                    = "Budget Plus Button Day";
                    buttonPlusDay.size                    = new Vector2(18, 18);
                    buttonPlusDay.relativePosition        = new Vector3(117, 5);
                    buttonPlusDay.normalBgSprite          = "ButtonMenu";
                    buttonPlusDay.focusedBgSprite         = "ButtonMenuFocused";
                    buttonPlusDay.hoveredBgSprite         = "ButtonMenuHovered";
                    buttonPlusDay.pressedBgSprite         = "ButtonMenuPressed";
                    buttonPlusDay.text                    = "+";
                    buttonPlusDay.textColor               = new Color32(0, 255, 0, 255);
                    buttonPlusDay.textScale               = 1.2f;
                    buttonPlusDay.textHorizontalAlignment = UIHorizontalAlignment.Center;
                    buttonPlusDay.textVerticalAlignment   = UIVerticalAlignment.Middle;
                    buttonPlusDay.eventClick             += adjustBudgetPlusDay;
                    buttonPlusDay.isVisible               = false;

                    buttonPlusNight.name                    = "Budget Plus Button Night";
                    buttonPlusNight.size                    = new Vector2(18, 18);
                    buttonPlusNight.relativePosition        = new Vector3(117, 23);
                    buttonPlusNight.normalBgSprite          = "ButtonMenu";
                    buttonPlusNight.focusedBgSprite         = "ButtonMenuFocused";
                    buttonPlusNight.hoveredBgSprite         = "ButtonMenuHovered";
                    buttonPlusNight.pressedBgSprite         = "ButtonMenuPressed";
                    buttonPlusNight.text                    = "+";
                    buttonPlusNight.textColor               = new Color32(0, 255, 0, 255);
                    buttonPlusNight.textScale               = 1.2f;
                    buttonPlusNight.textHorizontalAlignment = UIHorizontalAlignment.Center;
                    buttonPlusNight.textVerticalAlignment   = UIVerticalAlignment.Middle;
                    buttonPlusNight.eventClick             += adjustBudgetPlusNight;
                    buttonPlusNight.isVisible               = false;

                    buttonMinusDay.name                    = "Budget Minus Button Day";
                    buttonMinusDay.size                    = new Vector2(18, 18);
                    buttonMinusDay.relativePosition        = new Vector3(45, 5);
                    buttonMinusDay.normalBgSprite          = "ButtonMenu";
                    buttonMinusDay.focusedBgSprite         = "ButtonMenuFocused";
                    buttonMinusDay.hoveredBgSprite         = "ButtonMenuHovered";
                    buttonMinusDay.pressedBgSprite         = "ButtonMenuPressed";
                    buttonMinusDay.text                    = "-";
                    buttonMinusDay.textScale               = 1.2f;
                    buttonMinusDay.textHorizontalAlignment = UIHorizontalAlignment.Center;
                    buttonMinusDay.textVerticalAlignment   = UIVerticalAlignment.Middle;
                    buttonMinusDay.textColor               = new Color32(255, 0, 0, 255);
                    buttonMinusDay.eventClick             += adjustBudgetMinusDay;
                    buttonMinusDay.isVisible               = false;

                    buttonMinusNight.name                    = "Budget Minus Button Night";
                    buttonMinusNight.size                    = new Vector2(18, 18);
                    buttonMinusNight.relativePosition        = new Vector3(45, 23);
                    buttonMinusNight.normalBgSprite          = "ButtonMenu";
                    buttonMinusNight.focusedBgSprite         = "ButtonMenuFocused";
                    buttonMinusNight.hoveredBgSprite         = "ButtonMenuHovered";
                    buttonMinusNight.pressedBgSprite         = "ButtonMenuPressed";
                    buttonMinusNight.text                    = "-";
                    buttonMinusNight.textScale               = 1.2f;
                    buttonMinusNight.textHorizontalAlignment = UIHorizontalAlignment.Center;
                    buttonMinusNight.textVerticalAlignment   = UIVerticalAlignment.Middle;
                    buttonMinusNight.textColor               = new Color32(255, 0, 0, 255);
                    buttonMinusNight.eventClick             += adjustBudgetMinusNight;
                    buttonMinusNight.isVisible               = false;;


                    icon.relativePosition = new Vector3(1, icon.relativePosition.y);
                    icon.isInteractive    = true;
                    icon.eventClick      += toggleMode;
                    icon.BringToFront();

                    _sliderList.Add(panel);
                }
            }
            this.height = _sliderList.Count * 50 + 46;
        }
Exemplo n.º 8
0
 public virtual void Show()
 {
     if (base.enabled && NGUITools.GetActive(base.gameObject) && UIPopupList.mChild == null && this.atlas != null && this.isValid && this.items.Count > 0)
     {
         this.mLabelList.Clear();
         base.StopCoroutine("CloseIfUnselected");
         UICamera.selectedObject = (UICamera.hoveredObject ?? base.gameObject);
         this.mSelection         = UICamera.selectedObject;
         this.source             = UICamera.selectedObject;
         if (this.source == null)
         {
             Debug.LogError("Popup list needs a source object...");
             return;
         }
         this.mOpenFrame = Time.frameCount;
         if (this.mPanel == null)
         {
             this.mPanel = UIPanel.Find(base.transform);
             if (this.mPanel == null)
             {
                 return;
             }
         }
         UIPopupList.mChild       = new GameObject("Drop-down List");
         UIPopupList.mChild.layer = base.gameObject.layer;
         UIPopupList.current      = this;
         Transform transform = UIPopupList.mChild.transform;
         transform.parent = this.mPanel.cachedTransform;
         Vector3 localPosition;
         Vector3 vector;
         Vector3 v;
         if (this.openOn == UIPopupList.OpenOn.Manual && this.mSelection != base.gameObject)
         {
             localPosition           = UICamera.lastEventPosition;
             vector                  = this.mPanel.cachedTransform.InverseTransformPoint(this.mPanel.anchorCamera.ScreenToWorldPoint(localPosition));
             v                       = vector;
             transform.localPosition = vector;
             localPosition           = transform.position;
         }
         else
         {
             Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(this.mPanel.cachedTransform, base.transform, false, false);
             vector = bounds.min;
             v      = bounds.max;
             transform.localPosition = vector;
             localPosition           = transform.position;
         }
         base.StartCoroutine("CloseIfUnselected");
         transform.localRotation = Quaternion.identity;
         transform.localScale    = Vector3.one;
         this.mBackground        = NGUITools.AddSprite(UIPopupList.mChild, this.atlas, this.backgroundSprite);
         this.mBackground.pivot  = UIWidget.Pivot.TopLeft;
         this.mBackground.depth  = NGUITools.CalculateNextDepth(this.mPanel.gameObject);
         this.mBackground.color  = this.backgroundColor;
         Vector4 border = this.mBackground.border;
         this.mBgBorder = border.y;
         this.mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f);
         this.mHighlight       = NGUITools.AddSprite(UIPopupList.mChild, this.atlas, this.highlightSprite);
         this.mHighlight.pivot = UIWidget.Pivot.TopLeft;
         this.mHighlight.color = this.highlightColor;
         UISpriteData atlasSprite = this.mHighlight.GetAtlasSprite();
         if (atlasSprite == null)
         {
             return;
         }
         float          num             = (float)atlasSprite.borderTop;
         float          num2            = (float)this.activeFontSize;
         float          activeFontScale = this.activeFontScale;
         float          num3            = num2 * activeFontScale;
         float          num4            = 0f;
         float          num5            = -this.padding.y;
         List <UILabel> list            = new List <UILabel>();
         if (!this.items.Contains(this.mSelectedItem))
         {
             this.mSelectedItem = null;
         }
         int i     = 0;
         int count = this.items.Count;
         while (i < count)
         {
             string  text    = this.items[i];
             UILabel uilabel = NGUITools.AddWidget <UILabel>(UIPopupList.mChild);
             uilabel.name         = i.ToString();
             uilabel.pivot        = UIWidget.Pivot.TopLeft;
             uilabel.bitmapFont   = this.bitmapFont;
             uilabel.trueTypeFont = this.trueTypeFont;
             uilabel.fontSize     = this.fontSize;
             uilabel.fontStyle    = this.fontStyle;
             string text2 = (!this.isLocalized) ? text : Localization.Get(text);
             if (this.toUpper)
             {
                 text2 = text2.ToUpper();
             }
             uilabel.text  = text2;
             uilabel.color = this.textColor;
             uilabel.cachedTransform.localPosition = new Vector3(border.x + this.padding.x - uilabel.pivotOffset.x, num5, -1f);
             uilabel.overflowMethod = UILabel.Overflow.ResizeFreely;
             uilabel.alignment      = this.alignment;
             list.Add(uilabel);
             num5 -= num3;
             num5 -= this.padding.y;
             num4  = Mathf.Max(num4, uilabel.printedSize.x);
             UIEventListener uieventListener = UIEventListener.Get(uilabel.gameObject);
             uieventListener.onHover   = new UIEventListener.BoolDelegate(this.OnItemHover);
             uieventListener.onPress   = new UIEventListener.BoolDelegate(this.OnItemPress);
             uieventListener.parameter = text;
             if (this.mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(this.mSelectedItem)))
             {
                 this.Highlight(uilabel, true);
             }
             this.mLabelList.Add(uilabel);
             i++;
         }
         num4 = Mathf.Max(num4, v.x - vector.x - (border.x + this.padding.x) * 2f);
         float   num6    = num4;
         Vector3 vector2 = new Vector3(num6 * 0.5f, -num3 * 0.5f, 0f);
         Vector3 vector3 = new Vector3(num6, num3 + this.padding.y, 1f);
         int     j       = 0;
         int     count2  = list.Count;
         while (j < count2)
         {
             UILabel uilabel2 = list[j];
             NGUITools.AddWidgetCollider(uilabel2.gameObject);
             uilabel2.autoResizeBoxCollider = false;
             BoxCollider component = uilabel2.GetComponent <BoxCollider>();
             if (component != null)
             {
                 vector2.z        = component.center.z;
                 component.center = vector2;
                 component.size   = vector3;
             }
             else
             {
                 BoxCollider2D component2 = uilabel2.GetComponent <BoxCollider2D>();
                 component2.offset = vector2;
                 component2.size   = vector3;
             }
             j++;
         }
         int width = Mathf.RoundToInt(num4);
         num4 += (border.x + this.padding.x) * 2f;
         num5 -= border.y;
         this.mBackground.width  = Mathf.RoundToInt(num4);
         this.mBackground.height = Mathf.RoundToInt(-num5 + border.y);
         int k      = 0;
         int count3 = list.Count;
         while (k < count3)
         {
             UILabel uilabel3 = list[k];
             uilabel3.overflowMethod = UILabel.Overflow.ShrinkContent;
             uilabel3.width          = width;
             k++;
         }
         float num7 = 2f * this.atlas.pixelSize;
         float f    = num4 - (border.x + this.padding.x) * 2f + (float)atlasSprite.borderLeft * num7;
         float f2   = num3 + num * num7;
         this.mHighlight.width  = Mathf.RoundToInt(f);
         this.mHighlight.height = Mathf.RoundToInt(f2);
         bool flag = this.position == UIPopupList.Position.Above;
         if (this.position == UIPopupList.Position.Auto)
         {
             UICamera uicamera = UICamera.FindCameraForLayer(this.mSelection.layer);
             if (uicamera != null)
             {
                 flag = (uicamera.cachedCamera.WorldToViewportPoint(localPosition).y < 0.5f);
             }
         }
         if (this.isAnimated)
         {
             this.AnimateColor(this.mBackground);
             if (Time.timeScale == 0f || Time.timeScale >= 0.1f)
             {
                 float bottom = num5 + num3;
                 this.Animate(this.mHighlight, flag, bottom);
                 int l      = 0;
                 int count4 = list.Count;
                 while (l < count4)
                 {
                     this.Animate(list[l], flag, bottom);
                     l++;
                 }
                 this.AnimateScale(this.mBackground, flag, bottom);
             }
         }
         if (flag)
         {
             vector.y = v.y - border.y;
             v.y      = vector.y + (float)this.mBackground.height;
             v.x      = vector.x + (float)this.mBackground.width;
             transform.localPosition = new Vector3(vector.x, v.y - border.y, vector.z);
         }
         else
         {
             v.y      = vector.y + border.y;
             vector.y = v.y - (float)this.mBackground.height;
             v.x      = vector.x + (float)this.mBackground.width;
         }
         Transform parent = this.mPanel.cachedTransform.parent;
         if (parent != null)
         {
             vector = this.mPanel.cachedTransform.TransformPoint(vector);
             v      = this.mPanel.cachedTransform.TransformPoint(v);
             vector = parent.InverseTransformPoint(vector);
             v      = parent.InverseTransformPoint(v);
         }
         Vector3 b = (!this.mPanel.hasClipping) ? this.mPanel.CalculateConstrainOffset(vector, v) : Vector3.zero;
         localPosition           = transform.localPosition + b;
         localPosition.x         = Mathf.Round(localPosition.x);
         localPosition.y         = Mathf.Round(localPosition.y);
         transform.localPosition = localPosition;
     }
     else
     {
         this.OnSelect(false);
     }
 }
Exemplo n.º 9
0
 private void OnClick()
 {
     if (((this.mChild == null) && (this.atlas != null)) && ((this.font != null) && (this.items.Count > 0)))
     {
         this.mLabelList.Clear();
         this.handleEvents = true;
         if (this.mPanel == null)
         {
             this.mPanel = UIPanel.Find(base.transform, true);
         }
         Transform child  = base.transform;
         Bounds    bounds = NGUIMath.CalculateRelativeWidgetBounds(child.parent, child);
         this.mChild       = new GameObject("Drop-down List");
         this.mChild.layer = base.gameObject.layer;
         Transform transform = this.mChild.transform;
         transform.parent        = child.parent;
         transform.localPosition = bounds.min;
         transform.localRotation = Quaternion.identity;
         transform.localScale    = Vector3.one;
         this.mBackground        = NGUITools.AddSprite(this.mChild, this.atlas, this.backgroundSprite);
         this.mBackground.pivot  = UIWidget.Pivot.TopLeft;
         this.mBackground.depth  = NGUITools.CalculateNextDepth(this.mPanel.gameObject);
         this.mBackground.color  = this.backgroundColor;
         Vector4 border = this.mBackground.border;
         this.mBgBorder = border.y;
         this.mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f);
         this.mHighlight       = NGUITools.AddSprite(this.mChild, this.atlas, this.highlightSprite);
         this.mHighlight.pivot = UIWidget.Pivot.TopLeft;
         this.mHighlight.color = this.highlightColor;
         UIAtlas.Sprite atlasSprite = this.mHighlight.GetAtlasSprite();
         if (atlasSprite != null)
         {
             float          num   = atlasSprite.inner.yMin - atlasSprite.outer.yMin;
             float          num2  = (this.font.size * this.font.pixelSize) * this.textScale;
             float          a     = 0f;
             float          y     = -this.padding.y;
             List <UILabel> list  = new List <UILabel>();
             int            num5  = 0;
             int            count = this.items.Count;
             while (num5 < count)
             {
                 string  key  = this.items[num5];
                 UILabel item = NGUITools.AddWidget <UILabel>(this.mChild);
                 item.pivot = UIWidget.Pivot.TopLeft;
                 item.font  = this.font;
                 item.text  = (!this.isLocalized || (Localization.instance == null)) ? key : Localization.instance.Get(key);
                 item.color = this.textColor;
                 item.cachedTransform.localPosition = new Vector3(border.x + this.padding.x, y, -1f);
                 item.MakePixelPerfect();
                 if (this.textScale != 1f)
                 {
                     Vector3 localScale = item.cachedTransform.localScale;
                     item.cachedTransform.localScale = (Vector3)(localScale * this.textScale);
                 }
                 list.Add(item);
                 y -= num2;
                 y -= this.padding.y;
                 a  = Mathf.Max(a, item.relativeSize.x * num2);
                 UIEventListener listener = UIEventListener.Get(item.gameObject);
                 listener.onHover   = new UIEventListener.BoolDelegate(this.OnItemHover);
                 listener.onPress   = new UIEventListener.BoolDelegate(this.OnItemPress);
                 listener.parameter = key;
                 if (this.mSelectedItem == key)
                 {
                     this.Highlight(item, true);
                 }
                 this.mLabelList.Add(item);
                 num5++;
             }
             a = Mathf.Max(a, bounds.size.x - ((border.x + this.padding.x) * 2f));
             Vector3 vector5 = new Vector3((a * 0.5f) / num2, -0.5f, 0f);
             Vector3 vector6 = new Vector3(a / num2, (num2 + this.padding.y) / num2, 1f);
             int     num7    = 0;
             int     num8    = list.Count;
             while (num7 < num8)
             {
                 UILabel     label2   = list[num7];
                 BoxCollider collider = NGUITools.AddWidgetCollider(label2.gameObject);
                 vector5.z       = collider.center.z;
                 collider.center = vector5;
                 collider.size   = vector6;
                 num7++;
             }
             a += (border.x + this.padding.x) * 2f;
             y -= border.y;
             this.mBackground.cachedTransform.localScale = new Vector3(a, -y + border.y, 1f);
             this.mHighlight.cachedTransform.localScale  = new Vector3((a - ((border.x + this.padding.x) * 2f)) + ((atlasSprite.inner.xMin - atlasSprite.outer.xMin) * 2f), num2 + (num * 2f), 1f);
             bool placeAbove = this.position == Position.Above;
             if (this.position == Position.Auto)
             {
                 UICamera camera = UICamera.FindCameraForLayer(base.gameObject.layer);
                 if (camera != null)
                 {
                     placeAbove = camera.cachedCamera.WorldToViewportPoint(child.position).y < 0.5f;
                 }
             }
             if (this.isAnimated)
             {
                 float bottom = y + num2;
                 this.Animate(this.mHighlight, placeAbove, bottom);
                 int num10 = 0;
                 int num11 = list.Count;
                 while (num10 < num11)
                 {
                     this.Animate(list[num10], placeAbove, bottom);
                     num10++;
                 }
                 this.AnimateColor(this.mBackground);
                 this.AnimateScale(this.mBackground, placeAbove, bottom);
             }
             if (placeAbove)
             {
                 transform.localPosition = new Vector3(bounds.min.x, (bounds.max.y - y) - border.y, bounds.min.z);
             }
         }
     }
     else
     {
         this.OnSelect(false);
     }
 }
Exemplo n.º 10
0
        public void Display(object data, bool isRowOdd)
        {
            if (data != null)
            {
                IncentiveOptionItem option = data as IncentiveOptionItem;
                Initialise();

                if (option != null && option.title != null && option.title != "" && background != null)
                {
                    currentOption = option;

                    background.width            = width;
                    background.height           = height;
                    background.relativePosition = Vector2.zero;
                    background.zOrder           = 0;

                    amount.isInteractive = true;
                    amount.value         = option.sliderValue;
                    amount.maxValue      = option.ticketCount;
                    amount.width         = width - ((width * 40f) / 100f);

                    UIPanel sliderPanel = amount.parent as UIPanel;
                    sliderPanel.relativePosition = new Vector2(5, 5);
                    sliderPanel.width            = amount.width;

                    UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");
                    sliderLabel.tooltip       = option.description;
                    sliderLabel.textScale     = 0.8f;
                    sliderLabel.processMarkup = true;

                    totalsPanel.relativePosition = new Vector3(sliderPanel.relativePosition.x + sliderPanel.width + 5, 5);
                    totalsPanel.width            = width - totalsPanel.relativePosition.x - 15;
                    totalsPanel.height           = height - 10;
                    totalsPanel.atlas            = CimTools.CimToolsHandler.CimToolBase.SpriteUtilities.GetAtlas("Ingame");
                    totalsPanel.backgroundSprite = "GenericPanel";
                    totalsPanel.color            = new Color32(91, 97, 106, 255);

                    effects.autoSize          = false;
                    effects.autoHeight        = false;
                    effects.width             = totalsPanel.width;
                    effects.height            = 20;
                    effects.relativePosition  = new Vector2(0, totalsPanel.height - effects.height);
                    effects.textScale         = 0.6f;
                    effects.padding           = new RectOffset(5, 5, 5, 5);
                    effects.name              = "Effects";
                    effects.processMarkup     = true;
                    effects.text              = string.Format("<sprite NotificationIconHappy> {0}%         <sprite NotificationIconNotHappy> {1}%", option.positiveEffect, option.negativeEffect);
                    effects.textAlignment     = UIHorizontalAlignment.Center;
                    effects.verticalAlignment = UIVerticalAlignment.Middle;

                    costsLabel.relativePosition  = Vector3.zero;
                    costsLabel.autoSize          = false;
                    costsLabel.autoHeight        = false;
                    costsLabel.width             = 40;
                    costsLabel.height            = (totalsPanel.height / 2f) - (effects.height / 2f);
                    costsLabel.name              = "CostsLabel";
                    costsLabel.textScale         = 0.6f;
                    costsLabel.padding           = new RectOffset(4, 4, 4, 4);
                    costsLabel.textAlignment     = UIHorizontalAlignment.Left;
                    costsLabel.verticalAlignment = UIVerticalAlignment.Middle;
                    costsLabel.textColor         = new Color32(255, 100, 100, 255);
                    costsLabel.color             = new Color32(91, 97, 106, 255);

                    returnsLabel.relativePosition  = new Vector3(0, (totalsPanel.height / 2f) - (effects.height / 2f));
                    returnsLabel.autoSize          = false;
                    returnsLabel.autoHeight        = false;
                    returnsLabel.width             = 40;
                    returnsLabel.height            = (totalsPanel.height / 2f) - (effects.height / 2f);
                    returnsLabel.name              = "ReturnsLabel";
                    returnsLabel.textScale         = 0.6f;
                    returnsLabel.padding           = new RectOffset(4, 4, 4, 4);
                    returnsLabel.textAlignment     = UIHorizontalAlignment.Left;
                    returnsLabel.verticalAlignment = UIVerticalAlignment.Middle;
                    returnsLabel.textColor         = new Color32(206, 248, 0, 255);
                    returnsLabel.color             = new Color32(91, 97, 106, 255);

                    costsReadout.relativePosition  = costsLabel.relativePosition + new Vector3(costsLabel.width + 5, 1);
                    costsReadout.autoSize          = false;
                    costsReadout.autoHeight        = false;
                    costsReadout.width             = totalsPanel.width - costsReadout.relativePosition.x - 5;
                    costsReadout.height            = costsLabel.height - 2;
                    costsReadout.atlas             = CimTools.CimToolsHandler.CimToolBase.SpriteUtilities.GetAtlas("Ingame");
                    costsReadout.backgroundSprite  = "TextFieldPanel";
                    costsReadout.name              = "Cost";
                    costsReadout.textScale         = 0.6f;
                    costsReadout.textAlignment     = UIHorizontalAlignment.Right;
                    costsReadout.verticalAlignment = UIVerticalAlignment.Middle;
                    costsReadout.textColor         = new Color32(238, 95, 0, 255);
                    costsReadout.color             = new Color32(45, 52, 61, 255);

                    returnsReadout.relativePosition  = returnsLabel.relativePosition + new Vector3(returnsLabel.width + 5, 1);
                    returnsReadout.autoSize          = false;
                    returnsReadout.autoHeight        = false;
                    returnsReadout.width             = totalsPanel.width - returnsReadout.relativePosition.x - 5;
                    returnsReadout.height            = returnsLabel.height - 2;
                    returnsReadout.atlas             = CimTools.CimToolsHandler.CimToolBase.SpriteUtilities.GetAtlas("Ingame");
                    returnsReadout.backgroundSprite  = "TextFieldPanel";
                    returnsReadout.name              = "Returns";
                    returnsReadout.textScale         = 0.6f;
                    returnsReadout.textAlignment     = UIHorizontalAlignment.Right;
                    returnsReadout.verticalAlignment = UIVerticalAlignment.Middle;
                    returnsReadout.textColor         = new Color32(151, 238, 0, 255);
                    returnsReadout.color             = new Color32(45, 52, 61, 255);

                    option.OnTicketSizeChanged += Option_OnTicketSizeChanged;

                    /*title.name = option.title;
                     * title.text = option.title;
                     * title.autoSize = false;
                     * title.relativePosition = new Vector2(0, 0);
                     * title.width = width - ((width * 40) / 100);
                     * title.height = sliderPanel.relativePosition.y;
                     * title.textScale = 1f;
                     * title.padding = new RectOffset(5, 5, 5, 5);
                     * title.tooltip = option.description;*/

                    Deselect(isRowOdd);
                    UpdateTotals();
                    UpdateVariableStrings();
                    Translation_OnLanguageChanged("Manual Call!");
                }
            }
        }
Exemplo n.º 11
0
 private void OnClick()
 {
     if (this.mChild == null && this.atlas != null && this.font != null && this.items.Count > 0)
     {
         this.mLabelList.Clear();
         this.handleEvents = true;
         if (this.mPanel == null)
         {
             this.mPanel = UIPanel.Find(base.transform, true);
         }
         Transform transform = base.transform;
         Bounds    bounds    = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, transform);
         this.mChild       = new GameObject("Drop-down List");
         this.mChild.layer = base.gameObject.layer;
         Transform transform2 = this.mChild.transform;
         transform2.parent        = transform.parent;
         transform2.localPosition = bounds.min;
         transform2.localRotation = Quaternion.identity;
         transform2.localScale    = Vectors.one;
         this.mBackground         = NGUITools.AddSprite(this.mChild, this.atlas, this.backgroundSprite);
         this.mBackground.pivot   = UIWidget.Pivot.TopLeft;
         this.mBackground.depth   = NGUITools.CalculateNextDepth(this.mPanel.gameObject);
         this.mBackground.color   = this.backgroundColor;
         Vector4 border = this.mBackground.border;
         this.mBgBorder = border.y;
         this.mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f);
         this.mHighlight       = NGUITools.AddSprite(this.mChild, this.atlas, this.highlightSprite);
         this.mHighlight.pivot = UIWidget.Pivot.TopLeft;
         this.mHighlight.color = this.highlightColor;
         UIAtlas.Sprite atlasSprite = this.mHighlight.GetAtlasSprite();
         if (atlasSprite == null)
         {
             return;
         }
         float          num   = atlasSprite.inner.yMin - atlasSprite.outer.yMin;
         float          num2  = (float)this.font.size * this.font.pixelSize * this.textScale;
         float          num3  = 0f;
         float          num4  = -this.padding.y;
         List <UILabel> list  = new List <UILabel>();
         int            i     = 0;
         int            count = this.items.Count;
         while (i < count)
         {
             string  text    = this.items[i];
             UILabel uilabel = NGUITools.AddWidget <UILabel>(this.mChild);
             uilabel.pivot = UIWidget.Pivot.TopLeft;
             uilabel.font  = this.font;
             uilabel.text  = ((!this.isLocalized || !(Localization.instance != null)) ? text : Localization.instance.Get(text));
             uilabel.color = this.textColor;
             uilabel.cachedTransform.localPosition = new Vector3(border.x + this.padding.x, num4, -1f);
             uilabel.MakePixelPerfect();
             if (this.textScale != 1f)
             {
                 Vector3 localScale = uilabel.cachedTransform.localScale;
                 uilabel.cachedTransform.localScale = localScale * this.textScale;
             }
             list.Add(uilabel);
             num4 -= num2;
             num4 -= this.padding.y;
             num3  = Mathf.Max(num3, uilabel.relativeSize.x * num2);
             UIEventListener uieventListener = UIEventListener.Get(uilabel.gameObject);
             uieventListener.onHover   = new UIEventListener.BoolDelegate(this.OnItemHover);
             uieventListener.onPress   = new UIEventListener.BoolDelegate(this.OnItemPress);
             uieventListener.parameter = text;
             if (this.mSelectedItem == text)
             {
                 this.Highlight(uilabel, true);
             }
             this.mLabelList.Add(uilabel);
             i++;
         }
         num3 = Mathf.Max(num3, bounds.size.x - (border.x + this.padding.x) * 2f);
         Vector3 center = new Vector3(num3 * 0.5f / num2, -0.5f, 0f);
         Vector3 size   = new Vector3(num3 / num2, (num2 + this.padding.y) / num2, 1f);
         int     j      = 0;
         int     count2 = list.Count;
         while (j < count2)
         {
             UILabel     uilabel2    = list[j];
             BoxCollider boxCollider = NGUITools.AddWidgetCollider(uilabel2.gameObject);
             center.z           = boxCollider.center.z;
             boxCollider.center = center;
             boxCollider.size   = size;
             j++;
         }
         num3 += (border.x + this.padding.x) * 2f;
         num4 -= border.y;
         this.mBackground.cachedTransform.localScale = new Vector3(num3, -num4 + border.y, 1f);
         this.mHighlight.cachedTransform.localScale  = new Vector3(num3 - (border.x + this.padding.x) * 2f + (atlasSprite.inner.xMin - atlasSprite.outer.xMin) * 2f, num2 + num * 2f, 1f);
         bool flag = this.position == UIPopupList.Position.Above;
         if (this.position == UIPopupList.Position.Auto)
         {
             UICamera uicamera = UICamera.FindCameraForLayer(base.gameObject.layer);
             if (uicamera != null)
             {
                 flag = (uicamera.cachedCamera.WorldToViewportPoint(transform.position).y < 0.5f);
             }
         }
         if (this.isAnimated)
         {
             float bottom = num4 + num2;
             this.Animate(this.mHighlight, flag, bottom);
             int k      = 0;
             int count3 = list.Count;
             while (k < count3)
             {
                 this.Animate(list[k], flag, bottom);
                 k++;
             }
             this.AnimateColor(this.mBackground);
             this.AnimateScale(this.mBackground, flag, bottom);
         }
         if (flag)
         {
             transform2.localPosition = new Vector3(bounds.min.x, bounds.max.y - num4 - border.y, bounds.min.z);
         }
     }
     else
     {
         this.OnSelect(false);
     }
 }
Exemplo n.º 12
0
 public QuayRoadsPanelField(NetInfo netInfo, int sectionIndex, FieldInfo fieldInfo, IConvertible flag, UIPanel parent, RoadEditorPanel parentPanel)
 {
     netInfo_      = netInfo;
     sectionIndex_ = sectionIndex;
     fieldInfo_    = fieldInfo;
     flag_         = flag;
     parentPanel_  = parentPanel;
     if (flag_ is not null)
     {
         Log.Debug(flag.ToString());
         Log.Debug(flag.ToUInt64().ToString());
         var propertyCheckbox = parent.AddUIComponent <UICheckBoxExt>();
         propertyCheckbox.Label              = "";
         propertyCheckbox.width              = 20f;
         propertyCheckbox.isChecked          = (AssetValue as IConvertible).IsFlagSet(flag);
         propertyCheckbox.eventCheckChanged += (_, _isChecked) => {
             //TODO: find a better / more robust way to do this.
             if (_isChecked)
             {
                 if (Enum.GetUnderlyingType(fieldInfo_.FieldType) == typeof(Int32))
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt32(CultureInfo.InvariantCulture) | flag.ToInt32(CultureInfo.InvariantCulture);
                 }
                 else
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt64() | flag.ToInt64();
                 }
             }
             else
             {
                 if (Enum.GetUnderlyingType(fieldInfo_.FieldType) == typeof(Int32))
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt32(CultureInfo.InvariantCulture) & ~flag.ToInt32(CultureInfo.InvariantCulture);
                 }
                 else
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt64() & ~flag.ToInt64();
                 }
             }
         };
     }
     else
     {
         // TODO: right now, this assumes everything that is not a flags enum is a float
         // TODO: find a better way to create a text field - maybe something similar to UICheckBoxExt from KianCommons?
         var propertyHelper    = new UIHelper(parent);
         var propertyTextField = propertyHelper.AddTextfield("wawa", (AssetValue as float?).ToString(), (_) => { }, (_) => { }) as UITextField;
         var labelObject       = parent.Find <UILabel>("Label");
         labelObject.parent.RemoveUIComponent(labelObject);
         Destroy(labelObject.gameObject);
         (propertyTextField.parent as UIPanel).autoFitChildrenHorizontally = true;
         (propertyTextField.parent as UIPanel).autoFitChildrenVertically   = true;
         propertyTextField.numericalOnly       = true;
         propertyTextField.allowFloats         = true;
         propertyTextField.allowNegative       = true;
         propertyTextField.eventTextSubmitted += (_, value) => {
             float newValue = (float)LenientStringToDouble(value, (double)(float)AssetValue);
             propertyTextField.text = newValue.ToString();
             if (newValue != (float)AssetValue)
             {
                 AssetValue = newValue;
             }
         };
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// If the mouse leaves the slider, this method shows total and hides percentage value.
 /// </summary>
 /// <param name="panel">The slider object the player hovers over</param>
 private void closePanel(UIPanel panel)
 {
     UILabel total = panel.Find<UILabel>("Total");
     total.isVisible = true;
     UILabel percentage = panel.Find<UILabel>("Percentage");
     percentage.isVisible = false;
     if (Parent.mode == Mode.Slim)
     {
         panel.width = 130;
         UIComponent slider = panel.Find("Slider");
         slider.isVisible = false;
         slider.size = new Vector2(210, slider.height);
         if (Parent.isLeft)
         {
             UISprite icon = panel.Find<UISprite>("Icon");
             icon.relativePosition = new Vector3(cs.iconX, icon.relativePosition.y);
             percentage.relativePosition = new Vector3(cs.percentageX, cs.percentageY);
             total.relativePosition = new Vector3(cs.totalX, cs.totalY);
         }
         else
         {
             percentage.relativePosition = new Vector3(45, cs.percentageY);
             total.relativePosition = new Vector3(45, cs.totalY);
         }
     }
     else if (Parent.mode == Mode.noSlider)
     {
         UIButton buttonPlus = panel.Find<UIButton>("Budget Plus One Button");
         UIButton buttonMinus = panel.Find<UIButton>("Budget Minus One Button");
         buttonPlus.isVisible = false;
         buttonMinus.isVisible = false;
     }
 }
Exemplo n.º 14
0
        public override void Start()
        {
            base.Start();

            Initialise();

            atlas            = CimTools.CimToolsHandler.CimToolBase.SpriteUtilities.GetAtlas("Ingame");
            backgroundSprite = "MenuPanel2";

            _titleBar.name             = "TitleBar";
            _titleBar.relativePosition = new Vector3(0, 0);
            _titleBar.width            = width;

            _informationLabel.width         = width;
            _informationLabel.padding       = new RectOffset(5, 5, 5, 5);
            _informationLabel.autoHeight    = true;
            _informationLabel.processMarkup = true;
            _informationLabel.wordWrap      = true;
            _informationLabel.textScale     = 0.7f;

            _ticketSlider.eventValueChanged += TicketSlider_eventValueChanged;

            UIPanel sliderPanel = _ticketSlider.parent as UIPanel;

            sliderPanel.name = "TicketSliderPanel";

            UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");

            sliderLabel.textScale = 0.8f;

            _totalPanel.atlas            = CimTools.CimToolsHandler.CimToolBase.SpriteUtilities.GetAtlas("Ingame");
            _totalPanel.backgroundSprite = "GenericPanel";
            _totalPanel.color            = new Color32(91, 97, 106, 255);
            _totalPanel.name             = "Totals";

            _totalAmountLabel.autoSize          = false;
            _totalAmountLabel.autoHeight        = false;
            _totalAmountLabel.name              = "TotalLabel";
            _totalAmountLabel.padding           = new RectOffset(4, 4, 4, 4);
            _totalAmountLabel.textAlignment     = UIHorizontalAlignment.Left;
            _totalAmountLabel.verticalAlignment = UIVerticalAlignment.Middle;
            _totalAmountLabel.textColor         = new Color32(255, 100, 100, 255);
            _totalAmountLabel.color             = new Color32(91, 97, 106, 255);
            _totalAmountLabel.textScale         = 0.7f;

            _totalIncomeLabel.autoSize          = false;
            _totalIncomeLabel.autoHeight        = false;
            _totalIncomeLabel.name              = "TotalIncome";
            _totalIncomeLabel.padding           = new RectOffset(4, 4, 4, 4);
            _totalIncomeLabel.textAlignment     = UIHorizontalAlignment.Left;
            _totalIncomeLabel.verticalAlignment = UIVerticalAlignment.Middle;
            _totalIncomeLabel.textColor         = new Color32(206, 248, 0, 255);
            _totalIncomeLabel.color             = new Color32(91, 97, 106, 255);
            _totalIncomeLabel.textScale         = 0.7f;

            _costLabel.autoSize          = false;
            _costLabel.autoHeight        = false;
            _costLabel.atlas             = CimTools.CimToolsHandler.CimToolBase.SpriteUtilities.GetAtlas("Ingame");
            _costLabel.backgroundSprite  = "TextFieldPanel";
            _costLabel.name              = "Cost";
            _costLabel.padding           = new RectOffset(4, 4, 2, 2);
            _costLabel.textAlignment     = UIHorizontalAlignment.Right;
            _costLabel.verticalAlignment = UIVerticalAlignment.Middle;
            _costLabel.textColor         = new Color32(238, 95, 0, 255);
            _costLabel.color             = new Color32(45, 52, 61, 255);
            _costLabel.textScale         = 0.7f;

            _incomeLabel.autoSize          = false;
            _incomeLabel.autoHeight        = false;
            _incomeLabel.atlas             = CimTools.CimToolsHandler.CimToolBase.SpriteUtilities.GetAtlas("Ingame");
            _incomeLabel.backgroundSprite  = "TextFieldPanel";
            _incomeLabel.name              = "Income";
            _incomeLabel.padding           = new RectOffset(4, 4, 2, 2);
            _incomeLabel.textAlignment     = UIHorizontalAlignment.Right;
            _incomeLabel.verticalAlignment = UIVerticalAlignment.Middle;
            _incomeLabel.textColor         = new Color32(151, 238, 0, 255);
            _incomeLabel.color             = new Color32(45, 52, 61, 255);
            _incomeLabel.textScale         = 0.7f;

            _incentiveList.canSelect        = false;
            _incentiveList.name             = "IncentiveSelectionList";
            _incentiveList.backgroundSprite = "UnlockingPanel";
            _incentiveList.rowHeight        = 76f;
            _incentiveList.rowsData.Clear();
            _incentiveList.selectedIndex = -1;

            sliderPanel           = _startTimeSlider.parent as UIPanel;
            sliderLabel           = sliderPanel.Find <UILabel>("Label");
            sliderLabel.textScale = 0.8f;

            sliderPanel           = _startDaySlider.parent as UIPanel;
            sliderLabel           = sliderPanel.Find <UILabel>("Label");
            sliderLabel.textScale = 0.8f;

            _createButton.textScale = 0.9f;
            _createButton.anchor    = UIAnchorStyle.Right | UIAnchorStyle.Bottom;

            Translation_OnLanguageChanged("Manually Called!");
            PerformLayout();
        }
Exemplo n.º 15
0
        public void CalculateTotal()
        {
            if (_linkedEvent != null && _ticketSlider != null)
            {
                EconomyManager    economyManager = Singleton <EconomyManager> .instance;
                CityEventXmlCosts costs          = _linkedEvent.GetCosts();

                totalCost = 0f;
                maxIncome = 0f;

                totalCost += costs._creation;
                totalCost += _ticketSlider.value * costs._perHead;

                maxIncome += _ticketSlider.value * costs._entry;

                if (_incentiveList != null)
                {
                    FastList <object> optionItems = _incentiveList.rowsData;

                    foreach (IncentiveOptionItem optionItemObject in optionItems)
                    {
                        totalCost += optionItemObject.cost * optionItemObject.sliderValue;
                        maxIncome += optionItemObject.returnCost * optionItemObject.sliderValue;
                    }
                }

                if (_costLabel != null)
                {
                    _costLabel.text   = totalCost.ToString(Settings.moneyFormat, LocaleManager.cultureInfo);
                    _incomeLabel.text = maxIncome.ToString(Settings.moneyFormat, LocaleManager.cultureInfo);
                }

                if (_ticketSlider != null)
                {
                    UIPanel sliderPanel = _ticketSlider.parent as UIPanel;
                    UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");
                    sliderLabel.text = string.Format(LocalisationStrings.EVENT_TICKETCOUNT, _ticketSlider.value);
                }

                if (_startTimeSlider != null)
                {
                    UIPanel sliderPanel = _startTimeSlider.parent as UIPanel;
                    UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");
                    sliderLabel.text = string.Format(LocalisationStrings.EVENT_STARTTIMESLIDER, TimeOfDaySlider.getTimeFromFloatingValue(_startTimeSlider.value));
                }

                if (_startDaySlider != null)
                {
                    UIPanel sliderPanel = _startDaySlider.parent as UIPanel;
                    UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");
                    sliderLabel.text = string.Format(LocalisationStrings.EVENT_STARTDAYSLIDER, _startDaySlider.value);
                }

                if (_createButton != null)
                {
                    int adjustedCost = Mathf.RoundToInt(totalCost * 100f);
                    if (economyManager.PeekResource(EconomyManager.Resource.Construction, adjustedCost) != adjustedCost)
                    {
                        _createButton.Disable();
                    }
                    else
                    {
                        _createButton.Enable();
                    }
                }
            }
        }
Exemplo n.º 16
0
        public override void PerformLayout()
        {
            base.PerformLayout();

            _titleBar.width = width;

            _informationLabel.width            = width;
            _informationLabel.relativePosition = new Vector3(0, _titleBar.height + 10);

            _ticketSlider.width = width - ((width * 60f) / 100f);

            UIPanel sliderPanel = _ticketSlider.parent as UIPanel;

            sliderPanel.width            = _ticketSlider.width;
            sliderPanel.relativePosition = new Vector3(10, _informationLabel.relativePosition.y + _informationLabel.height + 5);

            UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");

            sliderLabel.width = _ticketSlider.width;

            _totalPanel.relativePosition = sliderPanel.relativePosition + new Vector3(sliderPanel.width + 10, 0);
            _totalPanel.width            = width - sliderPanel.width - 30;
            _totalPanel.height           = sliderPanel.height;

            _totalAmountLabel.relativePosition = Vector3.zero;
            _totalAmountLabel.width            = 110;
            _totalAmountLabel.height           = _totalPanel.height / 2f;

            _totalIncomeLabel.relativePosition = _totalAmountLabel.relativePosition + new Vector3(0, _totalAmountLabel.height);
            _totalIncomeLabel.width            = 110;
            _totalIncomeLabel.height           = _totalPanel.height / 2f;

            _costLabel.relativePosition = _totalAmountLabel.relativePosition + new Vector3(_totalAmountLabel.width, 4);
            _costLabel.width            = _totalPanel.width - _totalAmountLabel.width - 4;
            _costLabel.height           = _totalAmountLabel.height - 8;

            _incomeLabel.relativePosition = _totalIncomeLabel.relativePosition + new Vector3(_totalIncomeLabel.width, 4);
            _incomeLabel.width            = _totalPanel.width - _totalIncomeLabel.width - 4;
            _incomeLabel.height           = _totalIncomeLabel.height - 8;

            _incentiveList.relativePosition = sliderPanel.relativePosition + new Vector3(0, sliderPanel.height + 10);
            _incentiveList.width            = width - 20;

            _createButton.height = sliderPanel.height;

            _incentiveList.height = height - _incentiveList.relativePosition.y - 20 - _createButton.height;

            float availableWidth = width - _createButton.width;

            _createButton.relativePosition = new Vector3(width - _createButton.width - 10, height - _createButton.height - 10);

            _startTimeSlider.width = (availableWidth / 2f) - 10;

            UIPanel startTimeSliderPanel = _startTimeSlider.parent as UIPanel;

            startTimeSliderPanel.width            = _startTimeSlider.width;
            startTimeSliderPanel.relativePosition = new Vector3(10, _createButton.relativePosition.y - 7f);

            sliderLabel       = startTimeSliderPanel.Find <UILabel>("Label");
            sliderLabel.width = _startTimeSlider.width;

            _startDaySlider.width = (availableWidth / 2f) - 35;

            UIPanel startDaySliderPanel = _startDaySlider.parent as UIPanel;

            startDaySliderPanel.width            = _startDaySlider.width;
            startDaySliderPanel.relativePosition = new Vector3(startTimeSliderPanel.relativePosition.x + startTimeSliderPanel.width + 5, _createButton.relativePosition.y - 7f);

            sliderLabel       = startTimeSliderPanel.Find <UILabel>("Label");
            sliderLabel.width = _startDaySlider.width;

            _incentiveList.DisplayAt(0);
        }
    // Token: 0x060002AD RID: 685 RVA: 0x0001AA7C File Offset: 0x00018C7C
    public virtual void Show()
    {
        if (!base.enabled || !NGUITools.GetActive(base.gameObject) || !(UIPopupList.mChild == null) || !this.isValid || this.items.Count <= 0)
        {
            this.OnSelect(false);
            return;
        }
        this.mLabelList.Clear();
        base.StopCoroutine("CloseIfUnselected");
        UICamera.selectedObject = (UICamera.hoveredObject ?? base.gameObject);
        this.mSelection         = UICamera.selectedObject;
        this.source             = this.mSelection;
        if (this.source == null)
        {
            Debug.LogError("Popup list needs a source object...");
            return;
        }
        this.mOpenFrame = Time.frameCount;
        if (this.mPanel == null)
        {
            this.mPanel = UIPanel.Find(base.transform);
            if (this.mPanel == null)
            {
                return;
            }
        }
        UIPopupList.mChild       = new GameObject("Drop-down List");
        UIPopupList.mChild.layer = base.gameObject.layer;
        if (this.separatePanel)
        {
            if (base.GetComponent <Collider>() != null)
            {
                UIPopupList.mChild.AddComponent <Rigidbody>().isKinematic = true;
            }
            else if (base.GetComponent <Collider2D>() != null)
            {
                UIPopupList.mChild.AddComponent <Rigidbody2D>().isKinematic = true;
            }
            UIPanel uipanel = UIPopupList.mChild.AddComponent <UIPanel>();
            uipanel.depth        = 1000000;
            uipanel.sortingOrder = this.mPanel.sortingOrder;
        }
        UIPopupList.current = this;
        Transform cachedTransform = this.mPanel.cachedTransform;
        Transform transform       = UIPopupList.mChild.transform;

        transform.parent = cachedTransform;
        Transform parent = cachedTransform;

        if (this.separatePanel)
        {
            UIRoot uiroot = this.mPanel.GetComponentInParent <UIRoot>();
            if (uiroot == null && UIRoot.list.Count != 0)
            {
                uiroot = UIRoot.list[0];
            }
            if (uiroot != null)
            {
                parent = uiroot.transform;
            }
        }
        Vector3 vector;
        Vector3 vector2;

        if (this.openOn == UIPopupList.OpenOn.Manual && this.mSelection != base.gameObject)
        {
            this.startingPosition = UICamera.lastEventPosition;
            vector  = cachedTransform.InverseTransformPoint(this.mPanel.anchorCamera.ScreenToWorldPoint(this.startingPosition));
            vector2 = vector;
            transform.localPosition = vector;
            this.startingPosition   = transform.position;
        }
        else
        {
            Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(cachedTransform, base.transform, false, false);
            vector  = bounds.min;
            vector2 = bounds.max;
            transform.localPosition = vector;
            this.startingPosition   = transform.position;
        }
        base.StartCoroutine("CloseIfUnselected");
        float fitScale = this.fitScale;

        transform.localRotation = Quaternion.identity;
        transform.localScale    = new Vector3(fitScale, fitScale, fitScale);
        int num = this.separatePanel ? 0 : NGUITools.CalculateNextDepth(this.mPanel.gameObject);

        if (this.background2DSprite != null)
        {
            UI2DSprite ui2DSprite = UIPopupList.mChild.AddWidget(num);
            ui2DSprite.sprite2D = this.background2DSprite;
            this.mBackground    = ui2DSprite;
        }
        else
        {
            if (!(this.atlas != null))
            {
                return;
            }
            this.mBackground = UIPopupList.mChild.AddSprite(this.atlas as INGUIAtlas, this.backgroundSprite, num);
        }
        bool flag = this.position == UIPopupList.Position.Above;

        if (this.position == UIPopupList.Position.Auto)
        {
            UICamera uicamera = UICamera.FindCameraForLayer(this.mSelection.layer);
            if (uicamera != null)
            {
                flag = (uicamera.cachedCamera.WorldToViewportPoint(this.startingPosition).y < 0.5f);
            }
        }
        this.mBackground.pivot = UIWidget.Pivot.TopLeft;
        this.mBackground.color = this.backgroundColor;
        Vector4 border = this.mBackground.border;

        this.mBgBorder = border.y;
        this.mBackground.cachedTransform.localPosition = new Vector3(0f, flag ? (border.y * 2f - (float)this.overlap) : ((float)this.overlap), 0f);
        if (this.highlight2DSprite != null)
        {
            UI2DSprite ui2DSprite2 = UIPopupList.mChild.AddWidget(num + 1);
            ui2DSprite2.sprite2D = this.highlight2DSprite;
            this.mHighlight      = ui2DSprite2;
        }
        else
        {
            if (!(this.atlas != null))
            {
                return;
            }
            this.mHighlight = UIPopupList.mChild.AddSprite(this.atlas as INGUIAtlas, this.highlightSprite, num + 1);
        }
        float num2 = 0f;
        float num3 = 0f;

        if (this.mHighlight.hasBorder)
        {
            num2 = this.mHighlight.border.w;
            num3 = this.mHighlight.border.x;
        }
        this.mHighlight.pivot = UIWidget.Pivot.TopLeft;
        this.mHighlight.color = this.highlightColor;
        float          num4 = (float)this.activeFontSize * this.activeFontScale;
        float          num5 = num4 + this.padding.y;
        float          num6 = 0f;
        float          num7 = flag ? (border.y - this.padding.y - (float)this.overlap) : (-this.padding.y - border.y + (float)this.overlap);
        float          num8 = border.y * 2f + this.padding.y;
        List <UILabel> list = new List <UILabel>();

        if (!this.items.Contains(this.mSelectedItem))
        {
            this.mSelectedItem = null;
        }
        int i     = 0;
        int count = this.items.Count;

        while (i < count)
        {
            string  text    = this.items[i];
            UILabel uilabel = UIPopupList.mChild.AddWidget(this.mBackground.depth + 2);
            uilabel.name         = i.ToString();
            uilabel.pivot        = UIWidget.Pivot.TopLeft;
            uilabel.bitmapFont   = (this.bitmapFont as INGUIFont);
            uilabel.trueTypeFont = this.trueTypeFont;
            uilabel.fontSize     = this.fontSize;
            uilabel.fontStyle    = this.fontStyle;
            uilabel.text         = (this.isLocalized ? Localization.Get(text, true) : text);
            uilabel.modifier     = this.textModifier;
            uilabel.color        = this.textColor;
            uilabel.cachedTransform.localPosition = new Vector3(border.x + this.padding.x - uilabel.pivotOffset.x, num7, -1f);
            uilabel.overflowMethod = UILabel.Overflow.ResizeFreely;
            uilabel.alignment      = this.alignment;
            uilabel.symbolStyle    = NGUIText.SymbolStyle.Colored;
            list.Add(uilabel);
            num8 += num5;
            num7 -= num5;
            num6  = Mathf.Max(num6, uilabel.printedSize.x);
            UIEventListener uieventListener = UIEventListener.Get(uilabel.gameObject);
            uieventListener.onHover   = new UIEventListener.BoolDelegate(this.OnItemHover);
            uieventListener.onPress   = new UIEventListener.BoolDelegate(this.OnItemPress);
            uieventListener.onClick   = new UIEventListener.VoidDelegate(this.OnItemClick);
            uieventListener.parameter = text;
            if (this.mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(this.mSelectedItem)))
            {
                this.Highlight(uilabel, true);
            }
            this.mLabelList.Add(uilabel);
            i++;
        }
        num6 = Mathf.Max(num6, vector2.x - vector.x - (border.x + this.padding.x) * 2f);
        float   num9    = num6;
        Vector3 vector3 = new Vector3(num9 * 0.5f, -num4 * 0.5f, 0f);
        Vector3 vector4 = new Vector3(num9, num4 + this.padding.y, 1f);
        int     j       = 0;
        int     count2  = list.Count;

        while (j < count2)
        {
            UILabel uilabel2 = list[j];
            NGUITools.AddWidgetCollider(uilabel2.gameObject);
            uilabel2.autoResizeBoxCollider = false;
            BoxCollider component = uilabel2.GetComponent <BoxCollider>();
            if (component != null)
            {
                vector3.z        = component.center.z;
                component.center = vector3;
                component.size   = vector4;
            }
            else
            {
                BoxCollider2D component2 = uilabel2.GetComponent <BoxCollider2D>();
                component2.offset = vector3;
                component2.size   = vector4;
            }
            j++;
        }
        int width = Mathf.RoundToInt(num6);

        num6 += (border.x + this.padding.x) * 2f;
        num7 -= border.y;
        this.mBackground.width  = Mathf.RoundToInt(num6);
        this.mBackground.height = Mathf.RoundToInt(num8);
        int k      = 0;
        int count3 = list.Count;

        while (k < count3)
        {
            UILabel uilabel3 = list[k];
            uilabel3.overflowMethod = UILabel.Overflow.ShrinkContent;
            uilabel3.width          = width;
            k++;
        }
        float      num10      = 2f;
        INGUIAtlas inguiatlas = this.atlas as INGUIAtlas;

        if (inguiatlas != null)
        {
            num10 *= inguiatlas.pixelSize;
        }
        float f  = num6 - (border.x + this.padding.x) * 2f + num3 * num10;
        float f2 = num4 + num2 * num10;

        this.mHighlight.width  = Mathf.RoundToInt(f);
        this.mHighlight.height = Mathf.RoundToInt(f2);
        if (this.isAnimated)
        {
            this.AnimateColor(this.mBackground);
            if (Time.timeScale == 0f || Time.timeScale >= 0.1f)
            {
                float bottom = num7 + num4;
                this.Animate(this.mHighlight, flag, bottom);
                int l      = 0;
                int count4 = list.Count;
                while (l < count4)
                {
                    this.Animate(list[l], flag, bottom);
                    l++;
                }
                this.AnimateScale(this.mBackground, flag, bottom);
            }
        }
        if (flag)
        {
            float num11 = border.y * fitScale;
            vector.y  = vector2.y - border.y * fitScale;
            vector2.y = vector.y + ((float)this.mBackground.height - border.y * 2f) * fitScale;
            vector2.x = vector.x + (float)this.mBackground.width * fitScale;
            transform.localPosition = new Vector3(vector.x, vector2.y - num11, vector.z);
        }
        else
        {
            vector2.y = vector.y + border.y * fitScale;
            vector.y  = vector2.y - (float)this.mBackground.height * fitScale;
            vector2.x = vector.x + (float)this.mBackground.width * fitScale;
        }
        UIPanel uipanel2 = this.mPanel;

        for (;;)
        {
            UIRect parent2 = uipanel2.parent;
            if (parent2 == null)
            {
                break;
            }
            UIPanel componentInParent = parent2.GetComponentInParent <UIPanel>();
            if (componentInParent == null)
            {
                break;
            }
            uipanel2 = componentInParent;
        }
        if (cachedTransform != null)
        {
            vector  = cachedTransform.TransformPoint(vector);
            vector2 = cachedTransform.TransformPoint(vector2);
            vector  = uipanel2.cachedTransform.InverseTransformPoint(vector);
            vector2 = uipanel2.cachedTransform.InverseTransformPoint(vector2);
            float pixelSizeAdjustment = UIRoot.GetPixelSizeAdjustment(base.gameObject);
            vector  /= pixelSizeAdjustment;
            vector2 /= pixelSizeAdjustment;
        }
        Vector3 b       = uipanel2.CalculateConstrainOffset(vector, vector2);
        Vector3 vector5 = transform.localPosition + b;

        vector5.x = Mathf.Round(vector5.x);
        vector5.y = Mathf.Round(vector5.y);
        transform.localPosition = vector5;
        transform.parent        = parent;
    }
Exemplo n.º 18
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            // do base processing
            base.OnLevelLoaded(mode);

            try
            {
                // initialize only if user has Industries DLC
                if (SteamHelper.IsDLCOwned(SteamHelper.DLC.IndustryDLC))
                {
                    // check for new or loaded game
                    if (mode == LoadMode.NewGame || mode == LoadMode.NewGameFromScenario || mode == LoadMode.LoadGame)
                    {
                        // initialize Harmony
                        ExcludeMail.harmony = HarmonyInstance.Create("com.github.rcav8tr.ExcludeMail");
                        if (ExcludeMail.harmony == null)
                        {
                            Debug.LogError("Unable to create Harmony instance.");
                            return;
                        }

                        // find Ingame atlas
                        UITextureAtlas   ingameAtlas = null;
                        UITextureAtlas[] atlases     = Resources.FindObjectsOfTypeAll(typeof(UITextureAtlas)) as UITextureAtlas[];
                        for (int i = 0; i < atlases.Length; i++)
                        {
                            if (atlases[i] != null)
                            {
                                if (atlases[i].name == "Ingame")
                                {
                                    ingameAtlas = atlases[i];
                                    break;
                                }
                            }
                        }
                        if (ingameAtlas == null)
                        {
                            Debug.LogError("Unable to find atlas [Ingame].");
                            return;
                        }

                        // get the OutsideConnectionsInfoViewPanel panel (displayed when the user clicks on the Outside Connections info view button)
                        OutsideConnectionsInfoViewPanel ocPanel = UIView.library.Get <OutsideConnectionsInfoViewPanel>(typeof(OutsideConnectionsInfoViewPanel).Name);
                        if (ocPanel == null)
                        {
                            Debug.LogError("Unable to find [OutsideConnectionsInfoViewPanel].");
                            return;
                        }

                        // find the import and export legend mail panels
                        UIPanel importLegendMailPanel = ocPanel.Find <UIPanel>("ResourceLegendMail");
                        if (importLegendMailPanel == null)
                        {
                            Debug.LogError($"Unable to find panel [ResourceLegendMail] on [OutsideConnectionsInfoViewPanel]");
                            return;
                        }
                        UIPanel exportLegendMailPanel = ocPanel.Find <UIPanel>("ResourceLegendMail2");
                        if (exportLegendMailPanel == null)
                        {
                            Debug.LogError($"Unable to find panel [ResourceLegendMail2] on [OutsideConnectionsInfoViewPanel]");
                            return;
                        }

                        // find the import and export legend mail boxes
                        _importLegendMailBox = importLegendMailPanel.Find <UISprite>("MailColor");
                        if (_importLegendMailBox == null)
                        {
                            Debug.LogError($"Unable to find import sprite [MailColor] on [ResourceLegendMail] on [OutsideConnectionsInfoViewPanel]");
                            return;
                        }
                        _exportLegendMailBox = exportLegendMailPanel.Find <UISprite>("MailColor");
                        if (_exportLegendMailBox == null)
                        {
                            Debug.LogError($"Unable to find export sprite [MailColor] on [ResourceLegendMail2] on [OutsideConnectionsInfoViewPanel]");
                            return;
                        }

                        // find the import and export legend mail labels
                        _importLegendMailLabel = importLegendMailPanel.Find <UILabel>("Type");
                        if (_importLegendMailLabel == null)
                        {
                            Debug.LogError($"Unable to find import label [Type] on [ResourceLegendMail] on [OutsideConnectionsInfoViewPanel]");
                            return;
                        }
                        _exportLegendMailLabel = exportLegendMailPanel.Find <UILabel>("Type");
                        if (_exportLegendMailLabel == null)
                        {
                            Debug.LogError($"Unable to find export label [Type] on [ResourceLegendMail2] on [OutsideConnectionsInfoViewPanel]");
                            return;
                        }

                        // find import total label
                        UILabel totalLabel = ocPanel.Find <UILabel>("ImportTotal");
                        if (totalLabel == null)
                        {
                            Debug.LogError("Unable to find label [ImportTotal] on [OutsideConnectionsInfoViewPanel].");
                            return;
                        }

                        // create the check box (i.e. a sprite)
                        _includeMailCheckBox = ocPanel.component.AddUIComponent <UISprite>();
                        if (_includeMailCheckBox == null)
                        {
                            Debug.LogError("Unable to create check box sprite on [OutsideConnectionsInfoViewPanel].");
                            return;
                        }
                        _includeMailCheckBox.name             = "IncludeMailCheckBox";
                        _includeMailCheckBox.autoSize         = false;
                        _includeMailCheckBox.size             = new Vector2(totalLabel.size.y, totalLabel.size.y); // width is same as height
                        _includeMailCheckBox.relativePosition = new Vector3(8f, 82f);
                        _includeMailCheckBox.atlas            = ingameAtlas;
                        SetCheckBox(_includeMailCheckBox, true);
                        _includeMailCheckBox.isVisible = true;
                        _includeMailCheckBox.BringToFront();
                        _includeMailCheckBox.eventClicked += CheckBox_eventClicked;

                        // create the label and right align it to the info view
                        _includeMailLabel = ocPanel.component.AddUIComponent <UILabel>();
                        if (_includeMailLabel == null)
                        {
                            Debug.LogError("Unable to create label on [OutsideConnectionsInfoViewPanel].");
                            return;
                        }
                        _includeMailLabel.name              = "IncludeMailLabel";
                        _includeMailLabel.text              = "Include Mail";
                        _includeMailLabel.textAlignment     = UIHorizontalAlignment.Left;
                        _includeMailLabel.verticalAlignment = UIVerticalAlignment.Top;
                        _includeMailLabel.font              = totalLabel.font;
                        _includeMailLabel.textScale         = totalLabel.textScale;
                        _includeMailLabel.textColor         = totalLabel.textColor;
                        _includeMailLabel.autoSize          = true;
                        _includeMailLabel.relativePosition  = new Vector3(_includeMailCheckBox.relativePosition.x + _includeMailCheckBox.size.x + 5f, _includeMailCheckBox.relativePosition.y + 2.5f);
                        _includeMailLabel.isVisible         = true;
                        _includeMailLabel.BringToFront();
                        _includeMailLabel.eventClicked += Label_eventClicked;

                        // create the patches
                        PostOfficeAIPatch.CreateGetColorPatch();
                        PostVanAIPatch.CreateGetColorPatch();
                        OutsideConnectionsInfoViewPanelPatch.CreateUpdatePanelPatch();

                        // legend colors are not initialized
                        _legendColorsInitialized = false;
                    }
                }
                else
                {
                    // show a nice message
                    ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel", true);
                    panel.SetMessage(
                        "Exclude Mail Mod",
                        "Industries DLC is not installed.  Having the Exclude Mail mod enabled without Industries DLC will not cause an error in the mod, but the functionality of the mod will not be available.",
                        false);
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
        public void OnSettingsUI(UIHelperBase helper)
        {
            if (LocalizationManager.instance == null)
            {
                LocalizationManager.CreateManager();
            }

            UIHelperBase group       = helper.AddGroup("    Procedural Objects");
            UIPanel      globalPanel = ((UIPanel)((UIHelper)group).self);

            propRenderSlider         = (UISlider)group.AddSlider(string.Format(LocalizationManager.instance.current["settings_RD_PROP_label"], PropRenderDistance.value.ToString()), 0f, 16000f, 10f, PropRenderDistance.value, propRenderDistanceChanged);
            propRenderSlider.width   = 715;
            propRenderSlider.height  = 16;
            propRenderSlider.tooltip = LocalizationManager.instance.current["settings_RD_PROP_tooltip"];

            var propRenderPanel = globalPanel.Find <UIPanel>("OptionsSliderTemplate(Clone)");

            propRenderPanel.name   = "PropRenderSliderPanel";
            propRenderLabel        = propRenderPanel.Find <UILabel>("Label");
            propRenderLabel.width *= 3.5f;

            //  group.AddSpace(10);

            buildingRenderSlider         = (UISlider)group.AddSlider(string.Format(LocalizationManager.instance.current["settings_RD_BUILDING_label"], BuildingRenderDistance.value.ToString()), 0f, 16000f, 10f, BuildingRenderDistance.value, buildingRenderDistanceChanged);
            buildingRenderSlider.width   = 715;
            buildingRenderSlider.height  = 16;
            buildingRenderSlider.tooltip = LocalizationManager.instance.current["settings_RD_BUILDING_tooltip"];

            var buildingRenderPanel = globalPanel.components.First(c => c.GetType() == typeof(UIPanel) && c != propRenderPanel);

            buildingRenderPanel.name   = "BuildingRenderSliderPanel";
            buildingRenderLabel        = buildingRenderPanel.Find <UILabel>("Label");
            buildingRenderLabel.width *= 3.5f;


            //  group.AddSpace(10);

            gizmoSizeSlider         = (UISlider)group.AddSlider(string.Format(LocalizationManager.instance.current["settings_GIZMO_label"], GizmoSize.value.ToString()), 0.3f, 2.5f, 0.1f, GizmoSize.value, gizmoSizeChanged);
            gizmoSizeSlider.width   = 715;
            gizmoSizeSlider.height  = 16;
            gizmoSizeSlider.tooltip = LocalizationManager.instance.current["settings_GIZMO_tooltip"];

            var gizmoPanel = globalPanel.components.First(c => c.GetType() == typeof(UIPanel) && c != propRenderPanel && c != buildingRenderPanel);

            gizmoPanel.name       = "GizmoSizePanel";
            gizmoSizeLabel        = gizmoPanel.Find <UILabel>("Label");
            gizmoSizeLabel.width *= 3.5f;

            group.AddSpace(32);

            var sliderGroup = helper.AddGroup("  " + LocalizationManager.instance.current["settings_CONFDEL_title"]);

            confirmDelCheckbox = (UICheckBox)sliderGroup.AddCheckbox(LocalizationManager.instance.current["settings_CONFDEL_toggle"], ShowConfirmDeletion.value, confirmDeletionCheckboxChanged);

            //   sliderGroup.AddSpace(10);

            confirmDelThresholdSlider         = (UISlider)sliderGroup.AddSlider(string.Format(LocalizationManager.instance.current["settings_CONFDEL_SLIDER_label"], ConfirmDeletionThreshold.value.ToString()), 1f, 15f, 1f, ConfirmDeletionThreshold.value, confirmDeletionThresholdChanged);
            confirmDelThresholdSlider.width   = 715;
            confirmDelThresholdSlider.height  = 16;
            confirmDelThresholdSlider.tooltip = LocalizationManager.instance.current["settings_CONFDEL_SLIDER_tooltip"];

            confirmDelThresholdLabel = (UILabel)((UIPanel)((UIHelper)sliderGroup).self).components.First(c => c.GetType() == typeof(UIPanel) && c.components.Any(comp => comp.GetType() == typeof(UISlider)))
                                       .components.First(c => c.GetType() == typeof(UILabel));
            confirmDelThresholdLabel.width *= 3.5f;
            if (!ShowConfirmDeletion.value)
            {
                confirmDelThresholdSlider.isEnabled = false;
            }

            sliderGroup.AddSpace(32);
            var languageGroup = helper.AddGroup("  " + LocalizationManager.instance.current["settings_LANG_title"]);

            languageGroup.AddDropdown("Language selection", LocalizationManager.instance.identifiers, LocalizationManager.instance.available.IndexOf(LocalizationManager.instance.current), languageChanged);

            languageGroup.AddSpace(32);

            showDevCheckbox = (UICheckBox)languageGroup.AddCheckbox(LocalizationManager.instance.current["settings_DEVTOOLS_toggle"], ShowDeveloperTools.value, (value) =>
            {
                ShowDeveloperTools.value = value;
            });
            showDevCheckbox.tooltip = LocalizationManager.instance.current["settings_DEVTOOLS_tooltip"];
        }
Exemplo n.º 20
0
 public void Show()
 {
     if (base.enabled && NGUITools.GetActive(base.gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
     {
         mLabelList.Clear();
         if (mPanel == null)
         {
             mPanel = UIPanel.Find(base.transform);
             if (mPanel == null)
             {
                 return;
             }
         }
         handleEvents = true;
         Transform transform = base.transform;
         Bounds    bounds    = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, transform);
         mChild       = new GameObject("Drop-down List");
         mChild.layer = base.gameObject.layer;
         Transform transform2 = mChild.transform;
         transform2.parent        = transform.parent;
         transform2.localPosition = bounds.min;
         transform2.localRotation = Quaternion.identity;
         transform2.localScale    = Vector3.one;
         mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
         mBackground.pivot = UIWidget.Pivot.TopLeft;
         mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
         mBackground.color = backgroundColor;
         Vector4 border = mBackground.border;
         mBgBorder = border.y;
         mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f);
         mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
         mHighlight.pivot = UIWidget.Pivot.TopLeft;
         mHighlight.color = highlightColor;
         UISpriteData atlasSprite = mHighlight.GetAtlasSprite();
         if (atlasSprite != null)
         {
             float          num             = (float)atlasSprite.borderTop;
             float          num2            = (float)activeFontSize;
             float          activeFontScale = this.activeFontScale;
             float          num3            = num2 * activeFontScale;
             float          num4            = 0f;
             float          num5            = 0f - padding.y;
             List <UILabel> list            = new List <UILabel>();
             if (!items.Contains(mSelectedItem))
             {
                 mSelectedItem = null;
             }
             int i = 0;
             for (int count = items.Count; i < count; i++)
             {
                 string  text    = items[i];
                 UILabel uILabel = NGUITools.AddWidget <UILabel>(mChild);
                 uILabel.name         = i.ToString();
                 uILabel.pivot        = UIWidget.Pivot.TopLeft;
                 uILabel.bitmapFont   = bitmapFont;
                 uILabel.trueTypeFont = trueTypeFont;
                 uILabel.fontSize     = fontSize;
                 uILabel.fontStyle    = fontStyle;
                 uILabel.text         = ((!isLocalized) ? text : Localization.Get(text));
                 uILabel.color        = textColor;
                 Transform cachedTransform = uILabel.cachedTransform;
                 float     num6            = border.x + padding.x;
                 Vector2   pivotOffset     = uILabel.pivotOffset;
                 cachedTransform.localPosition = new Vector3(num6 - pivotOffset.x, num5, -1f);
                 uILabel.overflowMethod        = UILabel.Overflow.ResizeFreely;
                 uILabel.alignment             = alignment;
                 list.Add(uILabel);
                 num5 -= num3;
                 num5 -= padding.y;
                 float   a           = num4;
                 Vector2 printedSize = uILabel.printedSize;
                 num4 = Mathf.Max(a, printedSize.x);
                 UIEventListener uIEventListener = UIEventListener.Get(uILabel.gameObject);
                 uIEventListener.onHover   = OnItemHover;
                 uIEventListener.onPress   = OnItemPress;
                 uIEventListener.onClick   = OnItemClick;
                 uIEventListener.parameter = text;
                 if (mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                 {
                     Highlight(uILabel, instant: true);
                 }
                 mLabelList.Add(uILabel);
             }
             float   a2   = num4;
             Vector3 size = bounds.size;
             num4 = Mathf.Max(a2, size.x * activeFontScale - (border.x + padding.x) * 2f);
             float   num7    = num4;
             Vector3 vector  = new Vector3(num7 * 0.5f, (0f - num2) * 0.5f, 0f);
             Vector3 vector2 = new Vector3(num7, num3 + padding.y, 1f);
             int     j       = 0;
             for (int count2 = list.Count; j < count2; j++)
             {
                 UILabel uILabel2 = list[j];
                 NGUITools.AddWidgetCollider(uILabel2.gameObject);
                 uILabel2.autoResizeBoxCollider = false;
                 BoxCollider component = uILabel2.GetComponent <BoxCollider>();
                 if (component != null)
                 {
                     Vector3 center = component.center;
                     vector.z         = center.z;
                     component.center = vector;
                     component.size   = vector2;
                 }
                 else
                 {
                     BoxCollider2D component2 = uILabel2.GetComponent <BoxCollider2D>();
                     component2.offset = vector;
                     component2.size   = vector2;
                 }
             }
             int width = Mathf.RoundToInt(num4);
             num4 += (border.x + padding.x) * 2f;
             num5 -= border.y;
             mBackground.width  = Mathf.RoundToInt(num4);
             mBackground.height = Mathf.RoundToInt(0f - num5 + border.y);
             int k = 0;
             for (int count3 = list.Count; k < count3; k++)
             {
                 UILabel uILabel3 = list[k];
                 uILabel3.overflowMethod = UILabel.Overflow.ShrinkContent;
                 uILabel3.width          = width;
             }
             float num8 = 2f * atlas.pixelSize;
             float f    = num4 - (border.x + padding.x) * 2f + (float)atlasSprite.borderLeft * num8;
             float f2   = num3 + num * num8;
             mHighlight.width  = Mathf.RoundToInt(f);
             mHighlight.height = Mathf.RoundToInt(f2);
             bool flag = position == Position.Above;
             if (position == Position.Auto)
             {
                 UICamera uICamera = UICamera.FindCameraForLayer(base.gameObject.layer);
                 if (uICamera != null)
                 {
                     Vector3 vector3 = uICamera.cachedCamera.WorldToViewportPoint(transform.position);
                     flag = (vector3.y < 0.5f);
                 }
             }
             if (isAnimated)
             {
                 float bottom = num5 + num3;
                 Animate(mHighlight, flag, bottom);
                 int l = 0;
                 for (int count4 = list.Count; l < count4; l++)
                 {
                     Animate(list[l], flag, bottom);
                 }
                 AnimateColor(mBackground);
                 AnimateScale(mBackground, flag, bottom);
             }
             if (flag)
             {
                 Transform transform3 = transform2;
                 Vector3   min        = bounds.min;
                 float     x          = min.x;
                 Vector3   max        = bounds.max;
                 float     y          = max.y - num5 - border.y;
                 Vector3   min2       = bounds.min;
                 transform3.localPosition = new Vector3(x, y, min2.z);
             }
         }
     }
     else
     {
         OnSelect(isSelected: false);
     }
 }
Exemplo n.º 21
0
    /// <summary>
    /// Display the drop-down list when the game object gets clicked on.
    /// </summary>

    void OnClick()
    {
        if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && font != null && items.Count > 0)
        {
            mLabelList.Clear();

            // Disable the navigation script
            handleEvents = true;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = UIPanel.Find(transform, true);
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Transform myTrans = transform;
            Bounds    bounds  = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;
            UIPanel droplistPanel = mChild.AddComponent <UIPanel>();
            if (droplistPanel != null)
            {
                droplistPanel.depth = 700;
            }

            Transform t = mChild.transform;
            t.parent        = myTrans.parent;
            t.localPosition = bounds.min;
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = UIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;

            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            UISpriteData hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null)
            {
                return;
            }

            float          hlspHeight = hlsp.borderTop;
            float          labelHeight = font.size * font.pixelSize * textScale;
            float          x = 0f, y = -padding.y;
            List <UILabel> labels = new List <UILabel>();

            // 加个补丁,如果国际化过程导致无法选中默认值,则设置一个默认值。
            UILabel labelFirst  = null;
            bool    bFocusLabel = false;
            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s        = items[i];
                string curDicID = "0";
                if (useDicTable)
                {
                    int id = 0;
                    if (int.TryParse(s, out id))
                    {
                        string val = Utils.GetDicByID(id);
                        s        = val;
                        curDicID = id.ToString();
                    }
                }

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild);
                lbl.pivot = UIWidget.Pivot.TopLeft;
                lbl.font  = font;
                lbl.text  = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s;
                lbl.color = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -1f);
                lbl.overflowMethod = UILabel.Overflow.ResizeFreely;

                Transform lblTrans = lbl.gameObject.transform;
                lblTrans.localPosition = new Vector3(lblTrans.localPosition.x, lblTrans.localPosition.y, 0);

                lbl.MakePixelPerfect();
                if (textScale != 1f)
                {
                    lbl.cachedTransform.localScale = Vector3.one * textScale;
                }
                labels.Add(lbl);

                y -= labelHeight;
                y -= padding.y;
                x  = Mathf.Max(x, labelHeight);

                // Add an event listener
                UIEventListener listener = UIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s || mSelectedItem == curDicID)
                {
                    Highlight(lbl, true);
                    bFocusLabel = true;
                }

                if (null == labelFirst)
                {
                    labelFirst = lbl;
                }
                // Add this label to the list
                mLabelList.Add(lbl);
            }

            if (!bFocusLabel && null != labelFirst)
            {
                Highlight(labelFirst, true);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f);

            Vector3 bcCenter = new Vector3(x * 0.5f, -labelHeight * 0.5f, 0f);
            Vector3 bcSize   = new Vector3(x, (labelHeight + padding.y), 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel     lbl = labels[i];
                BoxCollider bc  = NGUITools.AddWidgetCollider(lbl.gameObject);
                bcCenter.z = bc.center.z;
                bc.center  = bcCenter;
                bc.size    = bcSize;
            }

            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.width  = Mathf.RoundToInt(x);
            mBackground.height = Mathf.RoundToInt(-y + bgPadding.y);

            // Scale the highlight sprite to envelop a single item
            float scaleFactor = 2f * atlas.pixelSize;
            float w           = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor;
            float h           = labelHeight + hlspHeight * scaleFactor;
            mHighlight.width  = Mathf.RoundToInt(w);
            mHighlight.height = Mathf.RoundToInt(h);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.FindCameraForLayer(gameObject.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                float bottom = y + labelHeight;
                Animate(mHighlight, placeAbove, bottom);
                for (int i = 0, imax = labels.Count; i < imax; ++i)
                {
                    Animate(labels[i], placeAbove, bottom);
                }
                AnimateColor(mBackground);
                AnimateScale(mBackground, placeAbove, bottom);
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z);
            }
        }
        else
        {
            OnSelect(false);
        }
    }
        public void OnSettingsUI(UIHelperBase helper)
        {
            if (LocalizationManager.instance == null)
            {
                LocalizationManager.CreateManager();
            }
            SetUnits();

            ExtUITabstrip tabStrip = ExtUITabstrip.Create((UIHelper)helper);

            UIHelper     gentab         = tabStrip.AddTabPage("  " + LocalizationManager.instance.current["settings_GENERAL"] + "  ", out genTabButton);
            UIHelperBase group          = gentab.AddGroup(LocalizationManager.instance.current["settings_GENERAL"]);
            UIHelper     keybindingsTab = tabStrip.AddTabPage(" " + LocalizationManager.instance.current["settings_KB"] + " ", out kbTabButton);
            UIHelperBase kbGroup        = keybindingsTab.AddGroup(LocalizationManager.instance.current["settings_KB"]);

            // UIHelperBase group = helper.AddGroup("    Procedural Objects");

            // KEY BINDINGS TAB

            ((UIPanel)((UIHelper)kbGroup).self).gameObject.AddComponent <OptionsKeymappingGeneral>();
            kbGroup.AddSpace(8);
            var KBPosGroup = kbGroup.AddGroup(LocalizationManager.instance.current["position"]);

            ((UIPanel)((UIHelper)KBPosGroup).self).gameObject.AddComponent <OptionsKeymappingPosition>();
            KBPosGroup.AddSpace(8);
            var KBRotGroup = kbGroup.AddGroup(LocalizationManager.instance.current["rotation"]);

            ((UIPanel)((UIHelper)KBRotGroup).self).gameObject.AddComponent <OptionsKeymappingRotation>();
            KBRotGroup.AddSpace(8);
            var KBScaleGroup = kbGroup.AddGroup(LocalizationManager.instance.current["scale_obj"]);

            ((UIPanel)((UIHelper)KBScaleGroup).self).gameObject.AddComponent <OptionsKeymappingScale>();
            KBScaleGroup.AddSpace(8);
            var KBSMActionsGroup = kbGroup.AddGroup(LocalizationManager.instance.current["CTActions"] + " (" + LocalizationManager.instance.current["selection_mode"] + ")");

            ((UIPanel)((UIHelper)KBSMActionsGroup).self).gameObject.AddComponent <OptionsKeymappingSelectionModeActions>();
            KBSMActionsGroup.AddSpace(8);
            openKeybindingsButton = (UIButton)kbGroup.AddButton(LocalizationManager.instance.current["open_kbd_cfg"], openKeybindings);

            KeyBindingsManager.Initialize();

            // GENERAL TAB
            UIPanel globalPanel = ((UIPanel)((UIHelper)group).self);

            gizmoSizeSlider         = (UISlider)group.AddSlider(string.Format(LocalizationManager.instance.current["settings_GIZMO_label"], (GizmoSize.value * 100).ToString()), 0.2f, 3f, 0.1f, GizmoSize.value, gizmoSizeChanged);
            gizmoSizeSlider.width   = 600;
            gizmoSizeSlider.height  = 16;
            gizmoSizeSlider.tooltip = LocalizationManager.instance.current["settings_GIZMO_tooltip"];

            var gizmoSizePanel = globalPanel.Find <UIPanel>("OptionsSliderTemplate(Clone)");

            gizmoSizePanel.name   = "GizmoSizePanel";
            gizmoSizeLabel        = gizmoSizePanel.Find <UILabel>("Label");
            gizmoSizeLabel.width *= 3.5f;

            gizmoOpacitySlider        = (UISlider)group.AddSlider(string.Format(LocalizationManager.instance.current["settings_GIZMO_OPACITY_label"], (GizmoOpacity.value * 100).ToString()), .1f, 1f, 0.05f, GizmoOpacity.value, gizmoOpacityChanged);
            gizmoOpacitySlider.width  = 600;
            gizmoOpacitySlider.height = 16;

            var gizmoOpacityPanel = globalPanel.components.First(c => c.GetType() == typeof(UIPanel) && c != gizmoSizePanel);

            gizmoOpacityPanel.name   = "GizmoOpacityPanel";
            gizmoOpacityLabel        = gizmoOpacityPanel.Find <UILabel>("Label");
            gizmoOpacityLabel.width *= 3.5f;


            group.AddDropdown(LocalizationManager.instance.current["settings_DISTUNITS_label"],
                              new string[] { LocalizationManager.instance.current["settings_DISTUNITS_m"] + " (m)",
                                             LocalizationManager.instance.current["settings_DISTUNITS_ft"] + " (ft)",
                                             LocalizationManager.instance.current["settings_DISTUNITS_yd"] + " (yd)" }, DistanceUnits.value,
                              (int value) => {
                DistanceUnits.value = value;
                SetUnits();
                // propRenderDistanceChanged(PropRenderDistance.value);
                // buildingRenderDistanceChanged(BuildingRenderDistance.value);
            });

            group.AddDropdown(LocalizationManager.instance.current["settings_ANGUNITS_label"],
                              new string[] { LocalizationManager.instance.current["settings_ANGUNITS_deg"] + " (°)",
                                             LocalizationManager.instance.current["settings_ANGUNITS_rad"] + " (rad)" }, AngleUnits.value, (int value) => { AngleUnits.value = value; SetUnits(); });

            useUINightModeCheckbox = (UICheckBox)group.AddCheckbox(LocalizationManager.instance.current["settings_USEUINIGHTMODE_toggle"], UseUINightMode.value, (bool value) => { UseUINightMode.value = value; });

            hideDisLayerIconCheckbox = (UICheckBox)group.AddCheckbox(LocalizationManager.instance.current["settings_HIDEDISABLEDLAYERSICON_toggle"], HideDisabledLayersIcon.value, hideDisabledLayersIconChanged);

            // usePasteIntoCheckbox = (UICheckBox)group.AddCheckbox(LocalizationManager.instance.current["settings_USEPASTEINTO_toggle"], UsePasteInto.value, usePasteIntoChanged);

            autoResizeDecalsCheckbox = (UICheckBox)group.AddCheckbox(LocalizationManager.instance.current["settings_AUTORESIZEDECALS_toggle"], AutoResizeDecals.value, autoResizeDecalsChanged);

            includeSubBuildingsCheckbox = (UICheckBox)group.AddCheckbox(LocalizationManager.instance.current["settings_CONVERTSUBBUILDINGS_toggle"], IncludeSubBuildings.value, includeSubBuildingsChanged);

            useColorVariationCheckbox = (UICheckBox)group.AddCheckbox(LocalizationManager.instance.current["settings_USECOLORVAR_toggle"], UseColorVariation.value, useColorVariationChanged);

            group.AddSpace(10);
            var sliderGroup = gentab.AddGroup("  " + LocalizationManager.instance.current["settings_CONFDEL_title"]);

            confirmDelCheckbox = (UICheckBox)sliderGroup.AddCheckbox(LocalizationManager.instance.current["settings_CONFDEL_toggle"], ShowConfirmDeletion.value, confirmDeletionCheckboxChanged);

            confirmDelThresholdSlider         = (UISlider)sliderGroup.AddSlider(string.Format(LocalizationManager.instance.current["settings_CONFDEL_SLIDER_label"], ConfirmDeletionThreshold.value.ToString()), 1f, 15f, 1f, ConfirmDeletionThreshold.value, confirmDeletionThresholdChanged);
            confirmDelThresholdSlider.width   = 715;
            confirmDelThresholdSlider.height  = 16;
            confirmDelThresholdSlider.tooltip = LocalizationManager.instance.current["settings_CONFDEL_SLIDER_tooltip"];

            confirmDelThresholdLabel = (UILabel)((UIPanel)((UIHelper)sliderGroup).self).components.First(c => c.GetType() == typeof(UIPanel) && c.components.Any(comp => comp.GetType() == typeof(UISlider)))
                                       .components.First(c => c.GetType() == typeof(UILabel));
            confirmDelThresholdLabel.width *= 3.5f;
            if (!ShowConfirmDeletion.value)
            {
                confirmDelThresholdSlider.isEnabled = false;
            }


            sliderGroup.AddSpace(10);
            var languageGroup = gentab.AddGroup("  " + LocalizationManager.instance.current["settings_LANG_title"]);

            languageGroup.AddDropdown(LocalizationManager.instance.current["settings_LANG_title"], LocalizationManager.instance.identifiers, LocalizationManager.instance.available.IndexOf(LocalizationManager.instance.current), languageChanged);

            languageGroup.AddSpace(10);

            showDevCheckbox = (UICheckBox)languageGroup.AddCheckbox(LocalizationManager.instance.current["settings_DEVTOOLS_toggle"], ShowDeveloperTools.value, (value) =>
            {
                ShowDeveloperTools.value = value;
            });
            showDevCheckbox.tooltip = LocalizationManager.instance.current["settings_DEVTOOLS_tooltip"];
        }
Exemplo n.º 23
0
 protected override void Initialize()
 {
     panel  = UIUtil.CreateSlider(this, _description, 0, 100, 1, 50, Slider_onValueChanged);
     label  = panel.Find <UILabel>("Label");
     Slider = panel.Find <UISlider>("Slider");
 }
Exemplo n.º 24
0
 private void OnClick()
 {
     if (base.enabled && NGUITools.GetActive(base.gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
     {
         mLabelList.Clear();
         if (mPanel == null)
         {
             mPanel = UIPanel.Find(base.transform);
             if (mPanel == null)
             {
                 return;
             }
         }
         handleEvents = true;
         Transform transform = base.transform;
         Bounds    bounds    = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, transform);
         mChild       = new GameObject("Drop-down List");
         mChild.layer = base.gameObject.layer;
         Transform transform2 = mChild.transform;
         transform2.parent        = transform.parent;
         transform2.localPosition = bounds.min;
         transform2.localRotation = Quaternion.identity;
         transform2.localScale    = Vector3.one;
         mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
         mBackground.pivot = UIWidget.Pivot.TopLeft;
         mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
         mBackground.color = backgroundColor;
         Vector4 border = mBackground.border;
         mBgBorder = border.y;
         mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f);
         mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
         mHighlight.pivot = UIWidget.Pivot.TopLeft;
         mHighlight.color = highlightColor;
         UISpriteData atlasSprite = mHighlight.GetAtlasSprite();
         if (atlasSprite == null)
         {
             return;
         }
         float          num  = atlasSprite.borderTop;
         float          num2 = activeFontSize;
         float          num3 = activeFontScale;
         float          num4 = num2 * num3;
         float          a    = 0f;
         float          num5 = 0f - padding.y;
         int            num6 = ((bitmapFont != null) ? bitmapFont.defaultSize : fontSize);
         List <UILabel> list = new List <UILabel>();
         int            i    = 0;
         for (int count = items.Count; i < count; i++)
         {
             string  text    = items[i];
             UILabel uILabel = NGUITools.AddWidget <UILabel>(mChild);
             uILabel.name         = i.ToString();
             uILabel.pivot        = UIWidget.Pivot.TopLeft;
             uILabel.bitmapFont   = bitmapFont;
             uILabel.trueTypeFont = trueTypeFont;
             uILabel.fontSize     = num6;
             uILabel.fontStyle    = fontStyle;
             uILabel.text         = (isLocalized ? Localization.Get(text) : text);
             uILabel.color        = textColor;
             uILabel.cachedTransform.localPosition = new Vector3(border.x + padding.x, num5, -1f);
             uILabel.overflowMethod = UILabel.Overflow.ResizeFreely;
             uILabel.MakePixelPerfect();
             if (num3 != 1f)
             {
                 uILabel.cachedTransform.localScale = Vector3.one * num3;
             }
             list.Add(uILabel);
             num5 -= num4;
             num5 -= padding.y;
             a     = Mathf.Max(a, uILabel.printedSize.x);
             UIEventListener uIEventListener = UIEventListener.Get(uILabel.gameObject);
             uIEventListener.onHover   = OnItemHover;
             uIEventListener.onPress   = OnItemPress;
             uIEventListener.onClick   = OnItemClick;
             uIEventListener.parameter = text;
             if (mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
             {
                 Highlight(uILabel, instant: true);
             }
             mLabelList.Add(uILabel);
         }
         a = Mathf.Max(a, bounds.size.x * num3 - (border.x + padding.x) * 2f);
         float   num7    = a / num3;
         Vector3 vector  = new Vector3(num7 * 0.5f, (0f - num2) * 0.5f, 0f);
         Vector3 vector2 = new Vector3(num7, (num4 + padding.y) / num3, 1f);
         i = 0;
         for (int count = list.Count; i < count; i++)
         {
             UILabel uILabel = list[i];
             NGUITools.AddWidgetCollider(uILabel.gameObject);
             BoxCollider component = uILabel.GetComponent <BoxCollider>();
             if (component != null)
             {
                 vector.z         = component.center.z;
                 component.center = vector;
                 component.size   = vector2;
             }
             else
             {
                 BoxCollider2D component2 = uILabel.GetComponent <BoxCollider2D>();
                 component2.offset = vector;
                 component2.size   = vector2;
             }
         }
         a    += (border.x + padding.x) * 2f;
         num5 -= border.y;
         mBackground.width  = Mathf.RoundToInt(a);
         mBackground.height = Mathf.RoundToInt(0f - num5 + border.y);
         float num8 = 2f * atlas.pixelSize;
         float f    = a - (border.x + padding.x) * 2f + (float)atlasSprite.borderLeft * num8;
         float f2   = num4 + num * num8;
         mHighlight.width  = Mathf.RoundToInt(f);
         mHighlight.height = Mathf.RoundToInt(f2);
         bool flag = position == Position.Above;
         if (position == Position.Auto)
         {
             UICamera uICamera = UICamera.FindCameraForLayer(base.gameObject.layer);
             if (uICamera != null)
             {
                 flag = uICamera.cachedCamera.WorldToViewportPoint(transform.position).y < 0.5f;
             }
         }
         if (isAnimated)
         {
             float bottom = num5 + num4;
             Animate(mHighlight, flag, bottom);
             i = 0;
             for (int count = list.Count; i < count; i++)
             {
                 Animate(list[i], flag, bottom);
             }
             AnimateColor(mBackground);
             AnimateScale(mBackground, flag, bottom);
         }
         if (flag)
         {
             transform2.localPosition = new Vector3(bounds.min.x, bounds.max.y - num5 - border.y, bounds.min.z);
         }
     }
     else
     {
         OnSelect(isSelected: false);
     }
 }
Exemplo n.º 25
0
 public static UIPanel Find(Transform trans, bool createIfMissing)
 {
     return(UIPanel.Find(trans, createIfMissing, -1));
 }
        public void setSliderPanel(String[] sliderPanels)
        {
            clearSliderPanel();
            settings.budgetSliderNameList.Clear();

            int numberOfSliders = 0;

            foreach (String sliderName in sliderPanels)
            {
                BudgetItem budgetItem = _main.getBudgetCopy(sliderName);

                if (budgetItem != null)
                {
                    // DEBUG
                    //foreach (UIComponent component in budgetItem.components)
                    //{
                    //    Debug.Log(component.name, component);
                    //}

                    numberOfSliders++;

                    UIPanel panel = (UIPanel)budgetItem.component;

                    panel.name = panel.name.Substring(0, panel.name.Length - 7); // delete ' (Copy)' mark
                    //AttachUIComponent(panel.gameObject);
                    AttachUIComponent(budgetItem.gameObject);

                    UIComponent sliderDay        = panel.Find <UISlider>("DaySlider");
                    UIComponent sliderNight      = panel.Find <UISlider>("NightSlider");
                    UIComponent sliderBackground = panel.Find <UISlicedSprite>("SliderBackground");
                    UILabel     total            = panel.Find <UILabel>("Total");
                    UILabel     percentageDay    = panel.Find <UILabel>("DayPercentage");
                    UILabel     percentageNight  = panel.Find <UILabel>("NightPercentage");
                    UISprite    icon             = panel.Find <UISprite>("Icon");

                    panel.transform.parent = this.transform;
                    panel.relativePosition = new Vector3(0, _sliderList.Count * 50);
                    panel.size             = new Vector2(width, panel.height);

                    icon.relativePosition = new Vector3(1, icon.relativePosition.y);

                    sliderBackground.relativePosition = new Vector3(50, sliderBackground.relativePosition.y);
                    sliderBackground.size             = new Vector2(panel.width - 98 - 50, sliderBackground.height);
                    sliderDay.relativePosition        = new Vector3(50, sliderDay.relativePosition.y);
                    sliderDay.size = new Vector2(panel.width - 98 - 50, sliderDay.height);
                    sliderNight.relativePosition = new Vector3(50, sliderNight.relativePosition.y);
                    sliderNight.size             = new Vector2(panel.width - 98 - 50, sliderNight.height);

                    total.relativePosition           = new Vector3(panel.width - 92, total.relativePosition.y);
                    total.size                       = new Vector2(90, total.height);
                    percentageDay.relativePosition   = new Vector3(panel.width - 92, total.relativePosition.y);
                    percentageDay.size               = new Vector2(45, total.height);
                    percentageNight.relativePosition = new Vector3(panel.width - 47, total.relativePosition.y);
                    percentageNight.size             = new Vector2(45, total.height);

                    this._sliderList.Add(panel);
                    settings.budgetSliderNameList.Add(sliderName);
                }
            }

            if (numberOfSliders > 0)
            {
                changeInfoViewPanelHeight(_infoViewPanel.height + numberOfSliders * 50 + 10);
            }

            this.height += numberOfSliders * 50;
        }
Exemplo n.º 27
0
    /// <summary>
    /// Display the drop-down list when the game object gets clicked on.
    /// </summary>

    void OnClick()
    {
        if (mChild == null && atlas != null && font != null && items.Count > 0)
        {
            mLabelList.Clear();

            // Disable the navigation script
            handleEvents = true;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = UIPanel.Find(transform, true);
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Transform myTrans = transform;
            Bounds    bounds  = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            Transform t = mChild.transform;
            t.parent        = myTrans.parent;
            t.localPosition = bounds.min;
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = UIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;

            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            UIAtlas.Sprite hlsp = mHighlight.sprite;
            float          hlspHeight = hlsp.inner.yMin - hlsp.outer.yMin;
            float          fontScale = font.size * font.pixelSize * textScale;
            float          x = 0f, y = -padding.y;
            List <UILabel> labels = new List <UILabel>();

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild);
                lbl.pivot = UIWidget.Pivot.TopLeft;
                lbl.font  = font;
                lbl.text  = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s;
                lbl.color = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -0.01f);
                lbl.MakePixelPerfect();

                if (textScale != 1f)
                {
                    Vector3 scale = lbl.cachedTransform.localScale;
                    lbl.cachedTransform.localScale = scale * textScale;
                }
                labels.Add(lbl);

                y -= fontScale;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.relativeSize.x * fontScale);

                // Add an event listener
                UIEventListener listener = UIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s)
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f);

            Vector3 bcCenter = new Vector3((x * 0.5f) / fontScale, -0.5f, 0f);
            Vector3 bcSize   = new Vector3(x / fontScale, (fontScale + padding.y) / fontScale, 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel     lbl = labels[i];
                BoxCollider bc  = NGUITools.AddWidgetCollider(lbl.gameObject);
                bcCenter.z = bc.center.z;
                bc.center  = bcCenter;
                bc.size    = bcSize;
            }

            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.cachedTransform.localScale = new Vector3(x, -y + bgPadding.y, 1f);

            // Scale the highlight sprite to envelop a single item
            mHighlight.cachedTransform.localScale = new Vector3(
                x - (bgPadding.x + padding.x) * 2f + (hlsp.inner.xMin - hlsp.outer.xMin) * 2f,
                fontScale + hlspHeight * 2f, 1f);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.FindCameraForLayer(gameObject.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                float bottom = y + fontScale;
                Animate(mHighlight, placeAbove, bottom);
                for (int i = 0, imax = labels.Count; i < imax; ++i)
                {
                    Animate(labels[i], placeAbove, bottom);
                }
                AnimateColor(mBackground);
                AnimateScale(mBackground, placeAbove, bottom);
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z);
            }
        }
        else
        {
            OnSelect(false);
        }
    }
Exemplo n.º 28
0
        protected void CreateSoundSlider(UIHelperBase helper, ISound sound)
        {
            // Initialize variables
            var configuration    = Mod.Instance.Settings.GetSoundsByCategoryId <string>(sound.CategoryId);
            var customAudioFiles = SoundPacksManager.instance.AudioFiles.Where(kvp => kvp.Key.StartsWith(string.Format("{0}.{1}", sound.CategoryId, sound.Id))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            float volume = 0;

            if (configuration.ContainsKey(sound.Id))
            {
                volume = configuration[sound.Id].Volume;
            }
            else
            {
                Mod.Instance.Log.Info("No volume configuration found for {0}.{1}, using default value", sound.CategoryId, sound.Id);
                volume = sound.DefaultVolume;
            }

            // Add UI components
            UISlider   uiSlider   = null;
            UIPanel    uiPanel    = null;
            UILabel    uiLabel    = null;
            UIDropDown uiDropDown = null;
            var        maxVolume  = sound.MaxVolume;

            if (customAudioFiles.Count > 0 && configuration.ContainsKey(sound.Id) && !string.IsNullOrEmpty(configuration[sound.Id].SoundPack))
            {
                // Custom sound, determine custom max volume
                var audioFile = SoundPacksManager.instance.GetAudioFileByName(sound.CategoryId, sound.Id, configuration[sound.Id].SoundPack);
                maxVolume = Mathf.Max(audioFile.AudioInfo.MaxVolume, audioFile.AudioInfo.Volume);
            }

            uiSlider = (UISlider)helper.AddSlider(sound.Name, 0, maxVolume, 0.01f, volume, v => this.SoundVolumeChanged(sound, v));
            uiPanel  = (UIPanel)uiSlider.parent;
            uiLabel  = uiPanel.Find <UILabel>("Label");

            if (customAudioFiles.Count > 0)
            {
                uiDropDown        = uiPanel.AttachUIComponent(GameObject.Instantiate((UITemplateManager.Peek(UITemplateDefs.ID_OPTIONS_DROPDOWN_TEMPLATE) as UIPanel).Find <UIDropDown>("Dropdown").gameObject)) as UIDropDown;
                uiDropDown.items  = new[] { "Default" }.Union(customAudioFiles.Select(kvp => kvp.Value.Name)).ToArray();
                uiDropDown.height = 28;
                uiDropDown.textFieldPadding.top = 4;
                if (configuration.ContainsKey(sound.Id) && !string.IsNullOrEmpty(configuration[sound.Id].SoundPack))
                {
                    uiDropDown.selectedValue = configuration[sound.Id].SoundPack;
                }
                else
                {
                    uiDropDown.selectedIndex = 0;
                }

                uiDropDown.eventSelectedIndexChanged += (c, i) => this.SoundPackChanged(sound, i > 0 ? ((UIDropDown)c).items[i] : null, uiSlider);
                this.soundSelections[string.Format("{0}.{1}", sound.CategoryId, sound.Id)] = uiDropDown;
            }

            // Configure UI components
            uiPanel.autoLayout            = false;
            uiLabel.anchor                = UIAnchorStyle.Left | UIAnchorStyle.CenterVertical;
            uiLabel.width                 = 250;
            uiSlider.anchor               = UIAnchorStyle.CenterVertical;
            uiSlider.builtinKeyNavigation = false;
            uiSlider.width                = 207;
            uiSlider.relativePosition     = new Vector3(uiLabel.relativePosition.x + uiLabel.width + 20, 0);
            if (customAudioFiles.Count > 0)
            {
                uiDropDown.anchor           = UIAnchorStyle.CenterVertical;
                uiDropDown.width            = 180;
                uiDropDown.relativePosition = new Vector3(uiSlider.relativePosition.x + uiSlider.width + 20, 0);
                uiPanel.size = new Vector2(uiDropDown.relativePosition.x + uiDropDown.width, 32);
            }
            else
            {
                uiPanel.size = new Vector2(uiSlider.relativePosition.x + uiSlider.width, 32);
            }
        }
Exemplo n.º 29
0
        /// <summary>Initializes this instance by preparing connections to the necessary game parts.</summary>
        /// <returns><c>true</c> on success; otherwise, <c>false</c>.</returns>
        public bool Initialize()
        {
            if (mainLocale != null)
            {
                return(true);
            }

            try
            {
                FieldInfo field = typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic);
                mainLocale = field.GetValue(LocaleManager.instance) as Locale;
            }
            catch (Exception ex)
            {
                Log.Warning("The 'Real Time' mod could not obtain the locale field of the LocaleManager, error message: " + ex);
                return(false);
            }

            cityInfoPanelTourists = GameObject
                                    .Find(CityInfoPanelName)?
                                    .GetComponent <CityInfoPanel>()?
                                    .Find <UIPanel>(TouristsPanelName)?
                                    .Find <UILabel>(TouristsLabelName);

            if (cityInfoPanelTourists == null)
            {
                Log.Warning("The 'Real Time' mod could not obtain the CityInfoPanel.Tourists.Label object");
            }

            districtInfoPanelTourists = GameObject
                                        .Find(DistrictInfoPanelName)?
                                        .GetComponent <DistrictWorldInfoPanel>()?
                                        .Find <UIPanel>(TouristsPanelName)?
                                        .Find <UILabel>(TouristsLabelName);

            if (districtInfoPanelTourists == null)
            {
                Log.Warning("The 'Real Time' mod could not obtain the DistrictWorldInfoPanel.Tourists.Label object");
            }

            UIPanel infoPanel = UIView.Find <UIPanel>(InfoPanelName);

            if (infoPanel == null)
            {
                Log.Warning("The 'Real Time' mod could not obtain the InfoPanel object");
            }
            else
            {
                labelPopulation = infoPanel.Find <UILabel>(CitizensChangeLabelName);
                if (labelPopulation == null)
                {
                    Log.Warning("The 'Real Time' mod could not obtain the ProjectedChange object");
                }

                labelIncome = infoPanel.Find <UILabel>(IncomeLabelName);
                if (labelIncome == null)
                {
                    Log.Warning("The 'Real Time' mod could not obtain the ProjectedIncome object");
                }
            }

            buildingsTabContainer = UIView.Find <UITabContainer>(BuildingsButtonsContainer);
            if (buildingsTabContainer == null)
            {
                Log.Warning("The 'Real Time' mod could not obtain the TSContainer object");
            }

            LocaleManager.eventLocaleChanged += LocaleChanged;
            return(true);
        }
Exemplo n.º 30
0
 protected override void Initialize()
 {
     panel = UIUtil.CreateSlider(this, _description, 0, 100, 1, 50, Slider_onValueChanged);
     label = panel.Find<UILabel>("Label");
     Slider = panel.Find<UISlider>("Slider");
 }
        internal void CreateGraphics()
        {
            try {

                var uiView = UIView.GetAView();
                TextureDB.LoadFavCimsTextures();
                Atlas.LoadAtlasIcons();

                ////////////////////////////////////////////////
                ///////////Favorite Button Manu Panel/////////
                ///////////////////////////////////////////////

                //MainMenuPos = UIView.GetAView().FindUIComponent<UITabstrip> ("MainToolstrip");
                MainMenuPos = UIView.Find<UITabstrip> ("MainToolstrip");

                if(MainMenuPos.Find<FavoritesCimsButton>("FavCimsMenuPanel") != null) {
                    FavCimsMenuPanel = MainMenuPos.Find<FavoritesCimsButton>("FavCimsMenuPanel");
                }else{
                    FavCimsMenuPanel = MainMenuPos.AddUIComponent(typeof(FavoritesCimsButton)) as FavoritesCimsButton;
                }

                ////////////////////////////////////////////////
                ////////////////Favorite Panel////////////////
                ///////////////////////////////////////////////

                FullScreenContainer = UIView.Find<UIPanel> ("FullScreenContainer");
                FavCimsPanel = FullScreenContainer.AddUIComponent<FavoriteCimsMainPanel> ();
                FavCimsPanel.Hide ();

                FullScreenContainer.eventMouseDown += delegate {
                    if (!FavCimsPanel.containsMouse) {
                        FavCimsPanel.SendToBack ();
                    } else {
                        FavCimsPanel.BringToFront ();
                    }
                };

                ////////////////////////////////////////////////
                ////////////Humans Button & Subscribe///////////
                ///////////////////////////////////////////////

                FavCimsHumanPanel = FullScreenContainer.Find<UIPanel> ("(Library) CitizenWorldInfoPanel");

                if (FavCimsHumanPanel != null) {
                    if(FavCimsHumanPanel.GetComponentInChildren<AddToFavButton>() != null) {
                        FavStarButton = FavCimsHumanPanel.GetComponentInChildren<AddToFavButton>();
                    }else{
                        FavStarButton = FavCimsHumanPanel.AddUIComponent(typeof(AddToFavButton)) as AddToFavButton;
                    }
                }

                GenerateFamilyDetailsTpl();

            } catch (Exception e) {
                Debug.Error ("OnLoad List Error : " + e.ToString ());
            }
        }
Exemplo n.º 32
0
        private static void InitializeModSortDropDown()
        {
            if (GameObject.Find("ModsSortBy") != null)
            {
                return;
            }

            var shadows = GameObject.Find("Shadows").GetComponent <UIPanel>();

            if (shadows == null)
            {
                return;
            }

            var moarGroup = GameObject.Find("MoarGroup").GetComponent <UIPanel>();

            if (moarGroup == null)
            {
                return;
            }

            var moarLabel  = moarGroup.Find <UILabel>("Moar");
            var moarButton = moarGroup.Find <UIButton>("Button");

            moarGroup.position = new Vector3(moarGroup.position.x, -6.0f, moarGroup.position.z);

            moarLabel.isVisible  = false;
            moarButton.isVisible = false;

            sortDropDown = GameObject.Instantiate(shadows);
            sortDropDown.gameObject.name  = "ModsSortBy";
            sortDropDown.transform.parent = moarGroup.transform;
            sortDropDown.name             = "ModsSortBy";
            sortDropDown.Find <UILabel>("Label").isVisible = false;

            var dropdown = sortDropDown.Find <UIDropDown>("ShadowsQuality");

            dropdown.name      = "SortByDropDown";
            dropdown.size      = new Vector2(200.0f, 24.0f);
            dropdown.textScale = 0.8f;

            dropdown.eventSelectedIndexChanged += (component, value) =>
            {
                sortMode = (SortMode)value;
                RefreshPlugins();
            };

            var sprite = dropdown.Find <UIButton>("Sprite");

            sprite.foregroundSpriteMode = UIForegroundSpriteMode.Scale;

            var enumValues = Enum.GetValues(typeof(SortMode));

            dropdown.items = new string[enumValues.Length];

            int i = 0;

            foreach (var value in enumValues)
            {
                dropdown.items[i] = String.Format("Sort by: {0}", EnumToString((SortMode)value));
                i++;
            }
        }
Exemplo n.º 33
0
 // Token: 0x060003B8 RID: 952 RVA: 0x00004CB4 File Offset: 0x00002EB4
 public static UIPanel Find(Transform trans)
 {
     return(UIPanel.Find(trans, true));
 }
Exemplo n.º 34
0
 public static UIPanel GetWidgetPanel(UIWidget w)
 {
     return(w.panel ?? UIPanel.Find(w.transform));
 }