예제 #1
0
        /// <summary>
        /// Creates a scrolling tab.
        /// </summary>
        /// <param name="helper">The <see cref="UIHelper"/>.</param>
        /// <param name="tabstrip">The <see cref="UITabstrip"/> this tab should belong to.</param>
        /// <param name="buttonWidth">The width of the tab button.</param>
        /// <param name="title">The title of the tab.</param>
        /// <returns>A <see cref="UIHelper"/> object of the newly created tab.</returns>
        public static UIHelper AddScrollingTab(this UIHelper helper, UITabstrip tabstrip, float buttonWidth, string title)
        {
            UIPanel panelTemplate = (UIPanel)UITemplateManager.Peek(UITemplateDefs.ID_OPTIONS_SCROLL_PANEL_TEMPLATE);

            return(helper.AddCustomTab(tabstrip, panelTemplate, buttonWidth, title));
        }
예제 #2
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);
            }
        }
        public void OnSettingsUI(UIHelperBase helper)
        {
            LoadSettings();
            UIDropDown uIDropDown = (UIDropDown)helper.AddDropdown("Select Preset", EmergencyLightPresets, SelectedPreset, delegate(int sel)
            {
                if (sel == 1)
                {
                    CustomSettingsVisibility = true;
                }
                else
                {
                    CustomSettingsVisibility = false;
                }
                SelectedPreset = sel;
                if (loaded)
                {
                    Apply();
                }
            });
            UIScrollablePanel uIScrollablePanel = ((UIHelper)helper).self as UIScrollablePanel;

            uIScrollablePanel.autoLayout = false;
            int num  = 100;
            int num2 = 10;
            int num3 = 40;

            strip = uIScrollablePanel.AddUIComponent <UITabstrip>();
            strip.relativePosition = new Vector3(num2, num);
            strip.size             = new Vector2(744 - num2, num3);
            container = uIScrollablePanel.AddUIComponent <UITabContainer>();
            container.relativePosition = new Vector3(num2, num3 + num);
            container.size             = new Vector3(744 - num2, 713 - num);
            strip.tabPages             = container;
            UIButton uIButton  = (UIButton)UITemplateManager.Peek("OptionsButtonTemplate");
            UIButton uIButton2 = strip.AddTab("Police Car", uIButton, fillText: true);

            uIButton2.textColor         = uIButton.textColor;
            uIButton2.pressedTextColor  = uIButton.pressedTextColor;
            uIButton2.hoveredTextColor  = uIButton.hoveredTextColor;
            uIButton2.focusedTextColor  = uIButton.hoveredTextColor;
            uIButton2.disabledTextColor = uIButton.hoveredTextColor;
            UIPanel uIPanel = strip.tabContainer.components[0] as UIPanel;

            uIPanel.autoLayout          = true;
            uIPanel.wrapLayout          = true;
            uIPanel.autoLayoutDirection = LayoutDirection.Horizontal;
            UIHelper uIHelper = new UIHelper(uIPanel);

            uIHelper.AddSpace(15);
            uIHelper.AddDropdown("Left", ColorNames, Array.IndexOf(ColorNames, settings[Setting.PoliceLeft]), delegate(int sel)
            {
                settings[Setting.PoliceLeft] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            uIHelper.AddDropdown("Right", ColorNames, Array.IndexOf(ColorNames, settings[Setting.PoliceRight]), delegate(int sel)
            {
                settings[Setting.PoliceRight] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            uIButton2                   = strip.AddTab("Fire Truck");
            uIButton2.textColor         = uIButton.textColor;
            uIButton2.pressedTextColor  = uIButton.pressedTextColor;
            uIButton2.hoveredTextColor  = uIButton.hoveredTextColor;
            uIButton2.focusedTextColor  = uIButton.hoveredTextColor;
            uIButton2.disabledTextColor = uIButton.hoveredTextColor;
            uIPanel                     = (strip.tabContainer.components[1] as UIPanel);
            uIPanel.autoLayout          = true;
            uIPanel.wrapLayout          = true;
            uIPanel.autoLayoutDirection = LayoutDirection.Horizontal;
            uIHelper                    = new UIHelper(uIPanel);
            uIHelper.AddSpace(15);
            uIHelper.AddDropdown("Left", ColorNames, Array.IndexOf(ColorNames, settings[Setting.FireLeft]), delegate(int sel)
            {
                settings[Setting.FireLeft] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            uIHelper.AddDropdown("Right", ColorNames, Array.IndexOf(ColorNames, settings[Setting.FireRight]), delegate(int sel)
            {
                settings[Setting.FireRight] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            uIHelper.AddSpace(15);
            chkManualRearFire = (uIHelper.AddCheckbox("Configure Rear Lights Separately", Convert.ToBoolean(settings[Setting.ManualRearFire]), delegate(bool chkd)
            {
                settings[Setting.ManualRearFire] = chkd.ToString();
                ExportSettings();
                RearFireVisibility(chkd);
                if (loaded)
                {
                    Apply();
                }
            }) as UICheckBox);
            chkManualRearFire.width = 744f;
            uIHelper.AddSpace(15);
            ddFireLeftRear = (UIDropDown)uIHelper.AddDropdown("Left", ColorNames, Array.IndexOf(ColorNames, settings[Setting.FireLeftRear]), delegate(int sel)
            {
                settings[Setting.FireLeftRear] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            ddFireRightRear = (UIDropDown)uIHelper.AddDropdown("Right", ColorNames, Array.IndexOf(ColorNames, settings[Setting.FireRightRear]), delegate(int sel)
            {
                settings[Setting.FireRightRear] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            RearFireVisibility(Convert.ToBoolean(settings[Setting.ManualRearFire]));
            uIButton2                   = strip.AddTab("Ambulance");
            uIButton2.textColor         = uIButton.textColor;
            uIButton2.pressedTextColor  = uIButton.pressedTextColor;
            uIButton2.hoveredTextColor  = uIButton.hoveredTextColor;
            uIButton2.focusedTextColor  = uIButton.hoveredTextColor;
            uIButton2.disabledTextColor = uIButton.hoveredTextColor;
            uIPanel                     = (strip.tabContainer.components[2] as UIPanel);
            uIPanel.autoLayout          = true;
            uIPanel.wrapLayout          = true;
            uIPanel.autoLayoutDirection = LayoutDirection.Horizontal;
            uIHelper                    = new UIHelper(uIPanel);
            uIHelper.AddSpace(15);
            uIHelper.AddDropdown("Left", ColorNames, Array.IndexOf(ColorNames, settings[Setting.AmbulanceLeft]), delegate(int sel)
            {
                settings[Setting.AmbulanceLeft] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            uIHelper.AddDropdown("Right", ColorNames, Array.IndexOf(ColorNames, settings[Setting.AmbulanceRight]), delegate(int sel)
            {
                settings[Setting.AmbulanceRight] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            uIHelper.AddSpace(15);
            chkManualRearAmbulance = (uIHelper.AddCheckbox("Configure Rear Lights Separately", Convert.ToBoolean(settings[Setting.ManualRearAmbulance]), delegate(bool chkd)
            {
                settings[Setting.ManualRearAmbulance] = chkd.ToString();
                ExportSettings();
                RearAmbulanceVisibility(chkd);
                if (loaded)
                {
                    Apply();
                }
            }) as UICheckBox);
            chkManualRearAmbulance.width = 744f;
            uIHelper.AddSpace(15);
            ddAmbulanceLeftRear = (UIDropDown)uIHelper.AddDropdown("Left", ColorNames, Array.IndexOf(ColorNames, settings[Setting.AmbulanceLeftRear]), delegate(int sel)
            {
                settings[Setting.AmbulanceLeftRear] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            ddAmbulanceRightRear = (UIDropDown)uIHelper.AddDropdown("Right", ColorNames, Array.IndexOf(ColorNames, settings[Setting.AmbulanceRightRear]), delegate(int sel)
            {
                settings[Setting.AmbulanceRightRear] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            RearAmbulanceVisibility(Convert.ToBoolean(settings[Setting.ManualRearAmbulance]));

            uIButton2                   = strip.AddTab("Rotary (e.g. Snow Plow)", uIButton, fillText: true);
            uIButton2.textColor         = uIButton.textColor;
            uIButton2.pressedTextColor  = uIButton.pressedTextColor;
            uIButton2.hoveredTextColor  = uIButton.hoveredTextColor;
            uIButton2.focusedTextColor  = uIButton.hoveredTextColor;
            uIButton2.disabledTextColor = uIButton.hoveredTextColor;
            uIPanel                     = strip.tabContainer.components[3] as UIPanel;
            uIPanel.autoLayout          = true;
            uIPanel.wrapLayout          = true;
            uIPanel.autoLayoutDirection = LayoutDirection.Horizontal;
            uIHelper                    = new UIHelper(uIPanel);
            uIHelper.AddSpace(15);
            uIHelper.AddDropdown("Left", ColorNames, Array.IndexOf(ColorNames, settings[Setting.SnowPlowLeft]), delegate(int sel)
            {
                settings[Setting.SnowPlowLeft] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });
            uIHelper.AddDropdown("Right", ColorNames, Array.IndexOf(ColorNames, settings[Setting.SnowPlowRight]), delegate(int sel)
            {
                settings[Setting.SnowPlowRight] = ColorNames[sel];
                ExportSettings();
                if (loaded)
                {
                    Apply();
                }
            });

            strip.selectedIndex = -1;
            strip.selectedIndex = 0;
            int selectedIndex = uIDropDown.selectedIndex;

            uIDropDown.selectedIndex = -1;
            uIDropDown.selectedIndex = selectedIndex;
        }