private void OnBuildingChange(ushort buildingId)
        {
            SVMUtils.doLog("EventOnBuildingSelChanged");
            m_isLoading = true;
            IEnumerable <ServiceSystemDefinition> ssds = ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingId].Info);

            if (!ssds.Contains(Singleton <T> .instance.GetSSD()))
            {
                m_mainPanel.isVisible = false;
                return;
            }
            m_mainPanel.isVisible = true;
            var ssd = Singleton <T> .instance.GetSSD();

            var  ext            = ssd.GetTransportExtension();
            bool isCustomConfig = ext.GetIgnoreDistrict(buildingId);

            SVMUtils.doLog("ssd = {0}", ssd);

            List <string> selectedAssets;
            Color         selectedColor;

            if (isCustomConfig)
            {
                selectedAssets = ext.GetAssetListBuilding(buildingId);
                selectedColor  = ext.GetColorBuilding(buildingId);
            }
            else
            {
                var districtId = SVMUtils.GetBuildingDistrict(buildingId);
                selectedAssets = ext.GetAssetListDistrict(districtId);
                selectedColor  = ext.GetColorDistrict(districtId);
            }
            foreach (var i in m_checkboxes.Keys)
            {
                m_checkboxes[i].isChecked = selectedAssets.Contains(i);
            }
            if (m_color != null)
            {
                m_color.selectedColor = selectedColor;
            }

            if (isCustomConfig)
            {
                m_title.text = string.Format(Locale.Get("SVM_ASSET_SELECT_WINDOW_TITLE"), Singleton <BuildingManager> .instance.GetBuildingName(buildingId, default(InstanceID)), SVMConfigWarehouse.getNameForServiceSystem(ssd.toConfigIndex()));
            }
            else
            {
                var districtId = SVMUtils.GetBuildingDistrict(buildingId);
                if (districtId > 0)
                {
                    m_title.text = string.Format(Locale.Get("SVM_ASSET_SELECT_WINDOW_TITLE_DISTRICT"), Singleton <DistrictManager> .instance.GetDistrictName(SVMUtils.GetBuildingDistrict(buildingId)), SVMConfigWarehouse.getNameForServiceSystem(ssd.toConfigIndex()));
                }
                else
                {
                    m_title.text = string.Format(Locale.Get("SVM_ASSET_SELECT_WINDOW_TITLE_CITY"), SVMConfigWarehouse.getNameForServiceSystem(ssd.toConfigIndex()));
                }
            }

            m_isLoading = false;
            m_previewPanel.isVisible = false;
        }
Example #2
0
        private void CreateSsdTabstrip(ref UITabstrip strip, ref Dictionary <CategoryTab, UITabstrip> substrips, UIPanel titleLine, UIComponent parent, bool buildings = false)
        {
            SVMUtils.createUIElement(out strip, parent.transform, "SVMTabstrip", new Vector4(5, 0, parent.width - 10, 40));

            var effectiveOffsetY = strip.height + (titleLine?.height ?? 0);

            SVMUtils.createUIElement(out UITabContainer tabContainer, parent.transform, "SVMTabContainer", new Vector4(0, 40, parent.width, parent.height - 40));
            strip.tabPages = tabContainer;

            UIButton tabTemplate = CreateTabTemplate();

            UIComponent bodyContent = CreateContentTemplate(parent.width - 10, parent.height - effectiveOffsetY - 50);

            SVMUtils.createUIElement(out UIPanel bodySuper, null);
            bodySuper.name = "Container";
            bodySuper.area = new Vector4(0, 40, parent.width, parent.height - 50);

            Dictionary <CategoryTab, UIComponent> tabsCategories = new Dictionary <CategoryTab, UIComponent>();

            foreach (var catTab in Enum.GetValues(typeof(CategoryTab)).Cast <CategoryTab>())
            {
                GameObject tabCategory     = Instantiate(tabTemplate.gameObject);
                GameObject contentCategory = Instantiate(bodySuper.gameObject);
                UIButton   tabButtonSuper  = tabCategory.GetComponent <UIButton>();
                tabButtonSuper.tooltip           = catTab.getCategoryName();
                tabButtonSuper.normalFgSprite    = catTab.getCategoryIcon();
                tabsCategories[catTab]           = strip.AddTab(catTab.ToString(), tabCategory, contentCategory);
                tabsCategories[catTab].isVisible = false;
                SVMUtils.createUIElement(out UITabstrip subStrip, contentCategory.transform, "SVMTabstripCat" + catTab, new Vector4(5, 0, bodySuper.width - 10, 40));
                SVMUtils.createUIElement(out UITabContainer tabSubContainer, contentCategory.transform, "SVMTabContainer" + catTab, new Vector4(5, effectiveOffsetY, bodySuper.width - 10, bodySuper.height - effectiveOffsetY));
                subStrip.tabPages = tabSubContainer;
                substrips[catTab] = subStrip;
            }
            foreach (var kv in ServiceSystemDefinition.sysDefinitions)
            {
                GameObject tab       = Instantiate(tabTemplate.gameObject);
                GameObject body      = Instantiate(bodyContent.gameObject);
                var        configIdx = kv.Key.toConfigIndex();
                String     name      = kv.Value.Name;
                SVMUtils.doLog($"configIdx = {configIdx};kv.Key = {kv.Key}; kv.Value= {kv.Value} ");
                String   bgIcon    = SVMConfigWarehouse.getIconServiceSystem(configIdx);
                String   fgIcon    = SVMConfigWarehouse.getFgIconServiceSystem(configIdx);
                UIButton tabButton = tab.GetComponent <UIButton>();
                tabButton.tooltip        = SVMConfigWarehouse.getNameForServiceSystem(configIdx);
                tabButton.normalFgSprite = bgIcon;
                if (!string.IsNullOrEmpty(fgIcon))
                {
                    SVMUtils.createUIElement(out UISprite sprite, tabButton.transform, "OverSprite", new Vector4(0, 0, 40, 40));
                    sprite.spriteName = fgIcon;
                    sprite.atlas      = SVMController.taSVM;
                }
                Type[] components;
                Type   targetType;
                if (buildings)
                {
                    targetType = KlyteUtils.GetImplementationForGenericType(typeof(SVMTabControllerBuildingList <>), kv.Value);
                    components = new Type[] { targetType };
                }
                else
                {
                    try
                    {
                        targetType = KlyteUtils.GetImplementationForGenericType(typeof(SVMTabControllerDistrictList <>), kv.Value);
                        components = new Type[] { targetType };
                    }
                    catch
                    {
                        continue;
                    }
                }
                CategoryTab catTab = SVMConfigWarehouse.getCategory(configIdx);
                substrips[catTab].AddTab(name, tab, body, components);

                body.GetComponent <UIComponent>().eventVisibilityChanged += (x, y) =>
                {
                    if (y)
                    {
                        m_directionLabel.isVisible = kv.Key.outsideConnection;
                    }
                };
                tabsCategories[catTab].isVisible = true;
            }
        }