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; } } }
private void UpdateStopButtons(ushort lineID) { if (GetLineType(lineID) != LineType.WalkingTour || m_dirtyNames) { ushort stop = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_stops; foreach (UIPanel uiPanel in m_stopButtons.items) { UILabel uilabel = uiPanel.Find <UILabel>("PassengerCount"); UIButton uibutton = uiPanel.Find <UIButton>("StopButton"); if (m_dirtyNames) { uilabel.prefix = TLMStationUtils.GetFullStationName((ushort)uibutton.objectUserData, lineID, TransportSystemDefinition.GetDefinitionForLine(lineID).SubService); } if (m_dirtyTerminal) { UpdateTerminalStatus(lineID, stop, uibutton); } if (GetLineType(lineID) == LineType.WalkingTour) { continue; } UIPanel connectionPanel = uiPanel.Find <UIPanel>("ConnectionPanel"); if (connectionPanel != null) { connectionPanel.isVisible = m_currentMode == MapMode.CONNECTIONS; } switch (m_currentMode) { case MapMode.WAITING: TLMLineUtils.GetQuantityPassengerWaiting(stop, out int residents, out int tourists, out int timeTillBored); uilabel.text = "\n" + string.Format(Locale.Get("K45_TLM_WAITING_PASSENGERS_RESIDENT_TOURSTS"), residents + tourists, residents, tourists) + "\n"; uibutton.color = Color.Lerp(Color.red, Color.white, timeTillBored / 255f); uilabel.suffix = string.Format(Locale.Get("K45_TLM_TIME_TILL_BORED_TEMPLATE_STATION_MAP"), uibutton.color.ToRGB(), timeTillBored); break; case MapMode.NONE: uibutton.color = Color.white; uilabel.text = ""; uilabel.suffix = ""; uibutton.tooltip = ""; break; case MapMode.CONNECTIONS: uibutton.color = Color.white; uilabel.text = ""; uilabel.suffix = ""; uibutton.tooltip = ""; break; case MapMode.EARNINGS_ALL_TIME: TLMTransportLineStatusesManager.instance.GetStopIncome(stop, out long income); PrintIncomeStop(lineID, uibutton, uilabel, income); break; case MapMode.EARNINGS_CURRENT_WEEK: TLMTransportLineStatusesManager.instance.GetCurrentStopIncome(stop, out long income2); PrintIncomeStop(lineID, uibutton, uilabel, income2); break; case MapMode.EARNINGS_LAST_WEEK: TLMTransportLineStatusesManager.instance.GetLastWeekStopIncome(stop, out long income3); PrintIncomeStop(lineID, uibutton, uilabel, income3); break; } stop = TransportLine.GetNextStop(stop); } m_dirtyNames = false; m_dirtyTerminal = false; } }
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);