public override void OnLevelLoaded(LoadMode mode) { // do base processing base.OnLevelLoaded(mode); try { // check for new or loaded game if (mode == LoadMode.NewGame || mode == LoadMode.NewGameFromScenario || mode == LoadMode.LoadGame) { // get the PopulationInfoViewPanel panel (displayed when the user clicks on the Population info view button) PopulationInfoViewPanel populationPanel = UIView.library.Get <PopulationInfoViewPanel>(typeof(PopulationInfoViewPanel).Name); if (populationPanel == null) { Debug.LogError("Unable to find PopulationInfoViewPanel."); return; } // create a new PopulationDemographicsPanel which will eventually trigger the panel's Start method panel = populationPanel.component.AddUIComponent <PopulationDemographicsPanel>(); if (panel == null) { Debug.LogError("Unable to create Population Demographics panel on PopulationInfoViewPanel."); return; } // create button to show the panel _demographics = populationPanel.component.AddUIComponent <UIButton>(); if (_demographics == null) { Debug.LogError("Unable to create Demographics button on PopulationInfoViewPanel."); return; } _demographics.name = "Demographics"; _demographics.text = "Demographics"; _demographics.textScale = 0.75f; _demographics.horizontalAlignment = UIHorizontalAlignment.Center; _demographics.textVerticalAlignment = UIVerticalAlignment.Middle; _demographics.autoSize = false; _demographics.size = new Vector2(120f, 20f); _demographics.relativePosition = new Vector3(220f, 290f); _demographics.normalBgSprite = "ButtonMenu"; _demographics.hoveredBgSprite = "ButtonMenuHovered"; _demographics.pressedBgSprite = "ButtonMenuPressed"; _demographics.isVisible = true; _demographics.eventClicked += Demographics_eventClicked; // create Harmony patches HarmonyPatcher.CreatePatches(); } } catch (Exception ex) { Debug.LogException(ex); } }
/// <summary> /// Start is called after the panel is created in Loading /// set up and populate the panel /// </summary> public override void Start() { // do base processing base.Start(); try { // set panel properties name = "PopulationDemographicsPanel"; backgroundSprite = "MenuPanel2"; canFocus = true; opacity = 1f; height = 300; isVisible = true; // get the PopulationInfoViewPanel panel (displayed when the user clicks on the Population info view button) PopulationInfoViewPanel populationPanel = UIView.library.Get<PopulationInfoViewPanel>(typeof(PopulationInfoViewPanel).Name); if (populationPanel == null) { Debug.LogError("Unable to find PopulationInfoViewPanel."); return; } // place panel to the right of PopulationInfoViewPanel relativePosition = new Vector3(populationPanel.component.size.x - 1f, 0f); // copy text font from the Population label UILabel populationLabel = populationPanel.Find<UILabel>("Population"); if (populationLabel == null) { Debug.LogError("Unable to find Population label on PopulationInfoViewPanel."); return; } _textFont = populationLabel.font; // create heading row float top = 45f; if (!CreateDataRow(top, "Heading", "", out _heading)) return; // adjust heading properties _heading.eduLevel0.text = "Unedu"; _heading.eduLevel1.text = "Educated"; _heading.eduLevel2.text = "Well Edu"; _heading.eduLevel3.text = "High Edu"; _heading.total.text = "Total"; _heading.deceased.text = "Deceased"; _heading.movingIn.text = "MovingIn"; _heading.eduLevel0.tooltip = "Uneducated - Elementary School not completed"; _heading.eduLevel1.tooltip = "Educated - completed Elementary School"; _heading.eduLevel2.tooltip = "Well Educated - completed High School"; _heading.eduLevel3.tooltip = "Highly Educated - completed University"; _heading.eduLevel0.textScale = _heading.eduLevel1.textScale = _heading.eduLevel2.textScale = _heading.eduLevel3.textScale = _heading.total.textScale = _heading.deceased.textScale = _heading.movingIn.textScale = 0.75f; _heading.eduLevel0.textColor = _heading.eduLevel1.textColor = _heading.eduLevel2.textColor = _heading.eduLevel3.textColor = _heading.total.textColor = _heading.deceased.textColor = _heading.movingIn.textColor = HeadingTextColor; // create lines after headings top += 15f; CreateLines(top, "Heading"); // create data rows top += 4f; if (!CreateDataRow(top, "Children", "Children", out _children)) return; top += 15f; if (!CreateDataRow(top, "Teens", "Teens", out _teens )) return; top += 15f; if (!CreateDataRow(top, "Young", "Young Adults", out _youngs )) return; top += 15f; if (!CreateDataRow(top, "Adults", "Adults", out _adults )) return; top += 15f; if (!CreateDataRow(top, "Seniors", "Seniors", out _seniors )) return; top += 15f; // create total data row CreateLines(top, "Totals"); top += 4f; if (!CreateDataRow(top, "Total", "Total", out _total)) return; top += 15f; // create other data rows top += 12f; if (!CreateDataRow(top, "MovingIn", "Moving In", out _movingIn)) return; top += 15f; if (!CreateDataRow(top, "Deceased", "Deceased", out _deceased)) return; top += 15f; // hide duplicates for moving in and deceased _movingIn.movingIn.isVisible = false; _movingIn.deceased.isVisible = false; _deceased.movingIn.isVisible = false; _deceased.deceased.isVisible = false; // set panel width and height according to the labels width = _children.deceased.relativePosition.x + _children.deceased.size.x + _children.description.relativePosition.x; height = _deceased.deceased.relativePosition.y + _deceased.deceased.size.y + 5f; // create the title label UILabel title = AddUIComponent<UILabel>(); if (title == null) { Debug.LogError($"Unable to create title label on panel [{name}]."); return; } title.name = "Title"; title.font = _textFont; title.text = "Demographics"; title.textAlignment = UIHorizontalAlignment.Center; title.textScale = 1f; title.textColor = new Color32(254, 254, 254, 255); title.autoSize = false; title.size = new Vector2(width, 18f); title.relativePosition = new Vector3(0f, 11f); title.isVisible = true; // create population icon in upper left UISprite panelIcon = AddUIComponent<UISprite>(); if (panelIcon == null) { Debug.LogError($"Unable to create population icon on panel [{name}]."); return; } panelIcon.name = "PopulationIcon"; panelIcon.autoSize = false; panelIcon.size = new Vector2(36f, 36f); panelIcon.relativePosition = new Vector3(10f, 2f); panelIcon.spriteName = "InfoIconPopulationPressed"; panelIcon.isVisible = true; // create close button _closeButton = AddUIComponent<UIButton>(); if (_closeButton == null) { Debug.LogError($"Unable to create close button on panel [{name}]."); return; } _closeButton.name = "CloseButton"; _closeButton.autoSize = false; _closeButton.size = new Vector2(32f, 32f); _closeButton.relativePosition = new Vector3(width - 34f, 2f); _closeButton.normalBgSprite = "buttonclose"; _closeButton.hoveredBgSprite = "buttonclosehover"; _closeButton.pressedBgSprite = "buttonclosepressed"; _closeButton.isVisible = true; _closeButton.eventClicked += CloseButton_eventClicked; // create count/percent panels CreateCountPercentPanel(_movingIn.description.relativePosition.y, "CountOption", "Count", out _countPanel, out _countCheckBox); CreateCountPercentPanel(_deceased.description.relativePosition.y, "PercentOption", "Percent", out _percentPanel, out _percentCheckBox); SetCheckBox(_countCheckBox, true); // make sure manager exists if (!Singleton<BuildingManager>.exists) { Debug.LogError($"BuildingManager not ready during panel initialization."); return; } // initialize population counts, do each building Building[] buffer = Singleton<BuildingManager>.instance.m_buildings.m_buffer; for (ushort buildingID = 1; buildingID < buffer.Length; buildingID++) { // do only buildings that have a valid index if (buffer[buildingID].m_infoIndex != 0) { // check if building AI derives from ResidentialBuildingAI // PloppableRICO.GrowableResidentialAI and PloppableRICO.PloppableResidentialAI derive from ResidentialBuildingAI bool isResidentialBuildingAI = false; if (buffer[buildingID].Info != null && buffer[buildingID].Info.m_buildingAI != null) { Type type = buffer[buildingID].Info.m_buildingAI.GetType(); while (type != null) { if (type == typeof(ResidentialBuildingAI)) { isResidentialBuildingAI = true; break; } type = type.BaseType; } } // if derives from ResidentialBuildingAI, then do logic for ResidentialBuildingAI.SimulationStepActive if (isResidentialBuildingAI) { ResidentialSimulationStepActive(buildingID, ref buffer[buildingID], false); } } } // now do logic for District.SimulationStep DistrictSimulationStep(0, false); } catch (Exception ex) { Debug.LogException(ex); } }