/// <summary> /// Adds an input text field at the specified coordinates. /// </summary> /// <param name="textField">Textfield object</param> /// <param name="panel">panel to add to</param> /// <param name="posX">Relative X postion</param> /// <param name="posY">Relative Y position</param> /// <param name="tooltip">Tooltip, if any</param> protected UITextField AddTextField(UIPanel panel, float width, float posX, float posY, string tooltip = null) { UITextField textField = UIControls.SmallTextField(panel, posX, posY, width); textField.eventTextChanged += (control, value) => PanelUtils.IntTextFilter((UITextField)control, value); // Add tooltip. if (tooltip != null) { textField.tooltip = tooltip; } return(textField); }
/// <summary> /// Adds editing options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> internal PopulationPanel(UITabstrip tabStrip, int tabIndex) : base(tabStrip, tabIndex) { // Add title. float currentY = PanelUtils.TitleLabel(panel, TabTooltipKey); // Initialise arrays emptyAreaFields = new UITextField[5]; emptyPercentFields = new UITextField[5]; fixedPopChecks = new UICheckBox[5]; fixedPopFields = new UITextField[5]; areaPerFields = new UITextField[5]; multiFloorChecks = new UICheckBox[5]; rowLabels = new UILabel[5]; // Service selection dropdown. serviceDropDown = UIControls.AddPlainDropDown(panel, Translations.Translate("RPR_OPT_SVC"), serviceNames, -1); serviceDropDown.parent.relativePosition = new Vector3(20f, currentY); serviceDropDown.eventSelectedIndexChanged += ServiceChanged; // Pack selection dropdown. packDropDown = UIControls.AddPlainDropDown(panel, Translations.Translate("RPR_OPT_CPK"), new string[0], -1); currentY += 70f; packDropDown.parent.relativePosition = new Vector3(20f, currentY); packDropDown.eventSelectedIndexChanged += PackChanged; // Label strings - cached to avoid calling Translations.Translate each time (for the tooltips, anwyay, including the others makes code more readable). string emptyArea = Translations.Translate("RPR_CAL_VOL_EMP"); string emptyAreaTip = Translations.Translate("RPR_CAL_VOL_EMP_TIP"); string emptyPercent = Translations.Translate("RPR_CAL_VOL_EPC"); string emptyPercentTip = Translations.Translate("RPR_CAL_VOL_EPC_TIP"); string useFixedPop = Translations.Translate("RPR_CAL_VOL_FXP"); string useFixedPopTip = Translations.Translate("RPR_CAL_VOL_FXP_TIP"); string fixedPop = Translations.Translate("RPR_CAL_VOL_UNI"); string fixedPopTip = Translations.Translate("RPR_CAL_VOL_UNI_TIP"); string areaPer = Translations.Translate("RPR_CAL_VOL_APU"); string areaPerTip = Translations.Translate("RPR_CAL_VOL_APU_TIP"); string multiFloor = Translations.Translate("RPR_CAL_VOL_MFU"); string multiFloorTip = Translations.Translate("RPR_CAL_VOL_MFU_TIP"); // Headings. currentY += 140f; PanelUtils.ColumnLabel(panel, EmptyAreaX, currentY, ColumnWidth, emptyArea, emptyAreaTip, 1.0f); PanelUtils.ColumnLabel(panel, EmptyPercentX, currentY, ColumnWidth, emptyPercent, emptyPercentTip, 1.0f); PanelUtils.ColumnLabel(panel, PopCheckX, currentY, ColumnWidth, useFixedPop, useFixedPopTip, 1.0f); PanelUtils.ColumnLabel(panel, FixedPopX, currentY, ColumnWidth, fixedPop, fixedPopTip, 1.0f); PanelUtils.ColumnLabel(panel, AreaPerX, currentY, ColumnWidth, areaPer, areaPerTip, 1.0f); PanelUtils.ColumnLabel(panel, MultiFloorX, currentY, ColumnWidth, multiFloor, multiFloorTip, 1.0f); // Add level textfields. for (int i = 0; i < 5; ++i) { // Row label. rowLabels[i] = RowLabel(panel, currentY, Translations.Translate("RPR_OPT_LVL") + " " + (i + 1).ToString()); emptyPercentFields[i] = UIControls.AddTextField(panel, EmptyPercentX + Margin, currentY, width: TextFieldWidth, tooltip: emptyPercentTip); emptyPercentFields[i].eventTextChanged += (control, value) => PanelUtils.IntTextFilter((UITextField)control, value); emptyPercentFields[i].tooltipBox = TooltipUtils.TooltipBox; emptyAreaFields[i] = UIControls.AddTextField(panel, EmptyAreaX + Margin, currentY, width: TextFieldWidth, tooltip: emptyAreaTip); emptyAreaFields[i].eventTextChanged += (control, value) => PanelUtils.FloatTextFilter((UITextField)control, value); emptyAreaFields[i].tooltipBox = TooltipUtils.TooltipBox; // Fixed pop checkboxes - ensure i is saved as objectUserData for use by event handler. Starts unchecked by default. fixedPopChecks[i] = UIControls.AddCheckBox(panel, PopCheckX + (ColumnWidth / 2), currentY, tooltip: useFixedPopTip); fixedPopChecks[i].objectUserData = i; fixedPopChecks[i].eventCheckChanged += FixedPopCheckChanged; fixedPopChecks[i].tooltipBox = TooltipUtils.TooltipBox; // Fixed population fields start hidden by default. fixedPopFields[i] = UIControls.AddTextField(panel, FixedPopX + Margin, currentY, width: TextFieldWidth, tooltip: fixedPopTip); fixedPopFields[i].eventTextChanged += (control, value) => PanelUtils.IntTextFilter((UITextField)control, value); fixedPopFields[i].tooltipBox = TooltipUtils.TooltipBox; fixedPopFields[i].Hide(); areaPerFields[i] = UIControls.AddTextField(panel, AreaPerX + Margin, currentY, width: TextFieldWidth, tooltip: areaPerTip); areaPerFields[i].eventTextChanged += (control, value) => PanelUtils.FloatTextFilter((UITextField)control, value); areaPerFields[i].tooltipBox = TooltipUtils.TooltipBox; multiFloorChecks[i] = UIControls.AddCheckBox(panel, MultiFloorX + (ColumnWidth / 2), currentY, tooltip: multiFloorTip); multiFloorChecks[i].tooltipBox = TooltipUtils.TooltipBox; // Move to next row. currentY += RowHeight; } // Add footer controls. PanelFooter(currentY); // Set service menu to initial state (residential), which will also update textfield visibility via event handler. serviceDropDown.selectedIndex = 0; }