Esempio n. 1
0
        public TLMMapTransportLine(Color32 color, bool day, bool night, ushort lineId)
        {
            TransportLine t = Singleton <TransportManager> .instance.m_lines.m_buffer[lineId];

            lineName = Singleton <TransportManager> .instance.GetLineName(lineId);

            lineStringIdentifier = TLMLineUtils.GetLineStringId(lineId);
            TransportType        = t.Info.m_transportType;
            subservice           = t.Info.GetSubService();
            vehicleType          = t.Info.m_vehicleType;
            stations             = new List <TLMMapStation>();
            lineColor            = color;
            activeDay            = day;
            activeNight          = night;
            this.lineId          = lineId;
            lineNumber           = t.m_lineNumber;
        }
        public void OnSetTarget(Type source)
        {
            if (source == GetType())
            {
                return;
            }

            TransportSystemDefinition tsd = TransportSystem;

            if (!tsd.HasVehicles())
            {
                MainPanel.isVisible = false;
                return;
            }
            m_isLoading = true;
            LogUtils.DoLog("tsd = {0}", tsd);
            IBasicExtension config = TLMLineUtils.GetEffectiveExtensionForLine(GetLineID());

            if (TransportSystem != m_lastSystem)
            {
                m_defaultAssets = tsd.GetTransportExtension().GetAllBasicAssetsForLine(0);
                UIPanel[] depotChecks = m_checkboxTemplateList.SetItemCount(m_defaultAssets.Count);

                LogUtils.DoLog("m_defaultAssets Size = {0} ({1})", m_defaultAssets?.Count, string.Join(",", m_defaultAssets.Keys?.ToArray() ?? new string[0]));
                for (int i = 0; i < m_defaultAssets.Count; i++)
                {
                    string     assetName = m_defaultAssets.Keys.ElementAt(i);
                    UICheckBox checkbox  = depotChecks[i].GetComponentInChildren <UICheckBox>();
                    checkbox.objectUserData = assetName;
                    UITextField capacityEditor = depotChecks[i].GetComponentInChildren <UITextField>();
                    capacityEditor.text = VehicleUtils.GetCapacity(PrefabCollection <VehicleInfo> .FindLoaded(assetName)).ToString("0");
                    if (checkbox.label.objectUserData == null)
                    {
                        checkbox.eventCheckChanged += (x, y) =>
                        {
                            if (m_isLoading)
                            {
                                return;
                            }

                            ushort          lineId    = GetLineID();
                            IBasicExtension extension = TLMLineUtils.GetEffectiveExtensionForLine(lineId);

                            LogUtils.DoLog($"checkbox event: {x.objectUserData} => {y} at {extension}[{lineId}]");
                            if (y)
                            {
                                extension.AddAssetToLine(lineId, x.objectUserData.ToString());
                            }
                            else
                            {
                                extension.RemoveAssetFromLine(lineId, x.objectUserData.ToString());
                            }
                        };
                        CreateModelCheckBox(checkbox);
                        KlyteMonoUtils.LimitWidthAndBox(checkbox.label, 280);
                        capacityEditor.eventTextSubmitted += CapacityEditor_eventTextSubmitted;;

                        capacityEditor.eventMouseEnter += (x, y) =>
                        {
                            m_lastInfo = PrefabCollection <VehicleInfo> .FindLoaded(checkbox.objectUserData.ToString());

                            RedrawModel();
                        };
                        checkbox.label.objectUserData = true;
                    }
                    checkbox.text = m_defaultAssets[assetName];
                }
                m_lastSystem = TransportSystem;
            }
            else
            {
                List <string> allowedAssets = config.GetAssetListForLine(GetLineID());
                for (int i = 0; i < m_checkboxTemplateList.items.Count; i++)
                {
                    UICheckBox checkbox = m_checkboxTemplateList.items[i].GetComponentInChildren <UICheckBox>();
                    checkbox.isChecked = allowedAssets.Contains(checkbox.objectUserData.ToString());
                }
            }

            if (TransportLinesManagerMod.DebugMode)
            {
                List <string> allowedAssets = config.GetAssetListForLine(GetLineID());
                LogUtils.DoLog($"selectedAssets Size = {allowedAssets?.Count} ({ string.Join(",", allowedAssets?.ToArray() ?? new string[0])}) {config?.GetType()}");
            }

            if (config is TLMTransportLineConfiguration)
            {
                m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE"), TLMLineUtils.GetLineStringId(GetLineID()));
            }
            else
            {
                int prefix = (int)TLMPrefixesUtils.GetPrefix(GetLineID());
                m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? NumberingUtils.GetStringFromNumber(TLMPrefixesUtils.GetStringOptionsForPrefix(tsd), prefix + 1) : Locale.Get("K45_TLM_UNPREFIXED"), tsd.GetTransportName());
            }

            m_isLoading = false;
        }