private void CreateTsdTabstrip() { UIButton tabTemplate = CreateTabSubStripTemplate(); UIComponent bodyContent = CreateContentTemplate(m_stripMain.tabContainer.width, m_stripMain.tabContainer.height, false); foreach (KeyValuePair <TransportSystemDefinition, Func <ITLMSysDef> > kv in TransportSystemDefinition.SysDefinitions) { Type[] components; Type targetType; try { targetType = ReflectionUtils.GetImplementationForGenericType(typeof(UVMLinesPanel <>), kv.Value().GetType()); components = new Type[] { targetType }; } catch { continue; } TransportSystemDefinition tsd = kv.Key; GameObject tab = Instantiate(tabTemplate.gameObject); GameObject body = Instantiate(bodyContent.gameObject); var configIdx = kv.Key.ToConfigIndex(); string name = kv.Value().GetType().Name; TLMUtils.doLog($"configIdx = {configIdx};kv.Key = {kv.Key}; kv.Value= {kv.Value} "); string bgIcon = KlyteResourceLoader.GetDefaultSpriteNameFor(TLMUtils.GetLineIcon(0, configIdx, ref tsd), true); string fgIcon = kv.Key.GetTransportTypeIcon(); UIButton tabButton = tab.GetComponent <UIButton>(); tabButton.tooltip = TLMConfigWarehouse.getNameForTransportType(configIdx); 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, components); } }
private void Awake() { parent = GetComponentInChildren <UIScrollablePanel>(); int parentWidth = 730; KlyteMonoUtils.CreateUIElement(out UITabstrip strip, parent.transform, "TLMTabstrip", new Vector4(5, 0, parentWidth - 10, 40)); float effectiveOffsetY = strip.height; KlyteMonoUtils.CreateUIElement(out UITabContainer tabContainer, parent.transform, "TLMTabContainer", new Vector4(0, 40, parentWidth - 10, 320)); tabContainer.autoSize = true; strip.tabPages = tabContainer; UIButton tabTemplate = CreateTabSubStripTemplate(); UIComponent bodyContent = CreateContentTemplate(parentWidth, 320, false); foreach (System.Collections.Generic.KeyValuePair <TransportSystemDefinition, Func <ITLMSysDef> > kv in TransportSystemDefinition.SysDefinitions) { Type[] components; Type targetType; try { targetType = ReflectionUtils.GetImplementationForGenericType(typeof(TLMShowConfigTab <>), kv.Value().GetType()); components = new Type[] { targetType }; } catch { continue; } GameObject tab = Instantiate(tabTemplate.gameObject); GameObject body = Instantiate(bodyContent.gameObject); var configIdx = kv.Key.ToConfigIndex(); TransportSystemDefinition tsd = kv.Key; string name = kv.Value().GetType().Name; TLMUtils.doLog($"configIdx = {configIdx};kv.Key = {kv.Key}; kv.Value= {kv.Value} "); string bgIcon = KlyteResourceLoader.GetDefaultSpriteNameFor(TLMUtils.GetLineIcon(0, configIdx, ref tsd), true); string fgIcon = kv.Key.GetTransportTypeIcon(); UIButton tabButton = tab.GetComponent <UIButton>(); tabButton.tooltip = TLMConfigWarehouse.getNameForTransportType(configIdx); 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.white; 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; } strip.AddTab(name, tab, body, components); } strip.selectedIndex = -1; strip.selectedIndex = 0; }