private void SetupControls() { save = UIUtils.CreateButton(this); save.text = "Save"; save.width = 140; addLocal = UIUtils.CreateButton(this); addLocal.text = "Add Local"; addLocal.width = 140; addLocal.eventClick += (c, p) => { if (!currentSelection.hasLocal) { currentSelection.local = new RICOBuilding(); currentSelection.hasLocal = true; //Set some basic settings for assets with no settings currentSelection.local.name = currentSelection.name; currentSelection.local.ricoEnabled = true; currentSelection.local.service = "residential"; currentSelection.local.subService = "low"; currentSelection.local.level = 1; currentSelection.local.uiCategory = "reslow"; currentSelection.local.constructionCost = 10; currentSelection.local.homeCount = 10; //If selected asset has author settings, copy those to local if (currentSelection.hasAuthor) { currentSelection.local = (RICOBuilding)currentSelection.author.Clone(); } else if (currentSelection.hasMod) { currentSelection.local = (RICOBuilding)currentSelection.mod.Clone(); } currentSelection.local.name = currentSelection.name; //currentSelection.local = (PloppableRICODefinition.Building)newlocal.Clone(); if (enabled) { RICOSettingsPanel.instance.UpdateBuildingInfo(currentSelection); } if (enabled) { RICOSettingsPanel.instance.UpdateSelection(); } Save(); } }; removeLocal = UIUtils.CreateButton(this); removeLocal.eventClick += (c, p) => { currentSelection.local = null; currentSelection.hasLocal = false; RICOSettingsPanel.instance.UpdateBuildingInfo(currentSelection); if (enabled) { RICOSettingsPanel.instance.UpdateSelection(); } Save(); }; removeLocal.text = "Remove Local"; removeLocal.width = 140; save.eventClick += (c, p) => { Save(); }; }
/// <summary> /// Draws the Ploppable Tool panel. /// </summary> private void DrawPloppablePanel() { // Check to make sure that we haven't already done this. if (PloppableButton == null) { // Set state flag; this is a new setup. hasShown = false; // Main button on ingame toolbar. PloppableButton = UIView.GetAView().FindUIComponent <UITabstrip>("MainToolstrip").AddUIComponent <UIButton>(); PloppableButton.size = new Vector2(43, 49); PloppableButton.normalBgSprite = "ToolbarIconGroup6Normal"; PloppableButton.normalFgSprite = "IconPolicyBigBusiness"; PloppableButton.focusedBgSprite = "ToolbarIconGroup6Focused"; PloppableButton.hoveredBgSprite = "ToolbarIconGroup6Hovered"; PloppableButton.pressedBgSprite = "ToolbarIconGroup6Pressed"; PloppableButton.disabledBgSprite = "ToolbarIconGroup6Disabled"; PloppableButton.relativePosition = new Vector2(800, 0); PloppableButton.name = "PloppableButton"; PloppableButton.tooltip = Translations.Translate("PRR_NAME"); // Event handler - show the Ploppable Tool panel when the button is clicked. PloppableButton.eventClick += (component, clickEvent) => { component.Focus(); buildingPanel.isVisible = true; }; // Base panel. buildingPanel = UIView.GetAView().FindUIComponent("TSContainer").AddUIComponent <UIPanel>(); buildingPanel.backgroundSprite = "SubcategoriesPanel"; buildingPanel.isVisible = false; buildingPanel.name = "PloppableBuildingPanel"; buildingPanel.size = new Vector2(859, 109); buildingPanel.relativePosition = new Vector2(0, 0); // Tabstrip. Tabs = UIView.GetAView().FindUIComponent("PloppableBuildingPanel").AddUIComponent <UITabstrip>(); Tabs.size = new Vector2(832, 25); Tabs.relativePosition = new Vector2(13, -25); Tabs.pivot = UIPivotPoint.BottomCenter; Tabs.padding = new RectOffset(0, 3, 0, 0); // Get game sprite thumbnail atlas. UITextureAtlas gameIconAtlas = Resources.FindObjectsOfTypeAll <UITextureAtlas>().FirstOrDefault(a => a.name == "Thumbnails"); // Scroll panel. AddScrollPanel(); // Tabs. for (int i = 0; i <= NumTypes; i++) { // Draw tabs in tabstrip. TabButtons[i] = new UIButton(); TabButtons[i] = Tabs.AddUIComponent <UIButton>(); TabButtons[i].size = new Vector2(46, 25); TabButtons[i].normalBgSprite = "SubBarButtonBase"; TabButtons[i].disabledBgSprite = "SubBarButtonBaseDisabled"; TabButtons[i].pressedBgSprite = "SubBarButtonBasePressed"; TabButtons[i].hoveredBgSprite = "SubBarButtonBaseHovered"; TabButtons[i].focusedBgSprite = "SubBarButtonBaseFocused"; TabButtons[i].state = UIButton.ButtonState.Normal; TabButtons[i].name = Names[i] + "Button"; TabButtons[i].tabStrip = true; TabSprites[i] = new UISprite(); TabSprites[i] = TabButtons[i].AddUIComponent <UISprite>(); // Standard "Vanilla" categories (low and high residential, low and high commercial, and offices) - use standard zoning icons from original vanilla release. if (i <= 5) { TabSprites[i].atlas = gameIconAtlas; SetTabSprite(TabSprites[i], "Zoning" + Names[i]); } else { // Other types don't have standard zoning icons; use policy icons instead. SetTabSprite(TabSprites[i], "IconPolicy" + Names[i]); } } // This can't happen in a loop, because the loop index is undefined after setup has occured (i.e. when the function is actually called). TabButtons[0].eventClick += (component, clickEvent) => TabClicked(0, TabSprites[0]); TabButtons[1].eventClick += (component, clickEvent) => TabClicked(1, TabSprites[1]); TabButtons[2].eventClick += (component, clickEvent) => TabClicked(2, TabSprites[2]); TabButtons[3].eventClick += (component, clickEvent) => TabClicked(3, TabSprites[3]); TabButtons[4].eventClick += (component, clickEvent) => TabClicked(4, TabSprites[4]); TabButtons[5].eventClick += (component, clickEvent) => TabClicked(5, TabSprites[5]); TabButtons[6].eventClick += (component, clickEvent) => TabClicked(6, TabSprites[6]); TabButtons[7].eventClick += (component, clickEvent) => TabClicked(7, TabSprites[7]); TabButtons[8].eventClick += (component, clickEvent) => TabClicked(8, TabSprites[8]); TabButtons[9].eventClick += (component, clickEvent) => TabClicked(9, TabSprites[9]); // Below are DLC categories - AD for first two, then GC for next 3. Will be hidden if relevant DLC is not installed. TabButtons[10].eventClick += (component, clickEvent) => TabClicked(10, TabSprites[10]); TabButtons[11].eventClick += (component, clickEvent) => TabClicked(11, TabSprites[11]); TabButtons[12].eventClick += (component, clickEvent) => TabClicked(12, TabSprites[12]); TabButtons[13].eventClick += (component, clickEvent) => TabClicked(13, TabSprites[13]); TabButtons[14].eventClick += (component, clickEvent) => TabClicked(14, TabSprites[14]); // Activate low residential panel to start with (what the user sees on first opening the panel). //BuildingPanels[0].isVisible = true; // Hide AD tabs if AD is not installed. if (!Util.IsADinstalled()) { TabButtons[10].isVisible = false; TabButtons[11].isVisible = false; } // Hide GC tabs if GC is not installed. if (!Util.IsGCinstalled()) { TabButtons[12].isVisible = false; TabButtons[13].isVisible = false; TabButtons[14].isVisible = false; } // Settings tab. showSettings = UIUtils.CreateButton(Tabs); showSettings.size = new Vector2(100, 25); showSettings.normalBgSprite = "SubBarButtonBase"; showSettings.eventClick += (component, clickEvent) => { SettingsPanel.Open(scrollPanel?.selectedItem?.prefab); }; // Add UI text. SetText(); // Toggle active state on visibility changed if we're using the UI speed boost (deactivating when hidden to minimise UI workload and impact on performance). buildingPanel.eventVisibilityChanged += (component, isVisible) => { // Additional check to allow for the case where speedboost has been deactivated mid-game while the panel was deactivated. if ((ModSettings.speedBoost) || (isVisible && !buildingPanel.gameObject.activeSelf)) { buildingPanel.gameObject.SetActive(isVisible); } // Other checks. if (isVisible) { //if Yet Another Toolbar exists, reset panel UI scale try { GameObject yatObject = GameObject.Find("YetAnotherToolbar"); Type YatType = Type.GetType("YetAnotherToolbar.YetAnotherToolbar"); Component yatComponent = yatObject.GetComponent("YetAnotherToolbar"); object yatInstance = YatType.GetField("instance").GetValue(yatComponent); MethodInfo resetScaleMethod = YatType.GetMethod("ResetScale"); resetScaleMethod.Invoke(yatInstance, new object[] {}); } catch (Exception ex) { Debug.Log(ex.Message); } // If this is the first time we're visible, set the display to the initial default tab (low residential). if (!hasShown) { // Set initial default tab. TabClicked(0, _instance.TabSprites[0]); // Done! hasShown = true; } else { // Clear previous selection and refresh panel. scrollPanel.selectedItem = null; scrollPanel.Refresh(); } //if Yet Another Toolbar exists, restore panel UI scale try { GameObject yatObject = GameObject.Find("YetAnotherToolbar"); Type YatType = Type.GetType("YetAnotherToolbar.YetAnotherToolbar"); Component yatComponent = yatObject.GetComponent("YetAnotherToolbar"); object yatInstance = YatType.GetField("instance").GetValue(yatComponent); MethodInfo restoreScaleMethod = YatType.GetMethod("RestoreScale"); restoreScaleMethod.Invoke(yatInstance, new object[] { }); } catch (Exception ex) { Debug.Log(ex.Message); } } else { // Destroy thumbnail renderer if we're no longer visible. ThumbnailManager.Close(); } }; } }