コード例 #1
0
        public void OnSetTarget(Type source)
        {
            if (source == GetType())
            {
                return;
            }

            ushort lineID = GetLineID();

            if (lineID != 0)
            {
                LineType lineType = GetLineType(lineID);
                bool     isTour   = (lineType == LineType.WalkingTour);
                m_mapModeDropDown.isVisible = !isTour;
                m_vehiclesLabel.isVisible   = !isTour && m_currentMode != MapMode.CONNECTIONS;
                m_connectionLabel.isVisible = !isTour || m_currentMode == MapMode.CONNECTIONS;


                if (isTour)
                {
                    m_currentMode = MapMode.CONNECTIONS;
                    m_stopsLabel.relativePosition      = new Vector3(215f, 12f, 0f);
                    m_stopsLineSprite.relativePosition = m_kLineSSpritePositionForWalkingTours;
                    m_actualStopsX = m_kstopsXForWalkingTours;
                }
                else
                {
                    m_stopsLabel.relativePosition      = new Vector3(215f, 12f, 0f);
                    m_stopsLineSprite.relativePosition = m_kLineSSpritePosition;
                    m_actualStopsX = m_kstopsX;
                }
                m_lineStringLabel.text  = TLMLineUtils.GetIconString(lineID);
                m_stopsLineSprite.color = Singleton <TransportManager> .instance.GetLineColor(lineID);

                NetManager instance      = Singleton <NetManager> .instance;
                int        stopsCount    = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].CountStops(lineID);
                float[]    stopPositions = new float[stopsCount];
                m_cachedStopOrder = new ushort[stopsCount];
                float     minDistance  = float.MaxValue;
                float     lineLength   = 0f;
                UIPanel[] stopsButtons = m_stopButtons.SetItemCount(stopsCount);
                ushort    firstStop    = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_stops;
                ushort    currentStop  = firstStop;
                int       idx          = 0;
                while (currentStop != 0 && idx < stopsButtons.Length)
                {
                    stopsButtons[idx].GetComponentInChildren <UIButton>().objectUserData = currentStop;

                    m_cachedStopOrder[idx] = currentStop;
                    UILabel uilabel = stopsButtons[idx].Find <UILabel>("PassengerCount");

                    uilabel.prefix = TLMStationUtils.GetFullStationName(currentStop, lineID, TransportSystemDefinition.GetDefinitionForLine(lineID).SubService);
                    uilabel.text   = "";

                    UILabel dist = stopsButtons[idx].Find <UILabel>("Distance");
                    dist.text = "(???)";


                    CreateConnectionPanel(instance, stopsButtons[idx], currentStop);
                    UIButton button = stopsButtons[idx].GetComponentInChildren <UIButton>();
                    UpdateTerminalStatus(lineID, currentStop, button);
                    button.tooltipLocaleID
                        = !TransportSystemDefinition.From(lineID).CanHaveTerminals() ? ""
                        : currentStop == firstStop ? "K45_TLM_FIRSTSTOPALWAYSTERMINAL"
                        : "K45_TLM_RIGHTCLICKSETTERMINAL";

                    if (uilabel.objectUserData == null)
                    {
                        UITextField stopNameField = stopsButtons[idx].Find <UITextField>("StopNameField");
                        uilabel.eventMouseEnter += (c, r) => uilabel.backgroundSprite = "TextFieldPanelHovered";
                        uilabel.eventMouseLeave += (c, r) => uilabel.backgroundSprite = string.Empty;
                        uilabel.eventClick      += (c, r) =>
                        {
                            uilabel.Hide();
                            stopNameField.Show();
                            stopNameField.text = TLMStationUtils.GetStationName((ushort)button.objectUserData, GetLineID(), TransportSystemDefinition.GetDefinitionForLine(GetLineID()).SubService);
                            stopNameField.Focus();
                        };
                        stopNameField.eventLeaveFocus += delegate(UIComponent c, UIFocusEventParameter r)
                        {
                            stopNameField.Hide();
                            uilabel.Show();
                        };
                        stopNameField.eventTextSubmitted += (x, y) => TLMStationUtils.SetStopName(y.Trim(), (ushort)button.objectUserData, GetLineID(), () => uilabel.prefix = $"<color white>{TLMStationUtils.GetFullStationName((ushort)button.GetComponentInChildren<UIButton>().objectUserData, GetLineID(), TransportSystemDefinition.GetDefinitionForLine(GetLineID()).SubService)}</color>");
                        button.eventMouseUp += (x, y) =>
                        {
                            var stop   = (ushort)x.objectUserData;
                            var lineId = GetLineID();
                            if ((y.buttons & UIMouseButton.Right) != 0 && TransportSystemDefinition.From(lineId).CanHaveTerminals() && stop != Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].m_stops)
                            {
                                var newVal = TLMStopDataContainer.Instance.SafeGet(stop).IsTerminal;
                                TLMStopDataContainer.Instance.SafeGet(stop).IsTerminal = !newVal;
                                NetProperties properties = NetManager.instance.m_properties;
                                if (!(properties is null) && !(properties.m_drawSound is null))
                                {
                                    AudioManager.instance.DefaultGroup.AddPlayer(0, properties.m_drawSound, 1f);
                                }
                                m_dirtyTerminal = true;
                            }
                        };

                        uilabel.objectUserData = true;
                    }
                    for (int i = 0; i < 8; i++)
                    {
                        ushort segmentId = instance.m_nodes.m_buffer[currentStop].GetSegment(i);
                        if (segmentId != 0 && instance.m_segments.m_buffer[segmentId].m_startNode == currentStop)
                        {
                            currentStop = instance.m_segments.m_buffer[segmentId].m_endNode;
                            dist.text   = (instance.m_segments.m_buffer[segmentId].m_averageLength).ToString("0");
                            float segmentSize = m_unscaledMode ? m_kminStopDistance : instance.m_segments.m_buffer[segmentId].m_averageLength;
                            if (segmentSize == 0f)
                            {
                                CODebugBase <LogChannel> .Error(LogChannel.Core, "Two transport line stops have zero distance");

                                segmentSize = 100f;
                            }
                            stopPositions[idx] = segmentSize;
                            if (segmentSize < minDistance)
                            {
                                minDistance = segmentSize;
                            }
                            lineLength += stopPositions[idx];
                            break;
                        }
                    }

                    if (stopsCount > 2 && currentStop == firstStop)
                    {
                        break;
                    }
                    if (stopsCount == 2 && idx > 0)
                    {
                        break;
                    }
                    if (stopsCount == 1)
                    {
                        break;
                    }
                    if (++idx >= 32768)
                    {
                        CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                        break;
                    }
                }
                float stopDistanceFactor = m_kminStopDistance / minDistance;
                m_uILineLength = stopDistanceFactor * lineLength;
                if (m_uILineLength < m_kminUILineLength)
                {
                    m_uILineLength     = m_kminUILineLength;
                    stopDistanceFactor = m_uILineLength / lineLength;
                }
                else if (m_uILineLength > m_kmaxUILineLength)
                {
                    m_uILineLength     = m_kmaxUILineLength;
                    stopDistanceFactor = m_uILineLength / lineLength;
                }
                if (stopsCount <= 2)
                {
                    m_uILineOffset = (stopDistanceFactor * stopPositions[stopPositions.Length - 1]) - 30f;
                }
                if (m_uILineOffset < 20f || stopsCount > 2)
                {
                    m_uILineOffset = stopDistanceFactor * stopPositions[stopPositions.Length - 1] / 2f;
                }
                m_uILineLength          += 20;
                m_stopsLineSprite.height = m_uILineLength;
                m_stopsContainer.height  = m_uILineLength + m_kvehicleButtonHeight;
                Vector3 relativePosition = m_lineEnd.relativePosition;
                relativePosition.y         = m_uILineLength + 13f;
                relativePosition.x         = m_stopsLineSprite.relativePosition.x + 4f;
                m_lineEnd.relativePosition = relativePosition;
                float num8 = 0f;
                for (int j = 0; j < stopsCount; j++)
                {
                    Vector3 relativePosition2 = m_stopButtons.items[j].relativePosition;
                    relativePosition2.x = m_actualStopsX;
                    relativePosition2.y = ShiftVerticalPosition(num8);
                    m_stopButtons.items[j].relativePosition = relativePosition2;
                    num8 += stopPositions[j] * stopDistanceFactor;
                }
                RefreshVehicleButtons(lineID);
                if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None)
                {
                    m_labelLineIncomplete.isVisible = false;
                    m_stopsContainer.isVisible      = true;
                }
                else
                {
                    m_labelLineIncomplete.isVisible = true;
                    m_stopsContainer.isVisible      = false;
                }
            }
        }
コード例 #2
0
        public static void DrawCityMap()
        {
            TLMController controller  = TLMController.Instance;
            var           linesByType = new Dictionary <TransportInfo.TransportType, List <ushort> >();

            foreach (object type in Enum.GetValues(typeof(TransportInfo.TransportType)))
            {
                linesByType[(TransportInfo.TransportType)type] = new List <ushort>();
            }

            int nextStationId = 1;

            for (ushort lineId = 0; lineId < TransportManager.instance.m_lines.m_size; lineId++)
            {
                TransportLine t = TransportManager.instance.m_lines.m_buffer[lineId];

                if (t.m_lineNumber > 0 && allowedTypesToDraw.Contains(t.Info.m_transportType) && (t.m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None)
                {
                    linesByType[t.Info.m_transportType].Add(lineId);
                }
            }
            Func <Vector3, float, Vector2> calc = MapUtils.GridPosition81Tiles;
            NetManager nm           = NetManager.instance;
            float      invPrecision = 35;

            var stations       = new List <TLMMapStation>();
            var transportLines = new Dictionary <ushort, TLMMapTransportLine>();

            foreach (var tt in linesByType.OrderByDescending(x => GetRangeFromTransportType(x.Key)))
            {
                foreach (ushort lineId in tt.Value)
                {
                    ref TransportLine t     = ref TransportManager.instance.m_lines.m_buffer[lineId];
                    float             range = GetRangeFromTransportType(t.Info.m_transportType);

                    int stopsCount = t.CountStops(lineId);
                    if (stopsCount == 0)
                    {
                        continue;
                    }
                    Color color = t.m_color;
                    t.GetActive(out bool day, out bool night);
                    transportLines[lineId] = new TLMMapTransportLine(color, day, night, lineId);
                    ushort startStop = t.m_stops;
                    ushort nextStop  = startStop;
                    do
                    {
                        string name = TLMStationUtils.GetStationName(nextStop, lineId, t.Info.m_stationSubService, out ItemClass.Service service, out ItemClass.SubService nil2, out string prefix, out ushort buildingId, out NamingType namingType);

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

                        TLMMapStation idx = stations.FirstOrDefault(x => x.stopsWithWorldPos.ContainsKey(nextStop));
                        if (idx != null)
                        {
                            transportLines[lineId].AddStation(ref idx);
                        }
                        else
                        {
                            var nearStops = new Dictionary <ushort, Vector3>();
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] {
                                ItemClass.SubService.PublicTransportShip,
                                ItemClass.SubService.PublicTransportPlane,
                                ItemClass.SubService.PublicTransportTrain,
                                ItemClass.SubService.PublicTransportMonorail,
                                ItemClass.SubService.PublicTransportCableCar,
                                ItemClass.SubService.PublicTransportMetro,
                                ItemClass.SubService.PublicTransportTram,
                                ItemClass.SubService.PublicTransportBus,
                                ItemClass.SubService.PublicTransportTrolleybus
                            }, 15);
                            if (!nearStops.ContainsKey(nextStop))
                            {
                                nearStops[nextStop] = NetManager.instance.m_nodes.m_buffer[nextStop].m_position;
                            }
                            var thisStation = new TLMMapStation(name, pos2D, worldPos, nearStops, nextStationId++, service, nextStop);
                            stations.Add(thisStation);
                            transportLines[lineId].AddStation(ref thisStation);
                        }
                        nextStop = TransportLine.GetNextStop(nextStop);
                    } while (nextStop != startStop && nextStop != 0);
                }
            }
コード例 #3
0
 public static string GetFullStationName(ushort stopId, ushort lineId, ItemClass.SubService subService) =>
 stopId == 0 ? ""
         : TLMLineUtils.IsRoadLine(lineId) ? TLMStationUtils.GetFullStationName(stopId, lineId, subService)
         : TLMStationUtils.GetStationName(stopId, lineId, subService);