Ejemplo n.º 1
0
        private void OnToggleKeyDown(UIComponent c, UIKeyEventParameter e)
        {
            if (SliderDataDict != null && m_Toggle != ToggleType.None)
            {
                SliderData sData = SliderDataDict[m_Toggle];

                switch (e.keycode)
                {
                case KeyCode.LeftArrow:
                    SliderDict[m_Toggle].value = Math.Max(sData.Min, SetDict[m_Toggle] - sData.Step);
                    break;

                case KeyCode.RightArrow:
                    SliderDict[m_Toggle].value = Math.Min(sData.Max, SetDict[m_Toggle] + sData.Step);
                    break;

                case KeyCode.UpArrow:
                    SliderDict[m_Toggle].value = sData.Max;
                    break;

                case KeyCode.DownArrow:
                    SliderDict[m_Toggle].value = sData.Min;
                    break;

                case KeyCode.RightControl:
                    SliderDict[m_Toggle].value = sData.Def;
                    break;
                }

                m_T.Run();
            }
        }
        protected UISlider CreateSlider(UISliderParamProps properties)
        {
            SliderData sData           = SliderDataDict[properties.TrackAlterType];
            string     typeString      = properties.TrackAlterType.ToString();
            var        parentComponent = GetParentComponent(properties);

            UILabel titleLabel = CreateLabel(new UILabelParamProps()
            {
                Name            = "lblTitle" + typeString,
                Text            = "Station " + typeString,
                ParentComponent = parentComponent,
                ColShare        = 3.25f,
                Margins         = new Vector4(0, 2, 0, 0)
            });

            titleLabel.isInteractive   = true;
            titleLabel.eventMouseDown += delegate(UIComponent sender, UIMouseEventParameter e)
            { OnToggleMouseDown(sender, e, properties.TrackAlterType); };
            titleLabel.eventKeyDown += delegate(UIComponent sender, UIKeyEventParameter e)
            { OnToggleKeyDown(sender, e); };

            UIPanel sliderPanel = CreatePanel(new UIPanelParamProps()
            {
                Name             = "sldPanel" + typeString,
                ParentComponent  = parentComponent,
                ColShare         = 8.75f,
                Atlas            = atlas,
                BackgroundSprite = "GenericPanel",
                Color            = new Color32(150, 150, 150, 210)
            });

            PanelDict[properties.TrackAlterType] = sliderPanel;
            sliderPanel.playAudioEvents          = true;
            sliderPanel.eventMouseDown          += delegate(UIComponent sender, UIMouseEventParameter e)
            { OnToggleMouseDown(sender, e, properties.TrackAlterType); };
            sliderPanel.eventKeyDown += delegate(UIComponent sender, UIKeyEventParameter e)
            { OnToggleKeyDown(sender, e); };

            //var pnlStationTypeSelectorInfo = CreatePanel(new UIPanelParamProps()
            //{
            //    Name = "pnlStationTypeSelectorInfo" + typeString,
            //    ParentComponent = parentComponent,
            //    ColShare = 1
            //});
            //var btnStationTypeSelectorInfo = CreateButton(new UIButtonParamProps()
            //{
            //    Name = "btnStationTypeSelectorInfo" + typeString,
            //    Atlas = atlas,
            //    ParentComponent = pnlStationTypeSelectorInfo,
            //    NormalBgSprite = "EconomyMoreInfo",
            //    HoveredBgSprite = "EconomyMoreInfoHovered",
            //    PressedBgSprite = "EconomyMoreInfoHovered",
            //    Height = 12,
            //    Width = 12,
            //    TooltipComponent = properties.TooltipComponent,
            //    StackWidths = true
            //});

            UIPanel sliderLeftPanel = CreatePanel(new UIPanelParamProps()
            {
                Name            = "sliderLeftPanel" + typeString,
                ParentComponent = sliderPanel,
                Height          = 12,
                ColShare        = 10,
                Margins         = new Vector4(2, 0, 0, 2)
            });
            //sliderLeftPanel.height = sliderPanel.height - 4;
            UIPanel sliderRightPanel = CreatePanel(new UIPanelParamProps()
            {
                Name            = "sliderRightPanel" + typeString,
                ParentComponent = sliderPanel,
                ColShare        = 2
            });

            UILabel sliderValueLabel = CreateLabel(new UILabelParamProps()
            {
                Name            = "sliderValueLabel" + typeString,
                Text            = sData.Def.ToString(),
                ParentComponent = sliderRightPanel,
                ColumnCount     = 1,
            });

            sliderValueLabel.isInteractive   = false;
            sliderValueLabel.eventMouseDown += delegate(UIComponent sender, UIMouseEventParameter e)
            { OnToggleMouseDown(sender, e, properties.TrackAlterType); };

            UISlicedSprite sliderBgSprite = sliderLeftPanel.AddUIComponent <UISlicedSprite>();

            sliderBgSprite.isInteractive    = false;
            sliderBgSprite.atlas            = atlas;
            sliderBgSprite.name             = "ssBgSprite" + typeString;
            sliderBgSprite.spriteName       = "BudgetSlider";
            sliderBgSprite.size             = sliderLeftPanel.size;
            sliderBgSprite.relativePosition = new Vector2(0, 0);
            sliderBgSprite.zOrder           = 0;

            UISlicedSprite sliderMkSprite = sliderLeftPanel.AddUIComponent <UISlicedSprite>();

            sliderMkSprite.atlas         = atlas;
            sliderMkSprite.name          = "ssMkSprite" + typeString;
            sliderMkSprite.spriteName    = "SliderBudget";
            sliderMkSprite.isInteractive = true;
            sliderMkSprite.zOrder        = 1;

            UISlider slider = sliderLeftPanel.AddUIComponent <UISlider>();

            SliderDict[properties.TrackAlterType] = slider;
            slider.name             = typeString + " Slider";
            slider.isInteractive    = true;
            slider.maxValue         = sData.Max;
            slider.minValue         = sData.Min;
            slider.value            = sData.Def;
            slider.stepSize         = sData.Step;
            slider.relativePosition = new Vector2(0, 0);
            slider.size             = sliderLeftPanel.size;
            slider.thumbObject      = sliderMkSprite;
            slider.zOrder           = 2;
            slider.eventMouseWheel += (c, v) =>
            {
                slider.value += v.wheelDelta > 0 ? sData.Step : -sData.Step;
                OnToggleMouseDown(c, v, properties.TrackAlterType);
            };
            slider.eventValueChanged += (c, v) =>
            {
                if (sliderValueLabel.text != v.ToString())
                {
                    m_valueChanged = true;
                    v = Math.Min(Math.Max(sData.Min, v), sData.Max);
                    sliderValueLabel.text = v.ToString();
                    SetDict[properties.TrackAlterType] = v;
                    //m_T.Run();
                }
            };
            slider.eventMouseUp += (c, e) =>
            {
                OnToggleMouseDown(c, e, properties.TrackAlterType);
                if (m_valueChanged)
                {
                    m_valueChanged = false;
                }
            };
            return(slider);
        }
Ejemplo n.º 3
0
        private void CreateSlider(ToggleType type)
        {
            SliderData sData      = SliderDataDict[type];
            string     typeString = type.ToString();
            UILabel    TitleLabel = AddUIComponent <UILabel>();

            TitleLabel.relativePosition = new Vector3()
            {
                x = 8, y = 30 + m_SliderCount * 40, z = 0
            };
            TitleLabel.text            = "Station " + typeString;
            TitleLabel.isInteractive   = true;
            TitleLabel.name            = "lbl" + typeString;
            TitleLabel.eventMouseDown += delegate(UIComponent sender, UIMouseEventParameter e) { OnToggleMouseDown(sender, e, type); };
            TitleLabel.eventKeyDown   += delegate(UIComponent sender, UIKeyEventParameter e) { OnToggleKeyDown(sender, e); };

            UIPanel sliderPanel = AddUIComponent <UIPanel>();

            PanelDict[type]              = sliderPanel;
            sliderPanel.atlas            = atlas;
            sliderPanel.backgroundSprite = "GenericPanel";
            sliderPanel.name             = "pnl" + typeString;
            sliderPanel.color            = new Color32(150, 150, 150, 210);
            sliderPanel.playAudioEvents  = true;
            sliderPanel.size             = new Vector2(width - 16, 20);
            sliderPanel.relativePosition = new Vector2(8, 48 + m_SliderCount * 40);
            sliderPanel.eventMouseDown  += delegate(UIComponent sender, UIMouseEventParameter e) { OnToggleMouseDown(sender, e, type); };
            sliderPanel.eventKeyDown    += delegate(UIComponent sender, UIKeyEventParameter e) { OnToggleKeyDown(sender, e); };

            UIPanel sliderLeftPanel = sliderPanel.AddUIComponent <UIPanel>();

            sliderLeftPanel.name             = "pnlLeft" + typeString;
            sliderLeftPanel.height           = sliderPanel.height - 4;
            sliderLeftPanel.width            = (0.7f * sliderPanel.width) - 5;
            sliderLeftPanel.relativePosition = new Vector2(2, 2);

            UITextField sliderTextField = sliderPanel.AddUIComponent <UITextField>();

            sliderTextField.isInteractive    = false;
            sliderTextField.name             = "tf" + typeString;
            sliderTextField.text             = sData.Def.ToString();
            sliderTextField.height           = sliderPanel.height;
            sliderTextField.width            = sliderPanel.size.x - sliderLeftPanel.size.x;
            sliderTextField.relativePosition = new Vector2(sliderLeftPanel.width, 2);
            sliderTextField.eventMouseDown  += delegate(UIComponent sender, UIMouseEventParameter e) { OnToggleMouseDown(sender, e, type); };

            UISlicedSprite sliderBgSprite = sliderLeftPanel.AddUIComponent <UISlicedSprite>();

            sliderBgSprite.isInteractive    = false;
            sliderBgSprite.atlas            = atlas;
            sliderBgSprite.name             = "ssBgSprite" + typeString;
            sliderBgSprite.spriteName       = "BudgetSlider";
            sliderBgSprite.size             = sliderLeftPanel.size;
            sliderBgSprite.relativePosition = new Vector2(0, 0);
            sliderBgSprite.zOrder           = 0;

            UISlicedSprite sliderMkSprite = sliderLeftPanel.AddUIComponent <UISlicedSprite>();

            sliderMkSprite.atlas         = atlas;
            sliderMkSprite.name          = "ssMkSprite" + typeString;
            sliderMkSprite.spriteName    = "SliderBudget";
            sliderMkSprite.isInteractive = true;
            sliderMkSprite.zOrder        = 1;

            UISlider slider = sliderLeftPanel.AddUIComponent <UISlider>();

            SliderDict[type]        = slider;
            slider.name             = typeString + " Slider";
            slider.isInteractive    = true;
            slider.maxValue         = sData.Max;
            slider.minValue         = sData.Min;
            slider.value            = sData.Def;
            slider.stepSize         = sData.Step;
            slider.relativePosition = new Vector2(0, 0);
            slider.size             = sliderLeftPanel.size;
            slider.thumbObject      = sliderMkSprite;
            slider.zOrder           = 2;
            slider.eventMouseWheel += (c, v) =>
            {
                slider.value += v.wheelDelta > 0 ? sData.Step : -sData.Step;
                OnToggleMouseDown(c, v, type);
            };
            slider.eventValueChanged += (c, v) =>
            {
                if (sliderTextField.text != v.ToString())
                {
                    m_valueChanged = true;
                    v = Math.Min(Math.Max(sData.Min, v), sData.Max);
                    sliderTextField.text = v.ToString();
                    SetDict[type]        = v;
                    //m_T.Run();
                }
            };
            slider.eventMouseUp += (c, e) =>
            {
                OnToggleMouseDown(c, e, type);
                if (m_valueChanged)
                {
                    m_valueChanged = false;
                }
            };

            m_SliderCount++;
        }