private void CreateTsdTabstrip() { UIButton tabTemplate = CreateTabSubStripTemplate(); UIComponent bodyContent = CreateContentTemplate(m_stripMain.tabContainer.width, m_stripMain.tabContainer.height, false); foreach (var targetType in ReflectionUtils.GetSubtypesRecursive(typeof(UVMLinesPanel), GetType())) { TransportSystemDefinition tsd = (targetType.GetConstructor(new Type[0]).Invoke(null) as UVMLinesPanel).TSD; GameObject tab = Instantiate(tabTemplate.gameObject); GameObject body = Instantiate(bodyContent.gameObject); string name = tsd.GetTransportName(); string bgIcon = KlyteResourceLoader.GetDefaultSpriteNameFor(TLMPrefixesUtils.GetLineIcon(0, tsd), true); string fgIcon = tsd.GetTransportTypeIcon(); UIButton tabButton = tab.GetComponent <UIButton>(); tabButton.tooltip = name; tabButton.hoveredBgSprite = bgIcon; tabButton.focusedBgSprite = bgIcon; tabButton.normalBgSprite = bgIcon; tabButton.disabledBgSprite = bgIcon; tabButton.focusedColor = Color.green; tabButton.hoveredColor = new Color(0, 0.5f, 0f); tabButton.color = Color.black; tabButton.disabledColor = Color.gray; if (!string.IsNullOrEmpty(fgIcon)) { KlyteMonoUtils.CreateUIElement(out UIButton secSprite, tabButton.transform, "OverSprite", new Vector4(5, 5, 30, 30)); secSprite.normalFgSprite = fgIcon; secSprite.foregroundSpriteMode = UIForegroundSpriteMode.Scale; secSprite.isInteractive = false; secSprite.disabledColor = Color.black; } m_stripMain.AddTab(name, tab, body, new Type[] { targetType }); } }
public uint LineToIndex(ushort lineId) => TLMPrefixesUtils.GetPrefix(lineId);
public bool MayBeVisible() => TLMPrefixesUtils.HasPrefix(GetLineID()) && !TLMTransportLineExtension.Instance.IsUsingCustomConfig(GetLineID());
public void OnSetTarget(Type source) { if (source == GetType()) { return; } m_isLoading = true; uint sel = SelectedPrefix; m_prefixColor.selectedColor = Extension.GetColor(sel); m_useColorForModel.isChecked = Extension.IsUsingColorForModel(sel); m_prefixName.text = Extension.GetName(sel) ?? ""; m_paletteDD.selectedIndex = Math.Max(0, m_paletteDD.items.ToList().IndexOf(Extension.GetCustomPalette(sel))); m_formatDD.selectedIndex = Math.Max(0, (int)Extension.GetCustomFormat(sel)); m_title.text = string.Format(Locale.Get("K45_TLM_PREFIX_TAB_WIP_TITLE"), sel > 0 ? NumberingUtils.GetStringFromNumber(TLMPrefixesUtils.GetStringOptionsForPrefix(TransportSystem), (int)sel + 1) : Locale.Get("K45_TLM_UNPREFIXED"), TransportSystem.GetTransportName()); m_isLoading = false; }
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; }
public void OnSetTarget(Type source) { ushort lineID = UVMPublicTransportWorldInfoPanel.GetLineID(); m_firstStopSelect.items = TLMLineUtils.GetAllStopsFromLine(lineID); m_firstStopSelect.selectedIndex = 0; if (source == GetType()) { return; } if (lineID != 0) { m_colorField.selectedColor = Singleton <TransportManager> .instance.GetLineColor(lineID); LineType lineType = UVMPublicTransportWorldInfoPanel.GetLineType(lineID); m_weeklyPassengersString = ((lineType != LineType.WalkingTour) ? "TRANSPORT_LINE_PASSENGERS" : "TRANSPORT_LINE_PASSENGERS_WALKINGTOUR"); m_ageChart.tooltipLocaleID = ((lineType != LineType.WalkingTour) ? "PUBLICTRANSPORT_PASSENGERAGEGROUPS_TOOLTIP" : "PUBLICTRANSPORT_PASSENGERAGEGROUPS_TOOLTIP_WALKINGTOUR"); m_tripSaved.isVisible = (lineType == LineType.Default); m_pullValuePanel.isVisible = (lineType == LineType.WalkingTour); m_lineLengthLabel.text = StringUtils.SafeFormat(Locale.Get("LINEINFOPANEL_LINELENGTH"), (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_totalLength / 1000f).ToString("F2", LocaleManager.cultureInfo)); m_linePrefixDropDown.eventSelectedIndexChanged -= SaveLineNumber; m_lineNumberLabel.eventLostFocus -= SaveLineNumber; m_customLineCodeInput.eventTextSubmitted -= SaveLineCode; ref TransportLine t = ref TransportManager.instance.m_lines.m_buffer[lineID]; ushort lineNumber = t.m_lineNumber; var tsd = TransportSystemDefinition.GetDefinitionForLine(lineID); var config = tsd.GetConfig(); var mnPrefixo = config.Prefix; if (TLMPrefixesUtils.HasPrefix(lineID)) { m_lineNumberLabel.maxLength = 3; m_lineNumberLabel.width = 40; m_lineNumberLabel.text = (lineNumber % 1000).ToString(); m_linePrefixDropDown.enabled = false; string[] temp = TLMPrefixesUtils.GetStringOptionsForPrefix(tsd, true, true, false); m_linePrefixDropDown.items = temp; m_linePrefixDropDown.selectedIndex = lineNumber / 1000; m_linePrefixDropDown.enabled = true; bool invertPrefixSuffix = config.InvertPrefixSuffix; if (invertPrefixSuffix) { m_linePrefixDropDown.zOrder = 9999; } else { m_lineNumberLabel.zOrder = 9999; } } else { m_lineNumberLabel.maxLength = 4; m_lineNumberLabel.width = 180; m_lineNumberLabel.text = (lineNumber).ToString(); m_linePrefixDropDown.enabled = false; } m_lineNumberLabel.color = TransportManager.instance.GetLineColor(lineID); m_customLineCodeInput.text = TLMTransportLineExtension.Instance.SafeGet(lineID).CustomCode ?? ""; m_linePrefixDropDown.eventSelectedIndexChanged += SaveLineNumber; m_lineNumberLabel.eventLostFocus += SaveLineNumber; m_customLineCodeInput.eventTextSubmitted += SaveLineCode; }