Beispiel #1
0
        public FinalConnector(NetInfo centerNodeNetInfo, EdgeIntersections2 edgeIntersections, Ellipse ellipse, bool insertControllingVertices)
        {
            intersections = edgeIntersections?.Intersections ?? new List <VectorNodeStruct>();
            m_group       = edgeIntersections?.TmpeActionGroup();

            this.ellipse = ellipse;
            pleasenoinfiniterecursion = 0;
            this.centerNodeNetInfo    = centerNodeNetInfo;
            leftHandTraffic           = Singleton <SimulationManager> .instance.m_metaData.m_invertTraffic ==
                                        SimulationMetaData.MetaBool.True;

            // We ensure that the segments are not too long. For circles only (with ellipses it would be more difficult)
            m_maxAngDistance = Math.Min(Math.PI * 25 / ellipse.RadiusMain, Math.PI / 2 + 0.1d);

            bool isCircle = ellipse.IsCircle();

            if (!isCircle && insertControllingVertices)
            {
                /* See doc in the method below */
                InsertIntermediateNodes();
            }

            /* If the list of edge nodes is empty, we add one default intersection. */
            if (isCircle && intersections.Count == 0)
            {
                Vector3 defaultIntersection = new Vector3(ellipse.RadiusMain, 0, 0) + ellipse.Center;
                ushort  newNodeId           = NetAccess.CreateNode(centerNodeNetInfo, defaultIntersection);
                intersections.Add(new VectorNodeStruct(newNodeId));
            }

            int count = intersections.Count;

            foreach (VectorNodeStruct item in intersections)
            {
                item.angle = Ellipse.VectorsAngle(item.vector - ellipse.Center);
            }

            /* We sort the nodes according to their angles */
            intersections.Sort();

            /* Goes over all the nodes and conntets each of them to the angulary closest neighbour. (In a given direction) */

            for (int i = 0; i < count; i++)
            {
                VectorNodeStruct prevNode = intersections[i];
                if (isCircle)
                {
                    prevNode = CheckAngularDistance(intersections[i], intersections[(i + 1) % count]);
                }
                ConnectNodes(intersections[(i + 1) % count], prevNode);
            }

            if (m_group != null)
            {
                ModThreading.Timer(m_group);
            }
        }
 public void Build()
 {
     ModThreading.PushAction(actionGroupRoads, actionGroupTMPE);
 }
Beispiel #3
0
        public FinalConnector(NetInfo centerNodeNetInfo, EdgeIntersections2 edgeIntersections, Ellipse ellipse, bool insertControllingVertices)
        {
            intersections      = edgeIntersections?.Intersections ?? new List <RoundaboutNode>();
            actionGroupTMPE    = edgeIntersections?.ActionGroupTMPE ?? new ActionGroup("Set up TMPE");
            actionGroupRoads   = edgeIntersections?.ActionGroupRoads ?? new ActionGroup("Build roundabout");
            wrappersDictionary = edgeIntersections?.networkDictionary ?? new WrappersDictionary();

            this.ellipse = ellipse;
            pleasenoinfiniterecursion = 0;
            this.centerNodeNetInfo    = centerNodeNetInfo;
            leftHandTraffic           = Singleton <SimulationManager> .instance.m_metaData.m_invertTraffic ==
                                        SimulationMetaData.MetaBool.True;

            // We ensure that the segments are not too long. For circles only (with ellipses it would be more difficult)
            m_maxAngDistance = Math.Min(Math.PI * 25 / ellipse.RadiusMain, Math.PI / 2 + 0.1d);

            bool isCircle = ellipse.IsCircle();

            if (!isCircle && insertControllingVertices)
            {
                /* See doc in the method below */
                InsertIntermediateNodes();
            }

            /* If the list of edge nodes is empty, we add one default intersection. */
            if (isCircle && intersections.Count == 0)
            {
                Vector3 defaultIntersection = new Vector3(ellipse.RadiusMain, 0, 0) + ellipse.Center;
                //ushort newNodeId = NetAccess.CreateNode(centerNodeNetInfo, defaultIntersection);

                WrappedNode newNodeW = new WrappedNode();
                newNodeW.Position = defaultIntersection;
                newNodeW.NetInfo  = centerNodeNetInfo;
                RoundaboutNode raNode = new RoundaboutNode(newNodeW);
                raNode.Create(actionGroupRoads);
                intersections.Add(raNode);
            }

            int count = intersections.Count;

            foreach (RoundaboutNode item in intersections)
            {
                item.angle = Ellipse.VectorsAngle(item.wrappedNode.Position - ellipse.Center);
            }

            /* We sort the nodes according to their angles */
            intersections.Sort();

            /* Goes over all the nodes and conntets each of them to the angulary closest neighbour. (In a given direction) */

            for (int i = 0; i < count; i++)
            {
                RoundaboutNode prevNode = intersections[i];
                if (isCircle)
                {
                    prevNode = CheckAngularDistance(intersections[i], intersections[(i + 1) % count]);
                }
                ConnectNodes(intersections[(i + 1) % count], prevNode);
            }

            // Charge player
            var chargePlayerAction = new ChargePlayerAction(actionGroupRoads.DoCost(), centerNodeNetInfo.m_class);

            if (!chargePlayerAction.CheckMoney())
            {
                throw new PlayerException("Not enough money!");
            }

            actionGroupRoads.Actions.Add(chargePlayerAction);

            // Create
            ModThreading.PushAction(actionGroupRoads, actionGroupTMPE);
        }
Beispiel #4
0
        private void CreateOptionPanel()
        {
            name             = "RAB_ToolOptionsPanel";
            atlas            = ResourceLoader.GetAtlas("Ingame");
            backgroundSprite = "SubcategoriesPanel";
            size             = new Vector2(204, 180);
            absolutePosition = new Vector3(RoundAboutBuilder.savedWindowX.value, RoundAboutBuilder.savedWindowY.value);

            isVisible = false;

            //DebugUtils.Log("absolutePosition: " + absolutePosition);

            eventPositionChanged += (c, p) =>
            {
                if (absolutePosition.x < 0)
                {
                    absolutePosition = RoundAboutBuilder.defWindowPosition;
                }

                Vector2 resolution = GetUIView().GetScreenResolution();

                absolutePosition = new Vector2(
                    Mathf.Clamp(absolutePosition.x, 0, resolution.x - width),
                    Mathf.Clamp(absolutePosition.y, 0, resolution.y - height));

                RoundAboutBuilder.savedWindowX.value = (int)absolutePosition.x;
                RoundAboutBuilder.savedWindowY.value = (int)absolutePosition.y;
            };

            UIDragHandle dragHandle = AddUIComponent <UIDragHandle>();

            dragHandle.width            = width;
            dragHandle.relativePosition = Vector3.zero;
            dragHandle.target           = parent;

            P_RoundAboutPanel = AddUIComponent <RoundAboutPanel>();
            P_EllipsePanel_1  = AddUIComponent <EllipsePanel_1>();
            P_EllipsePanel_2  = AddUIComponent <EllipsePanel_2>();
            P_EllipsePanel_3  = AddUIComponent <EllipsePanel_3>();
            P_TmpeSetupPanel  = AddUIComponent <TmpeSetupPanel>();
            P_FreeToolPanel   = AddUIComponent <FreeToolPanel>();
            //P_RoundAboutPanel.height = 104f; // cheat

            // From Elektrix's Road Tools
            UIButton openDescription = AddUIComponent <UIButton>();

            openDescription.relativePosition = new Vector3(width - 24f, 8f);
            openDescription.size             = new Vector3(15f, 15f);
            openDescription.normalFgSprite   = "ToolbarIconHelp";
            openDescription.name             = "RAB_workshopButton";
            openDescription.tooltip          = "Roundabout Builder [" + RoundAboutBuilder.VERSION + "] by Strad\nOpen in Steam Workshop";
            SetupButtonStateSprites(ref openDescription, "OptionBase", true);
            if (!PlatformService.IsOverlayEnabled())
            {
                openDescription.isVisible = false;
                openDescription.isEnabled = false;
            }
            openDescription.eventClicked += delegate(UIComponent component, UIMouseEventParameter click)
            {
                if (PlatformService.IsOverlayEnabled() && RoundAboutBuilder.WORKSHOP_FILE_ID != null)
                {
                    PlatformService.ActivateGameOverlayToWorkshopItem(RoundAboutBuilder.WORKSHOP_FILE_ID);
                }
                openDescription.Unfocus();
            };
            // -- Elektrix

            float cummulativeHeight = 8;

            /* Top section */
            m_topSection = AddUIComponent <UIPanel>();
            m_topSection.relativePosition = new Vector2(0, 0);
            m_topSection.SendToBack();

            UILabel label = m_topSection.AddUIComponent <UILabel>();

            label.textScale        = 0.9f;
            label.text             = "Roundabout Builder";
            label.relativePosition = new Vector2(8, cummulativeHeight);
            label.SendToBack();
            cummulativeHeight += label.height + 8;

            m_topSection.height = cummulativeHeight;
            m_topSection.width  = width;
            dragHandle.height   = cummulativeHeight;

            dropDown = AddUIComponent <UINetInfoDropDown>();
            //dropDown.relativePosition = new Vector2(8, cummulativeHeight);
            dropDown.width = width - 16;
            //cummulativeHeight += dropDown.height + 8;


            /* Bottom section */

            m_setupTmpeSection              = AddUIComponent <UIPanel>();
            m_setupTmpeSection.width        = 204f;
            m_setupTmpeSection.clipChildren = true;
            var setupTmpe = CreateCheckBox(m_setupTmpeSection);

            setupTmpe.name               = "RAB_setupTmpe";
            setupTmpe.label.text         = "Set up TMPE";
            setupTmpe.tooltip            = "Apply TMPE policies to the roundabout";
            setupTmpe.isChecked          = SavedSetupTmpe;
            setupTmpe.relativePosition   = new Vector3(8, 0);
            setupTmpe.eventCheckChanged += (c, state) =>
            {
                SavedSetupTmpe.value = state;
            };
            var tmpeButton = CreateButton(m_setupTmpeSection);

            tmpeButton.text             = "...";
            tmpeButton.tooltip          = "TMPE settings";
            tmpeButton.height           = setupTmpe.height;
            tmpeButton.width            = 30;
            tmpeButton.relativePosition = new Vector2(width - tmpeButton.width - 8, 0);
            tmpeButton.eventClick      += (c, p) =>
            {
                bool holder = this.keepOpen;
                this.keepOpen    = true;
                toolOnUI.enabled = false;
                this.keepOpen    = holder;
                SwitchWindow(P_TmpeSetupPanel);
            };
            m_setupTmpeSection.height = setupTmpe.height + 8;
            //cummulativeHeight += keepOpen.height + 8;

            cummulativeHeight = 0;
            m_bottomSection   = AddUIComponent <UIPanel>();

            var keepOpen = CreateCheckBox(m_bottomSection);

            keepOpen.name               = "RAB_keepOpen";
            keepOpen.label.text         = "Keep open";
            keepOpen.tooltip            = "Window won't close automatically when the tool is unselected";
            keepOpen.isChecked          = true;
            keepOpen.relativePosition   = new Vector3(8, cummulativeHeight);
            keepOpen.width              = 196; // width - padding
            keepOpen.eventCheckChanged += (c, state) =>
            {
                this.keepOpen = state;
            };
            cummulativeHeight += keepOpen.height + 8;

            // Back button
            backButton                  = CreateButton(m_bottomSection);
            backButton.text             = "Back";
            backButton.relativePosition = new Vector2(8, cummulativeHeight);
            backButton.width            = width - 16;
            backButton.eventClick      += (c, p) =>
            {
                if (backButton.isVisible)
                {
                    if (m_panelOnUI.IsSpecialWindow)
                    {
                        SwitchWindow(m_lastStandardPanel);
                        toolOnUI.enabled = true;
                    }
                    else
                    {
                        toolOnUI.GoToFirstStage();
                        SwitchTool(RoundaboutTool.Instance);
                    }
                }
            };

            cummulativeHeight += backButton.height + 8;

            closeButton                  = CreateButton(m_bottomSection);
            closeButton.text             = "Close";
            closeButton.relativePosition = new Vector2(8, cummulativeHeight);
            closeButton.eventClick      += (c, p) =>
            {
                enabled = false;
                if (toolOnUI != null)
                {
                    toolOnUI.enabled = false;
                }
            };

            undoButton                  = CreateButton(m_bottomSection);
            undoButton.text             = "Undo";
            undoButton.tooltip          = "Remove last built roundabout (CTRL+Z). Warning: Use only right after the roundabout has been built";
            undoButton.relativePosition = new Vector2(16 + closeButton.width, cummulativeHeight);
            undoButton.isEnabled        = false;
            undoButton.eventClick      += (c, p) =>
            {
                ModThreading.UndoAction();
            };

            cummulativeHeight += closeButton.height + 8;

            m_bottomSection.height = cummulativeHeight;
            m_bottomSection.width  = width;

            m_hoveringLabel           = AddUIComponent <HoveringLabel>();
            m_hoveringLabel.isVisible = false;

            /* Enable roundabout tool as default */
            SwitchTool(RoundaboutTool.Instance);

            // Is done by modthreading from 1.5.3 on

            /*try
             * {
             *  if(RoundAboutBuilder.ShowUIButton)
             *     UIPanelButton.CreateButton();
             * }
             * catch(Exception e)
             * {
             *  Debug.LogWarning("Failed to create UI button.");
             *  Debug.LogWarning(e);
             * }*/


            enabled = false;
        }