Example #1
0
        private float addStationToLinearMap(string stationPrefix, string stationName, Vector3 location, float offsetX, List <ushort> intersections, string airport, string harbor, string taxi, string regionalTrainStation, ushort stationNodeId, ItemClass.SubService ss, bool simple = false)//, out float intersectionPanelHeight)
        {
            ushort           lineID = lineInfoPanel.lineIdSelecionado.TransportLine;
            TransportLine    t      = lineInfoPanel.controller.tm.m_lines.m_buffer[(int)lineID];
            TransportManager tm     = Singleton <TransportManager> .instance;

            UIButton stationButton = null;

            TLMUtils.createUIElement <UIButton>(ref stationButton, lineStationsPanel.transform);
            stationButton.relativePosition = new Vector3(offsetX, 15f);
            stationButton.width            = 20;
            stationButton.height           = 20;
            stationButton.name             = "Station [" + stationName + "]";
            TLMUtils.initButton(stationButton, true, "IconPolicyBaseCircle");

            UITextField stationLabel = null;

            TLMUtils.createUIElement <UITextField>(ref stationLabel, stationButton.transform);
            stationLabel.autoSize            = true;
            stationLabel.width               = 220;
            stationLabel.height              = 20;
            stationLabel.useOutline          = true;
            stationLabel.pivot               = UIPivotPoint.MiddleLeft;
            stationLabel.horizontalAlignment = UIHorizontalAlignment.Left;
            stationLabel.verticalAlignment   = UIVerticalAlignment.Middle;
            stationLabel.name             = "Station [" + stationName + "] Name";
            stationLabel.relativePosition = new Vector3(23f, -13f);
            stationLabel.text             = (!string.IsNullOrEmpty(stationPrefix) ? stationPrefix.Trim() + " " : "") + stationName.Trim();
            stationLabel.textScale        = Math.Max(0.5f, Math.Min(1, 24f / stationLabel.text.Length));

            TLMUtils.uiTextFieldDefaults(stationLabel);
            stationLabel.color           = new Color(0.3f, 0.3f, 0.3f, 1);
            stationLabel.textColor       = Color.white;
            stationLabel.cursorWidth     = 2;
            stationLabel.cursorBlinkTime = 100;
            stationLabel.eventGotFocus  += (x, y) =>
            {
                stationLabel.text = TLMUtils.getStationName(stationNodeId, lineID, ss);
            };
            stationLabel.eventTextSubmitted += (x, y) =>
            {
                TLMUtils.setStopName(y, stationNodeId, lineID, () =>
                {
                    stationLabel.text = TLMUtils.getFullStationName(stationNodeId, lineID, ss);
                    m_autoName        = TLMUtils.calculateAutoName(lineID);
                    lineInfoPanel.autoNameLabel.text = autoName;
                });
            };

            stationButton.gameObject.transform.localPosition    = new Vector3(0, 0, 0);
            stationButton.gameObject.transform.localEulerAngles = new Vector3(0, 0, 45);
            stationButton.eventClick += (component, eventParam) =>
            {
                lineInfoPanel.cameraController.SetTarget(lineInfoPanel.lineIdSelecionado, location, false);
                lineInfoPanel.cameraController.ClearTarget();
            };
            if (!simple)
            {
                stationOffsetX.Add(stationNodeId, offsetX);
                if (showIntersections)
                {
                    var otherLinesIntersections = TLMLineUtils.SortLines(intersections, t);

                    int intersectionCount = otherLinesIntersections.Count + (airport != string.Empty ? 1 : 0) + (taxi != string.Empty ? 1 : 0) + (harbor != string.Empty ? 1 : 0) + (regionalTrainStation != string.Empty ? 1 : 0);
                    if (intersectionCount > 0)
                    {
                        UIPanel intersectionsPanel = null;
                        TLMUtils.createUIElement <UIPanel>(ref intersectionsPanel, stationButton.transform);
                        intersectionsPanel.autoSize                  = false;
                        intersectionsPanel.autoLayout                = false;
                        intersectionsPanel.autoLayoutStart           = LayoutStart.TopLeft;
                        intersectionsPanel.autoLayoutDirection       = LayoutDirection.Horizontal;
                        intersectionsPanel.relativePosition          = new Vector3(-20, 10);
                        intersectionsPanel.wrapLayout                = false;
                        intersectionsPanel.autoFitChildrenVertically = true;

                        TLMLineUtils.PrintIntersections(airport, harbor, taxi, regionalTrainStation, intersectionsPanel, otherLinesIntersections);

                        intersectionsPanel.autoLayout = true;
                        intersectionsPanel.wrapLayout = true;
                        intersectionsPanel.width      = 55;
                        //
                        return(42f);
                    }
                    else
                    {
                        return(25f);
                    }
                }
                else if (showExtraStopInfo)
                {
                    float normalWidth = 42.5f;

                    NetNode stopNode = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stationNodeId];

                    int residents, tourists;
                    TLMLineUtils.GetQuantityPassengerWaiting(stationNodeId, out residents, out tourists);

                    UIPanel stationInfoStatsPanel = null;
                    TLMUtils.createUIElement <UIPanel>(ref stationInfoStatsPanel, stationButton.transform);
                    stationInfoStatsPanel.autoSize   = false;
                    stationInfoStatsPanel.autoLayout = false;
                    stationInfoStatsPanel.autoFitChildrenVertically = true;
                    stationInfoStatsPanel.autoLayoutStart           = LayoutStart.TopLeft;
                    stationInfoStatsPanel.autoLayoutDirection       = LayoutDirection.Horizontal;
                    stationInfoStatsPanel.relativePosition          = new Vector3(-20, 10);
                    stationInfoStatsPanel.autoLayout = true;
                    stationInfoStatsPanel.wrapLayout = true;
                    stationInfoStatsPanel.width      = normalWidth;

                    UILabel residentsWaiting = null;
                    TLMUtils.createUIElement <UILabel>(ref residentsWaiting, stationInfoStatsPanel.transform);
                    residentsWaiting.autoSize         = false;
                    residentsWaiting.useOutline       = true;
                    residentsWaiting.text             = residents.ToString();
                    residentsWaiting.tooltipLocaleID  = "TLM_RESIDENTS_WAITING";
                    residentsWaiting.backgroundSprite = "EmptySprite";
                    residentsWaiting.color            = new Color32(0x12, 0x68, 0x34, 255);
                    residentsWaiting.width            = normalWidth;
                    residentsWaiting.padding          = new RectOffset(0, 0, 4, 2);
                    residentsWaiting.height           = 20;
                    residentsWaiting.textScale        = 0.7f;
                    residentsWaiting.textAlignment    = UIHorizontalAlignment.Center;
                    residentCounters[stationNodeId]   = residentsWaiting;

                    UILabel touristsWaiting = null;
                    TLMUtils.createUIElement <UILabel>(ref touristsWaiting, stationInfoStatsPanel.transform);
                    touristsWaiting.autoSize         = false;
                    touristsWaiting.text             = tourists.ToString();
                    touristsWaiting.tooltipLocaleID  = "TLM_TOURISTS_WAITING";
                    touristsWaiting.useOutline       = true;
                    touristsWaiting.width            = normalWidth;
                    touristsWaiting.height           = 20;
                    touristsWaiting.padding          = new RectOffset(0, 0, 4, 2);
                    touristsWaiting.textScale        = 0.7f;
                    touristsWaiting.backgroundSprite = "EmptySprite";
                    touristsWaiting.color            = new Color32(0x1f, 0x25, 0x68, 255);
                    touristsWaiting.textAlignment    = UIHorizontalAlignment.Center;
                    touristCounters[stationNodeId]   = touristsWaiting;
                    //
                    return(normalWidth);
                }
                else
                {
                    return(25f);
                }
            }
            else
            {
                return(30f);
            }
        }
Example #2
0
        Vector3 getStation(ushort lineId, ushort stopId, ItemClass.SubService ss, out string stationName, out List <ushort> linhas, out string airport, out string harbor, out string taxiStand, out string regionalTrainStation, out string prefix)
        {
            NetManager      nm = Singleton <NetManager> .instance;
            BuildingManager bm = Singleton <BuildingManager> .instance;
            NetNode         nn = nm.m_nodes.m_buffer[(int)stopId];

            ItemClass.Service    servFound;
            ItemClass.SubService subServFound;
            ushort buildingId;

            stationName = TLMUtils.getStationName(stopId, lineId, ss, out servFound, out subServFound, out prefix, out buildingId);

            //paradas proximas (metro e trem)
            TransportManager tm           = Singleton <TransportManager> .instance;
            TransportInfo    thisLineInfo = tm.m_lines.m_buffer[(int)nn.m_transportLine].Info;
            TransportLine    thisLine     = tm.m_lines.m_buffer[(int)nn.m_transportLine];

            linhas = new List <ushort>();
            Vector3 location = nn.m_position;

            if (buildingId > 0 && ss == subServFound)
            {
                location = Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingId].CalculateSidewalkPosition();
            }
            TLMLineUtils.GetNearLines(location, 120f, ref linhas);

            airport              = String.Empty;
            taxiStand            = String.Empty;
            harbor               = String.Empty;
            regionalTrainStation = String.Empty;

            if (TLMCW.getCurrentConfigBool(TLMCW.ConfigIndex.TRAIN_SHOW_IN_LINEAR_MAP))
            {
                ushort trainStation = TLMUtils.FindBuilding(location != Vector3.zero ? location : nn.m_position, 120f, ItemClass.Service.PublicTransport, ItemClass.SubService.PublicTransportTrain, null, Building.Flags.None, Building.Flags.Untouchable | Building.Flags.Downgrading);

                if (trainStation > 0)
                {
                    InstanceID iid = default(InstanceID);
                    iid.Building         = trainStation;
                    regionalTrainStation = bm.GetBuildingName(trainStation, iid);
                }
            }

            if (TLMCW.getCurrentConfigBool(TLMCW.ConfigIndex.PLANE_SHOW_IN_LINEAR_MAP))
            {
                ushort airportId = TLMUtils.FindBuilding(location != Vector3.zero ? location : nn.m_position, 120f, ItemClass.Service.PublicTransport, ItemClass.SubService.PublicTransportPlane, new TransferManager.TransferReason[] { TransferManager.TransferReason.PassengerPlane }, Building.Flags.None, Building.Flags.Untouchable);

                if (airportId > 0)
                {
                    InstanceID iid = default(InstanceID);
                    iid.Building = airportId;
                    airport      = bm.GetBuildingName(airportId, iid);
                }
            }

            if (TLMCW.getCurrentConfigBool(TLMCW.ConfigIndex.SHIP_SHOW_IN_LINEAR_MAP))
            {
                ushort harborId = TLMUtils.FindBuilding(location != Vector3.zero ? location : nn.m_position, 120f, ItemClass.Service.PublicTransport, ItemClass.SubService.PublicTransportShip, new TransferManager.TransferReason[] { TransferManager.TransferReason.PassengerShip }, Building.Flags.None, Building.Flags.Untouchable);

                if (harborId > 0)
                {
                    InstanceID iid = default(InstanceID);
                    iid.Building = harborId;
                    harbor       = bm.GetBuildingName(harborId, iid);
                }
            }
            if (TLMCW.getCurrentConfigBool(TLMCW.ConfigIndex.TAXI_SHOW_IN_LINEAR_MAP))
            {
                ushort taxiId = TLMUtils.FindBuilding(location != Vector3.zero ? location : nn.m_position, 50f, ItemClass.Service.PublicTransport, ItemClass.SubService.PublicTransportTaxi, new TransferManager.TransferReason[] { TransferManager.TransferReason.Taxi }, Building.Flags.None, Building.Flags.Untouchable);

                if (taxiId > 0)
                {
                    InstanceID iid = default(InstanceID);
                    iid.Building = taxiId;
                    taxiStand    = bm.GetBuildingName(taxiId, iid);
                }
            }


            return(location);
        }
Example #3
0
        public static void drawCityMap()
        {
            TLMController controller = TLMController.instance;
            Dictionary <TransportInfo.TransportType, List <ushort> > linesByType = new Dictionary <TransportInfo.TransportType, List <ushort> >();

            linesByType[TransportInfo.TransportType.Metro] = new List <ushort>();
            linesByType[TransportInfo.TransportType.Train] = new List <ushort>();
            linesByType[TransportInfo.TransportType.Tram]  = new List <ushort>();
            linesByType[TransportInfo.TransportType.Ship]  = new List <ushort>();

            //			List<int> usedX = new List<int> ();
            //			List<int> usedY = new List<int> ();
            int nextStationId = 1;

            for (ushort lineId = 0; lineId < controller.tm.m_lines.m_size; lineId++)
            {
                TransportLine t = controller.tm.m_lines.m_buffer[(int)lineId];
                if (t.m_lineNumber > 0 && (t.Info.m_transportType == TransportInfo.TransportType.Metro ||
                                           t.Info.m_transportType == TransportInfo.TransportType.Train ||
                                           t.Info.m_transportType == TransportInfo.TransportType.Tram ||
                                           t.Info.m_transportType == TransportInfo.TransportType.Ship))
                {
                    switch (t.Info.m_transportType)
                    {
                    case TransportInfo.TransportType.Ship:
                    case TransportInfo.TransportType.Train:
                    case TransportInfo.TransportType.Metro:
                    case TransportInfo.TransportType.Tram:
                        linesByType[t.Info.m_transportType].Add(lineId);
                        break;
                    }
                }
            }

            CalculateCoords calc         = TLMLineUtils.gridPosition81Tiles;
            NetManager      nm           = NetManager.instance;
            float           invPrecision = 32;
            //Restart:
            Dictionary <int, List <int> > positions = new Dictionary <int, List <int> >();
            List <Station> stations = new List <Station>();
            Dictionary <Segment2, Color32>        svgLines       = new Dictionary <Segment2, Color32>();
            Dictionary <ushort, MapTransportLine> transportLines = new Dictionary <ushort, MapTransportLine>();

            foreach (TransportInfo.TransportType tt in new TransportInfo.TransportType[] { TransportInfo.TransportType.Ship, TransportInfo.TransportType.Train, TransportInfo.TransportType.Metro, TransportInfo.TransportType.Tram })
            {
                foreach (ushort lineId in linesByType[tt])
                {
                    TransportLine t     = controller.tm.m_lines.m_buffer[(int)lineId];
                    float         range = 75f;
                    switch (tt)
                    {
                    case TransportInfo.TransportType.Ship:
                        range = 150f;
                        break;

                    case TransportInfo.TransportType.Metro:
                    case TransportInfo.TransportType.Train:
                        range = 100f;
                        break;
                    }


                    int stopsCount = t.CountStops(lineId);
                    if (stopsCount == 0)
                    {
                        continue;
                    }
                    Color   color = t.m_color;
                    Vector2 ultPos = Vector2.zero;
                    bool    day, night;
                    t.GetActive(out day, out night);
                    transportLines[lineId] = new MapTransportLine(color, day, night, lineId);
                    int startStop = 0;
                    int finalStop = stopsCount;

                    for (int j = startStop; j < finalStop; j++)
                    {
                        //						Debug.Log ("ULT POS:" + ultPos);
                        ushort               nextStop = t.GetStop(j % stopsCount);
                        ItemClass.Service    service;
                        ItemClass.SubService nil2;
                        string               prefix;
                        ushort               buildingId;
                        string               name = TLMUtils.getStationName(nextStop, lineId, t.Info.m_stationSubService, out service, out nil2, out prefix, out buildingId);

                        Vector3 worldPos = TLMUtils.getStationBuildingPosition(nextStop, t.Info.m_stationSubService);
                        Vector2 pos2D    = calc(worldPos, invPrecision);
                        Vector2 gridAdd  = Vector2.zero;


                        var idx = stations.FirstOrDefault(x => x.stops.Contains(nextStop) || x.centralPos == pos2D);
                        if (idx != null)
                        {
                            transportLines[lineId].addStation(ref idx);
                        }
                        else
                        {
                            //if (positions.containskey((int)pos2d.x) && positions[(int)pos2d.x].contains((int)pos2d.y))
                            //{
                            //    float exp = (float)(math.log(invprecision) / math.log(2)) - 1;
                            //    invprecision = (float)math.pow(2, exp);
                            //    goto restart;
                            //}
                            List <ushort> nearStops = new List <ushort>();
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportShip }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTrain, ItemClass.SubService.PublicTransportMetro }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTram }, 10);
                            TLMUtils.doLog("Station: ${0}; nearStops: ${1}", name, string.Join(",", nearStops.Select(x => x.ToString()).ToArray()));
                            Station thisStation = new Station(name, pos2D, nearStops, nextStationId++, service, nextStop);
                            stations.Add(thisStation);
                            transportLines[lineId].addStation(ref thisStation);
                        }
                        if (!positions.ContainsKey((int)pos2D.x))
                        {
                            positions[(int)pos2D.x] = new List <int>();
                        }
                        positions[(int)pos2D.x].Add((int)pos2D.y);
                        //						Debug.Log ("POS:" + pos);
                        ultPos = pos2D;
                    }
                }
            }
            printToSVG(stations, transportLines, Singleton <SimulationManager> .instance.m_metaData.m_CityName + "_" + Singleton <SimulationManager> .instance.m_currentGameTime.ToString("yyyy.MM.dd"));
        }