private void CapacityEditor_eventTextSubmitted(UIComponent x, string y) { if (m_isLoading || !int.TryParse(y.IsNullOrWhiteSpace() ? "0" : y, out int value)) { return; } var capacityEditor = x as UITextField; string assetName = x.parent.GetComponentInChildren <UICheckBox>().objectUserData.ToString(); VehicleInfo info = PrefabCollection <VehicleInfo> .FindLoaded(assetName); TransportSystemDefinition.From(info).GetTransportExtension().SetVehicleCapacity(assetName, value); m_isLoading = true; capacityEditor.text = VehicleUtils.GetCapacity(info).ToString("0"); m_isLoading = false; }
public static Dictionary <string, string> GetSelectedBasicAssetsForLine <T>(this T it, ushort lineId) where T : IAssetSelectorExtension => it.GetAssetListForLine(lineId).Intersect(it.GetBasicAssetListForLine(lineId)).ToDictionary(x => x, x => string.Format("[Cap={0}] {1}", VehicleUtils.GetCapacity(PrefabCollection <VehicleInfo> .FindLoaded(x)), Locale.Get("VEHICLE_TITLE", x)));
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; }