/// <summary> /// Adds a Ploppable RICO button to a building info panel to directly access that building's RICO settings. /// The button will be added to the right of the panel with a small margin from the panel edge, at the relative Y position specified. /// </summary> /// <param name="infoPanel">Infopanel to apply the button to</param> private static void AddInfoPanelButton(BuildingWorldInfoPanel infoPanel) { UIButton panelButton = infoPanel.component.AddUIComponent <UIButton>(); // Basic button setup. panelButton.size = new Vector2(34, 34); panelButton.normalBgSprite = "ToolbarIconGroup6Normal"; panelButton.normalFgSprite = "IconPolicyBigBusiness"; panelButton.focusedBgSprite = "ToolbarIconGroup6Focused"; panelButton.hoveredBgSprite = "ToolbarIconGroup6Hovered"; panelButton.pressedBgSprite = "ToolbarIconGroup6Pressed"; panelButton.disabledBgSprite = "ToolbarIconGroup6Disabled"; panelButton.name = "PloppableButton"; panelButton.tooltip = Translations.Translate("PRR_SET_RICO"); // Find ProblemsPanel relative position to position button. // We'll use 40f as a default relative Y in case something doesn't work. UIComponent problemsPanel; float relativeY = 40f; // Player info panels have wrappers, zoned ones don't. UIComponent wrapper = infoPanel.Find("Wrapper"); if (wrapper == null) { problemsPanel = infoPanel.Find("ProblemsPanel"); } else { problemsPanel = wrapper.Find("ProblemsPanel"); } try { // Position button vertically in the middle of the problems panel. If wrapper panel exists, we need to add its offset as well. relativeY = (wrapper == null ? 0 : wrapper.relativePosition.y) + problemsPanel.relativePosition.y + ((problemsPanel.height - 34) / 2); } catch { // Don't really care; just use default relative Y. Logging.Message("couldn't find ProblemsPanel relative position"); } // Set position. panelButton.AlignTo(infoPanel.component, UIAlignAnchor.TopRight); panelButton.relativePosition += new Vector3(-5f, relativeY, 0f); // Event handler. panelButton.eventClick += (control, clickEvent) => { // Select current building in the building details panel and show. Open(InstanceManager.GetPrefabInfo(WorldInfoPanel.GetCurrentInstanceID()) as BuildingInfo); // Manually unfocus control, otherwise it can stay focused until next UI event (looks untidy). control.Unfocus(); }; }
protected UIButton AddRemoveVehicleButton(WorldInfoPanel panel) { UIButton button = UIView.GetAView().AddUIComponent(typeof(RemoveVehicleButton)) as RemoveVehicleButton; button.AlignTo(panel.component, UIAlignAnchor.TopRight); button.relativePosition += new Vector3(-button.width - 40f, 50f); return(button); }
public static void Pairup(UICheckBox checkbox, UIButton button) { Assertion.NotNull(checkbox, "checkbox"); Assertion.NotNull(button, "button"); var container = checkbox.parent as UIComponent; Assertion.NotNull(container, "container"); var panel = container.AddUIComponent <UIPanel>(); panel.width = container.width; panel.height = button.height; checkbox.AlignTo(panel, UIAlignAnchor.TopLeft); checkbox.relativePosition += new Vector3(0, 10); button.AlignTo(panel, UIAlignAnchor.TopRight); button.relativePosition -= new Vector3(button.width, 0); }
public static UIButton CreateToggleButton(UIComponent parentComponent, Vector3 offset, UIAlignAnchor anchor, MouseEventHandler handler) { UIButton uibutton = UIView.GetAView().AddUIComponent(typeof(UIButton)) as UIButton; uibutton.name = "CustomizeItButton"; uibutton.width = 26f; uibutton.height = 26f; uibutton.normalFgSprite = "Options"; uibutton.disabledFgSprite = "OptionsDisabled"; uibutton.hoveredFgSprite = "OptionsHovered"; uibutton.focusedFgSprite = "OptionsFocused"; uibutton.pressedFgSprite = "OptionsPressed"; uibutton.normalBgSprite = "OptionBase"; uibutton.disabledBgSprite = "OptionBaseDisabled"; uibutton.hoveredBgSprite = "OptionBaseHovered"; uibutton.focusedBgSprite = "OptionBaseFocused"; uibutton.pressedBgSprite = "OptionBasePressed"; uibutton.eventClick += handler; uibutton.AlignTo(parentComponent, anchor); uibutton.relativePosition += offset; return(uibutton); }
private void Start() { foreach (UIDynamicPanels.DynamicPanelInfo dynamicPanel in UIView.library.m_DynamicPanels) { VehicleWorldInfoPanel[] panels = dynamicPanel.instance.gameObject.GetComponents <VehicleWorldInfoPanel>(); foreach (VehicleWorldInfoPanel panel in panels) { UIButton button = panel.component.AddUIComponent <UIButton>(); button.eventClick += RemoveButtonHandler; button.text = Translation.GetString("Remove_Vehicle"); button.name = String.Format("{0} :: {1}", _settings.Tag, button.text); button.autoSize = true; UIButton target = panel.Find <UIButton>("Target"); button.font = target.font; button.textScale = target.textScale; button.textColor = target.textColor; button.disabledTextColor = target.disabledTextColor; button.hoveredTextColor = target.hoveredTextColor; button.focusedTextColor = target.focusedTextColor; button.pressedTextColor = target.pressedTextColor; button.useDropShadow = target.useDropShadow; button.dropShadowColor = target.dropShadowColor; button.dropShadowOffset = target.dropShadowOffset; button.AlignTo(panel.Find <UILabel>("Type"), UIAlignAnchor.TopRight); button.relativePosition += new Vector3(button.width + 7, 0); _buttons.Add(button); } } }
/// <summary> /// Adds an ABLC button to a building info panel to open the ABLC panel for that building. /// The button will be added to the right of the panel with a small margin from the panel edge, at the relative Y position specified. /// </summary> internal static void AddInfoPanelButton() { BuildingWorldInfoPanel infoPanel = UIView.library.Get <ZonedBuildingWorldInfoPanel>(typeof(ZonedBuildingWorldInfoPanel).Name); panelButton = infoPanel.component.AddUIComponent <UIButton>(); // Basic button setup. panelButton.atlas = Textures.ABLCButtonSprites; panelButton.size = new Vector2(36, 36); panelButton.normalFgSprite = "normal"; panelButton.focusedFgSprite = "hovered"; panelButton.hoveredFgSprite = "hovered"; panelButton.pressedFgSprite = "pressed"; panelButton.disabledFgSprite = "disabled"; panelButton.name = "ABLCbutton"; panelButton.tooltip = Translations.Translate("ABLC_NAME"); // Find ProblemsPanel relative position to position button. // We'll use 40f as a default relative Y in case something doesn't work. UIComponent problemsPanel; float relativeY = 40f; // Player info panels have wrappers, zoned ones don't. UIComponent wrapper = infoPanel.Find("Wrapper"); if (wrapper == null) { problemsPanel = infoPanel.Find("ProblemsPanel"); } else { problemsPanel = wrapper.Find("ProblemsPanel"); } try { // Position button vertically in the middle of the problems panel. If wrapper panel exists, we need to add its offset as well. relativeY = (wrapper == null ? 0 : wrapper.relativePosition.y) + problemsPanel.relativePosition.y + ((problemsPanel.height - 36) / 2); } catch { // Don't really care; just use default relative Y. Logging.Message("couldn't find ProblemsPanel relative position"); } // Set position. panelButton.AlignTo(infoPanel.component, UIAlignAnchor.TopRight); panelButton.relativePosition += new Vector3(-62f, relativeY, 0f); // Event handler. panelButton.eventClick += (control, clickEvent) => { // Toggle panel visibility. if (uiGameObject == null) { Create(); } else { Close(); } // Manually unfocus control, otherwise it can stay focused until next UI event (looks untidy). control.Unfocus(); }; }
void Start() { GameObject modsList = GameObject.Find("ModsList"); if (modsList == null) { return; } GameObject mod = null; foreach (var item in modsList.GetComponentsInChildren <UILabel>().Where(l => l.name == "Name")) { if (item.text.Contains("jfarias") || item.text.Contains("Traffic++")) { mod = item.transform.parent.gameObject; break; } } if (mod == null) { return; } // Options Button UIButton shareButton = mod.transform.FindChild("Share").GetComponent <UIButton>(); this.m_optionsButtonGo = GameObject.Instantiate <GameObject>(shareButton.gameObject); this.m_optionsButtonGo.transform.SetParent(shareButton.transform.parent); this.m_optionsButtonGo.transform.localPosition = shareButton.transform.localPosition; UIButton optionsButton = this.m_optionsButtonGo.GetComponent <UIButton>(); optionsButton.isVisible = true; optionsButton.text = "Options"; optionsButton.eventClick += OpenOptionsPanel; optionsButton.position += Vector3.left * shareButton.width * 2.1f; // Options Panel GameObject optionsPanel = GameObject.Find("(Library) OptionsPanel"); this.m_optionsPanel = GameObject.Instantiate <GameObject>(optionsPanel); this.m_optionsPanel.transform.SetParent(modsList.transform.parent.transform); GameObject.Destroy(this.m_optionsPanel.GetComponent <OptionsPanel>()); GameObject checkboxTemplate = this.m_optionsPanel.GetComponentsInChildren <UICheckBox>().Where(c => c.name == "EdgeScrolling").FirstOrDefault().gameObject; GameObject.Destroy(checkboxTemplate.GetComponent <BindProperty>()); Vector3 localPosition = checkboxTemplate.transform.localPosition; GameObject caption = null; foreach (Transform transform in m_optionsPanel.transform) { if (transform.name == "Caption") { caption = transform.gameObject; } else { GameObject.Destroy(transform.gameObject); } } this.m_optionsPanel.GetComponent <UIPanel>().autoFitChildrenVertically = true; this.m_optionsPanel.GetComponent <UIPanel>().autoFitChildrenHorizontally = true; // set caption UIButton closeButton = caption.transform.FindChild("Close").GetComponent <UIButton>(); GameObject.Destroy(closeButton.GetComponent <BindEvent>()); closeButton.eventClick += CloseOptionsPanel; caption.transform.FindChild("Label").GetComponent <UILabel>().text = "Traffic++ Options"; // set options list GameObject optionsList = GameObject.Instantiate <GameObject>(modsList); for (int i = optionsList.transform.childCount - 1; i >= 0; i--) { Destroy(optionsList.transform.GetChild(i).gameObject); } optionsList.transform.SetParent(this.m_optionsPanel.transform); optionsList.GetComponent <UIScrollablePanel>().AlignTo(this.m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.TopLeft); optionsList.GetComponent <UIScrollablePanel>().position += new Vector3(caption.transform.FindChild("Label").GetComponent <UILabel>().height, -caption.transform.FindChild("Label").GetComponent <UILabel>().height * 2f); // allow trucks GameObject allowTrucks = GameObject.Instantiate <GameObject>(checkboxTemplate); allowTrucks.transform.SetParent(optionsList.transform); this.m_allowTrucksCheckBox = allowTrucks.GetComponent <UICheckBox>(); this.m_allowTrucksCheckBox.isChecked = false; this.m_allowTrucksCheckBox.text = "Allow Trucks in Pedestrian Roads"; this.m_allowTrucksCheckBox.isVisible = true; this.m_allowTrucksCheckBox.zOrder = 0; //TODO: allow residents //GameObject allowTrucks = GameObject.Instantiate<GameObject>(checkboxTemplate); //GameObject.Destroy(allowTrucks.GetComponent<BindProperty>()); //allowTrucks.transform.SetParent(optionsList.transform); ////allowTrucks.transform.localPosition = localPosition + new Vector3(0.05f, -0.1f, 0f); //this.m_allowTrucksCheckBox = allowTrucks.GetComponent<UICheckBox>(); //this.m_allowTrucksCheckBox.isChecked = false; //this.m_allowTrucksCheckBox.text = "Allow Trucks in Pedestrian Roads"; //this.m_allowTrucksCheckBox.isVisible = true; //this.m_allowTrucksCheckBox.zOrder = 0; // disable central lane GameObject disableCentralLane = GameObject.Instantiate <GameObject>(allowTrucks); disableCentralLane.transform.SetParent(allowTrucks.transform.parent); this.m_disableCentralLaneCheckBox = disableCentralLane.GetComponent <UICheckBox>(); this.m_disableCentralLaneCheckBox.isChecked = false; this.m_disableCentralLaneCheckBox.text = "Disable Central Lane on Pedestrian Roads"; this.m_disableCentralLaneCheckBox.isVisible = true; this.m_disableCentralLaneCheckBox.zOrder = 2; GameObject ghostMode = GameObject.Instantiate <GameObject>(allowTrucks); ghostMode.transform.SetParent(this.m_optionsPanel.transform); this.m_ghostModeCheckBox = ghostMode.GetComponent <UICheckBox>(); this.m_ghostModeCheckBox.isChecked = false; this.m_ghostModeCheckBox.text = "Enable Ghost Mode (disables all mod functionality leaving only enough logic to load the map)"; this.m_ghostModeCheckBox.isVisible = true; this.m_ghostModeCheckBox.AlignTo(m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.BottomLeft); // save button GameObject save = GameObject.Instantiate <GameObject>(this.m_optionsButtonGo); save.transform.SetParent(this.m_optionsPanel.transform); UIButton saveButton = save.GetComponent <UIButton>(); saveButton.isVisible = true; saveButton.eventClick += OnSave; saveButton.color = Color.green; saveButton.text = "Save"; saveButton.AlignTo(m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.BottomRight); this.Load(); this.m_initialized = true; }
void Start() { #if DEBUG //foreach (var item in GameObject.FindObjectsOfType<GameObject>()) //{ // if (item.transform.parent == null) // Initializer.PrintGameObjects(item, "MainMenuScene_110b.txt"); //} #endif GameObject contentManager = GameObject.Find("(Library) ContentManagerPanel"); if (contentManager == null) { return; } Transform mods = contentManager.transform.GetChild(0).FindChild("Mods"); if (mods == null) { //Logger.LogInfo("Can't find mods"); return; } UILabel modLabel = mods.GetComponentsInChildren <UILabel>().FirstOrDefault(l => l.text.Contains("jfarias") || l.text.Contains("Traffic++")); if (modLabel == null) { //Logger.LogInfo("Can't find label"); return; } GameObject mod = modLabel.transform.parent.gameObject; UIButton shareButton = mod.GetComponentsInChildren <UIButton>(true).FirstOrDefault(b => b.name == "Share"); if (shareButton == null) { return; } //// Options Button //Transform shareButtonTransform = mod.transform.FindChild("Share"); //if (shareButtonTransform == null) //{ // //Logger.LogInfo("Can't find share"); // return; //} //UIButton shareButton = shareButtonTransform.gameObject.GetComponent<UIButton>(); this.m_optionsButtonGo = Instantiate <GameObject>(shareButton.gameObject); this.m_optionsButtonGo.name = "Options"; UIButton optionsButton = mod.GetComponent <UIPanel>().AttachUIComponent(this.m_optionsButtonGo) as UIButton; this.m_optionsButtonGo.transform.localPosition = shareButton.transform.localPosition; optionsButton.isVisible = true; optionsButton.text = "Options"; optionsButton.eventClick += OpenOptionsPanel; optionsButton.position += Vector3.right * (optionsButton.width * 1.1f); // Options Panel GameObject optionsPanel = GameObject.Find("(Library) OptionsPanel"); this.m_optionsPanel = Instantiate <GameObject>(optionsPanel); this.m_optionsPanel.transform.SetParent(GameObject.Find("(Library) ContentManagerPanel").transform); GameObject.Destroy(this.m_optionsPanel.GetComponent <OptionsPanel>()); m_checkboxTemplate = this.m_optionsPanel.GetComponentsInChildren <UICheckBox>().FirstOrDefault(c => c.name == "EdgeScrolling").gameObject; GameObject.Destroy(m_checkboxTemplate.GetComponent <BindProperty>()); // clear panel but keep title GameObject caption = null; foreach (Transform transform in m_optionsPanel.transform) { if (transform.name == "Caption") { caption = transform.gameObject; } else { GameObject.Destroy(transform.gameObject); } } this.m_optionsPanel.GetComponent <UIPanel>().autoFitChildrenVertically = true; this.m_optionsPanel.GetComponent <UIPanel>().autoFitChildrenHorizontally = true; // set caption caption.transform.FindChild("Label").GetComponent <UILabel>().text = "Traffic++ Options"; // clear close event UIButton closeButton = caption.transform.FindChild("Close").GetComponent <UIButton>(); GameObject.Destroy(closeButton.GetComponent <BindEvent>()); closeButton.eventClick += CloseOptionsPanel; // set options list m_optionsList = Instantiate <GameObject>(mod.transform.parent.gameObject); for (int i = m_optionsList.transform.childCount - 1; i >= 0; i--) { Destroy(m_optionsList.transform.GetChild(i).gameObject); } m_optionsList.transform.SetParent(this.m_optionsPanel.transform); m_optionsList.GetComponent <UIScrollablePanel>().AlignTo(this.m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.TopLeft); m_optionsList.GetComponent <UIScrollablePanel>().position += new Vector3(caption.transform.FindChild("Label").GetComponent <UILabel>().height, -caption.transform.FindChild("Label").GetComponent <UILabel>().height * 2f); // save button GameObject save = Instantiate <GameObject>(this.m_optionsButtonGo); save.transform.SetParent(this.m_optionsPanel.transform); UIButton saveButton = save.GetComponent <UIButton>(); saveButton.isVisible = true; saveButton.eventClick += OnSave; saveButton.color = Color.green; saveButton.text = "Save"; saveButton.AlignTo(m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.BottomRight); Vector3 cornerOffset = new Vector3(saveButton.width * -0.1f, saveButton.height * 0.3f); saveButton.position += cornerOffset; // add options m_allowTrucksCheckBox = AddOptionCheckbox("Allow Trucks in Pedestrian Roads", 0); m_allowResidentsCheckBox = AddOptionCheckbox("Allow Residents in Pedestrian Roads", 1); m_disableCentralLaneCheckBox = AddOptionCheckbox("Disable Central Lane on Pedestrian Roads", 2); m_noDespawnCheckBox = AddOptionCheckbox("No Despawn by CBeTHaX", 3); m_realisticSpeedsCheckBox = AddOptionCheckbox("Beta Test: Realistic Speeds", 4); m_betaTestRoadCustomizerCheckBox = AddOptionCheckbox("Beta Test: Road Customizer Tool", 5); m_improvedAICheckBox = AddOptionCheckbox("Beta Test: Improved AI", 6); m_noStopForCrossing = AddOptionCheckbox("Beta Test: Cars drive trough pedestrian crossings", 7); m_ghostModeCheckBox = AddOptionCheckbox("Ghost Mode (disables all mod functionality leaving only enough logic to load the map)"); m_ghostModeCheckBox.gameObject.transform.SetParent(m_optionsPanel.transform); m_ghostModeCheckBox.AlignTo(m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.BottomLeft); m_ghostModeCheckBox.position += new Vector3(-cornerOffset.x, cornerOffset.y); m_ghostModeCheckBox.width -= saveButton.width; LoadOptions(); m_initialized = true; }
void Start() { GameObject modsList = GameObject.Find("ModsList"); if (modsList == null) { return; } GameObject mod = null; foreach (var item in modsList.GetComponentsInChildren <UILabel>().Where(l => l.name == "Name")) { if (item.text.Contains("jfarias") || item.text.Contains("Traffic++")) { mod = item.transform.parent.gameObject; break; } } if (mod == null) { return; } // Options Button UIButton shareButton = mod.transform.FindChild("Share").GetComponent <UIButton>(); this.m_optionsButtonGo = Instantiate <GameObject>(shareButton.gameObject); this.m_optionsButtonGo.name = "Options"; this.m_optionsButtonGo.transform.SetParent(shareButton.transform.parent); this.m_optionsButtonGo.transform.localPosition = shareButton.transform.localPosition; UIButton optionsButton = this.m_optionsButtonGo.GetComponent <UIButton>(); optionsButton.isVisible = true; optionsButton.text = "Options"; optionsButton.eventClick += OpenOptionsPanel; optionsButton.position += Vector3.left * shareButton.width * 2.1f; // Options Panel GameObject optionsPanel = GameObject.Find("(Library) OptionsPanel"); this.m_optionsPanel = Instantiate <GameObject>(optionsPanel); this.m_optionsPanel.transform.SetParent(modsList.transform.parent.transform); GameObject.Destroy(this.m_optionsPanel.GetComponent <OptionsPanel>()); m_checkboxTemplate = this.m_optionsPanel.GetComponentsInChildren <UICheckBox>().FirstOrDefault(c => c.name == "EdgeScrolling").gameObject; GameObject.Destroy(m_checkboxTemplate.GetComponent <BindProperty>()); // clear panel but keep title GameObject caption = null; foreach (Transform transform in m_optionsPanel.transform) { if (transform.name == "Caption") { caption = transform.gameObject; } else { GameObject.Destroy(transform.gameObject); } } this.m_optionsPanel.GetComponent <UIPanel>().autoFitChildrenVertically = true; this.m_optionsPanel.GetComponent <UIPanel>().autoFitChildrenHorizontally = true; // set caption caption.transform.FindChild("Label").GetComponent <UILabel>().text = "Traffic++ Options"; // clear close event UIButton closeButton = caption.transform.FindChild("Close").GetComponent <UIButton>(); GameObject.Destroy(closeButton.GetComponent <BindEvent>()); closeButton.eventClick += CloseOptionsPanel; // set options list m_optionsList = Instantiate <GameObject>(modsList); for (int i = m_optionsList.transform.childCount - 1; i >= 0; i--) { Destroy(m_optionsList.transform.GetChild(i).gameObject); } m_optionsList.transform.SetParent(this.m_optionsPanel.transform); m_optionsList.GetComponent <UIScrollablePanel>().AlignTo(this.m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.TopLeft); m_optionsList.GetComponent <UIScrollablePanel>().position += new Vector3(caption.transform.FindChild("Label").GetComponent <UILabel>().height, -caption.transform.FindChild("Label").GetComponent <UILabel>().height * 2f); // save button GameObject save = Instantiate <GameObject>(this.m_optionsButtonGo); save.transform.SetParent(this.m_optionsPanel.transform); UIButton saveButton = save.GetComponent <UIButton>(); saveButton.isVisible = true; saveButton.eventClick += OnSave; saveButton.color = Color.green; saveButton.text = "Save"; saveButton.AlignTo(m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.BottomRight); Vector3 cornerOffset = new Vector3(saveButton.width * -0.1f, saveButton.height * 0.3f); saveButton.position += cornerOffset; // add options m_allowTrucksCheckBox = AddOptionCheckbox("Allow Trucks in Pedestrian Roads", 0); m_allowResidentsCheckBox = AddOptionCheckbox("Allow Residents in Pedestrian Roads", 1); m_disableCentralLaneCheckBox = AddOptionCheckbox("Disable Central Lane on Pedestrian Roads", 2); m_realisticSpeedsCheckBox = AddOptionCheckbox("Beta Test: Realistic Speeds", 3); m_betaTestRoadsCheckBox = AddOptionCheckbox("Beta Test: New Road Types and Textures", 4); m_betaTestRoadCustomizerCheckBox = AddOptionCheckbox("Beta Test: Road Customizer Tool", 5); m_ghostModeCheckBox = AddOptionCheckbox("Ghost Mode (disables all mod functionality leaving only enough logic to load the map)"); m_ghostModeCheckBox.gameObject.transform.SetParent(m_optionsPanel.transform); m_ghostModeCheckBox.AlignTo(m_optionsPanel.GetComponent <UIPanel>(), UIAlignAnchor.BottomLeft); m_ghostModeCheckBox.position += new Vector3(-cornerOffset.x, cornerOffset.y); m_ghostModeCheckBox.width -= saveButton.width; HandleImprovedModsPanel(mod); LoadOptions(); m_initialized = true; }