Esempio n. 1
0
        protected override bool SetFromProperties()
        {
            BuildingProperties buildingProperties = BuildingManager.instance.m_properties;
            NetProperties      netProperties      = NetManager.instance.m_properties;

            switch (Name)
            {
            case TextureName.UpwardRoadDiffuse:
                return(SetTexture(netProperties.m_upwardDiffuse));

            case TextureName.DownwardRoadDiffuse:
                return(SetTexture(netProperties.m_downwardDiffuse));

            case TextureName.BuildingFloorDiffuse:
                return(SetTexture(buildingProperties.m_floorDiffuse));

            case TextureName.BuildingBaseDiffuse:
                return(SetTexture(buildingProperties.m_baseDiffuse));

            case TextureName.BuildingBaseNormal:
                return(SetTexture(buildingProperties.m_baseNormal));

            case TextureName.BuildingBurntDiffuse:
                return(SetTexture(buildingProperties.m_burnedDiffuse));

            case TextureName.BuildingAbandonedDiffuse:
                return(SetTexture(buildingProperties.m_abandonedDiffuse));

            case TextureName.LightColorPalette:
                return(SetTexture(buildingProperties.m_lightColorPalette));

            default: return(false);
            }
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
0
        protected override void LoadValue()
        {
            BuildingProperties buildingProperties = BuildingManager.instance.m_properties;
            NetProperties      netProperties      = NetManager.instance.m_properties;
            Texture            oldTexture         = null;

            switch (Name)
            {
            case TextureName.UpwardRoadDiffuse:
                oldTexture = netProperties.m_upwardDiffuse;
                netProperties.m_upwardDiffuse = Texture;
                Shader.SetGlobalTexture("_RoadUpwardDiffuse", netProperties.m_upwardDiffuse);
                break;

            case TextureName.DownwardRoadDiffuse:
                oldTexture = netProperties.m_downwardDiffuse;
                netProperties.m_downwardDiffuse = Texture;
                Shader.SetGlobalTexture("_RoadDownwardDiffuse", netProperties.m_downwardDiffuse);
                break;

            case TextureName.BuildingFloorDiffuse:
                oldTexture = buildingProperties.m_floorDiffuse;
                buildingProperties.m_floorDiffuse = Texture;
                Shader.SetGlobalTexture("_BuildingFloorDiffuse", buildingProperties.m_floorDiffuse);
                break;

            case TextureName.BuildingBaseDiffuse:
                oldTexture = buildingProperties.m_baseDiffuse;
                buildingProperties.m_baseDiffuse = Texture;
                Shader.SetGlobalTexture("_BuildingBaseDiffuse", buildingProperties.m_baseDiffuse);
                break;

            case TextureName.BuildingBaseNormal:
                oldTexture = buildingProperties.m_baseNormal;
                buildingProperties.m_baseNormal = Texture;
                Shader.SetGlobalTexture("_BuildingBaseNormal", buildingProperties.m_baseNormal);
                break;

            case TextureName.BuildingBurntDiffuse:
                oldTexture = buildingProperties.m_burnedDiffuse;
                buildingProperties.m_burnedDiffuse = Texture;
                Shader.SetGlobalTexture("_BuildingBurnedDiffuse", buildingProperties.m_burnedDiffuse);
                break;

            case TextureName.BuildingAbandonedDiffuse:
                oldTexture = buildingProperties.m_abandonedDiffuse;
                buildingProperties.m_abandonedDiffuse = Texture;
                Shader.SetGlobalTexture("_BuildingAbandonedDiffuse", buildingProperties.m_abandonedDiffuse);
                break;

            case TextureName.LightColorPalette:
                oldTexture = buildingProperties.m_lightColorPalette;
                buildingProperties.m_lightColorPalette = Texture;
                Shader.SetGlobalTexture("_BuildingLightColorPalette", buildingProperties.m_lightColorPalette);
                break;
            }
            if (oldTexture != null && !ReferenceEquals(oldTexture, Texture))
            {
                Object.Destroy(oldTexture);
            }
        }