/// <summary>
        /// Radio station buttons in vanilla game have multiple sprites (one for normal state,
        /// another one for if the button is pressed, ...). Custom stations only have a thumbnail.
        /// This detour method overwrites the vanilla behavior and makes is possible for
        /// music pack creators to only provide a thumbnail.
        /// </summary>
        /// <param name="button">Button.</param>
        /// <param name="station">Station.</param>
        private void CustomAssignStationToButton(UIButton button, RadioChannelInfo station)
        {
            UserRadioCollection collection = LoadingExtension.UserRadioContainer;
            UISprite            iconsprite = button.Find <UISprite>("sprite");

            // Additional sprite on top of the button
            if (iconsprite == null)
            {
                iconsprite      = button.AddUIComponent <UISprite>();
                iconsprite.name = "sprite";
            }

            // Different behavior depending on if the button is displayed in the panel or in the list
            if (button.parent != null && button.parent.name == "StationsList")
            {
                if (ModOptions.Instance.EnableImprovedRadioStationList)
                {
                    AssignStationToButtonInList(button, iconsprite, station, collection);
                }
                else
                {
                    AssignStationToButtonInPanel(button, iconsprite, station, collection);
                }
            }
            else
            {
                AssignStationToButtonInPanel(button, iconsprite, station, collection);

//	            if(ModOptions.Instance.EnableImprovedRadioStationList)
//	                AddComboboxVisualClue(button, iconsprite, station);
            }
        }
Beispiel #2
0
        private UIButton initDepotShortcutOnWorldInfoPanel(UIPanel parent)
        {
            UIButton saida = parent.AddUIComponent <UIButton>();

            saida.relativePosition = new Vector3(10, parent.height - 50);
            saida.atlas            = taTLM;
            saida.width            = 30;
            saida.height           = 30;
            saida.name             = "TLMDepotShortcut";
            saida.tooltipLocaleID  = "TLM_GOTO_DEPOT_PREFIX_EDIT";
            TLMUtils.initButton(saida, false, "TransportLinesManagerIcon");
            saida.eventClick += (x, y) =>
            {
                var prop = typeof(WorldInfoPanel).GetField("m_InstanceID", System.Reflection.BindingFlags.NonPublic
                                                           | System.Reflection.BindingFlags.Instance);
                ushort buildingId = ((InstanceID)(prop.GetValue(parent.gameObject.GetComponent <WorldInfoPanel>()))).Building;
                depotInfoPanel.openDepotInfo(buildingId);
            };

            UILabel prefixes = saida.AddUIComponent <UILabel>();

            prefixes.autoSize         = false;
            prefixes.width            = 200;
            prefixes.wordWrap         = true;
            prefixes.textAlignment    = UIHorizontalAlignment.Left;
            prefixes.prefix           = Locale.Get("TLM_PREFIXES_SERVED") + ":\n";
            prefixes.useOutline       = true;
            prefixes.height           = 60;
            prefixes.textScale        = 0.6f;
            prefixes.relativePosition = new Vector3(40, 10);
            prefixes.name             = "Prefixes";
            return(saida);
        }
Beispiel #3
0
        private void CreateValuesPanel()
        {
            _valuesButton               = AddUIComponent <UIButton>();
            _valuesButton.size          = new Vector2(66.0f, 66.0f);
            _valuesButton.eventClicked += OnValuesButtonClicked;

            _valuesLabel                   = _valuesButton.AddUIComponent <UILabel>();
            _valuesLabel.text              = " ";
            _valuesLabel.autoSize          = false;
            _valuesLabel.size              = _valuesButton.size;
            _valuesLabel.relativePosition  = new Vector2(0.0f, 0.0f);
            _valuesLabel.textAlignment     = UIHorizontalAlignment.Center;
            _valuesLabel.verticalAlignment = UIVerticalAlignment.Middle;

            _valuesSprite                  = _valuesButton.AddUIComponent <UISprite>();
            _valuesSprite.atlas            = ThemeSprites.Atlas;
            _valuesSprite.size             = new Vector2(64.0f, 64.0f);
            _valuesSprite.relativePosition = new Vector2(1.0f, 1.0f);

            _valuesButton.isVisible = false;
        }
Beispiel #4
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame && mode != LoadMode.NewMap && mode != LoadMode.LoadMap)
            {
                return;
            }
            modeU = mode;

            buildingWindowGameObject = new GameObject("buildingWindowObject");

            var currentUIView = UIView.GetAView();

            this.buildingWindow = buildingWindowGameObject.AddComponent <UIWindowold>();
            this.buildingWindow.transform.parent = currentUIView.transform;
            this.buildingWindow.position         = new Vector3(300, 122);
            this.buildingWindow.Hide();

            gdButton      = (UIButton)currentUIView.AddUIComponent(typeof(UIButton));
            gdButtonImage = (UISprite)gdButton.AddUIComponent(typeof(UISprite));

            gdButton.tooltip            = "GeodataLoader Switch";
            gdButton.isTooltipLocalized = false;
            gdButton.RefreshTooltip();
            gdButton.spritePadding = new RectOffset();

            gdButton.width  = 36;
            gdButton.height = 36;

            gdButtonImage.spriteName = "ToolbarIconZoomOutGlobeHovered";
            gdButtonImage.position   = new Vector3(18, -18);
            gdButtonImage.width      = 32;
            gdButtonImage.height     = 32;


            if (gdButtonImage.atlas == null || gdButtonImage.atlas.material == null)
            {
                Debug.Log("Could not get reference material!");
                return;
            }

            gdButton.playAudioEvents   = true;
            gdButton.transformPosition = new Vector3(-0.50f, 1.02f);//(-1.11f, 0.98f);
            gdButton.eventClicked     += uiButton_eventClick;
            Debug.Log("Loaded");
        }
Beispiel #5
0
        private void setLineNumberMainListing(int num, UIButton button)
        {
            UILabel uILabel = button.AddUIComponent <UILabel>();

            uILabel.autoSize          = false;
            uILabel.autoHeight        = false;
            uILabel.pivot             = UIPivotPoint.TopLeft;
            uILabel.verticalAlignment = UIVerticalAlignment.Middle;
            uILabel.textAlignment     = UIHorizontalAlignment.Center;
            uILabel.relativePosition  = new Vector3(0f, 0f);
            uILabel.width             = button.width;
            uILabel.height            = button.height;
            uILabel.useOutline        = true;
            uILabel.text = num.ToString();
            float num2 = uILabel.width / 50f;
            bool  flag = uILabel.text.Length == 4;

            if (flag)
            {
                uILabel.textScale        = num2;
                uILabel.relativePosition = new Vector3(0f, 1f);
            }
            else
            {
                bool flag2 = uILabel.text.Length == 3;
                if (flag2)
                {
                    uILabel.textScale        = num2 * 1.25f;
                    uILabel.relativePosition = new Vector3(0f, 1.5f);
                }
                else
                {
                    bool flag3 = uILabel.text.Length == 2;
                    if (flag3)
                    {
                        uILabel.textScale        = num2 * 1.75f;
                        uILabel.relativePosition = new Vector3(-0.5f, 0.5f);
                    }
                    else
                    {
                        uILabel.textScale = num2 * 2.3f;
                    }
                }
            }
        }
Beispiel #6
0
        private void setLineNumberMainListing(int num, UIButton button)
        {
            UILabel l = button.AddUIComponent <UILabel>();

            l.autoSize          = false;
            l.autoHeight        = false;
            l.pivot             = UIPivotPoint.TopLeft;
            l.verticalAlignment = UIVerticalAlignment.Middle;
            l.textAlignment     = UIHorizontalAlignment.Center;
            l.relativePosition  = new Vector3(0, 0);
            l.width             = button.width;
            l.height            = button.height;
            l.useOutline        = true;
            l.text = num.ToString();
            float ratio = l.width / 50;

            if (l.text.Length == 4)
            {
                l.textScale        = ratio;
                l.relativePosition = new Vector3(0f, 1f);
            }
            else if (l.text.Length == 3)
            {
                l.textScale        = ratio * 1.25f;
                l.relativePosition = new Vector3(0f, 1.5f);
            }
            else if (l.text.Length == 2)
            {
                l.textScale        = ratio * 1.75f;
                l.relativePosition = new Vector3(-0.5f, 0.5f);
            }
            else
            {
                l.textScale = ratio * 2.3f;
            }
        }
Beispiel #7
0
        private void CreateToggleBudgetButtons(UIPanel reference)
        {
            TLMUtils.createUIElement(out m_enableBudgetPerHour, reference.transform);
            m_enableBudgetPerHour.relativePosition = new Vector3(reference.width - 65f, 0f);
            m_enableBudgetPerHour.textScale        = 0.6f;
            m_enableBudgetPerHour.width            = 40;
            m_enableBudgetPerHour.height           = 40;
            m_enableBudgetPerHour.tooltip          = Locale.Get("TLM_USE_PER_PERIOD_BUDGET");
            TLMUtils.initButton(m_enableBudgetPerHour, true, "ButtonMenu");
            m_enableBudgetPerHour.name        = "EnableBudgetPerHour";
            m_enableBudgetPerHour.isVisible   = true;
            m_enableBudgetPerHour.eventClick += (component, eventParam) =>
            {
                IBudgetableExtension bte;
                uint idx;
                var  tsdRef = tsd;
                bte = TLMLineUtils.getExtensionFromTransportSystemDefinition(ref tsdRef);
                idx = (uint)SelectedPrefix;

                uint[] saveData    = bte.GetBudgetsMultiplier(idx);
                uint[] newSaveData = new uint[8];
                for (int i = 0; i < 8; i++)
                {
                    newSaveData[i] = saveData[0];
                }
                bte.SetBudgetMultiplier(idx, newSaveData);
                updateSliders();
            };

            var icon = m_enableBudgetPerHour.AddUIComponent <UISprite>();

            icon.relativePosition = new Vector3(2, 2);
            icon.atlas            = TLMController.taTLM;
            icon.width            = 36;
            icon.height           = 36;
            icon.spriteName       = "PerHourIcon";


            TLMUtils.createUIElement(out m_disableBudgetPerHour, reference.transform);
            m_disableBudgetPerHour.relativePosition = new Vector3(reference.width - 65f, 0f);
            m_disableBudgetPerHour.textScale        = 0.6f;
            m_disableBudgetPerHour.width            = 40;
            m_disableBudgetPerHour.height           = 40;
            m_disableBudgetPerHour.tooltip          = Locale.Get("TLM_USE_SINGLE_BUDGET");
            TLMUtils.initButton(m_disableBudgetPerHour, true, "ButtonMenu");
            m_disableBudgetPerHour.name        = "DisableBudgetPerHour";
            m_disableBudgetPerHour.isVisible   = true;
            m_disableBudgetPerHour.eventClick += (component, eventParam) =>
            {
                IBudgetableExtension bte;
                uint idx;
                var  tsdRef = tsd;
                bte = TLMLineUtils.getExtensionFromTransportSystemDefinition(ref tsdRef);
                idx = (uint)SelectedPrefix;

                uint[] saveData    = bte.GetBudgetsMultiplier(idx);
                uint[] newSaveData = new uint[] { saveData[0] };
                bte.SetBudgetMultiplier(idx, newSaveData);

                updateSliders();
            };

            icon = m_disableBudgetPerHour.AddUIComponent <UISprite>();
            icon.relativePosition = new Vector3(2, 2);
            icon.atlas            = TLMController.taTLM;
            icon.width            = 36;
            icon.height           = 36;
            icon.spriteName       = "24hLineIcon";
        }
Beispiel #8
0
        private void SetupControls()
        {
            if (m_policyButton != null)
            {
                return;
            }

            isVisible        = true;
            canFocus         = true;
            isInteractive    = true;
            backgroundSprite = "GenericPanel";
            size             = new Vector2(364f, 44f);
            objectUserData   = ToolsModifierControl.policiesPanel;

            m_policyButton                         = AddUIComponent <UIButton>();
            m_policyButton.name                    = "PolicyButton";
            m_policyButton.text                    = "Theme Name";
            m_policyButton.size                    = new Vector2(324f, 40f);
            m_policyButton.focusedBgSprite         = "PolicyBarBackActive";
            m_policyButton.normalBgSprite          = "PolicyBarBack";
            m_policyButton.relativePosition        = new Vector3(2f, 2f, 0f);
            m_policyButton.textPadding.left        = 50;
            m_policyButton.textColor               = new Color32(0, 0, 0, 255);
            m_policyButton.disabledTextColor       = new Color32(0, 0, 0, 255);
            m_policyButton.hoveredTextColor        = new Color32(0, 0, 0, 255);
            m_policyButton.pressedTextColor        = new Color32(0, 0, 0, 255);
            m_policyButton.focusedTextColor        = new Color32(0, 0, 0, 255);
            m_policyButton.disabledColor           = new Color32(124, 124, 124, 255);
            m_policyButton.dropShadowColor         = new Color32(103, 103, 103, 255);
            m_policyButton.dropShadowOffset        = new Vector2(1f, 1f);
            m_policyButton.textHorizontalAlignment = UIHorizontalAlignment.Left;
            m_policyButton.useDropShadow           = false;
            m_policyButton.textScale               = 0.875f;

            // This helper component updates the checkbox state every game tick
            m_policyButton.gameObject.AddComponent <ThemePolicyContainer>();

            m_policyCheckBox                  = m_policyButton.AddUIComponent <UICheckBox>();
            m_policyCheckBox.name             = "Checkbox";
            m_policyCheckBox.size             = new Vector2(363f, 44f);
            m_policyCheckBox.relativePosition = new Vector3(0f, -2f, 0f);
            m_policyCheckBox.clipChildren     = true;

            // Connect the checkbox with our theme manager
            m_policyCheckBox.eventCheckChanged += delegate(UIComponent component, bool isChecked)
            {
                lock (component)
                {
                    var districtId     = ToolsModifierControl.policiesPanel.targetDistrict;
                    var districtThemes = BuildingThemesManager.instance.GetDistrictThemes(districtId, true);

                    if (isChecked == districtThemes.Contains(m_theme))
                    {
                        return;
                    }

                    if (isChecked)
                    {
                        BuildingThemesManager.instance.EnableTheme(districtId, m_theme);
                    }
                    else
                    {
                        BuildingThemesManager.instance.DisableTheme(districtId, m_theme);
                    }
                }
            };

            // Checkbox-related UI components
            m_sprite                  = m_policyCheckBox.AddUIComponent <UISprite>();
            m_sprite.name             = "Unchecked";
            m_sprite.spriteName       = "ToggleBase";
            m_sprite.size             = new Vector2(16f, 16f);
            m_sprite.relativePosition = new Vector3(336.6984f, 14, 0f);

            m_policyCheckBox.checkedBoxObject      = m_sprite.AddUIComponent <UISprite>();
            m_policyCheckBox.checkedBoxObject.name = "Checked";
            ((UISprite)m_policyCheckBox.checkedBoxObject).spriteName = "ToggleBaseFocused";
            m_policyCheckBox.checkedBoxObject.size             = new Vector2(16f, 16f);
            m_policyCheckBox.checkedBoxObject.relativePosition = Vector3.zero;
        }
        private void Setup()
        {
            width                = parent.width;
            height               = 122f;
            autoLayout           = true;
            autoLayoutDirection  = LayoutDirection.Horizontal;
            padding              = new RectOffset(10, 0, 0, 0);
            autoLayoutPadding    = new RectOffset(0, 0, 0, 0);
            isInteractive        = true;
            builtinKeyNavigation = true;
            relativePosition     = new Vector2(410.0f, 0.0f);

            ScrollablePanel                      = AddUIComponent <UIScrollablePanel>();
            ScrollablePanel.zOrder               = 0;
            ScrollablePanel.width                = 366f;
            ScrollablePanel.height               = height;
            ScrollablePanel.autoLayout           = true;
            ScrollablePanel.wrapLayout           = true;
            ScrollablePanel.clipChildren         = true;
            ScrollablePanel.backgroundSprite     = "TextFieldPanel";
            ScrollablePanel.autoLayoutDirection  = LayoutDirection.Horizontal;
            ScrollablePanel.autoLayoutPadding    = new RectOffset(2, 2, 2, 2);
            ScrollablePanel.color                = new Color32(255, 255, 255, 255);
            ScrollablePanel.isInteractive        = true;
            ScrollablePanel.builtinKeyNavigation = true;
            ScrollablePanel.scrollWheelDirection = UIOrientation.Vertical;
            ScrollablePanel.scrollWithArrowKeys  = true;
            Dictionary <string, Texture2D> brushes = ForestBrush.Instance.GetBrushBitmaps();

            foreach (KeyValuePair <string, Texture2D> brush in brushes)
            {
                UIButton button = ScrollablePanel.AddUIComponent <UIButton>();
                button.atlas          = ResourceLoader.Atlas;
                button.normalBgSprite = ResourceLoader.GenericPanel;
                if (UserMod.Settings.SelectedBrush != null &&
                    UserMod.Settings.SelectedBrush.Options != null &&
                    UserMod.Settings.SelectedBrush.Options.BitmapID == brush.Key)
                {
                    button.normalBgSprite = string.Empty;
                }
                button.color        = new Color32(170, 170, 170, 255);
                button.hoveredColor = new Color32(210, 210, 210, 255);
                button.focusedColor = Color.white;
                button.pressedColor = Color.white;
                button.size         = new Vector2(57.0f, 57.0f);
                UITextureSprite sprite = button.AddUIComponent <UITextureSprite>();
                sprite.size             = button.size - new Vector2(4.0f, 4.0f);
                sprite.relativePosition = new Vector2(2.0f, 2.0f);
                sprite.texture          = brush.Value;
                button.objectUserData   = brush.Key;
                button.eventClicked    += Button_eventClicked;
                BrushButtons.Add(brush.Key, button);
            }

            UIScrollbar scrollbar = AddUIComponent <UIScrollbar>();

            scrollbar.zOrder          = 1;
            scrollbar.width           = 13f;
            scrollbar.height          = ScrollablePanel.height;
            scrollbar.orientation     = UIOrientation.Vertical;
            scrollbar.minValue        = 0;
            scrollbar.value           = 0;
            scrollbar.incrementAmount = 61;

            UISlicedSprite tracSprite = scrollbar.AddUIComponent <UISlicedSprite>();

            tracSprite.atlas            = ResourceLoader.Atlas;
            tracSprite.relativePosition = new Vector3(0, 0);
            tracSprite.autoSize         = true;
            tracSprite.size             = tracSprite.parent.size;
            tracSprite.fillDirection    = UIFillDirection.Vertical;
            tracSprite.spriteName       = ResourceLoader.LevelBarBackground;

            scrollbar.trackObject = tracSprite;

            UISlicedSprite thumbSprite = tracSprite.AddUIComponent <UISlicedSprite>();

            thumbSprite.atlas            = ResourceLoader.Atlas;
            thumbSprite.relativePosition = Vector2.zero;
            thumbSprite.fillDirection    = UIFillDirection.Vertical;
            thumbSprite.autoSize         = true;
            thumbSprite.width            = 13f;
            thumbSprite.spriteName       = ResourceLoader.LevelBarForeground;

            scrollbar.thumbObject = thumbSprite;

            ScrollablePanel.verticalScrollbar = scrollbar;

            owner = (ForestBrushPanel)parent;
        }
        private void SetupControls()
        {
            if (m_policyButton != null) return;

            isVisible = true;
            canFocus = true;
            isInteractive = true;
            backgroundSprite = "GenericPanel";
            size = new Vector2(364f, 44f);
            objectUserData = ToolsModifierControl.policiesPanel;

            m_policyButton = AddUIComponent<UIButton>();
            m_policyButton.name = "PolicyButton";
            m_policyButton.text = "Theme Name";
            m_policyButton.size = new Vector2(324f, 40f);
            m_policyButton.focusedBgSprite = "PolicyBarBackActive";
            m_policyButton.normalBgSprite = "PolicyBarBack";
            m_policyButton.relativePosition = new Vector3(2f, 2f, 0f);
            m_policyButton.textPadding.left = 50;
            m_policyButton.textColor = new Color32(0, 0, 0, 255);
            m_policyButton.disabledTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.hoveredTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.pressedTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.focusedTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.disabledColor = new Color32(124, 124, 124, 255);
            m_policyButton.dropShadowColor = new Color32(103, 103, 103, 255);
            m_policyButton.dropShadowOffset = new Vector2(1f, 1f);
            m_policyButton.textHorizontalAlignment = UIHorizontalAlignment.Left;
            m_policyButton.useDropShadow = false;
            m_policyButton.textScale = 0.875f;

            // This helper component updates the checkbox state every game tick
            m_policyButton.gameObject.AddComponent<ThemePolicyContainer>();

            m_policyCheckBox = m_policyButton.AddUIComponent<UICheckBox>();
            m_policyCheckBox.name = "Checkbox";
            m_policyCheckBox.size = new Vector2(363f, 44f);
            m_policyCheckBox.relativePosition = new Vector3(0f, -2f, 0f);
            m_policyCheckBox.clipChildren = true;

            // Connect the checkbox with our theme manager
            m_policyCheckBox.eventCheckChanged += delegate(UIComponent component, bool isChecked)
            {
                lock (component)
                {
                    var districtId = ToolsModifierControl.policiesPanel.targetDistrict;
                    var districtThemes = BuildingThemesManager.instance.GetDistrictThemes(districtId, true);

                    if (isChecked == districtThemes.Contains(m_theme)) return;

                    if (isChecked)
                    {
                        BuildingThemesManager.instance.EnableTheme(districtId, m_theme);
                    }
                    else
                    {
                        BuildingThemesManager.instance.DisableTheme(districtId, m_theme);
                    }
                }

            };

            // Checkbox-related UI components
            m_sprite = m_policyCheckBox.AddUIComponent<UISprite>();
            m_sprite.name = "Unchecked";
            m_sprite.spriteName = "ToggleBase";
            m_sprite.size = new Vector2(16f, 16f);
            m_sprite.relativePosition = new Vector3(336.6984f, 14, 0f);

            m_policyCheckBox.checkedBoxObject = m_sprite.AddUIComponent<UISprite>();
            m_policyCheckBox.checkedBoxObject.name = "Checked";
            ((UISprite)m_policyCheckBox.checkedBoxObject).spriteName = "ToggleBaseFocused";
            m_policyCheckBox.checkedBoxObject.size = new Vector2(16f, 16f);
            m_policyCheckBox.checkedBoxObject.relativePosition = Vector3.zero;
        }
Beispiel #11
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            if (NetPickerTool.instance == null)
            {
                ToolController toolController = GameObject.FindObjectOfType <ToolController>();
                NetPickerTool.instance         = toolController.gameObject.AddComponent <NetPickerTool>();
                NetPickerTool.instance.enabled = false;
            }

            if (!config.HasSeenHowToDragTheStupidIcon)
            {
                NetPickerTool.instance.ThrowError("Double-click the Elektrix's Mods icon to move it.");
                config.HasSeenHowToDragTheStupidIcon = true;
                Configuration <ElektrixModsConfiguration> .Save();
            }

            // Load Sprites
            LoadSprites();

            // Initiate UI
            // 1.1 - modular?
            UIPanel modsPanel = (UIPanel)UIView.Find("ElektrixModsPanel");

            if (modsPanel == null)
            {
                UIComponent TSBar = UIView.Find("TSBar");
                UIPanel     elektrixModsBackground = TSBar.AddUIComponent <UIPanel>();
                elektrixModsBackground.name             = "ElektrixMB";
                elektrixModsBackground.absolutePosition = new Vector2(config.PanelX, config.PanelY);
                elektrixModsBackground.width            = 60f;
                elektrixModsBackground.height           = 60f;
                elektrixModsBackground.zOrder           = 1;

                UIButton doneButton = elektrixModsBackground.AddUIComponent <UIButton>();
                doneButton.normalBgSprite   = "GenericPanel";
                doneButton.width            = 100f;
                doneButton.height           = 50f;
                doneButton.relativePosition = new Vector2(70f, 5f);
                doneButton.text             = "Done";
                doneButton.hoveredTextColor = new Color32(0, 255, 255, 1);
                doneButton.Hide();
                doneButton.zOrder = 99;

                UIDragHandle handle = elektrixModsBackground.AddUIComponent <UIDragHandle>();
                handle.name             = "ElektrixDragHandle";
                handle.relativePosition = Vector2.zero;
                handle.width            = elektrixModsBackground.width - 5;
                handle.height           = elektrixModsBackground.height - 5;
                handle.zOrder           = 0;
                handle.target           = elektrixModsBackground;
                handle.Start();
                handle.enabled = false;

                elektrixModsBackground.zOrder = 9;
                handle.zOrder = 10;

                elektrixModsBackground.eventDoubleClick += (component, ms) =>
                {
                    handle.zOrder = 13;
                    doneButton.Show();
                    handle.enabled = true;
                };

                /*
                 * elektrixModsBackground.eventMouseMove += (component, ms) =>
                 * {
                 *  if (ms.buttons.IsFlagSet(UIMouseButton.Right))
                 *  {
                 *      Vector3 mousePos = Input.mousePosition;
                 *      mousePos.y = UIView.GetAView().fixedHeight - mousePos.y;
                 *      elektrixModsBackground.absolutePosition = mousePos + m_deltaPos;
                 *
                 *      Debug.Log(mousePos + ", " + Input.mousePosition);
                 *      config.PanelX = (int)elektrixModsBackground.absolutePosition.x;
                 *      config.PanelY = (int)elektrixModsBackground.absolutePosition.y;
                 *      Configuration<ElektrixModsConfiguration>.Save();
                 *  }
                 * };*/
                /*
                 * elektrixModsBackground.eventMouseDown += (component, ms) =>
                 * {
                 *  if (ms.buttons.IsFlagSet(UIMouseButton.Right))
                 *  {
                 *      Vector3 mousePos = Input.mousePosition;
                 *      mousePos.y = UIView.GetAView().fixedHeight - mousePos.y;
                 *      m_deltaPos = elektrixModsBackground.absolutePosition - mousePos;
                 *      elektrixModsBackground.absolutePosition = mousePos + m_deltaPos;
                 *
                 *
                 *      config.PanelX = (int)elektrixModsBackground.absolutePosition.x;
                 *      config.PanelY = (int)elektrixModsBackground.absolutePosition.y;
                 *      Configuration<ElektrixModsConfiguration>.Save();
                 *  }
                 * };*/

                doneButton.eventClick += (component, ms) =>
                {
                    doneButton.Hide();
                    handle.zOrder  = 10;
                    handle.enabled = false;

                    config.PanelX = (int)elektrixModsBackground.absolutePosition.x;
                    config.PanelY = (int)elektrixModsBackground.absolutePosition.y;
                    Configuration <ElektrixModsConfiguration> .Save();
                };

                if (m_atlasLoaded)
                {
                    elektrixModsBackground.atlas            = SpriteUtilities.GetAtlas(m_atlasName);
                    elektrixModsBackground.backgroundSprite = "Blank";
                }
                else
                {
                    elektrixModsBackground.backgroundSprite = "GenericPanelLight";
                }


                elektrixModsBackground.color = new Color32(96, 96, 96, 255);

                UIButton elektrixModsToggle = elektrixModsBackground.AddUIComponent <UIButton>();
                elektrixModsToggle.disabledTextColor = new Color32(128, 128, 128, 255);
                ElektrixUI.SetupButtonStateSprites(ref elektrixModsToggle, "ToolbarIconGroup1");
                elektrixModsToggle.relativePosition = new Vector3(5f, 0f);
                elektrixModsToggle.size             = new Vector2(45f, 50f);
                elektrixModsToggle.name             = "ElektrixModsButton";
                elektrixModsToggle.zOrder           = 11;
                if (m_atlasLoaded)
                {
                    UISprite internalSprite = elektrixModsToggle.AddUIComponent <UISprite>();
                    internalSprite.atlas            = SpriteUtilities.GetAtlas(m_atlasName);
                    internalSprite.spriteName       = "Elektrix";
                    internalSprite.relativePosition = new Vector3(-3, 0);
                    internalSprite.width            = internalSprite.height = 50f;
                }
                else
                {
                    elektrixModsToggle.text = "E";
                }
                elektrixModsToggle.textScale               = 1.3f;
                elektrixModsToggle.textVerticalAlignment   = UIVerticalAlignment.Middle;
                elektrixModsToggle.textHorizontalAlignment = UIHorizontalAlignment.Center;

                modsPanel = elektrixModsBackground.AddUIComponent <UIPanel>();
                modsPanel.backgroundSprite = "MenuPanel2";
                modsPanel.name             = "ElektrixModsPanel";
                modsPanel.width            = 0;
                modsPanel.relativePosition = new Vector3(0, -modsPanel.height - 7);
                modsPanel.Hide();

                UILabel panelLabel = modsPanel.AddUIComponent <UILabel>();
                panelLabel.text             = "Elektrix's Mods";
                panelLabel.name             = "EL";
                panelLabel.relativePosition = new Vector3(12f, 15f);

                elektrixModsToggle.eventClicked += (component, click) =>
                {
                    if (!modsPanel.isVisible)
                    {
                        elektrixModsToggle.Focus();
                        modsPanel.Show();
                    }
                    else
                    {
                        elektrixModsToggle.Unfocus();
                        modsPanel.Hide();
                    }
                };
            }

            modsPanel = (UIPanel)UIView.Find("ElektrixModsPanel");

            UIPanel backgroundPanel = modsPanel.AddUIComponent <UIPanel>();

            backgroundPanel.backgroundSprite = "GenericPanelWhite";
            backgroundPanel.name             = "E2";
            backgroundPanel.height           = 70f;
            backgroundPanel.width            = 135f;
            backgroundPanel.relativePosition = new Vector3(10f, 0f);
            backgroundPanel.color            = new Color32(91, 97, 106, 255);

            UILabel title = backgroundPanel.AddUIComponent <UILabel>();

            title.text             = "Net Picker";
            title.name             = "E2L";
            title.textScale        = 0.9f;
            title.relativePosition = new Vector3(7f, 7f);

            UIButton netPickerTool = backgroundPanel.AddUIComponent <UIButton>();
            int      netClicks     = 0;

            ElektrixUI.SetupButtonStateSprites(ref netPickerTool, "OptionBase", true);
            netPickerTool.size             = new Vector2(45f, 45f);
            netPickerTool.relativePosition = new Vector3(5f, 22f);
            netPickerTool.name             = "E2A";
            netPickerTool.tooltip          = "Click a road to select it in the roads panel.";
            if (m_atlasLoaded)
            {
                UISprite internalSprite = netPickerTool.AddUIComponent <UISprite>();
                internalSprite.atlas            = SpriteUtilities.GetAtlas(m_atlasName);
                internalSprite.spriteName       = "NetTool";
                internalSprite.relativePosition = Vector3.zero;
                internalSprite.width            = internalSprite.height = 50f;
            }
            else
            {
                netPickerTool.text = "P";
            }
            netPickerTool.textScale = 1.3f;

            UIButton openDescription = backgroundPanel.AddUIComponent <UIButton>();

            openDescription.relativePosition = new Vector3(backgroundPanel.width - 20, 5);
            openDescription.size             = new Vector3(15, 15);
            openDescription.normalFgSprite   = "ToolbarIconHelp";
            openDescription.name             = "E2H";
            openDescription.tooltip          = "Open in Steam Workshop";
            ElektrixUI.SetupButtonStateSprites(ref openDescription, "OptionBase", true);
            if (!PlatformService.IsOverlayEnabled())
            {
                openDescription.isVisible = false;
                openDescription.isEnabled = false;
            }
            openDescription.eventClicked += (component, click) => {
                if (PlatformService.IsOverlayEnabled() && toolID != PublishedFileId.invalid)
                {
                    PlatformService.ActivateGameOverlayToWorkshopItem(toolID);
                }
                openDescription.Unfocus();
            };

            // Final overrides
            //UIPanel modsPanel = (UIPanel) UIView.Find("ElektrixModsPanel");
            IList <UIComponent> panels = modsPanel.components;
            float longestPanelWidth    = 0;

            for (int i = 0; i < panels.Count; i++)
            {
                if (!(panels[i] is UIPanel))
                {
                    continue;
                }
                panels[i].relativePosition = new Vector3(panels[i].relativePosition.x, 50 + (80 * (i - 1)));
                if (panels[i].width > longestPanelWidth)
                {
                    longestPanelWidth = panels[i].width;
                }
            }

            modsPanel.height           = 50f + (modsPanel.childCount - 1) * 80f;
            modsPanel.width            = 20f + longestPanelWidth;
            modsPanel.relativePosition = new Vector3(0, -modsPanel.height - 7);

            // Events
            netPickerTool.eventClicked += (component, click) =>
            {
                if (!NetPickerTool.instance.enabled)
                {
                    netClicks = 0;
                }

                netClicks++;
                if (netClicks == 1)
                {
                    netPickerTool.Focus();
                    NetPickerTool.instance.enabled = true;
                }
                else
                {
                    netPickerTool.Unfocus();
                    netClicks = 0;
                    NetPickerTool.instance.enabled = false;
                    ToolsModifierControl.SetTool <DefaultTool>();
                }
            };
        }
Beispiel #12
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            if (ResolveOverlapsTool.instance == null)
            {
                ToolController toolController = GameObject.FindObjectOfType <ToolController>();
                ResolveOverlapsTool.instance         = toolController.gameObject.AddComponent <ResolveOverlapsTool>();
                ResolveOverlapsTool.instance.enabled = false;
            }

            // Load Sprites
            LoadSprites();

            // Initiate UI
            // 1.1 - modular?
            UIPanel modsPanel    = (UIPanel)UIView.Find("ElektrixModsPanel");
            int     toggleClicks = 0;

            if (modsPanel == null)
            {
                UIComponent TSBar = UIView.Find("TSBar");
                UIPanel     elektrixModsBackground = TSBar.AddUIComponent <UIPanel>();
                elektrixModsBackground.name             = "ElektrixMB";
                elektrixModsBackground.absolutePosition = new Vector2(config.PanelX, config.PanelY);
                elektrixModsBackground.width            = 60f;
                elektrixModsBackground.height           = 60f;
                elektrixModsBackground.zOrder           = 1;

                UIButton doneButton = elektrixModsBackground.AddUIComponent <UIButton>();
                doneButton.normalBgSprite   = "GenericPanel";
                doneButton.width            = 100f;
                doneButton.height           = 50f;
                doneButton.relativePosition = new Vector2(70f, 5f);
                doneButton.text             = "Done";
                doneButton.hoveredTextColor = new Color32(0, 255, 255, 1);
                doneButton.Hide();
                doneButton.zOrder = 99;

                UIDragHandle handle = elektrixModsBackground.AddUIComponent <UIDragHandle>();
                handle.name             = "ElektrixDragHandle";
                handle.relativePosition = Vector2.zero;
                handle.width            = elektrixModsBackground.width - 5;
                handle.height           = elektrixModsBackground.height - 5;
                handle.zOrder           = 0;
                handle.target           = elektrixModsBackground;
                handle.Start();
                handle.enabled = false;

                elektrixModsBackground.zOrder = 9;
                handle.zOrder = 10;

                elektrixModsBackground.eventDoubleClick += (component, ms) =>
                {
                    handle.zOrder = 13;
                    doneButton.Show();
                    handle.enabled = true;
                };

                doneButton.eventClick += (component, ms) =>
                {
                    doneButton.Hide();
                    handle.zOrder  = 10;
                    handle.enabled = false;

                    config.PanelX = (int)elektrixModsBackground.absolutePosition.x;
                    config.PanelY = (int)elektrixModsBackground.absolutePosition.y;
                    Configuration <ElektrixModsConfiguration> .Save();
                };

                if (m_atlasLoaded)
                {
                    elektrixModsBackground.atlas            = SpriteUtilities.GetAtlas(m_atlasName);
                    elektrixModsBackground.backgroundSprite = "Blank";
                }
                else
                {
                    elektrixModsBackground.backgroundSprite = "GenericPanelLight";
                }


                elektrixModsBackground.color = new Color32(96, 96, 96, 255);

                UIButton elektrixModsToggle = elektrixModsBackground.AddUIComponent <UIButton>();
                elektrixModsToggle.disabledTextColor = new Color32(128, 128, 128, 255);
                ElektrixUI.SetupButtonStateSprites(ref elektrixModsToggle, "ToolbarIconGroup1");
                elektrixModsToggle.relativePosition = new Vector3(5f, 0f);
                elektrixModsToggle.size             = new Vector2(45f, 50f);
                elektrixModsToggle.name             = "ElektrixModsButton";
                elektrixModsToggle.zOrder           = 11;
                if (m_atlasLoaded)
                {
                    UISprite internalSprite = elektrixModsToggle.AddUIComponent <UISprite>();
                    internalSprite.atlas            = SpriteUtilities.GetAtlas(m_atlasName);
                    internalSprite.spriteName       = "Elektrix";
                    internalSprite.relativePosition = new Vector3(-3, 0);
                    internalSprite.width            = internalSprite.height = 50f;
                }
                else
                {
                    elektrixModsToggle.text = "E";
                }
                elektrixModsToggle.textScale               = 1.3f;
                elektrixModsToggle.textVerticalAlignment   = UIVerticalAlignment.Middle;
                elektrixModsToggle.textHorizontalAlignment = UIHorizontalAlignment.Center;

                modsPanel = elektrixModsBackground.AddUIComponent <UIPanel>();
                modsPanel.backgroundSprite = "GenericPanelLight";
                modsPanel.color            = new Color32(96, 96, 96, 255);
                modsPanel.name             = "ElektrixModsPanel";
                modsPanel.width            = 0;
                modsPanel.relativePosition = new Vector3(0, -modsPanel.height - 7);
                modsPanel.Hide();

                UILabel panelLabel = modsPanel.AddUIComponent <UILabel>();
                panelLabel.text             = "Elektrix's Mods";
                panelLabel.relativePosition = new Vector3(12f, 12f);

                elektrixModsToggle.eventClicked += (component, click) =>
                {
                    toggleClicks++;
                    if (toggleClicks == 1)
                    {
                        elektrixModsToggle.Focus();
                        modsPanel.Show();
                    }
                    else
                    {
                        elektrixModsToggle.Unfocus();
                        toggleClicks = 0;
                        modsPanel.Hide();
                    }
                };
            }

            modsPanel = (UIPanel)UIView.Find("ElektrixModsPanel");

            UIPanel backgroundPanel = modsPanel.AddUIComponent <UIPanel>();

            backgroundPanel.backgroundSprite = "GenericPanelLight";
            backgroundPanel.name             = "E3";
            backgroundPanel.height           = 50f;
            backgroundPanel.width            = 135f;
            backgroundPanel.relativePosition = new Vector3(10f, 40f + 70f);

            UIButton resolveOverlapsTool = backgroundPanel.AddUIComponent <UIButton>();
            int      buttonClicks        = 0;

            ElektrixUI.SetupButtonStateSprites(ref resolveOverlapsTool, "OptionBase", true);
            resolveOverlapsTool.size             = new Vector2(45f, 45f);
            resolveOverlapsTool.relativePosition = new Vector3(5f, 2.5f);
            resolveOverlapsTool.name             = "E3A";
            if (m_atlasLoaded)
            {
                UISprite internalSprite = resolveOverlapsTool.AddUIComponent <UISprite>();
                internalSprite.atlas            = SpriteUtilities.GetAtlas(m_atlasName);
                internalSprite.spriteName       = "ResolveOverlaps";
                internalSprite.relativePosition = Vector3.zero;
                internalSprite.width            = internalSprite.height = 50f;
            }
            else
            {
                resolveOverlapsTool.text = "R";
            }
            resolveOverlapsTool.textScale = 1.3f;

            UIButton addNodeTool   = backgroundPanel.AddUIComponent <UIButton>();
            int      button2Clicks = 0;

            ElektrixUI.SetupButtonStateSprites(ref addNodeTool, "OptionBase", true);
            addNodeTool.size             = new Vector2(45f, 45f);
            addNodeTool.relativePosition = new Vector3(55f, 2.5f);
            addNodeTool.name             = "E3B";
            if (m_atlasLoaded)
            {
                UISprite internalSprite2 = addNodeTool.AddUIComponent <UISprite>();
                internalSprite2.atlas            = SpriteUtilities.GetAtlas(m_atlasName);
                internalSprite2.spriteName       = "AddNode";
                internalSprite2.relativePosition = Vector3.zero;
                internalSprite2.width            = internalSprite2.height = 50f;
            }
            else
            {
                resolveOverlapsTool.text = "A";
            }
            resolveOverlapsTool.textScale = 1.3f;

            // Final overrides
            //UIPanel modsPanel = (UIPanel) UIView.Find("ElektrixModsPanel");
            IList <UIComponent> panels = modsPanel.components;
            float longestPanelWidth    = 0;

            for (int i = 0; i < panels.Count; i++)
            {
                if (!(panels[i] is UIPanel))
                {
                    continue;
                }
                panels[i].relativePosition = new Vector3(panels[i].relativePosition.x, 35 + (60 * (i - 1)));
                if (panels[i].width > longestPanelWidth)
                {
                    longestPanelWidth = panels[i].width;
                }
            }

            modsPanel.height           = 40f + (modsPanel.childCount - 1) * 60f;
            modsPanel.width            = 20f + longestPanelWidth;
            modsPanel.relativePosition = new Vector3(0, -modsPanel.height - 7);

            // Events
            resolveOverlapsTool.eventClicked += (component, click) =>
            {
                if (!ResolveOverlapsTool.instance.enabled)
                {
                    buttonClicks = 0;
                }

                buttonClicks++;
                if (buttonClicks == 1)
                {
                    resolveOverlapsTool.Focus();
                    ResolveOverlapsTool.instance.enabled = true;
                    ResolveOverlapsTool.instance.mode    = 0;
                }
                else
                {
                    resolveOverlapsTool.Unfocus();
                    buttonClicks = 0;
                    ResolveOverlapsTool.instance.enabled = false;
                    ResolveOverlapsTool.instance.mode    = 0;
                    ToolsModifierControl.SetTool <DefaultTool>();
                }
            };

            addNodeTool.eventClicked += (component, click) =>
            {
                if (!ResolveOverlapsTool.instance.enabled)
                {
                    button2Clicks = 0;
                }

                button2Clicks++;
                if (button2Clicks == 1)
                {
                    addNodeTool.Focus();
                    ResolveOverlapsTool.instance.enabled = true;
                    ResolveOverlapsTool.instance.mode    = 1;
                }
                else
                {
                    addNodeTool.Unfocus();
                    button2Clicks = 0;
                    ResolveOverlapsTool.instance.enabled = false;
                    ResolveOverlapsTool.instance.mode    = 0;
                    ToolsModifierControl.SetTool <DefaultTool>();
                }
            };
        }