public MapTransportLine(Color32 color, bool day, bool night, ushort lineId) { TransportLine t = Singleton <TransportManager> .instance.m_lines.m_buffer[lineId]; this.lineName = Singleton <TransportManager> .instance.GetLineName(lineId); this.lineStringIdentifier = TLMLineUtils.getLineStringId(lineId); transportType = t.Info.m_transportType; stations = new List <Station>(); lineColor = color; activeDay = day; activeNight = night; this.lineId = lineId; }
private void BindParentChanges() { m_lineInfo.EventOnLineChanged += (lineId) => { TLMUtils.doLog("EventOnLineChanged"); m_isLoading = true; bool isCustomLine = TLMTransportLineExtension.instance.GetUseCustomConfig(lineId); TransportSystemDefinition tsd = TransportSystemDefinition.from(lineId); TLMUtils.doLog("tsd = {0}", tsd); if (m_lastDef != tsd) { foreach (var i in m_checkboxes.Keys) { UnityEngine.Object.Destroy(m_checkboxes[i].gameObject); } m_defaultAssets = tsd.GetTransportExtension().GetAllBasicAssets(0); m_checkboxes = new Dictionary <string, UICheckBox>(); TLMUtils.doLog("m_defaultAssets Size = {0} ({1})", m_defaultAssets?.Count, string.Join(",", m_defaultAssets.Keys?.ToArray() ?? new string[0])); foreach (var i in m_defaultAssets.Keys) { var checkbox = (UICheckBox)m_uiHelper.AddCheckbox(m_defaultAssets[i], false, (x) => { ushort lineIdx = m_lineInfo.CurrentSelectedId; if (m_isLoading) { return; } if (x) { if (TLMTransportLineExtension.instance.GetUseCustomConfig(lineIdx)) { TLMTransportLineExtension.instance.AddAsset(lineIdx, i); } else { tsd.GetTransportExtension().AddAsset(TLMLineUtils.getPrefix(lineIdx), i); } } else { if (TLMTransportLineExtension.instance.GetUseCustomConfig(lineIdx)) { TLMTransportLineExtension.instance.RemoveAsset(lineIdx, i); } else { tsd.GetTransportExtension().RemoveAsset(TLMLineUtils.getPrefix(lineIdx), i); } } }); CreateModelCheckBox(i, checkbox); checkbox.label.tooltip = checkbox.label.text; checkbox.label.textScale = 0.9f; checkbox.label.transform.localScale = new Vector3(Math.Min((m_mainPanel.width - 50) / checkbox.label.width, 1), 1); m_checkboxes[i] = checkbox; } } m_lastDef = tsd; List <string> selectedAssets; if (isCustomLine) { selectedAssets = TLMTransportLineExtension.instance.GetAssetList(lineId); } else { selectedAssets = tsd.GetTransportExtension().GetAssetList(TLMLineUtils.getPrefix(lineId)); } TLMUtils.doLog("selectedAssets Size = {0} ({1})", selectedAssets?.Count, string.Join(",", selectedAssets?.ToArray() ?? new string[0])); foreach (var i in m_checkboxes.Keys) { m_checkboxes[i].isChecked = selectedAssets.Contains(i); } if (isCustomLine) { m_title.text = string.Format(Locale.Get("TLM_ASSET_SELECT_WINDOW_TITLE"), TLMLineUtils.getLineStringId(lineId), TLMConfigWarehouse.getNameForTransportType(tsd.toConfigIndex())); } else { TLMConfigWarehouse.ConfigIndex transportType = tsd.toConfigIndex(); ModoNomenclatura mnPrefixo = (ModoNomenclatura)TLMConfigWarehouse.getCurrentConfigInt(TLMConfigWarehouse.ConfigIndex.PREFIX | transportType); var prefix = TLMLineUtils.getPrefix(lineId); m_title.text = string.Format(Locale.Get("TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? TLMUtils.getStringFromNumber(TLMUtils.getStringOptionsForPrefix(mnPrefixo), (int)prefix + 1) : Locale.Get("TLM_UNPREFIXED"), TLMConfigWarehouse.getNameForTransportType(tsd.toConfigIndex())); } m_isLoading = false; m_previewPanel.isVisible = false; }; }
public void OnSetTarget(Type source) { if (source == GetType()) { return; } TransportSystemDefinition tsd = TransportSystem; if (!tsd.HasVehicles()) { MainPanel.isVisible = false; return; } m_isLoading = true; TLMUtils.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); TLMUtils.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); TLMUtils.doErrorLog($"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()); TLMUtils.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)TLMLineUtils.getPrefix(GetLineID()); m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? NumberingUtils.GetStringFromNumber(TLMUtils.GetStringOptionsForPrefix(tsd), prefix + 1) : Locale.Get("K45_TLM_UNPREFIXED"), TLMConfigWarehouse.getNameForTransportType(tsd.ToConfigIndex())); } m_isLoading = false; }